368 lines
8.2 KiB
C++
368 lines
8.2 KiB
C++
#include "stdafx.h"
|
|
#include "TRoadGradeArrowJig.h"
|
|
|
|
extern void GetArrowPolyLineByParam(AcGePoint3d &ptCenter, AcGeVector2d &vecDirction, double dArrowLenth, XPoly2D &poly2d);
|
|
|
|
TRoadGradeArrowJig::TRoadGradeArrowJig(XPoly2D poly2d, XPoint ptPosition, TDbSymbArrow* pSymblArrow, int nArrowLength, bool bRotation, bool bDynamic)
|
|
{
|
|
m_poly2d = poly2d;
|
|
m_Position[0] = ptPosition.x;
|
|
m_Position[1] = ptPosition.y;
|
|
m_Position[2] = ptPosition.z;
|
|
|
|
if (!pSymblArrow)
|
|
{
|
|
m_pEntSymbArrowEnt = new TDbSymbArrow();
|
|
}
|
|
m_pEntSymbArrowEnt = pSymblArrow;
|
|
m_dAngle = 0;
|
|
m_nArrowLength = nArrowLength;
|
|
m_bRotation = bRotation;
|
|
m_bDynamic = bDynamic;
|
|
}
|
|
|
|
TRoadGradeArrowJig::~TRoadGradeArrowJig()
|
|
{
|
|
}
|
|
|
|
void TRoadGradeArrowJig::SetPrompt(const TCHAR *m_pTemp)
|
|
{
|
|
m_pszPrompt = m_pTemp;
|
|
acutPrintf(m_pTemp);
|
|
}
|
|
int TRoadGradeArrowJig::GetRetCode() const
|
|
{
|
|
int ret = m_nRetCode;
|
|
if (ret == AcEdJig::kCancel)
|
|
ret = RTCAN;
|
|
else if (ret == AcEdJig::kNull)
|
|
ret = RTNONE;
|
|
else if (ret == AcEdJig::kNormal)
|
|
ret = RTNORM;
|
|
else
|
|
{
|
|
ret = RTKWORD;
|
|
}
|
|
return ret;
|
|
}
|
|
int TRoadGradeArrowJig::doIt()
|
|
{
|
|
m_nRetCode = drag();
|
|
int nRet = GetRetCode();
|
|
return nRet;
|
|
}
|
|
|
|
Adesk::Boolean TRoadGradeArrowJig::update()
|
|
{
|
|
int nLen = m_poly2d.Length() - 1;
|
|
if (nLen > 0)
|
|
{
|
|
TADSGePoint3d ptProjectStart;
|
|
TGGeDirectionCurve cvDirectionCurve;//方向
|
|
m_poly2d.Nth(0, cvDirectionCurve);
|
|
|
|
double dMindis = 0;
|
|
cvDirectionCurve.ProjectToMe(m_ptPoint, ptProjectStart);//使用WCS计算
|
|
if (!m_poly2d.HitTestOnCurve(ptProjectStart))//当前投影点不在当前多段线上
|
|
{
|
|
dMindis = 1.7976931348623158e+308;
|
|
}
|
|
else
|
|
dMindis = abs(ptProjectStart.Distance(m_ptPoint));//当前点到投影点的距离
|
|
|
|
if (m_ptPoint != ptProjectStart)
|
|
{
|
|
for (int i = 1; i < nLen; ++i)
|
|
{
|
|
double dMinTemp = 0;
|
|
TGGeDirectionCurve cvCurveTemp;
|
|
TADSGePoint3d ptProjectTemp;
|
|
m_poly2d.Nth(i, cvCurveTemp);
|
|
if (0 == cvCurveTemp.ProjectToMe(m_ptPoint, ptProjectTemp))
|
|
break;
|
|
if (!m_poly2d.HitTestOnCurve(ptProjectTemp))
|
|
{
|
|
dMinTemp = 1.7976931348623158e+308;
|
|
}
|
|
else
|
|
dMinTemp = abs(ptProjectTemp.Distance(m_ptPoint));
|
|
if(dMinTemp < dMindis)
|
|
{
|
|
ptProjectStart = ptProjectTemp;
|
|
cvDirectionCurve = cvCurveTemp;
|
|
dMindis = abs(ptProjectTemp.Distance(m_ptPoint));
|
|
}
|
|
}
|
|
}
|
|
double dDirction = cvDirectionCurve.Direction(ptProjectStart);
|
|
if (cvDirectionCurve.m_dBulge < -1.0E-8)
|
|
dDirction = PI - dDirction;
|
|
m_dAngle =dDirction;
|
|
}
|
|
AcGeVector2d vecDirction(1,0);
|
|
if (m_bDynamic)
|
|
vecDirction = Ucs2Wcs(-AcGeVector2d::kXAxis, TRUE);
|
|
AcGeMatrix2d mat;
|
|
mat.setToRotation(m_dAngle);
|
|
vecDirction.transformBy(mat);
|
|
|
|
XPoly2D poly2d;
|
|
GetArrowPolyLineByParam(m_Position, vecDirction, m_nArrowLength, poly2d);
|
|
m_pEntSymbArrowEnt->SetPoly2D(poly2d);
|
|
m_pEntSymbArrowEnt->SetTextLocation(m_pEntSymbArrowEnt->GetDefaultTextLocation());
|
|
m_pEntSymbArrowEnt->SetText2Location(m_pEntSymbArrowEnt->GetDefaultText2Location());
|
|
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
void TRoadGradeArrowJig::SetAngle(double dAngle)
|
|
{
|
|
m_dAngle = dAngle;
|
|
update();
|
|
}
|
|
double TRoadGradeArrowJig::GetAngle()
|
|
{
|
|
return m_dAngle;
|
|
}
|
|
|
|
AcEdJig::DragStatus TRoadGradeArrowJig::sampler()
|
|
{
|
|
DragStatus stat;
|
|
setUserInputControls((UserInputControls)
|
|
(AcEdJig::kNullResponseAccepted));
|
|
if (m_bRotation)
|
|
{
|
|
DragStatus res = acquireAngle(m_dAngle, m_Position);
|
|
if (res == kNormal)
|
|
{
|
|
static double temp;
|
|
if (fabs(m_dAngle - temp) > 1e-6)
|
|
temp = m_dAngle;
|
|
else
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
return res;
|
|
}
|
|
else
|
|
{
|
|
stat = acquirePoint(m_point);
|
|
m_ptPoint = XPoint(m_point);
|
|
if (stat==AcEdJig::kNormal)
|
|
{
|
|
static XPoint PointTemp = m_ptPoint;
|
|
m_Position = m_point;
|
|
if (PointTemp==m_ptPoint)
|
|
return AcEdJig::kNoChange;
|
|
else
|
|
PointTemp = m_ptPoint;
|
|
}
|
|
}
|
|
return stat;
|
|
}
|
|
|
|
AcDbEntity* TRoadGradeArrowJig::entity() const
|
|
{
|
|
return (AcDbEntity *)(m_pEntSymbArrowEnt);
|
|
}
|
|
|
|
TDbSymbArrow* TRoadGradeArrowJig::GetSymbArrow()
|
|
{
|
|
return m_pEntSymbArrowEnt;
|
|
}
|
|
|
|
TRoadElevJig::TRoadElevJig(XPoly2D poly2d, TDbSymbElevation* pSymblElev, bool bOneElev , bool bSelectBaseline)
|
|
{
|
|
m_poly2d = poly2d;
|
|
|
|
if (!pSymblElev)
|
|
{
|
|
m_pEntSymbElevEnt = new TDbSymbElevation();
|
|
}
|
|
m_pEntSymbElevEnt = pSymblElev;
|
|
m_dAngle = 0;
|
|
m_bSelect = bSelectBaseline;
|
|
m_bOneElev = bOneElev;
|
|
}
|
|
|
|
void TRoadElevJig::SetPrompt(const TCHAR *m_pTemp)
|
|
{
|
|
m_pszPrompt = m_pTemp;
|
|
acutPrintf(m_pTemp);
|
|
}
|
|
|
|
int TRoadElevJig::doIt(int *keyIndex)
|
|
{
|
|
int nRetCode=0;
|
|
acedGetAcadDwgView()->SetFocus(); //屏幕菜单点取时, 命令焦点没有在图形窗口
|
|
if (m_sKeyword) {
|
|
INITGET_BEG(-1, m_sKeyword);
|
|
try {
|
|
nRetCode = drag();
|
|
} catch(...) {
|
|
nRetCode=AcEdJig::kCancel;
|
|
}
|
|
INITGET_END();
|
|
} else {
|
|
try {
|
|
nRetCode = drag();
|
|
} catch(...) {
|
|
nRetCode=AcEdJig::kCancel;
|
|
}
|
|
}
|
|
m_nRetCode = nRetCode;
|
|
return GetRetCode();
|
|
}
|
|
|
|
TDbSymbElevation* TRoadElevJig::GetSymbElev()
|
|
{
|
|
return m_pEntSymbElevEnt;
|
|
}
|
|
|
|
AcEdJig::DragStatus TRoadElevJig::sampler()
|
|
{
|
|
DragStatus stat;
|
|
setUserInputControls((UserInputControls)
|
|
(AcEdJig::kNullResponseAccepted));
|
|
if (!!m_sKeyword) setKeywordList(m_sKeyword);
|
|
else setKeywordList(NULL);
|
|
|
|
stat = acquirePoint(m_point);
|
|
m_ptPoint = XPoint(m_point);
|
|
if (stat == AcEdJig::kNormal)
|
|
{
|
|
static XPoint PointTemp = m_ptPoint;
|
|
if (PointTemp == m_ptPoint)
|
|
return AcEdJig::kNoChange;
|
|
else
|
|
PointTemp = m_ptPoint;
|
|
}
|
|
return stat;
|
|
}
|
|
|
|
Adesk::Boolean TRoadElevJig::update()
|
|
{
|
|
if (m_bOneElev)//只有一个标高值
|
|
{
|
|
m_pEntSymbElevEnt->SetLocation(m_ptPoint);
|
|
//计算数值
|
|
return Adesk::kTrue;;
|
|
}
|
|
|
|
int nLen = m_poly2d.Length() - 1;
|
|
|
|
if (nLen > 0)
|
|
{
|
|
XPoint ptPolyStart, ptPolyEnd;
|
|
TGGeDirectionCurve cvCurve;
|
|
m_poly2d.Nth(0, cvCurve); //整个曲段的起点
|
|
ptPolyStart = cvCurve.GetStartPoint();
|
|
m_poly2d.Nth(nLen - 1, cvCurve);
|
|
ptPolyEnd = cvCurve.GetStartPoint(); //整个曲段的终点
|
|
|
|
CRoadElevStyle road;
|
|
TADSGePoint3d ptProjectPoint;//投影点
|
|
TGGeDirectionCurve cvDirectionCurve;
|
|
m_poly2d.Nth(0, cvDirectionCurve);
|
|
double dMindis = 0;
|
|
cvDirectionCurve.ProjectToMe(m_point, ptProjectPoint);
|
|
if (!m_poly2d.HitTestOnCurve(ptProjectPoint))//当前投影点不在当前多段线上
|
|
dMindis = 1.7976931348623158e+308;//最大值
|
|
else
|
|
dMindis = abs(ptProjectPoint.Distance(m_point));//当前点到投影点的距离
|
|
|
|
if (m_point != ptProjectPoint)
|
|
{
|
|
for (int i = 1; i < nLen; ++i)
|
|
{
|
|
double dMinTemp = 0;
|
|
TGGeDirectionCurve cvCurveTemp;
|
|
TADSGePoint3d ptProjectTemp;
|
|
m_poly2d.Nth(i, cvCurveTemp);
|
|
if (0 == cvCurveTemp.ProjectToMe(m_point, ptProjectTemp))
|
|
break;
|
|
if (!m_poly2d.HitTestOnCurve(ptProjectTemp))
|
|
{
|
|
dMinTemp = 1.7976931348623158e+308;
|
|
if (abs(ptProjectTemp.Distance(ptPolyStart)) < abs(ptProjectTemp.Distance(ptPolyEnd)))
|
|
{
|
|
m_poly2d.Nth(0, cvCurveTemp);
|
|
cvCurveTemp.ProjectToMe(m_point, ptProjectTemp);
|
|
dMinTemp = abs(ptProjectTemp.Distance(m_point));
|
|
}
|
|
else
|
|
{
|
|
m_poly2d.Nth(nLen - 1, cvCurveTemp);
|
|
cvCurveTemp.ProjectToMe(m_point, ptProjectTemp);
|
|
dMinTemp = abs(ptProjectTemp.Distance(m_point));
|
|
}
|
|
}
|
|
else
|
|
dMinTemp = abs(ptProjectTemp.Distance(m_point));
|
|
if (dMinTemp < dMindis)
|
|
{
|
|
ptProjectPoint = ptProjectTemp;
|
|
cvDirectionCurve = cvCurveTemp;
|
|
dMindis = abs(ptProjectTemp.Distance(m_point));
|
|
}
|
|
}
|
|
}
|
|
if (!m_bSelect)
|
|
{
|
|
for (int j = 0; j < nLen; ++j)
|
|
{
|
|
TGGeDirectionCurve cvCurveTemp;
|
|
m_poly2d.Nth(j, cvCurveTemp);
|
|
m_pEntSymbElevEnt->SetLocation(ptProjectPoint);
|
|
m_pEntSymbElevEnt->SetText(road.CalcElevData(m_poly2d, ptProjectPoint));
|
|
}
|
|
}
|
|
else//选择基线
|
|
{
|
|
for (int j = 0; j < nLen; ++j)
|
|
{
|
|
TGGeDirectionCurve cvCurveTemp;
|
|
|
|
m_poly2d.Nth(j, cvCurveTemp);
|
|
if (m_poly2d.HitTestOnCurve(ptProjectPoint))//0在不曲段上,非0在曲段上,排除投影点不在曲段上的情况
|
|
{
|
|
m_pEntSymbElevEnt->SetLocation(ptProjectPoint);
|
|
m_pEntSymbElevEnt->SetText(road.CalcElevData(m_poly2d, ptProjectPoint));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
TRoadElevJig::~TRoadElevJig()
|
|
{
|
|
|
|
}
|
|
|
|
AcDbEntity* TRoadElevJig::entity() const
|
|
{
|
|
return (AcDbEntity *)(m_pEntSymbElevEnt);
|
|
}
|
|
|
|
int TRoadElevJig::GetRetCode() const
|
|
{
|
|
int ret = m_nRetCode;
|
|
if (ret == AcEdJig::kCancel)
|
|
ret = RTCAN;
|
|
else if (ret == AcEdJig::kNull)
|
|
ret = RTNONE;
|
|
else if (ret == AcEdJig::kNormal)
|
|
ret = RTNORM;
|
|
else
|
|
{
|
|
ret = RTKWORD;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void TRoadElevJig::SetKeyword(const TCHAR *k)
|
|
{
|
|
m_sKeyword = k;
|
|
}
|