349 lines
6.9 KiB
C++
349 lines
6.9 KiB
C++
#include "stdafx.h"
|
|
//#include "Resource.h"
|
|
#include "KTEntityDragMgr.h"
|
|
#include "KTCadUtility.h"
|
|
|
|
extern HINSTANCE _hdllInstance;
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
CKTEntityDragMgr::CKTEntityDragMgr(BOOL bAutoRelease)
|
|
: m_DumbEntity(bAutoRelease)
|
|
{
|
|
m_bMove = TRUE;
|
|
m_bScale = TRUE;
|
|
m_bRotate = TRUE;
|
|
}
|
|
|
|
CKTEntityDragMgr::CKTEntityDragMgr(const AcGePoint3d& ptDrag, const AcDbObjectId& idEnt, BOOL bAutoRelease)
|
|
: m_DumbEntity(idEnt, bAutoRelease)
|
|
{
|
|
m_ptDrag = ptDrag;
|
|
|
|
m_bMove = TRUE;
|
|
m_bScale = TRUE;
|
|
m_bRotate = TRUE;
|
|
}
|
|
|
|
CKTEntityDragMgr::CKTEntityDragMgr(const AcGePoint3d& ptDrag, const AcDbObjectIdArray& aridEnts, BOOL bAutoRelease)
|
|
: m_DumbEntity(aridEnts, bAutoRelease)
|
|
{
|
|
m_ptDrag = ptDrag;
|
|
|
|
m_bMove = TRUE;
|
|
m_bScale = TRUE;
|
|
m_bRotate = TRUE;
|
|
}
|
|
|
|
CKTEntityDragMgr::CKTEntityDragMgr(const AcGePoint3d& ptDrag, AcDbEntity* pEnt, BOOL bAutoRelease)
|
|
: m_DumbEntity(pEnt, bAutoRelease)
|
|
{
|
|
m_ptDrag = ptDrag;
|
|
|
|
m_bMove = TRUE;
|
|
m_bScale = TRUE;
|
|
m_bRotate = TRUE;
|
|
}
|
|
|
|
CKTEntityDragMgr::CKTEntityDragMgr(const AcGePoint3d& ptDrag, const AcDbVoidPtrArray& arpEnts, BOOL bAutoRelease)
|
|
: m_DumbEntity(arpEnts, bAutoRelease)
|
|
{
|
|
m_ptDrag = ptDrag;
|
|
|
|
m_bMove = TRUE;
|
|
m_bScale = TRUE;
|
|
m_bRotate = TRUE;
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::IsAutoRelease()
|
|
{
|
|
return m_DumbEntity.IsAutoRelease();
|
|
}
|
|
|
|
void CKTEntityDragMgr::EnableAutoRelease(BOOL bEnable)
|
|
{
|
|
m_DumbEntity.EnableAutoRelease(bEnable);
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::Add(AcDbEntity* pEnt)
|
|
{
|
|
return m_DumbEntity.Add(pEnt);
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::Add(const AcDbObjectId& idEnt)
|
|
{
|
|
return m_DumbEntity.Add(idEnt);
|
|
}
|
|
|
|
AcDbVoidPtrArray* CKTEntityDragMgr::GetAll()
|
|
{
|
|
return m_DumbEntity.GetAll();
|
|
}
|
|
|
|
CKTEntityDumb& CKTEntityDragMgr::GetDumbEntity()
|
|
{
|
|
return m_DumbEntity;
|
|
}
|
|
|
|
void CKTEntityDragMgr::SetDragPoint(const AcGePoint3d& pt, BOOL bMoveEnt)
|
|
{
|
|
if (bMoveEnt)
|
|
{
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(pt - m_ptDrag);
|
|
m_DumbEntity.transformBy(mat);
|
|
}
|
|
|
|
m_ptDrag = pt;
|
|
}
|
|
|
|
void CKTEntityDragMgr::TransformBy(const AcGeMatrix3d& mat)
|
|
{
|
|
m_DumbEntity.transformBy(mat);
|
|
}
|
|
|
|
AcGePoint3d CKTEntityDragMgr::GetDragPoint()
|
|
{
|
|
return m_ptDrag;
|
|
}
|
|
|
|
double CKTEntityDragMgr::GetDragValue()
|
|
{
|
|
return m_dLastVal;
|
|
}
|
|
|
|
void CKTEntityDragMgr::EnableMove(BOOL bEnable, LPCTSTR pszPrompt/*, const AcGePoint3d& pt, BOOL bMoveEnt*/)
|
|
{
|
|
m_bMove = bEnable;
|
|
m_sMove = pszPrompt;
|
|
|
|
// if (bMoveEnt)
|
|
// {
|
|
// AcGeMatrix3d mat;
|
|
// mat.setToTranslation(pt - m_ptDrag);
|
|
// m_DumbEntity.transformBy(mat);
|
|
// }
|
|
// m_ptDrag = pt;
|
|
}
|
|
|
|
void CKTEntityDragMgr::EnableScale(BOOL bEnable, LPCTSTR pszPrompt, double dScale)
|
|
{
|
|
m_bScale = bEnable;
|
|
m_sScale = pszPrompt;
|
|
m_dInitScale = dScale;
|
|
}
|
|
|
|
void CKTEntityDragMgr::EnableRotate(BOOL bEnable, LPCTSTR pszPrompt, double dAngle)
|
|
{
|
|
m_bRotate = bEnable;
|
|
m_sRotate = pszPrompt;
|
|
m_dInitAngle = dAngle;
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::Remove()
|
|
{
|
|
return m_DumbEntity.Remove();
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::Release(BOOL bErase)
|
|
{
|
|
return m_DumbEntity.Release(bErase);
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::append()
|
|
{
|
|
return m_DumbEntity.AddToBlockTableRecord();
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::append(AcDbObjectIdArray& aridEnts)
|
|
{
|
|
return m_DumbEntity.AddToBlockTableRecord(aridEnts);
|
|
}
|
|
|
|
BOOL CKTEntityDragMgr::DoDrag()
|
|
{
|
|
m_matMoveTrans.setToIdentity();
|
|
m_matScaleTrans.setToIdentity();
|
|
m_matRotateTrans.setToIdentity();
|
|
|
|
if (m_bMove)
|
|
{
|
|
if (m_sMove.IsEmpty())
|
|
{
|
|
//::LoadString(_hdllInstance, IDS_DRAGMGR_MOVEPROMPT, m_sMove.GetBuffer(MAX_PATH), MAX_PATH);
|
|
m_sMove = _T("\n请指定位置点:");
|
|
m_sMove.ReleaseBuffer();
|
|
}
|
|
|
|
m_iDragStep = 1;
|
|
setDispPrompt(m_sMove);
|
|
AcEdJig::DragStatus status = CKTEntityDragMgr::drag();
|
|
if (status != AcEdJig::kNormal)
|
|
{
|
|
m_DumbEntity.transformBy(m_matMoveTrans.inverse());
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
if (m_bScale)
|
|
{
|
|
if (m_sScale.IsEmpty())
|
|
{
|
|
//::LoadString(_hdllInstance, IDS_DRAGMGR_SCALEPROMPT, m_sScale.GetBuffer(MAX_PATH), MAX_PATH);
|
|
m_sScale = _T("\n请设置缩放比列<1.0>:");
|
|
m_sScale.ReleaseBuffer();
|
|
}
|
|
|
|
m_iDragStep = 2;
|
|
m_dLastVal = m_dInitScale;
|
|
setDispPrompt(m_sScale);
|
|
AcEdJig::DragStatus status = CKTEntityDragMgr::drag();
|
|
if (status != AcEdJig::kNormal)
|
|
{
|
|
if (status == AcEdJig::kNull)
|
|
{
|
|
m_dLastVal = 1.0;
|
|
m_DumbEntity.transformBy(m_matScaleTrans.inverse());
|
|
}
|
|
else
|
|
{
|
|
m_DumbEntity.transformBy(m_matMoveTrans.inverse() * m_matScaleTrans.inverse());
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
if (m_bRotate)
|
|
{
|
|
if (m_sRotate.IsEmpty())
|
|
{
|
|
//::LoadString(_hdllInstance, IDS_DRAGMGR_ROTATEPROMPT, m_sRotate.GetBuffer(MAX_PATH), MAX_PATH);
|
|
m_sRotate = _T("\n请设置旋转角度<0.0>:");
|
|
m_sRotate.ReleaseBuffer();
|
|
}
|
|
|
|
m_iDragStep = 3;
|
|
m_dLastVal = m_dInitAngle;
|
|
setDispPrompt(m_sRotate);
|
|
AcEdJig::DragStatus status = CKTEntityDragMgr::drag();
|
|
if (status != AcEdJig::kNormal)
|
|
{
|
|
if (status == AcEdJig::kNull)
|
|
{
|
|
m_dLastVal = 0.0;
|
|
m_DumbEntity.transformBy(m_matRotateTrans.inverse());
|
|
}
|
|
else
|
|
{
|
|
m_DumbEntity.transformBy(m_matMoveTrans.inverse() * m_matScaleTrans.inverse() * m_matRotateTrans.inverse());
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
AcEdJig::DragStatus CKTEntityDragMgr::sampler()
|
|
{
|
|
setUserInputControls((UserInputControls)
|
|
(kNullResponseAccepted | kAccept3dCoordinates |
|
|
kGovernedByOrthoMode | kDontUpdateLastPoint));
|
|
|
|
double dValue;
|
|
AcGePoint3d pt;
|
|
m_iStatus = AcEdJig::kCancel;
|
|
m_matTrans.setToIdentity();
|
|
switch (m_iDragStep)
|
|
{
|
|
case 1:
|
|
m_iStatus = acquirePoint(pt);
|
|
if (m_iStatus == AcEdJig::kNormal)
|
|
{
|
|
if (pt != m_ptDrag)
|
|
{
|
|
m_matTrans.setTranslation(pt - m_ptDrag);
|
|
m_ptDrag = pt;
|
|
}
|
|
else
|
|
m_iStatus = AcEdJig::kNoChange;
|
|
}
|
|
break;
|
|
case 2:
|
|
m_iStatus = acquireDist(dValue, m_ptDrag);
|
|
if (m_iStatus == AcEdJig::kNormal)
|
|
{
|
|
if (dValue != 0.0 && dValue != m_dLastVal)
|
|
{
|
|
m_matTrans.setToScaling(dValue / m_dLastVal, m_ptDrag);
|
|
m_dLastVal = dValue;
|
|
}
|
|
else
|
|
m_iStatus = AcEdJig::kNoChange;
|
|
}
|
|
break;
|
|
case 3:
|
|
m_iStatus = acquireAngle(dValue, m_ptDrag);
|
|
if (m_iStatus == AcEdJig::kNormal)
|
|
{
|
|
if (dValue != m_dLastVal)
|
|
{
|
|
m_matTrans.setToRotation(dValue - m_dLastVal, UcsZAxis, m_ptDrag);
|
|
m_dLastVal = dValue;
|
|
}
|
|
else
|
|
m_iStatus = AcEdJig::kNoChange;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (m_iStatus == AcEdJig::kNull || m_iStatus == AcEdJig::kCancel)
|
|
return AcEdJig::kNormal;
|
|
|
|
return m_iStatus;
|
|
}
|
|
|
|
// overridden methods from AcEdJig class
|
|
AcDbEntity* CKTEntityDragMgr::entity() const
|
|
{
|
|
return (AcDbEntity*)&m_DumbEntity;
|
|
}
|
|
|
|
Adesk::Boolean CKTEntityDragMgr::update()
|
|
{
|
|
switch (m_iDragStep)
|
|
{
|
|
case 1:
|
|
m_matMoveTrans.postMultBy(m_matTrans);
|
|
break;
|
|
case 2:
|
|
m_matScaleTrans.postMultBy(m_matTrans);
|
|
break;
|
|
case 3:
|
|
m_matRotateTrans.postMultBy(m_matTrans);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
m_DumbEntity.transformBy(m_matTrans);
|
|
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
AcEdJig::DragStatus CKTEntityDragMgr::drag()
|
|
{
|
|
AcEdJig::DragStatus status = AcEdJig::drag();
|
|
|
|
if (m_iStatus == AcEdJig::kNull || m_iStatus == AcEdJig::kCancel)
|
|
status = m_iStatus;
|
|
m_iStatus = AcEdJig::kNormal;
|
|
|
|
return status;
|
|
}
|
|
|