#include "stdafx.h" #include "DbPipe.h" #include "HDbEquipment.h" #include "PipePrototype.h" #include "DbDuct.h" // sg add ACRX_DXF_DEFINE_MEMBERS(ATSHDbEquipment, ATSPipeNode, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, ATS_HEQUIPMENT, "ATS_HEQUIPMENT图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com"); IMPLEMENT_TENTBASE(THDbEquipment); const Adesk::UInt8 THDbEquipment::g_nVersion = 1; THDbEquipment::THDbEquipment(): m_nMirror(0), m_vtDirection(1,0,0), m_dSizeX(0), m_dSizeY(0), m_dSizeZ(0), m_bDrawLabel(FALSE), m_modelType(TPipeSys::kModel), m_dSysAngle(PI/4) { m_visibility = TPipeSys::kVisible; } void THDbEquipment::AddInterface(XString sName, const XPoint& ptLoc, const XVector3D& vt) { assertWriteEnabled(); for (int i=0; im_sSysLabel) == 0) return pFace; } return NULL; } BOOL THDbEquipment::RemoveInterface(XString sName) { for (int i=0; im_sSysLabel) == 0) { m_lstInterface.Remove(); return TRUE; } } return FALSE; } void THDbEquipment::CopyPropertiesFrom(AcDbEntity *pSrc, unsigned gMatchFlag) { assertWriteEnabled(); TDbPipeNode::CopyPropertiesFrom(pSrc, gMatchFlag); TLabelStyle::CopyPropertiesFrom(pSrc, gMatchFlag); THDbEquipment *pEqu = THDbEquipment::cast(pSrc); if (pEqu != NULL) { //m_dSizeX = pEqu->m_dSizeX; //m_dSizeY = pEqu->m_dSizeY; //m_dSizeZ = pEqu->m_dSizeZ; //m_nMirror = pEqu->m_nMirror; //m_idBlock2d = pEqu->m_idBlock2d; //m_idBlock3d = pEqu->m_idBlock3d; m_idLabelLayer = pEqu->m_idLabelLayer; m_idLabelLayer = pEqu->m_idLabelLayer; } } // sg add Acad::ErrorStatus THDbEquipment::subGetClassID(CLSID* pClsid) const { return Acad::eOk; } Acad::ErrorStatus THDbEquipment::subGetOsnapPoints(AcDb::OsnapMode osnapMode, INT_PTR gsSelectionMark, const AcGePoint3d& ptPick, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { assertReadEnabled(); Acad::ErrorStatus es=Acad::eOk; if (osnapMode == AcDb::kOsModeIns || osnapMode == AcDb::kOsModeCen || osnapMode == AcDb::kOsModeNode) { snapPoints.append(m_ptLocation); } es = TDbPipeNode::subGetOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint, viewXform, snapPoints, geomIds); return es; } // 从DWG读入数据: Acad::ErrorStatus THDbEquipment::dwgInFields(AcDbDwgFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = TDbPipeNode::dwgInFields(pFiler); if (es != Acad::eOk) return es; es = TLabelStyle::dwgInFields(pFiler); if (es != Acad::eOk) return es; Adesk::UInt8 nVer; pFiler->readItem(&nVer); if (nVer>g_nVersion) { // Version is too new return Acad::eMakeMeProxy; } pFiler->readItem(&m_idBlock2d); pFiler->readItem(&m_idBlock3d); pFiler->readItem(&m_idLabelLayer); pFiler->readItem((AcGePoint3d *)&m_ptLocation); pFiler->readItem((AcGePoint3d *)&m_ptLabel); pFiler->readItem((AcGePoint3d *)&m_ptLabelOut); pFiler->readItem((AcGeVector3d *)&m_vtDirection); pFiler->readItem(&m_dSizeX); pFiler->readItem(&m_dSizeY); pFiler->readItem(&m_dSizeZ); pFiler->readItem(&m_nMirror); ReadString(pFiler, m_sLabel); //pFiler->readItem(&m_bDrawLabel); FilerRead(pFiler, m_bDrawLabel); pFiler->readItem(&m_dSysAngle); Adesk::UInt8 nTemp = 0; pFiler->readItem(&nTemp); m_modelType = (TPipeSys::ModelType)nTemp; return pFiler->filerStatus(); } Acad::ErrorStatus THDbEquipment::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = TDbPipeNode::dwgOutFields(pFiler); if (es != Acad::eOk) return es; es = TLabelStyle::dwgOutFields(pFiler); if (es != Acad::eOk) return es; pFiler->writeItem(g_nVersion); pFiler->writeItem(m_idBlock2d); pFiler->writeItem(m_idBlock3d); pFiler->writeItem(m_idLabelLayer); pFiler->writeItem((const AcGePoint3d &)m_ptLocation); pFiler->writeItem((const AcGePoint3d &)m_ptLabel); pFiler->writeItem((const AcGePoint3d &)m_ptLabelOut); pFiler->writeItem((const AcGeVector3d &)m_vtDirection); pFiler->writeItem(m_dSizeX); pFiler->writeItem(m_dSizeY); pFiler->writeItem(m_dSizeZ); pFiler->writeItem(m_nMirror); pFiler->writeItem((const TCHAR *)m_sLabel); //pFiler->writeItem(m_bDrawLabel); FilerWrite(pFiler, m_bDrawLabel); pFiler->writeItem(m_dSysAngle); pFiler->writeItem((Adesk::UInt8)m_modelType); return pFiler->filerStatus(); } Acad::ErrorStatus THDbEquipment::dxfInFields(AcDbDxfFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = Acad::eOk; es = TDbPipeNode::dxfInFields(pFiler); if (es != Acad::eOk) return es; es = TLabelStyle::dxfInFields(pFiler); if (es != Acad::eOk) return es; if (!pFiler->atSubclassData(_T("THDbEquipment"))) { return Acad::eBadDxfSequence; } resbuf rb; while((es==Acad::eOk) && ((es=pFiler->readResBuf(&rb))==Acad::eOk)) { switch (rb.restype) { case AcDb::kDxfXCoord: m_ptLocation =rb.resval.rpoint; break; case AcDb::kDxfXReal: m_dSizeX=rb.resval.rreal; break; case AcDb::kDxfXReal+1: m_dSizeY=rb.resval.rreal; break; case AcDb::kDxfXReal+2: m_dSizeZ=rb.resval.rreal; break; case AcDb::kDxfXTextString: break; default: pFiler->pushBackItem(); es = Acad::eEndOfFile; break; } } if(es!=Acad::eEndOfFile) return Acad::eInvalidResBuf; return pFiler->filerStatus(); } Acad::ErrorStatus THDbEquipment::dxfOutFields(AcDbDxfFiler* pFiler) const { Acad::ErrorStatus es = Acad::eOk; es = TDbPipeNode::dxfOutFields(pFiler); assert(es == Acad::eOk); es = TLabelStyle::dxfOutFields(pFiler); assert(es == Acad::eOk); es = pFiler->writeItem(AcDb::kDxfSubclass, _T("THDbEquipment")); assert(es==Acad::eOk); pFiler->writePoint3d(AcDb::kDxfXCoord, m_ptLocation); pFiler->writeDouble(AcDb::kDxfXReal, m_dSizeX); pFiler->writeDouble(AcDb::kDxfXReal+1, m_dSizeY); pFiler->writeDouble(AcDb::kDxfXReal+2, m_dSizeZ); CString sBlkName, sDesName; GetBlkNameById(m_idBlock2d, sBlkName, sDesName); pFiler->writeString(AcDb::kDxfXTextString, (const TCHAR*)sBlkName); return es; } AcGeScale3d THDbEquipment::GetInsert2dScale() const { assertReadEnabled(); AcGeScale3d scale(1); double x = 0, y = 0; GetInsertExtend(m_idBlock2d, x, y); // double x = 1, y = 1; if (x > 1.0E-3) scale.sx *= m_dSizeX/x; if (y > 1.0E-3) scale.sy *= m_dSizeY/y; if (IsMirrorByY()) scale.sx *= -1; if (IsMirrorByX()) scale.sy *= -1; return scale; } AcGeScale3d THDbEquipment::GetInsert3dScale() const { assertReadEnabled(); AcGeScale3d scale(1); double x=0,y=0,z=0; // GetInsertExtend(m_idBlock2d,x,y,z); // mcl modify GetInsertExtend(m_idBlock3d,x,y,z); if(x>1.0E-3) scale.sx *= m_dSizeX/x; if(y>1.0E-3) scale.sy *= m_dSizeY/y; if(z>1.0E-3) scale.sz *= m_dSizeZ/z; if(IsMirrorByY()) scale.sx *= -1; if(IsMirrorByX()) scale.sy *= -1; return scale; } Acad::ErrorStatus THDbEquipment::ExplodeOrDraw2d(XExplodeDraw &dc) const { // cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制) AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead); if (player.openStatus() == Acad::eOk && player->isOff()) { return Acad::eOk; } if(IsSysType()) return DrawSystem(dc); return _ExplodeOrDraw2d(dc); } Acad::ErrorStatus THDbEquipment:: _ExplodeOrDraw2d(XExplodeDraw &dc,BOOL bZEqual0) const { if(!m_idBlock2d.isValid()) return Acad::eInvalidInput; if(fabs(m_vtDirection.x)<1.0E-6 && fabs(m_vtDirection.y)<1.0E-6) return Acad::eOk; //垂直设备 AcGeScale3d scale=GetInsert2dScale(); OPENOBJ_BEGIN(m_idBlock2d, AcDb::kForRead, AcDbBlockTableRecord, pBlock); if(pBlock != NULL) { XPoint ptLocation(m_ptLocation); if(bZEqual0) ptLocation.z=0; double dAngle = ads_angle(XPoint(),m_vtDirection); dc.DrawBlock(*pBlock,ptLocation,scale,dAngle,TRUE); } OPENOBJ_END(); //绘制接口 for(int i=0; iy += m_dSizeZ/2; poly2[i]->y -= m_dSizeZ/2; dc << XLine(*poly1[i],*poly2[i]); } dc << poly1 << poly2; return Acad::eOk; } Acad::ErrorStatus THDbEquipment::DrawLabelText(XExplodeDraw &dc) const { AcDbObjectId idLayerOld=dc.GetLayerId(); if(m_idLabelLayer.isValid()) dc.SetLayer(m_idLabelLayer); TDbMText text; text.setPropertiesFrom(this); text.setLayer(m_idLabelLayer); text.SetStyleId(m_idTextStyle); text.SetText((const TCHAR*)m_sLabel); text.SetHeight(m_dTextHeight); text.SetAlignment(XExplodeDraw::kLeft); text.SetLineSpace(0.4*m_dTextHeight); text.SetPageWidth(200*m_dTextHeight/3.5); AcDbExtents extents; if(text.getGeomExtents(extents)==Acad::eOk) { XPoint ptMin=extents.minPoint(); XPoint ptMax=extents.maxPoint(); double x=ptMax.x-ptMin.x; double y=ptMax.y-ptMin.y; XPoint ptLabel=m_ptLabel; ptLabel.z=0; if(IsOutLabel()) { // 引出标注 double dDist = GetPScale()*m_dTextHeight/3; XPoint ptMid(ptLabel.x+dDist,ptLabel.y+y+dDist,0); text.SetLocation(ptMid); XPoint ptLabelOut=m_ptLabelOut; ptLabelOut.z=0; XPoint ptLabel2(ptLabel.x+x+2*dDist,ptLabel.y,0); dc << XLine(ptLabel,ptLabel2) << XLine(ptLabel,ptLabelOut); } else { // 非引出标注 double dAngle=GetTextRotation(); XPoint ptMid=ptLabel; ptMid.x -= x/2; ptMid.y += y/2; ads_matrix mat; ptLabel.GetRotationMatrix(dAngle,mat); ptMid.TransformBy(mat); text.SetRotation(dAngle); text.SetLocation(ptMid); } dc.DrawEntity(text); } dc.SetLayer(idLayerOld); return Acad::eOk; } Acad::ErrorStatus THDbEquipment::ExplodeOrDraw3d(XExplodeDraw &dc) const { if (IsSysType()) return DrawSystem(dc, FALSE); if (!m_idBlock3d.isValid()) return _ExplodeOrDraw2d(dc, FALSE); AcGeScale3d scale = GetInsert3dScale(); OPENOBJ_BEGIN(m_idBlock3d, AcDb::kForRead, AcDbBlockTableRecord, pBlock); if (pBlock != NULL) { XVector3D vtNormal(0,0,1); if (fabs(m_vtDirection.z)>1.0E-6) { // 非水平面,计算法向 vtNormal = XVector3D(1,0,0)*m_vtDirection; vtNormal.Normalize(); } XPoint ptLoc = Wcs2Ecs(m_ptLocation, vtNormal); double nRotEcs = ads_angle(XPoint(),m_vtDirection); // 计算ECS下的转角 AcDbBlockReference insert(ptLoc, m_idBlock3d); insert.setRotation(nRotEcs); insert.setScaleFactors(scale); if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0) { AcGeMatrix3d mat=insert.blockTransform(); AcGiGeometry *geom=((XAcGiViewDraw &)dc).GetCommonDraw()->rawGeometry(); geom->pushModelTransform(mat); geom->draw(pBlock); geom->popModelTransform(); } else if (_tcscmp(dc.Desc(), XExplodeStream::Descriptor())==0) { ((XExplodeStream &)dc).Append((AcDbEntity *)insert.clone()); } } else { return Acad::eInvalidInput; } OPENOBJ_END(); // 绘制接口 for (int i=0; i &info) const { CString sBlkName,sDesName; if(GetBlkNameById(m_idBlock2d,sBlkName,sDesName) && !sDesName.IsEmpty()) { info.Append(new TObjInfoUnit(_T("对象名称"), (const TCHAR*)sDesName)); } if(m_modelType==TPipeSys::kModel) { for(int i=0; i=0 && idx=nNodeGrip && idx=nThisGrip) continue; if(indices[i]==nNodeGrip){ m_ptLocation.TransformBy(mat); m_ptLabel.TransformBy(mat); m_ptLabelOut.TransformBy(mat); for(int j=0; jEndPoint() : pPipe->StartPoint(); int nCount = m_lstInterface.Length(); for (int i=0; igetFirstDeriv(ptRef, vt); if (nPos) vt.negate(); AcGeTol myTol; myTol.setEqualVector(1.0E-6); // sg modify,扩大了容忍度 if (vt.isCodirectionalTo(iFace.m_vtLocation, myTol)) { bRet = TRUE; break; } } } } OPENOBJ_END(); return bRet; } // 对st类型的接口进行重新连接 void THDbEquipment::UpdateLinkage(const XPoint &ptAt, TPipeSys::SysType st, const DList &idPipes) { assertWriteEnabled(); double dSnap = PS_SNAP; for (int i=0; iStartPoint()) < dSnap) { AcGeVector3d vt; pPipe->getFirstDeriv(pPipe->StartPoint(), vt); if (vt.isCodirectionalTo(iFace.m_vtLocation)) { iFace.m_sysType = pPipe->GetSysType(); // iFace.m_sSysLabel = pPipe->GetSysLabel(); continue; } } else if (iFace.m_ptLocation.Distance(pPipe->EndPoint()) < dSnap) { AcGeVector3d vt; pPipe->getFirstDeriv(pPipe->EndPoint(),vt); vt.negate(); if (vt.isCodirectionalTo(iFace.m_vtLocation)) { iFace.m_sysType = pPipe->GetSysType(); // iFace.m_sSysLabel = pPipe->GetSysLabel(); continue; } } else { // sg add if (pPipe->isKindOf(TDbDuct::desc())) { TDbDuct *pDuct = TDbDuct::cast(pPipe); if (pDuct->FindEquipment(objectId())) { iFace.m_sysType = pDuct->GetSysType(); continue; } } } } OPENOBJ_END(); // 重新验证所有管线 iFace.m_idPipe = AcDbObjectId::kNull; for (int j=0; jStartPoint()) < dSnap) { AcGeVector3d vt; pPipe->getFirstDeriv(pPipe->StartPoint(), vt); if (vt.isCodirectionalTo(iFace.m_vtLocation)) { iFace.m_idPipe = id; iFace.m_sysType = pPipe->GetSysType(); // iFace.m_sSysLabel = pPipe->GetSysLabel(); break; } } else if (iFace.m_ptLocation.Distance(pPipe->EndPoint()) < dSnap) { AcGeVector3d vt; pPipe->getFirstDeriv(pPipe->EndPoint(), vt); vt.negate(); if (vt.isCodirectionalTo(iFace.m_vtLocation)) { iFace.m_idPipe = id; iFace.m_sysType = pPipe->GetSysType(); // iFace.m_sSysLabel = pPipe->GetSysLabel(); break; } } } OPENOBJ_END(); } } } void THDbEquipment::SetLocation(const XPoint &pt) { assertWriteEnabled(); if (m_ptLabelOut == m_ptLocation) m_ptLabelOut = pt; if (m_ptLabel==m_ptLocation) m_ptLabel = pt; ads_matrix mat; m_ptLocation.GetMoveMatrix(pt, mat); for (int i=0; i1.0E-3 || fabs(y-m_dSizeY)>1.0E-3 || fabs(z-m_dSizeZ)>1.0E-3) ) { ads_matrix mat; double dScaleX = fabs(m_dSizeX)>1.0E-3 ? x/m_dSizeX : 1; double dScaleY = fabs(m_dSizeY)>1.0E-3 ? y/m_dSizeY : 1; double dScaleZ = fabs(m_dSizeZ)>1.0E-3 ? z/m_dSizeZ : 1; m_ptLocation.GetScaleMatrix(dScaleX, dScaleY, dScaleZ, mat); for (int i=0; i1.0E-3) { ads_matrix mat; dAngle -= GetAngle(); m_ptLocation.GetRotationMatrix(dAngle, mat); for (int i=0; i