]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Simupedia! (refs #3511)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 12 Jul 2013 13:57:06 +0000 (13:57 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 12 Jul 2013 13:57:06 +0000 (13:57 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27706 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/exports/ExportModelHandler.java
org.simantics.sysdyn/scl/Sysdyn.scl
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java

index e82df8580c84ba5b6e6a9bd7ef8be9ab2c737bc7..8d2ec6d25f0563306a0f664d6b948286169d1d74 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.sysdyn.ui.handlers.exports;\r
 \r
 import java.io.File;\r
+import java.util.HashMap;\r
 \r
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
@@ -28,6 +29,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;\r
 import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;\r
 import org.simantics.db.layer0.util.TransferableGraphConfiguration2;\r
 import org.simantics.db.request.Read;\r
@@ -100,7 +102,18 @@ public class ExportModelHandler extends AbstractHandler {
 \r
                    @Override\r
                    public void run(ReadGraph graph) throws DatabaseException {\r
+                       HashMap<Resource, ExtentStatus> map = new HashMap<Resource, ExtentStatus>();\r
+                       \r
+                       Resource relation = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/createdBy");\r
+                       if(relation != null) {\r
+                           Resource createdBy = graph.getPossibleObject(model, relation);\r
+                           if(createdBy != null)\r
+                               map.put(createdBy, ExtentStatus.EXCLUDED);\r
+                       }\r
+                       \r
                        TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, model);\r
+                       conf.preStatus.putAll(map);\r
+                       \r
                        TransferableGraphSource s = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));\r
                        try {\r
                            TransferableGraphs.writeTransferableGraph(graph, "sysdynModel", 1, s,new File(selected));\r
index 72217d49020c36216b21797fa7b1ac28b641ee42..d0c69402105b505a036032843bd1b453e5bed1c7 100644 (file)
@@ -12,6 +12,15 @@ importJava "org.simantics.sysdyn.utils.DocumentationUtils" where
     @JavaName getRoleVariables\r
     getRoleVariables :: Variable -> <ReadGraph> [Variable]    \r
 \r
+    @JavaName getDocumentVariables\r
+    getDocumentVariables :: Variable -> <ReadGraph> [Variable]    \r
+\r
+    @JavaName getIndexDocuments\r
+    getIndexDocuments :: Variable -> <ReadGraph> [Variable]    \r
+    \r
+    @JavaName getResultVariables\r
+    getResultVariables :: Variable -> <ReadGraph> [Variable]  \r
+    \r
     @JavaName getConfiguration\r
     getConfiguration :: Resource -> <ReadGraph> Resource\r
     \r
@@ -67,5 +76,12 @@ importJava "org.simantics.sysdyn.utils.DocumentationUtils" where
     \r
     @JavaName numberOfModuleTypes\r
     numberOfModuleTypes :: Variable -> <ReadGraph> Integer\r
+   \r
+    @JavaName base64Encode\r
+    base64Encode :: Variable -> String -> <ReadGraph> String \r
+    \r
+    @JavaName formatDate\r
+    formatDate :: Long -> <ReadGraph> String \r
+    \r
     \r
     
\ No newline at end of file
index 5d468db077841c773e0fbd130963fb9c91314b4e..17c5aa355994cb9a1c3d0d65655134c5b476737f 100644 (file)
@@ -1,10 +1,14 @@
 package org.simantics.sysdyn.utils;\r
 \r
+import java.text.DateFormat;\r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
 import java.util.Comparator;\r
+import java.util.Date;\r
 import java.util.List;\r
 \r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.util.Base64;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ObjectsWithSupertype;\r
@@ -101,6 +105,57 @@ public class DocumentationUtils {
         return result;\r
     }\r
     \r
+    public static List<org.simantics.db.layer0.variable.Variable> getDocumentVariables(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException {\r
+        if(model == null)\r
+            return Collections.emptyList();\r
+        \r
+        Resource documentType = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/Document");\r
+        if(documentType == null)\r
+            return Collections.emptyList();\r
+        \r
+        ArrayList<org.simantics.db.layer0.variable.Variable> result = new ArrayList<org.simantics.db.layer0.variable.Variable>();\r
+        for(org.simantics.db.layer0.variable.Variable part : model.getChildren(graph)) {\r
+            if(graph.isInstanceOf(part.getRepresents(graph), documentType)) {\r
+                result.add(part);\r
+            }\r
+        }\r
+\r
+        return result;\r
+    }\r
+    \r
+    public static List<org.simantics.db.layer0.variable.Variable> getResultVariables(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException {\r
+        if(model == null)\r
+            return Collections.emptyList();\r
+        \r
+        org.simantics.db.layer0.variable.Variable library = model.getPossibleChild(graph, "PDFLibrary");\r
+        if(library == null)\r
+            return Collections.emptyList();\r
+        \r
+        \r
+        return new ArrayList<org.simantics.db.layer0.variable.Variable>(library.getChildren(graph));\r
+    }\r
+    \r
+    public static List<org.simantics.db.layer0.variable.Variable> getIndexDocuments(ReadGraph graph, org.simantics.db.layer0.variable.Variable project) throws DatabaseException {\r
+        Resource indexRelation = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/indexDocument");\r
+\r
+        if(indexRelation == null)\r
+            return Collections.emptyList();\r
+        \r
+        ArrayList<org.simantics.db.layer0.variable.Variable> result = new ArrayList<org.simantics.db.layer0.variable.Variable>();\r
+        for(org.simantics.db.layer0.variable.Variable model : project.getChildren(graph)) {\r
+            Resource modelResource = model.getRepresents(graph);\r
+            if(modelResource == null)\r
+                continue;\r
+            \r
+            Resource indexDocumentResource = graph.getPossibleObject(modelResource, indexRelation);\r
+            if(indexDocumentResource != null) {\r
+                org.simantics.db.layer0.variable.Variable indexDoc = Variables.getVariable(graph, indexDocumentResource);\r
+                result.add(indexDoc);\r
+            } \r
+        }\r
+        return result;\r
+    }\r
+    \r
     public static Resource getConfiguration(ReadGraph graph, Resource module) throws DatabaseException {\r
         if(module == null)\r
             return null;\r
@@ -391,4 +446,17 @@ public class DocumentationUtils {
                 .size();\r
     }\r
     \r
+    public static String base64Encode(ReadGraph graph, org.simantics.db.layer0.variable.Variable variable, String property) throws DatabaseException {\r
+        byte[] fileBArray = variable.getPossiblePropertyValue(graph, property, Bindings.BYTE_ARRAY);\r
+        if(fileBArray != null)\r
+            return Base64.encode(fileBArray);\r
+        else\r
+            return "";\r
+    }\r
+    \r
+    public static String formatDate(long timeMillis) {\r
+        Date date = new Date(timeMillis);\r
+        String result = DateFormat.getDateInstance().format(date);\r
+        return result;\r
+    }\r
 }\r
index a9f6d1df703bb5ff295685de9a35563494dca7ad..2f2632e8b7651806f5e8c5fa64a254930bfc9225 100644 (file)
@@ -57,10 +57,11 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.modeling.utils.BatchValidations;\r
 import org.simantics.operation.Layer0X;\r
+import org.simantics.scl.runtime.function.Function1;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.Activator;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.utils.ModelUtils;\r
 \r
 /**\r
@@ -135,6 +136,9 @@ public class ImportUtils {
     /* *******   IMPORT MODEL  ********* */\r
     /* ********************************* */\r
     public static IStatus importModelFile(String path, final IProgressMonitor monitor) {\r
+        return importModelFile(path, monitor, null);\r
+    }\r
+    public static IStatus importModelFile(String path, final IProgressMonitor monitor, Function1<Resource,WriteRequest> callback) {\r
         final Resource project = Simantics.getProject().get();\r
         if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null);\r
 \r
@@ -245,6 +249,12 @@ public class ImportUtils {
 \r
                 worked(monitor, 1);\r
 \r
+                if(callback != null) {\r
+                    WriteRequest userRequest = callback.apply(result);\r
+                    if(userRequest != null)\r
+                        Simantics.sync(userRequest);\r
+                }\r
+\r
             } catch (DatabaseException e) {\r
                 e.printStackTrace();\r
                 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model failed: Model could not be imported.", e);\r
@@ -256,7 +266,6 @@ public class ImportUtils {
 \r
     protected static void addSCLMain(WriteGraph graph, Resource modelRoot) throws DatabaseException {\r
         Layer0 L0 = Layer0.getInstance(graph);\r
-        SysdynResource SR = SysdynResource.getInstance(graph);\r
         \r
         Collection<Resource> SCLModules = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, L0.SCLModule));\r
         \r