本帖最后由 作者 于 2007-4-27 0:31:35 编辑
我用AcEdJig产生几个命令Move/Copy/Mirror/Rotate 来操作我自己定义的 entity. 这些命令在AutoCAD2002/2004运行地很好,但当我升级到AutoCAD2007后,这些命令总是在拖动鼠标时死掉, 那位知道AcEdJig用在AutoCAD2007时与AutoCAD2002/2004版本有何不同. 需要注意些什么.是否有其他途径来实现Move/Copy/Mirror/Rotate命令. 我定义了以下entity 实现选择物体的Matrix转换和worldDraw. class TransformedObjects : public AcDbEntity { ............. public: virtual void viewportDraw(AcGiViewportDraw* pVpDraw); virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode); ........ private: AcDbObjectIdArray mObjectIds; //objects to be drawn AcGeMatrix3d mTransform; //Matrix定义 }; 我定义Move如下: class ObjectJig : public AcEdJig { public: ObjectJig(); ~ObjectJig(); virtual AcDbEntity *entity() const; virtual DragStatus sampler(); virtual Adesk::Boolean update(); virtual DragStatus Run(CString Prompt); void setTransform(AcGeMatrix3d trans); void addObject(AcDbObjectId id); void addObjects(AcDbObjectIdArray &ids); void applyTransform(); //Matrix操作 private: TransformedObjects mTransObject; AcGeMatrix3d mTransform; } class MoveJig : public ObjectJig { public: virtual DragStatus sampler(); virtual DragStatus Run(CString Prompt); void setRefPoint(AcGePoint3d pt) {mRefPoint = pt;} private: AcGePoint3d mRefPoint; AcGePoint3d mPoint; }; 程序在运行Move时在virtual DragStatus sampler();内部死掉,virtual DragStatus sampler()定义如下 AcEdJig::DragStatus MoveJig::sampler() { AcEdJig::DragStatus ds; AcGePoint3d Pt; setUserInputControls(AcEdJig::kAccept3dCoordinates); ds = acquirePoint(Pt, mRefPoint); if(ds == AcEdJig::kCancel) return ds; if(mPoint.isEqualTo(Pt)) return AcEdJig::kNoChange; mPoint = Pt; setTransform(AcGeMatrix3d::translation(mPoint - mRefPoint)); return ds; } private: AcDbObjectIdArray mObjectIds; //objects to be drawn AcGeMatrix3d mTransform; //Matrix定义 }; 我定义Move如下: class ObjectJig : public AcEdJig { public: ObjectJig(); ~ObjectJig(); virtual AcDbEntity *entity() const; virtual DragStatus sampler(); virtual Adesk::Boolean update(); virtual DragStatus Run(CString Prompt); void setTransform(AcGeMatrix3d trans); void addObject(AcDbObjectId id); void addObjects(AcDbObjectIdArray &ids); void applyTransform(); //Matrix操作 private: TransformedObjects mTransObject; AcGeMatrix3d mTransform; } class MoveJig : public ObjectJig { public: virtual DragStatus sampler(); virtual DragStatus Run(CString Prompt); void setRefPoint(AcGePoint3d pt) {mRefPoint = pt;} private: AcGePoint3d mRefPoint; AcGePoint3d mPoint; }; 程序在运行Move时在virtual DragStatus sampler();内部死掉,virtual DragStatus sampler()定义如下 AcEdJig::DragStatus MoveJig::sampler() { AcEdJig::DragStatus ds; AcGePoint3d Pt; setUserInputControls(AcEdJig::kAccept3dCoordinates); ds = acquirePoint(Pt, mRefPoint); if(ds == AcEdJig::kCancel) return ds; if(mPoint.isEqualTo(Pt)) return AcEdJig::kNoChange; mPoint = Pt; setTransform(AcGeMatrix3d::translation(mPoint - mRefPoint)); return ds; } 具体实施Move的函数如下 AcEdJig::DragStatus MoveJig::Run(CString Prompt) { AcEdJig::DragStatus status; mPoint = mRefPoint; setDispPrompt(Prompt); status = drag(); if(status == AcEdJig::kNormal) applyTransform(); return status; } 望那位高手指点迷津,多谢了 |