Shape Design & Styling

Generative Shape Design

Creating an Open Body

How to create a GSMTool in a Part document
Technical Article

Abstract

This article discusses the Open Body The class CAAGsiUserTools Objec explains how to create an open body feature that is bound to imbed Shape Design Features.

What is an Open Body

An "Open Body" is a mechanical modeler object required as father for any GSD feature to be insert in a part document.

This article is intended to help you make your first steps in programming with CATIA Shape Design [1]. Its main intent is to practically describe the creation of the open body

Before creating this open body, you will have to navigate through the feature model of CATIA V5 to find the objects that will enable you to create this open body (also called a GSMTool object) under the part feature.

[Top]

The CAAGsiUserTools Object - Creating an OpenBody

CAAGsiUserTools is a usefull class in CAAGsiToolkit.m module of the CAAGSMInterfaces.edu framework that illustrates GSMInterfaces framework object standard use.

CAAGsiUserTools is a toolkit object that encapsulate three aspects of CAA development in Wireframe and Shape Design

Two first aspects are general behaviors to re-use to instanciate any GSD features of GSMInterfaces in CATIA V5 frame.

The first aspect is presented in this article

[Top]

What Does CAAGsiUserTools Do

The goal of CAAGsiUserTools Object is to show how to create an open body feature, which is the first common step before creating shape design features in a part document. We enrich the sample code CAAGsiUserTools.cpp(.h) and illustrates some backbone concepts thats are shared by all Mechanical Applications.

CAAGsiUserTools is used in CAAGsiNozzle sample

[Top]Top]

Where to Find the CAAGsiUserTools Code

The CAAGsiUserTools Object is made of a single class named CAAGsiUserTools located in the CAAGsiToolkit.m module of the CAAGSMInterfaces.edu framework:

Windows InstallRootDirectory\CAAGSMInterfaces.edu\CAAGsiToolkit.m\
Unix InstallRootDirectory/CAAGSMInterfaces.edu/CAAGsiToolkit.m/

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

[Top]

Step-by-Step

There are six logical steps illustrated in CAAGsiUserTools for creating an Open Body :

  1. Prolog
  2. Retrieving the Part Container Feature
  3. Retrieving the Current Tool
  4. Locating the Tool Under The Part Feature
  5. Creating a GSMTool Feature Instance
  6. Setting the Created Tool as Current

We will now first comment the Part document creation and intialization in the method CAAGsiUserTools::Init in the prolog, and then each of these steps by looking at the code of the method CAAGsiUserTools::CreateGSMTool.

[Top]

Prolog

We first have created a Part document handled using the _pDoc smart pointer. We have stored the _pFact pointer in the CAAGsiUserTools class in the method Init that has to be called before doing anything with a CAAGsiUserTools object.

HRESULT CAAGsiUserTools::Init(char *& iSessionName) 
{
  HRESULT rc = S_OK;
  ...  // Create the CATPart document
  CATInit_var spInit = _pDoc;
  spInit->Init(TRUE);

  CATIPrtContainer * piPartContainer = (CATIPrtContainer*) spInit->GetRootContainer("CATIPrtContainer");
  ... // Process piPartContainer == NULLL
  rc = piPartContainer -> QueryInterface(IID_CATIGSMFactory, (void**)&_pFact);
  ... // Process rc == E_xxx
}    

Once the Part document is created, it must be initialized thanks to the Init method of the CATInit interface. This method creates the document's root container. Then, the root container is retrieved as a pointer to the CATIPrtContainer interface using the GetRootContainer method of the the CATInit interface. This root container implements also the CATIGSMFactory interface. A pointer to CATIGSMFactory is retrieved from on root container and stored as a data member to be used later.

[Top]

Retrieving the Part Container Feature

We need a CATIPrtPart interface pointer onto the Part Container feature to be able to get the current Tool Feature.

