]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.annotation.ui/scl/Simantics/Annotation2.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.annotation.ui / scl / Simantics / Annotation2.scl
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
8 \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
12 \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
18 \r
19 importJava "org.simantics.annotation.ui.SCLAnnotation" where\r
20     @JavaName newAnnotationType\r
21     """\r
22     Creates new AnnotationType under the given Library instance and returns it without PropertyRelation\r
23     """\r
24     newAnnotationType :: Library -> <WriteGraph> AnnotationType\r
25     \r
26     @JavaName newAnnotationValue\r
27     """\r
28     Creates new AnnotationValue under the given Library instance with the AnnotationType reference. Returns the created AnnotationValue.\r
29     """\r
30     newAnnotationValue :: Library -> AnnotationType -> <WriteGraph> AnnotationValue\r
31     newAnnotationValueWithName :: Library -> String -> AnnotationType -> <WriteGraph> AnnotationValue\r
32     \r
33     @JavaName newAnnotationType1\r
34     """\r
35     Creates new AnnotationType under the given Library instance. Returns a Tuple2 consisting the AnnotationPropertyRelation and AnnotationType instances.\r
36     """\r
37     newAnnotationType1 :: Library -> <WriteGraph> (AnnotationPropertyRelation, AnnotationType)\r
38     \r
39     @JavaName newAnnotationProperty\r
40     """\r
41     Creates new AnnotationProperty under the given AnnotatoinType instance. Returns the created AnnotationProperty.\r
42     """\r
43     newAnnotationProperty :: AnnotationType -> <WriteGraph> AnnotationProperty\r
44     \r
45     @JavaName advancedAnnotationProperty\r
46     """\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
48     \r
49     * name\r
50     * type\r
51     * unit\r
52     * range\r
53     * label\r
54     * description\r
55     """\r
56     advancedAnnotationProperty :: AnnotationType -> String -> String -> String -> String -> String -> String -> <WriteGraph> AnnotationProperty\r
57     \r
58     @JavaName removeAnnotationProperty\r
59     """\r
60     Removes the given AnnotationProperty instance.\r
61     """\r
62     removeAnnotationProperty :: AnnotationProperty -> <WriteGraph> ()\r
63     \r
64     @JavaName attachAnnotation\r
65     """\r
66     Attaches the given AnnotationType to the given Resource which can be for example a Diagram or a Symbol.\r
67     """\r
68     attachAnnotationType :: Resource -> AnnotationType -> <WriteGraph> Annotation\r
69     \r
70     @JavaName setPropertyLabel\r
71     setPropertyLabel :: AnnotationProperty -> String -> <WriteGraph> ()\r
72     \r
73     @JavaName setPropertyUnit\r
74     setPropertyUnit :: AnnotationProperty -> String -> <WriteGraph> ()\r
75     \r
76     @JavaName setPropertyRange\r
77     setPropertyRange :: AnnotationProperty -> String -> <WriteGraph> ()\r
78     \r
79     @JavaName setPropertyDescription\r
80     setPropertyDescription :: AnnotationProperty -> String -> <WriteGraph> ()\r
81     \r
82     @JavaName setPropertyType\r
83     setPropertyType :: AnnotationProperty -> String -> <WriteGraph> ()\r
84     \r
85     @JavaName saveAnnotation\r
86     saveAnnotation :: Annotation -> Library -> String -> <WriteGraph> Resource\r
87     \r
88     @JavaName importAnnotationFromFile\r
89     importAnnotation :: File -> Library -> <Proc> ()\r
90     \r
91     @JavaName exportAnnotationToFile\r
92     exportAnnotationType :: File -> AnnotationType -> <Proc> ()\r
93     \r
94     @JavaName copyAnnotationData\r
95     copyAnnotationData :: Resource -> Resource -> <WriteGraph> ()\r
96 \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
101 \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
108      else Nothing\r
109     \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
117     \r
118 /*  \r
119 findAnnotationType :: Model -> [AnnotationType]\r
120 findAnnotationType m = do\r
121     fromResource $ searchByQuery m "Types: AnnotationType"\r
122 */\r