3D PLM PPR Hub Open Gateway

Knowledge Modeler

Test Your Integration with the Knowledge Language

A very basic application manipulating user types, methods and Objects

Use Case

Abstract

This article discusses the CAALifTestIntegrateKnowledge use case. If you have done what is necessary to integrate some of your applicative types, object and functions [1], you will be able to use them in the Knowledge language and to look at them in the Search functionality.

But At first time, you may want to test your integration. This is what illustrates this use case: how to manipulate your applicative objects and user functions.


What You Will Learn With This Use Case

This use case is intended to show you how to manage user types, objects and functions in order to test that your integration to Knowledge language is correct.

[Top]

The CAALifTestIntegrateKnowledge Use Case

CAALifTestIntegrateKnowledge is a use case of the CAALiteralFeatures.edu framework that illustrates KnowledgeInterfaces framework capabilities.

[Top]

What Does CAALifTestIntegrateKnowledge Do

CAALifTestIntegrateKnowledge gives you a feel of how you can load a package and search types in it. Then it instanciates a feature from a startup CAALifFeatureScrew and valuates its 3 parameters length attributes. Then from this feature, we get a handler on the interface CATIInstance  in order to manipulate this object through the user view which has been defined in the context of the technical article [1].

The implementation of the object user view is located in the CAALifIntegrateKnowledge library. It contains a package DotItYourself, 2 types Screw and Bolt with their attributes and a user method calculating the volume of a screw.

[Top]

How to Launch CAALifTestIntegrateKnowledge

To launch CAALifTestIntegrateKnowledge, you will need to set up the build time environment, then compile CAALifTestIntegrateKnowledge along with its prerequisites, set up the run time environment, and then execute the use case [2] . To Launch the use case execute the command:

mkrun -c CAALifTestIntegrateKnowledge

[Top]

Where to Find the CAALifTestIntegrateKnowledge Code

The CAALifTestIntegrateKnowledge use case is made of a source file named CAALifTestIntegrateKnowledge.cpp located in the CAALifTestIntegrateKnowledge.m module of the CAALiteralFeatures.edu framework:

Windows InstallRootDirectory\CAALiteralFeatures.edu\CAALifTestIntegrateKnowledge.m\
Unix InstallRootDirectory/CAALiteralFeatures.edu/CAALifTestIntegrateKnowledge.m/

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

The use case is running thanks to the library CAALifIntegrateKnowledge, which code is located in the CAALifIntegrateKnowledge.m module of the CAALiteralFeatures.edu framework.

[Top]

Step-by-Step

The main steps if CAALifTestIntegrateKnowledge are:

  1. Prolog
    This step creates a session, a Part document, open a given catalog and retrieves from the catalog a startup CAALifFeatureScrew in order to instanciate a feature Screw.
  2. Loading a package and getting types
    This step activates the package DoItYourself in the session to make its associated types available.
  3. Creating an object Screw
    This step instanciates a feature Screw and valuates its attributes with 3 parameters.
  4. Manipulating the object with CATIInstance
    This step creates a handler of the Screw on the interface CATIInstance and uses its services.
  5. Listing methods in a package and evaluate a user function
  6. Epilog
    This step closes the document and the session.

[Top]

Prolog

Before going any further, you must initialize your environment.

This task consists in:   

CAALifServices CAAliteralFeaturesServices; 
...
HRESULT rc = CAAliteralFeaturesServices.CAALifInitSession ();
CATIContainer* piContainer = NULL; 

...
rc = CAAliteralFeaturesServices.CAALifCreateInstanceContainer(&piContainer);
CATICatalog* piCatalog = NULL;
...
rc = CAAliteralFeaturesServices.CAALifOpenCatalogFromContainer(piContainer,"CAA2_CAALifFeatCatalog.CATfct",&piCatalog);
CATUnicodeString startupType( "CAALifFeatureScrew" ); 
CATISpecObject* piStartupFeat = NULL; 
...
rc = CAAliteralFeaturesServices.CAALifRetrieveStartupFromCatalog(piCatalog, startupType,&piStartupFeat); 

    The CAALifFeatureScrew startup has been created thanks to the CAALifCreateStartUps method of the CAALifFeatureCatalog class defined in the CAALifFeatureCatalog.m module.

