1 import "JavaBuiltin" as Java
\r
2 include "Simantics/Variables"
\r
3 include "Simantics/Ontologies"
\r
4 include "Simantics/SCL"
\r
5 include "Simantics/Misc"
\r
6 import "http://www.simantics.org/Layer0-1.1/Entity" as ENTITY
\r
8 createClusterSet :: Resource -> <WriteGraph> ()
\r
9 createClusterSet r = do
\r
14 createLibrary :: Resource -> Resource -> String -> Boolean -> <WriteGraph> Resource
\r
15 createLibrary parentLibrary libraryType name clusterSet = do
\r
16 selectClusterSet parentLibrary
\r
17 library = newResource ()
\r
18 match clusterSet with
\r
19 True -> createClusterSet library
\r
21 claim library L0.InstanceOf libraryType
\r
22 claimRelatedValue library L0.HasName name
\r
23 claim parentLibrary L0.ConsistsOf library
\r
26 uriParts :: String -> [String]
\r
31 parts = splitURI uri
\r
32 addList (uriParts (parts!0)) (parts!1)
\r
34 getOrCreateLibrary :: Resource -> Resource -> String -> Boolean -> <WriteGraph> Resource
\r
35 getOrCreateLibrary parentLibrary libraryType name clusterSet = do
\r
36 match possibleResourceChild parentLibrary name with
\r
38 Nothing -> createLibrary parentLibrary libraryType name clusterSet
\r
40 createSharedOntology :: String -> Resource -> <WriteGraph> Resource
\r
41 createSharedOntology uri ontologyType = do
\r
43 lastId = length path - 1
\r
44 parentLibrary = foldl (\p id -> getOrCreateLibrary p L0.Library (path!id) False)
\r
45 (getRootLibrary ())
\r
47 res = getOrCreateLibrary parentLibrary ontologyType (path!lastId) True
\r
48 createSCLModule res "SCLMain"
\r
51 traverseOntologies :: Resource -> (Resource -> <ReadGraph> Boolean) -> <ReadGraph> [Resource]
\r
52 traverseOntologies library filterFn =
\r
53 if library `isInstanceOf` L0.Ontology then (filter filterFn [library])
\r
54 else if library `isInstanceOf` SIMU.Model then []
\r
55 else if library `isInstanceOf` L0.Library then
\r
56 foldl (\result r -> (result + (traverseOntologies r filterFn))) [] (library # L0.ConsistsOf)
\r
59 traverseSharedOntologies :: Resource -> <ReadGraph> [Resource]
\r
60 traverseSharedOntologies library = traverseOntologies library acceptSharedOntology
\r
62 acceptSharedOntology :: Resource -> <ReadGraph> Boolean
\r
63 acceptSharedOntology ontology =
\r
64 if ontology `isInstanceOf` L0.SharedOntology then
\r
65 not $ relatedValue ontology L0.SharedOntology.treatAsSystemOntology
\r
68 traverseSystemOntologies :: Resource -> <ReadGraph> [Resource]
\r
69 traverseSystemOntologies library = traverseOntologies library acceptSystemOntology
\r
71 acceptSystemOntology :: Resource -> <ReadGraph> Boolean
\r
72 acceptSystemOntology ontology =
\r
73 if ontology `isInstanceOf` L0.SharedOntology then
\r
74 relatedValue ontology L0.SharedOntology.treatAsSystemOntology
\r
77 linkSharedOntology :: Resource -> Resource -> <WriteGraph> ()
\r
78 linkSharedOntology model ontology = do
\r
80 claim model L0.IsLinkedTo ontology
\r
81 addCommentMetadata ("Linked shared ontology " + (relatedValue2 ontology L0.HasName) + " to " + (relatedValue2 model L0.HasName))
\r
84 unlinkSharedOntology :: Resource -> Resource -> <WriteGraph> ()
\r
85 unlinkSharedOntology model ontology = do
\r
87 deny model L0.IsLinkedTo ontology
\r
88 addCommentMetadata ("Unlinked shared ontology " + (relatedValue2 ontology L0.HasName) + " from " + (relatedValue2 model L0.HasName))
\r
91 getSharedOntologies :: () -> <ReadGraph> [Resource]
\r
92 getSharedOntologies dummy = traverseSharedOntologies $ getRootLibrary ()
\r
94 getSystemOntologies :: () -> <ReadGraph> [Resource]
\r
95 getSystemOntologies dummy = traverseSystemOntologies $ getRootLibrary ()
\r
97 getVisibleSystemOntologies :: () -> <ReadGraph> [Resource]
\r
98 getVisibleSystemOntologies dummy = do
\r
99 match (queryPreference "org.simantics" "ontology.visibility") with
\r
101 "all" -> getSystemOntologies ()
\r
104 usedSharedOntologies :: Resource -> <ReadGraph> [Resource]
\r
105 usedSharedOntologies model = do
\r
106 ontologies = getSharedOntologies ()
\r
107 let f e = existsStatement3 model L0.IsLinkedTo e
\r
108 in filter f ontologies
\r
110 availableSharedOntologies :: Resource -> <ReadGraph> [Resource]
\r
111 availableSharedOntologies r = do
\r
112 ontologies = getSharedOntologies ()
\r
113 ontologies = filter f ontologies
\r
114 where f ontology = not $ existsStatement3 r L0.IsLinkedTo ontology
\r
115 ontologies = filter f ontologies
\r
116 where f ontology = not $ isLinkedToDeep ontology r
\r
119 querySharedOntologyType :: () -> <ReadGraph> Resource
\r
120 querySharedOntologyType dummy = do
\r
121 ontologies = listOntologies ()
\r
122 types = foldl (\result ontology -> (result + (searchByType ontology L0.IndexRootType))) [] $ listOntologies ()
\r
123 types = filter f types
\r
124 where f res = not $ isInheritedFrom res SIMU.Model
\r
125 types = filter f types
\r
126 where f res = not $ existsStatement res L0.Abstract
\r
129 importJava "org.simantics.modeling.ModelingUtils" where
\r
130 importSharedOntologyWithUI :: Variable -> <ReadGraph> ()
\r
131 importSharedOntology :: String -> ()
\r
132 createSharedOntologyWithUI :: Resource -> <ReadGraph> ()
\r
133 unlinkSharedOntologyWithUI :: Variable -> [Resource] -> <ReadGraph> ()
\r
134 createNewVersionWithUI :: Resource -> <ReadGraph> ()
\r
135 createNewVersionWithoutUI :: Resource -> <WriteGraph> ()
\r
136 exportSharedOntology :: Resource -> String -> String -> Integer -> <ReadGraph> ()
\r
137 publishComponentTypeWithUI :: Resource -> <WriteGraph> ()
\r
138 publishSharedOntologyWithUI :: Resource -> <WriteGraph> ()
\r
139 isLinkedToDeep :: Resource -> Resource -> <ReadGraph> Boolean
\r
140 publish :: Resource -> <WriteGraph> ()
\r
142 publishAction :: Resource -> <Proc> ()
\r
143 publishAction res = do
\r
144 syncWrite (\() -> publish res)
\r
147 publishComponentTypeAction :: Resource -> <Proc> ()
\r
148 publishComponentTypeAction res = do
\r
149 syncWrite (\() -> publishComponentTypeWithUI res)
\r
152 publishSharedOntologyAction :: Resource -> <Proc> ()
\r
153 publishSharedOntologyAction res = do
\r
154 syncWrite (\() -> publishSharedOntologyWithUI res)
\r
157 newVersionAction :: Resource -> <Proc> ()
\r
158 newVersionAction res = do
\r
159 syncRead (\() -> createNewVersionWithUI res)
\r
162 isNotPublished :: Resource -> <ReadGraph> Boolean
\r
163 isNotPublished r = match (untypedPossibleRelatedValue r ENTITY.published) with
\r
167 isContainerNotPublished :: Resource -> <ReadGraph> Boolean
\r
168 isContainerNotPublished r = match (possibleIndexRoot r) with
\r
169 Just root -> isNotPublished root
\r
172 isPublished :: Resource -> <ReadGraph> Boolean
\r
173 isPublished r = match (untypedPossibleRelatedValue r ENTITY.published) with
\r
177 isLocked :: Resource -> <ReadGraph> Boolean
\r
178 isLocked r = existsStatement r STR.ComponentType.Locked
\r
180 isNotLocked = not . isLocked
\r
182 treatAsSystemOntology :: Resource -> Boolean -> <WriteGraph> ()
\r
183 treatAsSystemOntology sharedOntology setting = claimRelatedValue sharedOntology L0.SharedOntology.treatAsSystemOntology setting
\r