Commit 166cda20 authored by Christopher Lees's avatar Christopher Lees

New: Allow a delay to be set for each power / brake notch

parent c74b94a1
......@@ -298,8 +298,22 @@ A non-negative floating point number representing the time in <b>seconds</b> (s)
<tr><td><font color="#808080">
</font></td></tr></table>
A non-negative floating point number representing the time in <b>seconds</b> (s) before decreasing the brake notch takes effect. Applies only to trains that have notched brakes. The default value is 0.<br /><br /><table>
A non-negative floating point number representing the time in <b>seconds</b> (s) before decreasing the brake notch takes effect. Applies only to trains that have notched brakes. The default value is 0.<br />
<br /><table><tr style="height: 4px;"><td /></tr></table>
<table style="border:1px dashed;margin-left:0pt;margin-right:20pt;">
<tr><td bgcolor="#FFE080" style="border:2px; border-style:ridge;"><font color="#404040">
<b></b> Setting a delay for each notch
</font></td></tr><tr><td bgcolor="#FFFFFF">
From <b>V1.5.3.4</b> onwards, a comma separated list may be used for any of the above parameters, supplying the delay values from Notch 0 upwards. If this list is <em>shorter</em> than the total number of notches, the last value will be used for all subsequent notches.
</td></tr></table>
<table><tr style="height: 4px;"><td /></tr></table>
<table>
<tr>
<td width="16" valign="top" /><td>
<font size="-1"><em>Example of a Delay section:</em></font>
</td></tr><tr>
......
using System;
using System.Linq;
using System.Windows.Forms;
using OpenBveApi.Math;
......@@ -36,7 +37,8 @@ namespace OpenBve {
}
}
TrainDatFormats currentFormat = TrainDatFormats.openBVE;
const int currentVersion = 1530;
const int currentVersion = 1534;
int myVersion = -1;
for (int i = 0; i < Lines.Length; i++) {
if (Lines[i].Length > 0) {
string t = Lines[i].ToLowerInvariant();
......@@ -61,11 +63,10 @@ namespace OpenBve {
if (t.ToLowerInvariant().StartsWith("openbve"))
{
string tt = t.Substring(7, t.Length - 7);
int v;
if (NumberFormats.TryParseIntVb6(tt, out v))
if (NumberFormats.TryParseIntVb6(tt, out myVersion))
{
currentFormat = TrainDatFormats.openBVE;
if (v > currentVersion)
if (myVersion > currentVersion)
{
Interface.AddMessage(Interface.MessageType.Warning, false, "The train.dat " + FileName + " was created with a newer version of openBVE. Please check for an update.");
}
......@@ -247,17 +248,45 @@ namespace OpenBve {
double a; if (NumberFormats.TryParseDoubleVb6(Lines[i], out a)) {
switch (n) {
case 0:
Train.Specs.DelayPowerUp = new[] { a };
if (currentFormat == TrainDatFormats.openBVE && myVersion >= 1534)
{
Train.Specs.DelayPowerUp = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
}
else
{
Train.Specs.DelayPowerUp = new[] { a };
}
break;
case 1:
Train.Specs.DelayPowerDown = new[] { a };
break;
if (currentFormat == TrainDatFormats.openBVE && myVersion >= 1534)
{
Train.Specs.DelayPowerDown = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
}
else
{
Train.Specs.DelayPowerDown = new[] { a };
}
break;
case 2:
Train.Specs.DelayBrakeUp = new[] { a };
break;
if (currentFormat == TrainDatFormats.openBVE && myVersion >= 1534)
{
Train.Specs.DelayBrakeUp = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
}
else
{
Train.Specs.DelayBrakeUp = new[] { a };
}
break;
case 3:
Train.Specs.DelayBrakeDown = new[] { a };
break;
if (currentFormat == TrainDatFormats.openBVE && myVersion >= 1534)
{
Train.Specs.DelayBrakeDown = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
}
else
{
Train.Specs.DelayBrakeDown = new[] { a };
}
break;
}
} i++; n++;
} i--; break;
......
......@@ -3,5 +3,5 @@
[assembly: AssemblyTitle("TrainEditor")]
[assembly: AssemblyProduct("TrainEditor")]
[assembly: AssemblyCopyright("The openBVE Project")]
[assembly: AssemblyVersion("1.2.12.0")]
[assembly: AssemblyFileVersion("1.2.12.0")]
\ No newline at end of file
[assembly: AssemblyVersion("1.5.4.0")]
[assembly: AssemblyFileVersion("1.5.4.0")]
......@@ -19,7 +19,7 @@ namespace TrainEditor.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
......
......@@ -12,7 +12,7 @@ namespace TrainEditor.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
......
using System;
using System.Linq;
using System.Windows.Forms;
namespace TrainEditor {
......@@ -48,15 +49,15 @@ namespace TrainEditor {
// delay
/// <summary>The Delay section of the train.dat. All members are stored in the unit as specified by the train.dat documentation.</summary>
internal class Delay {
internal double DelayPowerUp;
internal double DelayPowerDown;
internal double DelayBrakeUp;
internal double DelayBrakeDown;
internal double[] DelayPowerUp;
internal double[] DelayPowerDown;
internal double[] DelayBrakeUp;
internal double[] DelayBrakeDown;
internal Delay() {
this.DelayPowerUp = 0.0;
this.DelayPowerDown = 0.0;
this.DelayBrakeUp = 0.0;
this.DelayBrakeDown = 0.0;
this.DelayPowerUp = new double[] { 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0 };
this.DelayPowerDown = new double[] { 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0 };
this.DelayBrakeUp = new double[] { 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0 };
this.DelayBrakeDown = new double[] { 0.0, 0.0, 0.0 , 0.0, 0.0, 0.0, 0.0, 0.0 };
}
}
......@@ -301,7 +302,7 @@ namespace TrainEditor {
}
}
const int currentVersion = 1530;
const int currentVersion = 1534;
// load
/// <summary>Loads a file into an instance of the Train class.</summary>
......@@ -439,22 +440,42 @@ namespace TrainEditor {
} i--; break;
case "#delay":
i++; while (i < Lines.Length && !Lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase)) {
double a; if (double.TryParse(Lines[i], System.Globalization.NumberStyles.Float, Culture, out a)) {
double a;
if (double.TryParse(Lines[i], System.Globalization.NumberStyles.Float, Culture, out a)) {
switch (n) {
case 0:
if(a >= 0.0) t.Delay.DelayPowerUp = a;
if(a >= 0.0) t.Delay.DelayPowerUp = new double[] { a };
break;
case 1:
if(a >= 0.0) t.Delay.DelayPowerDown = a;
if(a >= 0.0) t.Delay.DelayPowerDown = new double[] { a };
break;
case 2:
if(a >= 0.0) t.Delay.DelayBrakeUp = a;
if(a >= 0.0) t.Delay.DelayBrakeUp = new double[] { a };
break;
case 3:
if(a >= 0.0) t.Delay.DelayBrakeDown = a;
if(a >= 0.0) t.Delay.DelayBrakeDown = new double[] { a };
break;
}
} i++; n++;
}
else if (Lines[i].IndexOf(',') != -1)
{
switch (n)
{
case 0:
t.Delay.DelayPowerUp = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
break;
case 1:
t.Delay.DelayPowerDown = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
break;
case 2:
t.Delay.DelayBrakeUp = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
break;
case 3:
t.Delay.DelayBrakeDown = Lines[i].Split(',').Select(Convert.ToDouble).ToArray();
break;
}
}
i++; n++;
} i--; break;
case "#move":
i++; while (i < Lines.Length && !Lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase)) {
......@@ -699,6 +720,25 @@ namespace TrainEditor {
break;
}
}
if (t.Delay.DelayPowerUp.Length < t.Handle.PowerNotches)
{
int l = t.Delay.DelayPowerUp.Length;
Array.Resize(ref t.Delay.DelayPowerUp, t.Handle.PowerNotches);
for (int i = l + 1; i < t.Delay.DelayPowerUp.Length; i++)
{
t.Delay.DelayPowerUp[i] = 0;
}
}
if (t.Delay.DelayPowerDown.Length < t.Handle.PowerNotches)
{
int l = t.Delay.DelayPowerDown.Length;
Array.Resize(ref t.Delay.DelayPowerDown, t.Handle.PowerNotches);
for (int i = l + 1; i < t.Delay.DelayPowerDown.Length; i++)
{
t.Delay.DelayPowerDown[i] = 0;
}
}
if (t.Pressure.BrakePipeNormalPressure <= 0.0) {
if (t.Brake.BrakeType == Brake.BrakeTypes.AutomaticAirBrake) {
t.Pressure.BrakePipeNormalPressure = t.Pressure.BrakeCylinderEmergencyMaximumPressure + 0.75 * (t.Pressure.MainReservoirMinimumPressure - t.Pressure.BrakeCylinderEmergencyMaximumPressure);
......@@ -752,10 +792,10 @@ namespace TrainEditor {
b.AppendLine(t.Performance.CoefficientOfRollingResistance.ToString(Culture).PadRight(n, ' ') + "; CoefficientOfRollingResistance");
b.AppendLine(t.Performance.AerodynamicDragCoefficient.ToString(Culture).PadRight(n, ' ') + "; AerodynamicDragCoefficient");
b.AppendLine("#DELAY");
b.AppendLine(t.Delay.DelayPowerUp.ToString(Culture).PadRight(n, ' ') + "; DelayPowerUp");
b.AppendLine(t.Delay.DelayPowerDown.ToString(Culture).PadRight(n, ' ') + "; DelayPowerDown");
b.AppendLine(t.Delay.DelayBrakeUp.ToString(Culture).PadRight(n, ' ') + "; DelayBrakeUp");
b.AppendLine(t.Delay.DelayBrakeDown.ToString(Culture).PadRight(n, ' ') + "; DelayBrakeDown");
b.AppendLine(string.Join(",", t.Delay.DelayPowerUp.Select(d => d.ToString(Culture)).ToList()).PadRight(n, ' ') + "; DelayPowerUp");
b.AppendLine(string.Join(",", t.Delay.DelayPowerDown.Select(d => d.ToString(Culture)).ToList()).PadRight(n, ' ') + "; DelayPowerDown");
b.AppendLine(string.Join(",", t.Delay.DelayBrakeUp.Select(d => d.ToString(Culture)).ToList()).PadRight(n, ' ') + "; DelayBrakeUp");
b.AppendLine(string.Join(",", t.Delay.DelayBrakeDown.Select(d => d.ToString(Culture)).ToList()).PadRight(n, ' ') + "; DelayBrakeDown");
b.AppendLine("#MOVE");
b.AppendLine(t.Move.JerkPowerUp.ToString(Culture).PadRight(n, ' ') + "; JerkPowerUp");
b.AppendLine(t.Move.JerkPowerDown.ToString(Culture).PadRight(n, ' ') + "; JerkPowerDown");
......
......@@ -15,7 +15,7 @@
<NoStdLib>False</NoStdLib>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<ApplicationIcon>..\..\assets\icon.ico</ApplicationIcon>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
......@@ -36,6 +36,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -100,6 +101,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
This diff is collapsed.
......@@ -101,11 +101,7 @@ namespace TrainEditor {
textboxCoefficientOfStaticFriction.Text = Train.Performance.CoefficientOfStaticFriction.ToString(Culture);
textboxCoefficientOfRollingResistance.Text = Train.Performance.CoefficientOfRollingResistance.ToString(Culture);
textboxAerodynamicDragCoefficient.Text = Train.Performance.AerodynamicDragCoefficient.ToString(Culture);
// delay
textboxDelayPowerUp.Text = Train.Delay.DelayPowerUp.ToString(Culture);
textboxDelayPowerDown.Text = Train.Delay.DelayPowerDown.ToString(Culture);
textboxDelayBrakeUp.Text = Train.Delay.DelayBrakeUp.ToString(Culture);
textboxDelayBrakeDown.Text = Train.Delay.DelayBrakeDown.ToString(Culture);
// move
textboxJerkPowerUp.Text = Train.Move.JerkPowerUp.ToString(Culture);
textboxJerkPowerDown.Text = Train.Move.JerkPowerDown.ToString(Culture);
......@@ -125,8 +121,8 @@ namespace TrainEditor {
textboxBrakePipeNormalPressure.Text = Train.Pressure.BrakePipeNormalPressure.ToString(Culture);
// handle
comboboxHandleType.SelectedIndex = (int)Train.Handle.HandleType;
textboxPowerNotches.Text = Train.Handle.PowerNotches.ToString(Culture);
textboxBrakeNotches.Text = Train.Handle.BrakeNotches.ToString(Culture);
numericUpDownPowerNotches.Value = Train.Handle.PowerNotches;
numericUpDownBrakeNotches.Value = Train.Handle.BrakeNotches;
textboxPowerNotchReduceSteps.Text = Train.Handle.PowerNotchReduceSteps.ToString(Culture);
// cab
textboxX.Text = Train.Cab.X.ToString(Culture);
......@@ -166,12 +162,7 @@ namespace TrainEditor {
if (!SaveControlContent(textboxCoefficientOfStaticFriction, "CoefficientOfStaticFriction", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Performance.CoefficientOfStaticFriction)) return false;
if (!SaveControlContent(textboxCoefficientOfRollingResistance, "CoefficientOfRollingResistance", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Performance.CoefficientOfRollingResistance)) return false;
if (!SaveControlContent(textboxAerodynamicDragCoefficient, "AerodynamicDragCoefficient", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Performance.AerodynamicDragCoefficient)) return false;
// delay
if (!SaveControlContent(textboxDelayPowerUp, "DelayPowerUp", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Delay.DelayPowerUp)) return false;
if (!SaveControlContent(textboxDelayPowerDown, "DelayPowerDown", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Delay.DelayPowerDown)) return false;
if (!SaveControlContent(textboxDelayBrakeUp, "DelayBrakeUp", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Delay.DelayBrakeUp)) return false;
if (!SaveControlContent(textboxDelayBrakeDown, "DelayBrakeDown", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Delay.DelayBrakeDown)) return false;
// delay
// Jerk
if (!SaveControlContent(textboxJerkPowerUp, "JerkPowerUp", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Move.JerkPowerUp)) return false;
if (!SaveControlContent(textboxJerkPowerDown, "JerkPowerDown", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Move.JerkPowerDown)) return false;
if (!SaveControlContent(textboxJerkBrakeUp, "JerkBrakeUp", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Move.JerkBrakeUp)) return false;
......@@ -190,13 +181,12 @@ namespace TrainEditor {
if (!SaveControlContent(textboxBrakePipeNormalPressure, "BrakePipeNormalPressure", tabpagePropertiesOne, NumberRange.Positive, out Train.Pressure.BrakePipeNormalPressure)) return false;
// handle
Train.Handle.HandleType = (TrainDat.Handle.HandleTypes)comboboxHandleType.SelectedIndex;
if (!SaveControlContent(textboxPowerNotches, "PowerNotches", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Handle.PowerNotches)) return false;
if (!SaveControlContent(textboxBrakeNotches, "BrakeNotches", tabpagePropertiesOne, NumberRange.NonNegative, out Train.Handle.BrakeNotches)) return false;
Train.Handle.PowerNotches = (int)numericUpDownPowerNotches.Value;
Train.Handle.BrakeNotches = (int)numericUpDownBrakeNotches.Value;
if (Train.Handle.BrakeNotches == 0 & checkboxHoldBrake.Checked) {
MessageBox.Show("BrakeNotches must be at least 1 if HoldBrake is set.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
tabcontrolTabs.SelectedTab = tabpagePropertiesOne;
textboxBrakeNotches.SelectAll();
textboxBrakeNotches.Focus();
numericUpDownBrakeNotches.Focus();
return false;
}
Train.Handle.HandleBehaviour = (TrainDat.Handle.EbHandleBehaviour) comboBoxHandleBehaviour.SelectedIndex;
......@@ -1384,5 +1374,125 @@ namespace TrainEditor {
return 3.6 * a;
}
private void buttonSetDelayPowerUp_Click(object sender, EventArgs e)
{
this.setDelay(ref this.Train.Delay.DelayPowerUp, "DelayPowerUp");
}
private void buttonSetDelayPowerDown_Click(object sender, EventArgs e)
{
this.setDelay(ref this.Train.Delay.DelayPowerDown, "DelayPowerDown");
}
private void buttonSetDelayBrakeUp_Click(object sender, EventArgs e)
{
this.setDelay(ref this.Train.Delay.DelayBrakeUp, "DelayBrakeUp");
}
private void buttonSetDelayBrakeDown_Click(object sender, EventArgs e)
{
this.setDelay(ref this.Train.Delay.DelayBrakeDown, "DelayBrakeDown");
}
private void setDelay(ref double[] delayValues, string delayType)
{
using (Form formDelay = new Form())
{
formDelay.ShowIcon = false;
formDelay.FormBorderStyle = FormBorderStyle.FixedSingle;
formDelay.MinimizeBox = false;
formDelay.MaximizeBox = false;
formDelay.StartPosition = FormStartPosition.CenterParent;
formDelay.Text = delayType;
int currentPosition = 10;
for (int index = 0; index < delayValues.Length; ++index)
{
TextBox t = new TextBox
{
Location = new Point(20, currentPosition),
Text = delayValues[index].ToString()
};
formDelay.Controls.Add(t);
Label l = new Label
{
Location = new Point(140, currentPosition + 3),
Text = "Notch " + (object) index
};
formDelay.Controls.Add(l);
currentPosition += 25;
}
Button buttonOK = new Button
{
Text = "Save",
DialogResult = DialogResult.OK,
Location = new Point(30, currentPosition)
};
formDelay.Controls.Add(buttonOK);
Button buttonCancel = new Button
{
Text = "Cancel",
DialogResult = DialogResult.Cancel,
Location = new Point(110, currentPosition)
};
formDelay.Controls.Add(buttonCancel);
int height = currentPosition + 75;
formDelay.Size = new Size(210, height);
if (formDelay.ShowDialog() != DialogResult.OK)
return;
int arrayIndex = 0;
for (int i = 0; i < formDelay.Controls.Count; i++)
{
if (formDelay.Controls[i] is TextBox)
{
if (this.SaveControlContent((TextBox)formDelay.Controls[i], delayType + (object) i, this.tabpagePropertiesOne, formEditor.NumberRange.NonNegative, out delayValues[arrayIndex]))
{
arrayIndex++;
}
else
{
break;
}
}
}
}
}
private void numericUpDownPowerNotches_ValueChanged(object sender, EventArgs e)
{
int length = Train.Delay.DelayPowerUp.Length;
if (length == numericUpDownPowerNotches.Value)
{
return;
}
Array.Resize(ref Train.Delay.DelayPowerUp, (int)numericUpDownPowerNotches.Value);
Array.Resize(ref Train.Delay.DelayPowerDown, (int)numericUpDownPowerNotches.Value);
if (numericUpDownPowerNotches.Value > length)
{
for (int i = length; i < numericUpDownPowerNotches.Value; i++)
{
Train.Delay.DelayPowerUp[i] = 0.0;
Train.Delay.DelayPowerDown[i] = 0.0;
}
}
}
private void numericUpDownBrakeNotches_ValueChanged(object sender, EventArgs e)
{
int length = Train.Delay.DelayBrakeUp.Length;
if (length == numericUpDownBrakeNotches.Value)
{
return;
}
Array.Resize(ref Train.Delay.DelayBrakeUp, (int)numericUpDownBrakeNotches.Value);
Array.Resize(ref Train.Delay.DelayBrakeDown, (int)numericUpDownBrakeNotches.Value);
if (numericUpDownBrakeNotches.Value > length)
{
for (int i = length; i < numericUpDownBrakeNotches.Value; i++)
{
Train.Delay.DelayBrakeUp[i] = 0.0;
Train.Delay.DelayBrakeDown[i] = 0.0;
}
}
}
}
}
\ No newline at end of file
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment