]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add executionPeriod property for user component SCL scripts
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 25 May 2022 20:46:19 +0000 (23:46 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 25 May 2022 21:11:12 +0000 (00:11 +0300)
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)

bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl
bundles/org.simantics.structural.ontology/graph/Structural.pgraph

index d79db922229d5c9c2bfa114d0f27c41e9f471d3f..b28faa9fb932ed6b87ca81b05983bfa734cb3dbe 100644 (file)
@@ -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 -> <ReadGraph> [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 -> <Proc,WriteGraph> ()
+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 -> <ReadGraph> [Double]
+userComponentScriptExecutionPeriod userComponent scriptName =
+    map executionPeriod
+        (componentTypeScriptsWithName userComponent scriptName)
+  where
+    executionPeriod script = fromMaybe 0 (possibleRelatedValue script STR.ComponentTypeScript.executionPeriod)
+
 @private
 possibleSubstructure :: Resource -> <ReadGraph> Maybe Resource
 possibleSubstructure element = do
index aa31879c524944a994d17f72065de7d328036170..b3558861055e7492da1e7ff93a8561b3c40ff6a5 100644 (file)
@@ -339,6 +339,7 @@ STR.ComponentType
 STR.ComponentTypeScript <T L0.Entity
     >-- STR.ComponentTypeScript.type --> L0.String <R L0.HasProperty : L0.FunctionalRelation
     >-- STR.ComponentTypeScript.code --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+    >-- STR.ComponentTypeScript.executionPeriod --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
 
 STR.ComponentType.Locked
     @L0.defTag