#include "stdafx.h" #include #include #include #include "DimPipeGradientDlg.h" #include "jig.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CString GetDimLayByEnt(Entity ent) { CString csLay; TPipeSys::SysType sysType; OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe); if(pPipe){ sysType = pPipe->GetSysType(); } OPENOBJ_END(); csLay = GetDimLayBySys(sysType); return csLay; } //void DelDimedPipeGradient(Entity entPipe); //删除已经标注的坡度和长度 void DelDimedPipeGradient(Entity entPipe, BOOL bDelPipeLen, BOOL bDelArrow) { double nLen(0); CString csPipeName; OPENOBJ_BEGIN(entPipe, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ AcDbObjectId idPipe = pPipe->objectId(); AcDbHandle handle = idPipe.handle(); TCHAR szHandle[17]=_T(""); handle.getIntoAsciiBuffer(szHandle); csPipeName = szHandle; nLen = pPipe->Length(); } OPENOBJ_END(); XPoint ptStart, ptEnd, ptText; GetPipePoint(entPipe, 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; if(bDelPipeLen == TRUE && bDelArrow == FALSE) { RBList rbMask = ads_buildlist( -4, _T(""), -4, _T("or>"), NULL); ss.Get(_T("C"), ptTemp1, ptTemp2, rbMask); } else if(bDelPipeLen == TRUE && bDelArrow == TRUE) { RBList rbMask = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); ss.Get(_T("C"), ptTemp1, ptTemp2, rbMask); } else if(bDelPipeLen == FALSE && bDelArrow == TRUE) { RBList rbMask = ads_buildlist( -4, _T(""), -4, _T("or>"), NULL); ss.Get(_T("C"), ptTemp1, ptTemp2, rbMask); } long len1 = ss.Length(); for(long j=0;jobjectId(); AcDbHandle handle = idPipe.handle(); TCHAR szHandle[17]=_T(""); handle.getIntoAsciiBuffer(szHandle); csPipeName = szHandle; pPipe->ProjectToMe(ptPick, ptText); } OPENOBJ_END(); CString csLay = GetPipeTextLayByEnt(entSel); InitLayer(csLay); XPoint ptend; int itype = -1; ads_prompt(_T("\n请选择标注方向<确定>")); while(1){ struct resbuf pointbuf; int iRet = ads_grread(5, &itype, &pointbuf); ads_point_set(pointbuf.resval.rpoint, ptend); ptend = Ucs2Wcs(ptend); if(itype != 5 && itype != 3 && itype != 11) break; AcGeVector3d vectBase(ptEnd.x - ptStart.x, ptEnd.y - ptStart.y, 0); AcGeVector3d vectTmp(ptend.x - ptPick.x, ptend.y - ptPick.y, 0); double dAng2 = vectBase.angleTo(vectTmp, AcGeVector3d::kZAxis); if(dAng2 < PI) ads_polar(ptPick, nRotate + PI/2, g_nDnDimDist2Pipe*DocGetPScale(), ptText); else{ ads_polar(ptPick, nRotate - PI/2, g_nDnDimDist2Pipe*DocGetPScale(), ptText); } ads_redraw(NULL, 1); if(itype == 3 || itype == 11){ break; } else{ XPoint ptTmpUcs1 = Wcs2Ucs(ptPick); XPoint ptTmpUcs2 = Wcs2Ucs(ptText); ads_grdraw(ptTmpUcs1, ptTmpUcs2, -1, 0); } } TCHAR szLayer[256]; entSel.GetData(8, szLayer); GetPipePoint(entSel, ptStart, ptEnd); ptStart.z = 0; ptEnd.z = 0; double nLen = ads_distance(ptStart, ptEnd); if(!DocGetMeterUnitDraw()) nLen = nLen / 1000; CString csLen; // cet 2011.5.20 modify // csLen.Format(_T("L=%sm"), GetDimPipeLen(nLen)); GetDimPipeLen(csLen, nLen); double nRotateText = nRotate; if((nRotateText + 0.001) > PI && (nRotateText - 0.001) < PI/2*3) nRotateText -= PI; else if((nRotateText - 0.001) > PI/2 && (nRotateText + 0.001) < PI) nRotateText += PI; XText text(csLen, ptText, g_nTwtDimHeight * DocGetPScale(), g_nDimScale, g_csTwtDimStyle, csLay); text.SetRotate(nRotateText); text.TgDraw(XExplodeDraw::kMiddleCenter); if(_tcscmp(szLayer, _T("")) != 0){ Entity entLast; entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); WriteXdata(entLast, _T("TG-BINDPIPE"), csPipeName); } } void DimPipeLength() { double nArrowLen = 15*DocGetPScale(); RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL); Entity entSel; XPoint ptPick; double nGradient = 0.004; // InitLayer(LAY_DIM); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); while(1){ int ret = SelectEntity1(g_nCurPipeWidth*DocGetPScale(), _T("\n请选择要标注管长度的管线<退出>:"), entSel, ptPick, rbMask); if(ret == RTNORM){ ptPick = Ucs2Wcs(ptPick); DoDimPipeLength(entSel, ptPick); } else break; } } //仅标注水流方向 void DimPipeArrow(Entity ent, double nArrowLen, BOOL bHalfArrow, double dArrowSize, BOOL bOnLine) { AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); if(!idTextStyle) return; nArrowLen = nArrowLen*DocGetPScale(); BOOL bReverse = FALSE; double nGradient(0), nLen(0); CString csPipeName; OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ AcDbObjectId idPipe = pPipe->objectId(); AcDbHandle handle = idPipe.handle(); TCHAR szHandle[17]=_T(""); handle.getIntoAsciiBuffer(szHandle); csPipeName = szHandle; TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if(dir == TPipeSys::kFromStart) bReverse = FALSE; else bReverse = TRUE; } OPENOBJ_END(); XPoint ptStart, ptEnd, ptText; GetPipePoint(ent, ptStart, ptEnd, ptText); double nRotate = ads_angle(ptStart, ptEnd); if(bOnLine) nArrowLen = dArrowSize*DocGetPScale(); if(bReverse){ //管线是否反画 ads_polar(ptText, nRotate-PI, nArrowLen/2, ptEnd); ads_polar(ptText, nRotate, nArrowLen/2, ptStart); } else{ ads_polar(ptText, nRotate-PI, nArrowLen/2, ptStart); ads_polar(ptText, nRotate, nArrowLen/2, ptEnd); } if(!bOnLine) { if((nRotate - 0.001) < PI/2 || (nRotate - 0.001) > PI/2*3){ ads_polar(ptStart, nRotate - PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptStart); ads_polar(ptEnd, nRotate - PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptEnd); } else{ ads_polar(ptStart, nRotate + PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptStart); ads_polar(ptEnd, nRotate + PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptEnd); } } DelDimedPipeGradient(ent, FALSE, TRUE); // zxl 2014.04.18 modify //InitLayer(LAY_PIPE_DIM); CString csLay = GetDimLayByEnt(ent); InitLayer(csLay); TDbSymbArrow *pArrow = new TDbSymbArrow; XPoly2D poly; poly.AppendNode(ptStart); poly.AppendNode(ptEnd); double nRotateText = ads_angle(ptStart, ptEnd); Midpoint(ptStart, ptEnd, ptText); pArrow->SetPoly2D(poly); // zxl 2014.04.18 modify //pArrow->setLayer(LAY_PIPE_DIM); pArrow->setLayer(csLay); pArrow->SetTextStyleId(idTextStyle); pArrow->SetTextAlign(TDbSymbArrow::kAlignMid); pArrow->SetArrowSize(dArrowSize); if(bHalfArrow) pArrow->SetArrowType(TDbSymbArrow::kHalfArrow); pArrow->SetTextLayerId(InitLayer(LAY_TEXT)); if((nRotate - 0.001) < PI/2 || (nRotate - 0.001) > PI/2*3){ ads_polar(ptText, nRotate-PI/2, g_nTwtDimHeight*DocGetPScale(), ptText); } else{ ads_polar(ptText, nRotate+PI/2, g_nTwtDimHeight*DocGetPScale(), ptText); } pArrow->SetTextLocation(ptText); AddToCurrentSpace(pArrow, Adesk::kTrue); TCHAR szLayer[256]; ent.GetData(8, szLayer); Entity entLast; entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); WriteXdata(entLast, _T("TG-BINDPIPE"), csPipeName); } void DoDimPipeGradient(Entity ent, double i, BOOL bReverse, double nArrowLen, BOOL bHalfArrow, BOOL bDrawLen, BOOL bDrawGradient, double dArrowSize) { nArrowLen = nArrowLen*DocGetPScale(); int iMode = (int)bReverse; AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); if(!idTextStyle) return; double nGradient(0), nLen(0); CString csLen,csPipeName; CString csLay = GetDimLayByEnt(ent); InitLayer(csLay); CString csLayText = GetPipeTextLayByEnt(ent); InitLayer(csLayText); OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ AcDbObjectId idPipe = pPipe->objectId(); AcDbHandle handle = idPipe.handle(); TCHAR szHandle[17]=_T(""); handle.getIntoAsciiBuffer(szHandle); csPipeName = szHandle; if(iMode > -1){ if(bReverse) pPipe->SetFlowDir(TPipeSys::kFromEnd); else pPipe->SetFlowDir(TPipeSys::kFromStart); } else{ //命令【管线坡度】多选标注 TPipeSys::FlowDirection dir = pPipe->GetFlowDir(); if(dir == TPipeSys::kFromStart) bReverse = FALSE; else bReverse = TRUE; } nLen = pPipe->Length(); // if(!DocGetMeterUnitDraw()) // nLen = nLen / 1000; // csLen.Format(_T("L=%sm"), GetDimPipeLen(nLen)); cet 2011.5.20 modify GetDimPipeLen(csLen, nLen); // csLen.Format(_T("L=%.2fm"), nLen); nGradient = pPipe->GetPipeGradient(); if(nGradient > 1) nGradient = 0; } OPENOBJ_END(); XPoint ptStart, ptEnd, ptText; GetPipePoint(ent, ptStart, ptEnd, ptText); double nRotate = ads_angle(ptStart, ptEnd); if(bReverse){ //管线是否反画 ads_polar(ptText, nRotate-PI, nArrowLen/2, ptEnd); ads_polar(ptText, nRotate, nArrowLen/2, ptStart); } else{ ads_polar(ptText, nRotate-PI, nArrowLen/2, ptStart); ads_polar(ptText, nRotate, nArrowLen/2, ptEnd); } if((nRotate - 0.001) < PI/2 || (nRotate - 0.001) > PI/2*3){ ads_polar(ptStart, nRotate - PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptStart); ads_polar(ptEnd, nRotate - PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptEnd); } else{ ads_polar(ptStart, nRotate + PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptStart); ads_polar(ptEnd, nRotate + PI/2, ( g_nDnDimDist2Pipe/2)*DocGetPScale(), ptEnd); } CString csText = _T("i=") + I2Str(i); i = i/1000; DelDimedPipeGradient(ent, TRUE, TRUE); OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe && !pPipe->IsVertical()){ pPipe->SetPipeGradient(i); } OPENOBJ_END(); Entity entLast; TCHAR szLayer[256]; ent.GetData(8, szLayer); // InitLayer(LAY_PIPE_DIM); double nRotateText = ads_angle(ptStart, ptEnd); if((nRotate - 0.001) < PI/2 || (nRotate - 0.001) > PI/2*3){ ads_polar(ptText, nRotate-PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); } else{ ads_polar(ptText, nRotate+PI/2, (g_nTwtDimHeight + 1)*DocGetPScale(), ptText); } //标注坡度 if(bDrawGradient){ TDbSymbArrow *pArrow = new TDbSymbArrow; XPoly2D poly; poly.AppendNode(ptStart); poly.AppendNode(ptEnd); Midpoint(ptStart, ptEnd, ptText); pArrow->SetPoly2D(poly); pArrow->setLayer(csLay); pArrow->SetTextStyleId(idTextStyle); pArrow->SetTextHeight(g_nTwtDimHeight); pArrow->SetTextAlign(TDbSymbArrow::kAlignMid); pArrow->SetArrowSize(dArrowSize); if(bHalfArrow) pArrow->SetArrowType(TDbSymbArrow::kHalfArrow); pArrow->SetText(csText); pArrow->SetTextLayerId(InitLayer(LAY_TEXT)); double dDist = pArrow->GetText2BaseRatio(); if((nRotate - 0.001) < PI/2 || (nRotate - 0.001) > PI/2*3){ ads_polar(ptText, nRotate-PI/2, (g_nTwtDimHeight + dDist)*DocGetPScale(), ptText); } else{ ads_polar(ptText, nRotate+PI/2, (g_nTwtDimHeight + dDist)*DocGetPScale(), ptText); } pArrow->SetTextLocation(ptText); AddToCurrentSpace(pArrow, Adesk::kTrue); entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); WriteXdata(entLast, _T("TG-BINDPIPE"), csPipeName); } //标注管长 if(bDrawLen){ if((nRotateText + 0.001) > PI && (nRotateText - 0.001) < PI/2*3) nRotateText -= PI; else if((nRotateText - 0.001) > PI/2 && (nRotateText + 0.001) < PI) nRotateText += PI; if(bDrawGradient) ads_polar(ptText, nRotateText, nArrowLen/3*2, ptText); XText text(csLen, ptText, g_nTwtDimHeight * DocGetPScale(), g_nDimScale, g_csTwtDimStyle, csLayText); text.SetRotate(nRotateText); text.TgDraw(XExplodeDraw::kBottomLeft); entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); WriteXdata(entLast, _T("TG-BINDPIPE"), csPipeName); } } void DimPipeGradient() { double dGradient(-1); Entity entGradent; CDimPipeGradientDlg dlg(acedGetAcadFrame()); { CTemporaryResourceOverride vTemp; dlg.Create(IDD_DIM_PIPE_GRADIENT, acedGetAcadFrame()); } dlg.ShowWindow(SW_SHOW); acedGetAcadDwgView()->SetFocus(); InitLayer(LAY_DIM); double nArrowLen = 15*DocGetPScale(); RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL); Entity entSel; XPoint ptPick; TCHAR szLayer[256]; double nGradient = 0.004; InitLayer(LAY_PIPE_DIM); AcDbObjectId idTextStyle = InitTwtTextStyle(g_csTwtDimStyle); while(1){ dlg.UpdateData(); if(dlg.m_bPick){ dlg.m_bChangeMode = FALSE; dlg.m_bPick = FALSE; Entity entGradent; RBList reMaskRef = ads_buildlist( -4, _T(""), -4, _T(""), -4, _T(""), -4, _T(""), -4, _T("or>"), NULL); if(SelectEntity(_T("\n请选择图中可参考坡度标注:<返回>"), entGradent, reMaskRef) == RTNORM){ if(entGradent.Is(_T("ATS_PIPE"))){ dGradient = GetPipeGradient(entGradent); } else if(entGradent.Is(_T("ATS_ARROW"))){ OPENOBJ_BEGIN(entGradent, AcDb::kForRead, TDbSymbArrow, pEnt); if(pEnt){ CString csText = pEnt->GetText(); int idx = csText.Find(_T("=")); csText = csText.Right(csText.GetLength()-idx-1); dGradient = _tstof(csText); } OPENOBJ_END(); } else{ TCHAR szText[256]; entGradent.GetData(1, szText); CString csText = szText; int idx = csText.Find(_T("=")); csText = csText.Right(csText.GetLength()-idx-1); idx = csText.Find(_T("%")); if(idx > -1){ csText = csText.Left(idx); dGradient = _tstof(csText) / 100.0; } else dGradient = _tstof(csText); } } dlg.m_csGradient.Format(_T("%.4f"), dGradient); dlg.UpdateData(FALSE); continue; } if(dlg.m_iMode == 1){ //多选 PickSet ss(SS_FREE); int ret = SelectEntities(_T("\n请选择要标注坡度的管线<退出>:"), ss, rbMask); if(ret == RTNORM) { dlg.UpdateData(); double nOld = g_nTwtDimHeight; g_nTwtDimHeight = dlg.m_nTextHeight; nGradient = _tstof(dlg.m_csGradient); long len = ss.Length(); for(long i=0;iGetPipeGradient(); } OPENOBJ_END(); } if(!dlg.m_bGradient && !dlg.m_bPipeLen && !dlg.m_bOnlyArrow){ OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ pPipe->SetPipeGradient(nGradient); } OPENOBJ_END(); } else if(dlg.m_bOnlyArrow) DimPipeArrow(entTmp, dlg.m_nArrowLen, dlg.m_bArrowHalf, dlg.m_dArrow, dlg.m_bOnLine); else DoDimPipeGradient(entTmp, nGradient*1000, -1, dlg.m_nArrowLen, dlg.m_bArrowHalf, dlg.m_bPipeLen, dlg.m_bGradient, dlg.m_dArrow); } g_nTwtDimHeight = nOld; } else if(ret == RTERROR && dlg.m_bChangeMode){ dlg.m_bChangeMode = FALSE; continue; } else break; } else{ //单选 int ret = SelectEntity1(g_nCurPipeWidth*DocGetPScale(), _T("\n请选择要标注坡度的管线<退出>:"), entSel, ptPick, rbMask); if(ret == RTNORM){ ptPick = Ucs2Wcs(ptPick); dlg.UpdateData(); //什么都不标注, 仅仅更新一下数据 if(!dlg.m_bGradient && !dlg.m_bPipeLen && !dlg.m_bOnlyArrow){ DelDimedPipeGradient(entSel, TRUE, TRUE); CString csPipeName; OPENOBJ_BEGIN(entSel, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ if(dlg.m_csGradient == _T("读图")) nGradient = pPipe->GetPipeGradient(); else nGradient = _tstof(dlg.m_csGradient); pPipe->SetPipeGradient(nGradient); } OPENOBJ_END(); continue; } //仅标注管长 if(!dlg.m_bGradient && dlg.m_bPipeLen && !dlg.m_bOnlyArrow){ DoDimPipeLength(entSel, ptPick); continue; } CString csLay = GetDimLayByEnt(entSel); InitLayer(csLay); CString csLayText = GetPipeTextLayByEnt(entSel); InitLayer(csLayText); nArrowLen = dlg.m_nArrowLen*DocGetPScale(); entSel.GetData(8, szLayer); TDbSymbArrow *pArrow = new TDbSymbArrow; XPoint ptStart, ptEnd, ptText; GetPipePoint(entSel, ptStart, ptEnd); ptStart.z = 0; ptEnd.z = 0; double nLen = ads_distance(ptStart, ptEnd); if(!DocGetMeterUnitDraw()) nLen = nLen / 1000; CString csLen; //csLen.Format(_T("L=%sm"), GetDimPipeLen(nLen)); cet 2011.5.20 modify GetDimPipeLen(csLen, nLen); double nRotate = ads_angle(ptStart, ptEnd); if(dlg.m_bOnlyArrow && dlg.m_bOnLine) nArrowLen = dlg.m_dArrow * DocGetPScale(); ads_polar(ptPick, nRotate-PI, nArrowLen/2, ptStart); ads_polar(ptPick, nRotate, nArrowLen/2, ptEnd); XPoly2D poly; poly.AppendNode(ptStart); poly.AppendNode(ptEnd); pArrow->SetPoly2D(poly); pArrow->setLayer(csLay); pArrow->SetTextStyleId(idTextStyle); pArrow->SetTextHeight(dlg.m_nTextHeight); pArrow->SetTextAlign(TDbSymbArrow::kAlignMid); pArrow->SetArrowSize(dlg.m_dArrow); if(dlg.m_bArrowHalf) pArrow->SetArrowType(TDbSymbArrow::kHalfArrow); pArrow->SetTextLayerId(InitLayer(LAY_TEXT)); double dTmpDnDimDist2Pipe = g_nDnDimDist2Pipe; if(dlg.m_bOnlyArrow && dlg.m_bOnLine) // 2009-8-6 x12提的水流方向,线上标注 dTmpDnDimDist2Pipe = 0; TArrowEdJig jig(pArrow, ptPick, ptStart, ptEnd, dTmpDnDimDist2Pipe); if(jig.DoIt()==RTNORM) { dlg.UpdateData(); DelDimedPipeGradient(entSel, !dlg.m_bOnlyArrow, TRUE); //如果仅仅标水流方向,就不删除管长标注了 CString csPipeName; OPENOBJ_BEGIN(entSel, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe){ AcDbObjectId idPipe = pPipe->objectId(); AcDbHandle handle = idPipe.handle(); TCHAR szHandle[17]=_T(""); handle.getIntoAsciiBuffer(szHandle); csPipeName = szHandle; if(dlg.m_csGradient == _T("读图")) nGradient = pPipe->GetPipeGradient(); else nGradient = _tstof(dlg.m_csGradient); if(jig.m_bFromStart) pPipe->SetFlowDir(TPipeSys::kFromStart); else pPipe->SetFlowDir(TPipeSys::kFromEnd); } OPENOBJ_END(); if(dlg.m_bGradient){ int iTmp = int(nGradient * 1000) * 10; int iTmp2 = int(nGradient * 10000); CString csText; if(iTmp == iTmp2){ iTmp = int(nGradient * 100) * 10; iTmp2 = int(nGradient * 1000); if(iTmp == iTmp2) csText.Format(_T("i=%.2f"), nGradient); else csText.Format(_T("i=%.3f"), nGradient); } else csText.Format(_T("i=%.4f"), nGradient); pArrow->SetText(csText); pArrow->SetArrowSize(dlg.m_dArrow); } ptText = pArrow->GetTextLocation(); if(dlg.m_bPipeLen && !dlg.m_bGradient) delete pArrow; else{ if(!dlg.m_bPipeLen && !dlg.m_bGradient) pArrow->SetText(_T("")); // pArrow->AddToCSpace(Adesk::kTrue); AddToCurrentSpace(pArrow, Adesk::kTrue); } if(_tcscmp(szLayer, _T("")) != 0){ Entity entLast; entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); WriteXdata(entLast, _T("TG-BINDPIPE"), csPipeName); } OPENOBJ_BEGIN(entSel, AcDb::kForWrite, TDbPipe, pPipe); if(pPipe && !pPipe->IsVertical()){ if(dlg.m_bGradient) pPipe->SetPipeGradient(nGradient); } OPENOBJ_END(); if((nRotate + 0.001) > PI && (nRotate - 0.001) < PI/2*3) nRotate -= PI; else if((nRotate - 0.001) > PI/2 && (nRotate + 0.001) < PI) nRotate += PI; if(dlg.m_bPipeLen){ if(dlg.m_bGradient) ads_polar(ptText, nRotate, nArrowLen/3*2, ptText); XText text(csLen, ptText, dlg.m_nTextHeight * DocGetPScale(), g_nDimScale, g_csTwtDimStyle, csLayText); text.SetRotate(nRotate); text.TgDraw(XExplodeDraw::kBottomLeft); if(_tcscmp(szLayer, _T("")) != 0){ Entity entLast; entLast.GetLast(); WriteXdata(entLast, _T("TG-LAYER"), szLayer); WriteXdata(entLast, _T("TG-BINDPIPE"), csPipeName); } } continue; } delete pArrow; } else if(ret == RTNONE && dlg.m_bChangeMode){ dlg.m_bChangeMode = FALSE; continue; } else break; } } dlg.DestroyWindow(); } IMPLEMENT_DYNAMIC(CDimPipeGradientDlg, CModelessDialog) CString CDimPipeGradientDlg::m_csGradient = _T("0.004"); double CDimPipeGradientDlg::m_nTextHeight = 3.0; double CDimPipeGradientDlg::m_nArrowLen = 15; double CDimPipeGradientDlg::m_dArrow = 2.0; // cet 2010.7.19 add BOOL CDimPipeGradientDlg::m_bOnlyArrow = FALSE; BOOL CDimPipeGradientDlg::m_bOnLine = FALSE; BOOL CDimPipeGradientDlg::m_bGradient = TRUE; BOOL CDimPipeGradientDlg::m_bPipeLen = FALSE; CDimPipeGradientDlg::CDimPipeGradientDlg(CWnd* pParent /*=NULL*/) : CModelessDialog(CDimPipeGradientDlg::IDD, pParent) { //{{AFX_DATA_INIT(CDimPipeGradientDlg) m_bArrowHalf = FALSE; m_iMode = 0; // m_dArrow = 2.0; cet 2010.7.19 del //}}AFX_DATA_INIT m_bChangeMode = FALSE; m_dRefGradient = -1; m_bPick = FALSE; } void CDimPipeGradientDlg::DoDataExchange(CDataExchange* pDX) { CModelessDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDimPipeGradientDlg) DDX_Check(pDX, IDC_CHECK_HALF, m_bArrowHalf); DDX_Check(pDX, IDC_CHECK_GRADIENT, m_bGradient); DDX_Check(pDX, IDC_CHECK_LEN, m_bPipeLen); DDX_Radio(pDX, IDC_RADIO_SINGLE, m_iMode); DDX_Text(pDX, IDC_EDIT_ARROW, m_dArrow); DDX_Check(pDX, IDC_CHECK_ONLYARROW, m_bOnlyArrow); DDX_Text(pDX, IDC_EDIT_TEXT_HEIGHT, m_nTextHeight); DDX_Text(pDX, IDC_EDIT_ARROW_LEN, m_nArrowLen); DDX_CBString(pDX, IDC_COMBO_GRADIENT, m_csGradient); DDX_Check(pDX, IDC_CHECK_ONLINE, m_bOnLine); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDimPipeGradientDlg, CModelessDialog) //{{AFX_MSG_MAP(CDimPipeGradientDlg) ON_BN_CLICKED(IDC_RADIO_SINGLE, OnRadioSingle) ON_BN_CLICKED(IDC_RADIO_ALL, OnRadioAll) ON_WM_CLOSE() ON_BN_CLICKED(IDC_BUTTON_PICK, OnButtonPick) ON_BN_CLICKED(IDC_CHECK_ONLYARROW, OnCheckOnlyarrow) ON_BN_CLICKED(IDC_CHECK_LEN, OnCheckLen) ON_BN_CLICKED(IDC_CHECK_GRADIENT, OnCheckGradient) //}}AFX_MSG_MAP ON_WM_DESTROY() ON_EN_KILLFOCUS(IDC_EDIT_TEXT_HEIGHT, &CDimPipeGradientDlg::OnEnKillfocusEditTextHeight) ON_EN_KILLFOCUS(IDC_EDIT_ARROW, &CDimPipeGradientDlg::OnEnKillfocusEditArrow) ON_EN_KILLFOCUS(IDC_EDIT_ARROW_LEN, &CDimPipeGradientDlg::OnEnKillfocusEditArrowLen) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDimPipeGradientDlg message handlers void CDimPipeGradientDlg::OnRadioSingle() { m_bChangeMode = TRUE; PostCommand(_T(" "), false); acedGetAcadDwgView()->SetFocus(); } void CDimPipeGradientDlg::OnRadioAll() { m_bChangeMode = TRUE; PostCommand(_T(" "), false); acedGetAcadDwgView()->SetFocus(); } void CDimPipeGradientDlg::OnClose() { WriteRegData();// zxl 2014.04.17 add CModelessDialog::OnClose(); PostCommand(_T("\33"),false); } // zxl 2014.04.17 add void CDimPipeGradientDlg::WriteRegData() { UpdateData(TRUE); CRegProperty regProp(GetRegLocation(), _T("TWTConfig")); regProp.SetTopRootKey(HKEY_CURRENT_USER); regProp.SetValue(_T("PipeGradientDimHeight"), m_nTextHeight); regProp.SetValue(_T("PipeGradientDimArrowLen"), m_nArrowLen); regProp.SetValue(_T("PipeGradientDimArrowSize"), m_dArrow); regProp.SetValue(_T("PipeGradientDimArrowHalf"), m_bArrowHalf); } BOOL CDimPipeGradientDlg::OnInitDialog() { CModelessDialog::OnInitDialog(); // zxl 2014.04.17 add CRegProperty regProp(GetRegLocation(), _T("TWTConfig")); regProp.SetTopRootKey(HKEY_CURRENT_USER); if (!regProp.GetValue(_T("PipeGradientDimHeight"), m_nTextHeight)) { m_nTextHeight = 3.0; } if (!regProp.GetValue(_T("PipeGradientDimArrowLen"), m_nArrowLen)) { m_nArrowLen = 15; } if (!regProp.GetValue(_T("PipeGradientDimArrowSize"), m_dArrow)) { m_dArrow = 2.0; } if (!regProp.GetValue(_T("PipeGradientDimArrowHalf"), m_bArrowHalf)) { m_bArrowHalf = FALSE; } UpdateData(FALSE); if(m_dRefGradient > -1){ m_csGradient.Format(_T("%.4f"), m_dRefGradient); UpdateData(FALSE); } OnCheckOnlyarrow(); // zxl 2014.04.17 add OnEnKillfocusEditTextHeight(); OnEnKillfocusEditArrow(); OnEnKillfocusEditArrowLen(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CDimPipeGradientDlg::OnButtonPick() { m_bChangeMode = TRUE; m_bPick = TRUE; PostCommand(_T(" "), false); acedGetAcadDwgView()->SetFocus(); } void CDimPipeGradientDlg::OnCheckOnlyarrow() { UpdateData(TRUE); CWnd *pWnd = GetDlgItem(IDC_COMBO_GRADIENT); CWnd *pWnd2 = GetDlgItem(IDC_CHECK_ONLINE); if(m_bOnlyArrow){ pWnd->EnableWindow(FALSE); pWnd2->EnableWindow(TRUE); m_bGradient = FALSE; m_bPipeLen = FALSE; } else{ pWnd2->EnableWindow(FALSE); pWnd->EnableWindow(TRUE); m_bGradient = TRUE; } UpdateData(FALSE); } void CDimPipeGradientDlg::OnCheckLen() { UpdateData(TRUE); CWnd *pWnd = GetDlgItem(IDC_COMBO_GRADIENT); CWnd *pWnd2 = GetDlgItem(IDC_CHECK_ONLINE); pWnd->EnableWindow(TRUE); pWnd2->EnableWindow(FALSE); m_bOnlyArrow = FALSE; UpdateData(FALSE); } void CDimPipeGradientDlg::OnCheckGradient() { UpdateData(TRUE); CWnd *pWnd = GetDlgItem(IDC_COMBO_GRADIENT); CWnd *pWnd2 = GetDlgItem(IDC_CHECK_ONLINE); pWnd->EnableWindow(TRUE); pWnd2->EnableWindow(FALSE); m_bOnlyArrow = FALSE; UpdateData(FALSE); } // zxl 2014.04.17 add void CDimPipeGradientDlg::OnDestroy() { WriteRegData(); CModelessDialog::OnDestroy(); } // zxl 2014.04.17 add bool StringIsAllNum(CString str) { // 判断字符是否是合法数字 CString sText = str.SpanIncluding(_T("0123456789.-")); // 小数点可以出现在中间,但只能出现一次 int nIndex = sText.Find(_T("."), 0); if (nIndex > 0) { nIndex = sText.Find(_T("."), ++nIndex); } // 负号可以出现在起始处,但只能出现一次 int nIndex2 = sText.Find(_T("-")); if (nIndex2 == 0) { nIndex2 = sText.Find(_T("-"), 1); } bool bFigure = true; if (str == sText && nIndex < 0 && nIndex2 <= 0)// 全是数字 { return true; } return false; } // zxl 2014.04.17 add void CDimPipeGradientDlg::OnEnKillfocusEditTextHeight() { CEdit *pEdt = (CEdit *)GetDlgItem(IDC_EDIT_TEXT_HEIGHT); if (pEdt == NULL) { return; } double dTextHeight = m_nTextHeight; CString sTextHeight; pEdt->GetWindowText(sTextHeight); m_nTextHeight = _tstof(sTextHeight); sTextHeight.Format(_T("%.2f"), m_nTextHeight); if (m_nTextHeight <= 0.0 || !StringIsAllNum(sTextHeight)) { sTextHeight.Format(_T("%.2f"), dTextHeight); m_nTextHeight = dTextHeight; pEdt->SetWindowText(sTextHeight); } else { pEdt->SetWindowText(sTextHeight); } } // zxl 2014.04.17 add void CDimPipeGradientDlg::OnEnKillfocusEditArrow() { CEdit *pEdt = (CEdit *)GetDlgItem(IDC_EDIT_ARROW); if (pEdt == NULL) { return; } double dText = m_dArrow; CString sText; pEdt->GetWindowText(sText); m_dArrow = _tstof(sText); sText.Format(_T("%.2f"), m_dArrow); if (m_dArrow <= 0.0 || !StringIsAllNum(sText)) { sText.Format(_T("%.2f"), dText); m_dArrow = dText; pEdt->SetWindowText(sText); } else { pEdt->SetWindowText(sText); } } // zxl 2014.04.17 add void CDimPipeGradientDlg::OnEnKillfocusEditArrowLen() { CEdit *pEdt = (CEdit *)GetDlgItem(IDC_EDIT_ARROW_LEN); if (pEdt == NULL) { return; } double dText = m_nArrowLen; CString sText; pEdt->GetWindowText(sText); m_nArrowLen = _tstof(sText); sText.Format(_T("%.2f"), m_nArrowLen); if (m_nArrowLen <= 0.0 || !StringIsAllNum(sText)) { sText.Format(_T("%.2f"), dText); m_nArrowLen = dText; pEdt->SetWindowText(sText); } else { pEdt->SetWindowText(sText); } }