3D PLM PPR Hub Open Gateway |
Knowledge Modeler |
Creating and Manipulating FormulasHow to do some basic operations with formulas |
Use Case |
AbstractThis article explains how to create, modify, and display formulas. To keep up with the material presented in this article, it is better if you have a prerequisite knowledge of formulas from an end user point of view. If need be, refer to the Knowledge Advisor User's Guide. |
In this use case, you will learn how to:
[Top]
CAALifFormula is a use case of the CAALiteralFeatures.edu framework that illustrates KnowledgeInterfaces framework capabilities.
[Top]
The CAALifFormula use case:
Reminder
The ExtractForm:ProjectKey=ModuleName.Extract(0,6) notation the one used to display a formula in the specification tree. ExtractForm is the formula name, ProjectKey is the parameter to be constrained by the formula, ModuleName is the parameter the Extract method applied to.
In this article, we use the same notation as in the specification tree.
[Top]
To launch CAALifFormula, you will need to set up the build time environment, then compile CAALifFormula along with its prerequisites, set up the run time environment, and then execute the use case which main program is CAALifRelationMain. This program encompasses two use cases [1].
[Top]
The CAALifFormula use case is made of CAALifFormula.cpp file located in the CAALifRelations.m module of the CAALiteralFeatures.edu framework:
Windows | InstallRootDirectory\CAALiteralFeatures.edu\CAALifRelations.m\ |
Unix | InstallRootDirectory/CAALiteralFeatures.edu/CAALifRelations.m/ |
where InstallRootDirectory
is the directory where the CAA
CD-ROM is installed.
The main program related to this file is CAALifRelationMain.
[Top]
CAALifFormula is divided into seven steps:
[Top]
Three parameters are created [2] [3]. Note that in a usual application, these parameters are already created. You just have to retrieve them and append them within a list.
The CATParmDictionary::VisibleParms method can be used to retrieve list of parameters below a published feature.
... // ------------------------- // 1 - Create the parameters // ------------------------- // Create the "ModuleName" parameter // Initial value = "CAALifRelations" CATICkeParm_var spString1=spFact->CreateString("ModuleName","CAALifRelations"); // Create the "ProjectKey" parameter // No initial value specified CATICkeParm_var spString2=spFact->CreateString("ProjectKey",""); // Create the "Topic" parameter // Initial value is "Formulas" CATICkeParm_var spString3=spFact->CreateString("Topic","Formulas"); ... |
[Top]
Before creating a formula or any other relation, you must create a parameter list containing at least, all the parameters to be used in the formula. The parameter to be constrained by the formula and the parameters used as the arguments in the formula expression must be appended to the list.
Note that you can create a list with more parameters that required.
Objects can be appended in any order but you should bear in mind that the order they are declared in the list (that is their rank) is reused when you create the formula.
... // ----------------------------- // 2 - Create the parameter list // ----------------------------- // Create the parameter list CATCkeListOf(Parm) pList; // Append ModuleName to the created list pList.Append (spString1); // a1 = "ModuleName" // Append ProjectKey to the created list pList.Append (spString2); // a2 = "ProjectKey" // Append Topic to the created list pList.Append (spString3); // a3 = "Topic" ... |
If you modify the parameter list, pay attention to the relations which rely on this parameter list.
[Top]
The CATICkeParmDictionary::CreateFormula method allows you to create a formula. The formula created specifies that the ProjectKey parameter equals the first six characters of the ModuleName parameter value.
The formula which would be displayed
// ------------------------------------------------------------- // 3 - Create the ExtractForm formula which extracts // the first six characters from the ModuleName parameter // ------------------------------------------------------------- CATICkeRelation_var spFormula1 = spFact->CreateFormula ("ExtractForm", "", "", spString2, &list, "a1.Extract(0,6)", NULL_var, CATCke::False); |
Here is the description of the arguments:
If the syntax of the formula expression is wrong, the CreateFormula method returns NULL_var.
[Top]
The expected value for ProjectKey parameter is CAALif. To check this value, we use the CATICkeInst::AsString method.
... // ------------------------------------------------------------- // 3 - Retrieving and displaying the new ProjectKey value // ------------------------------------------------------------- cout << "The ProjectKey value is: " ; cout << (spString2->Value()->AsString()).CastToCharPtr() << endl; ... |
At run-time, the statements above display in the standard output the message below:
The ProjectKey value is: CAALif
[Top]
The CATICkeRelationExp::Modify method is to be used to modify the expression of a formula. Note that modifying a formula deactivates it. If you display the value of the constrained parameter before the relation has been reactivated, you don't get the new value.
... // ------------------------------------------------ // 4 - Modify the formula // Replace a1.Extract(0,6) with a3.Extract(0.5) // ------------------------------------------------ CATICkeRelationExp_var spExpform = spFormula1 ; spExpform->Modify(&list,"a3.Extract(0,5)", NULL_var, CATCke::False); |
Here is the description of the arguments:
[Top]
A formula which is modified is deactivated. We check that ExtractForm is no longer active.
... // ------------------------------------------------ // 5 - Test the formula activity // ------------------------------------------------ cout << spFormula1->IsActivated() << endl; ... cout << "The ProjectKey value is: " ; cout << (spString2->Value()->AsString()).CastToCharPtr() << endl; |
At run-time, the statements above display in the standard output the messages below
0 The ProjectKey value is: CAALif
[Top]
The CATICkeRelation::Activate() method allows you to reactivate a formula which has just been modified (this also applies to rules and checks).
... // ------------------------------------------------ // 6 - Re-activate the formula // ------------------------------------------------ spFormula1->Activate(); cout << "The ProjectKey value is: " ; cout << (spString2->Value()->AsString()).CastToCharPtr() << endl; |
At run time, the statements above display in the standard output the messages below:
The ProjectKey value is: Formu
[Top]
The following programming steps are typically required when writing formulas:
[Top]
[1] | Building and Launching a CAA V5 Use Case |
[2] | Using Persistent Parameters |
[3] | Using Volatile Parameters |
[Top] |
Version: 1 [Jan 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.