|
发表于 2009-3-27 01:44:20
|
显示全部楼层
棒!谢谢保罗。
这里有一个示例,如果有人需要一个(AcDbPolyLine)
.h
- #pragma once
- class RectJig : public AcEdJig
- {
- // fields
- private:
- Adesk::Boolean m_append;
- AcGePoint3d m_cur;
- AcGePoint3d m_last;
- const CString m_msg;
- AcDbPolyline *m_line;
- AcDbObjectId m_id;
- public:
- // ctor && dtor
- RectJig(double width, double height, const CString &msg, Adesk::Boolean append = Adesk::kTrue);
- virtual ~RectJig(void);
- // methods
- void doIt();
- Adesk::Boolean cursorHasMoved(void);
- virtual AcEdJig::DragStatus sampler(void);
- virtual Adesk::Boolean update(void);
- virtual AcDbEntity* entity(void) const;
- AcGePoint2d getPoint2d(void) const;
- AcGePoint3d getPoint3d(void) const;
- AcDbObjectId getObjectId(void)const;
- __declspec(property(get = getPoint2d))AcGePoint2d Point2d;
- __declspec(property(get = getPoint3d))AcGePoint3d Point3d;
- __declspec(property(get = getObjectId))AcDbObjectId ObjectId;
- };
.cpp
- #include "StdAfx.h"
- #include "JigTest.h"
- RectJig::RectJig(double width, double height, const CString &msg, Adesk::Boolean append /*= Adesk::kTrue*/)
- :m_append(append), m_line(new AcDbPolyline(4)), m_cur(AcGePoint3d::kOrigin),
- m_last(AcGePoint3d::kOrigin) , m_msg(msg) , m_id(AcDbObjectId::kNull)
- {
- AcGePoint2d pt0(m_cur.x, m_cur.y);
- AcGePoint2d pt1(pt0.x + width,pt0.y);
- AcGePoint2d pt2(pt0.x + width, pt0.y + height);
- AcGePoint2d pt3(pt0.x, pt0.y + height);
- this->m_line->addVertexAt(0,pt0);
- this->m_line->addVertexAt(1,pt1);
- this->m_line->addVertexAt(2,pt2);
- this->m_line->addVertexAt(3,pt3);
- this->m_line->setClosed(Adesk::kTrue);
- }
- RectJig::~RectJig(void)
- {
- if(!m_append)
- {
- delete m_line;
- }
- }
- inline Adesk::Boolean RectJig::cursorHasMoved( void )
- {
- return this->m_cur != this->m_last;
- }
- AcEdJig::DragStatus RectJig::sampler()
- {
- setUserInputControls(UserInputControls(kAccept3dCoordinates));
- if(acquirePoint(m_cur) != AcEdJig::kNormal)
- {
- return AcEdJig::kCancel;
- }
- if(this->cursorHasMoved())
- {
- return AcEdJig::kNormal;
- }
- return AcEdJig::kNoChange;
- }
- Adesk::Boolean RectJig::update(void)
- {
- if(this->m_line->transformBy(AcGeMatrix3d::translation(AcGeVector3d(m_cur - m_last))) != Acad::eOk)
- {
- return Adesk::kFalse;
- }
- m_last = m_cur;
- return Adesk::kTrue;
- }
- AcDbEntity* RectJig::entity(void) const
- {
- return this->m_line;
- }
- void RectJig::doIt(void)
- {
- setDispPrompt(m_msg);
- if(drag() != AcEdJig::kNormal)
- {
- m_append = Adesk::kFalse;
- }
- if(m_append)
- {
- m_id = append();
- m_line->close();
- }
- }
- AcGePoint2d RectJig::getPoint2d(void) const
- {
- return AcGePoint2d(m_last.x, m_last.y);
- }
- AcGePoint3d RectJig::getPoint3d(void) const
- {
- return m_last;
- }
- AcDbObjectId RectJig::getObjectId( void ) const
- {
- return m_id;
- }
和命令
- static void CabDraw_RectJig(void)
- {
- RectJig jig(100,100, _T("Pick Start Point: "));
- jig.doIt();
- acutPrintf(_T("\n%g,%g"),jig.Point2d.x, jig.Point2d.y);
- }
编辑添加了objectid属性 |
|