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

159 lines
4.0 KiB
C++

#include "StdAfx.h"
#include "globalFunc.h"
#include "TBlockGeomInfo.h"
BlockGeomInfo::BlockGeomInfo()
:m_nRotation(0.0), m_nSizeX(0.0), m_nSizeY(0.0), m_nSizeZ(0.0)
{
}
BlockGeomInfo::~BlockGeomInfo()
{
}
double BlockGeomInfo::GetRotation() const
{
return m_nRotation;
}
ADSGePoint3d BlockGeomInfo::GetCenter() const
{
return m_ptCen;
}
double BlockGeomInfo::GetSizeX() const
{
return m_nSizeX;
}
double BlockGeomInfo::GetSizeY() const
{
return m_nSizeY;
}
double BlockGeomInfo::GetSizeZ() const
{
return m_nSizeZ;
}
void BlockGeomInfo::SetFromInsert(const AcDbBlockReference *pBlk)
{
if(pBlk)
{
ADSGePoint3d pt;
GlobalFunc::GetBlockRefSizeInfo(pBlk, pt, &m_nRotation, m_ptCen, &m_nSizeX, &m_nSizeY, &m_nSizeZ);
m_ptCen.z -= m_nSizeZ / 2.0;
}
}
void BlockGeomInfo::UpdateInsert(AcDbBlockReference *pInsert) const
{
ADSGePoint3d ptNewBase;
double nNewRot;
AcGeScale3d scale;
if(CalInsertParameters(pInsert, ptNewBase, &nNewRot, &scale[0], &scale[1], &scale[2]) != Acad::eOk)
{
return;
}
pInsert->setPosition(ptNewBase);
pInsert->setRotation(nNewRot);
pInsert->setScaleFactors(scale);
}
// 用包络参数换算图块的插入参数
// ptNewBase--新的插入点; nRotation--新的转角; nSx,nSy,nSZ--新的比例
Acad::ErrorStatus
BlockGeomInfo::CalInsertParameters(const AcDbBlockReference *pBlkSrc, ADSGePoint3d &ptNewBase, double *nRotation,
double *nSx, double *nSy, double *nSz) const
{
ads_matrix matRotOld, matMove, matScale, matRotNew, matTransform;
double nSizeX, nSizeY, nSizeZ, nRot;
ADSGePoint3d ptBase, ptCen, ptNewCen;
VERIFY(GlobalFunc::GetBlockRefSizeInfo(pBlkSrc, ptBase, &nRot, ptCen, &nSizeX, &nSizeY, &nSizeZ) == RTNORM);
ptNewCen = m_ptCen;
ptNewCen.z += m_nSizeZ / 2.0;
// 绕旧中心旋转-nRotOld -> 绕旧中心Scale -> 平移到新中心 -> 旋转 RotNew
// or
// 绕旧中心旋转-nRotOld -> 绕旧中心Scale -> 旋转 RotNew -> 平移到新中心 (Current Method)
AcGeScale3d bScale = pBlkSrc->scaleFactors();
double sx = 1.0, sy = 1.0, sz = 1.0;
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_nRotation, matRotNew);
ptCen.GetMoveMatrix(ptNewCen, matMove);
GlobalFunc::MatrixMultiply(matTransform, matMove, matRotNew, matScale, matRotOld, NULL);
ptNewBase = ptBase.TransformAs(matTransform); //换算新的基点位置
*nRotation = m_nRotation;
*nSx = bScale[0];
*nSy = bScale[1];
*nSz = bScale[2];
return Acad::eOk;
}
// 取得四个角点
ADSGePoint3d BlockGeomInfo::GetLowLeft() const
{
double nAng = atan(m_nSizeY / m_nSizeX);
double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX);
ADSGePoint3d ptLowLeft;
ads_polar(m_ptCen, m_nRotation + PI + nAng, nLen / 2.0, ptLowLeft);
return ptLowLeft;
}
ADSGePoint3d BlockGeomInfo::GetLowRight() const
{
double nAng = atan(m_nSizeY / m_nSizeX);
double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX);
ADSGePoint3d ptLowRight;
ads_polar(m_ptCen, m_nRotation - nAng, nLen / 2.0, ptLowRight);
return ptLowRight;
}
ADSGePoint3d BlockGeomInfo::GetUpRight() const
{
double nAng = atan(m_nSizeY / m_nSizeX);
double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX);
ADSGePoint3d ptUpRight;
ads_polar(m_ptCen, m_nRotation + nAng, nLen / 2.0, ptUpRight);
return ptUpRight;
}
ADSGePoint3d BlockGeomInfo::GetUpLeft() const
{
double nAng = atan(m_nSizeY / m_nSizeX);
double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX);
ADSGePoint3d ptUpLeft;
ads_polar(m_ptCen, m_nRotation + PI - nAng, nLen / 2.0, ptUpLeft);
return ptUpLeft;
}
void BlockGeomInfo::GetPolyline(AcDbPolyline &pline) const
{
pline.addVertexAt(0, GetLowLeft().AsAcGePoint2d());
pline.addVertexAt(1, GetLowRight().AsAcGePoint2d());
pline.addVertexAt(2, GetUpRight().AsAcGePoint2d());
pline.addVertexAt(3, GetUpLeft().AsAcGePoint2d());
pline.setClosed(Adesk::kTrue);
}