X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fscl%2FSimantics%2FDistrict.scl;h=6318d7550b5a7bfcf7a15c0a245bdce85c83aef9;hb=ac6ad8ff2b20a10e85e7b12c1af670500daebdd4;hp=ed1225138cbd09f84e39c286c68137e487be233e;hpb=55f42e7fcc2f6733082ab8c150efe3a2b54ff22b;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network/scl/Simantics/District.scl b/org.simantics.district.network/scl/Simantics/District.scl index ed122513..6318d755 100644 --- a/org.simantics.district.network/scl/Simantics/District.scl +++ b/org.simantics.district.network/scl/Simantics/District.scl @@ -1,4 +1,85 @@ import "Simantics/DB" +import "Simantics/Ontologies" + +import "Map" as Map +import "MSet" as MSet importJava "org.simantics.district.network.DistrictNetworkUtil" where - calculateDistance :: Resource -> Resource -> Double \ No newline at end of file + calculateDistance :: Resource -> Resource -> Double + +importJava "org.simantics.district.network.ModelledCRS" where + xToLongitude :: Double -> Double + yToLatitude :: Double -> Double + longitudeToX :: Double -> Double + latitudeToY :: Double -> Double + +findBrokenConnections :: Resource -> () +findBrokenConnections diagram = do + elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement + print $ "Found " + show (length elements) + " elements from diagram" + symbols = MMap.create () + iter (\el -> do + symbol = singleObject el L0.InstanceOf + print $ "Found symbol " + uriOf symbol + ccs = collectionToList $ objects_ symbol L0.ConsistsOf + connectionPointRelations = filter (\cc -> isSubrelationOf cc STR.IsConnectedTo) ccs + print $ "Found " + show (length connectionPointRelations) + " cprs" + iter (\cpr -> do + connectionPoints = objectsWithType el cpr DIA.Connector + print $ "Found " + show (length connectionPoints) + " cps" + if length connectionPoints > 1 /*|| length connectionPoints == 0*/ + then do + // get existing map + print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el + instances = match MMap.get symbols (uriOf symbol) with + Just m -> m + Nothing -> do + set = MSet.create () + MMap.put symbols (uriOf symbol) set + set + ignore $ MSet.add instances $ singleObject el MOD.ElementToComponent + else () + () + ) connectionPointRelations + ) elements + MMap.iter (\key val -> do + print key + MSet.iter (\v -> print (nameOf v)) val + () + ) symbols + () + +translateAllElements :: Resource -> () +translateAllElements diagram = do + print $ "Translating elements of diagram " + uriOf diagram + elements = objectsWithType diagram L0.ConsistsOf DIA.DefinedElement + print $ "Found " + show (length elements) + " elements from diagram" + iter (\el -> do + connectionPoints = objectsWithType el STR.IsConnectedTo DIA.Connector + print $ "Found " + show (length connectionPoints) + " connections for element " + nameOf el + ) elements + + +translateElement :: Resource -> () +translateElement elem = do + connectionPoints = objectsWithType elem STR.IsConnectedTo DIA.Connector + if length connectionPoints < 5 + then do //this we can handle + areConnected = MSet.create () + iter (\cp -> do + aconnector = singleObject cp DIA.AreConnected + //otherElem + () + ) [] + //if length areConnected == 2 + //then do // this we can handle - only two symbols + // () + //else () + () + else () + () + +importJava "org.simantics.district.network.DistrictNetworkUtil" where + createVertex :: Resource -> Vector Double -> Resource -> Resource + createEdge :: Resource -> Resource -> Resource +