]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.annotation.ui/scl/Simantics/Annotation2.scl
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.annotation.ui / scl / Simantics / Annotation2.scl
1 import "Simantics/DB"
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
8
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
12
13 type Annotation = Resource
14 type AnnotationPropertyRelation = Resource
15 type AnnotationType = Resource
16 type AnnotationValue = Resource
17 type AnnotationProperty = Resource
18
19 importJava "org.simantics.annotation.ui.SCLAnnotation" where
20     @JavaName newAnnotationType
21     """
22     Creates new AnnotationType under the given Library instance and returns it without PropertyRelation
23     """
24     newAnnotationType :: Library -> <WriteGraph> AnnotationType
25     
26     @JavaName newAnnotationValue
27     """
28     Creates new AnnotationValue under the given Library instance with the AnnotationType reference. Returns the created AnnotationValue.
29     """
30     newAnnotationValue :: Library -> AnnotationType -> <WriteGraph> AnnotationValue
31     newAnnotationValueWithName :: Library -> String -> AnnotationType -> <WriteGraph> AnnotationValue
32     
33     @JavaName newAnnotationType1
34     """
35     Creates new AnnotationType under the given Library instance. Returns a Tuple2 consisting the AnnotationPropertyRelation and AnnotationType instances.
36     """
37     newAnnotationType1 :: Library -> <WriteGraph> (AnnotationPropertyRelation, AnnotationType)
38     
39     @JavaName newAnnotationProperty
40     """
41     Creates new AnnotationProperty under the given AnnotatoinType instance. Returns the created AnnotationProperty.
42     """
43     newAnnotationProperty :: AnnotationType -> <WriteGraph> AnnotationProperty
44     
45     @JavaName advancedAnnotationProperty
46     """
47     Creates new AnnotationProperty under the given AnnotationType instance with advanced options for user to define non-default parameters for the following values
48     
49     * name
50     * type
51     * unit
52     * range
53     * label
54     * description
55     """
56     advancedAnnotationProperty :: AnnotationType -> String -> String -> String -> String -> String -> String -> <WriteGraph> AnnotationProperty
57     
58     @JavaName removeAnnotationProperty
59     """
60     Removes the given AnnotationProperty instance.
61     """
62     removeAnnotationProperty :: AnnotationProperty -> <WriteGraph> ()
63     
64     @JavaName attachAnnotation
65     """
66     Attaches the given AnnotationType to the given Resource which can be for example a Diagram or a Symbol.
67     """
68     attachAnnotationType :: Resource -> AnnotationType -> <WriteGraph> Annotation
69     
70     @JavaName setPropertyLabel
71     setPropertyLabel :: AnnotationProperty -> String -> <WriteGraph> ()
72     
73     @JavaName setPropertyUnit
74     setPropertyUnit :: AnnotationProperty -> String -> <WriteGraph> ()
75     
76     @JavaName setPropertyRange
77     setPropertyRange :: AnnotationProperty -> String -> <WriteGraph> ()
78     
79     @JavaName setPropertyDescription
80     setPropertyDescription :: AnnotationProperty -> String -> <WriteGraph> ()
81     
82     @JavaName setPropertyType
83     setPropertyType :: AnnotationProperty -> String -> <WriteGraph> ()
84     
85     @JavaName saveAnnotation
86     saveAnnotation :: Annotation -> Library -> String -> <WriteGraph> Resource
87     
88     @JavaName importAnnotationFromFile
89     importAnnotation :: File -> Library -> <Proc> ()
90     
91     @JavaName exportAnnotationToFile
92     exportAnnotationType :: File -> AnnotationType -> <Proc> ()
93     
94     @JavaName copyAnnotationData
95     copyAnnotationData :: Resource -> Resource -> <WriteGraph> ()
96
97 getAnnotationNameFromType :: Resource -> <ReadGraph> String
98 getAnnotationNameFromType annotationType = do
99     relation = singleObject annotationType HasRange.Inverse
100     untypedRelatedValue relation L0.HasName
101
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)
107      then Just (fromResource $ named!0) 
108      else Nothing
109     
110 setAnnotationPropertyValue :: AnnotationPropertyRelation -> Resource -> String -> String -> <WriteGraph> ()
111 setAnnotationPropertyValue annotation resource property newValue = do
112     resourceUri = uriOf resource
113     annotationName = DB.nameOf (toResource annotation)
114     completeUri = resourceUri + "#" + annotationName + "#" + property + "#HasDisplayValue"
115     propertyVariable = variable completeUri
116     setValue propertyVariable newValue
117     
118 /*  
119 findAnnotationType :: Model -> [AnnotationType]
120 findAnnotationType m = do
121     fromResource $ searchByQuery m "Types: AnnotationType"
122 */