3D PLM Enterprise Architecture

Data Access - Database

Working with VPM Graphs

Performing basic VPM Graph operations.
Use Case

Abstract

This article shows how to use interfaces in the VPMInterfaces framework to perform certain graph operations using the Graph Manager and Graph Administrator.


What You Will Learn With This Use Case

This use case is intended to show you how to use basic graph functionalities available in the VPMInterfaces framework. First of all, you will see how to retrieve a Graph manager and a Graph administrator. Using the Graph administrator, you will be able to retrieve a list of Graph predicates. Using the Graph manager, you will be able to retrieve a list of Graph names, add a new Graph type, list statuses and terminals and step forward in the Graph.

[Top]

The CAAVpiGraph Use Case

CAAVpiGraph is a use case of the CAAVPMInterfaces.edu framework that illustrates VPMInterfaces framework capabilities.

[Top]

What Does CAAVpiGraph Do?

CAAVpiGraph begins by opening a VPM session and creating a login session. Then, the Graph manager and Graph administrator are retrieved. Using the Graph administrator, a list of Graph predicates is retrieved. Using the Graph manager, a list of Graph names is retrieved, a new Graph type is added and lists of statuses and terminals are also retrieved. Finally, still using the Graph manager, we can make a step forward in the Graph from the initial transition status to a new transition status.

[Top]

How to Launch CAAVpiGraph

To launch CAAVpiGraph, you will need to set up the build time environment, then compile CAAVpiGraph along with its prerequisites, set up the run time environment, and then execute the use case. [1]. The required interfaces can be found in the VPM Persistency and VPMInterfaces frameworks. Launch the use case by executing the following command:

mkrun -c "CAAVpiGraph"

[Top]

Where to Find the CAAVpiGraph Code

The CAAVpiGraph use case is made of a single file located in the CAAVpiGraph.m module of the CAAVPMInterfaces.edu framework:

Windows InstallRootDirectory\CAAVPMInterfaces.edu\CAAVpiGraph.m\
Unix InstallRootDirectory/CAAVPMInterfaces.edu/CAAVpiGraph.m/

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

[Top]

Step-by-Step

For demonstration purposes, the code from the CAAVpiGraph use case is shown here. There are ten logical steps in the CAAVpiGraph use case:

  1. Initializing the VPM Session
  2. Retrieving the Graph and Administration Managers
  3. Retrieving a List of Predicates
  4. Retrieving a List of Graph Names
  5. Adding a New Graph Type
  6. Retrieving a List of Statuses
  7. Initializing a Status
  8. Retrieving a List of Terminals
  9. Stepping Forward in the Graph
  10. Closing the VPM Session

[Top]

Initializing the VPM Session

1. Open a new VPM session.

    VPMSession *pSession = VPMSession::OpenSession();
    if (NULL == pSession)
    {
        cout << "Failed to Open Session." << endl;
	return 1;
    }
    cout << "Open Session successful." << endl;  

...

Use the OpenSession static method of VPMSession in order to open a new VPM session.

[Top]

2. Create a new login session.

...
    const int netWorkCommunication = 1;
    CATIVpmLoginSession_var spLogSession = NULL_var;
    HRESULT rc = pSession -> CreateLoginSession("MySelf",
	                                        "MyEncodedPsswd", 
	   				        "MyRole",
	   	                                netWorkCommunication, 
						spLogSession);
    if(FAILED(rc))
    {
	cout << "Failed to get Login." << endl;
        VPMSession::CloseSession();
        return 2;
    }
    cout << "Login successful." << endl;  	

...

In order to create a new login session, use the CreateLoginSession method of VPMSession. This method is used to get the login session corresponding to a specific user or to create one if none exists. The input arguments are:

The method returns a CATIVpmLoginSession smart pointer to the login session. This is the entry point for all user dependant actions: once a pointer to this interface has been obtained, it is assumed that the user has been authenticated and that the implementation of the interface keeps track of the user's permissions.

[Top]

Retrieving the Graph and Administration Managers

1. Retrieve the Graph Manager.

...
    cout << "Retrieve the factory manager." << endl;
    CATIVpmFactoryManager_var spFactoManager = NULL_var;
    rc = pSession -> GetVPMObjectFactory(spFactoManager);
    if(FAILED(rc))
    {
	cout << "Failed to get Factory Manager."<< endl;
	VPMSession::CloseSession();
	return 3; 
    }
    cout << "Factory manager retrieved: OK" << endl;

    CATUnicodeString domain ("APLECO");
    CATIContainer_var spC1;
    rc = pSession -> SeekContainer(domain,
	                           spC1); 
    if(FAILED(rc))
    {
	cout << "Failed to retrieve domain container." << endl;
	VPMSession::CloseSession();
	return 4;
    }
    cout << "Domain container retrieved: OK" << endl;
		 
    //  Construct rules from domain container
    CATIVpmObjectRules_var spRules(spC1);

    //  Retrieve the factory manager
    CATIVpmGraphMng_var spGraphMng = spFactoManager -> GetGraphManager("ENOVIA_ECO_Release_Routine",
	                                                               spRules);
    if (spGraphMng == NULL_var)
    {
	cout << "Failed to retrieve graph manager." << endl;
	VPMSession::CloseSession();
	return 5;
    }	
    cout << "Graph manager retrieved: OK " << endl;
