Open CASCADE Technology
6.7.0


This guide describes the usage of the Function Mechanism of Open CASCADE Application Framework on a simple example. This example represents a "nail" composed by a cone and two cylinders of different radius and height:
So, the cylinders depend on the cone and the cone parameters define the size of the nail.
It means that repositioning the cone (changing its apex point) moves the nail, the change of the radius of the cone produces a thinner or thicker nail, and the change of the height of the cone shortens or prolongates the nail. It is suggested to examine the programming steps needed to create a 3D parametric model of the "nail". This guide describes in detail usage of the Function Mechanism. Other aspects, such as the data model and the interfaces are mentioned in brief.
The first step consists in model data allocation in the OCAF tree. In other words, it is necessary to decide where to put the data.
In this case, the data can be organized into a simple tree using references for definition of dependent parameters:
Nail
The "nail" object has three subleaves in the tree: the cone and two cylinders.
The cone object is independent.
The long cylinder representing a "stem" of the nail refers to the corresponding parameters of the cone to define its own data (position, radius and height). It means that the long cylinder depends on the cone.
The parameters of the head cylinder may be expressed through the cone parameters only or through the cone and the long cylinder parameters. It is suggested to express the position and the radius of the head cylinder through the position and the radius of the long cylinder, and the height of the head cylinder through the height of the cone. It means that the head cylinder depends on the cone and the long cylinder.
The interfaces of the data model are responsible for dynamic creation of the data tree of the represented at the previous step, data modification and deletion.
The interface called INail should contain the methods for creation of the data tree for the nail, setting and getting of its parameters, computation, visualization and removal.
This method of the interface creates a data tree for the nail at a given leaf of OCAF data tree.
It creates three subleaves for the cone and two cylinders and allocates the necessary data (references at the subleaves of the long and the head cylinders).
It sets the default values of position, radius and height of the nail.
The nail has the following user parameters:
The values of the position and the radius of the nail are defined for the cone object data. The height of the cone is recomputed as 2 * heights of nail and divided by 9.
The Function Mechanism is responsible for recomputation of the nail. It will be described in detail later in this document.
A data leaf consists of the reference to the location of the real data and a real value defining a coefficient of multiplication of the referenced data.
For example, the height of the long cylinder is defined as a reference to the height of the cone with coefficient 3. The data leaf of the height of the long cylinder should contain two attributes: a reference to the height of cone and a real value equal to 3.
The shape resulting of the nail function can be displayed using the standard OCAF visualization mechanism.
To automatically erase the nail from the viewer and the data tree it is enough to clean the nail leaf from attributes.
The nail is defined by four functions: the cone, the two cylinders and the nail function. The function of the cone is independent. The functions of the cylinders depend on the cone function. The nail function depends on the results of all functions:
The Function Mechanism of Open CASCADE Technology creates this graph of dependencies and allows iterating it following the dependencies. The only thing the Function Mechanism requires from its user is the implementation of pure virtual methods of TFunction_Driver:
These methods give the Function Mechanism the information on the location of arguments and results of the function and allow building a graph of functions. The class TFunction_Iterator iterates the functions of the graph in the execution order.
The pure virtual method TFunction_Driver::Execute() calculating the function should be overridden.
The method ::MustExecute() calls the method ::Arguments() of the function driver and ideally this information (knowledge of modification of arguments of the function) is enough to make a decision whether the function should be executed or not. Therefore, this method usually shouldn’t be overridden.
The cone and cylinder functions differ only in geometrical construction algorithms. Other parameters are the same (position, radius and height).
It means that it is possible to create a base class – function driver for the three functions, and two descendent classes producing: a cone or a cylinder.
For the base function driver the methods ::Arguments() and ::Results() will be overridden. Two descendent function drivers responsible for creation of a cone and a cylinder will override only the method ::Execute().
The method ::Arguments() of the function driver of the nail returns the results of the functions located under it in the tree of leaves. The method ::Execute() just collects the results of the functions and makes one shape – a nail.
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.
This appendix gives an example of the code for iteration and execution of functions.
This appendix gives an example of the code for a cylinder function driver. In order to make the things clearer, the methods ::Arguments() and ::Results() from the base class are also mentioned.