#include "StdAfx.h" #include "DbPipeLabel.h" #include "DbWell.h" //*************************************************************************************************** // 管径移动 //*************************************************************************************************** // add 2010.1.18 add void GetPipeDim(PickSet &ss, PickSet &ssDim) { for (long i = 0; i < ss.Length(); i++) { Entity ent = ss[i]; OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe); if (pPipe != NULL) { if (pPipe->IsDrawLabel()) { AcDbVoidPtrArray arPtr; pPipe->explode(arPtr); for (int i = 0; i < arPtr.length(); i++) { AcDbEntity *pEnt = (AcDbEntity*)(arPtr[i]); TDbText *pText = TDbText::cast(pEnt); if (pText != NULL) { AddToCurrentSpace(pText, Adesk::kTrue); ent.GetLast(); ssDim += ent; continue; } delete pEnt; } } } OPENOBJ_END(); } } void MoveDnDimCmd() { RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL); PickSet ss(SS_FREE); if(SelectEntities(_T("\n请选择需要移动管径标注的管线: <退出>"), ss, rbMask) != RTNORM) return; long len = ss.Length(); if(len < 1) return; // cet 2010.1.18 add PickSet ssDim; GetPipeDim(ss, ssDim); // 根据管标注生成TDbText,用于动态预览 int n = ssDim.Length(); int iRet(0); AcGeMatrix3d mat; BOOL bReset = FALSE; BOOL bResetUp = FALSE; XPoint ptBase, ptMove; INITGET_BEG(0, _T("F R")); iRet = ads_getpoint(NULL, _T("\n选择移动的参考点[管径向上复位(F)/管径向下复位(R)]<退出>"), ptBase); INITGET_END(); if(iRet != RTNORM && iRet != RTKWORD){ ssDim.Erase(); // zxl 2012.04.09 add 退出时删除动态预览生成的TDbText return; } if(iRet == RTKWORD){ XString sKeyword; ads_getinput(sKeyword); TCHAR cKey = sKeyword[0]; bReset = TRUE; if(cKey==_T('F')) bResetUp = TRUE; else bResetUp = FALSE; } else { // modify cet 2010.1.18 支持动态预览 // if(ads_getpoint(ptBase, _T("\n选择移动的目标点<退出>"), ptMove) != RTNORM) // return; if (DragMovePickSet(ssDim, _T("\n选择移动的目标点<退出>"), ptBase, ptMove) != RTNORM) { ssDim.Erase(); return; } ptBase = Ucs2Wcs(ptBase); ptMove = Ucs2Wcs(ptMove); AcGeVector3d vt(ptMove - ptBase); mat.setToTranslation(vt); } for(long i=0;iIsVertical()) continue; XPoint ptLoc = pPipe->GetLabelLocation(); ptLoc.z = 0; if(pPipe->IsDrawLabel()) { if(bReset) { AcGePoint3d pt1 = ptLoc; AcGePoint3d pt2, ptStart, ptEnd; // 移动管径标注不匹配 zxl 2012.07.19 add ptStart = pPipe->StartPoint(); ptStart.z = 0; ptEnd = pPipe->EndPoint(); ptEnd.z = 0; AcDbLine line; line.setStartPoint(ptStart); line.setEndPoint(ptEnd); line.getClosestPointTo(pt1, pt2); double dRotation=0; XPoint ptMid = pPipe->MidPoint(); ptMid.z = 0; dRotation = pPipe->OrthoDirection(ptMid); dRotation = CT_std_angle(dRotation); if(fabs(dRotation) < 1e-6) dRotation = 0; if(fabs(dRotation - PI) < 1e-5) dRotation = PI; if(!(dRotation>0 && dRotation<=PI)) { dRotation = CT_std_angle(dRotation+PI); } double nScale = pPipe->GetPScale(); XPoint ptNear = pt2; if(bResetUp) ads_polar(ptNear,dRotation,g_nDnDimDist2Pipe*nScale,ptLoc); else ads_polar(ptNear,dRotation,-g_nDnDimDist2Pipe*nScale,ptLoc); pPipe->SetLabelLocation(ptLoc); } else { ptLoc.TransformBy(mat); pPipe->SetLabelLocation(ptLoc); } } } OPENOBJ_END(); } ssDim.Erase(); } //*************************************************************************************************** // 标注复位 //*************************************************************************************************** // 获得也标注最近的平行管线 cet 2012.8.29 add AcDbObjectId GetArrowDimPipe(Entity &entDim, PickSet &ssPipe) { // 标注方向 AcDbObjectId idRet = AcDbObjectId::kNull; XPoint pt1, pt2; OPENOBJ_BEGIN(entDim, AcDb::kForWrite, TDbSymbArrow, pDim); if (pDim != NULL) { XPoly2D poly; pDim->GetPoly2D(poly); if (poly.Length() < 2) { return idRet; } XCurveSegment seg; poly.Nth(0, seg); pt1 = seg.GetStartPoint(); pt2 = seg.GetEndPoint(); } OPENOBJ_END(); pt1.z = 0.0; pt2.z = 0.0; AcGeVector3d vtDim = pt1 - pt2; AcGePoint3d ptDimS = pt1; AcGePoint3d ptDimE = pt2; // 与标注平行且距离最近的管线 XPoint ptS, ptE; AcGeVector3d vtPipe; AcGeTol tol; tol.setEqualVector(0.001); int nLen = ssPipe.Length(); Entity entRet; double dDist = 0.0; AcDbLine linePipe; AcGePoint3d ptPrj1, ptPrj2; for (long i = 0; i < nLen; i++) { ptS = XPoint(); ptE = ptS; GetPipePoint(ssPipe[i], ptS, ptE); if (!ptS || !ptE) { continue; } ptS.z = 0.0; ptE.z = 0.0; vtPipe = ptS - ptE; if (!vtPipe.isParallelTo(vtDim, tol)) { continue; } linePipe.getClosestPointTo(ptDimS, ptPrj1); linePipe.getClosestPointTo(ptDimE, ptPrj2); double dDist1 = ptDimS.distanceTo(ptPrj1); double dDist2 = ptDimE.distanceTo(ptPrj2); double dMinDist = dDist1 < dDist2 ? dDist1 : dDist2; if (!entRet || dMinDist < dDist) { dDist = dMinDist; entRet = ssPipe[i]; } } if (!!entRet) { acdbGetObjectId(idRet, entRet); } return idRet; } // 调整标注位置 cet 2012.8.22 add void AdjustArrowDim(Entity &entDim, PickSet &ssPipe) { // 标注关联管线 AcDbObjectId idPipe = GetArrowDimPipe(entDim, ssPipe); if (idPipe.isNull()) { return; } TDbPipe *pPipe = NULL; acdbOpenObject(pPipe, idPipe, AcDb::kForRead); if (pPipe == NULL) { return; } XPoint ptS = pPipe->StartPoint(); XPoint ptE = pPipe->EndPoint(); pPipe->close(); ptS.z = 0.0; ptE.z = 0.0; // 调整标注 OPENOBJ_BEGIN(entDim, AcDb::kForWrite, TDbSymbArrow, pDim); if (pDim != NULL) { XPoly2D poly; pDim->GetPoly2D(poly); if (poly.Length() < 2) { return; } XCurveSegment seg; poly.Nth(0, seg); XPoint ptMid = seg.MidPoint(); XLine line(ptS, ptE); XPoint ptPrj; ptMid.Project(&line, ptPrj); if (!ptPrj) { return; } AcGeVector3d vtDir = ptMid - ptPrj; vtDir.normalize(); double dDist = pDim->GetText2BaseRatio(); AcGeVector3d vtX = AcGeVector3d::kXAxis; vtX.rotateBy(Ucs2Wcs(0.0), AcGeVector3d::kZAxis); double dAngle = vtX.angleTo(vtDir, AcGeVector3d::kZAxis); if (dAngle > PI + 0.001 && dAngle < PI *2 + 0.001 || fabs(dAngle) < 0.001) { dDist = g_nTwtDimHeight + dDist; } dDist *= DocGetPScale(); ptMid += vtDir * dDist; pDim->SetTextLocation(ptMid); } OPENOBJ_END(); } void ResetDimPosition() { RBList rbMask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); RBList rbMaskText(RTDXF0, _T("TEXT,ATS_TEXT"), 8, LAY_DIM, NULL); PickSet ss(SS_FREE); if(SelectEntities(_T("\n请选择要复位的管径标注、坡度标注,井标注:<退出>"), ss, rbMask) == RTNORM){ BOOL bHasWell = FALSE; for(long i=0;i"), &nDist); } // cet 2012.8.28 add bool bArrowDim = false; PickSet ssPipe(SS_FREE); for (i = 0; i < ss.Length(); i++) { if (ss[i].Is(_T("ATS_PIPE"))) { ssPipe += ss[i]; } } for(i=0;iIsDrawLabel()) continue; if(pPipe->IsVertical()) continue; XPoint ptDim = pPipe->GetLabelLocation(); double nScale = pPipe->GetPScale(); double dDist = g_nDnDimDist2Pipe*nScale; ptDim.z = 0; AcGePoint3d pt1 = ptDim; AcGePoint3d pt2, ptStart, ptEnd; // 标注复位功能改进:复位到距离管线较近一侧 zxl 2012.06.21 add ptStart = pPipe->StartPoint(); ptStart.z = 0; ptEnd = pPipe->EndPoint(); ptEnd.z = 0; AcDbLine line; line.setStartPoint(ptStart); line.setEndPoint(ptEnd); line.getClosestPointTo(pt1, pt2, Adesk::kTrue); pt2.z = 0; if (pt1.distanceTo(pt2) > 0.001) { AcGeVector3d vtPt2Pipe = pt1 - pt2; vtPt2Pipe.normalize(); line.getClosestPointTo(pt1, pt2); ptDim = pt2 + vtPt2Pipe * dDist; } else { line.getClosestPointTo(pt1, pt2); double dRotation=0; XPoint ptMid = pPipe->MidPoint(); ptMid.z = 0; dRotation = pPipe->OrthoDirection(ptMid); dRotation = CT_std_angle(dRotation); if(fabs(dRotation) < 1e-6) dRotation = 0; if(fabs(dRotation - PI) < 1e-5) dRotation = PI; if(!(dRotation>0 && dRotation<=PI)) { dRotation = CT_std_angle(dRotation+PI); } XPoint ptNear = pt2; ads_polar(ptNear,dRotation,dDist,ptDim); } pPipe->SetLabelLocation(ptDim); } OPENOBJ_END(); OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipeLabel, pLabel); if(pLabel){ double dRoate(0); pLabel->SetDistToPipe(-g_nDnDimDist2Pipe*DocGetPScale()); AcDbObjectId idPipe = pLabel->GetPipeId(); OPENOBJ_BEGIN(idPipe, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ dRoate = ads_angle(pPipe->GetStartPoint(), pPipe->GetEndPoint()); } OPENOBJ_END(); if(dRoate > PI/2 && dRoate <=PI*3/2)//管反了 pLabel->SetDistToPipe((-1)*pLabel->GetDistToPipe()); } OPENOBJ_END(); OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbSymbArrow, pDim); if(pDim){ /* cet 2012.8.28 modify XPoly2D poly; pDim->GetPoly2D(poly); XCurveSegment segFirst; poly.Nth(0, segFirst); XPoint ptMid = segFirst.MidPoint(); XPoint ptText = pDim->GetTextLocation(); double nAng = ads_angle(ptMid, ptText); ads_polar(ptMid, nAng, g_nTwtDimHeight*DocGetPScale(), ptText); pDim->SetTextLocation(ptText); */ CString sText = pDim->GetText(); if (!sText.IsEmpty() && ssPipe.Length() > 0) { bArrowDim = true; } } OPENOBJ_END(); // cet 2012.8.28 add if (bArrowDim) { AdjustArrowDim(ent, ssPipe); } OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbWell, pWell); if(pWell && pWell->IsDrawLabel()){ XPoint ptLable; XPoint ptLoc = pWell->GetLocation(); double Len = pWell->GetScale() * pWell->GetPScale(); double nLenText = Len/2*nDist; ads_polar(ptLoc, PI/2,nLenText,ptLable); pWell->SetLabelLocation(ptLable); } OPENOBJ_END(); } } }