Mechanical Modeler

Instantiating Combined Curves

How to create an instance and store it in a geometrical features set?
Use Case

Abstract

This use case explains how to create a Combined Curve instance, and how to insert it into a geometrical features set [1].


What You Will Learn With This Use Case

The CAACombinedCurveInstantiation use case explains:

[Top]

The CAACombinedCurveInstantiation Use Case

CAACombinedCurveInstantiation is a use case of the CAAMechanicalModeler.edu framework that illustrates MechanicalModeler framework capabilities

[Top]

What Does CAACombinedCurveInstantiation Do

The use case shows how to create, and insert a Combined Curve instance into a geometrical features set.

The yellow Combined Curve is into Geometrical Set.1, the green Combined Curve is into Ordered Geometrical Set.2, and the purple Combined Curve is into Body.1. The thee possible cases for a geometrical features set.

The use case has been updated in V5R13, and V5R14 enabling you to select the type of the aggregating features. Thanks an environment variable you can aggregate the newly created feature:

[Top]

How to Launch CAACombinedCurveInstantiation

See the section entitled "How to Launch the Combined Curve Use Case" in the "Creating a New Geometrical Feature: The Combined Curve" use case for a detailed description of how this use case should be launched.

There are three kinds of scenario to consider. Each one enable you to choose the way to aggregate the new instances:

  1. You impose the Geometrical Set
  2. You only accept the surfacic sets, and you prohibit Body features
  3. You accept any kind of geometrical features set

Here the scenario are described in detail.

  1. You impose the Geometrical Set
  2. First, check that CAAMmrCombCrvNoHybridBody and CAAMmrCombCrvOGS , two environment variables are not set.

    Launch CATIA, when the application is ready, follow the scenario described below:

    The new combined curve can only be inserted into a Geometrical Set.

  3. You only accept surfacic sets, and you prohibit Body features
  4. First, check that CAAMmrCombCrvOGS is not set, and export the CAAMmrCombCrvNoHybridBody environment variable such as

    Launch CATIA, when the application is ready, follow the scenario described below:

    The new combined curve cannot be inserted into a Body feature.

  5. You accept any kind of geometrical features set
  6. First, export the CAAMmrCombCrvOGS environment variable such as

    Launch CATIA, when the application is ready, follow the scenario described below:

(*) The file is located in the directory CAAMechanicalModeler.edu/InputData

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

(**) To launch the command, there are three ways:

  1. In the Tools menu click Customize
  2. In the View menu click CommandList and select Combined Curve in the list
  3. Enter c:Combined Curve into the power input

[Top]

Where to Find the CAACombinedCurveInstantiation Code

The CAACombinedCurveInstantiation use case is made one class, CAAMmrCombCrvPanelStCmd, located in the CAAMmrCombinedCurveUI.m module of the CAAMechanicalModeler.edu framework:

Windows InstallRootDirectory\CAAMechanicalModeler.edu\CAAMmrCombinedCurveUI.m\
Unix InstallRootDirectory/CAAMechanicalModeler.edu/CAAMmrCombinedCurveUI.m/

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

The use case is an extract of the CAAMmrCombCrvPanelStCmd class which is a state command. Refer to the referenced article [5] for complete detail about this command.

[Top]

Step-by-Step

The CAACombinedCurveInstantiation use case is divided into five steps. The first three steps are grouped together into the CreateCombinedCurve method of the CAAMmrCombCrvPanelStCmd class (state command). The last two are done once all the Combined Curve inputs are valuated, so at the end of the command, in its OkAction method.

  1. Looking for a Geometrical Features Set
  2. Creating the Combined Curve
  3. Aggregating the new Combined Curve into the Set
  4. Updating the Feature
  5. Ending the aggregation

[Top]

Looking for a Geometrical Feature Set

It is the first part of the CreateCombinedCurve method of the CAAMmrCombCrvPanelStCmd command. The goal of this method is to retrieve, or create if necessary, a geometrical features set which will aggregate the new instance. 

...     
    CATIGSMTool * piGSMTool = NULL ;

    char * pCombCrvOGS = NULL ;
    CATLibStatus result = ::CATGetEnvValue("CAAMmrCombCrvOGS",&pCombCrvOGS);  
    if ( (CATLibError == result) || ( NULL == pCombCrvOGS) )
    {
        char * pCombCrvNoHybridBody = NULL ;
        result = ::CATGetEnvValue("CAAMmrCombCrvNoHybridBody",&pCombCrvNoHybridBody); 
        if ( (CATLibError == result) || ( NULL == pCombCrvNoHybridBody) )
        {
           rc = LookingForGeomSet(&piGSMTool);
        }else
        {
           rc = LookingForGeomSetOrOrderedGeomSet(&piGSMTool);   
        }
    }else
    {
       rc = LookingForAnyTypeOfBody(&piGSMTool);       
    }

