Inspection Process Definition

Inspection

Creating and Measuring Activities

Creating a measured path activity
Use Case

Abstract

This article discusses the CAADNBInsMeasActivities use case. This use case explains how to create a CATProcess in a Batch Mode , to add features to it and then to measure them .


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 measure these activities.

[Top]

The CAADNBInsMeasActivities Use Case

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

[Top]

What Does CAADNBInsMeasActivities Do

CAADNBInsMeasActivities is a main program (a batch mode application). First, it creates a Process document named Experiment.CATProcess, and then it creates two activities, namely a DefineSphere and a DefinePlane activity. Then it measures both activites and creates a path for them. Finally, it saves the Process document.

The Experiment.CATProcess Document
 

[Top]

How to Launch CAADNBInsMeasActivities

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

Launch the use case as follows:

where CAADNBInsMeasPaths is the module which contains the use case.

[Top]

Where to Find the CAADNBInsMeasActivities Code

The CAADNBInsMeasActivities use case is located in the CAADNBInsMeasPaths.m module of the CAADNBInspectInterfaces.edu framework:

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

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

[Top]

Step-by-Step

Following are the logical steps in CAADNBInsMeasActivities:

  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 Sphere Feature and a DefineSphere Activity
  6. Creating a Plane Feature and a DefinePlane Activity
  7. Measuring the DefinePlane Activity
  8. Measuring the DefineSphere Activity
  9. 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 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 ;
  
  // 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 );

  CATISpecObject_var spObj = NULL_var;
  CATBaseUnknown_var spIDefineSphere = NULL_var;
  
  //----------------------------------------------------------------------
  //  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 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.

