[Next] [Previous] [Up] [Top] [Contents] [Index]

Chapter 3 Working With Templates And Color Rules

2. Color Rules


Color rules alert the user to a certain condition at run-time by changing the color of dynamic objects that are modified by the color rule. You configure a color rule by defining conditions and then choosing colors from the display's color table to correspond to each of those conditions. For instance, you might create a color rule that defined three conditions for an analog channel, with blue as the color for the first condition, green as the color for the second, and blue as the color for the third.

A display can have up to eight color rules. Adding and Deleting Color Rules in Chapter 2 explains how to add a color rule to the color rule list. The rest of this section explains how to configure a color rule and how to configure an object to be modified by one. The last section of this chapter gives some useful guidelines regarding the use of color in displays and in color rules.

2.1. Modifying an Object by a Color Rule

To modify an object by a color rule you must do three things in an object's property sheet (See Property Sheets in Chapter 4 for an explanation of property sheets):

1. Set the 'color modifier' property in the object's property sheet to rule. This property may or may not be already set to rule, depending on the 'default color modifier' attribute in the Display Attributes window. If it is set to static, hold down the right mouse button when the property is highlighted and choose rule from the menu that appears.

2. Specify which color rule to use from the color rule list. The color rule list is in a submenu of the display menu. If you bring up the submenu of the modify display option and then the submenu under the color rule option, you will see the list of color rules for the current display, as in Figure 3-3 (the color rules for your displays may be different). Enter in the name of the color rule you wish to use in the 'color rule name' property, in the object's property sheet.

Color Rule List--Menu Expansion.

3. Specify a color rule argument or arguments in the 'color rule arguments' property. Below is an explanation of color rule arguments and how to use them.

A color rule monitors a channel just as any dynamic object does. However, instead of specifying a specific channel, color rules generally use macros. Macros consist of a character string. A color rule can have up to 256 macros. When you modify an object by a color rule, you replace the macro with its expansion, i.e., the name of an actual channel. The channel name does not have to be the same as the channel in the object's 'channel to control or monitor' property (See the section General Characteristics and Properties in Chapters 5, 6, or 7 for an explanation of this property). Conceivably, the object itself could be configured to monitor one channel, yet its color could be modified by the conditions of another channel.

For example, Figure 3-4 shows what the entries for the 'color modifier,' 'color rule name,' and 'color rule arguments' properties might look like in an object's property sheet. In this case, the object is configured to use the alarm color rule. The color rule argument is C=demo:ao1. The letter C is the macro and demo:ao1 is the expansion--i.e., the name of the channel that replaces the macro. Thus, if we looked at the color rule expression in the alarm rule's Color Rule Modify window, the letter C replaces the record name as the channel element. Actually, we would see $(C), because the dollar sign and parentheses are used to set off the macro.

'Color Modifier', 'Color Rule Name' and 'Color Rule Arguments' Properties.

2.2. Configuring a Color Rule

When you choose a color rule from the color rule list, the Color Rule Modify window appears with the information for the color rule. You configure a color rule by changing the information in this window. If you would like to create a new color rule, you must add a color rule to the color rule list and then choose it from the color rule list. Adding and Deleting Color Rules in Chapter 2 explains how to add a color rule to the color rule list.

Figure 3-5 shows the Color Rule Modify window for the alarm rule, the already-configured color rule that comes with EDD. The alarm rule could alert the operator to the exigent condition of a process variable by monitoring the SEVR field of a record. The alarm rule is a very simple one.

The Color Rule Modify window consists of 16 lines, each of which consists of five elements:

1. Channel

2. Comparator

3. Value

4. Connector

5. Color

A line or lines that define one condition is an expression. Potentially, each line can be an expression. However, the connector element of a line allows the line to be connected to the following line to further define a condition, if necessary. Thus, a color rule can have as many as 16 expressions, or as few as one. What follows is an explanation of what each element in a line does, and how they combine to form an expression and thus define a condition. The alarm rule uses three of the 16 lines, and each of the lines defines a separate expression.

Channel

A color rule expression specifies a channel just as a dynamic object does. You specify that channel in the channel element. The channel can be any record or any field within a record, or in a non-EPICS context, it can be any process variable. For EPICS records, when only a record name is specified, the VAL field of that record is used. The expressions in the alarm rule are configured to connect to the SEVR field (severity field) of an EPICS record.

