Mechanical Modeler

Creating a New StartUp Deriving from a Mechanical StartUp

Creating a StartUp and a StartUp factory interface
Technical Article

Abstract

The aim of this article is to describe all the steps to build a new mechanical feature: creating a new StartUp, creating a StartUp's catalog and creating a factory to create instances. This new feature, deriving from a mechanical feature, benefits from mechanical behaviors. The "Integrating a New Mechanical Feature in V5" [1] article lists them and explains the interfaces that the new feature must necessarily implement, or eventually implement, to be fully integrated in V5 and to behave as any other Dassault Systemes mechanical feature.

This article is part of a set of documents which describe the Mechanical Modeler. Refer to the "Mechanical Modeler Overview" [2] article to have a view of all these articles.


Choosing the Mechanical Feature to Derive from

 The next UML schema [Fig.1] presents a part of the mechanical feature tree:

Fig.1: Mechanical Features Architecture

To create a new feature type, you should derive from an existing public feature. These features and their public attributes can be found in the .CATSpec files. In the CAA encyclopedia, you will find references to these files in the Quick Reference section. 

In the case of mechanical features, there are two files:

This file references the GSMGeom StartUp that you can also derive from.

How to choose ? The choice depends on the targeted domain in which the new feature should be part of:

By deriving only from the MechanicalFeature StartUp, you have a mechanical feature without geometry but integrated in some mechanical mechanisms. For example, you can insert this feature inside the MechanicalPart [9] and the feature will be displayed in the specification tree.

However, it is preferable to derive from MechanicalElement StartUp which is really dedicated to define non geometrical feature

[Top]

Creating the New Derived StartUp

The StartUp is a feature prototype that describes the data structure of all feature instances that will be created from it. The new StartUp must be created in a .CATFct catalog file. Here are the steps needed to realize the creation of a new StartUp:

  1. Create a catalog (using the CreateCatalog global function) or open an existing catalog (using the UpgradeCatalog global function) that will contain the new derived StartUp. 
  2. Use the generic StartUp Factory to create the new derived StartUp (using the CATOsmSUFactory global function)
  3. Add new attributes to the StartUp (using the AddAttribute method)
  4. Save the catalog (using the SaveCatalog global function)
  5. Create or modify the CatalogNameNLS.CATNls file to set an NLS name to the new StartUp.

You can execute the forth first operations in a main batch program which will create/modify the .CATFct file. This file is used as input to the factory that will instantiate the StartUp in a document.

These five steps are described in more details in the following articles:

Once created, the StartUp should be able to be instantiated; See the "Creating the New Derived StartUp Factory" section below. Each feature instance should also be modifiable, as you will see in the next section.

[Top]

Creating an Interface of Type

The new feature has certainly its own specific attributes (see step 3 in the previous section). To valuate them or to retrieve their values, it is recommended to create an interface of type, as compared to an interface of behavior. This interface enables you to access all specific attributes of the feature. 

To achieve this goal, two steps are necessary:

  1. Defining the Interface Of Type
  2. Implementing the Interface of Type

Creating the Interface of Type

Refer to the "Creating an Interface" article [7], to create the header, the source and the .trsc files of this interface.

Implementing the Interface of Type

This interface will be implemented on the new StartUp, so in the implementation source file you will find: 

...
CATImplementClass ( SourceName,
                    DataExtension         ,
                    CATBaseUnknown        ,
                    NameOfTheNewStartup);
...

The CATImplementClass macro means that SourceName is a data extension of  NameOfTheNewStartup. The third argument must always be set to CATBaseUnknown or CATNull for any kind of extension.  NameOfTheNewStartup is the name set in the CATOsmSUFactory global function (see step 4 of the previous section)

[Top]

Creating the New Derived StartUp Factory

This paragraph explains how to create instances of the new StartUp. To achieve this goal, two steps are necessary:

  1. Defining the Factory Interface
  2. Implementing this Interface 

Creating the Factory Interface

In most cases, this interface contains only one method which has as input arguments, the values needed to initialize the attributes of the new instance and as output argument, the new instance. Here is an example:

#ifndef CAAIXXFactory_h
#define CAAIXXFactory_h

#include "CATBaseUnknown.h"
class CATISpecObject ;
extern ExportedByCAADLL IID IID_CAAIXXFactory;

class ExportedByCAADLL CAAIXXFactory : public CATBaseUnknown
{
  CATDeclareInterface;
  public :
    virtual HRESULT CreateMyNewFeature(...,..., 
                                       CATISpecObject **pISpecObjectOnInstance) = 0;
};

#endif

The last argument of this method, pISpecObjectOnInstance,  is the newly created instance.  

Refer to the "Creating an Interface" article [7], to create the src and the .trsc files . 

Implementing the Factory Interface

This section answers the following questions:

Implementing the Interface on the Specification Container

This factory interface will be implemented on the specification container named CATPrtCont [8]. So in the implementation source file, you will have a declaration such as:

CATImplementClass ( CAAEXXFactory,
                    DataExtension         ,
                    CATBaseUnknown        ,
                    CATPrtCont );
                    
#include "TIE_CAAIXXFactory.h" 
TIE_CAAIXXFactory( CAAEXXFactory);

The CATImplementClass macro means that CAAEXXFactory is a data extension of CATPrtCont . The third argument must always be set to CATBaseUnknown or CATNull for any kind of extension. The TIE macro is needed to tie the implementation to its interface. 

Do not forget to modify the interface dictionary to declare that CATPrtCont implements the interface factory in the library which contains the implementation of the interface.