[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 ;
  
  // 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 );
	
  CATISpecObject_var spObj = NULL_var;
  CATBaseUnknown_var spIDefinePlane = NULL_var;
  
  //----------------------------------------------------------------------
  //  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 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]

Measuring the DefinePlane Activity

//-----------------------------------------------------------------------------
//  MeasurePlane : To Measure a Plane
//-----------------------------------------------------------------------------
HRESULT
MeasurePlane( DNBIInsPlane  *objPlane ,
              CATDocument* INSLibDoc ,
              CATISPPChildManagement_var &InsertActivity )
{
  HRESULT rc = E_FAIL;
  
  DNBIInsMPathFactory_var spIMPathFactory = NULL_var;
  // Check if the Plane Element or spIMPathFactory is not NULL_var
  if( NULL_var == objPlane )
    return( E_FAIL );
  
  // Get the handler to the DNBIInsFeature Interface
  DNBIInsFeature_var spIFeature( objPlane );
  if( NULL_var == spIFeature ) 
    return( E_FAIL );
  
  CATBSTR bstrMPathName;
  CATUnicodeString MPathName;
  CATUnicodeString pathType;
  CATBaseUnknown_var NewOp = NULL_var ;
  CATIContainer_var Cont = NULL_var;
  
  pathType = "DNBInsPlaneFtrPath";
  MPathName.Append( "PlanePath" );
  MPathName.ConvertToBSTR( &bstrMPathName );
  DNBIInsMPath *pIMPath=NULL;
  
  // Get a Handler to the BasicServices ,return if NULL_var
  DNBIInsBasicServices_var InsServ( INSLibDoc );
  if ( NULL_var == InsServ )
    return( E_FAIL );

  // Get MPathContainer
  spIMPathFactory = InsServ->GetMPathContainer();

  // Create MPath for the Given PathType
  spIMPathFactory->CreateMPath( bstrMPathName,
    pathType,
    pIMPath );
  ::CATFreeString( bstrMPathName );
  
  // return if the path created is Null
  if( NULL == pIMPath )
    return( E_FAIL );
  
  // To set the feature in the created path
  pIMPath->SetFeature( spIFeature );
  
  // Get Inspect Container
  rc = InsServ->GetInspectContainer( Cont, INSLibDoc );
  if ( NULL_var == Cont )
    return( E_FAIL );
    
  //----------------------------------------------------------------------
  // Apply rules to modify the path parameters according to the feature
  //----------------------------------------------------------------------
   DNBIInsKWFactory_var spIRuleFact( Cont );

  CATIRuleBase_var spIRuleBase = spIRuleFact->GetRuleBase();
  if( spIRuleBase != NULL_var )
  {
    CATISpecObject_var spISpecPath( pIMPath );
    CATISpecObject_var spISpecFtr( spIFeature );
    spIRuleFact->AddKWInstance( spISpecFtr );
    spIRuleFact->AddKWInstance( spISpecPath );
    spIRuleBase->Solve( 1 );
  }
  else
  {
    DNBIInsFtrPathRules_var spIRules ( pIMPath );
    spIRules->SetRules();
  }
  
  //----------------------------------------------------------------------
  // To get the smart pointer to the given path
  // This is done because the AcquiredFeature takes only the Smart Pointer
  //----------------------------------------------------------------------
  DNBIInsMPath_var spIMPath = pIMPath ;
  if( NULL_var == spIMPath )
    return( E_FAIL );
  
  pIMPath->Release();
  pIMPath = NULL;

  DNBIInsFeature   *Feat;
  spIMPath->GetFeature( Feat );
  if( NULL == Feat )
   return( E_FAIL );

  // Get the handler to the ActivitiesFactory
  DNBIInsActivitiesFactory_var ActFact = NULL_var ;
  ActFact = CAADNBInsServices::GetActivityFactory( InsertActivity );

  // Create a MeasureActivity
  NewOp = ActFact->Create( InsertActivity,"MeasurePlane" );
  
  CATISPPItemMgt_var spItm ( NewOp );
  if( NULL_var == spItm )
   return( NULL );

  // SetItem for the Plane feature in the Measure Feature
  spItm->AddItem( Feat );
  Feat->Release();
  Feat = NULL ;
  
  // SetItem for the Path in the Measure Feature
  spItm->AddItem( spIMPath );
  InsertActivity = NewOp ;
  
  return( S_OK );
}

The MeasurePlane method gets the handler to the Plane feature which needs to be measured. It  creates a path for that and then it applies rules to it. Finally it creates a MeasurePlane activity and adds it to the Activity list.

[Top]

Measuring the DefineSphere Activity

//-----------------------------------------------------------------------------
//  MeasureSphere : To Measure a Sphere
//-----------------------------------------------------------------------------
HRESULT
MeasureSphere( DNBIInsSphere  *objSphere ,
               CATDocument* INSLibDoc ,
               CATISPPChildManagement_var &InsertActivity )
{
 
  HRESULT rc = E_FAIL;
  DNBIInsMPathFactory_var spIMPathFactory = NULL_var;

  // Check if the Sphere Element or spIMPathFactory is not NULL_var
  if( NULL_var == objSphere )
    return( E_FAIL );
  
  // Get the handler to the DNBIInsFeature Interface
  DNBIInsFeature_var spIFeature( objSphere );
  if( NULL_var == spIFeature ) 
    return( E_FAIL );
  

  CATBSTR bstrMPathName;
  CATUnicodeString MPathName;
  CATUnicodeString pathType;
  CATBaseUnknown_var NewOp = NULL_var;
  CATIContainer_var Cont = NULL_var;
  
  pathType = "DNBInsSphereFtrPath";
  MPathName.Append( "SpherePath" );
  MPathName.ConvertToBSTR( &bstrMPathName );
  DNBIInsMPath *pIMPath=NULL;
  
  // Get a Handler to the BasicServices ,return if NULL_var
  DNBIInsBasicServices_var InsServ( INSLibDoc );
  if ( NULL_var == InsServ )
    return( E_FAIL );

  // Get MPathContainer
  spIMPathFactory = InsServ->GetMPathContainer();

  // Create MPath for the Given PathType
  spIMPathFactory->CreateMPath( bstrMPathName,
    pathType,
    pIMPath );
  ::CATFreeString( bstrMPathName );
  
  // return if the path created is Null
  if( NULL == pIMPath )
    return( E_FAIL );
  
  // To set the feature in the created path
  pIMPath->SetFeature( spIFeature );

  // Get Inspect Container
  rc = InsServ->GetInspectContainer( Cont, INSLibDoc );
  if ( NULL_var == Cont )
    return( E_FAIL );

  //----------------------------------------------------------------------
  // Apply rules to modify the path parameters according to the feature
  //----------------------------------------------------------------------
   DNBIInsKWFactory_var
    spIRuleFact( Cont );

  CATIRuleBase_var spIRuleBase = spIRuleFact->GetRuleBase();
  if( spIRuleBase != NULL_var )
  {
    CATISpecObject_var spISpecPath( pIMPath );
    CATISpecObject_var spISpecFtr( spIFeature );
    spIRuleFact->AddKWInstance( spISpecFtr );
    spIRuleFact->AddKWInstance( spISpecPath );
    spIRuleBase->Solve( 1 );
  }
  else
  {
    DNBIInsFtrPathRules_var spIRules ( pIMPath );
    spIRules->SetRules();
  }

  //----------------------------------------------------------------------
  // To get the smart pointer to the given path
  // This is done coz the AcquiredFeature takes only the Smart POinter
  //----------------------------------------------------------------------
  DNBIInsMPath_var spIMPath = pIMPath ;
  if( NULL_var == spIMPath )
    return( E_FAIL );
  
  pIMPath->Release();
  pIMPath = NULL;
  
  DNBIInsFeature   *Feat;
  spIMPath->GetFeature( Feat );
  
  DNBIInsActivitiesFactory_var ActFact = NULL_var ;
  ActFact = CAADNBInsServices::GetActivityFactory( InsertActivity );

  // Create a MeasureActivity
  if( NULL_var == ActFact )
    return( E_FAIL );
  
  // Create the Measured Feature
  NewOp = ActFact->Create( InsertActivity, "MeasureSphere");
  if( NULL == Feat )
    return( E_FAIL );  
  
  CATISPPItemMgt_var spItm ( NewOp );
  if( NULL_var == spItm )
   return( NULL );

  // SetItem for the Sphere feature in the Measure Feature
  spItm->AddItem( Feat );
  // SetItem for the Path in the Measure Feature
  spItm->AddItem( spIMPath );
  InsertActivity = NewOp ;

  Feat->Release();
  Feat = NULL ;
  return( S_OK );
}

The MeasureSphere method gets the handler to the Sphere feature which needs to be measured. It  creates a path for that and then it applies rules to it. Finally it creates a MeasureSphere activity and adds it to the Activity list.

[Top]

Saving the Process Document

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]


In Short

This use case has demonstrated the way to create a Process document, to add features, to create activities and finally to measure the activites and to add the measure activities to the activity list.

The use case:

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[Top]

[Top]


History
Version: 1 [Mar 2002] Document created

[Top]


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