Commit 62a3a827 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 livechart 有bug, 不显示出来,就无法读取binding 的值

parent caa8b5e4
...@@ -12,6 +12,7 @@ using System.IO; ...@@ -12,6 +12,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Threading; using System.Windows.Threading;
namespace FLY.Thick.FilmCasting.UI.Server namespace FLY.Thick.FilmCasting.UI.Server
...@@ -106,7 +107,7 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -106,7 +107,7 @@ namespace FLY.Thick.FilmCasting.UI.Server
Load(); Load();
InitKeepDay(); InitKeepDay();
lastScanDataId = bulkDb.LastProfileId; lastScanDataId = bulkDb.LastScanDataId;
this.scanGraphVm = new ScanGraphVm(); this.scanGraphVm = new ScanGraphVm();
...@@ -150,8 +151,9 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -150,8 +151,9 @@ namespace FLY.Thick.FilmCasting.UI.Server
//触发!!! //触发!!!
CounterSec = 0; CounterSec = 0;
if (lastScanDataId != bulkDb.LastProfileId) if (lastScanDataId != bulkDb.LastScanDataId)
{ {
lastScanDataId = bulkDb.LastScanDataId;
GetFrame(); GetFrame();
} }
} }
...@@ -188,7 +190,36 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -188,7 +190,36 @@ namespace FLY.Thick.FilmCasting.UI.Server
Directory.CreateDirectory(dirpath); Directory.CreateDirectory(dirpath);
return $@"{dirpath}\{dt:HH_mm_ss}.jpg"; return $@"{dirpath}\{dt:HH_mm_ss}.jpg";
} }
public async void SavePic(string path)
{
//一定要把 scangraph 放入容器, 且scangraph Left,Top 对齐,margin=0
//不然有黑框
//整个scangraph 的尺寸是 Margin+(Width,Height)
//Margin 是透明,也就是黑色
var viewbox = new Viewbox();
ScanGraph scanGraph = new ScanGraph
{
Width = PicWidth,
Height = PicHeight,
//HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
//VerticalAlignment = System.Windows.VerticalAlignment.Top,
//Margin = new System.Windows.Thickness()
};
scanGraph.Init(scanGraphVm);
viewbox.Child = scanGraph;
viewbox.Measure(scanGraph.RenderSize);
viewbox.Arrange(new System.Windows.Rect(new System.Windows.Point(0, 0), scanGraph.RenderSize));
scanGraph.ChartUpdate();//强制使 livechart 刷新
viewbox.UpdateLayout();
ChartToImage.SaveToJpeg(scanGraph, path);
}
public async Task Add(Pack_GetFrameReponse reponse) public async Task Add(Pack_GetFrameReponse reponse)
{ {
if (reponse.scanData == null) if (reponse.scanData == null)
...@@ -209,11 +240,7 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -209,11 +240,7 @@ namespace FLY.Thick.FilmCasting.UI.Server
{ {
scanGraphVm.UpdateValue(reponse, isWarning); scanGraphVm.UpdateValue(reponse, isWarning);
ScanGraph scanGraph = new ScanGraph(); SavePic(path);
scanGraph.Init(scanGraphVm);
scanGraph.Update(PicWidth, PicHeight);
ChartToImage.SaveToJpeg(scanGraph, path);
}); });
await Task.Factory.StartNew(() => await Task.Factory.StartNew(() =>
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<lvc:CartesianChart x:Name="chart" Grid.Row="1" <lvc:CartesianChart x:Name="chart" Grid.Row="1"
Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" Margin="{StaticResource ControlMargin}"> Hoverable="False" DisableAnimations="True" DataTooltip="{x:Null}" Margin="{StaticResource ControlMargin}">
<lvc:CartesianChart.AxisX> <lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding XFormatter}" <lvc:Axis x:Name="axisX_0" LabelFormatter="{Binding XFormatter}"
Foreground="{StaticResource Brushes.ChartAxisLabel}" Foreground="{StaticResource Brushes.ChartAxisLabel}"
MaxValue="{Binding XMax}" MinValue="{Binding XMin}" MaxValue="{Binding XMax}" MinValue="{Binding XMin}"
> >
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
</lvc:Axis> </lvc:Axis>
</lvc:CartesianChart.AxisX> </lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY> <lvc:CartesianChart.AxisY>
<lvc:Axis LabelFormatter="{Binding YFormatter}" MaxValue="{Binding YMax}" MinValue="{Binding YMin}" Panel.ZIndex="0" Foreground="Transparent" FontFamily="Courier New"> <lvc:Axis x:Name="axisY_0" LabelFormatter="{Binding YFormatter}" MaxValue="{Binding YMax}" MinValue="{Binding YMin}" Panel.ZIndex="0" Foreground="Transparent" FontFamily="Courier New">
<lvc:Axis.Sections> <lvc:Axis.Sections>
<lvc:AxisSection Style="{StaticResource AxisSectionStyle}" <lvc:AxisSection Style="{StaticResource AxisSectionStyle}"
Value="{Binding YMax}" Value="{Binding YMax}"
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
</lvc:CartesianChart.AxisY> </lvc:CartesianChart.AxisY>
<lvc:CartesianChart.Series> <lvc:CartesianChart.Series>
<lvc2:Column2Series <lvc2:Column2Series x:Name="series_0"
YAxisCrossing="{Binding Target}" YAxisCrossing="{Binding Target}"
Values="{Binding Values}" Values="{Binding Values}"
Stroke = "Black" Stroke = "Black"
...@@ -112,18 +112,6 @@ ...@@ -112,18 +112,6 @@
</lvc2:Column2Series> </lvc2:Column2Series>
</lvc:CartesianChart.Series> </lvc:CartesianChart.Series>
<!--Series = new SeriesCollection
{
new Column2Series
{
Values = Values,
Stroke = new SolidColorBrush(Colors.Black),
StrokeThickness = 1,
PointGeometry = null,
Configuration = Mapper
}
};
((Series)Series[0]).SetBinding(Column2Series.YAxisCrossingProperty, new Binding(nameof(Target)) { Source = this });-->
</lvc:CartesianChart> </lvc:CartesianChart>
</Grid> </Grid>
<Grid> <Grid>
...@@ -135,25 +123,13 @@ ...@@ -135,25 +123,13 @@
<Viewbox MaxHeight="75"> <Viewbox MaxHeight="75">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<StackPanel> <StackPanel>
<Grid > <Grid Background="{StaticResource MahApps.Brushes.Gray10}">
<Grid.Style>
<Style TargetType="Grid">
<Style.Setters>
<Setter Property="Background" Value="{StaticResource MahApps.Brushes.Gray10}"/>
</Style.Setters>
<Style.Triggers>
<DataTrigger Binding="{Binding IsWarning}" Value="true">
<Setter Property="Background" Value="{StaticResource MahApps.Brushes.Validation5}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition Width="auto"/> <ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Title}" /> <TextBlock Style="{StaticResource ValueStyle}" Text="{Binding Title}" />
<TextBlock Grid.Column="1" Text="厚度报警" FontSize="20" Foreground="{StaticResource MahApps.Brushes.Text.Validation}" Margin="10,1" <TextBlock Grid.Column="1" Text="厚度报警" FontSize="20" Foreground="{StaticResource MahApps.Brushes.Validation5}" Margin="10,1"
Visibility="{Binding IsWarning,Converter={StaticResource visbilityconv}}"/> Visibility="{Binding IsWarning,Converter={StaticResource visbilityconv}}"/>
</Grid> </Grid>
<StackPanel Orientation="Horizontal" > <StackPanel Orientation="Horizontal" >
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using Misc; using Misc;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
namespace FLY.Thick.FilmCasting.UI.Server namespace FLY.Thick.FilmCasting.UI.Server
{ {
...@@ -20,15 +21,36 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -20,15 +21,36 @@ namespace FLY.Thick.FilmCasting.UI.Server
{ {
this.DataContext = viewModel; this.DataContext = viewModel;
//下面是 livechart 的 bug
//没有 触发 ChartUpdater.Timer 的事件前,就算 axisX.DataContext 有值, binding 也无效, 无法获取数据
axisX_0.SetBinding( LiveCharts.Wpf.Axis.LabelFormatterProperty, new Binding(nameof(viewModel.XFormatter)) { Source = viewModel });
axisX_0.SetBinding( LiveCharts.Wpf.Axis.MinValueProperty, new Binding(nameof(viewModel.XMin)) { Source = viewModel });
axisX_0.SetBinding( LiveCharts.Wpf.Axis.MaxValueProperty, new Binding(nameof(viewModel.XMax)) { Source = viewModel });
axisX_0.Separator.SetBinding( LiveCharts.Wpf.Separator.StepProperty, new Binding(nameof(viewModel.XStep)) { Source = viewModel });
axisY_0.SetBinding( LiveCharts.Wpf.Axis.LabelFormatterProperty, new Binding(nameof(viewModel.YFormatter)) { Source = viewModel });
axisY_0.SetBinding( LiveCharts.Wpf.Axis.MinValueProperty, new Binding(nameof(viewModel.YMin)) { Source = viewModel });
axisY_0.SetBinding( LiveCharts.Wpf.Axis.MaxValueProperty, new Binding(nameof(viewModel.YMax)) { Source = viewModel });
axisY_0.Sections[0].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.YMax)) { Source = viewModel });
axisY_0.Sections[1].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.YMin)) { Source = viewModel });
axisY_0.Sections[2].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.Tolerance2YMax)) { Source = viewModel });
axisY_0.Sections[3].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.Tolerance2YMin)) { Source = viewModel });
axisY_0.Sections[4].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.ToleranceYMax)) { Source = viewModel });
axisY_0.Sections[5].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.ToleranceYMin)) { Source = viewModel });
axisY_0.Sections[6].SetBinding( LiveCharts.Wpf.AxisSection.ValueProperty, new Binding(nameof(viewModel.Target)) { Source = viewModel });
series_0.SetBinding(LiveCharts.Wpf.Column2Series.YAxisCrossingProperty, new Binding(nameof(viewModel.Target)) { Source = viewModel });
series_0.SetBinding(LiveCharts.Wpf.Column2Series.ValuesProperty, new Binding(nameof(viewModel.Values)) { Source = viewModel });
series_0.SetBinding(LiveCharts.Wpf.Column2Series.ConfigurationProperty, new Binding(nameof(viewModel.Mapper)) { Source = viewModel });
} }
public void Update(int width, int height)
public void ChartUpdate()
{ {
Width = width;
Height = height;
Measure(RenderSize);
Arrange(new System.Windows.Rect(new System.Windows.Point(0, 0), RenderSize));
chart.Update(true, true); //force chart redraw chart.Update(true, true); //force chart redraw
UpdateLayout();
} }
} }
} }
...@@ -15,10 +15,13 @@ ...@@ -15,10 +15,13 @@
</Window.Resources> </Window.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition />
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<local:ScanGraph x:Name="scanGraph" Margin="{StaticResource ControlMargin}"/> <Grid x:Name="grid_root"/>
<Grid Margin="{StaticResource ControlMargin}" >
<local:ScanGraph x:Name="scanGraph" />
</Grid>
<StackPanel Margin="{StaticResource ControlMargin}" Grid.Row="1" > <StackPanel Margin="{StaticResource ControlMargin}" Grid.Row="1" >
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<StackPanel Margin="{StaticResource ControlMargin}"> <StackPanel Margin="{StaticResource ControlMargin}">
...@@ -89,7 +92,11 @@ ...@@ -89,7 +92,11 @@
<CheckBox IsChecked="{Binding IsPercent}"/> <CheckBox IsChecked="{Binding IsPercent}"/>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
<Button Style="{StaticResource Styles.Button.Square.Accent2}" HorizontalAlignment="Right" Content="确定" Command="{Binding OkCmd}" /> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<Button Style="{StaticResource Styles.Button.Square.Accent2}" Content="图片保存" Click="btnSavePicClick" Width="auto"/>
<Button Style="{StaticResource Styles.Button.Square.Accent2}" Content="确定" Command="{Binding OkCmd}" />
</StackPanel>
</StackPanel> </StackPanel>
</Grid> </Grid>
......
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
...@@ -22,17 +23,35 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -22,17 +23,35 @@ namespace FLY.Thick.FilmCasting.UI.Server
public partial class WdPicHistory : Window public partial class WdPicHistory : Window
{ {
WdPicHistoryVm viewModel; WdPicHistoryVm viewModel;
PicHistory picHistory;
public WdPicHistory() public WdPicHistory()
{ {
InitializeComponent(); InitializeComponent();
} }
public void Init(PicHistory picHistory) public void Init(PicHistory picHistory)
{ {
this.picHistory = picHistory;
viewModel = new WdPicHistoryVm(); viewModel = new WdPicHistoryVm();
this.viewModel.Init(picHistory); this.viewModel.Init(picHistory);
this.DataContext = viewModel; this.DataContext = viewModel;
scanGraph.DataContext = picHistory.scanGraphVm; scanGraph.Init(picHistory.scanGraphVm);
}
private void btnSavePicClick(object sender, RoutedEventArgs e)
{
string strDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = strDesktopPath;
sfd.Filter = "jpg|*.jpg";
sfd.FileName = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(),".jpg");
if (sfd.ShowDialog() == true)
{
//ChartToImage.SaveToJpeg(scanGraph, sfd.FileName);
picHistory.SavePic(sfd.FileName);
}
} }
} }
...@@ -82,7 +101,6 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -82,7 +101,6 @@ namespace FLY.Thick.FilmCasting.UI.Server
public bool IsPercent { get; set; } = true; public bool IsPercent { get; set; } = true;
public RelayCommand OkCmd { get; private set; } public RelayCommand OkCmd { get; private set; }
private PicHistory picHistory; private PicHistory picHistory;
public PicHistory PicHistory => picHistory; public PicHistory PicHistory => picHistory;
public WdPicHistoryVm() public WdPicHistoryVm()
......
...@@ -66,12 +66,24 @@ namespace FLY.Thick.FilmCasting.UI.Server ...@@ -66,12 +66,24 @@ namespace FLY.Thick.FilmCasting.UI.Server
FlyAdAddr = flyAd.Addr; FlyAdAddr = flyAd.Addr;
DbKeepMonth = initParam.DBKeepMonth; DbKeepMonth = initParam.DBKeepMonth;
if (DbKeepMonth > 0 && DbKeepMonth < 12)
DbKeepMonth = 12;
DbDirPath = initParam.DbDirPath; DbDirPath = initParam.DbDirPath;
} }
private void Ok() private void Ok()
{ {
if (DbKeepMonth>0 && DbKeepMonth < 12)
{
if (MessageBox.Show($"数据库容量 最小值为12个月", "提示") == MessageBoxResult.No)
{
DbKeepMonth = 12;
return;
}
}
if (MessageBox.Show($"程序必须重启才能执行新的参数, 是否重启?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) if (MessageBox.Show($"程序必须重启才能执行新的参数, 是否重启?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{ {
return; return;
......
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