3D PLM PPR Hub Open Gateway

Knowledge Modeler

Using Persistent Parameters

How to create and modify persistent parameters

Use Case

Abstract

This article explains how to create and manage persistent parameters, i.e., literals that you can save in a permanent binary form (a CATPart document for example) that persists after they are deleted from memory. Later you can load the persistent objects from persistent storage and reconstruct them in memory.


What You Will Learn With This Use Case

In this use case, you will learn how to create and modify parameters of simple, dimension and enumerated types.

[Top]

The CAALifParametersPersistent Use Case

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

[Top]

What Does CAALifParametersPersistent Do

The CAALifParametersPersistent use case is divided into five parts:

  1. Creating and managing simple type parameters
    1. creates four simple type parameters:
      • intParam - which is an integer with an initial value of  2
      • realParam - which is a real with an initial value of 2.3
      • stringParam - which is a string with an initial value of "Bonjour"
      • booleanParam - which is a boolean with an initial value of true (CATCke::True).
    2. displays the name and the value of each simple type parameter.
    3. modifies each simple type parameter
  2. Creating and managing length and angle parameters
    1. creates two dimension type parameters:
      • lengthParam - which is a length with an initial value of  2
      • angleParam - which is an angle with an initial value of 3.1416
    2. displays the name and value of each dimension type parameter.
  3. Creating and managing magnitude type parameters
    1. creates one magnitude type parameter
      • volumeParam - which is a VOLUME magnitude with an initial value of 20.5
    2. displays the name and the value of volumeParam
    3. modifies the volumeParam value
  4. Creating and managing enumerated type parameter
    1. creates the ListOfPeople1 enum parameter.
    2. modifies it.

[Top]

How to Launch CAALifParametersPersistent

To launch CAALifParametersPersistent, you will need to set up the build time environment, then compile CAALifParametersPersistent along with its prerequisites, set up the run time environment, and then execute the use case which main program is CAALifParametersMain. This program encompasses several use cases [1].

[Top]

Where to Find the CAALifParametersPersistent Code

The CAALifParametersPersistent use case is made of the  CAALifParametersPersistent.cpp file located in the CAALifParameters.m module of the CAALiteralFeatures.edu framework:

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

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

The main program related to this use case is CAALifParametersMain.

[Top]

Step-by-Step

CAALifParametersPersistent is divided into five steps:

  1. Creating and Managing Simple Type Parameters
  2. Creating and Managing Dimension Type Parameters
  3. Creating and Managing Magnitude Type Parameters
  4. Creating and Managing Enumerated Type Parameters

[Top]

Creating and Managing Simple Type Parameters

