Files
envi-code/SourceCode/Code2026/tg_shs/shs_siteplan/TPlaceTreePreviewJig.cpp
T
2026-09-28 15:28:50 +08:00

247 lines
6.0 KiB
C++

#include "stdafx.h"
#include "TPlaceTreePreviewJig.h"
#include "TchGlobalCurveFunc.h"
#include "GlwGlobalVariable.h"
#include "GlwPlaceTreeDataManage.h"
#include "TGGeCurveSegment.h"
TPlaceTreePreviewJig::TPlaceTreePreviewJig(AcDbPolyline* pLine)
{
m_pPolyLineRef = pLine;
m_bRight = true;
m_pPolyLine = new AcDbPolyline();
m_entPlaceTree = new TDbPlaceTree();
UpdateData();
}
TPlaceTreePreviewJig::~TPlaceTreePreviewJig()
{
if (m_pPolyLine)
delete m_pPolyLine;
if (m_entPlaceTree)
delete m_entPlaceTree;
}
void TPlaceTreePreviewJig::SetPrompt(const TCHAR *m_pTemp)
{
m_pszPrompt = m_pTemp;
acutPrintf(m_pTemp);
}
int TPlaceTreePreviewJig::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 TPlaceTreePreviewJig::doIt()
{
m_nRetCode = drag();
int nRet = GetRetCode();
return nRet;
}
Adesk::Boolean TPlaceTreePreviewJig::update()
{
//实时获取偏移量
UpdateData();
if (m_bRight)
{
TGGePoly2D poly;
PolyConvert(*m_pPolyLineRef, poly);
Offset(m_dOffset, poly);
PolyConvert(poly, *m_pPolyLine);
m_entPlaceTree->SetPolyPath(poly);
}
else
{
TGGePoly2D poly;
PolyConvert(*m_pPolyLineRef, poly);
Offset(-m_dOffset, poly);
PolyConvert(poly, *m_pPolyLine);
m_entPlaceTree->SetPolyPath(poly);
}
return Adesk::kTrue;
}
AcEdJig::DragStatus TPlaceTreePreviewJig::sampler()
{
DragStatus stat;
setUserInputControls((UserInputControls)
(AcEdJig::kNullResponseAccepted));
stat = acquirePoint(m_point);
m_ptPoint=XPoint(m_point);
if (stat==AcEdJig::kNormal)
{
static XPoint PointTemp;
if (PointTemp!=m_ptPoint)
{
PointTemp=m_ptPoint;
//根据输入点,输入polyline判断在哪侧
TGGePoly2D poly2d;
PolyConvert(*m_pPolyLineRef, poly2d);
int nSide = OnWitchSideByPtOnPoly(poly2d, PointTemp);
if (nSide == 0)
m_bRight = false;
else if (nSide == 1)
m_bRight = true;
else
m_bRight = 0;
}
else
return AcEdJig::kNoChange;
}
return stat;
}
AcDbEntity* TPlaceTreePreviewJig::entity() const
{
return (AcDbEntity *)(m_entPlaceTree);
}
AcDbPolyline* TPlaceTreePreviewJig::CloneCurrentSelectPoly()
{
return (AcDbPolyline*)m_pPolyLine->clone();
}
TGGeDirectionCurve TPlaceTreePreviewJig::GetNearestSegByPtOnPoly(XPoly2D poly2d, XPoint point)
{
TGGeCurveSegment cv, cvNearest;
TGGeDirectionCurve cvDirction , cvDirctionNearset;
double dDistMin = 0;
double dDist = 0;
int nSegNum = 0;
nSegNum = poly2d.TotalSegments();
poly2d.Nth(0, cvNearest);
poly2d.Nth(0, cvDirctionNearset);
dDistMin = abs(cvNearest.GetDist2Me(point));
for(int num = 1; num < nSegNum; ++num)
{
poly2d.Nth(num, cv);
poly2d.Nth(num, cvDirction);
dDist = fabs(cv.GetDist2Me(point));
if(dDist < dDistMin)
{
dDistMin = dDist;
cvNearest = cv;
cvDirctionNearset = cvDirction;
}
}
return cvDirctionNearset;
}
int TPlaceTreePreviewJig::OnWitchSideByPtOnPoly(XPoly2D poly2d, XPoint point)
{
TGGeDirectionCurve cvNearset;
cvNearset = GetNearestSegByPtOnPoly(poly2d, point);
return cvNearset.OnWhichSide(point);
}
void TPlaceTreePreviewJig::UpdateData()
{
if(!GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage))
SET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage, new GlwPlaceTreeDataManage);
GlwPlaceTreeDataManage *pDataManage = GET_GLOBAL_VARIABLE(GlwPlaceTreeDataManage);
m_dOffset = pDataManage->GetTreeOffset();
m_entPlaceTree->UpdatePlaceTreeData(pDataManage->GetTreeRad(false),pDataManage->GetTreeDis(),
pDataManage->GetIsSetDis(), pDataManage->GetIsSetRotation(),pDataManage->GetTreeId());
}
TPolyEdTreeJig::TPolyEdTreeJig(AcDbPolyline* pLine):TPolyEdJig(pLine)
{
}
AcEdJig::DragStatus TPolyEdTreeJig::sampler()
{
DragStatus stat;
XPoint ptTemp;
setUserInputControls((UserInputControls)
(AcEdJig::kAccept3dCoordinates | AcEdJig::kNullResponseAccepted
| AcEdJig::kNoNegativeResponseAccepted
| AcEdJig::kNoZeroResponseAccepted));
if (!!m_sKeyword) setKeywordList(m_sKeyword);
else setKeywordList(NULL);
if(m_nOperCode==kLinePoint || m_nOperCode==kArcPoint){
stat=GetPoint(ptTemp);
if(stat == AcEdJig::kNormal) {
if (IsPosChanged(ptTemp)) {
m_ptResult=ptTemp;
} else
return AcEdJig::kNoChange;
}
} else if(m_nOperCode==kArcRadius) { //已知起点终点, 待定半径
double dTemp;
XPoint ptBase;
int numVert=m_pDrawEnt->numVerts();
m_pDrawEnt->getPointAt(numVert-1, (AcGePoint3d &)ptBase);
stat = acquireDist(dTemp, ptBase);
if (fabs(dTemp-m_dRadius)>_DIST_SNAP && dTemp > 0) {
m_dRadius=dTemp;
} else if (stat==AcEdJig::kNormal) {
return AcEdJig::kNoChange;
}
}
return stat;
}
Adesk::Boolean TPolyEdTreeJig::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())>_DIST_SNAP)
seg.SetBulge(-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);
if(nChordLen<2.0*m_dRadius+1.0E-6) {
double bulge=2.0*asin(nChordLen/2.0/m_dRadius);
if(XLine(ptPrev, ptBase).OnWhichSide(m_ptResult)==OFFSET_LEFT)
bulge = -bulge;
poly2d.SetBulge(poly2d.Length()-2, bulge);
}
else
{
return Adesk::kFalse;
}
}
PolyConvert(poly2d, *m_pDrawEnt);
return bRet;
}
void TPolyEdTreeJig::SetRadius(double dRadius)
{
m_dRadius = dRadius;
}
double TPolyEdTreeJig::GetRadius()
{
return m_dRadius;
}
void TPolyEdTreeJig::SetPoly(AcDbPolyline* pLine)
{
m_pDrawEnt = pLine;
}