Mechanical Modeler |
Part Design |
Implementing the Cut/Copy/Paste Behavior for Mechanical Design FeaturesImplementing Mechanical Modeler interfaces |
Use Case |
AbstractThis article discusses the CAAPriCutCopyPaste use case. This use case explains, with the CAAPriUserPad simplified pad as example, how to implement the interfaces CATIMechanicalCCP and CATIShapeFeatureProperties. to enable a mechanical design feature for the cut, copy and paste capabilities. |
This use case is intended to help you use the Cut/Copy/Paste and understand how to implement it on the simplified pad feature.
[Top]
The CAAPriCutCopyPaste is a use case of the CAAPartInterfaces.edu framework that illustrates PartInterfaces framework capabilities.
[Top]
The goal of CAAPriCutCopyPaste is to show how to implement the CATIMechanicalCCP and CATIShapeFeatureProperties interfaces onto a given form feature [1], namely the simplified pad. The simplified pad exists as a Start Up in the CAAPriFormFeature.CATfct catalog and has the type CAAPriUserPad [2]. The two interfaces are implemented in the following classes:
The CAAPriCutCopyPasteMain.m module contains a main program that creates a
Part document, instantiates the CAAPriUserPad StartUp with a first
sketch, calls its Build
method and saves the resulting Part
Document. In a second step, a second sketch is created, and a Copy/Paste
operation is performed from the simplified pad onto this sketch. The resulting
Part is saved in a second Part document. Fig.1 shows the pad
to copy in the first Part document. Fig.2 shows the pad to
copy and the copied pad saved in the second Part document.
![]() |
![]() |
[Top]
To launch CAAPriCutCopyPaste, you will need to set up the build time environment, then compile CAAPriCutCopyPaste along with its prerequisites, set up the run time environment, and then execute the use case [3].
Launch the use case as follows:
e:>CAAPriCutCopyPasteMain outputDirectory\CAAUserPadCCP1.CATPart outputDirectory\CAAUserPadCCP2.CATPart |
$ CAAPriCutCopyPasteMain outputDirectory/CAAUserPadCCP1.CATPart outputDirectory/CAAUserPadCCP2.CATPart |
where:
outputDirectory |
The directory into which CAAUserPadCCP1.CATPart and CAAUserPadCCP2.CATPart
will be stored |
CAAUserPadCCP1.CATPart
| The file that contains the pad created |
CAAUserPadCCP2.CATPart |
The file that contains the two pads after Copy/paste operation |
[Top]
The CAAPriCutCopyPaste use case is made of two modules named CAAPriCutCopyPast.m and CAAPriCutCopyPasteMain.m module of the CAAPartInterfaces.edu framework:
Windows |
InstallRootDirectory\CAAPartInterfaces.edu\CAAPriCutCopyPaste.m\ InstallRootDirectory\CAAPartInterfaces.edu\CAAPriCutCopyPasteMain.m\ |
Unix |
InstallRootDirectory/CAAPartInterfaces.edu/CAAPriCutCopyPaste.m/ InstallRootDirectory/CAAPartInterfaces.edu/CAAPriCutCopyPasteMain.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed. These modules contain:
CAAPriCutCopyPaste.m | The two classes CAAPriEMechanicalCCP and CAAPriECCPProp that implements the CATIMechanicalCCP and CATIShapeFeatureProperties interfaces respectively as CAAPriUserPad feature extensions |
CAAPriCutCopyPasteMain.m | The main program that performs the copy/paste operation |
[Top]
CATIMechanicalCCP is implemented using a class named CAAPriEMechanicalCPP that is a data extension of the late type CAAPriUserPad. There are six methods to implement:
We will now comment each of these methods.
[Top]
GiveMeYourFavoriteSpecifications
is a method that returns the
list of the features that are required to build the simplified pad. That is the
sketch the pad is built on.
... CATLISTV(CATISpecObject_var) CAAPriEMechanicalCCP::GiveMeYourFavoriteSpecifications() const { // Retrieves the Profile attribute of the UserPad feature. // CATLISTV(CATISpecObject_var) listSpec; CATISpecObject *piUserPad = NULL; HRESULT rc = ((CATBaseUnknown*)this)->QueryInterface( IID_CATISpecObject , ( void** ) &piUserPad ); if( FAILED(rc) ) return listSpec; CATISpecAttribute *piProfileAtt = piUserPad->GetAttribute("Profile"); if(NULL != piProfileAtt) { CATISpecObject_var spProfile = piProfileAtt->GetSpecObject(1); piProfileAtt->Release(); if(NULL_var != spProfile) { spProfile->Release(); // To decrement the reference count // Retrieves the sketch associated with the profile // The sketch is added in the returned list // CATIPrtProfile_var spPrtProfileOnProfile(spProfile); if (NULL_var != spPrtProfileOnProfile) { CATISpecObject_var spElt = NULL_var; spPrtProfileOnProfile->GetElement(1, spElt); if (NULL_var != spElt) { listSpec.Append(spElt); } } } } piUserPad->Release(); return listSpec; } ... |
The "Profile" attribute of the simplified pad references the
profile, which in turns, references the unique sketch. We get the attribute by
using the GetAttribute
method of the CATISpecObject
interface. We get the sketch from the profile by using the GetElement
method of the CATIPrtProfile interface. The sketch is inserted into the
returned list.
Note that the spProfile
smart pointer to CATISpecObject
is released. This is usually useless with smart pointers that are automatically
released when going out of scope, but here, this is required, because GetSpecObject
returns an interface pointer, and as any good method that returns an interface
pointer, GetSpecObject
calls AddRef
onto the returned
pointer. This pointer is then used in the same statement to create the smart
pointer using the redefined assignment operator of the smart pointer class, that
also calls AddRef
onto the created smart pointer. The reference
count is incremented twice, and must be decremented. Since the returned pointer
cannot be handled, the smart pointer is used to call Release
. This
decrements the reference count. Then the smart pointer can be used and is again
released when going out of scope.
[Top]
IsElementValidForPaste
is a method that returns 1 to let the
paste occur, 0 to prevent it.
... int CAAPriEMechanicalCCP::IsElementValidForPaste(CATPathElement* ispPath) const { // // return value: the paste is not valid yet. // int valid = 0; // // checking if there is a sketch in the path element // CATBaseUnknown *spiSketchOnElt = ispPath->FindElement(IID_CATISketch); if( NULL != spiSketchOnElt ) { spiSketchOnElt->Release(); valid = 1; } return valid; } ... |
The input argument is the selected object onto which the user intends to paste the cut or copied object: it is a CATPathElement instance that holds the whole user selection. For the simplified pad, the intent is to let the paste operation occur if the destination object is a sketch that is going to replace the current sketch of the pad.
We look for a sketch in the input path element using the FindElement
method to which the CATISketch IID
is passed. If a sketch is
found, the paste operation is possible and the method returns 1.
[Top]
GetAnchorPoint
is used to retrieve the absolute positioning of
the object being copied.
... CATMathPoint CAAPriEMechanicalCCP::GetAnchorPoint() const { // Retrieves the Profile attribute of the UserPad feature. // CATMathPoint anchorPoint; CATISpecObject * piUserPad = NULL; HRESULT rc = ((CATBaseUnknown*)this)->QueryInterface( IID_CATISpecObject , ( void** ) &piUserPad ); if( FAILED(rc) ) return anchorPoint; CATISpecAttribute *piProfileAtt = piUserPad->GetAttribute("Profile"); if(NULL != piProfileAtt) { CATISpecObject_var spProfile = piProfileAtt->GetSpecObject(1); piProfileAtt->Release(); if(NULL_var != spProfile) { spProfile->Release(); // Retrieves the sketch associated with the profile // The sketch is added in the returned list // CATIPrtProfile_var spPrtProfileOnProfile(spProfile); if (NULL_var != spPrtProfileOnProfile) { int nbElt = spPrtProfileOnProfile->GetElementCount(); if (1 == nbElt) { // Retrieves the sketch associated to the profile // CATISpecObject_var spElt; spPrtProfileOnProfile->GetElement(1, spElt); CATIMechanicalCCP_var spCCPOnElt(spElt); if (NULL_var != spCCPOnElt) { // Delegates GetAnchorPoint to the sketch // anchorPoint = spCCPOnElt->GetAnchorPoint(); } } } } } piUserPad->Release(); return anchorPoint; } ... |
In the case of the simplified pad, the anchor point is the one of the sketch. The sketch is retrieved in the same way than in the GiveMeYourFavoriteSpecifications method. The algorithm consists in finding the referenced sketch and delegate the call to it.
[Top]
GetReferenceNormal
is a used to retrieve the absolute normal of
the result of feature.
... CATMathDirection CAAPriEMechanicalCCP::GetReferenceNormal() const { // Retrieves the Profile attribute of the UserPad feature. // CATMathDirection normal; CATISpecObject *piUserPad = NULL; HRESULT rc = ((CATBaseUnknown*)this)->QueryInterface( IID_CATISpecObject , ( void** ) &piUserPad ); if( FAILED(rc) ) return normal; CATISpecAttribute *piProfileAtt = piUserPad->GetAttribute("Profile"); if(NULL != piProfileAtt) { CATISpecObject_var spProfile = piProfileAtt->GetSpecObject(1); piProfileAtt->Release(); if(NULL_var != spProfile) { spProfile->Release(); // Retrieves the sketch associated with the profile // The sketch is added in the returned list // CATIPrtProfile_var spPrtProfileOnProfile(spProfile); if (NULL_var != spPrtProfileOnProfile) { int nbElt = spPrtProfileOnProfile->GetElementCount(); if (1 == nbElt) { CATISpecObject_var spElt; spPrtProfileOnProfile->GetElement(1, spElt); CATIMechanicalCCP_var spCCPOnElt(spElt); if (spCCPOnElt != NULL_var) { // Delegates GetReferenceNormal to the sketch // normal = spCCPOnElt->GetReferenceNormal(); } } } } } piUserPad->Release(); return normal; } ... |
In the case of the simplified pad, the normal is the one of the sketch. The sketch is retrieved in the same way than in the GiveMeYourFavoriteSpecifications method. The algorithm consists in finding the referenced sketch and delegate the call to it.
[Top]
CanBeDeleted
is used to know whether the cut feature can be
actually be cut. It should return 1 if the feature can be cut, and 0 otherwise
... int CAAPriEMechanicalCCP::CanBeDeleted(CATListValCATISpecObject_var List) const { return 1; } ... |
The simplified pad can always be the cut.
[Top]
CanBeCopied
is used to know whether the copied feature can be
actually be copied. It should return 1 if the feature can be copied, and 0
otherwise.
... int CAAPriEMechanicalCCP::CanBeCopied() const { return 1; } ... |
The simplified pad can always be the copied.
[Top]
CATIShapeFeatureProperties is implemented using a class named CAAPriECCPProp that is a data extension of the late type CAAPriUserPad. This class derives from the CATMmrShapeFeaturePropertiesAdapter adaptor class. There are only two methods to implement :
The CATIShapeFeatureProperties has also the followings methods:
IsAContextualFeature
: Implemented by the CATMmrShapeFeaturePropertiesAdapter
adaptor classIsAFreeFormFeature
: implemented by the CATMmrShapeFeaturePropertiesAdapter
adaptor class. These two methods are implemented by the CATMmrShapeFeaturePropertiesAdapter adaptor class, you do not have to overwrite them.
and,
GiveMeYourBRepSpecifications
: the default implementation
provides an empty list.CanBePatterned
: the default implementation sets that
the feature can not be patterned.The default implementation of these two methods are available. So the CAAPriECCPProp class do not overwrite them.
The CATIShapeFeatureProperties is an interface which can be implemented by the BOA mechanism [4]. So lets us consider the first part of the CAAPriECCPProp code file:
... CATImplementClass(CAAPriECCPProp, DataExtension, CATIShapeFeatureProperties, CAAPriUserPad); CATImplementBOA(CATIShapeFeatureProperties, CAAPriECCPProp); ... |
CATImplementClass
macro is used in conjunction with the CATDeclareClass
macro in the class header file to express that the class is part of a CAA V5
Object Modeler component. Its argument read as follows:
CAAPriECCPProp
: the class name
DataExtension
: the CAA V5 Object Modeler class type.
CATIShapeFeatureProperties
:
The name of
implemented interface
CAAPriUserPad
: the name of the extended componentCATImplementBOA
macro replaces the TIE_CATIShapeFeatureProperties
macro. Its arguments are the BOA-implemented interface and the extension class
name respectively.
GetPolarity
returns the polarity of the feature, that is,
whether the feature adds or removes matter.
... CATUnicodeString CAAPriECCPProp::GetPolarity ( ) { CATUnicodeString PrtAdd("Add"); return PrtAdd; } ... |
The simplified pad adds matter.
GiveMeYourFavoriteSketches
returns the sketches used to build
the feature. In the case of the simplified pad, there is a single sketch. It is
retrieved as in GiveMeYourFavoriteSpecifications.
[Top]
This use case has demonstrated the way to implement the Cut/Copy/Paste behavior for the simplified pad. This is achieved by making theb CAAPriUserPad feature implement the CATIMechanicalCCP and CATIShapeFeatureProperties interfaces. Implementing CATIMechanicalCCP is enough for features that directly aggregate a sketch. If this is not the case, CATIShapeFeatureProperties must also be implemented. Both interfaces are implemented in data extension classes of the feature late type.
[Top]
[1] | Form Feature and Contextual Feature Concepts |
[2] | Implementing a Mechanical Design Feature Building |
[3] | Building and Launching a CAA V5 Use Case |
[4] | Creating Components |
[Top] |
Version: 1 [May 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.