positionToDoubleArray (Position a b c d e f) = toDoubleArray [a,b,c,d,e,f]
+positionToVector :: Position -> Vector Double
+positionToVector (Position a b c d e f) = runProc
+ (do r = createMVector 6
+ setMVector r 0 a
+ setMVector r 1 b
+ setMVector r 2 c
+ setMVector r 3 d
+ setMVector r 4 e
+ setMVector r 5 f
+ freezeMVector r)
+
// --- Diagram element data types -----------------------------------
data Property res = Property res Dynamic
"""Returns all diagrams of the given model."""
diagramsOf :: Model -> <ReadGraph> [Diagram]
-diagramsOf model = recurse
- DIA.Diagram
- (configurationOf model)
+diagramsOf model = diagramsUnder $ configurationOf model
+
+"""
+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`.
+"""
+diagramsUnder :: DiagramFolder -> <ReadGraph> [Resource]
+diagramsUnder folder = recurse DIA.Diagram folder
where
recurse t r = do
cs = children r
diagramResourceOf :: Diagram -> <ReadGraph> Resource
diagramResourceOf d = singleObject d MOD.CompositeToDiagram
-import "Extras/HashMap" as Map
-
"""Constructs a transformation for a diagram element."""
mapDiagramElement :: (a -> <e> b) -> (a -> <e> b) -> (a -> <e> Maybe b) -> (a -> <e> b) -> DiagramElement a -> <e> DiagramElement b
mapDiagramElement mapComponentType mapTerminal mapAttribute mapFlagType diagramElement =
configuration = diagram'
diagram = compositeToDiagram' configuration
hasName = L0.HasName
- componentMap = Map.fromList [ (c `relatedValue` hasName :: String, c)
- | c <- children configuration
- ]
+ componentMap = MMap.fromEntryList [ (c `relatedValue` hasName :: String, c)
+ | c <- children configuration
+ ]
denyByPredicate diagram L0.ConsistsOf
elements = setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs
claimRelatedValue diagram DIA.HasModCount
createDiagramR (NewDiagram model path folderType compositeType) joinMap elementSpecs = (runProc do
configuration = createConfiguration ()
diagram = compositeToDiagram' configuration
- elements = setElements (DiagramInfo diagram configuration (Map.create ())) joinMap elementSpecs
+ elements = setElements (DiagramInfo diagram configuration (MMap.create ())) joinMap elementSpecs
claimRelatedValue diagram DIA.HasModCount
(fromInteger (length elements) :: Long)
(configuration, elements)
/*
createJoin :: (Dynamic -> <WriteGraph> Resource) -> Dynamic -> <Proc,WriteGraph> Resource
-createJoin joinMap key = if Map.contains joinMap key
- then Map.unsafeGet joinMap key
+createJoin joinMap key = if MMap.containsKey joinMap key
+ then MMap.unsafeGet joinMap key
else do
j = newEntity [
hasType STR.ConnectionJoin
]
- Map.put joinMap key j
+ MMap.put joinMap key j
j
*/
data DiagramInfo = DiagramInfo
Resource // diagram
Resource // configuration
- (Map.T String Resource) // existing components
+ (MMap.T String Resource) // existing components
"""
Sets the elements of the diagram. Diagram is assumed to be empty,
for (zip elementSpecs elements) setConnectionName
elements
) where
- elementMap = Map.create ()
+ elementMap = MMap.create ()
idRef = ref (0 :: Integer)
isConnectionResource r = isInstanceOf r DIA.Connection
idRef := id + 1
show id
createElement (Component componentType name position properties) = do
- component = if Map.contains componentMap name
- then Map.unsafeGet componentMap name
+ component = if MMap.containsKey componentMap name
+ then MMap.unsafeGet componentMap name
else newEntity [
hasName name,
hasParent configuration,
MOD.ElementToComponent
component
]
- Map.put elementMap name element
+ MMap.put elementMap name element
Just element
newOrMappedElement eName = do
- element = match Map.get elementMap eName with
+ element = match MMap.get elementMap eName with
Just element -> element
Nothing -> newEntity []
- Map.put elementMap eName element
+ MMap.put elementMap eName element
element
createElement (SimpleConnection aName ar bName br _) = do
connection = newEntity [
then do
claim flag DIA.ExternalFlag flag
else ()
- Map.put elementMap name flag
+ MMap.put elementMap name flag
Just flag
createElement (Connection nodeSpecs edges _) = do
connection = newEntity [
hasFont font
]
createElement (Monitor label (Just (MonitorReference componentName suffix)) (MonitorVisuals font strokeWidth hAlign vAlign) position) = do
- match (Map.get elementMap componentName) with
+ match (MMap.get elementMap componentName) with
Nothing -> Nothing // Monitored component is not on the same diagram as the monitor. Not supported by this routine.
Just element -> do
component = singleObject element MOD.ElementToComponent
nodeResources = connectors + routeLines
nodeResourceWithIds = zip nodeResources [0..length nodeResources-1]
edges = runProc do
- rMap = Map.fromList nodeResourceWithIds
+ rMap = MMap.fromEntryList nodeResourceWithIds
edgesOf (node,i) =
[ Edge i j
| r <- node # DIA.AreConnected
- , j = Map.unsafeGet rMap r
+ , j = MMap.unsafeGet rMap r
, j > i ]
concatMap edgesOf nodeResourceWithIds
importJava "org.simantics.modeling.svg.CreateSVGElement" where
createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> ()
+ createSVGElementR :: Resource -> String -> ByteArray -> Double -> Double -> <WriteGraph> Resource
importSVGElement :: Resource -> File -> Double -> Double -> <WriteGraph> ()
+ importSVGElementR :: Resource -> File -> Double -> Double -> <WriteGraph> Resource
importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where
removeElement :: Resource -> Resource -> <WriteGraph> ()