]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/scl/Simantics/District.scl
Pushing some (very) old changes to remote.. should have done long ago
[simantics/district.git] / org.simantics.district.network / scl / Simantics / District.scl
1 import "Simantics/DB"
2 import "Simantics/Ontologies"
3
4 import "Map" as Map
5 import "MSet" as MSet
6
7 importJava "org.simantics.district.network.DistrictNetworkUtil" where
8     calculateDistance :: Resource -> Resource -> <ReadGraph> Double
9
10 importJava "org.simantics.district.network.ModelledCRS" where
11     xToLongitude :: Double -> <Proc> Double
12     yToLatitude :: Double -> <Proc> Double
13     longitudeToX :: Double -> <Proc> Double
14     latitudeToY :: Double -> <Proc> Double
15
16 findBrokenConnections :: Resource -> <ReadGraph, Proc> ()
17 findBrokenConnections diagram = do
18     elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement
19     print $ "Found " + show (length elements) + " elements from diagram"
20     symbols = MMap.create ()
21     iter (\el -> do
22         symbol = singleObject el L0.InstanceOf
23         print $ "Found symbol " + uriOf symbol
24         ccs = collectionToList $ objects_ symbol L0.ConsistsOf
25         connectionPointRelations = filter (\cc -> isSubrelationOf cc  STR.IsConnectedTo) ccs
26         print $ "Found " + show (length connectionPointRelations) + " cprs"
27         iter (\cpr -> do
28             connectionPoints = objectsWithType el cpr DIA.Connector
29             print $ "Found " + show (length connectionPoints) + " cps"
30             if length connectionPoints > 1 /*|| length connectionPoints == 0*/
31             then do
32                 // get existing map
33                 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
34                 instances = match MMap.get symbols (uriOf symbol) with
35                     Just m -> m
36                     Nothing -> do
37                         set = MSet.create ()
38                         MMap.put symbols (uriOf symbol) set
39                         set
40                 ignore $ MSet.add instances $ singleObject el MOD.ElementToComponent
41             else ()
42             ()
43         ) connectionPointRelations
44     ) elements
45     MMap.iter (\key val -> do
46         print key
47         MSet.iter (\v -> print (nameOf v)) val
48         ()
49     ) symbols 
50     ()
51
52 translateAllElements :: Resource -> <WriteGraph, Proc> ()
53 translateAllElements diagram = do
54     print $ "Translating elements of diagram " + uriOf diagram 
55     elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement
56     print $ "Found " + show (length elements) + " elements from diagram"
57     iter (\el -> do
58         connectionPoints = objectsWithType el STR.IsConnectedTo DIA.Connector
59         print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
60     ) elements
61
62
63 translateElement :: Resource -> <WriteGraph, Proc> ()
64 translateElement elem = do
65     connectionPoints = objectsWithType elem STR.IsConnectedTo DIA.Connector
66     if length connectionPoints < 5
67     then do //this we can handle
68         areConnected = MSet.create ()
69         iter (\cp -> do
70             aconnector = singleObject cp  DIA.AreConnected
71             //otherElem
72             ()
73         ) []
74         //if length areConnected == 2
75         //then do // this we can handle - only two symbols
76         //    ()
77         //else ()
78         ()
79     else ()
80     ()