Module Simantics/Diagram

Affine Transforms

data Position
Position xx xy yx yy tx ty

is a 2D affine transform with a rotation/scale/shear part, i.e. xx xy yx yy and a translation part tx ty which represents the matrix

[xx yx | tx]
[xy yy | ty]
Position :: Double -> Double -> Double -> Double -> Double -> Double -> Position
location :: Double -> Double -> Position
location x y

Returns an affine transform with identity rotation and x y for translation.

move :: (Double, Double) -> Position -> Position
move (dx,dy)

Returns a function that adds (dx, dy) to the translation of a specified affine transform.

rotate :: Integer -> Position -> Position
rotate n

Returns a function that rotates the specified affine transform by n*90 degrees

scale :: Double -> Position -> Position
scale s transform

Multiplies the rotation part of the specified affine transform by s

[xx yx tx] => [s*xx s*yx tx]
[xy yy ty]    [s*xy s*yy ty]
withScale :: Double -> Position -> Position
withScale scale transform

Sets the rotation part so that the base vectors defined by u=[xx xy] and v=[yx yy] are of length scale. This effectively sets the scaling of the elements without touching their rotation/shear.

su = scale / |u|
sv = scale / |v|

[xx yx tx] => [su*xx sv*yx tx]
[xy yy ty]    [su*xy sv*yy ty]
flipX :: Position -> Position
flipX transform

Performs a mirror operation for the specified transform about the Y-axis.

flipY :: Position -> Position
flipY transform

Performs a mirror operation for the specified transform about the X-axis.

positionToDoubleArray :: Position -> Vector Double

Converts a Position into a DoubleArray.

positionToVector :: Position -> Vector Double

Converts a Position into a Vector Double.

Diagram Browsing

diagram :: Resource -> [String] -> <ReadGraph> Resource

Returns a diagram in the given model with the given model relative path.

The first Resource parameter is the model from which to look for the diagram and the second [String] list is the name path of the diagram under the model's configuration.

Note that this function returns the diagram configuration composite resource. If you need to get the actual diagram resource, use compositeToDiagram on the configuration composite resource.

So for example if you have the following hierarchy

- Model A            
  - Configuration
    - Folder A
      - Diagram A.1

the function would be used to fetch the Resource of Diagram A.1 as follows:

import "Simantics/Diagram"

m = (model "Model A")
// Or if you want to look from the `Model A` and it is the currently active model:
// m = currentModel
d = diagram m ["Folder A", "Diagram A.1"]
possibleDiagram :: Resource -> [String] -> <ReadGraph> Maybe Resource

Same as diagram but returns Nothing instead of failing with an exception if diagram is not found and Just diagram when the diagram is found.

Note that this function returns the diagram configuration composite resource. If you need to get the actual diagram resource, use compositeToDiagram on the configuration composite resource.

diagramsOf :: Resource -> <ReadGraph> [Resource]
diagramsOf (model "model name") 

Returns all configuration diagrams of the given model.

Note that this function returns the diagram configuration composite resource. If you need to get the actual diagram resource, use compositeToDiagram on the configuration composite resources.

diagramsUnder :: Resource -> <ReadGraph> [Resource]

Returns all diagrams under the specified diagram folder.

The parameter can also be the configuration root configurationOf in which case this function returns the same as diagramsOf model.

Note that this function returns diagram configuration composite resources. If you need to get the actual diagram resources, use map compositeToDiagram on the configuration composite resources.

Consider for example if you have the following hierarchy

- Model A            
  - Configuration
    - Folder A
      - Diagram A.1
      - Diagram A.2

the function would be used to fetch the Resources of all diagrams under Folder A as follows:

import "Simantics/Diagram"

m = (model "Model A")
// Or if you want to look from the `Model A` and it is the currently active model:
// m = currentModel
dias = diagramsUnder (childWithPath (configurationOf m) ["Folder A"])

Undocumented entities

