3D PLM Enterprise Architecture

Middleware Abstraction - Object Modeler

Creating Interfaces

Declaring component expected type and behavior
Use Case

Abstract

This article shows how to create interfaces.


What You Will Learn With This Use Case

This use case is intended to show you how to create interfaces  that declare either a type or a behavior that a component [1] can implement [2] and that can be used in client application [3].

[Top]

The CAASysGeoModelInf Use Case

CAASysGeoModelInf is a use case of the CAASystem.edu framework that illustrates CATIA System framework capabilities.

[Top]

What Does CAASysGeoModelInf Do

This use case gives a set of interfaces whose header files are located in the PublicInterfaces directory. The CAAISysCircle interface is taken as an example in this article to describe the steps of an interface creation. This interface is a type interface for a circle component.

[Top]

How to Launch CAASysGeoModelInf

To launch CAASysGeoModelInf, you will need to set up the build time environment, then compile CAASysGeoModelInf along with its prerequisites, set up the run time environment, and then execute the use case [3].

Do not type the module name on the command line, but type CNEXT instead. When CATIA is ready, do the following:

[Top]

Where to Find the CAASysGeoModelInf Code

The CAASysGeoModelInf use case is made of several classes located in the CAASysGeoModelInf.m module of the CAASystem.edu framework:

Windows InstallRootDirectory\CAASystem.edu\CAASysGeoModelInf.m\
Unix InstallRootDirectory/CAASystem.edu/CAASysGeoModelInf.m/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

To create an interface such as CAAISysCircle, there are three main steps:

# Step Where
1 Create the CAAISysCircle interface header file CAAISysCircle.h file in PublicInterfaces
2 Create the CAAISysCircle interface source file CAAISysCircle.cpp file
3 Create the CAAISysCircle interface TIE TIE_CAAISysCircle.tsrc file

[Top]

Creating the CAAISysCircle Header File

#ifndef CAAISysCircle_H
#define CAAISysCircle_H

#include "CATBaseUnknown.h"   // Needed to derive from CATBaseUnknown

#include "CATMathPoint.h"     // Needed by GetCenter & SetCenter -> class CATMathPoint; ??
#include "CATMathVector.h"    // Needed by SetPlane & GetPlanar -> class CATMathVector; ??

#include "CAASysGeoModelInf.h"  // Needed to export the IID and the class

// Global Unique IDentifier defined in .cpp 
extern ExportedByCAASysGeoModelInf IID IID_CAAISysCircle;

class ExportedByCAASysGeoModelInf CAAISysCircle : public CATBaseUnknown
{
  // Used in conjunction with CATImplementInterface in the .cpp file 
  CATDeclareInterface;

  public :

    virtual HRESULT SetPlane (const CATMathVector & iNormal, 
                              const CATMathVector & iAxis)   =0 ;
    virtual HRESULT SetCenter(const CATMathPoint & iCenter)  =0 ;
    virtual HRESULT SetRadius(const float iRadius)           =0 ;

    virtual HRESULT GetPlane (CATMathVector & oNormal,
                              CATMathVector & oAxis)  const  =0 ;   
    virtual HRESULT GetCenter(CATMathPoint & oCenter) const  =0 ;
    virtual HRESULT GetRadius(float & oRadius)        const  =0 ;
};
#endif

The CAAISysCircle interface IID (Interface IDentifier) [4] is declared using the extern keyword to enable client application to ask for CAAISysCircle interface pointers. The CAAISysCircle interface is an abstract class. All its methods are consequently declared as pure virtual, using the virtual keyword and by placing =0 at the end of their declarations. CAAISysCircle derives from CATBaseUnknown, as any interface. The CATDeclareInterface macro declares that the abstract class CAAISysCircle is an interface. There is neither constructor nor destructor, since this class cannot ne instantiated.

To define a circle in the 3D space, three data should be set:

The three methods SetPlane, SetCenter, and SetRadius set this data, and the associated GetPlane, GetCenter and GetRadius methods retrieve it. They all return an HRESULT [5]. Note that the parameters of the setter methods are declared as const, and thus cannot be modified by these methods. In the same way, the getter methods are declared as read-only using the const keywords placed after the closing parenthesis. Both setter and getter methods use references to components as parameters. This is to simplify the implementation code that have to deal with the Mathematics framework that uses references extensively. Otherwise, pointers could also be used.

[Top]

Creating the CAAISysCircle Source File

#include "CAAISysCircle.h"

IID IID_CAAISysCircle={ /* f281aba4-d4b4-11d3-b7f5-0008c74fe8dd */
    0xf281aba4,
    0xd4b4,
    0x11d3,
    {0xb7, 0xf5, 0x00, 0x08, 0xc7, 0x4f, 0xe8, 0xdd}
  };

CATImplementInterface(CAAISysCircle, CATBaseUnknown);

The CAAISysCircle interface source file gives the value of CAAISysCircle IID [4]. The CATImplemenInterface macro declares that the CAAISysCircle interface OM-derives [6] from CATBaseUnknown.

[Top]

Creating the CAAISysCircle Interface TIE

#include "CAAISysCircle.h"

The CAAISysCircle interface TIE is created by the code builder mkmk using a simple include of the CAAISysCircle.h file in the TIE_CAAISysCircle.tsrc. This file should be located in the same src directory than CAAISysCircle.cpp.

[Top]


In Short

This use case shows how to create an interface as an abstract class, and how to create the interface TIE.

[Top]


References

[1] Creating Components
[2] Creating Interfaces
[3] Object Modeler Component and Implementation Inheritance
[4] About Globally Unique IDentifiers
[5] What Is HRESULT?
[6] Object Modeler Component and Implementation Inheritances
[Top]

History

Version: 1 [Mar 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.