Files
envi-code/SourceCode/Code2026/tg_shs/shs_pipebase/TDbHvacDimensionEx.cpp
T

1341 lines
29 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
#include "TDbHvacDimensionEx.h"
#include "dbproxy.h"
#include "TGripImp.h"
#include "dbtext.h"
#include "dbhatch.h"
#define VERSION_HVACDIMENSION 1
//{{AFX_ARX_MACRO
ACRX_DXF_DEFINE_MEMBERS( TDbHvacDimensionEx, TDbEntity,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kAllAllowedBits,
2026-10-04 00:04:20 +08:00
ATS_HVACDIMENSIONEX, "图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
2026-09-28 15:28:50 +08:00
//}}AFX_ARX_MACRO
IMPLEMENT_TENTBASE(TDbHvacDimensionEx);
TDbHvacDimensionEx::TDbHvacDimensionEx()
{
m_XDataMap.SetAt(KEY_DXF, _T("ATS_HVACDIMENSIONEX"));
SetArrowLen(350.0);
SetArrowStyle(1);
}
TDbHvacDimensionEx::~TDbHvacDimensionEx()
{
}
2026-10-04 00:04:20 +08:00
// 特性表用
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus TDbHvacDimensionEx::subGetClassID(CLSID* pClsid) const
{
assertReadEnabled();
return Acad::eOk;
}
Acad::ErrorStatus TDbHvacDimensionEx::dxfOutFields( AcDbDxfFiler* pFiler ) const
{
assertReadEnabled();
Acad::ErrorStatus es;
if ((es = TDbEntity::dxfOutFields(pFiler)) != Acad::eOk)
return es;
// Write subclass marker.
pFiler->writeItem(AcDb::kDxfSubclass, _T("TDbHvacDimensionEx"));
// Write version number.
pFiler->writeItem(AcDb::kDxfInt16, (Adesk::UInt16) VERSION_HVACDIMENSION);
return es;
}
Acad::ErrorStatus TDbHvacDimensionEx::dxfInFields( AcDbDxfFiler* pFiler )
{
assertWriteEnabled();
struct resbuf rb;
if ((TDbEntity::dxfInFields(pFiler) != Acad::eOk)
|| !pFiler->atSubclassData(_T("TDbHvacDimensionEx")))
{
return pFiler->filerStatus();
}
// Read version number.
pFiler->readItem(&rb);
if (rb.restype != AcDb::kDxfInt16)
{
pFiler->pushBackItem();
pFiler->setError(Acad::eInvalidDxfCode,
_T("Error: expected object version group code %d"),
AcDb::kDxfInt16);
return pFiler->filerStatus();
}
else
{
Adesk::UInt16 version = rb.resval.rint;
if (version > VERSION_HVACDIMENSION)
return Acad::eMakeMeProxy;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbHvacDimensionEx::dwgOutFields( AcDbDwgFiler* pFiler ) const
{
assertReadEnabled();
Acad::ErrorStatus es;
// Call dwgOutFields from TDbInterfacesObj
if ((es = TDbEntity::dwgOutFields(pFiler)) != Acad::eOk)
return es;
pFiler->writeItem((Adesk::UInt16) VERSION_HVACDIMENSION);
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbHvacDimensionEx::dwgInFields( AcDbDwgFiler* pFiler )
{
assertWriteEnabled();
Acad::ErrorStatus es;
// Call dwgInFields from TDbInterfacesObj
if ((es = TDbEntity::dwgInFields(pFiler)) != Acad::eOk)
return es;
// Read version number.
Adesk::UInt16 version;
pFiler->readItem(&version);
if (version > VERSION_HVACDIMENSION)
return Acad::eMakeMeProxy;
InitDuctXData();
return pFiler->filerStatus();
}
2026-10-04 00:04:20 +08:00
// 返回所有需要绘制的实体指针,用完负责删除
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::MakeEntity( AcDbVoidPtrArray &entityArr ) const
{
HvacDimType eType = GetType();
AcGePoint3d ptBase(GetBasePoint());
AcDbObjectId idStyle = GetTextStyle();
double dHeigh = GetTextHeigh();
double dAngle = GetTextAngle();
2026-10-04 00:04:20 +08:00
// 矫正角度
2026-09-28 15:28:50 +08:00
XVector3D vt(cos(dAngle), sin(dAngle), 0);
if (TAuxTools::GetUcsXvt().angleTo(vt) > PI * 0.5)
vt *= -1;
AcGeVector3d vtUcsY = TAuxTools::GetUcsYvt();
if (vtUcsY.isCodirectionalTo(-vt.AsAcGeVector3d()))
vt = vtUcsY;
dAngle = acutAngle(XPoint(), vt);
CStringArray arrText;
if(!GetEachStr(GetText(), arrText))
return;
AcDbObjectId idLayer = layerId();
2026-10-04 00:04:20 +08:00
if(eType == eDimLeadLine || eType == eDimLeadBound) // 带引线及中间割线/边框
2026-09-28 15:28:50 +08:00
{
TDbText* pText = NULL;
AcGeVoidPointerArray arTexts;
int i = 0;
for(i = 0; i < arrText.GetSize(); i++)
{
pText = CrteatText(arrText[i], idLayer, idStyle, dHeigh, ptBase, dAngle);
arTexts.append(pText);
}
AcGePoint3dArray arPts;
GetTextPoint(arTexts, arPts);
if(arPts.length() == arTexts.length())
{
for(i = 0; i < arTexts.length(); i++)
{
((TDbText*)arTexts[i])->SetLocation(arPts[i]);
entityArr.append(arTexts[i]);
}
GetKeyPoint(arTexts, arPts);
MakeLeadAndFrame(arPts, entityArr);
}
else
{
for(i = 0; i < arTexts.length(); i++)
{
delete (AcDbEntity*)arTexts[i];
}
}
}
else
{
CString csText;
for(int i = 0; i < arrText.GetSize(); i++)
{
csText += arrText[i];
}
TDbText* pText = CrteatText(csText, idLayer, idStyle, dHeigh, ptBase, dAngle);
entityArr.append(pText);
}
}
2026-10-04 00:04:20 +08:00
// 创建引线及边框
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::MakeLeadAndFrame( AcGePoint3dArray &ptArr, AcDbVoidPtrArray &entityArr ) const
{
if(6 > ptArr.length())
return;
AcDbObjectId idLayer = layerId();
int nLeadShow = GetLeadShow();
2026-10-04 00:04:20 +08:00
// 引线
2026-09-28 15:28:50 +08:00
if(0 != nLeadShow)
{
XPoint ptBase(GetBasePoint()), ptLead(GetLeadPoint());
AcDbLine* pLineLead = new AcDbLine(ptBase, ptLead);
pLineLead->setLayer(idLayer);
entityArr.append(pLineLead);
}
2026-10-04 00:04:20 +08:00
// 方向线
2026-09-28 15:28:50 +08:00
AcDbLine* pLineDirect = new AcDbLine(ptArr[2], ptArr[3]);
pLineDirect->setLayer(idLayer);
entityArr.append(pLineDirect);
2026-10-04 00:04:20 +08:00
// 边框
2026-09-28 15:28:50 +08:00
HvacDimType eType = GetType();
if (eType == eDimLeadBound)
{
CStringArray arrText;
if (!GetEachStr(GetText(), arrText))
return;
2026-10-04 00:04:20 +08:00
// 边框
2026-09-28 15:28:50 +08:00
AcDbPolyline* pPolyLine = new AcDbPolyline;
pPolyLine->addVertexAt(0, ptArr[0].convert2d(AcGePlane::kXYPlane));
pPolyLine->addVertexAt(1, ptArr[1].convert2d(AcGePlane::kXYPlane));
pPolyLine->addVertexAt(2, ptArr[5].convert2d(AcGePlane::kXYPlane));
pPolyLine->addVertexAt(3, ptArr[4].convert2d(AcGePlane::kXYPlane));
pPolyLine->setClosed(Adesk::kTrue);
pPolyLine->setLayer(idLayer);
entityArr.append(pPolyLine);
2026-10-04 00:04:20 +08:00
// 分割线
2026-09-28 15:28:50 +08:00
for(int i = 6; i < ptArr.length(); i += 2)
{
AcDbLine* pLineDivid = new AcDbLine(ptArr[i], ptArr[i + 1]);
pLineDivid->setLayer(idLayer);
entityArr.append(pLineDivid);
}
}
2026-10-04 00:04:20 +08:00
// 绘制箭头
2026-09-28 15:28:50 +08:00
if(0 != GetArrowStyle() && 0 != nLeadShow)
{
MakeArrow(entityArr);
}
}
2026-10-04 00:04:20 +08:00
// 创建标注原点箭头
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::MakeArrow( AcDbVoidPtrArray &entityArr ) const
{
int nArrowStyle = GetArrowStyle();
2026-10-04 00:04:20 +08:00
if(4 == nArrowStyle) // 半箭头
2026-09-28 15:28:50 +08:00
{
double dArrowLen = GetArrowLen() * GetPScale();
AcGePoint3d ptBase(GetBasePoint()), ptLead(GetLeadPoint());
AcGeVector3d vtNormal = TAuxTools::GetUcsZvt();
AcGeVector3d vtLead = (ptLead - ptBase).orthoProject(vtNormal).normalize();
AcGePoint3d ptSta = ptBase;
AcGePoint3d ptEnd = ptBase + dArrowLen * vtLead;
double dEndWidth = dArrowLen * tan(8.0 * PI / 180.0);
AcGeVector3d vtTemp = vtLead.rotateBy(PI * 0.5, TAuxTools::GetUcsZvt());
vtTemp.normalize();
AcGePoint3d ptBra = ptEnd + vtTemp * dEndWidth;
XPoly2D polyRect(1);
polyRect.AppendNode(ptSta);
polyRect.AppendNode(ptEnd);
polyRect.AppendNode(ptBra);
AcDbHatch* pHatch = NewHatchFromPoly2D(polyRect, _T("SOLID"), 1);
pHatch->setLayer(layerId());
entityArr.append(pHatch);
}
else
{
TDbHvacDimension::MakeArrow(entityArr);
}
}
2026-10-04 00:04:20 +08:00
// 特性表信息
2026-09-28 15:28:50 +08:00
BOOL TDbHvacDimensionEx::OPMInfo( LPCTSTR pszName, TDb::OPMInfo* pInfo )
{
if (isWriteEnabled())
assertWriteEnabled();
else
assertReadEnabled();
ASSERT(NULL != pszName && NULL != pInfo && NULL != m_pXDataMap);
HvacDimType eDimType = GetType();
if (0 == _tcsicmp(pszName, HDIM_DimType))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = TRUE;
2026-10-04 00:04:20 +08:00
// 提供数据列表和对应关系
2026-09-28 15:28:50 +08:00
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
{
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("无边框引出标注"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(TDb::eDimLeadLine);
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("有边框引出标注"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(TDb::eDimLeadBound);
}
2026-10-04 00:04:20 +08:00
// 设置数据
2026-09-28 15:28:50 +08:00
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
{
SetAt(pszName, *pInfo->pXData);
2026-10-04 00:04:20 +08:00
pInfo->pXData->nVt = 0; // 设置处理完成标识
2026-09-28 15:28:50 +08:00
SetTextAngle(0.0);
AcGeMatrix3d mat;
transformBy(mat);
}
return TRUE;
}
2026-10-04 00:04:20 +08:00
// 直接传id,64位下会导致截断情况,com里不容易改,改用下面记录样式字符名方式,设置时再转为AcDbObjectId。
// 重新启用这种调用方法,Lixl modify 2012-5-16
2026-09-28 15:28:50 +08:00
#if ADS <= 17
if (0 == _tcsicmp(pszName, HDIM_DimTextId))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = TRUE;
2026-10-04 00:04:20 +08:00
// 设置数据(必须手动设置,由于AcDbOjbectId::asOldId(),拷贝到前他图中不适用
2026-09-28 15:28:50 +08:00
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
{
AcDbObjectId idStyle;
idStyle.setFromOldId((*pInfo->pXData).nVal);
SetTextStyle(idStyle);
2026-10-04 00:04:20 +08:00
pInfo->pXData->nVt = 0; // 设置处理完成标识
2026-09-28 15:28:50 +08:00
}
else
{
2026-10-04 00:04:20 +08:00
// 提供数据列表和对应关系
2026-09-28 15:28:50 +08:00
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
{
CStringArray csArrStyle;
TAuxTools::GetAllTextStyleNameArray(csArrStyle);
int i(0);
for (i = 0; i < csArrStyle.GetSize(); i++)
{
pInfo->parsValues->Add(csArrStyle[i]);
pInfo->parlValues->Add((DWORD)GetTextStyleId(csArrStyle[i]).asOldId());
}
}
}
return TRUE;
}
#else
if (0 == _tcsicmp(pszName, HDIM_DimTextId))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = TRUE;
if (NULL != pInfo->pXData)
{
2026-10-04 00:04:20 +08:00
// 设置数据
2026-09-28 15:28:50 +08:00
if (0 != pInfo->pXData->nVt)
{
AcDbObjectId idStyle = InitTextStyle(pInfo->pXData->pszVal);
if (idStyle.isValid())
{
SetTextStyle(idStyle);
2026-10-04 00:04:20 +08:00
pInfo->pXData->nVt = 0; // 设置处理完成标识
2026-09-28 15:28:50 +08:00
}
}
2026-10-04 00:04:20 +08:00
else // 读数据,获取样式名
2026-09-28 15:28:50 +08:00
{
TCHAR* pTChar = TAuxTools::GetFontStyle(GetTextStyle());
if (NULL != pTChar)
{
pInfo->pXData->npszLen = 0;
pInfo->pXData->pszVal = NULL;
pInfo->pXData->pszVal = pTChar;
pInfo->pXData->npszLen = _tcslen(pTChar);
pInfo->pXData->nVt = TXSTR;
}
}
}
return TRUE;
}
#endif
if (0 == _tcsicmp(pszName, HDIM_DimTextHeigh))
{
pInfo->bVisible = TRUE;
pInfo->bEditable = TRUE;
2026-10-04 00:04:20 +08:00
// 文字高度变化后,需重定位
2026-09-28 15:28:50 +08:00
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
{
SetAt(pszName, *pInfo->pXData);
2026-10-04 00:04:20 +08:00
pInfo->pXData->nVt = 0; // 设置处理完成标识
2026-09-28 15:28:50 +08:00
}
return TRUE;
}
if (0 == _tcsicmp(pszName, HDIM_DimTextAngle))
{
pInfo->bVisible = (eDimType != eDimLeadLine && eDimType != eDimLeadBound);
pInfo->bEditable = pInfo->bVisible;
if (NULL != pInfo->pXData)
{
2026-10-04 00:04:20 +08:00
if (0 == pInfo->pXData->nVt) // 读数据
2026-09-28 15:28:50 +08:00
{
pInfo->pXData->dVal[0] = GetTextAngle() * 180.0 / PI;
pInfo->pXData->nVt = TXDBL;
}
else
{
2026-10-04 00:04:20 +08:00
// 设置数据
2026-09-28 15:28:50 +08:00
SetTextAngle(pInfo->pXData->dVal[0] * PI / 180.0);
2026-10-04 00:04:20 +08:00
pInfo->pXData->nVt = 0; // 设置处理完成标识
2026-09-28 15:28:50 +08:00
}
}
return TRUE;
}
if (0 == _tcsicmp(pszName, HDIM_DimArrowStyle))
{
pInfo->bVisible = (eDimType == eDimLeadLine || eDimType == eDimLeadBound);
pInfo->bEditable = pInfo->bVisible;
2026-10-04 00:04:20 +08:00
// 提供数据列表和对应关系
2026-09-28 15:28:50 +08:00
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
{
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("无箭头"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(0);
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("常规箭头"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(1);
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("十字"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(2);
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("圆点"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(3);
2026-10-04 00:04:20 +08:00
pInfo->parsValues->Add(_T("半箭头"));
2026-09-28 15:28:50 +08:00
pInfo->parlValues->Add(4);
}
return TRUE;
}
if (0 == _tcsicmp(pszName, HDIM_DimArrowLen))
{
pInfo->bVisible = (eDimType == eDimLeadLine || eDimType == eDimLeadBound);
pInfo->bEditable = pInfo->bVisible;
return TRUE;
}
return FALSE;
}
void TDbHvacDimensionEx::SetColumnCount(int nCount)
{
assertWriteEnabled();
m_XDataMap.SetAt(HDIM_DimColumn, nCount);
}
int TDbHvacDimensionEx::GetColumnCount() const
{
assertReadEnabled();
int nCount = 0;
m_XDataMap.GetAt(HDIM_DimColumn, nCount);
if(0 >= nCount)
2026-10-04 00:04:20 +08:00
nCount = 3; // 默认3列
2026-09-28 15:28:50 +08:00
return nCount;
}
void TDbHvacDimensionEx::SetUpGrid(const CUIntArray& arFlag)
{
assertWriteEnabled();
int nCol = GetColumnCount();
if(nCol == arFlag.GetSize())
{
CString sFlag, sTemp;
for(int i = 0; i < nCol; i++)
{
sTemp.Format(_T("%d,"), arFlag[i]);
sFlag += sTemp;
}
sFlag.TrimRight(_T(","));
m_XDataMap.SetAt(HDIM_UpGridFlag, sFlag);
}
}
void TDbHvacDimensionEx::GetUpGrid(CUIntArray& arFlag) const
{
assertReadEnabled();
CString sFlag;
m_XDataMap.GetAt(HDIM_UpGridFlag, sFlag);
if(!sFlag.IsEmpty())
{
arFlag.RemoveAll();
CStringArray arSubs;
TAuxTools::StrTokenize(sFlag, _T(","), arSubs);
for(INT_PTR i = 0; i < arSubs.GetSize(); i++)
{
arFlag.Add(_ttoi(arSubs[i]));
}
}
int nCol = GetColumnCount();
if(nCol != arFlag.GetSize())
{
arFlag.RemoveAll();
for(int i = 0; i < nCol; i++)
arFlag.Add(1);
}
}
void TDbHvacDimensionEx::SetDownGrid(const CUIntArray& arFlag)
{
assertWriteEnabled();
int nCol = GetColumnCount();
if(nCol == arFlag.GetSize())
{
CString sFlag, sTemp;
for(int i = 0; i < nCol; i++)
{
sTemp.Format(_T("%d,"), arFlag[i]);
sFlag += sTemp;
}
sFlag.TrimRight(_T(","));
m_XDataMap.SetAt(HDIM_DownGridFlag, sFlag);
}
}
void TDbHvacDimensionEx::GetDownGrid(CUIntArray& arFlag) const
{
assertReadEnabled();
CString sFlag;
m_XDataMap.GetAt(HDIM_DownGridFlag, sFlag);
if(!sFlag.IsEmpty())
{
arFlag.RemoveAll();
CStringArray arSubs;
TAuxTools::StrTokenize(sFlag, _T(","), arSubs);
for(INT_PTR i = 0; i < arSubs.GetSize(); i++)
{
arFlag.Add(_ttoi(arSubs[i]));
}
}
int nCol = GetColumnCount();
if(nCol != arFlag.GetSize())
{
arFlag.RemoveAll();
for(int i = 0; i < nCol; i++)
arFlag.Add(1);
}
}
void TDbHvacDimensionEx::SetLeadShow(int nShow)
{
assertWriteEnabled();
m_XDataMap.SetAt(HDIM_DimLeadShow, nShow);
}
int TDbHvacDimensionEx::GetLeadShow() const
{
assertReadEnabled();
int nShow = 0;
if(!m_XDataMap.GetAt(HDIM_DimLeadShow, nShow))
return 1;
return nShow;
}
void TDbHvacDimensionEx::SetGridMask(LPCTSTR pszMask)
{
assertWriteEnabled();
m_XDataMap.SetAt(HDIM_DimMask, pszMask);
}
CString TDbHvacDimensionEx::GetGridMask() const
{
assertReadEnabled();
CString sMask;
m_XDataMap.GetAt(HDIM_DimMask, sMask);
return sMask;
}
2026-10-04 00:04:20 +08:00
// 转换各部分字符串 SetText()传递的字符应符合 A|B|C|D 规则
2026-09-28 15:28:50 +08:00
BOOL TDbHvacDimensionEx::TransTextToResult()
{
assertReadEnabled();
CStringArray arrResult;
if (!GetEachStr(GetFormatStr(), arrResult))
return FALSE;
CString sDimString;
for(int i = 0; i < arrResult.GetSize(); i++)
{
if(!arrResult[i].IsEmpty())
{
TranslateDimText(arrResult[i]);
}
sDimString += arrResult[i] + _T("|");
}
sDimString.TrimRight(_T("|"));
m_XDataMap.SetAt(HDIM_DimString, sDimString);
return TRUE;
}
BOOL TDbHvacDimensionEx::GetEachStr( const CString &csText, CStringArray &arrText ) const
{
assertReadEnabled();
if(csText.IsEmpty())
return FALSE;
arrText.RemoveAll();
CStringArray arSubs;
TAuxTools::StrTokenize(csText, _T("|"), arrText);
return TRUE;
}
2026-10-04 00:04:20 +08:00
// 转换格式字符为实际标注内容,按头文件“标注字符格式化字符说明”把实际变量值替换原宏标识
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::TranslateDimText(CString &csText) const
{
HvacSectType eSect = eRectangular;
if (NULL != m_pDuctXDataMap)
m_pDuctXDataMap->GetAt(HVAC_SectType, (int&)eSect);
int nFind = csText.Find(DV_SIZE, 0);
if(-1 != nFind)
{
int nLen = _tcslen(DV_SIZE);
2026-10-04 00:04:20 +08:00
// 侧风口标注样式
2026-09-28 15:28:50 +08:00
int nSidetype = _ttoi(csText.Mid(nFind + nLen, 1));
2026-10-04 00:04:20 +08:00
// 圆风口标注前缀
2026-09-28 15:28:50 +08:00
int nPrefix = _ttoi(csText.Mid(nFind + nLen + 1, 1));
csText.Delete(nFind + nLen, 2);
2026-10-04 00:04:20 +08:00
if(eSect == eCircular) // 圆形
2026-09-28 15:28:50 +08:00
{
if(0 == nPrefix)
csText.Insert(nFind, _T("%%C"));
else
csText.Insert(nFind, _T("D"));
ChangeTextIdByValue(csText, DV_SIZE);
}
2026-10-04 00:04:20 +08:00
else // 方形
2026-09-28 15:28:50 +08:00
{
csText.Delete(nFind, nLen);
2026-10-04 00:04:20 +08:00
// 侧风口
2026-09-28 15:28:50 +08:00
if(IsSideEquip())
{
if(0 == nSidetype)
2026-10-04 00:04:20 +08:00
csText.Insert(nFind, _T("DV_LENGTH×DV_WIDTH")); // 长*宽
2026-09-28 15:28:50 +08:00
else
2026-10-04 00:04:20 +08:00
csText.Insert(nFind, _T("DV_WIDTH×DV_HEIGH")); // 宽*高
2026-09-28 15:28:50 +08:00
}
else
{
2026-10-04 00:04:20 +08:00
csText.Insert(nFind, _T("DV_LENGTH×DV_WIDTH"));
2026-09-28 15:28:50 +08:00
}
ChangeTextIdByValue(csText, DV_LENGTH);
ChangeTextIdByValue(csText, DV_WIDTH);
ChangeTextIdByValue(csText, DV_HEIGH);
}
}
if(-1 != csText.Find(DV_AIRVOL))
ChangeTextIdByValue(csText, DV_AIRVOL);
if(-1 != csText.Find(DV_NAME))
ChangeTextIdByValue(csText, DV_NAME);
}
2026-10-04 00:04:20 +08:00
// 根据变量名具体替换每个相应变量宏字符
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::ChangeTextIdByValue( CString &csText, const CString &csTextid ) const
{
2026-10-04 00:04:20 +08:00
double dValue(0.0); // 变量实际值
2026-09-28 15:28:50 +08:00
CString csValue;
2026-10-04 00:04:20 +08:00
if(csTextid == DV_NAME) // 名称
2026-09-28 15:28:50 +08:00
{
csValue = GetEquipName();
}
else
{
2026-10-04 00:04:20 +08:00
if(csTextid == DV_SIZE) // 尺寸
2026-09-28 15:28:50 +08:00
dValue = GetEquipDiameter();
2026-10-04 00:04:20 +08:00
else if(csTextid == DV_LENGTH) // 长度
2026-09-28 15:28:50 +08:00
dValue = GetEquipLength();
2026-10-04 00:04:20 +08:00
else if(csTextid == DV_WIDTH) // 宽度
2026-09-28 15:28:50 +08:00
dValue = GetEquipWidth();
2026-10-04 00:04:20 +08:00
else if(csTextid == DV_HEIGH) // 高度
2026-09-28 15:28:50 +08:00
dValue = GetEquipHeight();
2026-10-04 00:04:20 +08:00
else if(csTextid == DV_AIRVOL) // 风量
2026-09-28 15:28:50 +08:00
dValue = GetEquipAirVol();
csValue.Format(_T("%.f"), dValue);
}
csText.Replace(csTextid, csValue);
}
2026-10-04 00:04:20 +08:00
// 初始化标注风口的XData数据
2026-09-28 15:28:50 +08:00
BOOL TDbHvacDimensionEx::InitDuctXData()
{
BOOL bOK(FALSE);
m_pDuctXDataMap = NULL;
2026-10-04 00:04:20 +08:00
const AcDbVoidPtrArray* pArrVoidPt = reactors(); // 反应器数组
2026-09-28 15:28:50 +08:00
if (NULL == pArrVoidPt || pArrVoidPt->length() < 1)
return FALSE;
2026-10-04 00:04:20 +08:00
void* pReactSome = NULL; // 反应器指针
AcDbObjectId objId(AcDbObjectId::kNull); // 反应器对应实体id3.
2026-09-28 15:28:50 +08:00
int i(0);
for (i = 0; i < pArrVoidPt->length(); i++)
{
pReactSome = pArrVoidPt->at(i);
if (acdbIsPersistentReactor(pReactSome))
{
objId = acdbPersistentReactorObjectId(pReactSome);
OPENOBJ_BEGIN(objId, AcDb::kForRead, TDbHvacEquipment, pEquip);
if (pEquip != NULL)
{
m_pDuctXDataMap = pEquip->GetSpecialtyData();
bOK = TRUE;
pEquip->close();
break;
}
OPENOBJ_END();
}
}
return bOK;
}
int TDbHvacDimensionEx::GetFirstVersion() const
{
return 10;
}
2026-10-04 00:04:20 +08:00
// 设置编辑文字
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::SetSubText( long i, CString sText )
{
if (sText.IsEmpty())
return;
CStringArray csArr;
GetEachStr(GetText(), csArr);
if (i > csArr.GetSize() - 1)
return;
csArr.SetAt(i, sText);
CString csResult;
INT_PTR n(0), nSize = csArr.GetSize();
for (n = 0; n < nSize; n++)
{
csResult += csArr[n];
if (n < nSize - 1)
csResult += _T("|");
}
SetText(csResult);
}
2026-10-04 00:04:20 +08:00
// 按 nIndex 索引获取标注文字基点
2026-09-28 15:28:50 +08:00
AcGePoint3d TDbHvacDimensionEx::GetTextBasePt(Adesk::UInt32 nIndex) const
{
HvacDimType eType = GetType();
AcGePoint3d ptBase(GetBasePoint());
AcDbObjectId idStyle = GetTextStyle();
double dHeigh = GetTextHeigh();
double dAngle = GetTextAngle();
2026-10-04 00:04:20 +08:00
// 矫正角度
2026-09-28 15:28:50 +08:00
XVector3D vt(cos(dAngle), sin(dAngle), 0);
if (TAuxTools::GetUcsXvt().angleTo(vt) > PI * 0.5)
vt *= -1;
AcGeVector3d vtUcsY = TAuxTools::GetUcsYvt();
if (vtUcsY.isCodirectionalTo(-vt.AsAcGeVector3d()))
vt = vtUcsY;
dAngle = acutAngle(XPoint(), vt);
CStringArray arrText;
if(!GetEachStr(GetText(), arrText))
return ptBase;
AcDbObjectId idLayer = layerId();
2026-10-04 00:04:20 +08:00
if(eType == eDimLeadLine || eType == eDimLeadBound) // 带引线及中间割线/边框
2026-09-28 15:28:50 +08:00
{
TDbText* pText = NULL;
AcGeVoidPointerArray arTexts;
int i = 0;
for(i = 0; i < arrText.GetSize(); i++)
{
pText = CrteatText(arrText[i], idLayer, idStyle, dHeigh, ptBase, dAngle);
arTexts.append(pText);
}
AcGePoint3dArray arPts;
GetTextPoint(arTexts, arPts);
if(arPts.length() == arTexts.length())
{
if(0 <= nIndex && arPts.length() > nIndex)
{
ptBase = arPts[nIndex];
}
}
for(i = 0; i < arTexts.length(); i++)
{
delete arTexts[i];
}
}
return ptBase;
}
2026-10-04 00:04:20 +08:00
// 获取标注各关键点
2026-09-28 15:28:50 +08:00
/*
2026-10-04 00:04:20 +08:00
0━━━━━━━━━6━━━━━━1
┃ Lable1 ┃ Lable2 ┃
2━━━━8━━━━7 10━━━━━3
┃ Lable3 ┃ Lable4 ┃ Lable5 ┃
4━━━━9━━━━━11━━━━━5
2026-09-28 15:28:50 +08:00
*/
void TDbHvacDimensionEx::GetKeyPoint(const AcGeVoidPointerArray& arrTexts,
AcGePoint3dArray &arrPoint) const
{
arrPoint.setLogicalLength(0);
XPoint ptLead = GetLeadPoint();
CDblArray arUpLen, arDnLen;
double dTextLen = GetTextsLen(arrTexts, arUpLen, arDnLen);
double dScale = GetPScale();
double dTextHeigh = GetTextHeigh();
double dGapLen = DocGetText2BaseRatio() * dTextHeigh * dScale * 2;
double dRowHeigh = dTextHeigh * dScale + dGapLen;
double dAngle = GetTextAngle();
AcGePoint3d ptBase(GetBasePoint());
AcGeVector3d vtDirect = ptLead - ptBase;
XPoint ptMidS = ptLead;
if(vtDirect.angleTo(TAuxTools::GetUcsXvt()) > PI * 0.5)
{
dAngle += PI;
acutPolar(ptLead, dAngle, -dTextLen, ptMidS);
}
double dAnglePer = dAngle + PI * 0.5;
XPoint ptUpS, ptDnS, ptUpE, ptDnE, ptMidE;
acutPolar(ptMidS, dAnglePer, dRowHeigh, ptUpS);
acutPolar(ptMidS, dAnglePer, -dRowHeigh, ptDnS);
acutPolar(ptUpS, dAngle, dTextLen, ptUpE);
acutPolar(ptDnS, dAngle, dTextLen, ptDnE);
acutPolar(ptMidS, dAngle, dTextLen, ptMidE);
2026-10-04 00:04:20 +08:00
// 边框及方向点
2026-09-28 15:28:50 +08:00
arrPoint.append(ptUpS);
arrPoint.append(ptUpE);
arrPoint.append(ptMidS);
arrPoint.append(ptMidE);
arrPoint.append(ptDnS);
arrPoint.append(ptDnE);
2026-10-04 00:04:20 +08:00
// 分割点
2026-09-28 15:28:50 +08:00
int i = 0;
XPoint ptTop, ptBtm;
XPoint ptTopT, ptBtmT;
for(i = 0; i < arUpLen.GetSize() - 1; i++)
{
if(0 == i)
{
ptTopT = ptUpS;
ptBtmT = ptMidS;
}
else
{
ptTopT = ptTop;
ptBtmT = ptBtm;
}
acutPolar(ptTopT, dAngle, arUpLen[i], ptTop);
acutPolar(ptBtmT, dAngle, arUpLen[i], ptBtm);
arrPoint.append(ptTop);
arrPoint.append(ptBtm);
}
for(i = 0; i < arDnLen.GetSize() - 1; i++)
{
if(0 == i)
{
ptTopT = ptMidS;
ptBtmT = ptDnS;
}
else
{
ptTopT = ptTop;
ptBtmT = ptBtm;
}
acutPolar(ptTopT, dAngle, arDnLen[i], ptTop);
acutPolar(ptBtmT, dAngle, arDnLen[i], ptBtm);
arrPoint.append(ptTop);
arrPoint.append(ptBtm);
}
}
2026-10-04 00:04:20 +08:00
// 计算文字基点
2026-09-28 15:28:50 +08:00
void TDbHvacDimensionEx::GetTextPoint(const AcGeVoidPointerArray& arrTexts,
AcGePoint3dArray &arrPoint) const
{
arrPoint.setLogicalLength(0);
XPoint ptLead = GetLeadPoint();
CDblArray arUpLen, arDnLen;
double dTextLen = GetTextsLen(arrTexts, arUpLen, arDnLen);
double dScale = GetPScale();
double dTextHeigh = GetTextHeigh();
double dGapLen = DocGetText2BaseRatio() * dTextHeigh * dScale * 2;
double dRowHeigh = dTextHeigh * dScale + dGapLen;
double dAngle = GetTextAngle();
AcGePoint3d ptBase(GetBasePoint());
AcGeVector3d vtDirect = ptLead - ptBase;
XPoint ptMidS = ptLead;
if(vtDirect.angleTo(TAuxTools::GetUcsXvt()) > PI * 0.5)
{
dAngle += PI;
acutPolar(ptLead, dAngle, -dTextLen, ptMidS);
}
double dAnglePer = dAngle + PI * 0.5;
XPoint ptUpS, ptDnS;
acutPolar(ptMidS, dAnglePer, dRowHeigh, ptUpS);
acutPolar(ptMidS, dAnglePer, -dRowHeigh, ptDnS);
int i = 0;
XPoint ptLT, ptRB;
for(i = 0; i < arUpLen.GetSize(); i++)
{
if(0 == i)
{
ptLT = ptUpS;
acutPolar(ptMidS, dAngle, arUpLen[i], ptRB);
}
else
{
acutPolar(ptLT, dAngle, arUpLen[i - 1], ptLT);
acutPolar(ptRB, dAngle, arUpLen[i], ptRB);
}
arrPoint.append(TAuxTools::Mid(ptLT, ptRB));
}
for(i = 0; i < arDnLen.GetSize(); i++)
{
if(0 == i)
{
ptLT = ptMidS;
acutPolar(ptDnS, dAngle, arDnLen[i], ptRB);
}
else
{
acutPolar(ptLT, dAngle, arDnLen[i - 1], ptLT);
acutPolar(ptRB, dAngle, arDnLen[i], ptRB);
}
arrPoint.append(TAuxTools::Mid(ptLT, ptRB));
}
}
2026-10-04 00:04:20 +08:00
// 取得有效的表格标记
2026-09-28 15:28:50 +08:00
int TDbHvacDimensionEx::GetValidGridFlag(CUIntArray& arUp, CUIntArray& arDown) const
{
2026-10-04 00:04:20 +08:00
// 取得上下列数据标志位
2026-09-28 15:28:50 +08:00
GetUpGrid(arUp);
GetDownGrid(arDown);
int nCol = GetColumnCount();
if(nCol != arUp.GetSize()
|| nCol != arDown.GetSize())
{
return 0;
}
int i = 0, j = 0;
2026-10-04 00:04:20 +08:00
// 将有效标志位调整到首位
2026-09-28 15:28:50 +08:00
CUIntArray* pAr[] = {&arUp, &arDown};
for(j = 0; j < 2; j++)
{
if(0 != (*pAr[j])[0])
continue;
int nF = -1;
for(i = 0; i < nCol; i++)
{
if(0 == (*pAr[j])[i])
{
if(-1 == nF)
nF = i;
}
else if(-1 != nF)
{
(*pAr[j])[nF] = (*pAr[j])[i];
(*pAr[j])[i] = 0;
nF = -1;
}
}
}
2026-10-04 00:04:20 +08:00
// 移除上下同为0的标记
2026-09-28 15:28:50 +08:00
for(i = nCol - 1; i >= 0; i--)
{
if(arUp[i] == arDown[i] && 0 == arUp[i])
{
arUp.RemoveAt(i);
arDown.RemoveAt(i);
nCol--;
}
else
{
2026-10-04 00:04:20 +08:00
// 确保有效标志位 为1
2026-09-28 15:28:50 +08:00
if(0 != arUp[i])
arUp.SetAt(i, 1);
if(0 != arDown[i])
arDown.SetAt(i, 1);
}
}
2026-10-04 00:04:20 +08:00
// 移除无效的标记位
2026-09-28 15:28:50 +08:00
int nUp = 0, nDn = 0, nF = -1;
for(i = 0; i < nCol; i++)
{
if(arUp[i] == arDown[i] || i == nCol - 1)
{
if(-1 == nF || nF == i - 1)
nF = i;
else if(nF != i - 1)
{
int nEnd = i == nCol - 1 ? i + 1 : i;
for(int j = nF; j < nEnd; j++)
{
if(0 != arUp[j])
nUp++;
if(0 != arDown[j])
nDn++;
}
if(nUp == nDn)
{
for(int k = nEnd - 1; k >= nF; k--)
{
if(0 == arUp[k])
arUp.RemoveAt(k);
if(0 == arDown[k])
arDown.RemoveAt(k);
}
nCol -= (nEnd - nF - nUp);
i += nUp;
}
nF = -1;
}
}
}
return nCol;
}
2026-10-04 00:04:20 +08:00
// 计算文字长度
2026-09-28 15:28:50 +08:00
double TDbHvacDimensionEx::GetTextsLen(const AcGeVoidPointerArray& arrTexts,
CDblArray& arUpLen, CDblArray&arDnLen) const
{
2026-10-04 00:04:20 +08:00
// 取得表格标记
2026-09-28 15:28:50 +08:00
CUIntArray arUpFlag, arDnFlag;
int nCol = GetValidGridFlag(arUpFlag, arDnFlag);
if(0 == nCol)
return 0;
2026-10-04 00:04:20 +08:00
// 统计有效单元格数量
2026-09-28 15:28:50 +08:00
int i = 0;
int nUpCol = 0, nDnCol = 0;
for(i = 0; i < arUpFlag.GetSize(); i++)
{
if(0 != arUpFlag[i])
nUpCol++;
}
for(i = 0; i < arDnFlag.GetSize(); i++)
{
if(0 != arDnFlag[i])
nDnCol++;
}
2026-10-04 00:04:20 +08:00
// 计算文字长度
2026-09-28 15:28:50 +08:00
if(arrTexts.length() != nUpCol + nDnCol)
return 0;
double dUpLenTemp = 0, dDnLenTemp = 0, dLenTemp = 0, dMaxLen = 0;
TDbText* pText = NULL;
int nUpIdx = 0;
int nDnIdx = nUpCol;
for(i = 0; i < nCol; i++)
{
if(arUpFlag[i] == arDnFlag[i])
{
pText = (TDbText*)arrTexts[nUpIdx];
dUpLenTemp = GetTextLen(pText);
if(EQUAL_ZERO(dUpLenTemp) && 0 != _tcslen(pText->GetText()))
{
dUpLenTemp = 0.1;
}
arUpLen.Add(dUpLenTemp);
pText = (TDbText*)arrTexts[nDnIdx];
dDnLenTemp = GetTextLen(pText);
if(EQUAL_ZERO(dDnLenTemp) && 0 != _tcslen(pText->GetText()))
{
dDnLenTemp = 0.1;
}
arDnLen.Add(dDnLenTemp);
nUpIdx++;
nDnIdx++;
}
else
{
if(0 != arUpFlag[i])
{
pText = (TDbText*)arrTexts[nUpIdx];
dLenTemp = GetTextLen(pText);
if(EQUAL_ZERO(dLenTemp) && 0 != _tcslen(pText->GetText()))
{
dLenTemp = 0.1;
}
arUpLen.Add(dLenTemp);
arDnLen.Add(0);
nUpIdx++;
}
else
{
pText = (TDbText*)arrTexts[nDnIdx];
dLenTemp = GetTextLen(pText);
if(EQUAL_ZERO(dLenTemp) && 0 != _tcslen(pText->GetText()))
{
dLenTemp = 0.1;
}
arDnLen.Add(dLenTemp);
arUpLen.Add(0);
nDnIdx++;
}
}
}
double dScale = GetPScale();
double dTextHeigh = GetTextHeigh();
double dGapLen = DocGetText2BaseRatio() * dTextHeigh * dScale * 2;
2026-10-04 00:04:20 +08:00
// 合并单元格
2026-09-28 15:28:50 +08:00
if(nUpCol == nDnCol)
{
for(i = 0; i < nCol; i++)
{
if(arUpLen[i] < arDnLen[i])
arUpLen[i] = arDnLen[i];
else
arDnLen[i] = arUpLen[i];
arUpLen[i] += dGapLen;
arDnLen[i] += dGapLen;
}
}
else
{
int nF = -1;
double dUpSum = 0, dDnSum = 0, dSum = 0;
double nUp = 0, nDn = 0;
2026-10-04 00:04:20 +08:00
// 为避免单独处理最后一个元素太麻烦,增加一列,之后再删除
2026-09-28 15:28:50 +08:00
arUpLen.Add(1.0);
arDnLen.Add(1.0);
for(i = 0; i < nCol + 1; i++)
{
if(!EQUAL_ZERO(arUpLen[i]) && !EQUAL_ZERO(arDnLen[i]))
{
if(-1 == nF)
nF = i;
else
{
for(int j = nF; j < i; j++)
{
dUpSum += arUpLen[j];
dDnSum += arDnLen[j];
}
dSum = dUpSum < dDnSum ? dDnSum : dUpSum;
for(int k = nF; k < i; k++)
{
arUpLen[k] = arUpLen[k] / dUpSum * dSum;
arDnLen[k] = arDnLen[k] / dDnSum * dSum;
}
dUpSum = dDnSum = 0;
nF = i;
}
}
}
arUpLen.RemoveAt(arUpLen.GetSize() - 1);
arDnLen.RemoveAt(arDnLen.GetSize() - 1);
dUpSum = dDnSum = 0;
for(i = nCol - 1; i >= 0; i--)
{
dUpSum += dGapLen;
dDnSum += dGapLen;
if(EQUAL_ZERO(arUpLen[i]))
arUpLen.RemoveAt(i);
else
{
arUpLen[i] += dUpSum;
dUpSum = 0;
}
if(EQUAL_ZERO(arDnLen[i]))
arDnLen.RemoveAt(i);
else
{
arDnLen[i] += dDnSum;
dDnSum = 0;
}
}
}
2026-10-04 00:04:20 +08:00
// 统计总长度
2026-09-28 15:28:50 +08:00
double dTextLen = 0;
for(i = 0; i < arUpLen.GetSize(); i++)
dTextLen += arUpLen[i];
return dTextLen;
}
2026-10-04 00:04:20 +08:00
// 取得圆形设备的直径
2026-09-28 15:28:50 +08:00
double TDbHvacDimensionEx::GetEquipDiameter() const
{
if(NULL == m_pDuctXDataMap)
return 0.0;
double dValue = 0;
m_pDuctXDataMap->GetAt(HEQU_Width, dValue);
return dValue;
}
2026-10-04 00:04:20 +08:00
// 取得长度
2026-09-28 15:28:50 +08:00
double TDbHvacDimensionEx::GetEquipLength() const
{
if(NULL == m_pDuctXDataMap)
return 0.0;
double dValue = 0;
m_pDuctXDataMap->GetAt(HEQU_Length, dValue);
return dValue;
}
2026-10-04 00:04:20 +08:00
// 取得宽度
2026-09-28 15:28:50 +08:00
double TDbHvacDimensionEx::GetEquipWidth() const
{
if(NULL == m_pDuctXDataMap)
return 0.0;
double dValue = 0;
m_pDuctXDataMap->GetAt(HEQU_Width, dValue);
return dValue;
}
2026-10-04 00:04:20 +08:00
// 取得高度
2026-09-28 15:28:50 +08:00
double TDbHvacDimensionEx::GetEquipHeight() const
{
if(NULL == m_pDuctXDataMap)
return 0.0;
double dValue = 0;
m_pDuctXDataMap->GetAt(HEQU_Thick, dValue);
return dValue;
}
2026-10-04 00:04:20 +08:00
// 取得设备风量
2026-09-28 15:28:50 +08:00
double TDbHvacDimensionEx::GetEquipAirVol() const
{
return GetDuctAirVol();
}
2026-10-04 00:04:20 +08:00
// 取得名称
2026-09-28 15:28:50 +08:00
CString TDbHvacDimensionEx::GetEquipName() const
{
if(NULL == m_pDuctXDataMap)
return _T("");
CString sName;
m_pDuctXDataMap->GetAt(HEQU_SEquipName, sName);
return sName;
}
2026-10-04 00:04:20 +08:00
// 是否侧风口
2026-09-28 15:28:50 +08:00
BOOL TDbHvacDimensionEx::IsSideEquip() const
{
if(NULL == m_pDuctXDataMap)
return FALSE;
int nSide = 0;
m_pDuctXDataMap->GetAt(HALT_IsSide, nSide);
return nSide;
}