//DimPipe.cpp #include "stdafx.h" #include #include #include #include #include #include #include #include #include "jig.h" #include "TPipeGraph.h" #include "DbVPipeDim.h" #include "TVPipeDimJig.h" #include "SprinklerDimDlg.h" #include "GlobalFunction.h" #define IDC_USER_COMBOX_TYPE3 1092 extern BOOL IsPtOnPipe(XPoint pt, Entity ent); extern void SearchOneselfPipe(AcDbObjectId idPipe, TPipeGraph &PipeGraph); //*************************************************************************************************** // 标注图层 //*************************************************************************************************** CString GetEquipLayBySys(TPipeSys::SysType sys) { CString csRet; if(sys == TPipeSys::kFeedWater || sys == TPipeSys::kFeedWater2 || sys == TPipeSys::kFeedWater3) // cet 2011.12.6 modify 增加中高区 csRet = LAY_EQ_FEED; else if(sys == TPipeSys::kHeatFeedWater || sys == TPipeSys::kHeatFeedWater2 || sys == TPipeSys::kHeatFeedWater3) // cet 2011.12.6 modify 增加中高区 csRet = LAY_EQ_HEADFEED; else if(sys == TPipeSys::kHeatBackWater || sys == TPipeSys::kHeatBackWater2 || sys == TPipeSys::kHeatBackWater3) // cet 2011.12.6 modify 增加中高区 csRet = LAY_EQ_HEADBACK; else if(sys == TPipeSys::kDirtWater) csRet = LAY_EQ_DIRT; else if(sys == TPipeSys::kUselessWater) csRet = LAY_EQ_USELESS; else if(sys == TPipeSys::kRainWater) csRet = LAY_EQ_RAIN; else if(sys == TPipeSys::kUsedWater || sys == TPipeSys::kUsedWater2 || sys == TPipeSys::kUsedWater3) // cet 2011.12.6 modify 增加中高区 csRet = LAY_EQ_USED; else if(sys == TPipeSys::kFireFighting || sys == TPipeSys::kFireFighting2 || sys == TPipeSys::kFireFighting3) // cet 2011.12.6 modify 增加中高区 csRet = LAY_EQ_FIRE; else if(sys == TPipeSys::kSprinkle || sys == TPipeSys::kSprinkle2 || sys == TPipeSys::kSprinkle3) // cet 2011.12.6 modify 增加中高区 csRet = LAY_EQ_SPRINKLE; else if(sys == TPipeSys::kCoagulate) csRet = LAY_EQ_COAGULATE; else if(sys == TPipeSys::kDrink) csRet = LAY_EQ_DRINK; else if(sys == TPipeSys::kPressDirt) csRet = LAY_EQ_PRESSDIRT; else if(sys == TPipeSys::kPressUseless) csRet = LAY_EQ_PRESSUSELESS; else if(sys == TPipeSys::kPressRain) csRet = LAY_EQ_PRESSRAIN; else if(sys == TPipeSys::kCivilFeed) csRet = LAY_EQ_USER1; else if(sys == TPipeSys::kCycleFeed) csRet = LAY_EQ_USER2; else if(sys == TPipeSys::kOther) csRet = LAY_EQ_OTHER; else if(sys == TPipeSys::kUser3) // cet 2011.12.2 add user3-user8 csRet = LAY_EQ_USER3; else if(sys == TPipeSys::kUser4) csRet = LAY_EQ_USER4; else if(sys == TPipeSys::kUser5) csRet = LAY_EQ_USER5; else if(sys == TPipeSys::kUser6) csRet = LAY_EQ_USER6; else if(sys == TPipeSys::kUser7) csRet = LAY_EQ_USER7; else if(sys == TPipeSys::kUser8) csRet = LAY_EQ_USER8; return csRet; } //*************************************************************************************************** // 立管标注 //*************************************************************************************************** //extern const TCHAR* GetDnByMat(const TCHAR* szMat); // zxl 2013.08.22 add static CString GetXDataByName(const AcDbObjectId &id,const TCHAR*szName) { CString sXData; AcDbEntity *pEnt = NULL; if (acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead) == Acad::eOk) { resbuf *pRb = pEnt->xData(szName); if (pRb != NULL) { CString csRet; if (pRb != NULL) { resbuf *pTemp = pRb; if (pTemp->rbnext != NULL) { pTemp = pTemp->rbnext; if (pTemp->restype == 1000) csRet = pTemp->resval.rstring; } } ads_relrb(pRb); sXData = csRet; } pEnt->close(); } return sXData; } // zxl 2013.08.22 add double GetDimStrLen(const AcDbObjectId id, double &dDnLength) { CString sText, csDimHead; ads_name name; acdbGetAdsName(name, id); Entity entPipe = name; AcDbEntity *pEnt = NULL; if (Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead)) { TDbPipe *pPipe = TDbPipe::cast(pEnt); if (pPipe != NULL) { CString csLabel = pPipe->GetLabel(); double dDn = pPipe->GetDnDiameter(); csDimHead.Format(_T("%s%.0f"), csLabel, dDn); } pEnt->close(); } CString csLay = GetPipeLayer(entPipe); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); if(!g_bIsPipeDimCir) csDim += _T("-"); int nFind = csDim.Find(_T("-"),0); if (nFind != -1) csDim = csDim.Left(nFind); CString sPipeIndex = GetXDataByName(id, _T("PIPE-SERIAL")); CString sFloorNum = GetXDataByName(id, _T("BUILDING-SERIAL")); if (!sFloorNum.IsEmpty()) { switch(g_iVPipeDimStyle) { case TVPipeDim::eType1: sText.Format(_T("%s-%s-%s"), sFloorNum, csDim, sPipeIndex); break; case TVPipeDim::eType2: sText.Format(_T("%s-%s-%s"), csDim, sFloorNum, sPipeIndex); break; case TVPipeDim::eType3: sText.Format(_T("%s-%s%s"), csDim, sFloorNum, sPipeIndex); break; case TVPipeDim::eType4: { sText.Format(_T("%s%s-%s"), sFloorNum, csDim, sPipeIndex); break; } case TVPipeDim::eType5: sText.Format(_T("%s%s-%s"), csDim, sFloorNum, sPipeIndex); break; default: break; } } else { sText.Format(_T("%s-%s"), csDim, sPipeIndex); } double dLabelLen = 0.0; AcDbObjectId idTextStyle = InitTwtTextStyle(g_csVPipeStyle); CString sStyleName = GetSymbolName(idTextStyle).cs(); struct resbuf* pRb = acutBuildList(RTDXF0, _T("TEXT"), 1, sText, 7, sStyleName, 40, g_nVPipeHeight, 41, DocGetPScale(), 0); ads_point adsPt1, adsPt2; int iRet = acedTextBox(pRb, adsPt1, adsPt2); dLabelLen = asPnt3d(adsPt1).distanceTo(asPnt3d(adsPt2)) + g_nVPipeHeight*DocGetPScale(); acutRelRb(pRb); TDbText text; text.SetText((const TCHAR*)sText); text.SetStyleId(idTextStyle); text.SetLocation(XPoint()); text.SetHeight(g_nVPipeHeight); text.SetAlignment(XExplodeDraw::kMiddleCenter); XPoint pt = text.GetExtents(); dLabelLen = asPnt3d(adsPt1).distanceTo(pt); text.SetText((const TCHAR*)csDimHead); pt = text.GetExtents(); dDnLength = asPnt3d(adsPt1).distanceTo(pt); return dLabelLen; } // zxl 2012.06.29 add 通过管线图层获取相对应的立管图层 void GetVPipeLayerByPipeLayer(CString &strPipeLayer) { if (strPipeLayer.Compare(LAY_PIPE_FEED) == 0 || strPipeLayer.Compare(LAY_PIPE_FEED2) == 0 || strPipeLayer.Compare(LAY_PIPE_FEED3) == 0) { strPipeLayer = LAY_VPIPE_FEED; } else if (strPipeLayer.Compare(LAY_PIPE_HEADFEED) == 0 || strPipeLayer.Compare(LAY_PIPE_HEADFEED2) == 0 || strPipeLayer.Compare(LAY_PIPE_HEADFEED3) == 0 ) { strPipeLayer = LAY_VPIPE_HEADFEED; } else if (strPipeLayer.Compare(LAY_PIPE_HEADBACK) == 0 || strPipeLayer.Compare(LAY_PIPE_HEADBACK2) == 0 || strPipeLayer.Compare(LAY_PIPE_HEADBACK3) == 0) { strPipeLayer = LAY_VPIPE_HEADBACK; } else if (strPipeLayer.Compare(LAY_PIPE_DIRT) == 0) { strPipeLayer = LAY_VPIPE_DIRT; } else if (strPipeLayer.Compare(LAY_PIPE_USELESS) == 0) { strPipeLayer = LAY_VPIPE_DIRT; } else if (strPipeLayer.Compare(LAY_PIPE_RAIN) == 0) { strPipeLayer = LAY_VPIPE_RAIN; } else if (strPipeLayer.Compare(LAY_PIPE_USED) == 0 || strPipeLayer.Compare(LAY_PIPE_USED2) == 0 || strPipeLayer.Compare(LAY_PIPE_USED3) == 0) { strPipeLayer = LAY_VPIPE_USED; } else if (strPipeLayer.Compare(LAY_PIPE_FIRE) == 0 || strPipeLayer.Compare(LAY_PIPE_FIRE2) == 0 || strPipeLayer.Compare(LAY_PIPE_FIRE3) == 0) { strPipeLayer = LAY_VPIPE_FIRE; } else if (strPipeLayer.Compare(LAY_PIPE_SPRINKLE) == 0 || strPipeLayer.Compare(LAY_PIPE_SPRINKLE2) == 0 || strPipeLayer.Compare(LAY_PIPE_SPRINKLE3) == 0) { strPipeLayer = LAY_VPIPE_SPRINKLE; } else if (strPipeLayer.Compare(LAY_PIPE_COAGULATE) == 0) { strPipeLayer = LAY_VPIPE_COAGULATE; } else if (strPipeLayer.Compare(LAY_PIPE_DRINK) == 0) { strPipeLayer = LAY_VPIPE_DRINK; } else if (strPipeLayer.Compare(LAY_PIPE_PRESSDIRT) == 0) { strPipeLayer = LAY_VPIPE_PRESSDIRT; } else if (strPipeLayer.Compare(LAY_PIPE_PRESSUSELESS) == 0) { strPipeLayer = LAY_VPIPE_PRESSUSELESS; } else if (strPipeLayer.Compare(LAY_PIPE_PRESSRAIN) == 0) { strPipeLayer = LAY_VPIPE_PRESSRAIN; } else if (strPipeLayer.Compare(LAY_PIPE_OTHER) == 0) { strPipeLayer = LAY_VPIPE_OTHER; } else if(strPipeLayer.Compare(LAY_PIPE_USER1) == 0) { strPipeLayer = LAY_VPIPE_USER1; } else if(strPipeLayer.Compare(LAY_PIPE_USER2) == 0) { strPipeLayer = LAY_VPIPE_USER2; } else if (strPipeLayer.Compare(LAY_PIPE_USER3) == 0) { strPipeLayer = LAY_VPIPE_USER3; } else if (strPipeLayer.Compare(LAY_PIPE_USER4) == 0) { strPipeLayer = LAY_VPIPE_USER4; } else if (strPipeLayer.Compare(LAY_PIPE_USER5) == 0) { strPipeLayer = LAY_VPIPE_USER5; } else if (strPipeLayer.Compare(LAY_PIPE_USER6) == 0) { strPipeLayer = LAY_VPIPE_USER6; } else if (strPipeLayer.Compare(LAY_PIPE_USER7) == 0) { strPipeLayer = LAY_VPIPE_USER7; } else if (strPipeLayer.Compare(LAY_PIPE_USER8) == 0) { strPipeLayer = LAY_VPIPE_USER8; } } void DoDimStandPipe(AcDbObjectId idPipe, const TCHAR* szName, const TCHAR* szSerial) { DocSetMultiLeaderDistRatio(0.2); //设置文字距线端距离(全局) XPoint ptPick1, ptPick2; TCHAR szLayer[256]; double nDn; CString csDimHead; CString csLay; double dRadius(0); CString sPipeLayer; // cet 2012.4.19 add OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ dRadius = pPipe->GetRadius()*pPipe->GetPScale(); TCHAR *layer; layer = pPipe->layer(); _tcscpy(szLayer, layer); csDimHead = pPipe->GetLabel(); sPipeLayer = layer; // cet 2012.4.19 add delete [] layer; if(csDimHead == _T("")){ int iMaterial = pPipe->GetMaterial(); CString csMat = GetPipeMaterialByIdx(iMaterial); csDimHead = GetDnByMat(csMat); } nDn = pPipe->GetDnDiameter(); // 2013.3.28 cet modify csDimHead用法可能导致崩溃,尤其是debug模式下 // csDimHead.Format(_T("%s%.0f"), csDimHead, nDn); CString sTemp = csDimHead; csDimHead.Format(_T("%s%.0f"), sTemp, nDn); if(pPipe->IsVertical()){ ptPick1 = pPipe->StartPoint(); ptPick1.z = 0; } else /*if(!g_bIsPipeDimCir)*/{ if(ads_getpoint(NULL, _T("\n请点取标注起点<退出>:"), ptPick1) != RTNORM) return; ptPick1 = Ucs2Wcs(ptPick1); } csLay = GetDimLayBySys(pPipe->GetSysType()); } OPENOBJ_END(); InitLayer(csLay); // InitLayer(LAY_VPIPE_DIM); // DocSetText2Base(0.2); CString csDim = szName; // csDim += szSerial; int nFind = csDim.Find(_T("-"),0); if (nFind != -1) csDim = csDim.Left(nFind); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csVPipeStyle); if(!idTextStyle) return; TDbVPipeDim *pDim = new TDbVPipeDim; pDim->SetDimRadius(g_nDimCirDiam); pDim->SetDimType(g_bIsPipeDimCir); // ZXL 2013.08.22 ADD double dDn = 0.0; double dDst = GetDimStrLen(idPipe, dDn) + g_dVPipeDimDn2Label * DocGetPScale(); CString sDst; sDst.Format(_T("%.1f"), dDst); dDst = _tstof(sDst); pDim->SetDnDistance2LabelLoc(dDst); pDim->SetDnDistBetweenLabel(g_dVPipeDimDn2Label); // cet 2012.8.27 modify 无论当前设置是否是标注4样式都需设置此值,以便编辑标注更改为样式4时,显示正确设置 // // cet 2012.4.19 add // if (g_bIsPipeDimCir == TVPipeDim::eDimType4) { GetVPipeLayerByPipeLayer(sPipeLayer);// zxl 2012.06.29 add 通过管线图层获取相对应的立管图层 pDim->SetShowDnForDimType4(IsShowVPipeDimDn(sPipeLayer) ? true : false); pDim->SetAlignTypeForDimType4(g_nAlignTypeForVPipeDim4); } pDim->SetDimTypeText(csDim); pDim->SetTextHeight(g_nVPipeHeight); if (g_bIsPipeDimCir == TVPipeDim::eDimType2) { pDim->SetTextStyleId(InitTwtTextStyle(g_csCircleTextStyle)); } else { pDim->SetTextStyleId(idTextStyle); pDim->SetText2BaseRatio(g_nDimCirDiam); // SR 2009-11-5 全局变量g_nDnDimDist2Pipe改为g_nDimCirDiam } pDim->SetVtDir(AcGeVector3d::kXAxis); pDim->SetStartPt(ptPick1); pDim->SetTextLayerId(InitLayer(LAY_TEXT)); pDim->setLayer(csLay); pDim->SetLayoutRotation(Ucs2Wcs(0.0)); pDim->SetVPipeFloorType(g_iVPipeDimStyle); pDim->SetVPipeId(idPipe); TVPipeDimJig jig(pDim); jig.SetStartPt(ptPick1); if(jig.DoIt() == RTNORM) { if (g_bIsPipeDimCir == TVPipeDim::eDimType2) { pDim->AddToCSpace(Adesk::kFalse); pDim->setLayer(LAY_VPIPE_DIM); pDim->close(); } else { AddToCurrentSpace(pDim,Adesk::kTrue); } if(_tcscmp(szLayer, _T("")) != 0) { Entity entLast; entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); } } else { delete pDim; } } void DoDimStandPipe2(AcDbObjectId idPipe, const TCHAR* szName, const TCHAR* szSerial) { XPoint ptPick1, ptPick2; TCHAR szLayer[256]; double nDn; CString csDimHead; double dRadius(0); OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ dRadius = pPipe->GetRadius()*pPipe->GetPScale(); TCHAR *layer; layer = pPipe->layer(); _tcscpy(szLayer, layer); csDimHead = pPipe->GetLabel(); delete [] layer; if(csDimHead == ""){ int iMaterial = pPipe->GetMaterial(); CString csMat = GetPipeMaterialByIdx(iMaterial); csDimHead = GetDnByMat(csMat); } nDn = pPipe->GetDnDiameter(); csDimHead.Format(_T("%s%.0f"), csDimHead, nDn); if(pPipe->IsVertical()){ ptPick1 = pPipe->StartPoint(); ptPick1.z = 0; } else if(!g_bIsPipeDimCir){ if(ads_getpoint(NULL, _T("\n请点取标注起点<退出>:"), ptPick1) != RTNORM) return; } } OPENOBJ_END(); InitLayer(LAY_VPIPE_DIM); // DocSetText2Base(0.2); CString csDim = szName; csDim += szSerial; AcDbObjectId idTextStyle = InitTwtTextStyle(g_csVPipeStyle); if(!idTextStyle) return; if(g_bIsPipeDimCir == 1){ TDbSymbDrawingIndex *pIndex = new TDbSymbDrawingIndex; pIndex->SetTextStyleId(InitTwtTextStyle(g_csCircleTextStyle)); pIndex->SetIndexLabel(szSerial); pIndex->SetDrawingLabel(szName); pIndex->SetTextLayerId(InitLayer(LAY_TEXT)); pIndex->SetRadius(g_nDimCirDiam/2); pIndex->SetLineWidth(0); XPoint ptLoc; xg_getvar(_T("VIEWCTR"), ptLoc); pIndex->SetCenter(Ucs2Wcs(ptLoc)); TDrawingIdxEdJig jig(pIndex); jig.SetPrompt(_T("\n请给出标注位置<退出>:")); if(jig.DoIt()==RTNORM) { pIndex->AddToCSpace(Adesk::kFalse); pIndex->setLayer(LAY_VPIPE_DIM); pIndex->close(); } else delete pIndex; if(_tcscmp(szLayer, _T("")) != 0){ Entity entLast; entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); } return; } else if(g_bIsPipeDimCir == 3){ TDbSymbMultiLeader *pLeader = new TDbSymbMultiLeader; XPointList lstVertexes; lstVertexes.Append(new XPoint(ptPick1)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->SetText1(csDim); pLeader->SetText2(csDimHead); pLeader->SetLeaderPoint(ptPick1); pLeader->SetArrow(TDbSymbMultiLeader::kNone); pLeader->SetTextStyleId(idTextStyle); pLeader->SetTextLayerId(InitLayer(LAY_TEXT)); pLeader->SetTextHeight(g_nVPipeHeight); pLeader->SetTextBaseLen(pLeader->GetDefaultTextBaseLen()); TLeaderEdJig jig(pLeader); jig.SetOperCode(TLeaderEdJig::kLeader); jig.SetPrompt(_T("\n输入引线位置<退出>: ")); if(jig.DoIt()==RTNORM) { XPoint ptPick2 = pLeader->GetLeaderPoint(); //// double dRotation = ads_angle(ptPick1, ptPick2); // ads_polar(ptPick1, dRotation, dRadius, ptPick1); lstVertexes.Reset(); lstVertexes.Append(new XPoint(ptPick1)); pLeader->SetLeaderVertexes(lstVertexes); pLeader->AddToCSpace(Adesk::kFalse); pLeader->setLayer(LAY_VPIPE_DIM); pLeader->close(); // ((TDbEntity *)pLeader->clone())->AddToCSpace(Adesk::kTrue); } else delete pLeader; } else{ TDbSymbComposing ent; ent.setLayer(LAY_VPIPE_DIM); ent.SetLayoutRotation(Ucs2Wcs(0.0)); ent.SetStartPoint(ptPick1); ent.SetTurnPoint(ptPick1); ent.SetText(csDim); ent.SetSideText(0); ent.SetTextStyleId(idTextStyle); ent.SetTextLayerId(InitLayer(LAY_TEXT)); ent.SetTextHeight(g_nVPipeHeight); ent.SetTextBaseLen(ent.GetDefaultTextBaseLen()*1.3); TComposingEdJig jig(&ent); jig.SetPrompt(_T("\n请给出标注第二点<退出>:")); jig.SetOperCode(TComposingEdJig::kTurnPoint); if(jig.DoIt()==RTNORM) { // XPoint ptPick2 = ent.GetTurnPoint(); // double dRotation = ads_angle(ptPick1, ptPick2); // ads_polar(ptPick1, dRotation, dRadius, ptPick1); // ent.SetStartPoint(ptPick1); ((TDbEntity *)ent.clone())->AddToCSpace(Adesk::kTrue); } } if(_tcscmp(szLayer, _T("")) != 0){ Entity entLast; entLast.GetLast(); OPENOBJ_BEGIN(entLast, AcDb::kForWrite, TDbSymbComposing, pDim); if(pDim){ pDim->setLayer(LAY_VPIPE_DIM); } OPENOBJ_END(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); } } Entity CheckSameSerialPipe(const TCHAR *szLay, const TCHAR *sNum, Entity entPipe) { PickSet ss(SS_FREE); XPoint pt1,pt2; GetPipePoint(entPipe, pt1, pt2); pt1.z = 0; RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, szLay, NULL); ss.Get(_T("X"), NULL, NULL, rbMask); long len = ss.Length(); for(long i=0;iIsVertical()){ pt2 = pPipe->StartPoint(); pt2.z = 0; CString csSerial = ReadXdata(ent, _T("PIPE-SERIAL")); if(csSerial.Compare(sNum) == 0 && !(entPipe == ent) && pt1 != pt2){ return ent; } } OPENOBJ_END(); } return Entity(); } void DrawRedFork(XPoint pt1) { XPoint p1, p2, p3, p4; ads_polar(pt1, 0, 500, p1); ads_polar(p1, PI/2, 500, p1); ads_polar(pt1, PI, 500, p2); ads_polar(p2, PI/2, -500, p2); ads_grdraw(p1, p2, 1, 0); ads_polar(pt1, PI/2, 500, p3); ads_polar(p3, PI, 500, p3); ads_polar(pt1, PI/2, -500, p4); ads_polar(p4, 0, 500, p4); ads_grdraw(p3, p4, 1, 0); } //输入立管,返回立管编号 Entity GetPipeDimByEnt(Entity ent) { PickSet ssAll(SS_FREE); RBList rbMaskVPipe(RTDXF0, _T("ATS_VPIPEDIM"),NULL); ssAll.Get(_T("A"),NULL,NULL,rbMaskVPipe); long lLen = ssAll.Length(); PickSet ssRenew(SS_FREE); for (long m = 0; m < lLen; ++m) { OPENOBJ_BEGIN(ssAll[m], AcDb::kForRead, TDbVPipeDim, pDim); if (pDim != NULL) { AcDbObjectId idDim = pDim->GetVPipeId(); ads_name name; acdbGetAdsName(name,idDim); Entity ent2(name); if (ent2 == ent) { ssRenew += ssAll[m]; } } OPENOBJ_END(); } Entity entRet; if(ssRenew.Length() == 1) //正常情况下,只得到一个编号,返回它 entRet = ssRenew[0L]; else if(ssRenew.Length() == 0) //没有得到编号,可能1没有标注 2标注是copy过来的 { XPoint ptS, ptE; GetPipePoint(ent, ptS, ptE); PickSet ssDim(SS_FREE); GetPointPickSet(ptS, ssDim, rbMaskVPipe, 50); if(ssDim.Length() == 1) { entRet = ssDim[0L]; AcDbObjectId idDim; acdbGetObjectId(idDim, entRet); RebindVPipeDim(idDim); //重新绑定 } } else if(ssRenew.Length() > 1) //如果得到多于1个,说明曾经被复制过 { XPoint ptS, ptE; GetPipePoint(ent, ptS, ptE); PickSet ssDim(SS_FREE); GetPointPickSet(ptS, ssDim, rbMaskVPipe, 50); if(ssDim.Length() == 1) { Entity entTmp = ssDim[0L]; if(ssRenew.IsInclude(entTmp)) entRet = entTmp; } } return entRet; } //从立管上得到立管标注,圆标注复杂一些,需要扩大搜索范围 /* Entity GetPipeDimByPt(XPoint pt, int idx) { PickSet ssDim(SS_FREE); RBList rbMaskDim = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); // RBList rbMaskDim(RTDXF0, _T("ATS_COMPOSING"), 8, LAY_VPIPE_DIM, NULL); RBList rbMaskDim2(RTDXF0, _T("ATS_DRAWINGINDEX"), 8, LAY_VPIPE_DIM, NULL); RBList rbMaskDim3(RTDXF0, _T("ATS_MULTILEADER"), NULL); if(g_bIsPipeDimCir == 0 || g_bIsPipeDimCir == 2){ GetPointPickSet(pt, ssDim, rbMaskDim, 50); if(ssDim.Length() == 1){ Entity entDim = ssDim[0L]; return entDim; } return Entity(); } else if(g_bIsPipeDimCir == 3){ GetPointPickSet(pt, ssDim, rbMaskDim3, 50); if(ssDim.Length() == 1){ Entity entDim = ssDim[0L]; return entDim; } return Entity(); } GetPointPickSet(pt, ssDim, rbMaskDim2, 500); if(ssDim.Length() == 0){ GetPointPickSet(pt, ssDim, rbMaskDim2, 1000); if(ssDim.Length() == 0){ GetPointPickSet(pt, ssDim, rbMaskDim2, 1500); } } long len = ssDim.Length(); for(long i=0;iGetIndexLabel(); if(_ttoi(csText) == idx) return ent; } OPENOBJ_END(); } return Entity(); } */ void FindStandPipeBySerial() { TCHAR szText[256]; RBList rbMask(RTDXF0, _T("ATS_VPIPEDIM"), NULL); PickSet ss(SS_FREE); ss.Get(_T("X"), NULL, NULL, rbMask); long len = ss.Length(); XStringList lstWellName, lstRepeat; for(long i=0;iGetDimTypeText(csHead); CString sSerial; pDim->GetDimVPipeNum(sSerial); CString csName,csFloor; pDim->GetVPipeFloorNum(csFloor); if (csFloor.IsEmpty()) csName.Format(_T("%s-%s"), csHead, sSerial); else csName.Format(_T("%s-%s-%s"), csHead,csFloor, sSerial); if(lstWellName.Index(csName, 0) < 0) lstWellName.Append(tstrnew(csName)); else lstRepeat.Append(tstrnew(csName)); } OPENOBJ_END(); } for(int j=0;j:"), szText) != RTNORM) return; if(_tcsicmp(szText, _T("")) == 0) return; int count = 0; AcDbObjectIdArray idArray; PickSet ssWell(SS_FREE); for(i=0;iGetDimTypeText(csHead); // int iSerial = pDim->GetDimVPipeNum(); CString csName1, csName2; pDim->GetDimText(csName1); if(_tcsicmp(csName1, szText) == 0){ AcDbObjectId id = pDim->GetVPipeId(); idArray.append(id); ssWell += ent; count ++; } } OPENOBJ_END(); } XPoint ptCen, ptLow, ptUp; double x,y,z; ssWell.GetExtend(ptCen, &x, &y, &z); ptLow = ptUp = ptCen; ptLow.x -= x; ptLow.y -= y; ptUp.x += x; ptUp.y += y; if(count < 1) adsout << _T("\n没有发现该编号的立管!"); else if(count > 1){ adsout << _T("\n发现多个重名的立管!"); AssureInCurrentView(ptLow, ptUp); } else{ adsout << _T("\n已经成功发现!该立管位于屏幕中心黄叉处。"); arxZoomTo(ptCen, 100*DocGetPScale(), 100*DocGetPScale()); } for(i=0;iIsVertical()){ CString csName = ReadXdata(ent, _T("PIPE-SERIAL")); CString csLay = pPipe->GetLayer(); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); // TPipeSys::SysType sys = pPipe->GetSysType(); // CString csDim = g_csPipeDim[GetPipeLayerIdxBySys(sys)] + _T("L"); csName = csDim + _T("-") + csName; if(lstWellName.Index(csName, 0) < 0) { lstWellName.Append(tstrnew(csName)); } else lstRepeat.Append(tstrnew(csName)); } OPENOBJ_END(); } for(int j=0;j:"), szText) != RTNORM) return; if(_tcsicmp(szText, _T("")) == 0) return; int count = 0; PickSet ssWell(SS_FREE); for(i=0;iIsVertical()){ CString csName = ReadXdata(ent, _T("PIPE-SERIAL")); CString csLay = pPipe->GetLayer(); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); // TPipeSys::SysType sys = pPipe->GetSysType(); // CString csDim = g_csPipeDim[GetPipeLayerIdxBySys(sys)] + _T("L"); csName = csDim + _T("-") + csName; if(_tcsicmp(csName, szText) == 0){ ssWell += ent; count ++; } } OPENOBJ_END(); } XPoint ptCen, ptLow, ptUp; double x,y,z; ssWell.GetExtend(ptCen, &x, &y, &z); ptLow = ptUp = ptCen; ptLow.x -= x; ptLow.y -= y; ptUp.x += x; ptUp.y += y; if(count < 1) adsout << _T("\n没有发现该编号的立管!"); else if(count > 1){ adsout << _T("\n发现多个重名的立管!"); AssureInCurrentView(ptLow, ptUp); } else{ adsout << _T("\n已经成功发现!该立管位于屏幕中心黄叉处。"); arxZoomTo(ptCen, 100*DocGetPScale(), 100*DocGetPScale()); } for(i=0;i &mapVPipes, AcGeVector3d &vtDir) { AcGeTol tolVec; tolVec.setEqualVector(0.001); std::map::iterator it; it = mapVPipes.begin(); AcGeVector3d vtFirst, vtSecond; AcGePoint3d ptFirst, ptSecond, ptThird; ptFirst = it->second; ptFirst.z = 0; it++; ptSecond = it->second; ptSecond.z = 0; ptFirst = Wcs2Ucs(ptFirst); ptSecond = Wcs2Ucs(ptSecond); vtFirst = ptFirst - ptSecond; it++; if (!vtFirst.isParallelTo(AcGeVector3d::kXAxis, tolVec) && !vtFirst.isParallelTo(AcGeVector3d::kYAxis, tolVec)) { return false; } vtDir = vtFirst; while (it != mapVPipes.end()) { ptThird = it->second; ptThird.z = 0; ptThird = Wcs2Ucs(ptThird); vtSecond = ptSecond - ptThird; if (!vtFirst.isParallelTo(vtSecond, tolVec)) { return false; } ptSecond = ptThird; it++; } return true; } // 对立管按照共线方向进行排序 void SortVPipes(PickSet &ssAll, AcGeVector3d &vtDir) { AcGeTol tolVec; tolVec.setEqualVector(0.001); std::map mapPipe; Entity ent; AcDbObjectId id; AcGePoint3d ptLoc; double dLoc = 0.0; std::map mapVPipes; for (long l = 0l; l < ssAll.Length(); l++) { ent = ssAll[l]; acdbGetObjectId(id, ent); OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe); if(pPipe != NULL) { ptLoc = pPipe->GetStartPoint(); ptLoc.z = 0; WCS2UCS(ptLoc); if (vtDir.isParallelTo(AcGeVector3d::kXAxis, tolVec)) { dLoc = ptLoc.x; } else { dLoc = ptLoc.y; } if(mapPipe.find(dLoc) != mapPipe.end()) { dLoc += 1; } mapPipe.insert(std::make_pair(dLoc, ent)); } OPENOBJ_END(); } ssAll.Free(); std::map::iterator it; for (it = mapPipe.begin(); it != mapPipe.end(); it++) { ssAll += it->second; } } bool CheckPipes(PickSet &ssAll, AcGeVector3d &vtDir) { Entity ent; AcDbObjectId id; AcGePoint3d ptLoc; std::map mapVPipes; long len = ssAll.Length(); for (long l = 0l; l < ssAll.Length(); l++) { ent = ssAll[l]; acdbGetObjectId(id, ent); OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe); if(pPipe != NULL) { if (!pPipe->IsVertical()) { return false; } ptLoc = pPipe->GetStartPoint(); ptLoc.z = 0; mapVPipes.insert(std::make_pair(id, ptLoc)); } OPENOBJ_END(); } if (IsPtsParallel(mapVPipes, vtDir)) { SortVPipes(ssAll, vtDir); return true; } vtDir = AcGeVector3d::kXAxis; SortVPipes(ssAll, vtDir); return false; } // zxl 2013.08.22 add double GetMaxDimLen(const std::vector vecPipe, const XString sHouse, double &nLength) { std::vector::const_iterator itPipe; double nLen = 0; for (itPipe = vecPipe.begin(); itPipe != vecPipe.end(); itPipe++) { ads_name name; acdbGetAdsName(name, *itPipe); Entity entPipe = name; WriteXdata(entPipe,_T("BUILDING-SERIAL"),sHouse); double nDnLength = 0.0; double nDLen = GetDimStrLen(*itPipe, nDnLength); if (nDLen > nLen) { nLen = nDLen; } if (nDnLength > nLength) { nLength = nDnLength; } } return nLen; } // 多立管标注 void DoDimStandPipes(PickSet &ssAll, AcGeVector3d &vtDir) { Entity entPipe; XPoint ptStart, ptEnd; std::vector vecDim; std::vector vecPipe; XString sHouse; XString sTmp; for (long l = 0l; l < ssAll.Length(); l++) { entPipe = ssAll[l]; CString csSerial = ReadXdata(entPipe, _T("PIPE-SERIAL")); CString csHouse = ReadXdata(entPipe, _T("BUILDING-SERIAL")); CString csLay = GetPipeLayer(entPipe); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); TCHAR szName[256]; CString csPrompt; csPrompt.Format(_T("请输入立管编号 %s-<%s>:"), csDim, csSerial); int ret = ads_getstring(0, csPrompt, szName); if(ret != RTNORM && ret != RTNONE) return; if(_tcsicmp(szName, _T("")) == 0) _tcscpy(szName, csSerial); if (l == ssAll.Length() - 1) { csPrompt.Format(_T("请输入立管所属楼号:")); if(csHouse != _T("")) { sTmp = csHouse; csPrompt.Format(_T("请输入立管所属楼号(按ESC设置为空):<%s>"), csHouse); } ret = ads_getstring(0, csPrompt, sHouse); if(ret != RTNORM && ret != RTNONE && ret != RTCAN) return; if(sTmp != _T("") && sHouse == _T("")) { sHouse = sTmp; } if(ret == RTCAN) sHouse = _T(""); } // int idx = _ttoi(szName); // if(idx < 1) // return; AcDbObjectId id = NULL; acdbGetObjectId(id, entPipe); vecPipe.push_back(id); WriteXdata(entPipe, _T("PIPE-SERIAL"), szName); //WriteXdata(entPipe,_T("BUILDING-SERIAL"),sHouse); } // zxl 2013.08.22 add std::vector::iterator itPipe; double nMaxDimDnLen = 0.0; double nMaxLabelLen = 0.0; nMaxLabelLen = GetMaxDimLen(vecPipe, sHouse, nMaxDimDnLen); nMaxDimDnLen *= 1.05; nMaxDimDnLen += nMaxLabelLen; int i = 0; for (itPipe = vecPipe.begin(); itPipe != vecPipe.end(); itPipe++, i++) { AcDbObjectId id = *itPipe; ads_name name; acdbGetAdsName(name, id); entPipe = name; WriteXdata(entPipe,_T("BUILDING-SERIAL"),sHouse); CString csLay = GetPipeLayer(entPipe); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); DocSetMultiLeaderDistRatio(0.2); //设置文字距线端距离(全局) XPoint ptPick1, ptPick2; TCHAR szLayer[256]; double nDn; CString csDimHead; double dRadius(0); CString sPipeLayer; OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe); if(pPipe) { dRadius = pPipe->GetRadius()*pPipe->GetPScale(); TCHAR *layer; layer = pPipe->layer(); _tcscpy(szLayer, layer); csDimHead = pPipe->GetLabel(); sPipeLayer = layer; delete [] layer; if(csDimHead == "") { int iMaterial = pPipe->GetMaterial(); CString csMat = GetPipeMaterialByIdx(iMaterial); csDimHead = GetDnByMat(csMat); } nDn = pPipe->GetDnDiameter(); csDimHead.Format(_T("%s%.0f"), csDimHead, nDn); ptPick1 = pPipe->StartPoint(); ptPick1.z = 0; if (i == 0) { ptStart = ptPick1; } else if (i == vecPipe.size() - 1) { ptEnd = ptPick1; } csLay = GetDimLayBySys(pPipe->GetSysType()); } OPENOBJ_END(); InitLayer(csLay); if(!g_bIsPipeDimCir) csDim += _T("-"); int nFind = csDim.Find(_T("-"),0); if (nFind != -1) csDim = csDim.Left(nFind); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csVPipeStyle); if(!idTextStyle) return; TDbVPipeDim *pDim = new TDbVPipeDim; pDim->SetDimRadius(g_nDimCirDiam); pDim->SetDimType(g_bIsPipeDimCir); // cet 2012.8.27 modify 无论当前设置是否是标注4样式都需设置此值,以便编辑标注更改为样式4时,显示正确 // if (g_bIsPipeDimCir == TVPipeDim::eDimType4) { pDim->SetShowDnForDimType4(IsShowVPipeDimDn(sPipeLayer) ? true : false); pDim->SetAlignTypeForDimType4(g_nAlignTypeForVPipeDim4); } pDim->SetDimTypeText(csDim); pDim->SetTextHeight(g_nVPipeHeight); pDim->SetTextStyleId(idTextStyle); pDim->SetText2BaseRatio(g_nDimCirDiam); pDim->SetVtDir(AcGeVector3d::kXAxis); pDim->SetStartPt(ptPick1); pDim->SetTextLayerId(InitLayer(LAY_TEXT)); pDim->setLayer(csLay); pDim->SetLayoutRotation(Ucs2Wcs(0.0)); pDim->SetVPipeFloorType(g_iVPipeDimStyle); // zxl 2013.08.22 add double dDst = nMaxLabelLen + g_dVPipeDimDn2Label * DocGetPScale(); CString sDst; sDst.Format(_T("%.1f"), dDst); dDst = _tstof(sDst); pDim->SetDnDistance2LabelLoc(dDst); pDim->SetTextBaseLineLen(nMaxDimDnLen / DocGetPScale() + g_dVPipeDimDn2Label); pDim->SetDnDistBetweenLabel(g_dVPipeDimDn2Label); pDim->SetVPipeId(id); vecDim.push_back(pDim); } TMultVPipeDimJig jig(vecDim, ptEnd, vtDir); XPoint ptTurn; jig.SetStartPt(ptStart); if(jig.DoIt() != RTNORM) { return; } AcGeVector3d vtDimDir; vtDimDir = jig.GetDimDir(); std::vector::iterator it; for (it = vecDim.begin(); it != vecDim.end(); it++) { TDbVPipeDim *pDim = NULL; pDim = *it; if (pDim != NULL) { pDim->SetVtDir(vtDimDir); AddToCurrentSpace(pDim,Adesk::kTrue); } } } // 用户单选标注立管 bool GetSelPipe(PickSet &ss, Entity &entPipe) { long len = ss.Length(); XPoint ptCen; for (long l = 0l; l < ss.Length(); l++) { entPipe = ss[l]; AcDbObjectId id; acdbGetObjectId(id, entPipe); OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe != NULL) { if (!pPipe->IsVertical()) { continue; } ptCen = pPipe->GetStartPoint(); ptCen.z = 0; arxZoomTo(ptCen, 10*DocGetPScale(), 10*DocGetPScale()); } OPENOBJ_END(); ads_name adsent; acdbGetAdsName(adsent, id); Entity ent = adsent; double nX(1), nY(1); ent.GetExtend(ptCen, &nX, &nY); double nDist = DocGetPScale()*0.5; XPoint p1, p2, p3, p4; WCS2UCS(ptCen); ads_polar(ptCen, 0, nDist, p1); ads_polar(p1, PI/2, nDist, p1); ads_polar(ptCen, PI, nDist, p2); ads_polar(p2, PI/2, -nDist, p2); ads_grdraw(p1, p2, 2, 0); ads_polar(ptCen, PI/2, nDist, p3); ads_polar(p3, PI, nDist, p3); ads_polar(ptCen, PI/2, -nDist, p4); ads_polar(p4, 0, nDist, p4); ads_grdraw(p3, p4, 2, 0); CString sNote = _T("\n是否为该对象?[是(Y)/否(N)]:"); TCHAR szText[256]; int nStatus = 0; INITGET_BEG(0, _T("N Y")); nStatus = acedGetString(0, sNote, szText); INITGET_END(); if (nStatus == RTNORM) { if (szText[0] == _T('y') || szText[0] == _T('Y') || szText[0] == _T('\0')) { return true; } } else { return false; } if (l == ss.Length() - 1) { FindStandPipeBySerial(); return false; } } return false; } void StandPipeDimCmd() { Entity entPipe; RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL); // zxl 2012.07.04 modify // if(SelectEntity(_T("\n请选择要标注的立管:<搜索立管>"), entPipe, rbMask) != RTNORM){ // FindStandPipeBySerial(); // return; // } PickSet ss(SS_FREE); int iIndex = SelectEntities(_T("\n请选择要标注的立管:<搜索立管>"), ss, rbMask); if (iIndex != RTNORM) { if (iIndex == RTCAN) { return; } FindStandPipeBySerial(); return; } // 立管共线 long len = ss.Length(); AcGeVector3d vtDir; if (ss.Length() > 1 && CheckPipes(ss, vtDir) && g_bIsPipeDimCir != TVPipeDim::eDimType2) { DoDimStandPipes(ss, vtDir); return; } len = ss.Length(); if (len > 1) { if (!GetSelPipe(ss, entPipe)) { return; } } else { entPipe = ss[0l]; } CString csSerial = ReadXdata(entPipe, _T("PIPE-SERIAL")); CString csHouse = ReadXdata(entPipe, _T("BUILDING-SERIAL")); CString csLay = GetPipeLayer(entPipe); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); //TPipeSys::SysType sys = GetPipeSys(entPipe); //CString csDim = g_csPipeDim[GetPipeLayerIdxBySys(sys)] + _T("L"); TCHAR szName[256]; CString csPrompt; csPrompt.Format(_T("请输入立管编号 %s-<%s>:"), csDim, csSerial); int ret = ads_getstring(0, csPrompt, szName); if(ret != RTNORM && ret != RTNONE) return; if(_tcsicmp(szName, _T("")) == 0) _tcscpy(szName, csSerial); XString sHouse; XString sTmp; // TCHAR szHouse[200]; csPrompt.Format(_T("请输入立管所属楼号:")); if(csHouse != _T("")) { sTmp = csHouse; csPrompt.Format(_T("请输入立管所属楼号(按ESC设置为空):<%s>"), csHouse); } // if(s_sHouse != _T("")) // { // sTmp = s_sHouse; // csPrompt.Format(_T("请输入立管所属楼号:<%s>"), s_sHouse); // } ret = ads_getstring(0, csPrompt, sHouse); if(ret != RTNORM && ret != RTNONE && ret != RTCAN) return; if(sTmp != _T("") && sHouse == _T("")) { sHouse = sTmp; } if(ret == RTCAN) sHouse = _T(""); // int idx = _ttoi(szName); //zxl 2012.08.20 del // if(idx < 1) // return; AcDbObjectId id = NULL; acdbGetObjectId(id, entPipe); if(!g_bIsPipeDimCir) csDim += _T("-"); WriteXdata(entPipe, _T("PIPE-SERIAL"), szName); // if(_tcsicmp(szHouse, _T("")) != 0) WriteXdata(entPipe,_T("BUILDING-SERIAL"),sHouse); //得到所有的立管标注 bool bIsDim = false; PickSet ssAll(SS_FREE); RBList rbMaskVPipe(RTDXF0, _T("ATS_VPIPEDIM"),NULL); ssAll.Get(_T("A"),NULL,NULL,rbMaskVPipe); long lLen = ssAll.Length(); Entity entT; for (long i = 0; i < lLen; ++i) { OPENOBJ_BEGIN(ssAll[i], AcDb::kForRead, TDbVPipeDim, pDim); if (pDim != NULL) { AcDbObjectId idDim = pDim->GetVPipeId(); if (idDim == id) { pDim->upgradeOpen(); pDim->RenewDimLen(); pDim->SaveCurText(); pDim->downgradeOpen(); entT = ssAll[i]; bIsDim = true; break; } } OPENOBJ_END(); } if (!bIsDim) { //标注立管 DoDimStandPipe(id, csDim, szName); } else { PickSet ssReNew(SS_FREE); ssReNew += entT; UpdateGraphic(ssReNew); } XPoint pt1,pt2; TCHAR szLay[256]; entPipe.GetData(8, szLay); Entity entSame = CheckSameSerialPipe(szLay, szName, entPipe); if(!!entSame){ adsout << _T("\n注意:有一个同编号的立管!请用【标注立管】修改编号,以保证标注与立管信息一致。"); GetPipePoint(entSame, pt1, pt2); pt1.z = 0; DrawRedFork(pt1); } } /* void StandPipeDimCmd2() { Entity entPipe; RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL); if(SelectEntity(_T("\n请选择要标注的立管:<搜索立管>"), entPipe, rbMask) != RTNORM){ FindStandPipeBySerial(); return; } CString csSerial = ReadXdata(entPipe, _T("PIPE-SERIAL")); CString csLay = GetPipeLayer(entPipe); CString csDim = g_csPipeDim[GetPipeLayerIdxByName(csLay)] + _T("L"); //TPipeSys::SysType sys = GetPipeSys(entPipe); //CString csDim = g_csPipeDim[GetPipeLayerIdxBySys(sys)] + _T("L"); TCHAR szName[256]; CString csPrompt; csPrompt.Format(_T("请输入立管编号 %s-<%s>:"), csDim, csSerial); int ret = ads_getstring(0, csPrompt, szName); if(ret != RTNORM && ret != RTNONE) return; if(_tcsicmp(szName, _T("")) == 0) _tcscpy(szName, csSerial); int idx = _ttoi(szName); if(idx < 1) return; AcDbObjectId id = NULL; acdbGetObjectId(id, entPipe); if(!g_bIsPipeDimCir) csDim += _T("-"); XPoint pt1, pt2; GetPipePoint(entPipe, pt1, pt2); pt1.z = 0; XPoint ptUcs = Wcs2Ucs(pt1); Entity entDim = GetPipeDimByPt(ptUcs, _ttoi(csSerial)); if(!!entDim){ if(g_bIsPipeDimCir){ OPENOBJ_BEGIN(entDim, AcDb::kForWrite, TDbSymbDrawingIndex, pDim); if(pDim){ pDim->SetIndexLabel(szName); } OPENOBJ_END(); } else{ OPENOBJ_BEGIN(entDim, AcDb::kForRead, TDbSymbComposing, pDim); if(pDim){ CString csTmp = pDim->GetText(); int idx = csTmp.Find(_T("-")); csTmp = csTmp.Right(csTmp.GetLength() - idx-1); if(csTmp == csSerial){ if(pDim->upgradeOpen()==Acad::eOk){ csDim += szName; pDim->SetText(csDim); pDim->downgradeOpen(); } } else DoDimStandPipe(id, csDim, szName); } OPENOBJ_END(); } } else DoDimStandPipe(id, csDim, szName); WriteXdata(entPipe, _T("PIPE-SERIAL"), szName); PickSet ss(SS_FREE); GetAllVertPipeByPt(ss, id); long len = ss.Length(); for(long i=0;i: "), szText) != RTNORM) return; CString csText; csText = szText; if(csText == _T("")) bAuto = TRUE; // csText.MakeUpper(); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csPipeTextStyle); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// XText text(_T(""), XPoint(), g_nTwtDimHeight * DocGetPScale(), g_nDimScale, g_csPipeTextStyle, _T("0")); text.Draw(AcDb::kTextBase, AcDb::kTextRight); Entity ent; ent.GetLast(); ent.Erase(); //写1个字,然后删除,很弱智。TDbPipeText::GetWidth()第一次执行时AcGiTextStyle计算外框用的是STANDARD样式 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// while(1){ int ret(0); INITGET_BEG(0, _T("M N T F")); ret = SelectEntity1(g_nCurPipeWidth*DocGetPScale()/2.0, _T("\n请点取要插入文字管线的位置[多选管线(M)/多选指定层管线(N)/两点栏选(T)/修改文字(F)] <退出>:"), entSel, ptPick, rbMask); INITGET_END(); if(ret == RTKWORD){ XString sKeyword; ads_getinput(sKeyword); TCHAR cKey = sKeyword[0]; if(cKey==_T('M') || cKey==_T('N')){ PickSet ss(SS_FREE); if(cKey==_T('M')){ if(SelectEntities(_T("\n请选择所有要标注的管线<退出>:"), ss, rbMask) != RTNORM) break; } else{ Entity entTmp; if(SelectEntity(_T("\n请选择要标注的其中一根管线<退出>:"), entTmp, rbMask) != RTNORM) break; char szLay[256]; entTmp.GetData(8, szLay); RBList rbMask2(RTDXF0, _T("ATS_PIPE"), 8, szLay, NULL); if(SelectEntities(_T("\n请选择要标注的管线的范围<退出>:"), ss, rbMask2) != RTNORM) break; } double nDist(5000); ads_getreal(_T("\n请输入文字最小间距:<5000>"), &nDist); if(nDist < 1) nDist = 5000; for(long i=0;iIsVertical()) //立管不标注 continue; sysType = pPipe->GetSysType(); DList lstAttachment; pPipe->GetAttachments(lstAttachment); int leng = lstAttachment.Length(); for(int m=0;mGetLocation(); lstNode.NewAppend(ptNode); } OPENOBJ_END(); } } OPENOBJ_END(); XPoint p1, p2; GetPipePoint(ent, p1, p2); XLine line(p1, p2, 1); if(line.GetLength() < nDist) //太短,无法标注 continue; int num = int(line.GetLength()/nDist); XCurveSegment seg; seg = line; GetPointList(seg, num, lstPt); CString csLay = GetTextLayBySys(sysType); InitLayer(csLay); for(int j=0;jSetTextStyleId(idTextStyle); pText->SetLocation(ptTmp); pText->SetTextHeight(g_nPipeTextHeight); pText->setLayer(csLay); pText->setColor(AcCmColor()); //随层 pText->SetText((const TCHAR*)csText); AddToCurrentSpace(pText, Adesk::kTrue); } } return; } if(cKey==_T('T')){ XPushVar vOrthoMode(_T("ORTHOMODE"), 1); //f8 while(1){ adsout<<_T("\n多管文字标注,与管线相交出进行标注:"); XPoint ptStartPick,ptEndPick; if(ads_getpoint(NULL, _T("\n起点:"), ptStartPick) != RTNORM) return; if(ads_getpoint(ptStartPick, _T("\n终点:"), ptEndPick) != RTNORM) return; struct resbuf *pointlist; PickSet ss(SS_FREE); pointlist = ads_buildlist(RTPOINT, &ptStartPick, RTPOINT, &ptEndPick, NULL); ss.Get(_T("F"), pointlist, NULL, RBList(RTDXF0, _T("ATS_PIPE"), 0)); ads_relrb(pointlist); if(ss.Length() < 1) return; ptStartPick = Ucs2Wcs(ptStartPick); ptEndPick = Ucs2Wcs(ptEndPick); XLine line1(ptStartPick, ptEndPick, 1); for(long i=0;iSetTextStyleId(idTextStyle); pText->SetLocation(ptInt); pText->SetTextHeight(g_nPipeTextHeight); pText->setLayer(csLay); pText->setColor(AcCmColor()); //随层 pText->SetText((const TCHAR*)csText); AddToCurrentSpace(pText, Adesk::kTrue); } } TPipePerDocData *pData = GetCurPipeDocData(); pData->ApplyUpdates(); } } else if(cKey==_T('F')){ if(bAuto){ if(ads_getstring(0, _T("\n请输入新的标注内容<退出>: "), szText) != RTNORM) return; if(_tcsicmp(szText, _T("")) == 0) return; csText = szText; // csText.MakeUpper(); } Entity ent; if(SelectEntity(_T("\n请选择系统上其中一根管线<退出>:"), ent, rbMask) != RTNORM) return; AcDbObjectId idPipe; acdbGetObjectId(idPipe, ent); TPipeGraph PipeGraph; SearchOneselfPipe(idPipe, PipeGraph); int len = PipeGraph.m_lstEdge.Length(); for(int i=0;im_idPipe; OPENOBJ_BEGIN(idTmp, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ double dDn = pPipe->GetDnDiameter(); CString csDn; csDn.Format(_T("%.0f"), dDn); DList lstAttachment; pPipe->GetAttachments(lstAttachment); int leng = lstAttachment.Length(); for(int m=0;mGetText(); if(csText2.Find(csDn) < 0) pLabel->SetText((const TCHAR*)csText); } OPENOBJ_END(); } } OPENOBJ_END(); } return; } TPipePerDocData *pData = GetCurPipeDocData(); pData->ApplyUpdates(); } else if(ret != RTNORM) break; if(bAuto){ TCHAR szLayer[256]; entSel.GetData(8, szLayer); int idx = GetPipeLayerIdxByName(szLayer); if(idx < 0) csText = _T("NO"); else csText = g_csPipeDim[idx]; } ptPick = Ucs2Wcs(ptPick); if(!IsPtOnPipe(ptPick, entSel)) continue; CString csLay = GetPipeTextLayByEnt(entSel); InitLayer(csLay); TDbPipeText *pText = new TDbPipeText(); pText->SetTextStyleId(idTextStyle); pText->SetLocation(ptPick); pText->SetTextHeight(g_nPipeTextHeight); pText->setLayer(csLay); pText->setColor(AcCmColor()); //随层 pText->SetText((const TCHAR*)csText); AddToCurrentSpace(pText, Adesk::kTrue); TPipePerDocData *pData = GetCurPipeDocData(); pData->ApplyUpdates(); } } //*************************************************************************************************** // 喷头尺寸 //*************************************************************************************************** BOOL IsOnLine(XPoint p1, XPoint p2, XPoint p3) { AcGeVector3d vt1(p1 - p2); AcGeVector3d vt2(p2 - p3); if(vt1.isParallelTo(vt2)) return TRUE; else return FALSE; } ////////////////////////////////////////////////////////////////////////////////// // cet 2010.12.3 add 点是否存在于data中 bool IsPtExist(XPoint &pt, std::vector > &data) { std::vector >::iterator it; for (it = data.begin(); it != data.end(); it++) { if (std::find((*it).begin(), (*it).end(), pt) != (*it).end()) { return true; } } return false; } // cet 2010.12.3 add // 当点不共线也不共圆时 调整点使所有点在同一直线上(该直线是所有点中共线点最多的点所在直线) // 前提条件所有喷头交度相同,根据喷头插入点与角度做两条直线,一条直线与喷头方向平行, // 另一条与喷头方向垂直,根据这两条直线寻找共线点 void AdjustPtsToLine(XPointList &lstPt, double dAngle) { dAngle = Ucs2Wcs(dAngle); AcGeVector3d vt = AcGeVector3d::kXAxis; vt.rotateBy(Ucs2Wcs(0.0), AcGeVector3d::kZAxis); vt.rotateBy(dAngle, AcGeVector3d::kZAxis); AcGeVector3d vtDir = vt; vtDir.rotateBy(-PI/2, AcGeVector3d::kZAxis); std::vector > data1, data2; for (int i = 0; i < lstPt.Length(); i++) // 获得共线点 { XPoint pt = *lstPt[i]; AcDbLine line1(pt, pt + vt), line2(pt, pt + vtDir); std::vector vec1, vec2; vec1.push_back(pt); vec2.push_back(pt); bool bExist1 = false, bExist2 = false; if (IsPtExist(pt, data1)) { bExist1 = true; } if (IsPtExist(pt, data2)) { bExist2 = true; } if (bExist1 && bExist2) { continue; } for (int j = i + 1; j < lstPt.Length(); j++) { XPoint ptTemp; if (!bExist1) { line1.getClosestPointTo(*lstPt[j], ptTemp, Adesk::kTrue); double d = ptTemp.Distance(*lstPt[j]); if (ptTemp.Distance(*lstPt[j]) < 1e-2) { vec1.push_back(*lstPt[j]); } } if (!bExist2) { line2.getClosestPointTo(*lstPt[j], ptTemp, Adesk::kTrue); double d = ptTemp.Distance(*lstPt[j]); if (ptTemp.Distance(*lstPt[j]) < 1e-2) { vec2.push_back(*lstPt[j]); } } } if (vec1.size() > 1) { data1.push_back(vec1); } if (vec2.size() > 1) { data2.push_back(vec2); } } std::vector >::iterator it; for (it = data2.begin(); it != data2.end(); it++) { data1.push_back(*it); } std::vector vec; for (it = data1.begin(); it != data1.end(); it++) { if (vec.size() < (*it).size()) { vec = *it; } } XPointList lstPt2; if (vec.size() > 0) // 存在共线点 { AcDbLine line(vec[0], vec[1]); std::vector::iterator it; for (it = vec.begin(); it != vec.end(); it++) { lstPt2.Append(new XPoint(*it)); } for (int i = 0; i < lstPt.Length(); i++) { XPoint pt = *lstPt[i]; if (std::find(vec.begin(), vec.end(), pt) == vec.end()) { XPoint ptTemp; line.getClosestPointTo(pt, ptTemp, Adesk::kTrue); vec.push_back(ptTemp); lstPt2.Append(new XPoint(ptTemp)); } } lstPt.Reset(); lstPt.copyFrom(lstPt2); } } void ModifyLstPts(XPointList &lstPts, CSprinklerDimDlg &dlg, bool bIsLine) { // 不标注距墙距离 if (dlg.m_nDim == 0 || lstPts.Length() < 2) { return; } XPoint ptS, ptE, ptOnLine; double dAngle = 0.0; // if (bIsLine) { ptS = *lstPts[0]; ptE = *lstPts[1]; for (int i = 2; i < lstPts.Length(); i++) { XPoint pt = *lstPts[i]; double dLen = ptS.Distance2d(ptE); double dDstS = pt.Distance2d(ptS); double dDstE = pt.Distance2d(ptE); if (dDstE - dLen > 0.001) { ptOnLine = ptS; ptS = pt; } else if (dDstS - dLen > 0.001) { ptOnLine = ptE; ptE = pt; } else { ptOnLine = pt; } } } if (!bIsLine) { XArc arc(ptS, ptOnLine, ptE); dAngle = arc.Bulge(); if(fabs(dAngle) > (2*PI-0.001)) { dAngle -= 2*PI; } } if (dlg.m_nDimType == 0)// 距墙体 { XPoint ptOnWall1, ptOnWall2; RBList rbMask(RTDXF0, _T("ATS_WALL"), NULL); PickSet ss(SS_FREE); double dDst = _tstof(dlg.m_sDst); if (!DocGetMeterUnitDraw()) { dDst *= 1000; } GetPointPickSet(Wcs2Ucs(ptS), ss, rbMask, dDst); double dMinLen = 0.0; for (long l = 0; l < ss.Length(); l++) { Entity ent = ss[l]; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWall, pWall); if (pWall != NULL) { XPoint pt; XCurveSegment lineWall; XCurveSegment lCurve, rCurve; pWall->GetSideCurve(lCurve, rCurve); if (lCurve.GetDist2Me(ptS) * rCurve.GetDist2Me(ptS) < 0.001) //点在墙内 { continue; } if (fabs(lCurve.GetDist2Me(ptS)) - fabs(rCurve.GetDist2Me(ptS)) > 0.001) { lineWall = rCurve; } else { lineWall = lCurve; } if (dAngle < 0.001) { XLine line(ptS, ptE); XPoint pt1, pt2; lineWall.Intersection(line,pt1, pt2); pt = GetNearPt(ptS, pt1, pt2); } else { XArc line(ptS, ptOnLine, ptE); AcGePoint3dArray arPt; double dRadius = line.GetRadius(); double dStartAngle = line.GetStarAngle(); double dEndAngle = line.GetEndAngle(); AcGePoint3d ptCenter = line.GetCenterPt(); AcDbArc arc(ptCenter, dRadius, dStartAngle, dEndAngle); if (lineWall.GetBulge() > 0.0) { XArc line2(lineWall.StartPoint(), lineWall.MidPoint(), lineWall.EndPoint()); dRadius = line2.GetRadius(); dStartAngle = line2.GetStarAngle(); dEndAngle = line2.GetEndAngle(); ptCenter = line2.GetCenterPt(); AcDbArc arc2(ptCenter, dRadius, dStartAngle, dEndAngle); arc.intersectWith(&arc2, AcDb::kExtendBoth, arPt); } else { AcDbLine line2; line2.setStartPoint(lineWall.GetStartPoint()); line2.setEndPoint(lineWall.GetEndPoint()); arc.intersectWith(&line2, AcDb::kExtendBoth, arPt); } if (arPt.length() > 0) { GetNearestPoint(arPt, ptS, pt); } } if (pt.Distance2d(ptE) - ptS.Distance2d(ptE) > 0.001 && pt.Distance2d(ptS) < dDst) { if (!ptOnWall1) { ptOnWall1 = pt; dMinLen = pt.Distance2d(ptS); } else if (pt.Distance2d(ptS) - dMinLen < 0.001) { ptOnWall1 = pt; dMinLen = pt.Distance2d(ptS); } } } OPENOBJ_END(); } if (!!ptOnWall1) { lstPts.NewAppend(ptOnWall1); } ss.Free(); GetPointPickSet(Wcs2Ucs(ptE), ss, rbMask, dDst); dMinLen = 0.0; for (long l = 0; l < ss.Length(); l++) { Entity ent = ss[l]; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWall, pWall); if (pWall != NULL) { XPoint pt; XCurveSegment lineWall; XCurveSegment lCurve, rCurve; pWall->GetSideCurve(lCurve, rCurve); if (lCurve.GetDist2Me(ptE) * rCurve.GetDist2Me(ptE) < 0.001) //点在墙内 { continue; } if (fabs(lCurve.GetDist2Me(ptE)) - fabs(rCurve.GetDist2Me(ptE)) > 0.001) { lineWall = rCurve; } else { lineWall = lCurve; } if (dAngle < 0.001) { XLine line(ptS, ptE); XPoint pt1, pt2; lineWall.Intersection(line,pt1, pt2); pt = GetNearPt(ptE, pt1, pt2); } else { XArc line(ptS, ptOnLine, ptE); AcGePoint3dArray arPt; double dRadius = line.GetRadius(); double dStartAngle = line.GetStarAngle(); double dEndAngle = line.GetEndAngle(); AcGePoint3d ptCenter = line.GetCenterPt(); AcDbArc arc(ptCenter, dRadius, dStartAngle, dEndAngle); if (lineWall.GetBulge() > 0.0) { XArc line2(lineWall.StartPoint(), lineWall.MidPoint(), lineWall.EndPoint()); dRadius = line2.GetRadius(); dStartAngle = line2.GetStarAngle(); dEndAngle = line2.GetEndAngle(); ptCenter = line2.GetCenterPt(); AcDbArc arc2(ptCenter, dRadius, dStartAngle, dEndAngle); arc.intersectWith(&arc2, AcDb::kExtendBoth, arPt); } else { AcDbLine line2; line2.setStartPoint(lineWall.GetStartPoint()); line2.setEndPoint(lineWall.GetEndPoint()); arc.intersectWith(&line2, AcDb::kExtendBoth, arPt); } if (arPt.length() > 0) { GetNearestPoint(arPt, ptE, pt); } } if (pt.Distance2d(ptS) - ptS.Distance2d(ptE) > 0.001 && pt.Distance2d(ptE) < dDst) { if (!ptOnWall2) { ptOnWall2 = pt; dMinLen = pt.Distance2d(ptE); } else if (pt.Distance2d(ptE) - dMinLen < 0.001) { ptOnWall2 = pt; dMinLen = pt.Distance2d(ptE); } } } OPENOBJ_END(); } if (!!ptOnWall2) { lstPts.NewAppend(ptOnWall2); } } else// 距轴线 { XPoint ptOnWall1, ptOnWall2; RBList rbMask = ads_buildlist(RTDXF0, _T("LINE,ARC"), NULL); PickSet ss(SS_FREE); double dDst = _tstof(dlg.m_sDst); if (!DocGetMeterUnitDraw()) { dDst *= 1000; } GetPointPickSet(Wcs2Ucs(ptS), ss, rbMask, dDst); double dMinLen = 0.0; for (long l = 0; l < ss.Length(); l++) { Entity ent = ss[l]; TCHAR szLayer[256]; ent.GetData(8, szLayer); CString sLyer = szLayer; sLyer = sLyer.MakeUpper(); if (sLyer.Compare(LAY_AXIS) != 0 && sLyer.Find(_T("DOTE")) < 0 && sLyer.Find(_T("轴线")) < 0) { continue; } XPoint pt; XCurveSegment seg(ent); if (dAngle < 0.001) { XLine line(ptS, ptE); XPoint pt1, pt2; seg.Intersection(line,pt1, pt2); pt = GetNearPt(ptS, pt1, pt2); } else { XArc line(ptS, ptOnLine, ptE); AcGePoint3dArray arPt; double dRadius = line.GetRadius(); double dStartAngle = line.GetStarAngle(); double dEndAngle = line.GetEndAngle(); AcGePoint3d ptCenter = line.GetCenterPt(); AcDbArc arc(ptCenter, dRadius, dStartAngle, dEndAngle); if (seg.GetBulge() > 0.0) { XArc line2(seg.StartPoint(), seg.MidPoint(), seg.EndPoint()); dRadius = line2.GetRadius(); dStartAngle = line2.GetStarAngle(); dEndAngle = line2.GetEndAngle(); ptCenter = line2.GetCenterPt(); AcDbArc arc2(ptCenter, dRadius, dStartAngle, dEndAngle); arc.intersectWith(&arc2, AcDb::kExtendBoth, arPt); } else { AcDbLine line2; line2.setStartPoint(seg.GetStartPoint()); line2.setEndPoint(seg.GetEndPoint()); arc.intersectWith(&line2, AcDb::kExtendBoth, arPt); } if (arPt.length() > 0) { GetNearestPoint(arPt, ptS, pt); } } if (pt.Distance2d(ptE) - ptS.Distance2d(ptE) > 0.001 && pt.Distance2d(ptS) < dDst) { if (!ptOnWall1) { ptOnWall1 = pt; dMinLen = pt.Distance2d(ptS); } else if (pt.Distance2d(ptS) - dMinLen < 0.001) { ptOnWall1 = pt; dMinLen = pt.Distance2d(ptS); } } } if (!!ptOnWall1) { lstPts.NewAppend(ptOnWall1); } ss.Free(); GetPointPickSet(Wcs2Ucs(ptE), ss, rbMask, dDst); dMinLen = 0.0; for (long l = 0; l < ss.Length(); l++) { Entity ent = ss[l]; TCHAR szLayer[256]; ent.GetData(8, szLayer); CString sLyer = szLayer; sLyer = sLyer.MakeUpper(); if (sLyer.Compare(LAY_AXIS) != 0 && sLyer.Find(_T("DOTE")) < 0 && sLyer.Find(_T("轴线")) < 0) { continue; } XPoint pt; XCurveSegment seg(ent); if (dAngle < 0.001) { XLine line(ptS, ptE); XPoint pt1, pt2; seg.Intersection(line,pt1, pt2); pt = GetNearPt(ptS, pt1, pt2); } else { XArc line(ptS, ptOnLine, ptE); AcGePoint3dArray arPt; double dRadius = line.GetRadius(); double dStartAngle = line.GetStarAngle(); double dEndAngle = line.GetEndAngle(); AcGePoint3d ptCenter = line.GetCenterPt(); AcDbArc arc(ptCenter, dRadius, dStartAngle, dEndAngle); if (seg.GetBulge() > 0.0) { XArc line2(seg.StartPoint(), seg.MidPoint(), seg.EndPoint()); dRadius = line2.GetRadius(); dStartAngle = line2.GetStarAngle(); dEndAngle = line2.GetEndAngle(); ptCenter = line2.GetCenterPt(); AcDbArc arc2(ptCenter, dRadius, dStartAngle, dEndAngle); arc.intersectWith(&arc2, AcDb::kExtendBoth, arPt); } else { AcDbLine line2; line2.setStartPoint(seg.GetStartPoint()); line2.setEndPoint(seg.GetEndPoint()); arc.intersectWith(&line2, AcDb::kExtendBoth, arPt); } if (arPt.length() > 0) { GetNearestPoint(arPt, ptE, pt); } } if (pt.Distance2d(ptS) - ptS.Distance2d(ptE) > 0.001 && pt.Distance2d(ptE) < dDst) { if (!ptOnWall2) { ptOnWall2 = pt; dMinLen = pt.Distance2d(ptE); } else if (pt.Distance2d(ptE) - dMinLen < 0.001) { ptOnWall2 = pt; dMinLen = pt.Distance2d(ptE); } } } if (!!ptOnWall2) { lstPts.NewAppend(ptOnWall2); } } } void DimSprinklerLength() { /* g_ssPickFirst.Free(); PickSet ss(SS_FREE), ssNew(SS_FREE); RBList rbMask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); // RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, LAY_EQUIP_SPRINKLE, NULL); // cet 2010.12.03 modify 支持不共线、不共圆的情况 // if(SelectEntities(_T("\n请选取喷头(所选喷头要共线或共圆)<退出>:"), ss, rbMask) != RTNORM) // return; // zxl 2014.04.14 add CSprinklerDimDlg dlg(acedGetAcadFrame()); { CTemporaryResourceOverride vTemp; dlg.Create(IDD_SPRINKLER_DIM, acedGetAcadFrame()); } dlg.ShowWindow(SW_SHOW); acedGetAcadDwgView()->SetFocus(); double dDist = _tstof(dlg.m_sDst); if(SelectEntities(_T("\n请选取喷头<退出>:"), ss, rbMask) != RTNORM) { dlg.DestroyWindow(); return; } dlg.m_bIsSelected = true; for(long i=0;iGetLocation(); pt.z = 0; lstPt.NewAppend(pt); // cet 2010.12.3 add if (!bSprikle) { bSprikle = true; dAngle = pEquip->GetAngle(); } } OPENOBJ_END(); } if(ssNew.Length() == 0){ for(i=0;i 3){ XPoint p1 = *lstPt[0]; XPoint p2 = *lstPt[1]; XPoint p3 = *lstPt[2]; XPoint p4 = *lstPt[3]; if(!(IsOnLine(p1,p2,p3) && IsOnLine(p2,p3,p4))) { XArc arc(p1, p2, p3); double nn = arc.Bulge(); if(fabs(nn) > (2*PI-0.001)){ nn -= 2*PI; } if(fabs(nn) > 0.001){ int ret = arc.HitTest2d(p4); if(ret > 2){ bIsLine = FALSE; arDim = arc; } else{ // cet 2010.12.3 modify 处理喷头不共线也不共圆的情况 //adsout << _T("\n所选喷头既不共线,又不共圆!"); //return; //既不共线, 又不共圆 if (bSprikle) // 喷头 { AdjustPtsToLine(lstPt, dAngle); } else // 洁具 { adsout << XString(_T("\n所选洁具既不共线,又不共圆!")); return; } } } } } else if(lstPt.Length() == 3){ XPoint p1 = *lstPt[0]; XPoint p2 = *lstPt[1]; XPoint p3 = *lstPt[2]; if(!IsOnLine(p1,p2,p3)) { XArc arc(p1, p2, p3); double nn = arc.Bulge(); if(fabs(nn) > (2*PI-0.001)){ nn -= 2*PI; } if(fabs(nn) > 0.001){ bIsLine = FALSE; arDim = arc; } } } ///////////////////////////////////////////////////////////////////////////// InitLayer(LAY_DIM_SPRINKLE); while(true) { dlg.UpdateData(TRUE); XPointList lstPtCp = lstPt; ModifyLstPts(lstPt, dlg, bIsLine); if(bIsLine){ TDbDimension2 *pDim = new TDbDimension2; pDim->setLayer(LAY_DIM_SPRINKLE); pDim->SetDist2DimLine(0); pDim->SetLocation(*lstPt[0]); pDim->SetStyleId(InitDimStyle(DS_LINEAR)); pDim->SetRotation(ads_angle(*lstPt[1], *lstPt[0])); for(int j=1;jAddSegment(pt); } TDimensionEdJig jig(pDim, _T("\n请点取尺寸线位置<退出>:"), _T("R ")); jig.m_nFlag=1; int nRet = jig.doIt(); if (nRet == RTKWORD) { lstPt = lstPtCp; delete pDim; continue; } if(nRet != RTNORM){ delete pDim; dlg.DestroyWindow(); return; } ((TDbEntity *)pDim)->setLayer(LAY_DIM_SPRINKLE); AcDbObjectId idDim = pDim->AddToMSpace(Adesk::kTrue); // OPENOBJ_BEGIN(idDim, AcDb::kForWrite, TDbEntity, pEnt) // if(pEnt){ // pEnt->setLayer(LAY_DIM_SPRINKLE); // } // OPENOBJ_END() } else{ TDbDimension2 *pDim = new TDbDimension2; XCurveSegment segDim; segDim=arDim; pDim->setLayer(LAY_DIM_SPRINKLE); pDim->SetStyleId(InitDimStyle(DS_ANGLE)); pDim->SetDist2DimLine(-6.0); XPoint ptFix; ads_polar(segDim.GetStartPoint(), segDim.IDirection(0)-PI/2, 2.0*DocGetPScale(), ptFix); pDim->SetLocation(ptFix); pDim->SetRotation(segDim.IDirection(0)); pDim->SetAngular(TRUE); pDim->SetDimChord(FALSE); pDim->SetObjRadius(arDim.GetRadius()); pDim->SetDimRadius(arDim.GetRadius() + 8.0*DocGetPScale()); XArc arDimLine=arDim; arDimLine.SetRadius(arDimLine.GetRadius() + 8.0*DocGetPScale()); for(int j=0;jAddSegment(pt); } pDim->SwitchDimChord(); TDimensionEdJig jig(pDim, _T("\n请点取尺寸线位置<退出>: "), _T("R ")); jig.m_nFlag=1; int nRet = jig.doIt(); if (nRet == RTKWORD) { lstPt = lstPtCp; delete pDim; continue; } if(nRet != RTNORM){ delete pDim; dlg.DestroyWindow(); return; } ((TDbEntity *)pDim)->setLayer(LAY_DIM_SPRINKLE); AcDbObjectId idDim = pDim->AddToMSpace(Adesk::kTrue); } break; } Entity entLast; entLast.GetLast(); OPENOBJ_BEGIN(entLast, AcDb::kForWrite, AcDbEntity, pEnt) if(pEnt){ pEnt->setLayer(LAY_DIM_SPRINKLE); } OPENOBJ_END() dlg.DestroyWindow(); // WriteXdata(entLast, _T("TG-LAYER"), LAY_PIPE_SPRINKLE); */ } //*************************************************************************************************** // 更改管径 //*************************************************************************************************** void DoChangeAllPipeDnDim() { Entity entPipe; RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL); if(SelectEntity(_T("\n请选取要更改管径的管线 <退出>:"), entPipe, rbMask)!=RTNORM) return; int iDnNew(0), iDnOld(0); int iMat(0); OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ iDnOld = (int)pPipe->GetDnDiameter(); iMat = pPipe->GetMaterial(); } OPENOBJ_END(); CString csPrompt; csPrompt.Format(_T("\n请输入新管径<%d>"), iDnOld); if(ads_getint(csPrompt, &iDnNew) != RTNORM) return; if(iDnNew == iDnOld) return; PickSet ss(SS_FREE); ss.Get(_T("X"), NULL, NULL, rbMask); for(long i=0;iGetDnDiameter(); int iMat2 = pPipe->GetMaterial(); if(iDn == iDnOld && iMat == iMat2){ if(pPipe->upgradeOpen()==Acad::eOk) { pPipe->SetDnDiameter(iDnNew); pPipe->downgradeOpen(); } } } OPENOBJ_END(); } } void ChangeDnDim() { Entity entPipe; RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL); XPoint ptPick; InitLayer(LAY_PIPE_DIM); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); while(1){ acedGetAcadDwgView()->SetFocus(); if(SelectEntity1(g_nCurPipeWidth*DocGetPScale(), _T("\n请选取要更改管径的管线<替换所有同管材同规格的管线>:"), entPipe, ptPick, rbMask)!=RTNORM) { DoChangeAllPipeDnDim(); break; } InitSheetHook(TRUE); CPoint ptDwgView; int cvport=0; VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM); acedCoordFromWorldToPixel(cvport, ptPick, ptDwgView); CTemporaryResourceOverride vTmp; CString csText; OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ if(pPipe->IsVertical()){ InitSheetHook(FALSE); continue; } if(pPipe->GetDnDiameter() < 0) csText = _T("无信息"); else csText.Format(_T("%.0f"), pPipe->GetDnDiameter()); } OPENOBJ_END(); CComboBox *pEdit = new CComboBox(); pEdit->Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWN |CBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP, CRect(ptDwgView.x, ptDwgView.y, ptDwgView.x+80, ptDwgView.y +200), acedGetAcadDwgView(), IDC_USER_COMBOX_TYPE3); pEdit->AddString(_T("不标注")); pEdit->AddString(_T("25")); pEdit->AddString(_T("32")); pEdit->AddString(_T("40")); pEdit->AddString(_T("50")); pEdit->AddString(_T("70")); pEdit->AddString(_T("80")); pEdit->AddString(_T("100")); pEdit->AddString(_T("125")); pEdit->AddString(_T("150")); pEdit->SetWindowText(csText); int lenText = csText.GetLength(); pEdit->SetEditSel(0, lenText); pEdit->SetFocus(); int nKey, ret; ads_prompt(_T("\n请在编辑框内输入文字<回车键或鼠标右键完成, ESC键退出>")); BOOL bFisrt = TRUE; while(1){ ret = ads_getint(_T(""), &nKey); if(ret == RTNONE && g_nKey != 0) { if(g_nKey == VK_ESCAPE) break; if(g_nKey == VK_RETURN || (g_nKey == VK_RBUTTON && bFisrt) || (g_nKey == VK_LBUTTON && bFisrt)){ CString csTmp; pEdit->GetWindowText(csTmp); OPENOBJ_BEGIN(entPipe, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ if(csTmp == _T("不标注")) pPipe->EnableDrawLabel(FALSE); else{ if(csText == _T("无信息")){ pPipe->SetTextStyle(InitTwtTextStyle(g_csTwtDimStyle)); pPipe->SetTextHeight(g_nTwtDimHeight); pPipe->SetLabel(_T("DN")); } pPipe->SetDnDiameter(_tstof(csTmp)); pPipe->EnableDrawLabel(TRUE); } } OPENOBJ_END(); UpdateMultDim(entPipe); break; } } else if(ret == RTCAN) break; bFisrt = TRUE; } InitSheetHook(FALSE); if(pEdit) pEdit->DestroyWindow(); delete pEdit; } SHads_command(RTSTR, _T(".REDRAW"), RTNONE); } #define WHV_ON 0x0 //原点 #define WHV_UP 0x2 //上 #define WHV_RIGHT 0x4 //右 int WhereOfVector2d(const XPoint& ptWho, const ads_real dRotation, const XPoint &ptQst) { int flag=0x0; ads_matrix mat1; ads_matrix mat2; ptWho.GetRotationMatrix( dRotation*-1, mat1 ); ptWho.GetMoveMatrix(XPoint(), mat2); XPoint ptTmp(ptQst); ptTmp.TransformBy( mat1 ); ptTmp.TransformBy( mat2 ); if (ptTmp == ptQst) { flag |= WHV_ON; } if (ptTmp.x > 0.0) { flag |= WHV_RIGHT; } if (ptTmp.y > 0.0) { flag |= WHV_UP; } return flag; } TComposingEdJig::TComposingEdJig(TDbSymbComposing *pElev) { m_pDrawEnt=pElev; using namespace std; std::vector vTxt; m_cs1 = m_pDrawEnt->GetText() ; CString csTmp; for(int i=0; i<=m_cs1.GetLength(); i++) { if (_istspace(m_cs1[i])||m_cs1[i]==NULL) { vTxt.push_back(csTmp); csTmp.Empty(); }else{ csTmp+=m_cs1[i]; } } std::reverse(vTxt.begin(), vTxt.end()); for(std::vector::iterator pvTxt=vTxt.begin(); pvTxt !=vTxt.end(); pvTxt++) { m_cs2 += (*pvTxt + _T("\n")); } if (m_cs2.GetLength () !=0) { m_cs2.TrimRight(_T("\n")); } } AcEdJig::DragStatus TComposingEdJig::GetPoint(XPoint &pt) { if( m_nOperCode == kDimPos ) return acquirePoint(pt); XPoint ptBase=m_nOperCode==kTextLine? m_pDrawEnt->GetTurnPoint() : m_pDrawEnt->GetStartPoint(); return acquirePoint(pt, ptBase); } // 开始执行拖动 int TComposingEdJig::DoIt(int *keyIndex) { if(m_nOperCode==kTurnPoint) { m_ptResult=m_pDrawEnt->GetStartPoint(); } else if(m_nOperCode==kTextLine) { XPoint ptTemp; ads_polar(m_pDrawEnt->GetTurnPoint(), 0.0, m_pDrawEnt->GetTextBaseLen(FALSE), ptTemp); m_ptResult=ptTemp; } else if(m_nOperCode == kDimPos ){ m_ptResult=m_pDrawEnt->GetTurnPoint(); } int nRet = TSymbEdJig::DoIt(keyIndex); return nRet; } // 更新实体数据 Adesk::Boolean TComposingEdJig::update() { Adesk::Boolean bRet=Adesk::kTrue; if(m_nOperCode==kTurnPoint) { XPoint ptStart = m_pDrawEnt->GetStartPoint(); ptStart = Wcs2Ucs(ptStart); XPoint ptResult = Wcs2Ucs(m_ptResult); double nAng = ads_angle(ptStart, ptResult); double nLen = m_pDrawEnt->GetTextBaseLen(); if(nAng > PI/2 && nAng < PI/2*3) nLen = -fabs(nLen); else nLen = fabs(nLen); m_pDrawEnt->SetTextBaseLen(nLen); m_pDrawEnt->SetTurnPoint(m_ptResult); } else if(m_nOperCode==kTextLine) { // double nVal=m_ptResult.x - m_pDrawEnt->GetTurnPoint().x; double nVal=Wcs2Ucs(m_ptResult).x - Wcs2Ucs(m_pDrawEnt->GetTurnPoint()).x; m_pDrawEnt->SetTextBaseLen(nVal, FALSE); } else if(m_nOperCode == kDimPos ){ XLine lnMin(m_ptLeftUp, m_ptRightUp); double dir = lnMin.Direction(); int flagLeftUp = WhereOfVector2d(m_ptLeftUp, dir, m_ptResult); int flagRightUp = WhereOfVector2d(m_ptRightUp, dir, m_ptResult); int flagLeftDown = WhereOfVector2d(m_ptLeftDown, dir, m_ptResult); if ( (flagLeftUp&WHV_RIGHT) == WHV_RIGHT && (flagRightUp&WHV_RIGHT) != WHV_RIGHT ) { XPoint ptTmp1,ptTmp2; m_ptResult.Project(&lnMin, ptTmp1); if ((flagLeftUp&WHV_UP) == WHV_UP ) { ads_polar(ptTmp1, dir-PI/2, m_ptLeftUp.Distance2d(m_ptLeftDown)+DocGetPScale(), ptTmp2); m_pDrawEnt->SetStartPoint(ptTmp2); m_pDrawEnt->SetTurnPoint(m_ptResult); m_pDrawEnt->SetText(m_cs1); //m_pDrawEnt->SetLayoutRotation(XLine(m_ptLeftUp,m_ptRightUp).Direction() ); } else if ((flagLeftDown&WHV_UP) != WHV_UP) { ads_polar(ptTmp1, dir+PI/2, 0.5*DocGetPScale(), ptTmp2); m_pDrawEnt->SetStartPoint(ptTmp2); m_pDrawEnt->SetTurnPoint(m_ptResult); m_pDrawEnt->SetText(m_cs2); //m_pDrawEnt->SetLayoutRotation(XLine(m_ptLeftUp,m_ptRightUp).Direction()+PI ); } } } return bRet; } AcDbEntity* TComposingEdJig::entity() const { return (AcDbEntity *)m_pDrawEnt; }