3D PLM PPR Hub Open Gateway

Knowledge Modeler

Creating and Managing Relations

How to manipulate formulas, rules and checks
Use Case

Abstract

This article explains how to create relations such as formulas, rules and checks.


What You Will Learn With This Use Case

In these use cases, you will learn how to:

[Top]

A Reminder about Relations

There are three types of relations: the formulas, the rules and the checks. Relations as well as parameters are created by the appropriate services of the CATICkeParmFactory object. A relation is described by the CATICkeRelation interface which allows you to manage the relation activity, hide or make a relation reappear in the specification tree, add, remove or replace a parameter in the relation expression. The expression, i.e. the body of a relation is described by the CATICkeRelationExp interface. This article illustrates how to use very simply the most common services provided by CATICkeRelation and CATICkeRelationExp interfaces.

[Top]

The CAALifRuleCheck Use Case

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

[Top]

What Does CAALifRuleCheck Do

This use case creates a rule and a check and retrieves the expression or body of a relation.

[Top]

How to Launch CAALifRuleCheck

To launch CAALifRuleCheck, you will need to set up the build time environment, then compile CAALifRuleCheck 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]

Where to Find the CAALifRuleCheck Code

The CAALifRuleCheck use case is made of the CAALifRuleCheck.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]

Step-by-Step

The CAALifRuleCheck is divided into four steps:

  1. Creating a Rule
  2. Displaying the Rule Body
  3. Checking a Rule
  4. Creating a Check

[Top]

Creating a Rule

  1. The parameters required for the purpose of the rule are created as well as the parameter list which is to be passed as the argument 5 of the creation method. If need be, refer to the explanations given above for the formula sample.
  2. The "rel1" rule is created.
    // Create a rule
      CATICkeRelation_var 
        spRule1 = spFact->CreateProgram ("rel1",
                                             "",
                                             "",
                                          &list,
           "if (a1 > 9 m) \n {a4 = a1*a2*a3} \n else {a4 = 100*a5*a2}",
                                    NULL_var, CATCke::False);

    The whole string passed in the argument 5 should be declared as one statement line (you cannot break the string between quotes in your C++ code). To specify a new line in the rule body, use the \n character.

    If the syntax of your rule/check is wrong, the CreateProgram/Check method returns NULL_var, but this only applies to expressions declared with the 'ai' notation.

    The rule which would be displayed as:

    If (Width > 9 m)
      {v=Width*Length*Height}
    else
      {v=100*surface*Length}

    in the rule editor, is specified as "if (a1>9m)\n {a4=a1*a2*a3}\n else {a4 = 100*a5*a2}" in the CreateProgram method.

[Top]

Displaying the Rule Body

The CATICkeRelationExp::Body allows you to display the expression making up the rule body. You must specify '1' as the first argument value, if you want to re-calculate the expression. In an application, it is recommended to recalculate the expression since parameter names and values are subject to changes.

[Top]

Checking the Rule

The "Width" parameter is modified by using the CATICkeParm::Valuate method. The first part of the rule is no longer valid and the else statement is applied.

[Top]

Creating a Check

The 'Ch1' check is created. The check which would be displayed as: Length > Width in the check editor is specified as a2 > a3 in the CreateCheck method. Replacing the check body with a2 - a3 results in a syntax error. If you are using the ai notation, NULL_var is returned by the CreateCheck method and the following message is displayed in the standard output:
"The check cannot be created"

// Create a check                          
  CATICkeRelation_var 
  check1 = fact->CreateCheck ("rel2","","",&list,"a2 > a3",NULL_var,CATCke::False);

If need be, to manage the rule and check activity after an expression has been modified, you can proceed exactly as explained in the formula sample.

[Top]


In Short

The following programming steps are typically required when writing relations:

  1. Create the parameter list to be passed as the argument 5 of the CreateFormula/Program/Check
  2. Create the formula itself. Using the ai notation is strongly recommended to get rid of NLS problems. If the ai notation method is used and the expression syntax wrong, the creation method returns NULL_var.
  3. Modify the relation by using the CATIRelationExp::Modify method. Beware that modifying the body of relation deactivates this relation.

[Top]


References

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

History

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

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