]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #4854
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Sat, 24 May 2014 11:07:44 +0000 (11:07 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Sat, 24 May 2014 11:07:44 +0000 (11:07 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29538 ac1ea38d-2e2b-0410-8846-a27921b304fc

fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportSharedLibraryHandler.java [new file with mode: 0644]
org.simantics.sysdyn/scl/Sysdyn.scl
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentBase.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperimentInternal.java

index 1a0145574c24fe96f16c7255db834c0fbab3df1b..013f8893403ac152c63bb208a93695013b439878 100644 (file)
@@ -51,17 +51,10 @@ public class Solver {
        }\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
index b16564db14da697dfbd49bc802ce6c20cbfcf550..58e73242ba7a3af3662f9e607732f9efc0672d29 100644 (file)
                      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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportSharedLibraryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/imports/ImportSharedLibraryHandler.java
new file mode 100644 (file)
index 0000000..4190860
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************\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
index a3c4a81ff2b47175802002436de48f2f5eae4707..d9ea7c17ca1e71be5ed29303c24756ad2e519a33 100644 (file)
@@ -98,7 +98,9 @@ importJava "org.simantics.sysdyn.manager.SysdynExperiments" where
     \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
index 567b18748ba6796bd65454f9439c4d46a42f2c48..1e7bf51b6c7e99304b35f13726da6125942d87a7 100644 (file)
@@ -104,6 +104,7 @@ abstract public class ValueIndexVariableBase<T> extends IndexVariable<T> {
                                        }\r
 \r
                                }\r
+                               exp.refresh();\r
                                exp.updateSubscriptions();\r
                        \r
                        } catch (Exception e) {\r
index 3b333601228f812405bbe92ee8b71c11813cd25e..ebb8092ff75cabc721a2c4131fdc640566b786de 100644 (file)
@@ -172,15 +172,21 @@ public class SysdynExperiments {
        \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
@@ -213,5 +219,41 @@ public class SysdynExperiments {
                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
index 16ab3a5240eec444ac96abc6aff098226579a1c0..7c5a8edeb3147f1519097044728719c84e8e13a6 100644 (file)
@@ -127,6 +127,9 @@ abstract public class SysdynGameExperimentBase extends OldSysdynExperiment {
                job.schedule();\r
        }\r
        \r
+       public void refresh() {\r
+       }\r
+       \r
     public abstract ISolver getSolver();\r
     \r
 }\r
index c67ba4886c6438d0d69cb784b9177248275ea0ed..924455f04ddeb359a74ea73d739a721259a6ca13 100644 (file)
@@ -152,6 +152,19 @@ public class SysdynGameExperimentInternal extends SysdynGameExperimentBase {
                }\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