Simple type parameters are integers, reals, strings or booleans.

  1. Creating simple type parameters

    To create a simple type parameter, you should use one of the methods below:

    1. CATICkeParmFactory::CreateInteger
    2. CATICkeParmFactory::CreateReal
    3. CATICkeParmFactory::CreateString
    4. or CATICkeParmFactory CreateBoolean.

    Each method takes the parameter name as its first argument, the parameter value as its second argument.

    CATCke::Boolean CAALifParametersPersistent(CATICkeParmFactory_var ispFact)
    {
    // ------------------------------
    // Simple type parameters
    // ------------------------------
    
       // Create a real
       // Parameter name is "realParam", parameter value is 2.3
       CATICkeParm_var spPp2 = ispFact->CreateReal ("realParam",2.3);
       ...
       // Create a boolean
       // Parameter name is "booleanParam", parameter value is CATCke::True
       CATICkeParm_var spPp4 = ispFact->CreateBoolean ("booleanParam",CATCke::True);

    If the second argument of  CATICkeParmFactory::CreateInteger is passed as a real, its is converted to an integer. Likewise, if the second argument of CATICkeParmFactory::CreateReal is passed as an integer, the method converts it to a real.

    The value of a boolean is either CATCke::True or CATCke::False.

  2. Retrieving and displaying parameter values
  3. There are three methods to retrieve and display a parameter value whatever its type:

    1. CATICkeInst::Show which displays the end user view of the parameter value (i.e the parameter value with the units and settings specified in the Tools->Options...->General Units tab).
    2. CATICkeInst::AsType which:
      • either returns the parameter value when the parameter is of the appropriate type
      • or converts the parameter value to a value with the type expected.
        • CATICkeInst::AsInteger converts:
          • a real to an integer
          • a boolean to 0 or 1
          • an enum to its rank
        • CATICkeInst::AsReal converts
          • an integer to a real
          • a boolean to 0 or 1
          • an enum to its rank
    3. CATIParmAsStored::ValueStored which returns the value in model units [3].

    Here is a code extract illustrating how to use these methods.

    ...
    // Display the name and value of realParam
    cout << spPp2->Name().CastToCharPtr() << " value is: " << endl;
    cout << spPp2->Show ().CastToCharPtr()<< " (with CATICkeParm::Show)" << endl ;
    cout << spPp2->Value()->AsReal ()   << " (with CATICkeInst::AsReal)" << endl;

[Top]

Creating and Managing Dimension Type Parameters

  1. Creating length and angle type parameters

    They are created by the following methods:

    1. CATICkeParmFactory::CreateLength
    2. CATICkeParmFactory ::CreateAngle

    The value passed as the second argument should be specified in MKS units, i.e, in meters for a length type parameter and in radians for an angle type parameters.

    ...
    // ------------------------------------------------
    // Dimension type parameters (Length and Angle) 
    // ------------------------------------------------
     
      // Create and display a Length type parameter
      // Parameter name is "lengthParam", parameter value is 2
      CATICkeParm_var spPp5 = ispFact->CreateLength ("lengthParam",2);
      ...
      
      // Create and display an Angle type parameter
      // Parameter name is "angleParam", parameter value is 3.1416
      CATICkeParm_var spPp6 = ispFact->CreateAngle ("angleParam",3.1416);
      ...
    
  2. Retrieving Parameter Values

    The portion of code below

    ...
    // Display the name and value of lengthParam
    cout << spPp5->Name().CastToCharPtr() << " value is: " << endl;
    cout << spPp5->Show ().CastToCharPtr() << " (with CATICkeParm::Show)" << endl ;
    cout << spPp5->Value()->AsReal () << " (with CATICkeInst::AsReal)" << endl;
    
    CATIParmAsStored_var spPps5 = spPp5;
    cout << spPps5->ValueStored() ;
    cout << " (with CATIParmAsStored::ValueStored (in mm)) " << endl;

    displays in the standard output:

    lengthParam value is:
    2 (with CATICkeParm::Show)
    2.0 (with CATICkeInst::AsReal)

[Top]

Creating and Managing Magnitude Type Parameters

Dimension other than lengths and angles are created by using the CATIParmFactory::CreateDimension method.

To create a magnitude type parameter:

...
// ------------------------------
// Magnitude type parameters
// ------------------------------

CATICkeParm_var
  spPp7 = ispFact->CreateDimension(
CATCkeGlobalFunctions::GetParmDictionary()->FindMagnitude("VOLUME"),
                                                 "volumeParam",20.5);

[Top]

Creating and Managing Enumerated Type Parameters

An enumerated type is a user-defined type consisting of a set of named constants called enumerators. By default, the first enumerator has a value of 1, and each successive enumerator is one larger than the value of the previous one.

Here are the steps required to create then modify an enumerated type parameter:

  1. Create the list of objects making up the enumerated type parameter

    In the example above, we create the ListOfPeople enum type which defines the list of strings below:
    enum ListOfPeople {John, Emmanuel, Pierre, Frederic}

    ...
    // ------------------------------
    // Enum type parameters
    // ------------------------------
    
       //  Create the list of items making up the enum
       CATListOfCATUnicodeString pLst;
       pLst.Append("John");
       pLst.Append("Emmanuel");
       pLst.Append("Pierre");
       pLst.Append("Frederic");
    
  2. Create the enumerated type

    You must use CATICkeParmFactory::CreateEnumereType which takes as its first argument the name of the parameter and as its second argument the object list

    ...
    // Create the enumerated type
    CATIEnumere_var 
       spTypeEnumere = ispFact->CreateEnumereType("ListOfPeople",pLst);  
  3. Create the enumerated object itself

    You must use the CATICkeParmFactory::CreateEnumere method which takes as its third argument the object (from the list) to be assigned to the enum parameter.

    ...
    // Create the object of type "ListOfPeople" 
    //     ListOfPeople1 is the object name
    //     Pierre is the value assigned to the enum at creation
    CATICkeParm_var spPp8 = ispFact->CreateEnumere (spTypeEnumere,
                                                   "ListOfPeople1","Pierre");
    cout << spPp8->Value()->AsInteger () << endl; // Returns 3

    Note that the CATICkeInst::AsInteger method returns 3, i.e. the rank of "Pierre" in the enumerated list.

  4. Modify the enum value

    To modify the value of an enum, you must use

    ...
    // Assign the first value of the list to the enum 
    spPp8->Valuate (1);
    cout << spPp8->Name().CastToCharPtr() ;
    cout << " enum new value is (John): " << endl;
    cout << spPp8->Show().CastToCharPtr() << endl;
    cout << spPp8->Name().CastToCharPtr() ;
    cout << " enum new value is (Frederic): " << endl;
    // Assign the "frederic" string to the enum
    spPp8->Valuate ("Frederic");

[Top]


In Short

To create a parameter you must use the CATICkeParmFactory::CreateType appropriate method.

To create a magnitude type parameter:

To modify a parameter, you must use the CATICkeParm::Valuate method.

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[2] Getting Started with Literal Programming
[3] About Units
[Top]

History

Version: 1 [Jan 2000] Document created
[Top]

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