X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fscl%2FSimantics%2FDiagram.scl;h=554a25edad081a50f4388688d19820b359440942;hp=2490acc5b916b52ccd6e05e8b26accfcf15abce8;hb=04f200d2010339b05ba016b6f0c247653f5bdc97;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl b/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl index 2490acc5b..554a25eda 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/Diagram.scl @@ -57,6 +57,17 @@ flipY (Position xx xy yx yy x y) = Position xx (-xy) yx (-yy) x y positionToDoubleArray (Position a b c d e f) = toDoubleArray [a,b,c,d,e,f] +positionToVector :: Position -> Vector Double +positionToVector (Position a b c d e f) = runProc + (do r = createMVector 6 + setMVector r 0 a + setMVector r 1 b + setMVector r 2 c + setMVector r 3 d + setMVector r 4 e + setMVector r 5 f + freezeMVector r) + // --- Diagram element data types ----------------------------------- data Property res = Property res Dynamic @@ -140,18 +151,18 @@ hasRandomIdentifier entity = runProc (claimRelatedValue_ entity L0.identifier GU diagramsOf :: Model -> [Diagram] diagramsOf model = recurse DIA.Diagram - (toResource (configurationOf model)) + (configurationOf model) where recurse t r = do - cs = resourceChildrenOf r - dias = map fromResource $ filter isDiagramComposite cs + cs = children r + dias = filter isDiagramComposite cs folders = filter (not . isDiagramComposite) cs dias + concatMap (recurse t) folders isDiagramComposite r = existsStatement r MOD.CompositeToDiagram """Returns a model relative path of the given diagram.""" pathOf :: Diagram -> [String] -pathOf diagram = map nameOf $ unfoldl aux $ toResource diagram +pathOf diagram = map nameOf $ unfoldl aux diagram where aux r = if existsStatement r SIMU.IsConfigurationOf then Nothing @@ -169,7 +180,7 @@ pathNameOf diagram = do // @Private? diagramResourceOf :: Diagram -> Resource -diagramResourceOf d = singleObject (toResource d) MOD.CompositeToDiagram +diagramResourceOf d = singleObject d MOD.CompositeToDiagram import "Extras/HashMap" as Map @@ -214,11 +225,11 @@ compositeToDiagram' c = singleObject c MOD.CompositeToDiagram """Creates or modifies an existing diagram to contain the given diagram elements.""" createDiagramR :: DiagramSpec -> (Dynamic -> Resource) -> [DiagramElement Resource] -> (Diagram, [Resource]) createDiagramR (ExistingDiagram diagram') joinMap elementSpecs = runProc do - configuration = toResource diagram' + configuration = diagram' diagram = compositeToDiagram' configuration hasName = L0.HasName componentMap = Map.fromList [ (c `relatedValue` hasName :: String, c) - | c <- resourceChildrenOf configuration + | c <- children configuration ] denyByPredicate diagram L0.ConsistsOf elements = setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpecs @@ -232,12 +243,12 @@ createDiagramR (NewDiagram model path folderType compositeType) joinMap elementS elements = setElements (DiagramInfo diagram configuration (Map.create ())) joinMap elementSpecs claimRelatedValue diagram DIA.HasModCount (fromInteger (length elements) :: Long) - (fromResource configuration, elements) + (configuration, elements) ) where createConfiguration () = do lastId = length path - 1 parentFolder = foldl (\p id -> getOrCreateFolder p (path!id)) - (toResource (configurationOf model)) + (configurationOf model) [0..lastId-1] createComposite_ parentFolder (path!lastId) compositeType getOrCreateFolder parentFolder name = @@ -250,14 +261,14 @@ claimFolder :: Model -> [String] -> Resource -> Resource claimFolder model path folderType = do lastId = length path foldl (\p id -> getOrCreateFolder p folderType (path!id)) - (toResource (configurationOf model)) + (configurationOf model) [0..lastId-1] claimModelFolder :: Model -> [String] -> Resource -> Resource claimModelFolder model path folderType = do lastId = length path foldl (\p id -> getOrCreateFolder p folderType (path!id)) - (toResource model) + model [0..lastId-1] getOrCreateFolder :: Resource -> Resource -> String -> Resource @@ -554,21 +565,21 @@ setElements (DiagramInfo diagram configuration componentMap) joinMap elementSpec """Returns a diagram in the given model with the given model relative path.""" diagram :: Model -> [String] -> Diagram diagram model path = - fromResource $ foldl + foldl (\r name -> match possibleResourceChild r name with Just c -> c Nothing -> fail ("Didn't find " + name + ".") ) - (toResource (configurationOf model)) path + (configurationOf model) path possibleDiagram :: Model -> [String] -> (Maybe Diagram) possibleDiagram model path = - map fromResource (foldl + foldl (\r name -> match r with Just p -> possibleResourceChild p name Nothing -> Nothing ) - (Just $ toResource (configurationOf model)) path) + (Just (configurationOf model)) path /* """FIXME: doesn't work anymore with the elementsOfR spec @@ -757,7 +768,7 @@ importJava "org.simantics.modeling.typicals.TypicalUtil" where syncActivateDiagram :: Diagram -> Boolean syncActivateDiagram composite = do - diagram = compositeToDiagram' $ toResource composite + diagram = compositeToDiagram' composite syncActivateOnce diagram True @@ -768,25 +779,21 @@ importJava "org.simantics.structural2.utils.StructuralUtils" where createComposite__ :: Configuration -> String -> Resource -> Diagram compositeToDiagram :: Resource -> Diagram -compositeToDiagram c = fromResource (singleObject c MOD.CompositeToDiagram) +compositeToDiagram c = singleObject c MOD.CompositeToDiagram createComposite :: Configuration -> String -> Resource -> Diagram createComposite diagramFolder name compositeType = do - newName = findFreshName name (toResource diagramFolder) + newName = findFreshName name diagramFolder createComposite__ diagramFolder newName compositeType elementToComponent :: Element -> Component -elementToComponent element = do - component = singleObject (toResource element) MOD.ElementToComponent - fromResource component +elementToComponent element = singleObject element MOD.ElementToComponent componentToElement :: Component -> Element -componentToElement component = do - element = singleObject (toResource component) MOD.ComponentToElement - fromResource element +componentToElement component = singleObject component MOD.ComponentToElement getConnections :: Diagram -> [Resource] -getConnections diagram = [object | object <- (toResource $ compositeToDiagram $ toResource diagram) # L0.ConsistsOf, isInstanceOf object DIA.RouteGraphConnection] +getConnections diagram = [object | object <- (compositeToDiagram diagram) # L0.ConsistsOf, isInstanceOf object DIA.RouteGraphConnection] getConnection :: Diagram -> String -> [Resource] getConnection diagram name = do @@ -798,8 +805,10 @@ setTransform element transform = claimRelatedValueWithType element DIA.HasTransf importJava "org.simantics.modeling.svg.CreateSVGElement" where createSVGElement :: Resource -> String -> ByteArray -> Double -> Double -> () + createSVGElementR :: Resource -> String -> ByteArray -> Double -> Double -> Resource importSVGElement :: Resource -> File -> Double -> Double -> () + importSVGElementR :: Resource -> File -> Double -> Double -> Resource importJava "org.simantics.diagram.synchronization.graph.RemoveElement" where removeElement :: Resource -> Resource -> ()