Product Synthesis & Knowledgeware

Space Analysis

Compute the Inertia Data of Products

From document to computation
Use Case

Abstract

This paper discusses the CAASpaComputeInertia use case. This use case explains how to open a CATProduct document and explore its content from an inertia analysis perspective.


What You Will Learn With This Use Case

This use case is intended to help you make your first steps in programming the CATIA analysis tools. Its main intent is to introduce the analysis API, and a way to use it.

The scenario is based on an industrial need : users want to export the mass of each sub-assemblies from a product. To perform the user will use a batch utility to compute the masses and to output them.

The target of this use case is to learn how to build such utility.

This picture represents a CATProduct document containing some products.

[Top]

The CAASpaComputeInertia Use Case

CAASpaComputeInertia is a use case of the CAASPAInterfaces.edu framework that illustrates SpaceAnalysisInterfaces framework capabilities.

[Top]

What Does CAASpaComputeInertia Do

The goal of CAASpaComputeInertia is to open a CATProduct document, navigate on products to compute the inertia data and print them. Namely, it:

[Top]

How to Launch CAASpaComputeInertia

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

Launch the use case as follows:

where:

inputDirectory The directory in which inputFile.CATProduct is located
inputFile.CATProduct The file that contains the use case CATProduct document

[Top]

Where to Find the CAASpaComputeInertia Code

The CAASpaComputeInertia use case is made of a single class named CAASpaComputeInertia whose header and source files are located in the CAASpaComputeInertia.m module of the CAASPAInterfaces.edu framework:

Windows InstallRootDirectory\CAASPAInterfaces.edu\CAASpaComputeInertia.m\
Unix InstallRootDirectory/CAASPAInterfaces.edu/CAASpaComputeInertia.m/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed. The CAASpaComputeInertia class derives from CATInteractiveApplication. The described code is located in the BeginApplication method.

[Top]

Step-by-Step

There are four main steps in CAASpaComputeInertia:

  1. Prolog
  2. Searching the Products
  3. Computing and Printing the Inertia Data
  4. Epilog

We will now comment each of those sections by looking at the code.

[Top]

Prolog

The use case is the CAASpaComputeInertia class that derives from CATInteractiveApplication and that is simply instantiated. It runs in one shot and the described code is located in the BeginApplication method. It begins by creating a session, and by opening the use case CATProduct document passed as an argument: pDocument refers to it. This is the usual sequence for creating a CATIA document [2].

[Top]

Searching the Products

...
  //==========================================================================================
  // 3 - Search the products
  //==========================================================================================
  CATIProduct* piProduct = NULL;
  CATIDocRoots* piDocRootsOnDocument = NULL;
  HR = pDocument->QueryInterface(IID_CATIDocRoots,(void**)&piDocRootsOnDocument);
  if (SUCCEEDED(HR) && NULL != piDocRootsOnDocument)
  {
    // Search the root product
    CATIProduct* piRootProduct = NULL;
    CATListValCATBaseUnknown_var* pRootList = piDocRootsOnDocument->GiveDocRoots();
    int nRoots = pRootList->Size();
    for (int i = 1; i <= nRoots && NULL == piRootProduct; i++)
    {
      HR = (*pRootList)[i]->QueryInterface(IID_CATIProduct,(void**)&piRootProduct);
    }
    // Search all children of the root product
    if (NULL != piRootProduct)
    {
      CATListValCATBaseUnknown_var* pProductList = piRootProduct->GetChildren("CATIProduct");
      int nProducts = pProductList->Size();
      for (int j = 1; j <= nProducts; j++)
      {
        HR = (*pProductList)[j]->QueryInterface(IID_CATIProduct,(void**)&piProduct);
        if (SUCCEEDED(HR))
        {
...

The first step is to find all the roots of the document using CATIDocRootsCATSession::GiveDocRoots method.

The root product is the one of the roots which mates the interface CATIProduct.

The CATIProduct::GetChildren method gives a list of all the chidren of any product.

Then the use case loops on all these children.

[Top]

Computing and Printing the Inertia Data

...
          //================================================================================
          // 4 - Print the inertia data
          //================================================================================
          CATIInertia* piInertiaOnProduct = NULL;
          HR = piProduct->QueryInterface(IID_CATIInertia,(void**)&piInertiaOnProduct);
          if (SUCCEEDED(HR))
          {
            double density = 0.;
            double mass = -1.;
            double position[3];
            double matrix[9];
            double components[9];
            double values[3];
            HR = piInertiaOnProduct->GetInertia (&density,&mass, position, matrix, components, values);
            if (SUCCEEDED(HR))
            {
              CATIAlias* piAliasOnProduct = NULL;
              HR = piProduct->QueryInterface(IID_CATIAlias,(void**)&piAliasOnProduct);
              if (SUCCEEDED(HR))
              {
                cout << "Product " << piAliasOnProduct->GetAlias().ConvertToChar() << " : mass = " << mass;   
                piAliasOnProduct->Release();
                piAliasOnProduct = NULL;
                if (density <= 0.)
                {
                  cout <<" with non homogeneous density" <<endl;
                }
                else
                {
                  cout << " with density = " << density <<endl;
                }
              }  
            }
            // Release the reference to the inertia
            piInertiaOnProduct->Release(); 
            piInertiaOnProduct = NULL;
          }
          // Release the reference to the product  
          piProduct->Release();
          piProduct = NULL;
        } 
      }
      // Clean the product list
      delete pProductList;
      pProductList = NULL;
      // Release the reference to the root product
      piRootProduct->Release();
      piRootProduct = NULL;
    }
    // Clean the root list
    delete pRootList;
    pRootList = NULL;
    // Release the reference to the doc roots
    piDocRootsOnDocument->Release();
    piDocRootsOnDocument = NULL;
  }
...

For each product the CATIInertia interface is queried, then the CATIInertia::GetInertia method computes all inertia data.

The CATIAlias interface is used to retrieve the name of the product and to print it in front of the corresponding mass.

The next step consist in cleaning the environment and releasing all resources.

The technique is fairly simple : all references to interfaces have to be released using CATBaseUnknown::Release() and then the list is deleted. All pointer are nullified.

[Top]

Epilog

The document is closed using its LifeCycleObject interface and more specifically the removemethod. The environment is cleaned, and the session is deleted by the Delete_Session global function, which is passed the same identifier that was used to open it. This is the usual sequence for closing a document, and for deleting the session [2].

[Top]


In Short

This use case has demonstrated the way to programmatically navigate a CATProduct document and computes the inertia data of its' products.

More specifically, you have learn how to access:

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[2] Creating a New Document
[Top]

History

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

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