]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / UserComponent.scl
diff --git a/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl b/bundles/org.simantics.modeling/scl/Simantics/UserComponent.scl
new file mode 100644 (file)
index 0000000..0eaff18
--- /dev/null
@@ -0,0 +1,135 @@
+include "Simantics/Model"\r
+import "Simantics/Diagram"\r
+import "Simantics/Flag"\r
+include "Simantics/Ontologies"\r
+\r
+type UserComponent = Resource\r
+type ComponentTypeConfiguration = Resource\r
+type ComponentTypeProperty = Resource\r
+    \r
+importJava "org.simantics.modeling.NewComponentType" where\r
+    @JavaName createComponentType\r
+    createUserComponent :: Model -> <WriteGraph> UserComponent\r
+    \r
+configurationOfComponentType :: UserComponent -> <ReadGraph> Resource\r
+configurationOfComponentType component = do\r
+      config = singleObject (toResource component) STR.IsDefinedBy \r
+      config\r
+      \r
+importJava "org.simantics.modeling.flags.LiftFlag" where\r
+    liftFlag :: Resource -> <WriteGraph> Maybe String\r
+    \r
+flagToTerminal :: Flag -> <WriteGraph> Resource\r
+flagToTerminal flag = do\r
+    result = liftFlag (toResource flag)\r
+    if result == Nothing\r
+    then singleObject (toResource flag) DIA.IsLiftedAs\r
+    else do\r
+        show result\r
+        (toResource flag)\r
+    \r
+configToDiagram :: Resource -> Diagram\r
+configToDiagram config = do\r
+    fromResource config\r
+\r
+populateTerminalToSymbol :: Resource  -> (Double, Double) -> <WriteGraph> Element\r
+populateTerminalToSymbol terminal (x, y) = do\r
+    uc = singleObject terminal L0.PartOf\r
+    symbol = singleObject uc MOD.ComponentTypeToSymbol\r
+    diagram = singleObject symbol STR.IsDefinedBy\r
+    element = newResource ()\r
+    addToOrderedSet diagram element\r
+    claim diagram\r
+        L0.ConsistsOf\r
+        element\r
+    elementClass = singleObject terminal MOD.ConnectionRelationToTerminal\r
+    claim element\r
+        L0.InstanceOf\r
+        elementClass\r
+    s = ((match possibleRelatedValue diagram DIA.HasModCount with Nothing -> 1 ; Just v -> v) :: Long)\r
+    claimRelatedValue element\r
+        L0.HasName\r
+        (show s)\r
+    claimRelatedValue diagram \r
+        DIA.HasModCount\r
+        ((match possibleRelatedValue diagram DIA.HasModCount with Nothing -> 1 ; Just v -> v+1) :: Long)\r
+    claimRelatedValueWithType element\r
+        DIA.HasTransform\r
+        G2D.Transform\r
+        (toDoubleArray [1,0,0,1,x,y])\r
+    addToGraph diagram terminal element\r
+    addCommentMetadata ("Populated terminal " + (show element) + " to user component " + (show uc))\r
+    (fromResource element)\r
+\r
+importJava "org.simantics.modeling.symbolEditor.PopulateTerminal" where\r
+    addToGraph :: Resource -> Resource -> Resource -> <WriteGraph> ()\r
+\r
+importJava "org.simantics.modeling.NewSymbolGroupRequest" where\r
+    createNewSymbolGroup :: Model -> String -> <WriteGraph> Resource\r
+\r
+importJava "org.simantics.modeling.AssignSymbolGroupRequest" where\r
+    assignSymbolGroup :: [Resource] -> [Resource] -> [UserComponent] -> <WriteGraph> ()\r
+\r
+importJava "org.simantics.modeling.GetSymbolGroups" where\r
+    getSymbolGroups :: Resource -> <ReadGraph> [Resource]\r
+\r
+importJava "org.simantics.modeling.userComponent.ComponentTypeCommands" where\r
+    @JavaName createPropertyWithDefaults\r
+    createUserComponentProperty :: UserComponent -> <WriteGraph> Resource\r
+     \r
+    @JavaName rename\r
+    renameUserComponentProperty :: Resource -> String -> <WriteGraph> ()\r
+    \r
+    @JavaName setDescription\r
+    setUserComponentPropertyDescription :: Resource -> String -> <WriteGraph> ()\r
+    \r
+    @JavaName createMonitorPropertyWithDefaults\r
+    createUserComponentMonitorProperty :: UserComponent -> <WriteGraph> Resource\r
+    \r
+    setMonitorExpression :: Resource -> Resource -> String -> <WriteGraph> ()\r
+    \r
+    @JavaName setDefaultValue \r
+    setUserComponentPropertyDefaultValue :: Resource -> Resource -> String -> <WriteGraph> ()\r
+    \r
+    @JavaName setUnit\r
+    setUserComponentPropertyUnit :: Resource -> Resource -> String -> <WriteGraph> ()\r
+    \r
+    @JavaName setRange\r
+    setUserComponentPropertyRange :: Resource -> Resource -> String -> <WriteGraph> ()\r
+    \r
+    @JavaName setLabel\r
+    setUserComponentPropertyLabel :: Resource -> String -> <WriteGraph> ()\r
+\r
+    @private\r
+    editType :: Resource -> Resource -> Boolean -> String -> <WriteGraph> ()\r
+    \r
+setUserComponentPropertyRequiredType :: Resource -> Resource -> String -> <WriteGraph> ()\r
+setUserComponentPropertyRequiredType componentType property newValue = do\r
+    editType componentType property True newValue\r
\r
+importJava "org.simantics.modeling.UserComponentMigration" where\r
+    migrateUserComponents :: UserComponent -> UserComponent -> [Component] -> <WriteGraph> ()\r
+\r
+\r
+/*\r
+    @JavaName newAnnotationProperty\r
+    createProperty :: UserComponent -> <WriteGraph> ComponentTypeProperty\r
+    \r
+    @JavaName advancedAnnotationProperty\r
+    createAdvancedProperty :: UserComponent -> String -> String -> String -> String -> String -> String -> <WriteGraph> ComponentTypeProperty\r
+\r
+    @JavaName removeAnnotationProperty\r
+    removeProperty :: UserComponent -> ComponentTypeProperty -> <WriteGraph> ()\r
+*/\r
+\r
+"""\r
+`addUserComponentScript userComponent scriptType scriptCode` adds the script to the user component.\r
+"""\r
+addUserComponentScript :: Resource -> String -> String -> String -> <WriteGraph> ()\r
+addUserComponentScript userComponent scriptName scriptType scriptCode = do\r
+    script = newResource ()\r
+    claim script L0.InstanceOf STR.ComponentTypeScript\r
+    claim userComponent STR.ComponentType.hasScript script\r
+    claimRelatedValue script L0.HasName scriptName\r
+    claimRelatedValue script STR.ComponentTypeScript.type scriptType \r
+    claimRelatedValue script STR.ComponentTypeScript.code scriptCode \r