Conditions
Sometimes you may want to use a different formatting for properties depending on certain conditions.
For example, the resistor component displays 2.2 MΩ when the resistance is above a certain value, instead of simply 2200000 Ω. This is achieved using formatting conditions.
As described in the previous section, the <formatting>
tag can contain multiple <format>
tags.
Circuit Diagram checks each of the <format>
tags, starting with the first, and uses the first one for which the conditions are met.
Conditions are made using the conditions
attribute. If the conditions attribute is omitted, the conditions are deemed to have been met by default.
The last <format>
tag must have no conditions in order to make sure that something can always be displayed.
Conditions String
A conditions string is costructed by combining the elements described as follows.
Boolean operators
Combine two expressions.
- Logical AND:
,
(comma) - Logical OR:
|
(pipe)
Example: horizontal,$type==LDR
Property or state operators
Combine a property with a value to test against.
- Equal:
==
- Not equal:
!=
- Less than:
[lt]
- Less than or equal:
[lteq]
- Greater than:
[gt]
- Greater than or equal:
[gteq]
Example: $resistance[gt]200
Negation and Brackets
Useful for constructing more complex expressions.
- Brackets:
(
and)
to group subexpressions - Negation:
!
to negate an expression
Example: !(horizontal|$type==LDR)
Properties and States
You can refer to properties by appending the property name with a dollar symbol.
Component states can also be referenced, which are not prefixed with a dollar symbol:
horizontal
: true if the component has been placed horizontally, false if vertical
Example
The resistor component uses conditions to apply formatting based on the resistance value.
<property
name="Resistance"
type="double"
default="4700"
serialize="resistance"
display="Resistance">
<formatting>
<format conditions="$Resistance[lt]1000" value="$Resistance \u2126" />
<format conditions="$Resistance[lt]1000000"
value="$Resistance(div_1000_)(round_1) k\u2126" />
<format value="$Resistance(div_1000000)(round_1) M\u2126" />
</formatting>
</property>