#include "stdafx.h" class TRegionEdJig : public TSymbEdJig { public: enum RegionOper {kNone=0, kThick=1,}; protected: RegionOper m_nOperCode; XPoly2D m_polyOut; DList m_lstPolyIns; // I/O AcDbHatch *m_pDrawEnt; public: TRegionEdJig(const XRegion &extRegion, const DList &lstAllRegion); ~TRegionEdJig() { if (m_pDrawEnt) delete m_pDrawEnt; } //DragStatus GetPoint(XPoint &pt); protected: virtual Adesk::Boolean update(); virtual AcDbEntity* entity() const { return m_pDrawEnt; } public: void SetOperCode(TRegionEdJig::RegionOper opCode) { m_nOperCode=opCode; } const XPoly2D *GetHitRegion(XPoint pt) const; }; TRegionEdJig::TRegionEdJig(const XRegion &extRegion, const DList &lstAllRegion) :m_pDrawEnt(NULL) { m_ptResult=GetCursorWcs(); m_ptResult.z=0; m_polyOut.SetFlag(1); extRegion.CenterPoly2D(m_polyOut); m_polyOut.SetElevation(0.0); m_polyOut.Compress(); for(int i=0; iSetElevation(0.0); pNew->Compress(); m_lstPolyIns.Append(pNew); if (!m_pDrawEnt && (m_ptResult&(*pNew))==PR_INSIDE) { m_pDrawEnt=NewHatchFromPoly2D(*pNew); } } if (!m_pDrawEnt) m_pDrawEnt=NewHatchFromPoly2D(m_polyOut); } //AcEdJig::DragStatus TComposingEdJig::GetPoint(XPoint &pt) //{ // XPoint ptBase=m_nOperCode==kTextLine? m_pDrawEnt->GetTurnPoint() : m_pDrawEnt->GetStartPoint(); // return acquirePoint(pt, ptBase); //} const XPoly2D *TRegionEdJig::GetHitRegion(XPoint pt) const { pt.z=0; for(int i=0; i: "), ent, RBList(RTDXF0, _T("INSERT"), NULL))==RTNORM) { XPoly2D polyBoundary(1); if (GetBoundaryFromInsert2D(ent, polyBoundary)==RTNORM) { XScreenDc dc; dc.SetColor(1); XPoly2D polyTemp(polyBoundary); polyTemp.TransUCS(Groups(0), Groups(1)); dc << polyTemp; if (YesNoQuestion(_T("\n是否生成pline"))==Q_YES) { polyBoundary.Make(); } } } } /////////////////////////////////////////// // Command: 由二维实体生成轮廓线, 产生pline // bOnElev--TRUE, 用于生成立面轮廓(不封闭) // FALSE, 封闭轮廓 void SearchOutlineArg(BOOL bOnElev) { XPushMemVar vTemp(g_bEchoSearch, TRUE); XPushPrec var(_AS_SYS_UNIT(0.1), 1.0E-5); PickSet ss(SS_FREE); if (SelectEntities(_T("\n选择二维对象:"), ss, RBList(RTDXF0, _T("LINE,ARC,CIRCLE,INSERT,TCH_BLOCK_INSERT,TCH_MVINSERT,POLYLINE,LWPOLYLINE"), NULL))==RTNORM) { DList lstSegs; long lCount=ss.Length(); for(long i=0L; i_DIST_SNAP) lstSegs.Append(new XCurveSegment(seg)); } } } else { XCurveSegment *pSeg=new XCurveSegment(ent); if (!(*pSeg) || pSeg->GetLength()<_DIST_SNAP) { delete pSeg; } else { lstSegs.Append(pSeg); } } } for(i=0; iCenterPoly2D(polyOut); polyOut.Compress(); } else { adsout << _T("\n对不起, 找不出轮廓线!"); return; } //if (GetExternalBoundaryFromCurves(lstSegs, polyOut)==RTNORM) { // polyOut.Compress(); if (polyOut.PathArea()>0.0) polyOut.Reverse(); if (bOnElev) { XPoint ptLow, ptUp; polyOut.GetExtend(ptLow, ptUp); double yMin=ptLow.y; DList lstIdx; for(int k=0; ky; if (fabs(y-yMin)<_DIST_SNAP) lstIdx.Append(new int(k)); } if (lstIdx.Length()==2 && (*lstIdx[0] - *lstIdx[1])==-1) { XPoint pt1=*polyOut[*lstIdx[0]]; XPoint pt2=*polyOut[*lstIdx[1]]; XPoly2D poly1, poly2; if (SplitPoly2D(polyOut, pt1, pt2, poly1, poly2)==RTNORM) { polyOut=poly2; } } } if (bOnElev) { XScreenDc dc(1, 3); XPoly2D polyTemp(polyOut); polyTemp.TransUCS(Groups(0), Groups(1)); dc << polyTemp; static double nThick=0.0; int nRetCode=RTNORM; ads_initget(RSG_NONEG|RSG_NOZERO, NULL); adsout << _T("\n请输入轮廓线宽度(按模型空间的尺寸)<") << nThick << _T(">: "); nRetCode=ads_getreal(_T(""), &nThick); if (nRetCode==RTNORM || nRetCode==RTNONE) { AcDbPolyline *pline=new AcDbPolyline; PolyConvert(polyOut, *pline); pline->setConstantWidth(nThick); AddToModelSpace(pline, Adesk::kTrue); adsout << _T("\n成功的生成了轮廓线!"); } } else { XPushVar vFillMode(_T("FILLMODE"), 1); XPushVar vOsMode(_T("OSMODE"),0);//add by whl on 060305 TRegionEdJig jig(*pExt, aSearch.m_regions); jig.SetPrompt(_T("\n点取要生成的轮廓(提示:点取外部生成外轮廓; PLINEWID 系统变量设置pline宽度)<退出>:")); while(jig.DoIt()==RTNORM) { const XPoly2D *pRegion=jig.GetHitRegion(jig.GetPickPoint()); AcDbPolyline *pline=new AcDbPolyline; PolyConvert(*pRegion, *pline); double nThick=0.0; xg_getvar(_T("PLINEWID"), &nThick); pline->setConstantWidth(nThick); AcDbObjectId id=AddToModelSpace(pline, Adesk::kTrue); if (id.isValid()) { adsout << _T("\n成功生成轮廓,接着点取生成其他轮廓!"); } else { delete pline; } } /* INITGET_BEG(RSG_NONEG|RSG_NOZERO, _T("S")); adsout << _T("\n请输入轮廓线宽度(按模型空间的尺寸)或 {选择内轮廓[S]}<") << nThick << _T(">: "); nRetCode=ads_getreal(_T(""), &nThick); INITGET_END(); if (nRetCode==RTNORM || nRetCode==RTNONE) { AcDbPolyline *pline=new AcDbPolyline; PolyConvert(polyOut, *pline); pline->setConstantWidth(nThick); AddToModelSpace(pline, Adesk::kTrue); adsout << _T("\n成功的生成了轮廓线!"); } else if (nRetCode==RTKWORD) { }*/ } } } void SearchOutline() { SearchOutlineArg(FALSE); } void ElevOutline() { SearchOutlineArg(TRUE); } /////////////////////////////////////////// // Command: 由二维实体生成轮廓线, 产生pline void GenBoundary() { XPushMemVar vTemp(g_bEchoSearch, TRUE); PickSet ss(SS_FREE); if (SelectEntities(_T("\n选择二维对象:"), ss, RBList(RTDXF0, _T("LINE,ARC,CIRCLE,INSERT,TCH_BLOCK_INSERT,TCH_MVINSERT,POLYLINE,LWPOLYLINE"), NULL))==RTNORM) { DList lstSegs; long lCount=ss.Length(); for(long i=0L; i_DIST_SNAP) lstSegs.Append(new XCurveSegment(seg)); } } } else { XCurveSegment *pSeg=new XCurveSegment(ent); if (!(*pSeg) || pSeg->GetLength()<_DIST_SNAP) { delete pSeg; } else { lstSegs.Append(pSeg); } } } DList lstPolyBoundary(1); if (GetExternalBoundaryFromCurves(lstSegs, lstPolyBoundary)==RTNORM && lstPolyBoundary.Length()) { for(int k=0; k