X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fscl%2FSimantics%2FDistrict.scl;h=0e79ef774402aa6a83a06e093c9023129223c181;hb=refs%2Fchanges%2F10%2F3010%2F1;hp=8025c9adea127991bf78d7f98ff3b0644ec6998e;hpb=1bc60c2213f9b3fc7b4d935ba9afda2b767290e5;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 8025c9ad..0e79ef77 100644 --- a/org.simantics.district.network/scl/Simantics/District.scl +++ b/org.simantics.district.network/scl/Simantics/District.scl @@ -1,4 +1,10 @@ import "Simantics/DB" +import "Simantics/Ontologies" +import "Simantics/Variables" +import "http://www.simantics.org/DistrictNetwork-1.0" as DN + +import "Map" as Map +import "MSet" as MSet importJava "org.simantics.district.network.DistrictNetworkUtil" where calculateDistance :: Resource -> Resource -> Double @@ -7,4 +13,146 @@ importJava "org.simantics.district.network.ModelledCRS" where xToLongitude :: Double -> Double yToLatitude :: Double -> Double longitudeToX :: Double -> Double - latitudeToY :: Double -> Double \ No newline at end of file + 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 -> Double -> Resource -> Resource + createEdge :: Resource -> Resource -> Vector Double -> Resource + +""" +Tries to look for the Resource representing the configuration component +mapped to the specified district network diagram element. +""" +possibleMappedComponent :: Resource -> 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. + +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 -> Maybe Variable +possibleMappedComponentVariable r = match possibleMappedComponent r with + Nothing -> Nothing + Just mc -> do + mcv = resourceVariable mc + match possibleActiveVariable mcv with + Nothing -> Just mcv + a -> a + +""" +""" +possibleMappedComponentPropertyValue :: Serializable a => Typeable a => String -> Resource -> Maybe a +possibleMappedComponentPropertyValue propName r = match possibleMappedComponentVariable r with + Nothing -> Nothing + Just mv -> possiblePropertyValue mv propName + +""" +""" +mappedComponentPropertyValue :: Serializable a => Typeable a => a -> String -> Resource -> a +mappedComponentPropertyValue def propName r = match possibleMappedComponentVariable r with + Nothing -> def + 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 -> 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] -> [Resource] +dnElementsMappedToComponents mappedComponents = mapMaybe possibleDNElementMappedToComponent mappedComponents + + +importJava "org.simantics.district.network.DistrictNetworkUtil" where + createNetworkDiagram :: Resource -> Resource -> String -> Resource -> Resource -> Resource -> Resource -> Resource -> Resource + changeMappingType :: Resource -> [Resource] -> () + findDNElementById :: Resource -> String -> Maybe Resource + findDNElementByXYCoordinates :: Resource -> Double -> Double -> Double -> [Resource] +