CATPrtCont CAAIXXFactory libYYYY
The Contents of the Instantiation Method

The generic contents of the CreateMyNewFeature method can be the following:

HRESULT CAAEXXFactory::CreateMyNewFeature( ...,...,
                                        CATISpecObject ** pISpecObjectOnInstance )  
{
  1. Get a CATIContainer pointer on "this"
  2. Open the catalog which contains the newly derived StartUp
  3. Retrieve the newly derived StartUp
  4. Create an instance of the newly derived StartUp
  5. Subscribes to repository for Configuration Data Storage
  6. Gets Feature Type Information for BackUp / StartUp management - Only if you use a Geometrical Feature
  7. Set default values for the attributes of the new feature instance
}

1) Get the CATIContainer interface pointer on "this"

...
CATIContainer * pIContainer = NULL ;  
rc = QueryInterface( IID_CATIContainer , ( void**)&pIContainer);    
...

2) Open the catalog which contains the newly derived StartUp

    CATICatalog * pICatalog = NULL;

    CATUnicodeString StorageName = "NameOfTheCatalog.CATfct";

    CATUnicodeString ClientId = "MyCatalogClientId";

    rc = ::AccessCatalog( &StorageName, &ClientId, pIContainer, &pICatalog);
        

To open the catalog, you can use the AccessCatalog global function. The parameters of this function are:

3) Retrieve the newly derived StartUp

...
CATBaseUnknown *pStartup = NULL;
CATUnicodeString StartupType = "NameOfTheNewStartup";
rc = pICatalog->RetrieveSU( &pStartup , &StartupType ,"CATISpecObject" );                                      
...

The RetrieveSU method retrieves from the catalog the StartUp whose the name was defined in the "Use the Generic StartUp Factory to Create the New Derived StartUp" step.

4) Create an instance of the newly derived StartUp

...
CATISpecObject *pISpecObjectOnStartup = NULL;
rc = pStartup->QueryInterface( IID_CATISpecObject , ( void**)&pISpecObjectOnStartup );

(*pISpecObjectOnInstance) = pISpecObjectOnStartup->Instanciate( NULL_string ,
                                                                    pIContainer );
...

pISpecObjectOnInstance is the output argument of the method. 

5) Subscribes to repository for Configuration Data Storage

As Mechanical Modeler and CGM algorithms are versioned, feature instances are "software level dependant".
Consequently, feature instances must store the software configuration to choose the right level to use, particularly on build process.[10]
This storage must be initialize just after instantiation thanks to "CreateConfigurationData" method of CATMmrAlgoConfigServices.
 

...
   rc = CATMmrAlgoConfigServices::CreateConfigurationData(*pISpecObjectOnInstance);
   if( FAILED(rc) )
     return rc;
...

pISpecObjectOnInstance is the output argument of the method. 

6) Gets Feature Type Information for BackUp / StartUp management - Only if you use a Geometrical Feature

BackUp / StartUp is a specific mode which occurs when something goes wrong with the CAA feature (when startup catalog and code are not longer available on the runtime view) [11]

If your feature derived from a "geometrical startup" ( GeometricalElement3D or GSMGeom ) ,  you need to define and store its type according to CATIInputDescription implementation. This information, stored on the instance, will be useful in BackUpStartUp Mode to determine which behaviours are authorized.

This operation is done after instantiation, calling CATMmrFeatureAttributes::SetFeatureType 

...
CATIInputDescription* pInputDescriptionOnInstance = NULL;
rc = (*pISpecObjectOnInstance)->QueryInterface( IID_CATIInputDescription, (void**) &pInputDescriptionOnInstance);

...

CATIInputDescription::FeatureType Feature_type = CATIInputDescription::FeatureType_Unset;
rc = pInputDescriptionOnInstance -> GetFeatureType(Feature_type);

...

rc = CATMmrFeatureAttributes::SetFeatureType(*pISpecObjectOnInstance, Feature_type);
...

Note: This step is not to do if your feature is not geometrical or if it is a "Solid feature" i.e. derivate from MechanicalFormFeature, MechanicalContextualFeature.

7) Set default values for the attributes of the new feature instance

By using the interface described in "Creating an Interface of Type" section, you can apply default values for the attributes.

Location of the New Instance

It is recommended that the factory does not aggregate the new instance in a geometrical features set or in a MechanicalSet[9]. 

[Top]


In Short

A new mechanical feature should derive from one of the five available public mechanical StartUps list below:

You can also create a new mechanical feature designed to aggregate features. In this case, you should derived from GSMTool or MechanicalSet startUps, depending on what kind of features you want to aggregate.

The main steps necessary to create the new StartUp are:

[Top]


References

[1] Integrating a New Mechanical Feature in V5
[2] Mechanical Modeler Overview
[3] The Contents of the Specification Container - Geometrical Features
[4] The MecMod Public Specs Reference 
[5] Deriving New StartUps Using a Generic factory
[6] Creating Combined Curve's Catalog
[7] Creating an Interface
[8] The Structure of a Part Document
[9] The Contents of the Specification Container - Geometrical Features Sets
[10] Configuration and Versioning in Mechanical Modeler
[11] Geometrical Backup StartUp - BackUp / StartUp Mode
[12] MechanicalElement StartUp and Feature
[13] MechanicalSet StartUp and Feature
[Top]

History

Version: 1 [Dec 2002] Document created
Version: 2 [Jan 2007] Document updated (Algorithm Services and BackUp/StartUp data)
Version: 3 [Mar 2007] Document updated (New Derivable StartUp - MechanicalElement & MechanicalSet)
[Top]

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