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
1 /*******************************************************************************
2  * Copyright (c) 2007, 2019 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *     Semantum Oy - added step end time and mode
12  *******************************************************************************/
13 package org.simantics.simulation.ui.preferences;
14
15 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
16 import org.simantics.utils.format.TimeFormat;
17
18 /**
19  * Constant definitions for plug-in preferences
20  */
21 public final class SimulationPreferences {
22
23     public static final String                P_SIMULATION_STEP_DURATION       = "simulation.step.duration";
24     public static final String                P_SIMULATION_STEP_END_TIME       = "simulation.step.endTime";
25     public static final String                P_SIMULATION_STEP_MODE           = "simulation.step.mode";
26
27     public static enum StepMode {
28         DURATION,
29         END_TIME;
30
31         public static StepMode fromInt(int stepMode) {
32             switch (stepMode) {
33             case 1: return END_TIME;
34             default: return DURATION;
35             }
36         }
37     }
38
39     public static final double                DEFAULT_SIMULATION_STEP_DURATION = 0.1;
40     public static final double                DEFAULT_SIMULATION_STEP_END_TIME = 0;
41     public static final StepMode              DEFAULT_SIMULATION_STEP_MODE     = StepMode.DURATION;
42
43     public static final SimulationPreferences DEFAULT_PREFS
44         = new SimulationPreferences(null,
45                 DEFAULT_SIMULATION_STEP_DURATION,
46                 DEFAULT_SIMULATION_STEP_END_TIME,
47                 DEFAULT_SIMULATION_STEP_MODE);
48
49     public final IEclipsePreferences          prefs;
50     public final double                       stepDuration;
51     public final double                       stepEndTime;
52     public final StepMode                     stepMode;
53
54     public SimulationPreferences(double stepDuration, double stepEndTime, StepMode stepMode) {
55         this(null, stepDuration, stepEndTime, stepMode);
56     }
57
58     public SimulationPreferences(IEclipsePreferences prefs, double stepDuration, double stepEndTime, StepMode stepMode) {
59         this.prefs = prefs;
60         this.stepDuration = stepDuration;
61         this.stepEndTime = stepEndTime;
62         this.stepMode = stepMode;
63     }
64
65     public SimulationPreferences withDuration(double duration) {
66         return new SimulationPreferences(duration, stepEndTime, stepMode);
67     }
68
69     public SimulationPreferences withEndTime(double endTime) {
70         return new SimulationPreferences(stepDuration, endTime, stepMode);
71     }
72
73     public SimulationPreferences withStepMode(StepMode mode) {
74         return new SimulationPreferences(stepDuration, stepEndTime, mode);
75     }
76
77     @Override
78     public String toString() {
79         return getClass().getSimpleName()
80                 + "[step duration=" + stepDuration
81                 + ", step end time=" + stepEndTime
82                 + ", step mode=" + stepMode
83                 + "]";
84     }
85
86 }