From 5f52377b152e0ad4d628310a4108acc71bb03d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Sun, 11 Nov 2018 17:52:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=B4=D0=BB=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80=D1=8B,=20?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20TextBox=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B5=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20+=20=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Signal Generator/DrawTask.cs | 18 +++++++++++------- Signal Generator/ProcedureModel.cs | 11 +++++++++++ Signal Generator/Signal Generator.csproj | 1 + Signal Generator/StringDoubleConverter.cs | 23 +++++++++++++++++++++++ Signal Generator/TaskWindow.xaml | 9 +++++++-- 5 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 Signal Generator/StringDoubleConverter.cs diff --git a/Signal Generator/DrawTask.cs b/Signal Generator/DrawTask.cs index efebd93..933742e 100644 --- a/Signal Generator/DrawTask.cs +++ b/Signal Generator/DrawTask.cs @@ -57,8 +57,7 @@ namespace Signal_Generator double w = canvas.ActualWidth; for (int i = 0; i != (int)w; i++) { - procedureModel.CurrentAmplitude = multiSignal.currentAmplitude(i / 5.0).ToString(); - procedureModel.CurrentTime = (i / 5.0).ToString(); + updateTextBoxProps(multiSignal.currentAmplitude(i / 5.0), i / 5.0); double y = multiSignal.currentAmplitude(i / 5.0); drawLine(lastX, lastY, i, y); lastX = i; @@ -76,6 +75,12 @@ namespace Signal_Generator state = State.Finished; } + private void updateTextBoxProps(double amp, double time) + { + procedureModel.CurrentAmplitude = amp.ToString(); + procedureModel.CurrentTime = time.ToString(); + } + private void drawLine(double x1, double y1, double x2, double y2) { Action a = () => { @@ -83,18 +88,17 @@ namespace Signal_Generator l.StrokeThickness = 1; l.Stroke = Brushes.Red; l.X1 = x1; - l.Y1 = remap(y1); + l.Y1 = remapOY(y1, 100, canvas.ActualHeight); l.X2 = x2; - l.Y2 = remap(y2); + l.Y2 = remapOY(y2, 100, canvas.ActualHeight); canvas.Children.Add(l); }; canvas.Dispatcher.Invoke(a); } - private double remap(double x, double oldMin = -100.0, double oldMax = 100.0, double newMin = 100.0, double newMax = 0.0) + private double remapOY(double x, double amp = 100.0, double height = 100.0) { - newMin = canvas.ActualHeight; - return newMin + (x - oldMin) * (newMax - newMin) / (oldMax - oldMin); + return height + (x + amp) * (-height) / (2 * amp); } } } diff --git a/Signal Generator/ProcedureModel.cs b/Signal Generator/ProcedureModel.cs index 2b3fcf2..ea6367f 100644 --- a/Signal Generator/ProcedureModel.cs +++ b/Signal Generator/ProcedureModel.cs @@ -167,5 +167,16 @@ namespace Signal_Generator PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime")); } } + + private double duration; + public double Duration + { + get { return duration; } + set + { + duration = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime")); + } + } } } diff --git a/Signal Generator/Signal Generator.csproj b/Signal Generator/Signal Generator.csproj index af53227..df770ba 100644 --- a/Signal Generator/Signal Generator.csproj +++ b/Signal Generator/Signal Generator.csproj @@ -66,6 +66,7 @@ + TaskWindow.xaml diff --git a/Signal Generator/StringDoubleConverter.cs b/Signal Generator/StringDoubleConverter.cs new file mode 100644 index 0000000..53eb9fa --- /dev/null +++ b/Signal Generator/StringDoubleConverter.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Signal_Generator +{ + class StringDoubleConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return ((double)value).ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return double.Parse((string)value); + } + } +} diff --git a/Signal Generator/TaskWindow.xaml b/Signal Generator/TaskWindow.xaml index aad6f82..fa1aef6 100644 --- a/Signal Generator/TaskWindow.xaml +++ b/Signal Generator/TaskWindow.xaml @@ -11,6 +11,7 @@ + @@ -19,6 +20,7 @@ + @@ -34,7 +36,10 @@ Текущий сигнал: - -