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
translation 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 Vector Double.

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> ()
applyDiagramMapping :: Resource -> <Proc,WriteGraph> ()
claimFolder :: Resource -> [String] -> Resource -> <Proc,WriteGraph> Resource
claimModelFolder :: Resource -> [String] -> Resource -> <Proc,WriteGraph> Resource
componentToElement :: Resource -> <ReadGraph> Resource
compositeToDiagram :: Resource -> <ReadGraph> Resource
compositeToDiagram' :: Resource -> <ReadGraph> Resource
createComposite :: Resource -> String -> Resource -> <WriteGraph> Resource
createComposite_ :: Resource -> String -> Resource -> <WriteGraph> Resource
createComposite__ :: Resource -> String -> Resource -> <WriteGraph> Resource
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
createSVGElement :: Resource -> String -> Vector Byte -> Double -> Double -> <WriteGraph> ()
createSVGElementR :: Resource -> String -> Vector Byte -> Double -> Double -> <WriteGraph> Resource
defaultSymbolDropHandler :: [WorkbenchSelectionElement] -> <WriteGraph> ()
determineConnectionType :: Resource -> <ReadGraph> Maybe Resource

Takes one connection element and returns possible diagram type.

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

Returns the elements of the given diagram.

flipConnection :: Resource -> Boolean -> Double -> <WriteGraph> ()
genericFlagType :: () -> <ReadGraph> Resource

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

getConnection :: Resource -> String -> <ReadGraph> [Resource]
getConnections :: Resource -> <ReadGraph> [Resource]
getOrCreateFolder :: Resource -> Resource -> String -> <Proc,WriteGraph> Resource
importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
importSVGElementR :: Resource -> File -> Double -> Double -> <WriteGraph> Resource
joinFlagsLocal :: [Resource] -> <WriteGraph> ()
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> ()
newTypicalDiagram :: Resource -> Resource
pathNameOf :: Resource -> <ReadGraph> String
pathOf :: Resource -> <ReadGraph> [String]

Returns a model configuration relative path of the given diagram.

relatedValueWithDefault :: Serializable a => a -> Resource -> Resource -> <ReadGraph> a
removeElement :: Resource -> Resource -> <WriteGraph> ()
resourceToAlignment :: Show a => Browsable a => a -> <ReadGraph> Alignment
rotateConnection :: Resource -> Double -> Double -> Boolean -> <WriteGraph> ()
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> ()
setStraightConnectionLines :: Resource -> Boolean -> <WriteGraph> ()
setTransform :: Resource -> Vector Double -> <WriteGraph> ()
showProfileMonitors :: Resource -> Boolean -> <WriteGraph> ()
splitConnection :: Resource -> Double -> Double -> <WriteGraph> ()
syncActivateDiagram :: Resource -> <WriteGraph,Proc> Boolean
syncTypicalInstance :: Resource -> <WriteGraph> ()
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 scaleTransform and transformWithScale.

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. scaleTransform and transformWithScale 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> ()