[Top]

Loading a Package and Getting Types

To manage packages and types use the CATITypeDictionary interface which is dedicated to accessing the unique dictionary of types shown to the user. To retrieve a smart pointer on it, you can use the static GetTypeDictionary method of the CATGlobalFunction class of KnowledgeInterfaces.

The method LoadPackage load the package which name is given in argument if it isn't already done. The loading process is described in the corresponding technical article [1].

   ...
  CATITypeDictionary_var dico = CATGlobalFunctions::GetTypeDictionary();
  CATUnicodeString package_name = "DoItYourself";
  rc = dico->LoadPackage(package_name);
  ...	

You can access types from different manners:

    ...
  CATListValCATIType_var listTypes;
  dico->ListTypesForPackage(package_name,listTypes,0);
  ...

or

    ...
  CATIType_var ScrewType;
  rc = dico->FindType("Screw",ScrewType);
  ...

[Top]

Creating an Object Screw

First, we instanciate a feature from its startup.

CATISpecObject* ScrewObj = piStartupFeat->Instanciate ("my_screw_obj",piContainer);

Then, we valuate the attributes of this instance. In the following code we valuate the attribute "ScrewLength" of ScrewObj with a parameter of type length length_parm:

  ...
  CATICkeParm_var length_parm = ...
  ...
  CATISpecAttrAccess * piSpecAttrAccessOnScrewLength = NULL; 
  rc = ScrewObj->QueryInterface(IID_CATISpecAttrAccess, (void**) & piSpecAttrAccessOnScrewLength);
  if ( SUCCEEDED(rc) ) 
  { 
    CATISpecAttrKey * piSpecAttrKeyOnScrewLength = NULL; 
    piSpecAttrKeyOnScrewLength = piSpecAttrAccessOnScrewLength->GetAttrKey("ScrewLength");

    if ( NULL != piSpecAttrKeyOnScrewLength )
    {
      piSpecAttrAccessOnScrewLength->SetSpecObject(piSpecAttrKeyOnScrewLength,length_parm);
      piSpecAttrKeyOnScrewLength->Release();
      piSpecAttrKeyOnScrewLength = NULL;
    }
  }
  piSpecAttrAccessOnScrewLength->Release();
  piSpecAttrAccessOnScrewLength = NULL;

  ...

Top]

Manipulating the Object with CATIInstance

= Now that we have a feature object (it could have been a C++ object too), we want to see it through the user view which has bee defined on purpose. For That we have to get a handler on the CATIInstance interface for our "Screw".

 

  
  CATIInstance* piInstance = NULL;
  rc = ScrewObj->QueryInterface(IID_CATIInstance, (void**) &piInstance);

= Let's check the type of the object. It must be a "Screw".

  
  CATIType* TypeInDico = piInstance->Type(); 
  ...
  CATUnicodeString TypeName = TypeInDico->Name();
  if (TypeName != "Screw")
 	...

 Is it in the correct package DoItYourself ?

  
  CATIType_var TypeInPackage = NULL_var;
  rc = dico->FindTypeInPackage(TypeName,package_name,TypeInPackage);
  ...

 

= To manipulate the attributes of this instance, there are 2 methods GetValue and SetValue which manipulate CATIValue.

This interface is a union of different types of object. It can be values (parameters) or features (in features, we include List of features).

To Get an attribute "ScrewLength" containing a length value do it this way:

  CATIValue_var value = piInstance->GetValue("ScrewLength");
  if (value != NULL_var)
  {
    value->Release(); 

    if (value->AsReal() != 5.0)
    	...
    
  }

The method GetValue of CATIInstance takes in argument the name of the wanted attribute which has been defined in the object user user view. It returns a CATIValue*. Consequently, the smart pointer value has to be released once. In this example, the value of the attribute is a parameter length and it can be directly accessed with the method AsReal of CATIValue. Then we check that the numerical value returned by the GetValue method is correct.

