}\r
\r
public void setStep(double step) {\r
- \r
- new Exception().printStackTrace();\r
- \r
this.step = step;\r
- \r
}\r
\r
public void setStart(double start) {\r
- \r
- new Exception().printStackTrace();\r
-\r
this.start = start;\r
ready = false;\r
}\r
checkEnabled="true">\r
</visibleWhen>\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.importSharedLibrary"\r
+ label="Shared Library"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ </visibleWhen>\r
+ </command>\r
<!--\r
<command\r
commandId="org.simantics.sysdyn.ui.importMdl"\r
label="Import Model"\r
style="push">\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.importSharedLibrary"\r
+ label="Import Shared Library"\r
+ style="push">\r
+ </command>\r
</menuContribution>\r
<menuContribution\r
allPopups="false"\r
id="org.simantics.sysdyn.ui.importModel"\r
name="Import Model">\r
</command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.importSharedLibrary"\r
+ name="Import Shared Library">\r
+ </command>\r
<command\r
id="org.simantics.sysdyn.ui.newEnumeration"\r
name="New Enumeration">\r
class="org.simantics.sysdyn.ui.handlers.imports.ImportModelHandler"\r
commandId="org.simantics.sysdyn.ui.importModel">\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.imports.ImportSharedLibraryHandler"\r
+ commandId="org.simantics.sysdyn.ui.importSharedLibrary">\r
+ </handler>\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.exports.ExportModelHandler"\r
commandId="org.simantics.sysdyn.ui.exportModel">\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers.imports;\r
+\r
+import java.io.File;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.DatabaseJob;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.utils.imports.ImportUtilsUI;\r
+\r
+public class ImportSharedLibraryHandler extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ // Get imported transferable graph file using FileDialog\r
+ Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
+ fd.setText("Import Model");\r
+\r
+ String path = Activator.getDefault().getPreferenceStore().getString(ImportUtilsUI.IMPORTMODELTPATH);\r
+ if(path.isEmpty() || !(new File(path).exists())){\r
+ String execDir = System.getProperty("user.dir");\r
+ String slash = System.getProperty("file.separator");\r
+ path = execDir + slash + "sampleModels"; \r
+ }\r
+ \r
+ fd.setFilterPath(path);\r
+ String[] filterExt = {"*.sharedLibrary; *.tg", "*.*"};\r
+ fd.setFilterExtensions(filterExt);\r
+ final String selected = fd.open();\r
+ if(selected == null) return null;\r
+\r
+ Job job = new DatabaseJob("Import model") {\r
+\r
+ @Override\r
+ protected IStatus run(IProgressMonitor monitor) {\r
+ ModelingUtils.importSharedOntology(selected);\r
+ return Status.OK_STATUS;\r
+ }\r
+ };\r
+ job.setUser(true);\r
+ job.schedule();\r
+\r
+ return null;\r
+\r
+ }\r
+}\r
\r
activateExperiment :: Resource -> String\r
run :: String -> ()\r
- saveIC :: Variable -> String -> <WriteGraph> Resource\r
+ saveIC :: Variable -> String -> <WriteGraph> Maybe Resource\r
assignIC :: Variable -> String -> <WriteGraph> ()\r
+ applyIC :: Variable -> String -> <WriteGraph> ()\r
+ deleteIC :: Variable -> String -> <WriteGraph> ()\r
\r
\ No newline at end of file
}\r
\r
}\r
+ exp.refresh();\r
exp.updateSubscriptions();\r
\r
} catch (Exception e) {\r
\r
Resource model = Variables.getModel(graph, input);\r
Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
- if(child != null)\r
- RemoverUtil.remove(graph, child);\r
+ SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
+ \r
+ if(child != null) {\r
+ if(graph.isInstanceOf(child, SYSDYN.InitialCondition)) {\r
+ RemoverUtil.remove(graph, child);\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
\r
PartialIC IC = new PartialIC();\r
processChild(graph, input, IC);\r
\r
Layer0 L0 = Layer0.getInstance(graph);\r
ModelingResources MOD = ModelingResources.getInstance(graph);\r
- SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
Resource ic = graph.newResource();\r
graph.claim(ic, L0.InstanceOf, SYSDYN.InitialCondition);\r
graph.addLiteral(ic, L0.HasName, L0.NameOf, L0.String, name, Bindings.STRING);\r
graph.claim(exp, SYSDYN.Experiment_ic, ic);\r
\r
}\r
+\r
+ public static void applyIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException {\r
+\r
+ System.err.println("applyIC " + experiment.getURI(graph));\r
+\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
+\r
+ Resource run = experiment.getPossibleRepresents(graph);\r
+ if(run == null) return;\r
+ Resource exp = graph.getPossibleObject(run, L0.PartOf);\r
+ if(exp == null) return;\r
+\r
+ Resource model = Variables.getModel(graph, experiment);\r
+ Resource ic = Layer0Utils.getPossibleChild(graph, model, name);\r
+ if(ic == null) return;\r
+ \r
+ if(!graph.isInstanceOf(ic, SYSDYN.InitialCondition)) return;\r
+ \r
+ Variable base = Variables.getVariable(graph, run);\r
+ \r
+ PartialIC data = graph.getPossibleRelatedValue(ic, SYSDYN.InitialCondition_HasInitialValues, PartialIC.BINDING);\r
+ data.apply(graph, base);\r
+ \r
+ }\r
+ \r
+ public static void deleteIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
+\r
+ Resource model = Variables.getModel(graph, input);\r
+ Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
+ SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
+\r
+ if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition))\r
+ RemoverUtil.remove(graph, child);\r
+ \r
+ }\r
\r
}\r
job.schedule();\r
}\r
\r
+ public void refresh() {\r
+ }\r
+ \r
public abstract ISolver getSolver();\r
\r
}\r
}\r
}\r
\r
+ @Override\r
+ public void refresh() {\r
+ try {\r
+ setSubscribedResults(new NullProgressMonitor(), solver.getTime());\r
+ \r
+ ((MemoryResult)getCurrentResult()).setResult(new GameResult(this, this.results, this.subscription));\r
+ \r
+ resultsChanged(true);\r
+ } catch (Exception e) {\r
+ Logger.defaultLogError(e);\r
+ } \r
+ }\r
+ \r
@Override\r
public void rewindTo(double time) {\r
\r