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 -> Double -> Resource -> <WriteGraph, Proc> Resource
86 createEdge :: Resource -> Resource -> Vector Double -> <WriteGraph, Proc> Resource
89 Tries to look for the Resource representing the configuration component
90 mapped to the specified district network diagram element.
92 possibleMappedComponent :: Resource -> <ReadGraph> Maybe Resource
93 possibleMappedComponent r = match possibleObject r DN.MappedComponent with
95 Just me -> possibleObject me MOD.ElementToComponent
98 Tries to look for the Variable representing the configuration component
99 mapped to the specified district network diagram element.
101 The variable returned is by default the active experiment context variable
102 but if that is not available then a configuration context variable is returned.
104 possibleMappedComponentVariable :: Resource -> <ReadGraph> Maybe Variable
105 possibleMappedComponentVariable r = match possibleMappedComponent r with
108 mcv = resourceVariable mc
109 match possibleActiveVariable mcv with
115 possibleMappedComponentPropertyValue :: Serializable a => Typeable a => String -> Resource -> <ReadGraph> Maybe a
116 possibleMappedComponentPropertyValue propName r = match possibleMappedComponentVariable r with
118 Just mv -> possiblePropertyValue mv propName
122 mappedComponentPropertyValue :: Serializable a => Typeable a => a -> String -> Resource -> <ReadGraph> a
123 mappedComponentPropertyValue def propName r = match possibleMappedComponentVariable r with
125 Just mv -> match possiblePropertyValue mv propName with
130 Returns possible district network element that is mapped to the
131 specified model configuration component. The DN element is found
132 using the following relation path:
134 domain model configuration component ---[MOD.ComponentToElement]---> domain model diagram element
135 ----[DN.MappedFromElement]----> district network diagram element
137 possibleDNElementMappedToComponent :: Resource -> <ReadGraph> Maybe Resource
138 possibleDNElementMappedToComponent mappedComponent = match possibleObject mappedComponent MOD.ComponentToElement with
140 Just element -> possibleObject element DN.MappedFromElement
143 Returns all district network elements that are found to be mapped the
144 specified mapped model configuration components by
145 [possibleDNElementMappedToComponent](possibleDNElementMappedToComponent).
147 The result list can be smaller than the input resource list, even empty.
149 dnElementsMappedToComponents :: [Resource] -> <ReadGraph> [Resource]
150 dnElementsMappedToComponents mappedComponents = mapMaybe possibleDNElementMappedToComponent mappedComponents
153 importJava "org.simantics.district.network.DistrictNetworkUtil" where
154 createNetworkDiagram :: Resource -> Resource -> String -> Resource -> Resource -> Resource -> Resource -> Resource -> <WriteGraph, Proc> Resource
155 changeMappingType :: Resource -> [Resource] -> <WriteGraph, Proc> ()
156 findDNElementById :: Resource -> String -> <ReadGraph, Proc> Maybe Resource
157 findDNElementByXYCoordinates :: Resource -> Double -> Double -> Double -> <ReadGraph, Proc> [Resource]