import "JavaBuiltin" as Java include "Simantics/Variables" include "Simantics/Ontologies" include "Simantics/SCL" include "Simantics/Misc" import "http://www.simantics.org/Layer0-1.1/Entity" as ENTITY createClusterSet :: Resource -> () createClusterSet r = do newClusterSet r selectClusterSet r () createLibrary :: Resource -> Resource -> String -> Boolean -> Resource createLibrary parentLibrary libraryType name clusterSet = do selectClusterSet parentLibrary library = newResource () match clusterSet with True -> createClusterSet library False -> () claim library L0.InstanceOf libraryType claimRelatedValue library L0.HasName name claim parentLibrary L0.ConsistsOf library library uriParts :: String -> [String] uriParts uri = do match uri with "http://" -> [] _ -> do parts = splitURI uri addList (uriParts (parts!0)) (parts!1) getOrCreateLibrary :: Resource -> Resource -> String -> Boolean -> Resource getOrCreateLibrary parentLibrary libraryType name clusterSet = do match possibleResourceChild parentLibrary name with Just child -> child Nothing -> createLibrary parentLibrary libraryType name clusterSet createSharedOntology :: String -> Resource -> Resource createSharedOntology uri ontologyType = do path = uriParts uri lastId = length path - 1 parentLibrary = foldl (\p id -> getOrCreateLibrary p L0.Library (path!id) False) (getRootLibrary ()) [0..lastId-1] res = getOrCreateLibrary parentLibrary ontologyType (path!lastId) True createSCLModule res "SCLMain" res traverseOntologies :: Resource -> (Resource -> Boolean) -> [Resource] traverseOntologies library filterFn = if library `isInstanceOf` L0.Ontology then (filter filterFn [library]) else if library `isInstanceOf` SIMU.Model then [] else if library `isInstanceOf` L0.Library then foldl (\result r -> (result + (traverseOntologies r filterFn))) [] (library # L0.ConsistsOf) else [] traverseSharedOntologies :: Resource -> [Resource] traverseSharedOntologies library = traverseOntologies library acceptSharedOntology acceptSharedOntology :: Resource -> Boolean acceptSharedOntology ontology = if ontology `isInstanceOf` L0.SharedOntology then not $ relatedValue ontology L0.SharedOntology.treatAsSystemOntology else False traverseSystemOntologies :: Resource -> [Resource] traverseSystemOntologies library = traverseOntologies library acceptSystemOntology acceptSystemOntology :: Resource -> Boolean acceptSystemOntology ontology = if ontology `isInstanceOf` L0.SharedOntology then relatedValue ontology L0.SharedOntology.treatAsSystemOntology else True linkSharedOntology :: Resource -> Resource -> () linkSharedOntology model ontology = do markUndoPoint () claim model L0.IsLinkedTo ontology addCommentMetadata ("Linked shared ontology " + (relatedValue2 ontology L0.HasName) + " to " + (relatedValue2 model L0.HasName)) () unlinkSharedOntology :: Resource -> Resource -> () unlinkSharedOntology model ontology = do markUndoPoint () deny model L0.IsLinkedTo ontology addCommentMetadata ("Unlinked shared ontology " + (relatedValue2 ontology L0.HasName) + " from " + (relatedValue2 model L0.HasName)) () getSharedOntologies :: () -> [Resource] getSharedOntologies dummy = traverseSharedOntologies $ getRootLibrary () getSystemOntologies :: () -> [Resource] getSystemOntologies dummy = traverseSystemOntologies $ getRootLibrary () getVisibleSystemOntologies :: () -> [Resource] getVisibleSystemOntologies dummy = do match (queryPreference "org.simantics" "ontology.visibility") with "shared" -> [] "all" -> getSystemOntologies () "" -> [] usedSharedOntologies :: Resource -> [Resource] usedSharedOntologies model = do ontologies = getSharedOntologies () let f e = existsStatement3 model L0.IsLinkedTo e in filter f ontologies availableSharedOntologies :: Resource -> [Resource] availableSharedOntologies r = do ontologies = getSharedOntologies () ontologies = filter f ontologies where f ontology = not $ existsStatement3 r L0.IsLinkedTo ontology ontologies = filter f ontologies where f ontology = not $ isLinkedToDeep ontology r ontologies querySharedOntologyType :: () -> Resource querySharedOntologyType dummy = do ontologies = listOntologies () types = foldl (\result ontology -> (result + (searchByType ontology L0.IndexRootType))) [] $ listOntologies () types = filter f types where f res = not $ isInheritedFrom res SIMU.Model types = filter f types where f res = not $ existsStatement res L0.Abstract types!0 importJava "org.simantics.modeling.ModelingUtils" where importSharedOntologyWithUI :: Variable -> () importSharedOntology :: String -> () importSharedOntology2 :: String -> [Resource] createSharedOntologyWithUI :: Resource -> () unlinkSharedOntologyWithUI :: Variable -> [Resource] -> () createNewVersionWithUI :: Resource -> () createNewVersionWithoutUI :: Resource -> () exportSharedOntology :: Resource -> String -> String -> Integer -> () publishComponentTypeWithUI :: Resource -> () publishSharedOntologyWithUI :: Resource -> () isLinkedToDeep :: Resource -> Resource -> Boolean publish :: Resource -> () publishAction :: Resource -> () publishAction res = do syncWrite (\() -> publish res) () publishComponentTypeAction :: Resource -> () publishComponentTypeAction res = do syncWrite (\() -> publishComponentTypeWithUI res) () publishSharedOntologyAction :: Resource -> () publishSharedOntologyAction res = do syncWrite (\() -> publishSharedOntologyWithUI res) () newVersionAction :: Resource -> () newVersionAction res = do syncRead (\() -> createNewVersionWithUI res) () isNotPublished :: Resource -> Boolean isNotPublished r = match (untypedPossibleRelatedValue r ENTITY.published) with Just a -> False Nothing -> True isContainerNotPublished :: Resource -> Boolean isContainerNotPublished r = match (possibleIndexRoot r) with Just root -> isNotPublished root Nothing -> True isPublished :: Resource -> Boolean isPublished r = match (untypedPossibleRelatedValue r ENTITY.published) with Just a -> True Nothing -> False isLocked :: Resource -> Boolean isLocked r = existsStatement r STR.ComponentType.Locked isNotLocked = not . isLocked treatAsSystemOntology :: Resource -> Boolean -> () treatAsSystemOntology sharedOntology setting = claimRelatedValue sharedOntology L0.SharedOntology.treatAsSystemOntology setting