Mechanical Modeler

 

Copying Mechanical Features

Using CATMmrInterPartCopy
Use Case

Abstract

This article shows how to copy mechanical features using CATMmrInterPartCopy.


What You Will Learn With This Use Case

This use case explains the usage of the CATMmrInterPartCopy to copy mechanical features. Its presents:

In the What Does CAAMmrInterIntraPartCopy Do section, all the copies done by the code are presented by pictures, and commented. It gives you an overview of the CATMmrInterPartCopy possibilities, and the result of the copies.

[Top]

The CAAMmrInterIntraPartCopy Use Case

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

[Top]

What Does CAAMmrInterIntraPartCopy Do

This use case uses a Product document containing instances of Part documents.

Fig.1 The CAAMmrPartCopy Document

The CAAMmrPartCopy document contains one of the CAAMmrPartCopy_Comp3 Part document, and two instances of the CAAMmrPartCopy_Comp1 Part document.

Fig.2 The CAAMmrPartCopy_Comp1 Document

The CAAMmrPartCopy_Comp1 document only contains geometrical features sets [2].

Fig.3 The CAAMmrPartCopy_Comp3 Document

The CAAMmrPartCopy_Comp3 document contains some points, one pad, and an invisible surface (an extruded sketch which is splitted: the result is not visible because Split.1 is not the current feature. Refer to the article entitled "Order and Absorption Concept [3]). 

These four documents, the two Part documents and the two Product documents are located in the InputData directory of the CAAMechanicalModeler.edu framework.

The batch carries out a series of copies between mechanical features:

Now the result of these copies are presenting according to the different alternatives.

  1. Copies from two documents out of Assembly context.
  2. Copies from two documents In Assembly context.
  3. Copies into the same document.

 

  1. Copies from two documents out of the Assembly context.
  2. It consists to copy mechanical features from CAAMmrPartCopy_Comp3 to CAAMmrPartCopy_Comp1.

    Fig.4  Copies from CAAMmrPartCopy_Comp3 to CAAMmrPartCopy_Comp1 Out of Assembly Context                                    

     Copy As Result With Link 

    Copy As Result 

    These two images show the CAAMmrPartCopy_Comp1 after the copies. The four existing sets of this Part document are surrounded in yellow. 

    First considerations:

    Note that the same icons are now: and

    Other considerations:

  3. Copies from two documents In Assembly context.
  4. It is always the same copies from CAAMmrPartCopy_Comp3 to CAAMmrPartCopy_Comp1, but now in Assembly context.

    Fig.5 Copies from CAAMmrPartCopy_Comp3 to CAAMmrPartCopy_Comp1 In Assembly Context

     Copy As  Result with link

    Copy As Result 

    These two images show the CAAMmrPartCopy document after the copies. The four existing sets of this Part document are surrounded in yellow.  

    First considerations are about the Product's icons.

    The Part origin of the features is the CAAMmrPartCopy_Comp3 document. They are copied in an instance of the CAAMmrPartCopy_Comp1 Part document. (CAAMmrPartCopy_Comp1.1). So sometimes, you can also read Ref/Inst copies.

    Second considerations are about the copies's location.

    You can see on [Fig.5] that two results are coincident: The yellow pad (from CAAMmrPartCopy_Comp1.1) and the grey one (from CAAMmrPartCopy_Comp3) are coincident. On the Product instance links to CAAMmrPartCopy_Comp1.1, a positioning matrix, computed from the matrix of  CAAMmrPartCopy_Comp3 and CAAMmrPartCopy_Comp1.1, is stored.

    Otherwise, about the result of the copies with (on the left), or without link (on the right) it is the same comments as for copies without Assembly context ([Fig.4]).

  5. Copies into the same document
  6. In this last case, copies are done from and to the CAAMmrPartCopy_Comp3 Part document.

    Fig.6 Copies Inside CAAMmrPartCopy_Comp3

    Copy As Result with link

    Copy As Result 

    These two images show the CAAMmrPartCopy_Comp3 Part document after the copies.

    First considerations:

    About the copies themself:

 

How to Launch CAAMmrInterIntraPartCopy

To launch CAAMmrInterIntraPartCopy, you will need to set up the build time environment, then compile CAAMmrInterIntraPartCopy along with its prerequisites, set up the run time environment, and then execute the use case [5]. To launch the use case, execute the following steps:

  1. Copy the following documents in another directory
  2. They are located in the CAAMechanicalModeler.edu/InputData directory

  3. mkrun -c "CAAMmrInterIntraPartCopy InputPath Copy_Option PS_Option "
  4. where
  5. Read the modified documents
  6. The input documents, those of your directory, are modified, and contain the result of the copies.

Some examples:

To copy the mechanical features, out of the Assembly context, and with "As Result with link" option. See the results, Fig.4 and Fig.6, both on the left

To copy the mechanical features, out of the Assembly context, and with "As Result" option. See the results, Fig.4 and Fig.6, both on the right

To copy the mechanical features, in Assembly context, and with "As Result with link" option. See the results, Fig.5, on the left

[Top]

Where to Find the CAAMmrInterIntraPartCopy Code

The CAAMmrInterIntraPartCopy use case is made of a single source file named CAAMmrInterIntraPartCopyMain.cpp located in the CAAMmrInterIntraPartCopy.m module of the CAAMechanicalModeler.edu framework

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

The use case uses two global functions, CAAMmrGetGeometry and CAAMmrGetPartFromProduct, which are defined in the following directory:

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

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

[Top]

Step-by-Step

There are five logical steps in CAAMmrInterIntraPartCopy:

  1. Prolog
  2. Copying out of Assembly Context
  3. Copying in Assembly Context
  4. Saving Documents
  5. Epilog

All the copies shown in the "What Does CAAMmrInterIntraPartCopy Do" section are not there detailed. Only two of them are given to explain the usage of the CATMmrInterPartCopy class.

[Top]

Prolog

CAAMmrInterIntraPartCopy begins by creating a session, and opening the input Product document. Next it retrieves all the Product components begining with its root product,piProductOnRoot. This is the usual sequence for loading a Product document [6].

...
CATListValCATBaseUnknown_var * pListDirectChildren = piProductOnRoot->GetChildren(); 

// Comp1 and Comp2
CATIProduct_var spComp1 = (*pListDirectChildren)[1] ;
CATIProduct_var spComp2 = (*pListDirectChildren)[2] ;

delete pListDirectChildren ;
pListDirectChildren = NULL ;
pListDirectChildren = spComp2->GetChildren(); 

// Comp3
CATIProduct_var spComp3 = (*pListDirectChildren)[1] ;
...

From the two Product documents, spComp1 and spComp3, their MechanicalPart feature is retrieved thanks the CAAMmrGetPartFromProduct global function. Once the Part feature is retrieved, the useful mechanical features are retrieved using the CAAMmrGetGeometry global function. The contents of these two global functions being not essential for the use case, the code is not detailed here; refer to the source files otherwise. 

[Top]

Copying out of Assembly Context

The copy of Point.3 (CAAMmrPartCopy_Comp3) into Ordered Geometrical Set.2 (CAAMmrPartCopy_Comp3) is detailed. The new feature is Point.6. You can see the result on the [Fig.6].  The copy is done with five steps.

  1. Create a CATMmrInterPartCopy class instance.
  2. ...
    CATISpecObject_var SourceToCopy = spOnPoint3OfComp3 ;
    CATISpecObject_var Target = spOnOrderedGeomSet2OfComp3 ;
    CATMmrInterPartCopy * ptCATMmrInterPartCopy = new CATMmrInterPartCopy 
                                                           (SourceToCopy,Target) ;
    ...

    spOnPoint3OfComp3 and spOnOrderedGeomSet2OfComp3 are smart pointers on Point.3 and Ordered Geometrical Set.2, two mechanical features of the CAAMmrPartCopy_Comp3 Part document See [Fig.3]. Refer to the code of the use case, the way to retrieve these two pointers.

  3. Set the copy option thanks the SetLinkMode method.
  4. ...
    ptCATMmrInterPartCopy ->SetLinkMode(CopyWithLink);
    ...

    CopyWithLink is a CATBoolean value. It is valuated according to the Copy_Option argument of the program. See the How to Launch CAAMmrInterIntraPartCopy section. If the argument is 1, the value of CopyWithLink is TRUE, otherwise  its value is FALSE. If you do not use the SetLinkMode method, the option of copy depends on the "Keep link with selected object" option.

    Fig.7 Tools Options
  5. Execute the copy using the Run method.
  6. ...
    ErrorMsg = "" ;
    rc = ptCATMmrInterPartCopy ->Run(&ErrorMsg);
    ...
  7. Retrieve the result thanks to the GetResult method.
  8. ...
    rc = ptCATMmrInterPartCopy ->GetResult(Result);
    if ( SUCCEEDED(rc) && (NULL_var != Result) )
    {
        CATIAlias_var spAlias = Result ;
        if ( NULL_var != spAlias )
        {
           cout <<" The result of the copy is" ;
           cout <<" " << spAlias->GetAlias().CastToCharPtr() << endl << endl;
         }
    ...

    This step is of course optional.

  9. Delete the CATMmrInterPartCopy class instance.
  10. ...
    delete ptCATMmrInterPartCopy ;
    ptCATMmrInterPartCopy = NULL ;

    To copy another mechanical feature you must come back to the first step.

[Top]

Copying in Assembly Context

The copy of Point.1 of CAAMmrPartCopy_Comp3 into the Part feature of CAAMmrPartCopy_Comp1.1 is detailed. The new feature is Point.1. You can the result on the [Fig.4]. These copy is done with six steps.

  1. Create a CATMmrInterPartCopy class instance.
  2. CATISpecObject_var SourceToCopy = spOnPoint1OfComp3 ;
    CATISpecObject_var Target = spSpecObjectOnMechPartOfComp1;
    CATMmrInterPartCopy * ptCATMmrInterPartCopy = new CATMmrInterPartCopy (SourceToCopy,Target) ;
    ...

    spOnPoint1OfComp3 is a smart pointer on Point.1 of the CAAMmrPartCopy_Comp3 document [Fig.3]. spSpecObjectOnMechPartOfComp1 is a smart pointer on the Part feature of the CAAMmrPartCopy_Comp1 document [Fig.2]. Refer to the code of the use case, the way to retrieve these two pointers.

  3. Set the copy option thanks the SetLinkMode method.
  4. ...
    ptCATMmrInterPartCopy ->SetLinkMode(CopyWithLink);
    ...

    CopyWithLink is a CATBoolean value. It is valuated according to the Copy_Option argument of the program. See the How to Launch CAAMmrInterIntraPartCopy section. If the argument is 1, the value of CopyWithLink is TRUE, otherwise  its value is FALSE. If you do not use the SetLinkMode method, the option of copy depends on the "Keep link with selected object" option. See [Fig.7]

  5. Set the Assembly Context
  6. Until then, no difference with the previous copy. But if you use SetSourceInstance, and the SetTargetInstance you are in Assembly context.

    ...
    ptCATMmrInterPartCopy ->SetSourceInstance(spComp3);
    ptCATMmrInterPartCopy ->SetTargetInstance(spComp1);
    ...

    spComp3 and spComp1 are smart pointers on a CATIProduct interface retrieved in the prolog step. spComp3 is a pointer on the CAAMmrPartCopy_Comp3 Product instance, and spComp1 pointer on the CAAMmrPartCopy_Comp1.1 Product instance

    1. Using the CATMmrInterPartCopy constructor with CATISpecObject as argument, it is mandatory to call these two methods to be in Assembly Context.
    2. Do not call only one: the two calls are mandatory.
    3. However, if you use the CATMmrInterPartCopy constructor with CATPathElement as argument, calling the two methods is useless if the paths already contain the Product.

    If you do not specify the product context, so if you do not use these two methods, you are copying features without Assembly context.  So it is the result that you can see on the [Fig.4].

  7. Execute the copy using the Run method.
  8. ...
    ErrorMsg = "" ;
    rc = ptCATMmrInterPartCopy ->Run(&ErrorMsg);
    ...
  9. Retrieve the result thanks to the GetResult method.
  10. ...
    rc = ptCATMmrInterPartCopy ->GetResult(Result);
    ...

    This step is of course facultative.

  11. Delete the CATMmrInterPartCopy class instance.
  12. ...
    delete ptCATMmrInterPartCopy ;
    ptCATMmrInterPartCopy = NULL ;

    To copy another mechanical feature you must come back to the first step.

Saving Documents

The four modified documents: CAAMmrPartCopy_Comp3.CATPart, CAAMmrPartCopy_Comp1.CATPart, CAAMmrPartCopy.CATProduct and CAAMmrProduct2.CATProduct are saved using the SaveAs method of the CATDocumentServices class.

  1. The input documents are rewritten, and are not saved under another name because of contextual links. Let us consider the following schema summing ups the link's information that you retrieve in the Edit/Links command.

    If you first save the Product with another name, the saved document pointes to Comp1.1 which will be after saved under another name

    If you first save Comp1.1 with another name, the saved document pointes to Product1 which will be after saved under another name

  2. Do not use the Save method which does not work in batch mode.

[Top]

Epilog

All the documents are removed from the session using the Remove method of the CATDocumentServices class, and then the session is closed using the global function named Delete_Session.

[Top]


In Short

This use case has shown different kind of copies, and explained the usage of the CATMmrInterPartCopy class.

[Top]


References

[1]
[2] The Contents of the Specification Container - Geometrical Features Sets
[3] Order and Absorption Concepts
[4] The Contents of the Specification Container - Geometrical Features
[5] Building and Launching a CAA V5 Use Case
[6] Browsing a Product Structure
[Top]

History

Version: 1 [Oct 2004] Document created
[Top]

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