]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/scl/Simantics/District.scl
First prototype of HSV color space based dynamic DN element coloring
[simantics/district.git] / org.simantics.district.network / scl / Simantics / District.scl
1 import "Simantics/DB"
2 import "Simantics/Ontologies"
3 import "Simantics/Variables"
4 import "http://www.simantics.org/DistrictNetwork-1.0" as DN
5
6 import "Map" as Map
7 import "MSet" as MSet
8
9 importJava "org.simantics.district.network.DistrictNetworkUtil" where
10     calculateDistance :: Resource -> Resource -> <ReadGraph> Double
11
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
17
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 ()
23     iter (\el -> do
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"
29         iter (\cpr -> do
30             connectionPoints = objectsWithType el cpr DIA.Connector
31             print $ "Found " + show (length connectionPoints) + " cps"
32             if length connectionPoints > 1 /*|| length connectionPoints == 0*/
33             then do
34                 // get existing map
35                 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
36                 instances = match MMap.get symbols (uriOf symbol) with
37                     Just m -> m
38                     Nothing -> do
39                         set = MSet.create ()
40                         MMap.put symbols (uriOf symbol) set
41                         set
42                 ignore $ MSet.add instances $ singleObject el MOD.ElementToComponent
43             else ()
44             ()
45         ) connectionPointRelations
46     ) elements
47     MMap.iter (\key val -> do
48         print key
49         MSet.iter (\v -> print (nameOf v)) val
50         ()
51     ) symbols 
52     ()
53
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"
59     iter (\el -> do
60         connectionPoints = objectsWithType el STR.IsConnectedTo DIA.Connector
61         print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
62     ) elements
63
64
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 ()
71         iter (\cp -> do
72             aconnector = singleObject cp  DIA.AreConnected
73             //otherElem
74             ()
75         ) []
76         //if length areConnected == 2
77         //then do // this we can handle - only two symbols
78         //    ()
79         //else ()
80         ()
81     else ()
82     ()
83
84 importJava "org.simantics.district.network.DistrictNetworkUtil" where
85     createVertex :: Resource -> Vector Double -> Resource -> <WriteGraph, Proc> Resource
86     createEdge :: Resource -> Resource -> <WriteGraph, Proc> Resource
87
88 """
89 Tries to look for the Variable representing the configuration component
90 mapped to the specified district network diagram element.
91
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.
94 """
95 possibleMappedComponentVariable :: Resource -> <ReadGraph> Maybe Variable
96 possibleMappedComponentVariable r = match possibleObject r DN.MappedComponent with
97     Nothing -> Nothing
98     Just me -> match possibleObject me MOD.ElementToComponent with
99         Nothing -> Nothing
100         Just mc -> do
101             mcv = resourceVariable mc
102             match possibleActiveVariable mcv with
103                 Nothing -> Just mcv
104                 a       -> a
105
106 """
107 """
108 possibleMappedComponentPropertyValue :: String -> Resource -> <ReadGraph> Maybe Double
109 possibleMappedComponentPropertyValue propName r = match possibleMappedComponentVariable r with
110     Nothing -> Nothing
111     Just mv -> possiblePropertyValue mv propName
112
113 """
114 """
115 mappedComponentPropertyValue :: Double -> String -> Resource -> <ReadGraph> Double
116 mappedComponentPropertyValue def propName r = match possibleMappedComponentVariable r with
117     Nothing -> def
118     Just mv -> match possiblePropertyValue mv propName with
119         Nothing -> def
120         Just v  -> v