天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 164|回复: 0

[每日一码] 从AcDbPolyline派生

[复制链接]
  • TA的每日心情
    开心
    昨天 06:36
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    105

    主题

    11

    回帖

    1308

    积分

    管理员

    积分
    1308
    QQ
    发表于 2024-3-14 21:06:27 | 显示全部楼层 |阅读模式
    1. AcDb: deriving from AcDbPolyline
    2. Published date: 2008-10-14
    3. ID: TS47354
    4. Applies to:
    5. AutoCAD® 2009
    6. AutoCAD® 2008
    7. AutoCAD® 2007
    8. 问题:
    9. Deriving from AcDbPolyline works correctly, however, it seems DWG files
    10. containing instances of my custom entity derived from AcDbPolyline do not
    11. contain proxy graphic information for them. Why?
    12. 解决方案:
    13. AutoCAD does not save the proxy graphic information for classes derived from
    14. AcDbPolyline. The reason for this is that the 'saveAs()' method is implemented
    15. as follows:
    16. void AcDbPolyline::saveAs(AcGiWorldDraw* mode, AcDb::SaveType st) {
    17.     assertReadEnabled();
    18.     if ( st == AcDb::kR12Save )
    19.         // ... do something to convert into AcDb2dPolyline
    20. }
    21. Whereas it should be as follows:
    22. void AcDbPolyline::saveAs(AcGiWorldDraw* mode, AcDb::SaveType st) {
    23.     assertReadEnabled();
    24.     if ( st == AcDb::kR12Save )
    25.         // ... do something to convert into AcDb2dPolyline
    26.     else
    27.         worldDraw (mode) ;
    28. }
    29. As a result, proxy graphic data is never saved, which causes your derived
    30. AcDbPolyline entity to be invisible if your DBX-object enabler application is
    31. not loaded. Although this is not ideal, it does not affect any other behavior or
    32. functionality of your custom entity.
    33. A simple override of the 'saveAs()' method can solve this problem as follows:
    34. 本帖隐藏的内容
    35. void AcDbMyPolyline::saveAs(AcGiWorldDraw* mode, AcDb::SaveType st) {
    36.     assertReadEnabled();
    37.     if ( st == AcDb::kR12Save )
    38.         AcDbPolyline::saveAs (mode, st) ;
    39.     else
    40.         worldDraw (mode) ;
    41. }
    42. This would be the correct solution, however there is another known problem in
    43. AutoCAD that prevents the 'saveAs()' method from being called for proxy graphic
    44. generation. This second problem is more serious because it prevents 'saveAs()'
    45. method being called. The reason for this is that AutoCAD makes an exception in
    46. the case of an AcDbPolyline entity. Instead of asking 'are you an AcDbPolyline
    47. class?', AutoCAD asks 'Are you a "kind of" AcDbPolyline?' This also includes any
    48. of your derived classes from AcDbPolyline.
    49. The only solution is to pretend your custom AcDbPolyline entity is not an
    50. AcDbPolyline class, even if it really is. This will cause AutoCAD to properly
    51. call the 'saveAs()' method and then your implementation of the 'worldDraw()'
    52. method for your custom entity. In order to pretend that it is not an
    53. AcDbPolyline entity, just implement the 'ACRX采用DXF采用DEFINE采用MEMBERS' ARX macro as
    54. follows:
    55. ACRX采用DXF采用DEFINE采用MEMBERS(AcDbMyPolyline, AcDbCurve,
    56. AcDb::kDHL采用CURRENT, AcDb::kMReleaseCurrent,
    57. AcDbProxyEntity::kNoOperation,
    58. ACDBMYPOLYLINE, ACDBMYAPP
    59. );
    60. There are other requirements in the implemention of the 'worldDraw()' method:
    61. you should not call AcDbPolyline::worldDraw() when called from the 'saveAs()'
    62. method because this would cause the same problem that was outlined previously.
    63. (AutoCAD filters out all AcDbPolyline calls in that context). An 'unhandled
    64. exception error' will occur as a result. (rememeber we are pretending not to be
    65. an AcDbPolyline entity). To solve the problem, you need to modify the 'saveAs()'
    66. method like this:
    67. bool mbDrawWithExplode = false ;
    68. void AcDbMyPolyline::saveAs(AcGiWorldDraw* mode, AcDb::SaveType st) {
    69.     assertReadEnabled();
    70.     if ( st == AcDb::kR12Save ) {
    71.         AcDbPolyline::saveAs (mode, st) ;
    72.     } else {
    73.         mbDrawWithExplode = true ;
    74.         worldDraw (mode) ;
    75.         mbDrawWithExplode = false ;
    76.     }
    77. }
    78. Implement your 'worldDraw()' method like this:
    79. Adesk::Boolean AsdkOPLine::worldDraw(AcGiWorldDraw* mode)
    80. {
    81.     assertReadEnabled();
    82.     if ( !mbDrawWithExplode ) {
    83.         bPEdit =true ;
    84.         if ( AcDbPolyline::worldDraw (mode) != Adesk::kTrue ) {
    85.             bPEdit =false ;
    86.             return (Adesk::kFalse) ;
    87.         }
    88.         bPEdit =false ;
    89.     } else {
    90.         AcDbVoidPtrArray ents ;
    91.         AcDbPolyline::explode (ents) ;
    92.         for ( int j =ents.length () - 1 ; j >= 0 ; j-- ) {
    93.             ((AcDbEntity *)ents.at (j))->worldDraw (mode) ;
    94.             delete (AcDbEntity *)ents.at (j) ;
    95.         }
    96.         ents.setLogicalLength (0) ;
    97.     }
    98.     return (Adesk::kTrue) ;
    99. }
    100. If you pretend it is not an AcDbPolyline, the AutoCAD "采用PEDIT" command will not
    101. work for your custom entity anymore. If you do not intend to support "采用PEDIT",
    102. then it is not a problem. However, if you intend to support "采用PEDIT" then you
    103. need to pretend that it is an AcDbPolyline only for the "采用PEDIT" command. To
    104. support "采用PEDIT" for a special class requires a considerable amount of work.
    105. First, you need to rewrite the 'ACRX采用DXF采用DEFINE采用MEMBERS' ARX macro like this:
    106. bool bPEdit =false ;
    107. void set采用bPEdit (bool flag) {
    108.     bPEdit =flag ;
    109. }
    110. //------------------------------------------
    111. #define MY采用ACRX采用DEFINE采用MEMBERS(CLASS采用NAME) \
    112. AcRxClass* CLASS采用NAME::desc() \
    113. { \
    114.    return (AcRxClass*)((AcRxDictionary*)acrxSysRegistry() \
    115.         ->at(ACRX采用CLASS采用DICTIONARY))->at(bPEdit ? "AcDbPolyline" :
    116. "AcDbMyPolyline"); \
    117. } \
    118. AcRxClass* CLASS采用NAME::isA() const \
    119. { \
    120.    return (AcRxClass*)((AcRxDictionary*)acrxSysRegistry() \
    121.         ->at(ACRX采用CLASS采用DICTIONARY))->at(bPEdit ? "AcDbPolyline" :
    122. "AcDbMyPolyline"); \
    123. } \
    124. AcRxClass* CLASS采用NAME::gpDesc = NULL
    125. //----------------------------------------------------------------------
    126. #define MY采用ACRX采用DXF采用DEFINE采用MEMBERS(CLASS采用NAME,PARENT采用CLASS,DWG采用VERSION,\
    127.           MAINTENANCE采用VERSION,PROXY采用FLAGS,DXF采用NAME,APP) \
    128. MY采用ACRX采用DEFINE采用MEMBERS(CLASS采用NAME); \
    129. static AcRxObject * make##CLASS采用NAME() { return new CLASS采用NAME(); } \
    130. void CLASS采用NAME::rxInit() { \
    131.    if (CLASS采用NAME::gpDesc != NULL) \
    132.     return; \
    133.    CLASS采用NAME::gpDesc = newAcRxClass(#CLASS采用NAME, #PARENT采用CLASS, \
    134.     DWG采用VERSION,MAINTENANCE采用VERSION,PROXY采用FLAGS, \
    135.     &make##CLASS采用NAME, #DXF采用NAME, #APP); \
    136. }
    137. Replace the 'ACRX采用DXF采用DEFINE采用MEMBERS' ARX macro with the following definition:
    138. MY采用ACRX采用DXF采用DEFINE采用MEMBERS(AcDbMyPolyline, AcDbCurve,
    139.             AcDb::kDHL采用CURRENT, AcDb::kMReleaseCurrent,
    140.             AcDbProxyEntity::kNoOperation,
    141.             ACDBMYPOLYLINE, ACDBMYAPP
    142. );
    143. The last item you need to implement is an AcEditorReactor to detect when the
    144. "采用PEDIT" command is executed and set the pPEdit flag to True as follows:
    145. void AsdkEdReactor::commandWillStart(const TCHAR* cmdStr)
    146. {
    147. if ( 采用tcsicmp (cmdStr, 采用T("PEDIT")) == 0 )
    148.   set采用bPEdit (true) ;
    149. }
    150. void AsdkEdReactor::commandEnded(const TCHAR* cmdStr)
    151. {
    152. if ( 采用tcsicmp (cmdStr, 采用T("PEDIT")) == 0 )
    153.   set采用bPEdit (false) ;
    154. }
    155. void AsdkEdReactor::commandCancelled(const TCHAR* cmdStr)
    156. {
    157. if ( 采用tcsicmp (cmdStr, 采用T("PEDIT")) == 0 )
    158.   set采用bPEdit (false) ;
    159. }
    160. void AsdkEdReactor::commandFailed(const TCHAR* cmdStr)
    161. {
    162. if ( 采用tcsicmp (cmdStr, 采用T("PEDIT")) == 0 )
    163.   set采用bPEdit (false) ;
    164. }
    复制代码

     

     

     

     

    [每日一码] 从AcDbPolyline派生
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-11-1 07:58 , Processed in 0.186229 second(s), 29 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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