...    

In order to retrieve the Graph manager, it is first of all necessary to retrieve a Factory manager. This is done using the GetVPMObjectFactory method of VPMSession. This method returns a CATIVpmFactoryManager smart pointer. Then, it is also necessary to retrieve a domain container. In this case, the domain used is "APLECO". Retrieve the domain container using the SeekContainer method of VPMSession. This method returns a CATIContainer smart pointer from which we can retrieve a CATIVpmObjectRules smart pointer which is a necessary input argument to the GetGraphManager method of CATIVpmFactoryManager. This method returns a CATIVpmGraphMng smart pointer to the Graph named "ENOVIA_ECO_Release_Routine".

[Top]

2. Retrieve the Graph Administrator.

...
    //  Construct the graph administrator from the graph manager
    CATIVpmGraphAdministrator_var spGraphAdmin(spGraphMng);
	
    if (spGraphAdmin == NULL_var)
    {
	cout << "Failed to create graph administrator." << endl;
	VPMSession::CloseSession();
	return 6;
    }	
    cout << "Graph administrator created: OK " << endl;
...

A CATIVpmGraphAdministrator smart pointer is constructed from the CATIVpmGraphMng smart pointer.

[Top]

Retrieving a List of Predicates

...
    CATLISTV(CATBaseUnknown_var) listOfPredicates;
	
    rc = spGraphAdmin -> GetListOfPredicats(listOfPredicates);
	
    if(FAILED(rc))
    {
	cout << "Failed to retrieve list of predicates. " << endl;
	VPMSession::CloseSession();
	return 7;
    }
    cout << "Retrieved list of predicates: OK " << endl;

    int nbPred = listOfPredicates.Size();
    cout << "Number of predicates found = " << nbPred << endl;

    for (int p =1; p <= nbPred; p++)
    {
	CATIVpmGraphPredicat_var spPred = listOfPredicates[p];
	CATUnicodeString predName;
	rc = spPred -> GetName(predName);	
	if(FAILED(rc))
        {
	    cout << "Failed to retrieve predicate name. " << endl;
	    VPMSession::CloseSession();
	    return 8;
	}
	char *pPredName = (char*) predName.ConvertToChar();
	cout << "Predicate Name " << p << ": " << pPredName << endl;
    }

...

In order to retrieve a list of Graph predicates, use the GetListOfPredicats method of CATIVpmGraphAdministrator. This method returns a list of CATBaseUnknown pointers. For each of these pointers, a CATIVpmGraphPredicat smart pointer is retrieved. Then, using the GetName method of CATIVpmGraphPredicat, each predicate's name can be retrieved and printed out. Here is a partial trace resulting from the above code:

Number of predicates found = 93
Predicate Name 1: Affected_Object
Predicate Name 2: Action>AFLParent
Predicate Name 3: Action>AFLParent|Action_Design
Predicate Name 4:
Predicate Name 5: FOUND_OBJECTS
...
Predicate Name 91: MIMEtype
Predicate Name 92: AddSheet
Predicate Name 93: MIMEtype

[Top]

Retrieving a List of Graph Names

...
    CATLISTV(CATUnicodeString) listOfGraph;
    rc = spGraphMng -> GetListOfGraphName(listOfGraph);
    if(FAILED(rc))
    {
	cout << "Failed to retrieve a list of graph names." << endl;
	VPMSession::CloseSession();
	return 9;
    }
    cout << "Retrieved list of graph names: OK " << endl;
	
    for(int loop=1; loop<=listOfGraph.Size(); loop++)
    {
	CATUnicodeString curGraph = listOfGraph[loop];
	char *pCurGraph = (char*) curGraph.ConvertToChar();
	cout << "Graph Name: " << loop << " " << pCurGraph << endl;
    }

...

Use the GetListOfGraphName method of CATIVpmGraphMng in order to retrieve a list of Graph names. Then, print out each name retrieved. Here is a partial example of the trace produced by the above code:

Graph Name: 1 ACTIONCONDFAIL
Graph Name: 2 AFLTESTCOMMAND
Graph Name: 3 AFLTESTCONDFILTER
Graph Name: 4 AFLTESTFILTER
Graph Name: 5 AFLTESTFIND
...
Graph Name: 59 ODTGraph1
Graph Name: 60 ODTGraph2
Graph Name: 61 VPMDocumentRevisionECO_V_status
Graph Name: 62 VPMDocumentRevision_V_status
Graph Name: 63 VPMDocumentRevision_V_status1
Graph Name: 64 VPMObject_V_status

[Top]

Adding a New Graph Type

...
    rc = spGraphMng -> PutGraphType("ENOVIA_ECO_status");
	
    if(FAILED(rc))
    {
	cout << "Failed to add a new graph type." << endl;
	VPMSession::CloseSession();
	return 10;
    }
    cout << "New graph type added: OK " << endl;