To Get an attribute "CenterPoint" containing a feature point do it this way :

  ...
  value = piInstance->GetValue("CenterPoint");
  if (value != NULL_var)
  {
    value->Release();

    CATIGSMPointCoord_var point = NULL_var;

    point = value->AsObject();
    //test of the point coordinates
  }
  ...

In the following example, the CATIValue  is a feature which we access with the method AsObject of CATIValue.

To Set an attribute "ScrewLength" with a length value do it this way:

  ...
  CATICkeParmFactory_var VolFactory = CATCkeGlobalFunctions::GetVolatileFactory();
  if(VolFactory == NULL_var) ...

  rc = piInstance->SetValue("ScrewLength", VolFactory->CreateLength("L1",15.23));
 
  ...

To Set an attribute "CenterPoint" with a feature point do it this way:

  ...
  piInstance->SetValue("CenterPoint", VolFactory->CreateObjectReference(GSMPt));
  ...

The methods CreateObjectReference or CreateLength of the volatile factory VolFactory, create a temporary CATIValue handle on your feature point or on a numerical value, just to give it in argument to the SetValue method.

Remark: The code to manage feature attributes will be available in a use case of Mechanical Modeler from a future Service Pack of the V5R14.

 

[Top]

Listing Methods in a package

Let's check the existence of the user function which has been defined in the package CATPackageMethodDoItYourself in the library CAALifIntegrateKnowledge [1].

First, we list the user functions and methods of the package.

  CATListValCATBaseUnknown_var listOfSignatures;
  rc = dico->ListMethodsForPackage("CATPackageMethodDoItYourself", listOfSignatures);
  if (SUCCEEDED(rc))
  {

    int nbOfMethods = listOfSignatures.Size();
    ...
    CATICkeSignature_var aSignature;
    CATUnicodeString name;
    for (i=1;i<=nbOfMethods ;i++)
    {
    	aSignature = listOfSignatures[i];
    	name = aSignature->Name();
	...

Then we create a formula to test the evaluation of the user function EvaluateScrewVolume : volume = EvaluateScrewVolume(My_Screw).

In the following code, spVolume is a parameter which will be valuated by the new formula. ScrewObj is the SpecObject result of the instanciation of the startup CAALifFeatureScrew. ScrewParm is the transformation of ScrewObj in a parameter.

  
    CATICkeParm_var spVolume = ...;

    CATICkeParm_var ScrewParm = VolFactory->CreateObjectReference(ScrewObj);

    CATCkeListOf(Parm) pParamList;
    pParamList.Append (spVolume); 
    pParamList.Append (ScrewParm);

    CATICkeRelation_var spFormula = piFact->CreateFormula ("VolumeFormula",
                                                           "",
                                                           "", 
                                                           spVolume, 
                                                           &pParamList,
                                                           "EvaluateScrewVolume(a2)",
                                                           NULL_var,
                                                           CATCke::False);
  ...

To run the user function, change an attribute of the screw and evaluate the formula.

  ...
  spFormula->SetNotUpdated(ScrewParm);
  spFormula->Evaluate();
  ...

Epilog

  ...
  rc = services.CAALifCloseSession();
  return rc;
}

The CAALifCloseSession method of the CAALifServices class defined in the CAALifBasis.m module removes the Part document and deletes the session.

[Top]


In Short

The Knowledgeware allows to integrate your own types, objects, functions or method in oder to create a simplified user view of your data.

For that, you have to create a few ressources files and to implement the interfaces CATIAddTypeLibrary, CATICreateInstance and CATIInstance.

Afterwards, your object user view will be accessible in the Search functionality and  understood in the Knowledge language.

 

[Top]


References

[1] Technical Article - Knowledge Language Integration
[2] Building and Lauching CAA V5 Samples
[Top]

History

Version: 1 [Nov 2003] Document created
[Top]

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