The environment variables enable you to choose between three modes:

In the three cases, the geometrical feature set which will aggregate the new instance is a feature implementing the CATIGSMTool interface [1].

The LookingForGeomSet Method

The goal of this method is to retrieve or create a Geometrical Set.

 HRESULT CAAMmrCombCrvPanelStCmd::LookingForGeomSet(CATIGSMTool ** piGsmtool)
{
...
    CATIPrtPart * pIPrtPart = NULL ;
    CATPathElement PathAct = _editor->GetUIActiveObject();
    rc = PathAct.Search(IID_CATIPrtPart,(void**)&pIPrtPart) ;

    if ( SUCCEEDED(rc) && ( NULL!=pIPrtPart) )
    {
       CATBoolean ToolToCreate = TRUE ;

       CATIBasicTool_var CurrentTool ;
       CurrentTool = pIPrtPart->GetCurrentTool() ;

       if ( NULL_var != CurrentTool )
       {        
          CATIMmiNonOrderedGeometricalSet * pIGSOnCurrentTool = NULL ;
          rc = CurrentTool->QueryInterface(IID_CATIMmiNonOrderedGeometricalSet, 
                                            (void**) &pIGSOnCurrentTool);
          if ( SUCCEEDED(rc) )
          {
             ToolToCreate = FALSE ;
             ...
...
       if ( TRUE == ToolToCreate )
       {
          rc = CreateTool(pIPrtPart,piGsmtool);
...

The first part consists in to retrieve the Part feature of the current document thanks to the Search method of the CATPathElement class. This object is into the UI active object path, and implements the CATIPrtPart interface [6]. The Part feature knows the current set, you retrieve it thanks to the GetCurrentTool of the CATIBasicTool interface. There is only one case where it is not necessary to create a new Geometrical Set: the current set is already a Geometrical Set. There are two means to check that the current set is a Geometrical Set:

  1. Check that the current set implements the CATIMmiNonOrderedGeometricalSet interface (the methodology currently used)

  2. Check that the current set implements CATIGSMTool, and that its GetType method returns 0 (the methodology used in V5R13)

The CreateTool method creates a new Geometrical Set.

The LookingForGeomSetOrOrderedGeomSet Method

The goal of this method is to retrieve a surfacic set (ordered or not), or to create a Geometrical Set. 

HRESULT CAAMmrCombCrvPanelStCmd::LookingForGeomSetOrOrderedGeomSet
                                                      (CATIGSMTool ** piGsmtool)
{
...

   CATIPrtPart * pIPrtPart = NULL ;
   CATPathElement PathAct = _editor->GetUIActiveObject();
    
   rc = PathAct.Search(IID_CATIPrtPart,(void**)&pIPrtPart)  ;

   if ( SUCCEEDED(rc) && ( NULL!=pIPrtPart) )
   {
       CATBoolean ToolToCreate = TRUE ;  

       CATIBasicTool_var CurrentTool ;
       CurrentTool = pIPrtPart->GetCurrentTool() ;

       CATIMmiGeometricalSet * pIGSMToolOnCurrentTool = NULL ;
       rc = CurrentTool->QueryInterface(IID_CATIMmiGeometricalSet, 
                                           (void**) &pIGSMToolOnCurrentTool);
       if ( SUCCEEDED(rc) )
       {             
          ToolToCreate = FALSE ;
          ...
       if ( (TRUE == ToolToCreate) )
       {
          rc = CreateTool(pIPrtPart,piGsmtool);
       }
...

The first part consists in to retrieve the Part feature of the current document thanks to the Search method of the CATPathElement class. This object is into the UI active object path, and implements the CATIPrtPart interface [6]. The Part feature knows the current set, you retrieve it thanks to the GetCurrentTool of the CATIBasicTool interface. The CreateTool method is invoked only if the current set is a Body feature, it means that the current set does not implement the CATIMmiGeometricalSet interface. 

The LookingForAnyKindOfBody Method

The goal of this method is to retrieve a set implementing the CATIGSMTool interface, or to create a Geometrical Set. From the V5R14, all the new geometrical features sets implement CATIGSMTool. The only one case where a set can do not implement this interface, is the case of the solid set, in other words a feature instantiated from the MechanicalTool StartUp. It is possible only into a Part document created before the V5R14.

HRESULT CAAMmrCombCrvPanelStCmd::LookingForGeomSetOrOrderedGeomSet
                               (CATIGSMTool ** piGsmtool)
{
...
   CATIPrtPart * pIPrtPart = NULL ;
   CATPathElement PathAct = _editor->GetUIActiveObject();
    
   rc = PathAct.Search(IID_CATIPrtPart,(void**)&pIPrtPart)  ;

   if ( SUCCEEDED(rc) && ( NULL!=pIPrtPart) )
   {
       CATBoolean ToolToCreate = TRUE ;  

       CATIBasicTool_var CurrentTool ;
       CurrentTool = pIPrtPart->GetCurrentTool() ;

       if ( NULL_var != CurrentTool )
       {         
          CATIGSMTool * pIGSMToolOnCurrentTool = NULL ;
          rc = CurrentTool->QueryInterface(IID_CATIGSMTool, 
                                      (void**) &pIGSMToolOnCurrentTool);
          if ( SUCCEEDED(rc) )
          {            
              ToolToCreate = FALSE ;
...
       if ( TRUE == ToolToCreate )
       {
          rc = CreateTool(pIPrtPart,piGsmtool);
       }
...

The first part consists in to retrieve the Part feature of the current document thanks to the Search method of the CATPathElement class. This object is into the UI active object path, and implements the CATIPrtPart interface [6]. The Part feature knows the current set, you retrieve it thanks to the GetCurrentTool of the CATIBasicTool interface. The CreateTool method is invoked only if the current set is a solid body, it means that the current set does not implement CATIGSMTool

The CreateTool Method

HRESULT CAAMmrCombCrvPanelStCmd::CreateTool(CATIPrtPart * pIPrtPart, 
                                                       CATIGSMTool ** pIGsmTool)
{
...
    CATISpecObject * pISpecOnPart = NULL ;
    rc = pIPrtPart->QueryInterface(IID_CATISpecObject,(void**) &pISpecOnPart) ;
    if ( SUCCEEDED(rc) )
    {
       CATIContainer_var spContainer = pISpecOnPart->GetFeatContainer();  
       if ( NULL_var != spContainer )
       {
          CATIMechanicalRootFactory * pMechanicalRootFactory = NULL;
          rc = spContainer->QueryInterface( IID_CATIMechanicalRootFactory , 
                                           ( void**)& pMechanicalRootFactory );
          if ( SUCCEEDED(rc) )
          {
              CATISpecObject_var spiSpecOnGSMTool ;
              rc = pMechanicalRootFactory->CreateGeometricalSet("" ,
                                                                pIPrtPart,
                                                                spiSpecOnGSMTool);
...
}

The method to create a Geometrical Set is the CreateGeometricalSet method of the CATIMechanicalRootFactory interface. This interface is implemented on the container of specifications, CATPrtCont [7]. You retrieve it thanks the GetFeatContainer method of the CATISpecObject interface implemented on any mechanical feature of the Part document. The Part feature being useful for the set creation, this feature has been used to retrieve CATPrtCont

The argument of the CreateGeometricalSet method re:

It means that the spiSpecOnGSMTool will be inserted at the end of the Part feature. 

[Top]

Creating the Combined Curve

The CAAIMmrCombCrvFactory interface enables us to create an instance of the Combined Curve StartUp. 

...
          CATISpecObject_var piSpecObjOnTool = piGSMTool ;
          CATIContainer_var spContainer = piSpecObjOnTool->GetFeatContainer();  

          if ( NULL_var != spContainer )
          {
             CAAIMmrCombCrvFactory *piCombinedCurveFactory = NULL;
             rc = spContainer->QueryInterface( IID_CAAIMmrCombCrvFactory , 
                                                    (void**)& piCombinedCurveFactory );
... 
                rc = piCombinedCurveFactory -> CreateCombinedCurve ( _piSpecOnCurve1       ,
                                                               _piSpecOnDir1         ,
                                                               _piSpecOnCurve2       ,
                                                               _piSpecOnDir2         ,
...

piGSMTool is a CATIGSMTool interface pointer on the geometrical features set, retrieved or created by one of the methods described just above. See the Looking for a Geometrical Features Set section.

piSpecObjOnTool is a CATISpecObject interface pointer on this set. Since, the set is a Mechanical feature, it is included within the CATPrtCont container [7]. So the GetFeatContainer method retrieves the CATPrtCont feature which implements the CAAIMmrCombCrvFactory interface.

The argument of the CreateCombinedCurve method are data members of the CAAMmrCombCrvPanelStCmd state command. They are the four inputs of the Combined Curve to create.

[Top]

Aggregating the new Combined Curve into the Set 

The new Combined curve is aggregated into a geometrical features set thanks to the CATIDescendants interface. But depending on the type of the set, the position of the new instance can be different. 

...
         CATIDescendants * pIDescendantsOnGSMTool = NULL ;
         rc = piGSMTool->QueryInterface(IID_CATIDescendants, 
                                          (void**) & pIDescendantsOnGSMTool);
         
         if ( SUCCEEDED(rc) )
         {
            int IsAnOrderedBody= -1 ;
            piGSMTool->GetType(IsAnOrderedBody);

            if ( 1 == IsAnOrderedBody)
            { see Aggregation into Ordered Set} 
            }else
            { see Aggregation into Non Ordered Set } 

Before the aggregation check the type of the set using the CATIGSMTool interface and its GetType method. 1 it is an ordered set, 0 otherwise. pIDescendantsOnGSMTool is a CATIDescendants interface pointer on the set (piGSMTool) retrieved or created in the Looking for a Geometrical Features Set section. pIDescendantsOnGSMTool is used in the Aggregation into Ordered Set and Aggregation into Non Ordered Set sections.

Aggregation into Ordered Set

When the set is ordered, the location of the new feature depends on the current feature. The current feature is:

...
               int pos = 0 ;
               CATISpecObject_var CurrentElt = GetCurrentFeature() ;
               if ( NULL_var != CurrentElt)
               {
                   pos = pIDescendantsOnGSMTool->GetPosition(CurrentElt);                   
               }
               if ( 0 == pos )
               {
                  // the CC is appended at the end
                  pIDescendantsOnGSMTool->Append(piSpecOnCombinedCurve);
               }else
               {
                  // the current feature is inside the body 
                  // the CC is appended just below it (which can be at the end)
                  pIDescendantsOnGSMTool->AddChild(piSpecOnCombinedCurve,pos+1);
               }
 ...

The current feature is known by the Part feature and its CATIPrtPart interface. But since the CAAMmrCombCrvPanelStCmd derives from the CATMMUIStateCommand class, the GetCurrentFeature of this class has been used. 

GetPosition, a method  of the CATIDescendants interface, applied to the set, enables us to know the position of the current feature inside the set. If the method returns 0, the current feature is not into the list of components of the set. 

piSpecOnCombinedCurve, is a CATISpecObject interface pointer on the new instance, see the Creating the Combined Curve section. It is inserted after the current feature thanks to the AddChild method, or at the end of the current set thanks to the Append method, two methods of the CATIDescendants interface. 

Aggregation into Non Ordered Set

When the set is not ordered, piSpecOnCombinedCurve is always appended at the end of the set.

...
    pIDescendantsOnGSMTool->Append(piSpecOnCombinedCurve);
...

 pIDescendantsOnGSMTool is a CATIDescendants interface pointer on the set (piGSMTool) retrieved or created in the Looking for a Geometrical Features Set section, and piSpecOnCombinedCurve, a CATISpecObject interface pointer on the new instance, created in the Creating the Combined Curve section.

[Top]

Updating the Feature

Once the feature is created and aggregated into a set, you must update it. In an interactive command, you can use the CATPrtUpdateCom class to benefit of error management. 

CATPrtUpdateCom *pUpdateCommand =  new CATPrtUpdateCom ( piSpecOnCombinedCurve ,  
                                                        1                    ,  
                                                        GetMode()            ); 

piSpecOnCombinedCurve is a CATISpecObject  interface pointer on the created or modified feature. The second argument, 1, enables us to follow the automatic/manual update of the Part Infrastructure settings. The last argument specifies the mode of the command, creation or edition. GetMode is a method of the state command.

[Top]

Ending the Aggregation 

Finally, once the feature is created, aggregated into a set, and updated, if the set is ordered, you must call the Insert method of the CATMmrLinearBodyServices class. 

       CATBoolean IsInsideOrderedBody= FALSE ;
       rc = IsCombCrvInsideOrderedBody(IsInsideOrderedBody);
       if ( SUCCEEDED(rc) && (TRUE == IsInsideOrderedBody) )
       {
 
          CATBaseUnknown_var spBUOnCC = piSpecOnCombinedCurve ;
          rc = CATMmrLinearBodyServices::Insert(spBUOnCC);

The IsCombCrvInsideOrderedBody method is a method of the CAAMmrCombCrvPanelStCmd class which is detailed in the Editing Combined Curves use case [5]. 

[Top]


In Short

This use case has explained the methodology to insert a new feature in a geometrical features set:

  1. Aggregate the new feature thanks to CATIDescendants 
  2. Update the new feature thanks to CATPrtUpdateCom
  3. Call the Insert method of the CATMmrLinearBodyServices class if the set is ordered

[Top]


References

[1] The Contents of the Specification Container- Geometrical Features Sets  
[2] Creating Combined Curve's Factory Interface
[3] The Contents of the Specification Container - Geometrical Features
[4] Order and Absorption Concepts
[5] Editing Combined Curves
[6] The Contents of the Specification Container- The Part Feature 
[7] The Structure of a Part Document
[Top]

History

Version: 1 [Nov 2003] Document created
[Top]

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