#include "stdafx.h" void myHandrail() { // XPushVar vOsMode(_T("OSMODE"), 0); PickSet ss(SS_FREE); g_ssPickFirst.Free(); RBList mask(RTDXF0, _T("TCH_HANDRAIL"), NULL); if (SelectEntities(_T("\n选择待连接的扶手(注意与顶点顺序一致): "), ss, mask)!=RTNORM) return; AcDbObjectId idHandRail; Entity ent; XPoint myPoint; XPointList myPointList; Adesk::UInt8 myAlignment=1; XPoly2D myPolyPath; long lCount=ss.Length(); for(long i=0L; iGetPathPoly(polyPath,normal); myAlignment=pHandRail->GetAlignment(); OPENOBJ_END(); /* long l=polyPath.Length(); XPoint firstPt=*polyPath[0L], lastPt=*polyPath[l-1]; if (firstPt[2] < lastPt[2]) for (long j=0L; j=0L; j--) { myPoint=*polyPath[j]; myPointList.NewAppend(myPoint); }*/ if (!myPolyPath) myPolyPath=polyPath; else { if (myPolyPath.Tail()->Distance(*polyPath.Head())>myPolyPath.Tail()->Distance(*polyPath.Tail())) polyPath.Reverse(); for(int kk=0; kkSetPathPoly(myPolyPath); //pHandRail->SetAlignment(myAlignment); //pHandRail->AddToMSpace(Adesk::kTrue); Entity eFirst=ss[0L]; OPENOBJ_BEGIN(eFirst, AcDb::kForWrite, TDbHandRail, pHand); if (pHand) { pHand->SetPathPoly(myPolyPath,pHand->GetNormal().AsAcGeVector3d()); } OPENOBJ_END(); ss -= eFirst; ss.Erase(); } void myStair() { // XPushVar vOsMode(_T("OSMODE"), 512); Entity ent; XPoint pickPt; RBList mask(RTDXF0, _T("TCH_LINESTAIR,TCH_ARCSTAIR,TCH_CURVESTAIR"), NULL); if (SelectEntity(_T("\n选择梯段: "), ent, pickPt, mask)!=RTNORM) return; pickPt=Ucs2Wcs(pickPt); AcDbObjectId id; acdbGetObjectId(id, ent); AcDbEntity *pEnt=NULL; acdbOpenObject(pEnt, id, AcDb::kForRead); // pEnt->highlight(kNullSubent); TDbStair *pStair; pStair=TDbStair::cast(pEnt); if (!pStair) { pEnt->close(); return; } XDirectionCurve mySide1,mySide2; XCurveSegment myCurve1,myCurve2; mySide1=pStair->GetSideCurve2d(0); myCurve1=mySide1.GetCurve(); mySide2=pStair->GetSideCurve2d(1); myCurve2=mySide2.GetCurve(); XPoint myPt1,myPt2; myCurve1.ProjectToMe(pickPt,myPt1); myCurve2.ProjectToMe(pickPt,myPt2); XPoly2D myPolyPath; Adesk::UInt8 myAlignment; XDirectionCurve cv; if (myPt1.Distance2d(pickPt) < myPt2.Distance2d(pickPt)) { //mySide1.AsPoly2D(myPolyPath); myAlignment=1; cv=mySide1; } else { //mySide2.AsPoly2D(myPolyPath); myAlignment=2; cv=mySide2; } XPoint ptStart=cv.StartPoint(); ptStart.z=pStair->GetElevation(); XPoint ptEnd=cv.EndPoint(); ptEnd.z=pStair->GetElevation()+pStair->GetStairHeight(); TDbHandRail *pHandRail = new TDbHandRail; pHandRail->SetAlignment(myAlignment); int nFlag2d=pStair->Get2DFlag(); if (nFlag2d==SF_NO2D) pHandRail->SetHas2D(FALSE); else pHandRail->SetHas2D(TRUE); int nFlag3d=pStair->Get3DFlag(); if (nFlag3d&SF_HAS3D) pHandRail->SetHas3D(TRUE); else pHandRail->SetHas3D(FALSE); double nStepWidth=cv.GetLength()/(pStair->GetStepNum()-1); if (nFlag2d==SF_1SECT) { XPointDir2d ptDir; cv.Polar(nStepWidth/2, ptDir); ptStart=XPoint(ptDir.x, ptDir.y, ptStart.z+pStair->GetStepHeight()); } else { XPointDir2d ptDir; cv.Polar(-nStepWidth/2, ptDir); ptStart=XPoint(ptDir.x, ptDir.y, ptStart.z); } { XPointDir2d ptDir; cv.Polar(-nStepWidth/2, ptDir, FALSE); ptEnd=XPoint(ptDir.x, ptDir.y, ptEnd.z); } pStair->close(); //*myPolyPath.Head()=ptStart; //*myPolyPath.Tail()=ptEnd; cv.SetPoints(ptStart, ptEnd); cv.AsPoly2D(myPolyPath); myPolyPath.Head()->z=ptStart.z; myPolyPath.Tail()->z=ptEnd.z; pHandRail->SetPathPoly(myPolyPath,pHandRail->GetNormal().AsAcGeVector3d()); pHandRail->AddToMSpace(Adesk::kTrue); PickSet ss(SS_FREE); ss += ent; UpdateGraphic(ss); } enum myFlag { kRectangle=1, // Rectangle kCircle=2, // Circle }; static myFlag g_typ; static XPoint g_pt; static double g_nRot; static XPoly2D g_poly; static void GetPoly(myFlag typ, const XPoint &pt1, const XPoint &pt2, XPoly2D &poly) { poly.Reset(); poly.SetFlag(1); switch (typ) { case kRectangle: { XPoint p1, p2; XLine lnSide1(pt1, g_nRot); XLine lnSide2(pt2, g_nRot+PI/2.0); lnSide1.Intersection(&lnSide2, p1); XLine lnSide3(pt1, g_nRot+PI/2.0); XLine lnSide4(pt2, g_nRot); lnSide3.Intersection(&lnSide4, p2); poly.AppendNode(pt1); poly.AppendNode(p1); poly.AppendNode(pt2); poly.AppendNode(p2); } break; case kCircle: { XCurveSegment seg; seg=XCircle(pt1, pt1.Distance(pt2)); seg.AsPoly2D(poly); } break; } } static BOOL myMouseMoveMonitor(MSG* msg) { if (!acdbCurDwg()) return FALSE; BOOL bRet=FALSE; switch(msg->message) { case WM_MOUSEMOVE: { CPoint ptClient=msg->pt; acedGetAcadDwgView()->ScreenToClient(&ptClient); int nVpNum=acedGetWinNum(ptClient.x, ptClient.y); int nCurVp=0; VERIFY(xg_getvar(_T("CVPORT"), &nCurVp)==RTNORM); if (nVpNum==nCurVp) { XPoint ptDwgWcs, ptDwgDcs; BOOL nRetCode=TRUE; if (acedCoordFromPixelToWorld(nVpNum, ptClient, ptDwgWcs)) { XScreenDc dc(-1); if (g_poly.Length()) dc << g_poly; XPoint ptDwgUcs=Wcs2Ucs(ptDwgWcs); ptDwgUcs.z=g_pt.z; GetPoly(g_typ, g_pt, ptDwgUcs, g_poly); dc << g_poly; } } } break; default: break; } return bRet; } int XGetPoints(const XPoint &pt1, const TCHAR *pszMsg, myFlag typ, XPoint &pt2) { if (pszMsg) adsout << pszMsg; g_poly.Reset(); g_poly.SetFlag(1); g_typ=typ; g_nRot=0.0; g_pt=pt1; acedRegisterFilterWinMsg(myMouseMoveMonitor); int nRet=ads_getpoint(NULL, _T(""), pt2); acedRemoveFilterWinMsg(myMouseMoveMonitor); g_poly.Reset(); ads_redraw(NULL,0); return nRet; } int myGetClipBoundary1(XPoly2D &poly2d) { XPoint ptStart; adsout << _T("\n矩形的第一个角点或 [圆形裁剪(C)/多边形裁剪(P)/多段线定边界(L)/图块定边界(B)]<退出>:"); int nCode; INITGET_BEG(0, _T("C P L B")); nCode=ads_getpoint(NULL, _T(""), ptStart); INITGET_END(); if (nCode!=RTKWORD && nCode!=RTNORM) return nCode; XScreenDc dc; dc.m_nDrawMode=1; if (nCode==RTNORM) { XPoint ptOther; int nCode=XGetPoints(ptStart, _T("\n另一个角点<退出>:"), kRectangle, ptOther); if (nCode!=RTNORM) return nCode; XRectAngle rect(ptStart, ptOther); rect.AsPoly2D(poly2d); dc << poly2d; } else { nCode=RTNORM; XString sKey; ads_getinput(sKey); if (sKey[0]==_T('C')) { int nCode=ads_getpoint(NULL, _T("\n圆心点<退出>:"), ptStart); if (nCode!=RTNORM) return nCode; XPoint ptOther; nCode=XGetPoints(ptStart, _T("\n半径点<退出>:"), kCircle, ptOther); if (nCode!=RTNORM) return nCode; XCurveSegment seg; seg=XCircle(ptStart, ptStart.Distance(ptOther)); seg.AsPoly2D(poly2d); dc << poly2d; } else if (sKey[0]==_T('P')) { if (ads_getpoint(NULL, _T("\n多边形起点<退出>:"), ptStart)!=RTNORM) return RTERROR; XPoint pt2; DStack aStack; aStack.Push(new XPoint(ptStart)); while(1) { XPoint &ptFrom=*aStack.Top(); if (aStack.Length()>=3) adsout << _T("\n下一点或 [回退(U)]<封闭>: "); else adsout << _T("\n下一点或 [回退(U)]<退出>: "); int rc; INITGET_BEG(0, _T("U")); rc=ads_getpoint(ptFrom, _T(""), pt2); INITGET_END(); if (rc==RTCAN) { aStack.Reset(); return rc; } else if (rc==RTKWORD) { if (*aStack.Top() != ptStart) {// Not on first state XPoint *pPt2 = aStack.Pop(); XPoint *pPt1 = aStack.Top(); dc.SetColor(-1); dc << XLine(*pPt1, *pPt2); delete pPt2; } } else { if (rc==RTNONE) { if (aStack.Length()<3) return RTERROR; else pt2=ptStart; } XLine ln(*aStack.Top(), pt2); if (ln.GetLength()>_DIST_SNAP) { dc.SetColor(7); dc << ln; if (!(rc==RTNONE)) aStack.Push(new XPoint(pt2)); else break; } } } poly2d.Reset(); XPoint *ptCur=NULL; while((ptCur=aStack.Pop())!=NULL) { poly2d.AppendNode(*ptCur); delete ptCur; } } else if (sKey[0]==_T('L')) { Entity entFront; if (SelectEntity(_T("\n请选择封闭的多段线作为裁剪边界<退出>: "), entFront, RBList(RTDXF0, _T("POLYLINE,LWPOLYLINE"), 70, 1, NULL)) != RTNORM) return RTERROR; poly2d=XPoly2D(entFront); poly2d.TransUCS(Groups(0), Groups(1)); dc << poly2d; } else if (sKey[0]==_T('B')) { Entity entFront; if (SelectEntity(_T("\n请选择图块作为裁剪边界<退出>: "), entFront, RBList(RTDXF0, _T("INSERT,TCH_BLOCK_INSERT,TCH_MVINSERT"), NULL)) != RTNORM) return RTERROR; if (GetBoundaryFromInsert2D(entFront, poly2d)!=RTNORM) { adsout << _T("\n无法搜到图块的边界!"); return RTERROR; } poly2d.TransUCS(Groups(0), Groups(1)); dc << poly2d; int nAnser=YesNoQuestion(_T("\n系统确定的图块轮廓线是否正确")); if (nAnser!=Q_YES) { adsout << _T("\n请用其他方法确定裁剪边界!"); return RTERROR; } } } poly2d.Compress(); if (!poly2d || poly2d.Length()<2) return RTERROR; return RTNORM; } static BOOL myDelete=FALSE; void addHatch(AcDbObjectId hatchId) { XPoly2D poly2d; if (myGetClipBoundary1(poly2d)!=RTNORM) return; if (myDelete) poly2d.Make(); OPENOBJ_BEGIN(hatchId, AcDb::kForWrite, AcDbHatch, pHatch); pHatch->setAssociative(Adesk::kFalse); AcGePoint2dArray vertices; AcGeDoubleArray bulges; int len=poly2d.Length(); vertices.setLogicalLength(len+1); bulges.setLogicalLength(len+1); AcDbPolyline pline(len); PolyConvert(poly2d,pline); AcGePoint3d p; pline.getPointAt(0,p); vertices[0].set(p.x,p.y); vertices[len].set(p.x,p.y); double b; pline.getBulgeAt(0,b); bulges[0]=b; bulges[len]=b; for (int i=1;iappendLoop(AcDbHatch::kOutermost,vertices,bulges); pHatch->evaluateHatch(); OPENOBJ_END(); } void removeHatch(AcDbObjectId hatchId) { XPoint pt; XPushVar vOsMode(_T("OSMODE"), 0); if (acedGetPoint(NULL,_T("\n选取边界区域内的点<退出>: "),pt)!=RTNORM) return; OPENOBJ_BEGIN(hatchId, AcDb::kForWrite, AcDbHatch, pHatch); pHatch->setAssociative(Adesk::kFalse); int num=pHatch->numLoops(); for (int i=0;igetLoopAt(i,typ,vertices,bulges); if (!(typ & AcDbHatch::kExternal)) { int len=vertices.length(); BOOL flag2=bulges.length()>0; XPoly2D boundary; for (int j=0;jremoveLoopAt(i); break; // ZJQ add here } } } pHatch->evaluateHatch(); OPENOBJ_END(); } void myHatch() { Entity ent; RBList mask(RTDXF0, _T("HATCH"), NULL); if (SelectEntity(_T("\n请选择图案填充<退出>: "),ent,mask)!=RTNORM) return; AcDbObjectId hatchId; acdbGetObjectId(hatchId, ent); adsout << _T("\nAdd[A]/Remove[R]<退出>:"); int nCode; XString sKey; INITGET_BEG(0, _T("A R C")); nCode=acedGetKword(NULL, sKey); INITGET_END(); if (nCode!=RTKWORD && nCode!=RTNORM) return; if (sKey[0]==_T('A')) addHatch(hatchId); else if (sKey[0]==_T('R')) removeHatch(hatchId); } void addHatch() { Entity ent; RBList mask(RTDXF0, _T("HATCH"), NULL); if (SelectEntity(_T("\n请选择图案填充<退出>: "),ent,mask)!=RTNORM) return; AcDbObjectId hatchId; acdbGetObjectId(hatchId, ent); addHatch(hatchId); } void removeHatch() { Entity ent; RBList mask(RTDXF0, _T("HATCH"), NULL); if (SelectEntity(_T("\n请选择图案填充<退出>: "),ent,mask)!=RTNORM) return; AcDbObjectId hatchId; acdbGetObjectId(hatchId, ent); removeHatch(hatchId); }