import org.simantics.db.layer0.adapter.DropActionFactory;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
// Remove dragged entity from its parent and add it to the new parent\r
graph.claim(tobemoved, L0.PartOf, library);\r
graph.deny(tobemoved, L0.PartOf, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library); \r
}\r
\r
});\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
\r
/**\r
l0.HasDescription, "",\r
sr.SysdynModelicaFunction_modelicaFunctionCode, "",\r
l0.PartOf, library);\r
-\r
- FunctionUtils.updateFunctionFileForLibrary(g, library);\r
}\r
});\r
\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
\r
/**\r
\r
if(shared)\r
g.claim(libraryLocation, l0.IsLinkedTo, functionLibrary);\r
-\r
- FunctionUtils.updateFunctionFileForLibrary(g, functionLibrary);\r
}\r
});\r
}\r
import org.simantics.db.layer0.util.RemoverUtil;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
for(Resource tobeMoved : resources) {\r
if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
- Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
graph.deny(tobeMoved, l0.PartOf);\r
graph.claim(tobeMoved, l0.PartOf, library);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
}\r
}\r
}\r
import org.simantics.db.layer0.util.RemoverUtil;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
if(library == null) {\r
library = graph.getSingleObject(thisFunction, l0.PartOf);\r
}\r
- Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
graph.deny(tobeMoved, l0.PartOf);\r
graph.claim(tobeMoved, l0.PartOf, library);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
}\r
}\r
}\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
for(Resource tobeMoved : resources) {\r
if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
- Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
graph.deny(tobeMoved, l0.PartOf);\r
graph.claim(tobeMoved, l0.PartOf, library);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
}\r
}\r
}\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
\r
for(Resource tobeMoved : resources) {\r
if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
- Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
graph.deny(tobeMoved, l0.PartOf);\r
graph.claim(tobeMoved, l0.PartOf, library);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
}\r
}\r
\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.Pair;\r
\r
FileInputStream fis = new FileInputStream(file);\r
fis.read(fileBArray);\r
graph.claimLiteral(externalFile, sr.ExternalFunctionFile_externalFile, fileBArray, Bindings.BYTE_ARRAY);\r
- \r
- FunctionUtils.createExternalFunctionFile(graph, externalFile);\r
+ fis.close();\r
} catch (IOException e) {\r
e.printStackTrace();\r
}\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
import org.simantics.ui.SimanticsUI;\r
displayErrorMessage(shell, "The imported file is not of type: Function Library (" + ft +")"); \r
}\r
});\r
- } else {\r
- // imported library is already in the right place. Update function library files.\r
- FunctionUtils.updateFunctionFileForLibrary(graph, functionLibrary);\r
}\r
\r
}\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
l0.HasDescription, "",\r
sr.SysdynModelicaFunction_modelicaFunctionCode, "",\r
l0.PartOf, library);\r
- \r
- FunctionUtils.updateFunctionFileForLibrary(g, library);\r
}\r
});\r
\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
\r
\r
if(shared)\r
g.claim(model, l0.IsLinkedTo, functionLibrary);\r
-\r
- FunctionUtils.updateFunctionFileForLibrary(g, functionLibrary);\r
}\r
});\r
}\r
import org.simantics.project.features.AbstractProjectFeature;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.simulation.project.ExperimentManagerKeys;\r
+import org.simantics.simulation.project.ExperimentManagerMode;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.editor.SysdynEditorNamingService;\r
final Session session = getSession();\r
\r
getProjectElement().setHint(ProjectKeys.DEFAULT_PERSPECTIVE, DEFAULT_PERSPECTIVE);\r
-\r
+ \r
+ // Multi for simupedia use\r
+// getProjectElement().setHint(ExperimentManagerKeys.EXPERIMENT_MANAGER_MODE, ExperimentManagerMode.MULTI_EXPERIMENT);\r
+ // Single for normal workbench use\r
+ getProjectElement().setHint(ExperimentManagerKeys.EXPERIMENT_MANAGER_MODE, ExperimentManagerMode.SINGLE_EXPERIMENT);\r
+ \r
getProjectElement().setHint(IEditorNamingService.KEY_EDITOR_NAMING_SERVICE, new SysdynEditorNamingService());\r
\r
// Install naming strategy for model components.\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
-import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListenerImpl;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.sysdyn.ui.properties.widgets.FunctionLabelFactory;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField;\r
import org.simantics.sysdyn.ui.properties.widgets.functions.FunctionCodeWidget;\r
TrackedText nameText = new TrackedText(composite, support, SWT.BORDER);\r
nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName));\r
nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName));\r
- nameText.addModifyListener(new TextModifyListenerImpl<Resource>() {\r
-\r
- @Override\r
- public void applyText(WriteGraph graph, Resource input, String text)\r
- throws DatabaseException {\r
- Resource library = graph.getSingleObject(input, Layer0.getInstance(graph).PartOf);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
- }\r
- });\r
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(nameText.getWidget());\r
\r
\r
import org.simantics.db.layer0.util.RemoverUtil;\r
import org.simantics.db.request.Write;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
\r
public class ExternalFileNode extends AbstractNode<Resource> implements IModifiableNode, IDeletableNode {\r
return new WriteRequest() {\r
@Override\r
public void perform(WriteGraph g) throws DatabaseException {\r
- FunctionUtils.removeExternalFunctionFile(g, data);\r
g.claimLiteral(data, hasName, label);\r
- FunctionUtils.createExternalFunctionFile(g, data);\r
}\r
};\r
}\r
\r
@Override\r
public void perform(WriteGraph graph) throws DatabaseException {\r
- FunctionUtils.removeExternalFunctionFile(graph, data);\r
RemoverUtil.remove(graph, data);\r
}\r
});\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.request.Read;\r
-import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.modelParser.ModelParser;\r
import org.simantics.sysdyn.modelParser.ParseException;\r
import org.simantics.sysdyn.modelParser.Token;\r
import org.simantics.sysdyn.modelParser.TokenMgrError;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionField;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.AdaptionUtils;\r
function, \r
SysdynResource.getInstance(graph).SysdynModelicaFunction_modelicaFunctionCode, \r
code);\r
- Resource library = graph.getSingleObject(function, Layer0.getInstance(graph).PartOf);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
}\r
});\r
}\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.utils.ResourceAdaptionUtils;\r
for(Resource tobeMoved : resources) {\r
if(graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunction) ||\r
graph.isInstanceOf(tobeMoved, sr.SysdynModelicaFunctionLibrary)) {\r
- Resource oldLib = graph.getSingleObject(tobeMoved, l0.PartOf);\r
graph.deny(tobeMoved, l0.PartOf);\r
graph.claim(tobeMoved, l0.PartOf, library);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, oldLib);\r
- FunctionUtils.updateFunctionFileForLibrary(graph, library);\r
}\r
}\r
- \r
}\r
});\r
}\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.FunctionUtils;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.datastructures.ArrayMap;\r
\r
} \r
graph.deny(root, l0.PartOf);\r
error = type;\r
- } else {\r
- FunctionUtils.updateFunctionFileForLibrary(graph, selectedModel);\r
}\r
-\r
}\r
});\r
} catch (DatabaseException e) {\r
\r
Variable var = parent.getParent(graph);\r
Resource represents = var.getRepresents(graph);\r
- Resource experiment = null;\r
+ \r
+ Resource activeRun = null;\r
while(represents != null && !graph.isInstanceOf(represents, MOD.StructuralModel)) {\r
\r
- if(graph.isInstanceOf(represents, SIMU.Experiment)) {\r
- experiment = represents;\r
+ if(graph.isInstanceOf(represents, SIMU.Run)) {\r
+ activeRun = represents;\r
break;\r
}\r
\r
}\r
\r
IProject project = Simantics.peekProject();\r
- if(experiment != null && project != null) {\r
+ if(activeRun != null && project != null) {\r
IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
- IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, experiment));\r
+ IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, activeRun));\r
if(e instanceof SysdynExperiment)\r
this.experiment = (SysdynExperiment)e;\r
}\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.Activator;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
public class FunctionUtils {\r
\r
- public static List<String> getLibraryPathsForModelica(final SysdynModel model) {\r
+ public static List<String> getLibraryPathsForModelica(final SysdynExperiment sysdynExperiment) {\r
final ArrayList<String> paths = new ArrayList<String>();\r
\r
try {\r
\r
@Override\r
public void run(ReadGraph graph) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- SimulationResource simu = SimulationResource.getInstance(graph);\r
- \r
- Set<Resource> parents = getParents(graph, model, true);\r
- for(Resource parent : parents) {\r
- if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
- Resource configuration = graph.getPossibleObject(parent, simu.HasConfiguration);\r
- if(configuration.equals(model.getConfigurationResource())) {\r
- String parentName = NameUtils.getSafeName(graph, parent);\r
- paths.add(parentName + "_functions.mo");\r
- }\r
- } else {\r
- String libraryname = NameUtils.getSafeName(graph, parent);\r
- paths.add("..\\\\\\\\..\\\\\\\\libraries\\\\\\\\functions\\\\\\\\" + libraryname + ".mo");\r
- }\r
- }\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+ Set<Resource> parents = getParents(graph, sysdynExperiment.getModel(), true);\r
+ for(Resource parent : parents) {\r
+ if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
+ String parentName = NameUtils.getSafeName(graph, parent);\r
+ paths.add(parentName + "_functions.mo");\r
+ } else {\r
+ String libraryname = NameUtils.getSafeName(graph, parent);\r
+ paths.add("..\\\\\\\\..\\\\\\\\libraries\\\\\\\\functions\\\\\\\\" + libraryname + ".mo");\r
+ }\r
+ }\r
}\r
});\r
} catch (DatabaseException e) {\r
return paths;\r
}\r
\r
- private static Set<Resource> getParents(ReadGraph graph, SysdynModel model, boolean onlyWithContent) throws DatabaseException{\r
+ private static Set<Resource> getParents(ReadGraph graph, Resource model, boolean onlyWithContent) throws DatabaseException{\r
HashSet<Resource> parents = new HashSet<Resource>();\r
\r
+ if(model == null)\r
+ return parents;\r
+ \r
Layer0 l0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- SimulationResource simu = SimulationResource.getInstance(graph);\r
- Resource modelResource = graph.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf);\r
- if(modelResource == null)\r
- return parents;\r
- \r
- parents.add(modelResource);\r
- \r
- for(Resource r : graph.getObjects(modelResource, l0.IsLinkedTo)) {\r
+\r
+ parents.add(model);\r
+ for(Resource r : graph.getObjects(model, l0.IsLinkedTo)) {\r
if(graph.isInstanceOf(r, sr.SharedFunctionOntology)) {\r
parents.add(r);\r
} else {\r
return false;\r
}\r
\r
- public static void updateFunctionFilesForModel(ReadGraph graph, SysdynModel model) throws DatabaseException {\r
+ public static void updateFunctionFilesForExperiment(ReadGraph graph, SysdynExperiment experiment) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
- Set<Resource> parents = getParents(graph, model, false);\r
+ Set<Resource> parents = getParents(graph, experiment.getModel(), false);\r
\r
for(Resource parent : parents) {\r
if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
String parentName = NameUtils.getSafeName(graph, parent);\r
- File scriptFile = new File(model.getSimulationDir(), parentName + "_functions.mo");\r
+ File scriptFile = new File(experiment.getSimulationDir(), parentName + "_functions.mo");\r
updateFunctionFile(graph, parent, scriptFile, false);\r
} else {\r
updateFunctionFileForLibrary(graph, parent);\r
return;\r
}\r
\r
+ /*\r
private static File getDir(ReadGraph graph, Resource resource) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
}\r
return dir;\r
}\r
+ */\r
\r
- public static void createExternalFunctionFile(ReadGraph graph, Resource externalFunction) throws DatabaseException {\r
+ public static void createExternalFunctionFile(ReadGraph graph, Resource externalFunction, File scriptFile) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
\r
- Resource function = graph.getSingleObject(externalFunction, l0.PartOf);\r
- File dir = getDir(graph, function);\r
+ File dir = scriptFile.getParentFile();\r
+ \r
+ if(!dir.exists())\r
+ dir.mkdir();\r
+ \r
+ if(!dir.isDirectory())\r
+ return;\r
\r
try {\r
String name = NameUtils.getSafeName(graph, externalFunction);\r
}\r
}\r
\r
- public static void removeExternalFunctionFile(ReadGraph graph, Resource externalFunction) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ protected static void updateFunctionFileForLibrary(ReadGraph graph, Resource library) throws DatabaseException {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
\r
- Resource function = graph.getSingleObject(externalFunction, l0.PartOf);\r
- File dir = getDir(graph, function);\r
- String name = NameUtils.getSafeName(graph, externalFunction);\r
- File file = new File(dir, name);\r
- file.delete();\r
- }\r
+ while(!graph.isInstanceOf(library, l0.Ontology)) {\r
+ library = graph.getSingleObject(library, l0.PartOf);\r
+ }\r
\r
- \r
- \r
- public static void updateFunctionFileForLibrary(ReadGraph graph, Resource library) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- \r
- while(!graph.isInstanceOf(library, sr.SysdynModel) && !graph.isInstanceOf(library, l0.Ontology)) {\r
- library = graph.getSingleObject(library, l0.PartOf);\r
- }\r
- \r
- if(graph.isInstanceOf(library, sr.SysdynModel)) {\r
- SimulationResource simu = SimulationResource.getInstance(graph);\r
- Resource configuration = graph.getSingleObject(library, simu.HasConfiguration);\r
- SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
- SysdynModel model = smm.getModel(graph, configuration);\r
- updateFunctionFilesForModel(graph, model);\r
- } else {\r
- \r
- File librariesDir = Activator.getBundleContext().getDataFile("libraries");\r
- if (!librariesDir.exists()) {\r
- librariesDir.mkdir();\r
- }\r
- File dir = new File(librariesDir, "functions");\r
- if (!dir.exists()) {\r
- dir.mkdir();\r
- }\r
- String parentName = NameUtils.getSafeName(graph, library);\r
- File scriptFile = new File(dir, parentName + ".mo");\r
- \r
- Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1");\r
+ File librariesDir = Activator.getBundleContext().getDataFile("libraries");\r
+ if (!librariesDir.exists()) {\r
+ librariesDir.mkdir();\r
+ }\r
+ File dir = new File(librariesDir, "functions");\r
+ if (!dir.exists()) {\r
+ dir.mkdir();\r
+ }\r
+ String parentName = NameUtils.getSafeName(graph, library);\r
+ File scriptFile = new File(dir, parentName + ".mo");\r
\r
- if(library.equals(sysdyn)) {\r
- updateFunctionFile(graph, library, scriptFile, true);\r
- } else {\r
- updateFunctionFile(graph, library, scriptFile, false);\r
- }\r
- }\r
- \r
+ Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1");\r
+\r
+ if(library.equals(sysdyn)) {\r
+ updateFunctionFile(graph, library, scriptFile, true);\r
+ } else {\r
+ updateFunctionFile(graph, library, scriptFile, false);\r
+ }\r
\r
}\r
\r
String name = NameUtils.getSafeName(graph, library);\r
if(!builtIn && !graph.isInstanceOf(library, sr.SysdynModel))\r
s.println("package " + name);\r
- writeLibrary(graph, library, s, builtIn);\r
+ writeLibrary(graph, library, scriptFile, s, builtIn);\r
if(!builtIn && !graph.isInstanceOf(library, sr.SysdynModel))\r
s.println("end " + name + ";\n");\r
\r
s.close();\r
}\r
\r
- private static void writeLibrary(ReadGraph graph, Resource library, PrintStream stream, boolean builtIn) throws DatabaseException {\r
+ private static void writeLibrary(ReadGraph graph, Resource library, File scriptFile, PrintStream stream, boolean builtIn) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- writeLibraryFunctions(graph, library, stream);\r
+ writeLibraryFunctions(graph, library, scriptFile, stream);\r
for(Resource sublibrary : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
String name = NameUtils.getSafeName(graph, sublibrary);\r
if(!builtIn)\r
stream.println("encapsulated package " + name);\r
- writeLibrary(graph, sublibrary, stream, builtIn);\r
+ writeLibrary(graph, sublibrary, scriptFile, stream, builtIn);\r
if(!builtIn)\r
stream.println("end " + name + ";\n");\r
}\r
}\r
\r
- private static void writeLibraryFunctions(ReadGraph graph, Resource library, PrintStream stream) throws DatabaseException {\r
+ private static void writeLibraryFunctions(ReadGraph graph, Resource library, File scriptFile, PrintStream stream) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
for(Resource function : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction))) {\r
stream.println(functionCode);\r
stream.println("end " + name + ";\n");\r
for(Resource externalFunction : graph.syncRequest(new ObjectsWithType(function, l0.ConsistsOf, sr.ExternalFunctionFile))) {\r
- createExternalFunctionFile(graph, externalFunction);\r
+ createExternalFunctionFile(graph, externalFunction, scriptFile);\r
}\r
}\r
}\r
import java.io.IOException;\r
import java.io.StringReader;\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.Collection;\r
import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
import java.util.UUID;\r
import java.util.concurrent.locks.Lock;\r
import org.simantics.simulation.experiment.IDynamicExperiment;\r
import org.simantics.simulation.experiment.IExperimentListener;\r
import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.sysdyn.Activator;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.adapter.VariableValueSubscription;\r
import org.simantics.sysdyn.modelica.ModelicaWriter;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.Model;\r
import org.simantics.sysdyn.simulation.SimulationScheduler;\r
-import org.simantics.sysdyn.manager.SysdynInitKeys;\r
\r
public class SysdynExperiment extends Experiment implements IDynamicExperiment, VariableSubscriptionManager {\r
\r
protected ExperimentState sysdynExperimentState;\r
\r
private SysdynResult result;\r
+ private File simulationDir;\r
\r
+ protected String experimentName;\r
+ \r
public static SysdynExperiment INSTANCE;\r
\r
- public SysdynExperiment(Resource experiment, Resource model, String identifier) {\r
- super(experiment, model, identifier);\r
+ public SysdynExperiment(Resource experiment, Resource model) {\r
+ super(experiment, model);\r
INSTANCE = this;\r
}\r
\r
* @param g ReadGraph\r
*/\r
public void init(ReadGraph g) {\r
+ try {\r
+ this.experimentName = NameUtils.getSafeName(g, experiment);\r
+ } catch (DatabaseException e) {\r
+ this.experimentName = "Experiment";\r
+ }\r
+ \r
this.session = g.getSession();\r
state = ExperimentState.STOPPED;\r
for(IExperimentListener listener : listeners.getListeners())\r
* @return\r
* @throws IOException\r
*/\r
- protected static SimulationLocation createSimulationFiles(SysdynModel sysdynModel, String modelText, HashMap<String, String> inits, String additionalScript, boolean fmu) throws IOException {\r
+ protected SimulationLocation createSimulationFiles(SysdynModel sysdynModel, String modelText, HashMap<String, String> inits, String additionalScript, boolean fmu) throws IOException {\r
+ File simulationDir = getSimulationDir();\r
+\r
+ // update all function files. both the model's and built-in\r
+ try {\r
+ final SysdynExperiment experiment = this;\r
+ session.syncRequest(new ReadRequest() {\r
+ \r
+ @Override\r
+ public void run(ReadGraph graph) throws DatabaseException {\r
+ FunctionUtils.updateFunctionFilesForExperiment(graph, experiment);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
return ModelicaManager.createSimulationFiles(\r
- sysdynModel.getSimulationDir(),\r
+ simulationDir,\r
sysdynModel.getConfiguration().getLabel(),\r
modelText,\r
inits,\r
additionalScript,\r
fmu);\r
}\r
+ \r
+ /**\r
+ * Get a simulation directory for this model\r
+ * @return File directory\r
+ */\r
+ public File getSimulationDir() {\r
+ if(simulationDir == null) {\r
+ File modelsDir = Activator.getBundleContext().getDataFile("models");\r
+ String experimentName = this.experimentName;\r
+ List<String> files = Arrays.asList(modelsDir.list());\r
+ if (files.contains(experimentName)) {\r
+ int i = 2;\r
+ while (files.contains(experimentName + "_" + i)){\r
+ i++;\r
+ }\r
+ experimentName += "_" + i;\r
+ }\r
+\r
+ simulationDir = Activator.getBundleContext().getDataFile("models/" + experimentName);\r
+ if (!simulationDir.exists()) {\r
+ simulationDir.mkdir();\r
+ }\r
+ }\r
+ return simulationDir;\r
+ }\r
\r
/**\r
* \r
*/\r
protected String getAdditionalScripts() {\r
StringBuilder functionscript = new StringBuilder();\r
- for(String path : FunctionUtils.getLibraryPathsForModelica(sysdynModel)) {\r
+ for(String path : FunctionUtils.getLibraryPathsForModelica(this)) {\r
functionscript.append("loadFile(\"" + path + "\");\n"); \r
}\r
return functionscript.toString();\r
public static double DEFAULT_STEP_LENGTH = 0.1;\r
public static int DEFAULT_OUTPUT_INTERVAL = 1;\r
\r
- public SysdynGameExperiment(Resource experiment, Resource model, String identifier) {\r
- super(experiment, model, identifier);\r
+ public SysdynGameExperiment(Resource experiment, Resource model) {\r
+ super(experiment, model);\r
}\r
\r
public double getStepDuration() {\r
\r
import gnu.trove.set.hash.THashSet;\r
\r
-import java.io.File;\r
import java.util.ArrayList;\r
-import java.util.Arrays;\r
import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
-import java.util.List;\r
import java.util.Map;\r
import java.util.Set;\r
import java.util.concurrent.CopyOnWriteArrayList;\r
import org.simantics.simulation.project.IExperimentActivationListener;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.Activator;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.adapter.VariableValueSubscription;\r
import org.simantics.sysdyn.representation.Configuration;\r
@SuppressWarnings("rawtypes")\r
private Map<Class, Object> services = new HashMap<Class, Object>();\r
\r
- private File simulationDir;\r
-\r
/**\r
* Recursively read all module configurations that are used in \r
* configResource and its components children\r
SysdynResource sr = SysdynResource.getInstance(g);\r
IDynamicExperiment exp;\r
\r
- String name = NameUtils.getSafeName(g, experiment);\r
if(g.isInstanceOf(experiment, sr.PlaybackExperiment)) {\r
- exp = new SysdynPlaybackExperiment(experiment, modelResource, name);\r
+ exp = new SysdynPlaybackExperiment(experiment, modelResource);\r
} else if(g.isInstanceOf(experiment, sr.GameExperiment)) {\r
- exp = new SysdynGameExperiment(experiment, modelResource, name);\r
+ exp = new SysdynGameExperiment(experiment, modelResource);\r
} else if(g.isInstanceOf(experiment, sr.BasicExperiment)) {\r
- exp = new SysdynExperiment(experiment, modelResource, name);\r
+ exp = new SysdynExperiment(experiment, modelResource);\r
} else {\r
return null;\r
}\r
return inits;\r
}\r
\r
- /**\r
- * Get a simulation directory for this model\r
- * @return File directory\r
- */\r
- public File getSimulationDir() {\r
- if(simulationDir == null) {\r
- File modelsDir = Activator.getBundleContext().getDataFile("models");\r
- String configName = configuration.getLabel();\r
- List<String> files = Arrays.asList(modelsDir.list());\r
- if (files.contains(configName)) {\r
- int i = 2;\r
- while (files.contains(configName + "_" + i)){\r
- i++;\r
- }\r
- configName += "_" + i;\r
- }\r
-\r
- simulationDir = Activator.getBundleContext().getDataFile("models/" + configName);\r
- if (!simulationDir.exists()) {\r
- simulationDir.mkdir();\r
- }\r
- }\r
- return simulationDir;\r
- }\r
-\r
\r
@SuppressWarnings("rawtypes")\r
/**\r
import org.simantics.db.Session;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
\r
/**\r
* Manages system dynamic models.\r
public void run(ReadGraph graph) throws DatabaseException {\r
SysdynModel model = new SysdynModel(graph, resource);\r
models.put(resource, model);\r
- FunctionUtils.updateFunctionFilesForModel(graph, model);\r
}\r
});\r
} catch (DatabaseException e) {\r
if(model == null) {\r
model = new SysdynModel(g, resource);\r
models.put(resource, model);\r
- try {\r
- SimulationResource simu = SimulationResource.getInstance(g);\r
- Resource modelResource = g.getPossibleObject(model.getConfigurationResource(), simu.IsConfigurationOf);\r
- if(modelResource != null)\r
- FunctionUtils.updateFunctionFilesForModel(g, model);\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
}\r
return model;\r
}\r
ScheduledExecutorService playbackExecutionService;\r
PlaybackConfiguration playbackConfiguration;\r
\r
- public SysdynPlaybackExperiment(Resource experiment, Resource model, String identifier) {\r
- super(experiment, model, identifier);\r
+ public SysdynPlaybackExperiment(Resource experiment, Resource model) {\r
+ super(experiment, model);\r
this.time = 0;\r
}\r
\r