0028654: Existed tool (gendoc) for generation documentation does not take into accoun...
[occt.git] / dox / user_guides / ocaf / ocaf.md
1 OCAF  {#occt_user_guides__ocaf}
2 ========================
3
4 @tableofcontents
5
6 @section occt_ocaf_1 Introduction
7
8 This manual explains how to use the Open CASCADE Application Framework (OCAF).
9 It provides basic documentation on using OCAF. For advanced information on OCAF 
10 and its applications, see our <a href="http://www.opencascade.com/content/tutorial-learning">E-learning & Training</a> offerings.
11
12 @subsection occt_ocaf_1_1 Purpose of OCAF
13
14 OCAF (the Open CASCADE Application Framework) is an  easy-to-use platform for rapidly developing
15   sophisticated domain-specific  design applications. 
16   A typical application developed using OCAF deals with two or three-dimensional (2D or 3D) geometric modeling 
17   in trade-specific Computer Aided Design (CAD) systems, manufacturing or analysis applications, 
18   simulation  applications or illustration tools. 
19   
20   Developing a design application requires addressing many technical aspects. 
21   In particular, given the functional specification of your application, you must at least:  
22   
23   * Design the  architecture of the application— definition of the software components and the way they cooperate;
24   * Define the  data model able to support the functionality required — a design application  operates on data maintained during the whole end-user working session;
25   * Structure  the software in order to:
26     * synchronize the display with the  data — commands modifying objects must update the views;  
27     * support generalized undo-redo  commands — this feature has to be taken into account very early in the design  process;  
28   * Implement  the function for saving the data — if the application has a long life cycle,  the compatibility of data between versions of the application has to be  addressed;
29   * Build the  application user interface.
30  
31 Architectural guidance and ready-to-use solutions provided by OCAF offer you the following benefits:
32   * You can concentrate on the functionality specific for your application;  
33   * The underlying mechanisms required to support the application are already provided; 
34   * The application can be rapidly be prototyped thanks to the coupling the other Open CASCADE Technology modules;
35   * The final application can be developed by industrializing the prototype — you don't need to restart the development from scratch. 
36   * The Open Source nature of the platform guarantees the long-term usefulness of your development.   
37
38 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 their logical supplement. 
39
40 The table below contrasts the design of a modeling application using object libraries alone and using OCAF. 
41
42 **Table 1: Services provided by OCAF** 
43
44 |Development tasks      |Comments | Without OCAF        | With OCAF |
45 |------------------:|---------:|---------------:|-----------:|
46 |Creation of geometry| Algorithm Calling the modeling libraries |       To be created by the user       | To be created by the user| 
47 | Data organization | Including specific attributes and modeling process | To be created by the user |  Simplified| 
48 | Saving data in a file | Notion of document | To be created by the user | Provided |
49 | Document-view management |    |  To be created by the user | Provided |
50 | Application infrastructure | New, Open, Close, Save and Save As File menus | To be created by the user | Provided | 
51 | Undo-Redo | Robust, multi-level       | To be created by the user     | Provided |
52 | Application-specific dialog boxes     |    | To be created by the user  |     To be created by the user |
53
54 OCAF uses other modules of Open CASCADE Technology — the Shape  is implemented with the geometry supported by the <a href="#user_guides__modeling_data">Modeling Data</a> module and the viewer is the one provided with the <a href="#user_guides__visualization">Visualization</a> module. Modeling functions can be implemented using the <a href="#user_guides__modeling_algos">Modeling Algorithms</a> module.
55
56 The relationship between OCAF and the Open CASCADE Technology (**OCCT**) Object Libraries can be seen in the image below. 
57
58 @figure{/user_guides/ocaf/images/ocaf_image003.svg,"OCCT Architecture",360}
59
60 In 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. 
61  
62 The subsequent chapters of this document explain the concepts and show how to use the services of OCAF.
63
64 @subsection occt_ocaf_1_2 Architecture Overview
65
66 OCAF provides you with an object-oriented Application-Document-Attribute model consisting of C++ class libraries. 
67
68 @figure{ocaf_wp_image003.png,"The Application-Document-Attribute model",420}
69
70 @subsubsection occt_ocaf_1_2_1 Application
71
72 The *Application* is an abstract class in charge of handling documents during the working session, namely:  
73   * Creating new  documents;
74   * Saving documents and opening them;
75   * Initializing document views.
76   
77 @subsubsection occt_ocaf_1_2_2 Document   
78  
79   The document, implemented by the concrete class  *Document*, is the container for the application data. Documents offer access to the data framework and serve the following purposes: 
80
81   * Manage the notification of changes
82   * Update external links
83   * Manage the saving and restoring of data
84   * Store the names of software extensions.
85   * Manage command transactions
86   * Manage Undo and Redo options. 
87   
88   Each  document is saved in a single flat ASCII file defined by its format and  extension (a ready-to-use format is provided with  OCAF).  
89
90   Apart 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.   
91   
92 @subsubsection occt_ocaf_1_2_3 Attribute
93
94   Application data is described by **Attributes**, which are instances of  classes derived from the *Attribute* abstract class, organized according to the OCAF Data  Framework. 
95   
96   The @ref occt_ocaf_3 "OCAF Data Framework" references aggregations of attributes using  persistent identifiers in a single hierarchy. A wide range of  attributes come with OCAF, including:    
97   
98   * @ref occt_ocaf_6 "Standard attributes" 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)....;
99   * @ref occt_ocaf_5 "Shape attributes" contain the geometry of the whole model or its elements including reference to the shapes and tracking of shape evolution;
100   * Other  geometric attributes such as **Datums** (points, axis and plane) and **Constraints** (*tangent-to, at-a-given-distance, from-a-given-angle, concentric,* etc.)
101   * User  attributes, that is, attributes typed by the application  
102   * @ref occt_ocaf_7 "Visualization 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.
103   * @ref occt_ocaf_8 "Function services" — the purpose of these attributes is to rebuild  objects after they have been modified (parameterization of models). While 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. 
104   
105 In addition,  application-specific data can be added by defining new attribute classes; naturally, this changes the standard file format. The only functions that have to be implemented are:
106     * Copying the  attribute
107     * Converting  it from and persistent data storage
108         
109 @subsection occt_ocaf_1_3  Reference-key model
110
111   In most existing geometric modeling systems, the data are topology driven. 
112   They usually use a boundary representation (BRep), where geometric models 
113   are defined by a collection of faces, edges and vertices, 
114   to which application data are attached. Examples of data include:  
115  
116   * a color;
117   * a material;
118   * information that a particular edge is blended.
119  
120   When the geometric model is parameterized, that is, when you can change 
121   the value of parameters used to build the model (the radius of a  blend, the thickness of a rib, etc.), 
122   the geometry is highly subject to change. 
123   In order to maintain the attachment of application data, the geometry must be  distinguished from other data.  
124    
125   In OCAF, the data are reference-key driven. It is a  uniform model in which reference-keys 
126   are the persistent identification of  data. All **accessible** data, including the geometry, 
127   are implemented as attributes attached to reference-keys. 
128   The geometry becomes the  value of the Shape attribute, just as a number is the value 
129   of the Integer and  Real attributes and a string that of the Name attribute.  
130    
131   On a single reference-key, many attributes can be  aggregated; 
132   the application can ask at runtime which attributes are available. 
133   For example, to associate a texture to a face in a geometric model, 
134   both the face and the texture are attached to the same reference-key.  
135  
136 @figure{ocaf_image004.png,"Topology driven versus reference-key driven approaches",360}
137
138  Reference-keys can be created in two ways:   
139  
140   * At  programming time, by the application
141   * At runtime,  by the end-user of the application (providing that you include this capability  in the application)
142  
143   As an application developer, you generate reference-keys in order to give semantics to the data. 
144   For example, a function building a  prism may create three reference-keys: 
145   one for the base of the prism, a second  for the lateral faces and a third for the top face. 
146   This makes up a semantic  built-in the application's prism feature.
147   On the other hand, in a command  allowing the end-user to set a texture to a face he/she selects, 
148   you must create  a reference-key to the selected face 
149   if it has not previously been referenced in any feature 
150   (as in the case of one of the lateral faces of the prism).  
151  
152   When you create a reference-key to selected topological  elements (faces, edges or vertices), 
153   OCAF attaches to the reference-key  information defining the selected topology — the Naming attribute. 
154   For example,  it may be the faces to which a selected edge is common to. 
155   This information, as  well as information about the evolution of the topology at each modeling step 
156   (the modified, updated and deleted faces), is used by the naming algorithm to  maintain the topology 
157   attached to the reference-key. As such, on a  parametrized model, 
158   after modifying the value of a parameter, the reference-keys still address the appropriate faces, 
159   even if their geometry has  changed. 
160   Consequently, you change the size of the cube shown in the figure above, 
161   the user texture stay attached to the right face.  
162  
163   <b>Note</b> As Topological naming is based on the reference-key and attributes such as Naming 
164   (selection information) and Shape (topology evolution  information), 
165   OCAF is not coupled to the underlying modeling libraries. 
166   The  only modeling services required by OCAF are the following:  
167
168   * Each  algorithm must provide information about the evolution of the topology 
169    (the  list of faces modified, updated and deleted by the algorithm)
170   * Exploration  of the geometric model must be available 
171    (a 3D model is made of faces bounded  by close wires, 
172    themselves composed by a sequence of edges connected by their  vertices)
173  
174   Currently, OCAF uses the Open CASCADE Technology  modeling libraries.   
175  
176   To design an OCAF-based data model, the application  developer is encouraged to aggregate 
177   ready-to-use attributes instead of defining new attributes by inheriting from an abstract root class.  
178   There are two major advantages in using aggregation  rather than inheritance:
179   
180   * As you don't  implement data by defining new classes, the format of saved data 
181     provided with OCAF doesn't change; so you don't have to write the Save and Open functions
182   * The application can query the data at runtime if a particular attribute is  available
183   
184 **Summary**
185
186   * OCAF is  based on a uniform reference-key model in which:
187     * Reference-keys provide  persistent identification of data;  
188     * Data, including geometry, are  implemented as attributes attached to reference-keys;  
189     * Topological naming maintains the  selected geometry attached to reference-keys in parametrized models; 
190   * In many  applications, the data format provided with OCAF doesn't need to be extended;
191   * OCAF is not  coupled to the underlying modeling libraries.
192   
193   
194 @section occt_ocaf_3 The Data  Framework
195  
196 @subsection occt_ocaf_3_1 Data Structure
197  
198   The OCAF Data Framework is the Open CASCADE Technology  realization 
199   of the reference-key model in a tree structure. It offers a single environment where data from different application components can be handled. This allows exchanging and modifying data simply, consistently, with a maximum level of information and stable semantics.
200   
201
202 The building blocks of this approach are: 
203
204   * The tag
205   * The label
206   * The attribute
207
208 As 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. 
209
210 Each 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. 
211
212 The 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. 
213
214 The most important property is that a label’s entry is its persistent address in the data framework. 
215   
216 @figure{/user_guides/ocaf/images/ocaf_image005.png,"A simple framework model",216}
217
218 In this image the circles contain tags of the corresponding labels.  The lists of tags are located under the circles. The root label always has a zero tag. 
219
220 The children of a root label are middle-level labels with tags 1 and 3. These labels are brothers. 
221
222 List 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). 
223
224 @subsection occt_ocaf_3_2 Examples of a Data Structure
225
226 Let's have a look at the example:
227   
228 @figure{ocaf_wp_image007.png,"The coffee machine",200}
229   
230    In the image the application for designing coffee  machines first allocates 
231   a label for the machine unit. It then adds sub-labels  for the main features 
232   (glass coffee pot, water receptacle and filter) which it  refines as needed 
233   (handle and reservoir of the coffee pot and spout of the  reservoir). 
234   
235   You now attach technical data describing the handle — its geometry and color — 
236   and the reservoir — its geometry and material. 
237   Later on, you can  modify the handle's geometry without changing its color — 
238   both remain attached  to the same label.  
239   
240 @figure{ocaf_wp_image005.png,"The data structure of the coffee machine",361}
241  
242   The nesting of labels is key to OCAF. This allows a  label to have its own structure 
243   with its local addressing scheme which can be  reused in a more complex structure. 
244   Take, for example, the coffee machine.  Given that the coffee pot's handle has a label of tag [1], 
245   the entry for the handle in  the context of the coffee pot only (without the machine unit) is [0:1:1]. 
246   If you now model a coffee  machine with two coffee pots, one at the label [1], 
247   the second at the label [4] in the machine unit, 
248   the handle  of the first pot would have the entry [0:1:1:1] 
249   whereas the handle of the second pot would be [0:1:4:1]. 
250   This way, we avoid any  confusion between coffee pot handles.
251
252 Another example is the application for designing table lamps. The first label is allocated to the lamp unit. 
253
254 @figure{/user_guides/ocaf/images/ocaf_image006.png,"",200}
255
256 The root label cannot have brother labels. Consequently, various lamps in the framework allocation correspond to the sub-labels of the root label. This allows avoiding any confusion between table lamps in the data framework. Different lamp parts have different material, color and other attributes, so a child label of the lamp with the specified tags is allocated for each sub-unit of the lamp: 
257
258   * a lamp-shade label with tag 1
259   * a bulb label with tag 2
260   * a stem label with tag 3
261
262 Label tags are chosen at will. They are only identifiers of the lamp parts. Now you can refine all units: by setting geometry, color, material and other information about the lamp or its parts to the specified label. This information is placed into special attributes of the label: the pure label contains no data -- it is only a key to access data. 
263
264 Remember 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 reused in your design, the part name could be integrated into the framework as an attribute. 
265
266 So, 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. 
267
268 @figure{/user_guides/ocaf/images/ocaf_image007.png,"",360}
269
270
271 The 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. 
272
273 The 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. 
274
275 Note that the root label can have attributes too, usually global attributes: the name of the document, for example. 
276
277 @subsection occt_ocaf_3_3 Tag
278
279 A tag is an integer, which identifies a label in two ways: 
280
281   * Relative identification
282   * Absolute identification.
283
284 In 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. 
285
286 In 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. 
287
288 In 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. 
289
290 The tag can be created in two ways: 
291
292   * Random delivery
293   * User-defined delivery
294
295 As 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. 
296
297 @subsubsection occt_ocaf_3_3_1 Creating child labels using random delivery of tags
298
299 To 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*. 
300
301
302 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303 TDF_Label child1 = TDF_TagSource::NewChild (level2); 
304 TDF_Label child2 = TDF_TagSource::NewChild (level2); 
305 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
306
307 @subsubsection occt_ocaf_3_3_2 Creation of a child label by user delivery from a tag
308
309 The 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. 
310
311 To 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. 
312
313
314 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
315 TDF_Label achild = root.FindChild(3,Standard_False); 
316 if (!achild.IsNull()) { 
317 Standard_Integer tag = achild.Tag(); 
318
319 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
320
321 @subsection occt_ocaf_3_4 Label
322
323 The 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.
324
325 Label 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. 
326
327 @subsubsection occt_ocaf_3_4_1 Label creation
328
329 Labels 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. 
330
331 @subsubsection occt_ocaf_3_4_2 Creating child labels
332
333 To create a new child label in the data framework using explicit delivery of tags, use *TDF_Label::FindChild*. 
334
335
336 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
337 //creating a label with tag 10 at Root 
338 TDF_Label lab1 = aDF->Root().FindChild(10); 
339
340 //creating labels 7 and 2 on label 10 
341 TDF_Label lab2 = lab1.FindChild(7); 
342
343 TDF_Label lab3 = lab1.FindChild(2); 
344 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345 You 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. 
346
347
348 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
349 TDF_Label level1 = root.FindChild(3,Standard_True); 
350 TDF_Label level2 = level1.FindChild(1,Standard_True); 
351 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352 @subsubsection occt_ocaf_3_4_3 Retrieving child labels
353
354 You can retrieve child labels of your current label by iteration on the first level in the scope of this label. 
355
356
357 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
358 TDF_Label current; 
359 // 
360 for (TDF_ChildIterator it1 (current,Standard_False); it1.More(); it1.Next()) { 
361 achild = it1.Value(); 
362 // 
363 // do something on a child (level 1) 
364 // 
365
366 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367 You 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. 
368 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
369 for (TDF_ChildIterator itall (current,Standard_True); itall.More(); itall.Next()) { 
370 achild = itall.Value(); 
371 // 
372 // do something on a child (all levels) 
373 // 
374
375 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376 Using *TDF_Tool::Entry* with *TDF_ChildIterator* you can retrieve the entries of your current label’s child labels as well. 
377
378  
379 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
380 void DumpChildren(const TDF_Label& aLabel) 
381
382   TDF_ChildIterator it; 
383   TCollection_AsciiString es; 
384   for (it.Initialize(aLabel,Standard_True); it.More(); it.Next()){ 
385     TDF_Tool::Entry(it.Value(),es); 
386     cout  <<  as.ToCString()  <<  endl; 
387   } 
388
389 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
390 @subsubsection occt_ocaf_3_4_4 Retrieving the father label
391
392 Retrieving the father label of a current label. 
393
394
395 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
396 TDF_Label father = achild.Father(); 
397 isroot = father.IsRoot(); 
398 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
399
400 @subsection occt_ocaf_3_5 Attribute
401
402 The 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. 
403
404 The 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. 
405
406 @subsubsection occt_ocaf_3_5_1 Retrieving an attribute from a label
407
408 To 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. 
409
410
411 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
412 if(current.FindAttribute(TDataStd_Integer::GetID(),INT)) 
413
414   // the attribute is found 
415
416 else 
417
418   // the attribute is not found 
419
420 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
421 @subsubsection occt_ocaf_3_5_2 Identifying an attribute using a GUID
422
423 You 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*. 
424
425
426 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
427 Handle(TDataStd_Integer) INT = new TDataStd_Integer(); 
428 Standard_GUID guid = INT->ID(); 
429 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
430
431 @subsubsection occt_ocaf_3_5_3 Attaching an attribute to a label
432
433 To 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. 
434
435 *TDF_Attribute::Label* for *INT* then returns the label *attach* to which *INT* is attached. 
436
437
438 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
439 current.Add (INT); // INT is now attached to current 
440 current.Add (INT); // causes failure 
441 TDF_Label attach = INT->Label(); 
442 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
443 @subsubsection occt_ocaf_3_5_4 Testing the attachment to a label
444
445 You 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. 
446
447 *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*. 
448
449
450 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
451 // Testing of attribute attachment 
452 // 
453 if (current.IsA(TDataStd_Integer::GetID())) { 
454 // the label has an Integer attribute attached 
455
456 if (current.HasAttribute()) { 
457 // the label has at least one attribute attached 
458 Standard_Integer nbatt = current.NbAttributes(); 
459 // the label has nbatt attributes attached 
460
461 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
462 @subsubsection occt_ocaf_3_5_5 Removing an attribute from a label
463
464 To 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*. 
465
466
467 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
468 current.Forget(TDataStd_Integer::GetID()); 
469 // integer attribute is now not attached to current label 
470 current.ForgetAll(); 
471 // current has now 0 attributes attached 
472 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
473 @subsubsection occt_ocaf_3_5_6 Specific attribute creation
474
475 If 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. 
476
477 There 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) 
478
479 In order to create a new attribute in the standard way, create a class inherited from *TDF_Attribute* and implement all purely virtual and necessary virtual methods:
480 * **ID()** -- returns a unique GUID of a given attribute 
481 * **Restore(attribute)** -- sets fields of this attribute equal to the fields of a given attribute of the same type 
482 * **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 . 
483 * **NewEmpty()** -- returns a new attribute of this class with empty fields 
484 * **Dump(stream)** --  outputs information about a given attribute to a given stream debug (usually outputs an attribute of type string only) 
485
486 Methods *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. 
487
488 To enable possibility to save / restore the new attribute in XML format, do the following: 
489   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).
490   2. Create a new package (or do it in the current one) with two package methods: 
491           * *Factory*, which loads the document storage and retrieval drivers; and 
492           * *AttributeDrivers*, which calls the methods AddDrivers for all packages responsible for persistence of the document.
493   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.
494
495 To enable possibility to save / restore the new attribute in binary format, do the following: 
496   1. Create a new package with name <i> Bin[package name] </i> (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.
497   2. Create a new package (or do it in the current one) with two package methods: 
498           * Factory, which loads the document storage and retrieval drivers; and 
499           * AttributeDrivers, which calls the methods AddDrivers for all packages responsible for persistence of the document.
500   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.
501 See @ref occt_ocaf_4_3_3 "Saving the document" and @ref occt_ocaf_4_3_4 "Opening the document from a file" for the description of document save/open mechanisms. 
502
503 If 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: 
504   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).
505   2. Create child labels and allocate all necessary data through standard attributes at the child labels.
506   3. Define an interface class for access to the data of the child labels.
507
508 Choosing 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. 
509
510 Let’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). 
511
512 1. The first way: creation of a new attribute. The implementation of the transformation by creation of a new attribute is represented in the @ref occt_ocaf_11 "Samples". 
513
514 2. 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: 
515   * Type of transformation <i>(gp_Translation)</i> as *TDataStd_Integer*;
516   * First point as *TDataStd_RealArray* (three values: X1, Y1 and Z1);
517   * Second point as *TDataStd_RealArray* (three values: X2, Y2 and Z2).
518
519 @figure{/user_guides/ocaf/images/ocaf_image010.png,"Data tree for translation",240}
520
521 If the type of transformation is changed to rotation, the data tree looks like this: 
522   * Type of transformation <i>(gp_Rotation)</i> as *TDataStd_Integer*;
523   * Point of axis of rotation as *TDataStd_RealArray* (three values: X, Y and Z);
524   * Axis of rotation as *TDataStd_RealArray* (three values: DX, DY and DZ);
525   * Angle of rotation as *TDataStd_Real*.
526
527 @figure{/user_guides/ocaf/images/ocaf_image011.png,"Data tree for rotation",240}
528
529 The 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). 
530   
531 @subsection occt_ocaf_3_6 Compound documents
532  
533   As the identification of data is persistent, one document can reference data contained in another document, 
534   the referencing and  referenced documents being saved in two separate files.  
535  
536   Lets look at the coffee machine application again. The  coffee pot can be placed in one document. 
537   The coffee machine document then  includes an *occurrence* — a positioned copy — of the coffee pot. 
538   This occurrence is defined by an XLink attribute (the external Link) 
539   which references the coffee pot of the first document 
540   (the XLink contains the relative path of the coffee pot document and the entry of the coffee pot data [0:1] ).  
541
542 @figure{ocaf_wp_image006.png,"The coffee machine compound document",360}
543  
544   In this context, the end-user of the coffee machine application can open the coffee pot document, 
545   modify the geometry of, for  example, the reservoir, and overwrite the document without worrying 
546   about the impact of the modification in the coffee machine document. 
547   To deal with this  situation, OCAF provides a service which allows the application to check 
548   whether a document is up-to-date. This service is based on a modification counter included in each document: 
549   when an external link is created, a copy of  the referenced document counter is associated to the XLink 
550   in the referencing  document. Providing that each modification of the referenced document increments its own counter,   
551   we can detect that the referencing document has to  be updated by comparing the two counters 
552   (an update function importing the data  referenced by an XLink into the referencing document is also provided).  
553  
554  @subsection occt_ocaf_3_7 Transaction mechanism
555  
556   The Data Framework also provides a transaction mechanism inspired from database management systems: 
557   the data are modified within a transaction which is terminated either by a Commit 
558   if the modifications are validated  or by an Abort if the modifications are abandoned — 
559   the data are then restored  to the state it was in prior to the transaction. 
560   This mechanism is extremely useful for:
561
562   * Securing  editing operations (if an error occurs, the transaction is abandoned and the  structure retains its integrity)
563   * Simplifying  the implementation of the **Cancel** function (when the end-user begins a command, 
564   the application may launch a transaction and operate directly in the data structure; 
565   abandoning the action causes the transaction to Abort)
566   * Executing  **Undo** (at commit time, the modifications are recorded in order to be able to  restore the data to their previous state)
567  
568   The transaction mechanism simply manages a  backup copy of attributes. 
569   During a transaction, attributes are copied before  their first modification. 
570   If the transaction is validated, the copy is  destroyed. 
571   If the transaction is abandoned, the attribute is restored to its initial value 
572   (when attributes are added or deleted, the operation is simply  reversed).
573
574   Transactions are document-centered, that is, the application starts a transaction on a document. 
575   So, modifying a referenced  document and updating one of its referencing documents requires 
576   two transactions, even if both operations are done in the same working session.
577
578   
579 @section occt_ocaf_4_ Standard Document Services
580
581 @subsection occt_ocaf_4_1 Overview
582
583 Standard documents offer ready-to-use documents containing a TDF-based data framework. Each document can contain only one framework. 
584
585 The documents themselves are contained in the instantiation of a class *TDocStd_Application* (or its descendant). This application manages the creation, storage and retrieval of documents. 
586
587 You 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. 
588
589 To sum up, standard documents alone provide access to the data framework. They also allow you to: 
590
591   * Update external links
592   * Manage the saving and opening of data
593   * Manage the undo/redo functionality.
594
595
596 @subsection occt_ocaf_4_2 The Application
597
598 As 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 *TDocStd_Application* or a class inheriting from it. 
599
600 @subsubsection occt_ocaf_4_2_1 Creating an application
601
602 To create an application, use the following syntax. 
603
604 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
605 Handle(TDocStd_Application) app = new TDocStd_Application (); 
606 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
607
608 @subsubsection occt_ocaf_4_2_2 Creating a new document
609
610 To 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*. 
611
612 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
613 Handle(TDocStd_Document) doc; 
614 app->NewDocument("NewDocumentFormat", doc); 
615 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
616
617 Here "NewDocumentFormat" is identifier of the format of your document.
618 OCCT defines several standard formats, distinguishing by a set of supported OCAF attributes, and method of encoding (e.g. binary data or XML), described below.
619 If your application defines specific OCAF attributes, you need to define your own format for it.
620
621 @subsubsection occt_ocaf_4_2_3 Retrieving the application to which the document belongs
622
623 To retrieve the application containing your document, you use the syntax below. 
624
625 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
626 app = Handle(TDocStd_Application)::DownCast (doc->Application()); 
627 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
628 @subsection occt_ocaf_4_3 The Document
629
630 The 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. 
631
632 @subsubsection occt_ocaf_4_3_1 Accessing the main label of the framework
633
634 To 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. 
635
636 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
637 TDF_Label label = doc->Main(); 
638 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
639 @subsubsection occt_ocaf_4_3_2 Retrieving the document from a label in its framework
640
641 To 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*. 
642 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
643 doc = TDocStd_Document::Get(label); 
644 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
645
646 @subsubsection occt_ocaf_4_3_format Defining storage format
647
648 OCAF uses a customizable mechanism for storage of the documents.
649 In order to use OCAF persistence to save and read your documents to / from the file, you need to define one or several formats in your application.
650
651 For that, use method TDocStd_Application::DefineFormat(), for instance:
652 ~~~~~
653 app->DefineFormat ("NewDocumentFormat", "New format for OCAF documents", "ndf",
654                    new NewDocumentFormat_RetrievalDriver(),
655                    new NewDocumentFormat_StorageDriver());
656 ~~~~~
657
658 This example defines format "NewDocumentFormat" with a default file extension "ndf", and instantiates drivers for reading and storing documents from and to that format.
659 Either of the drivers can be null, in this case the corresponding action will not be supported for that format.
660
661 OCAF provides several standard formats, each covering some set of OCAF attributes:
662
663 <table>
664 <tr><th>Format</th><th>Persistent toolkit</th><th>OCAF attributes covered</th></tr>
665 <tr><td colspan=3>Legacy formats (read only)</td></tr>
666 <tr><td>OCC-StdLite    </td><td> TKStdL             </td><td> TKLCAF </td></tr>
667 <tr><td>MDTV-Standard  </td><td> TKStd              </td><td> TKLCAF + TKCAF </td></tr>
668 <tr><td colspan=3>Binary formats</td></tr>
669 <tr><td>BinLOcaf       </td><td> TKBinL             </td><td> TKLCAF </td></tr>
670 <tr><td>BinOcaf        </td><td> TKBin              </td><td> TKLCAF + TKCAF </td></tr>
671 <tr><td>BinXCAF        </td><td> TKBinXCAF          </td><td> TKLCAF + TKCAF + TKXCAF </td></tr>
672 <tr><td>TObjBin        </td><td> TKBinTObj          </td><td> TKLCAF + TKTObj </td></tr>
673 <tr><td colspan=3>XML formats</td></tr>
674 <tr><td>XmlLOcaf       </td><td> TKXmlL             </td><td> TKLCAF </td></tr>
675 <tr><td>XmlOcaf        </td><td> TKXml              </td><td> TKLCAF + TKCAF </td></tr>
676 <tr><td>XmlXCAF        </td><td> TKXmlXCAF          </td><td> TKLCAF + TKCAF + TKXCAF </td></tr>
677 <tr><td>TObjXml        </td><td> TKXmlTObj          </td><td> TKLCAF + TKTObj </td></tr>
678 </table>
679
680 For convenience, these toolkits provide static methods *DefineFormat()* accepting handle to application.
681 These methods allow defining corresponding formats easily, e.g.:
682
683 ~~~~~
684 BinDrivers::DefineFormat (app); // define format "BinOcaf"
685 ~~~~~
686
687 Use these toolkits as an example for implementation of persistence drivers for custom attributes, or new persistence formats.
688
689 The application can define several storage formats.
690 On save, the format specified in the document (see *TDocStd_Document::StorageFormat()*) will be used (save will fail if that format is not defined in the application).
691 On reading, the format identifier stored in the file is used and recorded in the document.
692
693 @subsubsection occt_ocaf_4_3_plugins Defining storage format by resource files 
694
695 The alternative  method to define formats is via usage of resource files. 
696 This  method was  used in earlier versions of OCCT and is considered as deprecated since version 7.1.0.
697 This method allows loading persistence drivers on demand, using plugin mechanism.
698
699 To use this method, create your own application class inheriting from *TDocStd_Application*, and override method *ResourcesName()*.
700 That method should return a string with a name of resource file, e.g. "NewDocumentFormat", which will contain a description of the format.
701
702 Then create that resource file and define the parameters of your format:
703
704 ~~~~~
705 ndf.FileFormat: NewDocumentFormat
706 NewDocumentFormat.Description: New Document Format Version 1.0 
707 NewDocumentFormat.FileExtension: ndf 
708 NewDocumentFormat.StoragePlugin: bb5aa176-c65c-4c84-862e-6b7c1fe16921
709 NewDocumentFormat.RetrievalPlugin: 76fb4c04-ea9a-46aa-88a2-25f6a228d902 
710 ~~~~~
711
712 The GUIDs should be unique and correspond to the GUIDs supported by relevant plugin.
713 You can use an existing plugins (see the table above) or create your own.
714
715 Finally, make a copy of the resource file "Plugin" from *$CASROOT/src/StdResource* and, if necessary, add the definition of your plugin in it, for instance:
716
717 ~~~~~
718 bb5aa176-c65c-4c84-862e-6b7c1fe16921.Location: TKNewFormat
719 76fb4c04-ea9a-46aa-88a2-25f6a228d902.Location: TKNewFormat
720 ~~~~~
721
722 In order to have these resource files loaded during the program execution, it is necessary to set two environment variables: *CSF_PluginDefaults* and *CSF_NewFormatDefaults*.
723 For example, set the files in the directory *MyApplicationPath/MyResources*: 
724
725 ~~~~~
726 setenv CSF_PluginDefaults MyApplicationPath/MyResources 
727 setenv CSF_NewFormatDefaults MyApplicationPath/MyResources 
728 ~~~~~
729
730 @subsubsection occt_ocaf_4_3_3 Saving a document
731
732 To save the document, make sure that its parameter *StorageFormat()* corresponds to one of the formats defined in the application, and use method *TDocStd_Application::SaveAs*, for instance: 
733
734 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
735 app->SaveAs(doc, "/tmp/example.caf"); 
736 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
737
738 @subsubsection occt_ocaf_4_3_4 Opening the document from a file
739
740 To open the document from a file where it has been previously saved, you can use *TDocStd_Application::Open* as in the example below. The arguments are the path of the file and the document saved in this file. 
741
742 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
743 app->Open("/tmp/example.caf", doc); 
744 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
745
746 @subsubsection occt_ocaf_4_3_5 Cutting, copying and pasting inside a document
747
748 To cut, copy and paste inside a document, use the class *TDF_CopyLabel*.
749
750 In fact, you must define a *Label*, which contains the temporary value of a cut or 
751 copy operation (say, in <i> Lab_Clipboard</i>). You must also define two other labels:
752
753 * The data container (e.g. <i> Lab_source</i>)
754 * The destination of the copy (e.g. <i> Lab_ Target</i> )
755
756 ~~~~
757     Copy = copy (Lab_Source => Lab_Clipboard)
758     Cut = copy + Lab_Source.ForgetAll() // command clear the contents of LabelSource.
759     Paste = copy (Lab_Clipboard => Lab_target)
760 ~~~~
761
762 So we need a tool to copy all (or a part) of the content of a label and its sub-label,
763 to another place defined by a label.
764
765 ~~~~
766     TDF_CopyLabel aCopy;
767     TDF_IDFilter aFilter (Standard_False);
768
769     //Don't copy TDataStd_TreeNode attribute
770
771      aFilter.Ignore(TDataStd_TreeNode::GetDefaultTreeID());
772      aCopy.Load(aSource, aTarget); aCopy.UseFilter(aFilter); aCopy.Perform();
773
774     // copy the data structure to clipboard 
775
776     return aCopy.IsDone(); }
777 ~~~~
778
779 The filter is used to forbid copying a specified type of attribute. 
780
781 You can also have a look at the class *TDF_Closure*, which can be useful to determine the dependencies of the part you want to cut from the document.
782
783 @subsection occt_ocaf_4_4 External Links
784
785 External links refer from one document to another. They allow you to update the copy of data  framework later on. 
786
787 @figure{/user_guides/ocaf/images/ocaf_image012.png,"External links between documents",360}
788
789 Note that documents can be copied with or without a possibility of updating an external link. 
790
791 @subsubsection occt_ocaf_4_4_1 Copying the document
792
793 #### With the possibility of updating it later
794
795 To copy a document with a possibility of updating it later, you use *TDocStd_XLinkTool::CopyWithLink*. 
796
797 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
798 Handle(TDocStd_Document) doc1; 
799 Handle(TDocStd_Document) doc2; 
800
801 TDF_Label source = doc1->GetData()->Root(); 
802 TDF_Label target = doc2->GetData()->Root(); 
803 TDocStd_XLinkTool XLinkTool; 
804
805 XLinkTool.CopyWithLink(target,source); 
806 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
807
808 Now 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. 
809
810 In 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*. 
811
812 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
813 XLinkTool.UpdateLink(target); 
814 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
815
816 #### Without any link between the copy and the original
817
818 You 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.* 
819
820 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
821 XLinkTool.Copy(target, source); 
822
823 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
824
825
826 @section occt_ocaf_5 OCAF Shape Attributes
827 @subsection occt_ocaf_5_1 Overview
828
829 A topological attribute can be seen as a hook into the topological structure. It is possible to attach data to define references to it.
830
831 OCAF 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. 
832
833 The 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. 
834
835 If 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. 
836
837 @figure{/user_guides/ocaf/images/ocaf_image013.png,"",455}
838
839 @subsection occt_ocaf_5_2 Shape attributes in data framework. 
840
841 Different algorithms may dispose sub-shapes of the result shape at the individual labels depending on whether it is necessary to do so: 
842
843 * 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.
844 * 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.
845
846 *TNaming_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. 
847
848 Consider 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. 
849
850 @figure{/user_guides/ocaf/images/ocaf_image014.png,"Resulting box",200}
851
852 After 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) and to the new shape resulting from the fuse operation, and has evolution MODIFY (see the following figure). 
853
854 Named shapes, which contain information about modified faces, belong to the fuse result sub-labels: 
855 * sub-label with tag 1 -- modified faces from box 1, 
856 * sub-label with tag 2 -- modified faces from box 2. 
857
858 @figure{/user_guides/ocaf/images/ocaf_image015.png,"",360}
859
860 This 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: 
861
862   * face F1’ as a modification of face F11  
863   * face F1’’ as generation of face F12 
864   * edges as an intersection of two contiguous faces
865   * vertices as an intersection of three contiguous faces
866
867 After 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. 
868
869 @subsection occt_ocaf_5_3 Registering shapes and their evolution
870
871 When using TNaming_NamedShape to create attributes, the following fields of an attribute are filled: 
872
873 * 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.
874 * The type of evolution, which is a term of the *TNaming_Evolution* enumeration used for the selected shapes that are placed to the separate label: 
875         * PRIMITIVE -- newly created topology, with no previous history;
876         * 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 );
877         * MODIFY -- the new shape is a modified old shape;
878         * DELETE -- the new shape is empty; the named shape with this evolution just indicates that the old shape topology is deleted from the model;
879         * SELECTED -- a named shape with this evolution has no effect on the history of the topology.
880
881 Only pairs of shapes with equal evolution can be stored in one named shape. 
882
883 @subsection occt_ocaf_5_4 Using naming resources
884
885 The class *TNaming_Builder* allows creating 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. 
886
887 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
888 // a new empty named shape is created at "label" 
889 TNaming_Builder builder(label); 
890 // set a pair of shapes with evolution GENERATED 
891 builder.Generated(oldshape1,newshape1); 
892 // set another pair of shapes with the same evolution 
893 builder.Generated(oldshape2,newshape2); 
894 // get the result - TNaming_NamedShape attribute 
895 Handle(TNaming_NamedShape) ns = builder.NamedShape(); 
896 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
897
898 @subsection occt_ocaf_5_5 Reading the contents of a named shape attribute
899
900 You can use the method <i>TNaming_NamedShape::Evolution()</i> to get the evolution of this named shape and the method <i>TNaming_NamedShape::Get()</i> to get a compound of new shapes of all pairs of this named shape.
901   
902 More detailed information about the contents of the named shape or about the modification history of a topology can be obtained with the following: 
903 * *TNaming_Tool* provides a common high-level functionality for access to the named shapes contents:
904         * The method <i>GetShape(Handle(TNaming_NamedShape)) </i>  returns a compound of new shapes of the given named shape;
905         * The method <i>CurrentShape(Handle(TNaming_NamedShape))</i>  returns a compound of the shapes, which are latest versions of the shapes from the given named shape;
906         * The method <i>NamedShape(TopoDS_Shape,TDF_Label) </i> returns a named shape, which contains a given shape as a new shape. A given label is any label from the data framework -- it just gives access to it.
907 * *TNaming_Iterator* gives access to the named shape and hooks pairs.
908
909 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
910 // create an iterator for a named shape 
911 TNaming_Iterator iter(namedshape); 
912 // iterate while some pairs are not iterated 
913 while(iter.More()) { 
914 // get the new shape from the current pair 
915 TopoDS_Shape newshape = iter.NewShape(); 
916 // get the old shape from the current pair 
917 TopoDS_Shape oldshape = iter.OldShape(); 
918 // do something... 
919
920 // go to the next pair 
921 iter.Next(); 
922
923 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
924
925
926 @subsection occt_ocaf_5_6 Topological naming
927
928 The Topological Naming mechanism is based on 3 components:
929 * History of the used modeling operation algorithm;
930 * Registering of the built result in Data Framework (i.e. loading the necessary elements of the extracted history in OCAF document);
931 * Selection / Recomputation of a "selected" sub-shape of the algorithm result.
932
933 To get the expected result the work of the three components should be synchronized and the rules of each component should be respected.
934
935 @subsubsection occt_ocaf_5_6_1 Algorithm history
936
937 The "correct" history of a used modeling operation serves the basis of naming mechanism. It should be provided by the algorithm supporting the operation. The history content depends on the type of the topological result. The purpose of the history is to provide all entities for consistent and correct work of the Selection / Recomputation mechanism. The table below presents expected types of entities depending on the result type.
938
939 | Result type | Type of sub-shapes to be returned by history of algorithm | Comments |
940 | :---------- | :-------------------------------------------------------- | :------- |
941 | Solid or closed shell | Faces | All faces |
942 | Open shell or single face | Faces and edges of opened boundaries only | All faces plus all edges of opened boundaries |
943 | Closed wire | Edges | All edges |
944 | Opened wire | Edges and ending vertexes | All edges plus ending vertexes of the wire |
945 | Edge | Vertexes |     Two vertexes are expected |
946 | Compound or CompSolid | To be used consequentially the above declared rule applied to all sub-shapes of the first level | Compound/CompSolid to be explored level by level until any the mentioned above types will be met | 
947
948 The history should return (and track) only elementary types of sub-shapes, i.e. Faces, Edges and Vertexes, while other so-called aggregation types: Compounds, Shells, Wires, are calculated by Selection mechanism automatically.
949
950 There are some simple exceptions for several cases. For example, if the Result contains a seam edge -- in conical, cylindrical or spherical surfaces -- this seam edge should be tracked by the history and in addition should be defined before the types. All degenerated entities should be filtered and excluded from consideration.
951
952 @subsubsection occt_ocaf_5_6_2 Loading history in data framework
953
954 All elements returned by the used algorithm according to the aforementioned rules should be put in the Data Framework (or OCAF document in other words) consequently in linear order under the so-called **Result Label**. 
955
956 The "Result Label" is *TDF_label* used to keep the algorithm result *Shape* from *TopoDS* in *NamedShape* attribute. During loading sub-shapes of the result in Data Framework should be used the rules of chapter @ref occt_ocaf_5_3.  These rules are also applicable for loading the main shape, i.e. the resulting shape produced by the modeling algorithm.
957
958 @subsubsection occt_ocaf_5_6_3 Selection / re-computation mechanism
959
960 When the Data Framework is filled with all impacted entities (including the data structures resulting from the current modeling operation and the data structures resulting from the previous modeling operations, on which the current operation depends) any sub-shape of the current result can be **selected**, i.e. the corresponding new naming data structures, which support this functionality, can be produced and kept in the Data Framework.
961
962 One of the user interfaces for topological naming is the class *TNaming_Selector*. It implements the above mentioned sub-shape "selection" functionality as an additional one. I.e. it can be used for:
963 * Storing the selected shape on a label -- its **Selection**;
964 * Accessing the named shape -- check the kept value of the shape
965 * Update of this naming -- recomputation of an earlier selected shape.
966
967 The selector places a new named shape with evolution **SELECTED** to the given label. The selector creates a **name** of the selected shape, which is a unique description (data structure) of how to find the selected topology using as resources:
968 * the given context shape, i.e. the main shape kept on **Result Label**, which contains a selected sub-shape, 
969 * its evolution and
970 * naming structure.
971
972 After any modification of a context shape and update of the corresponding naming structure, it is necessary to call method *TNaming_Selector::Solve*. If the naming structure, i.e. the above mentioned **name**, is correct, the selector automatically updates the selected sub-shape in the corresponding named shape, else it fails.
973
974 @subsection occt_ocaf_5_7 Exploring shape evolution
975
976 The class *TNaming_Tool* provides a toolkit to read current data contained in the attribute. 
977
978 If you need to create a topological attribute for existing data, use the method *NamedShape*. 
979
980 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
981 class MyPkg_MyClass 
982
983 public: Standard_Boolean SameEdge (const Handle(CafTest_Line)& L1, const Handle(CafTest_Line)& L2); 
984 }; 
985
986 Standard_Boolean CafTest_MyClass::SameEdge (const Handle(CafTest_Line)& L1, const Handle(CafTest_Line)& L2) 
987
988   Handle(TNaming_NamedShape) NS1 = L1->NamedShape(); 
989   Handle(TNaming_NamedShape) NS2 = L2->NamedShape(); 
990   return BRepTools::Compare(NS1,NS2); 
991
992 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
993
994
995 @subsection occt_ocaf_5_8 Example of topological naming usage
996
997 **Topological naming** is a mechanism of Open CASCADE aimed to keep reference to the selected shape. If, for example, we select a vertex of a solid shape and “ask” the topological naming to keep reference to this vertex, it will refer to the vertex whatever happens with the shape (translations, scaling, fusion with another shape, etc.).
998
999 Let us consider an example: imagine a wooden plate. The job is to drive several nails in it:
1000
1001 @figure{/user_guides/ocaf/images/ocaf_image020.png,"A nail driven in a wooden plate",360}
1002
1003 There may be several nails with different size and position. A **Hammer** should push each **Nail** exactly in the center point of the top surface. For this the user does the following:
1004 *       Makes several Nails of different height and diameter (according to the need),
1005 *       Chooses (selects) the upper surface of each Nail for the Hammer.
1006
1007 The job is done. The application should do the rest -- the Hammer calculates a center point for each selected surface of the Nail and “strikes” each Nail driving it into the wooden plate.
1008
1009 What happens if the user changes the position of some Nails? How will the Hammer know about it? It keeps reference to the surface of each Nail. However, if a Nail is relocated, the Hammer should know the new position of the selected surface. Otherwise, it will “strike” at the old position (keep the fingers away!)…
1010
1011 Topological naming mechanism should help the Hammer to obtain the relocated surfaces. The Hammer “asks” the mechanism to “resolve” the selected shapes by calling method *TNaming_Selection::Solve()* and the mechanism “returns” the modified surfaces located at the new position by calling  *TNaming_Selector::NamedShape()*.
1012
1013 The topological naming is represented as a “black box” in the example above. Now it is time to make the box a little more “transparent”.
1014
1015 The application contains 3 functions:
1016 * **Nail** -- produces a shape representing a nail,
1017 * **Translator** -- translates a shape along the wooden plate,
1018 * **Hammer** -- drives the nail in the wooden plate.
1019
1020 Each function gives the topological naming some hints how to “re-solve” the selected sub-shapes:
1021 * The Nail constructs a solid shape and puts each face of the shape into sub-labels: 
1022
1023 @figure{/user_guides/ocaf/images/ocaf_image021.png,"Distribution of faces through sub-labels of the Nail",185}
1024
1025 * The **Translator** moves a shape and registers modification for each face: it puts a pair: “old” shape -- “new” shape at a sub-label of each moving Nail. The “old” shape represents a face of the Nail at the initial position. The “new” shape -- is the same face, but at a new position:
1026
1027 @figure{/user_guides/ocaf/images/ocaf_image022.png,"Registration of relocation of faces of a Nail",240}
1028
1029 How does it work?
1030 * The Hammer selects a face of a Nail calling *TNaming_Selector::Select()*. This call makes a unique name for the selected shape. In our example, it will be a direct reference to the label of the top face of the Nail (Face 1).
1031 * When the user moves a Nail along the wooden plate, the Translator registers this modification by putting the pairs: “old” face of the Nail -- new face of the Nail into its sub-labels. 
1032 * When the Hammer calls *TNaming::Solve()*, the topological naming “looks” at the unique name of the selected shape and tries to re-solve it:
1033         * It finds the 1st appearance of the selected shape in the data tree -- it is a label under the Nail function *Face 1*.
1034         * It follows the evolution of this face. In our case, there is only one evolution -- the translation: *Face 1* (top face) -- <i>Face 1’</i> (relocated top face). So, the last evolution is the relocated top face.
1035 * Calling the method *TNaming_Selector::NamedShape()* the Hammer obtains the last evolution of the selected face -- the relocated top face.
1036
1037 The job is done.
1038
1039 P.S. Let us say a few words about a little more complicated case -- selection of a wire of the top face. Its topological name is an “intersection” of two faces. We remember that the **Nail** puts only faces under its label. So, the selected wire will represent an “intersection” of the top face and the conic face keeping the “head” of the nail. Another example is a selected vertex. Its unique name may be represented as an “intersection” of three or even more faces (depends on the shape).
1040
1041
1042 @section occt_ocaf_6 Standard Attributes
1043
1044 @subsection occt_ocaf_6_1 Overview
1045
1046 Standard attributes are 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: 
1047
1048   * Geometric attributes;
1049   * General attributes;
1050   * Relationship attributes;
1051   * Auxiliary attributes.
1052   
1053    
1054
1055 ### Geometric attributes
1056
1057   * **Axis** -- simply identifies, that the concerned *TNaming_NamedShape* attribute with an axis shape inside belongs to the same label; 
1058   * **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;
1059   * **Geometry** -- simply identifies, that the concerned *TNaming_NamedShape* attribute with a specified-type geometry belongs to the same label; 
1060   * **Plane** -- simply identifies, that the concerned *TNaming_NamedShape* attribute with a plane shape inside belongs to the same label;
1061   * **Point** -- simply identifies, that the concerned *TNaming_NamedShape* attribute with a  point shape inside belongs to the same label;
1062   * **Shape** -- simply identifies, that the concerned *TNaming_NamedShape* attribute belongs to the same label;
1063   * **PatternStd**  -- identifies one of five available pattern models (linear, circular, rectangular, circular rectangular and mirror);
1064   * **Position** -- identifies the position in 3d global space.
1065
1066 ### General attributes
1067
1068   * **AsciiString** -- contains AsciiString value;
1069   * **BooleanArray** -- contains an array of Boolean;
1070   * **BooleanList** -- contains a list of Boolean;
1071   * **ByteArray** -- contains an array of Byte (unsigned char) values;
1072   * **Comment** -- contains a string -- the comment for a given label (or attribute);
1073   * **Expression** -- contains an expression string and a list of used variables attributes;
1074   * **ExtStringArray** -- contains an array of *ExtendedString* values;
1075   * **ExtStringList** -- contains a list of *ExtendedString* values;
1076   * **Integer** -- contains an integer value;
1077   * **IntegerArray** -- contains an array of integer values;
1078   * **IntegerList** -- contains a list of integer values;
1079   * **IntPackedMap** -- contains a packed map of integers;
1080   * **Name** -- contains a string -- the name of a given label (or attribute);
1081   * **NamedData** -- may contain up to 6 of the following named data sets (vocabularies): *DataMapOfStringInteger, DataMapOfStringReal, DataMapOfStringString, DataMapOfStringByte, DataMapOfStringHArray1OfInteger* or *DataMapOfStringHArray1OfReal*;
1082   * **NoteBook** -- contains a *NoteBook* object attribute;
1083   * **Real** -- contains a real value;
1084   * **RealArray** -- contains an array of  real values;
1085   * **RealList** -- contains a list of real values;
1086   * **Relation** -- contains a relation string and a list of used variables attributes;
1087   * **Tick** -- defines a boolean attribute;
1088   * **Variable** -- simply identifies, that a variable belongs to this label; contains the flag *is constraint* and a string of used units ("mm", "m"...);
1089   * **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).
1090   
1091 ### Relationship attributes 
1092
1093   * **Reference** -- contains reference to the label of its own data framework;
1094   * **ReferenceArray** -- contains an array of references;
1095   * **ReferenceList** -- contains a list of references;
1096   * **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.
1097
1098 ### Auxiliary attributes
1099
1100   * **Directory** -- high-level tool attribute for sub-labels management;
1101   * **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.
1102
1103 All 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. 
1104
1105
1106 @subsection occt_ocaf_6_2 Services common to all attributes
1107
1108 @subsubsection occt_ocaf_6_2_1 Accessing GUIDs
1109
1110 To access the GUID of an attribute, you can use two methods: 
1111   * 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.
1112   * 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.
1113   
1114 To find an attribute attached to a specific label, you use the GUID of the attribute type you are looking for. This information can be found using the method  <i> GetID</i> and the method <i> Find</i> for the label as follows:
1115
1116 ~~~~
1117     Standard_GUID anID = MyAttributeClass::GetID();
1118     Standard_Boolean HasAttribute = aLabel.Find(anID,anAttribute);
1119 ~~~~
1120
1121 @subsubsection occt_ocaf_6_2_2 Conventional Interface of Standard Attributes
1122
1123 It is usual to create standard named methods for the attributes: 
1124
1125   * 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.
1126   * Method *Get()* returns the value of an attribute if it is characterized by one value.
1127   * Method *Dump(Standard_OStream)* outputs debug information about a given attribute to a given stream.
1128   
1129 @subsection occt_ocaf_6_3 The choice between standard and custom attributes
1130
1131 When you start to design an application  based on OCAF, usually it is necessary to choose, which attribute will be used for allocation of data in the OCAF document: standard or newly-created?
1132
1133 It is possible to describe any model by means of standard OCAF attributes. 
1134   However, it is still a question if  this description will be  efficient in terms of memory and speed, and, at the same time, convenient to use.
1135   
1136   This depends on a particular model.  
1137    
1138   OCAF imposes the restriction that only one attribute type may be allocated to one label. 
1139   It is necessary to take into  account the design of the application data tree. 
1140   For example, if a label should  possess several double values, 
1141   it is necessary to distribute them through several child sub-labels or use an array of double values.   
1142    
1143   Let us consider several boundary implementations of the same model in OCAF tree and analyze the advantages and disadvantages of each approach.  
1144
1145   
1146 @subsubsection occt_ocaf_6_2_3 Comparison  and analysis of approaches
1147
1148   Below are described two different model implementations: 
1149   one is based on standard OCAF attributes and the other is based 
1150   on the creation of a new attribute possessing all data of the model.  
1151    
1152   A load is distributed through the shape. The measurements are taken at particular points defined by (x, y and z) co-ordinates. The load is represented as a projection onto X, Y and Z axes of the local co-ordinate system at each point of measurement. A matrix of transformation is needed 
1153   to convert the local co-ordinate system to the global one, but this is optional.   
1154    
1155   So, we have 15 double values at each point  of measurement. 
1156   If the number of such points is 100 000, for example, it means 
1157   that we have to store 1 500 000 double values in the OCAF document.  
1158    
1159   The first  approach consists in using standard OCAF attributes. 
1160   Besides, there are several  variants of how the standard attributes may be used:  
1161   * Allocation of all 1 500 000 double values as one array of double values attached to one label;
1162   * Allocation of values of one measure of load (15 values) as one array of double values and attachment of one point of measure to one label;
1163   * Allocation of each point of measure as an array of 3 double values attached to one label, the projection of load onto the local co-ordinate system  axes as another array of 3 double values attached to a sub-label, and the matrix of projection (9 values) as the third array also attached to a sub-label.  
1164   
1165   Certainly, other variants are also  possible.   
1166  
1167 @figure{ocaf_tree_wp_image003.png,"Allocation of all data as one  array of double values",350}
1168  
1169   The first approach to allocation of all  data represented as one array of double values 
1170   saves initial memory and is easy to implement. 
1171   But access to the data is difficult because the values are stored in a flat array. 
1172   It will be necessary to implement a class with several methods giving access 
1173   to particular fields like the measurement points, loads and so  on.  
1174    
1175   If the values may be edited in the  application, 
1176   it means that the whole array will be backed-up on each edition. 
1177   The memory usage will increase very fast! 
1178   So, this approach may be considered only in case of non-editable data.  
1179    
1180   Let’s consider the allocation of data of  each measurement point per label (the second case). 
1181   In this case we create 100  000 labels -- one label for each measurement point 
1182   and attach an array of double  values to these labels:  
1183  
1184 @figure{ocaf_tree_wp_image004.png,"Allocation of data of each  measurement point as arrays of double values",288}
1185  
1186   Now edition of data is safer as far as  memory usage is concerned. 
1187   Change of value for one measurement point (any  value: point co-ordinates, load, and so on) 
1188   backs-up only one small array of double values. 
1189   But this structure (tree) requires more memory space (additional  labels and attributes).  
1190    
1191   Besides, access to the values is still difficult and it is necessary 
1192   to have a class with methods of access to the  array fields.  
1193    
1194   The third case of allocation of data  through OCAF tree is represented below:  
1195
1196 @figure{ocaf_tree_wp_image005.png,"Allocation of data into separate arrays of double values",354}
1197
1198   In this case sub-labels are involved and we  can easily access the values of each measurement point, 
1199   load or matrix. We don’t need an interface class with methods of access to the data 
1200   (if it exists, it would help to use the data structure, but this is optional).  
1201
1202   On the one hand, this approach requires more  memory for allocation of the attributes (arrays of double values). 
1203   On the other  hand, it saves memory during the edition of data 
1204   by backing-up only the small array containing the modified data. 
1205   So, if the data is fully modifiable, this  approach is more preferable.  
1206
1207   Before making a conclusion, let’s consider the same model implemented through a newly created OCAF attribute.  
1208
1209   For example, we might allocate all data  belonging to one measurement point as one OCAF attribute. 
1210   In this case we  implement the third variant of using the standard attributes (see picture 3), 
1211   but we use less memory (because we use only one attribute instead of three):  
1212  
1213 @figure{ocaf_tree_wp_image006.png,"Allocation of data into newly  created OCAF attribute",383}
1214
1215   The second variant of using standard OCAF attributes still has drawbacks: 
1216   when data is edited, OCAF backs-up all values  of the measurement point.   
1217    
1218   Let’s imagine that we have some  non-editable data. 
1219   It would be better for us to allocate this data separately from editable data. 
1220   Back-up will not affect non-editable data and memory will not increase so much during data edition.  
1221   
1222  @subsubsection occt_ocaf_6_2_4 Conclusion
1223
1224   When deciding which variant of data model implementation to choose, 
1225   it is necessary to take into account the application  response time, 
1226   memory allocation and memory usage in transactions.   
1227    
1228   Most of the models may be implemented using only standard OCAF attributes. 
1229   Some other models need special treatment and require implementation of new OCAF attributes.
1230
1231     
1232 @section occt_ocaf_7 Visualization Attributes
1233
1234 @subsection occt_ocaf_7_1 Overview
1235
1236 Standard visualization attributes implement the Application Interactive Services (see @ref occt_user_guides__visualization "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. 
1237
1238 @subsection occt_ocaf_7_2 Services provided
1239
1240 @subsubsection occt_ocaf_7_2_1 Defining an interactive viewer attribute
1241
1242 The 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. 
1243
1244 To initialize the AIS viewer as in the example below, use method *Find*. 
1245
1246 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1247 // "access" is any label of the data framework 
1248 Handle(TPrsStd_AISViewer) viewer = TPrsStd_AISViewer::Find(access) 
1249 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1250
1251 @subsection occt_ocaf_7_2_2 Defining a presentation attribute
1252
1253 The 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. 
1254
1255 @subsubsection occt_ocaf_7_2_3 Creating your own driver
1256
1257 The 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. 
1258
1259 If 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: 
1260 @figure{/user_guides/ocaf/images/ocaf_image016.png,"",420}
1261
1262 As usual, the GUID of a driver and the GUID of a displayed attribute are the same. 
1263
1264 @subsubsection occt_ocaf_7_2_4 Using a container for drivers
1265
1266 You 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. 
1267
1268 To 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. 
1269
1270 **Example** 
1271 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1272 DriverTable::Get() -> InitStandardDrivers(); 
1273 // next, attach your named shape to a label 
1274 TPrsStd_AISPresentation::Set(NS}; 
1275 // here, attach the AISPresentation to NS. 
1276 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1277
1278
1279 @section occt_ocaf_8 Function Services
1280
1281 Function 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. 
1282
1283 When 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. 
1284
1285 @figure{/user_guides/ocaf/images/ocaf_image008.png,"Document structure",360}
1286
1287 Take, 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. 
1288
1289 @subsection occt_ocaf_8_1 Finding functions, their owners and roots
1290
1291 The 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. 
1292
1293 You 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. 
1294
1295 Then 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. 
1296
1297 @subsection occt_ocaf_8_2 Storing and accessing information about function status
1298
1299 For 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. 
1300
1301 @subsection occt_ocaf_8_3 Propagating modifications
1302
1303 An application must implement its functions, function drivers and the common solver for parametric model creation. For example, check the following model: 
1304
1305 @figure{/user_guides/ocaf/images/ocaf_image017.png,"",360}
1306
1307 The procedure of its creation is as follows:
1308   * create a rectangular planar face *F* with height 100 and width 200;
1309   * create prism *P* using face *F* as a basis;
1310   * create fillet *L* at the edge of the prism;
1311   * change the width of *F* from 200 to 300;
1312   * the solver for the function of face *F* starts;
1313   * the solver detects that an argument of the face *F* function has been modified;
1314   * the solver calls the driver of the face *F* function for a  regeneration of the face;
1315   * 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;
1316
1317   * the solver detects the function of *P* -- it depends on the function of *F*;
1318   * the solver calls the driver of the prism *P* function;
1319   * the driver rebuilds prism *P* and adds the label of this prism to the logbook as  impacted;
1320   * the solver detects the function of *L*  -- it depends on the function of *P*;
1321   * the solver calls the *L* function driver;
1322   * the driver rebuilds fillet *L* and adds the label of the fillet to the logbook as impacted.
1323   
1324  @section occt_ocaf_8a Example of Function Mechanism Usage
1325  
1326  @subsection occt_ocaf_8a_1 Introduction
1327
1328   Let us describe the usage of the Function Mechanism of Open CASCADE Application Framework on a simple example.  
1329   This example represents a "nail" composed by a cone and two cylinders of different radius and height:  
1330
1331 @figure{ocaf_functionmechanism_wp_image003.png,"A nail",160}
1332
1333   These three objects (a cone and two cylinders) are  independent, 
1334   but the Function Mechanism makes them connected to each other and representing one object -- a nail.  
1335   The object "nail" has the following parameters:  
1336   
1337   * The position of the nail is defined by the apex point of the  cone. 
1338    The cylinders are built on the cone and therefore they depend on the position  of the cone. 
1339    In this way we define a dependency of the cylinders on the cone.  
1340   * The height of the nail is defined by the height of the cone.  
1341    Let’s consider that the long cylinder has 3 heights of the cone 
1342    and the header cylinder has a half of the height of the cone.  
1343   * The radius of the nail is defined by the radius of the cone. 
1344   The radius of the long cylinder coincides with this value. 
1345   Let’s consider that the  header cylinder has one and a half radiuses of the cone.  
1346   
1347   So, the cylinders depend on the cone and the cone  parameters define the size of the nail.  
1348   
1349   It means that re-positioning the cone (changing its  apex point) moves the nail, 
1350   the change of the radius of the cone produces a thinner or thicker nail, 
1351   and the change of the height of the cone shortens or  prolongates the nail.  
1352    It is suggested to examine the programming steps needed to create a 3D parametric model of the "nail".  
1353   
1354 @subsection occt_ocaf_8a_2 Step 1: Data Tree
1355
1356   The first step consists in model data allocation in the OCAF tree. 
1357   In other words, it is necessary to decide where to put the data.  
1358   
1359   In this case, the data can be organized into a simple tree 
1360   using references for definition of dependent parameters:  
1361
1362 * Nail
1363         * Cone
1364                 + Position (x,y,z)
1365                 + Radius 
1366                 + Height
1367         * Cylinder (stem)
1368                 + Position = "Cone" position translated for "Cone" height along Z;
1369                 + Radius = "Cone" radius;
1370                 + Height = "Cone" height multiplied by 3;
1371         * Cylinder (head)  
1372                 + Position = "Long cylinder" position translated for "Long cylinder" height along Z;
1373                 + Radius = "Long cylinder" radius multiplied by 1.5;
1374                 + Height = "Cone" height divided by 2. 
1375
1376   The "nail" object has three sub-leaves in the tree:  the cone and two cylinders.   
1377   
1378   The cone object is independent.  
1379   
1380   The long cylinder representing a "stem" of the nail  refers to the corresponding parameters 
1381   of the cone to define its own data  (position, radius and height). It means that the long cylinder depends on the  cone.  
1382   
1383   The parameters of the head cylinder may be expressed  through the cone parameters 
1384   only or through the cone and the long cylinder  parameters. 
1385   It is suggested to express the position and the radius of the head cylinder 
1386   through the position and the radius of the long cylinder, and the height 
1387   of the head cylinder through the height of the cone. 
1388   It means that the head cylinder depends on the cone and the long cylinder.  
1389
1390 @subsection occt_ocaf_8a_3 Step 2: Interfaces
1391
1392   The interfaces of the data model are responsible for dynamic creation 
1393   of the data tree of the represented at the previous step, data  modification and deletion.  
1394   
1395   The interface called *INail*  should contain the methods for creation 
1396   of the data tree for the nail, setting  and getting of its parameters, computation, visualization and removal.  
1397
1398 @subsubsection occt_ocaf_8a_3_1 Creation of the nail
1399
1400   This method of the interface creates a data tree for the nail  at a given leaf of OCAF data tree.  
1401   
1402   It creates three sub-leaves for the cone and two cylinders  and allocates the necessary data (references at the sub-leaves of the long and the  head cylinders).  
1403   
1404   It sets the default values of position, radius and height of  the nail.  
1405   
1406   The nail has the following user parameters:  
1407   * The position -- coincides with the position of the cone  
1408   * The radius of the stem part of the nail -- coincides with the radius  of the cone  
1409   * The height of the nail -- a sum of heights of the cone and both  cylinders  
1410   
1411   The values of the position and the radius of the  nail are defined for the cone object data. 
1412   The height of the cone is recomputed  as 2 * heights of nail and divided by 9.  
1413
1414 @subsubsection occt_ocaf_8a_3_2 Computation
1415
1416   The Function Mechanism is responsible for re-computation of  the nail. 
1417   It will be described in detail later in this document.  
1418   
1419   A data leaf consists of the reference  to the location of the  real data 
1420   and a real value defining a coefficient of multiplication of the  referenced data.  
1421   
1422   For example, the height of the long cylinder is defined as a  reference to the height of the cone 
1423   with coefficient 3. The data  leaf of the height of the long cylinder 
1424   should contain two attributes: a  reference to the height of cone and a real value equal to 3.  
1425
1426 @subsubsection occt_ocaf_8a_3_3 Visualization
1427
1428  The shape resulting of the nail function can be displayed using the standard OCAF visualization mechanism.  
1429
1430 @subsubsection occt_ocaf_8a_3_4 Removal of the nail
1431
1432 To automatically erase the nail from the viewer and the data  tree it is enough to clean the nail leaf from attributes.  
1433
1434 @subsection occt_ocaf_8a_4 Step 3: Functions
1435
1436   The nail is defined by four functions: the cone, the two cylinders  and the nail function.  
1437   The function of the cone is independent. The functions of the cylinders depend on the cone function. 
1438   The nail function depends on the  results of all functions:  
1439
1440 @figure{ocaf_functionmechanism_wp_image005.png,"A graph of dependencies between functions",232}
1441
1442   Computation of the model starts with the cone function, then the long cylinder, 
1443   after that the header cylinder and, finally, the result is generated  by the nail function at the end of function chain.  
1444
1445   The Function Mechanism of Open CASCADE Technology creates this  graph of dependencies 
1446   and allows iterating it following the dependencies. 
1447   The  only thing the Function Mechanism requires from its user 
1448   is the implementation  of pure virtual methods of *TFunction_Driver*:  
1449   
1450   * <i>\::Arguments()</i> -- returns a list of arguments for the  function  
1451   * <i>\::Results()</i> -- returns a list of results of the function  
1452   
1453   These methods give the Function Mechanism the information on the location of arguments 
1454   and results of the function and allow building a  graph of functions. 
1455   The class *TFunction_Iterator* iterates the functions of the graph in the execution order.  
1456   
1457   The pure virtual method *TFunction_Driver::Execute()* calculating the function should be overridden.  
1458   
1459   The method <i>\::MustExecute()</i> calls the method <i>\::Arguments()</i>  of the function driver 
1460   and ideally this information (knowledge of modification  of arguments of the function) is enough
1461   to make a decision whether the function  should be executed or not. Therefore, this method usually shouldn’t be  overridden.  
1462
1463   The cone and cylinder functions differ only in geometrical construction algorithms. 
1464   Other parameters are the same (position, radius and height).  
1465   
1466   It means that it is possible to create a base class -- function driver for the three functions, 
1467   and two descendant classes producing:  a cone or a cylinder.  
1468   
1469   For the base function driver the methods <i>\::Arguments()</i>  and <i>\::Results()</i> will be overridden. 
1470   Two descendant function drivers responsible for creation of a cone and a cylinder will override only the method  <i>\::Execute()</i>. 
1471   
1472   The method <i>\::Arguments()</i> of the function driver of the nail returns the results of the functions located under it in the tree of leaves.   The method <i>\::Execute()</i> just collects the  results of the functions and makes one shape -- a nail. 
1473   
1474   This way the data model using the Function Mechanism is  ready for usage.   Do not forget to introduce the function drivers for a function  driver table with the help of *TFunction_DriverTable* class.
1475
1476 @subsection occt_ocaf_8a_5 Example 1: iteration and execution of functions. 
1477
1478   This is an example of the code for iteration and execution of functions.  
1479
1480 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1481
1482     // The scope of functions is  defined.  
1483     Handle(TFunction_Scope) scope = TFunction_Scope::Set( anyLabel );  
1484      
1485     // The information on  modifications in the model is received.  
1486     TFunction_Logbook&amp; log = scope-GetLogbook();  
1487      
1488     // The iterator is iInitialized by  the scope of functions.  
1489     TFunction_Iterator iterator( anyLabel );  
1490     Iterator.SetUsageOfExecutionOrder( true );  
1491      
1492     // The function is iterated,  its  dependency is checked on the modified data and  executed if necessary.  
1493     for (; iterator.more(); iterator.Next())  
1494     {  
1495       // The function iterator may return a list of  current functions for execution.  
1496       // It might be useful for multi-threaded execution  of functions.  
1497       const  TDF_LabelList&amp; currentFunctions = iterator.Current();  
1498        
1499       //The list of current functions is iterated.  
1500       TDF_ListIteratorOfLabelList  currentterator( currentFucntions );  
1501       for (;  currentIterator.More(); currentIterator.Next())  
1502       {  
1503         //  An interface for the function is created.  
1504         TFunction_IFunction  interface( currentIterator.Value() );  
1505      
1506         //  The function driver is retrieved.  
1507         Handle(TFunction_Driver)  driver = interface.GetDriver();  
1508      
1509         //  The dependency of the function on the  modified data is checked.  
1510         If  (driver-MustExecute( log ))  
1511         {  
1512           // The function is executed.  
1513           int  ret = driver-Execute( log );  
1514           if ( ret ) 
1515             return  false;  
1516         } // end if check on modification  
1517       } // end of iteration of current functions  
1518     } // end of iteration of  functions.
1519
1520 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1521
1522 @subsection occt_ocaf_8a_6 Example 2: Cylinder function driver
1523
1524   This is an example of the code for a cylinder function driver. To make the things clearer, the methods <i>\::Arguments()</i>  and <i>\::Results()</i>  from the base class are also mentioned.   
1525
1526 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1527
1528     // A virtual method  ::Arguments() returns a list of arguments of the function.  
1529     CylinderDriver::Arguments( TDF_LabelList&amp; args )  
1530     {  
1531       // The direct arguments, located at sub-leaves of  the fucntion, are collected (see picture 2).  
1532       TDF_ChildIterator  cIterator( Label(), false );  
1533       for (;  cIterator.More(); cIterator.Next() )  
1534       {  
1535         // Direct argument.  
1536         TDF_Label  sublabel = cIterator.Value();  
1537         Args.Append(  sublabel );  
1538
1539         // The references to the external data are  checked.  
1540         Handle(TDF_Reference)  ref;  
1541         If (  sublabel.FindAttribute( TDF_Reference::GetID(), ref ) )  
1542         {  
1543           args.Append(  ref-Get() );  
1544         }
1545     }
1546      
1547     // A virtual method ::Results()  returns a list of result leaves.  
1548     CylinderDriver::Results( TDF_LabelList&amp; res )  
1549     {  
1550       // The result is kept at the function  label.  
1551       Res.Append(  Label() );  
1552     }
1553      
1554     // Execution of the function  driver.  
1555     Int CylinderDriver::Execute( TFunction_Logbook&amp; log )  
1556     {  
1557       // Position of the cylinder - position of the first  function (cone)   
1558       //is  elevated along Z for height values of all  previous functions.  
1559       gp_Ax2 axes = …. // out of the scope of this guide.  
1560       // The radius value is retrieved.  
1561       // It is located at second child sub-leaf (see the  picture 2).  
1562       TDF_Label radiusLabel  = Label().FindChild( 2 );  
1563        
1564       // The multiplicator of the radius ()is retrieved.  
1565       Handle(TDataStd_Real)  radiusValue;  
1566       radiusLabel.FindAttribute(  TDataStd_Real::GetID(), radiusValue);  
1567        
1568       // The reference to the radius is retrieved.  
1569       Handle(TDF_Reference)  refRadius;  
1570       RadiusLabel.FindAttribute(  TDF_Reference::GetID(), refRadius );  
1571        
1572       // The radius value is calculated.  
1573       double radius = 0.0;
1574       
1575       if (  refRadius.IsNull() )
1576       {
1577         radius  = radiusValue-Get();  
1578       }
1579       else  
1580       {  
1581         // The referenced radius value is  retrieved.   
1582         Handle(TDataStd_Real)  referencedRadiusValue;  
1583         RefRadius-Get().FindAttribute(TDataStd_Real::GetID()  ,referencedRadiusValue );  
1584         radius  = referencedRadiusValue-Get() * radiusValue-Get();  
1585       }  
1586        
1587       // The height value is retrieved.  
1588       double height = … // similar code to taking the radius value.  
1589        
1590       // The cylinder is created.  
1591       TopoDS_Shape cylinder  = BRepPrimAPI_MakeCylinder(axes, radius, height);  
1592        
1593       // The result (cylinder) is set  
1594       TNaming_Builder  builder( Label() );  
1595       Builder.Generated(  cylinder );  
1596        
1597       // The modification of the result leaf is saved in  the log.  
1598       log.SetImpacted(  Label() );  
1599        
1600       return 0;
1601     }
1602 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1603  
1604   
1605
1606 @section occt_ocaf_9 XML Support
1607
1608 Writing and reading XML files in OCCT is provided by LDOM package, which constitutes an integral part
1609 of XML OCAF persistence, which is the optional component provided on top of Open CASCADE Technology.
1610
1611 The 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: 
1612 * 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* and *LDOM_CDATASection* -- represent the corresponding XML types and serve as branches of the tree of elements. 
1613 * Provide class *LDOM_Parser* to read XML files and convert them to *LDOM_Document* objects.
1614 * Provide class *LDOM_XmlWriter* to convert *LDOM_Document* to a character stream in XML format and store it in file. 
1615
1616 This 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: 
1617 * 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). 
1618 * To minimize the time required for parsing and formatting XML, as well as for access to DOM data structures. 
1619
1620 Both 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:
1621 * 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. 
1622 * Some superfluous methods are deleted: *getPreviousSibling, getParentNode,* etc. 
1623 * No resolution of XML Entities of any kind 
1624 * No support for DTD: the parser just checks for observance of general XML rules and never validates documents. 
1625 * Only 5 available types of DOM nodes: *LDOM_Element, LDOM_Attr, LDOM_Text, LDOM_Comment* and *LDOM_CDATASection*. 
1626 * No support of Namespaces; prefixed names are used instead of qualified names. 
1627 * No support of the interface *DOMException* (no exception when attempting to remove a non-existing node). 
1628
1629 LDOM 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. 
1630
1631 @subsection occt_ocaf_9_1 Document Drivers
1632
1633 The drivers for document storage and retrieval  manage  conversion between a transient OCAF
1634 Document in memory and its persistent reflection in a container (disk, memory, network). For XML Persistence, they are defined in the package XmlDrivers. 
1635
1636 The main methods (entry points) of these drivers are: 
1637 * *Write()* -- for a storage driver; 
1638 * *Read()* -- for a retrieval driver. 
1639
1640 The 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: 
1641
1642 First it is necessary to convert the transient document into another form (called persistent), suitable for writing into a file, and vice versa. 
1643 In XML Persistence LDOM_Document is used as the persistent form of an OCAF Document and the DOM_Nodes are the persistent objects. 
1644 An OCAF Document is a tree of labels with attributes. Its transformation into a persistent form can be functionally divided into two parts: 
1645 * Conversion of the labels structure, which is performed by the method XmlMDF::FromTo()
1646 * Conversion of the attributes and their underlying objects, which is performed by the corresponding attribute drivers (one driver per attribute type). 
1647
1648 The driver for each attribute is selected from a table of drivers, either by attribute
1649 type (on storage) or by the name of the corresponding DOM_Element (on retrieval).
1650 The table of drivers is created by by methods *XmlDrivers_DocumentStorageDriver::AttributeDrivers()*
1651 and *XmlDrivers_DocumentRetrievalDriver::AttributeDrivers()*. 
1652
1653 Then the persistent document is written into a file (or read from a file). 
1654 In 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.
1655
1656 Usually, 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. 
1657
1658 The 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. 
1659
1660 @subsection occt_ocaf_9_2 Attribute Drivers
1661
1662 There 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 <i>T*_*</i> is called <i>XmlM*_*</i>. Conversion between transient and persistent form of attribute is performed by two methods *Paste()* of attribute driver. 
1663
1664 *XmlMDF_ADriver* is the root class for all attribute drivers.
1665
1666 At 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. 
1667
1668 Every 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. 
1669
1670 The 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. 
1671
1672 @subsection occt_ocaf_9_3 XML Document Structure
1673
1674 Every 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:
1675 * **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. 
1676 * **Element comments** -- consists of an unlimited number of \<comment\> sub-elements containing necessary comment strings. 
1677 * **Element label** -- 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).
1678 * **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*.
1679
1680 ### OCAF Attributes Representation 
1681
1682 In 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. 
1683 For 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. 
1684 XML 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. 
1685
1686 ### Example of resulting XML file 
1687
1688 The 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. 
1689
1690 ~~~~
1691 <?xml version="1.0" encoding="UTF-8"?> 
1692 <document format="XmlOcaf" xmlns="http://www.opencascade.org/OCAF/XML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1693 xsi:schemaLocation="http://www.opencascade.org/OCAF/XML http://www.opencascade.org/OCAF/XML/XmlOcaf.xsd">
1694
1695 <info date="2001-10-04" schemav="0" objnb="3"> 
1696 <iitem>Copyright: Open Cascade, 2001</iitem> 
1697 <iitem>STORAGE_VERSION: PCDM_ReadWriter_1</iitem> 
1698 <iitem>REFERENCE_COUNTER: 0</iitem> 
1699 <iitem>MODIFICATION_COUNTER: 1</iitem> 
1700 </info> 
1701 <comments/> 
1702 <label tag="0"> 
1703 <TDataStd_Name id="1">Document_1</TDataStd_Name> 
1704 <label tag="2"> 
1705 <TNaming_NamedShape id="2" evolution="primitive"> 
1706 <olds/> 
1707 <news> 
1708 <shape tshape="+34" index="1"/> 
1709 </news> 
1710 </TNaming_NamedShape> 
1711 </label> 
1712 </label> 
1713 \<shapes\> 
1714 ... 
1715 </shapes> 
1716 </document> 
1717
1718 ~~~~
1719
1720 @subsection occt_ocaf_9_4 XML Schema
1721
1722 The XML Schema defines the class of a document. 
1723
1724 The 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). 
1725
1726 There 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. 
1727
1728 The Schema files (XSD) are intended for two purposes: 
1729 * documenting the data format of files generated by OCAF; 
1730 * validation of documents when they are used by external (non-OCAF) applications, e.g., to generate reports. 
1731
1732 The 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. 
1733
1734 ### Management of Namespaces 
1735
1736 Both 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 <i>[File XmlXcaf.xsd]</i>. For the correct management of Namespaces it is necessary to: 
1737 * Define *targetNamespace* in the new XSD file describing the format. 
1738 * 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:"). 
1739 * 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. 
1740 * Pass (in every OCAF attribute driver) the namespace prefix of the *targetNamespace* to the constructor of *XmlMDF_ADriver*. 
1741
1742 @section occt_ocaf_10 GLOSSARY
1743
1744 * **Application** -- a document container holding all documents containing all application data. 
1745 * **Application data** -- the data produced by an application, as opposed to data referring to it. 
1746 * **Associativity of data** -- the ability to propagate modifications made to one document to other documents, which refer to such document. Modification propagation is: 
1747   * unidirectional, that is, from the referenced to the referencing document(s), or
1748   * bi-directional, from the referencing to the referenced document and vice-versa.
1749 * **Attribute** -- a container for application data. An attribute is attached to a label in the hierarchy of the data framework. 
1750 * **Child** -- a label created from another label, which by definition, is the father label. 
1751 * **Compound document** -- a set of interdependent documents, linked to each other by means of external references. These references provide the associativity of data. 
1752 * **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. 
1753 * **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: 
1754         * Manage modifications, providing Undo and Redo functions 
1755         * Manage command transactions 
1756         * Update external links 
1757         * Manage save and restore options 
1758         * Store the names of software extensions. 
1759 * **Driver** -- an abstract class, which defines the communications protocol with a system. 
1760 * **Entry** -- an ASCII character string containing the tag list of a label. For example:
1761 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1762 0:3:24:7:2:7 
1763 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1764
1765 * **External links** -- references from one data structure to another data structure in another document. 
1766 To store these references properly, a label must also contain an external link attribute. 
1767 * **Father** -- a label, from which other labels have been created. The other labels are, by definition, the children of this label. 
1768 * **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: 
1769   * defining new classes which inherit from these abstract classes
1770   * composing framework class instances
1771   * implementing the services required by the framework.
1772
1773 In C++, the application behavior is implemented in virtual functions redefined in these derived classes. This is known as overriding. 
1774
1775 * **GUID** -- Global Universal ID. A string of 37 characters intended to uniquely identify an object. For example:
1776 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1777 2a96b602-ec8b-11d0-bee7-080009dc3333 
1778 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1779
1780 * **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. 
1781 * **Modified label** -- containing attributes whose data has been modified. 
1782 * **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. 
1783 * **Resource file** -- a file containing a list of each document’s schema name and the storage and retrieval plug-ins for that document. 
1784 * **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. 
1785 * **Scope** -- the set of all the attributes and labels which depend on a given label. 
1786 * **Tag list** -- a list of integers, which identify the place of a label in the data framework.  This list is displayed in an entry. 
1787 * **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. 
1788 * **Topological tracking** -- following a topological entity in a model through the steps taken to edit and regenerate that model. 
1789 * **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.   
1790
1791 @section occt_ocaf_11 Samples
1792
1793 @subsection occt_ocaf_11_a Getting  Started
1794
1795   At the beginning of your development, you first define  an application class by inheriting from the Application abstract class. 
1796   You only have to create and determine the resources of the application 
1797   for specifying the format of your documents (you generally use the standard one)  and their file extension.  
1798    
1799   Then, you design the application data model by  organizing attributes you choose among those provided with OCAF. 
1800   You can specialize these attributes using the User attribute. For example, if you need  a reflection coefficient, 
1801   you aggregate a User attribute identified as a  reflection coefficient 
1802   with a Real attribute containing the value of the  coefficient (as such, you don't define a new class).  
1803    
1804   If you need application specific data not provided with  OCAF, for example, 
1805   to incorporate a finite element model in the data structure,  
1806   you define a new attribute class containing the mesh, 
1807   and you include its persistent homologue in a new file format.  
1808    
1809   Once you have implemented the commands which create and modify the data structure 
1810   according to your specification, OCAF provides you, without any additional programming:  
1811    
1812   * Persistent  reference to any data, including geometric elements — several documents can be  linked with such reference;
1813   * Document-View  association;
1814   * Ready-to-use  functions such as :
1815     * Undo-redo;  
1816     * Save and open application data.  
1817  
1818   Finally, you  develop the application's graphical user interface using the toolkit of your  choice, for example:
1819   * KDE Qt or  GNOME GTK+ on Linux;
1820   * Microsoft  Foundation Classes (MFC) on Windows Motif on Sun;
1821   * Other  commercial products such as Ilog Views.
1822  
1823   You can also implement the user interface in the Java language using 
1824   the Swing-based Java Application Desktop component (JAD)  provided with OCAF.  
1825   
1826 @subsection occt_ocaf_11_1 Implementation of Attribute Transformation in a HXX file
1827
1828 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1829 #include <TDF_Attribute.hxx>
1830
1831 #include <gp_Ax3.hxx>
1832 #include <gp_Pnt.hxx>
1833 #include <gp_Vec.hxx>
1834 #include <gp_Trsf.hxx>
1835
1836 // This attribute implements a transformation data container
1837 class MyPackage_Transformation : public TDF_Attribute
1838 {
1839 public:
1840   //!@ name Static methods 
1841
1842   //! The method returns a unique GUID of this attribute. 
1843   //! By means of this GUID this attribute may be identified   
1844   //! among other attributes attached to the same label. 
1845   Standard_EXPORT static const Standard_GUID& GetID ();
1846
1847   //! Finds or creates the attribute attached to <theLabel>. 
1848   //! The found or created attribute is returned. 
1849   Standard_EXPORT static Handle(MyPackage_Transformation) Set (const TDF_Label theLabel);
1850
1851   //!@ name Methods for access to the attribute data 
1852       
1853   //! The method returns the transformation. 
1854   Standard_EXPORT gp_Trsf Get () const; 
1855
1856   //!@ name Methods for setting the data of transformation 
1857
1858   //! The method defines a rotation type of transformation. 
1859   Standard_EXPORT void SetRotation (const gp_Ax1& theAxis, Standard_Real theAngle); 
1860
1861   //! The method defines a translation type of transformation. 
1862   Standard_EXPORT void SetTranslation (const gp_Vec& theVector); 
1863
1864   //! The method defines a point mirror type of transformation (point symmetry). 
1865   Standard_EXPORT void SetMirror (const gp_Pnt& thePoint); 
1866
1867   //! The method defines an axis mirror type of transformation (axial symmetry). 
1868   Standard_EXPORT void SetMirror (const gp_Ax1& theAxis); 
1869
1870   //! The method defines a point mirror type of transformation (planar symmetry). 
1871   Standard_EXPORT void SetMirror (const gp_Ax2& thePlane); 
1872
1873   //! The method defines a scale type of transformation. 
1874   Standard_EXPORT void SetScale (const gp_Pnt& thePoint, Standard_Real theScale); 
1875
1876   //! The method defines a complex type of transformation from one co-ordinate system to another. 
1877   Standard_EXPORT void SetTransformation (const gp_Ax3& theCoordinateSystem1, const gp_Ax3& theCoordinateSystem2); 
1878
1879   //!@ name Overridden methods from TDF_Attribute 
1880       
1881   //! The method returns a unique GUID of the attribute. 
1882   //! By means of this GUID this attribute may be identified among other attributes attached to the same label. 
1883   Standard_EXPORT const Standard_GUID& ID () const; 
1884
1885   //! The method is called on Undo / Redo. 
1886   //! It copies the content of theAttribute into this attribute (copies the fields). 
1887   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& theAttribute); 
1888
1889   //! It creates a new instance of this attribute. 
1890   //! It is called on Copy / Paste, Undo / Redo. 
1891   Standard_EXPORT Handle(TDF_Attribute) NewEmpty () const;
1892
1893   //! The method is called on Copy / Paste. 
1894   //! It copies the content of this attribute into theAttribute (copies the fields). 
1895   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& theAttribute, const Handle(TDF_RelocationTable)& theRelocationTable); 
1896
1897   //! Prints the content of this attribute into the stream. 
1898   Standard_EXPORT Standard_OStream& Dump(Standard_OStream& theOS);
1899
1900   //!@ name Constructor 
1901
1902   //! The C++ constructor of this atribute class. 
1903   //! Usually it is never called outside this class. 
1904   Standard_EXPORT MyPackage_Transformation();
1905
1906 private:
1907   gp_TrsfForm myType;
1908
1909   // Axes (Ax1, Ax2, Ax3) 
1910   gp_Ax1 myAx1;
1911   gp_Ax2 myAx2;
1912   gp_Ax3 myFirstAx3;
1913   gp_Ax3 mySecondAx3;
1914
1915   // Scalar values 
1916   Standard_Real myAngle;
1917   Standard_Real myScale;
1918
1919   // Points 
1920   gp_Pnt myFirstPoint;
1921   gp_Pnt mySecondPoint;
1922 }; 
1923 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1924
1925 @subsection occt_ocaf_11_2 Implementation of Attribute Transformation in a CPP file
1926
1927 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
1928 #include <MyPackage_Transformation.hxx> 
1929
1930 //======================================================================= 
1931 //function : GetID 
1932 //purpose  : The method returns a unique GUID of this attribute. 
1933 //           By means of this GUID this attribute may be identified   
1934 //           among other attributes attached to the same label. 
1935 //======================================================================= 
1936 const Standard_GUID& MyPackage_Transformation::GetID()   
1937
1938   static Standard_GUID ID("4443368E-C808-4468-984D-B26906BA8573"); 
1939   return ID; 
1940
1941
1942 //======================================================================= 
1943 //function : Set 
1944 //purpose  : Finds or creates the attribute attached to <theLabel>. 
1945 //           The found or created attribute is returned. 
1946 //======================================================================= 
1947 Handle(MyPackage_Transformation) MyPackage_Transformation::Set(const TDF_Label& theLabel)   
1948
1949   Handle(MyPackage_Transformation) T; 
1950   if (!theLabel.FindAttribute(MyPackage_Transformation::GetID(), T))   
1951   { 
1952     T = new MyPackage_Transformation();   
1953     theLabel.AddAttribute(T); 
1954   } 
1955   return T; 
1956
1957
1958 //======================================================================= 
1959 //function : Get 
1960 //purpose  : The method returns the transformation. 
1961 //======================================================================= 
1962 gp_Trsf MyPackage_Transformation::Get() const 
1963
1964   gp_Trsf transformation; 
1965   switch (myType) 
1966   { 
1967     case gp_Identity: 
1968     { 
1969       break; 
1970     } 
1971     case gp_Rotation: 
1972     { 
1973       transformation.SetRotation(myAx1, myAngle); 
1974       break; 
1975     } 
1976     case gp_Translation: 
1977     { 
1978       transformation.SetTranslation(myFirstPoint, mySecondPoint); 
1979       break; 
1980     } 
1981     case gp_PntMirror: 
1982     { 
1983       transformation.SetMirror(myFirstPoint); 
1984       break; 
1985     } 
1986     case gp_Ax1Mirror: 
1987     { 
1988       transformation.SetMirror(myAx1); 
1989       break; 
1990     } 
1991     case gp_Ax2Mirror: 
1992     { 
1993       transformation.SetMirror(myAx2); 
1994       break; 
1995     } 
1996     case gp_Scale: 
1997     { 
1998       transformation.SetScale(myFirstPoint, myScale); 
1999       break; 
2000     } 
2001     case gp_CompoundTrsf: 
2002     { 
2003       transformation.SetTransformation(myFirstAx3, mySecondAx3); 
2004       break; 
2005     } 
2006     case gp_Other: 
2007     { 
2008       break; 
2009     } 
2010   } 
2011   return transformation; 
2012
2013
2014 //======================================================================= 
2015 //function : SetRotation 
2016 //purpose  : The method defines a rotation type of transformation. 
2017 //======================================================================= 
2018 void MyPackage_Transformation::SetRotation(const gp_Ax1& theAxis, const Standard_Real theAngle) 
2019
2020   Backup(); 
2021   myType = gp_Rotation; 
2022   myAx1 = theAxis; 
2023   myAngle = theAngle; 
2024
2025
2026 //======================================================================= 
2027 //function : SetTranslation 
2028 //purpose  : The method defines a translation type of transformation. 
2029 //======================================================================= 
2030 void MyPackage_Transformation::SetTranslation(const gp_Vec& theVector) 
2031
2032   Backup(); 
2033   myType = gp_Translation; 
2034   myFirstPoint.SetCoord(0, 0, 0); 
2035   mySecondPoint.SetCoord(theVector.X(), theVector.Y(), theVector.Z()); 
2036
2037
2038 //======================================================================= 
2039 //function : SetMirror 
2040 //purpose  : The method defines a point mirror type of transformation 
2041 //           (point symmetry). 
2042 //======================================================================= 
2043 void MyPackage_Transformation::SetMirror(const gp_Pnt& thePoint) 
2044
2045   Backup(); 
2046   myType = gp_PntMirror; 
2047   myFirstPoint = thePoint; 
2048
2049
2050 //======================================================================= 
2051 //function : SetMirror 
2052 //purpose  : The method defines an axis mirror type of transformation 
2053 //           (axial symmetry). 
2054 //======================================================================= 
2055 void MyPackage_Transformation::SetMirror(const gp_Ax1& theAxis) 
2056
2057   Backup(); 
2058   myType = gp_Ax1Mirror; 
2059   myAx1 = theAxis; 
2060
2061
2062 //======================================================================= 
2063 //function : SetMirror 
2064 //purpose  : The method defines a point mirror type of transformation 
2065 //           (planar symmetry). 
2066 //======================================================================= 
2067 void MyPackage_Transformation::SetMirror(const gp_Ax2& thePlane) 
2068
2069   Backup(); 
2070   myType = gp_Ax2Mirror; 
2071   myAx2 = thePlane; 
2072
2073
2074 //======================================================================= 
2075 //function : SetScale 
2076 //purpose  : The method defines a scale type of transformation. 
2077 //======================================================================= 
2078 void MyPackage_Transformation::SetScale(const gp_Pnt& thePoint, const Standard_Real theScale) 
2079
2080   Backup(); 
2081   myType = gp_Scale; 
2082   myFirstPoint = thePoint; 
2083   myScale = theScale; 
2084
2085
2086 //======================================================================= 
2087 //function : SetTransformation 
2088 //purpose  : The method defines a complex type of transformation 
2089 //           from one co-ordinate system to another. 
2090 //======================================================================= 
2091 void MyPackage_Transformation::SetTransformation(const gp_Ax3& theCoordinateSystem1,   
2092                                                                          const gp_Ax3& theCoordinateSystem2) 
2093
2094   Backup(); 
2095   myFirstAx3 = theCoordinateSystem1; 
2096   mySecondAx3 = theCoordinateSystem2; 
2097
2098
2099 //======================================================================= 
2100 //function : ID 
2101 //purpose  : The method returns a unique GUID of the attribute. 
2102 //           By means of this GUID this attribute may be identified   
2103 //           among other attributes attached to the same label. 
2104 //======================================================================= 
2105 const Standard_GUID& MyPackage_Transformation::ID() const   
2106 {   
2107   return GetID();   
2108
2109
2110 //======================================================================= 
2111 //function : Restore 
2112 //purpose  : The method is called on Undo / Redo. 
2113 //           It copies the content of <theAttribute> 
2114 //           into this attribute (copies the fields). 
2115 //======================================================================= 
2116 void MyPackage_Transformation::Restore(const Handle(TDF_Attribute)& theAttribute)   
2117
2118   Handle(MyPackage_Transformation) theTransformation = Handle(MyPackage_Transformation)::DownCast(theAttribute); 
2119   myType = theTransformation->myType; 
2120   myAx1 = theTransformation->myAx1; 
2121   myAx2 = theTransformation->myAx2; 
2122   myFirstAx3 = theTransformation->myFirstAx3; 
2123   mySecondAx3 = theTransformation->mySecondAx3; 
2124   myAngle = theTransformation->myAngle; 
2125   myScale = theTransformation->myScale; 
2126   myFirstPoint = theTransformation->myFirstPoint; 
2127   mySecondPoint = theTransformation->mySecondPoint; 
2128
2129
2130 //======================================================================= 
2131 //function : NewEmpty 
2132 //purpose  : It creates a new instance of this attribute. 
2133 //           It is called on Copy / Paste, Undo / Redo. 
2134 //======================================================================= 
2135 Handle(TDF_Attribute) MyPackage_Transformation::NewEmpty() const 
2136 {    
2137   return new MyPackage_Transformation();   
2138
2139
2140 //======================================================================= 
2141 //function : Paste 
2142 //purpose  : The method is called on Copy / Paste. 
2143 //           It copies the content of this attribute into 
2144 //           <theAttribute> (copies the fields). 
2145 //======================================================================= 
2146 void MyPackage_Transformation::Paste(const Handle(TDF_Attribute)& theAttribute, 
2147                                                      const Handle(TDF_RelocationTable)& ) const 
2148
2149   Handle(MyPackage_Transformation) theTransformation = Handle(MyPackage_Transformation)::DownCast(theAttribute); 
2150   theTransformation->myType = myType; 
2151   theTransformation->myAx1 = myAx1; 
2152   theTransformation->myAx2 = myAx2; 
2153   theTransformation->myFirstAx3 = myFirstAx3; 
2154   theTransformation->mySecondAx3 = mySecondAx3; 
2155   theTransformation->myAngle = myAngle; 
2156   theTransformation->myScale = myScale; 
2157   theTransformation->myFirstPoint = myFirstPoint; 
2158   theTransformation->mySecondPoint = mySecondPoint; 
2159
2160
2161 //======================================================================= 
2162 //function : Dump 
2163 //purpose  : Prints the content of this attribute into the stream. 
2164 //======================================================================= 
2165 Standard_OStream& MyPackage_Transformation::Dump(Standard_OStream& anOS) const 
2166 {    
2167   anOS = "Transformation: "; 
2168   switch (myType) 
2169   { 
2170     case gp_Identity: 
2171     { 
2172       anOS = "gp_Identity"; 
2173       break; 
2174     } 
2175     case gp_Rotation: 
2176     { 
2177       anOS = "gp_Rotation"; 
2178       break; 
2179     } 
2180     case gp_Translation: 
2181     { 
2182       anOS = "gp_Translation"; 
2183       break; 
2184     } 
2185     case gp_PntMirror: 
2186     { 
2187       anOS = "gp_PntMirror"; 
2188       break; 
2189     } 
2190     case gp_Ax1Mirror: 
2191     { 
2192       anOS = "gp_Ax1Mirror"; 
2193       break; 
2194     } 
2195     case gp_Ax2Mirror: 
2196     { 
2197       anOS = "gp_Ax2Mirror"; 
2198       break; 
2199     } 
2200     case gp_Scale: 
2201     { 
2202       anOS = "gp_Scale"; 
2203       break; 
2204     } 
2205     case gp_CompoundTrsf: 
2206     { 
2207       anOS = "gp_CompoundTrsf"; 
2208       break; 
2209     } 
2210     case gp_Other: 
2211     { 
2212       anOS = "gp_Other"; 
2213       break; 
2214     } 
2215   } 
2216   return anOS; 
2217
2218
2219 //=======================================================================
2220 //function : MyPackage_Transformation 
2221 //purpose  : A constructor. 
2222 //=======================================================================
2223 MyPackage_Transformation::MyPackage_Transformation():myType(gp_Identity){ 
2224
2225 }
2226 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2227
2228 @subsection occt_ocaf_11_3  Implementation of typical actions with standard OCAF attributes.
2229
2230 There are four sample files provided in the directory 'OpenCasCade/ros/samples/ocafsamples'. They present typical actions with OCAF services (mainly for newcomers). 
2231 The method *Sample()* of each file is not dedicated for execution 'as is', it is rather a set of logical actions using some OCAF services.
2232
2233 ### TDataStd_Sample.cxx
2234 This sample contains templates for typical actions with the following standard OCAF attributes:
2235 - Starting with data framework;
2236 - TDataStd_Integer attribute management;
2237 - TDataStd_RealArray attribute management;
2238 - TDataStd_Comment attribute management;
2239 - TDataStd_Name attribute management;
2240 - TDataStd_UAttribute attribute management;
2241 - TDF_Reference attribute management;
2242 - TDataXtd_Point attribute management;
2243 - TDataXtd_Plane attribute management;
2244 - TDataXtd_Axis attribute management;
2245 - TDataXtd_Geometry attribute management;
2246 - TDataXtd_Constraint attribute management;
2247 - TDataStd_Directory attribute management;
2248 - TDataStd_TreeNode attribute management.
2249   
2250 ### TDocStd_Sample.cxx
2251 This sample contains template for the following typical actions:
2252 - creating application;
2253 - creating the new document (document contains a framework);
2254 - retrieving the document from a label of its framework;
2255 - filling a document with data;
2256 - saving a document in the file;
2257 - closing a document;
2258 - opening the document stored in the file;
2259 - copying content of a document to another document with possibility to update the copy in the future.
2260  
2261 ### TPrsStd_Sample.cxx
2262 This sample contains template for the following typical actions:
2263 - starting with data framework;
2264 - setting the TPrsStd_AISViewer in the framework;
2265 - initialization of aViewer;
2266 - finding TPrsStd_AISViewer attribute in the DataFramework;
2267 - getting AIS_InteractiveContext from TPrsStd_AISViewer;
2268 - adding driver to the map of drivers;
2269 - getting driver from the map of drivers;
2270 - setting TNaming_NamedShape to \<ShapeLabel\>;
2271 - setting the new  TPrsStd_AISPresentation to \<ShapeLabel\>;
2272 - displaying;
2273 - erasing;
2274 - updating and displaying presentation of the attribute to be displayed;
2275 - setting a color to the displayed attribute;
2276 - getting transparency of the displayed attribute;
2277 -  modify attribute;
2278 - updating presentation of the attribute in viewer.
2279
2280 ### TNaming_Sample.cxx
2281 This sample contains template for typical actions with OCAF Topological Naming services.
2282 The following scenario is used:
2283 - data framework initialization;
2284 - creating Box1 and pushing it as PRIMITIVE in DF;
2285 - creating Box2 and pushing it as PRIMITIVE in DF;
2286 - moving Box2 (applying a transformation);
2287 - pushing the selected edges of the top face of Box1 in DF;
2288 - creating a Fillet (using the selected edges) and pushing the result as a modification of Box1;
2289 - creating a Cut (Box1, Box2) as a modification of Box1 and push it in DF;
2290 - recovering the result from DF.
2291
2292