376 lines
7.3 KiB
C++
376 lines
7.3 KiB
C++
#include "stdafx.h"
|
|
#include "Resource.h"
|
|
#include "KTAxisGridJig.h"
|
|
#include "KTStatusRecord.h"
|
|
#include "KTVirtualAxis.h"
|
|
#include "KTCadUtility.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
KTAxisGridJig::KTAxisGridJig()
|
|
{
|
|
m_pVirtualAxis = new KTVirtualAxis;
|
|
m_pStatus = NULL;
|
|
m_ptOrgBase.set(0.0,0.0,0.0);
|
|
InitStatusLoop();
|
|
}
|
|
|
|
KTAxisGridJig::~KTAxisGridJig()
|
|
{
|
|
FreeBuffer();
|
|
if (m_pVirtualAxis != NULL)
|
|
delete m_pVirtualAxis;
|
|
}
|
|
|
|
BOOL KTAxisGridJig::Doit()
|
|
{
|
|
if (m_pStatus == NULL)
|
|
return FALSE;
|
|
|
|
CString sPrompt,sKey;
|
|
|
|
while(TRUE)
|
|
{
|
|
m_pStatus->GetPrompt(sPrompt);
|
|
setDispPrompt(sPrompt);
|
|
|
|
AcEdJig::DragStatus eStatus = drag();
|
|
DeleteCurAxisToDbForTemp();
|
|
|
|
AcGePoint3d ptGe;
|
|
int nStep = 0;
|
|
m_pStatus->GetPlanPos(nStep);
|
|
|
|
switch(eStatus)
|
|
{
|
|
case AcEdJig::kNull:
|
|
{
|
|
return FALSE;
|
|
}
|
|
case AcEdJig::kNormal:
|
|
{
|
|
switch(nStep)
|
|
{
|
|
case modeDrag:
|
|
{
|
|
return TRUE;
|
|
}
|
|
case modeR:
|
|
{
|
|
m_pStatus = m_pStatus->GetParentStaRec();
|
|
if (m_pStatus == NULL)
|
|
return FALSE;
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
break;
|
|
}
|
|
case AcEdJig::kKW1://A
|
|
{
|
|
TransformEntitis(_T("A"));
|
|
break;
|
|
}
|
|
case AcEdJig::kKW2://S
|
|
{
|
|
TransformEntitis(_T("S"));
|
|
break;
|
|
}
|
|
case AcEdJig::kKW3://D
|
|
{
|
|
TransformEntitis(_T("D"));
|
|
break;
|
|
}
|
|
case AcEdJig::kKW4://T
|
|
{
|
|
AppendCurAxisToDbForTemp();
|
|
sPrompt.LoadString(IDS_INPUT_INSERT_POINT);
|
|
eStatus = AcGetPoint(NULL, sPrompt, ptGe);
|
|
DeleteCurAxisToDbForTemp();
|
|
if (AcEdJig::kNormal == eStatus)
|
|
{
|
|
AcGeMatrix3d xform;
|
|
xform.setToTranslation(m_ptOrgBase - ptGe);
|
|
TransformEntitis(xform);
|
|
}
|
|
else
|
|
{
|
|
return FALSE;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
AcEdJig::DragStatus KTAxisGridJig::sampler()
|
|
{
|
|
setUserInputControls( ( UserInputControls)
|
|
( AcEdJig::kAccept3dCoordinates |
|
|
AcEdJig::kNullResponseAccepted |
|
|
AcEdJig::kNoZeroResponseAccepted) );
|
|
|
|
if (m_pStatus == NULL)
|
|
return AcEdJig::kNoChange;
|
|
|
|
CString sKeyList;
|
|
m_pStatus->GetKeylist(sKeyList);
|
|
|
|
setKeywordList(sKeyList);
|
|
|
|
KTStatusRecord::EQuire eQuire = m_pStatus->GetQuire();
|
|
AcEdJig::DragStatus eStatus;
|
|
|
|
AcGePoint3d ptGe,ptGeLast;
|
|
int nStep = 0;
|
|
m_pStatus->GetPlanPos(nStep);
|
|
|
|
switch(eQuire)
|
|
{
|
|
case KTStatusRecord::kPoint:
|
|
{
|
|
switch(nStep)
|
|
{
|
|
case modeDrag:
|
|
{
|
|
eStatus = acquirePoint(ptGe);
|
|
m_pStatus->GetAcquireVal(ptGeLast);
|
|
|
|
if (eStatus == AcEdJig::kNormal)
|
|
{
|
|
double dDist = ptGeLast.distanceTo(ptGe);
|
|
if (dDist < 1.e-6)
|
|
{
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
AcGeVector3d vc = ptGe - ptGeLast;
|
|
AcGeMatrix3d xform;
|
|
xform.setToTranslation(vc);
|
|
TransformEntitis(xform);
|
|
m_ptOrgBase.transformBy(xform);
|
|
m_pStatus->SetAcquireVal(ptGe);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
case KTStatusRecord::kAngle:
|
|
{
|
|
KTStatusRecord* pParent = m_pStatus->GetParentStaRec();
|
|
ASSERT(pParent != NULL);
|
|
pParent->GetAcquireVal(ptGe);
|
|
|
|
double dAngle = 0.0;
|
|
eStatus = acquireAngle(dAngle,ptGe);
|
|
|
|
double dLastAng = 0.0;
|
|
m_pStatus->GetAcquireVal(dLastAng);
|
|
if (eStatus == AcEdJig::kNormal)
|
|
{
|
|
m_pStatus->SetAcquireVal(dAngle);
|
|
|
|
AcGeMatrix3d xform;
|
|
xform.setToRotation(dAngle,AcGeVector3d::kZAxis,ptGe);
|
|
|
|
AcGeMatrix3d xformLa;
|
|
xformLa.setToRotation(-dLastAng,AcGeVector3d::kZAxis,ptGe);
|
|
|
|
TransformEntitis(xformLa);
|
|
TransformEntitis(xform);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return eStatus;
|
|
}
|
|
|
|
void KTAxisGridJig::SetEntitiesPtrs(const AcDbVoidPtrArray& arEntityPtrs)
|
|
{
|
|
int nLen = arEntityPtrs.length();
|
|
for(int i = 0;i < nLen;i++)
|
|
{
|
|
m_pVirtualAxis->m_arEntitiesPtrs.append(arEntityPtrs.at(i));
|
|
}
|
|
}
|
|
|
|
Adesk::Boolean KTAxisGridJig::update()
|
|
{
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
AcDbEntity* KTAxisGridJig::entity() const
|
|
{
|
|
return m_pVirtualAxis;
|
|
}
|
|
|
|
void KTAxisGridJig::FreeBuffer()
|
|
{
|
|
KTStatusRecord *pRec = NULL;
|
|
int nSize = m_arStatusPtrs.GetSize();
|
|
for(int i = 0;i < nSize;i++)
|
|
{
|
|
pRec = (KTStatusRecord *)m_arStatusPtrs.GetAt(i);
|
|
if (pRec != NULL) delete pRec;
|
|
}
|
|
m_arStatusPtrs.RemoveAll();
|
|
}
|
|
|
|
void KTAxisGridJig::InitStatusLoop()
|
|
{
|
|
CString sPrompt,sKeyWords;
|
|
|
|
KTStatusRecord *pRec = new KTStatusRecord;
|
|
m_arStatusPtrs.Add(pRec);
|
|
sPrompt.LoadString(IDS_GET_POINT_POS);
|
|
sKeyWords = _T("A S D T");
|
|
pRec->SetPrompt(sPrompt);
|
|
pRec->SetKeyList(sKeyWords);
|
|
pRec->SetPlanPos(KTAxisGridJig::modeDrag);
|
|
pRec->SetQuire(KTStatusRecord::kPoint);
|
|
m_pStatus = pRec;
|
|
}
|
|
|
|
void KTAxisGridJig::TransformEntitis(const AcGeMatrix3d& xform)
|
|
{
|
|
AcDbEntity * pEnt = NULL;
|
|
int nLen = m_pVirtualAxis->m_arEntitiesPtrs.length();
|
|
for(int i = 0;i < nLen;i++)
|
|
{
|
|
pEnt = (AcDbEntity *)m_pVirtualAxis->m_arEntitiesPtrs.at(i);
|
|
pEnt->transformBy(xform);
|
|
}
|
|
}
|
|
|
|
void KTAxisGridJig::TransformEntitis(CString sKey)
|
|
{
|
|
if (m_pStatus == NULL)
|
|
return;
|
|
|
|
AcGeMatrix3d xform;
|
|
AcGeLine3d line;
|
|
AcGePoint3d ptStart, ptEnd, ptGe;
|
|
m_pStatus->GetAcquireVal(ptGe);
|
|
|
|
if (sKey.CompareNoCase(_T("A")) == 0)
|
|
{
|
|
xform.setToRotation(PI / 2, AcGeVector3d::kZAxis, ptGe);
|
|
}
|
|
else if (sKey.CompareNoCase(_T("S")) == 0)
|
|
{
|
|
ptStart = ptGe;
|
|
ptEnd = ptStart + AcGeVector3d::kYAxis * 1000;
|
|
line.set(ptStart, ptEnd);
|
|
xform.setToMirroring(line);
|
|
}
|
|
else if (sKey.CompareNoCase(_T("D")) == 0)
|
|
{
|
|
ptStart = ptGe;
|
|
ptEnd = ptStart + AcGeVector3d::kXAxis * 1000;
|
|
line.set(ptStart, ptEnd);
|
|
xform.setToMirroring(line);
|
|
}
|
|
|
|
AcDbEntity * pEnt = NULL;
|
|
int nLen = m_pVirtualAxis->m_arEntitiesPtrs.length();
|
|
for(int i = 0;i < nLen;i++)
|
|
{
|
|
pEnt = (AcDbEntity *)m_pVirtualAxis->m_arEntitiesPtrs.at(i);
|
|
pEnt->transformBy(xform);
|
|
}
|
|
}
|
|
|
|
void KTAxisGridJig::AppendCurAxisToDbForTemp()
|
|
{
|
|
AcDbObjectId id;
|
|
AcDbEntity* pEntSrc,*pEntNew = NULL;
|
|
int nSize = m_pVirtualAxis->m_arEntitiesPtrs.length();
|
|
for(int i = 0;i < nSize;i++)
|
|
{
|
|
pEntSrc = (AcDbEntity*)m_pVirtualAxis->m_arEntitiesPtrs.at(i);
|
|
if (pEntSrc != NULL)
|
|
{
|
|
pEntNew = (AcDbEntity*)(pEntSrc->isA()->create());
|
|
if (pEntNew != NULL)
|
|
{
|
|
AcDbLine* pLine = AcDbLine::cast(pEntNew);
|
|
AcDbLine* pLineSrc = AcDbLine::cast(pEntSrc);
|
|
if (pLine != NULL && pLineSrc != NULL)
|
|
{
|
|
pLine->setStartPoint(pLineSrc->startPoint());
|
|
pLine->setEndPoint(pLineSrc->endPoint());
|
|
CKTCadUtility::AddToBlockTableRecord(id, pLine);
|
|
pLine->close();
|
|
m_arIDsTemp.append(id);
|
|
}
|
|
else
|
|
{
|
|
delete pEntNew;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void KTAxisGridJig::DeleteCurAxisToDbForTemp()
|
|
{
|
|
int nSize = m_arIDsTemp.length();
|
|
if (nSize <= 0)
|
|
return;
|
|
|
|
AcDbObjectId id;
|
|
AcDbEntity* pEnt = NULL;
|
|
for(int i = 0; i < nSize;i++)
|
|
{
|
|
id = m_arIDsTemp.at(i);
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForWrite))
|
|
{
|
|
pEnt->erase();
|
|
pEnt->close();
|
|
}
|
|
}
|
|
m_arIDsTemp.setLogicalLength(0);
|
|
}
|
|
|
|
AcEdJig::DragStatus KTAxisGridJig::AcGetPoint(AcGePoint3d* pptGe, LPCTSTR pszPrompt, AcGePoint3d& ptRefE)
|
|
{
|
|
ads_point pt1,ptRes;
|
|
int nRes = 0;
|
|
if (pptGe == NULL)
|
|
{
|
|
nRes = acedGetPoint(NULL,pszPrompt,ptRes);
|
|
}
|
|
else
|
|
{
|
|
pt1[X] = pptGe->x;pt1[Y] = pptGe->y;pt1[Z] = pptGe->z;
|
|
acdbWcs2Ucs(pt1,pt1,false);
|
|
nRes = acedGetPoint(pt1,pszPrompt,ptRes);
|
|
}
|
|
|
|
if (nRes == RTNORM)
|
|
{
|
|
acdbUcs2Wcs(ptRes,ptRes,false);
|
|
ptRefE = asPnt3d((ptRes));
|
|
return AcEdJig::kNormal;
|
|
}
|
|
return AcEdJig::kCancel;
|
|
} |