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

471 lines
11 KiB
C++

#include "stdafx.h"
#include "StdArx.h"
#include "AecDbFloorTreeView.h"
#include "KTSetting.h"
#include "acgitransient.h"
#ifdef EARTHWORM_EXPORT
#define DLLIMPEXP __declspec(dllexport)
#else
#define DLLIMPEXP __declspec(dllimport)
#endif
double DLLIMPEXP PixelToWcs(int nPixel);
const LPCTSTR g_sBuiding = _T("构筑物");
const LPCTSTR g_sTextStyle = _T("Standard");
Adesk::UInt32 AecDbFloorTreeView::kCurrentVersionNumber = 1;
ACRX_DXF_DEFINE_MEMBERS (AecDbFloorTreeView, AecDbEntityBase,
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning,
AEC_FLOORTREEVIEW,
"AecDbFloorTreeView"
"|Product Desc: shanghua earthworm app obj"
"|Company: shanghua inc"
"|WEB Address: www.shanghuasoft.com")
AecDbFloorTreeView::AecDbFloorTreeView(void)
{
m_nFlag = 100;
m_sDbVerGUID = _T("");
}
AecDbFloorTreeView::~AecDbFloorTreeView(void)
{
}
void AecDbFloorTreeView::SetDbVersionGUID(LPCTSTR pszID)
{
assertWriteEnabled();
if (pszID != NULL)
m_sDbVerGUID = pszID;
}
LPCTSTR AecDbFloorTreeView::GetDbVersionGUID() const
{
assertReadEnabled();
return (LPCTSTR)m_sDbVerGUID;
}
Acad::ErrorStatus AecDbFloorTreeView::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
//----- Read parent class information first.
Acad::ErrorStatus es = AecDbEntityBase::dwgInFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be read first
Adesk::UInt32 version =0 ;
if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )
return (es) ;
if ( version > AecDbFloorTreeView::kCurrentVersionNumber )
return (Acad::eMakeMeProxy) ;
pFiler->readUInt32(&m_nFlag);
TCHAR* pszStr = NULL;
es = pFiler->readString(&pszStr);
if (pszStr != NULL)
{
m_sDbVerGUID = pszStr;
}
return (pFiler->filerStatus ()) ;
}
Acad::ErrorStatus AecDbFloorTreeView::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled () ;
//----- Save parent class information first.
Acad::ErrorStatus es = AecDbEntityBase::dwgOutFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be saved first
if ( (es =pFiler->writeUInt32 (AecDbFloorTreeView::kCurrentVersionNumber)) != Acad::eOk )
return (es) ;
pFiler->writeUInt32(m_nFlag);
pFiler->writeString((LPCTSTR)m_sDbVerGUID);
return (pFiler->filerStatus ()) ;
}
Acad::ErrorStatus AecDbFloorTreeView::Draw2d(AcGiDraw &dc) const
{
assertReadEnabled();
Clean2DBuffer();
double dRad = PixelToWcs(10);
AcGePoint3d ptCen(0,0,0);
CPoint pt(0,0);
acedDwgPoint ptWcs;
acedCoordFromPixelToWorld(pt,ptWcs);
ptCen = asPnt3d(ptWcs);
AcDbObjectId idSt = KTSetting::InitTextStyle(_T("Pipe_Dim"));
AcDbText* pText = new AcDbText;
pText->setTextStyle(idSt);
pText->setTextString(g_sBuiding);//数据
pText->setHeight(dRad);
pText->setWidthFactor(0.7);
pText->setRotation(0.0);
pText->setHorizontalMode(AcDb::kTextLeft);
pText->setPosition( ptCen);
pText->setLayer(acdbCurDwg()->clayer());
pText->setColorIndex(1);
dc.DrawEntity(pText);
Add2DBuffer(pText);
ShowFloorChild(dc,pText);
return Acad::eOk;
}
Acad::ErrorStatus AecDbFloorTreeView::DrawNodeStatus(AcGiDraw &dc,const AcGePoint3d& ptPos,bool bExpand) const
{
assertReadEnabled();
double dCmd = PixelToWcs(4);
AcGePoint3d ptGe[5];
ptGe[0] = ptPos;
ptGe[0] -= AcGeVector3d::kXAxis * 0.8 * dCmd;
ptGe[0] -= AcGeVector3d::kYAxis * 0.8 * dCmd;
ptGe[1] = ptGe[0];
ptGe[1] += AcGeVector3d::kXAxis * dCmd;
ptGe[2] = ptGe[1];
ptGe[2] += AcGeVector3d::kYAxis * dCmd;
ptGe[3] = ptGe[0] + AcGeVector3d::kYAxis * dCmd;
ptGe[4] = ptGe[0];
AcDbPolyline* pL = new AcDbPolyline;
for (int i = 0;i < 5;i++)
{
pL->addVertexAt(i,ptGe[i].convert2d(AcGePlane::kXYPlane));
}
pL->setColorIndex(1);
dc.DrawEntity(pL);
Add2DBuffer(pL);
return Acad::eOk;
}
Acad::ErrorStatus AecDbFloorTreeView::ShowFloorChild(AcGiDraw &dc,AcDbText* pParent) const
{
assertReadEnabled();
if (pParent == NULL)
return Acad::eOk;
AcDbDatabase *pDb = acdbCurDwg();
if (pDb != NULL)
{
int nFloor = -1;
AcDbIntArray arFloors;
Acad::ErrorStatus es;
AcDbBlockTable* pTable = NULL;
if ( Acad::eOk == (es = pDb->getBlockTable(pTable,AcDb::kForRead) ) )
{
AcDbBlockTableRecord* pRecord = NULL;
if (Acad::eOk == (es = pTable->getAt(ACDB_MODEL_SPACE,pRecord,AcDb::kForRead)))
{
AcDbEntity* pEnt = NULL;
AcDbBlockTableRecordIterator* pIt = NULL;
pRecord->newIterator(pIt);
if (pIt != NULL)
{
for (pIt->start();!pIt->done();pIt->step())
{
if ( Acad::eOk == (es = pIt->getEntity(pEnt,AcDb::kForRead) ) )
{
//墙,梁,板,柱子
AecDbXWall* pWall = AecDbXWall::cast(pEnt);
if (pWall != NULL)
{
nFloor = -1;
if ( pWall->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_FLOOR,nFloor) )
{
if (arFloors.find(nFloor) == -1)
{
arFloors.append(nFloor);
}
}
}
AecDbColumn* pCol = AecDbColumn::cast(pEnt);
if (pCol != NULL)
{
nFloor = -1;
if ( pCol->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_FLOOR,nFloor) )
{
if (arFloors.find(nFloor) == -1)
{
arFloors.append(nFloor);
}
}
}
AecDbBeam* pBeam = AecDbBeam::cast(pEnt);
if (pBeam != NULL)
{
nFloor = -1;
if ( pBeam->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_FLOOR,nFloor) )
{
if (arFloors.find(nFloor) == -1)
{
arFloors.append(nFloor);
}
}
}
/*AecDbXSlab* pSlab = AecDbXSlab::cast(pEnt);
if (pSlab != NULL)
{
nFloor = -1;
if ( pSlab->GetSpecialtyData()->GetAt(KEY_FLOOR,nFloor) )
{
if (arFloors.find(nFloor) == -1)
{
arFloors.append(nFloor);
}
}
}*/
AecDbXSlab* pBasin = AecDbXSlab::cast(pEnt);
if (pBasin != NULL)
{
nFloor = -1;
if ( pBasin->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_FLOOR,nFloor) )
{
if (arFloors.find(nFloor) == -1)
{
arFloors.append(nFloor);
}
}
}
pEnt->close();
}
}
delete pIt;
}
pRecord->close();
}
pTable->close();
}
AcGePoint3d ptPos = pParent->position();//
double dH = pParent->height();
dH *= 1.5;
AcGePoint3d ptLnTop = ptPos;
ptLnTop.x -= 0.2 * dH;
DrawNodeStatus(dc,ptLnTop,true);
AcGePoint3d ptText = ptPos;
ptText.x += dH;
ptText.y -= dH;
AcGePoint3d ptLnV = ptLnTop;
CString sText;
for (int i = 0;i < arFloors.length();i++)
{
nFloor = arFloors.at(i);
sText.Format(_T("第 %d 层"),i + 1);
AcDbText* pText = new AcDbText;
pText->setTextStyle(pParent->textStyle());
pText->setTextString(sText);//数据
pText->setHeight(pParent->height());
pText->setWidthFactor(0.7);
pText->setRotation(0.0);
pText->setHorizontalMode(AcDb::kTextLeft);
pText->setPosition( ptText);
pText->setLayer(acdbCurDwg()->clayer());
pText->setColorIndex(1);
dc.DrawEntity(pText);
Add2DBuffer(pText);
ptLnV.y = ptText.y;//竖线
DrawNodeStatus(dc,ptLnV,true);
AcDbLine* pLine = new AcDbLine;
pLine->setStartPoint(ptLnV);
pLine->setEndPoint(ptText);
dc.DrawEntity(pLine);
Add2DBuffer(pLine);
ptText.y -= dH;
}
if (!arFloors.isEmpty())
{
AcDbLine* pLine = new AcDbLine;
pLine->setStartPoint(ptLnTop);
pLine->setEndPoint(ptLnV);
dc.DrawEntity(pLine);
Add2DBuffer(pLine);
}
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbFloorTreeView::ShowChildItems(AcGiDraw &dc,AcDbText* pParent) const
{
return Acad::eOk;
}
Acad::ErrorStatus AecDbFloorTreeView::subGetGripPoints (AcGePoint3dArray& gripPoints,AcDbIntArray& osnapModes,AcDbIntArray& geomIds) const
{
return Acad::eOk;
}
Acad::ErrorStatus AecDbFloorTreeView::subMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset)
{
return Acad::eOk;
}
extern AcArray<AcDbEntity*> g_arFloorViewPtrs;
extern AcArray<int> g_viewportNumbers;
void ClearFloorTreeView()
{
AcGiTransientManager* pTransientManager = acgiGetTransientManager();
int numOfMarkers = g_arFloorViewPtrs.length();
if (numOfMarkers > 0)
{
for(int index = 0; index < numOfMarkers; index++)
{
AcDbEntity *pMarker = g_arFloorViewPtrs.at(index);
pTransientManager->eraseTransient(pMarker,g_viewportNumbers);
delete pMarker;
}
g_arFloorViewPtrs.removeAll();
}
}
bool FloorTreeViewIsExist()
{
AcDbDatabase *pDb = acdbCurDwg();
if (pDb != NULL)
{
TCHAR* pszGUID = NULL;
pDb->getVersionGuid(pszGUID);
if (pszGUID == NULL)
return false;
for(int index = 0; index < g_viewportNumbers.length(); index++)
{
AcDbEntity *pMarker = g_arFloorViewPtrs.at(index);
AecDbFloorTreeView* pFloorView = AecDbFloorTreeView::cast(pMarker);
if (pFloorView != NULL)
{
CString sID = pFloorView->GetDbVersionGUID();
if (sID.CompareNoCase(pszGUID) == 0)
{
acutDelString(pszGUID);
return true;
}
}
}
acutDelString(pszGUID);
}
return false;
}
void AddEntToTransient(AcDbEntity* pEntTo)
{
AcDbDatabase *pDb = acdbCurDwg();
if (pDb != NULL)
{
AcGiTransientManager* pTransientManager = acgiGetTransientManager();
AcDbTransactionManager* pTM = pDb->transactionManager();
if (pTM != NULL)
{
AcTransaction *pTransaction = pTM->startTransaction();
struct resbuf res;
acedGetVar(L"CVPORT", &res);
if (g_viewportNumbers.find(res.resval.rint) == -1)
g_viewportNumbers.append(res.resval.rint);
if (pTransientManager != NULL)
{
g_arFloorViewPtrs.append(pEntTo);
TCHAR* pszID = NULL;
pDb->getVersionGuid(pszID);
if ( pTransientManager->addTransient(pEntTo,kAcGiDirectShortTerm,0,g_viewportNumbers) )
{
acutPrintf(_T("\naddTransient success 2!"));
}
}
pTM->endTransaction();
pTM->queueForGraphicsFlush();
}
}
}
void ShowFloorTreeView()
{
AcDbDatabase *pDb = acdbCurDwg();
if (pDb != NULL)
{
AcGiTransientManager* pTransientManager = acgiGetTransientManager();
AcDbTransactionManager* pTM = pDb->transactionManager();
if (pTM != NULL)
{
if (FloorTreeViewIsExist())
{
pTM->queueForGraphicsFlush();
return;
}
AcTransaction *pTransaction = pTM->startTransaction();
struct resbuf res;
acedGetVar(L"CVPORT", &res);
if (g_viewportNumbers.find(res.resval.rint) == -1)
g_viewportNumbers.append(res.resval.rint);
if (pTransientManager != NULL)
{
AecDbFloorTreeView* pFloorView = new AecDbFloorTreeView;
g_arFloorViewPtrs.append(pFloorView);
TCHAR* pszID = NULL;
pDb->getVersionGuid(pszID);
CString sID = pszID;
pFloorView->SetDbVersionGUID(sID);
if ( pTransientManager->addTransient(pFloorView,kAcGiDirectShortTerm,0,g_viewportNumbers) )
{
acutPrintf(_T("\naddTransient success 2!"));
}
}
pTM->endTransaction();
pTM->queueForGraphicsFlush();
}
}
}