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

1069 lines
25 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TArchDbReactor 类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TArchDbReactor 定义
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TArchDbReactor.h"
//#include "TchGlobalDef.h"
#include "TEntityBase.h"
#include "TDbWall.h"
#include "TDbColumn.h"
#include "TArchCmdReactor.h"
#include "TAcDbObjectPtr.h"
#include "dbcornerwin.h"
#include "TDbRegion.h"
#include "Symdef.h"
#include "TGKatana.h"
#ifdef TASD
#include "TDbExtentsZoneTable.h"
#include "TArchAppDocGlobals.h"
#include "TAssocMsgContainer.h"
#endif
extern double g_nLtMScale, g_nLtPScale;
extern BOOL g_bAutoLTScale;
#ifdef TASD
CMapPtrToPtr g_mapDb2ZoneTable;
TDbExtentsZoneTable* g_pExtentsZoneTable = NULL;//分区表对象
extern BOOL g_bSplitFloor;
#define MAX_COUNT 200000
void RemoveAllMsg()
{
TArchDbReactor* pDbReactor = NULL;
TArchAppDocGlobals::g_mapGlobalsDb2Reactor.Lookup(acdbCurDwg(), (void*&)pDbReactor);
if (pDbReactor)
{
if (pDbReactor->m_pAssocMsgContainer)
{
pDbReactor->m_pAssocMsgContainer->RemoveAll();
}
}
}
void AddMsg(const TAssocMsg& assocMsg)
{
TArchDbReactor* pDbReactor = NULL;
TArchAppDocGlobals::g_mapGlobalsDb2Reactor.Lookup(acdbCurDwg(), (void*&)pDbReactor);
if (pDbReactor)
{
pDbReactor->m_pAssocMsgContainer->AddMsg(assocMsg);
}
}
// 打开分区表
void OpenZoneTbl(AcDbDatabase* pDb, TDbExtentsZoneTable* pZoneTbl)
{
if (pDb == NULL)
{
pDb = acdbCurDwg();
}
Acad::ErrorStatus es = Acad::eOk;
AcDbDictionary* pNamedObj = NULL;
if(pDb && pDb->getNamedObjectsDictionary(pNamedObj, AcDb::kForRead)==Acad::eOk && pNamedObj)
{
AcDbObjectId idExist;
es = pNamedObj->getAt(_T("ATS_STRUEXENTSZONETABLE"), idExist);
if(es == Acad::eOk && !!idExist)
{
TDbExtentsZoneTable* pIObj = NULL;
es = acdbOpenObject(pIObj, idExist, AcDb::kForRead);
if(es == Acad::eOk)
{
*pZoneTbl = *pIObj;
pIObj->close();
pNamedObj->close();
return ;
}
}
pNamedObj->close();
}
return;
AcDbBlockTable* pTable = NULL;
if (pDb != NULL)
{
pDb->getBlockTable(pTable,AcDb::kForRead);
if (pTable)
{
AcDbObjectId id = pTable->objectId();
pTable->close();
ads_name ent;
acdbGetAdsName(ent,id);
AcDbHandle handle = id.handle();
AcDbObjectId id2 = id,idOwner;
//遍历数据库,查找分区表
int nIndex = 0;
while(nIndex < MAX_COUNT)
{
AcDbObject* pObj = NULL;
if (Acad::eOk == acdbOpenAcDbObject(pObj,id2,AcDb::kForRead))
{
idOwner = pObj->ownerId();
CString str = pObj->isA()->name();
if (idOwner.isNull())
{
TDbExtentsZoneTable* pExtZoneTbl = TDbExtentsZoneTable::cast(pObj);
if (pExtZoneTbl != NULL) //找到分区表
{
*pZoneTbl = *pExtZoneTbl;
pExtZoneTbl->close();
ads_printf(_T("\nfind! nIndex = %d"),nIndex);
break;
}
}
pObj->close();
}
handle.increment();
pDb->getAcDbObjectId(id2,false,handle);
nIndex += 1;
}
if (nIndex >= MAX_COUNT)
{
ads_printf(_T("\nnot find! nIndex = %d"),nIndex);
}
}
}
}
// 保存分区表
void SaveZoneTbl(AcDbDatabase* pDb, TDbExtentsZoneTable* pZoneTbl)
{
if (pDb == NULL)
{
pDb = acdbCurDwg();
}
Acad::ErrorStatus es = Acad::eOk;
AcDbDictionary* pNamedObj = NULL;
if(pDb && pDb->getNamedObjectsDictionary(pNamedObj, AcDb::kForWrite)==Acad::eOk && pNamedObj)
{
AcDbObjectId idExist;
es = pNamedObj->getAt(_T("ATS_STRUEXENTSZONETABLE"), idExist);
if(es == Acad::eOk && !!idExist)
{
TDbExtentsZoneTable* pIObj = NULL;
es = acdbOpenObject(pIObj, idExist, AcDb::kForWrite);
if(es == Acad::eOk)
{
*pIObj = *pZoneTbl;
pIObj->close();
}
else
{
//if (pNamedObj->upgradeOpen() == Acad::eOk)
{
TDbExtentsZoneTable* pExtZoneTbl = new TDbExtentsZoneTable;
*pExtZoneTbl = *pZoneTbl;
AcDbObjectId id = AcDbObjectId::kNull;
es = pNamedObj->setAt(_T("ATS_STRUEXENTSZONETABLE"),pExtZoneTbl, id);
if (es == Acad::eOk)
{
pExtZoneTbl->close();
}
else
{
delete pExtZoneTbl;
}
//pNamedObj->downgradeOpen();
}
}
}
else// if (pNamedObj->upgradeOpen() == Acad::eOk)
{
TDbExtentsZoneTable* pExtZoneTbl = new TDbExtentsZoneTable;
*pExtZoneTbl = *pZoneTbl;
AcDbObjectId id = AcDbObjectId::kNull;
es = pNamedObj->setAt(_T("ATS_STRUEXENTSZONETABLE"),pExtZoneTbl, id);
if (es == Acad::eOk)
{
pExtZoneTbl->close();
}
else
{
delete pExtZoneTbl;
}
//pNamedObj->downgradeOpen();
}
pNamedObj->close();
}
return;
AcDbBlockTable* pTable = NULL;
if (pDb != NULL)
{
pDb->getBlockTable(pTable,AcDb::kForWrite);
if (pTable)
{
AcDbObjectId id = pTable->objectId();
pTable->close();
ads_name ent;
acdbGetAdsName(ent,id);
AcDbHandle handle = id.handle();
AcDbObjectId id2 = id,idOwner;
bool bFindZoneTbl = false;
//遍历数据库,查找分区表
int nIndex = 0;
while(nIndex < MAX_COUNT)
{
AcDbObject* pObj = NULL;
if ( Acad::eOk == acdbOpenAcDbObject(pObj,id2,AcDb::kForRead))
{
idOwner = pObj->ownerId();
if (idOwner.isNull())
{
TDbExtentsZoneTable* pExtZoneTbl = TDbExtentsZoneTable::cast(pObj);
if (pExtZoneTbl != NULL) //找到分区表
{
*pZoneTbl = *pExtZoneTbl;
pExtZoneTbl->close();
bFindZoneTbl = true;
ads_printf(_T("\nfind!nIndex = %d"),nIndex);
break;
}
}
pObj->close();
}
handle.increment();
pDb->getAcDbObjectId(id2,false,handle);
nIndex += 1;
}
if (nIndex >= MAX_COUNT)
{
ads_printf(_T("\nnot find! nIndex = %d"),nIndex);
}
//数据库没有,添加到数据库
if (!bFindZoneTbl)
{
TDbExtentsZoneTable* pExtZoneTbl = new TDbExtentsZoneTable;
*pExtZoneTbl = *pZoneTbl;
Acad::ErrorStatus es = pDb->addAcDbObject((AcDbObject*)pExtZoneTbl);
if (es == Acad::eOk)
{
pExtZoneTbl->close();
}
else
{
delete pExtZoneTbl;
}
}
}
//TDbExtentsZoneTable* pExtZoneTbl2 = new TDbExtentsZoneTable;
//OpenZoneTbl(pDb,pExtZoneTbl2);
//delete pExtZoneTbl2;
}
}
//全局分区表对象
TDbExtentsZoneTable* GetGlobalExtZoneTbl(const AcDbDatabase* pDb)
{
AcDbDatabase* pDbCur = (AcDbDatabase*)pDb;
if (!pDbCur)
{
pDbCur = acdbCurDwg();
}
TDbExtentsZoneTable* pZoneTbl = NULL;
g_mapDb2ZoneTable.Lookup(pDbCur, (void*&)pZoneTbl);
if (!pZoneTbl)
{
pZoneTbl = new TDbExtentsZoneTable();
}
return pZoneTbl;
}
#endif
TArchDbReactor::TArchDbReactor(TArchPerDocData*pDD)
: m_pDocData(pDD)
{
#ifdef TASD
m_pAssocMsgContainer = new TAssocMsgContainer;
#endif
}
TArchDbReactor::~TArchDbReactor()
{
#ifdef TASD
if (m_pAssocMsgContainer)
{
delete m_pAssocMsgContainer;
}
m_pAssocMsgContainer = NULL;
#endif
}
TArchPerDocData* TArchDbReactor::GetDocData()const
{
return m_pDocData;
}
void TArchDbReactor::AddWallCorners(TDbWall *pWall)
{
GetDocData()->AddWallCorners(pWall);
}
void TArchDbReactor::AddChangedColumn(TDbColumn *pColumn)
{
GetDocData()->AddChangedColumn(pColumn);
}
void TArchDbReactor::AddModifiedOpening(const AcDbObjectId &id)
{
GetDocData()->AddModifiedOpening(id);
}
void TArchDbReactor::AddModifiedWall(const AcDbObjectId &id)
{
GetDocData()->AddModifiedWall(id);
}
void TArchDbReactor::AddModifiedClip(const AcDbObjectId &id)
{
GetDocData()->AddModifiedClip(id);
}
void TArchDbReactor::AddModifiedClipped(const AcDbObjectId &id)
{
GetDocData()->AddModifiedClipped(id);
}
void TArchDbReactor::AddModifiedRegion(const AcDbObjectId &id)
{
GetDocData()->AddModifiedRegion(id);
}
void TArchDbReactor::headerSysVarChanged (const AcDbDatabase* dwg, const TCHAR* name, Adesk::Boolean bSuccess)
{
if (g_bAutoLTScale && dwg == acdbCurDwg() && _tcsicmp(name, _T("TILEMODE")) == 0 && bSuccess)
{
int psltscale = 0;
VERIFY(TGGetVar(_T("PSLTSCALE"), &psltscale) == RTNORM);
if (psltscale)
{
int nTileMode = 0;
VERIFY(TGGetVar(_T("TILEMODE"), &nTileMode) == RTNORM);
double ltscale = nTileMode ? g_nLtMScale : g_nLtPScale;
TGSetVar(_T("LTSCALE"), ltscale);
}
}
}
//处理发生变化的实体(Modified, Erased, Appended)
void TArchDbReactor::ObjectChanged(const AcDbObject *dbObj, int nChgFlag)
{
TCString sCmdNames;
TGGetVar(_T("CMDNAMES"), sCmdNames);
if (_tcsicmp(sCmdNames, _T("QSAVE")) == 0 ||
_tcsicmp(sCmdNames, _T("SAVE")) == 0 ||
_tcsicmp(sCmdNames, _T("SAVEAS")) == 0 ||
_tcsicmp(sCmdNames, _T("PLOT")) == 0 ||
_tcsicmp(sCmdNames, _T("PREVIEW")) == 0||
_tcsicmp(sCmdNames, _T("WBLOCK")) == 0)
{
return;
}
if (dbObj->database() == acdbCurDwg())
{
ModifyModelRecordZone(dbObj); //add by xlc on 100531 提速优化
TEntityBase *pEntBase = TEntityBase::Cast(dbObj);
if (pEntBase != NULL)
{
if (pEntBase->IsClipMe())
{
AddModifiedClipped(dbObj->objectId());
}
if (pEntBase->IsMeClip())
{
AddModifiedClip(dbObj->objectId());
}
}
if (dbObj->isKindOf(TDbWall::desc()))
{
TDbWall *pWall = (TDbWall *)dbObj;
AddWallCorners(pWall);
}
else if (dbObj->isKindOf(TDbOpening::desc()) || dbObj->isKindOf(TDbCornerWin::desc()))
{
AddModifiedOpening(dbObj->objectId());
}
else if (dbObj->isKindOf(TDbRegion::desc()))
{
AddModifiedRegion(dbObj->objectId());
}
else if (dbObj->isA() == TDbColumn::desc())
{
TDbColumn *pColumn = (TDbColumn *)dbObj;
if (!pColumn->IsFortifyColumn())
{
AddChangedColumn(pColumn);
}
}
else if (dbObj->isA() == AcDbLayerTableRecord::desc())
{
TArchCmdReactor::s_bLayerChanged = TRUE;
}
else if (dbObj->isA() == AcDbBlockReference::desc())
{
BOOL bAddRmat = FALSE;
AcDbBlockReference *pInsert = AcDbBlockReference::cast(dbObj);
if (pInsert)
{
AcDbObjectId idBlock = pInsert->blockTableRecord();
OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if (pBlock)
{
const TCHAR *rName = NULL;
if (pBlock->getName(rName) == Acad::eOk && rName && _tcsicmp(rName, _T("RM_SDB")) == 0)
{
bAddRmat = TRUE;
}
}
OPENOBJ_END();
}
// 新增材质,则要发送消息
if (bAddRmat)
{
TArchCmdReactor::s_bUpdateMaterial = TRUE;
}
}
}
}
// 当实体从当前DWG中删除时的处理
void TArchDbReactor::objectErased(const AcDbDatabase* dwg,
const AcDbObject* dbObj, Adesk::Boolean pErased)
{
if (!g_bMonitorDbAction || IsDocLocked())
{
return;
}
if ( dwg == acdbCurDwg())
{
if (dbObj->isA() == AcDbLayerTableRecord::desc())
{
TArchCmdReactor::s_bLayerChanged = TRUE;
}
else
{
ObjectChanged(dbObj, pErased == Adesk::kTrue? OBJ_DELETE:OBJ_APPEND);
}
GetDocData()->OnModified(dbObj);
}
#ifdef TASD
//结构
if (pErased) //正删除
{
if (dbObj->isKindOf(TDbBaseWall::desc())
//||dbObj->isKindOf(TDbWall::desc())
//||dbObj->isKindOf(TDbColumn::desc())
||dbObj->isKindOf(TDbStruFloorSlab::desc())
||dbObj->isKindOf(TDbStruHole::desc()))
{
//获得关联对象
AcDbObjectIdArray arIds;
((TDbStruEntityBase*)dbObj)->GetAssocRelation(ASSOC_ALL, arIds);
//获得同时操作的对象数组
AcDbObjectIdArray arIdPick;
g_ssPickFirst.AsIdArray(arIdPick);
bool bBaseWall = false;
TGGeCurveSegment cvCenter;
if (dbObj->isKindOf(TDbBaseWall::desc()))
{
bBaseWall = true;
cvCenter = ((TDbBaseWall*)dbObj)->GetCenterLine();
}
AcDbObjectIdArray arIdsFloor;
//解除关联
for (int i = 0; i < arIds.length(); i++)
{
//关联对象在同时删除数组里时,不需解除关联
if (arIdPick.contains(arIds[i]))
{
continue;
}
OPENOBJ_BEGIN(arIds[i], AcDb::kForWrite, TDbStruEntityBase, pEnt);
if (pEnt)
{
pEnt->RemoveAssocRelation(dbObj->objectId());
//处理有可能存在合并的楼板
if (bBaseWall && g_bSplitFloor)
{
if (pEnt->isKindOf(TDbStruFloorSlab::desc()))
{
int nKind = 0;
((TDbStruFloorSlab*)pEnt)->GetAt(KEY_KIND, nKind);
if (nKind == 0) //不处理悬挑板
{
AcGePoint3d ptPos;
if(pEnt->GetAt(KEY_POS, ptPos))
{
//对位置点进行判断,防止发生只有一端与楼板相交的情况也进行合并
TADSGePoint3d ptRes;
if(cvCenter.ProjectToMe(TADSGePoint3d(ptPos), ptRes)==RTNORM)
{
if((ptRes&cvCenter) != PR_INSIDE)
{
continue;
}
}
else
{
continue;
}
}
arIdsFloor.append(pEnt->objectId());
}
}
}
}
OPENOBJ_END();
}
//从分区表移除对象
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->RemoveBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
//合并楼板
if(bBaseWall && g_bSplitFloor)
{
int nLen = arIdsFloor.length();
if (nLen > 1)
{
bool bTrue = false;
for (int i = nLen-1; i > 0; i--)
{
TGGePoly2D polyThis;
double dThichThis(0);
OPENOBJ_BEGIN(arIdsFloor[i],AcDb::kForRead, TDbStruFloorSlab, pFloorThis);
if (pFloorThis)
{
pFloorThis->GetOutline(polyThis);
pFloorThis->GetAt(KEY_THICK, dThichThis);
}
else
{
continue;
}
OPENOBJ_END();
polyThis.SetElevation(0);
TADSGePoint3d ptPosThis;
polyThis.Center(ptPosThis);
TGGePoly2D poly;
for(int j = i-1; j >= 0; j--)
{
TGGePoly2D polyThat;
OPENOBJ_BEGIN(arIdsFloor[j],AcDb::kForRead, TDbStruFloorSlab, pFloorThat);
if (pFloorThat)
{
pFloorThat->GetOutline(polyThat);
polyThat.SetElevation(0);
double dThichThat(0);
pFloorThat->GetAt(KEY_THICK, dThichThat);
TADSGePoint3d ptPosThat;
polyThat.Center(ptPosThat);
int nSideThis = cvCenter.OnWhichSide(ptPosThis);
int nSideThat = cvCenter.OnWhichSide(ptPosThat);
if (nSideThis != nSideThat)
{
TDPtrList<TGGePoly2D> lstPoly;
Union(polyThis, polyThat, lstPoly);
// 融合成功
if (lstPoly.Length() == 1)
{
poly = *lstPoly[0];
bTrue = true;
if (dThichThat > dThichThis)
{
dThichThis = dThichThat;
}
if(pFloorThat->upgradeOpen()==Acad::eOk)
{
pFloorThat->erase();
pFloorThat->downgradeOpen();
}
break;
}
}
}
else
{
continue;
}
OPENOBJ_END();
}
if(bTrue)
{
OPENOBJ_BEGIN(arIdsFloor[i],AcDb::kForWrite, TDbStruFloorSlab, pFloorThis);
if (pFloorThis)
{
poly.Compress();
TADSGePoint3d ptPos;
poly.Center(ptPos);
AcGePoint3d pt;
pFloorThis->GetAt(KEY_POS, pt);
ptPos.z = pt.z;
poly.SetElevation(pt.z);
pFloorThis->SetOutlinePoly(poly);
pFloorThis->SetAt(KEY_THICK, dThichThis);
pFloorThis->SetAt(KEY_POS, ptPos.AsAcGePoint3d());
}
OPENOBJ_END();
bTrue = false;
}
}
}
}
}
else if (dbObj->isKindOf(TDbWall::desc())
||dbObj->isKindOf(TDbColumn::desc()))
{
//从分区表移除对象
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->RemoveBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
}
else //反删除
{
if (dbObj->isKindOf(TDbBaseWall::desc())
//||dbObj->isKindOf(TDbWall::desc())
//||dbObj->isKindOf(TDbColumn::desc())
||dbObj->isKindOf(TDbStruFloorSlab::desc())
||dbObj->isKindOf(TDbStruHole::desc()))
{
//对象添加到分区表
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->AddBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
//创建消息
TAssocMsg assocMsg;
assocMsg.SetMethod(TAssocMsg::kAppend);
assocMsg.SetAssocId(dbObj->objectId());
if(m_pAssocMsgContainer)
{
m_pAssocMsgContainer->AddMsg(assocMsg);
}
}
else if (dbObj->isKindOf(TDbWall::desc())
||dbObj->isKindOf(TDbColumn::desc()))
{
//对象添加到分区表
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->AddBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
}
#endif
}
// 当实体添加到当前DWG时的处理函数
void TArchDbReactor::objectAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj)
{
if (!g_bMonitorDbAction || IsDocLocked())
{
return;
}
if (dwg == acdbCurDwg())
{
if (dbObj->isA() == AcDbLayerTableRecord::desc())
{
TArchCmdReactor::s_bLayerChanged = TRUE;
AcDbLayerTableRecord *pLayer = AcDbLayerTableRecord::cast(dbObj);
if (pLayer != NULL)
{
const TCHAR *pszName = NULL;
pLayer->getName(pszName);
ASSERT(pszName);
//如果外部没有此全局定义,一律以0层作为默认值
if (LAY_VIEWPORT == NULL) LAY_VIEWPORT = (PSTRING)(_T("0"));
if (LAY_FLOOR_RECT == NULL) LAY_FLOOR_RECT = (PSTRING)(_T("0"));
if (_tcsicmp(pszName, LAY_VIEWPORT) == 0)
{
g_idViewportLayer = dbObj->objectId();
}
else if (_tcsicmp(pszName, LAY_FLOOR_RECT) == 0) // sg add 100126,增加楼层框图层
{
TArchCmdReactor::g_idFloorRectLayer = dbObj->objectId();
}
}
}
else
{
ObjectChanged(dbObj, OBJ_APPEND);
}
GetDocData()->OnModified(dbObj);
}
#ifdef TASD
//结构
if (!g_bMonitorDbAction) //不监视数据库
{
return;
}
if (dbObj->isKindOf(TDbStruBeam::desc())
//||dbObj->isKindOf(TDbColumn::desc())
||dbObj->isKindOf(TDbStruFloorSlab::desc())
||dbObj->isKindOf(TDbStruHole::desc()))
{
//对象添加到分区表
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->AddBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
//创建消息
TAssocMsg assocMsg;
assocMsg.SetMethod(TAssocMsg::kAppend);
assocMsg.SetAssocId(dbObj->objectId());
if (m_pAssocMsgContainer)
{
m_pAssocMsgContainer->AddMsg(assocMsg);
}
}
else if (dbObj->isKindOf(TDbWall::desc())
||dbObj->isKindOf(TDbColumn::desc()))
{
//对象添加到分区表
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->AddBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
//创建消息
TAssocMsg assocMsg;
assocMsg.SetMethod(TAssocMsg::kAppend);
assocMsg.SetAssocId(dbObj->objectId());
if (m_pAssocMsgContainer)
{
m_pAssocMsgContainer->AddMsg(assocMsg);
}
}
#endif
}
// 当墙体修改时,接收消息
// 考虑了转角窗TDbCornerWin
void TArchDbReactor::objectModified(const AcDbDatabase* dwg, const AcDbObject* dbObj)
{
#ifdef TASD
#if (ADS < 18) // R16-R17
#if (ADS == 16)
int ads = 16;
#endif
#if (ADS == 17)
int ads = 17;
#endif
AcApDocument *pDoc = curDoc();
if (!pDoc) return;
AcAp::DocLockMode lock = pDoc->lockMode();
OSVERSIONINFOEX info;
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
::GetVersionEx((OSVERSIONINFO*)&info);
TCHAR strVer[20];
TGGetVar(_T("ACADVER"), strVer);
CString str = strVer;
str = str.Left(4);
if (
((info.dwMajorVersion == 6) && (ads == 16)) // R16平台 + XP以后操作系统
||((info.dwMajorVersion) == 5 && (_T("17.0") == str)) // CAD2007 + xp操作系统
)
{
if (!g_bMonitorDbAction || (pDoc->lockMode() != AcAp::DocLockMode::kNone))
return;
}
else
{
if (!g_bMonitorDbAction || IsDocLocked())
return;
}
#else
if (!g_bMonitorDbAction || IsDocLocked())
return;
#endif
#else
if (!g_bMonitorDbAction || IsDocLocked())
{
return;
}
#endif
if (dwg == acdbCurDwg())
{
ObjectChanged(dbObj, OBJ_CHANGE);
if (dbObj->isKindOf(TDbWall::desc()))
{
AddModifiedWall(dbObj->objectId());
}
// add by gjm 2013/11/05
KatanaToolkit::ModifyKatana(CGlwKatana::cast(dbObj));
// end
GetDocData()->OnModified(dbObj);
}
#ifdef TASD
// 结构
if (!g_bMonitorDbAction) //不监视数据库
{
return;
}
if (dbObj->isKindOf(TDbBaseWall::desc())
//||dbObj->isKindOf(TDbColumn::desc())
||dbObj->isKindOf(TDbStruFloorSlab::desc())
||dbObj->isKindOf(TDbStruHole::desc()))
{
//更新分区表
AcDbExtents ext;
((AcDbEntity*)dbObj)->getGeomExtents(ext);
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->UpdatePartition(dbObj->objectId(), ext);
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
//创建消息
TAssocMsg assocMsg;
assocMsg.SetMethod(TAssocMsg::kEdit);
assocMsg.SetAssocId(dbObj->objectId());
if(m_pAssocMsgContainer)
{
m_pAssocMsgContainer->AddMsg(assocMsg);
}
}
else if(dbObj->isKindOf(TDbWall::desc()))
{
//更新分区表
AcDbExtents ext;
((AcDbEntity*)dbObj)->getGeomExtents(ext);
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->UpdatePartition(dbObj->objectId(), ext);
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
else if (dbObj->isKindOf(TDbColumn::desc()))
{
//更新分区表
AcDbExtents ext;
((AcDbEntity*)dbObj)->getGeomExtents(ext);
XPoint ptLoc = ((TDbColumn*)dbObj)->GetLocation();
double dHeight = ((TDbColumn*)dbObj)->GetHeight();
AcGePoint3d ptMin = ext.minPoint(), ptMax = ext.maxPoint();
ptMin.z = ptLoc.z;
ptMax.z = ptLoc.z + dHeight;
ext.set(ptMin,ptMax);
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->UpdatePartition(dbObj->objectId(), ext);
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
#endif
}
void TArchDbReactor::objectOpenedForModify(const AcDbDatabase* dwg,const AcDbObject* dbObj)
{
if (dwg != acdbCurDwg())
{
return;
}
GetDocData()->OnOpenedForModify(dbObj);
}
void TArchDbReactor::objectReAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj)
{
if (dwg != acdbCurDwg())
{
return;
}
GetDocData()->OnModified(dbObj);
#ifdef TASD
//结构
if (!g_bMonitorDbAction) //不监视数据库
{
return;
}
if (dbObj->isKindOf(TDbBaseWall::desc())
//||dbObj->isKindOf(TDbColumn::desc())
||dbObj->isKindOf(TDbStruFloorSlab::desc())
||dbObj->isKindOf(TDbStruHole::desc()))
{
//对象添加到分区表
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->AddBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
//创建消息
TAssocMsg assocMsg;
assocMsg.SetMethod(TAssocMsg::kAppend);
assocMsg.SetAssocId(dbObj->objectId());
if (m_pAssocMsgContainer)
{
m_pAssocMsgContainer->AddMsg(assocMsg);
}
}
else if (dbObj->isKindOf(TDbWall::desc())
||dbObj->isKindOf(TDbColumn::desc()))
{
//对象添加到分区表
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->AddBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
#endif
}
void TArchDbReactor::objectUnAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj)
{
if (dwg != acdbCurDwg())
{
return;
}
GetDocData()->OnModified(dbObj);
#ifdef TASD
//结构
if (!g_bMonitorDbAction) //不监视数据库
{
return;
}
if (dbObj->isKindOf(TDbBaseWall::desc())
//||dbObj->isKindOf(TDbColumn::desc())
||dbObj->isKindOf(TDbStruFloorSlab::desc())
||dbObj->isKindOf(TDbStruHole::desc()))
{
//获得关联对象
AcDbObjectIdArray arIds;
((TDbStruEntityBase*)dbObj)->GetAssocRelation(ASSOC_ALL, arIds);
//获得同时操作的对象数组
AcDbObjectIdArray arIdPick;
g_ssPickFirst.AsIdArray(arIdPick);
//解除关联
for (int i = 0; i < arIds.length(); i++)
{
//关联对象在同时删除数组里时,不需解除关联
if (arIdPick.contains(arIds[i]))
{
continue;
}
OPENOBJ_BEGIN(arIds[i], AcDb::kForWrite, TDbStruEntityBase, pEnt);
if (pEnt)
{
pEnt->RemoveAssocRelation(dbObj->objectId());
}
OPENOBJ_END();
}
//从分区表移除对象
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->RemoveBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
else if(dbObj->isKindOf(TDbWall::desc())
||dbObj->isKindOf(TDbColumn::desc()))
{
//从分区表移除对象
TDbExtentsZoneTable* pZoneTbl = GetGlobalExtZoneTbl(dwg);
pZoneTbl->RemoveBoxZoneCell(dbObj->objectId());
g_mapDb2ZoneTable.SetAt((AcDbDatabase*)dwg, pZoneTbl);
}
#endif
}
// 建立数据库的监测
void TArchDbReactor::Attach()
{
TArchPerDocData *pData = GetCurDocData();
if (pData)
{
pData->AttachReactor();
}
}
// 除去数据库的监测
void TArchDbReactor::Detach()
{
TArchPerDocData *pData = GetCurDocData();
if (pData)
{
pData->DetachReactor();
}
}
BOOL TArchDbReactor::IsDocLocked()const
{
return GetDocData()->IsDocLocked();
}