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 = recurse
154 (configurationOf model)
158 dias = filter isDiagramComposite cs
159 folders = filter (not . isDiagramComposite) cs
160 dias + concatMap (recurse t) folders
161 isDiagramComposite r = existsStatement r MOD.CompositeToDiagram
163 """Returns a model relative path of the given diagram."""
164 pathOf :: Diagram -> <ReadGraph> [String]
165 pathOf diagram = map nameOf $ unfoldl aux diagram
167 aux r = if existsStatement r SIMU.IsConfigurationOf
170 parents = r # L0.PartOf
171 if length parents == 1
172 then Just (r, parents!0)
174 nameOf r = relatedValue r $ L0.HasName
176 pathNameOf :: Diagram -> <ReadGraph> String
177 pathNameOf diagram = do
178 path = pathOf diagram
179 foldl1 (\s s1 -> s + " / " + s1) path
182 diagramResourceOf :: Diagram -> <ReadGraph> Resource
183 diagramResourceOf d = singleObject d MOD.CompositeToDiagram
185 import "Extras/HashMap" as Map
187 """Constructs a transformation for a diagram element."""
188 mapDiagramElement :: (a -> <e> b) -> (a -> <e> b) -> (a -> <e> Maybe b) -> (a -> <e> b) -> DiagramElement a -> <e> DiagramElement b
189 mapDiagramElement mapComponentType mapTerminal mapAttribute mapFlagType diagramElement =
190 (match diagramElement with
191 Component componentType name position properties -> do
192 Component (mapComponentType componentType) name position
193 (filterJust (map mapProperty properties))
194 SimpleConnection e1 r1 e2 r2 possibleName ->
195 SimpleConnection e1 (mapTerminal r1) e2 (mapTerminal r2) possibleName
196 Connection nodes edges possibleName ->
198 (map mapConnectionNode nodes)
200 Flag t e e2 e3 e4 e5 p p2 joins -> Flag (mapFlagType t) e e2 e3 e4 e5 p p2 joins
202 Monitor label ref visuals position -> Monitor label ref visuals position
203 Text elementType text visuals position -> Text elementType text visuals position
205 mapProperty (Property p v) =
206 match (mapAttribute p) with
207 Just mp -> Just (Property mp v)
209 mapConnectionNode (Terminal e r) = Terminal e (mapTerminal r)
210 mapConnectionNode (RouteLine iv p) = RouteLine iv p
212 importJava "org.simantics.structural2.utils.StructuralUtils" where
213 @JavaName newComponent
214 createComposite_ :: Resource -> String -> Resource -> <WriteGraph> Resource
216 data DiagramSpec = NewDiagram
218 [String] // path to the diagram
219 Resource // folder type
220 Resource // composite type
221 | ExistingDiagram Diagram
223 compositeToDiagram' c = singleObject c MOD.CompositeToDiagram
225 """Creates or modifies an existing diagram to contain the given diagram elements."""
226 createDiagramR :: DiagramSpec -> (Dynamic -> <WriteGraph> Resource) -> [DiagramElement Resource] -> <WriteGraph> (Diagram, [Resource])
227 createDiagramR (ExistingDiagram diagram') joinMap elementSpecs = runProc do
228 configuration = diagram'
229 diagram = compositeToDiagram' configuration
231 componentMap = Map.fromList [ (c `relatedValue` hasName :: String, c)
232 | c <- children configuration
234 denyByPredicate diagram L0.ConsistsOf
235 elements = setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs
236 claimRelatedValue diagram DIA.HasModCount
237 (fromInteger (length elements) :: Long)
240 createDiagramR (NewDiagram model path folderType compositeType) joinMap elementSpecs = (runProc do
241 configuration = createConfiguration ()
242 diagram = compositeToDiagram' configuration
243 elements = setElements (DiagramInfo diagram configuration (Map.create ())) joinMap elementSpecs
244 claimRelatedValue diagram DIA.HasModCount
245 (fromInteger (length elements) :: Long)
246 (configuration, elements)
248 createConfiguration () = do
249 lastId = length path - 1
250 parentFolder = foldl (\p id -> getOrCreateFolder p (path!id))
251 (configurationOf model)
253 createComposite_ parentFolder (path!lastId) compositeType
254 getOrCreateFolder parentFolder name =
255 match possibleResourceChild parentFolder name with
258 createComposite_ parentFolder name folderType
260 claimFolder :: Model -> [String] -> Resource -> <Proc,WriteGraph> Resource
261 claimFolder model path folderType = do
263 foldl (\p id -> getOrCreateFolder p folderType (path!id))
264 (configurationOf model)
267 claimModelFolder :: Model -> [String] -> Resource -> <Proc,WriteGraph> Resource
268 claimModelFolder model path folderType = do
270 foldl (\p id -> getOrCreateFolder p folderType (path!id))
274 getOrCreateFolder :: Resource -> Resource -> String -> <Proc,WriteGraph> Resource
275 getOrCreateFolder parentFolder folderType name = do
276 match possibleResourceChild parentFolder name with
279 createComposite_ parentFolder name folderType
281 relatedValueWithDefault :: Serializable a => a -> Resource -> Resource -> <ReadGraph> a
282 relatedValueWithDefault def r p =
283 if existsStatement r p
284 then relatedValue r p
287 applyConnectionType :: Resource -> <Proc,WriteGraph,ReadGraph> ()
288 applyConnectionType res = do
289 t = determineConnectionType res
291 Just t -> claim res STR.HasConnectionType t
292 Nothing -> print ("No connection type " + (show res))
295 importJava "org.simantics.modeling.utils.JoinMap" where
297 createJoinMap :: () -> <Proc> (Dynamic -> <WriteGraph> Resource)
300 createJoin :: (Dynamic -> <WriteGraph> Resource) -> Dynamic -> <Proc,WriteGraph> Resource
301 createJoin joinMap key = if Map.contains joinMap key
302 then Map.unsafeGet joinMap key
305 hasType STR.ConnectionJoin
307 Map.put joinMap key j
310 data DiagramInfo = DiagramInfo
312 Resource // configuration
313 (Map.T String Resource) // existing components
316 Sets the elements of the diagram. Diagram is assumed to be empty,
317 but the configuration may contain existing components that can be found
318 from the given existing components map.
320 setElements :: DiagramInfo -> (Dynamic -> <WriteGraph> Resource) -> [DiagramElement Resource] -> <Proc,WriteGraph> [Resource]
321 setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs = (do
322 /*elements = map createElement (filter (not . isConnection) elementSpecs)
323 + map createElement (filter isConnection elementSpecs)*/
324 elements = mapMaybe createElement elementSpecs
326 (claim diagram L0.ConsistsOf)
327 setOrderedSet diagram elements
328 iter applyConnectionType (filter isConnectionResource elements)
329 syncActivateOnce diagram
330 for (zip elementSpecs elements) setConnectionName
333 elementMap = Map.create ()
334 idRef = ref (0 :: Integer)
336 isConnectionResource r = isInstanceOf r DIA.Connection
337 isConnection (Connection _ _ _) = True
338 isConnection (SimpleConnection _ _ _ _ _) = True
339 isConnection _ = False
341 freshElementName () = do
345 createElement (Component componentType name position properties) = do
346 component = if Map.contains componentMap name
347 then Map.unsafeGet componentMap name
350 hasParent configuration,
353 for properties (\(Property prop value) ->
354 untypedClaimRelatedValue component prop value
356 element = newOrMappedElement name
357 element = updateEntity element [
358 hasName (freshElementName ()),
359 hasType componentType,
362 (positionToDoubleArray position)
365 MOD.ElementToComponent
368 Map.put elementMap name element
370 newOrMappedElement eName = do
371 element = match Map.get elementMap eName with
372 Just element -> element
373 Nothing -> newEntity []
374 Map.put elementMap eName element
376 createElement (SimpleConnection aName ar bName br _) = do
377 connection = newEntity [
378 hasName (freshElementName ()),
379 hasType DIA.RouteGraphConnection
381 a = newOrMappedElement aName
382 b = newOrMappedElement bName
383 ca = createConnector connection a ar
384 cb = createConnector connection b br
387 createElement (Flag t name label output external tableBinding tableRow position joins) = do
388 flag = newOrMappedElement name
389 flag = updateEntity flag [
390 hasName (freshElementName ()),
395 (positionToDoubleArray position)
398 DIA.Flag.HasIOTableBinding
401 DIA.Flag.HasIOTableRowIndex
412 claim flag DIA.HasFlagType DIA.FlagType.OutputFlag
416 claim flag DIA.ExternalFlag flag
418 Map.put elementMap name flag
420 createElement (Connection nodeSpecs edges _) = do
421 connection = newEntity [
422 hasName (freshElementName ()),
423 hasType DIA.RouteGraphConnection
426 nodes = map (createNode connection) nodeSpecs
427 for edges (\(Edge a b) -> connectNodes (nodes!a) (nodes!b))
429 createNode connection (Terminal elementName terminal) = do
430 element = newOrMappedElement elementName
431 createConnector connection element terminal
432 createNode connection (RouteLine isHorizontal position) = do
434 hasName (freshElementName ()),
435 hasType DIA.RouteLine,
436 hasProperty DIA.HasPosition
438 hasProperty DIA.IsHorizontal
440 hasStatement DIA.HasInteriorRouteNode.Inverse
443 createConnector connection component terminal = do
444 connector = newResource ()
448 claim component terminal connector
450 DIA.HasPlainConnector
454 claim a DIA.AreConnected b
455 createElement (SVG document position) =
457 hasName (freshElementName ()),
458 hasType DIA.SVGElement,
464 (positionToDoubleArray position)
467 createRealizedFont (Font family size style) = do
468 font = newResource ()
472 claimRelatedValue font DIA.RealizedFont.HasFamily family
473 claimRelatedValue font DIA.RealizedFont.HasSize size
474 claimRelatedValue font DIA.RealizedFont.HasStyle style
476 hasFont (Just font) = hasStatement DIA.HasFont (createRealizedFont font)
477 hasFont Nothing = const ()
478 createElement (Monitor label Nothing (MonitorVisuals font strokeWidth hAlign vAlign) position) = do
480 hasName (freshElementName ()),
487 (positionToDoubleArray position)
494 G2D.HasHorizontalAlignment
495 (alignmentToResource hAlign),
497 G2D.HasVerticalAlignment
498 (alignmentToResource vAlign),
501 createElement (Monitor label (Just (MonitorReference componentName suffix)) (MonitorVisuals font strokeWidth hAlign vAlign) position) = do
502 match (Map.get elementMap componentName) with
503 Nothing -> Nothing // Monitored component is not on the same diagram as the monitor. Not supported by this routine.
505 component = singleObject element MOD.ElementToComponent
507 hasName (freshElementName ()),
515 hasStatement DIA.HasMonitorComponent component,
518 (positionToDoubleArray position)
525 G2D.HasHorizontalAlignment
526 (alignmentToResource hAlign),
528 G2D.HasVerticalAlignment
529 (alignmentToResource vAlign),
532 createElement (Text elementType text (TextVisuals font hAlign vAlign) position) =
534 hasName (freshElementName ()),
541 (positionToDoubleArray position)
544 G2D.HasHorizontalAlignment
545 (alignmentToResource hAlign),
547 G2D.HasVerticalAlignment
548 (alignmentToResource vAlign),
551 setConnectionName (Connection _ _ (Just name), element) =
552 match possibleObject element MOD.ElementToComponent with
553 Just c -> claimRelatedValue c L0.HasName name
554 Nothing -> print ("Failed to set the name of the connection '" + name + "'.")
555 setConnectionName (SimpleConnection _ _ _ _ (Just name), element) =
556 match possibleObject element MOD.ElementToComponent with
557 Just c -> claimRelatedValue c L0.HasName name
558 Nothing -> print ("Failed to set the name of the connection '" + name + "'.")
559 setConnectionName (Flag _ name _ _ _ _ _ _ _, element) =
560 match possibleObject element MOD.ElementToComponent with
561 Just c -> claimRelatedValue c L0.HasName name
562 Nothing -> () // This is a typical case
563 setConnectionName _ = ()
565 """Returns a diagram in the given model with the given model relative path."""
566 diagram :: Model -> [String] -> <ReadGraph> Diagram
569 (\r name -> match possibleResourceChild r name with
571 Nothing -> fail ("Didn't find " + name + ".")
573 (configurationOf model) path
575 possibleDiagram :: Model -> [String] -> <ReadGraph> (Maybe Diagram)
576 possibleDiagram model path =
578 (\r name -> match r with
579 Just p -> possibleResourceChild p name
582 (Just (configurationOf model)) path
585 """FIXME: doesn't work anymore with the elementsOfR spec
586 elementsOf :: Diagram -> <ReadGraph> [DiagramElement String]
587 elementsOf diagram = map (mapDiagramElement nameOf mapTerminal possibleNameOf nameOf)
588 $ elementsOfR diagram
590 nameOf r = relatedValue r L0.HasName
593 if name == "ConnectionPoint" &&
594 r == DIA.Flag.ConnectionPoint
599 """Returns the elements of the given diagram."""
600 elementsOfR :: Diagram -> <ReadGraph> [(DiagramElement Resource, Resource)]
601 elementsOfR diagram = filterJust $ map readElement'
602 (diagramResourceOf diagram # L0.ConsistsOf)
604 readElement' element = match readElement element with
605 Just el -> Just (el, element)
607 readElement element =
608 if element `isInstanceOf` DIA.Flag
609 then readFlag element
610 else if element `isInstanceOf` DIA.SVGElement
612 else if element `isInstanceOf` DIA.Monitor
613 then readMonitor element
614 else if element `isInstanceOf` DIA.RouteGraphConnection
615 then readConnection element
616 else if element `isInstanceOf` DIA.TextElement
617 then readText element
618 else if element `isInstanceOf` DIA.Element
619 then readComponent element
621 readFlag flag = Just $ Flag
627 (existsStatement3 flag DIA.HasFlagType DIA.FlagType.OutputFlag)
628 (existsStatement flag DIA.ExternalFlag)
629 ((possibleRelatedString flag DIA.Flag.HasIOTableBinding) :: (Maybe String))
630 ((possibleRelatedInteger flag DIA.Flag.HasIOTableRowIndex) :: (Maybe Integer))
632 (map toDynamic $ flag # DIA.FlagIsJoinedBy)
633 readComponent element = do
634 component = singleObject
636 MOD.ElementToComponent
642 (transformOf element)
643 (readAttributes component))
646 (relatedValue element G2D.HasSVGDocument)
647 (transformOf element)
649 readMonitor element = do
650 font = readFont element (singleObject element DIA.HasFont)
651 hAlign = resourceToAlignment (singleObject element G2D.HasHorizontalAlignment)
652 vAlign = resourceToAlignment (singleObject element G2D.HasVerticalAlignment)
653 label = (relatedValue2 element L0.HasLabel)
654 strokeWidth = relatedValueWithDefault (-1.0) element G2D.HasStrokeWidth
655 transform = (transformOf element)
656 match (existsStatement element DIA.HasMonitorSuffix) with
658 suffix = (relatedValue element DIA.HasMonitorSuffix)
659 monitorComponent = (singleObject element DIA.HasMonitorComponent)
660 componentName = relatedValue monitorComponent L0.HasName
661 Just (Monitor label (Just (MonitorReference componentName suffix)) (MonitorVisuals font strokeWidth hAlign vAlign) transform)
662 False -> Just (Monitor label Nothing (MonitorVisuals font strokeWidth hAlign vAlign) transform)
663 readText element = do
664 elementType = singleTypeOf element DIA.Element
665 font = readPossibleFont element
666 hAlign = resourceToAlignment (singleObject element G2D.HasHorizontalAlignment)
667 vAlign = resourceToAlignment (singleObject element G2D.HasVerticalAlignment)
668 text = relatedValueWithDefault "" element DIA.HasText
669 transform = (transformOf element)
670 Just (Text elementType text (TextVisuals font hAlign vAlign) transform)
671 readPossibleFont element =
672 match possibleObject element DIA.HasFont with
673 Just f -> readFont element f
675 readFont element font = do
676 if font `isInstanceOf` DIA.RealizedFont
678 family = (relatedValue font DIA.RealizedFont.HasFamily)
679 size = (relatedValue font DIA.RealizedFont.HasSize)
680 style = (relatedValue font DIA.RealizedFont.HasStyle)
681 Just (Font family size style)
683 readAttributes component = let
684 allPredicates = map objectOf (statements (singleTypeOf component L0.Entity) L0.DomainOf)
685 is p = isSubrelationOf p L0.HasProperty
686 hasPropertyPredicates = filter is allPredicates
687 propertyStatements = map (singleStatement component) hasPropertyPredicates
688 p stm = match (untypedPossibleValueOf (objectOf stm)) with
689 Just v -> Just (Property (predicateOf stm) v)
691 in mapMaybe p propertyStatements
693 readConnection element = do
694 connectors = element # DIA.HasConnector
695 routeLines = element # DIA.HasInteriorRouteNode
696 nodes = map (readConnector element) connectors
697 + map readRouteLine routeLines
699 nodeResources = connectors + routeLines
700 nodeResourceWithIds = zip nodeResources [0..length nodeResources-1]
702 rMap = Map.fromList nodeResourceWithIds
705 | r <- node # DIA.AreConnected
706 , j = Map.unsafeGet rMap r
708 concatMap edgesOf nodeResourceWithIds
710 Just $ Connection nodes edges (readConnectionName element)
711 readConnectionName element =
712 match possibleObject element MOD.ElementToComponent with
713 Just c -> possibleNameOf c
715 readConnector connection r = Terminal
716 (idOf $ objectOf stat)
717 (inverseOf $ predicateOf stat)
720 | stat <- statements r STR.Connects
721 , objectOf stat != connection
723 readRouteLine r = RouteLine
724 (relatedValue r DIA.IsHorizontal)
725 (relatedValue r DIA.HasPosition)
726 transformOf element = do
727 da = fromDoubleArray $
728 relatedValue element DIA.HasTransform
729 Position (da!0) (da!1) (da!2) (da!3) (da!4) (da!5)
730 nameOf r = relatedValue r L0.HasName
731 labelOf r = relatedValue2 r L0.HasLabel
732 idOf r = match possibleObject r MOD.ElementToComponent with
734 Nothing -> if r `isInstanceOf` DIA.Flag
735 then "FLAG_" + nameOf r
736 else fail ("Element " + show r + " was not mapped to a component.")
738 importJava "org.simantics.diagram.synchronization.graph.DiagramGraphUtil" where
739 """Takes one connection element and returns possible diagram type."""
740 determineConnectionType :: Resource -> <ReadGraph> Maybe Resource
742 rotateConnection :: Resource -> Double -> Double -> Boolean -> <WriteGraph> ()
743 flipConnection :: Resource -> Boolean -> Double -> <WriteGraph> ()
745 applyDiagramMapping :: Resource -> <Proc,WriteGraph> ()
746 applyDiagramMapping diagram = do
747 syncActivateOnce diagram
750 """Returns the diagram flag type resource used for all generic diagram flags."""
751 genericFlagType :: () -> <ReadGraph> Resource
752 genericFlagType _ = DIA.Flag
754 /* Use functions in Simantics/PageSettings
755 importJava "org.simantics.diagram.synchronization.graph.DiagramGraphUtil" where
756 @JavaName setPageBordersVisible
757 setPageBordersVisible :: Diagram -> Boolean -> <WriteGraph> ()
759 @JavaName setMarginsVisible
760 setMarginsVisible :: Diagram -> Boolean -> <WriteGraph> ()
762 importJava "org.simantics.modeling.typicals.TypicalUtil" where
763 @JavaName newMasterTypical
764 newTypicalDiagram :: Library -> Diagram
766 @JavaName syncTypicalInstance
767 syncTypicalInstance :: Resource -> <WriteGraph> ()
769 syncActivateDiagram :: Diagram -> <WriteGraph, Proc> Boolean
770 syncActivateDiagram composite = do
771 diagram = compositeToDiagram' composite
772 syncActivateOnce diagram
775 // --- Diagrams ---------------------------------------------------
777 importJava "org.simantics.structural2.utils.StructuralUtils" where
778 @JavaName newComponent
779 createComposite__ :: Configuration -> String -> Resource -> <WriteGraph> Diagram
781 compositeToDiagram :: Resource -> <ReadGraph> Diagram
782 compositeToDiagram c = singleObject c MOD.CompositeToDiagram
784 createComposite :: Configuration -> String -> Resource -> <WriteGraph> Diagram
785 createComposite diagramFolder name compositeType = do
786 newName = findFreshName name diagramFolder
787 createComposite__ diagramFolder newName compositeType
789 elementToComponent :: Element -> <ReadGraph> Component
790 elementToComponent element = singleObject element MOD.ElementToComponent
792 componentToElement :: Component -> <ReadGraph> Element
793 componentToElement component = singleObject component MOD.ComponentToElement
795 getConnections :: Diagram -> <ReadGraph> [Resource]
796 getConnections diagram = [object | object <- (compositeToDiagram diagram) # L0.ConsistsOf, isInstanceOf object DIA.RouteGraphConnection]
798 getConnection :: Diagram -> String -> <ReadGraph> [Resource]
799 getConnection diagram name = do
800 connections = getConnections diagram
801 filter (\x -> relatedValue2 x L0.HasName == name) connections
803 setTransform :: Resource -> DoubleArray -> <WriteGraph> ()
804 setTransform element transform = claimRelatedValueWithType element DIA.HasTransform G2D.Transform transform
806 importJava "org.simantics.modeling.svg.CreateSVGElement" where
807 createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> ()
809 importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
811 importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where
812 removeElement :: Resource -> Resource -> <WriteGraph> ()
814 setStraightConnectionLines :: Resource -> Boolean -> <WriteGraph> ()
815 setStraightConnectionLines element v =
816 for (element # STR.IsConnectedTo) $ \connector ->
817 claimRelatedValue connector DIA.Connector.straight v
819 showProfileMonitors :: Resource -> Boolean -> <WriteGraph> ()
820 showProfileMonitors element v = claimRelatedValue element DIA.Element.hideProfileMonitors (not v)
822 setProfileMonitorsDirectionUp :: Resource -> Boolean -> <WriteGraph> ()
823 setProfileMonitorsDirectionUp element v = claimRelatedValue element DIA.Element.upProfileMonitors v
825 importJava "org.simantics.diagram.flag.Joiner" where
826 joinFlagsLocal :: [Resource] -> <WriteGraph> ()
828 importJava "org.simantics.diagram.flag.RouteGraphConnectionSplitter" where
829 splitConnection :: Resource -> Double -> Double -> <WriteGraph> ()
831 importJava "org.simantics.diagram.handler.CopyPasteUtil" where
832 moveConnection :: Resource -> Double -> Double -> <WriteGraph> ()
834 importJava "org.simantics.diagram.content.ConnectionUtil" where
835 translateRouteNodes :: Resource -> Double -> Double -> <WriteGraph> ()
837 importJava "org.simantics.diagram.synchronization.graph.DiagramGraphUtil" where
838 defaultSymbolDropHandler :: [WorkbenchSelectionElement] -> <WriteGraph> ()