...

Use the PutGraphType method of CATIVpmGraphMng in order to add a new Graph type called "ENOVIA_ECO_status".

[Top]

Retrieving a List of Statuses

...
    CATLISTV(CATUnicodeString) listOfStatus;
	
    rc = spGraphMng -> GetListOfStatus(listOfStatus);
	
    if(FAILED(rc))
    {
	cout << "Failed to retrieve the list of statuses." << endl;
	VPMSession::CloseSession();
	return 11;
    }
    cout << "List of statuses retrieved: OK " << endl;
	
    for(int s=1; s<=listOfStatus.Size(); s++)
    {
	CATUnicodeString curStat = listOfStatus[s];
	char *pCurStat = (char*)curStat.ConvertToChar();	
	cout << "Status " << s << ": " << pCurStat << endl;
    } 
...

Use the GetListOfStatus method of CATIVpmGraphMng in order to retrieve a list of Graph transition statuses. Then, print out each status retrieved. Here is a partial example of the trace produced by the above code:

Status 1: Proposed
Status 2: Prerelease
Status 3: Release
Status 4: Rejected

[Top]

Initializing a Status

...
    CATUnicodeString initStatus, newStatus, curStatus;

    rc = spGraphMng -> Init(initStatus);
	
    if(FAILED(rc))
    {
	cout << "Failed to initialize status.  " << endl;
	VPMSession::CloseSession();
	return 12;
    }
    cout << "Initialize Status: OK " << endl;
	
    char *pInitStatus = (char *) initStatus.ConvertToChar();
    cout << "Init Status: " << pInitStatus << endl;

...        

The Init method of CATIVpmGraphMng returns a CATUnicodeString containing the first status of the transition. Here is the trace of the retrieved status that is printed out:

Init Status: Proposed

[Top]

Retrieving a List of Terminals

...
    CATLISTV(CATUnicodeString) listOfTerm;
	
    rc = spGraphMng -> GetListOfTerminals(initStatus, listOfTerm);
	
    if(FAILED(rc))
    {
	cout << "Failed to retrieve a list of terminals." << endl;
	VPMSession::CloseSession();
	return 13;
    }
    cout << "List of terminals retrieved: OK " << endl;
	
    for(int x=1; x<=listOfTerm.Size(); x++)
    {
	CATUnicodeString curTerm = listOfTerm[x];
	char *pCurTerm = (char*) curTerm.ConvertToChar(); 
	cout << "Terminal " << x << ": " << pCurTerm << endl;
    
    }
 
...

The GetListOfTerminals method of CATIVpmGraphMng is used to retrieve a CATUnicodeString list of terminals corresponding to the initial status that was retrieved in the previous section. Then, each terminal in the list is printed out. Here is a trace produced by the code above:

Terminal 1: nls_promote
Terminal 2: nls_reject

[Top]

Stepping Forward in a Graph

...
    rc = spGraphMng -> StepForward(initStatus, 
	                           "nls_promote",
				   newStatus);
	
    if(FAILED(rc))
    {
	cout << "Failed to step forward, nls_promote not found." << endl;
    }
    cout << "Step Forward (nls_promote): OK " << endl;
	
    char *pNewStatus = (char*) newStatus.ConvertToChar();
    cout << "New Status: " << pNewStatus << endl;
	
    curStatus = newStatus;
	
    rc = spGraphMng -> StepForward(curStatus, 
	                           "nls_promote",
				   newStatus);
	
    if(FAILED(rc))
    {
	cout << "Failed to step forward, nls_promote not found." << endl;
    }
    cout << "Next Step Forward (nls_promote): OK " << endl;
	
    pNewStatus =  (char*) newStatus.ConvertToChar();
    cout << "New Status: " << pNewStatus << endl;

...

Use the StepForward method of CATIVpmGraphMng in order to step forward in the Graph. This method takes the following arguments:

We step forward twice in the Graph, the second time using the transition status retrieved from the first. Here is the trace produced by the above code:

Step Forward (nls_promote): OK
New Status: Prerelease
Next Step Forward (nls_promote): OK
New Status: Release

[Top]

Closing the VPM Session

...
    rc = pSession -> CloseSession();
    if (FAILED(rc))
    {
	cout << "Close Session failed.  " << endl;
	return 14;
    }
    cout << "Close Session successful. " << endl;
 	
    return 0;

Close the session using the CloseSession method of VPMSession. Then return a 0 value for a successful completion.

[Top]


In Short

This use case has illustrated how to use VPM Graph functionalities through the CATIVpmGraphMng and CATIVpmGraphAdministrator interfaces of the VPMInterfaces framework. It shows how to retrieve a Graph manager and a Graph administrator and how to retrieve Graph predicates, names, lists of statuses and terminals. It also shows how to add a new Graph type and how to initialize a transition status and use it to step forward in a Graph.

[Top]


References

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

History

Version: 1 [December 2001] Document created
[Top]

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