Presentation on theme: "Advanced deepclone API in AutoCAD ® Cyrille Fauvel Autodesk Developer Network ADN Sparks Manager."— Presentation transcript:
Advanced deepclone API in AutoCAD ® Cyrille Fauvel Autodesk Developer Network ADN Sparks Manager
Class Objective You learn AutoCAD deepClone API and cloning techniques Benchmarks, performance and implementation considerations Aspects of controlling cloning operations in AutoCAD We do not discuss and assume knowledge of How to program in.NET or ObjectARX The basics of the AutoCAD.Net or ObjectARX API AutoCAD product usage
About the Presenter Cyrille Fauvel Autodesk Developer Network Cyrille is a member of the M&E workgroup of the Autodesk Developer Network (ADN) team, providing developer support, training, and conference presentations on AutoCAD, RealDWG, Inventor, Maya, 3ds Max, FBX API. He joined Autodesk in 1994 as an AutoCAD developer based in Switzerland and California, USA. Later moved to the Developer Support group, and Consulting division. Cyrille graduated in Mechanics and Electronics in France, worked as a teacher and C++ developer for a 3 rd party developer on AutoCAD. He is fluent in six programming languages, tries to learn Japanese which turns out to be more difficult than learning English, has two kids, plays the guitar and piano, likes reading, love sailing on oceans, sports, and especially hand-ball.
Autodesk Developer Network Access to almost all Autodesk software and SDK’s Includes early access to beta software Members-only website with thousands of technical articles Unlimited technical support Product direction through conferences Marketing benefits Exposure on autodesk.com Promotional opportunities One to three free API training classes Based on user level www.autodesk.com/joinadn
Agenda 1 Overview Cloning! What is it? Why should I care? 2 Basics Shallow Clone, deep Clone & wblock Clone Who is using cloning? 3 API Cloning and ID Translations ObjectARX or.Net? 4 A concrete example Modify the default AutoCAD behavior 5 Additional information Inspect, spy, learning more
Overview Cloning! What is it? Why should I care?
Cloning Cloning in biology is the process of producing similar populations of genetically identical individuals that occurs in nature when organisms such as bacteria, insects or plants reproduce asexually. Cloning in biotechnology refers to processes used to create copies of DNA fragments (molecular cloning), cells (cell cloning), or organisms. The term also refers to the production of multiple copies of a product such as digital media or software.bacteriainsectsplantsasexually biotechnologyDNAmolecular cloningcellsorganisms digital mediasoftware The term clone is derived from κλ ῶ νος, the Greek word for "trunk, branch", referring to the process whereby a new plant can be created from a twig. In horticulture, the spelling clon was used until the twentieth century; the final e came into use to indicate the vowel is a "long o" instead of a "short o". Since the term entered the popular lexicon in a more general context, the spelling clone has been used exclusively.Greekhorticulture
Cloning (disambiguation) Cloning is the process of making an identical copy of something. Cloning may also refer to: Cloning (programming), the copying of a programming object Disk cloning, the copying of the contents of a computer hard disk to a storage medium or file Phone cloning, the transfer of identity between one mobile telephone and another Reduplication, aka "cloning", in linguistics refers to a process by which the root or stem of a word is repeated Molecular cloning, the process of identifying and isolating a specific gene
Cloning Clone is not Copy For this presentation Clone = make a new instance of an object which has the same property’ values of the original object Copy = copy the value of an object property
First user is AutoCAD AutoCAD uses deepClone and/or wblock Copy, Mirror, Array operations Wblock operations Insert operations Explode operation Copy & Paste Entity drag operation Reference editing … Any other plug-ins which want to control cloning operations to: Prevent clones Make sure objects required for a clone will be present Maintain the integrity of a user defined structure across AutoCAD commands …
Basics Shallow Clone, Deep Clone & Wblock Clone Who is using cloning?
Cloning methods Shallow Cloning Copy of a singleton ObjectARX C++ object AcRxObject::clone() RTTI and C++ object copy copyFrom() to copy properties Deep Cloning clones an object and its hard/soft ownership references but do not clone hard/soft pointer referenced objects however, copies the pointer reference values Wblock Cloning clones an object and its hard owner and hard pointer references but ignores any soft references and reset non cloned references to null
'Ownership' and 'Pointer References' 4 types Combination of [ Hard or Soft ] and [ Ownership or Pointer ] Hard Reference required for the object to survive in a database Soft Reference not required (can be ignored depending of the context) Ownership Parent – Child relation ship Pointer Cooperative object the object is referencing for its definition
References ObjectARX AcDbHardOwnershipId AcDbSoftOwnershipId AcDbHardPointerId AcDbSoftPointerId .Net ObjectId No custom objects in.Net Use overrules instead Cloning reference logic follows reference found in the filing protocol dwgInFields() / dwgOutFields()
Object ownership Dictionary Ext. Dict. Object Dictionary Object’ Hard Owner Soft Owner Soft Pointer Hard Pointer
Entity ownership Hard Owner Soft Owner Soft Pointer Hard Pointer Entity Sub Entity
Can we get things more complicated? Entities are objects Hard Owner Soft Owner Soft Pointer Hard Pointer Entity or BTR Sub Entity Sub Entity or Entity Object’ Dictionary Ext. Dict. Object Dictionary Ext. Dict. Object Dictionary Object’ Dictionary Ext. Dict. Object Dictionary Ext. Dict. Object Dictionary Ext. Dict.
Extension dictionary Using extension dictionary can simplify a lot cloning operations, because: The object hard ‘owns’ it extension dictionary versus having to reference an object in the NOD deepClone will find & clone it Wblock will find & clone it as well The extension dictionary hard ‘owns’ its elements deepClone will clone its elements Wblock will clone them as well Sounds a good solution to avoid to think about cloning. Well consider the following: Each DWG object is about ~300b footprint An object with an extension dictionary and an 1 object in it is ~ 1k Make a DWG 3 times bigger with no useful data in yet
Cloning phases Default cloning phase AutoCAD clones objects by following the ID references Application cloning phase AutoCAD may give control to a plug-in to do additional cloning and will follow the ID references as required ID translation phase AutoCAD translate clone IDs to new ID & handles for object in ‘Flux’
In Flux Clones in ‘Flux’ mode, means object being cloned, versus created and mapped to an original object Requires ID translation You cannot intervene during this ID translation process process Use the AcRxEventReactor class for monitoring activities and steps
Primary object If the key object is part of the primary set of objects cloned An object can tell if it's being cloned by referencing or not That's what the isPrimary flag is all about
AcDbObject::deepClone() AcDbObject::wblockClone() Never use AcDbObject::deepClone() or AcDbObject::wblockClone() directly You are missing the context But you can call them in custom object implementation or reactors Instead use Within the same database AcDbDatabase::deepCloneObjects() Across databases AcDbDatabase::wblockCloneObjects() AcDbDatabase::wblock() AcDbDatabase::insert()
API Cloning and ID Translations ObjectARX or.Net?
RefEdit RefEdit uses the wblock() mechanism Checkout Checkin Only modified objects will be clones in checkin See the AcApLongTransactionReactor class void beginCheckOut(AcDbLongTransaction&, AcDbObjectIdArray&); void endCheckOut(AcDbLongTransaction&); void beginCheckIn(AcDbLongTransaction&); void endCheckIn(AcDbLongTransaction&); void abortLongTransaction(AcDbLongTransaction&); Acad::ErrorStatus veto();
Custom objects ObjectARX Only AcDbObject Autodesk.AutoCAD.DatabaseServices.DBObject .Net implements these method, but you cannot override them You can call them in a cloning context/operation API Sealed in ARX now Acad::ErrorStatus deepClone(AcDbObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const; Acad::ErrorStatus wblockClone(AcRxObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const; Use the subXXX() version instead Acad::ErrorStatus subDeepClone(AcDbObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const; Acad::ErrorStatus subWblockClone(AcRxObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const;
Overrule API Overrules registered on per class basis PEX protocol See ‘CP230-1V -.Net Overrule API’ for detailsCP230-1V Can ‘modify’ Draw aspect, Grips, Avoid the need of a custom object
A concrete example Modify the default AutoCAD behavior
ARXCloning sample CLONE1 command Performs a shallow clone of a non-database resident object. CLONE2 command Performs a shallow clone of a database resident object into the same database CLONE3 command Performs a shallow clone of a database resident object to another DWG database Very basic code one simple object such as a line or circle.
OPLine project OPLine1 Custom entity derived from AcDbPolyline And a companion custom object derived from AcDdBObject stored in the NOD OPLine2 Try to replicate the above structure without custom object but using reactors instead OPLine3 Same but using the new overrule API
Bonus The deepClone Inspector tool Monitors deepClone activity in AutoCAD Record object status and cloning steps Shows primary and secondary clones Displays a diagram of the structures (original and clones) Displays differences between the original and target databases
Additional information Inspect, spy, learning more
Learning more CP230-1V -.Net Overrule API CP230-1V CP240-2V CP240-2V AutoCAD.NET: Practical Examples of Customizing AutoCAD Entity Behavior Stephen Preston – Autodesk, Inc.
Learning more AutoCAD API Online Help, Developer's Guide and SDK Samples AutoCAD Developer Center http://www.autodesk.com/developautocad Free DevTV for.NET API http://www.autodesk.com/developautocad Webcasts and Trainings on Programming and News http://www.adskconsulting.com/adn/cs/api_course_sched.php > AutoCAD API http://www.adskconsulting.com/adn/cs/api_course_sched.php Through the Interface http://through-the-interface.typepad.com http://through-the-interface.typepad.com