340 lines
8.8 KiB
C++
340 lines
8.8 KiB
C++
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "ThunderDbReactor.h"
|
|
#include "ThunderXData.h"
|
|
#include "LightningRodData.h"
|
|
#include "ThunderCmdGroup.h"
|
|
#include "dbxutil.h"
|
|
#include "FoldPinRelation.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
|
|
CThunderDbReactor::CThunderDbReactor()
|
|
{
|
|
|
|
}
|
|
|
|
CThunderDbReactor::~CThunderDbReactor()
|
|
{
|
|
|
|
}
|
|
|
|
void CThunderDbReactor::objectAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj)
|
|
{
|
|
if (dbObj != NULL && dwg != NULL)
|
|
{
|
|
// 支持复制粘贴命令
|
|
if (CThunderCmdGroup::bIsAllowDraw)
|
|
{
|
|
CString sNO;
|
|
CThunderXData thundXData;
|
|
thundXData.GetXData((AcDbEntity*)dbObj,TEL_GROUP_NO,sNO);
|
|
if (!sNO.IsEmpty())
|
|
{
|
|
AcDbObjectId idOwner = dbObj->ownerId();
|
|
if (!idOwner.isValid()) return;
|
|
|
|
AcDbObjectId idCurRcd;
|
|
AcDbBlockTable* pTable = NULL;
|
|
((AcDbDatabase*)dwg)->getBlockTable(pTable, AcDb::kForRead);
|
|
if (pTable != NULL)
|
|
{
|
|
pTable->getAt(ACDB_MODEL_SPACE,idCurRcd);
|
|
pTable->close();
|
|
}
|
|
|
|
if (!idCurRcd.isValid()) return;
|
|
if (idOwner != idCurRcd) return;
|
|
|
|
if (dbObj->isKindOf(AcDbBlockReference::desc()))
|
|
{
|
|
ThunderContainer->AppendThunder(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDbCircle::desc()))
|
|
{
|
|
ThunderContainer->AppendCircle(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDbRegion::desc()))
|
|
{
|
|
ThunderContainer->AppendRegion(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDb3dSolid::desc()))
|
|
{
|
|
ThunderContainer->Append3DSolid(sNO, dbObj->objectId());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 支持避雷线
|
|
thundXData.GetXData((AcDbEntity*)dbObj,KEY_LINE_GROUP_NO,sNO);
|
|
if (!sNO.IsEmpty())
|
|
{
|
|
AcDbObjectId idOwner = dbObj->ownerId();
|
|
if (!idOwner.isValid()) return;
|
|
|
|
AcDbObjectId idCurRcd;
|
|
AcDbBlockTable* pTable = NULL;
|
|
((AcDbDatabase*)dwg)->getBlockTable(pTable, AcDb::kForRead);
|
|
if (pTable != NULL)
|
|
{
|
|
pTable->getAt(ACDB_MODEL_SPACE,idCurRcd);
|
|
pTable->close();
|
|
}
|
|
|
|
if (!idCurRcd.isValid()) return;
|
|
if (idOwner != idCurRcd) return;
|
|
|
|
if (dbObj->isKindOf(AcDbPolyline::desc()))
|
|
{
|
|
ThunderContainer->AppendThunderLine(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDbRegion::desc()))
|
|
{
|
|
ThunderContainer->AppendLineRegion(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDb3dSolid::desc()))
|
|
{
|
|
ThunderContainer->AppendLine3DSolid(sNO, dbObj->objectId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CThunderDbReactor::objectModified(const AcDbDatabase* dwg, const AcDbObject* dbObj)
|
|
{
|
|
if (dbObj != NULL && dwg != NULL)
|
|
{
|
|
CThunderXData thundXData;
|
|
|
|
if (dbObj->isErased())
|
|
{
|
|
return;
|
|
}
|
|
if (dbObj->isUndoing())
|
|
{
|
|
//恢复修改
|
|
CString sGroup;
|
|
thundXData.GetXData((AcDbEntity*)dbObj,KEY_FOLD_GROUP_NO,sGroup);
|
|
if (!sGroup.IsEmpty())
|
|
{
|
|
//折线法避雷针
|
|
if (dbObj->isKindOf(AcDbBlockReference::desc()))
|
|
{
|
|
XFoldThunder thunder;
|
|
FoldManager->ReadDataFromID((AcDbEntity*)dbObj,thunder);
|
|
FoldManager->UpdateFoldPinInMap(_ttoi(sGroup),thunder);
|
|
}
|
|
}
|
|
}
|
|
if (!dbObj->isUndoing() && CThunderCmdGroup::bIsAllowDraw )
|
|
{
|
|
CString sNO,sType;
|
|
|
|
thundXData.GetXData((AcDbEntity*)dbObj,TEL_GROUP_NO,sNO);
|
|
if (!sNO.IsEmpty())
|
|
{
|
|
//滚球法
|
|
if (dbObj->isKindOf(AcDbCircle::desc()) ||
|
|
dbObj->isKindOf(AcDbRegion::desc()) ||
|
|
dbObj->isKindOf(AcDbBlockReference::desc()) )
|
|
{
|
|
AcDbObjectId id = dbObj->objectId();
|
|
AcGeDoubleArray arProHeight;
|
|
thundXData.GetProtectHeightFromObjEx((AcDbEntity*)dbObj, arProHeight);
|
|
ThunderContainer->AppendProHeight(sNO, arProHeight);
|
|
CThunderCmdGroup::bExecute = TRUE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
thundXData.GetXData((AcDbEntity*)dbObj,KEY_LINE_GROUP_NO,sNO);
|
|
if (!sNO.IsEmpty())
|
|
{
|
|
// if (dbObj->isKindOf(AcDbPolyline::desc()) ||
|
|
// dbObj->isKindOf(AcDbRegion::desc()) )
|
|
if (dbObj->isKindOf(AcDbPolyline::desc()))
|
|
{
|
|
AcDbObjectId id = dbObj->objectId();
|
|
AcGeDoubleArray arProHeight;
|
|
thundXData.GetProtectHeightFromObjEx((AcDbEntity*)dbObj, arProHeight);
|
|
ThunderContainer->AppendLineProHeight(sNO, arProHeight);
|
|
CThunderCmdGroup::bExecute = TRUE;
|
|
}
|
|
|
|
if (dbObj->isKindOf(AcDbPolyline::desc()))
|
|
{
|
|
CThunderCmdGroup::bReDraw = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CThunderDbReactor::objectUnAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj)
|
|
{
|
|
if (dwg != NULL && dbObj != NULL)// 恢复
|
|
{
|
|
AcDbBlockReference* pRef = AcDbBlockReference::cast(dbObj);
|
|
if (pRef != NULL)
|
|
{
|
|
CString sLayer = pRef->layer();
|
|
if (sLayer.CompareNoCase(LAY_EL_THUNDER) == 0)
|
|
{
|
|
ThunderContainer->RemoveThunderNoGNo(dbObj->objectId());
|
|
FoldManager->DelFoldPinFromMap(dbObj->objectId());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AcDbPolyline* pLine = AcDbPolyline::cast(dbObj);
|
|
if (pLine != NULL)
|
|
{
|
|
CString sLayer = pLine->layer();
|
|
if (sLayer.CompareNoCase(LAY_EL_THUNDER) == 0)
|
|
{
|
|
ThunderContainer->RemoveThunderLine(dbObj->objectId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 当实体从当前DWG中删除时的处理
|
|
void CThunderDbReactor::objectErased(const AcDbDatabase* dwg, const AcDbObject* dbObj, Adesk::Boolean pErased)
|
|
{
|
|
if (dbObj != NULL && dwg != NULL)
|
|
{
|
|
CString sNO = _T(""),sType = _T(""),sFoldNO = _T("");
|
|
CThunderXData thundXData;
|
|
thundXData.GetXData((AcDbEntity*)dbObj,KEY_FOLD_GROUP_NO,sFoldNO);
|
|
if (!sFoldNO.IsEmpty())
|
|
{
|
|
//折线避雷针
|
|
thundXData.GetXData((AcDbEntity*)dbObj,TEL_THUNDER_TYPE,sType);
|
|
if (sType.CompareNoCase(_T("1")) == 0)
|
|
{
|
|
//折线避雷针
|
|
if (pErased)
|
|
{
|
|
//删除数据映射
|
|
FoldManager->DelFoldPinFromMap(sFoldNO,((AcDbEntity*)dbObj)->objectId());
|
|
if (CThunderCmdGroup::bReDrawFold)
|
|
{
|
|
//重绘
|
|
FoldManager->ShowUnionPro2d(sFoldNO);
|
|
}
|
|
}
|
|
else if(dbObj->isUndoing())
|
|
{
|
|
//恢复
|
|
XFoldThunder thunder;
|
|
FoldManager->ReadDataFromID((AcDbEntity*)dbObj,thunder);
|
|
FoldManager->AddFoldPinToMap(thunder);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
thundXData.GetXData((AcDbEntity*)dbObj,TEL_GROUP_NO,sNO);
|
|
if (!sNO.IsEmpty())
|
|
{
|
|
//滚球避雷针
|
|
if (pErased && CThunderCmdGroup::bIsAllowDraw && !dbObj->isUndoing())
|
|
{
|
|
CString sTemp;
|
|
AcGeDoubleArray arProHeight;
|
|
thundXData.GetProtectHeightFromObjEx((AcDbEntity*)dbObj, arProHeight);
|
|
ThunderContainer->AppendProHeight(sNO, arProHeight);
|
|
if (dbObj->isKindOf(AcDbBlockReference::desc()))
|
|
{
|
|
ThunderContainer->RemoveThunder(sNO,dbObj->objectId());
|
|
CThunderCmdGroup::bExecute = TRUE;
|
|
}
|
|
else if (dbObj->isKindOf(AcDbCircle::desc()) ||
|
|
dbObj->isKindOf(AcDbRegion::desc()))
|
|
{
|
|
thundXData.GetXData((AcDbEntity*)dbObj,TEL_CURRENT_PROHEIGHT,sTemp);
|
|
ThunderContainer->AppendRemoveProHeight(sNO, _tstof(sTemp));
|
|
CThunderCmdGroup::bExecute = TRUE;
|
|
}
|
|
}
|
|
else if (!pErased && dbObj->isUndoing())// 恢复
|
|
{
|
|
if (dbObj->isKindOf(AcDbBlockReference::desc()))
|
|
{
|
|
ThunderContainer->AppendThunder(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDbCircle::desc()))
|
|
{
|
|
ThunderContainer->AppendCircle(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDbRegion::desc()))
|
|
{
|
|
ThunderContainer->AppendRegion(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDb3dSolid::desc()))
|
|
{
|
|
ThunderContainer->Append3DSolid(sNO, dbObj->objectId());
|
|
}
|
|
}
|
|
}
|
|
else // 避雷线
|
|
{
|
|
thundXData.GetXData((AcDbEntity*)dbObj,KEY_LINE_GROUP_NO,sNO);
|
|
if (!sNO.IsEmpty())
|
|
{
|
|
if (pErased && CThunderCmdGroup::bIsAllowDraw && !dbObj->isUndoing())
|
|
{
|
|
CString sTemp;
|
|
AcGeDoubleArray arProHeight;
|
|
thundXData.GetProtectHeightFromObjEx((AcDbEntity*)dbObj, arProHeight);
|
|
ThunderContainer->AppendLineProHeight(sNO, arProHeight);
|
|
if (dbObj->isKindOf(AcDbPolyline::desc()))
|
|
{
|
|
ThunderContainer->RemoveThunderLine(sNO,dbObj->objectId());
|
|
CThunderCmdGroup::bExecute = TRUE;
|
|
}
|
|
else if (dbObj->isKindOf(AcDbRegion::desc()))
|
|
{
|
|
thundXData.GetXData((AcDbEntity*)dbObj,TEL_CURRENT_PROHEIGHT,sTemp);
|
|
ThunderContainer->AppendRemoveLineProHeight(sNO, _tstof(sTemp));
|
|
CThunderCmdGroup::bExecute = TRUE;
|
|
}
|
|
}
|
|
else if (!pErased && dbObj->isUndoing())// 恢复
|
|
{
|
|
if (dbObj->isKindOf(AcDbPolyline::desc()))
|
|
{
|
|
ThunderContainer->AppendThunderLine(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDbRegion::desc()))
|
|
{
|
|
ThunderContainer->AppendLineRegion(sNO, dbObj->objectId());
|
|
}
|
|
else if (dbObj->isKindOf(AcDb3dSolid::desc()))
|
|
{
|
|
ThunderContainer->AppendLine3DSolid(sNO, dbObj->objectId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CThunderDbReactor::goodbye(const AcDbDatabase* dwg)
|
|
{
|
|
if (dwg != NULL)
|
|
{
|
|
dwg->removeReactor(this);
|
|
}
|
|
}
|