Inspection Process Definition

Inspection

Creating and Scanning Activities

Creating, accessing and reading activities
Use Case

Abstract

This article discusses the CAADNBInsScanActivities use case. This use case explains how to create a Process document, and then how to add activities to it. Then it scans the activity list and displays some of the parameters in a text file.


What You Will Learn With This Use Case

This use case is intended to help you create a Process document, create features and activities, and then scan these activities.

[Top]

The CAADNBInsScanActivities Use Case

CAADNBInsScanActivities is a use case of the CAADNBInsActivities.m module in the CAADNBInspectInterfaces.edu framework that illustrates CAADNBInspectInterfaces framework capabilities.

[Top]

What Does CAADNBInsScanActivities Do

CAADNBInsScanActivities 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. Then it scans the list of activities and displays the parameters in a text file named output.txt. Finally, it saves the Process document.

The Experiment.CATProcess Document

It also outputs a file named output.txt and displays the parameters of the activities in the process as shown below:

The output.txt Output File

[Top]

How to Launch CAADNBInsScanActivities

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

Launch the use case as follows:

where CAADNBInsActivites is the module which contains the use case.

[Top]

Where to Find the CAADNBInsScanActivities Code

The CAADNBInsScanActivities use case is located in the CAADNBInsActivities.m module of the CAADNBInspectInterfaces.edu framework:

Windows InstallRootDirectory\CAADNBInspectInterfaces.edu\CAADNBInsActivities.m\
Unix InstallRootDirectory/CAADNBInspectInterfaces.edu/CAADNBInsActivities.m/

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

[Top]

Step-by-Step

 

Following are the logical steps in CAADNBInsScanActivities:

  1. Creating and Initializing a Process Document
  2. Retrieving the Handler to the DNBIInsFtrFactory Interface
  3. Retrieving the Handler to the DNBIInsActivitiesFactory Interface
  4. Retrieving the Activity Root
  5. Creating a Line Feature and a DefineLine Activity
  6. Creating a Sphere Feature and a DefineSphere Activity
  7. Creating a Plane Feature and a DefinePlane Activity
  8. Scaning the DefineLine Activity
  9. Scaning the DefineSphere Activity
  10. Scaning the DefinePlane Activity
  11. Saving the Process Document

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

[Top]

Creating and Initializing a Process Document

//=============================================================================
//  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]

Retrieving the Handler to the DNBIInsFtrFactory Interface

//=============================================================================
//  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]

Retrieving the Handler to the DNBIInsActivitiesFactory Interface

//=============================================================================
//  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]

Retrieving the Activity Root

//=============================================================================
//  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]

Creating a Line Feature and a DefineLine Activity

//=============================================================================
//  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 );
  spLine->SetMatOffset( 1.00 );
  
  //----------------------------------------------------------------------
  //  Create Line 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 ;
  
  return( spLine );
}


The CreateLine method gets the InsertActivity, creates a Line feature then it creates a DefineLine activity, finally it adds this activity to the InsertActivity and it returns the handler to the Line.

[Top]

Creating a Sphere Feature and a DefineSphere Activity

//=============================================================================
//  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 Sphere 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 ;
  
  return( spSphere );
}

The CreateSphere method gets the InsertActivity, creates a Sphere feature then it creates a DefineSphere activity, finally it adds this activity to the InsertActivity and it returns the handler to the Sphere.

[Top]

Creating a Plane Feature and a DefinePlane Activity

//=============================================================================
//  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;
  DNBIInsFtrFactory_var ftrFact = NULL_var;
  DNBIInsActivitiesFactory_var ActFact = NULL_var;
  CATISpecObject_var spObj = NULL_var;
  CATBaseUnknown_var spIDefinePlane = 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 );
  
  
  CATMathVector Vec(-20.00,35.00,0);
  CATMathTransformation objPos;
  objPos.SetVector(Vec);
  
  // Set Plane Parameters
  spPlane->SetLength(40.00);
  spPlane->SetWidth(40.00);
  spPlane->SetPosition(objPos);
  //----------------------------------------------------------------------
  //  Create Plane 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 ;
  
  return( spPlane );
}

The CreatePlane method gets the InsertActivity, creates a Plane feature then it creates a DefinePlane activity, finally it adds this activity to the InsertActivity and it returns the handler to the Plane.

[Top]

Scanning the DefineLine Activity

//=============================================================================
//  ScanLine   : This method gets the handler to the Line Activity 
//               and then it displays the information about the Line
//=============================================================================
CATUnicodeString
ScanLine( DNBIInsLine *objLine )
{
  // Declaring the variables
  double length ,thick ;
  CATUnicodeString name;
  CATUnicodeString output;
  CATUnicodeString temp;
  
  // Check if handler to DNBIInsLine Interface is not null
  if( NULL == objLine )
    return( output );
  
  // Get the Parameters
  objLine->GetLength( length );         // Length
  objLine->GetMatOffset( thick );       // Thickness
  
  CATIAlias_var alias( objLine );       // Name
  if( NULL_var != alias )
  {
    name = alias->GetAlias();
  }
  
  // Output
  output.Append("\n LINE INFO ::\n");
  output.Append("\tName     \t\t");
  output.Append(name.ConvertToChar());
  output.Append("\n\tLength   \t\t");
  // To convert integer to string
  temp.BuildFromNum( length ); 
  output.Append( temp );
  output.Append(" mm\n");
  output.Append("\tThickness\t\t");
  temp.BuildFromNum( thick );
  output.Append( temp );
  output.Append(" mm\n");

  return( output );
}

The ScanLine method gets the handler to the Line feature which needs to be scanned. It then gets the Line parameters and returns a CATUnicodeString which holds all the Line Parameters.

