]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Method and tolerance -settings for models, movable value view columns
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 7 Sep 2010 12:55:32 +0000 (12:55 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 7 Sep 2010 12:55:32 +0000 (12:55 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17804 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java

index 11966b3296b463d26cdd2044ac1315cfd78e3519..478b81d5abc5ac8d0b8ff0c477a3cd6e920d31c1 100644 (file)
@@ -109,8 +109,7 @@ public class ModelicaManager {
             s.print("buildModel("+modelName+\r
                     ",startTime="+inits.get("start value")+\r
                     ",stopTime="+inits.get("stop value")+\r
-//                    ",numberOfIntervals="+inits.get("step value")+\r
-                    ",method=\"euler\""\r
+                    ",method="+inits.get("method")\r
             );\r
             if(inits.containsKey("tolerance")) {\r
                 s.print(",tolerance="+inits.get("tolerance"));\r
index 1493b48cc20ac11548a9629d6ad74453ab0369dd..49d09cec41786da2d142c86845aaf373a568fa88 100644 (file)
@@ -1,5 +1,8 @@
 package org.simantics.sysdyn.ui.properties;\r
 \r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
 import org.eclipse.jface.dialogs.IInputValidator;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
@@ -10,11 +13,18 @@ import org.eclipse.ui.IWorkbenchSite;
 import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\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.TrackedCombo;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
 import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\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.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.ComboStringPropertyModifier;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 \r
@@ -72,6 +82,54 @@ public class ConfigurationTab extends PropertyTabContributorImpl {
         outputInterval.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasOutputInterval));\r
         outputInterval.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(outputInterval.getWidget());\r
+        \r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Method");\r
+        \r
+        TrackedCombo method = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
+        method.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
+\r
+            @Override\r
+            public Map<String, Object> perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+\r
+                Map<String, Object> map = new HashMap<String, Object>();\r
+                map.put("euler", "euler");\r
+                map.put("rungekutta", "rungekutta");\r
+                map.put("dassl", "dassl");\r
+                map.put("dassl2", "dassl2");\r
+                map.put("inline-euler", "inline-euler");\r
+                map.put("inline-rungekutta", "inline-rungekutta");\r
+                return map;\r
+            }\r
+        });\r
+        \r
+        method.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+            @Override\r
+            public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                return graph.getRelatedValue(input, SysdynResource.getInstance(graph).HasSolver);\r
+            }\r
+        });\r
+        \r
+        method.addModifyListener(new ComboStringPropertyModifier<Resource>() {\r
+\r
+                       @Override\r
+                       public void applyText(WriteGraph graph, Resource input, String text)\r
+                                       throws DatabaseException {\r
+                               graph.claimLiteral(input, SysdynResource.getInstance(graph).HasSolver, text);\r
+                       }\r
+               });\r
+        \r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Tolerance");\r
+\r
+        TrackedText tolerance = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT);\r
+        tolerance.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasTolerance));\r
+        tolerance.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasTolerance));\r
+        tolerance.setInputValidator(new DoubleValidator());\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(tolerance.getWidget());\r
+\r
+        \r
     }\r
 \r
     private class DoubleValidator implements IInputValidator {\r
index 31acfd1150b9a4d07cba84e4f20a46c73a4f5dbf..14af26b73dc72b21e5981f35c08afabdc0fbb184 100644 (file)
@@ -11,7 +11,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
 import org.simantics.db.exception.ServiceException;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -29,7 +28,6 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
             SysdynResource sr = SysdynResource.getInstance(backend);\r
             DiagramResource dr = DiagramResource.getInstance(backend);\r
             ModelingResources mr = ModelingResources.getInstance(backend);\r
-            Layer0 l0 = Layer0.getInstance(backend);\r
             Collection<ComparableTabContributor> tabs = new ArrayList<ComparableTabContributor>();\r
             if (backend.isInstanceOf(r, dr.Element)) {\r
                 Resource component = backend.getPossibleObject(r, mr.ElementToComponent);\r
@@ -69,19 +67,15 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                         r,\r
                 "Input"));\r
             }\r
