From 30b79d3d2f717ea7f1861e9af05e3bb0021b90da Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 25 Jun 2013 09:57:39 +0000 Subject: [PATCH] Moving utils around (refs #3511) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27652 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/modelica/ModelicaManager.java | 2 +- .../actions/newActions/NewSheetAction.java | 2 +- .../newComponents/NewModelHandler.java | 2 +- .../newComponents/NewSpreadSheetHandler.java | 2 +- .../sysdyn/ui/structure/ModuleStructure.java | 1 + .../sysdyn/ui/utils/ArrayVariableUtils.java | 1 + .../ui/utils/VariableNameValidator.java | 1 + org.simantics.sysdyn/META-INF/MANIFEST.MF | 1 + .../simantics/sysdyn}/utils/ModelUtils.java | 36 +++++++++++++------ .../sysdyn}/utils/ProfileEntries.java | 2 +- .../simantics/sysdyn}/utils/SheetUtils.java | 2 +- .../sysdyn/utils/imports/ImportUtils.java | 29 +++++++++++++-- 12 files changed, 62 insertions(+), 19 deletions(-) rename {org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui => org.simantics.sysdyn/src/org/simantics/sysdyn}/utils/ModelUtils.java (82%) rename {org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui => org.simantics.sysdyn/src/org/simantics/sysdyn}/utils/ProfileEntries.java (96%) rename {org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui => org.simantics.sysdyn/src/org/simantics/sysdyn}/utils/SheetUtils.java (97%) diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index e0eaa210..d2f2d43a 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -175,7 +175,7 @@ public class ModelicaManager { public static String getOMCVersion(File OMHome) throws IOException { ArrayList parameters = new ArrayList(); - parameters.add(OMHome + "\\bin\\omc.exe"); + parameters.add(new File(OMHome, "/bin/omc").getAbsolutePath()); parameters.add("++v"); // Create the build process diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java index 418f0194..e579df6c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/actions/newActions/NewSheetAction.java @@ -16,7 +16,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.ActionFactory; -import org.simantics.sysdyn.ui.utils.SheetUtils; +import org.simantics.sysdyn.utils.SheetUtils; import org.simantics.ui.SimanticsUI; /** diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java index d60a1854..6ed6858e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewModelHandler.java @@ -23,7 +23,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.sysdyn.ui.Activator; -import org.simantics.sysdyn.ui.utils.ModelUtils; +import org.simantics.sysdyn.utils.ModelUtils; import org.simantics.ui.SimanticsUI; /** diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java index 16c6a3da..3a64607a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSpreadSheetHandler.java @@ -20,7 +20,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; -import org.simantics.sysdyn.ui.utils.SheetUtils; +import org.simantics.sysdyn.utils.SheetUtils; import org.simantics.ui.SimanticsUI; import org.simantics.ui.utils.ResourceAdaptionUtils; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java index 3354f7fd..c3b27997 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java @@ -114,6 +114,7 @@ public class ModuleStructure extends CTabItem { @Override public void run() { + if (component.isDisposed()) return; component.setGraph((Graph)getObject(), "dot"); component.fit(); } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java index ba8950cb..d6f024e1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java @@ -13,6 +13,7 @@ import org.simantics.sysdyn.representation.EnumerationIndex; import org.simantics.sysdyn.representation.IElement; import org.simantics.sysdyn.representation.Variable; import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField; +import org.simantics.sysdyn.utils.ModelUtils; public class ArrayVariableUtils { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameValidator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameValidator.java index 969517b2..05b8382a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameValidator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/VariableNameValidator.java @@ -27,6 +27,7 @@ import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.representation.Configuration; import org.simantics.sysdyn.representation.Model; import org.simantics.sysdyn.representation.ModuleType; +import org.simantics.sysdyn.utils.ModelUtils; import org.simantics.ui.SimanticsUI; /** diff --git a/org.simantics.sysdyn/META-INF/MANIFEST.MF b/org.simantics.sysdyn/META-INF/MANIFEST.MF index 39ecd3f7..ce2df41d 100644 --- a/org.simantics.sysdyn/META-INF/MANIFEST.MF +++ b/org.simantics.sysdyn/META-INF/MANIFEST.MF @@ -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 diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java 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 0974468c..c7923c8a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java @@ -1,7 +1,8 @@ -package org.simantics.sysdyn.ui.utils; +package org.simantics.sysdyn.utils; import java.util.UUID; +import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -22,7 +23,6 @@ import org.simantics.spreadsheet.resource.SpreadsheetResource; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.manager.SysdynModel; import org.simantics.sysdyn.manager.SysdynModelManager; -import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.ArrayMap; public class ModelUtils { @@ -40,7 +40,7 @@ public class ModelUtils { Resource configuration = graph.getPossibleObject(variable, l0.PartOf); if(configuration == null) return null; - SysdynModelManager sdm = SysdynModelManager.getInstance(SimanticsUI.getSession()); + SysdynModelManager sdm = SysdynModelManager.getInstance(Simantics.getSession()); SysdynModel model = sdm.getModel(graph, configuration); try { model.update(graph); @@ -51,7 +51,7 @@ public class ModelUtils { } public static void createModel(WriteGraph graph) { - createModelAt(graph, SimanticsUI.getProject().get()); + createModelAt(graph, Simantics.getProject().get()); } public static void createModelAt(WriteGraph g, Resource library) { @@ -65,7 +65,7 @@ public class ModelUtils { String modelName = NameUtils.findFreshName(g, "Model", library, l0.ConsistsOf, "%s%d"); - Resource project = SimanticsUI.getProject().get(); + Resource project = Simantics.getProject().get(); Resource model = GraphUtils.create2(g, sr.SysdynModel, l0.PartOf, project, @@ -164,12 +164,7 @@ public class ModelUtils { } } - GraphUtils.create2(g, - l0.SCLModule, - l0.PartOf, model, - l0.HasName, "SCLMain", - l0.SCLModule_definition, "include \"http:\\\\www.simantics.org\\DB\"\ninclude \"http:\\\\www.simantics.org\\Variables\"\n" - ); + createSCLMain(g, model); ProfileEntries.createStandardProfiles(g, model); @@ -178,4 +173,23 @@ public class ModelUtils { Logger.defaultLogError(e); } } + + public static void createSCLMain(WriteGraph graph, Resource model) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource SCLModule = GraphUtils.create2(graph, + L0.SCLModule, + L0.PartOf, model, + L0.HasName, "SCLMain" + ); + + if(graph.hasStatement(SCLModule, L0.SCLModule_definition)) + graph.deny(SCLModule, L0.SCLModule_definition); + graph.claimLiteral(SCLModule, L0.SCLModule_definition, + "include \"http://www.simantics.org/DB\"\n" + + "include \"http://www.simantics.org/Variables\"\n" + + "include \"" + graph.getURI(model) + "\"\n" + + "include \"http://www.simantics.org/Documentation-1.1/Components\"\n" + + "include \"http://www.simantics.org/Documentation-1.1/Properties\" as Properties\n" + + "include \"http://www.simantics.org/Documentation-1.1/Relations\" as Relations", Bindings.STRING); + } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java 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 120bceb5..f688b7fa 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ProfileEntries.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.utils; +package org.simantics.sysdyn.utils; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java 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 229aff9b..ca9c70c0 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SheetUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.utils; +package org.simantics.sysdyn.utils; import org.simantics.databoard.Bindings; import org.simantics.db.Resource; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java index 48ee948c..a9f6d1df 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java @@ -61,6 +61,7 @@ import org.simantics.simulation.ontology.SimulationResource; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.Activator; +import org.simantics.sysdyn.utils.ModelUtils; /** * Utilities for importing tg files: Models, Modules and Function libraries @@ -137,7 +138,7 @@ public class ImportUtils { final Resource project = Simantics.getProject().get(); if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null); - beginTask(monitor, "Import model", 9); + beginTask(monitor, "Import model", 10); MigrationState state = MigrationUtils.newState(); state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); @@ -189,7 +190,10 @@ public class ImportUtils { worked(monitor, 1); subTask(monitor, "Add shadow profile"); addShadowProfile(graph, ModelRoot); - worked(monitor, 1); + worked(monitor, 1); + subTask(monitor, "Add SCL Main"); + addSCLMain(graph, ModelRoot); + worked(monitor, 1); subTask(monitor, "Activate model"); activateModel(graph, ModelRoot); worked(monitor, 1); @@ -250,6 +254,27 @@ public class ImportUtils { } } + protected static void addSCLMain(WriteGraph graph, Resource modelRoot) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + SysdynResource SR = SysdynResource.getInstance(graph); + + Collection SCLModules = graph.syncRequest(new ObjectsWithType(modelRoot, L0.ConsistsOf, L0.SCLModule)); + + boolean hasIt = false; + + for(Resource r : SCLModules) { + if("SCLMain".equals(NameUtils.getSafeName(graph, r))) { + hasIt = true; + break; + } + } + + if(!hasIt) { + ModelUtils.createSCLMain(graph, modelRoot); + } + + } + private static void removeIssueSourcesFromModules(WriteGraph graph, Resource modelRoot) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); IssueResource ISSUE = IssueResource.getInstance(graph); -- 2.47.1