]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/preferences/SimulationPreferences.java
Added Set End Time command and handler as an alternate stepping mode
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / preferences / SimulationPreferences.java
index 862f51d8d8d1f6711bff193ae15006b9d2dd3dab..b3fe9506d1f4bc49e79f9bb77d657407d20ecc29 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * 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
@@ -8,10 +8,12 @@
  *
  * 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
@@ -19,27 +21,66 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 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
+                + "]";
     }
 
 }