Diagram Pragmas#

Graphical information is stored as diagram pragmas in the Swan source. This section describes the diagram pragma classes.

A diagram pragma specifies layout information, which is represented as a JSON string within the pragma. The exception is the detached pragma, which indicates that the diagram is hidden when specified as #pragma diagram detached #end.

../../../_images/diagram_pragma.svg

Fig. 19 DiagramPragma class diagram#

Diagram Pragma#

class ansys.scadeone.core.swan.DiagramPragma#

Bases: Pragma

The diagram information of a graphical object.

static filter(pragmas: List[Pragma], key: str, with_key: bool = True) List[Pragma]#

Filters a list of pragmas with/without a given key.

Parameters:
pragmasList[Pragma]

List of pragmas.

keystr

Key to filter.

with_keybool, optional

If True, return pragmas with the given key, otherwise without the key, by default True.

Returns:
List[Pragma]

List of pragmas with the given key.

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property coordinates: Coordinates | None#

Return the diagram coordinates.

property data: str#

Return a string representation of a property given.

property default_direction: Direction#

Return the default diagram direction (North-East).

property direction: Direction | None#

Return the diagram direction.

property is_detached: bool#

Return whether the diagram is detached (content not displayed).

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property key: PragmaKey | str#

Return the pragma key.

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property orientation: Orientation | None#

Return the diagram orientation.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property size: Size | None#

Return the diagram size.

property transition_path_info: PathInfo | None#

Return the diagram arrow info.

property wire_path_info: PathInfo | None#

Return the diagram wire info.

Coordinates#

Coordinates are used to define positions in the diagram. They represent a point with an absolute or relative position. The Coordinates class defines a point with its x and y coordinates. A Coordinate represents a single coordinate, which can be absolute or relative depending on the Position information. The letters “h” and “v” stand for horizontal and vertical positions, respectively, with capitalization indicating absolute or relative values.

Example: {"xy": "H100,V200"} specifies an absolute position at x=100 and y=200.

Relative values are computed from the center of the parent container. For wires and transitions, they correspond to the center of the source and target elements or the previous coordinate in the path.

class ansys.scadeone.core.swan.Coordinates(x: Coordinate | None = None, y: Coordinate | None = None)#

Bases: object

Coordinates define a horizontal (x) and a vertical (y) position of a graphical object.

Coordinates are specified as:

xy = COORD ";" COORD

where:

Coordinates are used to define the position of the diagram object, states or Active if/when blocks.

property x: Coordinate | None#

Return the x coordinate.

property y: Coordinate | None#

Return the y coordinate.

class ansys.scadeone.core.swan.Coordinate(position: Position, value: int)#

Bases: object

Coordinate defines a horizontal (x) or vertical (y) position of a graphical object.

Coordinate is defined as:

xy = ("H" | "h")x ";" ("V" | "v")y
  • ("H" | "h") or ("V" | "v"): Absolute or relative position (see Position)

  • x or y: Coordinate value

The relative coordinate values are computed from:

  • the center of the parent block

  • wire and transition: the center of the source/target, or the previous coordinate

property position: Position#

Return the coordinate position (absolute or relative).

property value: int#

Return the coordinate value.

class ansys.scadeone.core.swan.Position(value)#

Bases: Enum

Position of a coordinate.

xy = ("H" | "h")x ";" ("V" | "v")y
  • H, V: Absolute position

  • h, v: Relative position

ABSOLUTE = 1#

Absolute position.

RELATIVE = 2#

Relative position.

Size#

class ansys.scadeone.core.swan.Size(width: int, height: int)#

Bases: object

Size of a graphical object.

Size is defined as

wh = width ";" height

where:

  • width: Width value

  • height: Height value

Size is used to define the size of the diagram object, states, active if/when blocks or automaton. If omitted, the default size of the object is used.

property height: int#

Return the object height.

property width: int#

Return the object width.

