Getting Started
At the beginning of your development, you first define an application class by inheriting from the Application abstract class. You only have to create and determine the resources of the application for specifying the format of your documents (you generally use the standard one) and their file extension.
Then, you design the application data model by organizing attributes you choose among those provided with OCAF. You can specialize these attributes using the User attribute. For example, if you need a reflection coefficient, you aggregate a User attribute identified as a reflection coefficient with a Real attribute containing the value of the coefficient (as such, you don't define a new class).
If you need application specific data not provided with OCAF, for example, to incorporate a finite element model in the data structure, you define a new attribute class containing the mesh, and you include its persistent homologue in a new file format.
Once you have implemented the commands which create and modify the data structure according to your specification, OCAF provides you, without any additional programming:
- Persistent reference to any data, including geometric elements - several documents can be linked with such reference;
- Document-View association;
- Ready-to-use functions such as:
- Undo-redo;
- Save and open application data.
Finally, you develop the application's graphical user interface using the toolkit of your choice, for example Qt, GTK, MFC, .NET, or a similar framework.
An example of OCAF usage
To create a useful OCAF-based application, it is necessary to redefine two deferred methods: Formats and ResourcesName
In the Formats method, add the format of the documents, which need to be read by the application and may have been built in other applications.
For example:
{
}
void Append(const TheItemType &theItem)
In the ResourcesName method, you only define the name of the resource file. This file contains several definitions for the saving and opening mechanisms associated with each format and calling of the plug-in file.
const char* myApplication::ResourcesName()
{
return "Resources";
}
To obtain the saving and opening mechanisms, it is necessary to set two environment variables: CSF_PluginDefaults, which defines the path of the plug-in file, and CSF_ResourcesDefaults, which defines the resource file (the name of the resource environment variable is built from the value returned by ResourcesName()):
SetEnvironmentVariable ("CSF_PluginDefaults", myDirectory);
SetEnvironmentVariable ("CSF_ResourcesDefaults", myDirectory);
The plugin and the resource files of the application will be located in myDirectory. The name of the plugin file must be Plugin.
Resource File
The resource file describes the documents (type and extension) and the type of data that the application can manipulate by identifying the storage and retrieval drivers appropriate for this data.
Each driver is unique and identified by a GUID generated, for example, with the uuidgen tool in Windows.
Five drivers are required to use all standard attributes provided within OCAF:
- the schema driver (ad696002-5b34-11d1-b5ba-00a0c9064368)
- the document storage driver (ad696000-5b34-11d1-b5ba-00a0c9064368)
- the document retrieval driver (ad696001-5b34-11d1-b5ba-00a0c9064368)
- the attribute storage driver (47b0b826-d931-11d1-b5da-00a0c9064368)
- the attribute retrieval driver (47b0b827-d931-11d1-b5da-00a0c9064368)
These drivers are provided as plug-ins by OCCT toolkits such as TKStd / TKStdL (legacy binary), TKBin / TKBinL (current binary) and TKXml / TKXmlL (XML). The mapping from GUID to toolkit lives in the standard Plugin resource file shipped under resources/StdResource/Plugin.
For example, this is a resource file, which declares a new model document OCAF-MyApplication:
formatlist:OCAF-MyApplication
OCAF-MyApplication.Description: MyApplication Document Version 1.0
OCAF-MyApplication.FileExtension: sta
OCAF-MyApplication.StoragePlugin: ad696000-5b34-11d1-b5ba-00a0c9064368
OCAF-MyApplication.RetrievalPlugin: ad696001-5b34-11d1-b5ba-00a0c9064368
OCAF-MyApplicationSchema: ad696002-5b34-11d1-b5ba-00a0c9064368
OCAF-MyApplication.AttributeStoragePlugin: 47b0b826-d931-11d1-b5da-00a0c9064368
OCAF-MyApplication.AttributeRetrievalPlugin: 47b0b827-d931-11d1-b5da-00a0c9064368
Plugin File
The plugin file describes the list of required plug-ins to run the application and the toolkits in which the plug-ins are located.
You need the OCAF plug-in drivers (such as TKStd, TKBin, TKXml) to run an OCAF application; OCCT ships them in resources/StdResource/Plugin, which is loaded via the CSF_PluginDefaults environment variable.
The syntax of each item is Identification.Location: Toolkit_Name, where:
- Identification is the Standard_GUID of the service implemented by the plug-in.
- Location is the kind of attribute (here always
.Location).
- Toolkit_Name is the OCCT toolkit name without the platform-specific
lib/.dll/.so decoration; the platform's dynamic loader resolves the actual library at runtime.
For example, an excerpt from the standard Plugin file:
! standard attribute drivers plugin
ad696001-5b34-11d1-b5ba-00a0c9064368.Location: TKStd
! BinOcaf Document Plugin
03a56835-8269-11d5-aab2-0050044b1af1.Location: TKBin
03a56836-8269-11d5-aab2-0050044b1af1.Location: TKBin
! XmlOcaf Document Plugin
03a56820-8269-11d5-aab2-0050044b1af1.Location: TKXml
03a56822-8269-11d5-aab2-0050044b1af1.Location: TKXml
03a56824-8269-11d5-aab2-0050044b1af1.Location: TKXml
Implementation of Attribute Transformation in a HXX file
{
public:
public:
Standard_EXPORT
gp_Trsf Get ()
const;
public:
Standard_EXPORT
void SetRotation (
const gp_Ax1& theAxis,
double theAngle);
Standard_EXPORT
void SetTranslation (
const gp_Vec& theVector);
Standard_EXPORT
void SetMirror (
const gp_Pnt& thePoint);
Standard_EXPORT
void SetMirror (
const gp_Ax1& theAxis);
Standard_EXPORT
void SetMirror (
const gp_Ax2& thePlane);
Standard_EXPORT
void SetScale (
const gp_Pnt& thePoint,
double theScale);
Standard_EXPORT
void SetTransformation (
const gp_Ax3& theCoordinateSystem1,
const gp_Ax3& theCoordinateSystem2);
public:
public:
Standard_EXPORT MyPackage_Transformation();
private:
double myAngle;
double myScale;
};
std::ostream Standard_OStream
virtual void Restore(const occ::handle< TDF_Attribute > &anAttribute)=0
virtual const Standard_GUID & ID() const=0
virtual occ::handle< TDF_Attribute > NewEmpty() const=0
virtual Standard_OStream & Dump(Standard_OStream &anOS) const
virtual void Paste(const occ::handle< TDF_Attribute > &intoAttribute, const occ::handle< TDF_RelocationTable > &aRelocationTable) const=0
Implementation of Attribute Transformation in a CPP file
#include <MyPackage_Transformation.hxx>
{
return ID;
}
{
if (!theLabel.
FindAttribute(MyPackage_Transformation::GetID(), aT))
{
aT = new MyPackage_Transformation();
}
return aT;
}
gp_Trsf MyPackage_Transformation::Get()
const
{
switch (myType)
{
{
break;
}
{
break;
}
{
break;
}
{
break;
}
{
break;
}
{
break;
}
{
aTransformation.
SetScale(myFirstPoint, myScale);
break;
}
{
break;
}
{
break;
}
}
return aTransformation;
}
void MyPackage_Transformation::SetRotation(
const gp_Ax1& theAxis,
double theAngle)
{
Backup();
myAx1 = theAxis;
myAngle = theAngle;
}
void MyPackage_Transformation::SetTranslation(
const gp_Vec& theVector)
{
Backup();
myFirstPoint.SetCoord(0, 0, 0);
mySecondPoint.SetCoord(theVector.
X(), theVector.
Y(), theVector.
Z());
}
void MyPackage_Transformation::SetMirror(
const gp_Pnt& thePoint)
{
Backup();
myFirstPoint = thePoint;
}
void MyPackage_Transformation::SetMirror(
const gp_Ax1& theAxis)
{
Backup();
myAx1 = theAxis;
}
void MyPackage_Transformation::SetMirror(
const gp_Ax2& thePlane)
{
Backup();
myAx2 = thePlane;
}
void MyPackage_Transformation::SetScale(
const gp_Pnt& thePoint,
double theScale)
{
Backup();
myFirstPoint = thePoint;
myScale = theScale;
}
void MyPackage_Transformation::SetTransformation (
const gp_Ax3& theCoordinateSystem1,
const gp_Ax3& theCoordinateSystem2)
{
Backup();
myFirstAx3 = theCoordinateSystem1;
mySecondAx3 = theCoordinateSystem2;
}
{
return GetID();
}
{
myType = aTransformation->myType;
myAx1 = aTransformation->myAx1;
myAx2 = aTransformation->myAx2;
myFirstAx3 = aTransformation->myFirstAx3;
mySecondAx3 = aTransformation->mySecondAx3;
myAngle = aTransformation->myAngle;
myScale = aTransformation->myScale;
myFirstPoint = aTransformation->myFirstPoint;
mySecondPoint = aTransformation->mySecondPoint;
}
{
return new MyPackage_Transformation();
}
{
aTransformation->myType = myType;
aTransformation->myAx1 = myAx1;
aTransformation->myAx2 = myAx2;
aTransformation->myFirstAx3 = myFirstAx3;
aTransformation->mySecondAx3 = mySecondAx3;
aTransformation->myAngle = myAngle;
aTransformation->myScale = myScale;
aTransformation->myFirstPoint = myFirstPoint;
aTransformation->mySecondPoint = mySecondPoint;
}
{
theOS << "Transformation: ";
switch (myType)
{
{
theOS << "gp_Identity";
break;
}
{
theOS << "gp_Rotation";
break;
}
{
theOS << "gp_Translation";
break;
}
{
theOS << "gp_PntMirror";
break;
}
{
theOS << "gp_Ax1Mirror";
break;
}
{
theOS << "gp_Ax2Mirror";
break;
}
{
theOS << "gp_Scale";
break;
}
{
theOS << "gp_CompoundTrsf";
break;
}
{
theOS << "gp_Other";
break;
}
}
return theOS;
}
MyPackage_Transformation::MyPackage_Transformation()
{
}
void AddAttribute(const occ::handle< TDF_Attribute > &anAttribute, const bool append=true) const
bool FindAttribute(const Standard_GUID &anID, occ::handle< TDF_Attribute > &anAttribute) const
void SetRotation(const gp_Ax1 &theA1, const double theAng)
constexpr void SetMirror(const gp_Pnt &theP) noexcept
constexpr void SetTranslation(const gp_Vec &theV) noexcept
void SetTransformation(const gp_Ax3 &theFromSystem1, const gp_Ax3 &theToSystem2)
void SetScale(const gp_Pnt &theP, const double theS)
constexpr double Z() const noexcept
constexpr double X() const noexcept
constexpr double Y() const noexcept
handle< TDerived > down_cast(const handle< TBase > &theObject)
Implementation of typical actions with standard OCAF attributes.
The following four examples present typical actions with OCAF services (mainly for newcomers). The method Sample() of each example is not dedicated for execution "as is"; it is rather a set of logical actions using some OCAF services.
TDataStd_Sample.cxx
This sample contains templates for typical actions with the following standard OCAF attributes:
TDocStd_Sample.cxx
This sample contains template for the following typical actions:
- creating application;
- creating the new document (document contains a framework);
- retrieving the document from a label of its framework;
- filling a document with data;
- saving a document in the file;
- closing a document;
- opening the document stored in the file;
- copying content of a document to another document with possibility to update the copy in the future.
TPrsStd_Sample.cxx
This sample contains template for the following typical actions:
- starting with data framework;
- setting the TPrsStd_AISViewer in the framework;
- initialization of aViewer;
- finding TPrsStd_AISViewer attribute in the DataFramework;
- getting AIS_InteractiveContext from TPrsStd_AISViewer;
- adding driver to the map of drivers;
- getting driver from the map of drivers;
- setting TNaming_NamedShape to <ShapeLabel>;
- setting the new TPrsStd_AISPresentation to <ShapeLabel>;
- displaying;
- erasing;
- updating and displaying presentation of the attribute to be displayed;
- setting a color to the displayed attribute;
- getting transparency of the displayed attribute;
- modify attribute;
- updating presentation of the attribute in viewer.
TNaming_Sample.cxx
This sample contains template for typical actions with OCAF Topological Naming services. The following scenario is used:
- data framework initialization;
- creating Box1 and pushing it as PRIMITIVE in DF;
- creating Box2 and pushing it as PRIMITIVE in DF;
- moving Box2 (applying a transformation);
- pushing the selected edges of the top face of Box1 in DF;
- creating a Fillet (using the selected edges) and pushing the result as a modification of Box1;
- creating a Cut (Box1, Box2) as a modification of Box1 and push it in DF;
- recovering the result from DF.