Equipment & Systems |
Distributive Systems |
Accessing Spatial Integration DataHow to access integration data. |
| Use Case | ||
This article discusses the CAACloPspSpatialPhysical use case.
CAACloPspSpatialPhysical is a use case of the CAACommonLayoutItf.edu framework. It illustrates a CATPlantShipInterfaces interface that is implemented by CATCommonLayout.
[Top]
This use case is intended to show you how to obtain integration data from spatial object.
[Top]
CAACloPspSpatialPhysical retrieves the physical objects and corresponding connectors associated at the extremity of the spatial object.
[Top]
To launch CAACloPspSpatialPhysical, you will need to set up the build time environment, then compile CAACloPspSpatialPhysical along with its prerequisites, set up the run time environment, and then execute the sample. This is fully described in the referenced article [1]. When launching the use case, you must pass the following arguments:
[Top]
CAACloPspSpatialPhysical code is located in the CAACloPspSpatialPhysical.m use case module of the CAACommonLayoutItf.edu framework:
| Windows | InstallRootDirectory\CAACommonLayoutItf.edu\CAACloPspSpatialPhysical.m |
| Unix | InstallRootDirectory/CAACommonLayoutItf.edu/CAACloPspSpatialPhysical.m |
where InstallRootDirectory is the root directory of your CAA V5
installation. It is made of two unique source files named
CAACloPspSpatialPhysicalMain.cpp and CAACloPspSpatialPhysical.cpp.
[Top]
The remainder of this document describes the various parts of CAACloPspSpatialPhysicalMain.cpp and CAACloPspSpatialPhysical.cpp.
[Top]
CAACloPspSpatialPhysicalMain.cpp contains the main method that initiates processing. It reads the command line argument to find the path of the data file to be processed. It also creates the CAACloPspSpatialPhysical class and calls the DoSample method of CAACloPspSpatialPhysical.
// COPYRIGHT DASSAULT SYSTEMES 2011 //============================================================================= // // CAACloPspSpatialPhysicalMain // This sample illustrates how to use the CAA Plant Ship interfaces to: // 1.Query spatial objects. // // // Prerequisite: // ------------------- // This sample uses the input product CAACloPspEduIn.CATProduct. // // Running the program: // ------------------- // To run this program, you can use the command: // // mkrun -c "CAACloPspSpatialPhysical CAACloPspEduIn.CATProduct" // // where "CAACloPspEduIn.CATProduct" is the full path name of the input product. // //============================================================================= // #include <iostream.h> #include <string.h> // This framework #include "CAACloPspSpatialPhysical.h" // System #include "CATErrorMacros.h" #include "CATUnicodeString.h" //============================================================================= // Main //============================================================================= int main (int argc, char **argv) { cout <<"Start main CAACloPspSpatialPhysical" << endl; CATUnicodeString FileToBeLoaded = NULL; int rc = 0; CATTry { if (argc > 1) { FileToBeLoaded = argv[1]; } if (FileToBeLoaded.GetLengthInChar()) { cout << "**** must input the file name of " << endl; cout << "a CATProduct with Piping application objects " << endl; } else { CAACloPspSpatialPhysical myObject; cout << "FileToBeLoaded = " << FileToBeLoaded << endl; rc = myObject.DoSample(FileToBeLoaded); } } CATCatch (CATError, pError) { cout << "error in main " << endl; cout << "error message : " << ( error ->GetNLSMessage()).ConvertToChar()<<endl; delete error; rc = 999; } CATEndTry; cout << "End main CAACloPspSpatialPhysical" << endl; return rc; }
[Top]
The CAACloPspSpatialPhysical DoSample method runs the use cases. It starts by calling CreateCATProductEnv to load the input data model and create a CATIA product environment. CreateCATProductEnv is part of the CAAPspBaseEnvProtected class which is defined in these files.
After CAACloPspSpatialPhysical calls CreateCATProductEnv it calls ApplicationInit to initialize the Piping application. ApplicationInit is also a part of the CAAPspBaseEnvProtected class. With the data model and application properly initialized DoSample runs the use case. The code for DoSample is shown below.
//============================================================================= // Execute the CAACloPspSpatialPhysical sample code. //============================================================================= HRESULT CAACloPlacePart::DoSample(const CATUnicodeString &iuFileToBeLoaded) { cout <<"============================================================"<< endl; cout <<"=== CAACloPspSpatialPhysical::DoSample ==="<< endl; cout <<"============================================================"<< endl; cout <<" File: " << iuFileToBeLoaded << endl; HRESULT rc = CATReturnFailure; // Interface pointer variables used below in the try section. CATTry { // Load input document CreateCATProductEnv(iuFileToBeLoaded); cout << "Product environment created." << endl; // Initialize Piping Design application ApplicationInit("CATPiping"); cout << "Piping application initialized." << endl; // Retrieve a list of physical objects and connectors associated at the extremity of the spatial object. HRESULT rcListCntrPhy = ListConnectedPhysicalsToSpatial(); cout << "rcListCntrPhy = " << rcListCntrPhy << endl; // Set return code. if (SUCCEEDED(rcListCntrPhy)) rc = CATReturnSuccess; } // end CATTry CATCatch (CATError, pError) { cout << "CAACloPspSpatialPhysical::DoSample *** Error Caught ***" << endl; cout << pError; rc = CATReturnError(pError); } // end CATCatch CATEndTry; cout << "CAACloPspSpatialPhysical::DoSample rc = " << rc << endl; return rc; }
[Top]
The CATIPspPhysical interface is used to retrieve pointer associated to the spatial object. In this sample, the CATIPspPhysical interface pointer is obtained from a physical part in the document. Using the spatial object associated to the previous physical object, we find its CATIPspSpatial interface. The physical objects and corresponding connectors associated at the extremity of the spatial object can be retrieved using the CATIPspSpatial interface.
//=============================================================================================================== // Retrieve all physical objects and corresponding connectors associated at the extremity of the spatial object. //=============================================================================================================== HRESULT CAACloPspSpatialPhysical::ListConnectedPhysicalsToSpatial() { cout <<"======================================================================"<< endl; cout <<"=== CAACloPspSpatialPhysical::ListConnectedPhysicalsToSpatial ==="<< endl; cout <<"======================================================================"<< endl; HRESULT rc = E_FAIL; CATIPspPhysical *piPhysical = NULL; CATIPspSpatial *piSpatial = NULL; IUnknown *piUnknown = NULL; CATIArrSegmentsString *pRun = NULL; CATIArrNode_var ospEndPoint1 = NULL_var; CATIArrNode_var ospEndPoint2 = NULL_var; CATIArrNode_var spArrNode = NULL_var; CATIUnknownList *piListOfPhysicals = NULL; CATIUnknownList *piListOfConnectors = NULL; CATTry { //------------------------------------------------------------------------- // CATIPspPhysical methods //------------------------------------------------------------------------- piPhysical = GetAPhysicalObject(); if ( NULL != piPhysical ) { //---------------------------------------------------------------------- // Get the spatial object associated to the physical object //---------------------------------------------------------------------- if ( SUCCEEDED(piPhysical->GetSpatial(piUnknown)) && NULL != piUnknown ) { // Find CATIPspSpatial interface piUnknown->QueryInterface(IID_CATIPspSpatial,(void**)&piSpatial); piUnknown->Release(); piUnknown = NULL; } //------------------------------------------------------------------------- // CATIPspSpatial methods //------------------------------------------------------------------------- if ( NULL != piSpatial ) { //---------------------------------------------------------------------------------------------------- // Get a list of physical objects and connectors associated at the extremity of the spatial object. //---------------------------------------------------------------------------------------------------- if (SUCCEEDED (piSpatial->QueryInterface(IID_CATIArrSegmentsString, (void**)&pRun))) { pRun->GetEndPoints(ospEndPoint1,ospEndPoint2); if(!!ospEndPoint1) spArrNode = ospEndPoint1; if ( SUCCEEDED(piSpatial->ListConnectedPhysicals( spArrNode, piListOfPhysicals, piListOfConnectors )) && NULL != piListOfPhysicals && NULL != piListOfConnectors ) { unsigned int ListSize = 0; piListOfPhysicals->Count(&ListSize); cout << "Number of physical objects associated to the first extremity of the spatial object: " << (int)ListSize << endl; piListOfPhysicals->Release(); piListOfPhysicals = NULL; piListOfConnectors->Count(&ListSize); cout << "Number of connectors connected to the first extremity of the spatial object: " << (int)ListSize << endl; piListOfConnectors->Release(); piListOfConnectors = NULL; rc = S_OK; } } if ( NULL != pRun ) { pRun->Release(); pRun = NULL; } piSpatial->Release(); piSpatial = NULL; } // end piSpatial piPhysical->Release(); piPhysical = NULL; } // end piPhysical } // end CATTry CATCatch (CATError, error) { if ( NULL != piPhysical ) { piPhysical->Release(); piPhysical = NULL; } if ( NULL != piSpatial ) { piSpatial->Release(); piSpatial = NULL; } if ( NULL != piUnknown ) { piUnknown->Release(); piUnknown = NULL; } cout << "CAACloPspSpatialPhysical::ListConnectedPhysicalsToSpatial *** CATRethrow" << endl; CATRethrow; } CATEndTry; cout << "CAACloPspSpatialPhysical::ListConnectedPhysicalsToSpatial rc = " << rc << endl; return rc; }
[Top]
This use case has demonstrated how to use the Psp interfaces to obtain object integration data. Specifically, it has illustrated:
[Top]
| [1] | Building and Launching a CAA V5 Use Case |
| 1. This documents uses Unix-style forward slash (/) to separate directory names. Windows users should use backslash (\) instead of forward slash (/). |
| Version: 1 [February 2011] | Document created |
| [Top] | |
Copyright © 2011, Dassault Systèmes. All rights reserved.