151 lines
3.4 KiB
C++
151 lines
3.4 KiB
C++
#include "stdafx.h"
|
|
#include "KTJigTrapezia.h"
|
|
|
|
KTJigTrapezia::KTJigTrapezia()
|
|
: m_bDragEdge(TRUE), m_eSkirt(KTJigTrapezia::eSkirtNone), m_pPline(NULL)
|
|
{
|
|
}
|
|
|
|
KTJigTrapezia::~KTJigTrapezia()
|
|
{
|
|
}
|
|
|
|
AcDbPolyline* KTJigTrapezia::DragCreate(const AcGePoint3d& ptBase, const AcGeVector3d& vtEdge, const AcGeVector3d& vtNormal,
|
|
LPCTSTR pszPrompt, BOOL bDragEdge, KTJigTrapezia::ESkirtType eSkirt)
|
|
{
|
|
ASSERT(!vtEdge.isZeroLength() && !vtNormal.isZeroLength() && !vtEdge.isCodirectionalTo(vtNormal));
|
|
|
|
AcDbPolyline* pPline = new AcDbPolyline;
|
|
if (NULL == pPline)
|
|
return NULL;
|
|
|
|
m_bDragEdge = bDragEdge;
|
|
m_eSkirt = eSkirt;
|
|
m_ptLast = ptBase;
|
|
|
|
pPline->setNormal(vtNormal);
|
|
AcGePlane plane(AcGePoint3d::kOrigin, vtNormal);
|
|
pPline->setElevation(plane.distanceTo(ptBase));
|
|
|
|
AcGePoint3d ptVertex(ptBase);
|
|
AcGeVector3d vtPerp(vtNormal.crossProduct(vtEdge));
|
|
pPline->addVertexAt(0, ptVertex.convert2d(plane));
|
|
ptVertex += vtEdge;
|
|
pPline->addVertexAt(1, ptVertex.convert2d(plane));
|
|
ptVertex += vtPerp.normal();
|
|
pPline->addVertexAt(2, ptVertex.convert2d(plane));
|
|
ptVertex -= vtEdge;
|
|
pPline->addVertexAt(3, ptVertex.convert2d(plane));
|
|
|
|
pPline->setClosed(Adesk::kTrue);
|
|
|
|
if (NULL != pszPrompt)
|
|
setDispPrompt(pszPrompt);
|
|
|
|
ASSERT(NULL == m_pPline);
|
|
m_pPline = pPline;
|
|
BOOL bError = (pPline->numVerts() < 4 || AcEdJig::kNormal != drag());
|
|
m_pPline = NULL;
|
|
|
|
if (bError)
|
|
{
|
|
delete pPline;
|
|
return NULL;
|
|
}
|
|
|
|
return pPline;
|
|
}
|
|
|
|
AcEdJig::DragStatus KTJigTrapezia::sampler()
|
|
{
|
|
setUserInputControls((UserInputControls)(kAccept3dCoordinates | kNullResponseAccepted | kDontUpdateLastPoint));
|
|
|
|
AcGePoint3d ptDynamic;
|
|
AcEdJig::DragStatus eStatus = acquirePoint(ptDynamic);
|
|
if (AcEdJig::kNormal != eStatus)
|
|
return eStatus;
|
|
|
|
AcGePoint3d ptBase;
|
|
m_pPline->getPointAt(0, ptBase);
|
|
if (ptBase == ptDynamic || m_ptLast == ptDynamic)
|
|
return AcEdJig::kNoChange;
|
|
|
|
m_ptLast = ptDynamic;
|
|
|
|
AcGeVector3d vtNormal(m_pPline->normal());
|
|
AcGePlane plane(AcGePoint3d::kOrigin, vtNormal);
|
|
|
|
AcGePoint3d pt1, pt2;
|
|
m_pPline->getPointAt(1, pt1);
|
|
AcGeVector3d vtEdge = pt1 - ptBase;
|
|
AcGeVector3d vtPerp(vtNormal.crossProduct(vtEdge));
|
|
|
|
if (m_bDragEdge)
|
|
{
|
|
AcGeLine3d line1(ptBase, vtEdge);
|
|
AcGeLine3d line2(ptDynamic, vtPerp);
|
|
if (!line1.intersectWith(line2, pt1) || pt1 == ptBase)
|
|
return AcEdJig::kNoChange;
|
|
|
|
line1.set(ptBase, vtPerp);
|
|
line2.set(ptDynamic, vtEdge);
|
|
if (!line1.intersectWith(line2, pt2))
|
|
return AcEdJig::kNoChange;
|
|
|
|
m_pPline->setPointAt(1, pt1.convert2d(plane));
|
|
m_pPline->setPointAt(2, ptDynamic.convert2d(plane));
|
|
m_pPline->setPointAt(3, pt2.convert2d(plane));
|
|
}
|
|
else
|
|
{
|
|
if (m_eSkirt & eSkirtCoDir)
|
|
{
|
|
pt1 = ptDynamic;
|
|
}
|
|
else
|
|
{
|
|
AcGeLine3d line1(pt1, vtPerp);
|
|
AcGeLine3d line2(ptDynamic, vtEdge);
|
|
if (!line1.intersectWith(line2, pt1))
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
|
|
if (m_eSkirt & eSkirtReDir)
|
|
{
|
|
if (m_eSkirt & eSkirtCoDir)
|
|
{
|
|
pt2 = pt1;
|
|
pt2.mirror(AcGePlane(ptBase, vtEdge));
|
|
pt2 += vtEdge;
|
|
}
|
|
else
|
|
{
|
|
pt2 = ptDynamic;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AcGeLine3d line1(ptBase, vtPerp);
|
|
AcGeLine3d line2(ptDynamic, vtEdge);
|
|
if (!line1.intersectWith(line2, pt2))
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
|
|
m_pPline->setPointAt(2, pt1.convert2d(plane));
|
|
m_pPline->setPointAt(3, pt2.convert2d(plane));
|
|
}
|
|
|
|
return eStatus;
|
|
}
|
|
|
|
Adesk::Boolean KTJigTrapezia::update()
|
|
{
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
AcDbEntity* KTJigTrapezia::entity() const
|
|
{
|
|
ASSERT(NULL != m_pPline);
|
|
return m_pPline;
|
|
}
|