Files
envi-code/SourceCode/Code2026/PIDLineCmd/KTDimLeaderJig.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

207 lines
4.5 KiB
C++

#include "stdafx.h"
#include "KTDimLeaderJig.h"
#include "KTObjLifeMgr.h"
#include "CKTDimUtility.h"
KTDimLeaderJig::KTDimLeaderJig()
: m_Line1(NULL), m_Line2(NULL),m_ptextu(NULL), m_ptextd(NULL)
{
}
KTDimLeaderJig::~KTDimLeaderJig()
{
}
BOOL KTDimLeaderJig::DragCreate(AcGePoint3d ptBase, double dTextH,double dTextW,int ntype,LPCTSTR pszup,
LPCTSTR pszdown,LPCTSTR pszPrompt,AcDbObjectId idSt,AcDbObjectId idLayer, AcDbVoidPtrArray& arpEnt)
{
m_ntype=ntype;
m_ptFirst = ptBase;
m_idTextS=idSt;
m_idTextL=idLayer;
m_sTextup=pszup;
m_sTextdown=pszdown;
m_dTextH=dTextH;
m_dTextW=dTextW;
AcDbMText* ptextu = new AcDbMText();
if (NULL == ptextu)
return FALSE;
CKTObjLifeMgr entMgr;
entMgr.Add(ptextu);
ptextu->setLayer(idLayer);
m_cDumbEntity.m_arpEntity.append(ptextu);
//第二个线
AcDbMText* ptextd = new AcDbMText();
if (NULL == ptextd)
return FALSE;
entMgr.Add(ptextd);
ptextd->setLayer(idLayer);
m_cDumbEntity.m_arpEntity.append(ptextd);
//第三个线
AcDbLine* Line1 = new AcDbLine();
if (NULL == Line1)
return FALSE;
entMgr.Add(Line1);
Line1->setLayer(idLayer);
m_cDumbEntity.m_arpEntity.append(Line1);
AcDbLine* Line2 = new AcDbLine();
if (NULL == Line2)
return FALSE;
entMgr.Add(Line2);
Line2->setLayer(idLayer);
m_cDumbEntity.m_arpEntity.append(Line2);
ASSERT(NULL == m_ptextu && NULL == m_ptextd && NULL == m_Line1 && NULL == m_Line2);
m_ptextu = ptextu;
m_ptextd = ptextd;
m_Line1 = Line1;
m_Line2 = Line2;
if (NULL != pszPrompt)
setDispPrompt(pszPrompt);
BOOL bError = (AcEdJig::kNormal != drag());
m_ptextu = NULL;
m_ptextd = NULL;
m_Line1 = NULL;
m_Line2 = NULL;
if (bError)
return FALSE;
arpEnt.append(ptextu);
arpEnt.append(ptextd);
arpEnt.append(Line1);
arpEnt.append(Line2);
entMgr.Remove();
return TRUE;
}
AcEdJig::DragStatus KTDimLeaderJig::sampler()
{
setUserInputControls((UserInputControls)(AcEdJig::kAccept3dCoordinates
| AcEdJig::kNoNegativeResponseAccepted | AcEdJig::kNoZeroResponseAccepted));
AcEdJig::DragStatus eStatus = acquirePoint(m_ptDynamic,m_ptFirst);
m_ptDynamic.z = m_ptFirst.z;
if (AcEdJig::kNormal != eStatus)
return eStatus;
if (m_ptLast == m_ptDynamic)
return kNoChange;
return eStatus;
}
Adesk::Boolean KTDimLeaderJig::update()
{
if (m_ptLast == m_ptDynamic)
return Adesk::kTrue;
AcGeVector3d vDirx,vDiry;
AcGePoint3d ptE,ptu,ptd,ptm;
int nl = CKTDimUtility::GetDimTextLen(m_sTextup);
int nldown = CKTDimUtility::GetDimTextLen(m_sTextdown);
if (nl < nldown)
{
nl = nldown;
}
double dl=nl*m_dTextW;
if (m_ntype==0)
{
vDirx.set(1,0,0);
vDiry.set(0,1,0);
if (m_ptDynamic.x < m_ptFirst.x)
{
vDirx.set(-1,0,0);
}
ptu=m_ptDynamic+ vDirx*dl/2 + vDiry*20;
m_ptUp=ptu;
ptd=m_ptDynamic+ vDirx*dl/2 - vDiry*20;
m_ptDown=ptd;
ptE=m_ptDynamic + vDirx*dl;
ptu=m_ptDynamic + vDirx*m_dTextW + vDiry*20;
ptd=m_ptDynamic + vDirx*m_dTextW - vDiry*(m_dTextH+20);
m_ptextu->setTextStyle(m_idTextS);
m_ptextu->setTextHeight(m_dTextH);
m_ptextu->setLayer(m_idTextL);
m_ptextu->setContents(m_sTextup);
m_ptextu->setAttachment(AcDbMText::kBottomCenter);
m_ptextu->setRotation(0);
m_ptextu->setLocation(m_ptUp);
m_ptextd->setTextStyle(m_idTextS);
m_ptextd->setTextHeight(m_dTextH);
m_ptextd->setLayer(m_idTextL);
m_ptextd->setContents(m_sTextdown);
m_ptextd->setAttachment(AcDbMText::kTopCenter);
m_ptextd->setRotation(0);
m_ptextd->setLocation(m_ptDown);
}
else
{
vDirx.set(0,1,0);
vDiry.set(1,0,0);
if (m_ptDynamic.y < m_ptFirst.y)
{
vDirx.set(0,-1,0);
}
ptu=m_ptDynamic+ vDirx*dl/2 - vDiry*20;
m_ptUp=ptu;
ptd=m_ptDynamic+ vDirx*dl/2 + vDiry*20;
m_ptDown=ptd;
ptE=m_ptDynamic + vDirx*dl;
m_ptextu->setTextStyle(m_idTextS);
m_ptextu->setTextHeight(m_dTextH);
m_ptextu->setLayer(m_idTextL);
m_ptextu->setContents(m_sTextup);
m_ptextu->setAttachment(AcDbMText::kBottomCenter);
m_ptextu->setRotation(PI_2);
m_ptextu->setLocation(m_ptUp);
m_ptextd->setTextStyle(m_idTextS);
m_ptextd->setTextHeight(m_dTextH);
m_ptextd->setLayer(m_idTextL);
m_ptextd->setContents(m_sTextdown);
m_ptextd->setAttachment(AcDbMText::kTopCenter);
m_ptextd->setRotation(PI_2);
m_ptextd->setLocation(m_ptDown);
}
//第三个线
m_Line1->setStartPoint(m_ptFirst);
m_Line1->setEndPoint(m_ptDynamic);
m_Line1->setLayer(m_idTextL);
m_Line2->setStartPoint(ptE);
m_Line2->setEndPoint(m_ptDynamic);
m_Line2->setLayer(m_idTextL);
m_ptLast = m_ptDynamic;
return Adesk::kTrue;
}
AcDbEntity* KTDimLeaderJig::entity() const
{
return (AcDbEntity*)&m_cDumbEntity;
}