#include "stdafx.h" #include "StdArx.h" #include "THImpHvacBroSymbol.h" #include "TDbInterfaceRecord.h" #include "TDbXDataMap.h" #include "TDbInterfaceMsgWrite.h" #include "math.h" #include "dbxutil.h" #include "dbsymutl.h" using namespace TDb; THImpHvacBroSymbol::THImpHvacBroSymbol() { } THImpHvacBroSymbol::~THImpHvacBroSymbol() { } Acad::ErrorStatus THImpHvacBroSymbol::getClassID(CLSID* pClsid) const { // #if (ADS < 16) // // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6E5} // CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE5 }}; // #endif // // #if (ADS == 16) // // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6E5} // CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE6 }}; // #endif // // #if (ADS == 17) // // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6E7} // CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE7 }}; // #endif // // #if (ADS == 18) // CLSID CLSID_PipeBaseEntity = {0xD7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE8 }}; // #endif // // #if (ADS == 19) // CLSID CLSID_PipeBaseEntity = {0xD7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xE8 }}; // #endif return Acad::eOk; } BOOL THImpHvacBroSymbol::OPMInfo(LPCTSTR pszName, TDb::OPMInfo* pInfo) { ASSERT(NULL != pszName && NULL != pInfo && NULL != m_pXDataMap); // 暖通基本参数设置 if (0 == _tcsicmp(pszName, KEY_RUNTIME)) { pInfo->bVisible = TRUE; pInfo->bEditable = FALSE; // 提供数据列表和对应关系 if (NULL != pInfo->parsValues && NULL != pInfo->parlValues) { pInfo->parsValues->Add(_T("断管符号")); pInfo->parlValues->Add(TDb::eBroSymbol); } // 全局属性,需要特殊处理数据获取和设置 if (NULL != pInfo->pXData) { // 获取数据 if (0 == pInfo->pXData->nVt) { pInfo->pXData->nVt = TXINT; pInfo->pXData->nVal = TDb::eBroSymbol; } // 设置数据 else { pInfo->pXData->nVt = 0; // 设置处理完成标识 } } return TRUE; } if (0 == _tcsicmp(pszName, HVAC_SectType)) { pInfo->bVisible = TRUE; pInfo->bEditable = TRUE; // 提供数据列表和对应关系 if (NULL != pInfo->parsValues && NULL != pInfo->parlValues) { pInfo->parsValues->Add(_T("矩形")); pInfo->parlValues->Add(TDb::eRectangular); pInfo->parsValues->Add(_T("圆形")); pInfo->parlValues->Add(TDb::eCircular); } return TRUE; } if (0 == _tcsicmp(pszName, HVAC_HasBaseLine)) { pInfo->bVisible = FALSE; pInfo->bEditable = TRUE; // 提供数据列表和对应关系 if (NULL != pInfo->parsValues && NULL != pInfo->parlValues) { pInfo->parsValues->Add(_T("隐藏")); pInfo->parlValues->Add(0); pInfo->parsValues->Add(_T("显示")); pInfo->parlValues->Add(1); } return TRUE; } if (0 == _tcsicmp(pszName, HVAC_IsSingleLine)) { pInfo->bVisible = TRUE; pInfo->bEditable = TRUE; // 提供数据列表和对应关系 if (NULL != pInfo->parsValues && NULL != pInfo->parlValues) { pInfo->parsValues->Add(_T("双线")); pInfo->parlValues->Add(0); pInfo->parsValues->Add(_T("单线")); pInfo->parlValues->Add(1); } TAuxTools::SetAndUpdateCover((TDbInterfacesObj*)m_pOwnerEnt, pszName, pInfo); return TRUE; } // 获得单线状态,当状态为单线时不显示 BOOL bSingleLine = FALSE; m_pXDataMap->GetAt(HVAC_IsSingleLine, bSingleLine); return FALSE; } void THImpHvacBroSymbol::GetTips(CMapStringToString& mapLable2Tip) const { } void THImpHvacBroSymbol::list() const { ASSERT(NULL != m_pXDataMap); // 管件类型 acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t\t\t 暖通:断管符号")); // 截面类型 HvacSectType eSectType = eRectangular; m_pXDataMap->GetAt(HVAC_SectType, (int&)eSectType); switch (eSectType) { case TDb::eRectangular: acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t\t\t 截面:矩形")); break; case TDb::eCircular: acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t\t\t 截面:圆形")); break; case TDb::eOblate: acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t\t\t 截面:扁圆形")); break; } // 外围宽 double dSkirtSize = 0.0; m_pXDataMap->GetAt(HBSM_SkirtSize, dSkirtSize); // add by zh 2013-5-20 根据出图比例计算出头长度 double dPScale = ((TDbInterfacesObj*)m_pOwnerEnt)->GetPrintScale(); if (dPScale < 1.e-3) dPScale = 1.0; dSkirtSize *= dPScale/100; // acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t出头量:%.2f"), dSkirtSize); // 圆型截面显示直径 if (TDb::eCircular == eSectType) { double dDiameter = 0.0; m_pXDataMap->GetAt(HBSM_Diameter, dDiameter); acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t直径:%.2f"), dDiameter); } // 非圆型截面显示宽度和厚度 else { double dWidth = 0.0, dThick = 0.0; m_pXDataMap->GetAt(HBSM_Width, dWidth); m_pXDataMap->GetAt(HBSM_Thick, dThick); acutPrintf(_T("\n\t\t\t\t\t\t\t\t\t宽度:%.2f\t 厚度:%.2f"), dWidth, dThick); } // 插入点 AcGePoint3d pt; m_pXDataMap->GetAt(HBSM_InsertPoint, pt); acutPrintf(_T("\n\t\t\t\t\t\t\t\t自 点,X=%.4f\t Y=%.4f\t Z=%.4f"), pt.x, pt.y, pt.z); } BOOL THImpHvacBroSymbol::IsSingleLine() const { ASSERT(NULL != m_pXDataMap); BOOL bSingleLine = FALSE; m_pXDataMap->GetAt(HVAC_IsSingleLine, (int&)bSingleLine); return bSingleLine; } void THImpHvacBroSymbol::GetKindName(CString& sName) { sName = _T("TCH_HBROSYMBOL"); } int THImpHvacBroSymbol::GetInterfaceCount() const { // 返回接口个数 return 1; } BOOL THImpHvacBroSymbol::GetInterfaceSizeData(int nIndex, TInterface& pipeInterface) const { ASSERT(NULL != m_pXDataMap); // 获取截面类型 TDb::HvacSectType eSectType = TDb::eRectangular; m_pXDataMap->GetAt(HVAC_SectType, (int&)eSectType); // 获取接口截面、宽度、厚度数据key值 LPCTSTR pszWidthKey, pszThickKey; switch (nIndex) { case 0: pszWidthKey = ((TDb::eCircular == eSectType) ? HBSM_Diameter : HBSM_Width); pszThickKey = HBSM_Thick; break; default: return FALSE; } // 获取尺寸 double dWidth = 0.0, dThick = 0.0; m_pXDataMap->GetAt(pszWidthKey, dWidth); m_pXDataMap->GetAt(pszThickKey, dThick); // 设置接口数据 pipeInterface.SetType(eSectType); pipeInterface.SetSize(dWidth, dThick); return TRUE; } BOOL THImpHvacBroSymbol::GetInterface(int nIndex, TInterface& pipeInterface) const { if (NULL == m_pXDataMap) return FALSE; // 获取变径各点位置 AcGePoint3d ptInsert; AcGeVector3d vtDir; m_pXDataMap->GetAt(HBSM_InsertPoint, ptInsert); m_pXDataMap->GetAt(HBSM_Dir, vtDir); AcDbObjectId id; switch(nIndex) { case 0: // 如果起始接口和第一个管件连接 if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptInsert, vtDir, pipeInterface)) { GetInterfaceSizeData(nIndex, pipeInterface); return TRUE; } // 没有管件连接 pipeInterface.SetOutDir(vtDir); pipeInterface.SetOwnerId(m_pOwnerEnt->objectId()); pipeInterface.SetPosition(ptInsert); GetInterfaceSizeData(nIndex, pipeInterface); return TRUE; } return FALSE; } BOOL THImpHvacBroSymbol::GetInterface(const AcGePoint3d& ptConnect,TInterface& pipeInterface) const { if (NULL == m_pXDataMap) return FALSE; // 获取变径各点位置 AcGePoint3d ptInsert; AcGeVector3d vtDir; m_pXDataMap->GetAt(HBSM_InsertPoint, ptInsert); m_pXDataMap->GetAt(HBSM_Dir, vtDir); // 计算测试点到始末点的距离 double dDist = ptConnect.distanceTo(ptInsert); AcDbObjectId id; // 位于起始点 if (dDist < 1.e-3) { // 如果起始接口和第一个管件连接 if (m_pXDataMap->GetAt(KEY_IDCNT1, id) && MakesureInterfaceValidate(id, ptInsert, vtDir, pipeInterface)) { GetInterfaceSizeData(0, pipeInterface); return TRUE; } // 没有管件连接 pipeInterface.SetOutDir(vtDir); pipeInterface.SetOwnerId(m_pOwnerEnt->objectId()); pipeInterface.SetPosition(ptInsert); GetInterfaceSizeData(0, pipeInterface); return TRUE; } return FALSE; } BOOL THImpHvacBroSymbol::HasInterface(const AcGePoint3d& ptConnect,const AcGeVector3d& vtDir) { if (NULL == m_pXDataMap) return FALSE; // 获取变径各点位置 AcGePoint3d ptInsert; AcGeVector3d vtMainDir; m_pXDataMap->GetAt(HBSM_InsertPoint, ptInsert); m_pXDataMap->GetAt(HBSM_Dir, vtMainDir); // 计算测试点到始末点的距离 double dDist = ptConnect.distanceTo(ptInsert); // 位于起始点 if (dDist < 1.e-3) return (vtDir.isParallelTo(vtMainDir)); return FALSE; } BOOL THImpHvacBroSymbol::SetInterfaceRelation(const AcGePoint3d& ptConnect,const AcDbObjectId& idConnect) { if (NULL == m_pXDataMap) return FALSE; if ( !idConnect.isValid() ) return FALSE; // 打开对象 AcDbEntity* pEnt; if (Acad::eOk != acdbOpenObject(pEnt, idConnect, AcDb::kForRead)) return FALSE; // 检查对象类型,是否是暖通管件 if (!(pEnt->isKindOf(TDbHvacDuct::desc()) || pEnt->isKindOf(TDbHvacFitting::desc()) || pEnt->isKindOf(TDbHvacEquipment::desc()))) { pEnt->close(); return FALSE; } // 获取变径各点位置 AcGePoint3d ptInsert; AcGeVector3d vtDir; m_pXDataMap->GetAt(HBSM_InsertPoint, ptInsert); m_pXDataMap->GetAt(HBSM_Dir, vtDir); // 计算测试点到始末点的距离 double dDist = ptConnect.distanceTo(ptInsert); // 基类指针 TDbInterfacesObj* pInterfaceObj = TDbInterfacesObj::cast(pEnt); ASSERT(NULL != pInterfaceObj); // 位于起始点 if (dDist < 1.e-3 && pInterfaceObj->HasInterface(ptInsert, vtDir)) { m_pXDataMap->SetAt(KEY_IDCNT1, idConnect); pEnt->close(); return TRUE; } pEnt->close(); return FALSE; } BOOL THImpHvacBroSymbol::RemoveInterfaceRelation(const AcGePoint3d& ptConnect,const AcDbObjectId& idConnect) { if (NULL == m_pXDataMap) return FALSE; // 浅层次删除; 命名字典中的关系,需要外面移除关系,只移除内部关系 AcDbObjectId id; m_pXDataMap->GetAt(KEY_IDCNT1, id); if (id == idConnect) { m_pXDataMap->SetAt(KEY_IDCNT1, AcDbObjectId::kNull); return TRUE; } return FALSE; } BOOL THImpHvacBroSymbol::NotifyInterfaceToModify(const TInterfaceModifyMsg& iModiMsg,TInterfaceModifyMsgs& iModiMsgs) { if (NULL == m_pXDataMap) return FALSE; // 获得消息传递设置, 确定是否传递消息 CString sDispatch = _T("0"); GetGlobalContext(KEY_DISPATCHMSG, sDispatch); BOOL bDispatch = (_ttoi(sDispatch) != 0); BOOL bMsgTranslate = FALSE; // 获得消息类型, 根据消息类型处理 TDb::InterfaceOper eOper = iModiMsg.GetInterfaceOper(); switch (eOper) { case TDb::eMoveGripPoint: // 夹点移动消息处理 bMsgTranslate = OnMoveGripPointMsgNotify(iModiMsg, iModiMsgs); break; case TDb::eTransformBy: // 对象移动消息处理 bMsgTranslate = OnTransformMsgNotify(iModiMsg, iModiMsgs); break; case TDb::eSize: // 尺寸调整消息处理 bMsgTranslate = OnSizeMsgNotify(iModiMsg, iModiMsgs); break; default: return bMsgTranslate; } // 记录修改标识 if (m_pOwnerEnt != NULL) m_pOwnerEnt->recordGraphicsModified(); return bMsgTranslate; } Acad::ErrorStatus THImpHvacBroSymbol::ExplodeOrDraw2d(XExplodeDraw &mode) const { if (m_pXDataMap == NULL) { return Acad::eNotImplementedYet; } TComplexCurve cplCurve; MakeCurves(cplCurve); TDbExtentsEdge edage; edage.SetEdage(cplCurve); BOOL bWeight = FALSE; // m_pXDataMap->GetAt(KEY_EDAGEWEIGHT,bWeight); AcDbObjectId idReal = ((TDbInterfacesObj*)m_pOwnerEnt)->layerId(); AcDbObjectId idDash = ((TDbInterfacesObj*)m_pOwnerEnt)->DashLayer(); AcDbObjectId idCent = ((TDbInterfacesObj*)m_pOwnerEnt)->CenterLayer(); edage.ExplodeOrDraw2d(mode,idReal,idDash,idCent,NULL,bWeight,FALSE); return Acad::eOk; } BOOL THImpHvacBroSymbol::MakeCurves(TComplexCurve& cplCurve) const { if (NULL == m_pXDataMap) return FALSE; else { return MakeBroSymbol2D(cplCurve); } return FALSE; } Acad::ErrorStatus THImpHvacBroSymbol::transformBy(const AcGeMatrix3d& xform) { if (NULL == m_pXDataMap) return Acad::eNotApplicable; // 取得位置点 AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint, ptIns); // 变换位置 ptIns.transformBy(xform); // 更新点 m_pXDataMap->SetAt(HBSM_InsertPoint, ptIns); // 设置尺寸 double dScale = xform.scale(); double dWidth(0.0), dThick(0.0), dSkitSize(0.0); m_pXDataMap->GetAt(HBSM_SkirtSize, dSkitSize); // add by zh 2013-5-20 根据出图比例计算出头长度 // double dPScale = ((TDbInterfacesObj*)m_pOwnerEnt)->GetPrintScale(); // if (dPScale < 1.e-3) dPScale = 1.0; // dSkitSize *= dPScale/100; // m_pXDataMap->GetAt(HBSM_Width, dWidth); m_pXDataMap->GetAt(HBSM_Thick, dThick); dWidth *= dScale; dThick *= dScale; dSkitSize *= dScale; m_pXDataMap->SetAt(HBSM_SkirtSize, dSkitSize); m_pXDataMap->SetAt(HBSM_Width, dWidth); m_pXDataMap->SetAt(HBSM_Thick, dThick); // 传递消息及更新接口记录 if (m_pOwnerEnt != NULL && m_pOwnerEnt->objectId().isValid()) { // 如果实体不是在当前模型空间中,不做写消息,更新接口处理 AcDbDatabase* pDb = m_pOwnerEnt->database(); if (pDb == NULL) pDb = acdbCurDwg(); AcDbObjectId idModel; AcDbBlockTable* pTable = NULL; pDb->getBlockTable(pTable, AcDb::kForRead); if (pTable != NULL) { pTable->getAt(ACDB_MODEL_SPACE, idModel); pTable->close(); } // 如果实体不是在当前模型空间中,不做写消息,更新接口处理 if (idModel == m_pOwnerEnt->blockId()) { // 写入接口更改消息 TInterfaceModifyMsg iMsg; iMsg.SetMsgValidate(TRUE); iMsg.SetTransform(xform); iMsg.SetMsgOperateOn(m_pOwnerEnt->objectId()); iMsg.SetInterfaceOper(TDb::eAutoWorkOn); TDbInterfaceMsgWrite msgWrite; msgWrite.WriteInterfaceMsg(iMsg); //更新接口记录接口信息 UpdateInterfaceRec(m_pOwnerEnt->objectId(), xform); } } return Acad::eOk; } TDb::Position THImpHvacBroSymbol::ExplainGripIndex(int nIndex) const { TDb::Position ePos = TDb::eStart; switch(nIndex) { case 0: ePos = TDb::eMid; } return ePos; } Acad::ErrorStatus THImpHvacBroSymbol::getStretchPoints(AcGePoint3dArray& stretchPoints) const { if (NULL == m_pXDataMap) return Acad::eNotApplicable; // 取得位置点 AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint, ptIns); stretchPoints.append(ptIns); return Acad::eOk; } Acad::ErrorStatus THImpHvacBroSymbol::getGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { if (NULL == m_pXDataMap) return Acad::eNotApplicable; //取得位置点 AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint, ptIns); // 增加夹点 gripPoints.append(ptIns); return Acad::eOk; } Acad::ErrorStatus THImpHvacBroSymbol::getOsnapPoints(AcDb::OsnapMode osnapMode, INT_PTR gsSelectionMark, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { if (NULL == m_pXDataMap) return Acad::eNotApplicable; HvacDuctType eType = eStraight; m_pXDataMap->GetAt(HDCT_Type, (int&)eType); AcGePoint3dArray arPts; AcDbPolyline poly; if (eType == eStraight) { if (GetSectInsertPt(arPts, poly)) { if (poly.numVerts() > 0) { poly.getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform, snapPoints,geomIds); } } } else if (eType == eSoft) { if (GetCirInsertPt(arPts)) ; else return Acad::eNotImplementedYet; } return Acad::eOk; } Acad::ErrorStatus THImpHvacBroSymbol::moveStretchPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { if (indices.length() < 2) return Acad::eNotImplementedYet; AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint, ptIns); ptIns += offset; m_pXDataMap->SetAt(HBSM_InsertPoint, ptIns); if (m_pOwnerEnt != NULL && m_pOwnerEnt->objectId().isValid()) { //更新自身模型空间的扩展字典的接口信息 UpdateInterfaceRec(m_pOwnerEnt->objectId(), offset); return Acad::eOk; } return Acad::eNotImplementedYet; } Acad::ErrorStatus THImpHvacBroSymbol::moveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { return OnCHorEqualRMoveGripPointsAt(indices,offset); } Acad::ErrorStatus THImpHvacBroSymbol::OnCHorEqualRMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) { ASSERT(NULL != m_pXDataMap); // 如果有多个点,则去除命令点后,有多个点时作为移动,单个点时使用该点类型 TDb::Position ePos; if (indices.length() == 1) { // 单个夹点 ePos = ExplainGripIndex(indices[0]); } else { // 多个夹点 int iCount = 0; TDb::Position eTemp; int iPos = indices.length(); while ((--iPos) >= 0 && iCount < 2) { eTemp = ExplainGripIndex(indices[iPos]); switch (eTemp) { case TDb::eMid: ePos = eTemp; iCount++; break; } } // 多个命令夹点不处理 if (iCount == 0) return Acad::eOk; // 多个非命令夹点,移动整体 if (iCount > 1) { // 法兰夹点只是移动操作,移动最后一个夹点 } } // 取得位置点 AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint, ptIns); switch(ePos) { case TDb::eMid: MoveGripRandom(ePos, offset); //更新自身模型空间的扩展字典的接口信息 UpdateInterfaceRec(m_pOwnerEnt->objectId(), offset); break; default: break; } return Acad::eOk; } // 拖拽管件,支持转向等操作 Acad::ErrorStatus THImpHvacBroSymbol::MoveGripRandom(TDb::Position ePos, const AcGeVector3d& offset ) { AcGePoint3d ptDrag; if (ePos == eMid) m_pXDataMap->GetAt(HBSM_InsertPoint, ptDrag); TInterfaceModifyMsg iMsg; iMsg.SetMsgPoint(ptDrag); iMsg.SetGripPosition(ePos); iMsg.SetMoveGripOffset(offset); iMsg.SetMsgValidate(TRUE); iMsg.SetInterfaceOper(eNewCommand); iMsg.SetPreviewObjToCreate(eBroSymbol, 0); // 写入接口更改消息 AcDbSoftPointerId idOwner; m_pXDataMap->GetAt(KEY_THISID, idOwner); iMsg.SetMsgOperateOn(idOwner); TDbInterfaceMsgWrite msgWrite; msgWrite.WriteInterfaceMsg(iMsg); // 发送消息 acedPostCommand(_T("\33")); acedPostCommand(_T("znyd\n")); return Acad::eOk; } BOOL THImpHvacBroSymbol::OnMoveGripPointMsgNotify(const TInterfaceModifyMsg& iModiMsg, TInterfaceModifyMsgs& iModiMsgs) { if (!TAuxTools::IsAutoWorkOffset()) return FALSE; ASSERT(NULL != m_pXDataMap); BOOL bMsgTranslate = FALSE; AcDbObjectId id = iModiMsg.GetMsgOperateOn(); if (id != m_pOwnerEnt->objectId()) // 消息发送目标正确 return FALSE; AcGeVector3d vtOffset = iModiMsg.GetMoveGripOffset(); if (vtOffset.isZeroLength()) return FALSE; AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint,ptIns); AcGePoint3d ptGeInsOld = ptIns; AcGeVector3d vtDir; m_pXDataMap->GetAt(HBSM_Dir, vtDir); int nPos = iModiMsg.GetGripPosition(); if (nPos == eStart || nPos == eMid || nPos == eEnd || nPos == eBr1 || nPos == eBr2) { ptIns += vtOffset; m_pXDataMap->SetAt(HBSM_InsertPoint,ptIns); // 构造接口消息传递 开始端检查 AcDbObjectId idT; if (FindConnect(ptGeInsOld,vtDir,m_pOwnerEnt->objectId(),idT)) // sta 点的接口 { TInterfaceModifyMsg msg; msg.SetMsgPoint(ptGeInsOld); msg.SetMoveGripOffset(vtOffset); msg.SetMsgOperateOn(idT); msg.SetGripPosition(eStart); iModiMsgs.append(msg); bMsgTranslate = TRUE; } // 更新模型空间的扩展字典的注册的接口数据 AcGeMatrix3d xform; xform.setToTranslation(vtOffset); UpdateInterfaceRec(m_pOwnerEnt->objectId(), xform); } return bMsgTranslate; } BOOL THImpHvacBroSymbol::OnTransformMsgNotify(const TInterfaceModifyMsg& iModiMsg, TInterfaceModifyMsgs& iModiMsgs) { if (!TAuxTools::IsAutoWorkOffset()) return FALSE; ASSERT(NULL != m_pXDataMap); BOOL bMsgTranslate = FALSE; AcDbObjectId id = iModiMsg.GetMsgOperateOn(); if (id != m_pOwnerEnt->objectId()) // 消息发送目标正确 return FALSE; AcGeMatrix3d mtTrans = iModiMsg.GetTransform(); AcGePoint3d ptIns; AcGeVector3d vtDir; m_pXDataMap->GetAt(HBSM_InsertPoint,ptIns); m_pXDataMap->GetAt(HBSM_Dir,vtDir); AcGePoint3d ptInsOld = ptIns; ptIns.transformBy(mtTrans); m_pXDataMap->SetAt(HBSM_InsertPoint,ptIns); // 构造接口消息传递 开始端检查 AcDbObjectId idT; if (FindConnect(ptInsOld, vtDir, m_pOwnerEnt->objectId(), idT)) // sta 点的接口 { TInterfaceModifyMsg msg; msg.SetMsgPoint(ptInsOld); msg.SetTransform(mtTrans); msg.SetMsgOperateOn(idT); iModiMsgs.append(msg); bMsgTranslate = TRUE; } // 更新模型空间的扩展字典的注册的接口数据 UpdateInterfaceRec(m_pOwnerEnt->objectId(), mtTrans); return bMsgTranslate; return FALSE; } BOOL THImpHvacBroSymbol::OnSizeMsgNotify(const TInterfaceModifyMsg& iModiMsg, TInterfaceModifyMsgs& iModiMsgs) { ASSERT(NULL != m_pXDataMap); AcGePoint3d ptOrigIns; AcGeVector3d vtDir; m_pXDataMap->GetAt(HBSM_InsertPoint, ptOrigIns); m_pXDataMap->GetAt(HBSM_Dir,vtDir); // 设置各接口新尺寸 HvacSectType eSect = TDb::eRectangular; m_pXDataMap->GetAt(HVAC_SectType, (int&)eSect); double dNewWidth, dNewHeigh(0.0); if (eSect == TDb::eRectangular) { AcGeVector3d vtNormal = normal(); AcGeVector3d vtWidthDir, vtHeighDir; iModiMsg.GetSizeDir(vtWidthDir, vtHeighDir); // 判断是否是空间连接或导致宽高互换 if (vtHeighDir.isParallelTo(vtNormal)) iModiMsg.GetSize(dNewWidth, dNewHeigh); else iModiMsg.GetSize(dNewHeigh, dNewWidth); } else if (eSect == TDb::eCircular) { iModiMsg.GetSize(dNewWidth, dNewHeigh); dNewHeigh = dNewWidth; } AcGeVector3d vtOff = iModiMsg.GetMoveGripOffset(); AcGePoint3d ptNewIns = ptOrigIns+ vtOff; m_pXDataMap->SetAt(HBSM_Width, dNewWidth); m_pXDataMap->SetAt(HBSM_Thick, dNewHeigh); m_pXDataMap->SetAt(HBSM_InsertPoint, ptNewIns); vtDir.transformBy(vtOff); // 消息传递 AcGeVector3d vtLine = vtDir.transformBy(vtOff); AcDbObjectId idFind; if (FindConnect(ptOrigIns, -vtLine, m_pOwnerEnt->objectId(), idFind)) // sta 点的接口 { TInterfaceModifyMsg iMsg = iModiMsg; iMsg.SetMsgOperateOn(idFind); iMsg.SetMsgPoint(ptOrigIns); iModiMsgs.append(iMsg); } if (!ptOrigIns.isEqualTo(ptNewIns, g_globalTol)) ((TDbInterfacesObj*)m_pOwnerEnt)->UpdateInterfaceRec(ptOrigIns, ptNewIns); return TRUE; } int THImpHvacBroSymbol::AutoAppendPt(TComplexCurve &cplCurve, TCurveElement &cplEle, AcGePoint3d &ptS, AcGePoint3d &ptMid, AcGePoint3d &ptE) const { cplEle.ptGe[0] = ptS; cplEle.ptGe[1] = ptMid; cplEle.ptGe[2] = ptE; return cplCurve.append(cplEle); } BOOL THImpHvacBroSymbol::MakeBroSymbol2D(TComplexCurve& cplCurve) const { AcGePoint3dArray arPts; int iSectType = 2; AcGePoint3d ptBase; m_pXDataMap->GetAt(HBSM_InsertPoint, ptBase); m_pXDataMap->GetAt(HVAC_SectType, iSectType); // 计算方向向量 AcGeVector3d vtNormal = AcGeVector3d::kIdentity; AcGeVector3d vtDir = AcGeVector3d::kIdentity; m_pXDataMap->GetAt(KEY_NORMAL, vtNormal); m_pXDataMap->GetAt(HBSM_Dir, vtDir); vtDir = vtDir.normalize(); vtDir.rotateBy(PI / 2.0, vtNormal); double dWidth = 0.0, dDiameter = 0.0; m_pXDataMap->GetAt(HBSM_Width, dWidth); m_pXDataMap->GetAt(HBSM_Diameter, dDiameter); AcGePoint3d ptS, ptE; if (TDb::eRectangular == iSectType) { ptS = ptBase + vtDir*(dWidth/2); ptE = ptBase - vtDir*(dWidth/2); } else if (TDb::eCircular == iSectType) { ptS = ptBase + vtDir*(dDiameter/2); ptE = ptBase - vtDir*(dDiameter/2); } // 添加边 TDb::TCurveElement el; memset(&el, 0, sizeof(TDb::TCurveElement)); double dEdgeWidth = GetEdgeLineWidth(); el.dWidth = dEdgeWidth; AcDbPolyline poly; if (!IsSingleLine()) { if (TDb::eRectangular == iSectType) { if (GetSectInsertPt(arPts, poly)) { for(int i = 0; i < arPts.length() - 1; i++) { AutoAppendPt(cplCurve, el, arPts[i], arPts[i+1], arPts[i+1]); el.ptGe[0] = arPts[i]; el.ptGe[1] = arPts[i+1]; el.ptGe[2] = el.ptGe[1]; } } } else if (TDb::eCircular == iSectType) { if (GetCirInsertPt(arPts)) { if (arPts.length() == 6) { AutoAppendPt(cplCurve, el, arPts[1], arPts[3], arPts[0]); AutoAppendPt(cplCurve, el, arPts[0], arPts[4], arPts[2]); AutoAppendPt(cplCurve, el, arPts[2], arPts[5], arPts[0]); } } } } else { el.ptGe[0] = ptS; el.ptGe[1] = ptE; el.ptGe[2] = ptE; cplCurve.append(el); } return cplCurve.length() > 0; } double THImpHvacBroSymbol::GetEdgeLineWidth() const { BOOL bShow(FALSE); GetGlobalContext(HVAC_SHOWWIDTH, bShow); // add by hh 2011-01-05 从图纸中读取加粗标识 避免全局参数对不同的图纸间的影响 TAuxTools::GetTHvacDataFromDwg(HVAC_SHOWWIDTH, bShow); if (!bShow) return 0.0; ASSERT(NULL != m_pXDataMap); double dWidth(0.0); m_pXDataMap->GetAt(HVAC_EdgeWidth, dWidth); return dWidth; } BOOL THImpHvacBroSymbol::GetSectInsertPt(AcGePoint3dArray &arPts, AcDbPolyline &Poly) const { // 获取绘图数据 AcGePoint3d ptBase; m_pXDataMap->GetAt(HBSM_InsertPoint, ptBase); // 计算方向向量 AcGeVector3d vtNormal = AcGeVector3d::kIdentity; AcGeVector3d vtDir = AcGeVector3d::kIdentity; AcGeVector3d vtMainV = AcGeVector3d::kIdentity; m_pXDataMap->GetAt(KEY_NORMAL, vtNormal); m_pXDataMap->GetAt(HBSM_Dir, vtDir); int nType(0); m_pXDataMap->GetAt(HBSM_Type, nType); vtDir = vtDir.normalize(); vtMainV = vtDir; vtMainV.rotateBy(PI / 2.0, vtNormal); double dSkirtSize = 0.0; m_pXDataMap->GetAt(HBSM_SkirtSize, dSkirtSize); // add by zh 2013-5-20 根据出图比例计算出头长度 double dPScale = ((TDbInterfacesObj*)m_pOwnerEnt)->GetPrintScale(); if (dPScale < 1.e-3) dPScale = 1.0; dSkirtSize *= dPScale/100; // double dWidth = 0.0; m_pXDataMap->GetAt(HBSM_Width, dWidth); AcGePoint3d ptTemp; if (nType == 0) { ptTemp = ptBase - vtMainV * (dWidth/2 + dSkirtSize); arPts.append(ptTemp); ptTemp = ptBase - vtMainV * (dWidth/8); arPts.append(ptTemp); ptTemp = ptTemp - vtDir*(dWidth/8); arPts.append(ptTemp); ptTemp = ptTemp + vtDir*(dWidth/4) + vtMainV*(dWidth/4); arPts.append(ptTemp); ptTemp = ptBase + vtMainV * (dWidth/8); arPts.append(ptTemp); ptTemp = ptBase + vtMainV * (dWidth/2 + dSkirtSize); arPts.append(ptTemp); } else if (nType == 1) { ptTemp = ptBase - vtMainV * (dWidth/2 + dSkirtSize); arPts.append(ptTemp); ptTemp = ptBase - vtMainV * (dWidth/8); arPts.append(ptTemp); ptTemp = ptBase - vtMainV * (dWidth/16) - vtDir*(dWidth/8); arPts.append(ptTemp); ptTemp = ptTemp + vtDir*(dWidth/4) + vtMainV*(dWidth/8); arPts.append(ptTemp); ptTemp = ptBase + vtMainV * (dWidth/8); arPts.append(ptTemp); ptTemp = ptBase + vtMainV * (dWidth/2 + dSkirtSize); arPts.append(ptTemp); } else if (nType == 2) { ptTemp = ptBase - vtMainV * (dWidth/2 + dSkirtSize); arPts.append(ptTemp); ptTemp = ptBase - vtMainV * (dWidth/8); arPts.append(ptTemp); ptTemp = ptBase - vtDir*(dWidth/8); arPts.append(ptTemp); ptTemp = ptBase + vtDir*(dWidth/8); arPts.append(ptTemp); ptTemp = ptBase + vtMainV * (dWidth/8); arPts.append(ptTemp); ptTemp = ptBase + vtMainV * (dWidth/2 + dSkirtSize); arPts.append(ptTemp); } return arPts.length() > 0; } BOOL THImpHvacBroSymbol::GetCirInsertPt(AcGePoint3dArray &arPts) const { // 获取绘图数据 AcGePoint3d ptBase; m_pXDataMap->GetAt(HBSM_InsertPoint, ptBase); // 计算方向向量 AcGeVector3d vtNormal = AcGeVector3d::kIdentity; AcGeVector3d vtDir = AcGeVector3d::kIdentity; AcGeVector3d vtMainV = AcGeVector3d::kIdentity; m_pXDataMap->GetAt(KEY_NORMAL, vtNormal); m_pXDataMap->GetAt(HBSM_Dir, vtDir); vtDir = vtDir.normalize(); vtMainV = vtDir; vtMainV.rotateBy(PI / 2.0, vtNormal); double dA = 53.13*PI/180; double dDiameter = 0.0; m_pXDataMap->GetAt(HBSM_Diameter, dDiameter); double dDis = dDiameter/(4*sin(dA)) - dDiameter/(4*tan(dA)); arPts.append(ptBase); AcGePoint3d ptTemp; ptTemp = ptBase - vtMainV*(dDiameter/2); arPts.append(ptTemp); ptTemp = ptBase + vtMainV*(dDiameter/2); arPts.append(ptTemp); ptTemp = ptBase - vtMainV*(dDiameter/4); ptTemp = ptTemp - vtDir*dDis; arPts.append(ptTemp); ptTemp = ptBase + vtMainV*(dDiameter/4); ptTemp = ptTemp + vtDir*dDis; arPts.append(ptTemp); ptTemp = ptTemp - vtDir*dDis*2; arPts.append(ptTemp); return arPts.length() > 0; } // 注意:pXMap == NULL表示不想得到返回值,只是判断数据是否合理 // 先取出m_pXDataMap中数据进行判断是否合理,返回判断结果 // 如果pXMap不为NULL,则将有效参数填入pXMap BOOL THImpHvacBroSymbol::IsValid(TDbXDataMap* pXMap) { if (NULL == m_pXDataMap) return FALSE; AcGePoint3d ptIns; m_pXDataMap->GetAt(HBSM_InsertPoint, ptIns); return TRUE; } void THImpHvacBroSymbol::OnSubErase( Adesk::Boolean erasing ) { if (erasing == Adesk::kTrue && m_pOwnerEnt != NULL && m_pOwnerEnt->objectId().isValid()) { // 如果实体不是在当前模型空间中,不做写消息,更新接口处理 AcDbDatabase* pDb = m_pOwnerEnt->database(); if (pDb == NULL) pDb = acdbCurDwg(); AcDbObjectId idModel; AcDbBlockTable* pTable = NULL; pDb->getBlockTable(pTable, AcDb::kForRead); if (pTable != NULL) { pTable->getAt(ACDB_MODEL_SPACE, idModel); pTable->close(); } // 如果实体不是在当前模型空间中,不做写消息,更新接口处理 if (TAuxTools::IsAutoWorkConnect() && idModel == m_pOwnerEnt->blockId()) { // 写入接口更改消息 TInterfaceModifyMsg iMsg; iMsg.SetMsgValidate(TRUE); iMsg.SetMsgOperateOn(m_pOwnerEnt->objectId()); iMsg.SetInterfaceOper(TDb::eAutoWorkOn); TDbInterfaceMsgWrite msgWrite; msgWrite.WriteInterfaceMsg(iMsg); } } } LRESULT THImpHvacBroSymbol::UserCall( long i, LPVOID pData ) { ASSERT(NULL != m_pXDataMap); m_pXDataMap->SetAt(KEY_IDCNT1, NULL); return 1l; }