]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/scl/Simantics/District.scl
Allow starting/ending of manual network creation to vertices only
[simantics/district.git] / org.simantics.district.network / scl / Simantics / District.scl
index c92cc4cc6e97b88cbbe9dee9b971f52f43d06c85..f96ed607da33ee705fd591a08c946f401b3522ae 100644 (file)
@@ -1,5 +1,7 @@
 import "Simantics/DB"
 import "Simantics/Ontologies"
+import "Simantics/Variables"
+import "http://www.simantics.org/DistrictNetwork-1.0" as DN
 
 import "Map" as Map
 import "MSet" as MSet
@@ -78,3 +80,71 @@ translateElement elem = do
         ()
     else ()
     ()
+
+importJava "org.simantics.district.network.DistrictNetworkUtil" where
+    createVertex :: Resource -> Vector Double -> Double -> Resource -> <WriteGraph, Proc> Resource
+    createEdge :: Resource -> Resource -> Vector Double -> <WriteGraph, Proc> Resource
+
+"""
+Tries to look for the Resource representing the configuration component
+mapped to the specified district network diagram element.
+"""
+possibleMappedComponent :: Resource -> <ReadGraph> Maybe Resource
+possibleMappedComponent r = match possibleObject r DN.MappedComponent with
+    Nothing -> Nothing
+    Just me -> possibleObject me MOD.ElementToComponent
+
+"""
+Tries to look for the Variable representing the configuration component
+mapped to the specified district network diagram element.
+
+The variable returned is by default the active experiment context variable
+but if that is not available then a configuration context variable is returned.
+"""
+possibleMappedComponentVariable :: Resource -> <ReadGraph> Maybe Variable
+possibleMappedComponentVariable r = match possibleMappedComponent r with
+    Nothing -> Nothing
+    Just mc -> do
+        mcv = resourceVariable mc
+        match possibleActiveVariable mcv with
+            Nothing -> Just mcv
+            a       -> a
+
+"""
+"""
+possibleMappedComponentPropertyValue :: Serializable a => Typeable a => String -> Resource -> <ReadGraph> Maybe a
+possibleMappedComponentPropertyValue propName r = match possibleMappedComponentVariable r with
+    Nothing -> Nothing
+    Just mv -> possiblePropertyValue mv propName
+
+"""
+"""
+mappedComponentPropertyValue :: Serializable a => Typeable a => a -> String -> Resource -> <ReadGraph> a
+mappedComponentPropertyValue def propName r = match possibleMappedComponentVariable r with
+    Nothing -> def
+    Just mv -> match possiblePropertyValue mv propName with
+        Nothing -> def
+        Just v  -> v
+
+"""
+Returns possible district network element that is mapped to the
+specified model configuration component. The DN element is found
+using the following relation path:
+
+    domain model configuration component ---[MOD.ComponentToElement]---> domain model diagram element
+                                         ----[DN.MappedFromElement]----> district network diagram element
+"""
+possibleDNElementMappedToComponent :: Resource -> <ReadGraph> Maybe Resource
+possibleDNElementMappedToComponent mappedComponent = match possibleObject mappedComponent MOD.ComponentToElement with
+    Nothing      -> Nothing
+    Just element -> possibleObject element DN.MappedFromElement
+
+"""
+Returns all district network elements that are found to be mapped the
+specified mapped model configuration components by
+[possibleDNElementMappedToComponent](possibleDNElementMappedToComponent).
+
+The result list can be smaller than the input resource list, even empty.
+"""
+dnElementsMappedToComponents :: [Resource] -> <ReadGraph> [Resource]
+dnElementsMappedToComponents mappedComponents = mapMaybe possibleDNElementMappedToComponent mappedComponents