However, if you actually named the channel for the color rule to monitor, that color rule would be limited to monitoring that channel. Instead, color rules generally use macros in place of the record name, so that when an object is configured to use a color rule, you can replace the macro with an actual channel name in the object's 'color arguments' property. You can use macros to substitute for any part of the channel name or its entire name.

A macro consists of a character or character string, distinguished by a dollar sign and parentheses--$(macro_variable). The alarm rule uses only one macro, called C. The way the alarm rule is configured, the C macro is used with the three expressions to define three conditions for the SEVR field.

Comparator

The comparator is simply a relational operator that specifies the condition under which to use the value, the next element of the color rule expression. There are three comparators: (1) less than, (2) greater than, and (3) equals. In the default alarm rule the comparator is equals for all three expressions.

To change the comparator of an expression:

1. Highlight the comparator and hold down the right mouse button on the current comparator. This will bring up a small menu containing all three comparators.

2. Choose the comparator you wish to use.

Value

The value element is simply a possible value of the field specified in the channel element. It can be any string of characters, but it must be a possible value of the channel that is going to be monitored. For an analog channel, it can be a decimal value; for a menu field it can be one of possible choices for that field; and for a binary channel it must match one of the state values or state strings of the field. In the alarm rule, the values for each of the three expressions are strings that match one of the possible menu choices of the SEVR field: MAJOR, MINOR, and INFO. Refer to the EPICS Record Reference Manual for more information on fields, their data types, and the possible choices of menu fields.

Connector

The connector element does several things depending on which connector you use. There are four connectors:

1. Use

2. And

3. Or

4. And not

Use tells the color rule to use the color in the color element of the line, thus ending the definition of the expression. The other connectors join the line with the next line to further specify the condition of the expression, further extending the expression. The logical significance of each of these three connectors is fairly obvious, but a brief summation of each follows:

And
When this expression and the next are true, then. . .

Or
When either this expression is true or the following one is true, then. . .

And not
When this expression is true, and except when the following expression is true, then. . .

The above summaries assume that two lines will be the number of lines to be connected and joined into an expression; however, you can connect all 16 lines into one expression if necessary. When you use any of the other connectors besides use, the color element in that line is ignored. DM uses only color elements appearing after the use connector.

To change the connector:

1. Hold down the right mouse button on the current connector in the expression, which brings up a menu with all four expressions.

2. Choose the connector you wish to use.

Color

The color element is the color that shows up on the display when the condition defined in the expression is met, in which case the color in the color element replaces the foreground color of the object. Only the colors that go after the use connector are actually part of the expression. Colors that go after the and, or, and and not connectors are ignored.

To change the color of an expression:

1. Hold down the right mouse button on the current color. This brings up a menu of the colors available, i.e., the colors in the display's color table.

2. Choose the color you wish to use.

The Color Rule Modify Window.

2.3. More About Expressions
NOTE: At run time DM uses the first true expression, ignoring the other expressions.

This way, it is impossible to have contradicting expressions. If two expressions are true, DM only uses the first expression. For instance, if you were to create a color rule that turns a certain color when an analog channel is less than 50 and another color when the channel is less than 130, the two expressions would be true when the value of the channel is less than 50, in which case DM will only use the first expression, which is the first true expression, while ignoring the second.

Although impossible for two true expressions to contradict each other since only the first true expression is used, it is quite possible for an expression to be incorrect. There are three main errors that cause an expression to be invalid:

1. When the value specified in the 'value' element of the expression is not a possible value for that channel.

2. When two lines joined by the and, or, or and not connectors contradict each other. For instance, the following expression is invalid because both lines of the expression could be true at the same time: It is impossible for a channel to have two values at the same time.

In the above example, the and connector joins the first expression with the second, making them the same expression. DM will not use the first line without the adjoining line when a connector is used.

DM will not notify you that an expression is invalid. It simply treats it as an untrue expression. Thus, you must make sure all the expressions in a color rule are correct before use, and you may want to test them.

2.4. A Color Rule Example

