2 import "Simantics/Ontologies"
7 importJava "org.simantics.district.network.DistrictNetworkUtil" where
8 calculateDistance :: Resource -> Resource -> <ReadGraph> Double
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
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 ()
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"
28 connectionPoints = objectsWithType el cpr DIA.Connector
29 print $ "Found " + show (length connectionPoints) + " cps"
30 if length connectionPoints > 1 /*|| length connectionPoints == 0*/
33 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
34 instances = match MMap.get symbols (uriOf symbol) with
38 MMap.put symbols (uriOf symbol) set
40 ignore $ MSet.add instances $ singleObject el MOD.ElementToComponent
43 ) connectionPointRelations
45 MMap.iter (\key val -> do
47 MSet.iter (\v -> print (nameOf v)) val
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"
58 connectionPoints = objectsWithType el STR.IsConnectedTo DIA.Connector
59 print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el
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 ()
70 aconnector = singleObject cp DIA.AreConnected
74 //if length areConnected == 2
75 //then do // this we can handle - only two symbols