OCAF once again.....

Hi !

A long time ago :o) I tried to use OCAF in an application, this took a lot of time because there where no documentation on how to implement it. I had to look up most things by browsing through the source code.

A gave up and is now using my own code for doing the same stuff.

Today there is a pdf file that does a good job on explaining how to use OCAF in an application, but as far as I can tell, there are still not a word on how to get it up and running.

You need to subclass the TDocStd_Application and implement the Resourcenames() and Formats() methods (the doc says this ;-), but there are still not a single word about what these two methods should return.

As you can see there has been some question about OCAF the last few days, and the docs are still not enough to get you up and running.

The things that are missing are:

1. A simple example (or this there one available maybe, and I have missed it ?)

2. A description of how to implement the TDocStd_Application (Resourcenames and Formats methods).

3. A description on how to create and access the REGISTRY file you need.

4. A note that you need a driver for the serialization and where to find this driver and how to setup ip up so the application can find it, trust me this is not easy without documentation.

Without this information it is very, very difficult to get OCAF working without hours of browsing through the source code, belive me, I have done it.

Regards, Mikael

Philippe Poncot's picture


a SampleOcaf is now available in opencascade.com web site. The SampleOcaf is an example of use of Ocaf (undo/redo and store/retrieve mechanism, attribute manipulation, etc...).

Hopes it help you.


e-cocquebert's picture

I am unable to unzip it. Does other people succeed ?

e-cocquebert's picture

The files was bad, but it is now ok....

...nevertheless, if the building of the project is right, i am unable to execute it because of an error message 'un point d'arret a été atteint...'. Does anybody (and/or MDTV) have an idea ??

Regards, Etienne

Stephane Routelous's picture

Are you sure that your project settings are OK ? ( I mean Multitread DLL ).


e-cocquebert's picture

If you think about the list item located within 'C/C++' tab, for the category 'code generation' and under the label 'use run-time library', the answer is yes.

notice that i previously suceeded to built and execute the other Win NT samples.

Sergey RUIN's picture

Hi, Mikael

I hope that this decription answers some of the question you has asked.

There are two possible scenarios of Open/Save operations adjustment for Your documents. The first is the easiest one when You use in Your documents only standard attributes (from the packages TDF, TDataStd, TNaming, TFunction, TPrsStd and TDocStd). The second case (scenario) when You use Your own attribute(s) in Your documents. In this case You have to implement storage/retrival drivers for the attribute(s) and to recompile persistence schema. Let's begin with the first way (when You use only standard attributes in Your documents).

Open/Save operations of a document with standard attributes only

If You chose this way of a document creation, I'd like to congratulate You. You will have minimal work for making Your documents storable (retrivable).

1. First of all in Your application class (inherited from the deferred class Application from TDocStd) implement such methods as Formats() and ResourcesName() this way:

void MyTheBestPackage_MyTheBestApplication::Formats(TColStd_SequenceOfExtendedString& theFormats) {



Standard_CString MyTheBestPackage_MyTheBestApplication::ResourcesName() {

return "Standard";


The first method Formats() returns the format of documents (just You create a document the constructor of the document class takes the format as its argument). The second method ResourcesName() returns the name of the file where is the full description of the format identifiers (the extension of the document (*.std for standard documents), storage drivers identifier (GUID), retrieval drivers identifier (GUID), ...).

2. The second step consists of setting the path for files "Standard" and "Plugin". If You use standard attributes only, it's not necessary for You to write these files. They are already written in OCAF. The files: Standard:


MDTV-Standard.Description: Standard Document Version 1.0

MDTV-Standard.FileExtension: std

MDTV-Standard.StoragePlugin: ad696000-5b34-11d1-b5ba-00a0c9064368

MDTV-Standard.RetrievalPlugin: ad696001-5b34-11d1-b5ba-00a0c9064368

MDTV-StandardSchema: ad696002-5b34-11d1-b5ba-00a0c9064368

MDTV-Standard.AttributeStoragePlugin: 47b0b826-d931-11d1-b5da-00a0c9064368

MDTV-Standard.AttributeRetrievalPlugin: 47b0b827-d931-11d1-b5da-00a0c9064368


! Description of available plugins

! ********************************


a148e300-5740-11d1-a904-080036aaa103.Location: libFWOSPlugin.so


! standard document drivers plugin


ad696000-5b34-11d1-b5ba-00a0c9064368.Location: libPAppStdPlugin.so

ad696001-5b34-11d1-b5ba-00a0c9064368.Location: libPAppStdPlugin.so



! standard schema plugin


ad696002-5b34-11d1-b5ba-00a0c9064368.Location: libPAppStdPlugin.so


! standard attribute drivers plugin


47b0b826-d931-11d1-b5da-00a0c9064368.Location: libPAppStdPlugin.so

47b0b827-d931-11d1-b5da-00a0c9064368.Location: libPAppStdPlugin.so

To set the paths for these files it's necessary to set the enviroments: CSF_PluginDefaults and CSF_StandardDefaults. For example let's set the files in the directory "MyApplicationPath/MyResources":

setenv CSF_PluginDefaults MyApplicationPath/MyResources

setenv CSF_StandardDefaults MyApplicationPath/MyResources

Just these two steps are completed You may run Your application, create documents and Save/Open them.

Open/Save operations of a document with Your own defined attributes

If You use Your own attribute(s) in a document, You should make this (these) attribute(s) storable (retrievable). There are several steps of this realization.

Let's imagine that Your attribute is defined in the package TMyTheBestPackage and its name is MyTheBestAttribute. The name of the package has "T" letter at the first position. It means that the content of this package (its classes) may be located only in the operating memory (the classes can't be saved or retrieved). To make them storable and retrievable it's necessary to realize two packages else: with "P" and "M" letters at the first position. In our example they are: PMyTheBestPackage and MMyTheBestPackage. The first package (with "P" letter at the first position) contains the classes which have the fields of corresponding "T" package classes which should be saved or retrieved. These classes convert the transient type of a field into persistent type and vice versa. The "M" package contains drivers for convertation of attributes from their transient state into persistent and vice versa.

Just the classes of "P" and "M" packages are realized, it's necessary to add the new "P" package to the schema. For standard attributes there is used StdSchema. If You don't like this name or You would like to see Your own defined names - rename this package. For example, You may define such name as MyTheBestSchema. You should add Your package to a package list of MyTheBestSchema.cdl file. Then, recompile the schema.

The next step consists of implementation of plugin - an executable which will connect to Your application and it will store/retrieve Your documents. For standard attributes it is defined in the package PAppStdPlugin. As You've done it for the schema You may rename the plugin name to MyTheBestApplicationPlugin, for example. In this package You have to determine the executable and to call a macros "PLUGIN" for Your factory.

A factory is realized as a method which by a GUID returns drivers from "M" package described above. For standard attributes the factory is realized in the separate package named PAppStd. You may realize Your own factory anywhere.

Just all these steps are completed, implement two application methods Formats() and ResourcesName() which should return Your own defined format (for example, "MDTV-MyTheBestFormat") and a file where the GUIDs are determined (for example, "MyTheBestFormat" file), set the environments pointing to Your resource files ("Plugin" and "MyTheBestFormat") as it is described for standard Open/Save operations (see above).

Each step in details is described delow:

1. The first step is to implement a class-convertor in the package PMyTheBestPackage for our transient class MyTheBestAttribute. Let it be MyTheBestAttribute from PMyTheBestPackage. This class contains the fields which should be storable for our MyTheBestAttribute from TMyTheBestPackage. Also, this class has Set/Get methods for each of these fields. For example, let's our transient class has a field myValue of type integer. It means that the persistent class should have the same field and such methods as SetValue(int), GetValue() returning the integer value.

2. The second step is to implement store/retrieve drivers in the "M" package MMyTheBestPackage. Let name the drivers MyTheBestAttributeStorageDriver from MMyTheBestPackage and MyTheBestAttributeRetrievalDriver from MMyTheBestPackage. Now it's necessary to implement some methods of these drivers. For the storage driver:

MMyTheBestPackage_MyTheBestAttributeStorageDriver::SourceType() should return the transient type of our


MMyTheBestPackage_MyTheBestAttributeStorageDriver::NewEmpty() should return a new instance of the

persistent class MyTheBestAttribute from PMyTheBestPackage.

MMyTheBestPackage_MyTheBestAttributeStorageDriver::Paste() converts fields from the transient class

instance into its persistent class instance.

For the retrieval driver:

MMyTheBestPackage_MyTheBestAttributeRetrievalDriver::SourceType() should return the persistent type of

our attribute (defined in the "P" package).

MMyTheBestPackage_MyTheBestAttributeRetrievalDriver::NewEmpty() should return a new instance of the

transient class MyTheBestAttribute from TMyTheBestPackage.

MMyTheBestPackage_MyTheBestAttributeRetrievalDriver::Paste() converts fields from the persistent class

instance into its transient class instance.

3. And now, let's add our "P" package into the schema for standard attributes. Let's rename the schema for MyTheBestSchema.

Add the package PMyTheBestPackage to the list of packages of the file MyTheBestSchema.cdl and recompile this package.

4. The forth step consists of implementation of an executable which will connect to our application and open/save our documents.

Copy the package PAppStdPlugin and rename it for MyTheBestApplicationPlugin. In the PLUGIN macros type the name of Your factory which will be defined in the next step.

5. Factory is a method which returns drivers (standard drivers and our defined drivers from the "M" package) by a GUID.

Copy the package where the standard factory is defined. Rename it for MyTheBestSchemaLocation.

The Factory() method inside checks the GUID set as its argument and returns the corresponding table of drivers.

Set two new GUIDs for Your determined storage and retrieval drivers. Append two "if" declarations inside the Factory() method which should check the set GUID for coincidence with our defined GUIDs for our storage and retrieval drivers. If the GUID coincides with one of them, the method should return a table of storage or retrieval drivers respectively.

6. Now it's time to implement the mentioned two deferred methods of class Application from TDocStd and to set environment as it is described above in the previous topic concerning Open/Save operation for a document with standard attributes only.

Best regards Sergey

Mikael Aronsson's picture

Hi !

Thank's, this information should help a lot, and it should have been in the documentation from the start, if some one could add this stuff to the ocafwp.pdf or the ocaf documentation it should help a lot I think.

Thanks again, Mikael

Liu Ailin's picture

I just changed the "Ocaf-Sample" in Formats.Append(TCollection_ExtendedString ("Ocaf-Sample")) of TSampleOcaf_Application.cxx,in SampleOcafApp->NewDocument("Ocaf-Sample",myOcafDoc) of CSampleOcafDoc.cpp, and all "Ocaf-Sample" in "Resources" file to "MyOCAF", why does 10_SampleOcaf not work? i.e. I can not "Open" the test file?



Barbara's picture

Have you try to modify test file in the same way ( Ocaf-Sample by MyOCAF ) ?

there is a line :

FILE_FORMAT: Ocaf-Sample to substitute by : FILE_FORMAT: MyOCAF

best regards

Liu Ailin's picture

Dear Mr. Barbara,

You are GREAT!!
Thank you very much!

Liu Ailin