]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Moving utils around (refs #3511)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 25 Jun 2013 09:57:39 +0000 (09:57 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 25 Jun 2013 09:57:39 +0000 (09:57 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27652 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameValidator.java
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java with 82% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java with 96% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java [moved from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java with 97% similarity]
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java

index e0eaa2105bb4bf80e35b8a5d8a06dbe5a5c4d8ec..d2f2d43a31a58cd325f710f39404415951009ade 100644 (file)
@@ -175,7 +175,7 @@ public class ModelicaManager {
     \r
     public static String getOMCVersion(File OMHome) throws IOException {\r
         ArrayList<String> parameters = new ArrayList<String>();\r
-        parameters.add(OMHome + "\\bin\\omc.exe");\r
+        parameters.add(new File(OMHome, "/bin/omc").getAbsolutePath());\r
         parameters.add("++v");\r
 \r
         // Create the build process\r
index 418f01948dbf90c6f64861eecc650521f2f40317..e579df6c53abc74bdea0a181daf5ec604017ee5c 100644 (file)
@@ -16,7 +16,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.adapter.ActionFactory;\r
-import org.simantics.sysdyn.ui.utils.SheetUtils;\r
+import org.simantics.sysdyn.utils.SheetUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 /**\r
index d60a1854252bccbdfca255bcc40a17729174db26..6ed6858e8c96e183f784d0d134fbba4634cffe26 100644 (file)
@@ -23,7 +23,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.ui.Activator;\r
-import org.simantics.sysdyn.ui.utils.ModelUtils;\r
+import org.simantics.sysdyn.utils.ModelUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 /**\r
index 16c6a3dab32ba30b0989422fea482c1a33316fa6..3a64607af182da73b28fbbcb20279ac3f7ab70cc 100644 (file)
@@ -20,7 +20,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.sysdyn.ui.utils.SheetUtils;\r
+import org.simantics.sysdyn.utils.SheetUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 \r
index 3354f7fd3c4a790f4e1d5b5beb02fe51950a3a76..c3b27997d355e6c342a0f163005cd7c277b27971 100644 (file)
@@ -114,6 +114,7 @@ public class ModuleStructure extends CTabItem {
                             \r
                             @Override\r
                             public void run() {\r
+                                if (component.isDisposed()) return;\r
                                 component.setGraph((Graph)getObject(), "dot");\r
                                 component.fit();    \r
                             }\r
index ba8950cb92e4b4c9108ac26bcfd052dfe0771330..d6f024e1256152ab47ac954a3765ae0582232a49 100644 (file)
@@ -13,6 +13,7 @@ import org.simantics.sysdyn.representation.EnumerationIndex;
 import org.simantics.sysdyn.representation.IElement;\r
 import org.simantics.sysdyn.representation.Variable;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField;\r
+import org.simantics.sysdyn.utils.ModelUtils;\r
 \r
 public class ArrayVariableUtils {\r
 \r
index 969517b265d729441942e142d296a24c22337227..05b8382a31eb709d331b55b553b200a90fc899c5 100644 (file)
@@ -27,6 +27,7 @@ import org.simantics.sysdyn.manager.SysdynModel;
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.Model;\r
 import org.simantics.sysdyn.representation.ModuleType;\r
+import org.simantics.sysdyn.utils.ModelUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
 /**\r
index 39ecd3f7bb6bd3cec5b3b2aaf1f825b555333297..ce2df41dc83858c80f54c5314da3c8207fb67840 100644 (file)
@@ -44,6 +44,7 @@ Export-Package: org.simantics.sysdyn,
  org.simantics.sysdyn.representation.visitors,
  org.simantics.sysdyn.simulation,
  org.simantics.sysdyn.tableParser,
+ org.simantics.sysdyn.utils,
  org.simantics.sysdyn.utils.imports
 Bundle-Activator: org.simantics.sysdyn.Activator
 Bundle-ActivationPolicy: lazy
similarity index 82%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java
index 0974468c486068ead8386d8abaa1166c5680d782..c7923c8a9239fe79bff42765bfe0e84311d5a1aa 100644 (file)
@@ -1,7 +1,8 @@
-package org.simantics.sysdyn.ui.utils;\r
+package org.simantics.sysdyn.utils;\r
 \r
 import java.util.UUID;\r
 \r
+import org.simantics.Simantics;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -22,7 +23,6 @@ import org.simantics.spreadsheet.resource.SpreadsheetResource;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
-import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
 \r
 public class ModelUtils {\r
@@ -40,7 +40,7 @@ public class ModelUtils {
         Resource configuration = graph.getPossibleObject(variable, l0.PartOf);\r
         if(configuration == null)\r
             return null;\r
-        SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession());\r
+        SysdynModelManager sdm = SysdynModelManager.getInstance(Simantics.getSession());\r
         SysdynModel model = sdm.getModel(graph, configuration);\r
         try {\r
             model.update(graph);\r
@@ -51,7 +51,7 @@ public class ModelUtils {
     }\r
 \r
     public static void createModel(WriteGraph graph) {\r
-        createModelAt(graph, SimanticsUI.getProject().get());\r
+        createModelAt(graph, Simantics.getProject().get());\r
     }\r
 \r
     public static void createModelAt(WriteGraph g, Resource library) {\r
@@ -65,7 +65,7 @@ public class ModelUtils {
 \r
             String modelName = NameUtils.findFreshName(g, "Model", library, l0.ConsistsOf, "%s%d");\r
 \r
-            Resource project = SimanticsUI.getProject().get();\r
+            Resource project = Simantics.getProject().get();\r
             Resource model = GraphUtils.create2(g,\r
                     sr.SysdynModel,\r
                     l0.PartOf, project,\r
@@ -164,12 +164,7 @@ public class ModelUtils {
                 }\r
             }\r
             \r
-            GraphUtils.create2(g,\r
-                    l0.SCLModule,\r
-                    l0.PartOf, model,\r
-                    l0.HasName, "SCLMain",\r
-                    l0.SCLModule_definition, "include \"http:\\\\www.simantics.org\\DB\"\ninclude \"http:\\\\www.simantics.org\\Variables\"\n"\r
-                    );\r
+            createSCLMain(g, model);\r
             \r
             ProfileEntries.createStandardProfiles(g, model);\r
             \r
@@ -178,4 +173,23 @@ public class ModelUtils {
                Logger.defaultLogError(e);\r
         }\r
     }\r
+    \r
+    public static void createSCLMain(WriteGraph graph, Resource model) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        Resource SCLModule = GraphUtils.create2(graph,\r
+                L0.SCLModule,\r
+                L0.PartOf, model,\r
+                L0.HasName, "SCLMain"\r
+                );\r
+        \r
+        if(graph.hasStatement(SCLModule, L0.SCLModule_definition))\r
+            graph.deny(SCLModule, L0.SCLModule_definition);\r
+        graph.claimLiteral(SCLModule, L0.SCLModule_definition, \r
+                "include \"http://www.simantics.org/DB\"\n" +\r
+                "include \"http://www.simantics.org/Variables\"\n" + \r
+                "include \"" + graph.getURI(model) + "\"\n" +\r
+                "include \"http://www.simantics.org/Documentation-1.1/Components\"\n" + \r
+                "include \"http://www.simantics.org/Documentation-1.1/Properties\" as Properties\n" +\r
+                "include \"http://www.simantics.org/Documentation-1.1/Relations\" as Relations", Bindings.STRING);\r
+    }\r
 }\r
similarity index 96%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java
index 120bceb58711047748c3d758b37c46b60997770e..f688b7fa9157be1e150ed8e62b23d16ca71bb553 100644 (file)
@@ -9,7 +9,7 @@
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
  *******************************************************************************/\r
-package org.simantics.sysdyn.ui.utils;\r
+package org.simantics.sysdyn.utils;\r
 \r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
similarity index 97%
rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java
rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java
index 229aff9b124d6cd6f17a048969fc07aecba222d7..ca9c70c005ea76d811002dd3a195c0e3b65c0f5c 100644 (file)
@@ -9,7 +9,7 @@
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
  *******************************************************************************/\r
-package org.simantics.sysdyn.ui.utils;\r
+package org.simantics.sysdyn.utils;\r
 \r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.Resource;\r
index 48ee948cca9a44c52128bf6082ed4a1b0a019434..a9f6d1df703bb5ff295685de9a35563494dca7ad 100644 (file)
@@ -61,6 +61,7 @@ import org.simantics.simulation.ontology.SimulationResource;
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.Activator;\r
+import org.simantics.sysdyn.utils.ModelUtils;\r
 \r
 /**\r
  * Utilities for importing tg files: Models, Modules and Function libraries\r
@@ -137,7 +138,7 @@ public class ImportUtils {
         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
-        beginTask(monitor, "Import model", 9);\r
+        beginTask(monitor, "Import model", 10);\r
 \r
         MigrationState state = MigrationUtils.newState();\r
         state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration);\r
@@ -189,7 +190,10 @@ public class ImportUtils {
                             worked(monitor, 1);\r
                             subTask(monitor, "Add shadow profile");\r
                             addShadowProfile(graph, ModelRoot);\r
-                            worked(monitor, 1);                            \r
+                            worked(monitor, 1);                \r
+                            subTask(monitor, "Add SCL Main");\r
+                            addSCLMain(graph, ModelRoot);\r
+                            worked(monitor, 1);   \r
                             subTask(monitor, "Activate model");\r
                             activateModel(graph, ModelRoot);\r
                             worked(monitor, 1);\r
@@ -250,6 +254,27 @@ public class ImportUtils {
         }\r
     }\r
 \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
+        boolean hasIt = false;\r
+        \r
+        for(Resource r : SCLModules) {\r
+            if("SCLMain".equals(NameUtils.getSafeName(graph, r))) {\r
+                hasIt = true;\r
+                break;\r
+            }\r
+        }\r
+        \r
+        if(!hasIt) {\r
+            ModelUtils.createSCLMain(graph, modelRoot);\r
+        }\r
+        \r
+    }\r
+\r
     private static void removeIssueSourcesFromModules(WriteGraph graph, Resource modelRoot) throws DatabaseException {\r
         Layer0 L0 = Layer0.getInstance(graph);\r
         IssueResource ISSUE = IssueResource.getInstance(graph);\r