X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.annotation.ui%2Fscl%2FSimantics%2FAnnotation2.scl;fp=bundles%2Forg.simantics.annotation.ui%2Fscl%2FSimantics%2FAnnotation2.scl;h=ab97387d6be76b82605fe97909b578da6fedf80c;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.annotation.ui/scl/Simantics/Annotation2.scl b/bundles/org.simantics.annotation.ui/scl/Simantics/Annotation2.scl new file mode 100644 index 000000000..ab97387d6 --- /dev/null +++ b/bundles/org.simantics.annotation.ui/scl/Simantics/Annotation2.scl @@ -0,0 +1,122 @@ +import "Simantics/DB" +import "Simantics/Variables" +import "Simantics/Model" +import "Simantics/Diagram" +import "Simantics/Library" +import "Simantics/Misc" +import "Simantics/DB" as DB + +import "http://www.simantics.org/Layer0-1.1" as L0 +import "http://www.simantics.org/Layer0-1.1/HasRange" as HasRange +import "http://www.simantics.org/Annotation-1.0" as ANNO + +type Annotation = Resource +type AnnotationPropertyRelation = Resource +type AnnotationType = Resource +type AnnotationValue = Resource +type AnnotationProperty = Resource + +importJava "org.simantics.annotation.ui.SCLAnnotation" where + @JavaName newAnnotationType + """ + Creates new AnnotationType under the given Library instance and returns it without PropertyRelation + """ + newAnnotationType :: Library -> AnnotationType + + @JavaName newAnnotationValue + """ + Creates new AnnotationValue under the given Library instance with the AnnotationType reference. Returns the created AnnotationValue. + """ + newAnnotationValue :: Library -> AnnotationType -> AnnotationValue + newAnnotationValueWithName :: Library -> String -> AnnotationType -> AnnotationValue + + @JavaName newAnnotationType1 + """ + Creates new AnnotationType under the given Library instance. Returns a Tuple2 consisting the AnnotationPropertyRelation and AnnotationType instances. + """ + newAnnotationType1 :: Library -> (AnnotationPropertyRelation, AnnotationType) + + @JavaName newAnnotationProperty + """ + Creates new AnnotationProperty under the given AnnotatoinType instance. Returns the created AnnotationProperty. + """ + newAnnotationProperty :: AnnotationType -> AnnotationProperty + + @JavaName advancedAnnotationProperty + """ + Creates new AnnotationProperty under the given AnnotationType instance with advanced options for user to define non-default parameters for the following values + + * name + * type + * unit + * range + * label + * description + """ + advancedAnnotationProperty :: AnnotationType -> String -> String -> String -> String -> String -> String -> AnnotationProperty + + @JavaName removeAnnotationProperty + """ + Removes the given AnnotationProperty instance. + """ + removeAnnotationProperty :: AnnotationProperty -> () + + @JavaName attachAnnotation + """ + Attaches the given AnnotationType to the given Resource which can be for example a Diagram or a Symbol. + """ + attachAnnotationType :: Resource -> AnnotationType -> Annotation + + @JavaName setPropertyLabel + setPropertyLabel :: AnnotationProperty -> String -> () + + @JavaName setPropertyUnit + setPropertyUnit :: AnnotationProperty -> String -> () + + @JavaName setPropertyRange + setPropertyRange :: AnnotationProperty -> String -> () + + @JavaName setPropertyDescription + setPropertyDescription :: AnnotationProperty -> String -> () + + @JavaName setPropertyType + setPropertyType :: AnnotationProperty -> String -> () + + @JavaName saveAnnotation + saveAnnotation :: Annotation -> Library -> String -> Resource + + @JavaName importAnnotationFromFile + importAnnotation :: File -> Library -> () + + @JavaName exportAnnotationToFile + exportAnnotationType :: File -> AnnotationType -> () + + @JavaName copyAnnotationData + copyAnnotationData :: Resource -> Resource -> () + +getAnnotationNameFromType :: Resource -> String +getAnnotationNameFromType annotationType = do + relation = singleObject annotationType HasRange.Inverse + untypedRelatedValue relation L0.HasName + +getPossibleAnnotationType :: Resource -> String -> Maybe AnnotationType +getPossibleAnnotationType model name = do + all = searchByType model ANNO.AnnotationType + named = filter (\x -> (getAnnotationNameFromType x) == name) all + if ((length named) == 1) + then Just (fromResource $ named!0) + else Nothing + +setAnnotationPropertyValue :: AnnotationPropertyRelation -> Resource -> String -> String -> () +setAnnotationPropertyValue annotation resource property newValue = do + resourceUri = uriOf resource + annotationName = DB.nameOf (toResource annotation) + completeUri = resourceUri + "#" + annotationName + "#" + property + "#HasDisplayValue" + propertyVariable = variable completeUri + setValue propertyVariable newValue + +/* +findAnnotationType :: Model -> [AnnotationType] +findAnnotationType m = do + fromResource $ searchByQuery m "Types: AnnotationType" +*/