Previously only duration-based simulation stepping mode was available.
These changes add another mode: simulate until an end time.
gitlab #292
APROS-15393
Change-Id: Ia08bbd04abb40a2718c63781a8318a40d616b711
<elements xsi:type="commands:Handler" xmi:id="__O4KgKMJEeW8eee008tTJw" elementId="org.simantics.simulation.ui.handler.run" contributionURI="bundleclass://org.simantics.simulation.ui/org.simantics.simulation.ui.handlers.e4.Run" command="_38VJ8KMJEeW8eee008tTJw"/>
<elements xsi:type="commands:Handler" xmi:id="_TDgKkKMVEeW8eee008tTJw" elementId="org.simantics.simulation.ui.handler.step" contributionURI="bundleclass://org.simantics.simulation.ui/org.simantics.simulation.ui.handlers.e4.Step" command="_NxXikKMVEeW8eee008tTJw"/>
<elements xsi:type="commands:Handler" xmi:id="__eyi4KMWEeW8eee008tTJw" elementId="org.simantics.simulation.ui.handler.setduration" contributionURI="bundleclass://org.simantics.simulation.ui/org.simantics.simulation.ui.handlers.e4.SetDuration" command="_PhrCkKMVEeW8eee008tTJw"/>
+ <elements xsi:type="commands:Handler" xmi:id="_EnmMQGtCEemEZc07DWbcZA" elementId="org.simantics.simulation.ui.handler.setendtime" contributionURI="bundleclass://org.simantics.simulation.ui/org.simantics.simulation.ui.handlers.e4.SetEndTime" command="_-IPjMGtBEemEZc07DWbcZA"/>
<elements xsi:type="commands:Handler" xmi:id="_uxvLIKPkEeW8eee008tTJw" elementId="org.simantics.simulation.ui.handler.reload" contributionURI="bundleclass://org.simantics.simulation.ui/org.simantics.simulation.ui.handlers.e4.Reload" command="_r2lBkKPkEeW8eee008tTJw"/>
<elements xsi:type="commands:Handler" xmi:id="_l75g8KPmEeW8eee008tTJw" elementId="org.simantics.simulation.ui.handler.savestate" contributionURI="bundleclass://org.simantics.simulation.ui/org.simantics.simulation.ui.handlers.e4.SaveState" command="_kjF68KPmEeW8eee008tTJw"/>
</fragments>
<elements xsi:type="commands:Command" xmi:id="_38VJ8KMJEeW8eee008tTJw" elementId="org.simantics.simulation.ui.command.run" commandName="Run Simulation" description="Runs active simulator" category="_mEzHsKMJEeW8eee008tTJw"/>
<elements xsi:type="commands:Command" xmi:id="_NxXikKMVEeW8eee008tTJw" elementId="org.simantics.simulation.ui.command.step" commandName="Step" category="_mEzHsKMJEeW8eee008tTJw"/>
<elements xsi:type="commands:Command" xmi:id="_PhrCkKMVEeW8eee008tTJw" elementId="org.simantics.simulation.ui.command.setduration" commandName="Set Duration" category="_mEzHsKMJEeW8eee008tTJw"/>
+ <elements xsi:type="commands:Command" xmi:id="_-IPjMGtBEemEZc07DWbcZA" elementId="org.simantics.simulation.ui.command.setendtime" commandName="Set End Time" category="_mEzHsKMJEeW8eee008tTJw"/>
<elements xsi:type="commands:Command" xmi:id="_r2lBkKPkEeW8eee008tTJw" elementId="org.simantics.simulation.ui.command.reload" commandName="Reload"/>
<elements xsi:type="commands:Command" xmi:id="_kjF68KPmEeW8eee008tTJw" elementId="org.simantics.simulation.ui.command.savestate" commandName="Save State"/>
</fragments>
categoryId="org.simantics.simulation.ui.category"
id="org.simantics.simulation.ui.dispose">
</command>
- <command
- defaultHandler="org.simantics.simulation.ui.handlers.SetDuration"
- name="Set Duration"
- categoryId="org.simantics.simulation.ui.category"
- id="org.simantics.simulation.ui.setDuration">
- </command>
<command
defaultHandler="org.simantics.simulation.ui.handlers.SaveState"
name="Save State"
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
- * in Industry THTH ry.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * VTT Technical Research Centre of Finland - initial API and implementation
- *******************************************************************************/
-package org.simantics.simulation.ui.handlers;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.commands.ICommandService;
-import org.osgi.service.prefs.BackingStoreException;
-import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
-import org.simantics.simulation.ui.preferences.SimulationPreferences;
-import org.simantics.utils.ui.ExceptionUtils;
-import org.simantics.utils.ui.validators.DoubleValidator;
-
-public class SetDuration extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
-
- InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Set Simulation Step Duration", "Simulation step duration in seconds", "" + prefs.stepDuration, new DoubleValidator());
- if (dialog.open() == InputDialog.OK) {
- final double duration = Double.parseDouble(dialog.getValue());
- try {
- SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
- } catch (BackingStoreException e) {
- ExceptionUtils.logAndShowError(e);
- }
-
- // Update tool-tip for Step command
- ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
- Command command = service.getCommand("org.simantics.simulation.ui.step");
- service.refreshElements(command.getId(), null);
-
-// IExperimentManager manager = SimanticsUI.getProject2().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
-// IExperiment experiment = manager.getActiveExperiment();
-// if (experiment instanceof IDynamicExperiment)
-// ((IDynamicExperiment) experiment).simulateDuration(duration);
- }
-
- return null;
- }
-
-}
*******************************************************************************/
package org.simantics.simulation.ui.handlers.e4;
+import javax.inject.Inject;
+
import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
-import org.eclipse.e4.ui.internal.workbench.E4Workbench;
+import org.eclipse.e4.ui.di.UIEventTopic;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.ui.PlatformUI;
import org.osgi.service.prefs.BackingStoreException;
import org.simantics.simulation.SimulationEvents;
import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
import org.simantics.simulation.ui.preferences.SimulationPreferences;
+import org.simantics.simulation.ui.preferences.SimulationPreferences.StepMode;
import org.simantics.utils.ui.ExceptionUtils;
-import org.simantics.utils.ui.validators.DoubleValidator;
public class SetDuration {
+ private static final String SET_DURATION_ITEM_ID = "org.simantics.simulation.ui.handledmenuitem.setduration";
+
+ @Inject
+ private EModelService modelService;
+
+ @Inject
private IEventBroker eventBroker;
-
- public SetDuration() {
- eventBroker = E4Workbench.getServiceContext().get(IEventBroker.class);
- }
-
+
@Execute
- public void execute() {
+ public void execute(MMenuItem item) {
+ // This is a radio menu item, execute is called also when it is deselected
+ if (!item.isSelected())
+ return;
+
SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
- InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Set Simulation Step Duration", "Simulation step duration in seconds", "" + prefs.stepDuration, new DoubleValidator());
+ TimeInputDialog dialog = new TimeInputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Set Simulation Step Duration", "simulation step duration", "" + prefs.stepDuration);
if (dialog.open() == InputDialog.OK) {
final double duration = Double.parseDouble(dialog.getValue());
try {
- SimulationPreferenceUtil.flushPrefs(new SimulationPreferences(duration));
+ SimulationPreferenceUtil.flushPrefs(prefs.withDuration(duration).withStepMode(StepMode.DURATION));
eventBroker.post(SimulationEvents.TOPIC_STEP_DURATION, duration);
+ eventBroker.post(SimulationEvents.TOPIC_STEP_MODE, StepMode.DURATION);
} catch (BackingStoreException e) {
ExceptionUtils.logAndShowError(e);
}
+ } else {
+ eventBroker.post(SimulationEvents.TOPIC_STEP_MODE, prefs.stepMode);
}
}
+ @Inject
+ @Optional
+ public void updateElement(@Optional @UIEventTopic(SimulationEvents.TOPIC_STEP_MODE) StepMode mode, MApplication application) {
+ WorkbenchUtil.setMenuItemSelected(modelService, application, Step.HANDLED_ITEM_ID, SET_DURATION_ITEM_ID, mode == StepMode.DURATION);
+ }
+
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.simulation.ui.handlers.e4;
+
+import java.text.ParseException;
+
+import javax.inject.Inject;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.services.events.IEventBroker;
+import org.eclipse.e4.ui.di.UIEventTopic;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.ui.PlatformUI;
+import org.osgi.service.prefs.BackingStoreException;
+import org.simantics.simulation.SimulationEvents;
+import org.simantics.simulation.experiment.SimulationTimeUtil;
+import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
+import org.simantics.simulation.ui.preferences.SimulationPreferences;
+import org.simantics.simulation.ui.preferences.SimulationPreferences.StepMode;
+import org.simantics.utils.ui.ExceptionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.39.0
+ */
+public class SetEndTime {
+
+ private static final String SET_END_TIME_ITEM_ID = "org.simantics.simulation.ui.handledmenuitem.setendtime";
+
+ @Inject
+ private EModelService modelService;
+
+ @Inject
+ private IEventBroker eventBroker;
+
+ @Execute
+ public void execute(MMenuItem item) {
+ // This is a radio menu item, execute is called also when it is deselected
+ if (!item.isSelected())
+ return;
+
+ SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
+
+ InputDialog dialog = new TimeInputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Set Simulation Step End Time", "simulation step end time", "" + prefs.stepEndTime);
+ if (dialog.open() == InputDialog.OK) {
+ try {
+ double endTime = (double) SimulationTimeUtil.getTimeFormat().parseObject(dialog.getValue());
+ SimulationPreferenceUtil.flushPrefs(prefs.withEndTime(endTime).withStepMode(StepMode.END_TIME));
+ eventBroker.post(SimulationEvents.TOPIC_STEP_END_TIME, endTime);
+ eventBroker.post(SimulationEvents.TOPIC_STEP_MODE, StepMode.END_TIME);
+ } catch (BackingStoreException e) {
+ ExceptionUtils.logAndShowError(e);
+ } catch (ParseException e) {
+ ExceptionUtils.logAndShowError(e);
+ }
+ } else {
+ eventBroker.post(SimulationEvents.TOPIC_STEP_MODE, prefs.stepMode);
+ }
+ }
+
+ @Inject
+ @Optional
+ public void updateElement(@Optional @UIEventTopic(SimulationEvents.TOPIC_STEP_MODE) StepMode mode, MApplication application) {
+ WorkbenchUtil.setMenuItemSelected(modelService, application, Step.HANDLED_ITEM_ID, SET_END_TIME_ITEM_ID, mode == StepMode.END_TIME);
+ }
+
+}
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.MUILabel;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.osgi.util.NLS;
import org.simantics.Simantics;
import org.simantics.simulation.SimulationEvents;
import org.simantics.simulation.experiment.ExperimentUtil;
import org.simantics.simulation.experiment.IExperiment;
+import org.simantics.simulation.experiment.SimulationTimeUtil;
import org.simantics.simulation.project.IExperimentManager;
import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
import org.simantics.simulation.ui.preferences.SimulationPreferences;
public class Step {
- private static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step";
+ static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step";
@Inject
EModelService modelService;
-
+
@PostConstruct
public void updateToolTip(MApplication application) {
MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);
if (handledItem != null) {
- SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
- handledItem.setTooltip("Step " + prefs.stepDuration + "s");
+ updateItem(handledItem);
}
}
-
+
@CanExecute
public boolean canExecute() {
IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
return false;
return true;
}
-
+
@Execute
public void execute() {
SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
- ExperimentUtil.step(prefs.stepDuration);
+ switch (prefs.stepMode) {
+ case DURATION:
+ ExperimentUtil.step(prefs.stepDuration);
+ break;
+ case END_TIME:
+ ExperimentUtil.stepUntil(prefs.stepEndTime);
+ break;
+ }
}
@Inject
@Optional
- public void updateElement(@UIEventTopic(SimulationEvents.TOPIC_STEP_DURATION) double duration, MApplication application) {
+ public void updateElement(@Optional @UIEventTopic(SimulationEvents.TOPIC_STEP_CHANGE) Object changed, MApplication application) {
MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);
if (handledItem != null) {
- handledItem.setTooltip("Step " + duration + "s");
+ updateItem(handledItem);
+ }
+ }
+
+ private static void updateItem(MUILabel item) {
+ SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
+ switch (prefs.stepMode) {
+ case DURATION:
+ item.setTooltip(
+ NLS.bind("Step {0} s ({1})",
+ SimulationTimeUtil.formatSeconds(prefs.stepDuration),
+ SimulationTimeUtil.formatHMSS(prefs.stepDuration)));
+ break;
+ case END_TIME:
+ item.setTooltip(
+ NLS.bind("Step Until Simulation Time Reaches {0} s ({1})",
+ SimulationTimeUtil.formatSeconds(prefs.stepEndTime),
+ SimulationTimeUtil.formatHMSS(prefs.stepEndTime)));
+ break;
}
}
--- /dev/null
+package org.simantics.simulation.ui.handlers.e4;
+
+import java.text.ParseException;
+
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.simulation.experiment.SimulationTimeUtil;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class TimeInputDialog extends InputDialog {
+
+ private Text statusText;
+
+ public TimeInputDialog(Shell parentShell, String dialogTitle, String topic, String initialValue) {
+ super(parentShell, dialogTitle, message(topic), initialValue, new TimeValidator());
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+
+ statusText = new Text(composite, SWT.READ_ONLY | SWT.WRAP);
+ statusText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.HORIZONTAL_ALIGN_FILL));
+
+ return composite;
+ }
+
+ @Override
+ protected void validateInput() {
+ super.validateInput();
+
+ try {
+ double t = (double) SimulationTimeUtil.getTimeFormat().parseObject(getText().getText());
+ statusText.setText(statusMessage(t));
+ } catch (ParseException e) {
+ statusText.setText("");
+ }
+ }
+
+ private static String message(String topic) {
+ return NLS.bind("Give {0} in seconds or timestamp format ([Yy] [Dd] HH:mm:ss.ddd)", topic);
+ }
+
+ private static String statusMessage(double time) {
+ return NLS.bind(
+ "Specified time is {0} s ({1})",
+ SimulationTimeUtil.formatSeconds(time),
+ SimulationTimeUtil.formatHMSS(time));
+ }
+
+}
--- /dev/null
+package org.simantics.simulation.ui.handlers.e4;
+
+import java.text.ParseException;
+
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.osgi.util.NLS;
+import org.simantics.simulation.experiment.SimulationTimeUtil;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.39.0
+ */
+class TimeValidator implements IInputValidator {
+
+ public String isValid(String s) {
+ try {
+ SimulationTimeUtil.getTimeFormat().parseObject(s);
+ return null;
+ } catch (ParseException e) {
+ return NLS.bind("\"{0}\" is not a valid timestamp.", s);
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2019 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.simulation.ui.handlers.e4;
+
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.menu.MItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
+import org.eclipse.e4.ui.model.application.ui.menu.MToolItem;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.39.0
+ */
+class WorkbenchUtil {
+
+ public static boolean setMenuItemSelected(EModelService modelService, MApplication application, String toolItemId, String menuItemId, boolean selected) {
+ MToolItem toolItem = (MToolItem) modelService.find(toolItemId, application);
+ if (toolItem != null) {
+ MMenu menu = toolItem.getMenu();
+ if (menu != null) {
+ MItem menuItem = (MItem) modelService.find(menuItemId, menu);
+ if (menuItem != null) {
+ menuItem.setSelected(selected);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
import org.simantics.simulation.ui.Activator;
+import org.simantics.simulation.ui.preferences.SimulationPreferences.StepMode;
/**
public static SimulationPreferences getPrefs(IScopeContext context) {
IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);
double stepDuration = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, SimulationPreferences.DEFAULT_SIMULATION_STEP_DURATION);
+ double stepEndTime = node.getDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, SimulationPreferences.DEFAULT_SIMULATION_STEP_END_TIME);
+ int stepMode = node.getInt(SimulationPreferences.P_SIMULATION_STEP_MODE, SimulationPreferences.DEFAULT_SIMULATION_STEP_MODE.ordinal());
- return new SimulationPreferences(node, stepDuration);
+ return new SimulationPreferences(node, stepDuration, stepEndTime, StepMode.fromInt(stepMode));
}
/**
private static IEclipsePreferences _setPrefs(IScopeContext context, SimulationPreferences prefs) {
IEclipsePreferences node = context.getNode(Activator.PLUGIN_ID);
node.putDouble(SimulationPreferences.P_SIMULATION_STEP_DURATION, prefs.stepDuration);
+ node.putDouble(SimulationPreferences.P_SIMULATION_STEP_END_TIME, prefs.stepEndTime);
+ node.putInt(SimulationPreferences.P_SIMULATION_STEP_MODE, prefs.stepMode.ordinal());
return node;
}
/*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2019 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
*
* Contributors:
* VTT Technical Research Centre of Finland - initial API and implementation
+ * Semantum Oy - added step end time and mode
*******************************************************************************/
package org.simantics.simulation.ui.preferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.simantics.utils.format.TimeFormat;
/**
* Constant definitions for plug-in preferences
public final class SimulationPreferences {
public static final String P_SIMULATION_STEP_DURATION = "simulation.step.duration";
+ public static final String P_SIMULATION_STEP_END_TIME = "simulation.step.endTime";
+ public static final String P_SIMULATION_STEP_MODE = "simulation.step.mode";
+
+ public static enum StepMode {
+ DURATION,
+ END_TIME;
+
+ public static StepMode fromInt(int stepMode) {
+ switch (stepMode) {
+ case 1: return END_TIME;
+ default: return DURATION;
+ }
+ }
+ }
public static final double DEFAULT_SIMULATION_STEP_DURATION = 0.1;
+ public static final double DEFAULT_SIMULATION_STEP_END_TIME = 0;
+ public static final StepMode DEFAULT_SIMULATION_STEP_MODE = StepMode.DURATION;
public static final SimulationPreferences DEFAULT_PREFS
- = new SimulationPreferences(null, DEFAULT_SIMULATION_STEP_DURATION);
+ = new SimulationPreferences(null,
+ DEFAULT_SIMULATION_STEP_DURATION,
+ DEFAULT_SIMULATION_STEP_END_TIME,
+ DEFAULT_SIMULATION_STEP_MODE);
public final IEclipsePreferences prefs;
public final double stepDuration;
+ public final double stepEndTime;
+ public final StepMode stepMode;
- public SimulationPreferences(double stepDuration) {
- this(null, stepDuration);
+ public SimulationPreferences(double stepDuration, double stepEndTime, StepMode stepMode) {
+ this(null, stepDuration, stepEndTime, stepMode);
}
- public SimulationPreferences(IEclipsePreferences prefs, double stepDuration) {
+ public SimulationPreferences(IEclipsePreferences prefs, double stepDuration, double stepEndTime, StepMode stepMode) {
this.prefs = prefs;
this.stepDuration = stepDuration;
+ this.stepEndTime = stepEndTime;
+ this.stepMode = stepMode;
+ }
+
+ public SimulationPreferences withDuration(double duration) {
+ return new SimulationPreferences(duration, stepEndTime, stepMode);
+ }
+
+ public SimulationPreferences withEndTime(double endTime) {
+ return new SimulationPreferences(stepDuration, endTime, stepMode);
+ }
+
+ public SimulationPreferences withStepMode(StepMode mode) {
+ return new SimulationPreferences(stepDuration, stepEndTime, mode);
}
@Override
public String toString() {
- return getClass().getSimpleName() + "[step duration=" + stepDuration + "]";
+ return getClass().getSimpleName()
+ + "[step duration=" + stepDuration
+ + ", step end time=" + stepEndTime
+ + ", step mode=" + stepMode
+ + "]";
}
}
public static final String TOPIC_STATE_CHANGE = "org/simantics/simulation/state/*";
public static final String TOPIC_STATE_RUNNING = "org/simantics/simulation/state/running";
public static final String TOPIC_STATE_STOPPED = "org/simantics/simulation/state/stopped";
+ public static final String TOPIC_STEP_CHANGE = "org/simantics/simulation/step/*";
public static final String TOPIC_STEP_DURATION = "org/simantics/simulation/step/duration";
-}
+ public static final String TOPIC_STEP_END_TIME = "org/simantics/simulation/step/endTime";
+ public static final String TOPIC_STEP_MODE = "org/simantics/simulation/step/mode";
+
+}
\ No newline at end of file
((IDynamicExperiment)experiment).simulateDuration(duration);
}
+ public static boolean canStepUntil(double endTime) {
+ IExperimentManager manager =
+ Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
+ IExperiment experiment = manager.getActiveExperiment();
+ if (experiment instanceof IDynamicExperiment) {
+ IDynamicExperiment exp = (IDynamicExperiment) experiment;
+ double currentTime = exp.getSimulationTime();
+ return currentTime < endTime;
+ }
+ return false;
+ }
+
+ public static void stepUntil(double endTime) {
+ IExperimentManager manager =
+ Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
+ IExperiment experiment = manager.getActiveExperiment();
+ if (experiment instanceof IDynamicExperiment) {
+ IDynamicExperiment exp = (IDynamicExperiment) experiment;
+ double currentTime = exp.getSimulationTime();
+ if (currentTime < endTime) {
+ exp.simulateDuration(endTime - currentTime);
+ }
+ }
+ }
+
public static void simulate(boolean enabled) {
IExperimentManager manager =
Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
*/
public void rewindTo(double time);
+ /**
+ * @return current simulation time
+ */
+ double getSimulationTime();
+
/**
* Ensure that the current state of the experiment at the time of invocation
* is stored so that it can be returned to during a later session.
return result;
}
+ public static TimeFormat getTimeFormat() {
+ return timeFormat;
+ }
+
}