Skip to content

Commit

Permalink
Added legends chart and check current active com ports.
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxTes committed Mar 27, 2021
1 parent baaaa89 commit d2f77fd
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private bool CheckSessionItemsForZero()

private async void GetSessionInfo()
{
// TODO: Зарефакторить.
var sessionInfoTask = Task.Run(() =>
{
using var context = new Context();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
Grid.Row="1"
Width="150"
Command="{Binding CancelCommand}"
Content="Отмена" />
Content="Отмена"
Style="{DynamicResource AccentButtonStyle}" />
</Grid>
</GroupBox>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ private void InitChart()
tick: Color.FromArgb(170, 170, 170));
_plot.XAxis.TickLabelStyle(fontSize: 12);
_plot.YAxis.TickLabelStyle(fontSize: 12);

var legend = _plot.Legend();
legend.Padding = 8;
legend.FontSize = 12;
}

private async void InitChartValueAsync()
Expand Down Expand Up @@ -191,17 +195,23 @@ private async Task GetSensorDataAsync()
var result = getItemsTask.Result;

if (GroupCheckItems[0].Value)
_plot.AddSignal(result.Select(x => (double)x.Value1).ToArray(), color: Color.FromArgb(0x00, 0x3f, 0x5c));
_plot.AddSignal(result.Select(x => (double) x.Value1).ToArray(),
color: Color.FromArgb(0x00, 0x3f, 0x5c), label: "Датчик №1");
if (GroupCheckItems[1].Value)
_plot.AddSignal(result.Select(x => (double)x.Value2).ToArray(), color: Color.FromArgb(0x44, 0x4e, 0x86));
_plot.AddSignal(result.Select(x => (double) x.Value2).ToArray(),
color: Color.FromArgb(0x44, 0x4e, 0x86), label: "Датчик №2");
if (GroupCheckItems[2].Value)
_plot.AddSignal(result.Select(x => (double)x.Value3).ToArray(), color: Color.FromArgb(0x95, 0x51, 0x96));
_plot.AddSignal(result.Select(x => (double) x.Value3).ToArray(),
color: Color.FromArgb(0x95, 0x51, 0x96), label: "Датчик №3");
if (GroupCheckItems[3].Value)
_plot.AddSignal(result.Select(x => (double)x.Value4).ToArray(), color: Color.FromArgb(0xdd, 0x51, 0x82));
_plot.AddSignal(result.Select(x => (double) x.Value4).ToArray(),
color: Color.FromArgb(0xdd, 0x51, 0x82), label: "Датчик №4");
if (GroupCheckItems[4].Value)
_plot.AddSignal(result.Select(x => (double)x.Value5).ToArray(), color: Color.FromArgb(0xff, 0x6e, 0x54));
_plot.AddSignal(result.Select(x => (double) x.Value5).ToArray(),
color: Color.FromArgb(0xff, 0x6e, 0x54), label: "Датчик №5");
if (GroupCheckItems[5].Value)
_plot.AddSignal(result.Select(x => (double)x.Value6).ToArray(), color: Color.FromArgb(0xff, 0xa6, 0x00));
_plot.AddSignal(result.Select(x => (double) x.Value6).ToArray(),
color: Color.FromArgb(0xff, 0xa6, 0x00), label: "Датчик №6");

_plot.AxisAutoX();
_plot.SetAxisLimitsY(0, 165);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>

<ContentControl Margin="0,8,8,0" Content="{Binding PlotControl}" />
<ContentControl Margin="0,16,16,0" Content="{Binding PlotControl}" />

<Border
Grid.Column="1"
Margin="0,8,0,0"
Margin="0,16,0,0"
Background="{DynamicResource SystemControlBackgroundBaseMediumLowBrush}" />

<Grid Grid.Column="2" Margin="8,8,0,8">
<Grid Grid.Column="2" Margin="16,8,0,8">
<ui:SimpleStackPanel Spacing="16">
<GroupBox Padding="0,-8,0,0" Header="Сессии">
<ui:SimpleStackPanel Orientation="Vertical" Spacing="8">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid Margin="0,0,8,0">
<Grid Margin="0,8,8,0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
Expand Down Expand Up @@ -784,11 +784,11 @@

<Border
Grid.Column="1"
Margin="0,8,0,0"
Margin="0,16,0,0"
Background="{DynamicResource SystemControlBackgroundBaseMediumLowBrush}" />
<DataGrid
Grid.Column="2"
Padding="8,8,0,0"
Padding="16,16,0,0"
AutoGenerateColumns="False"
Background="Transparent"
CanUserResizeColumns="False"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ private void UploadingDataSources()

private void SetDefaultSettings()
{
AddressDeviceSelected = 3;
PortNameSelected = PortName[0];
AddressDeviceSelected = 3;
BaudRateSelected = BaudRate.S9600;
StopBitsSelected = StopBits.One;
ParitySelected = Parity.None;
Expand Down
20 changes: 18 additions & 2 deletions src/SmartThermo/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Prism.Ioc;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Prism.Ioc;
using Prism.Modularity;
using SmartThermo.Modules.Analytics;
using SmartThermo.Modules.DataViewer;
Expand All @@ -15,13 +18,27 @@
using ToastNotifications.Lifetime;
using ToastNotifications.Position;


namespace SmartThermo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
public App()
{
AppDomain.CurrentDomain.UnhandledException += (sender, e)
=> MessageBox.Show(e.ExceptionObject.ToString());
}

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppCenter.Start("3fb4a695-2ae6-4663-9878-d0fa3ada2d1e",
typeof(Analytics), typeof(Crashes));
}

protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
Expand Down Expand Up @@ -60,7 +77,6 @@ protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
}

