Mechanical Modeler

Creating Combined Curve's Interface of Type

Defining and implementing the interface to retrieve and modify the Combined Curve's specifications.
Use Case
Creating a New Geometrical Feature: the Combined Curve > Creating Combined Curve's Interface of Type

Abstract

This article explains how to create and implement an interface to retrieve and modify the attribute values of the Combined Curve.


What You Will Learn With This Use Case

This use case shows how to define and implement an interface on the Combined Curves. This interface summarizes what is specific to this new feature. Refer to the article entitled "Creating a New StartUp from a Mechanical StartUp" for details [1].

[Top]

The CAAMmrCombinedCurve Use Case

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

[Top]

What Does the CAAMmrCombinedCurve Do

This use case defines and implements a new interface modeling Combined Curves specific attributes. As a matter of fact, you only have to add methods to get and set the input Curves and Direction of Combined Curves. This interface is called CAAIMmrCombinedCurve.

Consequently, CAAIMmrCombinedCurve has four methods:

  1. GetCurve
  2. SetCurve
  3. GetDirection
  4. SetDirection

To implement this new interface, you must define a new extension of the Combined Curve late type. Logically, its class name is CAAEMmrCombinedCurve.

[Top]

How to Launch CAAMmrCombinedCurve

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.

[Top]

Where to Find the CAAMmrCombinedCurve Code

The CAAMmrCombinedCurve use case is made of a several classes located in the CAAMmrCombinedCurve.m module of the CAAMechanicalModeler.edu framework:

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

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

In the PrivateInterfaces of the CAAMechanicalModeler.edu framework there is the CAAIMmrCombinedCurve.h file.

[Top]

Step-by-Step

Combined Curve have their interface of type called CAAIMmrCombinedCurve. This interface deals with specific properties of Combined Curve, that is to get and set its two input curves and its two input directions. This interface is implemented according to the following steps:

[Top]

Defining the Combined Curve Behavior Interface

CAAIMmrCombinedCurve.h declares this new interface (associated with CAAIMmrCombinedCurve.cpp and TIE_CAAIMmrCombinedCurve.tsrc).

Four methods are declared to get/set input curves and to get/set input directions. This is a good compromise between the interface's completeness and shortness.

class ExportedByCAAMmrCombinedCurve CAAIMmrCombinedCurve : public CATBaseUnknown
{
  CATDeclareInterface;
  public:

   virtual HRESULT SetCurve     ( int iNum ,
                                  CATISpecObject *ipCurve )      = 0 ;
   virtual HRESULT GetCurve     ( int iNum ,
                                  CATISpecObject **opCurve )     = 0 ;
   virtual HRESULT SetDirection ( int iNum , 
                                  CATISpecObject *ipDirection )  = 0 ;
   virtual HRESULT GetDirection ( int iNum ,
                                  CATISpecObject **opDirection ) = 0 ;
}

[Top]

Implementing the Combined Curve Behavior Interface

The object chosen to implement Combined Curve Interface extends the "CombinedCurve" late type. The following code extracted from CAAEMmrCombinedCurve.cpp declares that CombinedCurve is extended to implement the Combined Curve Interface.

...
CATImplementClass ( CAAEMmrCombinedCurve,
                    DataExtension,    
                    CATBaseUnknown,
                    CombinedCurve );

// Tie the implementation to its interface
// ---------------------------------------

#include "TIE_CAAIMmrCombinedCurve.h" // needed to tie the implementation to its interface
TIE_CAAIMmrCombinedCurve(CAAEMmrCombinedCurve);
...

Add to your dictionary the line declaring CombinedCurve implements CAAIMmrCombinedCurve interface.

[Top]

Setting a Combined Curve Attribute Value

Here is how to set a Combined Curve's Curve Attribute. You first have to get the key of the attribute associating with the asking curve. This key, piSpecAttrKeyOnInputCurve, will be then useful to valuate the attribute. 

