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

1626 lines
42 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdafx.h"
#include "TDbRelInterfaceReactor.h"
#include "TReactorUnlockSwitch.h"
#include "TDbMakeObjAssocReactor.h"
#include "TInterfaceReleationManager.h"
#include "TInterfaceModifyManager.h"
#include "TInterfaceTransformByManager.h"
#include "TInterfaceSizeReleationManger.h"
#include "TCoverReleationManager.h"
#include "TInterfaceModifyMsgContext.h"
#include "TDbPipeMatchPropertiesReactor.h"
#include "TToolKitBase.h"
#include "TDbInterfaceMsgWrite.h"
#include "actrans.h"
Adesk::Boolean acedPostCommand( const TCHAR * );
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern TDbMakeObjAssocReactor* g_pObjAssocReactor;
extern TInterfaceModifyMsgContext g_iMsgContext;
extern TDbXDataMap g_mapClass2Cmd;
extern PickSet g_ssLastSel;
extern CString g_csLastCmd;
// #define SECTION_IGORE 80
// 常规、删除情况下:忽略更新遮挡的实体数量
#define IGOREHIDE_NORMAL 500
#define IGOREHIDE_DEL 100
TDbRelInterfaceReactor::TDbRelInterfaceReactor()
{
m_pToolKit = NULL;
m_bNestedUpdate = FALSE;
m_pMatchPropertiesReactor = new TDbPipeMatchPropertiesReactor;
//add by dyw
m_pDuctStretchReactor = new TDbDuctStretchRactor;
}
TDbRelInterfaceReactor::~TDbRelInterfaceReactor()
{
if (m_pMatchPropertiesReactor != NULL)
{
delete m_pMatchPropertiesReactor;
m_pMatchPropertiesReactor = NULL;
}
//add by dyw
if(m_pDuctStretchReactor != NULL)
{
delete m_pDuctStretchReactor;
m_pDuctStretchReactor = NULL;
}
}
void TDbRelInterfaceReactor::AddToolKit(TToolKitBase* pToolKit)
{
if (m_lstToolKitPtrs.Find(pToolKit) == NULL)
{
m_lstToolKitPtrs.AddTail(pToolKit);
}
}
void TDbRelInterfaceReactor::RemoveToolKit(TToolKitBase* pToolKit)
{
POSITION ps = m_lstToolKitPtrs.Find(pToolKit);
if (ps != NULL)
{
m_lstToolKitPtrs.RemoveAt(ps);
}
}
void TDbRelInterfaceReactor::commandWillStart(const TCHAR* cmdStr)
{
g_mapClass2Cmd.SetAt(KEY_MAX_SET_FOROP,0);
if(_tcsicmp(cmdStr, _T("matchprop"))==0 && curDoc() != NULL)
{
m_pMatchPropertiesReactor->ResetMatchProperties();
Acad::ErrorStatus es = curDoc()->inputPointManager()->addInputContextReactor(m_pMatchPropertiesReactor);
}
if( _tcsicmp(cmdStr, _T("move"))==0 ||
_tcsicmp(cmdStr, _T("mirror")) == 0||
_tcsicmp(cmdStr, _T("copy")) == 0 ||
_tcsicmp(cmdStr, _T("copybase")) == 0 ||
_tcsicmp(cmdStr, _T("copyclip")) == 0 ||
_tcsicmp(cmdStr, _T("pasteclip")) == 0 ||
_tcsicmp(cmdStr, _T("pasteblock")) == 0 ||
_tcsicmp(cmdStr, _T("array")) == 0
)
{
g_mapClass2Cmd.SetAt(KEY_MAX_SET_FOROP,2);
}
if(0 == _tcsicmp(cmdStr, _T("tzkb")))
{
// tzkb中嵌套COPY命令 标识一下 不进行关系更新
m_bNestedUpdate = TRUE;
}
//add by dyw 2014-7-16 解决风管备注拉伸位置不正确的问题
if(0 == _tcsicmp(cmdStr, _T("STRETCH")) && curDoc() != NULL)
{
curDoc()->inputPointManager()->addInputContextReactor(m_pDuctStretchReactor);
}
//add end
}
void TDbRelInterfaceReactor::beginDwgOpen(TCHAR* filename)
{
}
#if ADS < 17
void TDbRelInterfaceReactor::endDwgOpen(const TCHAR* filename)
{
// R15 16平台 该函数中无AcDbDatabase参数,需要查找一次
AcDbDatabase* pDb = NULL;
AcDbVoidPtrArray* pArDbs = acdbActiveDatabaseArray();
if(NULL != pArDbs)
{
TCHAR* pFileName = NULL;
// 刚打开的图纸总是在最后 反向查找比较快
for(int i = pArDbs->length() - 1; i >= 0; i--)
{
pDb = (AcDbDatabase*)pArDbs->at(i);
if(NULL != pDb)
{
if(Acad::eOk == pDb->getFilename(pFileName))
{
if(0 == _tcsicmp(filename, pFileName))
{
break;
}
}
pDb = NULL;
}
}
}
if(NULL == pDb)
return;
#else
void TDbRelInterfaceReactor::endDwgOpen(const TCHAR* filename, AcDbDatabase* pDb)
{
#endif
//1.从数据库中读取接口记录对象
TDbInterfaceRecord* pIRec = NULL;
if (!m_mapDbToIRecPtr.Lookup(pDb,(void*&)pIRec))
{
pIRec = new TDbInterfaceRecord;
m_mapDbToIRecPtr.SetAt(pDb,pIRec);
}
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == pDb->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
TDbInterfaceRecord* pInterfaceRec2 = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec2,AcDb::kForRead))
{
pIRec->CopyFrom(*pInterfaceRec2);
pInterfaceRec2->close();
}
pDict->close();
}
pNamedDict->close();
}
if (g_pObjAssocReactor != NULL)
{
pDb->removeReactor(g_pObjAssocReactor);
pDb->addReactor(g_pObjAssocReactor);
}
}
void TDbRelInterfaceReactor::beginSave(AcDbDatabase* pDb, const TCHAR* pIntendedName)
{
//1.把接口记录保存到数据库中
TDbInterfaceRecord* pIRec = NULL;
if (m_mapDbToIRecPtr.Lookup(pDb,(void*&)pIRec))
{
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == pDb->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
TDbInterfaceRecord* pInterfaceRec2 = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec2,AcDb::kForWrite))
{
pInterfaceRec2->RemoveAll();
pInterfaceRec2->CopyFrom(*pIRec);
pInterfaceRec2->close();
}
pDict->close();
}
pNamedDict->close();
}
}
}
void TDbRelInterfaceReactor::databaseToBeDestroyed(AcDbDatabase* pDb)
{
//1.从数据库中读取接口记录对象
TDbInterfaceRecord* pIRec = NULL;
if (m_mapDbToIRecPtr.Lookup(pDb,(void*&)pIRec))
{
delete pIRec;
m_mapDbToIRecPtr.RemoveKey(pDb);
}
}
void TDbRelInterfaceReactor::databaseConstructed(AcDbDatabase* pDb)
{
//1.从数据库中读取接口记录对象
TDbInterfaceRecord* pIRec = NULL;
if (!m_mapDbToIRecPtr.Lookup(pDb,(void*&)pIRec))
{
pIRec = new TDbInterfaceRecord;
m_mapDbToIRecPtr.SetAt(pDb,pIRec);
}
}
void TDbRelInterfaceReactor::beginWblock(AcDbDatabase* pTo, AcDbDatabase* pFrom)
{
//1.从数据库中读取接口记录对象
// TDbInterfaceRecord* pIRec = NULL;
// if (!m_mapDbToIRecPtr.Lookup(pTo,(void*&)pIRec))
// {
// pIRec = new TDbInterfaceRecord;
// m_mapDbToIRecPtr.SetAt(pTo,pIRec);
// }
//
// if (g_pObjAssocReactor != NULL)
// {
// pTo->removeReactor(g_pObjAssocReactor);
// pTo->addReactor(g_pObjAssocReactor);
// }
//1.把接口记录保存到数据库中
TDbInterfaceRecord* pIRec = NULL;
if (m_mapDbToIRecPtr.Lookup(pFrom,(void*&)pIRec))
{
AcDbDictionary* pNamedDict = NULL;
if (Acad::eOk == pFrom->getNamedObjectsDictionary(pNamedDict,AcDb::kForRead))
{
AcDbDictionary* pDict = NULL;
if (Acad::eOk == pNamedDict->getAt(KEY_IRECORD,(AcDbObject*&)pDict,AcDb::kForRead))
{
TDbInterfaceRecord* pInterfaceRec2 = NULL;
if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec2,AcDb::kForWrite))
{
pInterfaceRec2->RemoveAll();
pInterfaceRec2->CopyFrom(*pIRec);
pInterfaceRec2->close();
}
pDict->close();
}
pNamedDict->close();
}
}
//1.从数据库中读取接口记录对象
if (!m_mapDbToIRecPtr.Lookup(pTo,(void*&)pIRec))
{
pIRec = new TDbInterfaceRecord;
m_mapDbToIRecPtr.SetAt(pTo,pIRec);
}
if (g_pObjAssocReactor != NULL)
{
pTo->removeReactor(g_pObjAssocReactor);
//这个地方注释掉,否则保存低版本出错
//acdbSaveAs2000
//pTo->addReactor(g_pObjAssocReactor);
}
}
void TDbRelInterfaceReactor::endWblock(AcDbDatabase* pDb)
{
//1. 清空上下文信息
// CPtrArray* pArray = NULL;
// if (g_iMsgContext.m_mapDb2TIMsgs.Lookup((AcDbDatabase*)pDb,(void*&)pArray))
// {
// TDbInterfaceMsgObj* pMsgObj = NULL;
// TInterfaceModifyMsg msg;
//
// for (int i = 0;i < pArray->GetSize();i++)
// {
// pMsgObj = (TDbInterfaceMsgObj*)pArray->GetAt(i);
// delete pMsgObj;
// }
// pArray->RemoveAll();
// delete pArray;
// g_iMsgContext.m_mapDb2TIMsgs.RemoveKey((AcDbDatabase*)pDb);
// }
if (g_pObjAssocReactor != NULL)
{
pDb->removeReactor(g_pObjAssocReactor);
pDb->addReactor(g_pObjAssocReactor);
}
//1. 清空上下文信息
CPtrArray* pArray = NULL;
if (g_iMsgContext.m_mapDb2TIMsgs.Lookup((AcDbDatabase*)pDb,(void*&)pArray))
{
TDbInterfaceMsgObj* pMsgObj = NULL;
TInterfaceModifyMsg msg;
for (int i = 0;i < pArray->GetSize();i++)
{
pMsgObj = (TDbInterfaceMsgObj*)pArray->GetAt(i);
delete pMsgObj;
}
pArray->RemoveAll();
delete pArray;
g_iMsgContext.m_mapDb2TIMsgs.RemoveKey((AcDbDatabase*)pDb);
}
}
void TDbRelInterfaceReactor::commandEndedUser(const TCHAR* cmdStr)
{
//锁定文档
acDocManager->lockDocument(acDocManager->curDocument());
//1. 取出消息更改对象记录后清空,对象命名字典中的接口消息更改记录
TReactorUnlockSwitch<AcDbDatabase,AcDbDatabaseReactor> reactorUnlockSwitch(acdbCurDwg(),g_pObjAssocReactor);
//1.3 再处理接口更改传递消息
TInterfaceModifyMsgs msgs;
PickInterfaceModifyMsgs(msgs);
if (msgs.length() == 0)
{
acDocManager->unlockDocument(acDocManager->curDocument());
curDoc()->inputPointManager()->removeInputContextReactor(m_pMatchPropertiesReactor);
return;
}
TInterfaceTransformByManager transformByMgr;
TInterfaceReleationManager releationMgr;
TInterfaceSizeReleationManger szReleationMgr;
releationMgr.m_pToolKit = m_pToolKit;
TToolKitBase* pToolKit = NULL;
//2.通过分析消息,进入不同的消息处理
TInterfaceModifyMsg msg;
AcDbObjectIdArray ids;
//3.取出所有操作对象的实体,对于非grip 消息,当实体对于一个接口操作关联时
//3.1 关联接口如果在 ids 中,就可以不需要向关联对象发接口通知消息;
int i = 0, nFoundAt = -1, nAutoWorkOn = 0;
int nMsgLen = msgs.length();
AcDbObjectId idOperate;
for (i = 0; i < nMsgLen; i++)
{
msg = msgs.at(i);
idOperate = AcDbObjectId::kNull;
idOperate = msg.GetMsgOperateOn();
if (idOperate.isValid() && !ids.find(idOperate, nFoundAt))
{
ids.append(idOperate);
}
if (msg.GetInterfaceOper() == TDb::eAutoWorkOn)
{
nAutoWorkOn += 1;
}
}
//4.关系
int nUpdateDisp = 0,nUpdateRel = 0;
TDb::InterfaceOper iOper;
for (i = 0;i < msgs.length();i++)
{
msg = msgs.at(i);
iOper = msg.GetInterfaceOper();
switch(iOper)
{
case TDb::eMoveGripPoint: //夹点关系传递
{
releationMgr.TranslateMoveGripPointMsg(msg,ids);
break;
}
case TDb::eTransformBy: //变换关系传递
{
// 注:上华的几个特例命令内部调用copy等有问题,本处特列处理
struct resbuf rb;
acedGetVar(_T("users5"),&rb);
CString sSpecLock = rb.resval.rstring;
sSpecLock.MakeLower();
if (sSpecLock.CompareNoCase(KEY_IGNORETGCPCMD) == 0)
{
}
else
{
transformByMgr.TranslateTransformByMsg(msg,ids);
}
if (rb.restype == RTSTR && rb.resval.rstring != NULL)
acutDelString(rb.resval.rstring);
break;
}
case TDb::eSize: //尺寸关系传递
{
szReleationMgr.TranslateSizeModifyMsg(msg,ids);
break;
}
case TDb::eUpdateCover: //更新遮挡关系
{
break;
}
case TDb::eUpdateDisp: //刷新图形
{
nUpdateDisp = 1;
break;
}
case TDb::eUpdateRel: //更新关系
{
nUpdateRel += 1;
break;
}
case TDb::eAutoWorkOn:
{
// if (nAutoWorkOn <= 5) // 有同时删除多个阀门时候,所以不限制数量了
{
// 恢复操作不处理
// 竖向对齐,竖向调整的时候,关闭联动,不处理Lixl add 2012-4-13
if (_tcsicmp(cmdStr, _T("UNDO")) != 0
&& _tcsicmp(cmdStr, _T("U")) != 0
&& _tcsicmp(cmdStr, _T("SXDQ")) != 0
&& _tcsicmp(cmdStr, _T("SXTZ")) != 0
&& _tcsicmp(cmdStr, _T("SBLG")) != 0 //add by dyw 20140929 添加屏蔽设备连管命令, ucs下自动调整接口关系不正确
&& _tcsicmp(cmdStr, _T("FGHZ")) != 0) //add by dyw 20141112 添加屏蔽风管绘制命令, ucs下自动调整接口关系不正确
{
for (POSITION ps = m_lstToolKitPtrs.GetHeadPosition();ps!= NULL;)
{
pToolKit = (TToolKitBase*)m_lstToolKitPtrs.GetNext(ps);
if (pToolKit != NULL)
{
pToolKit->DispatchInterfaceMsgOut(msg);
}
}
//清空Toolkit 操作后产生的新消息
TInterfaceModifyMsgs msgs2;
PickInterfaceModifyMsgs(msgs2);
}
}
break;
}
default:
break;
}
}
//5.遮挡关系更新
// mcl changed by below 。删除SECTION_IGORE(500)个以下时更新遮挡
// TCoverReleationManager coverRel;
// if (ids.length() < SECTION_IGORE)//如果选择集合太多,忽略遮挡运算
// coverRel.UpdateCoverDisplay(ids);
BOOL bSaveLastPickset(FALSE); // 是否记忆上次用户选择集
//5.遮挡关系更新
int nNum = ids.length();
if (nNum > 0)
{
// 先记录更新前所选择的实体,更新后再选择一下,为了可以不影响 选择实体时,按“P”, 获取上次选择集
AcDbObjectIdArray arOirgSelId;
acedGetCurrentSelectionSet(arOirgSelId);
if (_tcsicmp(cmdStr, _T("e")) == 0 || _tcsicmp(cmdStr, _T("erase")) == 0)
{
if (nNum < IGOREHIDE_DEL)
{
TCoverReleationManager coverRel;
coverRel.UpdateCoverDisplay(ids);
}
}
// 撤销、重做时无需更新遮挡
else if (_tcsicmp(cmdStr, _T("UNDO")) != 0 && _tcsicmp(cmdStr, _T("U")) != 0
&& _tcsicmp(cmdStr, _T("redo")) != 0 && _tcsicmp(cmdStr, _T("mredo")) != 0)
{
if (nNum < IGOREHIDE_NORMAL || _tcsicmp(cmdStr, _T("rcov")) == 0) // rcov:专门更新关系命令不限个数
{
TCoverReleationManager coverRel;
coverRel.UpdateCoverDisplay(ids);
bSaveLastPickset = TRUE;
}
}
// “自由复制”中嵌套调用copy命令,故copy不允许支持P操作,否则将导致“自由复制”出现死循环
if (_tcsicmp(cmdStr, _T("move")) != 0)
{
bSaveLastPickset = FALSE;
}
if (bSaveLastPickset)
{
g_ssLastSel.Free();
for (i = 0; i < arOirgSelId.length(); i++)
{
g_ssLastSel += arOirgSelId[i];
}
}
}
// 6. 更新关联关系,
// mcl changed by below 重做时,无须更新,否则反删除类的重做会导致新增额外接口
// if (nUpdateRel > 0)
// {
// UpdateRelInterface(ids);
// }
if (_tcsicmp(cmdStr, _T("redo")) != 0 && _tcsicmp(cmdStr, _T("mredo")) != 0 && nUpdateRel > 0)
{
UpdateRelInterface(ids);
}
// add by hh 2014.8.8 撤销时 需要更新被风管遮挡的水管
if (_tcsicmp(cmdStr, _T("UNDO")) == 0 || _tcsicmp(cmdStr, _T("U")) == 0)
{
TArchPerDocData* pData = GetCurDocData();
if(NULL != pData)
{
BOOL bUpdate = FALSE;
AcDbObjectIdArray arPipeNeedUpdate;
for(int i = 0; i < nNum; i++)
{
OPENOBJ_BEGIN(ids[i], AcDb::kForRead, TDbInterfacesObj, pPipe);
if(NULL != pPipe)
{
pPipe->GetIdsCoverByMe(arPipeNeedUpdate);
}
OPENOBJ_END();
if(!bUpdate && 0 != arPipeNeedUpdate.length())
bUpdate = TRUE;
for(int j = 0; j < arPipeNeedUpdate.length(); j++)
{
pData->AddModifiedClipped(arPipeNeedUpdate[j]);
}
arPipeNeedUpdate.setLogicalLength(0);
}
if(bUpdate)
pData->UpdateClip();
}
}
//7. 用户定义的更新关系操作,来自其他调用,修补上华复制产生的关系丢失错误
// 把需要更新的id通过写入USERS5通知tch_pipebase,处理完了后会自动清除;
struct resbuf rbUr;
acedGetVar(_T("users5"),&rbUr);
CString sUr = rbUr.resval.rstring;
sUr.MakeUpper();
if (sUr.Find(_T("UR:"),0) != -1)
{
_tcscpy(rbUr.resval.rstring,_T(""));
acedSetVar(_T("users5"),&rbUr);
//ur:123,345,567,768
ids.setLogicalLength(0);
ParasUrObjectIds(sUr,ids);
UpdateRelInterface(ids);
}
//可能的图形刷新
acTransactionManagerPtr()->enableGraphicsFlush(true);
//修改原因:
//在Acad08 平台,当实体处于 shade 命令模式时,执行explode 命令,调用 acedUpdateDisplay 出错
//lfy 2010.2.2
#if ADS>=17
if(_tcsicmp(cmdStr, _T("explode")) != 0)
{
acedUpdateDisplay();
}
#else
acedUpdateDisplay();
#endif
acTransactionManagerPtr()->flushGraphics();
acDocManager->unlockDocument(acDocManager->curDocument());
if(_tcsicmp(cmdStr, _T("matchprop"))==0 && curDoc() != NULL)
{
curDoc()->inputPointManager()->removeInputContextReactor(m_pMatchPropertiesReactor);
}
// mcl add 2011.2.12. 保证用户上次选择集没有变化
if (bSaveLastPickset)
{
g_csLastCmd = cmdStr;
PostCommand(_T("ReSelOrig\n"));
}
}
void TDbRelInterfaceReactor::commandEnded(const TCHAR* cmdStr)
{
//add by dyw 2014-7-16 清空风管拉伸命令中的选择集,卸载反应器
if(0 == _tcsicmp(cmdStr, _T("stretch")) && curDoc() != NULL)
{
m_pDuctStretchReactor->m_arrId.setLogicalLength(0);
curDoc()->inputPointManager()->removeInputContextReactor(m_pDuctStretchReactor);
}
//add end
g_csLastCmd.Empty();
// mcl add.2010.05.21 删除时优化处理接口关系
if (_tcsicmp(cmdStr, _T("e")) == 0 || _tcsicmp(cmdStr, _T("erase")) == 0)
OptimizeEraseRelInterface();
int nMaxSetForOp = 0;
g_mapClass2Cmd.GetAt(KEY_MAX_SET_FOROP,nMaxSetForOp);
if (nMaxSetForOp == 2) //优化批量处理interfacerecord 的 update消息
{
if(!m_bNestedUpdate)
OptimizeUpdateRelInterface();
g_mapClass2Cmd.SetAt(KEY_MAX_SET_FOROP,0);
}
// “上华拷贝”命令结束时 更新一下关系
if(0 == _tcsicmp(cmdStr, _T("tzkb")))
{
m_bNestedUpdate = FALSE;
OptimizeUpdateRelInterface();
}
//如果是命令的内部acedcommand 调用undo做标记,则直接返回
int nWithinUndoMark = 0;
GetGlobalContext(_T("undo"),nWithinUndoMark);
if (nWithinUndoMark)
{
curDoc()->inputPointManager()->removeInputContextReactor(m_pMatchPropertiesReactor);
return;
}
//mod liaoy 170704 此后代码放到了commandEndedUser()中
commandEndedUser(cmdStr);
//mod end
}
void TDbRelInterfaceReactor::ParasUrObjectIds(CString& sUr,AcDbObjectIdArray& ids)
{
sUr.MakeLower();
sUr.TrimLeft();
sUr.TrimRight();
sUr.TrimLeft(_T("ur:"));
sUr.TrimRight(_T(","));
if (sUr.IsEmpty()) return;
//123,345,567,768
AcDbObjectId id;
CString sTemp;
int nIndex = -1,nStart = 0;
while(TRUE)
{
nIndex = sUr.Find(_T(","),nStart);
if (nIndex == -1)
{
if (sUr.GetLength() > 0)
{
id.setFromOldId((INT_PTR)_ttoi(sUr));
ids.append(id);
}
break;
}
else
{
sTemp = sUr.Mid(nStart,nIndex);
id.setFromOldId((INT_PTR)_ttoi(sTemp));
ids.append(id);
sTemp = sUr.Mid(nIndex + 1);
sUr = sTemp;
}
}
}
void TDbRelInterfaceReactor::UpdateRelInterface(const AcDbObjectIdArray& arIds)
{
//打开接口记录
TDbInterfaceRecord* pInterfaceRec = NULL;
// change by hh 2011-08-09 接口记录从字典移动到数据库中
BOOL bDowngrade = FALSE;
pInterfaceRec = TAuxTools::GetIntfPtrFromDB();
if(NULL == pInterfaceRec)
{
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();
pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForWrite);
pDict->close();
}
else
{
pNamedDict->close();
}
}
}
else
{
if(Acad::eOk == pInterfaceRec->upgradeOpen())
{
bDowngrade = TRUE;
}
}
// 关系更新
int nRefCount = 0;
AcDbEntity* pEnt = NULL;
// mcl add.2010.05.25 加进度条
int nLen = arIds.length();
acedSetStatusBarProgressMeter(_T("管线关系处理中..."), 0, nLen);
for (int j = 0;j < nLen;j++)
{
acedSetStatusBarProgressMeterPos(j);
// 已删除的id
if (MakesureIsErased(arIds[j]))
continue;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,arIds.at(j),AcDb::kForRead,true))
{
TDbInterfacesObj* pIObj = TDbInterfacesObj::cast(pEnt);
if (pIObj != NULL)
{
TInterface pipeInterface,pipeInterface2;
int nCount = pIObj->GetInterfaceCount();
// revert by hh 2011-05-05 修复字典中的错误接口记录
if (pInterfaceRec)
{
nRefCount = pInterfaceRec->GetObjInterfaceCount(arIds.at(j));
if (nCount != nRefCount)//实体本身的关系记录和接口记录中数量不一致
{
//删除原来的错误关系,重新注册新的关系
pInterfaceRec->Remove(arIds.at(j));
if ( !pIObj->isErased())
{
for (int i = 0;i < nCount;i++)
{
if (pIObj->GetInterface(i,pipeInterface))
{
RegisterInterface(pInterfaceRec,pipeInterface);
}
}
}
}
}
for (int i = 0;i < nCount;i++)
{
pipeInterface.SetCompareRule(0);
if (pIObj->GetInterface(i,pipeInterface))
{
if ( Find(pInterfaceRec,pipeInterface) )
{
if ( MakesureIsErased(pipeInterface.GetConnectObject()) )
{
pipeInterface.SetConnectObject(AcDbObjectId::kNull);
}
else
{
//建立关联关系e
if (Acad::eOk == pIObj->upgradeOpen())
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
pIObj->downgradeOpen();
}
//反向关系建立
pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject());
pipeInterface2.SetPosition(pipeInterface.GetPosition());
pipeInterface2.SetOutDir(-pipeInterface.GetOutDir());
pipeInterface2.SetConnectObject(pIObj->objectId());
SetInterfaceRelation(pInterfaceRec,pipeInterface2);
}
}
else
{
//没有,关系置空
pipeInterface.SetConnectObject(AcDbObjectId::kNull);
}
//1.1 没有接口则 注册接口信息
pipeInterface.SetOwnerId(pIObj->objectId());
if ( !Has(pInterfaceRec,pipeInterface))
{
//注册接口
if ( !pIObj->isErased())
{
RegisterInterface(pInterfaceRec,pipeInterface);
}
}
}
}
}
pEnt->close();
}
}
acedRestoreStatusBar();
if(bDowngrade && NULL != pInterfaceRec)
pInterfaceRec->downgradeOpen();
//关闭接口记录
if (pInterfaceRec != NULL)
pInterfaceRec->close();
}
BOOL TDbRelInterfaceReactor::UpdateInterfaceRelation(TDbInterfaceRecord* pInterfaceRec,TInterface& pipeInterface,
AcGePoint3dArray& arPtsOk,int& nCount,TDbInterfacesObj* pIObj)
{
if (pInterfaceRec != NULL)
{
if (arPtsOk.length() < nCount) //有效的注册的接口,比实际的少, 说明缺接口
{
//去掉有效的接口, 从剩下的无效接口中更正
int nFoundAt = -1;
TInterfaces interfaces;
pInterfaceRec->Find(pipeInterface.GetOwnerId(),interfaces);
// 注册的接口比实体上的少,则注册一下接口
if (interfaces.length() < nCount)
{
RegisterInterface(pInterfaceRec,pipeInterface);
//注册后,寻找新的可建立的关系
if ( Find(pInterfaceRec,pipeInterface))
{
//建立关联关系
if (pIObj->isWriteEnabled())
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
}
else if (Acad::eOk == pIObj->upgradeOpen())
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
pIObj->downgradeOpen();
}
//反向关系建立
TInterface pipeInterface2;
pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject());
pipeInterface2.SetPosition(pipeInterface.GetPosition());
pipeInterface2.SetOutDir(-pipeInterface.GetOutDir());
pipeInterface2.SetConnectObject(pIObj->objectId());
SetInterfaceRelation(pInterfaceRec,pipeInterface2);
}
//本次接口处理完毕,记录下
arPtsOk.append(pipeInterface.GetPosition());
return TRUE;
}
for (int j = 0;j < interfaces.length();j++)
{
if ( !arPtsOk.find(interfaces[j].GetPosition(),nFoundAt)) //该接口不在有效的范围内
{
//更新该无效的接口
pInterfaceRec->Update(pipeInterface.GetOwnerId(),interfaces[j].GetPosition(),pipeInterface.GetPosition());
arPtsOk.append(pipeInterface.GetPosition());
//更新后,寻找新的可建立的关系
if ( Find(pInterfaceRec,pipeInterface))
{
//建立关联关系
if (pIObj->isWriteEnabled())
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
}
else if (Acad::eOk == pIObj->upgradeOpen())
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
pIObj->downgradeOpen();
}
//反向关系建立
TInterface pipeInterface2;
pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject());
pipeInterface2.SetPosition(pipeInterface.GetPosition());
pipeInterface2.SetOutDir(-pipeInterface.GetOutDir());
pipeInterface2.SetConnectObject(pIObj->objectId());
SetInterfaceRelation(pInterfaceRec,pipeInterface2);
}
break;
}
}
}
}
return TRUE;
}
BOOL TDbRelInterfaceReactor::UpdateInterfacePoint(TInterfaceModifyMsg& msg)
{
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if(Acad::eOk == pIntfRec->upgradeOpen())
{
pIntfRec->Update(msg.GetMsgOperateOn(),msg.GetMsgPoint(),msg.GetMsgPoint().transformBy(msg.GetTransform()));
pIntfRec->downgradeOpen();
}
pIntfRec->close();
return TRUE;
}
// 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(msg.GetMsgOperateOn(),msg.GetMsgPoint(),msg.GetMsgPoint().transformBy(msg.GetTransform()));
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
return TRUE;
}
BOOL TDbRelInterfaceReactor::SetInterfaceRelation(TDbInterfaceRecord* pInterfaceRec,const TInterface& pipeInterface)
{
AcDbObjectId idOwner = pipeInterface.GetOwnerId();
AcDbEntity* pEnt = NULL;
if (idOwner.isValid() && Acad::eOk == acdbOpenAcDbEntity(pEnt,idOwner,AcDb::kForWrite,true))
{
TDbInterfacesObj* pIObj = TDbInterfacesObj::cast(pEnt);
if (pIObj != NULL)
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
}
pEnt->close();
}
pInterfaceRec->Update(pipeInterface.GetOwnerId(),pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
pInterfaceRec->Update(pipeInterface.GetConnectObject(),pipeInterface.GetPosition(),pipeInterface.GetOwnerId());
return TRUE;
}
BOOL TDbRelInterfaceReactor::Find(TDbInterfaceRecord* pInterfaceRec,TInterface& pipeInterface)
{
//到命名对象字典中找;
BOOL bSuccess = FALSE;
if (pInterfaceRec != NULL)
{
bSuccess = pInterfaceRec->FindOtherSide(pipeInterface.GetPosition(),pipeInterface.GetOutDir(),
pipeInterface,pipeInterface.GetOwnerId());
}
return bSuccess;
}
BOOL TDbRelInterfaceReactor::Has(TDbInterfaceRecord* pInterfaceRec,TInterface& pipeInterface)
{
//到命名对象字典中找;
BOOL bSuccess = FALSE;
if (pInterfaceRec != NULL)
{
bSuccess = pInterfaceRec->Find(pipeInterface.GetPosition(),pipeInterface.GetOutDir(),pipeInterface.GetOwnerId(),pipeInterface);
}
return bSuccess;
}
BOOL TDbRelInterfaceReactor::RegisterInterface(TDbInterfaceRecord* pInterfaceRec,TInterface& pipeInterface)
{
if (pInterfaceRec != NULL)
{
pInterfaceRec->Add(pipeInterface);
}
return TRUE;
}
void TDbRelInterfaceReactor::PickMakeObjAssocMsgs(TMakeObjAssocMsgs& msgs)
{
CPtrArray* pArray = NULL;
if (g_iMsgContext.m_mapDb2TAMsgs.Lookup(acdbCurDwg(),(void*&)pArray))
{
TDbInterfaceMsgObj* pMsgObj = NULL;
TMakeObjAssocMsg msg;
for (int i = 0;i < pArray->GetSize();i++)
{
pMsgObj = (TDbInterfaceMsgObj*)pArray->GetAt(i);
if (pMsgObj != NULL)
{
pMsgObj->GetAssocMsg(msg);
msgs.append(msg);
delete pMsgObj;
}
}
pArray->RemoveAll();
}
}
void TDbRelInterfaceReactor::PickInterfaceUpdateMsgs(TInterfaceModifyMsgs& msgs)
{
CPtrArray* pArray = NULL;
if (g_iMsgContext.m_mapDb2TUMsgs.Lookup(acdbCurDwg(),(void*&)pArray))
{
TDbInterfaceMsgObj* pMsgObj = NULL;
TInterfaceModifyMsg msg;
for (int i = 0;i < pArray->GetSize();i++)
{
pMsgObj = (TDbInterfaceMsgObj*)pArray->GetAt(i);
if (pMsgObj != NULL)
{
pMsgObj->GetModifyMsg(msg);
msgs.append(msg);
delete pMsgObj;
}
}
pArray->RemoveAll();
}
}
void TDbRelInterfaceReactor::commandCancelled( const TCHAR* cmdStr )
{
if (_tcsicmp(cmdStr, _T("copy")) == 0) // mcl add 2011.3.8 cad的复制后即使按escape取消也要更新关系
commandEnded(cmdStr);
DeleteOptimizeArr();
g_mapClass2Cmd.SetAt(KEY_MAX_SET_FOROP,0);
// commandEnded(cmdStr);
if(_tcsicmp(cmdStr, _T("matchprop"))==0 && curDoc() != NULL)
{
curDoc()->inputPointManager()->removeInputContextReactor(m_pMatchPropertiesReactor);
}
//add by dyw 2014-7-16 清空风管拉伸命令中的选择集,卸载反应器
if(0 == _tcsicmp(cmdStr, _T("stretch")) && curDoc() != NULL)
{
m_pDuctStretchReactor->m_arrId.setLogicalLength(0);
curDoc()->inputPointManager()->removeInputContextReactor(m_pDuctStretchReactor);
}
//add end
}
void TDbRelInterfaceReactor::commandFailed(const TCHAR* cmdStr)
{
DeleteOptimizeArr();
g_mapClass2Cmd.SetAt(KEY_MAX_SET_FOROP,0);
commandEnded(cmdStr);
}
// 判断id是否被删除
BOOL TDbRelInterfaceReactor::MakesureIsErased(const AcDbObjectId& id)
{
BOOL bEr = TRUE;
if (id.isValid())
{
AcDbEntity* pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead))
{
if (Adesk::kFalse == pEnt->isErased())
{
bEr = FALSE;
}
pEnt->close();
}
}
return bEr;
}
BOOL TDbRelInterfaceReactor::OptimizeUpdateRelInterface()
{
// 打开TDbInterfaceRecord,进行接口注册
AcDbObjectIdArray* pIdArr = NULL;
g_iMsgContext.m_mapDb2InfAppended.Lookup((void*)acdbCurDwg(), (void*&)pIdArr);
if (pIdArr != NULL)
{
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if(Acad::eOk == pIntfRec->upgradeOpen())
{
//1. 建立关系
AcDbObjectId idT;
int nArrIndex(0), nIfIndex(0), nCount(0);
int nDepClnFlag(0);
TInterface pipeInterface,pipeInterface2;
TDbInterfacesObj* pIObj = NULL;
AcDbEntity* pEnt = NULL;
for (nArrIndex = 0; nArrIndex < pIdArr->length(); nArrIndex++)
{
pEnt = NULL;
idT = (*pIdArr)[nArrIndex];
acdbOpenAcDbEntity(pEnt, idT, AcDb::kForWrite);
if (pEnt == NULL)
continue;
pIObj = TDbInterfacesObj::cast(pEnt);
if (pIObj == NULL)
{
pEnt->close();
continue;
}
//排除重合
pIObj->GetSpecialtyData()->GetAt(KEY_DEEPCLONEFLAG, nDepClnFlag);
if (nDepClnFlag)
{
pIObj->close();
continue;
}
pipeInterface.Reset();
pipeInterface2.Reset();
nCount = pIObj->GetInterfaceCount();
for (nIfIndex = 0; nIfIndex < nCount; nIfIndex++)
{
pipeInterface.SetCompareRule(0);
if (pIObj->GetInterface(nIfIndex,pipeInterface))
{
if (Find(pIntfRec, pipeInterface))
{
//建立关联关系
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject());
pipeInterface2.SetPosition(pipeInterface.GetPosition());
pipeInterface2.SetOutDir(-pipeInterface.GetOutDir());
pipeInterface2.SetConnectObject(pIObj->objectId());
SetInterfaceRelation(pIntfRec, pipeInterface2);
}
else
{
pipeInterface.SetConnectObject(AcDbObjectId::kNull);
}
// 注册接口信息
pipeInterface.SetOwnerId(idT);
RegisterInterface(pIntfRec, pipeInterface);
}
}
pIObj->UpdateCoverDisplay();
pIObj->close();
}
pIntfRec->downgradeOpen();
}
pIntfRec->close();
}
else
{
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();
//1. 建立关系
AcDbObjectId idT;
int nArrIndex(0), nIfIndex(0), nCount(0);
int nDepClnFlag(0);
TInterface pipeInterface,pipeInterface2;
TDbInterfacesObj* pIObj = NULL;
AcDbEntity* pEnt = NULL;
for (nArrIndex = 0; nArrIndex < pIdArr->length(); nArrIndex++)
{
pEnt = NULL;
// idT.setFromOldId((INT_PTR)pIdArr->GetAt(nArrIndex));
idT = (*pIdArr)[nArrIndex];
acdbOpenAcDbEntity(pEnt, idT, AcDb::kForWrite);
if (pEnt == NULL)
continue;
pIObj = TDbInterfacesObj::cast(pEnt);
if (pIObj == NULL)
{
pEnt->close();
continue;
}
//排除重合
pIObj->GetSpecialtyData()->GetAt(KEY_DEEPCLONEFLAG, nDepClnFlag);
if (nDepClnFlag)
{
pIObj->close();
continue;
}
pipeInterface.Reset();
pipeInterface2.Reset();
nCount = pIObj->GetInterfaceCount();
for (nIfIndex = 0; nIfIndex < nCount; nIfIndex++)
{
pipeInterface.SetCompareRule(0);
if (pIObj->GetInterface(nIfIndex,pipeInterface))
{
if (Find(pInterfaceRec, pipeInterface))
{
//建立关联关系
// if (Acad::eOk == pIObj->upgradeOpen()) 本来就可写
{
pIObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject());
// pIObj->downgradeOpen();
}
pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject());
pipeInterface2.SetPosition(pipeInterface.GetPosition());
pipeInterface2.SetOutDir(-pipeInterface.GetOutDir());
pipeInterface2.SetConnectObject(pIObj->objectId());
SetInterfaceRelation(pInterfaceRec, pipeInterface2);
}
else
{
pipeInterface.SetConnectObject(AcDbObjectId::kNull);
}
// 注册接口信息
pipeInterface.SetOwnerId(idT);
RegisterInterface(pInterfaceRec, pipeInterface);
}
}
pIObj->UpdateCoverDisplay();
pIObj->close();
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
}
g_iMsgContext.m_mapDb2InfAppended.RemoveKey((void*)acdbCurDwg());
delete pIdArr;
// 批量复制操作,也做更新接口关系,提前返回
// 也会产生m_mapDbTInfRecMsgs,所以返回前清空g_iMsgContext.m_mapDbTInfRecMsgs
CPtrArray* pArray = NULL;
g_iMsgContext.m_mapDbTInfRecMsgs.Lookup((void*)acdbCurDwg(),(void*&)pArray);
if (NULL != pArray)
{
delete pArray;
pArray = NULL;
g_iMsgContext.m_mapDbTInfRecMsgs.RemoveKey((void*)acdbCurDwg());
}
return TRUE;
}
CPtrArray* pArray = NULL;
g_iMsgContext.m_mapDbTInfRecMsgs.Lookup((void*)acdbCurDwg(),(void*&)pArray);
if (pArray != NULL)
{
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if(Acad::eOk == pIntfRec->upgradeOpen())
{
TInfUpdate* pInfUpdate = NULL;
TInterface pipeInterface;
TDbInterfacesObj* pObj = NULL;
AcDbEntity* pEnt = NULL;
int nIfIndex(0);
for (int i = 0;i < pArray->GetSize();i++)
{
pInfUpdate = (TInfUpdate*)pArray->GetAt(i);
if (pInfUpdate->nIntf == TDb::eTransformBy)
{
//如果没有注册接口,注册接口
if (!pIntfRec->Find(pInfUpdate->idOwner))
{
pEnt = NULL;
acdbOpenAcDbEntity(pEnt, pInfUpdate->idOwner, AcDb::kForWrite);
if (NULL == pEnt)
continue;
pObj = TDbInterfacesObj::cast(pEnt);
if (NULL == pObj)
{
pEnt->close();
continue;
}
for (nIfIndex = 0; nIfIndex < pObj->GetInterfaceCount(); nIfIndex++)
{
pipeInterface.Reset();
if (pObj->GetInterface(nIfIndex, pipeInterface))
{
pIntfRec->Add(pipeInterface);
}
}
pObj->UpdateCoverDisplay();
pObj->close();
}
else
{
if (pInfUpdate->bInfAll)
{
pIntfRec->TransformBy(pInfUpdate->idOwner,pInfUpdate->xForm);
}
else
{
pIntfRec->TransformBy(pInfUpdate->idOwner,pInfUpdate->ptOld,pInfUpdate->xForm);
}
// mcl add.更新时,也写遮挡消息
pEnt = NULL;
acdbOpenAcDbEntity(pEnt, pInfUpdate->idOwner, AcDb::kForWrite);
if (NULL == pEnt)
continue;
pObj = TDbInterfacesObj::cast(pEnt);
if (NULL == pObj)
{
pEnt->close();
continue;
}
pObj->UpdateCoverDisplay();
pObj->close();
}
}
else if (pInfUpdate->nIntf == TDb::eUpdateIntf)
{
AcGePoint3d ptGeNew = pInfUpdate->ptOld;
ptGeNew.transformBy(pInfUpdate->xForm);
pIntfRec->Update(pInfUpdate->idOwner,pInfUpdate->ptOld,ptGeNew);
}
}
pIntfRec->downgradeOpen();
}
pIntfRec->close();
}
else
{
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();
TInfUpdate* pInfUpdate = NULL;
TInterface pipeInterface;
TDbInterfacesObj* pObj = NULL;
AcDbEntity* pEnt = NULL;
int nIfIndex(0);
for (int i = 0;i < pArray->GetSize();i++)
{
pInfUpdate = (TInfUpdate*)pArray->GetAt(i);
if (pInfUpdate->nIntf == TDb::eTransformBy)
{
//如果没有注册接口,注册接口
if (!pInterfaceRec->Find(pInfUpdate->idOwner))
{
pEnt = NULL;
acdbOpenAcDbEntity(pEnt, pInfUpdate->idOwner, AcDb::kForWrite);
if (NULL == pEnt)
continue;
pObj = TDbInterfacesObj::cast(pEnt);
if (NULL == pObj)
{
pEnt->close();
continue;
}
for (nIfIndex = 0; nIfIndex < pObj->GetInterfaceCount(); nIfIndex++)
{
pipeInterface.Reset();
if (pObj->GetInterface(nIfIndex, pipeInterface))
{
pInterfaceRec->Add(pipeInterface);
}
}
pObj->UpdateCoverDisplay();
pObj->close();
}
else
{
if (pInfUpdate->bInfAll)
{
pInterfaceRec->TransformBy(pInfUpdate->idOwner,pInfUpdate->xForm);
}
else
{
pInterfaceRec->TransformBy(pInfUpdate->idOwner,pInfUpdate->ptOld,pInfUpdate->xForm);
}
// mcl add.更新时,也写遮挡消息
pEnt = NULL;
acdbOpenAcDbEntity(pEnt, pInfUpdate->idOwner, AcDb::kForWrite);
if (NULL == pEnt)
continue;
pObj = TDbInterfacesObj::cast(pEnt);
if (NULL == pObj)
{
pEnt->close();
continue;
}
pObj->UpdateCoverDisplay();
pObj->close();
}
}
else if (pInfUpdate->nIntf == TDb::eUpdateIntf)
{
AcGePoint3d ptGeNew = pInfUpdate->ptOld;
ptGeNew.transformBy(pInfUpdate->xForm);
pInterfaceRec->Update(pInfUpdate->idOwner,pInfUpdate->ptOld,ptGeNew);
}
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
}
TInfUpdate* pInfUpdate = NULL;
for (int i = 0;i < pArray->GetSize();i++)
{
pInfUpdate = (TInfUpdate*)pArray->GetAt(i);
if (pInfUpdate != NULL) delete pInfUpdate;
}
delete pArray;
g_iMsgContext.m_mapDbTInfRecMsgs.RemoveKey((void*)acdbCurDwg());
}
return TRUE;
}
// 优化处理删除后接口处理
void TDbRelInterfaceReactor::OptimizeEraseRelInterface()
{
// 先批量处理删除后,更新接口记录 mcl add 2010.05.19
// CUIntArray* pIdArr = NULL;
AcDbObjectIdArray* pIdArr = NULL;
g_iMsgContext.m_mapDb2InfErase.Lookup((void*)acdbCurDwg(), (void*&)pIdArr);
if (pIdArr != NULL)
{
// add by hh 2011-08-09 接口记录从字典移动到数据库中
TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB();
if(NULL != pIntfRec)
{
if(Acad::eOk == pIntfRec->upgradeOpen())
{
AcDbObjectId idT;
int nArrIndex(0);
AcDbEntity* pEnt = NULL;
for (nArrIndex = 0; nArrIndex < pIdArr->length(); nArrIndex++)
{
pEnt = NULL;
idT = (*pIdArr)[nArrIndex];
pIntfRec->Remove(idT);
pIntfRec->ResetConnect(idT);
}
pIntfRec->downgradeOpen();
}
pIntfRec->close();
g_iMsgContext.m_mapDb2InfErase.RemoveKey((void*)acdbCurDwg());
delete pIdArr;
pIdArr = NULL;
return;
}
// 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();
AcDbObjectId idT;
int nArrIndex(0);
AcDbEntity* pEnt = NULL;
for (nArrIndex = 0; nArrIndex < pIdArr->length(); nArrIndex++)
{
pEnt = NULL;
idT = (*pIdArr)[nArrIndex];
pInterfaceRec->Remove(idT);
pInterfaceRec->ResetConnect(idT);
}
pInterfaceRec->close();
}
else
{
pDict->close();
}
}
else
{
pNamedDict->close();
}
}
g_iMsgContext.m_mapDb2InfErase.RemoveKey((void*)acdbCurDwg());
delete pIdArr;
pIdArr = NULL;
}
}
// mcl add 2010.05.24 开关接口记录是否记忆撤销操作
// void TDbRelInterfaceReactor::TagRecordUndo(Adesk::Boolean bOpen)
// {
// 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))
// {
// TDbInterfaceRecord* pInterfaceRec = NULL;
// if (Acad::eOk == pDict->getAt(KEY_IRECORD,(AcDbObject*&)pInterfaceRec,AcDb::kForWrite))
// {
// pInterfaceRec->disableUndoRecording(!bOpen);
// pInterfaceRec->close();
// }
// pDict->close();
// }
// pNamedDict->close();
// }
// }
void TDbRelInterfaceReactor::DeleteOptimizeArr()
{
int nMaxSetForOp = 0;
g_mapClass2Cmd.GetAt(KEY_MAX_SET_FOROP,nMaxSetForOp);
if (nMaxSetForOp != 2) //优化批量处理标志
return;
// 依次删除各个优化数组
AcDbObjectIdArray* pIdArr = NULL;
g_iMsgContext.m_mapDb2InfAppended.Lookup((void*)acdbCurDwg(), (void*&)pIdArr);
if (pIdArr != NULL)
{
g_iMsgContext.m_mapDb2InfAppended.RemoveKey((void*)acdbCurDwg());
delete pIdArr;
}
CPtrArray* pArray = NULL;
g_iMsgContext.m_mapDbTInfRecMsgs.Lookup((void*)acdbCurDwg(),(void*&)pArray);
if (pArray != NULL)
{
TInfUpdate* pInfUpdate = NULL;
for (int i = 0;i < pArray->GetSize();i++)
{
pInfUpdate = (TInfUpdate*)pArray->GetAt(i);
if (pInfUpdate != NULL)
delete pInfUpdate;
}
g_iMsgContext.m_mapDbTInfRecMsgs.RemoveKey((void*)acdbCurDwg());
delete pArray;
}
pIdArr = NULL;
g_iMsgContext.m_mapDb2InfErase.Lookup((void*)acdbCurDwg(), (void*&)pIdArr);
if (pIdArr != NULL)
{
g_iMsgContext.m_mapDb2InfErase.RemoveKey((void*)acdbCurDwg());
delete pIdArr;
}
}