//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TBlockGeomInfo.cpp // = Version : ver2.0 // = Author : xlc // = CreateDate : 2002-09-09 // = Description: 图块几何信息类的定义 // = Maintainers: // //-----------------------------------------------------------------------------+ #include "StdAfx.h" #include "TBlockGeomInfo.h" #include "TchGlobalFunc.h" using namespace TchExport; TBlockGeomInfo::TBlockGeomInfo() :m_nRotation(0.0), m_nSizeX(0.0), m_nSizeY(0.0), m_nSizeZ(0.0) { } TBlockGeomInfo::~TBlockGeomInfo() { } double TBlockGeomInfo::GetRotation() const { return m_nRotation; } TADSGePoint3d TBlockGeomInfo::GetCenter() const { return m_ptCen; } double TBlockGeomInfo::GetSizeX() const { return m_nSizeX; } double TBlockGeomInfo::GetSizeY() const { return m_nSizeY; } double TBlockGeomInfo::GetSizeZ() const { return m_nSizeZ; } void TBlockGeomInfo::SetFromInsert(const AcDbBlockReference *pBlk) { if(pBlk) { TADSGePoint3d _pt; GetBlockRefSizeInfo(pBlk, _pt, &m_nRotation, m_ptCen, &m_nSizeX, &m_nSizeY, &m_nSizeZ); m_ptCen.z -= m_nSizeZ / 2.0; } } void TBlockGeomInfo::UpdateInsert(AcDbBlockReference *pInsert) const { TADSGePoint3d 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 TBlockGeomInfo::CalInsertParameters(const AcDbBlockReference *pBlkSrc, TADSGePoint3d &ptNewBase, double *nRotation, double *nSx, double *nSy, double *nSz) const { ads_matrix matRotOld, matMove, matScale, matRotNew, matTransform; double nSizeX, nSizeY, nSizeZ, nRot; TADSGePoint3d ptBase, ptCen, ptNewCen; VERIFY(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); 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; } // 取得四个角点 TADSGePoint3d TBlockGeomInfo::GetLowLeft() const { double nAng = atan(m_nSizeY / m_nSizeX); double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX); TADSGePoint3d ptLowLeft; ads_polar(m_ptCen, m_nRotation + PI + nAng, nLen / 2.0, ptLowLeft); return ptLowLeft; } TADSGePoint3d TBlockGeomInfo::GetLowRight() const { double nAng = atan(m_nSizeY / m_nSizeX); double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX); TADSGePoint3d ptLowRight; ads_polar(m_ptCen, m_nRotation - nAng, nLen / 2.0, ptLowRight); return ptLowRight; } TADSGePoint3d TBlockGeomInfo::GetUpRight() const { double nAng = atan(m_nSizeY / m_nSizeX); double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX); TADSGePoint3d ptUpRight; ads_polar(m_ptCen, m_nRotation + nAng, nLen / 2.0, ptUpRight); return ptUpRight; } TADSGePoint3d TBlockGeomInfo::GetUpLeft() const { double nAng = atan(m_nSizeY / m_nSizeX); double nLen = sqrt(m_nSizeY * m_nSizeY + m_nSizeX * m_nSizeX); TADSGePoint3d ptUpLeft; ads_polar(m_ptCen, m_nRotation + PI - nAng, nLen / 2.0, ptUpLeft); return ptUpLeft; } void TBlockGeomInfo::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); }