Browse Source

Добавлены привязки для текстовых полей. Теперь в полях в реальном времени отображается информация о сигнале.

master release_0.1
Никита 6 years ago
parent
commit
e05d3f1f3b
  1. 0
      Signal Generator/ArrayConverter.cs
  2. 21
      Signal Generator/DrawTask.cs
  3. 34
      Signal Generator/ProcedureModel.cs
  4. 2
      Signal Generator/Signal Generator.csproj
  5. 16
      Signal Generator/TaskWindow.xaml

0
Signal Generator/TaskViewConverter.cs → Signal Generator/ArrayConverter.cs

21
Signal Generator/DrawTask.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
@ -7,6 +8,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
@ -16,9 +18,8 @@ namespace Signal_Generator
public class DrawTask : Task, INotifyPropertyChanged
{
Canvas canvas;
System.Timers.Timer taskTimer;
Stopwatch stopwatch = new Stopwatch();
MultiSignal multiSignal;
ProcedureModel procedureModel;
private State _state;
public State state
@ -40,25 +41,15 @@ namespace Signal_Generator
public DrawTask(Action a) : base(a) { }
public void buildTask(Canvas c)
public void buildTask(ProcedureModel pm, Canvas c)
{
canvas = c;
procedureModel = pm;
multiSignal = MultiSignal.getInstance();
state = State.Running;
stopwatch.Start();
taskTimer = new System.Timers.Timer(2000);
taskTimer.Elapsed += updateTextForms;
taskTimer.Enabled = true;
drawSignalAtCanvas();
}
private void updateTextForms(object sender, ElapsedEventArgs e)
{
var elapsed = stopwatch.ElapsedMilliseconds;
}
private void drawSignalAtCanvas()
{
@ -66,6 +57,8 @@ 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();
double y = multiSignal.currentAmplitude(i / 5.0);
drawLine(lastX, lastY, i, y);
lastX = i;

34
Signal Generator/ProcedureModel.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
@ -8,10 +9,11 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;
namespace Signal_Generator
{
public class ProcedureModel : ICommand
public class ProcedureModel : ICommand, INotifyPropertyChanged
{
public DrawTask currentTask;
Canvas targetCanvas;
@ -43,7 +45,7 @@ namespace Signal_Generator
var btn = parameters[0] as Button;
var ms = MultiSignal.getInstance();
if ((ms == null) && (ms.count() == 0))
if ((ms == null) || (ms.count() == 0))
return false;
switch (btn.Name)
{
@ -95,7 +97,8 @@ namespace Signal_Generator
var parameters = parameter as object[];
var btn = parameters[0] as Button;
targetCanvas = parameters[1] as Canvas;
switch (btn.Name)
{
case "start_Button":
@ -123,7 +126,7 @@ namespace Signal_Generator
Action newAction = () =>
{
currentTask.PropertyChanged += RaiseCanExecuteChanged;
currentTask.buildTask(targetCanvas);
currentTask.buildTask(this, targetCanvas);
};
currentTask = new DrawTask(newAction);
currentTask.Start();
@ -141,5 +144,28 @@ namespace Signal_Generator
break;
}
}
public event PropertyChangedEventHandler PropertyChanged;
private string currentAmplitude;
public string CurrentAmplitude
{
get { return currentAmplitude; }
set
{
currentAmplitude = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentAmplitude"));
}
}
private string currentTime;
public string CurrentTime
{
get { return currentTime; }
set
{
currentTime = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentTime"));
}
}
}
}

2
Signal Generator/Signal Generator.csproj

@ -65,7 +65,7 @@
<Compile Include="Settings.cs" />
<Compile Include="Signal\Base\Parameter.cs" />
<Compile Include="Signal\SinusoidalSignal.cs" />
<Compile Include="TaskViewConverter.cs" />
<Compile Include="ArrayConverter.cs" />
<Compile Include="TaskWindow.xaml.cs">
<DependentUpon>TaskWindow.xaml</DependentUpon>
</Compile>

16
Signal Generator/TaskWindow.xaml

@ -13,7 +13,7 @@
<local:ArrayConverter x:Key="ArrayConverter"/>
</Window.Resources>
<Grid Margin="10" Loaded="Grid_Loaded">
<Grid Margin="10" Loaded="Grid_Loaded" DataContext="{Binding Source={StaticResource ProcedureModel}}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
@ -26,18 +26,22 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Canvas x:Name="signalGraph_Canvas" Background="AliceBlue" Grid.ColumnSpan="4" Margin="0,0,0,5"/>
<Canvas x:Name="signalGraph_Canvas" Background="AliceBlue" Grid.ColumnSpan="4" Margin="0,0,0,5" ClipToBounds="True"/>
<TextBlock x:Name="currentTime_TextBlock" Margin="0,0,5,5" Grid.Row="1" Grid.Column="1">Время выполения:</TextBlock>
<TextBox x:Name="currentTime_TextBox" Margin="0,0,0,5" Grid.Row="1" Grid.Column="2"/>
<TextBox x:Name="currentTime_TextBox" Margin="0,0,0,5" Grid.Row="1" Grid.Column="2" IsEnabled="False"
Text="{Binding Path=CurrentTime}"/>
<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"/>
<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"
Grid.ColumnSpan="2" Command="{StaticResource ProcedureModel}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ArrayConverter}">
<Binding ElementName="start_Button"/>
<Binding ElementName="signalGraph_Canvas"/>
<Binding ElementName="currentTime_TextBox"/>
<Binding ElementName="currentAmplitude_TextBox"/>
</MultiBinding>
</Button.CommandParameter>
</Button>
@ -47,6 +51,8 @@
<MultiBinding Converter="{StaticResource ArrayConverter}">
<Binding ElementName="pause_Button"/>
<Binding ElementName="signalGraph_Canvas"/>
<Binding ElementName="currentTime_TextBox"/>
<Binding ElementName="currentAmplitude_TextBox"/>
</MultiBinding>
</Button.CommandParameter>
</Button>

Loading…
Cancel
Save