2 import "Simantics/Variables"
3 import "Simantics/Model"
4 import "Simantics/Diagram"
5 import "Simantics/Library"
6 import "Simantics/Misc"
7 import "Simantics/DB" as DB
9 import "http://www.simantics.org/Layer0-1.1" as L0
10 import "http://www.simantics.org/Layer0-1.1/HasRange" as HasRange
11 import "http://www.simantics.org/Annotation-1.0" as ANNO
13 type Annotation = Resource
14 type AnnotationPropertyRelation = Resource
15 type AnnotationType = Resource
16 type AnnotationValue = Resource
17 type AnnotationProperty = Resource
19 importJava "org.simantics.annotation.ui.SCLAnnotation" where
20 @JavaName newAnnotationType
22 Creates new AnnotationType under the given Library instance and returns it without PropertyRelation
24 newAnnotationType :: Library -> <WriteGraph> AnnotationType
26 @JavaName newAnnotationValue
28 Creates new AnnotationValue under the given Library instance with the AnnotationType reference. Returns the created AnnotationValue.
30 newAnnotationValue :: Library -> AnnotationType -> <WriteGraph> AnnotationValue
31 newAnnotationValueWithName :: Library -> String -> AnnotationType -> <WriteGraph> AnnotationValue
33 @JavaName newAnnotationType1
35 Creates new AnnotationType under the given Library instance. Returns a Tuple2 consisting the AnnotationPropertyRelation and AnnotationType instances.
37 newAnnotationType1 :: Library -> <WriteGraph> (AnnotationPropertyRelation, AnnotationType)
39 @JavaName newAnnotationProperty
41 Creates new AnnotationProperty under the given AnnotatoinType instance. Returns the created AnnotationProperty.
43 newAnnotationProperty :: AnnotationType -> <WriteGraph> AnnotationProperty
45 @JavaName advancedAnnotationProperty
47 Creates new AnnotationProperty under the given AnnotationType instance with advanced options for user to define non-default parameters for the following values
56 advancedAnnotationProperty :: AnnotationType -> String -> String -> String -> String -> String -> String -> <WriteGraph> AnnotationProperty
58 @JavaName removeAnnotationProperty
60 Removes the given AnnotationProperty instance.
62 removeAnnotationProperty :: AnnotationProperty -> <WriteGraph> ()
64 @JavaName attachAnnotation
66 Attaches the given AnnotationType to the given Resource which can be for example a Diagram or a Symbol.
68 attachAnnotationType :: Resource -> AnnotationType -> <WriteGraph> Annotation
70 @JavaName setPropertyLabel
71 setPropertyLabel :: AnnotationProperty -> String -> <WriteGraph> ()
73 @JavaName setPropertyUnit
74 setPropertyUnit :: AnnotationProperty -> String -> <WriteGraph> ()
76 @JavaName setPropertyRange
77 setPropertyRange :: AnnotationProperty -> String -> <WriteGraph> ()
79 @JavaName setPropertyDescription
80 setPropertyDescription :: AnnotationProperty -> String -> <WriteGraph> ()
82 @JavaName setPropertyType
83 setPropertyType :: AnnotationProperty -> String -> <WriteGraph> ()
85 @JavaName saveAnnotation
86 saveAnnotation :: Annotation -> Library -> String -> <WriteGraph> Resource
88 @JavaName importAnnotationFromFile
89 importAnnotation :: File -> Library -> <Proc> ()
91 @JavaName exportAnnotationToFile
92 exportAnnotationType :: File -> AnnotationType -> <Proc> ()
94 @JavaName copyAnnotationData
95 copyAnnotationData :: Resource -> Resource -> <WriteGraph> ()
97 getAnnotationNameFromType :: Resource -> <ReadGraph> String
98 getAnnotationNameFromType annotationType = do
99 relation = singleObject annotationType HasRange.Inverse
100 untypedRelatedValue relation L0.HasName
102 getPossibleAnnotationType :: Resource -> String -> <ReadGraph> Maybe AnnotationType
103 getPossibleAnnotationType model name = do
104 all = searchByType model ANNO.AnnotationType
105 named = filter (\x -> (getAnnotationNameFromType x) == name) all
106 if ((length named) == 1)
110 setAnnotationPropertyValue :: AnnotationPropertyRelation -> Resource -> String -> String -> <WriteGraph> ()
111 setAnnotationPropertyValue annotation resource property newValue = do
112 resourceUri = uriOf resource
113 annotationName = DB.nameOf annotation
114 completeUri = resourceUri + "#" + annotationName + "#" + property + "#HasDisplayValue"
115 propertyVariable = variable completeUri
116 setValue propertyVariable newValue
119 findAnnotationType :: Model -> [AnnotationType]
120 findAnnotationType m = do
121 fromResource $ searchByQuery m "Types: AnnotationType"