...
HRESULT CAAEMmrCombinedCurve::SetCurve(int iNum, CATISpecObject* ipiSpecOnCurve) 
{
    CATISpecAttrAccess * piSpecAttrAccessOnCC = NULL; 
    HRESULT rc = QueryInterface(IID_CATISpecAttrAccess, (void**) & piSpecAttrAccessOnCC);
    if ( SUCCEEDED(rc) ) 
    { 
       CATISpecAttrKey * piSpecAttrKeyOnInputCurve = NULL;
       if ( 1 == iNum )
       {
          piSpecAttrKeyOnInputCurve = piSpecAttrAccessOnCC->GetAttrKey("Curve1");
       }
       else
       {
          piSpecAttrKeyOnInputCurve = piSpecAttrAccessOnCC->GetAttrKey("Curve2");
       }
 ...

If the input feature is a BRep feature it must be aggregated by the combined curve. A BRep feature must always be aggregated by someone to be delete.  If it is already aggregated, it is an error.

...
   CATISpecObject_var spiSpecOnCurve(ipiSpecOnCurve);

    CATIMfBRep *pIMfBRep = NULL ;
    rc = ipiSpecOnCurve->QueryInterface(IID_CATIMfBRep, (void**) & pIMfBRep);
    if ( SUCCEEDED(rc) )
    {
       CATISpecObject * pFather = ipiSpecOnCurve->GetFather() ;
       if ( NULL == pFather )
       {
          CATIDescendants * pIDescendantsOnCC = NULL ;
          rc = QueryInterface( IID_CATIDescendants , (void**) &pIDescendantsOnCC );
                                                
          if ( SUCCEEDED(rc) )
          {
             pIDescendantsOnCC->Append(spiSpecOnCurve) ;
...

Then, the SetSpecObject method of the CATISpecAttrAccess interface sets the input feature (spiSpecOnCurve) as Combined Curve attribute. The first argument piSpecAttrKeyOnInputCurve, is the key of the attribute retrieved just above.

...
    piSpecAttrAccessOnCC->SetSpecObject(piSpecAttrKeyOnInputCurve,spiSpecOnCurve);
...    

However, if the input parameter, ipiSpecOnCurve, is NULL, the last two steps ( BRep management, and SetSpecObject call) are not done. In particular, the SetSpecObject call will be without effect if the second argument is NULL. 

If piSpecOnCurve is NULL, you have only to do the following code. 

...
    piSpecAttrAccessOnCC->UnsetAttributeValue(piSpecAttrKeyOnInputCurve);
...    

the UnsetAttributeValue saids that the value of the attribute is no more those of the feature, but those of its reference. Since the Combined Curve instance is created from the CombinedCurve StartUp, the new value of the attribute is those of the StartUp attribute. If you read the CAAMmrCreateCombCrvCatalog use case [2], you can see that there is no value for the Combined Curve StartUp, since the attribute is created without valuation. Consequently, in the GetCurve method, the GetSpecObject will return NULL. 

[Top]

Getting a Combined Curve Attribute Value

The GetCurve method works just like the implementation of CAAIMmrCombinedCurve::SetCurve method. The only difference is that it uses the CATISpecAttribute::GetSpecObject method instead of CATISpecAttribute::SetSpecObject.

...
HRESULT CAAEMmrCombinedCurve::GetCurve(int iNum, CATISpecObject** opiSpecOnCurve) 
{
    HRESULT rc = E_FAIL;

    if ( NULL == opiSpecOnCurve )
       return E_FAIL ;

    CATISpecAttrAccess *piSpecAttrAccessOnCC = NULL;
    rc = QueryInterface( IID_CATISpecAttrAccess , (void**) &piSpecAttrAccessOnCC );
    if ( SUCCEEDED(rc) )
    {
       CATISpecAttrKey * piSpecAttrKeyOnInputCurve = NULL;
       if ( 1 == iNum )
       {
          piSpecAttrKeyOnInputCurve = piSpecAttrAccessOnCC->GetAttrKey("Curve1");
       }
       else
       {
          piSpecAttrKeyOnInputCurve = piSpecAttrAccessOnCC->GetAttrKey("Curve2");
       }

       rc = E_FAIL;
       
       if ( NULL != piSpecAttrKeyOnInputCurve )
       {
          *opiSpecOnCurve = piSpecAttrAccessOnCC->GetSpecObject(piSpecAttrKeyOnInputCurve);

          if ( NULL != *opiSpecOnCurve )
          {
              rc = S_OK ;
          } 
...

    return rc ;
}

You can note that if the value of the attribute is NULL or if there is an internal problem to retrieve the key of the attribute, the method returns E_FAIL. The caller will be sure that if the method is successful, it can be sure that the output value is valid. 

[Top]


In Short

This use case explains how to define and implement a new interface enabling to get and retrieve the Combined Curve's attributes.  As a matter of fact, this interface makes it possible to easily query and modify the input curves and directions of a Combined Curve. 

[Top]


References

[1] Creating a New StartUp from a Mechanical StartUp
[2] Creating Combined Curve's Catalog
[Top]

History

Version: 1 [Mar 2000] Document created
Version: 2 [Jan 2003] Document updated
Version: 3 [Dec 2003] Document updated
[Top]

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