Update testing cases due to changes of issue 24130
[occt.git] / dox / user_guides / ocaf / ocaf.md
CommitLineData
72b7576f 1OCAF {#user_guides__ocaf}
2========================
3
4@section occt_ocaf_1 Introduction
5
6This manual explains how to use the Open CASCADE Application Framework (OCAF).
7It provides basic documentation on using OCAF. For advanced information on OCAF
8and its applications, see our offerings on our web site at
9<a href="http://www.opencascade.org/support/training/">www.opencascade.org/support/training/</a>
10
11OCAF (the Open CASCADE Application Framework) is a RAD (Rapid Application Development) framework used for
12specifying and organizing application data. To do this, OCAF provides:
13
14 * Ready-to-use data common to most CAD/CAM applications,
15 * A scalable extension protocol for implementing new application specific data,
16 * An infrastructure
17 * To attach any data to any topological element
18 * To link data produced by different applications (*associativity of data*)
19 * To register the modeling process - the creation history, or parametrics, used to carry out the modifications.
20
21Using OCAF, the application designer concentrates on the functionality and its specific algorithms. In this way, he avoids architectural problems notably implementing Undo-redo and saving application data.
22
23In OCAF, all of the above are already handled for the application designer, allowing him to reach a significant increase in productivity.
24
25In this respect, OCAF is much more than just one toolkit among many in the CAS.CADE Object Libraries. Since it can handle any data and algorithms in these libraries - be it modeling algorithms, topology or geometry - OCAF is a logical supplement to these libraries.
26
27The table below contrasts the design of a modeling application using object libraries alone and using OCAF.
28
29**Table 1: Services provided by OCAF**
30
31|Development tasks |Comments | Without OCAF | With OCAF |
32|------------------:|---------:|---------------:|-----------:|
33|Creation of geometry| Algorithm Calling the modeling libraries | To be created by the user | To be created by the user|
34| Data organization | Including specific attributes and modeling process | To be created by the user | Simplified|
35| Saving data in a file | Notion of document | To be created by the user | Provided |
36| Document-view management | | To be created by the user | Provided |
37| Application infrastructure | New, Open, Close, Save and Save As File menus | To be created by the user | Provided |
38| Undo-Redo | Robust, multi-level | To be created by the user | Provided |
39| Application-specific dialog boxes | | To be created by the user | To be created by the user |
40
41
42
43The relationship between OCAF and the Open CASCADE Technology (**OCCT**) Object Libraries can be seen in the image below.
44
dba69de2 45@image html /user_guides/ocaf/images/ocaf_image003.png "OCAF Architecture"
46@image latex /user_guides/ocaf/images/ocaf_image003.png "OCAF Architecture"
72b7576f 47
48In the image, the OCAF (Open CASCADE Application Framework) is shown with black rectangles and OCCT Object Libraries required by OCAF are shown with white rectangles.
49
50The subsequent chapters of this document explain the concepts and show how to use the services of OCAF.
51
52@section occt_ocaf_2 Basic Concepts
53
54@subsection occt_ocaf_2_1 Overview
55
56In most existing geometric modeling systems, the data structure is shape driven. They usually use a brep model, where solids and surfaces are defined by a collection of entities such as faces, edges etc., and by attributes such as application data. These attributes are attached to the entities. Examples of application data include:
57
58 * color,
59 * material,
60 * information that a particular edge is blended.
61
62A shape, however, is inevitably tied to its underlying geometry. And geometry is highly subject to change in applications such as parametric modeling or product development. In this sort of application, using a brep (boundary representation) data structure proves to be a not very effective solution. A solution other than the shape must be found, i.e. a solution where attributes are attached to a deeper invariant structure of the model. Here, the topology itself will be one attribute among many.
63
64In OCAF, data structure is reference key-driven. The reference key is implemented in the form of labels. Application data is attached to these labels as attributes. By means of these labels and a tree structure they are organized in, the reference key aggregates all user data, not just shapes and their geometry. These attributes have similar importance; no attribute is master in respect of the others.
65
66The reference keys of a model - in the form of labels - have to be kept together in a single container. This container is called a document.
67
dba69de2 68@image html /user_guides/ocaf/images/ocaf_image004.png "Topology-driven vs. reference key-driven approaches"
69@image latex /user_guides/ocaf/images/ocaf_image004.png "Topology-driven vs. reference key-driven approaches"
72b7576f 70
71@subsection occt_ocaf_2_2 Applications and documents
72
73OCAF documents are in turn managed by an OCAF application, which is in charge of:
74
75 * Creating new documents
76 * Saving documents and opening them
77 * Initializing document views.
78
79Apart from their role as a container of application data, documents can refer to each other; Document A, for example, can refer to a specific label in Document B. This functionality is made possible by means of the reference key.
80
81@subsection occt_ocaf_23 The document and the data framework
82
83Inside a document, there is a data framework, a model, for example. This is a set of labels organized in a tree structure characterized by the following features:
84 * The first label in a framework is the root of the tree;
85 * Each label has a tag expressed as an integer value;
86 * Sub-labels of a label are called its children;
87 * Each label which is not the root has one father – label from an upper level of the framework;
88 * Labels which have the same father are called brothers;
89 * Brothers cannot share the same tag;
90 * A label is uniquely defined by an entry expressed as a list of tags (entry) of fathers from the root: this list of tags is written from right to left: tag of label, tag of its father, tag of father of its father,..., 0 (tag of the root label).
91
dba69de2 92@image html /user_guides/ocaf/images/ocaf_image005.png "A simple framework model"
93@image latex /user_guides/ocaf/images/ocaf_image005.png "A simple framework model"
72b7576f 94
95In the above figure inside the circles are the tags of corresponding labels. Under the circles are the lists of tags. The root label always has a zero tag.
96
97The children of a root label are middle-level labels with tags 1 and 3. These labels are brothers.
98
dba69de2 99List of tags of the right-bottom label is "0:3:4": this label has tag 4, its father (with entry "0:3") has tag 3, father of father has tag 0 (the root label always has "0" entry).
72b7576f 100
101For example, an application for designing table lamps will first allocate a label for the lamp unit (the lamp is illustrated below). The root label never has brother labels, so, for a lot of lamps in the framework allocation, one of the root label sub-labels for the lamp unit is used. By doing so, you would avoid any confusion between table lamps in the data framework. Parts of the lamp have different material, color and other attributes, so, for each sub-unit of the lamp a child label of the lamp label with specified tags is allocated:
102
103 * a lamp-shade label with tag 1
104 * a bulb label with tag 2
105 * a stem label with tag 3
106
107Label tags are chosen at will. They are just identifiers of the lamp parts. Now you can refine all units: set to the specified label geometry, color, material and other information about the lamp or it’s parts. This information is placed into special attributes of the label: the pure label contains no data – it is only a key to access data.
108
109The thing to remember is that tags are private addresses without any meaning outside the data framework. It would, for instance, be an error to use part names as tags. These might change or be removed from production in next versions of the application, whereas the exact form of that part might be what you wanted to use in your design, the part name could be integrated into the framework as an attribute.
110
dba69de2 111@image html /user_guides/ocaf/images/ocaf_image006.png
112@image latex /user_guides/ocaf/images/ocaf_image006.png
72b7576f 113
114So, after the user changes the lamp design, only corresponding attributes are changed, but the label structure is maintained. The lamp shape must be recreated by new attribute values and attributes of the lamp shape must refer to a new shape.
115
dba69de2 116@image html /user_guides/ocaf/images/ocaf_image007.png
117@image latex /user_guides/ocaf/images/ocaf_image007.png
72b7576f 118
119
120The previous figure shows the table-lamps document structure: each child of the root label contains a lamp shape attribute and refers to the sub-labels, which contain some design information about corresponding sub-units.
121
122The data framework structure allows to create more complex structures: each lamp label sub-label may have children labels with more detailed information about parts of the table lamp and its components.
123
124Note that the root label can have attributes too, usually global attributes: the name of the document, for example.
125
dba69de2 126As in the case of the table lamp example above, OCAF documents aggregate a battery of ready-to-use attributes, which represent typical data used in CAD. This data includes not only the Shape attribute, but a wide range of Standard attributes corresponding to the following types:
72b7576f 127
128 * Geometric attributes
129 * General attributes
130 * Relationship attributes
131 * Auxiliary attributes
132
133@subsubsection occt_ocaf_2_3_1 Documents
134
135Documents offer access to the data framework and manage the following items:
136
137 * Manage the notification of changes
138 * Update external links
139 * Manage the saving and restoring of data
140 * Store the names of software extensions.
141 * Manage command transactions
142 * Manage Undo and Redo options.
143
144@subsubsection occt_ocaf_2_3_2 Shape attribute
145
146The shape attribute implements the functionality of the OCCT topology manipulation:
147
148 * reference to the shapes
149 * tracking of shape evolution
150
151@subsubsection occt_ocaf_2_3_3 Standard attributes
152
153Several ready-to-use base attributes already exist. These allow operating with simple common data in the data framework (for example: integer, real, string, array kinds of data), realize auxiliary functions (for example: tag sources attribute for the children of the label counter), create dependencies (for example: reference, tree node)....
154
155@subsubsection occt_ocaf_2_3_4 Visualization attributes
156
157These attributes allow placing viewer information to the data framework, visual representation of objects and other auxiliary visual information, which is needed for graphical data representation.
158
159@subsubsection occt_ocaf_2_3_5 Function services
160
161Where the document manages the notification of changes, a function manages propagation of these changes. The function mechanism provides links between functions and calls to various algorithms.
162
dba69de2 163@image html /user_guides/ocaf/images/ocaf_image008.png "Document structure"
164@image latex /user_guides/ocaf/images/ocaf_image008.png "Document structure"
72b7576f 165
dba69de2 166@section occt_ocaf_3 Data Framework Services
72b7576f 167
168@subsection occt_ocaf_3_1 Overview
169
170The data framework offers a single environment in which data from different application components can be handled.
171
172This allows you to exchange and modify data simply, consistently, with a maximum level of information, and with stable semantics.
173
174The building blocks of this approach are:
175
176 * The tag
177 * The label
178 * The attribute
179
180As it has been mentioned earlier, the first label in a framework is the root label of the tree. Each label has a tag expressed as an integer value, and a label is uniquely defined by an entry expressed as a list of tags from the root, 0:1:2:1, for example.
181
182Each label can have a list of attributes, which contain data, and several attributes can be attached to a label. Each attribute is identified by a GUID, and although a label may have several attributes attached to it, it must not have more than one attribute of a single GUID.
183
184The sub-labels of a label are called its children. Conversely, each label, which is not the root, has a father. Brother labels cannot share the same tag.
185
186The most important property is that a label’s entry is its persistent address in the data framework.
187
dba69de2 188@image html /user_guides/ocaf/images/ocaf_image009.png "Contents of a document"
189@image latex /user_guides/ocaf/images/ocaf_image009.png "Contents of a document"
72b7576f 190
191@subsection occt_ocaf_3_2 The Tag
192
193A tag is an integer, which identifies a label in two ways:
194
195 * Relative identification
196 * Absolute identification.
197
198In relative identification, a label’s tag has a meaning relative to the father label only. For a specific label, you might, for example, have four child labels identified by the tags 2, 7, 18, 100. In using relative identification, you ensure that you have a safe scope for setting attributes.
199
dba69de2 200In absolute identification, a label’s place in the data framework is specified unambiguously by a colon-separated list of tags of all the labels from the one in question to the root of the data framework. This list is called an entry. *TDF_Tool::TagList* allows retrieving the entry for a specific label.
72b7576f 201
202In both relative and absolute identification, it is important to remember that the value of an integer has no intrinsic semantics whatsoever. In other words, the natural sequence that integers suggest, i.e. 0, 1, 2, 3, 4 ... - has no importance here. The integer value of a tag is simply a key.
203
204The tag can be created in two ways:
205
206 * Random delivery
207 * User-defined delivery
208
209As the names suggest, in random delivery, the tag value is generated by the system in a random manner. In user-defined delivery, you assign it by passing the tag as an argument to a method.
210
211@subsubsection occt_ocaf_3_2_1 Creating child labels using random delivery of tags
212
dba69de2 213To append and return a new child label, you use *TDF_TagSource::NewChild*. In the example below, the argument *level2*, which is passed to *NewChild,* is a *TDF_Label*.
214
72b7576f 215
72b7576f 216~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217TDF_Label child1 = TDF_TagSource::NewChild (level2);
218TDF_Label child2 = TDF_TagSource::NewChild (level2);
219~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220
221@subsubsection occt_ocaf_3_2_2 Creation of a child label by user delivery from a tag
222
223The other way to create a child label from a tag is by user delivery. In other words, you specify the tag, which you want your child label to have.
224
dba69de2 225To retrieve a child label from a tag which you have specified yourself, you need to use *TDF_Label::FindChild* and *TDF_Label::Tag* as in the example below. Here, the integer 3 designates the tag of the label you are interested in, and the Boolean false is the value for the argument *create*. When this argument is set to *false*, no new child label is created.
226
72b7576f 227
72b7576f 228~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229TDF_Label achild = root.FindChild(3,Standard_False);
230if (!achild.IsNull()) {
231Standard_Integer tag = achild.Tag();
232}
233~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234
235@subsection occt_ocaf_3_3 The Label
236
237The tag gives a persistent address to a label. The label – the semantics of the tag – is a place in the data framework where attributes, which contain data, are attached. The data framework is, in fact, a tree of labels with a root as the ultimate father label (refer to the following figure):
238
dba69de2 239@image html /user_guides/ocaf/images/ocaf_image007.png
240@image latex /user_guides/ocaf/images/ocaf_image007.png
72b7576f 241
242
243Label can not be deleted from the data framework, so, the structure of the data framework that has been created can not be removed while the document is opened. Hence any kind of reference to an existing label will be actual while an application is working with the document.
244
245@subsubsection occt_ocaf_3_3_1 Label creation
246
dba69de2 247Labels can be created on any labels, compared with brother labels and retrieved. You can also find their depth in the data framework (depth of the root label is 0, depth of child labels of the root is 1 and so on), whether they have children or not, relative placement of labels, data framework of this label. The class *TDF_Label* offers the above services.
72b7576f 248
249@subsubsection occt_ocaf_3_3_2 Creating child labels
250
dba69de2 251To create a new child label in the data framework using explicit delivery of tags, use *TDF_Label::FindChild*.
252
72b7576f 253
72b7576f 254~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
255//creating a label with tag 10 at Root
256TDF_Label lab1 = aDF->Root().FindChild(10);
257
258//creating labels 7 and 2 on label 10
259TDF_Label lab2 = lab1.FindChild(7);
260
261TDF_Label lab3 = lab1.FindChild(2);
262~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dba69de2 263You could also use the same syntax but add the Boolean *true* as a value of the argument **create**. This ensures that a new child label will be created if none is found. Note that in the previous syntax, this was also the case since **create** is *true* by default.
264
72b7576f 265
72b7576f 266~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
267TDF_Label level1 = root.FindChild(3,Standard_True);
268TDF_Label level2 = level1.FindChild(1,Standard_True);
269~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270@subsubsection occt_ocaf_3_3_3 Retrieving child labels
271
272You can retrieve child labels of your current label by iteration on the first level in the scope of this label.
273
dba69de2 274
72b7576f 275~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
276TDF_Label current;
277//
278for (TDF_ChildIterator it1 (current,Standard_False); it1.More(); it1.Next()) {
279achild = it1.Value();
280//
281// do something on a child (level 1)
282//
283}
284~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285You can also retrieve all child labels in every descendant generation of your current label by iteration on all levels in the scope of this label.
286~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
287for (TDF_ChildIterator itall (current,Standard_True); itall.More(); itall.Next()) {
288achild = itall.Value();
289//
290// do something on a child (all levels)
291//
292}
293~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dba69de2 294Using *TDF_Tool::Entry* with *TDF_ChildIterator* you can retrieve the entries of your current label’s child labels as well.
72b7576f 295
dba69de2 296
72b7576f 297~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
298void DumpChildren(const TDF_Label& aLabel)
299{
300 TDF_ChildIterator it;
301 TCollection_AsciiString es;
302 for (it.Initialize(aLabel,Standard_True); it.More(); it.Next()){
303 TDF_Tool::Entry(it.Value(),es);
304 cout = as.ToCString() = endl;
305 }
306}
307~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308@subsubsection occt_ocaf_3_3_4 Retrieving the father label
309
310Retrieving the father label of a current label.
311
dba69de2 312
72b7576f 313~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
314TDF_Label father = achild.Father();
315isroot = father.IsRoot();
316~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
317@subsection occt_ocaf_3_4 The Attribute
318
319The label itself contains no data. All data of any type whatsoever - application or non-application - is contained in attributes. These are attached to labels, and there are different types for different types of data. OCAF provides many ready-to-use standard attributes such as integer, real, constraint, axis and plane. There are also attributes for topological naming, functions and visualization. Each type of attribute is identified by a GUID.
320
dba69de2 321The advantage of OCAF is that all of the above attribute types are handled in the same way. Whatever the attribute type is, you can create new instances of them, retrieve them, attach them to and remove them from labels, "forget" and "remember" the attributes of a particular label.
72b7576f 322
323@subsubsection occt_ocaf_3_4_1 Retrieving an attribute from a label
324
dba69de2 325To retrieve an attribute from a label, you use *TDF_Label::FindAttribute*. In the example below, the GUID for integer attributes, and *INT*, a handle to an attribute are passed as arguments to *FindAttribute* for the current label.
326
72b7576f 327
72b7576f 328~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
329if(current.FindAttribute(TDataStd_Integer::GetID(),INT))
330{
331 // the attribute is found
332}
333else
334{
335 // the attribute is not found
336}
337~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
338@subsubsection occt_ocaf_3_4_2 Identifying an attribute using a GUID
339
dba69de2 340You can create a new instance of an attribute and retrieve its GUID. In the example below, a new integer attribute is created, and its GUID is passed to the variable *guid* by the method ID inherited from *TDF_Attribute*.
341
72b7576f 342
72b7576f 343~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
344Handle(TDataStd_Integer) INT = new TDataStd_Integer();
345Standard_GUID guid = INT->ID();
346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dba69de2 347
72b7576f 348@subsubsection occt_ocaf_3_4_3 Attaching an attribute to a label
349
dba69de2 350To attach an attribute to a label, you use *TDF_Label::Add*. Repetition of this syntax raises an error message because there is already an attribute with the same GUID attached to the current label.
351
352*TDF_Attribute::Label* for *INT* then returns the label *attach* to which *INT* is attached.
72b7576f 353
72b7576f 354
72b7576f 355~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
356current.Add (INT); // INT is now attached to current
357current.Add (INT); // causes failure
358TDF_Label attach = INT->Label();
359~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
360@subsubsection occt_ocaf_3_4_4 Testing the attachment to a label
361
dba69de2 362You can test whether an attribute is attached to a label or not by using *TDF_Attribute::IsA* with the GUID of the attribute as an argument. In the example below, you test whether the current label has an integer attribute, and then, if that is so, how many attributes are attached to it. *TDataStd_Integer::GetID* provides the GUID argument needed by the method IsAttribute.
363
364*TDF_Attribute::HasAttribute* tests whether there is an attached attribute, and *TDF_Tool::NbAttributes* returns the number of attributes attached to the label in question, e.g. *current*.
72b7576f 365
72b7576f 366
72b7576f 367~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
368// Testing of attribute attachment
369//
370if (current.IsA(TDataStd_Integer::GetID())) {
371// the label has an Integer attribute attached
372}
373if (current.HasAttribute()) {
374// the label has at least one attribute attached
375Standard_Integer nbatt = current.NbAttributes();
376// the label has nbatt attributes attached
377}
378~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
379@subsubsection occt_ocaf_3_4_5 Removing an attribute from a label
380
dba69de2 381To remove an attribute from a label, you use *TDF_Label::Forget* with the GUID of the deleted attribute. To remove all attributes of a label, *TDF_Label::ForgetAll*.
382
72b7576f 383
72b7576f 384~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
385current.Forget(TDataStd_Integer::GetID());
386// integer attribute is now not attached to current label
387current.ForgetAll();
388// current has now 0 attributes attached
389~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
390@subsubsection occt_ocaf_3_4_6 Specific attribute creation
391
dba69de2 392If the set of existing and ready to use attributes implementing standard data types does not cover the needs of a specific data presentation task, the user can build his own data type and the corresponding new specific attribute implementing this new data type.
72b7576f 393
dba69de2 394There are two ways to implement a new data type: create a new attribute (standard approach), or use the notion of User Attribute by means of a combination of standard attributes (alternative way)
72b7576f 395
396In order to create a new attribute in the standard way do the following:
dba69de2 397* Create a class inherited from *TDF_Attribute* and implement all purely virtual and necessary virtual methods:
398 + **ID()** – returns a unique GUID of a given attribute
399 + **Restore(attribute)** – sets fields of this attribute equal to the fields of a given attribute of the same type
400 + **Paste(attribute, relocation_table)** – sets fields of a given attribute equal to the field values of this attribute ; if the attribute has references to some objects of the data framework and relocation_table has this element, then the given attribute must also refer to this object .
401 + **NewEmpty()** - returns a new attribute of this class with empty fields
402 + **Dump(stream)** - outputs information about a given attribute to a given stream debug (usually outputs an attribute of type string only)
72b7576f 403* Create the persistence classes for this attribute according to the file format chosen for the document (see below).
404
dba69de2 405Methods *NewEmpty, Restore* and *Paste* are used for the common transactions mechanism (Undo/Redo commands). If you don’t need this attribute to react to undo/redo commands, you can write only stubs of these methods, else you must call the Backup method of the *TDF_Attribute* class every time attribute fields are changed.
72b7576f 406
407If you use a standard file format and you want your new attributes to be stored during document saving and retrieved to the data framework whenever a document is opened, you must do the following:
408
dba69de2 409 1. If you place an attribute to a new package, it is desirable (although not mandatory) if your package name starts with letter "T" (transient), for example: attribute *TMyAttributePackage_MyAttribute* in the package *TMyAttributePackage*.
410 2. Create a new package with name "P[package name]" (for example *PMyAttributePackage*) with class *PMyAttributePackage_MyAttribute* inside. The new class inherits the *PDF_Attribute* class and contains fields of attributes, which must be saved or retrieved ("P" - persistent).
411 3. Create a new package with name "M[package name]" (for example *MMyAttributePackage*) with classes *MMyAttributePackage_MyAttributeRetrievalDriver* and *MMyAttributePackage_MyAttributeStorageDriver* inside. The new classes inherit *MDF_ARDriver* and *MDF_ASDriver* classes respectively and contain the translation functionality: from T... attribute to P... and vice versa (M - middle) (see the realization of the standard attributes).
412 4. M... package must contain *AddStorageDrivers(aDriverSeq : ASDriverHSequence* from MDF) and *AddRetrievalDrivers(aDriverSeq : ASDriverHSequence* from MDF) methods, which append to the given sequence *<aDriverSeq>* of drivers a sequence of all new attribute drivers (see the previous point), which will be used for the attributes storage/retrieval.
413 5 Use the standard schema (*StdSchema* unit) or create a new one to add your P-package and compile it.
72b7576f 414
415If you use the XML format, do the following:
dba69de2 416 1. Create a new package with the name Xml[package name] (for example *XmlMyAttributePackage*) containing class *XmlMyAttributePackage_MyAttributeDriver*. The new class inherits *XmlMDF_ADriver* class and contains the translation functionality: from transient to persistent and vice versa (see the realization of the standard attributes in the packages *XmlMDataStd*, for example). Add package method AddDrivers which adds your class to a driver table (see below).
417 2. Create a new package (or do it in the current one) with two package methods:
418 * Factory, which loads the document storage and retrieval drivers; and
419 * AttributeDrivers, which calls the methods AddDrivers for all packages responsible for persistence of the document.
420 3. Create a plug-in implemented as an executable (see example *XmlPlugin*). It calls a macro PLUGIN with the package name where you implemented the method Factory.
72b7576f 421If you use the binary format, do the following:
dba69de2 422 1. Create a new package with name Bin[package name] (for example *BinMyAttributePackage*) containing a class *BinMyAttributePackage_MyAttributeDriver*. The new class inherits *BinMDF_ADriver* class and contains the translation functionality: from transient to persistent and vice versa (see the realization of the standard attributes in the packages *BinMDataStd*, for example). Add package method *AddDrivers*, which adds your class to a driver table (see below).
423 2. Create a new package (or do it in the current one) with two package methods:
424 * Factory, which loads the document storage and retrieval drivers; and
425 * AttributeDrivers, which calls the methods AddDrivers for all packages responsible for persistence of the document.
426 3. Create a plug-in implemented as an executable (see example *BinPlugin*). It calls a macro PLUGIN with the package name where you implemented the method Factory.
427See <a href="#occt_ocaf_4_3_3">Saving the document</a> and <a href="#occt_ocaf_4_3_4">Opening the document from a file</a> for the description of document save/open mechanisms.
72b7576f 428
dba69de2 429If you decided to use the alternative way (create a new attribute by means of *UAttribute* and a combination of other standard attributes), do the following:
430 1. Set a *TDataStd_UAttribute* with a unique GUID attached to a label. This attribute defines the semantics of the data type (identifies the data type).
431 2. Create child labels and allocate all necessary data through standard attributes at the child labels.
432 3. Define an interface class for access to the data of the child labels.
72b7576f 433
dba69de2 434Choosing the alternative way of implementation of new data types allows to forget about creating persistence classes for your new data type. Standard persistence classes will be used instead. Besides, this way allows separating the data and the methods for access to the data (interfaces). It can be used for rapid development in all cases when requirements to application performance are not very high.
72b7576f 435
dba69de2 436Let’s study the implementation of the same data type in both ways by the example of transformation represented by *gp_Trsf* class. The class *gp_Trsf* defines the transformation according to the type (*gp_TrsfForm*) and a set of parameters of the particular type of transformation (two points or a vector for translation, an axis and an angle for rotation, and so on).
72b7576f 437
dba69de2 4381. The first way: creation of a new attribute. The implementation of the transformation by creation of a new attribute is represented in the <a href="#occt_ocaf_11">Samples</a>.
72b7576f 439
4402. The second way: creation of a new data type by means of combination of standard attributes. Depending on the type of transformation it may be kept in data framework by different standard attributes. For example, a translation is defined by two points. Therefore the data tree for translation looks like this:
441 * Type of transformation (gp_Translation) as TDataStd_Integer;
442 * First point as TDataStd_RealArray (three values: X1, Y1 and Z1);
443 * Second point as TDataStd_RealArray (three values: X2, Y2 and Z2).
444
dba69de2 445@image html /user_guides/ocaf/images/ocaf_image010.png "Data tree for translation"
446@image latex /user_guides/ocaf/images/ocaf_image010.png "Data tree for translation"
72b7576f 447
448If the type of transformation is changed to rotation, the data tree looks like this:
449 * Type of transformation (gp_Rotation) as TDataStd_Integer;
450 * Point of axis of rotation as TDataStd_RealArray (three values: X, Y and Z);
451 * Axis of rotation as TDataStd_RealArray (three values: DX, DY and DZ);
452 * Angle of rotation as TDataStd_Real.
453
dba69de2 454@image html /user_guides/ocaf/images/ocaf_image011.png "Data tree for rotation"
455@image latex /user_guides/ocaf/images/ocaf_image011.png "Data tree for rotation"
72b7576f 456
457The attribute TDataStd_UAttribute with the chosen unique GUID identifies the data type. The interface class initialized by the label of this attribute allows access to the data container (type of transformation and the data of transformation according to the type).
458
459
460@section occt_ocaf_4_ Standard Document Services
461
462@subsection occt_ocaf_4_1 Overview
463
464Standard documents offer ready-to-use documents containing a TDF-based data framework. Each document can contain only one framework.
465
466The documents themselves are contained in the instantiation of a class inheriting from TDocStd_Application. This application manages the creation, storage and retrieval of documents.
467
468You can implement undo and redo in your document, and refer from the data framework of one document to that of another one. This is done by means of external link attributes, which store the path and the entry of external links.
469
470To sum up, standard documents alone provide access to the data framework. They also allow you to:
471
472 * Update external links
473 * Manage the saving and opening of data
474 * Manage the undo/redo functionality.
475
476
477@subsection occt_ocaf_4_2 The Application
478
dba69de2 479As a container for your data framework, you need a document, and your document must be contained in your application. This application will be a class inheriting from *TDocStd_Application*.
72b7576f 480
481@subsubsection occt_ocaf_4_2_1 Creating an application
482
483To create an application, use the following syntax.
484
72b7576f 485~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
486Handle(TDocStd_Application) app
487= new MyApplication_Application ();
488~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dba69de2 489Note that *MyApplication_Application* is a class, which you have to create and which will inherit from *TDocStd_Application*.
72b7576f 490
491@subsubsection occt_ocaf_4_2_2 Creating a new document
492
dba69de2 493To the application which you declared in the previous example (4.2.1), you must add the document *doc* as an argument of *TDocStd_Application::NewDocument*.
72b7576f 494
72b7576f 495~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
496Handle(TDocStd_Document) doc;
497app->NewDocument("NewDocumentFormat", doc);
498~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dba69de2 499
72b7576f 500@subsubsection occt_ocaf_4_2_3 Retrieving the application to which the document belongs
501
502To retrieve the application containing your document, you use the syntax below.
503
72b7576f 504~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
505app = Handle(TDocStd_Application)::DownCast
506(doc->Application());
507~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
508@subsection occt_ocaf_4_3 The Document
509
510The document contains your data framework, and allows you to retrieve this framework, recover its main label, save it in a file, and open or close this file.
511
512@subsubsection occt_ocaf_4_3_1 Accessing the main label of the framework
513
dba69de2 514To access the main label in the data framework, you use *TDocStd_Document::Main* as in the example below. The main label is the first child of the root label in the data framework, and has the entry 0:1.
72b7576f 515
72b7576f 516~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
517TDF_Label label = doc->Main();
518~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
519@subsubsection occt_ocaf_4_3_2 Retrieving the document from a label in its framework
520
521To retrieve the document from a label in its data framework, you use TDocStd_Document::Get as in the example below. The argument *label *passed to this method is an instantiation of TDF_Label.
72b7576f 522~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
523doc = TDocStd_Document::Get(label);
524~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dba69de2 525
72b7576f 526@subsubsection occt_ocaf_4_3_3 Saving the document
527
528If in your document you use only standard attributes (from the packages TDF, TDataStd, TNaming, TFunction, TPrsStd and TDocStd), you just do the following steps:
529
dba69de2 530* In your application class (which inherits class *TDocStd_Application*) implement two methods:
531 + Formats (TColStd_SequenceOfExtendedString& theFormats), which append to a given sequence <theFormats> your document format string, for example, "NewDocumentFormat" – this string is also set in the document creation command
532 + ResourcesName(), which returns a string with a name of resources file (this file contains a description about the extension of the document, storage/retrieval drivers GUIDs...), for example, "NewFormat"
533* Create the resource file (with name, for example, "NewFormat") with the following strings:
72b7576f 534
535~~~~~
536formatlist:NewDocumentFormat
537NewDocumentFormat: New Document Format Version 1.0
538NewDocumentFormat.FileExtension: ndf
539NewDocumentFormat.StoragePlugin: bd696000-5b34-11d1-b5ba-00a0c9064368
540NewDocumentFormat.RetrievalPlugin: bd696001-5b34-11d1-b5ba-00a0c9064368
541NewDocumentFormatSchema: bd696002-5b34-11d1-b5ba-00a0c9064368
542NewDocumentFormat.AttributeStoragePlugin:57b0b826-d931-11d1-b5da-00a0c9064368
543NewDocumentFormat.AttributeRetrievalPlugin:57b0b827-d931-11d1-b5da-00a0c9064368
544~~~~~
545
dba69de2 546* Create the resource file "Plugin" with GUIDs and corresponding plugin libraries, which looks like this:
72b7576f 547
548**Example**
549~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
550! Description of available plugins
551! ************
552
553b148e300-5740-11d1-a904-080036aaa103.Location: libFWOSPlugin.so
554!
555! standard document drivers plugin
556!
557bd696000-5b34-11d1-b5ba-00a0c9064368.Location: libPAppStdPlugin.so
558bd696001-5b34-11d1-b5ba-00a0c9064368.Location: libPAppStdPlugin.so
559!
560! standard schema plugin
561!
562bd696002-5b34-11d1-b5ba-00a0c9064368.Location: libPAppStdPlugin.so
563!
564! standard attribute drivers plugin
565!
56657b0b826-d931-11d1-b5da-00a0c9064368.Location: libPAppStdPlugin.so
56757b0b827-d931-11d1-b5da-00a0c9064368.Location: libPAppStdPlugin.so
568~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
569
dba69de2 570In order to set the paths for these files it is necessary to set the environments: *CSF_PluginDefaults* and *CSF_NewFormatDefaults*. For example, set the files in the directory *MyApplicationPath/MyResources*:
72b7576f 571
572~~~~~
573setenv CSF_PluginDefaults MyApplicationPath/MyResources
574setenv CSF_NewFormatDefaults MyApplicationPath/MyResources
575~~~~~
576
dba69de2 577Once these steps are taken you may run your application, create documents and Save/Open them. These resource files already exist in the OCAF (format "Standard").
72b7576f 578
dba69de2 579If you use your specific attributes from packages, for example, P-, M- and TMyAttributePackage, see "Specific attribute creation" on page 20; you must take some additional steps for the new plugin implementation:
72b7576f 580
dba69de2 5811. Add our "P" package to the standard schema. You can get an already existing (in Open CASCADE Technology sources) schema from StdSchema unit and add your package string to the cdl-file: "package PMyAttributePackage".
5822. Next step consists of implementation of an executable, which will connect our documents to our application and open/save them. Copy the package PAppStdPlugin and change its name to MyTheBestApplicationPlugin. In the PLUGIN macros type the name of your factory which will be defined in the next step.
5833. Factory is a method, which returns drivers (standard drivers and our defined drivers from the "M" package) by a GUID. Copy the package where the standard factory is defined (it is PAppStd in the OCAF sources). Change its name to MyTheBestSchemaLocation. The Factory() method of the PappStd package checks the GUID set as its argument and returns the corresponding table of drivers. Set two new GUIDs for your determined storage and retrieval drivers. Append two "if" declarations inside the Factory() method which should check whether the set GUID coincides with GUIDs defined by the Factory() method as far as our storage and retrieval drivers are concerned. If the GUID coincides with one of them, the method should return a table of storage or retrieval drivers respectively.
5844. Recompile all. Add the strings with GUIDs – in accordance with your plugin library GUID - to the "Plugin" file.
72b7576f 585
586@subsubsection occt_ocaf_4_3_4 Opening the document from a file
587
588To open the document from a file where it has been previously saved, you use TDocStd_Application::Open as in the example below. The arguments are the path of the file and the document saved in this file.
589
72b7576f 590~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
591app->Open("/tmp/example.caf", doc);
592~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
593
594@subsection occt_ocaf_4_4 External Links
595
dba69de2 596External links refer from one document to another. They allow you to update the copy of data framework later on.
72b7576f 597
dba69de2 598@image html /user_guides/ocaf/images/ocaf_image012.png "External links between documents"
599@image latex /user_guides/ocaf/images/ocaf_image012.png "External links between documents"
72b7576f 600
601Note that documents can be copied with or without a possibility of updating an external link.
602
603@subsubsection occt_ocaf_4_4_1 Copying the document
604
dba69de2 605#### With the possibility of updating it later
72b7576f 606
607To copy a document with a possibility of updating it later, you use TDocStd_XLinkTool::CopyWithLink.
608
72b7576f 609~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
610Handle(TDocStd_Document) doc1;
611Handle(TDocStd_Document) doc2;
612
613TDF_Label source = doc1->GetData()->Root();
614TDF_Label target = doc2->GetData()->Root();
615TDocStd_XLinkTool XLinkTool;
616
617XLinkTool.CopyWithLink(target,source);
618~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
619
620Now the target document has a copy of the source document. The copy also has a link in order to update the content of the copy if the original changes.
621
622In the example below, something has changed in the source document. As a result, you need to update the copy in the target document. This copy is passed to TDocStd_XLinkTool::UpdateLink as the argument *target*.
623
72b7576f 624~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
625XLinkTool.UpdateLink(target);
626~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
627
dba69de2 628#### Without any link between the copy and the original
72b7576f 629
630You can also create a copy of the document with no link between the original and the copy. The syntax to use this option is TDocStd_XLinkTool::Copy; the copied document is again represented by the argument *target*, and the original – by *source.*
631
72b7576f 632~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
633XLinkTool.Copy(target, source);
634
635~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
636
637
638@section occt_ocaf_5_ OCAF Shape Attributes
639@subsection occt_ocaf_5_1 Overview
640
641OCAF shape attributes are used for topology objects and their evolution access. All topological objects are stored in one TNaming_UsedShapes attribute at the root label of the data framework. This attribute contains a map with all topological shapes used in a given document.
642
643The user can add the TNaming_NamedShape attribute to other labels. This attribute contains references (hooks) to shapes from the TNaming_UsedShapes attribute and an evolution of these shapes. The TNaming_NamedShape attribute contains a set of pairs of hooks: to the *Old* shape and to a *New* shape (see the following figure). It allows not only to get the topological shapes by the labels, but also to trace the evolution of the shapes and to correctly update dependent shapes by the changed one.
644
645If a shape is newly created, then the old shape of a corresponding named shape is an empty shape. If a shape is deleted, then the new shape in this named shape is empty.
646
dba69de2 647@image html /user_guides/ocaf/images/ocaf_image013.png
648@image latex /user_guides/ocaf/images/ocaf_image013.png
72b7576f 649
650Different algorithms may dispose sub-shapes of the result shape at the individual labels depending on whether it is necessary to do so:
651
652* If a sub-shape must have some extra attributes (material of each face or color of each edge). In this case a specific sub-shape is placed to a separate label (usually to a sub-label of the result shape label) with all attributes of this sub-shape.
653* If the topological naming algorithm is needed, a necessary and sufficient set of sub-shapes is placed to child labels of the result shape label. As usual, for a basic solid and closed shells, all faces of the shape are disposed.
654
655
656TNaming_NamedShape may contain a few pairs of hooks with the same evolution. In this case the topology shape, which belongs to the named shape is a compound of new shapes.
657
658Consider the following example. Two boxes (solids) are fused into one solid (the result one). Initially each box was placed to the result label as a named shape, which has evolution PRIMITIVE and refers to the corresponding shape of the TNaming_UsedShapes map. The box result label has a material attribute and six child labels containing named shapes of Box faces.
659
dba69de2 660@image html /user_guides/ocaf/images/ocaf_image014.png "Resulting box"
661@image latex /user_guides/ocaf/images/ocaf_image014.png "Resulting box"
72b7576f 662
663After the fuse operation a modified result is placed to a separate label as a named shape, which refers to the old shape – one of the boxes, as well as to the new shape – the shape resulting from the fuse operation – and has evolution MODIFY (see the following figure).
664
665Named shapes, which contain information about modified faces, belong to the fuse result sub-labels: sub-label with tag 1 – modified faces of the first box, sub-label with tag 2 – generated faces of the box 2.
666
dba69de2 667@image html /user_guides/ocaf/images/ocaf_image015.png
668@image latex /user_guides/ocaf/images/ocaf_image015.png
72b7576f 669
670This is necessary and sufficient information for the functionality of the right naming mechanism: any sub-shape of the result can be identified unambiguously by name type and set of labels, which contain named shapes:
671
dba69de2 672 * face F1’ as a modification of F11 face
72b7576f 673 * face F1’’ as generation of F12 face
674 * edges as an intersection of two contiguous faces
675 * vertices as an intersection of three contiguous faces
676
677After any modification of source boxes the application must automatically rebuild the naming entities: recompute the named shapes of the boxes (solids and faces) and fuse the resulting named shapes (solids and faces) that reference to the new named shapes.
678
679@subsection occt_ocaf_5_2 Services provided
680
681@subsubsection occt_ocaf_5_2_1 Registering shapes and their evolution
682
683When using TNaming_NamedShape to create attributes, the following fields of an attribute are filled:
684
dba69de2 685* A list of shapes called the "old" and the "new" shapes A new shape is recomputed as the value of the named shape. The meaning of this pair depends on the type of evolution.
72b7576f 686* The type of evolution: a term of the TNaming_Evolution enumeration:
687* PRIMITIVE – newly created topology, with no previous history
dba69de2 688* GENERATED – as usual, this evolution of a named shape means, that the new shape is created from a low-level old shape ( a prism face from an edge, for example )
72b7576f 689* MODIFY – the new shape is a modified old shape
690* DELETE – the new shape is empty; the named shape with this evolution just indicates that the old shape topology is deleted from the model
dba69de2 691* SELECTED – a named shape with this evolution has no effect on the history of the topology; it is
72b7576f 692used for the selected shapes that are placed to the separate label
693
694Only pairs of shapes with equal evolution can be stored in one named shape.
695
696@subsubsection occt_ocaf_5_2_2 Using naming resources
697
698The class TNaming_Builder allows you to create a named shape attribute. It has a label of a future attribute as an argument of the constructor. Respective methods are used for the evolution and setting of shape pairs. If for the same TNaming_Builder object a lot of pairs of shapes with the same evolution are given, then these pairs would be placed in the resulting named shape. After the creation of a new object of the TNaming_Builder class, an empty named shape is created at the given label.
699
72b7576f 700~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
dba69de2 701// a new empty named shape is created at "label"
72b7576f 702TNaming_Builder builder(label);
703// set a pair of shapes with evolution GENERATED
704builder.Generated(oldshape1,newshape1);
705// set another pair of shapes with the same evolution
706builder.Generated(oldshape2,newshape2);
707// get the result – TNaming_NamedShape attribute
708Handle(TNaming_NamedShape) ns = builder.NamedShape();
709~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
710@subsubsection occt_ocaf_5_2_3 Reading the contents of a named shape attribute
711
dba69de2 712You can use TNaming_NamedShape class to get evolution of this named shape (method TNaming_NamedShape::Evolution()) and "value" of the named shape – compound of new shapes of all pairs of this named shape (method TNaming_NamedShape::Get()).
713
72b7576f 714More detailed information about the contents of the named shape or about the modification history of a topology can be obtained with the following:
715
716* TNaming_Tool provides a common high-level functionality for access to the named shapes contents:
717* GetShape(Handle(TNaming_NamedShape)) method returns a compound of new shapes of the given named shape
718* CurrentShape(Handle(TNaming_NamedShape)) method returns a compound of the shapes – last modifications ( latest versions ) of the shapes from the given named shape
719* NamedShape(TopoDS_Shape,TDF_Label) method returns a named shape, which contains a given shape as a new shape. Given label is any label from the data framework – it just gives access to it
720* TNaming_Iterator given access to the named shape hooks pairs.
721
72b7576f 722~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
723// create an iterator for a named shape
724TNaming_Iterator iter(namedshape);
725// iterate while some pairs are not iterated
726while(iter.More()) {
727// get the new shape from the current pair
728TopoDS_Shape newshape = iter.NewShape();
729// get the old shape from the current pair
730TopoDS_Shape oldshape = iter.OldShape();
731// do something...
732
733// go to the next pair
734iter.Next();
735}
736~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
737
738
739@subsubsection occt_ocaf_5_2_4 Selection Mechanism
740
741One of user interfaces for topological naming resources is the TNaming_Selector class. You can use this class to:
742
743 * Store a selected shape on a label
744 * Access the named shape
745 * Update this naming
746
dba69de2 747Selector places a new named shape with evolution SELECTED to the given label. By the given context shape (main shape, which contains a selected sub-shape), its evolution and naming structure the selector creates a "name" of the selected shape – unique description how to find a selected topology.
72b7576f 748
749After any modification of a context shape and updating of the corresponding naming structure, you must call the TNaming_Selector::Solve method. If the naming structure is right, then the selector automatically updates the selected shape in the corresponding named shape, else it fails.
750
751@subsubsection occt_ocaf_5_2_5 Exploring shape evolution
752
753The class TNaming_Tool provides a toolkit to read current data contained in the attribute.
754
755If you need to create a topological attribute for existing data, use the method NamedShape.
756
72b7576f 757~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
758class MyPkg_MyClass
759{
760public: Standard_Boolean SameEdge (const Handle(CafTest_Line)& L1, const Handle(CafTest_Line)& L2);
761};
762
763Standard_Boolean CafTest_MyClass::SameEdge (const Handle(CafTest_Line)& L1, const Handle(CafTest_Line)& L2)
764{
765 Handle(TNaming_NamedShape) NS1 = L1->NamedShape();
766 Handle(TNaming_NamedShape) NS2 = L2->NamedShape();
767 return BRepTools::Compare(NS1,NS2);
768}
769~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
770
771@section occt_ocaf_6_ Standard Attributes
772
773@subsection occt_ocaf_6_1 Overview
774
775There are several ready-to-use attributes, which allow creating and modifying attributes for many basic data types. They are available in the packages TDataStd, TDataXtd and TDF. Each attribute belongs to one of four types:
776
777 * Geometric attributes
778 * General attributes
779 * Relationship attributes
780 * Auxiliary attributes
781
dba69de2 782### Geometric attributes
783
72b7576f 784
785 * Axis – simply identifies, that the concerned TNaming_NamedShape attribute with an axis shape inside belongs to the same label
dba69de2 786 * Constraint – contains information about a constraint between geometries: used geometry attributes, type, value (if exists), plane (if exists), "is reversed", "is inverted" and "is verified" flags
72b7576f 787 * Geometry – simply identifies, that the concerned TNaming_NamedShape attribute with a specified-type geometry belongs to the same label
788 * Plane – simply identifies, that the concerned TNaming_NamedShape attribute with a plane shape inside belongs to the same label
dba69de2 789 * Point – simply identifies, that the concerned TNaming_NamedShape attribute with a point shape inside belongs to the same label
72b7576f 790 * Shape – simply identifies, that the concerned TNaming_NamedShape attribute belongs to the same label
dba69de2 791 * PatternStd – identifies one of five available pattern models (linear, circular, rectangular, circular rectangular and mirror)
72b7576f 792 * Position – identifies the position in 3d global space
793
dba69de2 794### General attributes
795
72b7576f 796
797 * AsciiString – contains AsciiString value
798 * BooleanArray – contains an array of Boolean
799 * BooleanList – contains a list of Boolean
800 * ByteArray – contains an array of Byte (unsigned char) values
801 * Comment – contains a string – some comment for a given label (or attribute)
802 * Expression – contains an expression string and a list of used variables attributes
803 * ExtStringArray – contains an array of ExtendedString values
804 * ExtStringList – contains a list of ExtendedString values
805 * Integer – contains an integer value
dba69de2 806 * IntegerArray – contains an array of integer values
72b7576f 807 * IntegerList – contains a list of integer values
808 * IntPackedMap – contains a packed map of integers
809 * Name – contains a string – some name of a given label (or attribute)
810 * NamedData – may contain up to 6 of the following named data sets (vocabularies): DataMapOfStringInteger, DataMapOfStringReal, DataMapOfStringString, DataMapOfStringByte, DataMapOfStringHArray1OfInteger, DataMapOfStringHArray1OfReal
811 * NoteBook – contains a NoteBook object attribute
812 * Real – contains a real value
dba69de2 813 * RealArray – contains an array of real values
814 * RealList – contains a list of real values
72b7576f 815 * Relation – contains a relation string and a list of used variables attributes
816 * Tick – defines a boolean attribute
dba69de2 817 * Variable – simply identifies, that a variable belongs to this label; contains the "is constraint" flag and a string of used units ("mm", "m"...)
72b7576f 818 * UAttribute – attribute with a user-defined GUID. As a rule, this attribute is used as a marker, which is independent of attributes at the same label (note, that attributes with the same GUIDs can not belong to the same label)
819
dba69de2 820### Relationship attributes
821
72b7576f 822
823 * Reference – contains reference to the label of its own data framework
824 * ReferenceArray – contains an array of references
825 * ReferenceList – contains a list of references
826 * TreeNode – this attribute allows to create an internal tree in the data framework; this tree consists of nodes with the specified tree ID; each node contains references to the father, previous brother, next brother, first child nodes and tree ID.
827
dba69de2 828### Auxiliary attributes
829
72b7576f 830 * Directory – hi-level tool attribute for sub-labels management
831 * TagSource – this attribute is used for creation of new children: it stores the tag of the last-created child of the label and gives access to the new child label creation functionality.
832
833All of these attributes inherit class TDF_Attribute, so, each attribute has its own GUID and standard methods for attribute creation, manipulation, getting access to the data framework.
834
835
836@subsection occt_ocaf_6_2 Services common to all attributes
837
838@subsubsection occt_ocaf_6_2_1 Accessing GUIDs
839
840To access the GUID of an attribute, you can use two methods:
841
dba69de2 842 * Method *GetID* is the static method of a class. It returns the GUID of any attribute, which is an object of a specified class (for example, TDataStd_Integer returns the GUID of an integer attribute). Only two classes from the list of standard attributes do not support these methods: TDataStd_TreeNode and TDataStd_Uattribute, because the GUIDs of these attributes are variable.
843 * Method *ID* is the method of an object of an attribute class. It returns the GUID of this attribute. Absolutely all attributes have this method: only by this identifier you can discern the type of an attribute.
72b7576f 844
845@subsubsection occt_ocaf_6_2_2 Conventional Interface of Standard Attributes
846
847It is usual to create standard named methods for the attributes:
848
dba69de2 849 * Method *Set(label, [value])* is the static method, which allows to add an attribute to a given label. If an attribute is characterized by one value this method may set it.
850 * Method *Get()* returns the value of an attribute if it is characterized by one value.
851 * Method *Dump(Standard_OStream)* outputs debug information about a given attribute to a given stream.
72b7576f 852
dba69de2 853@section occt_ocaf_7 Visualization Attributes
72b7576f 854
855@subsection occt_ocaf_7_1 Overview
856
857Standard visualization attributes implement the Application Interactive Services (see Open CASCADE Technology Visualization User’s Guide) in the context of Open CASCADE Technology Application Framework. Standard visualization attributes are AISViewer and Presentation and belong to the TPrsStd package.
858
859@subsection occt_ocaf_7_2 Services provided
860
861@subsubsection occt_ocaf_7_2_1 Defining an interactive viewer attribute
862
dba69de2 863The class TPrsStd_AISViewer allows you to define an interactive viewer attribute. There may be only one such attribute per one data framework and it is always placed to the root label. So, it could be set or found by any label ("access label") of the data framework. Nevertheless the default architecture can be easily extended and the user can manage several Viewers per one framework by himself.
72b7576f 864
865To initialize the AIS viewer as in the example below, use method Find.
866
72b7576f 867~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
dba69de2 868// "access" is any label of the data framework
72b7576f 869Handle(TPrsStd_AISViewer) viewer = TPrsStd_AISViewer::Find(access)
870~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
871
872@subsection occt_ocaf_7_2_2 Defining a presentation attribute
873
dba69de2 874The class TPrsStd_AISPresentation allows you to define the visual presentation of document labels contents. In addition to various visual fields (color, material, transparency, "isDisplayed", etc.), this attribute contains its driver GUID. This GUID defines the functionality, which will update the presentation every time when needed.
72b7576f 875
876@subsubsection occt_ocaf_7_2_3 Creating your own driver
877
878The abstract class TPrsStd_Driver allows you to define your own driver classes. Simply redefine the Update method in your new class, which will rebuild the presentation.
879
880If your driver is placed to the driver table with the unique driver GUID, then every time the viewer updates presentations with a GUID identical to your driver’s GUID, the Update method of your driver for these presentations must be called:
dba69de2 881@image html /user_guides/ocaf/images/ocaf_image016.png
882@image latex /user_guides/ocaf/images/ocaf_image016.png
72b7576f 883
884As usual, the GUID of a driver and the GUID of a displayed attribute are the same.
885
886@subsubsection occt_ocaf_7_2_4 Using a container for drivers
887
888You frequently need a container for different presentation drivers. The class TPrsStd_DriverTable provides this service. You can add a driver to the table, see if one is successfully added, and fill it with standard drivers.
889
890To fill a driver table with standard drivers, first initialize the AIS viewer as in the example above, and then pass the return value of the method InitStandardDrivers to the driver table returned by the method Get. Then attach a TNaming_NamedShape to a label and set the named shape in the presentation attribute using the method Set. Then attach the presentation attribute to the named shape attribute, and the AIS_InteractiveObject, which the presentation attribute contains, will initialize its drivers for the named shape. This can be seen in the example below.
891
892**Example**
893~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
894DriverTable::Get() -> InitStandardDrivers();
895// next, attach your named shape to a label
896TPrsStd_AISPresentation::Set(NS};
897// here, attach the AISPresentation to NS.
898~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
899
dba69de2 900@section occt_ocaf_8 Function Services
72b7576f 901
902Function services aggregate data necessary for regeneration of a model. The function mechanism - available in the package TFunction - provides links between functions and any execution algorithms, which take their arguments from the data framework, and write their results inside the same framework.
903
904When you edit any application model, you have to regenerate the model by propagating the modifications. Each propagation step calls various algorithms. To make these algorithms independent of your application model, you need to use function services.
905
906Take, for example, the case of a modeling sequence made up of a box with the application of a fillet on one of its edges. If you change the height of the box, the fillet will need to be regenerated as well.
907
dba69de2 908@subsection occt_ocaf_8_1 Finding functions, their owners and roots
72b7576f 909
910The class TFunction_Function is an attribute, which stores a link to a function driver in the data framework. In the static table TFunction_DriverTable correspondence links between function attributes and drivers are stored.
911
912You can write your function attribute, a driver for such attribute (which updates the function result in accordance to a given map of changed labels), and set your driver with the GUID to the driver table.
913
914Then the solver algorithm of a data model can find the Function attribute on a corresponding label and call the Execute driver method to update the result of the function.
915
dba69de2 916@subsection occt_ocaf_8_2 Storing and accessing information about function status
72b7576f 917
918For updating algorithm optimization, each function driver has access to the TFunction_Logbook object that is a container for a set of touched, impacted and valid labels. Using this object a driver gets to know which arguments of the function were modified.
919
dba69de2 920@subsection occt_ocaf_8_3 Propagating modifications
72b7576f 921
922An application must implement its functions, function drivers and the common solver for parametric model creation. For example, check the following model (see the following illustration):
923
dba69de2 924@image html /user_guides/ocaf/images/ocaf_image017.png
925@image latex /user_guides/ocaf/images/ocaf_image017.png
72b7576f 926
927The procedure of its creation is as follows:
928 * create a rectangular planar face F with height 100 and width 200
929 * create prism P using face F as a basis
930 * create fillet L at the edge of the prism
931 * change the width of F from 200 to 300:
932 * the solver for the function of face F starts
933 * the solver detects that an argument of the face *F* function has been modified
dba69de2 934 * the solver calls the driver of the face F function for a regeneration of the face
72b7576f 935 * the driver rebuilds face F and adds the label of the face *width* argument to the logbook as touched and the label of the function of face F as impacted
936
937 * the solver detects the function of P – it depends on the function of F
938 * the solver calls the driver of the prism P function
dba69de2 939 * the driver rebuilds prism P and adds the label of this prism to the logbook as impacted
940 * the solver detects the function of L – it depends on the function of P
72b7576f 941 * the solver calls the L function driver
942 * the driver rebuilds fillet L and adds the label of the fillet to the logbook as impacted
943
944@section occt_ocaf_9 XML Support
945
946Writing and reading XML files in OCCT is provided by LDOM package, which constitutes an integral part
947of XML OCAF persistence, which is the optional component provided on top of Open CASCADE Technology.
948
949The Light DOM (LDOM) package contains classes maintaining a data structure whose main principles conform to W3C DOM Level 1 Recommendations. The purpose of these classes as required by XML OCAF persistence schema is to:
950* Maintain a tree structure of objects in memory representing the XML document. The root of the structure is an object of the LDOM_Document type. This object contains all the data corresponding to a given XML document and contains one object of the LDOM_Element type named "document element". The document element contains other LDOM_Element objects forming a tree. Other types of nodes (LDOM_Attr, LDOM_Text, LDOM_Comment, LDOM_CDATASection) represent the corresponding XML types and serve as branches of the tree of elements.
951* Provide class LDOM_Parser to read XML files and convert them to LDOM_Document objects.
952* Provide class LDOM_XmlWriter to convert LDOM_Document to a character stream in XML format and store it in file.
953
954This package covers the functionality provided by numerous products known as "DOM parsers". Unlike most of them, LDOM was specifically developed to meet the following requirements:
955* To minimize the virtual memory allocated by DOM data structures. In average, the amount of memory of LDOM is the same as the XML file size (UTF-8).
956* To minimize the time required for parsing and formatting XML, as well as for access to DOM data structures.
957
958Both these requirements are important when XML files are processed by applications if these files are relatively large (occupying megabytes and even hundreds of megabytes). To meet the requirements, some limitations were imposed on the DOM Level 1 specification; these limitations are insignificant in applications like OCAF. Some of these limitations can be overridden in the course of future developments. The main limitations are:
959* No Unicode support as well as various other encodings; only ASCII strings are used in DOM/XML. Note: There is a data type TCollection_ExtendedString for wide character data. This type is supported by LDOM_String as a sequence of numbers.
960* Some superfluous methods are deleted: getPreviousSibling, getParentNode, etc.
961* No resolution of XML Entities of any kind
962* No support for DTD: the parser just checks for observance of general XML rules and never validates documents.
963* Only 5 available types of DOM nodes: LDOM_Element, LDOM_Attr, LDOM_Text, LDOM_Comment, LDOM_CDATASection.
964* No support of Namespaces; prefixed names are used instead of qualified names.
965* No support of the interface DOMException (no exception when attempting to remove a non-existing node).
966
967LDOM is dependent on Kernel OCCT classes only. Therefore, it can be used outside OCAF persistence in various algorithms where DOM/XML support may be required.
968
969@subsection occt_ocaf_9_1 Document Drivers
970
971The drivers for document storage and retrieval manage conversion between a transient OCAF
972Document in memory and its persistent reflection in a container (disk, memory, network ...). For XML Persistence, they are defined in the package XmlDrivers.
973
974The main methods (entry points) of these drivers are:
975* *Write()* - for a storage driver;
976* *Read()* - for a retrieval driver.
977
978The most common case (which is implemented in XML Persistence) is writing/reading document to/from a regular OS file. Such conversion is performed in two steps:
979
980First it is necessary to convert the transient document into another form (called persistent), suitable for writing into a file, and vice versa.
981In XML Persistence LDOM_Document is used as the persistent form of an OCAF Document and the DOM_Nodes are the persistent objects.
982An OCAF Document is a tree of labels with attributes. Its transformation into a persistent form can be functionally divided into two parts:
983* Conversion of the labels structure, which is performed by the method XmlMDF::FromTo()
984* Conversion of the attributes and their underlying objects, which is performed by the corresponding attribute drivers (one driver per attribute type).
985
986The driver for each attribute is selected from a table of drivers, either by attribute
987type (on storage) or by the name of the corresponding DOM_Element (on retrieval).
988The table of drivers is created by by methods *XmlDrivers_DocumentStorageDriver::AttributeDrivers()*
989and *XmlDrivers_DocumentRetrievalDriver::AttributeDrivers()*.
990
991Then the persistent document is written into a file (or read from a file).
992In standard persistence Storage and FSD packages contain classes for writing/reading the persistent document into a file. In XML persistence LDOMParser and LDOM_XmlWriter are used instead.
993
994Usually, the library containing document storage and retrieval drivers is loaded at run time by a plugin mechanism. To support this in XML Persistence, there is a plugin XmlPlugin and a Factory()method in the XmlDrivers package. This method compares passed GUIDs with known GUIDs and returns the corresponding driver or generates an exception if the GUID is unknown.
995
996The application defines which GUID is needed for document storage or retrieval and in which library it should be found. This depends on document format and application resources. Resources for XML Persistence and also for standard persistence are found in the StdResource unit. They are written for the XmlOcaf document format.
997
998@subsection occt_ocaf_9_2 Attribute Drivers
999
1000There is one attribute driver for XML persistence for each transient attribute from a set of standard OCAF attributes, with the exception of attribute types, which are never stored (pure transient). Standard OCAF attributes are collected in six packages, and their drivers also follow this distribution. Driver for attribute T*_* is called XmlM*_*. Conversion between transient and persistent form of attribute is performed by two methods Paste() of attribute driver.
1001
1002*XmlMDF_ADriver* is the root class for all attribute drivers.
1003
1004At the beginning of storage/retrieval process, one instance of each attribute driver is created and appended to driver table implemented as XmlMDF_ADriverTable. During OCAF Data storage, attribute drivers are retrieved from the driver table by the type of attribute. In the retrieval step, a data map is created linking names of DOM_Elements and attribute drivers, and then attribute drivers are sought in this map by DOM_Element qualified tag names.
1005
1006Every transient attribute is saved as a DOM_Element (root element of OCAF attribute) with attributes and possibly sub-nodes. The name of the root element can be defined in the attribute driver as a string passed to the base class constructor. The default is the attribute type name. Similarly, namespace prefixes for each attribute can be set. There is no default value, but it is possible to pass NULL or an empty string to store attributes without namespace prefixes.
1007
1008The basic class XmlMDF_ADriver supports errors reporting via the method *WriteMessage(const TCollection_ExtendedString&)*. It sends a message string to its message driver which is initialized in the constructor with a Handle(CDM_MessageDriver) passed from the application by Document Storage/Retrieval Driver.
1009
1010@subsection occt_ocaf_9_3 XML Document Structure
1011
1012Every XML Document has one root element, which may have attributes and contain other nodes. In OCAF XML Documents the root element is named "document" and has attribute "format" with the name of the OCAF Schema used to generate the file. The standard XML format is "XmlOcaf". The following elements are sub-elements of <document> and should be unique entries as its sub-elements, in a specific order. The order is:
1013* **Element info** - contains strings identifying the format version and other parameters of the OCAF XML document. Normally, data under the element is used by persistence algorithms to correctly retrieve and initialize an OCAF document. The data also includes a copyright string.
1014* **Element comments** - consists of an unlimited number of <comment> sub-elements containing necessary comment strings.
1015* **Element label** is the root label of the document data structure, with the XML attribute "tag" equal to 0. It contains all the OCAF data (labels, attributes) as tree of XML elements. Every sub-label is identified by a tag (positive integer) defining a unique key for all sub-labels of a label. Every label can contain any number of elements representing OCAF attributes (see OCAF Attributes Representation below).
1016* **Element shapes** - contains geometrical and topological entities in BRep format. These entities being referenced by OCAF attributes written under the element <label>. This element is empty if there are no shapes in the document. It is only output if attribute driver XmlMNaming_NamedShapeDriver has been added to drivers table by the DocumentStorageDriver.
1017
dba69de2 1018### OCAF Attributes Representation
72b7576f 1019
1020In XML documents, OCAF attributes are elements whose name identifies the OCAF attribute type. These elements may have a simple (string or number) or complex (sub-elements) structure, depending on the architecture of OCAF attribute. Every XML type for OCAF attribute possesses a unique positive integer "id" XML attribute identifying the OCAF attribute throughout the document. To ensure "id" uniqueness, the attribute name "id" is reserved and is only used to indicate and identify elements which may be referenced from other parts of the OCAF XML document.
1021For every standard OCAF attribute, its XML name matches the name of a C++ class in Transient data model. Generally, the XML name of OCAF attribute can be specified in the corresponding attribute driver.
1022XML types for OCAF attributes are declared with XML W3C Schema in a few XSD files where OCAF attributes are grouped by the package where they are defined.
1023
dba69de2 1024### Example of resulting XML file
1025
72b7576f 1026The following example is a sample text from an XML file obtained by storing an OCAF document with two labels (0: and 0:2) and two attributes - TDataStd_Name (on label 0:) and TNaming_NamedShape (on label 0:2). The <shapes> section contents are replaced by an ellipsis.
1027
1028~~~~~
1029<?xml version="1.0" encoding="UTF-8"?>
1030<document format="XmlOcaf" xmlns="http://www.opencascade.org/OCAF/XML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1031xsi:schemaLocation="http://www.opencascade.org/OCAF/XML http://www.opencascade.org/OCAF/XML/XmlOcaf.xsd">
1032
1033<info date="2001-10-04" schemav="0" objnb="3">
1034<iitem>Copyright: Open Cascade, 2001</iitem>
1035<iitem>STORAGE_VERSION: PCDM_ReadWriter_1</iitem>
1036<iitem>REFERENCE_COUNTER: 0</iitem>
1037<iitem>MODIFICATION_COUNTER: 1</iitem>
1038</info>
1039<comments/>
1040<label tag="0">
1041<TDataStd_Name id="1">Document_1</TDataStd_Name>
1042<label tag="2">
1043<TNaming_NamedShape id="2" evolution="primitive">
1044<olds/>
1045<news>
1046<shape tshape="+34" index="1"/>
1047</news>
1048</TNaming_NamedShape>
1049</label>
1050</label>
1051<shapes>
1052...
1053</shapes>
1054</document>
1055
1056~~~~~
1057
1058@subsection occt_ocaf_9_4 XML Schema
1059
1060The XML Schema defines the class of a document.
1061
1062The full structure of OCAF XML documents is described as a set of XML W3C Schema files with definitions of all XML element types. The definitions provided cannot be overridden. If any application defines new persistence schemas, it can use all the definitions from the present XSD files but if it creates new or redefines existing types, the definition must be done under other namespace(s).
1063
1064There are other ways to declare XML data, different from W3C Schema, and it should be possible to use them to the extent of their capabilities of expressing the particular structure and constraints of our XML data model. However, it must be noted that the W3C Schema is the primary format for declarations and as such, it is the format supported for future improvements of Open CASCADE Technology, including the development of specific applications using OCAF XML persistence.
1065
1066The Schema files (XSD) are intended for two purposes:
1067* documenting the data format of files generated by OCAF;
1068* validation of documents when they are used by external (non-OCAF) applications, e.g., to generate reports.
1069
1070The Schema definitions are not used by OCAF XML Persistence algorithms when saving and restoring XML documents. There are internal checks to ensure validity when processing every type of data.
1071
dba69de2 1072### Management of Namespaces
1073
72b7576f 1074Both the XML format and the XML OCAF persistence code are extensible in the sense that every new development can reuse everything that has been created in previous projects. For the XML format, this extensibility is supported by assigning names of XML objects (elements) to different XML Namespaces. Hence, XML elements defined in different projects (in different persistence libraries) can easily be combined into the same XML documents. An example is the XCAF XML persistence built as an extension to the Standard OCAF XML persistence [File XmlXcaf.xsd]. For the correct management of Namespaces it is necessary to:
dba69de2 1075* Define *targetNamespace* in the new XSD file describing the format.
72b7576f 1076* Declare (in XSD files) all elements and types in the targetNamespace to appear without a namespace prefix; all other elements and types use the appropriate prefix (such as "ocaf:").
dba69de2 1077* Add (in the new *DocumentStorageDriver*) the *targetNamespace* accompanied with its prefix, using method *XmlDrivers_DocumentStorageDriver::AddNamespace*. The same is done for all namespaces objects which are used by the new persistence, with the exception of the "ocaf" namespace.
1078* Pass (in every OCAF attribute driver) the namespace prefix of the *targetNamespace* to the constructor of *XmlMDF_ADriver*.
72b7576f 1079
1080@section occt_ocaf_10 GLOSSARY
1081
dba69de2 1082* **Application** - a document container holding all documents containing all application data.
1083* **Application data** - the data produced by an application, as opposed to data referring to it.
1084* **Associativity of data** - the ability to propagate modifications made to one document to other documents, which refer to such document. Modification propagation is:
72b7576f 1085 * unidirectional, that is, from the referenced to the referencing document(s), or
1086 * bi-directional, from the referencing to the referenced document and vice-versa.
dba69de2 1087* **Attribute** - a container for application data. An attribute is attached to a label in the hierarchy of the data framework.
1088* **Child** - a label created from another label, which by definition, is the father label.
1089* **Compound document** - a set of interdependent documents, linked to each other by means of external references. These references provide the associativity of data.
1090* **Data framework** - a tree-like data structure which in OCAF, is a tree of labels with data attached to them in the form of attributes. This tree of labels is accessible through the services of the *TDocStd_Document* class.
1091* *Document* - a container for a data framework which grants access to the data, and is, in its turn, contained by an application. A document also allows you to:
1092 * Manage modifications, providing Undo and Redo functions
1093 * Manage command transactions
1094 * Update external links
1095 * Manage save and restore options
1096 * Store the names of software extensions.
1097* **Driver** - an abstract class, which defines the communications protocol with a system.
1098* **Entry** - an ASCII character string containing the tag list of a label.
1099
72b7576f 1100
72b7576f 1101~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
11020:3:24:7:2:7
1103~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1104
dba69de2 1105* **External links** - references from one data structure to another data structure in another document.
72b7576f 1106To store these references properly, a label must also contain an external link attribute.
dba69de2 1107* **Father** - a label, from which other labels have been created. The other labels are, by definition, the children of this label.
1108* **Framework** - a group of co-operating classes which enable a design to be re-used for a given category of problem. The framework guides the architecture of the application by breaking it up into abstract classes, each of which has different responsibilities and collaborates in a predefined way. Application developer creates a specialized framework by:
72b7576f 1109
1110 * defining new classes which inherit from these abstract classes
1111 * composing framework class instances
1112 * implementing the services required by the framework.
1113
1114In C++, the application behavior is implemented in virtual functions redefined in these derived classes. This is known as overriding.
1115
dba69de2 1116* **GUID** - Global Universal ID. A string of 37 characters intended to uniquely identify an object.
72b7576f 1117
72b7576f 1118~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
11192a96b602-ec8b-11d0-bee7-080009dc3333
1120~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1121
dba69de2 1122* **Label** - a point in the data framework, which allows data to be attached to it by means of attributes. It has a name in the form of an entry, which identifies its place in the data framework.
1123* **Modified label** - containing attributes whose data has been modified.
1124* **Reference key** - an invariant reference, which may refer to any type of data used in an application. In its transient form, it is a label in the data framework, and the data is attached to it in the form of attributes. In its persistent form, it is an entry of the label. It allows an application to recover any entity in the current session or in a previous session.
1125* **Resource file** - a file containing a list of each document’s schema name and the storage and retrieval plug-ins for that document.
1126* **Root** - the starting point of the data framework. This point is the top label in the framework. It is represented by the [0] entry and is created at the same time with the document you are working on.
1127* **Scope** - the set of all the attributes and labels which depend on a given label.
1128* **Tag list** - a list of integers, which identify the place of a label in the data framework. This list is displayed in an entry.
1129* **Topological naming** - systematic referencing of topological entities so that these entities can still be identified after the models they belong to have gone through several steps in modeling. In other words, topological naming allows you to track entities through the steps in the modeling process. This referencing is needed when a model is edited and regenerated, and can be seen as a mapping of labels and name attributes of the entities in the old version of a model to those of the corresponding entities in its new version. Note that if the topology of a model changes during the modeling, this mapping may not fully coincide. A Boolean operation, for example, may split edges.
1130* **Topological tracking** - following a topological entity in a model through the steps taken to edit and regenerate that model.
1131* **Valid label** - in a data framework, this is a label, which is already recomputed in the scope of regeneration sequence and includes the label containing a feature which is to be recalculated. Consider the case of a box to which you first add a fillet, then a protrusion feature. For recalculation purposes, only valid labels of each construction stage are used. In recalculating a fillet, they are only those of the box and the fillet, not the protrusion feature which was added afterwards.
72b7576f 1132
dba69de2 1133@section occt_ocaf_11 Samples
1134@subsection occt_ocaf_11_1 Implementation of Attribute Transformation in a CDL file
72b7576f 1135
1136~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1137class Transformation from MyPackage inherits Attribute from TDF
1138
dba69de2 1139 ---Purpose: This attribute implements a transformation data container.
72b7576f 1140
1141uses
1142
dba69de2 1143 Attribute from TDF,
1144 Label from TDF,
1145 GUID from Standard,
1146 RelocationTable from TDF,
1147 Pnt from gp,
1148 Ax1 from gp,
1149 Ax2 from gp,
1150 Ax3 from gp,
1151 Vec from gp,
1152 Trsf from gp,
1153 TrsfForm from gp
72b7576f 1154
1155is
1156
dba69de2 1157 ---Category: Static methods
1158 -- ===============
1159
1160 GetID (myclass)
1161 ---C++: return const &
1162 ---Purpose: The method returns a unique GUID of this attribute.
1163 -- By means of this GUID this attribute may be identified
1164 -- among other attributes attached to the same label.
1165 returns GUID from Standard;
1166
1167 Set (myclass; theLabel : Label from TDF)
1168 ---Purpose: Finds or creates the attribute attached to <theLabel>.
1169 -- The found or created attribute is returned.
1170 returns Transformation from MyPackage;
1171
1172
1173 ---Category: Methods for access to the attribute data
1174 -- ========================================
1175
1176 Get (me)
1177 ---Purpose: The method returns the transformation.
1178 returns Trsf from gp;
1179
1180
1181 ---Category: Methods for setting the data of transformation
1182 -- ==============================================
1183
1184 SetRotation (me : mutable;
1185 theAxis : Ax1 from gp;
1186 theAngle : Real from Standard);
1187 ---Purpose: The method defines a rotation type of transformation.
1188
1189 SetTranslation (me : mutable;
1190 theVector : Vec from gp);
1191 ---Purpose: The method defines a translation type of transformation.
1192
1193 SetMirror (me : mutable;
1194 thePoint : Pnt from gp);
1195 ---Purpose: The method defines a point mirror type of transformation
1196 -- (point symmetry).
1197
1198 SetMirror (me : mutable;
1199 theAxis : Ax1 from gp);
1200 ---Purpose: The method defines an axis mirror type of transformation
1201 -- (axial symmetry).
1202
1203 SetMirror (me : mutable;
1204 thePlane : Ax2 from gp);
1205 ---Purpose: The method defines a point mirror type of transformation
1206 -- (planar symmetry).
1207
1208 SetScale (me : mutable;
1209 thePoint : Pnt from gp;
1210 theScale : Real from Standard);
1211 ---Purpose: The method defines a scale type of transformation.
1212
1213 SetTransformation (me : mutable;
1214 theCoordinateSystem1 : Ax3 from gp;
1215 theCoordinateSystem2 : Ax3 from gp);
1216 ---Purpose: The method defines a complex type of transformation
1217 -- from one co-ordinate system to another.
1218
1219
1220 ---Category: Overridden methods from TDF_Attribute
1221 -- =====================================
1222
1223 ID (me)
1224 ---C++: return const &
1225 ---Purpose: The method returns a unique GUID of the attribute.
1226 -- By means of this GUID this attribute may be identified
1227 -- among other attributes attached to the same label.
1228 returns GUID from Standard;
1229
1230 Restore (me: mutable;
1231 theAttribute : Attribute from TDF);
1232 ---Purpose: The method is called on Undo / Redo.
1233 -- It copies the content of <theAttribute>
1234 -- into this attribute (copies the fields).
1235
1236 NewEmpty (me)
1237 ---Purpose: It creates a new instance of this attribute.
1238 -- It is called on Copy / Paste, Undo / Redo.
1239 returns mutable Attribute from TDF;
1240
1241 Paste (me;
1242 theAttribute : mutable Attribute from TDF;
1243 theRelocationTable : mutable RelocationTable from TDF);
1244 ---Purpose:: The method is called on Copy / Paste.
1245 -- It copies the content of this attribute into
1246 -- <theAttribute> (copies the fields).
1247
1248 Dump(me; anOS : in out OStream from Standard)
1249 ---C++: return;
1250 ---Purpose: Prints the content of this attribute into the stream.
1251 returns OStream from Standard is redefined;
1252
1253
1254 ---Category: Constructor
1255 -- ===========
1256
1257 Create
1258 ---Purpose: The C++ constructor of this atribute class.
1259 -- Usually it is never called outside this class.
1260 returns mutable Transformation from MyPackage;
72b7576f 1261
1262
1263fields
1264
dba69de2 1265 -- Type of transformation
1266 myType : TrsfForm from gp;
72b7576f 1267
dba69de2 1268 -- Axes (Ax1, Ax2, Ax3)
1269 myAx1 : Ax1 from gp;
1270 myAx2 : Ax2 from gp;
1271 myFirstAx3 : Ax3 from gp;
1272 mySecondAx3 : Ax3 from gp;
1273
1274 -- Scalar values
1275 myAngle : Real from Standard;
1276 myScale : Real from Standard;
1277
1278 -- Points
1279 myFirstPoint : Pnt from gp;
1280 mySecondPoint : Pnt from gp;
72b7576f 1281
1282
1283end Transformation;
1284~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1285
dba69de2 1286@subsection occt_ocaf_11_2 Implementation of Attribute Transformation in a CPP file
1287
72b7576f 1288~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1289#include MyPackage_Transformation.ixx;
1290
1291//=======================================================================
1292//function : GetID
dba69de2 1293//purpose : The method returns a unique GUID of this attribute.
1294// By means of this GUID this attribute may be identified
1295// among other attributes attached to the same label.
72b7576f 1296//=======================================================================
1297const Standard_GUID& MyPackage_Transformation::GetID()
1298{
dba69de2 1299 static Standard_GUID ID("4443368E-C808-4468-984D-B26906BA8573");
1300 return ID;
72b7576f 1301}
1302
1303//=======================================================================
1304//function : Set
dba69de2 1305//purpose : Finds or creates the attribute attached to <theLabel>.
1306// The found or created attribute is returned.
72b7576f 1307//=======================================================================
1308Handle(MyPackage_Transformation) MyPackage_Transformation::Set(const TDF_Label& theLabel)
1309{
dba69de2 1310 Handle(MyPackage_Transformation) T;
1311 if (!theLabel.FindAttribute(MyPackage_Transformation::GetID(), T))
1312 {
1313 T = new MyPackage_Transformation();
1314 theLabel.AddAttribute(T);
1315 }
1316 return T;
72b7576f 1317}
1318
1319//=======================================================================
1320//function : Get
dba69de2 1321//purpose : The method returns the transformation.
72b7576f 1322//=======================================================================
1323gp_Trsf MyPackage_Transformation::Get() const
1324{
dba69de2 1325 gp_Trsf transformation;
1326 switch (myType)
1327 {
1328 case gp_Identity:
1329 {
1330 break;
1331 }
1332 case gp_Rotation:
1333 {
1334 transformation.SetRotation(myAx1, myAngle);
1335 break;
1336 }
1337 case gp_Translation:
1338 {
1339 transformation.SetTranslation(myFirstPoint, mySecondPoint);
1340 break;
1341 }
1342 case gp_PntMirror:
1343 {
1344 transformation.SetMirror(myFirstPoint);
1345 break;
1346 }
1347 case gp_Ax1Mirror:
1348 {
1349 transformation.SetMirror(myAx1);
1350 break;
1351 }
1352 case gp_Ax2Mirror:
1353 {
1354 transformation.SetMirror(myAx2);
1355 break;
1356 }
1357 case gp_Scale:
1358 {
1359 transformation.SetScale(myFirstPoint, myScale);
1360 break;
1361 }
1362 case gp_CompoundTrsf:
1363 {
1364 transformation.SetTransformation(myFirstAx3, mySecondAx3);
1365 break;
1366 }
1367 case gp_Other:
1368 {
1369 break;
1370 }
1371 }
1372 return transformation;
72b7576f 1373}
1374
1375//=======================================================================
1376//function : SetRotation
dba69de2 1377//purpose : The method defines a rotation type of transformation.
72b7576f 1378//=======================================================================
1379void MyPackage_Transformation::SetRotation(const gp_Ax1& theAxis, const Standard_Real theAngle)
1380{
dba69de2 1381 Backup();
1382 myType = gp_Rotation;
1383 myAx1 = theAxis;
1384 myAngle = theAngle;
72b7576f 1385}
1386
1387//=======================================================================
1388//function : SetTranslation
dba69de2 1389//purpose : The method defines a translation type of transformation.
72b7576f 1390//=======================================================================
1391void MyPackage_Transformation::SetTranslation(const gp_Vec& theVector)
1392{
dba69de2 1393 Backup();
1394 myType = gp_Translation;
1395 myFirstPoint.SetCoord(0, 0, 0);
1396 mySecondPoint.SetCoord(theVector.X(), theVector.Y(), theVector.Z());
72b7576f 1397}
1398
1399//=======================================================================
1400//function : SetMirror
dba69de2 1401//purpose : The method defines a point mirror type of transformation
1402// (point symmetry).
72b7576f 1403//=======================================================================
1404void MyPackage_Transformation::SetMirror(const gp_Pnt& thePoint)
1405{
dba69de2 1406 Backup();
1407 myType = gp_PntMirror;
1408 myFirstPoint = thePoint;
72b7576f 1409}
1410
1411//=======================================================================
1412//function : SetMirror
dba69de2 1413//purpose : The method defines an axis mirror type of transformation
1414// (axial symmetry).
72b7576f 1415//=======================================================================
1416void MyPackage_Transformation::SetMirror(const gp_Ax1& theAxis)
1417{
dba69de2 1418 Backup();
1419 myType = gp_Ax1Mirror;
1420 myAx1 = theAxis;
72b7576f 1421}
1422
1423//=======================================================================
1424//function : SetMirror
dba69de2 1425//purpose : The method defines a point mirror type of transformation
1426// (planar symmetry).
72b7576f 1427//=======================================================================
1428void MyPackage_Transformation::SetMirror(const gp_Ax2& thePlane)
1429{
dba69de2 1430 Backup();
1431 myType = gp_Ax2Mirror;
1432 myAx2 = thePlane;
72b7576f 1433}
1434
1435//=======================================================================
1436//function : SetScale
dba69de2 1437//purpose : The method defines a scale type of transformation.
72b7576f 1438//=======================================================================
1439void MyPackage_Transformation::SetScale(const gp_Pnt& thePoint, const Standard_Real theScale)
1440{
dba69de2 1441 Backup();
1442 myType = gp_Scale;
1443 myFirstPoint = thePoint;
1444 myScale = theScale;
72b7576f 1445}
1446
1447//=======================================================================
1448//function : SetTransformation
dba69de2 1449//purpose : The method defines a complex type of transformation
1450// from one co-ordinate system to another.
72b7576f 1451//=======================================================================
1452void MyPackage_Transformation::SetTransformation(const gp_Ax3& theCoordinateSystem1,
dba69de2 1453 const gp_Ax3& theCoordinateSystem2)
72b7576f 1454{
dba69de2 1455 Backup();
1456 myFirstAx3 = theCoordinateSystem1;
1457 mySecondAx3 = theCoordinateSystem2;
72b7576f 1458}
1459
1460//=======================================================================
1461//function : ID
dba69de2 1462//purpose : The method returns a unique GUID of the attribute.
1463// By means of this GUID this attribute may be identified
1464// among other attributes attached to the same label.
72b7576f 1465//=======================================================================
1466const Standard_GUID& MyPackage_Transformation::ID() const
1467{
dba69de2 1468 return GetID();
72b7576f 1469}
1470
1471//=======================================================================
1472//function : Restore
dba69de2 1473//purpose : The method is called on Undo / Redo.
1474// It copies the content of <theAttribute>
1475// into this attribute (copies the fields).
72b7576f 1476//=======================================================================
1477void MyPackage_Transformation::Restore(const Handle(TDF_Attribute)& theAttribute)
1478{
dba69de2 1479 Handle(MyPackage_Transformation) theTransformation = Handle(MyPackage_Transformation)::DownCast(theAttribute);
1480 myType = theTransformation->myType;
1481 myAx1 = theTransformation->myAx1;
1482 myAx2 = theTransformation->myAx2;
1483 myFirstAx3 = theTransformation->myFirstAx3;
1484 mySecondAx3 = theTransformation->mySecondAx3;
1485 myAngle = theTransformation->myAngle;
1486 myScale = theTransformation->myScale;
1487 myFirstPoint = theTransformation->myFirstPoint;
1488 mySecondPoint = theTransformation->mySecondPoint;
72b7576f 1489}
1490
1491//=======================================================================
1492//function : NewEmpty
dba69de2 1493//purpose : It creates a new instance of this attribute.
1494// It is called on Copy / Paste, Undo / Redo.
72b7576f 1495//=======================================================================
1496Handle(TDF_Attribute) MyPackage_Transformation::NewEmpty() const
dba69de2 1497{
1498 return new MyPackage_Transformation();
72b7576f 1499}
1500
1501//=======================================================================
1502//function : Paste
dba69de2 1503//purpose : The method is called on Copy / Paste.
1504// It copies the content of this attribute into
1505// <theAttribute> (copies the fields).
72b7576f 1506//=======================================================================
1507void MyPackage_Transformation::Paste(const Handle(TDF_Attribute)& theAttribute,
dba69de2 1508 const Handle(TDF_RelocationTable)& ) const
72b7576f 1509{
dba69de2 1510 Handle(MyPackage_Transformation) theTransformation = Handle(MyPackage_Transformation)::DownCast(theAttribute);
1511 theTransformation->myType = myType;
1512 theTransformation->myAx1 = myAx1;
1513 theTransformation->myAx2 = myAx2;
1514 theTransformation->myFirstAx3 = myFirstAx3;
1515 theTransformation->mySecondAx3 = mySecondAx3;
1516 theTransformation->myAngle = myAngle;
1517 theTransformation->myScale = myScale;
1518 theTransformation->myFirstPoint = myFirstPoint;
1519 theTransformation->mySecondPoint = mySecondPoint;
72b7576f 1520}
1521
1522//=======================================================================
1523//function : Dump
dba69de2 1524//purpose : Prints the content of this attribute into the stream.
72b7576f 1525//=======================================================================
1526Standard_OStream& MyPackage_Transformation::Dump(Standard_OStream& anOS) const
dba69de2 1527{
1528 anOS = "Transformation: ";
1529 switch (myType)
1530 {
1531 case gp_Identity:
1532 {
1533 anOS = "gp_Identity";
1534 break;
1535 }
1536 case gp_Rotation:
1537 {
1538 anOS = "gp_Rotation";
1539 break;
1540 }
1541 case gp_Translation:
1542 {
1543 anOS = "gp_Translation";
1544 break;
1545 }
1546 case gp_PntMirror:
1547 {
1548 anOS = "gp_PntMirror";
1549 break;
1550 }
1551 case gp_Ax1Mirror:
1552 {
1553 anOS = "gp_Ax1Mirror";
1554 break;
1555 }
1556 case gp_Ax2Mirror:
1557 {
1558 anOS = "gp_Ax2Mirror";
1559 break;
1560 }
1561 case gp_Scale:
1562 {
1563 anOS = "gp_Scale";
1564 break;
1565 }
1566 case gp_CompoundTrsf:
1567 {
1568 anOS = "gp_CompoundTrsf";
1569 break;
1570 }
1571 case gp_Other:
1572 {
1573 anOS = "gp_Other";
1574 break;
1575 }
1576 }
1577 return anOS;
72b7576f 1578}
1579
1580//=======================================================================
1581//function : MyPackage_Transformation
dba69de2 1582//purpose : A constructor.
72b7576f 1583//=======================================================================
1584MyPackage_Transformation::MyPackage_Transformation():myType(gp_Identity){
1585
1586}
dba69de2 1587~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1588
1589@subsection occt_ocaf_11_3 Implementation of typical actions with standard OCAF attributes.
1590
1591There are four sample files provided in the directory 'OpenCasCade\ros\samples\ocafsamples'. They present typical actions with OCAF services (mainly for newcomers).
1592The method *Sample()* of each file is not dedicated for execution 'as is', it is rather a set of logical actions using some OCAF services.
1593
1594### TDataStd_Sample.cxx
1595This sample contains templates for typical actions with the following standard OCAF attributes:
1596- Starting with data framework;
1597- TDataStd_Integer attribute management;
1598- TDataStd_RealArray attribute management;
1599- TDataStd_Comment attribute management;
1600- TDataStd_Name attribute management;
1601- TDataStd_UAttribute attribute management;
1602- TDF_Reference attribute management;
1603- TDataXtd_Point attribute management;
1604- TDataXtd_Plane attribute management;
1605- TDataXtd_Axis attribute management;
1606- TDataXtd_Geometry attribute management;
1607- TDataXtd_Constraint attribute management;
1608- TDataStd_Directory attribute management;
1609- TDataStd_TreeNode attribute management.
1610
1611### TDocStd_Sample.cxx
1612This sample contains template for the following typical actions:
1613- creating application;
1614- creating the new document (document contains a framework);
1615- retrieving the document from a label of its framework;
1616- filling a document with data;
1617- saving a document in the file;
1618- closing a document;
1619- opening the document stored in the file;
1620- copying content of a document to another document with possibility to update the copy in the future.
1621
1622### TPrsStd_Sample.cxx
1623This sample contains template for the following typical actions:
1624- starting with data framework;
1625- setting the TPrsStd_AISViewer in the framework;
1626- initialization of aViewer;
1627- finding TPrsStd_AISViewer attribute in the DataFramework;
1628- getting AIS_InteractiveContext from TPrsStd_AISViewer;
1629- adding driver to the map of drivers;
1630- getting driver from the map of drivers;
1631- setting TNaming_NamedShape to <ShapeLabel>;
1632- setting the new TPrsStd_AISPresentation to <ShapeLabel>;
1633- displaying;
1634- erasing;
1635- updating and displaying presentation of the attribute to be displayed;
1636- setting a color to the displayed attribute;
1637- getting transparency of the displayed attribute;
1638- modify attribute;
1639- updating presentation of the attribute in viewer.
1640
1641### TNaming_Sample.cxx
1642This sample contains template for typical actions with OCAF Topological Naming services.
1643The following scenario is used:
1644- data framework initialization;
1645- creating Box1 and pushing it as PRIMITIVE in DF;
1646- creating Box2 and pushing it as PRIMITIVE in DF;
1647- moving Box2 (applying a transformation);
1648- pushing the selected edges of the top face of Box1 in DF;
1649- creating a Fillet (using the selected edges) and pushing the result as a modification of Box1;
1650- creating a Cut (Box1, Box2) as a modification of Box1 and push it in DF;
1651- recovering the result from DF.
1652