几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(C++)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-16, 10:39 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】objectarx&dummies教程(十一)—— custom objectarx class

objectarx&dummies教程(十一)—— custom objectarx class
objectarx&dummies教程(十一)—— custom objectarx class
class 11 - custom objectarx class
introduction
in my personal opinion, the greatest feature of objectarx is the capability to develop your own objects and entities. this powerful feature will allow you to create complex applications and provide your users a unique experience using your software.
this feature is possible since objectarx beginning (officially at autocad r13). since autodesk provided this feature, its own developers thought that they could develop their selves vertical solutions for the most interesting market areas. at that time, products like map, mcad and adt start to show up.
today there are several vertical products based on autocad made by autodesk and much more developed by third-party companies.
how is this possible?
objectarx takes full advantage of c++ language features like inheritance, polymorphism and overriding among many others. this allows autodesk to publish part of autocad source code using a sdk like package with library and header files.
beyond this point, objectarx exports some classes allowing you to derive from them and implement your own behavior taking advantage of all ready-to-use methods and overriding those ones you need.
this way, when your custom class is defined and implemented your application will be compiled and linked with autocad native libraries and headers and will be possible to load your module (dll) at runtime to use your own objects inside autocad! great hum?
when to use and when not to use custom objects
even being a powerful feature of objectarx, custom objects are not the best solution for any kind of implementation. sometimes is better to user another solution like xdata or xrecords. this will totally depend on how much complex your application is and how much complex will be the way users will interact with your product.
you need to be sure when to use or not custom classes inside objectarx. personally i perform some questions to myself that will help me to decide:
- my product's elements are simple or complex?
- my elements are only complex in terms of non-graphical data or they will require complex graphical representation?
- do i need to protect my element's data when the drawing is out of my company?
- will my elements present a complex interaction with users very different from autocad native entities?
- do i need to share common information among my elements?
these questions will really help you to decide or not to user custom classes.
how to use a custom objects?
the first step is to choose your base class. this will depend on what type of custom object are you willing to implement. basically you need to choose if it will represent an entity or a data object. if it will be an entity you will need to derive it from acdbentity or other of its derived classes. in other hand, if it will not have graphical appearance, you will derive it from acdbobject. there are some objectarx classes that does not allow you to derive from. take a look at objectarx documentation for a complete list.
it is very important to you clearly understand these differences between acdbentity and acdbobject. remember that every acdbentity if also an acdbobject but not all acdbobject is an acdbentity. this is because acdbentity is derived from acdbobject.
i really would like you to walk through the objectarx class hierarchy to locate yourself in that tree and see clearly what are we talking about. there is a dwg file, called classmap.dwg, inside your objectarx sdk folder called \classmap.
runtime identification
autocad requires that every custom class has its own runtime type identification. this will be used by autocad and by your own application. basically you don't need to care about this because there are macros to do this job for you. the acrxobject class is the responsible to perform this feature and exactly due that it is on the top of acrx tree.
the runtime identification is made by some functions like the following:
desc(), a static member function that returns the class descriptor object of a particular (known) class.
cast(), a static member function that returns an object of the specified type, or null if the object is not of the required class (or a derived class).
iskindof() returns whether an object belongs to the specified class (or a derived class).
isa() returns the class descriptor object of an object whose class is unknown.
these functions are pretty useful because they help you to get runtime important information from autocad native objects and your own objects. a good example if when you have a pointer to an acdbentity and would like to know if it is an acdbcircle or an acdbline. how? just use the above functions to get the information or even try to cast the pointer.
to declare these functions you will need to use the following macro inside your class declaration:
acrx_declare_members(class_name);
to implement these functions, you will need to use one of the following macros:
acrx_no_cons_define_members (class_name, parent_class):
use for abstract classes and any other classes that should not be instantiated.
acrx_cons_define_members (class_name, parent_class, verno):
use for transient classes that can be instantiated but are not written to file.
acrx_dxf_define_members (class_name,parent_class, dwg_version, maintenance_version, proxy_flags, dxf_name, app):
use for classes that can be written to, or read from, dwg and dxf files.
additionally, you will need to initialize and delete your custom class from objectarx runtime tree which can be done, during your application's kinitappmsg and kunloadappmsg using the following functions implemented by the above macros:
// inside kinitappmsg function handler
myclass::rxinit();
// call this only once for all of your custom classes
acrxbuildclasshierarchy();
// inside kunloadappmsg function handler
deleteacrxclass(myclass::desc());
this will guarantee that when your application is loaded autocad recognizes your class and when it was not present (unloaded) autocad will transform your class instances into proxy entities. proxy entities are a binary package that protects and preserves your custom object during dwg roundtrip without your application.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】objectarx&dummies教程(三a)——minimum application yang686526 ObjectARX(C++) 0 2009-04-16 10:36 AM
【转帖】objectarx&dummies习题(三)—— creating a custom object yang686526 ObjectARX(C++) 0 2009-04-16 10:33 AM
【转帖】custom properties yang686526 SolidWorks二次开发 0 2009-04-13 10:09 AM
C++风格与技巧(转) huangyhg vc编程 0 2008-10-27 11:03 AM
C++风格与技巧 Faq huangyhg vc编程 0 2007-10-29 02:24 PM


所有的时间均为北京时间。 现在的时间是 10:04 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多