Browse Source

Добавлена переменная для длителельности выполнения процедуры, а также TextBox для ее задания + немного рефакторинга

master
Никита 6 years ago
parent
commit
5f52377b15
  1. 18
      Signal Generator/DrawTask.cs
  2. 11
      Signal Generator/ProcedureModel.cs
  3. 1
      Signal Generator/Signal Generator.csproj
  4. 23
      Signal Generator/StringDoubleConverter.cs
  5. 9
      Signal Generator/TaskWindow.xaml

18
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);
}
}
}

11
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"));
}
}
}
}

1
Signal Generator/Signal Generator.csproj

@ -66,6 +66,7 @@
<Compile Include="Signal\Base\Parameter.cs" />
<Compile Include="Signal\SinusoidalSignal.cs" />
<Compile Include="ArrayConverter.cs" />
<Compile Include="StringDoubleConverter.cs" />
<Compile Include="TaskWindow.xaml.cs">
<DependentUpon>TaskWindow.xaml</DependentUpon>
</Compile>

23
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);
}
}
}

9
Signal Generator/TaskWindow.xaml

@ -11,6 +11,7 @@
<Window.Resources>
<local:ProcedureModel x:Key="ProcedureModel"/>
<local:ArrayConverter x:Key="ArrayConverter"/>
<local:StringDoubleConverter x:Key="StringDoubleConverter"/>
</Window.Resources>
<Grid Margin="10" Loaded="Grid_Loaded" DataContext="{Binding Source={StaticResource ProcedureModel}}">
@ -19,6 +20,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
@ -34,7 +36,10 @@
<TextBlock x:Name="currentAmplitude_TextBlock" Margin="0,0,5,5" Grid.Row="2" Grid.Column="1">Текущий сигнал:</TextBlock>
<TextBox x:Name="currentAmplitude_TextBox" Margin="0,0,0,5" Grid.Row="2" Grid.Column="2" IsEnabled="False"
Text="{Binding Path=CurrentAmplitude}"/>
<Button x:Name="start_Button" Width="120" Content="Запустить" Margin="5,0" Grid.Row="3" Grid.Column="0"
<TextBlock x:Name="duration_TextBlock" Margin="0,0,5,5" Grid.Row="3" Grid.Column="1">Длительность (мс):</TextBlock>
<TextBox x:Name="duration_TextBox" Margin="0,0,0,5" Grid.Row="3" Grid.Column="2"
Text="{Binding Duration, Converter={StaticResource StringDoubleConverter}, Mode=TwoWay}"/>
<Button x:Name="start_Button" Width="120" Content="Запустить" Margin="5,0" Grid.Row="4" Grid.Column="0"
Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}">
@ -45,7 +50,7 @@
</MultiBinding>
</Button.CommandParameter>
</Button>
<Button x:Name="pause_Button" Width="120" Content="Приостановить" Margin="5,0" Grid.Row="3" Grid.Column="2"
<Button x:Name="pause_Button" Width="120" Content="Приостановить" Margin="5,0" Grid.Row="4" Grid.Column="2"
Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}">

Loading…
Cancel
Save