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

156 lines
4.6 KiB
C++

// TBlockInsertEdJig.cpp: implementation of the TBlockInsertEdJig class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TBlockInsertEdJig.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//******************************************************************************
//******************************************************************************
TBlockInsertEdJig2::TBlockInsertEdJig2(AcDbEntity *pDrag, XPoint ptRef)
{
m_pDrawEnt=pDrag;
m_pBackup=(AcDbEntity *)pDrag->clone();
m_ptRef=ptRef;
}
void TBlockInsertEdJig2::SetBlockId(AcDbObjectId idBlock)
{
if(m_pBackup->isKindOf(AcDbBlockReference::desc())) {
AcDbBlockReference *pInsert=AcDbBlockReference::cast(m_pDrawEnt);
pInsert->setBlockTableRecord(idBlock);
}
}
// 开始执行拖动
int TBlockInsertEdJig2::DoIt(int *keyIndex)
{
m_ptResult=m_ptRef;
int nRet = TSymbEdJig::DoIt(keyIndex);
return nRet;
}
// 反馈
AcEdJig::DragStatus TBlockInsertEdJig2::GetPoint(XPoint &pt)
{
DragStatus stat;
if(m_nOperCode==kRotate) {
double nAngle=0.0;
stat=acquireAngle(nAngle, m_ptRef);
ads_polar(m_ptRef, nAngle, 100.0, pt);
} else {
stat=acquirePoint(pt);
if (stat == kKW2)
{
AcDbBlockReference *pBlockInsert=AcDbBlockReference::cast(m_pDrawEnt);
if (pBlockInsert != NULL)
{
AcDbBlockReference &entInsert=*pBlockInsert;
double dRotate = entInsert.rotation();
entInsert.setRotation(dRotate + PI/2);
}
}
}
return stat;
}
// 更新实体数据
Adesk::Boolean TBlockInsertEdJig2::update()
{
Adesk::Boolean bRet=Adesk::kTrue;
AcGeMatrix3d mat;
AcGeScale3d scales(1);
if (m_pDrawEnt != NULL)
{
AcDbBlockReference *pBlockInsert=AcDbBlockReference::cast(m_pDrawEnt);
AcDbBlockReference &entInsert=*pBlockInsert;
scales = entInsert.scaleFactors();
if(m_nOperCode==kMove) {
// XVector3D vtMove=m_ptResult-m_ptRef;
// mat.setToTranslation(vtMove);
// GlobalFunc::CopyObject(*m_pBackup, *m_pDrawEnt);
// m_pDrawEnt->transformBy(mat);
entInsert.setPosition(m_ptResult);
} else if(m_nOperCode==kRotate) {
GlobalFunc::CopyObject(*m_pBackup, *m_pDrawEnt);
XVector3D vtNormal(0,0,1);
if(m_pDrawEnt->isKindOf(AcDbBlockReference::desc())) {
(AcGeVector3d &)vtNormal=AcDbBlockReference::cast(m_pDrawEnt)->normal();
}
double nRot=ads_angle(GlobalFunc::Wcs2Ecs(m_ptRef, vtNormal), GlobalFunc::Wcs2Ecs(m_ptResult, vtNormal));
mat.setToRotation(nRot, vtNormal, m_ptRef);
m_pDrawEnt->transformBy(mat);
} else if(m_nOperCode==kDragCorner) {
GlobalFunc::CopyObject(*m_pBackup, *m_pDrawEnt);
AcDbBlockReference *pInsert=AcDbBlockReference::cast(m_pDrawEnt);
double m_nRot=pInsert->rotation();
XPoint ptCorn1=m_ptRef;
XPoint ptCorn2=m_ptResult;
double nAngle1=CT_std_angle(ads_angle(ptCorn1, ptCorn2)-m_nRot);
double nDist=ptCorn1.Distance2d(ptCorn2);
XPoint m_ptCen;
Midpoint(ptCorn1, ptCorn2, m_ptCen);
double m_nSizeX=nDist*fabs(cos(nAngle1));
double m_nSizeY=nDist*fabs(sin(nAngle1));
ads_matrix matRotOld, matMove, matScale, matRotNew, matTransform;
double nSizeX, nSizeY, nSizeZ, nRot;
XPoint ptCen, ptNewCen;
XPoint ptIns;
VERIFY(GlobalFunc::GetBlockRefSizeInfo(pInsert, ptIns, &nRot, ptCen, &nSizeX, &nSizeY, &nSizeZ)==RTNORM);
ptNewCen = m_ptCen;
ptNewCen.z += nSizeZ/2.0;
ptNewCen = m_ptCen;
ptNewCen.z += nSizeZ/2.0;
// 绕旧中心旋转-nRotOld -> 绕旧中心Scale -> 平移到新中心 -> 旋转 RotNew
// or
// 绕旧中心旋转-nRotOld -> 绕旧中心Scale -> 旋转 RotNew -> 平移到新中心 (Current Method)
AcGeScale3d bScale = pInsert->scaleFactors();
double sx=1, sy=1, sz=1;
if(fabs(nSizeX)>1.0E-6) bScale[0] *= sx = m_nSizeX/nSizeX;
if(fabs(nSizeY)>1.0E-6) bScale[1] *= sy = m_nSizeY/nSizeY;
//if(fabs(nSizeZ)>1.0E-6) bScale[2] *= sz = m_nSizeZ/nSizeZ;
ptCen.GetRotationMatrix(-nRot, matRotOld);
ptCen.GetScaleMatrix(sx, sy, sz, matScale);
ptCen.GetRotationMatrix(m_nRot, matRotNew);
ptCen.GetMoveMatrix(ptNewCen, matMove);
GlobalFunc::MatrixMultiply(matTransform, matMove, matRotNew, matScale, matRotOld, NULL);
ptIns.TransformBy(matTransform); //换算新的基点位置
pInsert->setPosition(ptIns);
pInsert->setScaleFactors(bScale);
}
entInsert.setScaleFactors(scales);
}
return bRet;
}
AcDbEntity* TBlockInsertEdJig2::entity() const
{
return (AcDbEntity *)m_pDrawEnt;
}