Baseline :: Alignment
Center :: Alignment
Component :: a -> String -> Position -> [Property a] -> DiagramElement a
Connection :: [ConnectionNode a] -> [Edge] -> Maybe String -> DiagramElement a
DiagramInfo :: Resource -> Resource -> MMap.T String Resource -> DiagramInfo
Edge :: Integer -> Integer -> Edge
ExistingDiagram :: Resource -> DiagramSpec
Flag :: a -> String -> String -> Boolean -> Boolean -> Maybe String -> Maybe Integer -> Position -> [Dynamic] -> DiagramElement a
Font :: String -> Integer -> Integer -> Font
Leading :: Alignment
Monitor :: String -> Maybe MonitorReference -> MonitorVisuals -> Position -> DiagramElement a
MonitorReference :: String -> String -> MonitorReference
MonitorVisuals :: Maybe Font -> Double -> Alignment -> Alignment -> MonitorVisuals
NewDiagram :: Resource -> [String] -> Resource -> Resource -> DiagramSpec
Property :: a -> Dynamic -> Property a
RouteLine :: Boolean -> Double -> ConnectionNode a
SVG :: String -> Position -> DiagramElement a
SimpleConnection :: String -> a -> String -> a -> Maybe String -> DiagramElement a
Terminal :: String -> a -> ConnectionNode a
Text :: Resource -> String -> TextVisuals -> Position -> DiagramElement a
TextVisuals :: Maybe Font -> Alignment -> Alignment -> TextVisuals
Trailing :: Alignment
alignmentToResource :: Alignment -> Resource
applyConnectionType :: Resource -> <Proc,WriteGraph,ReadGraph> ()

Determines the connection type of the given diagram connection element and claims it as the STR.HasConnectionType of the connection. Prints a message and leaves the connection untyped if no type can be determined for it. See determineConnectionType.

applyDiagramMapping :: Resource -> <Proc,WriteGraph> ()

Runs the mapping of the given diagram resource once, which updates the configuration composite of the diagram to match the current contents of the diagram. syncActivateDiagram does the same starting from the configuration composite.

claimFolder :: Resource -> [String] -> Resource -> <Proc,WriteGraph> Resource
claimFolder model path folderType

Returns the folder at the given configuration relative path of model, creating the folders of the path that do not exist yet as composites of folderType.

claimModelFolder :: Resource -> [String] -> Resource -> <Proc,WriteGraph> Resource
claimModelFolder model path folderType

Same as claimFolder but the path is relative to the model resource itself instead of its configuration.

componentToElement :: Resource -> <ReadGraph> Resource

Returns the diagram element that the given configuration component is mapped to. Fails if the component has no element.

compositeToDiagram :: Resource -> <ReadGraph> Resource

Returns the diagram resource of the given diagram configuration composite. Fails if the composite has no diagram. The functions that read or write the elements of a diagram expect this resource rather than the composite.

compositeToDiagram' :: Resource -> <ReadGraph> Resource
createComposite :: Resource -> String -> Resource -> <WriteGraph> Resource
createComposite configuration name compositeType

Creates a new diagram composite of compositeType under configuration, which can also be a diagram folder. The given name is made unique among the children of the folder before it is used.

createComposite_ :: Resource -> String -> Resource -> <WriteGraph> Resource
createComposite_ parent name componentType

Creates a new component of componentType under parent, gives it the name name and a fresh identifier and returns it. This is how the diagram composites and the folders that contain them are created.

createComposite__ :: Resource -> String -> Resource -> <WriteGraph> Resource
createComposite__ configuration name compositeType

Creates a new diagram composite of compositeType with the given name under configuration, which can also be a diagram folder. The name is used as it is; createComposite makes it unique first.

createDiagramR :: DiagramSpec -> (Dynamic -> <WriteGraph> Resource) -> [DiagramElement Resource] -> <WriteGraph> (Resource, [Resource])

Creates or modifies an existing diagram to contain the given diagram elements.

createJoinMap :: () -> <Proc> Dynamic -> <WriteGraph> Resource
createJoinMap ()

Creates a function that maps a key to a connection join. The first call for a key creates a new STR.ConnectionJoin and every later call with an equal key returns that same join, so flags given the same key end up joined to each other. This is the join map that createDiagramR and setElements expect.

createSVGElement :: Resource -> String -> Vector Byte -> Double -> Double -> <WriteGraph> ()
createSVGElement diagram suffix data x y

Creates a new image element on the specified diagram from the raw image file contents data, positioned at the diagram coordinates (x, y).

