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
11 nearbyVertices :: Resource -> Double -> <ReadGraph> [Resource]
13 importJava "org.simantics.district.network.ModelledCRS" where
14 xToLongitude :: Double -> <Proc> Double
15 yToLatitude :: Double -> <Proc> Double
16 longitudeToX :: Double -> <Proc> Double
17 latitudeToY :: Double -> <Proc> Double
19 findBrokenConnections :: Resource -> <ReadGraph, Proc> ()
20 findBrokenConnections diagram = do
21 elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement
22 print $ "Found " + show (length elements) + " elements from diagram"
23 symbols = MMap.create ()
25 symbol = singleObject el L0.InstanceOf
26 print $ "Found symbol " + uriOf symbol
27 ccs = collectionToList $ objects_ symbol L0.ConsistsOf
28 connectionPointRelations = filter (\cc -> isSubrelationOf cc STR.IsConnectedTo) ccs
29 print $ "Found " + show (length connectionPointRelations) + " cprs"
31 connectionPoints = objectsWithType el cpr DIA.Connector
32 print $ "Found " + show (length connectionPoints) + " cps"
33 if length connectionPoints > 1 /*|| length connectionPoints == 0*/
36 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
37 instances = match MMap.get symbols (uriOf symbol) with
41 MMap.put symbols (uriOf symbol) set
43 ignore $ MSet.add instances $ singleObject el MOD.ElementToComponent
46 ) connectionPointRelations
48 MMap.iter (\key val -> do
50 MSet.iter (\v -> print (nameOf v)) val
55 translateAllElements :: Resource -> <WriteGraph, Proc> ()
56 translateAllElements diagram = do
57 print $ "Translating elements of diagram " + uriOf diagram
58 elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement
59 print $ "Found " + show (length elements) + " elements from diagram"
61 connectionPoints = objectsWithType el STR.IsConnectedTo DIA.Connector
62 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
66 translateElement :: Resource -> <WriteGraph, Proc> ()
67 translateElement elem = do
68 connectionPoints = objectsWithType elem STR.IsConnectedTo DIA.Connector
69 if length connectionPoints < 5
70 then do //this we can handle
71 areConnected = MSet.create ()
73 aconnector = singleObject cp DIA.AreConnected
77 //if length areConnected == 2
78 //then do // this we can handle - only two symbols
85 importJava "org.simantics.district.network.DistrictNetworkUtil" where
86 createVertex :: Resource -> Vector Double -> Double -> Resource -> <WriteGraph, Proc> Resource
87 createEdge :: Resource -> Resource -> Vector Double -> <WriteGraph, Proc> Resource
90 Tries to look for the Resource representing the configuration component
91 mapped to the specified district network diagram element.
93 possibleMappedComponent :: Resource -> <ReadGraph> Maybe Resource
94 possibleMappedComponent r = match possibleObject r DN.MappedComponent with
96 Just me -> possibleObject me MOD.ElementToComponent
99 Tries to look for the Variable representing the configuration component
100 mapped to the specified district network diagram element.
102 The variable returned is by default the active experiment context variable
103 but if that is not available then a configuration context variable is returned.
105 possibleMappedComponentVariable :: Resource -> <ReadGraph> Maybe Variable
106 possibleMappedComponentVariable r = match possibleMappedComponent r with
109 mcv = resourceVariable mc
110 match possibleActiveVariable mcv with
116 possibleMappedComponentPropertyValue :: Serializable a => Typeable a => String -> Resource -> <ReadGraph> Maybe a
117 possibleMappedComponentPropertyValue propName r = match possibleMappedComponentVariable r with
119 Just mv -> possiblePropertyValue mv propName
123 mappedComponentPropertyValue :: Serializable a => Typeable a => a -> String -> Resource -> <ReadGraph> a
124 mappedComponentPropertyValue def propName r = match possibleMappedComponentVariable r with
126 Just mv -> match possiblePropertyValue mv propName with
131 Returns possible district network element that is mapped to the
132 specified model configuration component. The DN element is found
133 using the following relation path:
135 domain model configuration component ---[MOD.ComponentToElement]---> domain model diagram element
136 ----[DN.MappedFromElement]----> district network diagram element
138 possibleDNElementMappedToComponent :: Resource -> <ReadGraph> Maybe Resource
139 possibleDNElementMappedToComponent mappedComponent = match possibleObject mappedComponent MOD.ComponentToElement with
141 Just element -> possibleObject element DN.MappedFromElement
144 Returns all district network elements that are found to be mapped the
145 specified mapped model configuration components by
146 [possibleDNElementMappedToComponent](possibleDNElementMappedToComponent).
148 The result list can be smaller than the input resource list, even empty.
150 dnElementsMappedToComponents :: [Resource] -> <ReadGraph> [Resource]
151 dnElementsMappedToComponents mappedComponents = mapMaybe possibleDNElementMappedToComponent mappedComponents
154 importJava "org.simantics.district.network.DistrictNetworkUtil" where
155 createNetworkDiagram :: Resource -> Resource -> String -> Resource -> Resource -> Resource -> Resource -> Resource -> <WriteGraph, Proc> Resource
156 changeMappingType :: Resource -> [Resource] -> <WriteGraph, Proc> ()
157 findDNElementById :: Resource -> String -> <ReadGraph, Proc> Maybe Resource
158 findDNElementByXYCoordinates :: Resource -> Double -> Double -> Double -> <ReadGraph, Proc> [Resource]