Files
envi-code/SourceCode/Code2026/tg_shs/shs_pipewire/DbIDDot.cpp
T
2026-09-28 15:28:50 +08:00

614 lines
15 KiB
C++

// DbIDDot.cpp: implementation of the TDbIDDot class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DbIDDot.h"
#include "actrans.h"
#include "dbtext.h"
#include "dbSymbolAnnotate.h"
#define TEXT_HEIGHT 3.0
#define DOT_SIZE 2.0 * 100
ACRX_DXF_DEFINE_MEMBERS(ATSIDDot, ATSEntity,AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, ATS_IDDOT,
"ATS_IDDOT图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbIDDot);
const Adesk::UInt8 TDbIDDot::g_nVersion = 1;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TDbIDDot::TDbIDDot()
{
m_dbDotSize = DOT_SIZE;
m_szDotName = _T("");
m_nLabelDirection = dTop;
m_bDrawLabel = FALSE;
m_IdLabelStyle = InitTextStyle(_T("Standard"));
}
TDbIDDot::~TDbIDDot()
{
}
void TDbIDDot::SetDbIDEntity(AcDbHandle IDHandle)
{
m_IDHandle = IDHandle;
}
TDbIDEntity* TDbIDDot::GetIDEntity()const
{
TDbIDEntity* pIDEnt = NULL;
AcDbObjectId Id;
acdbCurDwg()->getAcDbObjectId(Id,false,m_IDHandle);
AcDbEntity *pEnt = NULL;
acdbOpenAcDbEntity(pEnt,Id,AcDb::kForRead);
if(pEnt!= NULL)
{ pIDEnt = (TDbIDEntity*)pEnt;
pIDEnt->close();
}
return pIDEnt;
}
void TDbIDDot::CopyPropertiesFrom(AcDbEntity *pSrc,unsigned gMatchFlag)
{
assertWriteEnabled();
TDbEntity::CopyPropertiesFrom(pSrc, gMatchFlag);
TDbIDDot *pDot = TDbIDDot::cast(pSrc);
if(pDot != NULL)
{
m_DotPt = pDot->m_DotPt;
m_LabelPt = pDot->GetLabelPoint();
m_nLabelDirection = pDot->m_nLabelDirection;
m_bDrawLabel = pDot->m_bDrawLabel;
}
}
Acad::ErrorStatus TDbIDDot::subGetClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
void TDbIDDot::GetTips(DList<TObjInfoUnit> &info) const
{
TDbEntity::GetTips(info);
CString sz;
info.Append(new TObjInfoUnit(_T("对象类型"), _T("空气状态点")));
info.Append(new TObjInfoUnit(_T("名 称"), m_szDotName));
CAirState As;
TDbIDEntity *pEnt = GetIDEntity();
if (pEnt == NULL)
return;
As = pEnt->GetDot(m_DotPt);
sz.Format(_T("%0.1f℃"),As.GetD());
info.Append(new TObjInfoUnit(_T("干球温度"),sz));
sz.Format(_T("%0.1f℃"),As.GetW());
info.Append(new TObjInfoUnit(_T("湿球温度"),sz));
sz.Format(_T("%0.1f%%"),As.GetRH() * 100);
info.Append(new TObjInfoUnit(_T("相对湿度"),sz));
sz.Format(_T("%0.1fg/kg"),As.GetHR());
info.Append(new TObjInfoUnit(_T("含 湿 量"),sz));
sz.Format(_T("%0.1fkJ/kg"),As.GetE());
info.Append(new TObjInfoUnit(_T(" 焓 "),sz));
}
Acad::ErrorStatus TDbIDDot::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
if (player.openStatus() == Acad::eOk && player->isOff())
{
return Acad::eOk;
}
Acad::ErrorStatus es = Acad::eOk;
XAcGiViewDraw &viewDraw = (XAcGiViewDraw &)dc;
AcDbPolyline Line;
XPoint pt1,pt2;
pt1.x = m_DotPt.x - m_dbDotSize * 0.25;
pt1.y = m_DotPt.y;
pt2.x = m_DotPt.x + m_dbDotSize * 0.25;
pt2.y = m_DotPt.y;
Line.addVertexAt(0,pt1);
Line.addVertexAt(1,pt2);
Line.addVertexAt(3,pt1);
Line.setConstantWidth(m_dbDotSize * 0.5);
Line.setBulgeAt(0,-1);
Line.setBulgeAt(1,-1);
Line.setClosed(TRUE);
dc.Polyline(Line);
DrawText(dc,m_DotPt,m_nLabelDirection,m_szDotName);
//绘制引出标注内容
if(!m_bDrawLabel)
return es;
DrawLabelText(dc);
return es;
}
void TDbIDDot::DrawText(XExplodeDraw& dc,XPoint pt,int nDirection,XString szName)const
{
XPoint ptText;
switch(nDirection)
{
case dUnDraw:
break;
case dTopLeft:
{
ads_polar(pt,PI * 0.75,m_dbDotSize,ptText); //
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kMiddleRight);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dTopRight:
{
ads_polar(pt,PI * 0.25,m_dbDotSize,ptText);//
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kMiddleLeft);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dBottomLeft:
{
ads_polar(pt,PI * 1.25,m_dbDotSize,ptText);
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kTopRight);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dBottomRight:
{
ads_polar(pt,-PI * 0.25,m_dbDotSize,ptText);
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kTopLeft);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dLeft:
{
ads_polar(pt,PI,m_dbDotSize,ptText);
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kMiddleRight);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dRight:
{
ads_polar(pt,0,m_dbDotSize,ptText);
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kMiddleLeft);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dTop:
{
ads_polar(pt,PI * 0.5,m_dbDotSize * 2.0,ptText);//
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kMiddleCenter);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
case dBottom:
{
ads_polar(pt,-PI*0.5,m_dbDotSize,ptText);
TDbText text1;
text1.setPropertiesFrom(this);
text1.SetStyleId(m_IdLabelStyle);
text1.SetLocation(ptText);
text1.SetRotation(0);
text1.SetText(szName);
text1.SetAlignment(XExplodeDraw::kTopCenter);
text1.SetHeight(TEXT_HEIGHT);
dc.DrawEntity(text1);
}
break;
default:
break;
}
}
void TDbIDDot::subList() const
{
assertReadEnabled();
AcDbEntity::subList();
CString str;
CString sz;
CAirState As;
TDbIDEntity *pEnt = GetIDEntity();
if(pEnt == NULL)
return;
As = pEnt->GetDot(m_DotPt);
sz.Format(_T("\n干球温度:%0.1f℃"),As.GetD());
str += sz;
sz.Format(_T("\n湿球温度:%0.1f℃"),As.GetW());
str += sz;
sz.Format(_T("\n相对湿度:%0.1f%%"),As.GetRH() * 100);
str += sz;
sz.Format(_T("\n含 湿 量:%0.1fg/kg"),As.GetHR());
str += sz;
sz.Format(_T("\n 焓 :%0.1fkJ/kg"),As.GetE());
str += sz;
acutPrintf(str);
}
Acad::ErrorStatus TDbIDDot::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
m_DotPt.TransformBy(xform);
m_LabelPt.TransformBy(xform);
return Acad::eOk;
}
//-----------------------------------------------------------------------------
Acad::ErrorStatus TDbIDDot::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
gripPoints.append(m_DotPt);
if(m_bDrawLabel)
gripPoints.append(m_LabelPt);
return Acad::eOk;
}
Acad::ErrorStatus TDbIDDot::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& pickPoint,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
TDbEntity::subGetOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,snapPoints,geomIds);
snapPoints.setLogicalLength(0);
snapPoints.append(m_DotPt);
return Acad::eOk;
}
Acad::ErrorStatus TDbIDDot::subMoveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertReadEnabled();
recordGraphicsModified();
return Acad::eOk;
}
//-----------------------------------------------------------------------------
Acad::ErrorStatus TDbIDDot::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertReadEnabled();
for(int i=0; i<indices.length();i++)
{
int nIndex=indices[i];
switch(nIndex)
{
case 0:
m_DotPt = m_DotPt + offset;
break;
case 1:
m_LabelPt = m_LabelPt + offset;
break;
default:
break;
}
}
recordGraphicsModified();
return Acad::eOk;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Acad::ErrorStatus TDbIDDot::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es;
if ((es = AcDbEntity::dwgInFields(pFiler)) != Acad::eOk)
{
return es;
}
Adesk::UInt16 version;
pFiler->readItem(&version);
if (version > g_nVersion) // Version is too new
{
return Acad::eMakeMeProxy;
}
pFiler->readItem((AcGePoint3d *)&m_DotPt);
pFiler->readItem(&m_IDHandle);
pFiler->readItem((AcGePoint3d *)&m_LabelPt);
//pFiler->readItem(&m_bDrawLabel);
FilerRead(pFiler, m_bDrawLabel);
ReadString(pFiler,m_szDotName);
pFiler->readItem(&m_nLabelDirection);
pFiler->readItem(&m_IdLabelStyle);
switch (version)
{
case (1):
break;
}
return pFiler->filerStatus();
}
//-----------------------------------------------------------------------------
Acad::ErrorStatus TDbIDDot::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es;
// Call dwgOutFields from AcDbEntity
if ((es = AcDbEntity::dwgOutFields(pFiler)) != Acad::eOk)
{
return es;
}
// Write version number.
pFiler->writeItem((Adesk::UInt16) g_nVersion);
pFiler->writeItem((const AcGePoint3d &)m_DotPt);
pFiler->writeItem(m_IDHandle);
pFiler->writeItem((const AcGePoint3d &)m_LabelPt);
//pFiler->writeItem(m_bDrawLabel);
FilerWrite(pFiler, m_bDrawLabel);
pFiler->writeItem((const TCHAR *)m_szDotName);
pFiler->writeItem(m_nLabelDirection);
if(m_IdLabelStyle.isValid())
pFiler->writeItem(m_IdLabelStyle);
else
{
AcDbHardPointerId Id = InitTextStyle(_T("Standard"));
pFiler->writeItem(Id);
}
return pFiler->filerStatus();
}
// 取得夹点说明
Acad::ErrorStatus TDbIDDot::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
switch(idx)
{
case 0:
{
CString str;
CString sz;
CAirState As;
TDbIDEntity *pEnt = GetIDEntity();
if(pEnt == NULL)
return es;
As = pEnt->GetDot(m_DotPt);
sz.Format(_T("干球:%0.1f℃"),As.GetD());
str += sz;
sz.Format(_T(" | 湿球:%0.1f℃"),As.GetW());
str += sz;
sz.Format(_T(" | 相对湿度:%0.1f%%"),As.GetRH() * 100);
str += sz;
sz.Format(_T(" | 含湿量:%0.1fg/kg"),As.GetHR());
str += sz;
sz.Format(_T(" | 焓:%0.1fkJ/kg"),As.GetE());
str += sz;
cs=str;
}
break;
case 1:
{
cs = _T("移动标注位置");
}
break;
default:
break;
}
return es;
}
void TDbIDDot::SetDotPt(AcGePoint3d pt)
{
m_DotPt = pt;
recordGraphicsModified();
}
void TDbIDDot::SetDot(CAirState As)
{
TDbIDEntity *pEnt = GetIDEntity();
if(pEnt == NULL)
return;
AcGePoint3d pt = pEnt->GetPoint(As);
if(pEnt->IsRightAirStateDot(pt))
SetDotPt(pt);
else
{
AfxMessageBox(_T("状态点超出范围!"));
}
}
void TDbIDDot::SetLabelPoint(XPoint pt)
{
m_LabelPt = pt;
recordGraphicsModified();
}
void TDbIDDot::DrawLabelText(XExplodeDraw& dc)const
{
if(GetIDEntity() == NULL)
return;
CAirState As = GetDot();
if(!IsRightAirStateDot())
{
return;
}
CString str;
CString sz;
sz.Format(_T("\n状态点: %s"),m_szDotName);
str += sz;
sz.Format(_T("\n干球温度:%0.1f℃"),As.GetD());
str += sz;
sz.Format(_T("\n湿球温度:%0.1f℃"),As.GetW());
str += sz;
sz.Format(_T("\n相对湿度:%0.1f%%"),As.GetRH() * 100);
str += sz;
sz.Format(_T("\n含湿量:%0.1fg/kg"),As.GetHR());
str += sz;
sz.Format(_T("\n焓:%0.1fkJ/kg"),As.GetE());
str += sz;
sz.Format(_T("\n露点温度:%0.1f℃"),As.GetDew());
str += sz;
// sz.Format(_T("\n密度:%0.1fkg/m^U3^U\n"),As.GetDensity());
sz.Format(_T("\n密度:%0.3fkg/m^U3^U\n"),As.GetDensity());
str += sz;
TDbSymbComposing ent;
ent.setLayer(LAY_DIM);
ent.SetStartPoint(m_DotPt);
ent.SetTurnPoint(m_LabelPt);
ent.SetText(str);
ent.SetSideText(1);
ent.SetTextStyleId(m_IdLabelStyle);
ent.SetTextHeight(TEXT_HEIGHT);
ent.SetTextBaseLen(0.5);
dc.DrawEntity(ent);
}
void TDbIDDot::GetIdNewHandle()const
{
acDocManager->lockDocument(acDocManager->curDocument());
AcDbObjectIdArray IDEntIdAr;
GetIDEntAr(IDEntIdAr);
if (IDEntIdAr.length() <=1)
{
acDocManager->unlockDocument(acDocManager->curDocument());
return;
}
for (int i=0;i<IDEntIdAr.length();i++)
{
AcDbObjectId IDId = IDEntIdAr.at(i);
OPENOBJ_BEGIN(IDId, AcDb::kForWrite, TDbIDEntity, pEnt);
if (pEnt == NULL)
{
acDocManager->unlockDocument(acDocManager->curDocument());
return ;
}
AcDbHandle handle;
pEnt->getAcDbHandle(handle);
XPoint pt = m_DotPt;
BOOL bFlag = FALSE;
AcGePoint3dArray ptAr;
pEnt->GetMarginPoints(ptAr);
if (pt.x > ptAr[0].x && pt.y < ptAr[1].y)
bFlag = TRUE;
if (bFlag)
{
acDocManager->unlockDocument(acDocManager->curDocument());
return;
}
OPENOBJ_END();
}
acDocManager->unlockDocument(acDocManager->curDocument());
}
void TDbIDDot::GetIDEntAr(AcDbObjectIdArray & IdAr)const
{
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForRead);
pBlockTable->close();
AcDbBlockTableRecordIterator *pBlockIterator;
pBlockTableRecord->newIterator(pBlockIterator);
for (; !pBlockIterator->done();pBlockIterator->step())
{
AcDbEntity *pEntity;
pBlockIterator->getEntity(pEntity, AcDb::kForRead);
if(pEntity->isKindOf(TDbIDEntity::desc()))
IdAr.append(pEntity->objectId());
pEntity->close();
}
delete pBlockIterator;
pBlockTableRecord->close();
}
void InitDbIDDot(BOOL bTrue)
{
if (bTrue) {
TDbIDDot::rxInit();
TDbIDDot::InitMatchProtocol(TRUE);
}
else {
TDbIDDot::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbIDDot::desc());
}
}
CAirState TDbIDDot::GetDot() const
{
CAirState As;
TDbIDEntity *pID = NULL;
pID = GetIDEntity();
if(pID == NULL)
return As;
As = pID->GetDot(m_DotPt);
return As;
}