Because there is so much to remember about color rules, let's review all the steps of creating and configuring a color rule by creating one. This color rule will be a simple one--it will define three conditions to be used with an analog channel. Though simple, it will help you to better understand the steps involved in configuring a color rule.

First, add the color rule to the color rule list.

1. Choose edit list from the color rules submenu.

2. In the entry line for the number of color rules, enter in a new number--the sum of the current number plus 1.

3. In the blank entry line that is added to the list of names, enter analog monitor as the name for the new rule.

Now that the color rule is added to the color rule list, you can configure it. When you choose analog monitor from the list, a blank Color Rule Modify Window appears.

Since we want to configure a color rule that defines three different conditions, we will need three different expressions. Because the three conditions are for the same channel, we will need only one macro. Let's use Chan, an abbreviation for channel, as the macro. Because the color rule is intended for an analog channel, all the values used will be numeric.

Let's define the first expression. Let's define it for a condition greater than 0, but less than 50. And as its color, let's use blue.

4. In the channel element of the first line, type $(Chan).VAL.

Here, the dollar sign and parentheses define Chan as a macro. VAL is a real field name found in analog records. (Recall that in EPICS if a field is not specified, the VAL field is meant by default. However, for the sake of clarity, it is included here, which is also acceptable.)

5. Choose the comparator greater than from the comparator list.

6. Enter 0 in the entry line for the value element.

7. For the connector element, choose and from the connector list.

This first line does not itself constitute an expression because we have used the and connector. We can thus ignore the color element of this first line. To finish the definition for this expression, in the second line,

8. Enter $(Chan).VAL in the channel element, choose less than as the comparator, enter 50 as the value element, and choose use as the connector.

9. Because this line completes the definition of the expression, go ahead and choose blue or a bluish color in the color element.

Now, lets define the second expression for a condition greater than 49 but less than 150 and choose green as its corresponding color. The expression will use two lines.

10. For the first line, enter $(Chan).VAL in the channel element, choose greater than from the comparator list, enter 49 in the value element, and choose and from the connector list.

11. For the second line, enter $(Chan).VAL in the channel element, choose less than from the comparator list, enter 150 as the value, choose use as the connector, and then choose a green or greenish color in the color element.

Let's define the third expression for a condition greater than 149. This expression will take up only one line.

12. Enter $(Chan).VAL as the channel element, choose greater than from the comparator list, enter 149 as the value, choose use as the connector, and choose red or a reddish color in the color element.

Can you figure out what an object will do when modified by this color rule at run-time? When the value of the analog channel is 0 or less than 0, the object will be the color specified in its property sheet. When the value is 1-49, the object will be blue; when 50-149, green; and when 150 or above, it will be red.

To modify an object by this color rule, we must first set the object's 'color rule modifier' property to rule, if it isn't already. Then we must specify the name of our color rule in the 'color rule name' property; in this case, the name would be analog monitor. Finally, we must replace the macro Chan with a real record name in the 'color rule arguments' property. An entry in this property might be Chan=analog_output, where analog_output is the name of a record in database. For more on objects and their property sheets, see General Characteristics and Properties in Chapters 5, 6, or 7.

The Analog Monitor Color Rule.

2.5. More About Color Rules

The default foreground and default background options at the bottom and towards the right edge of the Color Rule Modify window, when turned on, specify the color that the object turns when none of the conditions in the color rule are met. When the options are turned off, the objects modified by the color rule use the foreground and background colors specified in their property sheets.

To turn either default on or off simply left-click on the desired choice in the choice button. To change its color, follow the same steps as you would to change the color of the element in an expression.

2.1. - Modifying an Object by a Color Rule
2.2. - Configuring a Color Rule
Channel
Comparator
To change the comparator of an expression:
Value
Connector
To change the connector:
Color
To change the color of an expression:
2.3. - More About Expressions
2.4. - A Color Rule Example
2.5. - More About Color Rules

EDD/DM User's Manual, 2.4 - 27 MARCH 1997
[Next] [Previous] [Up] [Top] [Contents] [Index]


| LANL | Lansce | UC | DOE |

L O S   A L A M O S   N A T I O N A L    L A B O R A T O R Y
Operated by the University of California for the US Department of Energy

Copyright � 1996 UC   Disclaimer   


For problems or questions regarding this web site contact George Vaughn.