找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 174|回复: 0

arx 自定义实体简单实例

[复制链接]

1

主题

0

回帖

37

积分

管理员

积分
37
发表于 2024-5-2 22:41:36 | 显示全部楼层 |阅读模式
  1. class DLLIMPEXP MyLineEx : public AcDbEntity {
  2. public:
  3. ACRX采用DECLARE采用MEMBERS(MyLineEx) ;
  4. protected:
  5. static Adesk::UInt32 kCurrentVersionNumber ;
  6. private:
  7. AcGePoint3d m采用ptStart;
  8. AcGePoint3d m采用ptEnd;
  9. public:
  10. MyLineEx () ;
  11. MyLineEx (const AcGePoint3d& s,const AcGePoint3d& e);
  12. virtual ~MyLineEx () ;
  13. //----- AcDbObject protocols
  14. //- Dwg Filing protocol
  15. 保存,复制
  16. virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;
  17. virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;
  18. //----- AcDbEntity protocols
  19. //- Graphics protocol
  20. protected:
  21. 显示的时候调用
  22. virtual Adesk::Boolean subWorldDraw (AcGiWorldDraw *mode) ;
  23. 暂时不知道
  24. virtual Adesk::UInt32 subSetAttributes (AcGiDrawableTraits *traits) ;
  25. 单击时候触发,显示夹点
  26. virtual Acad::ErrorStatus subGetGripPoints(
  27.     AcGePoint3dArray& gripPoints,
  28.     AcDbIntArray&  osnapModes,
  29.     AcDbIntArray&  geomIds) const;
  30. 移动时候触发
  31. virtual Acad::ErrorStatus subMoveGripPointsAt(const AcDbIntArray& indices,
  32.                                                      const AcGeVector3d& offset);
  33. 捕捉的时候
  34. virtual Acad::ErrorStatus subGetOsnapPoints(
  35.                                     AcDb::OsnapMode     osnapMode,
  36.                                     Adesk::GsMarker     gsSelectionMark,
  37.                                     const AcGePoint3d&  pickPoint,
  38.                                     const AcGePoint3d&  lastPoint,
  39.                                     const AcGeMatrix3d& viewXform,
  40.                                     AcGePoint3dArray&   snapPoints,
  41.                                     AcDbIntArray &   geomIds) const;
  42. 移动,旋转
  43. virtual Acad::ErrorStatus   subTransformBy(const AcGeMatrix3d& xform);
  44. 暂时不知道
  45. virtual Acad::ErrorStatus   subGetTransformedCopy(const AcGeMatrix3d& xform,
  46.                                                    AcDbEntity*& pEnt) const;
  47. } ;
  48. //===========================================================================
  49. MyLineEx::MyLineEx () : AcDbEntity () {
  50. }
  51. MyLineEx::MyLineEx(const AcGePoint3d& s,const AcGePoint3d& e)
  52. {
  53. m采用ptStart[X] = s[X];
  54. m采用ptStart[Y] = s[Y];
  55. m采用ptStart[Z] = s[Z];
  56. m采用ptEnd[X] = e[X];
  57. m采用ptEnd[Y] = e[Y];
  58. m采用ptEnd[Z] = e[Z];
  59. }
  60. MyLineEx::~MyLineEx () {
  61. }
  62. 单击实体的时候用到,添加夹点
  63. Acad::ErrorStatus MyLineEx::subGetGripPoints(
  64.     AcGePoint3dArray& gripPoints,
  65.     AcDbIntArray&  osnapModes,
  66. AcDbIntArray&  geomIds) const
  67. {
  68. //acedInitGet(RSG采用NOZERO + RSG采用NONULL+RSG采用NONEG,采用T(""));
  69. assertReadEnabled();
  70. // TODO: implement this function.
  71. AcGeVector3d vecLine = m采用ptEnd - m采用ptStart;
  72. acutPrintf(采用T("\nsubGetGripPoints"));
  73. gripPoints.append(m采用ptStart);
  74. gripPoints.append(m采用ptEnd);
  75. gripPoints.append(m采用ptStart + vecLine / 2.0);
  76. gripPoints.append(m采用ptStart + vecLine / 3.0);
  77. return Acad::eOk;
  78. }
  79. 拖动夹点的时候用到,indices为夹点数组的下标数组
  80. Acad::ErrorStatus MyLineEx::subMoveGripPointsAt(const AcDbIntArray& indices,
  81. const AcGeVector3d& offset)
  82. {
  83. assertWriteEnabled();
  84. // TODO: implement this function.
  85. assertReadEnabled();
  86. int len = indices.length();
  87. for(int i = 0;i < len; i++)
  88. {
  89. int k = indices[i];
  90. switch(k)
  91. {
  92. case 0:
  93. m采用ptStart += offset;
  94. break;
  95. case 1:
  96. m采用ptEnd += offset;
  97. break;
  98. case 2:
  99. case 3:
  100. m采用ptStart += offset;
  101. m采用ptEnd += offset;
  102. break;
  103. default:break;
  104. }
  105. }
  106. return Acad::eOk;
  107. }
  108. 捕捉的时候调用,添加捕捉点(交点不是这个函数)
  109. Acad::ErrorStatus MyLineEx::subGetOsnapPoints(
  110.                                     AcDb::OsnapMode     osnapMode,
  111.                                     Adesk::GsMarker     gsSelectionMark,
  112.                                     const AcGePoint3d&  pickPoint,
  113.                                     const AcGePoint3d&  lastPoint,
  114.                                     const AcGeMatrix3d& viewXform,
  115.                                     AcGePoint3dArray&   snapPoints,
  116.                                     AcDbIntArray &   geomIds) const
  117. {
  118. //assertWriteEnabled();
  119. // TODO: implement this function.
  120. assertReadEnabled();
  121. // TODO: implement this function.
  122. snapPoints.append(m采用ptStart);
  123. snapPoints.append(m采用ptEnd);
  124. snapPoints.append(m采用ptStart + (m采用ptEnd - m采用ptStart) / 2);
  125. snapPoints.append(m采用ptStart + (m采用ptEnd - m采用ptStart) / 3);
  126. //snapPoints.append(m采用ptStart + (m采用ptEnd - m采用ptStart) / 4);
  127. /*return Acad::eOk;*/
  128. return Acad::eOk;/*AcDbEntity::getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds);*/
  129. }
  130. 实现移动,旋转等变换
  131. Acad::ErrorStatus   MyLineEx::subTransformBy(const AcGeMatrix3d& xform)
  132. {
  133. assertReadEnabled();
  134. assertWriteEnabled();
  135. m采用ptStart.transformBy(xform);
  136. m采用ptEnd.transformBy(xform);
  137. //m采用center.transformBy(mat);
  138. return Acad::eOk;
  139. }
  140. Acad::ErrorStatus MyLineEx::subGetTransformedCopy(const AcGeMatrix3d& xform,AcDbEntity*& pEnt) const
  141. {
  142. assertReadEnabled();
  143. //AcGePoint3d ptS = m采用ptStart;
  144. //AcGePoint3d ptE = m采用ptEnd;
  145. //
  146. //ptS.transformBy(xform);
  147. //ptE.transformBy(xform);
  148. //AcDbLine* ent = new AcDbLine(m采用ptStart,m采用ptEnd);
  149. //assert(ent != NULL);
  150. //ent->setPropertiesFrom(this);
  151. //pEnt = ent;
  152. acutPrintf(采用T("\naaa"));
  153. //m采用ptStart.transformBy(xform);
  154. //m采用ptEnd.transformBy(xform);
  155. return Acad::eOk;
  156. }
  157. //-----------------------------------------------------------------------------
  158. //----- AcDbObject protocols
  159. //- Dwg Filing protocol
  160. Acad::ErrorStatus MyLineEx::dwgOutFields (AcDbDwgFiler *pFiler) const {
  161. assertReadEnabled () ;
  162. //----- Save parent class information first.
  163. Acad::ErrorStatus es =AcDbEntity::dwgOutFields (pFiler) ;
  164. if ( es != Acad::eOk )
  165. return (es) ;
  166. //----- Object version number needs to be saved first
  167. if ( (es =pFiler->writeUInt32 (MyLineEx::kCurrentVersionNumber)) != Acad::eOk )
  168. return (es) ;
  169. //----- Output params
  170. //.....
  171. 这两句加上才能复制
  172. pFiler->writePoint3d(m采用ptStart);
  173. pFiler->writePoint3d(m采用ptEnd);
  174. return (pFiler->filerStatus ()) ;
  175. }
  176. Acad::ErrorStatus MyLineEx::dwgInFields (AcDbDwgFiler *pFiler) {
  177. assertWriteEnabled () ;
  178. //----- Read parent class information first.
  179. Acad::ErrorStatus es =AcDbEntity::dwgInFields (pFiler) ;
  180. if ( es != Acad::eOk )
  181. return (es) ;
  182. //----- Object version number needs to be read first
  183. Adesk::UInt32 version =0 ;
  184. if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )
  185. return (es) ;
  186. if ( version > MyLineEx::kCurrentVersionNumber )
  187. return (Acad::eMakeMeProxy) ;
  188. //- Uncomment the 2 following lines if your current object implementation cannot
  189. //- support previous version of that object.
  190. //if ( version < MyLineEx::kCurrentVersionNumber )
  191. // return (Acad::eMakeMeProxy) ;
  192. //----- Read params
  193. //.....
  194. 这两句加上,才能复制
  195. pFiler->readPoint3d(&m采用ptStart);
  196. pFiler->readPoint3d(&m采用ptEnd);
  197. return (pFiler->filerStatus ()) ;
  198. }
  199. //-----------------------------------------------------------------------------
  200. //----- AcDbEntity protocols
  201. Adesk::Boolean MyLineEx::subWorldDraw (AcGiWorldDraw *mode) {
  202. assertReadEnabled () ;
  203. //获取虚线线型ID
  204. mode->subEntityTraits().setColor(150);
  205. AcGePoint3d Verts[2];
  206. Verts[0]=m采用ptStart;
  207. Verts[1]=m采用ptEnd;
  208. mode->geometry().polyline(2,Verts);
  209. return (AcDbEntity::subWorldDraw (mode)) ;
  210. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-4 13:19 , Processed in 0.121356 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表