#include "StdAfx.h" //*************************************************************************************************** // 镜像标注 //*************************************************************************************************** extern BOOL IsLineReverse(double nLineRotate); void MirrorDimCmd() { RBList rbMaskDim(RTDXF0, _T("ATS_ARROW"), NULL); RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL); PickSet ss(SS_FREE); if(SelectEntities(_T("\n请选择要改变镜像标注的管线:<退出>"), ss, rbMask) != RTNORM) return; for(long i=0;iLength(); AcDbObjectId idPipe = pPipe->objectId(); AcDbHandle handle = idPipe.handle(); TCHAR szHandle[17]=_T(""); handle.getIntoAsciiBuffer(szHandle); csPipeName = szHandle; } OPENOBJ_END(); PickSet ssDim(SS_FREE); XPoint ptStart, ptEnd, ptText; GetPipePoint(ent, ptStart, ptEnd, ptText); XPoint ptUcs = Wcs2Ucs(ptText); PickSet ss(SS_FREE); PickSet ssDel(SS_FREE); XPoint ptTemp1, ptTemp2; ptTemp1.x = ptUcs.x - nLen*1000; ptTemp1.y = ptUcs.y + nLen*1000; ptTemp2.x = ptUcs.x + nLen*1000; ptTemp2.y = ptUcs.y - nLen*1000; ptTemp1.z = 0; ptTemp2.z = 0; RBList rbMask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); ssDim.Get(_T("C"), ptTemp1, ptTemp2, rbMask); long len1 = ssDim.Length(); for(long j=0;jGetPoly2D(poly); XPoint pt1 = *poly[0]; XPoint pt2 = *poly[1]; double nRotate = ads_angle(pt1, pt2); Midpoint(pt1, pt2, ptText); OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ pPipe->getClosestPointTo(ptText, ptLoc); } OPENOBJ_END(); double dDist = ads_distance(ptText, ptLoc); AcGeVector3d vt(ptLoc - ptText); vt.normalize(); vt *= dDist*2; AcGeMatrix3d matNew; matNew.setToTranslation(vt); //pArrow->transformBy(matNew); ptText = pArrow->GetTextLocation(); //AcGeVector3d vectBase(ptStart.x - ptEnd.x, ptStart.y - ptEnd.y, 0);// zxl 2012.04.09 modify AcGeVector3d vectBase = AcGeVector3d::kXAxis; vectBase.normalize(); AcGeVector3d vectTmp(ptText.x - ptLoc.x, ptText.y - ptLoc.y, 0); vectTmp.normalize(); double nPipeAng = ads_angle(ptStart, ptEnd); if(fabs(nPipeAng - PI/2*3) < 0.0001) nPipeAng -= PI; BOOL flag = IsLineReverse(nPipeAng);//管线逆向绘制 double dAng = vectBase.angleTo(vectTmp, AcGeVector3d::kZAxis); // zxl 2012.04.09 modify double dMirrorDist = (pArrow->GetTextHeight() + pArrow->GetText2BaseRatio() * 2) * DocGetPScale(); if(!flag) { if (dAng > 0 && dAng <= PI) { ads_polar(ptText, nPipeAng - PI/2, dMirrorDist, ptText); } else { ads_polar(ptText, nPipeAng + PI/2, dMirrorDist, ptText); } } else { if (dAng > 0 && dAng <= PI) { ads_polar(ptText, nPipeAng + PI/2, dMirrorDist, ptText); } else { ads_polar(ptText, nPipeAng - PI/2, dMirrorDist, ptText); } } // if(flag){ // if(dAng > 0 && dAng <= PI/2){ //第1象限 // } // else if(dAng > PI/2 && dAng <= PI){ //第2象限 // } // else if(dAng > PI && dAng <= PI/2*3){ //第3象限 // //ads_polar(ptText, nPipeAng+PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); // ads_polar(ptText, nPipeAng+PI/2, dMirrorDist, ptText); // } // else if(dAng > PI/2*3 && dAng <= PI*2){//第4象限 // //ads_polar(ptText, nPipeAng+PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); // ads_polar(ptText, nPipeAng+PI/2, dMirrorDist, ptText); // } // } // else // { // if(dAng > 0 && dAng <= PI/2){ //第3象限 // //ads_polar(ptText, nPipeAng-PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); // ads_polar(ptText, nPipeAng-PI/2, dMirrorDist, ptText); // } // else if(dAng > PI/2 && dAng <= PI){ //第4象限 // //ads_polar(ptText, nPipeAng-PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); // ads_polar(ptText, nPipeAng-PI/2, dMirrorDist, ptText); // } // else if(dAng > PI && dAng <= PI/2*3){ //第1象限 // } // else if(dAng > PI/2*3 && dAng <= PI*2){ //第2象限 // } // // } pArrow->SetTextLocation(ptText); pArrow->transformBy(matNew); } OPENOBJ_END(); } } } } }