[Top]

Scanning the DefineSphere Activity

//=============================================================================
//  ScanSphere : This method gets the handler to the Sphere Activity
//               and then it displays the information about the Sphere
//=============================================================================
CATUnicodeString
ScanSphere( DNBIInsSphere *objSphere )
{
  // Declare the Variables
  double diam ,thick;
  CATUnicodeString name ;
  double ioI,ioJ,ioK ;
  double XCord, YCord, ZCord ;
  CATMathPoint Center ;
  CATMathVector oNorm ;
  CATUnicodeString output;
  CATUnicodeString temp;
  
  // Check if the Handler to the DNBIInsSphere interface is not null
  if( NULL == objSphere )
    return( output );
  
  // Get the parameters
  objSphere->GetNormal( oNorm );             // Handler for Normal
  oNorm.GetCoord( ioI,ioJ,ioK );             // Normal Co-ordinates
  objSphere->GetOrigin ( Center );           // Handler for Origin
  Center.GetCoord( XCord , YCord , ZCord );  // Origin Co-ordinates
  objSphere->GetDiameter( diam );
  objSphere->GetMatOffset( thick );
  
  CATIAlias_var alias( objSphere );       // Name
  if( NULL_var != alias )
  {
    name = alias->GetAlias();
  }
  
  // Output
  output.Append("\n\n\n SPHERE INFO ::\n");
  output.Append("\tName     \t\t");
  output.Append(name.ConvertToChar());
  output.Append("\n\tOrigin Coordinates   \n\t\tX\t\t");
  temp.BuildFromNum( XCord );
  output.Append( temp );
  output.Append( " mm\n\t\tY\t\t" );
  temp.BuildFromNum( YCord );
  output.Append( temp );
  output.Append( " mm\n\t\tZ\t\t" );
  temp.BuildFromNum( ZCord );
  output.Append( temp );
  output.Append( " mm\n\tNormalCordinates\n\t\tI\t\t" );
  temp.BuildFromNum( ioI );
  output.Append( temp );
  output.Append( " mm\n\t\tJ\t\t" );
  temp.BuildFromNum( ioJ );
  output.Append( temp );
  output.Append( " mm\n\t\tK\t\t" );
  temp.BuildFromNum( ioK );
  output.Append( temp );
  output.Append( " mm" );
  
  output.Append("\n\tDiameter\t\t");
  temp.BuildFromNum( diam );
  output.Append( temp );
  output.Append(" mm");
  
  output.Append("\n\tThickness\t\t");
  temp.BuildFromNum( thick );
  output.Append( temp );
  output.Append(" mm\n");
  
  return( output );
}

The ScanSphere method gets the handler to the Sphere feature which needs to be scanned. It then gets the Sphere parameters and returns a CATUnicodeString which holds all the Sphere parameters.

[Top]

Scanning the DefinePlane Activity

//=============================================================================
//  ScanPlane  : This method gets the handler to the Plane Activity
//               and then it displays the information about the Plane
//=============================================================================
CATUnicodeString
ScanPlane( DNBIInsPlane *objPlane )
{
  // Declaring the Variables
  int type ;
  CATUnicodeString name ;
  CATUnicodeString planetype ;
  double length,width,thick;
  double XCord, YCord, ZCord ;
  CATMathPoint Center ;
  CATUnicodeString output;
  CATUnicodeString temp;
  
  // Check if the object to the DNBIInsPlane Interface is not null
  if( NULL == objPlane )
    return( output );
  
  objPlane->GetLength( length );         // Length
  objPlane->GetWidth( width );           // Width
  objPlane->GetPlaneType( type );        
  objPlane->GetMatOffset( thick );       // Thickness
  objPlane->GetOrigin ( Center );           // Handler for Origin
  Center.GetCoord( XCord , YCord , ZCord );  // Origin Co-ordinates
  
  //----------------------------------------------------------------------
  //  Extract Plane Type from 'type' value
  //----------------------------------------------------------------------
  if( type == 1 )
    planetype = "Rectangular";
  else
    planetype = "Circular";
  
  
  CATIAlias_var alias( objPlane );       // Name
  if( NULL_var != alias )
  {
    name = alias->GetAlias();
  }
  
  // Output
  output.Append("\n\n PLANE INFO ::");
  output.Append("\n\tName\t\t");
  output.Append(name.ConvertToChar());
  output.Append("\n\tOrigin Coordinates\n\t\tX\t\t");
  temp.BuildFromNum( XCord );
  output.Append( temp );
  output.Append( " mm\n\t\tY\t\t" );
  temp.BuildFromNum( YCord );
  output.Append( temp );
  output.Append( " mm\n\t\tZ\t\t" );
  temp.BuildFromNum( ZCord );
  output.Append( temp ); 
  output.Append(" mm\n\tlength\t\t");
  temp.BuildFromNum( length );
  output.Append( temp );
  output.Append(" mm");
  
  output.Append("\n\tWidth\t\t\t");
  temp.BuildFromNum( width );
  output.Append( temp );
  output.Append(" mm");
  
  output.Append("\n\tThickness\t\t");
  temp.BuildFromNum( width );
  output.Append( temp );
  output.Append(" mm\n\t");
  output.Append("PlaneType\t\t");
  output.Append(planetype);
  
  return( output );
}

The ScanPlane method gets the handler to the Plane feature which needs to be scanned. It then gets the Plane parameters and returns a CATUnicodeString which holds all the Plane parameters.

[Top]

Saving the Process Document

The Process document is saved with the name 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]


In Short

This use case has demonstrated the way to create a Process document and add features, create activities and finally scanning the activities.

The use case:

[Top]


References

[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.