arx 自定义实体简单实例

来源:互联网 发布:如何在淘宝上买盗版书 编辑:程序博客网 时间:2024/05/16 01:00

class DLLIMPEXP MyLineEx : public AcDbEntity {public:ACRX_DECLARE_MEMBERS(MyLineEx) ;protected:static Adesk::UInt32 kCurrentVersionNumber ;private:AcGePoint3d m_ptStart;AcGePoint3d m_ptEnd;public:MyLineEx () ;MyLineEx (const AcGePoint3d& s,const AcGePoint3d& e);virtual ~MyLineEx () ;//----- AcDbObject protocols//- Dwg Filing protocol////保存,复制virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;//----- AcDbEntity protocols//- Graphics protocolprotected:////显示的时候调用virtual Adesk::Boolean subWorldDraw (AcGiWorldDraw *mode) ;////暂时不知道virtual Adesk::UInt32 subSetAttributes (AcGiDrawableTraits *traits) ;////单击时候触发,显示夹点virtual Acad::ErrorStatus subGetGripPoints(    AcGePoint3dArray& gripPoints,    AcDbIntArray&  osnapModes,    AcDbIntArray&  geomIds) const;////移动时候触发virtual Acad::ErrorStatus subMoveGripPointsAt(const AcDbIntArray& indices,                                                     const AcGeVector3d& offset);////捕捉的时候virtual Acad::ErrorStatus subGetOsnapPoints(                                    AcDb::OsnapMode     osnapMode,                                    Adesk::GsMarker     gsSelectionMark,                                    const AcGePoint3d&  pickPoint,                                    const AcGePoint3d&  lastPoint,                                    const AcGeMatrix3d& viewXform,                                    AcGePoint3dArray&   snapPoints,                                    AcDbIntArray &   geomIds) const;////移动,旋转virtual Acad::ErrorStatus   subTransformBy(const AcGeMatrix3d& xform);////暂时不知道virtual Acad::ErrorStatus   subGetTransformedCopy(const AcGeMatrix3d& xform,                                                   AcDbEntity*& pEnt) const;} ;//===========================================================================MyLineEx::MyLineEx () : AcDbEntity () {}MyLineEx::MyLineEx(const AcGePoint3d& s,const AcGePoint3d& e){m_ptStart[X] = s[X];m_ptStart[Y] = s[Y];m_ptStart[Z] = s[Z];m_ptEnd[X] = e[X];m_ptEnd[Y] = e[Y];m_ptEnd[Z] = e[Z];}MyLineEx::~MyLineEx () {}////单击实体的时候用到,添加夹点Acad::ErrorStatus MyLineEx::subGetGripPoints(    AcGePoint3dArray& gripPoints,    AcDbIntArray&  osnapModes,AcDbIntArray&  geomIds) const{//acedInitGet(RSG_NOZERO + RSG_NONULL+RSG_NONEG,_T(""));assertReadEnabled();// TODO: implement this function.AcGeVector3d vecLine = m_ptEnd - m_ptStart;acutPrintf(_T("\nsubGetGripPoints"));gripPoints.append(m_ptStart);gripPoints.append(m_ptEnd);gripPoints.append(m_ptStart + vecLine / 2.0);gripPoints.append(m_ptStart + vecLine / 3.0);return Acad::eOk;}////拖动夹点的时候用到,indices为夹点数组的下标数组Acad::ErrorStatus MyLineEx::subMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset){assertWriteEnabled();// TODO: implement this function.assertReadEnabled();int len = indices.length();for(int i = 0;i < len; i++){int k = indices[i];switch(k){case 0:m_ptStart += offset;break;case 1:m_ptEnd += offset;break;case 2:case 3:m_ptStart += offset;m_ptEnd += offset;break;default:break;}}return Acad::eOk;}////捕捉的时候调用,添加捕捉点(交点不是这个函数)Acad::ErrorStatus MyLineEx::subGetOsnapPoints(                                    AcDb::OsnapMode     osnapMode,                                    Adesk::GsMarker     gsSelectionMark,                                    const AcGePoint3d&  pickPoint,                                    const AcGePoint3d&  lastPoint,                                    const AcGeMatrix3d& viewXform,                                    AcGePoint3dArray&   snapPoints,                                    AcDbIntArray &   geomIds) const{//assertWriteEnabled();// TODO: implement this function.assertReadEnabled();// TODO: implement this function.snapPoints.append(m_ptStart);snapPoints.append(m_ptEnd);snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 2);snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 3);//snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 4);/*return Acad::eOk;*/return Acad::eOk;/*AcDbEntity::getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds);*/}////实现移动,旋转等变换Acad::ErrorStatus   MyLineEx::subTransformBy(const AcGeMatrix3d& xform){assertReadEnabled();assertWriteEnabled();m_ptStart.transformBy(xform);m_ptEnd.transformBy(xform);//m_center.transformBy(mat);return Acad::eOk;}Acad::ErrorStatus MyLineEx::subGetTransformedCopy(const AcGeMatrix3d& xform,AcDbEntity*& pEnt) const{assertReadEnabled();//AcGePoint3d ptS = m_ptStart;//AcGePoint3d ptE = m_ptEnd;////ptS.transformBy(xform);//ptE.transformBy(xform);//AcDbLine* ent = new AcDbLine(m_ptStart,m_ptEnd);//assert(ent != NULL);//ent->setPropertiesFrom(this);//pEnt = ent;acutPrintf(_T("\naaa"));//m_ptStart.transformBy(xform);//m_ptEnd.transformBy(xform);return Acad::eOk;}//-----------------------------------------------------------------------------//----- AcDbObject protocols//- Dwg Filing protocolAcad::ErrorStatus MyLineEx::dwgOutFields (AcDbDwgFiler *pFiler) const {assertReadEnabled () ;//----- Save parent class information first.Acad::ErrorStatus es =AcDbEntity::dwgOutFields (pFiler) ;if ( es != Acad::eOk )return (es) ;//----- Object version number needs to be saved firstif ( (es =pFiler->writeUInt32 (MyLineEx::kCurrentVersionNumber)) != Acad::eOk )return (es) ;//----- Output params//.....////这两句加上才能复制pFiler->writePoint3d(m_ptStart);pFiler->writePoint3d(m_ptEnd);return (pFiler->filerStatus ()) ;}Acad::ErrorStatus MyLineEx::dwgInFields (AcDbDwgFiler *pFiler) {assertWriteEnabled () ;//----- Read parent class information first.Acad::ErrorStatus es =AcDbEntity::dwgInFields (pFiler) ;if ( es != Acad::eOk )return (es) ;//----- Object version number needs to be read firstAdesk::UInt32 version =0 ;if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )return (es) ;if ( version > MyLineEx::kCurrentVersionNumber )return (Acad::eMakeMeProxy) ;//- Uncomment the 2 following lines if your current object implementation cannot//- support previous version of that object.//if ( version < MyLineEx::kCurrentVersionNumber )// return (Acad::eMakeMeProxy) ;//----- Read params//.....////这两句加上,才能复制pFiler->readPoint3d(&m_ptStart);pFiler->readPoint3d(&m_ptEnd);return (pFiler->filerStatus ()) ;}//-----------------------------------------------------------------------------//----- AcDbEntity protocolsAdesk::Boolean MyLineEx::subWorldDraw (AcGiWorldDraw *mode) {assertReadEnabled () ;//获取虚线线型IDmode->subEntityTraits().setColor(150);AcGePoint3d Verts[2];Verts[0]=m_ptStart;Verts[1]=m_ptEnd;mode->geometry().polyline(2,Verts);return (AcDbEntity::subWorldDraw (mode)) ;}


原创粉丝点击