From fe1c824058f007a649d32da56664e5c7d3259444 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Wed, 25 May 2022 23:46:19 +0300 Subject: [PATCH] Add executionPeriod property for user component SCL scripts Also added SCL API for setting/getting the execution periods of scripts: * `Simantics/UserComponent/setUserCOmponentScriptExecutionPeriod * `Simantics/UserComponent/userComponentTypeScriptExecutionPeriod gitlab #847 (cherry picked from commit 17b6833652ecfebf4cb3f231a94b54e158dccd6b) --- .../scl/Simantics/UserComponent.scl | 35 +++++++++++++++++++ .../graph/Structural.pgraph | 1 + 2 files changed, 36 insertions(+) diff --git a/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl b/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl index d79db9222..b28faa9fb 100644 --- a/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl +++ b/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl @@ -134,6 +134,41 @@ addUserComponentScript userComponent scriptName scriptType scriptCode = do claimRelatedValue script STR.ComponentTypeScript.type scriptType claimRelatedValue script STR.ComponentTypeScript.code scriptCode +@private +componentTypeScriptsWithName :: Resource -> String -> [Resource] +componentTypeScriptsWithName userComponent scriptName = + filter (\r -> nameOf r == scriptName) + (userComponent # STR.ComponentType.hasScript) + +""" +`setUserComponentScriptExecutionPeriod userComponent scriptName (Just N)` +sets the execution period of the specified `userComponent`s SCL scripts +with the specified `scriptName` to N seconds. + +To disable the execution period setting for a script/scripts specify +`executionPeriod` `Nothing` or `(Just 0)`. +""" +setUserComponentScriptExecutionPeriod :: Resource -> String -> Maybe Double -> () +setUserComponentScriptExecutionPeriod userComponent scriptName executionPeriod = + iter setExecutionPeriod + (componentTypeScriptsWithName userComponent scriptName) + where + setExecutionPeriod script = match executionPeriod with + Just ep -> claimRelatedValue script STR.ComponentTypeScript.executionPeriod ep + Nothing -> denyByPredicate script STR.ComponentTypeScript.executionPeriod + +""" +`userComponentScriptExecutionPeriod userComponent scriptName` +gets the execution periods of all user SCL scripts of the specified +`userComponent` with the name `scriptName`. +""" +userComponentScriptExecutionPeriod :: Resource -> String -> [Double] +userComponentScriptExecutionPeriod userComponent scriptName = + map executionPeriod + (componentTypeScriptsWithName userComponent scriptName) + where + executionPeriod script = fromMaybe 0 (possibleRelatedValue script STR.ComponentTypeScript.executionPeriod) + @private possibleSubstructure :: Resource -> Maybe Resource possibleSubstructure element = do diff --git a/bundles/org.simantics.structural.ontology/graph/Structural.pgraph b/bundles/org.simantics.structural.ontology/graph/Structural.pgraph index aa31879c5..b35588610 100644 --- a/bundles/org.simantics.structural.ontology/graph/Structural.pgraph +++ b/bundles/org.simantics.structural.ontology/graph/Structural.pgraph @@ -339,6 +339,7 @@ STR.ComponentType STR.ComponentTypeScript -- STR.ComponentTypeScript.type --> L0.String -- STR.ComponentTypeScript.code --> L0.String -- STR.ComponentTypeScript.executionPeriod --> L0.Double