]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Added new functions to Simantics/District 42/2542/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 10 Dec 2018 13:16:17 +0000 (15:16 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 10 Dec 2018 13:18:38 +0000 (15:18 +0200)
* possibleMappedComponent
* possibleDNElementMappedToComponent
* dnElementsMappedToComponents

gitlab #23

Change-Id: Ic6775beef2f6be30af655f4af243f1ee733b8842

org.simantics.district.network/scl/Simantics/District.scl

index b99442e6b0177c9e5e3c032c0ff42eadb029a1cf..36dee3979b74ea97dbc7fc2e15fa507518332a11 100644 (file)
@@ -85,6 +85,15 @@ importJava "org.simantics.district.network.DistrictNetworkUtil" where
     createVertex :: Resource -> Vector Double -> Resource -> <WriteGraph, Proc> Resource
     createEdge :: Resource -> Resource -> <WriteGraph, Proc> Resource
 
     createVertex :: Resource -> Vector Double -> Resource -> <WriteGraph, Proc> Resource
     createEdge :: Resource -> Resource -> <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.
 """
 Tries to look for the Variable representing the configuration component
 mapped to the specified district network diagram element.
@@ -93,15 +102,13 @@ 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
 but if that is not available then a configuration context variable is returned.
 """
 possibleMappedComponentVariable :: Resource -> <ReadGraph> Maybe Variable
-possibleMappedComponentVariable r = match possibleObject r DN.MappedComponent with
+possibleMappedComponentVariable r = match possibleMappedComponent r with
     Nothing -> Nothing
     Nothing -> Nothing
-    Just me -> match possibleObject me MOD.ElementToComponent with
-        Nothing -> Nothing
-        Just mc -> do
-            mcv = resourceVariable mc
-            match possibleActiveVariable mcv with
-                Nothing -> Just mcv
-                a       -> a
+    Just mc -> do
+        mcv = resourceVariable mc
+        match possibleActiveVariable mcv with
+            Nothing -> Just mcv
+            a       -> a
 
 """
 """
 
 """
 """
@@ -118,3 +125,26 @@ mappedComponentPropertyValue def propName r = match possibleMappedComponentVaria
     Just mv -> match possiblePropertyValue mv propName with
         Nothing -> def
         Just v  -> v
     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