Inspection Process Definition |
Inspection |
Creating ActivitiesCreating a Process document and adding features and activities |
Use Case |
AbstractThis article discusses the CAADNBInsCreateFeatures use case. This use case explains how to create a Process document and then how to add features to it. |
This use case is intended to help you create a Process document, and then create features and activities.
[Top]
CAADNBInsCreateFeatures is a use case of the CAADNBInsFeatures.m module in the CAADNBInspectInterfaces.edu framework that illustrates CAADNBInspectInterfaces framework capabilities.
[Top]
CAADNBInsCreateFeatures is a main program (a batch mode application). First, it creates a Process document named Experiment.CATProcess, and then it creates a Line feature and a DefineLine activity, a Sphere feature and a DefineSphere activity, and a Plane feature and a DefinePlane activity. Finally, it saves the Process document.
|
[Top]
To launch CAADNBInsCreateFeatures , you will need to set up the build time environment, then compile CAADNBInsCreateFeatures along with its prerequisites, set up the run time environment, and then execute the use case [1].
Launch the use case as follows:
d:>
|
$
|
where CAADNBInsFeatures
is the module which contains the use
case.
[Top]
The CAADNBInsCreateFeatures use case is located in the CAADNBInsFeatures.m module of the CAADNBInspectInterfaces.edu framework:
Windows | InstallRootDirectory\CAADNBInspectInterfaces.edu\CAADNBInsFeatures.m\ |
Unix | InstallRootDirectory/CAADNBInspectInterfaces.edu/CAADNBInsFeatures.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
This diagram can be used as a guide to follow the different steps of the use case.
Following are the logical steps in CAADNBInsCreateFeatures:
We will now comment each of these sections by looking at the code.
[Top]
//============================================================================= // Initialize : This method creates a New CATProcess // and intialize the current document //============================================================================= HRESULT CAADNBInsServices::Initialize( CATDocument **INSLibDoc ) { HRESULT rc = E_FAIL; //---------------------------------------------------------------------- // Initialize //---------------------------------------------------------------------- cout << endl; cout << "################################################" << endl; cout << "# Creating a CATProcess #" << endl; cout << "################################################" << endl; cout << endl; //---------------------------------------------------------------------- // Create a New CATProcess //---------------------------------------------------------------------- rc = CATDocumentServices::New( "CATProcess",*INSLibDoc ); if( *INSLibDoc == NULL ) return( E_FAIL ) ; // Get a Handler to the BasicServices ,return if NULL_var DNBIInsBasicServices_var spInsServ( *INSLibDoc ); if( NULL_var == spInsServ ) return( E_FAIL ) ; // Set the Current Document rc = spInsServ->SetCurrentDocument( *INSLibDoc ); return( S_OK ); } |
A new Process document is created. The input argument in this method is a pointer to the CATDocument class. This is a handler to the current document. This method returns a HRESULT value. This method can be found in CAADNBInsServ.cpp.
[Top]
//============================================================================= // GetFtrFactory : This method gets the Current Document and returns the // handler to the DNBIInsFtrFactory Interface //============================================================================= DNBIInsFtrFactory_var CAADNBInsServices::GetFtrFactory( CATDocument *INSLibDoc ) { HRESULT rc = E_FAIL; CATIContainer_var insCont = NULL_var; // Get a Handler to the BasicServices ,return if NULL_var DNBIInsBasicServices_var spInsServ ( INSLibDoc ); if( NULL_var == spInsServ ) return( NULL_var ); // Get Inspect Container rc = spInsServ->GetInspectContainer( insCont, INSLibDoc ); if ( NULL_var == insCont ) return( NULL_var ); // Handler to the DNBIInsFtrFactory DNBIInsFtrFactory_var ftrFact( insCont ); if( NULL_var == ftrFact ) return( NULL_var ); return( ftrFact ); } |
The GetFtrFactory
method is used to get the handler to the DNBIInsFtrFactory
Interface. It takes an argument which is the current document. It gets the
handler to the DNBIInsBasicServices and then it gets the Inspect
Container. This method can be found in CAADNBInsServ.cpp.
[Top]
//============================================================================= // GetActivityFactory : This method gets the InsertActivity and returns the // handler to the DNBIInsActivitiesFactory Interface //============================================================================= DNBIInsActivitiesFactory_var CAADNBInsServices::GetActivityFactory( CATISPPChildManagement_var InsertActivity ) { DNBIInsActivitiesFactory_var ActFact( InsertActivity ); return( ActFact ); } |
The GetActivityFactory
method is used to get the handler to the DNBIInsActivitesFactory
Interface. It takes an argument which is the object of type CATISPPChildManagement
class. This method can be found in CAADNBInsServ.cpp.
[Top]
//============================================================================= // GetActivityRoot : This method gets the the Current Document and returns the // insertion point where new activity needs to be added // In the first case its the fatherActivity //============================================================================= HRESULT CAADNBInsServices::GetActivityRoot( CATISPPChildManagement_var &InsertActivity , CATDocument **INSLibDoc ) { CATInit_var INSLibDocInit( *INSLibDoc ); // Process Container return if NULL_var CATISPPProcessContainer_var ProcessContainer = INSLibDocInit->GetRootContainer( CATISPPProcessContainer::ClassName() ); if( NULL_var == ProcessContainer ) return( E_FAIL ); // List Of Processes CATListValCATBaseUnknown_var *listOfProcesses = ProcessContainer->GetAllProcess(); if( NULL == listOfProcesses ) return( E_FAIL ); // Activity Root CATISPPActivityRoot_var spActivityRoot = ( *listOfProcesses )[1]; if( NULL_var == spActivityRoot ) return( E_FAIL ); // Get the Insert Activity , New Features will be added to the insert activity InsertActivity = spActivityRoot; return( S_OK ); } |
The GetActivityRoot
method is used to get the Activity Root. It
takes two arguments, one of which is the object of type CATISPPChildManagement
interface, and the other one is of type CATDocument class (the current
document). This method can be found in CAADNBInsServ.cpp.
[Top]
//============================================================================= // CreateLine : This method gets the InsertActivity , creates a LineFeature // ,creates a LineActivity, sets the LineItem to the Activity // List and returns the handler to the Line //============================================================================= DNBIInsLine *CreateLine( CATDocument *INSLibDoc, CATISPPChildManagement_var &InsertActivity ) { HRESULT rc = E_FAIL; DNBIInsFtrFactory_var ftrFact = NULL_var; DNBIInsActivitiesFactory_var ActFact = NULL_var ; CATISpecObject_var spObj = NULL_var; CATBaseUnknown_var spIDefineLine = NULL_var; // Get the handler to the feature factory ftrFact = CAADNBInsServices::GetFtrFactory( INSLibDoc ); // Get the handler to the Activity factory ActFact = CAADNBInsServices::GetActivityFactory( InsertActivity ); // Return if the Handler to the FtrFactory or ActivitiesFactory is NULL_var if( NULL_var == ftrFact || NULL_var == ActFact ) return( NULL ); //---------------------------------------------------------------------- // Create Line Feature //---------------------------------------------------------------------- rc = ftrFact->CreateLine( spObj ); if ( NULL_var == spObj ) return( NULL ); // Get the Handler to the Line DNBIInsLine *spLine = NULL; rc = spObj->QueryInterface( IID_DNBIInsLine,( void ** )&spLine ); if( FAILED( rc ) ) return( NULL ); // Set Line Parameters spLine->SetLength( 25.00 ); //---------------------------------------------------------------------- // Create DefineLine Activity //---------------------------------------------------------------------- spIDefineLine = ActFact->Create( InsertActivity,"DefineLine" ); // Set the Item CATISPPItemMgt_var spItm ( spIDefineLine ); if ( NULL_var == spItm ) return( NULL ); spItm->AddItem( spLine ); // Set the InsertActivity(Insertion Point) as the New Activity InsertActivity = spIDefineLine; // Returns a Handler to the Line Created return( spLine ); } |
The CreateLine
method is used from the feature factory to create
the Line feature. The parameters are set for the Line and then the DefineLine
activity is created using the Create
method from the activity
factory. At the end the item is added to the tree using the AddItem
method.
[Top]
//============================================================================= // CreateSphere : This method gets the InsertActivity ,creates a SphereFeature // creates a SphereActivity,sets the SphereItem to the Activity // list and returns the handler to the Sphere //============================================================================= DNBIInsSphere *CreateSphere( CATDocument *INSLibDoc , CATISPPChildManagement_var &InsertActivity ) { HRESULT rc = E_FAIL; DNBIInsFtrFactory_var ftrFact = NULL_var; DNBIInsActivitiesFactory_var ActFact = NULL_var ; CATISpecObject_var spObj = NULL_var; CATBaseUnknown_var spIDefineSphere = NULL_var; // Get the handler to the feature factory ftrFact = CAADNBInsServices::GetFtrFactory( INSLibDoc ); // Get the handler to the Activity factory ActFact = CAADNBInsServices::GetActivityFactory( InsertActivity ); // Return if the Handler to the FtrFactory or ActivitiesFactory is NULL_var if( NULL_var == ftrFact || NULL_var == ActFact ) return( NULL ); //---------------------------------------------------------------------- // Create Sphere Feature //---------------------------------------------------------------------- rc = ftrFact->CreateSphere( spObj ); if ( NULL_var == spObj ) return( NULL ); // Get the Handler to the Sphere DNBIInsSphere *spSphere = NULL; rc = spObj->QueryInterface( IID_DNBIInsSphere,( void ** )&spSphere ); if( FAILED( rc ) ) return( NULL ); CATMathVector Vec( 20.00,-30.00,0 ); CATMathTransformation objPos; objPos.SetVector( Vec ); // Set Sphere Parameters spSphere->SetDiameter( 30.00 ); spSphere->SetPosition( objPos ); //---------------------------------------------------------------------- // Create DefineSphere Activity //---------------------------------------------------------------------- spIDefineSphere = ActFact->Create( InsertActivity,"DefineSphere" ); // Set the Item CATISPPItemMgt_var spItm ( spIDefineSphere ); if ( NULL_var == spItm ) return( NULL ); spItm->AddItem( spSphere ); // Set the InsertActivity(Insertion Point) as the New Activity InsertActivity = spIDefineSphere; // returns the handler to the created sphere return( spSphere ); } |
The CreateSphere
method is used from the feature factory to
create the Sphere feature. The parameters are set for the Sphere and then the
DefineSphere activity is created using the Create
method from the
activity factory. At the end the item is added to the tree using the AddItem
method. It is similar to the CreateLine
method.
[Top]
//============================================================================= // CreatePlane : This method gets the InsertActivity , creates a PlaneFeature, // creates a PlaneActivity ,Sets the PlaneItem to the Activity // List and returns a handler to the Plane //============================================================================= DNBIInsPlane *CreatePlane( CATDocument *INSLibDoc , CATISPPChildManagement_var &InsertActivity ) { HRESULT rc = E_FAIL; CATISpecObject_var spObj = NULL_var; CATBaseUnknown_var spIDefinePlane = NULL_var; DNBIInsFtrFactory_var ftrFact = NULL_var; DNBIInsActivitiesFactory_var ActFact = NULL_var ; // Get the handler to the feature factory ftrFact = CAADNBInsServices::GetFtrFactory( INSLibDoc ); // Get the handler to the Activity factory ActFact = CAADNBInsServices::GetActivityFactory( InsertActivity ); // Return if the Handler to the FtrFactory or ActivitiesFactory is NULL_var if( NULL_var == ftrFact || NULL_var == ActFact ) return( NULL ); //---------------------------------------------------------------------- // Create Plane Feature //---------------------------------------------------------------------- rc = ftrFact->CreatePlane( spObj ); if ( NULL_var == spObj ) return( NULL ); // Get the Handler to the Plane DNBIInsPlane *spPlane = NULL; rc = spObj->QueryInterface( IID_DNBIInsPlane,( void ** )&spPlane ); if( FAILED( rc ) ) return( NULL ); // Set Plane Parameters CATMathVector Vec(-20.00,35.00,0); CATMathTransformation objPos; objPos.SetVector(Vec); spPlane->SetLength(40.00); spPlane->SetWidth(40.00); spPlane->SetPosition(objPos); //---------------------------------------------------------------------- // Create DefinePlane Activity //---------------------------------------------------------------------- spIDefinePlane = ActFact->Create( InsertActivity,"DefinePlane" ); // Set the Item CATISPPItemMgt_var spItm ( spIDefinePlane ); if ( NULL_var == spItm ) return( NULL ); spItm->AddItem( spPlane ); // Set the InsertActivity(Insertion Point) as the New Activity InsertActivity = spIDefinePlane; // Returns the handler to the Created Plane return( spPlane ); } |
The CreatePlane
method is used from the feature factory to
create the Plane feature. The parameters are set for the Plane and then the
DefinePlane activity is created using the Create
method from the
activity factory. At the end the item is added to the tree using the AddItem
method. It is similar to the CreateLine
and CreateSphere
method.
[Top]
The Process document is saved with the name as Experiment.CATProcess. This method can be found in CAADNBInsServ.cpp.
//============================================================================= // SaveProcess : This method gets the Current Document and saves the // CATProcess //============================================================================= HRESULT CAADNBInsServices::SaveProcess( CATDocument *INSLibDoc ) { //---------------------------------------------------------------------- // Save the CATProcess //---------------------------------------------------------------------- cout << endl; cout << "################################################" << endl; cout << "# Save the document #" << endl; cout << "################################################" << endl; cout << endl; cout << " Saving the process ..."; CATIPersistent_var Persistdoc (INSLibDoc); if( NULL_var == Persistdoc ) return( E_FAIL ); Persistdoc->SaveAs( "Experiment.CATProcess",FALSE ); cout << "OK" << endl; return( S_OK ); } |
[Top]
This use case has demonstrated the way to create a Process document and to create three features.
The use case:
[Top]
[1] | Building and Launching a CAA V5 Use Case |
[Top] |
History | |
Version: 1 [Mar 2002] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.