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