Direction#

The format is {"dir": "val"}, where val is one of

ne, nw, es, en, se, sw, ws, wn. For example, ne stands for “NorthEast,” nw for “NorthWest,” and so on.

The first letter represents the orientation of the top side of the block instance, while the second letter represents the orientation of its output side. The default orientation is ne, with inputs on the left and outputs on the right. A 90-degree clockwise rotation of the block instance results in a new orientation, while a 90-degree counter-clockwise rotation combined with a flip results in the ws orientation.

class ansys.scadeone.core.swan.Direction(value: DirectionType)#

Bases: object

The direction of the diagram object.

Direction is defined as

dir = dir_val

where dir_val is defined in DirectionType.

Direction is used to define the direction of predefined operator and block with text (Expr, Def, Instance, Equation).

property value: DirectionType#

Return the direction value.

class ansys.scadeone.core.swan.DirectionType(value)#

Bases: Enum

The direction value of a diagram object.

The direction value is defined as

dir_val = ne|nw|es|en|se|sw|ws|wn

where:

  • ne: North-East

  • nw: North-West

  • es: East-South

  • en: East-North

  • se: South-East

  • sw: South-West

  • ws: West-South

  • wn: West-North

The direction value is read as: the first direction is at the top of the graphical object, and the second direction is the right side of the graphical object.

The default direction is North-East:
  • West corresponding to inputs,

  • East corresponding to outputs.

EAST_NORTH = 'en'#

East-North direction. From the default direction, a 90° left rotation and a horizontal flip are applied (inputs are at the bottom and outputs are at the top).

EAST_SOUTH = 'es'#

East-South direction. From the default direction, a 90° left rotation is applied (inputs are at the bottom and outputs are at the top).

NORTH_EAST = 'ne'#

North-East direction. Default direction (inputs are on the left, outputs are on the right).

NORTH_WEST = 'nw'#

North-West direction. From the default direction, a horizontal flip is applied, or a 180° rotation and a vertical flip are applied (inputs are on the right and outputs are on the left).

SOUTH_EAST = 'se'#

South east direction. From the default direction, a vertical flip is applied (inputs are on the left and outputs are on the right).

SOUTH_WEST = 'sw'#

South-West direction. From the default direction, a 180° rotation is applied (inputs are on the right and outputs are on the left).

WEST_NORTH = 'wn'#

West-North direction. From the default direction a 90° right rotation is applied (inputs are at the top and outputs are at the bottom).

WEST_SOUTH = 'ws'#

West-South direction. From the default direction, a 90° right rotation and a horizontal flip are applied (inputs are at the top and outputs are at the bottom).

Orientation#

class ansys.scadeone.core.swan.Orientation(value: OrientationType)#

Bases: object

Text content orientation.

Orientation is defined as

orient = orient_val

where orient_val is defined in OrientationType.

Orientation is used to define the text content orientation of the diagram object.

property value: OrientationType#

Return the orientation value.

class ansys.scadeone.core.swan.OrientationType(value)#

Bases: Enum

Text content orientation value.

The orientation value is defined as:

orient_val = "H"|"V"

where:

  • H: Horizontal orientation

  • V: Vertical orientation

HORIZONTAL = 'H'#

Horizontal orientation.

VERTICAL = 'V'#

Vertical orientation.

Wire and transition path#

Path information for a wire or transition is encapsulated within a PathInfo object. This object includes a list of moves that define the path from the source element to the target element. Additionally, the path may contain multiple targets, which are represented as branches within the path structure.

The grammar for a path is as follows:

LUNUM = '#' [0-9]+
COORD = [hHvV]+ '-'? [0-9]+

path_info = path_anchor path
path_anchor = LUNUM
            | COORD '|' LUNUM
            | coordinate '|' LUNUM
            | coordinate
path = moves path_anchor
     | moves branches
