Class child rule and instances

Overview

How To

Options

Related Topics


A child rule is a special attribute that creates an instance of a class. The resultant value is an instance data type. The rule of a child rule is always a list of parameter name and value pairs.

 (child) Ch1: 
{  
  parameter1_name, parameter1_value, 
parameter2_name, parameter2_value,
parameter3_name, parameter3_value, };

It's customary, but not necessary, to organize them into columns as shown above.

At least one parameter name must be a class, followed by the name of the class to be instantiated. It is customary, but not necessary for class and the class name to be the first pair in the list.

(Child) MP: 
{  
  class, ug_mass_properties,  
features, {block1:, block2:} };

Names and values may be separated by commas or semicolons.

Values can be defined by rules. For example, the child rule below creates an instance of ug_block, or ug_cylinder, or nothing (NullDesign), depending on the value of the attribute named Option.

 (child) Feat2: 
{ 
  class, if Option:=1 then ug_block
  else if Option:=2 then ug_cylinder 
  else NullDesign,  
  Length, TotalLength:, 
   Height, WidgetHeight:,   
Diameter, CylDiameter:,   Wdth,   10 };

If extra or unused parameter name/value pairs are specified, they will be ignored. In the previous example, when the logic selects ug_block, the Diameter parameter is ignored. When logic selects ug_cylinder, the Length parameter is ignored. When logic selects NullDesign, all parameters are ignored. The downside of this flexibility is that misspelled parameter names are also ignored and generate no error message. In the above example, Wdth is misspelled and ignored.

Any value can be defined with a complex rule such as IF statements, loops, or expression blocks. This example swaps components.

(child) Comp2: 
{ 
   class, ug_component,  
  File_Name, if (Option:=1) then "tire1.prt"    
             else "tire2.prt", 
};