1 include "Simantics/Model"
2 include "Simantics/WorkbenchSelection"
3 include "Simantics/Library"
5 import "Simantics/GUID" as GUID
7 import "http://www.simantics.org/Layer0-1.1" as L0
8 import "http://www.simantics.org/Diagram-2.2" as DIA
9 import "http://www.simantics.org/G2D-1.1" as G2D
10 import "http://www.simantics.org/Modeling-1.2" as MOD
11 import "http://www.simantics.org/Simulation-1.1" as SIMU
12 import "http://www.simantics.org/Structural-1.2" as STR
14 // --- Entity types -------------------------------------------------
16 type Diagram = Resource
17 type DiagramFolder = Resource
18 type Component = Resource
19 type Element = Resource
20 type ComponentType = Resource
21 type Terminal = Resource
22 type Connection = Resource
23 type ConnectionType = Resource
25 // --- Position -----------------------------------------------------
27 data Position = Position Double Double Double Double Double Double
29 deriving instance Show Position
31 location :: Double -> Double -> Position
32 location x y = Position 1 0 0 1 x y
34 move :: (Double,Double) -> Position -> Position
35 move (dx,dy) (Position xx xy yx yy x y) = Position xx xy yx yy (x+dx) (y+dy)
37 rotate :: Integer -> Position -> Position
38 rotate angle (Position xx xy yx yy x y) =
39 Position (c*xx + s*xy) (c*xy - s*xx)
40 (c*yx + s*yy) (c*yy - s*yx)
44 then (angle `mod` 4) + 4
46 s = match a with 1 -> 1.0 ; 3 -> -1.0 ; _ -> 0.0
47 c = match a with 0 -> 1.0 ; 2 -> -1.0 ; _ -> 0.0
49 scale :: Double -> Position -> Position
50 scale s (Position xx xy yx yy x y) = Position (s*xx) (s*xy) (s*yx) (s*yy) x y
52 flipX :: Position -> Position
53 flipX (Position xx xy yx yy x y) = Position (-xx) xy (-yx) yy x y
55 flipY :: Position -> Position
56 flipY (Position xx xy yx yy x y) = Position xx (-xy) yx (-yy) x y
58 positionToDoubleArray (Position a b c d e f) = toDoubleArray [a,b,c,d,e,f]
60 positionToVector :: Position -> Vector Double
61 positionToVector (Position a b c d e f) = runProc
62 (do r = createMVector 6
71 // --- Diagram element data types -----------------------------------
73 data Property res = Property res Dynamic
74 instance (Show res) => Show (Property res) where
75 show (Property r _) = "Property " + show r
77 data Edge = Edge Integer Integer
78 deriving instance Show Edge
79 data ConnectionNode res = Terminal String res
81 Boolean // is horizontal
83 deriving instance (Show res) => Show (ConnectionNode res)
85 data Font = Font String Integer Integer
86 deriving instance Show Font
93 deriving instance Show Alignment
95 resourceToAlignment res = match (possibleNameOf res) with
96 Just "Baseline" -> Baseline
97 Just "Center" -> Center
98 Just "Leading" -> Leading
99 Just "Trailing" -> Trailing
100 _ -> fail ("Couldn't convert " + show res + " to Alignment.")
102 alignmentToResource Baseline = G2D.Alignment.Baseline
103 alignmentToResource Center = G2D.Alignment.Center
104 alignmentToResource Leading = G2D.Alignment.Leading
105 alignmentToResource Trailing = G2D.Alignment.Trailing
107 data MonitorReference = MonitorReference String String
108 deriving instance Show MonitorReference
110 data MonitorVisuals = MonitorVisuals (Maybe Font) Double Alignment Alignment
111 deriving instance Show MonitorVisuals
113 data TextVisuals = TextVisuals (Maybe Font) Alignment Alignment
114 deriving instance Show TextVisuals
116 data DiagramElement res =
118 res // component type
121 [Property res] // properties
122 | SimpleConnection String res String res (Maybe String)
123 | Connection [ConnectionNode res] [Edge] (Maybe String)
130 (Maybe String) // IOTableBinding
131 (Maybe Integer) // IOTableRowIndex
133 [Dynamic] // references to the joins
134 | SVG String Position
135 | Monitor String (Maybe MonitorReference) MonitorVisuals Position
137 Resource // element type
138 String // Text shown by the element
139 TextVisuals // text element visual attributes
140 Position // position on diagram
141 deriving instance (Show res) => Show (DiagramElement res)
143 // --- Functions ----------------------------------------------------
145 """Creates a random GUID L0.identifier property for the specified entity resource."""
147 hasRandomIdentifier :: Resource -> <ReadGraph,WriteGraph> ()
148 hasRandomIdentifier entity = runProc (claimRelatedValue_ entity L0.identifier GUID.randomGUID GUID.guidBinding)
150 """Returns all diagrams of the given model."""
151 diagramsOf :: Model -> <ReadGraph> [Diagram]
152 diagramsOf model = diagramsUnder $ configurationOf model
155 Returns all diagrams under the specified diagram folder.
156 The parameter can also be the configuration root `configurationOf`
157 in which case this function returns the same as `diagramsOf model`.
159 diagramsUnder :: DiagramFolder -> <ReadGraph> [Resource]
160 diagramsUnder folder = recurse DIA.Diagram folder
164 dias = filter isDiagramComposite cs
165 folders = filter (not . isDiagramComposite) cs
166 dias + concatMap (recurse t) folders
167 isDiagramComposite r = existsStatement r MOD.CompositeToDiagram
169 """Returns a model relative path of the given diagram."""
170 pathOf :: Diagram -> <ReadGraph> [String]
171 pathOf diagram = map nameOf $ unfoldl aux diagram
173 aux r = if existsStatement r SIMU.IsConfigurationOf
176 parents = r # L0.PartOf
177 if length parents == 1
178 then Just (r, parents!0)
180 nameOf r = relatedValue r $ L0.HasName
182 pathNameOf :: Diagram -> <ReadGraph> String
183 pathNameOf diagram = do
184 path = pathOf diagram
185 foldl1 (\s s1 -> s + " / " + s1) path
188 diagramResourceOf :: Diagram -> <ReadGraph> Resource
189 diagramResourceOf d = singleObject d MOD.CompositeToDiagram
191 import "Extras/HashMap" as Map
193 """Constructs a transformation for a diagram element."""
194 mapDiagramElement :: (a -> <e> b) -> (a -> <e> b) -> (a -> <e> Maybe b) -> (a -> <e> b) -> DiagramElement a -> <e> DiagramElement b
195 mapDiagramElement mapComponentType mapTerminal mapAttribute mapFlagType diagramElement =
196 (match diagramElement with
197 Component componentType name position properties -> do
198 Component (mapComponentType componentType) name position
199 (filterJust (map mapProperty properties))
200 SimpleConnection e1 r1 e2 r2 possibleName ->
201 SimpleConnection e1 (mapTerminal r1) e2 (mapTerminal r2) possibleName
202 Connection nodes edges possibleName ->
204 (map mapConnectionNode nodes)
206 Flag t e e2 e3 e4 e5 p p2 joins -> Flag (mapFlagType t) e e2 e3 e4 e5 p p2 joins
208 Monitor label ref visuals position -> Monitor label ref visuals position
209 Text elementType text visuals position -> Text elementType text visuals position
211 mapProperty (Property p v) =
212 match (mapAttribute p) with
213 Just mp -> Just (Property mp v)
215 mapConnectionNode (Terminal e r) = Terminal e (mapTerminal r)
216 mapConnectionNode (RouteLine iv p) = RouteLine iv p
218 importJava "org.simantics.structural2.utils.StructuralUtils" where
219 @JavaName newComponent
220 createComposite_ :: Resource -> String -> Resource -> <WriteGraph> Resource
222 data DiagramSpec = NewDiagram
224 [String] // path to the diagram
225 Resource // folder type
226 Resource // composite type
227 | ExistingDiagram Diagram
229 compositeToDiagram' c = singleObject c MOD.CompositeToDiagram
231 """Creates or modifies an existing diagram to contain the given diagram elements."""
232 createDiagramR :: DiagramSpec -> (Dynamic -> <WriteGraph> Resource) -> [DiagramElement Resource] -> <WriteGraph> (Diagram, [Resource])
233 createDiagramR (ExistingDiagram diagram') joinMap elementSpecs = runProc do
234 configuration = diagram'
235 diagram = compositeToDiagram' configuration
237 componentMap = Map.fromList [ (c `relatedValue` hasName :: String, c)
238 | c <- children configuration
240 denyByPredicate diagram L0.ConsistsOf
241 elements = setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs
242 claimRelatedValue diagram DIA.HasModCount
243 (fromInteger (length elements) :: Long)
246 createDiagramR (NewDiagram model path folderType compositeType) joinMap elementSpecs = (runProc do
247 configuration = createConfiguration ()
248 diagram = compositeToDiagram' configuration
249 elements = setElements (DiagramInfo diagram configuration (Map.create ())) joinMap elementSpecs
250 claimRelatedValue diagram DIA.HasModCount
251 (fromInteger (length elements) :: Long)
252 (configuration, elements)
254 createConfiguration () = do
255 lastId = length path - 1
256 parentFolder = foldl (\p id -> getOrCreateFolder p (path!id))
257 (configurationOf model)
259 createComposite_ parentFolder (path!lastId) compositeType
260 getOrCreateFolder parentFolder name =
261 match possibleResourceChild parentFolder name with
264 createComposite_ parentFolder name folderType
266 claimFolder :: Model -> [String] -> Resource -> <Proc,WriteGraph> Resource
267 claimFolder model path folderType = do
269 foldl (\p id -> getOrCreateFolder p folderType (path!id))
270 (configurationOf model)
273 claimModelFolder :: Model -> [String] -> Resource -> <Proc,WriteGraph> Resource
274 claimModelFolder model path folderType = do
276 foldl (\p id -> getOrCreateFolder p folderType (path!id))
280 getOrCreateFolder :: Resource -> Resource -> String -> <Proc,WriteGraph> Resource
281 getOrCreateFolder parentFolder folderType name = do
282 match possibleResourceChild parentFolder name with
285 createComposite_ parentFolder name folderType
287 relatedValueWithDefault :: Serializable a => a -> Resource -> Resource -> <ReadGraph> a
288 relatedValueWithDefault def r p =
289 if existsStatement r p
290 then relatedValue r p
293 applyConnectionType :: Resource -> <Proc,WriteGraph,ReadGraph> ()
294 applyConnectionType res = do
295 t = determineConnectionType res
297 Just t -> claim res STR.HasConnectionType t
298 Nothing -> print ("No connection type " + (show res))
301 importJava "org.simantics.modeling.utils.JoinMap" where
303 createJoinMap :: () -> <Proc> (Dynamic -> <WriteGraph> Resource)
306 createJoin :: (Dynamic -> <WriteGraph> Resource) -> Dynamic -> <Proc,WriteGraph> Resource
307 createJoin joinMap key = if Map.contains joinMap key
308 then Map.unsafeGet joinMap key
311 hasType STR.ConnectionJoin
313 Map.put joinMap key j
316 data DiagramInfo = DiagramInfo
318 Resource // configuration
319 (Map.T String Resource) // existing components
322 Sets the elements of the diagram. Diagram is assumed to be empty,
323 but the configuration may contain existing components that can be found
324 from the given existing components map.
326 setElements :: DiagramInfo -> (Dynamic -> <WriteGraph> Resource) -> [DiagramElement Resource] -> <Proc,WriteGraph> [Resource]
327 setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs = (do
328 /*elements = map createElement (filter (not . isConnection) elementSpecs)
329 + map createElement (filter isConnection elementSpecs)*/
330 elements = mapMaybe createElement elementSpecs
332 (claim diagram L0.ConsistsOf)
333 setOrderedSet diagram elements
334 iter applyConnectionType (filter isConnectionResource elements)
335 syncActivateOnce diagram
336 for (zip elementSpecs elements) setConnectionName
339 elementMap = Map.create ()
340 idRef = ref (0 :: Integer)
342 isConnectionResource r = isInstanceOf r DIA.Connection
343 isConnection (Connection _ _ _) = True
344 isConnection (SimpleConnection _ _ _ _ _) = True
345 isConnection _ = False
347 freshElementName () = do
351 createElement (Component componentType name position properties) = do
352 component = if Map.contains componentMap name
353 then Map.unsafeGet componentMap name
356 hasParent configuration,
359 for properties (\(Property prop value) ->
360 untypedClaimRelatedValue component prop value
362 element = newOrMappedElement name
363 element = updateEntity element [
364 hasName (freshElementName ()),
365 hasType componentType,
368 (positionToDoubleArray position)
371 MOD.ElementToComponent
374 Map.put elementMap name element
376 newOrMappedElement eName = do
377 element = match Map.get elementMap eName with
378 Just element -> element
379 Nothing -> newEntity []
380 Map.put elementMap eName element
382 createElement (SimpleConnection aName ar bName br _) = do
383 connection = newEntity [
384 hasName (freshElementName ()),
385 hasType DIA.RouteGraphConnection
387 a = newOrMappedElement aName
388 b = newOrMappedElement bName
389 ca = createConnector connection a ar
390 cb = createConnector connection b br
393 createElement (Flag t name label output external tableBinding tableRow position joins) = do
394 flag = newOrMappedElement name
395 flag = updateEntity flag [
396 hasName (freshElementName ()),
401 (positionToDoubleArray position)
404 DIA.Flag.HasIOTableBinding
407 DIA.Flag.HasIOTableRowIndex
418 claim flag DIA.HasFlagType DIA.FlagType.OutputFlag
422 claim flag DIA.ExternalFlag flag
424 Map.put elementMap name flag
426 createElement (Connection nodeSpecs edges _) = do
427 connection = newEntity [
428 hasName (freshElementName ()),
429 hasType DIA.RouteGraphConnection
432 nodes = map (createNode connection) nodeSpecs
433 for edges (\(Edge a b) -> connectNodes (nodes!a) (nodes!b))
435 createNode connection (Terminal elementName terminal) = do
436 element = newOrMappedElement elementName
437 createConnector connection element terminal
438 createNode connection (RouteLine isHorizontal position) = do
440 hasName (freshElementName ()),
441 hasType DIA.RouteLine,
442 hasProperty DIA.HasPosition
444 hasProperty DIA.IsHorizontal
446 hasStatement DIA.HasInteriorRouteNode.Inverse
449 createConnector connection component terminal = do
450 connector = newResource ()
454 claim component terminal connector
456 DIA.HasPlainConnector
460 claim a DIA.AreConnected b
461 createElement (SVG document position) =
463 hasName (freshElementName ()),
464 hasType DIA.SVGElement,
470 (positionToDoubleArray position)
473 createRealizedFont (Font family size style) = do
474 font = newResource ()
478 claimRelatedValue font DIA.RealizedFont.HasFamily family
479 claimRelatedValue font DIA.RealizedFont.HasSize size
480 claimRelatedValue font DIA.RealizedFont.HasStyle style
482 hasFont (Just font) = hasStatement DIA.HasFont (createRealizedFont font)
483 hasFont Nothing = const ()
484 createElement (Monitor label Nothing (MonitorVisuals font strokeWidth hAlign vAlign) position) = do
486 hasName (freshElementName ()),
493 (positionToDoubleArray position)
500 G2D.HasHorizontalAlignment
501 (alignmentToResource hAlign),
503 G2D.HasVerticalAlignment
504 (alignmentToResource vAlign),
507 createElement (Monitor label (Just (MonitorReference componentName suffix)) (MonitorVisuals font strokeWidth hAlign vAlign) position) = do
508 match (Map.get elementMap componentName) with
509 Nothing -> Nothing // Monitored component is not on the same diagram as the monitor. Not supported by this routine.
511 component = singleObject element MOD.ElementToComponent
513 hasName (freshElementName ()),
521 hasStatement DIA.HasMonitorComponent component,
524 (positionToDoubleArray position)
531 G2D.HasHorizontalAlignment
532 (alignmentToResource hAlign),
534 G2D.HasVerticalAlignment
535 (alignmentToResource vAlign),
538 createElement (Text elementType text (TextVisuals font hAlign vAlign) position) =
540 hasName (freshElementName ()),
547 (positionToDoubleArray position)
550 G2D.HasHorizontalAlignment
551 (alignmentToResource hAlign),
553 G2D.HasVerticalAlignment
554 (alignmentToResource vAlign),
557 setConnectionName (Connection _ _ (Just name), element) =
558 match possibleObject element MOD.ElementToComponent with
559 Just c -> claimRelatedValue c L0.HasName name
560 Nothing -> print ("Failed to set the name of the connection '" + name + "'.")
561 setConnectionName (SimpleConnection _ _ _ _ (Just name), element) =
562 match possibleObject element MOD.ElementToComponent with
563 Just c -> claimRelatedValue c L0.HasName name
564 Nothing -> print ("Failed to set the name of the connection '" + name + "'.")
565 setConnectionName (Flag _ name _ _ _ _ _ _ _, element) =
566 match possibleObject element MOD.ElementToComponent with
567 Just c -> claimRelatedValue c L0.HasName name
568 Nothing -> () // This is a typical case
569 setConnectionName _ = ()
571 """Returns a diagram in the given model with the given model relative path."""
572 diagram :: Model -> [String] -> <ReadGraph> Diagram
575 (\r name -> match possibleResourceChild r name with
577 Nothing -> fail ("Didn't find " + name + ".")
579 (configurationOf model) path
581 possibleDiagram :: Model -> [String] -> <ReadGraph> (Maybe Diagram)
582 possibleDiagram model path =
584 (\r name -> match r with
585 Just p -> possibleResourceChild p name
588 (Just (configurationOf model)) path
591 """FIXME: doesn't work anymore with the elementsOfR spec
592 elementsOf :: Diagram -> <ReadGraph> [DiagramElement String]
593 elementsOf diagram = map (mapDiagramElement nameOf mapTerminal possibleNameOf nameOf)
594 $ elementsOfR diagram
596 nameOf r = relatedValue r L0.HasName
599 if name == "ConnectionPoint" &&
600 r == DIA.Flag.ConnectionPoint
605 """Returns the elements of the given diagram."""
606 elementsOfR :: Diagram -> <ReadGraph> [(DiagramElement Resource, Resource)]
607 elementsOfR diagram = filterJust $ map readElement'
608 (diagramResourceOf diagram # L0.ConsistsOf)
610 readElement' element = match readElement element with
611 Just el -> Just (el, element)
613 readElement element =
614 if element `isInstanceOf` DIA.Flag
615 then readFlag element
616 else if element `isInstanceOf` DIA.SVGElement
618 else if element `isInstanceOf` DIA.Monitor
619 then readMonitor element
620 else if element `isInstanceOf` DIA.RouteGraphConnection
621 then readConnection element
622 else if element `isInstanceOf` DIA.TextElement
623 then readText element
624 else if element `isInstanceOf` DIA.Element
625 then readComponent element
627 readFlag flag = Just $ Flag
633 (existsStatement3 flag DIA.HasFlagType DIA.FlagType.OutputFlag)
634 (existsStatement flag DIA.ExternalFlag)
635 ((possibleRelatedString flag DIA.Flag.HasIOTableBinding) :: (Maybe String))
636 ((possibleRelatedInteger flag DIA.Flag.HasIOTableRowIndex) :: (Maybe Integer))
638 (map toDynamic $ flag # DIA.FlagIsJoinedBy)
639 readComponent element = do
640 component = singleObject
642 MOD.ElementToComponent
648 (transformOf element)
649 (readAttributes component))
652 (relatedValue element G2D.HasSVGDocument)
653 (transformOf element)
655 readMonitor element = do
656 font = readFont element (singleObject element DIA.HasFont)
657 hAlign = resourceToAlignment (singleObject element G2D.HasHorizontalAlignment)
658 vAlign = resourceToAlignment (singleObject element G2D.HasVerticalAlignment)
659 label = (relatedValue2 element L0.HasLabel)
660 strokeWidth = relatedValueWithDefault (-1.0) element G2D.HasStrokeWidth
661 transform = (transformOf element)
662 match (existsStatement element DIA.HasMonitorSuffix) with
664 suffix = (relatedValue element DIA.HasMonitorSuffix)
665 monitorComponent = (singleObject element DIA.HasMonitorComponent)
666 componentName = relatedValue monitorComponent L0.HasName
667 Just (Monitor label (Just (MonitorReference componentName suffix)) (MonitorVisuals font strokeWidth hAlign vAlign) transform)
668 False -> Just (Monitor label Nothing (MonitorVisuals font strokeWidth hAlign vAlign) transform)
669 readText element = do
670 elementType = singleTypeOf element DIA.Element
671 font = readPossibleFont element
672 hAlign = resourceToAlignment (singleObject element G2D.HasHorizontalAlignment)
673 vAlign = resourceToAlignment (singleObject element G2D.HasVerticalAlignment)
674 text = relatedValueWithDefault "" element DIA.HasText
675 transform = (transformOf element)
676 Just (Text elementType text (TextVisuals font hAlign vAlign) transform)
677 readPossibleFont element =
678 match possibleObject element DIA.HasFont with
679 Just f -> readFont element f
681 readFont element font = do
682 if font `isInstanceOf` DIA.RealizedFont
684 family = (relatedValue font DIA.RealizedFont.HasFamily)
685 size = (relatedValue font DIA.RealizedFont.HasSize)
686 style = (relatedValue font DIA.RealizedFont.HasStyle)
687 Just (Font family size style)
689 readAttributes component = let
690 allPredicates = map objectOf (statements (singleTypeOf component L0.Entity) L0.DomainOf)
691 is p = isSubrelationOf p L0.HasProperty
692 hasPropertyPredicates = filter is allPredicates
693 propertyStatements = map (singleStatement component) hasPropertyPredicates
694 p stm = match (untypedPossibleValueOf (objectOf stm)) with
695 Just v -> Just (Property (predicateOf stm) v)
697 in mapMaybe p propertyStatements
699 readConnection element = do
700 connectors = element # DIA.HasConnector
701 routeLines = element # DIA.HasInteriorRouteNode
702 nodes = map (readConnector element) connectors
703 + map readRouteLine routeLines
705 nodeResources = connectors + routeLines
706 nodeResourceWithIds = zip nodeResources [0..length nodeResources-1]
708 rMap = Map.fromList nodeResourceWithIds
711 | r <- node # DIA.AreConnected
712 , j = Map.unsafeGet rMap r
714 concatMap edgesOf nodeResourceWithIds
716 Just $ Connection nodes edges (readConnectionName element)
717 readConnectionName element =
718 match possibleObject element MOD.ElementToComponent with
719 Just c -> possibleNameOf c
721 readConnector connection r = Terminal
722 (idOf $ objectOf stat)
723 (inverseOf $ predicateOf stat)
726 | stat <- statements r STR.Connects
727 , objectOf stat != connection
729 readRouteLine r = RouteLine
730 (relatedValue r DIA.IsHorizontal)
731 (relatedValue r DIA.HasPosition)
732 transformOf element = do
733 da = fromDoubleArray $
734 relatedValue element DIA.HasTransform
735 Position (da!0) (da!1) (da!2) (da!3) (da!4) (da!5)
736 nameOf r = relatedValue r L0.HasName
737 labelOf r = relatedValue2 r L0.HasLabel
738 idOf r = match possibleObject r MOD.ElementToComponent with
740 Nothing -> if r `isInstanceOf` DIA.Flag
741 then "FLAG_" + nameOf r
742 else fail ("Element " + show r + " was not mapped to a component.")
744 importJava "org.simantics.diagram.synchronization.graph.DiagramGraphUtil" where
745 """Takes one connection element and returns possible diagram type."""
746 determineConnectionType :: Resource -> <ReadGraph> Maybe Resource
748 rotateConnection :: Resource -> Double -> Double -> Boolean -> <WriteGraph> ()
749 flipConnection :: Resource -> Boolean -> Double -> <WriteGraph> ()
751 applyDiagramMapping :: Resource -> <Proc,WriteGraph> ()
752 applyDiagramMapping diagram = do
753 syncActivateOnce diagram
756 """Returns the diagram flag type resource used for all generic diagram flags."""
757 genericFlagType :: () -> <ReadGraph> Resource
758 genericFlagType _ = DIA.Flag
760 /* Use functions in Simantics/PageSettings
761 importJava "org.simantics.diagram.synchronization.graph.DiagramGraphUtil" where
762 @JavaName setPageBordersVisible
763 setPageBordersVisible :: Diagram -> Boolean -> <WriteGraph> ()
765 @JavaName setMarginsVisible
766 setMarginsVisible :: Diagram -> Boolean -> <WriteGraph> ()
768 importJava "org.simantics.modeling.typicals.TypicalUtil" where
769 @JavaName newMasterTypical
770 newTypicalDiagram :: Library -> Diagram
772 @JavaName syncTypicalInstance
773 syncTypicalInstance :: Resource -> <WriteGraph> ()
775 syncActivateDiagram :: Diagram -> <WriteGraph, Proc> Boolean
776 syncActivateDiagram composite = do
777 diagram = compositeToDiagram' composite
778 syncActivateOnce diagram
781 // --- Diagrams ---------------------------------------------------
783 importJava "org.simantics.structural2.utils.StructuralUtils" where
784 @JavaName newComponent
785 createComposite__ :: Configuration -> String -> Resource -> <WriteGraph> Diagram
787 compositeToDiagram :: Resource -> <ReadGraph> Diagram
788 compositeToDiagram c = singleObject c MOD.CompositeToDiagram
790 createComposite :: Configuration -> String -> Resource -> <WriteGraph> Diagram
791 createComposite diagramFolder name compositeType = do
792 newName = findFreshName name diagramFolder
793 createComposite__ diagramFolder newName compositeType
795 elementToComponent :: Element -> <ReadGraph> Component
796 elementToComponent element = singleObject element MOD.ElementToComponent
798 componentToElement :: Component -> <ReadGraph> Element
799 componentToElement component = singleObject component MOD.ComponentToElement
801 getConnections :: Diagram -> <ReadGraph> [Resource]
802 getConnections diagram = [object | object <- (compositeToDiagram diagram) # L0.ConsistsOf, isInstanceOf object DIA.RouteGraphConnection]
804 getConnection :: Diagram -> String -> <ReadGraph> [Resource]
805 getConnection diagram name = do
806 connections = getConnections diagram
807 filter (\x -> relatedValue2 x L0.HasName == name) connections
809 setTransform :: Resource -> DoubleArray -> <WriteGraph> ()
810 setTransform element transform = claimRelatedValueWithType element DIA.HasTransform G2D.Transform transform
812 importJava "org.simantics.modeling.svg.CreateSVGElement" where
813 createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> ()
815 importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
817 importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where
818 removeElement :: Resource -> Resource -> <WriteGraph> ()
820 setStraightConnectionLines :: Resource -> Boolean -> <WriteGraph> ()
821 setStraightConnectionLines element v =
822 for (element # STR.IsConnectedTo) $ \connector ->
823 claimRelatedValue connector DIA.Connector.straight v
825 showProfileMonitors :: Resource -> Boolean -> <WriteGraph> ()
826 showProfileMonitors element v = claimRelatedValue element DIA.Element.hideProfileMonitors (not v)
828 setProfileMonitorsDirectionUp :: Resource -> Boolean -> <WriteGraph> ()
829 setProfileMonitorsDirectionUp element v = claimRelatedValue element DIA.Element.upProfileMonitors v
831 importJava "org.simantics.diagram.flag.Joiner" where
832 joinFlagsLocal :: [Resource] -> <WriteGraph> ()
834 importJava "org.simantics.diagram.flag.RouteGraphConnectionSplitter" where
835 splitConnection :: Resource -> Double -> Double -> <WriteGraph> ()
837 importJava "org.simantics.diagram.handler.CopyPasteUtil" where
838 moveConnection :: Resource -> Double -> Double -> <WriteGraph> ()
840 importJava "org.simantics.diagram.content.ConnectionUtil" where
841 translateRouteNodes :: Resource -> Double -> Double -> <WriteGraph> ()
843 importJava "org.simantics.diagram.synchronization.graph.DiagramGraphUtil" where
844 defaultSymbolDropHandler :: [WorkbenchSelectionElement] -> <WriteGraph> ()