From topic title, by “own component” I mean a class derived from FBComponent. Why would you want to have it, there are several advantages:

  • FBComponent has the ability to implement the internal list of properties, and the presence of all the methods for managing them. I wrote about this not too long ago in my blog. This feature is very useful, because there a visual component BrowserProperties, where you can view the properties of your components and work directly with them. It is very convenient!

  • FBComponent supports meta information about the class and its properties, often used ClassName, TypeInfo
  • You can use callbacks with FBComponent
  • set the flags of an object, including auto free memory out of this class or to control the availability of only one instance.

However, to work with the metadata and the object, inherited from FBComponent, it should be registered in a Mobu, otherwise it will crash the heap.
1. For the convenience of a declaration of basic methods and types, there is a define FBClassDeclare, in which you have to specify a class and a parent (FBComponent)

1
2
3
4
class CEPointsCloud : public FBComponent
{
FBClassDeclare( CEPointsCloud, FBComponent );
...

2. The class constructor should always contain a call FBClassInit and call for the FBComponent’s constructor, showing the parent (usually just NULL)

1
2
3
4
5
CEPointsCloud::CEPointsCloud()
: FBComponent(NULL)
{
FBClassInit;
}

And in the case when you want to introduce new properties for your component, it is better to do, overriding FBCreate method and there describing all the necessary properties. Similarly, the case with the release of memory, it should not do in the destructor, you have to override methods FBDestroy, FBDelete.
3. In the code, call FBClassImplementation to implement basic methods that are created through FBClassDeclare.

1
FBClassImplementation( CEPointsCloud );

Next, write a static function to create a new class object, it has the form

1
typedef HIObject (* kObjectCreatorFnc)(HIObject pOwner,char *pName,void *pData);

in my case it will be like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static HIObject RegisterPointsCloud(HIObject pOwner,char *pName,void *pData)

{

CEPointsCloud *Class = new CEPointsCloud();

if (Class->FBCreate() ) {

return Class->GetHIObject();

} else {

delete Class;

return NULL;

}

}

That call helps MoBu to allocate memory for the new object.

To describe the workpiece FBLibraryModule, which introduces the actual function of registration for the object. In this case we specify the category of object and meta name for a given class

1
2
3
4
5
6
7
8
9
FBLibraryModule( CEPointsCloud )

{

FBRegisterObject( CEPointsCloud, "PointsCloud/Object", "CEPointsCloud", "Object",

RegisterPointsCloud, true, FB_DEFAULT_SDK_ICON );

}

4. Now, you have to register the above function for the new class. This is done during the announcement to the library, such

1
2
3
4
5
6
7
8
9
10
11
12
13
//--- Library declaration.

FBLibraryDeclare( ortool_template )

{

FBLibraryRegister( CEPointsCloud );

FBLibraryRegister( ORTool_Template );

}

FBLibraryDeclareEnd;

That’s it! Now it’s ready to use:

1
2
3
mOptical = (CEPointsCloud*)FBCreateObject( "PointsCloud/Object",

"CEPointsCloud", "CEPointsCloud" );
Your own component in OR SDK
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *