From b116f97eee6a7f465a384548f4e2e21083ed75ec Mon Sep 17 00:00:00 2001 From: lempinen Date: Tue, 7 Sep 2010 12:55:32 +0000 Subject: [PATCH] Method and tolerance -settings for models, movable value view columns git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17804 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/modelica/ModelicaManager.java | 3 +- .../ui/properties/ConfigurationTab.java | 58 ++++++++++++++++++ .../ResourceSelectionProcessor.java | 16 ++--- .../ComboStringPropertyModifier.java | 59 +++++++++++++++++++ .../simantics/sysdyn/ui/values/ValueView.java | 1 + .../simantics/sysdyn/manager/SysdynModel.java | 5 +- .../sysdyn/simulation/SimulationJob.java | 2 +- 7 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/ComboStringPropertyModifier.java diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 11966b32..478b81d5 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -109,8 +109,7 @@ public class ModelicaManager { s.print("buildModel("+modelName+ ",startTime="+inits.get("start value")+ ",stopTime="+inits.get("stop value")+ -// ",numberOfIntervals="+inits.get("step value")+ - ",method=\"euler\"" + ",method="+inits.get("method") ); if(inits.containsKey("tolerance")) { s.print(",tolerance="+inits.get("tolerance")); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java index 1493b48c..49d09cec 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -1,5 +1,8 @@ package org.simantics.sysdyn.ui.properties; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -10,11 +13,18 @@ import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.swt.PropertyTabContributorImpl; import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory; import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier; +import org.simantics.browsing.ui.swt.widgets.TrackedCombo; import org.simantics.browsing.ui.swt.widgets.TrackedText; +import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl; import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.ui.properties.widgets.factories.ComboStringPropertyModifier; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory; import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier; @@ -72,6 +82,54 @@ public class ConfigurationTab extends PropertyTabContributorImpl { outputInterval.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasOutputInterval)); outputInterval.setInputValidator(new DoubleValidator()); GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(outputInterval.getWidget()); + + label = new Label(composite, SWT.NONE); + label.setText("Method"); + + TrackedCombo method = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY); + method.setItemFactory(new ReadFactoryImpl>() { + + @Override + public Map perform(ReadGraph graph, final Resource input) throws DatabaseException { + + Map map = new HashMap(); + map.put("euler", "euler"); + map.put("rungekutta", "rungekutta"); + map.put("dassl", "dassl"); + map.put("dassl2", "dassl2"); + map.put("inline-euler", "inline-euler"); + map.put("inline-rungekutta", "inline-rungekutta"); + return map; + } + }); + + method.setSelectionFactory(new ReadFactoryImpl() { + + @Override + public String perform(ReadGraph graph, final Resource input) throws DatabaseException { + return graph.getRelatedValue(input, SysdynResource.getInstance(graph).HasSolver); + } + }); + + method.addModifyListener(new ComboStringPropertyModifier() { + + @Override + public void applyText(WriteGraph graph, Resource input, String text) + throws DatabaseException { + graph.claimLiteral(input, SysdynResource.getInstance(graph).HasSolver, text); + } + }); + + label = new Label(composite, SWT.NONE); + label.setText("Tolerance"); + + TrackedText tolerance = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT); + tolerance.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.HasTolerance)); + tolerance.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.HasTolerance)); + tolerance.setInputValidator(new DoubleValidator()); + GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(tolerance.getWidget()); + + } private class DoubleValidator implements IInputValidator { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 31acfd11..14af26b7 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -11,7 +11,6 @@ import org.simantics.db.Resource; import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; import org.simantics.db.exception.ServiceException; import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.SysdynResource; @@ -29,7 +28,6 @@ public class ResourceSelectionProcessor implements SelectionProcessor tabs = new ArrayList(); if (backend.isInstanceOf(r, dr.Element)) { Resource component = backend.getPossibleObject(r, mr.ElementToComponent); @@ -69,19 +67,15 @@ public class ResourceSelectionProcessor implements SelectionProcessor implements TextModifyListener, Widget { + + private ISessionContext context; + private Object lastInput = null; + + final private Class clazz; + + public ComboStringPropertyModifier() { + clazz = ReflectionUtils.getSingleParameterType(getClass()); + } + + @Override + public void setInput(ISessionContext context, Object input) { + this.context = context; + lastInput = input; + } + + @Override + public void modifyText(TrackedModifyEvent e) { + Combo text = (Combo)e.getWidget(); + final String textValue = text.getText(); + final Object input = lastInput; + + try { + context.getSession().syncRequest(new WriteRequest() { + + @SuppressWarnings("unchecked") + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + T single = (T) ISelectionUtils.filterSingleSelection((ISelection)input, clazz); + applyText(graph, single, textValue); + + } + + }); + } catch (DatabaseException e1) { + e1.printStackTrace(); + } + + } + + abstract public void applyText(WriteGraph graph, T input, String text) throws DatabaseException; + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java index 05d48884..bebac33f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/values/ValueView.java @@ -160,6 +160,7 @@ public class ValueView extends ViewPart { TableColumn column = new TableColumn (table, SWT.NONE); column.setText (titles [i]); column.addListener(SWT.Selection, sortListener); + column.setMoveable(true); } table.setSortColumn(table.getColumn(0)); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java index f62dfee6..ec01a1c6 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java @@ -187,8 +187,8 @@ public class SysdynModel implements IMappingListener, IModel { } else { inits.put("step value", "" + (stopTime - startTime) / 500); } - if(model.getSolver() != null) - inits.put("solver", model.getSolver()); + String method = "\"" + model.getSolver() + "\""; + inits.put("method", method); if(model.getTolerance() != null) inits.put("tolerance", model.getTolerance().toString()); @@ -214,6 +214,7 @@ public class SysdynModel implements IMappingListener, IModel { previousImportantInits.clear(); previousImportantInits.put("start value", startTime.toString()); previousImportantInits.put("stop value", stopTime.toString()); + previousImportantInits.put("method", method); } catch (ModelicaException e) { monitor.showConsole(); canceled = true; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java index 8f8a4fb7..f13e32af 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java @@ -103,7 +103,7 @@ public class SimulationJob extends Job { MessageConsoleStream out = this.console.newMessageStream(); if(message.length() > 1) out.println("[" + time +"] " + message); - if(message.contains("Error:")) + if(message.contains("Error")) showConsole(); } -- 2.47.1