suffix selects the image format and must be exactly one of:

  • "svg" creates a DIA.SVGElement with data decoded as an UTF-8 SVG document
  • "png" creates a DIA.RasterElement backed by a new PNG image resource containing data

Any other suffix fails with Unknown image format <suffix>.

The created element is given a fresh element name within the diagram and is added first in the diagram's element ordered set. It is not put on any of the diagram's layers. Placing the element on the currently visible layers requires the created element, i.e. createSVGElementR.

createSVGElementR :: Resource -> String -> Vector Byte -> Double -> Double -> <WriteGraph> Resource
createSVGElementR diagram suffix data x y

Creates an image element into the given diagram resource at (x, y) and returns the created element. suffix selects the format of data: "svg" creates an SVG element and "png" a raster element. Any other suffix fails.

defaultSymbolDropHandler :: [WorkbenchSelectionElement] -> <WriteGraph> ()

The default handler for symbols dropped onto a diagram. The present implementation only prints the dropped selection and changes nothing.

determineConnectionType :: Resource -> <ReadGraph> Maybe Resource

Takes one connection element and returns possible connection type.

diagramResourceOf :: Resource -> <ReadGraph> Resource

Returns the diagram resource of the given diagram configuration composite, the same as compositeToDiagram. Fails if the composite has no diagram.

elementToComponent :: Resource -> <ReadGraph> Resource

Returns the configuration component that the given diagram element is mapped to. Fails if the element has no component, which is the case for elements such as flags and text elements.

elementsOfR :: Resource -> <ReadGraph> [(DiagramElement Resource, Resource)]

Returns the elements of the given diagram.

flipConnection :: Resource -> Boolean -> Double -> <WriteGraph> ()
flipConnection connection xAxis c

Mirrors the interior route lines of the given connection. When xAxis is True the horizontal route lines are mirrored about the line y = c, otherwise the vertical route lines are mirrored about the line x = c. The connectors that attach the connection to element terminals are not touched.

genericFlagType :: () -> <ReadGraph> Resource

Returns the diagram flag type resource used for all generic diagram flags.

getConnection :: Resource -> String -> <ReadGraph> [Resource]
getConnection diagram name

Returns the connection elements of the given diagram configuration composite whose element name is name. The result is empty if there is no such connection. Note that the name matched here is the L0.HasName of the connection element on the diagram, not the name of the connection component in the configuration.

getConnections :: Resource -> <ReadGraph> [Resource]

Returns the route graph connection elements of the diagram of the given configuration composite.

getOrCreateFolder :: Resource -> Resource -> String -> <Proc,WriteGraph> Resource
getOrCreateFolder parentFolder folderType name

Returns the child of parentFolder that has the given name, creating it as a new composite of folderType if there is no such child yet.

importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
importSVGElement diagram file x y

Reads the given image file and creates an element for it into the given diagram resource at (x, y). The format is taken from the last three characters of the file name, so only svg and png files can be imported.

importSVGElementR :: Resource -> File -> Double -> Double -> <WriteGraph> Resource

Same as importSVGElement but returns the created element.

joinFlagsLocal :: [Resource] -> <WriteGraph> ()

Joins each of the given flags with its counterpart flags on the same diagram: the two connections that end at a flag pair are merged into one connection. A flag is removed in the process unless it has more than one counterpart, i.e. is a merged flag. Flags that are not connected to anything are skipped.

mapDiagramElement :: (a -> <c> b) -> (a -> <c> b) -> (a -> <c> Maybe b) -> (a -> <c> b) -> DiagramElement a -> <c> DiagramElement b

Constructs a transformation for a diagram element.

moveConnection :: Resource -> Double -> Double -> <WriteGraph> ()
moveConnection connection dx dy

Translates the interior route lines of the given connection by (dx, dy) and records the change in the change set metadata. The connectors that attach the connection to element terminals stay where they are, so only the routing of the connection moves.

newTypicalDiagram :: Resource -> Resource

Creates a new master typical diagram into the given library and returns its configuration composite. The containing model or shared library must define the typical composite and diagram base types; nothing is created if it does not. Performs its own write transaction.

pathNameOf :: Resource -> <ReadGraph> String

