0026342: No materials are read from STEP
[occt.git] / dox / user_guides / ocaf_wp / ocaf_wp.md
CommitLineData
ba06f8bb 1OCAF White-Paper {#occt_user_guides__ocaf_wp}
bf62b306 2========================
3 @tableofcontents
4
5@section ocaf_wp_1 What is OCAF ?
6
7@subsection ocaf_wp_1_1 Purpose of OCAF
8
9 The Open CASCADE Application Framework (OCAF) is an easy-to-use platform for rapidly developing
10 sophisticated domain-specific design applications.
11 A typical application developed using OCAF deals with two or three-dimensional (2D or 3D) geometric modeling
12 in trade-specific Computer Aided Design (CAD) systems, manufacturing or analysis applications,
13 simulation applications or illustration tools.
14
15 Developing a design application requires addressing many technical aspects.
16 In particular, given the functional specification of your application, you must at least:
17
18 * Design the architecture of the application — definition of the software components and the way they cooperate
19 * Define the data model able to support the functionality required — a design application operates on data maintained during the whole end-user working session
20 * Structure the software in order to
21 * synchronize the display with the data — commands modifying objects must update the views
22 * support generalized undo-redo commands — this feature has to be taken into account very early in the design process
23 * 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
24 * Build the application user interface
25
26 By providing architectural guidance and ready-to-use solutions to these issues,
27 OCAF helps you to develop your application significantly faster: you concentrate on the application's functionality.
e2b55410 28
29 As you use the architecture provided by OCAF, the design of your application is made easy: as the application developer you can concentrate on the functionality instead of the underlying mechanisms required to support it.
30
31 Also, thanks to the coupling with the other Open CASCADE Technology modules,
32 your application can rapidly be prototyped. In addition, the final application
33 can be developed by industrializing the prototype — you don't need to restart the development from scratch.
34
35 Last but not least, you base your application on an Open Source component:
36 this guarantees the long-term usefulness of your development.
bf62b306 37
38@subsection ocaf_wp_1_2 Overview of the Architecture
39
40 OCAF provides you with an object-oriented Application-Document-Attribute model.
41 This consists of C++ class libraries. The main class, Application, is an abstract class
42 in charge of handling documents during the working session. Services provided by this class include:
43 * Creating new documents
44 * Saving documents and opening them
45 * Initializing document views
46
47 The document, implemented by the concrete class Document, is the container for the application data.
48 Its main purpose is to centralize notifications of data editing in order to provide Undo-Redo.
49 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).
50
51 Application data are attributes, that is, instances of classes derived from the *Attribute* abstract class,
52 organized according to the OCAF Data Framework.
53 The OCAF Data Framework references aggregations of attributes using persistent identifiers in a single hierarchy (the Data Framework is described <a href="#ocaf_wp_2">in the next chapter</a>). A wide range of attributes come with OCAF, including:
54
55 * Primitive attributes such as *Integer, Real, Name* and *Comment*;
56 * Shape attribute containing the geometry of the whole model or elements of it;
57 * Other geometric attributes such as Datums (points, axis and plane) and Constraints (*tangent-to, at-a-given-distance, from-a-given-angle, concentric,* etc.)
58 * Modeling step and Function attributes — the purpose of these attributes is to rebuild objects after they have been modified (parameterization of models)
59 * Visualization attributes — these attributes allow data to be visualized in a 2D or 3D viewer
60 * User attributes, that is, attributes typed by the application
61 * In addition, application-specific data can be added by defining new attribute classes;
62 naturally, this changes the standard file format. The only functions that have to be implemented are:
63 * Copying the attribute
64 * Converting it from and to its persistent homolog (persistence is briefly presented in the paragraph <a href="#ocaf_wp_2_3">Persistent Data Storage</a>)
65
66@image html ocaf_wp_image003.png "The Application-Document-Attribute model "
67@image latex ocaf_wp_image003.png "The Application-Document-Attribute model "
68
69OCAF uses other modules of Open CASCADE Technology — the Shape attribute 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.
70
71@subsection ocaf_wp_1_3 Getting Started
72
73 At the beginning of your development, you first define an application class by inheriting from the Application abstract class.
74 You only have to create and determine the resources of the application
75 for specifying the format of your documents (you generally use the standard one) and their file extension.
76
77 Then, you design the application data model by organizing attributes you choose among those provided with OCAF.
78 You can specialize these attributes using the User attribute. For example, if you need a reflection coefficient,
79 you aggregate a User attribute identified as a reflection coefficient
80 with a Real attribute containing the value of the coefficient (as such, you don't define a new class).
81
82 If you need application specific data not provided with OCAF, for example,
83 to incorporate a finite element model in the data structure,
84 you define a new attribute class containing the mesh,
e2b55410 85 and you include its persistent homologue in a new file format.
bf62b306 86
87 Once you have implemented the commands which create and modify the data structure
88 according to your specification, OCAF provides you, without any additional programming:
89
90 * Persistent reference to any data, including geometric elements — several documents can be linked with such reference;
91 * Document-View association;
92 * Ready-to-use functions such as :
93 * Undo-redo;
94 * Save and open application data.
ba06f8bb 95
bf62b306 96 Finally, you develop the application's graphical user interface using the toolkit of your choice, for example:
97 * KDE Qt or GNOME GTK+ on Linux;
98 * Microsoft Foundation Classes (MFC) on Windows Motif on Sun;
99 * Other commercial products such as Ilog Views.
100
101 You can also implement the user interface in the Java language using
102 the Swing-based Java Application Desktop component (JAD) provided with OCAF.
e2b55410 103
104@subsection ocaf_wp_1_4 An example of OCAF usage
bf62b306 105
e2b55410 106To create a useful OCAF-based application, it is necessary to redefine two deferred methods: <i> Formats</i> and <i> ResourcesName</i>
107
108In the <i> Formats </i> method, add the format of the documents, which need to be read by the application and may have been built in other applications.
109
110For example:
111
112~~~~
113 void myApplication::Formats(TColStd_SequenceOfExtendedString& Formats)
114 {
115 Formats.Append(TCollection_ExtendedString ("OCAF-myApplication"));
116 }
117~~~~
118
119In the <i> ResourcesName</i> method, you only define the name of the resource file. This
120file contains several definitions for the saving and opening mechanisms associated
121with each format and calling of the plug-in file.
122
123~~~~
124 Standard_CString myApplication::ResourcesName()
125 {
126 return Standard_CString ("Resources");
127 }
128~~~~
129
130To obtain the saving and opening mechanisms, it is necessary to set two environment variables: <i> CSF_PluginDefaults</i>, which defines the path of the plug-in file, and <i> CSF_ResourcesDefault</i>, which defines the resource file:
131
132~~~~
133 SetEnvironmentVariable ( "CSF_ResourcesDefaults",myDirectory);
134 SetEnvironmentVariable ( "CSF_PluginDefaults",myDirectory);
135~~~~
136
137The plugin and the resource files of the application will be located in <i> myDirector</i>.
138The name of the plugin file must be <i>Plugin</i>.
139
140### Resource File
141
142The resource file describes the documents (type and extension) and
143the type of data that the application can manipulate
144by identifying the storage and retrieval drivers appropriate for this data.
145
146Each driver is unique and identified by a GUID generated, for example, with the <i> uuidgen </i> tool in Windows.
147
148Five drivers are required to use all standard attributes provided within OCAF:
149
150 * the schema driver (ad696002-5b34-11d1-b5ba-00a0c9064368)
151 * the document storage driver (ad696000-5b34-11d1-b5ba-00a0c9064368)
152 * the document retrieval driver (ad696001-5b34-11d1-b5ba-00a0c9064368)
153 * the attribute storage driver (47b0b826-d931-11d1-b5da-00a0c9064368)
154 * the attribute retrieval driver (47b0b827-d931-11d1-b5da-00a0c9064368)
155
156These drivers are provided as plug-ins and are located in the <i> PappStdPlugin</i> library.
157
158
159For example, this is a resource file, which declares a new model document OCAF-MyApplication:
160
161~~~~
162formatlist:OCAF-MyApplication
163OCAF-MyApplication.Description: MyApplication Document Version 1.0
164OCAF-MyApplication.FileExtension: sta
165OCAF-MyApplication.StoragePlugin: ad696000-5b34-11d1-b5ba-00a0c9064368
166OCAF-MyApplication.RetrievalPlugin: ad696001-5b34-11d1-b5ba-00a0c9064368
167OCAF-MyApplicationSchema: ad696002-5b34-11d1-b5ba-00a0c9064368
168OCAF-MyApplication.AttributeStoragePlugin: 47b0b826-d931-11d1-b5da-00a0c9064368
169OCAF-MyApplication.AttributeRetrievalPlugin: 47b0b827-d931-11d1-b5da-00a0c9064368
170~~~~
bf62b306 171
e2b55410 172
173### Plugin File
174
175The plugin file describes the list of required plug-ins to run the application and the
176libraries in which plug-ins are located.
177
178You need at least the <i> FWOSPlugin</i> and the plug-in drivers to run an OCAF application.
179
180The syntax of each item is <i> Identification.Location Library_Name, </i> where:
181* Identification is GUID.
182* Location defines the location of the Identification (where its definition is found).
183* Library_Name is the name (and path to) the library, where the plug-in is located.
184
185For example, this is a Plugin file:
186
187~~~~
188a148e300-5740-11d1-a904-080036aaa103.Location: FWOSPlugin
189! base document drivers plugin
190ad696000-5b34-11d1-b5ba-00a0c9064368.Location: PAppStdPlugin
191ad696001-5b34-11d1-b5ba-00a0c9064368.Location: PAppStdPlugin
192ad696002-5b34-11d1-b5ba-00a0c9064368.Location: PAppStdPlugin
19347b0b826-d931-11d1-b5da-00a0c9064368.Location: PAppStdPlugin
19447b0b827-d931-11d1-b5da-00a0c9064368.Location: PAppStdPlugin
195~~~~
bf62b306 196
197@section ocaf_wp_2 A Look Inside OCAF
198
199@subsection ocaf_wp_2_1 The Design of OCAF
200
201@subsubsection ocaf_wp_2_1_1 Reference-key model
202
203 In most existing geometric modeling systems, the data are topology driven.
204 They usually use a boundary representation (BRep), where geometric models
205 are defined by a collection of faces, edges and vertices,
206 to which application data are attached. Examples of data include:
207
208 * a color;
209 * a material;
210 * information that a particular edge is blended.
211
212 When the geometric model is parameterized, that is, when you can change
213 the value of parameters used to build the model (the radius of a blend, the thickness of a rib, etc.),
214 the geometry is highly subject to change.
215 In order to maintain the attachment of application data, the geometry must be distinguished from other data.
216
217 In OCAF, the data are reference-key driven. It is a uniform model in which reference-keys
4ee1bdf4 218 are the persistent identification of data. All **accessible** data, including the geometry,
bf62b306 219 are implemented as attributes attached to reference-keys.
220 The geometry becomes the value of the Shape attribute, just as a number is the value
221 of the Integer and Real attributes and a string that of the Name attribute.
222
223 On a single reference-key, many attributes can be aggregated;
224 the application can ask at runtime which attributes are available.
225 For example, to associate a texture to a face in a geometric model,
226 both the face and the texture are attached to the same reference-key.
227
228@image html ocaf_wp_image004.png "Figure 2. Topology driven versus reference-key driven approaches"
229@image latex ocaf_wp_image004.png "Figure 2. Topology driven versus reference-key driven approaches"
230
231@subsubsection ocaf_wp_2_1_2 Topological naming
232
233 Reference-keys can be created in two ways:
234
235 * At programming time, by the application
236 * At runtime, by the end-user of the application (providing that you include this capability in the application)
237
238 As an application developer, you generate reference-keys in order to give semantics to the data.
239 For example, a function building a prism may create three reference-keys:
240 one for the base of the prism, a second for the lateral faces and a third for the top face.
241 This makes up a semantic built-in the application's prism feature.
242 On the other hand, in a command allowing the end-user to set a texture to a face he/she selects,
243 you must create a reference-key to the selected face
244 if it has not previously been referenced in any feature
245 (as in the case of one of the lateral faces of the prism).
246
247 When you create a reference-key to selected topological elements (faces, edges or vertices),
248 OCAF attaches to the reference-key information defining the selected topology — the Naming attribute.
249 For example, it may be the faces to which a selected edge is common to.
250 This information, as well as information about the evolution of the topology at each modeling step
251 (the modified, updated and deleted faces), is used by the naming algorithm to maintain the topology
252 attached to the reference-key. As such, on a parametrized model,
253 after modifying the value of a parameter, the reference-keys still address the appropriate faces,
254 even if their geometry has changed.
255 Consequently, you change the size of the cube shown in the figure 2 above,
256 the user texture stay attached to the right face.
257
258 <b>Note</b> As Topological naming is based on the reference-key and attributes such as Naming
259 (selection information) and Shape (topology evolution information),
260 OCAF is not coupled to the underlying modeling libraries.
261 The only modeling services required by OCAF are the following:
262
263 * Each algorithm must provide information about the evolution of the topology
264 (the list of faces modified, updated and deleted by the algorithm)
265 * Exploration of the geometric model must be available
266 (a 3D model is made of faces bounded by close wires,
267 themselves composed by a sequence of edges connected by their vertices)
268
269 Currently, OCAF uses the Open CASCADE Technology modeling libraries.
270
271@subsubsection ocaf_wp_2_1_3 Aggregation of attributes
272
273 To design an OCAF-based data model, the application developer is encouraged to aggregate
274 ready-to-use attributes instead of defining new attributes by inheriting from an abstract root class.
275 There are two major advantages in using aggregation rather than inheritance:
276
277 * As you don't implement data by defining new classes, the format of saved data
278 provided with OCAF doesn't change; so you don't have to write the Save and Open functions
279 * The application can query the data at runtime if a particular attribute is available
280
281@subsubsection ocaf_wp_2_1_4 Summary
282
283 * OCAF is based on a uniform reference-key model in which:
284 * Reference-keys provide persistent identification of data;
285 * Data, including geometry, are implemented as attributes attached to reference-keys;
286 * Topological naming maintains the selected geometry attached to reference-keys in parametrized models ;
287 * In many applications, the data format provided with OCAF doesn't need to be extended;
288 * OCAF is not coupled to the underlying modeling libraries.
289
290@subsection ocaf_wp_2_2 The Data Framework
291
292@subsubsection ocaf_wp_2_2_1 Data structure
293
294 The OCAF Data Framework is the Open CASCADE Technology realization
295 of the reference-key model presented in the previous paragraph.
296 It implements the reference-key as label objects,
297 organized in a tree structure characterized by the following features:
298
299 * A document contains only one tree of labels
300 * Each label has a tag expressed as an integer value unique at its level in the tree
301 * A label is identified by a string — the entry — built by concatenation of tags from the root of the tree, for example [0:1:2:1]
302 * Attributes are of a type identified by a universal unique identifier (GUID)
303 * Attributes are attached to labels; a label may refer to many attributes as long as each has a different GUID
304
305 As such, each piece of data has a unique persistent address made up of the document path,
306 its entry and the GUID of its class.
307
308 In the image the application for designing coffee machines first allocates
309 a label for the machine unit. It then adds sub-labels for the main features
310 (glass coffee pot, water receptacle and filter) which it refines as needed
311 (handle and reservoir of the coffee pot and spout of the reservoir).
312
313 You now attach technical data describing the handle — its geometry and color —
314 and the reservoir — its geometry and material.
315 Later on, you can modify the handle's geometry without changing its color —
316 both remain attached to the same label.
317
318@image html ocaf_wp_image005.png "Figure 3. The data structure of the coffee machine"
319@image latex ocaf_wp_image005.png "Figure 3. The data structure of the coffee machine"
320
321 The nesting of labels is key to OCAF. This allows a label to have its own structure
322 with its local addressing scheme which can be reused in a more complex structure.
323 Take, for example, the coffee machine. Given that the coffee pot's handle has a label of tag [1],
324 the entry for the handle in the context of the coffee pot only (without the machine unit) is [0:1:1].
325 If you now model a coffee machine with two coffee pots, one at the label [1],
326 the second at the label [4] in the machine unit,
327 the handle of the first pot would have the entry [0:1:1:1]
328 whereas the handle of the second pot would be [0:1:4:1].
329 This way, we avoid any confusion between coffee pot handles.
330
331@subsubsection ocaf_wp_2_2_2 Compound documents
332
333 As the identification of data is persistent, one document can reference data contained in another document,
334 the referencing and referenced documents being saved in two separate files.
335
336 Lets look at the coffee machine application again. The coffee pot can be placed in one document.
ba06f8bb 337 The coffee machine document then includes an *occurrence* — a positioned copy — of the coffee pot.
bf62b306 338 This occurrence is defined by an XLink attribute (the external Link)
339 which references the coffee pot of the first document
340 (the XLink contains the relative path of the coffee pot document and the entry of the coffee pot data [0:1] ).
341
342@image html ocaf_wp_image006.png "The coffee machine compound document"
343@image latex ocaf_wp_image006.png "The coffee machine compound document"
344
345 In this context, the end-user of the coffee machine application can open the coffee pot document,
346 modify the geometry of, for example, the reservoir, and overwrite the document without worrying
347 about the impact of the modification in the coffee machine document.
348 To deal with this situation, OCAF provides a service which allows the application to check
349 whether a document is up-to-date. This service is based on a modification counter included in each document:
350 when an external link is created, a copy of the referenced document counter is associated to the XLink
351 in the referencing document. Providing that each modification of the referenced document increments its own counter,
352 we can detect that the referencing document has to be updated by comparing the two counters
353 (an update function importing the data referenced by an XLink into the referencing document is also provided).
354
355
356@subsubsection ocaf_wp_2_2_3 Transaction mechanism
357
358 The Data Framework also provides a transaction mechanism inspired from database management systems:
359 the data are modified within a transaction which is terminated either by a Commit
360 if the modifications are validated or by an Abort if the modifications are abandoned —
361 the data are then restored to the state it was in prior to the transaction.
362 This mechanism is extremely useful for:
363
364 * Securing editing operations (if an error occurs, the transaction is abandoned and the structure retains its integrity)
365 * Simplifying the implementation of the Cancel function (when the end-user begins a command,
366 the application may launch a transaction and operate directly in the data structure;
367 abandoning the action causes the transaction to Abort)
368 * Executing Undo (at commit time, the modifications are recorded in order to be able to restore the data to their previous state)
369
370 The transaction mechanism consists simply of managing a backup copy of attributes.
371 During a transaction, attributes are copied before their first modification.
372 If the transaction is validated, the copy is destroyed.
373 If the transaction is abandoned, the attribute is restored to its initial value
ba06f8bb 374 (when attributes are added or deleted, the operation is simply reversed).
375
bf62b306 376 Transactions are document-centered, that is, the application starts a transaction on a document.
377 So, modifying a referenced document and updating one of its referencing documents requires
ba06f8bb 378 two transactions, even if both operations are done in the same working session.
bf62b306 379
ba06f8bb 380@subsection ocaf_wp_2_3 Persistent Data Storage
bf62b306 381
e2b55410 382@subsubsection ocaf_wp_2_3_1 Introduction
383
384In OCAF, persistence, that is, the mechanism used to save a document in a file, is based on an explicit formal description of the data saved.
bf62b306 385
e2b55410 386When you open a document, the application reads the corresponding file and first creates a memory representation of it. This representation is then converted to the application data model — the OCAF-based data structure the application operates on. The file's memory representation consists of objects defined by classes known as persistent.
bf62b306 387
e2b55410 388The persistent classes needed by an application to save its documents make the application's data schema. This schema defines the way the data are organized in the file — the format of the data. In other words, the file is simply an ASCII dump of the persistent data defined by the schema, the persistent data being created from the application data model during the save process.
389
390Only canonical information is saved. As a matter of fact, the application data model usually contains additional data to optimize processing. For example, the persistent Bézier curve is defined by its poles, whereas its data model equivalent also contains coefficients used to compute a point at a given parameter. The additional data is calculated when the document is opened.
391
392The major advantages of this approach are the following:
bf62b306 393 * Providing that the data format is published, files created by OCAF-based applications
394 can be read without needing a runtime of the application (openness)
395 * Although the persistence approach makes the data format more stable,
396 OCAF provides a framework for managing compatibility of data between versions of the application —
397 modification of the data format is supported through the versioning of schema.
398
399 OCAF includes a ready-to-use schema suitable for most applications.
400 However, it can be extended if needed. For that, the only things you have to do are:
401
402 * To define the additional persistent attributes
403 * To implement the functions converting these persistent attribute to and from the application data model.
404
405Applications using compound documents extensively (saving data in many files linked together) should implement data management services. As a matter of fact, it's out the scope of OCAF to provide functions such as:
ba06f8bb 406* Version and configuration management of compound documents;
407* Querying a referenced document for its referencing documents.
bf62b306 408
409In order to ease the delegation of document management to a data management application, OCAF encapsulates the file management functions in a driver (the meta-data driver). You have to implement this driver for your application to communicate with the data management system of your choice.
410
e2b55410 411
412@subsubsection ocaf_wp_2_3_2 Schemes of Persistence
413
414There are three schemes of persistence, which you can use to store and retrieve OCAF data (documents):
415
416 * <i> Standard</i> persistence schema, compatible with previous OCAF applications
417 * <i> XmlOcaf</i> persistence, allowing the storage of all OCAF data in XML form
418 * <i> BinOcaf</i> persistence, allowing the storage of all OCAF data in binary format form
419
420
421All schemes are independent of each other, but they guarantee that the standard OCAF
422attributes stored and retrieved by one schema will be storable and retrievable by
423the other. Therefore in any OCAF application you can use any persistence schema or
424even all three of them. The choice is made depending on the *Format* string of stored OCAF documents
425or automatically by the file header data - on retrieval.
426
427Persistent data storage in OCAF using the <i> Standard</i> package is presented in:
428
429 * Basic Data Storage
430 * Persistent Collections
431
432Persistent storage of shapes is presented in the following chapters:
433
434 * Persistent Geometry
435 * Persistent Topology
436
437Finally, information about opening and saving persistent data is presented in Standard
438Documents.
439
440@subsubsection ocaf_wp_2_3_3 Basic Data Storage
441
442Normally, all data structures provided by Open CASCADE Technology are run-time structures,
443in other words, transient data. As transient data, they exist only while an application
444is running and are not stored permanently. However, the Data Storage module provides
445resources, which enable an application to store data on disk as persistent data.
446
447Data storage services also provide libraries of persistent classes and translation
448functions needed to translate data from transient to persistent state and vice-versa.
449
450#### Libraries of persistent classes
451
452Libraries of persistent classes are extensible libraries of elementary classes you
453use to define the database schema of your application. They include:
454* Unicode (8-bit or 16-bit character type) strings
455* Collections of any kind of persistent data such as arrays.
456
457All persistent classes are derived from the \b Persistent base class, which defines
458a unique way of creating and handling persistent objects. You create new persistent
459classes by inheriting from this base class.
460
461#### Translation Functions
462
463Translation functions allow you to convert persistent objects to transient ones and
464vice-versa. These translation functions are used to build Storage and Retrieval drivers
465of an application.
466
467For each class of 2D and 3D geometric types, and for the general shape class in the
468topological data structure library, there are corresponding persistent class libraries,
469which allow you to translate your data with ease.
470
471#### Creation of Persistent Classes
472
473If you use Unix platforms as well as WOK and CDL, you can create your own persistent
474classes. In this case, data storage is achieved by implementing *Storage* and *Retrieval*
475drivers.
476
477The <i> Storage </i> package is used to write and read persistent objects.
478These objects are read and written by a retrieval or storage algorithm
479(<i> Storage_Schema </i>object) in a container (disk, memory, network ...).
480Drivers (<i> FSD_File</i> objects) assign a physical container for data to be stored or retrieved.
481
482The standard procedure for an application in reading a container is as follows:
483
484* open the driver in reading mode,
485* call the Read function from the schema, setting the driver as a parameter. This function returns an instance of the <i> Storage_Data </i> class which contains the data being read,
486* close the driver.
487
488The standard procedure for an application in writing a container is as follows:
489
490* open the driver in writing mode,
491* create an instance of the <i> Storage_Data </i> class, then add the persistent data to write with the function <i> AddRoot</i>,
492* call the function <i> Write </i> from the schema, setting the driver and the <i> Storage_Data </i> instance as parameters,
493* close the driver.
494
495@subsubsection ocaf_wp_2_3_4 Persistent Collections
496
497Persistent collections are classes which handle dynamically sized collections of data that can be stored in the database. These collections provide three categories of service:
498
499 * persistent strings,
500 * generic arrays of data,
501 * commonly used instantiations of arrays.
502
503Persistent strings are concrete classes that handle sequences of characters based
504on both ASCII (normal 8-bit) and Unicode (16-bit) character sets.
505
506Arrays are generic classes, that is, they can hold a variety of objects not necessarily inheriting from a unique root class. These arrays can be instantiated with any kind of storable or persistent object, and then inserted into the persistent data model of a user application.
507
508The purpose of these data collections is simply to convert transient data into its persistent equivalent so that it can be stored in the database. To this end, the collections are used to create the persistent data model and assure the link with the database. They do not provide editing or query capabilities because it is more efficient, within the operative data model of the application, to work with transient data structures (from the <i> TCollection</i> package).
509
510For this reason:
511
512 * the persistent strings only provide constructors and functions to convert between transient and persistent strings, and
513 * the persistent data collections are limited to arrays. In other words, <i> PCollection</i> does not include sequences, lists, and so on (unlike <i> TCollection</i>).
514
515Persistent string and array classes are found in the <i> PCollection</i> package. In addition, <i> PColStd</i> package provides standard, and frequently used, instantiations of persistent arrays, for very simple objects.
516
517@subsubsection ocaf_wp_2_3_5 Persistent Geometry
518
519The Persistent Geometry component describes geometric data structures which can be stored in the database. These packages provide a way to convert data from the transient "world" to the persistent "world".
520
521Persistent Geometry consists of a set of atomic data models parallel to the geometric data structures described in the geometry packages. Geometric data models, independent of each other, can appear within the data model of any application. The system provides the means to convert each atomic transient data model into a persistent one, but it does not provide a way for these data models to share data.
522
523Consequently, you can create a data model using these components, store data in, and retrieve it from a file or a database, using the geometric components provided in the transient and persistent "worlds". In other words, you customize the system by declaring your own objects, and the conversion of the geometric components from persistent to transient and vice versa is automatically managed for you by the system.
524
525However, these simple objects cannot be shared within a more complex data model. To allow data to be shared, you must provide additional tools.
526
527Persistent Geometry is provided by several packages.
528
529The <i> PGeom</i> package describes geometric persistent objects in 3D space, such as points,
530vectors, positioning systems, curves and surfaces.
531
532These objects are persistent versions of those provided by the <i> Geom</i> package: for
533each type of transient object provided by Geom there is a corresponding type of persistent
534object in the <i>PGeom</i> package. In particular the inheritance structure is parallel.
535
536However the <i> PGeom </i>package does not provide any functions to construct, edit or access
537the persistent objects. Instead the objects are manipulated as follows:
538
539 * Persistent objects are constructed by converting the equivalent transient <i> Geom </i> objects. To do this you use the <i>MgtGeom::Translate</i> function.
540 * Persistent objects created in this way are used to build persistent data structures that are then stored in a file or database.
541 * When these objects are retrieved from the file or database, they are converted back into the corresponding transient objects from the Geom package. To do this, you use <i>MgtGeom::Translate</i> function.
542
543In other words, you always edit or query transient data structures within the transient
544data model supplied by the session.
545Consequently, the documentation for the <i> PGeom </i> package consists simply of a list of available objects.
546
547The <i> PGeom2d </i> package describes persistent geometric objects in 2D space, such as points,
548vectors, positioning systems and curves. This package provides the same type of services
549as the <i> PGeom</i> package, but for the 2D geometric objects provided by the <i> Geom2d</i> package.
550Conversions are provided by the <i>MgtGeom::Translate</i> function.
551
552~~~~
553//Create a coordinate system
554Handle(Geom_Axis2Placement) aSys;
555
556
557//Create a persistent coordinate PTopoDS_HShape.cdlsystem
558Handle(PGeom_Axis2placement)
559 aPSys = MgtGeom::Translate(aSys);
560
561//Restore a transient coordinate system
562Handle(PGeom_Axis2Placement) aPSys;
563
564Handle(Geom_Axis2Placement)
565 aSys = MgtGeom::Translate(aPSys);
566~~~~
567
568
569@subsubsection ocaf_wp_2_3_6 Persistent Topology
570
571The Persistent Topology component describes topological data structures which can be stored in the database. These packages provide a way to convert data from the transient "world" to the persistent "world".
572
573Persistent Topology is based on the BRep concrete data model provided by the topology packages. Unlike the components of the Persistent Geometry package, topological components can be fully shared within a single model, as well as between several models.
574
575Each topological component is considered to be a shape: a <i> TopoDS_Shape</i> object. The system's capacity to convert a transient shape into a persistent shape and vice-versa applies to all objects, irrespective of their complexity: vertex, edge, wire, face, shell, solid, and so on.
576
577When a user creates a data model using BRep shapes, he uses the conversion functions that the system provides to store the data in, and retrieve it from the database. The data can also be shared.
578
579Persistent Topology is provided by several packages.
580
581The <i> PTopoDS</i> package describes the persistent data model associated with any BRep shape; it is the persistent version of any shape of type <i> TopoDS_Shape</i>. As is the case for persistent geometric models, this data structure is never edited or queried, it is simply stored in or retrieved from the database. It is created or converted by the <i>MgtBRep::Translate</i> function.
582
583The <i> MgtBRepAbs</i> and <i> PTColStd </i> packages provide tools used by the conversion functions of topological objects.
584
585~~~~
586//Create a shape
587TopoDS_Shape aShape;
588
589//Create a persistent shape
590PtColStd_DoubleTransientPersistentMap aMap;
591
592Handle(PTopoDS_HShape) aPShape =
593 aMap.Bind2(MgtBRep::Translate
594 aShape,aMap,MgtBRepAbs_WithTriangle));
595
596aPShape.Nullify();
597
598//Restore a transient shape
599Handle(PTopoDS_HShape) aPShape;
600
601Handle(TopoDS_HShape) aShape =
602 aMap.Bind1(MgtBRep::Translate
603 (aPShape,aMap,MgtBRepAbs_WithTriangle));
604
605aShape.Nullify();
606~~~~
607
608@subsubsection ocaf_wp_2_3_7 Standard Documents
609
610Standard documents offer you a ready-to-use document containing a TDF-based data
611structure. The documents themselves are contained in a class inheriting from <i> TDocStd_Application</i>
612which manages creation, storage and retrieval of documents.
613
614You can implement undo and redo in your document, and refer from the data framework
615of one document to that of another one. This is done by means of external link attributes,
616which store the path and the entry of external links. To sum up, standard documents
617alone provide access to the data framework. They also allow you to:
618* Update external links;
619* Manage the saving and opening of data;
620* Manage undo/redo functionality.
621