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

511 lines
11 KiB
C++

#include "StdAfx.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////
const Adesk::UInt8 TDbEquipmentBox::g_nVersion = 0; // 可能需要与TDbOpening::g_nVersion关联
ACRX_DXF_DEFINE_MEMBERS(ATSEquipmentBox, ATSOpening, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, ATS_EquipmentBox, "ATS_EquipmentBox图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbEquipmentBox);
TDbEquipmentBox::TDbEquipmentBox()
{
m_dBreadth = 200;
SetKind(TOpeningData::OP_EQUIPBOX);
}
TDbEquipmentBox::~TDbEquipmentBox()
{
}
BOOL TDbEquipmentBox::IsValid() const
{
BOOL bRet = TDbOpening::IsValid();
if (!bRet)
return bRet;
bRet = (m_dBreadth>_DIST_SNAP);
return bRet;
}
void TDbEquipmentBox::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
TDbOpening::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
TDbEquipmentBox *pSrc = TDbEquipmentBox::cast(pSrcEntity);
if (pSrc != NULL)
{
m_dBreadth = pSrc->m_dBreadth;
}
}
Acad::ErrorStatus TDbEquipmentBox::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbOpening::dwgInFields(pFiler);
if (es != Acad::eOk)
return es;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion)
return Acad::eMakeMeProxy;
pFiler->readItem(&m_dBreadth);
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbEquipmentBox::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbOpening::dwgOutFields(pFiler);
if (es != Acad::eOk)
return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_dBreadth);
return es;
}
Acad::ErrorStatus TDbEquipmentBox::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbOpening::dxfInFields(pFiler);
if (es != Acad::eOk)
return es;
if (!pFiler->atSubclassData(_T("TDbEquipmentBox")))
{
return Acad::eBadDxfSequence;
}
{
resbuf rb;
double dW(0.0);
while ((es == Acad::eOk) && ((es = pFiler->readResBuf(&rb)) == Acad::eOk))
{
switch (rb.restype)
{
case AcDb::kDxfReal + 7:
dW = rb.resval.rreal;
break;
default:
pFiler->pushBackItem();
break;
}
}
m_dBreadth = dW;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbEquipmentBox::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbOpening::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbEquipmentBox"));
assert(es == Acad::eOk);
pFiler->writeDouble(AcDb::kDxfReal+7, m_dBreadth);
return es;
}
Acad::ErrorStatus TDbEquipmentBox::GetGripText(int i, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
switch(i)
{
case 0:
cs = _T("移动设备箱");
break;
default:
es = Acad::eInvalidInput;
}
return es;
}
Acad::ErrorStatus TDbEquipmentBox::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const
{
gripPoints.append(m_ptLocation);
return Acad::eOk;
}
Acad::ErrorStatus TDbEquipmentBox::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
XPoint vtOffset = *(XPoint *)&offset;
vtOffset.z = 0;
double dSill = m_ptLocation.z;
for (int i=0; i<indices.length(); i++)
{
int idx = indices[i];
if (idx == 0) // 移动位置
{
XVector3D vt = vtOffset;
if (g_bModelNumber && IsLinear()) // 模数开关
{
ASSERT(g_nWinStep > 1.0E-3);
double nLen = vt.Length();
vt /= nLen;
nLen = AS_INT(nLen/g_nWinStep) * g_nWinStep;
vt *= nLen;
}
m_ptLocation += vt;
m_ptLocation.z = dSill; // 不改变设备箱底高
}
}
return Acad::eOk;
}
#if ADS>15
void TDbEquipmentBox::CreateGrip()
{
TDbEntity::CreateGrip();
XCurveSegment curve;
if (GetCenterCurve(curve) && curve.Is(CURVE_LINE))
{
GetGrip(0)->AppendDim(new TDbGripDistDim(AcDbDimData::kDimDeltaLength, false));
}
}
Acad::ErrorStatus TDbEquipmentBox::EntityToDim(long iGrip, long iDim, const AcDbEntity* pEnt0)
{
XCurveSegment wall;
if (!GetCenterCurve(wall)) // 中线
return Acad::eInvalidInput;
TDbGripDim *pDim = GetGripDim(iGrip, iDim);
if (pDim == NULL)
return Acad::eInvalidInput;
TDbEquipmentBox *pEnt = TDbEquipmentBox::cast(pEnt0);
if (pEnt == NULL)
pEnt = this;
switch(iGrip)
{
case 0: // 位置夹点
switch(iDim)
{
case 0: // 位置偏移
{
TDbGripDistDim *pDistDim = (TDbGripDistDim*)pDim;
XPoint pt;
wall.ProjectToMe(pEnt->GetLocation(), pt);
pDistDim->SetData(pt.AsAcGePoint3d(), pDim->GripPoint(), 800);
}
break;
default:
return Acad::eNotImplementedYet;
}
break;
default:
return Acad::eNotImplementedYet;
}
return Acad::eOk;
}
Acad::ErrorStatus TDbEquipmentBox::DimToEntity(long iGrip, long iDim, double newValue, const AcGeVector3d& offset)
{
assertWriteEnabled();
AcGePoint3d ptNew = GetGripPoint(iGrip) + offset;
XCurveSegment wall;
GetCenterCurve(wall);
XPoint vt = wall.EndPoint() - wall.StartPoint();
vt.Normalize();
switch(iGrip)
{
case 0: // 位置夹点
switch(iDim)
{
case 0: // 位置偏移
{
if (vt.AsAcGeVector3d().dotProduct(offset) > 0)
vt *= newValue;
else
vt *= -newValue;
m_ptLocation += vt;
}
break;
}
break;
}
return Acad::eOk;
}
#endif
Acad::ErrorStatus TDbEquipmentBox::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
TDbOpening::subTransformBy(xform);
return Acad::eOk;
}
Acad::ErrorStatus TDbEquipmentBox::GetInsert2DScale(double *pScaleX, double *pScaleY) const
{
assertReadEnabled();
double dScaleX = m_nWidth,
dScaleY = m_dBreadth;
if (m_nQuadrant == 1)
dScaleX = -dScaleX;
else if (m_nQuadrant == 2)
{
dScaleX = -dScaleX;
dScaleY = -dScaleY;
}
else if (m_nQuadrant == 3)
dScaleY = -dScaleY;
*pScaleX = dScaleX;
*pScaleY = dScaleY;
return Acad::eOk;
}
Acad::ErrorStatus TDbEquipmentBox::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
assertReadEnabled();
if (!IsValid() || !m_nIdStyle2d.isValid())
return Acad::eNotApplicable;
double nScaleX, nScaleY;
GetInsert2DScale(&nScaleX, &nScaleY); // 取墙的宽度作为门窗厚度
XPoint ptInsert = m_ptLocation;
if (GetBreakWall() && !!m_nIdOfWall) // 约定插入点在墙线的形心线上
{
double dWallWidth(0.0);
OPENOBJ_BEGIN(m_nIdOfWall, AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
dWallWidth = pWall->GetWidth(4);
dWallWidth *= 0.5;
}
OPENOBJ_END();
ads_polar(m_ptLocation, m_nRotation+PI/2, dWallWidth-m_nThickness+0.5*m_dBreadth, ptInsert);
}
ptInsert.z = 0.0;
BOOL bToTch3 = (_tcscmp(dc.Desc(), XExplodeStream::Descriptor())==0 &&
m_lstClipId.Length()==0 && dc.IsExportTch4() && m_nIdStyle2d.isValid());
if (bToTch3) // 导出T3
{
AcDbBlockReference *pInsert = new AcDbBlockReference(ptInsert, m_nIdStyle2d);
pInsert->setPropertiesFrom(this);
pInsert->setRotation(m_nRotation);
BOOL bReg = FALSE;
AcDbDatabase *pDb = database();
AcDbRegAppTable *pAppTab = NULL;
if (pDb)
pDb->getSymbolTable(pAppTab, AcDb::kForRead);
if (pAppTab)
{
bReg = pAppTab->has(_T("WTHICK"));
pAppTab->close();
}
double nWallWidth = GetWallThickness(TRUE);
if (pDb==acdbCurDwg() && bReg)
{
pInsert->setScaleFactors(AcGeScale3d(nScaleX, nScaleY, nScaleX));
resbuf *xdata = ads_buildlist(1001, _T("WTHICK"), 1040, m_dBreadth, NULL);
pInsert->setXData(xdata);
ads_relrb(xdata);
}
else
pInsert->setScaleFactors(AcGeScale3d(nScaleX, nScaleY, m_dBreadth));
((XExplodeStream &)dc).Append(pInsert, FALSE);
}
else // 显示图块
{
BOOL bMakeBlock = g_bMakeBlock;
if (_tcsicmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0)
{
if (dc.IsPlotGeneration()) // 强制打印时,不使用新方法
bMakeBlock = FALSE;
else
bMakeBlock = (g_nAcadVer>15.0001);
}
dc << XBlockRef(m_nIdStyle2d, ptInsert, AcGeScale3d(nScaleX, nScaleY, nScaleX), m_nRotation, bMakeBlock);
}
return Acad::eOk;
}
Acad::ErrorStatus TDbEquipmentBox::GetInsert3DScale(double *pScaleX, double *pScaleY, double *pScaleZ) const
{
assertReadEnabled();
double dScaleX, dScaleY, dScaleZ;
if (!(!m_nIdStyle3d)) // Use 3dStyle
{
XPoint origenalSize;
if (!GetOriginal3DSize(m_nIdStyle3d, origenalSize))
return Acad::eInvalidInput;
dScaleX = origenalSize.x>_DIST_SNAP ? (m_nWidth/origenalSize.x) : 1.0;
dScaleY = origenalSize.y>_DIST_SNAP ? (m_dBreadth/origenalSize.y) : 1.0;
dScaleZ = origenalSize.z>_DIST_SNAP ? (m_nHeight/origenalSize.z) : 1.0;
}
else // Use 2d Extrude
{
XDbObject objBlock(m_nIdStyle2d, AcDb::kForRead);
if(!objBlock)
return Acad::eInvalidInput;
AcDbBlockTableRecord *pBlock = AcDbBlockTableRecord::cast(objBlock.m_pObject);
dScaleY = m_dBreadth;
dScaleX = m_nWidth;
dScaleZ = 1.0;
}
// 镜像情况
if (m_nQuadrant == 1)
dScaleX = -dScaleX;
else if (m_nQuadrant == 2)
{
dScaleX = -dScaleX;
dScaleY = -dScaleY;
}
else if (m_nQuadrant == 3)
dScaleY = -dScaleY;
*pScaleX = dScaleX;
*pScaleY = dScaleY;
*pScaleZ = dScaleZ;
return Acad::eOk;
}
Acad::ErrorStatus TDbEquipmentBox::ExplodeOrDraw3d(XExplodeDraw &dc) const
{
assertReadEnabled();
if (!IsValid())
return Acad::eNotApplicable;
OPENOBJ_BEGIN(m_nIdOfWall, AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
if (!g_bIntWall3DVisible && !pWall->IsExternal(OFFSET_LEFT) && !pWall->IsExternal(OFFSET_RIGHT))
return Acad::eOk; // 关闭内墙显示
}
OPENOBJ_END();
double dScaleX, dScaleY, dScaleZ;
Acad::ErrorStatus es = Acad::eCannotExplodeEntity;
if (GetInsert3DScale(&dScaleX, &dScaleY, &dScaleZ) != Acad::eOk)
return es;
XPoint ptInsert = m_ptLocation;
if (!(!m_nIdStyle3d)) // 显示真三维
{
dc << XBlockRef(m_nIdStyle3d, ptInsert, AcGeScale3d(dScaleX, dScaleY, dScaleZ), m_nRotation, g_bMakeBlock);
}
else if(!!m_nIdStyle2d)
{
dc << XBlockRef(m_nIdStyle2d, ptInsert, AcGeScale3d(dScaleX, dScaleY, m_nHeight), m_nRotation, g_bMakeBlock);
}
return Acad::eOk;
}
const TCHAR* TDbEquipmentBox::GetKindString() const
{
return _T("设备箱");
}
void TDbEquipmentBox::MirrorSelf(BOOL bLeftRight)
{
assertWriteEnabled();
int nQua = m_nQuadrant;
switch(nQua)
{
case 0:
nQua = bLeftRight ? 1 : 3;
break;
case 1:
nQua = bLeftRight ? 0 : 2;
break;
case 2:
nQua = bLeftRight ? 3 : 1;
break;
case 3:
nQua = bLeftRight ? 2 : 0;
break;
}
m_nQuadrant = nQua;
}
// 设置设备箱的宽度
void TDbEquipmentBox::SetBreadth(double dBreadth)
{
assertWriteEnabled();
m_dBreadth = dBreadth;
}
double TDbEquipmentBox::GetBreadth() const
{
assertReadEnabled();
return m_dBreadth;
}
// 设置是否打断墙体
void TDbEquipmentBox::SetBreakWall(BOOL bBreak)
{
assertWriteEnabled();
SetLoneOpening(bBreak);
}
BOOL TDbEquipmentBox::GetBreakWall() const
{
assertReadEnabled();
return IsLoneOpening();
}
void InitDbEquipmentBox(BOOL bTrue)
{
if(bTrue)
{
TDbEquipmentBox::rxInit();
acrxBuildClassHierarchy();
TDbEquipmentBox::InitMatchProtocol(TRUE);
}
else
{
TDbEquipmentBox::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbEquipmentBox::desc());
}
}