Returns the model configuration relative path of the given diagram as a single string with the names separated by /. See pathOf.

pathOf :: Resource -> <ReadGraph> [String]

Returns a model configuration relative path of the given diagram.

relatedValueWithDefault :: Serializable a => a -> Resource -> Resource -> <ReadGraph> a
relatedValueWithDefault defaultValue subject predicate

Returns the value that subject has for predicate, or defaultValue if the subject has no such statement.

removeElement :: Resource -> Resource -> <WriteGraph> ()
removeElement diagram element

Removes the given element from the given diagram resource. A connection is removed together with its connectors and route lines. Fails if something prevents the element from being removed.

resourceToAlignment :: Show a => Browsable a => a -> <ReadGraph> Alignment
rotateConnection :: Resource -> Double -> Double -> Boolean -> <WriteGraph> ()
rotateConnection connection cx cy clockwise

Rotates the interior route lines of the given connection by 90 degrees around the point (cx, cy), clockwise when clockwise is True. Horizontal route lines become vertical and vice versa. The connectors that attach the connection to element terminals are not touched.

rotateDegrees :: Double -> Position -> Position
rotateDegrees theta

Returns a function that rotates the specified affine transform by theta degrees

setElements :: DiagramInfo -> (Dynamic -> <WriteGraph> Resource) -> [DiagramElement Resource] -> <Proc,WriteGraph> [Resource]

Sets the elements of the diagram. Diagram is assumed to be empty, but the configuration may contain existing components that can be found from the given existing components map.

setProfileMonitorsDirectionUp :: Resource -> Boolean -> <WriteGraph> ()
setProfileMonitorsDirectionUp element up

Sets whether the profile monitors of the given diagram element are stacked upwards from the element instead of downwards.

setStraightConnectionLines :: Resource -> Boolean -> <WriteGraph> ()
setStraightConnectionLines element straight

Sets whether the connections attached to the given diagram element are routed with straight lines between the terminals, route points and branch points instead of orthogonal lines. The setting is written to every connector of the element.

setTransform :: Resource -> Vector Double -> <WriteGraph> ()
setTransform element transform

Replaces the affine transform of the given diagram element. transform is the six element array [xx, xy, yx, yy, tx, ty] described by Position, which positionToDoubleArray produces from a Position. Use transformElement to modify the existing transform instead of replacing it.

showProfileMonitors :: Resource -> Boolean -> <WriteGraph> ()
showProfileMonitors element show

Sets whether the profile monitors of the given diagram element are shown.

splitConnection :: Resource -> Double -> Double -> <WriteGraph> ()
splitConnection connection x y

Splits the given route graph connection in two at the diagram coordinates (x, y). The route line nearest to the point is cut, the part of the connection that has no output terminal is moved into a new connection of the same type, and a pair of joined flags is created on the diagram to continue the connection over the cut. Does nothing if no route line can be picked at the given point.

syncActivateDiagram :: Resource -> <WriteGraph,Proc> Boolean

Runs the mapping of the diagram of the given configuration composite once, so that the composite matches the contents of the diagram. Always returns True.

syncTypicalInstance :: Resource -> <WriteGraph> ()

Synchronizes one typical instance diagram with the master typical diagram it was instantiated from, so that the changes made to the master are applied to the instance.

transformElement :: (Position -> Position) -> Resource -> <WriteGraph> ()
transformElement transformer element

Performs the affine transformation encapsulated by transformer for the specified diagram element.

For examples of possible transformer functions, see scale and withScale.

transformElements :: (Position -> Position) -> [Resource] -> <WriteGraph> ()
transformElements transformer elements

Runs transformElement using the specified transformer for all the specified elements.

Use this function together with e.g. scale and withScale or similar functions.

Examples:

import "Simantics/Diagram"

// Scale some elements by 1.5:
transformElements (scale 1.5) someElements
// Set scale of some elements to 10
transformElements (withScale 10) someElements
translateRouteNodes :: Resource -> Double -> Double -> <WriteGraph> ()
translateRouteNodes connection dx dy

Translates the interior route lines of the given connection by (dx, dy). The connectors that attach the connection to element terminals stay where they are. The same as moveConnection without the change set comment.