#include "stdafx.h" #include "TMakeObjAssocManager.h" #include "TReactorUnlockSwitch.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif extern TDbMakeObjAssocReactor* g_pObjAssocReactor; TMakeObjAssocManager::TMakeObjAssocManager() { } TMakeObjAssocManager::~TMakeObjAssocManager() { } BOOL TMakeObjAssocManager::RepairInterfaceRelation(AcDbDatabase* pDb,TDbInterfacesObj* pObj) { if (pDb == NULL || pObj == NULL) return FALSE; //1. 获取接口的个数,注册接口的个数 int nCountThis = pObj->GetInterfaceCount(); int nCountRegs = 0; //到命名对象字典中找; AcGePoint3d ptCon; AcGeVector3d vtDir; BOOL bSuccess = FALSE; // add by hh 2011-08-09 接口记录从字典移动到数据库中 TDbInterfaceRecord* pIntfRec = TAuxTools::GetIntfPtrFromDB(); if(NULL != pIntfRec) { if(Acad::eOk == pIntfRec->upgradeOpen()) { //统一删除接口记录,重新添加接口,尝试建立关系 pIntfRec->Remove(pObj->objectId()); TInterface pipeInterface,pipeInterface2; for (int i = 0;i < nCountThis;i++) { pipeInterface.SetCompareRule(0); if (pObj->GetInterface(i,pipeInterface)) { //1.1 注册接口信息 pipeInterface.SetOwnerId(pObj->objectId()); pIntfRec->Add(pipeInterface); //1.2 尝试建立关系 ptCon = pipeInterface.GetPosition(); vtDir = pipeInterface.GetOutDir(); bSuccess = pIntfRec->FindOtherSide(ptCon,vtDir,pipeInterface,pipeInterface.GetOwnerId()); if (bSuccess) { //建立关联关系 pObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject()); pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject()); pipeInterface2.SetPosition(pipeInterface.GetPosition()); pipeInterface2.SetOutDir(-pipeInterface.GetOutDir()); pipeInterface2.SetConnectObject(pObj->objectId()); AcDbEntity* pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt,pipeInterface.GetConnectObject(),AcDb::kForWrite,true)) { TDbInterfacesObj* pIObj2 = TDbInterfacesObj::cast(pEnt); if (pIObj2 != NULL) { pIObj2->SetInterfaceRelation(pipeInterface2.GetPosition(),pipeInterface2.GetConnectObject()); } pEnt->close(); } pIntfRec->Update(pipeInterface2.GetOwnerId(),pipeInterface2.GetPosition(),pipeInterface2.GetConnectObject()); pIntfRec->Update(pipeInterface2.GetConnectObject(),pipeInterface2.GetPosition(),pipeInterface2.GetOwnerId()); } } } pIntfRec->downgradeOpen(); } pIntfRec->close(); return bSuccess; } // add end AcDbDictionary* pNamedDict = NULL; if (Acad::eOk == ((AcDbDatabase*)pDb)->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->Remove(pObj->objectId()); TInterface pipeInterface,pipeInterface2; for (int i = 0;i < nCountThis;i++) { pipeInterface.SetCompareRule(0); if (pObj->GetInterface(i,pipeInterface)) { //1.1 注册接口信息 pipeInterface.SetOwnerId(pObj->objectId()); pInterfaceRec->Add(pipeInterface); //1.2 尝试建立关系 ptCon = pipeInterface.GetPosition(); vtDir = pipeInterface.GetOutDir(); bSuccess = pInterfaceRec->FindOtherSide(ptCon,vtDir,pipeInterface,pipeInterface.GetOwnerId()); if (bSuccess) { //建立关联关系 pObj->SetInterfaceRelation(pipeInterface.GetPosition(),pipeInterface.GetConnectObject()); pipeInterface2.SetOwnerId(pipeInterface.GetConnectObject()); pipeInterface2.SetPosition(pipeInterface.GetPosition()); pipeInterface2.SetOutDir(-pipeInterface.GetOutDir()); pipeInterface2.SetConnectObject(pObj->objectId()); AcDbEntity* pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt,pipeInterface.GetConnectObject(),AcDb::kForWrite,true)) { TDbInterfacesObj* pIObj2 = TDbInterfacesObj::cast(pEnt); if (pIObj2 != NULL) { pIObj2->SetInterfaceRelation(pipeInterface2.GetPosition(),pipeInterface2.GetConnectObject()); } pEnt->close(); } pInterfaceRec->Update(pipeInterface2.GetOwnerId(),pipeInterface2.GetPosition(),pipeInterface2.GetConnectObject()); pInterfaceRec->Update(pipeInterface2.GetConnectObject(),pipeInterface2.GetPosition(),pipeInterface2.GetOwnerId()); } } } pInterfaceRec->close(); } else { pDict->close(); } } else { pNamedDict->close(); } } return TRUE; }