#include "stdafx.h" #include "mfcdbdwgfiler.h" #include "AecDbXEquipment.h" #include "xequipmentimpl.h" #include "KTCADUtilityEx.h" #include "KTCadUtility.h" #include "aecdbx3dpart.h" #include "AcGiViewDraw.h" #include "AecGripCback.h" #include "CoreTools.h" #include "simpleproperty.h" extern void DLLIMPEXP OrthoProjected3DSolid(AcDb3dSolid* pSolidClone, const AcGePlane& plan, AcGeMatrix3d& xformPlanToWorld, AcDbVoidPtrArray& arEntPtrs); extern void DLLIMPEXP OrthoProjected3DSubMesh(AcDbSubDMesh* pSubMesh, const AcGePlane& plan, AcGeMatrix3d& xformPlanToWorld, AcDbVoidPtrArray& arEntPtrs); extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt, AcDbDatabase* pDb = NULL, bool bClose = true); extern void ProjectToPlane(AcDbVoidPtrArray& arEntPtrs, const AcGePlane& plan, AcDbVoidPtrArray& arNewPtrs); DLLIMPEXP bool MakeBlockRefSet(AcDbVoidPtrArray &arEntPtrs, const AcDbObjectId &idLay,Adesk::Boolean bDoSubent, LPCTSTR pszName, AcDbDatabase *pDb = NULL); extern void PushGripMessage(GripMessage &); extern BOOL Is2DView(); extern AcGeVector3d GetUcsZvt(); static const Adesk::UInt16 kBlue = 5; namespace { void setType(AecDbObjXDataMap *pXData, int nType) { if (pXData) pXData->SetAt(KEY_TYPE, nType); } CString GetGripCmd(int nType = 0) { if (nType == 0) return _T("PL_wpipeadd"); return _T("HA_ductadd"); } void writeInfToDWG(AcDbDwgFiler *pFiler, const AecInterface &inf, const int &ver) { if (ver < 2) return; /* AcGePoint3d ptPos; //位置 AcGeVector3d vtDir; //方向 double dSize1; //主尺寸,圆类为直径,矩形为长 double dSize2; //副尺寸 矩形为宽 double dV, dA; //电力管嘴电压电流 short nSectType; //截面类型 0 矩形 1 圆型 bool bSizeUnLock; //主体尺寸不锁定,默认 false 锁定 //以下数据辅助数据 AcDbObjectId idOwner; short nType; //nCmd 0:水管 1:风管 或者管件等标识 EFittingType short nLevel; //主0,1 次 >= 2 short nConnectType; */ pFiler->writePoint3d(inf.ptPos); pFiler->writeVector3d(inf.vtDir); pFiler->writeDouble(inf.dSize1); pFiler->writeDouble(inf.dSize2); pFiler->writeDouble(inf.dV); pFiler->writeDouble(inf.dA); pFiler->writeInt16(inf.nSectType); pFiler->writeBoolean(inf.bSizeUnLock); pFiler->writeSoftPointerId(inf.idOwner); pFiler->writeInt16(inf.nType); pFiler->writeInt16(inf.nLevel); pFiler->writeInt16(inf.nConnectType); } void readInfFromDWG(AcDbDwgFiler *pFiler, AecInterface &inf, const int &ver) { if (ver < 2) return; pFiler->readPoint3d(&inf.ptPos); pFiler->readVector3d(&inf.vtDir); pFiler->readDouble(&inf.dSize1); pFiler->readDouble(&inf.dSize2); pFiler->readDouble(&inf.dV); pFiler->readDouble(&inf.dA); pFiler->readInt16(&inf.nSectType); Adesk::Boolean bVal; pFiler->readBoolean(&bVal); inf.bSizeUnLock = bVal == Adesk::kFalse ? false : true; AcDbSoftPointerId id; pFiler->readSoftPointerId(&id); inf.idOwner = id; pFiler->readInt16(&inf.nType); pFiler->readInt16(&inf.nLevel); pFiler->readInt16(&inf.nConnectType); } } ACRX_DXF_DEFINE_MEMBERS(AecDbXEquipment, AecDbBDPipeBase, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kNoOperation | AcDbProxyEntity::kDisableProxyWarning, AEC_DBXEQUIPMENT, "AecDbXEquipment" "|Product Desc: shanghua earthworm app obj" "|Company: shanghua inc" "|WEB Address: www.shanghuasoft.com") //Adesk::UInt32 AecDbXEquipment::kCurrentVersionNumber = 1; // 1->2 记录管嘴信息,版本1是读取json动态生成,版本2改为dwg内保存 Adesk::UInt32 AecDbXEquipment::kCurrentVersionNumber = 2; AecDbXEquipment::AecDbXEquipment(const int &type): m_pImpl(NULL) { } AecDbXEquipment::~AecDbXEquipment(void) { DELETE_PTR(m_pImpl); } void AecDbXEquipment::SetType(int nType) { assertWriteEnabled(); setType(&m_mapSpecXData, nType); } int AecDbXEquipment::GetType() const { assertReadEnabled(); int nType = 0; m_mapSpecXData.GetAt(KEY_TYPE, nType); return nType; } Acad::ErrorStatus AecDbXEquipment::dwgInFields(AcDbDwgFiler* pFiler) { AssertWriteEnabled(); //----- Read parent class information first. Acad::ErrorStatus es = Acad::eOk; if (!pFiler->isKindOf(CMFCDbDwgFiler::desc())) { es = AecDbBDPipeBase::dwgInFields(pFiler); if (es != Acad::eOk) return (es); } //----- Object version number needs to be read first Adesk::UInt32 version = 0; if ((es = pFiler->readUInt32(&version)) != Acad::eOk) return (es); if (version > AecDbXEquipment::kCurrentVersionNumber) return (Acad::eMakeMeProxy); if (version > 1) { m_interfaces.removeAll(); Adesk::Int32 countOfInf(0); pFiler->readInt32(&countOfInf); AecInterface inf; for (Adesk::Int32 i(0); i < countOfInf; ++i) { ::memset(&inf, 0, sizeof(AecInterface)); readInfFromDWG(pFiler, inf, AecDbXEquipment::kCurrentVersionNumber); m_interfaces.append(inf); } } DELETE_PTR(m_pImpl); int type = GetType(); m_pImpl = createParamEquImpl(type, false); return pFiler->filerStatus(); } Acad::ErrorStatus AecDbXEquipment::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); //----- Save parent class information first. Acad::ErrorStatus es = Acad::eOk; if (!pFiler->isKindOf(CMFCDbDwgFiler::desc())) { es = AecDbBDPipeBase::dwgOutFields(pFiler); if (es != Acad::eOk) return (es); } //----- Object version number needs to be saved first if ((es = pFiler->writeUInt32(AecDbXEquipment::kCurrentVersionNumber)) != Acad::eOk) return (es); // version > 1 pFiler->writeInt32(m_interfaces.length()); for (int i(0); i < m_interfaces.length(); ++i) { writeInfToDWG(pFiler, m_interfaces[i], AecDbXEquipment::kCurrentVersionNumber); } return pFiler->filerStatus(); } Acad::ErrorStatus AecDbXEquipment::dxfInFields(AcDbDxfFiler* pFiler) { return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::dxfOutFields(AcDbDxfFiler* pFiler) const { return Acad::eOk; } void AecDbXEquipment::subList() const { assertReadEnabled(); AecDbBDPipeBase::subList(); } bool AecDbXEquipment::GetBimInfoTip(CString& sInfoTip) const { assertReadEnabled(); SH_BIM_BLOCK blk; CoreTools::getBimDatas(this, blk); CString sField,sFmt,sVal,sKey; GetSpecialtyData()->GetAt(KEY_NAME, sVal); MAKEFIELD(_T("名称"), _T("%s"), sVal, sInfoTip); sVal = _T("无设置"); GetSpecialtyData()->GetAt(PIPE_SYS, sVal); MAKEFIELD(_T("系统"), _T("%s"), sVal, sInfoTip); MAKEFIELD(_T("标高"), _T("%.3f"), const_cast(this)->GetElev(), sInfoTip); for (size_t i(0); i < blk.size(); ++i) { SH_BIM_REC &rec(blk[i]); MAKEFIELD(rec.first, _T("%s"), rec.second, sInfoTip); } return true; } Acad::ErrorStatus AecDbXEquipment::copyFrom(const AcRxObject* pSrc) { AssertWriteEnabled(); AecDbXEquipment *pSrcEqu = AecDbXEquipment::cast(pSrc); if (!pSrcEqu) return Acad::eInvalidInput; m_interfaces = pSrcEqu->m_interfaces; return Acad::eOk; //AssertWriteEnabled(); //AecDbXEquipment *pSrcEqu = AecDbXEquipment::cast(pSrc); //if (!pSrcEqu) return Acad::eInvalidInput; //m_mapSpecXData.CopyFrom(pSrcEqu->GetSpecialtyData()); //m_pImpl = pSrcEqu->cloneImpl(&m_mapSpecXData); //return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::copyFrom2(const AcRxObject* pSrc) { AssertWriteEnabled(); AecDbXEquipment *pSrcEqu = AecDbXEquipment::cast(pSrc); if (!pSrcEqu) return Acad::eInvalidInput; m_mapSpecXData.CopyFrom(pSrcEqu->GetSpecialtyData()); m_pImpl = pSrcEqu->cloneImpl(&m_mapSpecXData); return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::subTransformBy(const AcGeMatrix3d& xform) { AssertWriteEnabled(); if (m_pImpl) { AcGePoint3d pt; m_pImpl->transformBy(xform); for (int i(0); i < m_interfaces.length(); ++i) { AecInterface &inf(m_interfaces[i]); inf.ptPos.transformBy(xform); inf.vtDir.transformBy(xform); } } return AecDbBDPipeBase::subTransformBy(xform); } Acad::ErrorStatus AecDbXEquipment::subGetGripPoints(AcDbGripDataPtrArray & grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d & curViewDir, const int bitflags) const { if (!m_pImpl) return Acad::eInvalidInput; AcGePoint3d ptIns = m_pImpl->getPos(); int count = m_interfaces.length() +1; if (count >= GRIP_LENGTH) return Acad::eInvalidInput; if (count > eCommand19 - eCommand0) count = eCommand19 - eCommand0; AcDbGripData *pGripData = NULL; bool bIsMeter(CoreTools::IsMetersUnit()); double dCmd = CoreTools::PixelToWcs(10); CString sCmd(_T("")); AcGeVector3d vtoffset(1.0, 1.0, 0.0); AcGePoint3d ptGe; AcGeMatrix3d mat; // 管嘴 int i(0); for (; i < m_interfaces.length(); ++i) { const AecInterface &inf(m_interfaces[i]); ptGe = inf.ptPos; //ptGe += vtoffset * dCmd / 2.0; if (bIsMeter) { mat.setToScaling(.001, ptIns); ptGe.transformBy(mat); } pGripData = new AcDbGripData; sCmd = ::GetGripCmd(inf.nType); memset(&m_pGripAppData[i], 0, sizeof(AecGripData)); m_pGripAppData[i].nIndex = i; m_pGripAppData[i].ePos = (EPosition)(eCommand0 + i); m_pGripAppData[i].nColor = kBlue; m_pGripAppData[i].ptGrip = ptGe; _tcscpy(m_pGripAppData[i].szTip, sCmd); m_pGripAppData[i].pOwner = (AcDbEntity *)this; pGripData->setGripPoint(ptGe); pGripData->setAppData((void *)&m_pGripAppData[i]); pGripData->setWorldDraw(AecGripCback::WorldDrawfunc); pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc); m_pGripAppData[i].pOwner = (AcDbEntity *)this; m_pGripAppData[i].idHost = objectId(); grips.append(pGripData); } memset(&m_pGripAppData[i], 0, sizeof(AecGripData)); m_pGripAppData[i].nIndex = i; m_pGripAppData[i].ePos = eMid; m_pGripAppData[i].nColor = kBlue; m_pGripAppData[i].ptGrip = ptIns; _tcscpy(m_pGripAppData[i].szTip, _T("位置夹点")); m_pGripAppData[i].pOwner = (AcDbEntity *)this; m_pGripAppData[i].idHost = objectId(); pGripData = new AcDbGripData; pGripData->setGripPoint(ptIns); pGripData->setAppData((void *)&m_pGripAppData[i]); pGripData->setWorldDraw(AecGripCback::WorldDrawfunc); pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc); grips.append(pGripData); //调用基类加入单击修改 SubAddHitEditGrip(grips); return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const { assertReadEnabled(); if (!m_pImpl) return Acad::eInvalidInput; stretchPoints.append(m_pImpl->getPos()); return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::subMoveStretchPointsAt(const AcDbIntArray &indices, const AcGeVector3d &offset) { AssertWriteEnabled(); if (!indices.isEmpty()) { AcGeMatrix3d mat; mat.setToTranslation(offset); return subTransformBy(mat); } return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::subMoveGripPointsAt(const AcDbVoidPtrArray &gripAppData , const AcGeVector3d &offset , const int bitflags) { AssertWriteEnabled(); AecGripData *pAppData = NULL; pAppData = (AecGripData *)gripAppData.first(); if (HitOnGripEdit(gripAppData)) { return Acad::eOk; } AcGeVector3d vtOffset = offset; if (Is2DView()) { vtOffset = offset.orthoProject(GetUcsZvt()); } GripMessage msg; memset(&msg, 0, sizeof(GripMessage)); //reset msg.nSegindex = -1; msg.nType = -1; msg.idHost.setNull(); msg.pParam = 0; msg.nData = -1; _tcscpy(msg.szLockId, _T("0"));//锁定id,如果有 msg.fData = 0; msg.nSegindex = 0; msg.nSubSegIndex = 0; msg.vtOffset.set(0, 0, 0); msg.ptGrip.set(0, 0, 0); EPosition ePos = pAppData->ePos; AecInterface inf; if (ePos >= eCommand0 && ePos <= eCommand19) { msg.nType = ePos; msg.nData = ePos - eCommand0; GetInterface(msg.nData, inf); msg.ptGrip = inf.ptPos; msg.idHost = pAppData->idHost; msg.vtOffset = vtOffset; PushGripMessage(msg); CString sCmd = ::GetGripCmd(inf.nType); if (!sCmd.IsEmpty()) { acedPostCommand(_T("\x03")); sCmd += _T("\n"); acedPostCommand(sCmd); } } else // eMid { AcGeMatrix3d mat; mat.setToTranslation(offset); return subTransformBy(mat); } return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::subGetOsnapPoints(AcDb::OsnapMode osnapMode, INT_PTR gsSelectionMark, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { assertReadEnabled(); if (!m_pImpl) return Acad::eInvalidInput; AcGePoint3d ptIns = m_pImpl->getPos(); bool bIsMeter(CoreTools::IsMetersUnit()); AcGeMatrix3d mat; AcGePoint3d ptGe; int i(0); for (; i < m_interfaces.length(); ++i) { const AecInterface &inf(m_interfaces[i]); ptGe = inf.ptPos; if (bIsMeter) { mat.setToScaling(.001, ptIns); ptGe.transformBy(mat); } snapPoints.append(ptGe); } snapPoints.append(ptIns); AcDbPoint pos(ptIns); return pos.getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds); } Acad::ErrorStatus AecDbXEquipment::subGetGeomExtents(AcDbExtents& extents) const { assertReadEnabled(); if (!Has3DBuffer()) { AcGiViewDraw dc; Draw3d(dc); } AcDbExtents ext; const AcDbVoidPtrArray &ar = Get3DBuffer(); for (int i = 0; i < ar.length(); ++i) { AcDbEntity *pEnt = (AcDbEntity*)ar[i]; pEnt->getGeomExtents(ext); extents.addExt(ext); } return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::Draw2d(AcGiDraw &dc) const { int clr(256); GetSpecialtyData()->GetAt(_T("COLOR"), clr); int oldClr(dc.GetColor()); dc.SetColor(clr); DrawDTYG2D(dc); dc.SetColor(oldClr); return Acad::eOk; } Acad::ErrorStatus AecDbXEquipment::Draw3d(AcGiDraw &dc) const { return AecDbBDPipeBase::Draw3d(dc); } const AecDbObjXDataMap* AecDbXEquipment::GetSpecialtyData() const { return &m_mapSpecXData; } AecDbObjXDataMap* AecDbXEquipment::GetSpecialtyData(AcDb::OpenMode bMode) { if (bMode == AcDb::kForRead) assertReadEnabled(); else if (bMode == AcDb::kForWrite) { if (!isWriteEnabled()) { upgradeOpen(); } AssertWriteEnabled(); } else return NULL; return &m_mapSpecXData; } void AecDbXEquipment::SetPosAndDir(const AcGePoint3d & pt, const AcGeVector3d & dir) { AssertWriteEnabled(); m_mapSpecXData.SetAt(_T("Pos"), pt); m_mapSpecXData.SetAt(_T("Dir"), dir); } void AecDbXEquipment::GetInsert(AcGePoint3d& ptIns, AcGeVector3d& vtDir) const { assertReadEnabled(); m_mapSpecXData.GetAt(_T("Pos"), ptIns); m_mapSpecXData.GetAt(_T("Dir"), vtDir); } void AecDbXEquipment::SetElev(const double & dElev) { AssertWriteEnabled(); if (m_pImpl) m_pImpl->setElev(dElev); draw3dByImp(); } XEquipmentImplBase* AecDbXEquipment::cloneImpl(AecDbObjXDataMap *pXData) { if (m_pImpl) return m_pImpl->makeSelf(pXData); return NULL; } double AecDbXEquipment::GetElev() { if (m_pImpl) return m_pImpl->getPos().z; return 0.0; } #define _CREATE_(region,type1,func)\ case region::type1:\ setType(&m_mapSpecXData, type);\ pImp = new X##region::func(&m_mapSpecXData);\ break XEquipmentImplBase* AecDbXEquipment::createParamEquImpl(const int & type, bool bRedraw) { XEquipmentImplBase *pImp(NULL); switch (type) { _CREATE_(GESHAN, XHG_I, XHG); _CREATE_(GESHAN, XHG_II, XHG); _CREATE_(GESHAN, SG, SG); _CREATE_(GESHAN, BLQ, SG); _CREATE_(GESHAN, ZG_I, ZG); _CREATE_(GESHAN, ZG_II, ZG); _CREATE_(GESHAN, XGC, XGC); _CREATE_(GESHAN, XJT, XJT); _CREATE_(GESHAN, ZSB, ZSB); _CREATE_(GESHAN, BS, BS); _CREATE_(GESHAN, XL, XL); _CREATE_(BAOQIQI, PAN_SI, BaoQiQi); _CREATE_(BAOQIQI, GUAN_SI, BaoQiQi); _CREATE_(SHASHUIFENLI, XCS, XCS); _CREATE_(SHASHUIFENLI, HXS, HXS); _CREATE_(SHASHUIFENLI, LCS, LCS); _CREATE_(LUOXUANBENG, LXB, LXB); _CREATE_(QIBIJI, QS_I_P, QS_I_P); _CREATE_(QIBIJI, QS_I_Y, QS_I_Y); _CREATE_(QIBIJI, QS_I_L, QS_I_L); _CREATE_(QIBIJI, QS_II_Y, QS_II_Y); _CREATE_(QIBIJI, QS_II_L, QS_II_L); _CREATE_(ZHAMEN, RECT_ZHAMEN, RectZhaMen); _CREATE_(ZHAMEN, CIRCLE_ZHAMEN, CircleZhaMen); _CREATE_(ZHAMEN, SHENG_NI_FA, ShengNiFa); _CREATE_(GUANIJI, XZG, XZG); _CREATE_(GUANIJI, CZG, CZG); _CREATE_(GUANIJI, ZG, ZG); _CREATE_(GUANIJI, QG, QG); _CREATE_(GUANIJI, PJ, PJ); _CREATE_(GUANIJI, SX, SX); _CREATE_(GUANIJI, SB, SB); _CREATE_(GUANIJI, LIANTIAO, LIANTIAO); _CREATE_(NONGSUOJI, NC, NC); _CREATE_(NONGSUOJI, NB, NB); _CREATE_(BAOQIJI, YHG, YHG); _CREATE_(BAOQIJI, AD, AD); _CREATE_(JIAYAOHUNHE, GJ, GJ); _CREATE_(JIAYAOHUNHE, PJ, PJ); _CREATE_(JIAYAOHUNHE, TJ, TJ); _CREATE_(JIAYAOHUNHE, LJF, LJF); _CREATE_(LVBUJI, ZHUANPAN, ZHUANPAN); _CREATE_(XIEBANGUAN, XBG, XBG); _CREATE_(GUANXIANG, GUANXIANG_I, GUANXIANG_I); _CREATE_(GUANDAOGUOLVQI, DLD_FZ, DLD_FZ); _CREATE_(QIANCENGSHALV, DMF_56, DMF_56); _CREATE_(YIBANGUANTI, YUANXINGGUAN, YUANXINGGUAN); _CREATE_(YIBANXIANGTI, FANGXINGXIANG, FANGXINGXIANG); _CREATE_(LABAKOU, YUANXINGLABAKOU, YUANXINGLABAKOU); default: return NULL; } m_pImpl = pImp; // 接口生成一下 if (m_pImpl) m_pImpl->getInterfaces(m_interfaces); if (!bRedraw) return pImp; draw3dByImp(); return pImp; } bool AecDbXEquipment::GetSrcString(CString &src) const { assertReadEnabled(); return m_mapSpecXData.GetAt(_T("_SRC_STRING_"), src) == 0 ? false : true; } void AecDbXEquipment::SetSrcString(LPCTSTR src) { assertWriteEnabled(); if (src && !CString(src).IsEmpty()) m_mapSpecXData.SetAt(_T("_SRC_STRING_"), src); } int AecDbXEquipment::GetSectionDraw(const AcGePoint3d& ptFr, const AcGePoint3d& ptTo, const AcGeVector3d& vtViewDir, const AcGeVector3d& vtTo, AcDbVoidPtrArray& arRegPtrs) const { AcGeVector3d vtLn = ptTo - ptFr; AcGeVector3d vtNorm = vtLn.crossProduct(vtViewDir); AcGePlane plan; plan.set(ptFr, vtNorm); AcGeMatrix3d xform; xform.setToPlaneToWorld(plan); xform.invert(); if (Get3DBuffer().length() == 0) { AcGiViewDraw dc(NULL, NULL); Draw3d(dc); } AcDbEntity* pEnt = NULL; AcDb3dSolid* pSolid = NULL; AcDbSubDMesh* pSubMesh = NULL; AcDbVoidPtrArray arRegPtrsT; const AcDbVoidPtrArray &ar3D = Get3DBuffer(); for (int i = 0;i < ar3D.length();i++) { pEnt = (AcDbEntity*)ar3D.at(i); pSolid = AcDb3dSolid::cast(pEnt); if (pSolid != NULL) { //投影法 OrthoProjected3DSolid(pSolid, plan, xform, arRegPtrsT); } pSubMesh = AcDbSubDMesh::cast(pEnt); if (pSubMesh != NULL) { OrthoProjected3DSubMesh(pSubMesh, plan, xform, arRegPtrsT); } } CString sName; m_mapSpecXData.GetAt(KEY_NAME, sName); MakeBlockRefSet(arRegPtrsT, layerId(), Adesk::kTrue,sName); arRegPtrs.append(arRegPtrsT); //扩展数据 AcDbPoint* pPt = new AcDbPoint; AcGePoint3d ptIns, ptIns2; AcGeVector3d vtDir; GetInsert(ptIns, vtDir); pPt->setPosition(ptIns); pPt->setLayer(layerId()); pPt->setNormal(plan.normal()); pPt->transformBy(xform); m_mapSpecXData.Write(pPt, BIMDATA_APP); arRegPtrs.append(pPt); return arRegPtrs.length(); } void AecDbXEquipment::draw3dByImp() { if (!m_pImpl) return; RemoveAllX3dPart(); AcDbVoidPtrArray ar; m_pImpl->draw3d(ar); m_pImpl->getInterfaces(m_interfaces); for (int i = 0; i < ar.length(); ++i) { AecDbX3dPart *pPart((AecDbX3dPart*)ar[i]); if (!pPart) continue; AddX3dPart(pPart, (AcDb::BoolOperType)pPart->GetBoolOperFor()); } } bool AecDbXEquipment::isType(AcDbObjectId &id, const int &type) { OPENOBJ_BEGIN(id, AcDb::kForWrite, AecDbXEquipment, pEqu) if (pEqu) return isType(pEqu, type); OPENOBJ_END(); return false; } bool AecDbXEquipment::isType(AecDbXEquipment *pEqu, const int &type) { return pEqu->GetType() == type; } SHJson::WValue& AecDbXEquipment::ToJson(bool bExprotGeo) const { using namespace SHJson; if (bExprotGeo) { AcGePoint3d ptIns; AcGeVector3d vtDir; GetInsert(ptIns, vtDir); AecDbXEquipment *p = (AecDbXEquipment *)clone(); std::shared_ptr pNew(p); pNew->copyFrom2(this); pNew->Clean3DBuffer(); int count(GetX3dPartCount()); for (int i(0); i < count; ++i) { AecDbX3dPart *pPart = new AecDbX3dPart; pPart->CopyFrom(GetX3dPart(i)); p->AddX3dPart(pPart); } // 现在需要将pNew移动到原点,并把方向置为x方向 AcGeMatrix3d mat; mat.setToTranslation(-ptIns.asVector()); pNew->transformBy(mat); double dAngle = vtDir.angleTo(AcGeVector3d::kXAxis, AcGeVector3d::kZAxis); mat.setToRotation(dAngle, AcGeVector3d::kZAxis); pNew->transformBy(mat); AcGiViewDraw dc; //pNew->draw3dByImp(); //pNew->Draw3d(dc); pNew->SetPosAndDir(AcGePoint3d::kOrigin, AcGeVector3d::kXAxis); // 还原位置 GetInsert(ptIns, vtDir); pNew->m_mapSpecXData.SetAt(_T("Pos"), ptIns); pNew->m_mapSpecXData.SetAt(_T("Dir"), vtDir); return pNew->AecDbBDPipeBase::ToJson(true); } else return AecDbBDPipeBase::ToJson(bExprotGeo); } CString AecDbXEquipment::getUniqueName() const { if (m_pImpl) { // 对于参数化设备来说,用户可能会通过“造型设计”来修改其x3dpart // 所以,在UniqueName后面增加一个xpart数量的字符 // 至于x3dpart的数量没有修改,但改动的是part的形状等数据, 则不在考虑范围内 CString str(_T("")); str.Format(_T("%s%d"), m_pImpl->getUniqueName(), m_arX3DPartPtrs.length()); return str; } return _T(""); } bool AecDbXEquipment::ByJson(const SHJson::WValue &v) { AssertWriteEnabled(); return AecDbBDPipeBase::ByJson(v); } int AecDbXEquipment::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray &arEntPtrs) const { AcDbVoidPtrArray ar; AecDbBDPipeBase::GetDraw2dables(nDrawStyle, ar); if (!ar.isEmpty()) { AcGePoint3d ptIns; AcGeVector3d vtDir; GetInsert(ptIns, vtDir); ptIns.z = .0; CoreTools::projectToXOY(ar); AcDbObjectId idTblRec = CKTCadUtility::CreateBlockTableRecord(ar, ptIns, NULL, NULL, FALSE); if (idTblRec.isValid()) { deleteArrayVoidPtrs< AcDbEntity>(ar); AcDbBlockReference *pRef = new AcDbBlockReference(ptIns, idTblRec); AecDbObjXDataMap xData; xData.SetAt(KEY_ID, m_sGUID); xData.CopyFrom(&m_mapSpecXData); xData.Write(pRef, BIMDATA_APP); arEntPtrs.append(pRef); } else arEntPtrs.append(ar); } return 0; } void AecDbXEquipment::clearInterface() { m_interfaces.removeAll(); } bool AecDbXEquipment::GetInterface(AcArray &arInfs) const { assertReadEnabled(); arInfs.removeAll(); arInfs = m_interfaces; return !arInfs.isEmpty(); } bool AecDbXEquipment::GetInterface(int nIndex, AecInterface &inf) const { assertReadEnabled(); if (nIndex >= m_interfaces.length() || nIndex < 0) return false; inf = m_interfaces[nIndex]; return true; } int AecDbXEquipment::GetInterfaceCount() const { assertReadEnabled(); return m_interfaces.length(); } int AecDbXEquipment::GetActiveInf() const { assertReadEnabled(); return m_nInfActive; } void AecDbXEquipment::SetActiveInf(int nIndex) { AssertWriteEnabled(); m_nInfActive = nIndex; } void AecDbXEquipment::LockInf(int nInf) { } bool AecDbXEquipment::TransformAssocInf(int nInf, const AcGeMatrix3d &xform) { return false; } CString AecDbXEquipment::GetSpec() { CString str(_T("")); std::vector> spec; if (!GetSpec(spec)) return str; std::vector>::const_iterator it(spec.begin()); for (; it != spec.end(); ++it) { str += it->first; str += _T(":"); str += it->second; str += _T(";"); } return str; } bool AecDbXEquipment::GetSpec(std::vector> &spec) { if (m_pImpl) return m_pImpl->GetSpec(spec); return false; } bool AecDbXEquipment::GetJsonParams(std::vector> &spec) { CString mt, st; if (m_pImpl) return m_pImpl->GetJsonParams(spec, mt, st); return false; } #include "HlrCutOption.h" void AecDbXEquipment::ProcessHlrResult(const AcArray &ar , const std::map> &preAr , AcArray &output) const { HlrCutOption::ProcessHlrResult(this , FALSE , .0 , HlrCutOption::getHlrBLK_PARAEQU() , ar , preAr , output); } bool AecDbXEquipment::GetProperties(SimpleProperty::PropertySetByIndex &properties) const { AecDbBDPipeBase::GetProperties(properties); CoreTools::setLayerPorperty(properties); CoreTools::setSubSystemPorperty(properties); BOOL bPMFY(FALSE), bDLJC(FALSE); if (GetSpecialtyData()->GetAt(_T("PMFY"), bPMFY)) { SimpleProperty::makeAndInsert(properties, _T("类型"), _T("平面放样"), false); } else if (GetSpecialtyData()->GetAt(_T("DLJC"), bDLJC)) { SimpleProperty::makeAndInsert(properties, _T("类型"), _T("板基础"), false); } else { AcGePoint3d ptIns; AcGeVector3d vtIns; GetInsert(ptIns, vtIns); SimpleProperty::makeAndInsert(properties, _T("标高"), ptIns.z, true); } return true; } bool AecDbXEquipment::SetProperties(SimpleProperty::PropertySetByName & properties) { if (properties.m_set.empty()) return false; AecDbBDPipeBase::SetProperties(properties); double dVal(.0); if (properties.findAndSet(_T("标高"), dVal)) SetElev(dVal); return false; }