X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.db%2Fscl%2FSimantics%2FVariables.scl;h=9a6ffde8c17267717a3113d3ecfded655e262942;hp=c54048a7387591409cd4eb543780f5d2a982709b;hb=21137c34eea354153dbc83b92a5be05957b48ee5;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl index c54048a73..9a6ffde8c 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/Variables.scl @@ -1,423 +1,430 @@ -include "Simantics/Model" -include "Simantics/DB" -import "Simantics/DB" as DB - -importJava "java.lang.Object" where - @JavaName equals - """ -Function **variableEquals** compares the given input variables and returns True if they are the same. - -Example: - - import "Simantics/Variables" - import "Apros/Module" - my_variable_1 = moduleVariable "PO01" - my_variable_2 = moduleVariable "PO02" - variableEquals my_variable_1 my_variable_2 - - > False - - """ - variableEquals :: Variable -> Variable -> Boolean - @JavaName hashCode - variableHash :: Variable -> Integer - -instance Eq Variable where - (==) = variableEquals - -instance Hashable Variable where - hashP = hashP . variableHash - -importJava "org.simantics.db.layer0.variable.Variables" where - @JavaName getVariable - """ -Function **variable** converts a variable URI to a variable. - -Example: - - import "Simantics/Variables" - import "Apros/Module" - model_id = model "Model" - my_component = getComponent model_id "PO01" - my_uri = uriOf my_component - my_variable = variable my_uri - my_variable - - > - """ - variable :: String -> Variable - - @JavaName getVariable - """ -Function **resourceVariable** converts a resource to a corresponding variable. - -Example: - - import "Simantics/Variables" - import "Apros/Module" - model_id = model "Model" - my_resource = getComponent model_id "PO01" - my_variable = resourceVariable my_resource - my_variable - - > - """ - resourceVariable :: Resource -> Variable - - @JavaName getModel - """ -Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource** - -Example: - - import "Simantics/Variables" - import "Apros/Module" - my_variable = moduleVariable "PO01" - my_model = modelOfVariable my_variable - my_model - - > #376833 - - // use function nameOf, which works for resources, to print out the name of the model - nameOf(my_model) - - > "Model" - - """ - modelOfVariable :: Variable -> Model - - @JavaName getModel - modelResourceOfVariable :: Variable -> Resource - - @JavaName possibleActiveVariable - possibleActiveVariable :: Variable -> Maybe Variable - - @JavaName switchPossibleContext - switchPossibleContext :: Variable -> Resource -> Maybe Variable - - @JavaName getIndexRoot - instanceIndexRoot :: Variable -> Resource - - createValueAccessor :: (Variable -> a) -> (Variable -> Binding b -> b) -> (Variable -> c -> ()) -> (Variable -> d -> Binding d -> ()) -> (Variable -> Datatype) -> ValueAccessor - -importJava "org.simantics.db.layer0.function.All" where - - standardGetValue1 :: Variable -> a - standardGetValue2 :: Variable -> Binding a -> a - standardSetValue2 :: Variable -> a -> () - standardSetValue3 :: Variable -> a -> Binding a -> () - standardGetDatatype :: Variable -> Datatype - -importJava "org.simantics.db.layer0.variable.VariableMap" where - data VariableMap - -importJava "org.simantics.db.layer0.variable.ValueAccessor" where - data ValueAccessor - -importJava "org.simantics.db.layer0.variable.Variable" where - data Variable - - @JavaName getProperties - properties_ :: Variable -> Collection Variable - @JavaName getChildren - children_ :: Variable -> Collection Variable - - @JavaName getValue - value_ :: Variable -> Binding a -> a - - @JavaName getDatatype - datatype :: Variable -> Datatype - - @JavaName getValue - untypedValue :: Variable -> a - - @JavaName getPossibleValue - possibleVariableValue_ :: Variable -> Binding a -> Maybe a - - @JavaName getPossibleValue - untypedPossibleVariableValue :: Variable -> Maybe a - - @private - @JavaName getChild - child_ :: Variable -> String -> Variable - - @private - @JavaName getPossibleChild - possibleChild_ :: Variable -> String -> Maybe Variable - - browse :: Variable -> String -> Variable - browsePossible :: Variable -> String -> Maybe Variable - - @JavaName getProperty - """ -Function **property** return the wanted property as **Variable** - -**Input 1:** Module which property we want to obtain as **Variable** - -**Input 2:** Name of the property as **String** - -**Output:** wanted property as **Variable** - -Example - - import "Simantics/Variables" - import "Apros/Module" - my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE" - my_property_variable - - > - """ - property :: Variable -> String -> Variable - - @JavaName getPossibleProperty - possibleProperty :: Variable -> String -> Maybe Variable - - @JavaName getPropertyValue - propertyValue_ :: Variable -> String -> Binding a -> a - - @JavaName getPropertyValue - untypedPropertyValue :: Variable -> String -> a - - @JavaName getPossiblePropertyValue - possiblePropertyValue_ :: Variable -> String -> Binding a -> Maybe a - - @JavaName getPossiblePropertyValue - untypedPossiblePropertyValue :: Variable -> String -> Maybe a - - @JavaName getName - - """ -Function **name** return the name of the input variable as string - -Example: - - import "Simantics/Variables" - import "Apros/Module" - name (moduleVariable "PO01") - - > "PO01" - """ - - name :: Variable -> String - @JavaName getURI - """ -Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment** - -**Input 1:** wanted variable which uri is needed as **Variable** - -**Output:** uri of the variable as **String** - -Example: - - import "Simantics/Variables" - import "Apros/Module" - uri (moduleVariable "PO01") - - >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01" - - """ - uri :: Variable -> String - - @JavaName getParent - """ -Function **variableParent** returns the name of the parent variable as **Variable** - -Example: - - import "Simantics/Variables" - import "Apros/Module" - my_variable = moduleVariable "PO01" - variableParent my_variable - - > - - name (variableParent my_variable) - - > "NewGenericDiagram" - - """ - variableParent :: Variable -> Variable - - @JavaName getRepresents - - """ -Function **represents** returns the resource of the given input variable - -**Input 1:** **Variable** which resource is wanted to be obtainend - -**Output:** **Resource** of the given input variable. - -Example: Find out the resource of given variable - - import "Simantics/Variables" - import "Apros/Module" - represents (moduleVariable "PO01") - - > #426013 - - """ - represents :: Variable -> Resource - - @JavaName getPossibleRepresents - possibleRepresents :: Variable -> Maybe Resource - - @JavaName setValue - setValue :: Variable -> a -> () - - @JavaName setPropertyValue - setPropertyValue_ :: Variable -> String -> a -> Binding a -> () - - @JavaName getType - """ -Function **getType** returns the type of the input variable as resource - -Example: - - import "Simantics/Variables" - import "Apros/Module" - getType (moduleVariable "PO01") - - > #275837 - - nameOf(getType (moduleVariable "PO01")) - - > "POINT_QF" - """ - getType :: Variable -> Resource - - @JavaName getPossibleType - getPossibleType :: Variable -> Maybe Resource - - getPredicateResource :: Variable -> Resource - - getIndexRoot :: Variable -> Resource - -value :: Serializable a => Typeable a => Variable -> a -value var = value_ var binding - -possibleVariableValue :: Serializable a => Typeable a => Variable -> Maybe a -possibleVariableValue var = possibleVariableValue_ var binding - -""" -Function **propertyValue** finds the value of given property. - -Example: Find out the value of point PO01 attribute PO11_PRESSURE - - import "Simantics/Variables" - import "Apros/Module" - propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double - - > 0.75 - -""" - -propertyValue :: Serializable a => Typeable a => Variable -> String -> a -propertyValue var prop = propertyValue_ var prop binding - -possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> Maybe a -possiblePropertyValue var prop = possiblePropertyValue_ var prop binding - -""" -Function **setPropertyValue** sets wanted to value to given Variable property. - -**Input 1:** Wanted module as **Variable** - -**Input 2:** Wanted property name as **String** - -**Output:** No output, given value is inserted to property - -Example: - - import "Simantics/Variables" - import "Apros/Module" - setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5 -""" - -setPropertyValue :: Serializable a => Variable -> String -> a -> () -setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding - -""" -Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable** - -Example: - - import "Simantics/Variables" - import "Apros/Module" - my_model_variable = modelVariableOfVariable (moduleVariable "PO01") - my_model_variable - - > - - name my_model_variable - - > "Model" -""" - -modelVariableOfVariable :: Variable -> Variable -modelVariableOfVariable var = variable $ uriOf $ toResource $ modelOfVariable var - -uniqueChild :: Model -> Resource -> String -> Variable -uniqueChild model typet childName = do - typeName = DB.nameOf typet - query = "Types: " + typeName + " AND Name: " + childName - moduleResources = searchByQuery (toResource model) query - variable $ uriOf $ moduleResources ! 0 - -""" -Function **properties** returns a list, which contains of the properties of the input variable as **Variable** - -Example 1: print out all the properties of certain point as they are shown in Variable Debugger. - - import "Simantics/Variables" - import "Apros/Module" - point_properties_list = properties (moduleVariable "PO01") - //print out the names of the properties - for point_properties_list (\x -> print(name x) ) - - > IncludedInSimulation - > PO11_PRESSURE - > IsDesynchronized - > PO11_PROPERTY_CALC - > PO11_EPM_ROU - > PO11_ELEV_FROM_BOT - ... - -Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing. - - import "Simantics/Variables" - import "Apros/Module" - point_properties_list = properties (moduleVariable "PO01") - for point_properties_list (\x -> do - //print out the names of the properties, which name start as "PO11" - if (take 4 (name x) == "PO11") then do - print(name x) - () - else do - () - ) - - > PO11_PRESSURE - > PO11_PROPERTY_CALC - > PO11_EPM_ROU - > PO11_ELEV_FROM_BOT - > PO11_NODE_VELOCITY_CALC - ... - -""" -properties = collectionToList . properties_ - -instance Show Variable where - show _ = "" - -instance Browsable Variable where - fromUri = variable - uriOf = uri - nameOf = name - possibleNameOf v = Just (name v) - children v = collectionToList (children_ v) - parent = variableParent - possibleParent v = Just (variableParent v) - valueOf v = untypedValue v - variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic) - child = child_ - possibleChild = possibleChild_ \ No newline at end of file +include "Simantics/Model" +include "Simantics/DB" +import "Simantics/DB" as DB + +importJava "org.simantics.db.layer0.variable.Variables" where + @JavaName getVariable + """ +Function **variable** converts a variable URI to a variable. + +Example: + + import "Simantics/Variables" + import "Apros/Module" + model_id = model "Model" + my_component = getComponent model_id "PO01" + my_uri = uriOf my_component + my_variable = variable my_uri + my_variable + + > + """ + variable :: String -> Variable + + @JavaName getPossibleVariable + possibleVariable :: String -> Maybe Variable + + @JavaName getVariable + """ +Function **resourceVariable** converts a resource to a corresponding variable. + +Example: + + import "Simantics/Variables" + import "Apros/Module" + model_id = model "Model" + my_resource = getComponent model_id "PO01" + my_variable = resourceVariable my_resource + my_variable + + > + """ + resourceVariable :: Resource -> Variable + + @JavaName getModel + """ +Function **modelOfVariable** returns the model, in which the given input variable is located, as **Resource** + +Example: + + import "Simantics/Variables" + import "Apros/Module" + my_variable = moduleVariable "PO01" + my_model = modelOfVariable my_variable + my_model + + > #376833 + + // use function nameOf, which works for resources, to print out the name of the model + nameOf(my_model) + + > "Model" + + """ + modelOfVariable :: Variable -> Model + + @JavaName getModel + modelResourceOfVariable :: Variable -> Resource + + @JavaName possibleActiveVariable + possibleActiveVariable :: Variable -> Maybe Variable + + @JavaName switchPossibleContext + switchPossibleContext :: Variable -> Resource -> Maybe Variable + + @JavaName getIndexRoot + instanceIndexRoot :: Variable -> Resource + + createValueAccessor :: (Variable -> a) -> (Variable -> Binding b -> b) -> (Variable -> c -> ()) -> (Variable -> d -> Binding d -> ()) -> (Variable -> Datatype) -> ValueAccessor + + @JavaName getConfigurationContext + possibleConfigurationContext :: Resource -> Variable + + setRVIProperty :: Variable -> RVI -> () + +importJava "org.simantics.db.layer0.function.All" where + + standardGetValue1 :: Variable -> a + standardGetValue2 :: Variable -> Binding a -> a + standardSetValue2 :: Variable -> a -> () + standardSetValue3 :: Variable -> a -> Binding a -> () + standardGetDatatype :: Variable -> Datatype + +importJava "org.simantics.db.layer0.variable.VariableMap" where + data VariableMap + +importJava "org.simantics.db.layer0.variable.ResourceCollectionVariableMap" where + @JavaName "" + createVariableMap :: [Resource] -> VariableMap + +importJava "org.simantics.db.layer0.variable.ValueAccessor" where + data ValueAccessor + +importJava "org.simantics.db.layer0.variable.Variable" where + data Variable + + @JavaName getRVI + rviOf :: Variable -> RVI + + @JavaName getProperties + properties_ :: Variable -> Collection Variable + + @JavaName getProperties + propertiesClassified_ :: Variable -> Resource -> Collection Variable + + @JavaName getChildren + children_ :: Variable -> Collection Variable + + @JavaName getValue + value_ :: Variable -> Binding a -> a + + @JavaName getDatatype + datatype :: Variable -> Datatype + + @JavaName getValue + untypedValue :: Variable -> a + + @JavaName getPossibleValue + possibleVariableValue_ :: Variable -> Binding a -> Maybe a + + @JavaName getPossibleValue + untypedPossibleVariableValue :: Variable -> Maybe a + + @private + @JavaName getChild + child_ :: Variable -> String -> Variable + + @private + @JavaName getPossibleChild + possibleChild_ :: Variable -> String -> Maybe Variable + + browse :: Variable -> String -> Variable + browsePossible :: Variable -> String -> Maybe Variable + + @JavaName getProperty + """ +Function **property** return the wanted property as **Variable** + +**Input 1:** Module which property we want to obtain as **Variable** + +**Input 2:** Name of the property as **String** + +**Output:** wanted property as **Variable** + +Example + + import "Simantics/Variables" + import "Apros/Module" + my_property_variable = property (moduleVariable "PO01") "PO11_PRESSURE" + my_property_variable + + > + """ + property :: Variable -> String -> Variable + + @JavaName getPossibleProperty + possibleProperty :: Variable -> String -> Maybe Variable + + @JavaName getPropertyValue + propertyValue_ :: Variable -> String -> Binding a -> a + + @JavaName getPropertyValue + untypedPropertyValue :: Variable -> String -> a + + @JavaName getPossiblePropertyValue + possiblePropertyValue_ :: Variable -> String -> Binding a -> Maybe a + + @JavaName getPossiblePropertyValue + untypedPossiblePropertyValue :: Variable -> String -> Maybe a + + @JavaName getName + + """ +Function **name** return the name of the input variable as string + +Example: + + import "Simantics/Variables" + import "Apros/Module" + name (moduleVariable "PO01") + + > "PO01" + """ + + name :: Variable -> String + @JavaName getURI + """ +Function **uri** return the uri of given variable. The uri is fetched from the active **Experiment** + +**Input 1:** wanted variable which uri is needed as **Variable** + +**Output:** uri of the variable as **String** + +Example: + + import "Simantics/Variables" + import "Apros/Module" + uri (moduleVariable "PO01") + + >"http://Projects/Development%20Project/Model/Experiment/8ee6b693-891b-438e-a597-9e15a2634e8b/NewGenericDiagram/PO01" + + """ + uri :: Variable -> String + + @JavaName getParent + """ +Function **variableParent** returns the name of the parent variable as **Variable** + +Example: + + import "Simantics/Variables" + import "Apros/Module" + my_variable = moduleVariable "PO01" + variableParent my_variable + + > + + name (variableParent my_variable) + + > "NewGenericDiagram" + + """ + variableParent :: Variable -> Variable + + @JavaName getRepresents + + """ +Function **represents** returns the resource of the given input variable + +**Input 1:** **Variable** which resource is wanted to be obtainend + +**Output:** **Resource** of the given input variable. + +Example: Find out the resource of given variable + + import "Simantics/Variables" + import "Apros/Module" + represents (moduleVariable "PO01") + + > #426013 + + """ + represents :: Variable -> Resource + + @JavaName getPossibleRepresents + possibleRepresents :: Variable -> Maybe Resource + + @JavaName setValue + setValue :: Variable -> a -> () + + @JavaName setPropertyValue + setPropertyValue_ :: Variable -> String -> a -> Binding a -> () + + @JavaName getType + """ +Function **getType** returns the type of the input variable as resource + +Example: + + import "Simantics/Variables" + import "Apros/Module" + getType (moduleVariable "PO01") + + > #275837 + + nameOf(getType (moduleVariable "PO01")) + + > "POINT_QF" + """ + getType :: Variable -> Resource + + @JavaName getPossibleType + getPossibleType :: Variable -> Maybe Resource + + getPredicateResource :: Variable -> Resource + + getIndexRoot :: Variable -> Resource + +value :: Serializable a => Typeable a => Variable -> a +value var = value_ var binding + +possibleVariableValue :: Serializable a => Typeable a => Variable -> Maybe a +possibleVariableValue var = possibleVariableValue_ var binding + +""" +Function **propertyValue** finds the value of given property. + +Example: Find out the value of point PO01 attribute PO11_PRESSURE + + import "Simantics/Variables" + import "Apros/Module" + propertyValue (moduleVariable "PO01") "PO11_PRESSURE" :: Double + + > 0.75 + +""" + +propertyValue :: Serializable a => Typeable a => Variable -> String -> a +propertyValue var prop = propertyValue_ var prop binding + +possiblePropertyValue :: Serializable a => Typeable a => Variable -> String -> Maybe a +possiblePropertyValue var prop = possiblePropertyValue_ var prop binding + +""" +Function **setPropertyValue** sets wanted to value to given Variable property. + +**Input 1:** Wanted module as **Variable** + +**Input 2:** Wanted property name as **String** + +**Output:** No output, given value is inserted to property + +Example: + + import "Simantics/Variables" + import "Apros/Module" + setPropertyValue (moduleVariable "PO01") "PO11_PRESSURE" 0.5 +""" + +setPropertyValue :: Serializable a => Variable -> String -> a -> () +setPropertyValue subject prediate value = setPropertyValue_ subject prediate value binding + +""" +Function **modelVariableOfVariable** returns the model, in which the given input Variable is located, as **Variable** + +Example: + + import "Simantics/Variables" + import "Apros/Module" + my_model_variable = modelVariableOfVariable (moduleVariable "PO01") + my_model_variable + + > + + name my_model_variable + + > "Model" +""" + +modelVariableOfVariable :: Variable -> Variable +modelVariableOfVariable var = variable $ uriOf $ modelOfVariable var + +uniqueChild :: Model -> Resource -> String -> Variable +uniqueChild model typet childName = do + typeName = DB.nameOf typet + query = "Types: " + typeName + " AND Name: " + childName + moduleResources = searchByQuery model query + variable $ uriOf $ moduleResources ! 0 + +""" +Function **properties** returns a list, which contains of the properties of the input variable as **Variable** + +Example 1: print out all the properties of certain point as they are shown in Variable Debugger. + + import "Simantics/Variables" + import "Apros/Module" + point_properties_list = properties (moduleVariable "PO01") + //print out the names of the properties + for point_properties_list (\x -> print(name x) ) + + > IncludedInSimulation + > PO11_PRESSURE + > IsDesynchronized + > PO11_PROPERTY_CALC + > PO11_EPM_ROU + > PO11_ELEV_FROM_BOT + ... + +Example 2: print out only the properties of a point, which name starts as "PO11". Else do nothing. + + import "Simantics/Variables" + import "Apros/Module" + point_properties_list = properties (moduleVariable "PO01") + for point_properties_list (\x -> do + //print out the names of the properties, which name start as "PO11" + if (take 4 (name x) == "PO11") then do + print(name x) + () + else do + () + ) + + > PO11_PRESSURE + > PO11_PROPERTY_CALC + > PO11_EPM_ROU + > PO11_ELEV_FROM_BOT + > PO11_NODE_VELOCITY_CALC + ... + +""" +properties = collectionToList . properties_ + +instance Show Variable where + show _ = "" + +instance Browsable Variable where + fromUri = variable + uriOf = uri + nameOf = name + possibleNameOf v = Just (name v) + children v = collectionToList (children_ v) + parent = variableParent + possibleParent v = Just (variableParent v) + valueOf v = untypedValue v + variantValueOf v = createVariant (datatype v) (untypedValue v :: Dynamic) + child = child_ + possibleChild = possibleChild_ + +propertiesClassified :: Variable -> Resource -> [Variable] +propertiesClassified parent classified = do + collectionToList $ propertiesClassified_ parent classified + +importJava "org.simantics.db.layer0.variable.RVI" where + data RVI + + resolvePossible :: RVI -> Variable -> Maybe Variable + +instantiateUnder :: Resource -> Resource -> Resource +instantiateUnder container typeToInstantiate = do + fn = (resourceVariable typeToInstantiate)#methods#instantiateUnder :: Resource -> Resource -> Resource + fn container typeToInstantiate \ No newline at end of file