270 lines
8.4 KiB
C++
270 lines
8.4 KiB
C++
#include "stdafx.h"
|
|
|
|
//#include "arxtools.h"
|
|
//#include "DcStream.h"
|
|
|
|
#include "EdJigEx.h"
|
|
#include "tapi.h"
|
|
#include "teldef.h"
|
|
|
|
class TPolyEdJig2 : public TSymbEdJig {
|
|
public:
|
|
enum TPolyOper {kNone=0, kLinePoint=1, kArcPoint=2, kArcMidPoint=3, kArcRadius=4};
|
|
protected:
|
|
TPolyOper m_nOperCode;
|
|
// I/O
|
|
AcDbPolyline *m_pDrawEnt;
|
|
public:
|
|
TPolyEdJig2(AcDbPolyline *);
|
|
virtual int DoIt(int *pKeyIndex=NULL);
|
|
DragStatus GetPoint(XPoint &pt);
|
|
protected:
|
|
virtual Adesk::Boolean update();
|
|
virtual AcDbEntity* entity() const;
|
|
public:
|
|
void SetOperCode(TPolyEdJig2::TPolyOper opCode) {
|
|
m_nOperCode=opCode;
|
|
}
|
|
TPolyOper GetOperCode() {
|
|
return m_nOperCode;
|
|
}
|
|
};
|
|
|
|
|
|
TPolyEdJig2::TPolyEdJig2(AcDbPolyline *pElev)
|
|
{
|
|
m_pDrawEnt=pElev;
|
|
}
|
|
|
|
|
|
AcEdJig::DragStatus
|
|
TPolyEdJig2::GetPoint(XPoint &pt)
|
|
{
|
|
AcGePoint3d ptBase;
|
|
m_pDrawEnt->getPointAt(m_pDrawEnt->numVerts()-1, ptBase);
|
|
//if(m_nOperCode!=kArcMidPoint m_nOperCode!=kArcRadius)
|
|
// return acquirePoint(pt);
|
|
return acquirePoint(pt, ptBase);
|
|
}
|
|
|
|
// 开始执行拖动
|
|
int TPolyEdJig2::DoIt(int *keyIndex)
|
|
{
|
|
XPoly2D poly2d;
|
|
PolyConvert(*m_pDrawEnt, poly2d);
|
|
if(m_nOperCode==kLinePoint || m_nOperCode==kArcPoint) {
|
|
m_ptResult=*poly2d.Tail();
|
|
} else if(m_nOperCode==kArcMidPoint) { // MidPoint
|
|
XCurveSegment cv;
|
|
poly2d.Nth(poly2d.TotalSegments()-1, cv);
|
|
m_ptResult=cv.MidPoint();
|
|
}
|
|
|
|
int nRet = TSymbEdJig::DoIt(keyIndex);
|
|
return nRet;
|
|
}
|
|
|
|
|
|
// 更新实体数据
|
|
double g_dWireRadius(0);
|
|
Adesk::Boolean TPolyEdJig2::update()
|
|
{
|
|
Adesk::Boolean bRet=Adesk::kTrue;
|
|
XPoly2D poly2d;
|
|
PolyConvert(*m_pDrawEnt, poly2d);
|
|
if(m_nOperCode==kLinePoint || m_nOperCode==kArcPoint) {
|
|
//*poly2d.Tail()=m_ptResult;
|
|
} else if(m_nOperCode==kArcMidPoint) {
|
|
XDirectionCurve cv;
|
|
poly2d.Nth(poly2d.TotalSegments()-1, cv);
|
|
XCurveSegment seg;
|
|
seg = XArc(cv.StartPoint(), m_ptResult, cv.EndPoint());
|
|
if(!!seg) {
|
|
if(seg.StartPoint().Distance(cv.StartPoint())>_distSnap)
|
|
seg.SetBulge(-seg.GetBulge());// 2011-8-9 bsl TELEC8.2之后反向绘制弧线变成直线:seg.SetBulge(seg.GetBulge()-seg.GetBulge());
|
|
// *poly2d.bulges[poly2d.Length()-2]=seg.GetBulge();
|
|
poly2d.SetBulge(poly2d.Length()-2, seg.GetBulge());
|
|
}
|
|
} else if(m_nOperCode==kArcRadius) {
|
|
XPoint ptBase, ptPrev;
|
|
int numVert=m_pDrawEnt->numVerts();
|
|
m_pDrawEnt->getPointAt(numVert-1, (AcGePoint3d &)ptBase);
|
|
m_pDrawEnt->getPointAt(numVert-2, (AcGePoint3d &)ptPrev);
|
|
double nChordLen=ptBase.Distance2d(ptPrev);
|
|
// double nRadius=ptBase.Distance2d(m_ptResult); //axc alter 2013-12-31
|
|
// if(nChordLen<2.0*nRadius+1.0E-6) {
|
|
if(nChordLen<2.0*g_dWireRadius+1.0E-6) {
|
|
//double bulge=2.0*asin(nChordLen/2.0/nRadius);
|
|
double bulge=2.0*asin(nChordLen/2.0/g_dWireRadius);
|
|
if(XLine(ptPrev, ptBase).OnWhichSide(m_ptResult)==OFFSET_LEFT)
|
|
bulge = -bulge;
|
|
//*poly2d.bulges[poly2d.Length()-2]=bulge;
|
|
poly2d.SetBulge(poly2d.Length()-2, bulge);
|
|
}
|
|
}
|
|
PolyConvert(poly2d, *m_pDrawEnt);
|
|
return bRet;
|
|
}
|
|
|
|
AcDbEntity* TPolyEdJig2::entity() const
|
|
{
|
|
|
|
return (AcDbEntity *)m_pDrawEnt;
|
|
}
|
|
|
|
|
|
|
|
int DragInputPoly2d(XPoint ptStart, XPoly2D &poly2dRet)
|
|
{
|
|
AcDbPolyline pline;
|
|
pline.addVertexAt(0, ptStart);
|
|
TPolyEdJig2 jig(&pline);
|
|
jig.SetPrompt(_T("\n直段下一点 [弧段(A)/回退(U)} <结束>: "));
|
|
jig.SetOperCode(TPolyEdJig2::kLinePoint);
|
|
jig.SetKeyword(_T("A U"));
|
|
while(1) {
|
|
int nKeyIndex=0;
|
|
int nRetCode=jig.DoIt(&nKeyIndex);
|
|
if(nRetCode==RTNORM) {
|
|
pline.addVertexAt(pline.numVerts(), (AcGePoint2d &)jig.GetPickPoint());
|
|
if(jig.GetOperCode()==TPolyEdJig2::kArcPoint) {
|
|
TPolyEdJig2 jig1(&pline);
|
|
jig1.SetOperCode(TPolyEdJig2::kArcMidPoint);
|
|
jig1.SetPrompt(_T("\n点取弧上一点 [输入半径(R)]:"));
|
|
jig1.SetKeyword(_T("R"));
|
|
int nKeyIdx;
|
|
int nRetCode1=jig1.DoIt(&nKeyIdx);
|
|
if(nRetCode1==RTKWORD) {
|
|
TPolyEdJig2 jig2(&pline);
|
|
jig2.SetOperCode(TPolyEdJig2::kArcRadius);
|
|
//jig2.SetPrompt(_T("\n输入半径(光标位置确定弧的方向):"));
|
|
//axc add 2013-12-31解決弧形导线输入半径无法设置问题
|
|
CString sPrompt;
|
|
AcGePoint2d ptS,ptE;
|
|
pline.getPointAt(pline.numVerts()-2,ptS);
|
|
pline.getPointAt(pline.numVerts()-1,ptE);
|
|
double dLen = fabs(ptS.distanceTo(ptE));
|
|
sPrompt.Format(_T("\n输入半径<%.2f>:"),dLen/2);
|
|
do
|
|
{
|
|
int ret2 = ads_getdist(NULL, sPrompt, &g_dWireRadius);
|
|
if (RTNORM != ret2)
|
|
return -1;
|
|
|
|
if (dLen > 2*g_dWireRadius)
|
|
ads_prompt(_T("\n输入的半径小于弧形两点距离的一半无法构成导线!\n"));
|
|
else
|
|
break;
|
|
} while (TRUE);
|
|
//end
|
|
jig2.DoIt();
|
|
}
|
|
} else { //直段
|
|
jig.SetPrompt(_T("\n直段下一点 [弧段(A)/回退(U)] <结束>: "));
|
|
jig.SetOperCode(TPolyEdJig2::kLinePoint);
|
|
jig.SetKeyword(_T("A U"));
|
|
}
|
|
} else if(nRetCode==RTKWORD) {
|
|
if(jig.GetOperCode()==TPolyEdJig2::kLinePoint) {
|
|
if(nKeyIndex==0) {
|
|
jig.SetOperCode(TPolyEdJig2::kArcPoint);
|
|
jig.SetPrompt(_T("\n弧段下一点 [直段(L)/回退(U)] <结束>: "));
|
|
jig.SetKeyword(_T("L U"));
|
|
} else if(nKeyIndex==1) {
|
|
int numVert=pline.numVerts();
|
|
if(numVert>1) {
|
|
pline.removeVertexAt(numVert-1);
|
|
pline.setBulgeAt(numVert-2, 0.0);
|
|
}
|
|
}
|
|
} else if(jig.GetOperCode()==TPolyEdJig2::kArcPoint) {
|
|
if(nKeyIndex==0) {
|
|
jig.SetOperCode(TPolyEdJig2::kLinePoint);
|
|
jig.SetPrompt(_T("\n直段下一点 [弧段(A)/回退(U)] <结束>: "));
|
|
jig.SetKeyword(_T("A U"));
|
|
} else if(nKeyIndex==1) {
|
|
int numVert=pline.numVerts();
|
|
if(numVert>1) {
|
|
pline.removeVertexAt(numVert-1);
|
|
pline.setBulgeAt(numVert-2, 0.0);
|
|
}
|
|
}
|
|
}
|
|
} else if(nRetCode==RTNONE) {
|
|
break;
|
|
} else if(nRetCode==RTCAN) {
|
|
return RTERROR;
|
|
}
|
|
}
|
|
|
|
int numVert=pline.numVerts();
|
|
if(numVert<2)
|
|
return RTERROR;
|
|
PolyConvert(pline, poly2dRet);
|
|
return RTNORM;
|
|
}
|
|
|
|
// 输入多段线
|
|
int GetOpenPoly2D(const TCHAR *pMsg, XPoly2D &poly2d)
|
|
{
|
|
XString szPrompt;
|
|
if(pMsg)
|
|
szPrompt << pMsg;
|
|
else szPrompt << _T("\n曲线起点");
|
|
szPrompt << _T("或 [点取图中曲线(P)/点取参考点(R)]<退出>:");
|
|
XPoint ptStart;
|
|
|
|
int nCode;
|
|
INITGET_BEG(0, _T("P R"));
|
|
nCode=ads_getpoint(NULL, szPrompt, ptStart);
|
|
INITGET_END();
|
|
if(nCode==RTKWORD) {
|
|
XString sKeyword;
|
|
VERIFY(ads_getinput(sKeyword)==RTNORM);
|
|
if(sKeyword[0]==_T('R')) {
|
|
XPoint ptRef;
|
|
if(ads_getpoint(NULL, _T("\n输入参考点<退出>:"), ptRef)!=RTNORM)
|
|
return RTERROR;
|
|
if(ads_getpoint(ptRef, _T("\n曲线起点<退出>:"), ptStart)!=RTNORM)
|
|
return RTERROR;
|
|
ptStart=Ucs2Wcs(ptStart);
|
|
nCode=DragInputPoly2d(ptStart, poly2d);
|
|
} else {
|
|
RBList mask(RTDXF0, _T("POLYLINE,LWPOLYLINE,LINE,ARC"), NULL);
|
|
Entity ent;
|
|
LAB_RESELECT:
|
|
if((nCode=ent.FilterSelect(_T("\n选择一曲线(LINE/ARC/PLINE):"), mask))!=RTNORM)
|
|
return RTERROR;
|
|
if(ent.Is(_T("LINE")) || ent.Is(_T("ARC"))) {
|
|
XCurveSegment cv(ent);
|
|
poly2d.Reset();
|
|
cv.AsPoly2D(poly2d);
|
|
} else {
|
|
XPoly2D poly(ent);
|
|
if(!!poly) {
|
|
poly2d=poly;
|
|
} else {
|
|
adsout << _T("\n无效的选择!");
|
|
goto LAB_RESELECT;
|
|
}
|
|
}
|
|
}
|
|
} else if(nCode==RTNORM) {
|
|
ptStart=Ucs2Wcs(ptStart);
|
|
nCode=DragInputPoly2d(ptStart, poly2d);
|
|
} else { //
|
|
return nCode;
|
|
}
|
|
|
|
return nCode;
|
|
}
|
|
|
|
|
|
void TestPolyInput()
|
|
{
|
|
XPoly2D poly2d;
|
|
if(GetOpenPoly2D(NULL, poly2d)==RTNORM) {
|
|
XScreenDc dc(1);
|
|
dc << poly2d;
|
|
}
|
|
} |