// -Tooltip и легенда для аналитики.
// -Margin для всех.
// -Перевод графика во дата.
// -Запись null значений.
// -Выбор сессию (нет значений, если count ==0).
Expand Down
2 changes: 2 additions & 0 deletions src/SmartThermo/SmartThermo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.2.0" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.2.0" />
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
<PackageReference Include="NModbus" Version="3.0.62" />
<PackageReference Include="NModbus.Serial" Version="3.0.62" />
Expand Down
10 changes: 9 additions & 1 deletion src/SmartThermo/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using SmartThermo.Services.Notifications;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Threading.Tasks;
using System.Windows;
using ToastNotifications.Core;
Expand Down Expand Up @@ -98,7 +99,6 @@ public MainWindowViewModel(IRegionManager regionManager, IDeviceConnector device

private async void CreateSession()
{
// TODO: Возможно убрать в StartOn.
CheckDatabaseCreate();

await using var context = new Context();
Expand Down Expand Up @@ -147,11 +147,19 @@ private void ChangeConnectDeviceExecute()
Notifications.ShowWarning("Не удалось закрыть соединение.\n" + ex.Message, new MessageOptions());
}
else
{
if (SerialPort.GetPortNames().Length == 0)
{
Notifications.ShowError("В компьютере найдены активные COM порты.");
return;
}
DialogService.ShowNotification("SettingsPortDialog", r =>
{
if (r.Result == ButtonResult.Cancel)
Notifications.ShowInformation("Операция прервана пользователем.");
});
}

}

private void SettingDeviceExecute()
Expand Down
9 changes: 6 additions & 3 deletions src/SmartThermo/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="clr-namespace:SmartThermo.Core;assembly=SmartThermo.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:prism="http://prismlibrary.com/"
xmlns:ui="http://schemas.modernwpf.com/2019"
Width="1366"
Height="768"
Title="SmartThermo"
MinWidth="1280"
MinHeight="720"
prism:ViewModelLocator.AutoWireViewModel="True"
ui:ThemeManager.RequestedTheme="Dark"
ui:WindowHelper.UseModernWindowStyle="True"
Background="{DynamicResource SystemControlPageBackgroundChromeMediumLowBrush}"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
WindowState="Maximized">

<Grid>
<Grid.RowDefinitions>
Expand Down

0 comments on commit d2f77fd

Please sign in to comment.