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

170 lines
4.4 KiB
C++

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