moves =  move *
move = COORD
     | coordinate
     | COORD '|' coordinate
     | coordinate '|' coordinate
coordinate = COORD ',' COORD
branches = '['' path ( ',' path ) * ']'

Where path_info is the path information, starting with a path_anchor and followed by a path. A path consists of a list of moves and ends with a path_anchor or branches.

COORD:

Defines either an absolute or relative coordinate.

path_anchor:

Defines the anchor of the path (source or target element), where:

  • LUNUM: source/target element number

  • COORD ‘|’ LUNUM: connection to a group-related block

  • coordinate ‘|’ LUNUM: connection to a state

  • coordinate: unconnected endpoint

moves:

Moves are defined as:

  • COORD: a single move to the next coordinate, either horizontal or vertical

  • coordinate: move to a given point, which can be absolute or relative

  • coordinate ‘|’ coordinate: move to a point (first coordinate) for a fork object (second coordinate)

Check the examples from the Scade One distribution to see pragma content and results.

Path information#

class ansys.scadeone.core.swan.PathInfo(path_anchor: PathAnchor, path: PathPart)#

Bases: object

The wire or transition path between two objects. The path is defined by a list of moves.

The wire and transition paths are defined as:

  • Wire

wp = path_info
  • Transition

tp = path_info

where:

path_info = path_anchor path

path_anchor is defined in PathAnchor.

path is defined in PathPart.

property path: PathPart#

Return the path.

property path_anchor: PathAnchor#

Return the wire anchor.

Path anchor#

class ansys.scadeone.core.swan.PathAnchor(lunum: Lunum | None = None, coordinates: Coordinates | None = None)#

Bases: object

Path anchor is the starting or ending point of a path.

Path anchor is defined as:

path_anchor = LUNUM
    | COORD '|' LUNUM (* connection to a group-related block *)
    | coordinates '|' LUNUM (* coordinates of a starting/ending point of a transition for a state *)
    | coordinates (* unconnected point as a pair of COORD. *)

where:

  • LUNUM: The graphical object identifier (see Lunum)

  • COORD: Coordinate x or y (see Coordinate)

  • coordinates: Coordinates (x;*y*) (see Coordinates)

property coordinates: Coordinates | None#

Return the coordinates.

property lunum: Lunum | None#

Return the LUNUM.

Path moves#

class ansys.scadeone.core.swan.Move(coordinates: Coordinates, fork_coordinates: Coordinates | None = None)#

Bases: object

This class manages the moves along wire and transition paths.

A move is defined as:

move_coordinates = COORD | coordinates

for a move along a wire path and a transition path, and is defined as:

move_and_fork_coordinates = (COORD | coordinates) '|' coordinates

for a move along a transition path with a fork. The coordinates before the pipe symbol (‘|’) represent the move, and the coordinates after the pipe symbol represent the fork point.

property coordinates: Coordinates#

Return the coordinates.

property fork_coordinates: Coordinates | None#

Return the fork coordinates. Only applies to transitions.

Path part#

class ansys.scadeone.core.swan.PathPart(moves: List[Move] | None = None, path_anchor: PathAnchor | None = None, branches: Branches | None = None)#

Bases: object

The PathPart represents a segment of a path after the anchor or in branch.

The path part is defined as:

path = {move} path_anchor
     | {move} branch

{move} means zero or more moves. where:

  • move is defined in Move

  • path_anchor is defined in PathAnchor

  • branch is defined in Branch

property branches: Branches | None#

Return the branch.

property moves: List[Move] | None#

Return the moves.

property path_anchor: PathAnchor | None#

Return the wire anchor.

Path branches#

class ansys.scadeone.core.swan.Branches(path_list: List[PathPart])#

Bases: object

Branch is the graphic path followed by the wire or transition when there are multiple paths.

Branch is defined as:

branch = '[' path_list ']';
path_list = path
          | path_list ',' path

where:

property path_list: List[PathPart]#

Return the path list.