CATIGSMTool_var CAAGsiUserTools::CreateGSMTool(const CATUnicodeString &iName,
                                               int                    iSetAsCurrent,
                                               int                    iTopLevel)
{
  CATIContainer_var    spCont     = _pFact;
  CATIPrtContainer_var spPartCont = spCont;
  CATIPrtPart_var      spPart     = spPartCont -> GetPart();
...

We first get a smart pointer to CATIPrtContainer from the stored pointer _pFact, then we get the Part root feature from the Part container as a smart pointer to the CATIPrtPart interface.

[Top]

Retrieving the Current Tool

Now that we have retrieved the Part feature, we can retrieve the current tool, that can be a MechanicalTool or a GSMTool.

A GSMTool can be created only under another GSMTool or directly under the part root feature, but not under a MechanicalTool.

  ...
  CATIGSMTool_var spTool = NULL_var;
  if ( NULL_var != spPart )
  {
    CATIBasicTool_var spCurrentTool = spPart->GetCurrentTool();
    ...

The CATIPrtPart interface enables us to retrieve the current tool (One always exists.) Then, we try to get a CATIGSMTool smart pointer from the spCurrentTool CATIBasicTool smart pointer.

At this stage, we have to check that the tool retrieved is not the open body dedicated to store external references (Multi-model links) If it is the case, we set spTool to NULL_var which means that we need to create another GSMTool feature for our need.

[Top]

Locating the Tool Under the Part Feature

We show here how to get the position of a feature in the descendants' list of the part feature, using the CATIDescendants interface.

    ...
    int Position = 0;
    CATISpecObject_var spCurrentFeat = spPart->GetCurrentFeature();
    CATISpecObject_var spParentForGSMTool = spPart; 

    if (spCurrentFeat != spCurrentTool && 0 == iTopLevel)	
    {
      spParentForGSMTool  = spCurrentTool;
      CATISpecObject_var spExternalRef = spPart->GetBodyForExternalReferences();
      if (NULL_var != spExternalRef && spCurrentTool == spExternalRef)
      {
        spParentForGSMTool = spPart;
      }
      else 
      {
        CATIDescendants_var spRoot = spCurrentTool;
        Position = spRoot -> GetPosition( spCurrentFeat);
      }
    }
    ...

We use a again the CATIPrtPart interface to get the current feature. This feature can be a Tool or a mechanical feature. A GSMTool has to be created with a parent, and the parent candidate must be the part itself or another GSMTool.

spParentForGSMTool is initialized to the part feature and the retrieved Position is 0.

In case of a current feature that is different from the current tool and if iTopLevel equals 0, then we will compute the position of the current tool in order to create the new one just after the current feature in the procedural view and under the current tool. In order to get the position of the current feature with respect to the current tool, we use the CATIDescendants implementation of the current tool spRoot.

Note: In retrieving the require tool it is needed to check that the body is not a body used for "ExternalReferences" generated in assembly context when selecting geometry in a different part as of the current one.

[Top]

Creating a GSMTool Feature Instance

We can now create a new GSMTool feature instance by giving its name, parent reference and position under its parent.

...
    if (NULL_var != spParentForGSMTool)
    {
      CATIMechanicalRootFactory_var spMechRoot = spCont;
      spTool = spMechRoot -> CreateGSMTool(iName,spParentForGSMTool,Position);
    }
...

We get the CATIMechanicalRootFactory interface from the spCont smart pointer. The GSMTool is created by giving the smart pointer of its parent, that is, either the part feature or a GSMTol instance, and the position of the new tool under its parent. 0 will create the Tool directly under spParentForGSMTool.

[Top]

Setting the Created Tool as Current

Now that we have created this new tool, we have to set it as the current tool, if we want to automatically create skin and wireframe features under this open body.

...
    if (NULL_var != spTool && 0 != iSetAsCurrent)
    {
      CATIPrtManagement_var spPartManage = spPart;
      if (NULL_var != spPartManage)
        spPartManage->SetCurrentFeature(spTool);
    }
  }
  return spTool;

We check that we want to set the spTool smart pointer as the current tool by testing iSetAsCurrent. To set a tool as current we have to retrieve the CATIPrtManagement interface on the part feature, and call the SetCurrentFeature method with spTool as argument.

[Top]


In Short

This article has demonstrated the way to create an open body in a part document. We illustrate how some management interfaces on the part feature can be used like CATIPrtPart, CATIPrtManagement, CATIMechanicalRootFactory. We also illustrate the way to get the feature position in the descendant list of its parent using CATIDescendants.

[Top]


References

[1] About Generative Shape Design Features
[2] Building and Launching a CAA V5 Use Case
[3] CAAGsiNozzle Use case
[Top]

History

Version: 1 [Apr 2000] Document created
Version: 2 [June 2003] Document set as a technical article
[Top]

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