3D PLM PPR Hub Open Gateway |
Knowledge Modeler |
Using Persistent ParametersHow to create and modify persistent parameters |
Use Case |
AbstractThis 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. |
In this use case, you will learn how to create and modify parameters of simple, dimension and enumerated types.
[Top]
CAALifParametersPersistent is a use case of the CAALiteralFeatures.edu framework that illustrates KnowledgeInterfaces framework capabilities.
[Top]
The CAALifParametersPersistent use case is divided into five parts:
[Top]
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]
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]
CAALifParametersPersistent is divided into five steps:
[Top]
Simple type parameters are integers, reals, strings or booleans.
To create a simple type parameter, you should use one of the methods below:
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.
There are three methods to retrieve and display a parameter value whatever its type:
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]
They are created by the following methods:
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); ... |
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]
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]
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:
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"); |
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); |
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.
To modify the value of an enum, you must use
or the CATICkeParm::Valuate method and specify in the argument the object to be assigned to the enum.
... // 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]
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]
[1] | Building and Launching a CAA V5 Use Case |
[2] | Getting Started with Literal Programming |
[3] | About Units |
[Top] |
Version: 1 [Jan 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.