2 import "Simantics/Ontologies"
3 import "Simantics/Variables"
4 import "http://www.simantics.org/DistrictNetwork-1.0" as DN
9 importJava "org.simantics.district.network.DistrictNetworkUtil" where
10 calculateDistance :: Resource -> Resource -> <ReadGraph> Double
12 importJava "org.simantics.district.network.ModelledCRS" where
13 xToLongitude :: Double -> <Proc> Double
14 yToLatitude :: Double -> <Proc> Double
15 longitudeToX :: Double -> <Proc> Double
16 latitudeToY :: Double -> <Proc> Double
18 findBrokenConnections :: Resource -> <ReadGraph, Proc> ()
19 findBrokenConnections diagram = do
20 elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement
21 print $ "Found " + show (length elements) + " elements from diagram"
22 symbols = MMap.create ()
24 symbol = singleObject el L0.InstanceOf
25 print $ "Found symbol " + uriOf symbol
26 ccs = collectionToList $ objects_ symbol L0.ConsistsOf
27 connectionPointRelations = filter (\cc -> isSubrelationOf cc STR.IsConnectedTo) ccs
28 print $ "Found " + show (length connectionPointRelations) + " cprs"
30 connectionPoints = objectsWithType el cpr DIA.Connector
31 print $ "Found " + show (length connectionPoints) + " cps"
32 if length connectionPoints > 1 /*|| length connectionPoints == 0*/
35 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
36 instances = match MMap.get symbols (uriOf symbol) with
40 MMap.put symbols (uriOf symbol) set
42 ignore $ MSet.add instances $ singleObject el MOD.ElementToComponent
45 ) connectionPointRelations
47 MMap.iter (\key val -> do
49 MSet.iter (\v -> print (nameOf v)) val
54 translateAllElements :: Resource -> <WriteGraph, Proc> ()
55 translateAllElements diagram = do
56 print $ "Translating elements of diagram " + uriOf diagram
57 elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement
58 print $ "Found " + show (length elements) + " elements from diagram"
60 connectionPoints = objectsWithType el STR.IsConnectedTo DIA.Connector
61 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
65 translateElement :: Resource -> <WriteGraph, Proc> ()
66 translateElement elem = do
67 connectionPoints = objectsWithType elem STR.IsConnectedTo DIA.Connector
68 if length connectionPoints < 5
69 then do //this we can handle
70 areConnected = MSet.create ()
72 aconnector = singleObject cp DIA.AreConnected
76 //if length areConnected == 2
77 //then do // this we can handle - only two symbols
84 importJava "org.simantics.district.network.DistrictNetworkUtil" where
85 createVertex :: Resource -> Vector Double -> Resource -> <WriteGraph, Proc> Resource
86 createEdge :: Resource -> Resource -> <WriteGraph, Proc> Resource
89 Tries to look for the Variable representing the configuration component
90 mapped to the specified district network diagram element.
92 The variable returned is by default the active experiment context variable
93 but if that is not available then a configuration context variable is returned.
95 possibleMappedComponentVariable :: Resource -> <ReadGraph> Maybe Variable
96 possibleMappedComponentVariable r = match possibleObject r DN.MappedComponent with
98 Just me -> match possibleObject me MOD.ElementToComponent with
101 mcv = resourceVariable mc
102 match possibleActiveVariable mcv with
108 possibleMappedComponentPropertyValue :: String -> Resource -> <ReadGraph> Maybe Double
109 possibleMappedComponentPropertyValue propName r = match possibleMappedComponentVariable r with
111 Just mv -> possiblePropertyValue mv propName
115 mappedComponentPropertyValue :: Double -> String -> Resource -> <ReadGraph> Double
116 mappedComponentPropertyValue def propName r = match possibleMappedComponentVariable r with
118 Just mv -> match possiblePropertyValue mv propName with