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

230 lines
5.2 KiB
C++

#include "stdafx.h"
#include "TDbImpBase.h"
#include "TInterfaceModifyMsgContext.h"
extern TInterfaceModifyMsgContext g_iMsgContext;
extern TDbXDataMap g_mapClass2Cmd;
TDbImpBase::TDbImpBase()
{
}
TDbImpBase::~TDbImpBase()
{
}
BOOL TDbImpBase::GetInterface(int nIndex,TInterface& pipeInterface) const
{
return FALSE;
}
BOOL TDbImpBase::GetInterface(const AcGePoint3d& ptCon,TInterface& pipeInterface) const
{
return FALSE;
}
int TDbImpBase::GetInterfaceCount() const
{
return 0;
}
BOOL TDbImpBase::UpdateInterfaceRec(const AcDbObjectId& idOwner,const AcGeMatrix3d& xform,AcGePoint3d* ppOld)
{
//1.大数量的接口更新消息缓存处理
int nMaxSetForOp = 0;
g_mapClass2Cmd.GetAt(KEY_MAX_SET_FOROP,nMaxSetForOp);
if (nMaxSetForOp == 2) //优化批量处理interfacerecord 的 update消息
{
AcDbObjectIdArray arSet;
acedGetCurrentSelectionSet(arSet);
if (arSet.length() > MAX_SET_FOROP)
{
CPtrArray* pArray = NULL;
if (!g_iMsgContext.m_mapDbTInfRecMsgs.Lookup((void*)acdbCurDwg(),(void*&)pArray))
{
pArray = new CPtrArray;
g_iMsgContext.m_mapDbTInfRecMsgs.SetAt((void*)acdbCurDwg(),(void*&)pArray);
}
if (pArray != NULL)
{
TInfUpdate* pInfUpdate = new TInfUpdate;
pInfUpdate->nIntf = TDb::eTransformBy;
pInfUpdate->xForm = xform;
pInfUpdate->idOwner = idOwner;
pInfUpdate->bInfAll = false;
if (ppOld == NULL)
{
pInfUpdate->bInfAll = true;
}
else
{
pInfUpdate->ptOld = *ppOld;
}
pArray->Add(pInfUpdate);
return TRUE;
}
}
}
//2.到命名对象字典中找;
BOOL bSuccess = FALSE;
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if(Acad::eOk == pIntfRec->upgradeOpen())
{
//如果没有注册接口,注册接口
if (!pIntfRec->Find(idOwner))
{
TInterface pipeInterface;
for (int i = 0;i < GetInterfaceCount();i++)
{
pipeInterface.Reset();
if (GetInterface(i,pipeInterface))
{
pIntfRec->Add(pipeInterface);
}
}
}
else
{
if (ppOld == NULL)
bSuccess = pIntfRec->TransformBy(idOwner,xform);
else
bSuccess = pIntfRec->TransformBy(idOwner,*ppOld,xform);
}
pIntfRec->downgradeOpen();
}
pIntfRec->close();
return bSuccess;
}
// add end
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == acdbCurDwg()->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
pNamedDict->close();
TDbInterfaceRecord* pInterfaceRec = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForWrite))
{
pDict->close();
//如果没有注册接口,注册接口
if (!pInterfaceRec->Find(idOwner))
{
TInterface pipeInterface;
for (int i = 0;i < GetInterfaceCount();i++)
{
pipeInterface.Reset();
if (GetInterface(i,pipeInterface))
{
pInterfaceRec->Add(pipeInterface);
}
}
}
else
{
if (ppOld == NULL)
{
bSuccess = pInterfaceRec->TransformBy(idOwner,xform);
}
else
{
bSuccess = pInterfaceRec->TransformBy(idOwner,*ppOld,xform);
}
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
return bSuccess;
}
BOOL TDbImpBase::UpdateInterfaceRec(const AcDbObjectId& idOwner,const AcGePoint3d ptGeOld,const AcGePoint3d& ptGeNew)
{
//1.大数量的接口更新消息缓存处理
int nMaxSetForOp = 0;
g_mapClass2Cmd.GetAt(KEY_MAX_SET_FOROP,nMaxSetForOp);
if (nMaxSetForOp == 2) //优化批量处理interfacerecord 的 update消息
{
AcDbObjectIdArray arSet;
acedGetCurrentSelectionSet(arSet);
if (arSet.length() > MAX_SET_FOROP)
{
CPtrArray* pArray = NULL;
if (!g_iMsgContext.m_mapDbTInfRecMsgs.Lookup((void*)acdbCurDwg(),(void*&)pArray))
{
pArray = new CPtrArray;
g_iMsgContext.m_mapDbTInfRecMsgs.SetAt((void*)acdbCurDwg(),(void*&)pArray);
}
if (pArray != NULL)
{
TInfUpdate* pInfUpdate = new TInfUpdate;
pInfUpdate->nIntf = TDb::eUpdateIntf;
pInfUpdate->xForm.setToTranslation(ptGeNew - ptGeOld);
pInfUpdate->idOwner = idOwner;
pInfUpdate->ptOld = ptGeOld;
pInfUpdate->bInfAll = false;
pArray->Add(pInfUpdate);
return TRUE;
}
}
}
//2.到命名对象字典中找;
BOOL bSuccess = FALSE;
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if(Acad::eOk == pIntfRec->upgradeOpen())
{
pIntfRec->Update(idOwner,ptGeOld,ptGeNew);
pIntfRec->downgradeOpen();
}
pIntfRec->close();
return bSuccess;
}
// add end
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == acdbCurDwg()->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
pNamedDict->close();
TDbInterfaceRecord* pInterfaceRec = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForWrite))
{
pDict->close();
pInterfaceRec->Update(idOwner,ptGeOld,ptGeNew);
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
return bSuccess;
}