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
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.
<format> tag must have no conditions in order to make sure that something can always be displayed.
A conditions string is costructed by combining the elements described as follows.
Combine two expressions.
Combine a property with a value to test against.
Useful for constructing more complex expressions.
)to group subexpressions
!to negate an expression
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
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>