-            Resource represents = backend.getPossibleObject(r, l0.Represents);\r
-            if ((represents != null && backend.isInstanceOf(represents, sr.Configuration)) || (backend.isInstanceOf(r, sr.SysdynModel))) {\r
-                Resource model;\r
-                if (represents != null)\r
-                    model = backend.getPossibleObject(represents, SimulationResource.getInstance(backend).IsConfigurationOf);\r
-                else\r
-                    model = r;\r
-                if (model != null)\r
+            if ( backend.isInstanceOf(r, sr.Configuration) || backend.isInstanceOf(r, sr.SysdynModel)) {\r
+               if(!backend.isInstanceOf(r, sr.SysdynModel))\r
+                       r = backend.getPossibleObject(r, SimulationResource.getInstance(backend).IsConfigurationOf);\r
+                if (r != null)\r
                     return Collections.singleton(\r
                             new ComparableTabContributor(\r
                                     new ConfigurationTab(),\r
                                     0,\r
-                                    model,\r
+                                    r,\r
                             "Model Properties"));\r
             }\r
             if (backend.isInstanceOf(r, sr.Module)){\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java
new file mode 100644 (file)
index 0000000..ded2ed1
--- /dev/null
@@ -0,0 +1,59 @@
+package org.simantics.sysdyn.ui.properties.widgets.factories;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.utils.ReflectionUtils;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+abstract public class ComboStringPropertyModifier<T> implements TextModifyListener, Widget {\r
+\r
+       private ISessionContext context;\r
+       private Object lastInput = null;\r
+       \r
+    final private Class<?> clazz;\r
+       \r
+       public ComboStringPropertyModifier() {\r
+        clazz = ReflectionUtils.getSingleParameterType(getClass());\r
+       }\r
+       \r
+       @Override\r
+       public void setInput(ISessionContext context, Object input) {\r
+               this.context = context;\r
+               lastInput = input;\r
+       }\r
+\r
+       @Override\r
+       public void modifyText(TrackedModifyEvent e) {\r
+               Combo text = (Combo)e.getWidget();\r
+               final String textValue = text.getText();\r
+               final Object input = lastInput;\r
+               \r
+               try {\r
+                       context.getSession().syncRequest(new WriteRequest() {\r
+\r
+                               @SuppressWarnings("unchecked")\r
+                @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+                                       T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz);\r
+                                       applyText(graph, single, textValue);\r
+                                       \r
+                               }\r
+                               \r
+                       });\r
+               } catch (DatabaseException e1) {\r
+                       e1.printStackTrace();\r
+               }\r
+               \r
+       }\r
+       \r
+       abstract public void applyText(WriteGraph graph, T input, String text) throws DatabaseException;\r
+\r
+}\r
index 05d48884622d5323719573b379ee185d04594429..bebac33f63a964ec62997ed3c65f34b002422dc1 100644 (file)
@@ -160,6 +160,7 @@ public class ValueView  extends ViewPart {
                        TableColumn column = new TableColumn (table, SWT.NONE);\r
                        column.setText (titles [i]);\r
                        column.addListener(SWT.Selection, sortListener);\r
+                       column.setMoveable(true);\r
                }       \r
                \r
            table.setSortColumn(table.getColumn(0));\r
index f62dfee68c8b14dbd68df25794041514d1826612..ec01a1c64d0bf6a0080905e712c1157d00616cf8 100644 (file)
@@ -187,8 +187,8 @@ public class SysdynModel implements IMappingListener, IModel {
                } else {\r
                        inits.put("step value", "" + (stopTime - startTime) / 500);\r
                }\r
-               if(model.getSolver() != null)\r
-                       inits.put("solver", model.getSolver());\r
+               String method = "\"" + model.getSolver() + "\"";\r
+               inits.put("method", method);\r
                if(model.getTolerance() != null)\r
                        inits.put("tolerance", model.getTolerance().toString());\r
 \r
@@ -214,6 +214,7 @@ public class SysdynModel implements IMappingListener, IModel {
                                previousImportantInits.clear();\r
                                previousImportantInits.put("start value", startTime.toString());\r
                                previousImportantInits.put("stop value", stopTime.toString());\r
+                               previousImportantInits.put("method", method);\r
                        } catch (ModelicaException e) {\r
                                monitor.showConsole();\r
                                canceled = true;\r
index 8f8a4fb773b6469ba47e99fced225397f53f884d..f13e32af15bc9136c8cbd6822962faa1b0f4a781 100644 (file)
@@ -103,7 +103,7 @@ public class SimulationJob extends Job {
             MessageConsoleStream out = this.console.newMessageStream();\r
             if(message.length() > 1)\r
                out.println("[" + time +"] " + message);\r
-            if(message.contains("Error:"))\r
+            if(message.contains("Error"))\r
                showConsole();\r
         }\r
 \r