Files
envi-code/SourceCode/Code2026/SPLDCmd/AcLandFormJig.cpp
T
2026-09-28 15:28:50 +08:00

384 lines
7.1 KiB
C++

#include "stdafx.h"
#include "AcLandFormJig.h"
#include "AecAngleWatch.h"
#include "AECStatusRecord.h"
#include "EarThwormDef.h"
#ifndef WM_ELGETMSG
#define WM_ELGETMSG (WM_USER+0X1001)
#endif
AcLineSegs::AcLineSegs()
{
}
AcLineSegs::~AcLineSegs(void)
{
}
void AcLineSegs::SetLastPoint(const AcGePoint3d& pt)
{
m_ptLast = pt;
}
void AcLineSegs::AddLastPoint(const AcGePoint3d& pt)
{
m_arPoints.append(pt);
}
void AcLineSegs::RemoveLast()
{
if (!m_arPoints.isEmpty())
m_arPoints.removeLast();
}
Acad::ErrorStatus AcLineSegs::Draw2d(AcGiDraw &mode) const
{
AcGePoint3d ptFr,ptTo;
AcGeLineSeg3d ln;
for (int i = 0;i < m_arPoints.length() - 1;i++)
{
ptFr = m_arPoints.at(i);
ptTo = m_arPoints.at(i+1);
ln.set(ptFr,ptTo);
mode.DrawLine(ln);
}
//闭合
if (m_arPoints.length() >= 2)
{
ptFr = m_arPoints.first();
ptTo = m_ptLast;
ln.set(ptFr,ptTo);
mode.DrawLine(ln);
}
return Acad::eOk;
}
AcLandFormJig::AcLandFormJig(void)
{
m_pLineSegs = new AcLineSegs;
m_pCurStaRec = NULL;
m_nUndoGoupid = 0;
m_pElDlg = NULL;
InitStatusRecsForLineSegs();
}
AcLandFormJig::~AcLandFormJig(void)
{
if (m_pLineSegs != NULL)
delete m_pLineSegs;
}
void AcLandFormJig::FreeBuffer()
{
AECStatusRecord* pRec = NULL;
while(!m_arStaPtrs.IsEmpty())
{
pRec = (AECStatusRecord* )m_arStaPtrs.GetAt(0);
m_arStaPtrs.RemoveAt(0);
delete pRec;
}
}
bool AcLandFormJig::DoIt()
{
AcEdJig::DragStatus eStat;
int nPlanPos = 0;
CString sPrompt = _T("");
AcGePoint3d ptGe;
while(TRUE)
{
sPrompt = m_pCurStaRec->Prompt();
setDispPrompt(sPrompt);
eStat = drag();
nPlanPos = m_pCurStaRec->GetPlanPosition();
switch(eStat)
{
case AcEdJig::kNormal:
{
if (nPlanPos == 1 ) //Create line,Arc
{
//设置回退记录
AECStatusRecord* pRec = new AECStatusRecord;
pRec->CopyFrom(m_pCurStaRec);
PushBackStatusRec(pRec);
AcGePoint3d ptGe = m_pCurStaRec->GetAcquirePoint();
if (m_pElDlg != NULL)
m_pElDlg->SendMessage(WM_ELGETMSG,(WPARAM)&ptGe,0);
m_pLineSegs->AddLastPoint(ptGe);
if (m_pCurStaRec->IsCommand2Stop())
{
return true;
}
}
break;
}
case AcEdJig::kCancel:
{
acutPrintf(_T("\n"));
return false;
}
case AcEdJig::kNull:// 退出
{
acutPrintf(_T("\n"));
return true;
}
case AcEdJig::kKW1://圆弧 A 或 W 或 R
{
break;
}
case AcEdJig::kKW2://标高 E 或 W
{
break;
}
case AcEdJig::kKW3://放弃 U
{
if (m_lstStaPtrsBack.GetCount() > 1)
{
SHacedCommand(RTSTR,_T("u"),RTNONE);
PopUpStatusRec();
}
else
{
continue;
}
break;
}
case AcEdJig::kKW4://精度 J
{
break;
}
case AcEdJig::kKW5://宽度
{
//
double dW = 0.0;
if (acedGetReal(_T("\n请输入宽度:"), &dW) == RTNORM)
{
m_pCurStaRec->SetAcquireDouble(dW);
}
break;
}
default:
break;
}
//获取下个状态,plane判断是?
if (m_pCurStaRec->GetPlanPosition() == 0 )
{
AcGePoint3d ptGe = m_pCurStaRec->GetAcquirePoint();
if (m_pElDlg != NULL)
m_pElDlg->SendMessage(WM_ELGETMSG,(WPARAM)&ptGe,0);
m_pLineSegs->AddLastPoint(ptGe);
AECStatusRecord * pRec = new AECStatusRecord;
pRec->CopyFrom(m_pCurStaRec);
pRec->SetUndoGroupId(0);
PushBackStatusRec(pRec);
m_pCurStaRec = m_pCurStaRec->GetNextStatus(m_pCurStaRec->GetPos());
m_pCurStaRec->SetAcquirePoint(ptGe);
}
}
return true;
}
void AcLandFormJig::PopUpStatusRec()
{
//按 id 回退一次,调整当前状态
if (m_lstStaPtrsBack.GetCount() > 0)
{
AECStatusRecord* pLast = (AECStatusRecord*)m_lstStaPtrsBack.GetTail();
int nID = pLast->GetUndoGroupId();
while(m_lstStaPtrsBack.GetCount() > 0)
{
m_lstStaPtrsBack.RemoveTail();
DELETE_PTR(pLast);
pLast = NULL;
if (m_lstStaPtrsBack.GetCount() == 0)
{
break;
}
pLast = (AECStatusRecord*)m_lstStaPtrsBack.GetTail();
if (nID != pLast->GetUndoGroupId())
{
break;
}
}
//roadline 回退一次,调整接口记录
if (m_pLineSegs != NULL)
{
m_pLineSegs->RemoveLast();
}
}
}
void AcLandFormJig::PushBackStatusRec(AECStatusRecord* pRec)
{
pRec->SetUndoGroupId(m_nUndoGoupid);
m_lstStaPtrsBack.AddTail(pRec);
}
void AcLandFormJig::InitStatusRecsForLineSegs()
{
FreeBuffer();
AECStatusRecord* pRec1 = NULL;
pRec1 = new AECStatusRecord;
pRec1->SetPrompt(_T("\n指定起点<退出>:"));
pRec1->SetStatusType(AECStatusRecord::kPoint);
pRec1->SetPlanPosition(0);
m_arStaPtrs.Add(pRec1);
AECStatusRecord* pRec2 = NULL;
pRec2 = new AECStatusRecord;
pRec2->SetPrompt(_T("\n指定下一个点 [放弃(U):"));
pRec2->SetStatusType(AECStatusRecord::kPoint);
pRec2->SetKeywordList(_T("A E U J"));
m_arStaPtrs.Add(pRec2);
pRec1->SetNextStatus(pRec2);
pRec2->SetPlanPosition(1);
pRec2->SetNextStatus(pRec2,1);
m_pCurStaRec = pRec1;
}
bool AcLandFormJig::GetPoints(AcGePoint3dArray& arPts)
{
if (m_pLineSegs != NULL)
{
if (!m_pLineSegs->m_arPoints.isEmpty())
arPts.append(m_pLineSegs->m_arPoints);
return true;
}
return false;
}
AcEdJig::DragStatus AcLandFormJig::sampler()
{
setUserInputControls( ( UserInputControls)
( AcEdJig::kAccept3dCoordinates |
AcEdJig::kNullResponseAccepted ) );
CString sKeywordsList;
sKeywordsList = m_pCurStaRec->KeywordList();
if (!sKeywordsList.IsEmpty())
{
setKeywordList(sKeywordsList);
}
AcEdJig::DragStatus eStat = AcEdJig::kNormal;
AcGePoint3d ptGe,ptGeBase,ptGe2;
ptGeBase = AcGePoint3d::kOrigin;
AECStatusRecord::EAcquire eAcquire = m_pCurStaRec->GetStatusType();
switch(eAcquire)
{
case AECStatusRecord::kPoint:
{
int nPos = m_pCurStaRec->GetPlanPosition();
if (nPos == 0)//指定起点
{
eStat = acquirePoint(ptGe);
}
else
{
GetLastStatusAquire(ptGeBase);
eStat = acquirePoint(ptGe,ptGeBase);
//当前标高
ptGe.z = m_pCurStaRec->GetAcquirePoint().z;
double dDist = ptGeBase.distanceTo(ptGe);
if ( dDist < 1.e-6)
{
return AcEdJig::kNoChange;
}
}
if (eStat == AcEdJig::kNormal)
{
if (m_pCurStaRec->IsValSeted())
{
ptGe2 = m_pCurStaRec->GetAcquirePoint();
double dDis = ptGe2.distanceTo(ptGe);
if (dDis < 1.e-6)
{
//鼠标原地不动
return AcEdJig::kNoChange;
}
}
ptGe2 = m_pCurStaRec->GetAcquirePoint();
//当前标高
ptGe.z = ptGe2.z;
m_pCurStaRec->SetAcquirePoint(ptGe);
m_pLineSegs->SetLastPoint(ptGe);
if (m_pCurStaRec->GetPlanPosition() > 0 && m_lstStaPtrsBack.GetCount() > 0)
{
ptGe = m_pCurStaRec->GetAcquirePoint();
if (ptGe.distanceTo(ptGe2) < 1.e-6)
{
return AcEdJig::kNoChange;
}
return AcEdJig::kNormal;
}
}
else if (eStat == AcEdJig::kOther)
{
int nn = 0;
}
break;
}
default:
break;
}
return eStat;
}
bool AcLandFormJig::GetLastStatusAquire(AcGePoint3d& ptGe)
{
int nSize = (int)m_lstStaPtrsBack.GetCount();
if (nSize > 0)
{
AECStatusRecord* pRecLast = (AECStatusRecord*)m_lstStaPtrsBack.GetTail();
if (pRecLast != NULL)
ptGe = pRecLast->GetAcquirePoint();
return true;
}
return false;
}
AcDbEntity* AcLandFormJig::entity() const
{
return m_pLineSegs;
}
Adesk::Boolean AcLandFormJig::update()
{
return Adesk::kTrue;
}