Commit d638efef authored by 潘栩锋's avatar 潘栩锋 🚴

更换 grid 调试界面

parent bffd44f0
using FLY.OBJComponents.Client;
using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ThickTcpUiInWindow
{
/// <summary>
/// UcMicroGage.xaml 的交互逻辑
/// </summary>
public partial class CtMicroGage : UserControl
{
CtMicroGageVm viewModel;
/// <summary>
///
/// </summary>
public CtMicroGage()
{
InitializeComponent();
viewModel = new CtMicroGageVm();
this.DataContext = viewModel;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="dynArea"></param>
/// <param name="initParam"></param>
/// <param name="gageService"></param>
/// <param name="warningReasonWindow"></param>
public void Init(
DynArea dynArea,
InitParamServiceClient initParam,
TDGageServiceClient gageService,
BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory> warningReasonWindow)
{
viewModel.Init(dynArea,initParam,gageService,warningReasonWindow);
}
}
/// <summary>
///
/// </summary>
public class IO2BitColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
SolidColorBrush Color_theme_activity = new SolidColorBrush(Colors.WhiteSmoke);
SolidColorBrush Color_theme_static = new SolidColorBrush(Color.FromArgb(0xFF, 0x3B, 0x3B, 0x3B));
try
{
UInt16 io = (UInt16)value;
string str = (string)parameter;
int bitno = int.Parse(str);
if (Misc.MyBase.CHECKBIT(io, bitno))
return Color_theme_static;
else
return Color_theme_activity;
}
catch
{
return Color_theme_static;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ThickTcpUiInWindow">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Dictionary_MyStyle.xaml"/>
<ResourceDictionary Source="pack://application:,,,/ThickTcpUiInWindow;component/Converter/Dictionary_MyConv.xaml"/>
</ResourceDictionary.MergedDictionaries>
<local:IO2BitColorConverter x:Key="io2bitcolorconv"/>
<Style TargetType="TextBlock" x:Key="ItemHeaderStyle">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontFamily" Value="YouYuan"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Foreground" Value="#FF3B3B3B"/>
<Setter Property="Margin" Value="5,0"/>
</Style>
<Style x:Key="IOStyle" TargetType="Rectangle" >
<Setter Property="Width" Value="11" />
<Setter Property="Height" Value="12" />
<Setter Property="Margin" Value="1" />
</Style>
<Style x:Key="BtnStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource ButtonStyle_empty}">
<Setter Property="Margin" Value="2"/>
<Setter Property="Foreground" Value="{StaticResource AccentBaseColorBrush}"/>
<Setter Property="Background" Value="{StaticResource WhiteBrush}"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="10" RenderingBias="Quality" Color="Black" Direction="270" ShadowDepth="2" Opacity="0.5" />
</Setter.Value>
</Setter>
</Style>
<Style x:Key="IconStyle" TargetType="{x:Type Control}" >
<Setter Property="Margin" Value="6"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="30"/>
</Style>
</ResourceDictionary>
\ No newline at end of file
using FLY.OBJComponents.Client;
using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace ThickTcpUiInWindow
{
class CtMicroGageVm:ICtMicroGageVm
{
#region 延时推送 MARKNO
const int MARKNO_UPDATEERROR = 1;
#endregion
public event PropertyChangedEventHandler PropertyChanged;
public double Thick { get; set; }
public int AD { get; set; }
public int ADMax { get; set; }
public int Position { get; set; }
public int PosLength { get; set; }
public double Posmm { get; set; }
public double Velocity { get; set; }
public string ControllerState { get; set; }
public UInt16 OStatus { get; set; }
public UInt16 IStatus { get; set; }
public bool IsError { get; set; }
/// <summary>
/// 异常消息
/// </summary>
public string ErrMsg { get; set; }
public RelayCommand StopCmd { get; private set; }
public RelayCommand ForwCmd { get; private set; }
public RelayCommand BackwCmd { get; private set; }
public RelayCommand OrgCmd { get; private set; }
DynArea mDynArea;
TDGageServiceClient mTDGageService;
InitParamServiceClient mInitParam;
BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory> mWindow;
DispatcherTimer timer_error;
private int reason_list_index = -1;
public CtMicroGageVm()
{
InitCmd();
}
void InitCmd()
{
StopCmd = new RelayCommand(() =>
{
mTDGageService.StartP2(STARTP2_MODE.STOP);
});
OrgCmd = new RelayCommand(() =>
{
mTDGageService.StartP2(STARTP2_MODE.ORG);
});
ForwCmd = new RelayCommand(() =>
{
mTDGageService.StartP2(STARTP2_MODE.FORW);
});
BackwCmd = new RelayCommand(() =>
{
mTDGageService.StartP2(STARTP2_MODE.BACKW);
});
}
public void Init(
DynArea dynArea,
InitParamServiceClient initParam,
TDGageServiceClient gageService,
BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory> warningReasonWindow)
{
mTDGageService = gageService;
mDynArea = dynArea;
mInitParam = initParam;
mWindow = warningReasonWindow;
Misc.BindingOperations.SetBinding(mDynArea, "Thick", () =>
{
Thick = mDynArea.Thick / 100.0;
});
Misc.BindingOperations.SetBinding(mDynArea, "AD", this, "AD");
Misc.BindingOperations.SetBinding(mDynArea, "ADMax", this, "ADMax");
Misc.BindingOperations.SetBinding(mDynArea, "Position", this, "Position");
Misc.BindingOperations.SetBinding(mDynArea, "Velocity", this, "Velocity");
Misc.BindingOperations.SetBinding(mDynArea, "ControllerState", () =>
{
ThickTcpUiInWindow.Converter.ControllerStateConverter converter = new ThickTcpUiInWindow.Converter.ControllerStateConverter();
ControllerState = (string)converter.Convert(mDynArea.ControllerState, typeof(string), null, null);
});
Misc.BindingOperations.SetBinding(mInitParam, "PosLength", this, "PosLength");
Action action = () =>
{
Posmm = mDynArea.Position * mInitParam.Encoder1_mmpp;
};
Misc.BindingOperations.SetBinding(mDynArea, "Position", action);
Misc.BindingOperations.SetBinding(mInitParam, "Encoder1_mmpp", action);
Misc.BindingOperations.SetBinding(mDynArea, "OStatus", this, "OStatus");
Misc.BindingOperations.SetBinding(mDynArea, "IStatus", this, "IStatus");
//报警原因轮流显示
timer_error = new DispatcherTimer();
timer_error.Interval = TimeSpan.FromSeconds(3);
timer_error.Tick += (s, e) =>
{
reason_list_index--;
if (reason_list_index < 0)
reason_list_index = mWindow.Record.Count();
UpdateError();
};
mWindow.Record.CollectionChanged += Record_CollectionChanged;
mDynArea.PropertyChanged += (s, e) =>
{
if (e.PropertyName == "ServerIsConnected")
{
UpdateError();
}
};
UpdateError();
}
private void Record_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
FObjBase.PollModule.Current.Poll_JustOnce(
new FObjBase.PollModule.PollHandler(delegate ()
{
reason_list_index = mWindow.Record.Count() - 1;
UpdateError();
}), this, MARKNO_UPDATEERROR);
}
void UpdateError()
{
if (!mDynArea.ServerIsConnected)
{
ErrMsg = "服务器连接断开";
IsError = true;
reason_list_index = -1;
timer_error.Stop();
}
else if (mWindow.Record.Count > 0)
{
if (reason_list_index >= mWindow.Record.Count)
reason_list_index = mWindow.Record.Count - 1;
else if (reason_list_index < 0)
reason_list_index = 0;
ErrMsg = mWindow.Record[reason_list_index].Description;
IsError = true;
timer_error.Start();
}
else
{
IsError = false;
ErrMsg = "";
reason_list_index = -1;
timer_error.Stop();
}
}
}
}
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ThickTcpUiInWindow
{
class CtMircoGageVmUt:ICtMicroGageVm
{
public event PropertyChangedEventHandler PropertyChanged;
public double Thick { get; set; }
public int AD { get; set; }
public int ADMax { get; set; }
public int Position { get; set; }
public int PosLength { get; set; }
public double Posmm { get; set; }
public double Velocity { get; set; }
public string ControllerState { get; set; }
public UInt16 OStatus { get; set; }
public UInt16 IStatus { get; set; }
public bool IsError { get; set; }
/// <summary>
/// 异常消息
/// </summary>
public string ErrMsg { get; set; }
#region Command
public RelayCommand StopCmd { get; }
public RelayCommand ForwCmd { get; }
public RelayCommand BackwCmd { get; }
public RelayCommand OrgCmd { get; }
#endregion
}
}
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ThickTcpUiInWindow
{
interface ICtMicroGageVm:INotifyPropertyChanged
{
double Thick { get; set; }
int AD { get; set; }
int ADMax { get; set; }
int Position { get; set; }
int PosLength { get; set; }
double Posmm { get; set; }
double Velocity { get; set; }
string ControllerState { get; set; }
UInt16 OStatus { get; set; }
UInt16 IStatus { get; set; }
bool IsError { get; set; }
/// <summary>
/// 异常消息
/// </summary>
string ErrMsg { get; set; }
RelayCommand StopCmd { get; }
RelayCommand ForwCmd { get; }
RelayCommand BackwCmd { get; }
RelayCommand OrgCmd { get; }
}
}
......@@ -64,6 +64,18 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="LiveCharts">
<HintPath>..\..\dll\LiveCharts.dll</HintPath>
</Reference>
<Reference Include="LiveCharts.Feng">
<HintPath>..\..\dll\LiveCharts.Feng.dll</HintPath>
</Reference>
<Reference Include="LiveCharts.Feng.Wpf">
<HintPath>..\..\dll\LiveCharts.Feng.Wpf.dll</HintPath>
</Reference>
<Reference Include="LiveCharts.Wpf">
<HintPath>..\..\dll\LiveCharts.Wpf.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework.Aero" />
<Reference Include="System" />
<Reference Include="System.Data" />
......@@ -104,6 +116,12 @@
<Compile Include="Converter\ThickConverter.cs" />
<Compile Include="Converter\TimeSpan2MinConverter.cs" />
<Compile Include="Converter\VisibilityConverter.cs" />
<Compile Include="CtMicroGage\CtMicroGage.xaml.cs">
<DependentUpon>CtMicroGage.xaml</DependentUpon>
</Compile>
<Compile Include="CtMicroGage\CtMicroGageVm.cs" />
<Compile Include="CtMicroGage\CtMircoGageVmUt.cs" />
<Compile Include="CtMicroGage\ICtMicroGageVm.cs" />
<Compile Include="FLYLayoutManager.cs" />
<Compile Include="GageCommands.cs" />
<Compile Include="MainEdit\GraphTabItem.cs" />
......@@ -122,9 +140,6 @@
<Compile Include="Page_GetSample.xaml.cs">
<DependentUpon>Page_GetSample.xaml</DependentUpon>
</Compile>
<Compile Include="Page_Grid.xaml.cs">
<DependentUpon>Page_Grid.xaml</DependentUpon>
</Compile>
<Compile Include="Page_Initparam.xaml.cs">
<DependentUpon>Page_Initparam.xaml</DependentUpon>
</Compile>
......@@ -149,8 +164,17 @@
<Compile Include="Page_ScanCorr.xaml.cs">
<DependentUpon>Page_ScanCorr.xaml</DependentUpon>
</Compile>
<Compile Include="PgGrid\IPgGridVm.cs" />
<Compile Include="PgGrid\PgGrid.xaml.cs">
<DependentUpon>PgGrid.xaml</DependentUpon>
</Compile>
<Compile Include="PgGrid\PgGridVm.cs" />
<Compile Include="PgGrid\PgGridVmUt.cs" />
<Compile Include="PgGrid\PgGridXlsxOutput.cs" />
<Compile Include="PgGrid\SeriesInfo.cs" />
<Compile Include="SysParam.cs" />
<Compile Include="TDGage.cs" />
<Compile Include="Theme\Styles.cs" />
<Compile Include="UIModule\COMMON.cs" />
<Compile Include="UIModule\DynAreaSample.xaml.cs">
<DependentUpon>DynAreaSample.xaml</DependentUpon>
......@@ -224,6 +248,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="CtMicroGage\CtMicroGage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="CtMicroGage\CtMicroGageStyle.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Culture\StringResource.en-US.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......@@ -252,10 +284,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Page_Grid.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Page_Initparam.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......@@ -288,6 +316,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PgGrid\PgGrid.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="PgGrid\PgGridStyle.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Theme\Styles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UIModule\DynAreaSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......@@ -535,11 +575,23 @@
<Resource Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EPPlus">
<Version>4.5.3.2</Version>
</PackageReference>
<PackageReference Include="Fody">
<Version>4.2.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MahApps.Metro">
<Version>2.0.0-alpha0316</Version>
</PackageReference>
<PackageReference Include="MahApps.Metro.IconPacks">
<Version>3.0.0-alpha0213</Version>
</PackageReference>
<PackageReference Include="MvvmLight">
<Version>5.4.1.1</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>2.6.1</Version>
</PackageReference>
......
using GalaSoft.MvvmLight.Command;
using LiveCharts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ThickTcpUiInWindow
{
/// <summary>
///
/// </summary>
interface IPgGridVm : INotifyPropertyChanged
{
/// <summary>
/// 目标位置 单位:脉冲
/// </summary>
int TargetPos { get; set; }
/// <summary>
/// 目标位置 单位:mm
/// </summary>
double TargetMm { get; }
/// <summary>
/// AD值模式
/// </summary>
bool IsADMode { get; set; }
/// <summary>
/// 最多6条曲线
/// </summary>
ObservableCollection<SeriesInfo> SeriesInfos { get; }
#region 曲线
Func<double, string> XFormatter { get; }
Func<double, string> YFormatter { get; }
double XUpper { get; set; }
double XLower { get; set; }
double YUpper { get; set; }
double YLower { get; set; }
double XMax { get; }
double XMin { get; }
double YMax { get; }
double YMin { get; }
double SectionValue { get; }
double SectionWidth { get; }
SeriesCollection Series { get; }
#endregion
#region 测量
/// <summary>
/// 测量开始位置 单位:脉冲
/// </summary>
int MeasureValuePos { get; set; }
/// <summary>
/// 测量开始位置 单位:mm
/// </summary>
double MeasureValueMm { get; }
/// <summary>
/// 测量宽度 单位:脉冲
/// </summary>
int MeasureWidthPos { get; set; }
/// <summary>
/// 测量宽度 单位:mm
/// </summary>
double MeasureWidthMm { get; }
#endregion
#region command
RelayCommand RunToCmd { get; }
RelayCommand GetFDataCmd { get; }
RelayCommand GetBDataCmd { get; }
RelayCommand ClearCmd { get; }
RelayCommand MeasureCmd { get; }
RelayCommand SaveCmd { get; }
RelayCommand<SeriesInfo> SelectCmd { get; }
#endregion
#region 输出使用
int PosOfGrid { get; }
double Mmpp { get; }
#endregion
}
}
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.IO;
using System.Net;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.Client;
using FLY.Thick.Base.IService;
using FObjBase;
using System.Collections.ObjectModel;
using LiveCharts.Wpf;
using LiveCharts;
using LiveCharts.Helpers;
using FLY.OBJComponents.Client;
namespace ThickTcpUiInWindow
{
/// <summary>
/// PgGrid.xaml 的交互逻辑
/// </summary>
public partial class PgGrid : Page
{
PgGridVm viewModel;
/// <summary>
///
/// </summary>
public PgGrid()
{
InitializeComponent();
viewModel = new PgGridVm();
this.DataContext = viewModel;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="initParam"></param>
/// <param name="gageService"></param>
/// <param name="flyADService"></param>
/// <param name="dynArea"></param>
/// <param name="warningReasonWindow"></param>
public void Init(
InitParamServiceClient initParam,
TDGageServiceClient gageService,
FlyADServiceClient flyADService,
DynArea dynArea,
BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory> warningReasonWindow
)
{
viewModel.Init(initParam, gageService, flyADService);
mircoGage.Init(dynArea, initParam, gageService, warningReasonWindow);
}
private void UIElement_OnMouseMove(object sender, MouseEventArgs e)
{
if (!isDown)
return;
var vm = viewModel;
var series = vm.SeriesInfos.First(info => info.IsSelected).Series;
var chart = (LiveCharts.Wpf.CartesianChart)sender;
//lets get where the mouse is at our chart
var mouseCoordinate = e.GetPosition(chart);
//now that we know where the mouse is, lets use
//ConverToChartValues extension
//it takes a point in pixes and scales it to our chart current scale/values
var p = chart.ConvertToChartValues(mouseCoordinate);
//var series = chart.Series[0];
var closetsPoint = series.ClosestPointTo(p.X, AxisOrientation.X);
if (closetsPoint == null)
return;
xEnd = closetsPoint.X;
vm.MeasureValuePos = (int)(Math.Min(xBegin, xEnd) * vm.PosOfGrid);
vm.MeasureWidthPos = (int)((Math.Abs(xEnd - xBegin) + 1) * vm.PosOfGrid);
}
private double xBegin;
private double xEnd;
private bool isDown = false;
private void UIElement_MouseDown(object sender, MouseButtonEventArgs e)
{
isDown = true;
var vm = viewModel;
var series = vm.SeriesInfos.First(info => info.IsSelected).Series;
var chart = (LiveCharts.Wpf.CartesianChart)sender;
var mouseCoordinate = e.GetPosition(chart);
var p = chart.ConvertToChartValues(mouseCoordinate);
//var series = chart.Series[0];
var closetsPoint = series. ClosestPointTo(p.X, AxisOrientation.X);
if (closetsPoint == null)
{
isDown = false;
return;
}
xBegin = closetsPoint.X;
vm.MeasureValuePos = (int)(xBegin * vm.PosOfGrid);
}
private void UIElement_MouseUp(object sender, MouseButtonEventArgs e)
{
isDown = false;
var vm = viewModel;
var series = vm.SeriesInfos.First(info => info.IsSelected).Series;
var chart = (LiveCharts.Wpf.CartesianChart)sender;
//lets get where the mouse is at our chart
var mouseCoordinate = e.GetPosition(chart);
//now that we know where the mouse is, lets use
//ConverToChartValues extension
//it takes a point in pixes and scales it to our chart current scale/values
var p = chart.ConvertToChartValues(mouseCoordinate);
//for X in this case we will only highlight the closest point.
//lets use the already defined ClosestPointTo extension
//it will return the closest ChartPoint to a value according to an axis.
//here we get the closest point to p.X according to the X axis
//var series = chart.Series[0];
var closetsPoint = series.ClosestPointTo(p.X, AxisOrientation.X);
if (closetsPoint == null)
return;
xEnd = closetsPoint.X;
vm.MeasureValuePos = (int)(Math.Min(xBegin, xEnd) * vm.PosOfGrid);
vm.MeasureWidthPos = (int)((Math.Abs(xEnd - xBegin) + 1) * vm.PosOfGrid);
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:FLY.Thick.Normal.UI.Client"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Dictionary_MyStyle.xaml"/>
<ResourceDictionary Source="pack://application:,,,/ThickTcpUiInWindow;component/Converter/Dictionary_MyConv.xaml"/>
<!--<ResourceDictionary Source="pack://application:,,,/ThickTcpUiInWindow;component/Culture/StringResource.zh-CN.xaml"/>-->
</ResourceDictionary.MergedDictionaries>
<Style x:Key="AccentedSquareButtonStyle2" TargetType="Button" BasedOn="{StaticResource AccentedSquareButtonStyle}" >
<Setter Property="FontSize" Value="18"/>
<Setter Property="Width" Value="120"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Margin" Value="5"/>
</Style>
<Style x:Key="SquareButtonStyle2" TargetType="Button" BasedOn="{StaticResource SquareButtonStyle}" >
<Setter Property="FontSize" Value="18"/>
<Setter Property="Width" Value="120"/>
<Setter Property="Height" Value="40"/>
<Setter Property="Margin" Value="5"/>
</Style>
<SolidColorBrush x:Key="axisLabelColor" Color="DarkSlateBlue"/>
<SolidColorBrush x:Key="axisSeparatorColor" Color="DarkSlateBlue" Opacity="0.5"/>
<DropShadowEffect x:Key="CardShadow" Color="#303030" Opacity=".25" BlurRadius="5" ShadowDepth="3"/>
<Style x:Key="CardTitleStyle" TargetType="TextBlock">
<Setter Property="Background" Value="#FFC107"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Padding" Value="20 5"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
<Style x:Key="CardBorderStyle" TargetType="Border">
<Setter Property="Margin" Value="5"/>
<Setter Property="Background" Value="White"/>
<Setter Property="CornerRadius" Value="3"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="#EBEBEB"/>
<Setter Property="Effect" Value="{StaticResource CardShadow}"/>
</Style>
<Style x:Key="AxisSectionStyle" TargetType="lvc:AxisSection" >
<Setter Property="StrokeThickness" Value="1"/>
<Setter Property="DataLabel" Value="False"/>
<Setter Property="DisableAnimations" Value="True"/>
<Setter Property="DataLabelForeground" Value="White"/>
<Setter Property="Opacity" Value="0.1"/>
<Setter Property="Stroke" Value="#FFFDC8C8"/>
<Setter Property="Fill" Value="#59F7D8D8"/>
<!--<Setter Property="Fill" Value="Orange" />-->
</Style>
<Style TargetType="{x:Type ToggleButton}" x:Key="CheckStyle" >
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="{TemplateBinding Background}" CornerRadius="2" >
<iconPacks:PackIconMaterial x:Name="icon" Kind="CheckboxBlankOutline" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="icon" Property="Kind" Value="CheckboxMarkedOutline"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
\ No newline at end of file
This diff is collapsed.
using GalaSoft.MvvmLight.Command;
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace ThickTcpUiInWindow
{
class PgGridVmUt : IPgGridVm
{
public event PropertyChangedEventHandler PropertyChanged;
#region IPgGridVm Property
/// <summary>
/// 目标位置 单位:脉冲
/// </summary>
public int TargetPos { get; set; }
/// <summary>
/// 目标位置 单位:mm
/// </summary>
public double TargetMm => TargetPos * Mmpp;
/// <summary>
/// AD值模式
/// </summary>
public bool IsADMode { get; set; }
/// <summary>
/// 最多6条曲线
/// </summary>
public ObservableCollection<SeriesInfo> SeriesInfos { get; } = new ObservableCollection<SeriesInfo>();
#region 曲线
public Func<double, string> XFormatter { get; private set; }
public Func<double, string> YFormatter { get; private set; }
public double XUpper { get; set; } = 1024;
public double XLower { get; set; } = 0;
public double YUpper { get; set; } = double.NaN;
public double YLower { get; set; } = double.NaN;
public double XMax { get; private set; } = 1024;
public double XMin { get; private set; } = 0;
public double YMax { get; private set; } = double.NaN;
public double YMin { get; private set; } = double.NaN;
public double SectionValue => MeasureValuePos / PosOfGrid;
public double SectionWidth => MeasureWidthPos / PosOfGrid;
public SeriesCollection Series { get; } = new SeriesCollection();
#endregion
#region 测量
/// <summary>
/// 测量开始位置 单位:脉冲
/// </summary>
public int MeasureValuePos { get; set; }
/// <summary>
/// 测量开始位置 单位:mm
/// </summary>
public double MeasureValueMm => MeasureValuePos * Mmpp;
/// <summary>
/// 测量宽度 单位:脉冲
/// </summary>
public int MeasureWidthPos { get; set; }
/// <summary>
/// 测量宽度 单位:mm
/// </summary>
public double MeasureWidthMm => MeasureWidthPos * Mmpp;
#endregion
#endregion
#region command
public RelayCommand RunToCmd { get; }
public RelayCommand GetFDataCmd { get; }
public RelayCommand GetBDataCmd { get; }
public RelayCommand ClearCmd { get; }
public RelayCommand MeasureCmd { get; }
public RelayCommand SaveCmd { get; }
public RelayCommand<SeriesInfo> SelectCmd { get; }
#endregion
public int PosOfGrid { get; set; } = 10;
public double Mmpp { get; set; } = 0.1;
public PgGridVmUt()
{
#region 与数据无关界面参数
XFormatter = (x) =>
{
int index = (int)x;
int pos = index * PosOfGrid;
int mm = (int)(pos * Mmpp);
return $"{pos}\n{mm}mm";
};
YFormatter = (y) =>
{
if (IsADMode)
{
return $"{y}";
}
else
{
return $"{y:F1}";
}
};
for (int i = 0; i < 6; i++)
{
SeriesInfo info = new SeriesInfo()
{
Title = $"{i}",
Fill = Theme.Styles.GetForeground(i),
};
LineSeries lineSeries = new LineSeries
{
StrokeThickness = 2,
Fill = new SolidColorBrush(System.Windows.Media.Colors.Transparent),
PointGeometry = null
};
lineSeries.SetBinding(LineSeries.StrokeProperty, "Fill");
lineSeries.DataContext = info;
Series.Add(lineSeries);
info.Series = lineSeries;
SeriesInfos.Add(info);
}
#endregion
IsADMode = false;
UpdateADMode();
//-----------------------------------------------------------------
//虚拟数据
TargetPos = 800;
MeasureValuePos = 7000;
MeasureWidthPos = 500;
Random r = new Random();
for (int i = 0; i < 4; i++)
{
var info = SeriesInfos[i];
int period = r.Next(200, 600);
info.ADs.Clear();
info.Thicks.Clear();
info.ADs.AddRange(GetADs(period));
info.Thicks.AddRange(GetValues(info.ADs));
info.IsBackw = i % 2 == 0;
}
SeriesInfos[0].IsSelected = true;
UpdateMeasure();
}
void UpdateADMode()
{
if (IsADMode)
{
foreach (var info in SeriesInfos)
info.Series.SetBinding(LineSeries.ValuesProperty, "ADs");
}
else
{
foreach (var info in SeriesInfos)
info.Series.SetBinding(LineSeries.ValuesProperty, "Thicks");
}
}
void UpdateMeasure()
{
int begin_grid = MeasureValuePos / PosOfGrid;
int end_grid = (MeasureValuePos+MeasureWidthPos) / PosOfGrid;
foreach (var info in SeriesInfos)
{
if (IsADMode)
{
double sum = 0;
int cnt = 0;
for (int i = begin_grid; i <= end_grid && i < info.ADs.Count() && i >= 0; i++)
{
sum += info.ADs[i];
cnt++;
}
if (cnt == 0)
info.Avg = double.NaN;
else
info.Avg = sum / cnt;
}
else
{
double sum = 0;
int cnt = 0;
for (int i = begin_grid; i <= end_grid && i < info.Thicks.Count() && i >= 0; i++)
{
sum += info.Thicks[i];
cnt++;
}
if (cnt == 0)
info.Avg = double.NaN;
else
info.Avg = sum / cnt;
}
}
}
IEnumerable<double> GetADs(int period)
{
List<double> ads = new List<double>();
Random r = new Random();
for (int i = 0; i < 1000; i++)
{
if (i < 100 || i > 800)
{
ads.Add(double.NaN);
}
else
{
int ad = (int)(Math.Sin(Math.PI * 2 * i / period) * 2000) + r.Next(200) - 100 + 10000;
ads.Add(ad);
}
}
return ads;
}
IEnumerable<double> GetValues(IEnumerable<double> ADs)
{
return ADs.Select(ad =>
{
if (double.IsNaN(ad))
return double.NaN;
else
return ad / 100.0;
});
}
}
}
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace ThickTcpUiInWindow
{
/// <summary>
///
/// </summary>
class PgGridOutput
{
IPgGridVm viewModel;
/// <summary>
///
/// </summary>
/// <param name="viewModel"></param>
public void Init(IPgGridVm viewModel)
{
this.viewModel = viewModel;
}
/// <summary>
///
/// </summary>
/// <param name="filepath"></param>
public async void SaveToXlsx(string filepath)
{
if (viewModel.SeriesInfos.All(s => s.ADs.Count() == 0))
{
FLY.ControlLibrary.Window_WarningTip.Show("输出失败", "没有任何数据", TimeSpan.FromSeconds(2));
return;
//await ((MetroWindow)Application.Current.MainWindow).ShowMessageAsync("输出失败",
// "没有任何数据");
//return;
}
FLY.ControlLibrary.Window_Tip.Show("请等待...", "开始导出");
//var controller = await ((MetroWindow)Application.Current.MainWindow).ShowProgressAsync("请等待...", "开始导出",
// settings: new MetroDialogSettings()
// {
// NegativeButtonText = "停止",
// AnimateShow = false,
// AnimateHide = false,
// });
////controller.SetCancelable(true);
//controller.SetIndeterminate();
await Task.Factory.StartNew(() =>
{
using (ExcelPackage p = new ExcelPackage(new FileInfo(filepath)))
{
SaveToXlsxThicks(p);
SaveToXlsxAD(p);
p.Save();
}
});
//await controller.CloseAsync();
//await ((MetroWindow)Application.Current.MainWindow).ShowMessageAsync("输出成功",
// filepath);
FLY.ControlLibrary.Window_Tip.ShowShortTime("输出成功", filepath);
}
void SaveToXlsxAD(ExcelPackage p)
{
var seriesInfos = viewModel.SeriesInfos;
int posOfGrid = viewModel.PosOfGrid;
double mmpp = viewModel.Mmpp;
var ws = p.Workbook.Worksheets.Add("AD数据");
ws.Cells[1, 1].Value = "脉冲";
ws.Cells[1, 2].Value = "mm";
int max_pos_count = 0;
for (int i = 0; i < seriesInfos.Count(); i++)
{
var info = seriesInfos[i];
var values = info.ADs;
int col = 3 + i;
ws.Cells[1, col].Value = $"{info.Header}";
for (int j = 0; j < values.Count(); j++)
{
if(!double.IsNaN(values[j]))
ws.Cells[2 + j, col].Value = (int)values[j];
}
if (values.Count() <= max_pos_count)
continue;
// 脉冲 & mm
for (int j = max_pos_count; j < values.Count(); j++)
{
ws.Cells[2 + j, 1].Value = j * posOfGrid;
ws.Cells[2 + j, 2].Value = j * posOfGrid * mmpp;
}
max_pos_count = values.Count();
}
//设置格式
//格式
ws.Column(1).Style.Numberformat.Format = "0";
ws.Column(2).Style.Numberformat.Format = "0";
for (int i = 0; i < seriesInfos.Count(); i++)
{
int col = 3 + i;
ws.Column(col).Style.Numberformat.Format = "0";
}
}
void SaveToXlsxThicks(ExcelPackage p)
{
var seriesInfos = viewModel.SeriesInfos;
int posOfGrid = viewModel.PosOfGrid;
double mmpp = viewModel.Mmpp;
var ws = p.Workbook.Worksheets.Add("Thick数据");
ws.Cells[1, 1].Value = "脉冲";
ws.Cells[1, 2].Value = "mm";
int max_pos_count = 0;
for (int i = 0; i < seriesInfos.Count(); i++)
{
var info = seriesInfos[i];
var values = info.Thicks;
int col = 3 + i;
ws.Cells[1, col].Value = $"{info.Header}";
for (int j = 0; j < values.Count(); j++)
{
if (!double.IsNaN(values[j]))
ws.Cells[2 + j, col].Value = values[j];
}
if (values.Count() <= max_pos_count)
continue;
// 脉冲 & mm
for (int j = max_pos_count; j < values.Count(); j++)
{
ws.Cells[2 + j, 1].Value = j * posOfGrid;
ws.Cells[2 + j, 2].Value = j * posOfGrid * mmpp;
}
max_pos_count = values.Count();
}
//设置格式
//格式
ws.Column(1).Style.Numberformat.Format = "0";
ws.Column(2).Style.Numberformat.Format = "0";
for (int i = 0; i < seriesInfos.Count(); i++)
{
int col = 3 + i;
ws.Column(col).Style.Numberformat.Format = "0.00";
}
}
}
}
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace ThickTcpUiInWindow
{
class SeriesInfo : INotifyPropertyChanged
{
/// <summary>
/// 显示的标题,肯定是 0,1,2,3,4,5.。。。
/// </summary>
public string Title { get; set; }
/// <summary>
/// 是反向数据
/// </summary>
public bool? IsBackw { get; set; }
public string Header
{
get {
if (IsBackw == null)
return Title;
else
{
if (IsBackw == false)
return $"{Title} 正";
else
return $"{Title} 反";
}
}
}
/// <summary>
/// 颜色
/// </summary>
public Brush Fill { get; set; }
/// <summary>
/// 当前被选中
/// </summary>
public bool IsSelected { get; set; }
/// <summary>
/// 对应的曲线
/// </summary>
public LineSeries Series { get; set; }
/// <summary>
/// 测量区平均值
/// </summary>
public double Avg { get; set; } = double.NaN;
/// <summary>
/// 当非AD值模式时,显示的厚度值
/// </summary>
public ChartValues<double> Thicks { get; } = new ChartValues<double>();
/// <summary>
/// 当为AD值模式时,显示的AD值
/// </summary>
public ChartValues<double> ADs { get; } = new ChartValues<double>();
public void Clear()
{
Thicks.Clear();
ADs.Clear();
Avg = double.NaN;
IsBackw = null;
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
namespace ThickTcpUiInWindow.Theme
{
/// <summary>
///
/// </summary>
public static class Styles
{
/// <summary>
/// 获取随机颜色
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public static Brush GetForeground(int index)
{
IEnumerable<SolidColorBrush> randomColors = App.Current.FindResource("RandomColors") as IEnumerable<SolidColorBrush>;
return randomColors.ElementAt(index % randomColors.Count());
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="UIElement" x:Key="GridStyle_ButtonShadow">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="10" RenderingBias="Quality" Color="Black" Direction="270" ShadowDepth="2" Opacity="0.5" />
</Setter.Value>
</Setter>
</Style>
<Style TargetType="UIElement" x:Key="ButtonShadowStyle">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="10" RenderingBias="Quality" Color="Black" Direction="270" ShadowDepth="2" Opacity="0.5" />
</Setter.Value>
</Setter>
</Style>
<x:Array x:Key="RandomColors" Type="SolidColorBrush">
<SolidColorBrush>#2195f2</SolidColorBrush>
<SolidColorBrush>#f34336</SolidColorBrush>
<SolidColorBrush>#fec007</SolidColorBrush>
<SolidColorBrush>#607d8a</SolidColorBrush>
<SolidColorBrush>#e81e63</SolidColorBrush>
<SolidColorBrush>#4cae50</SolidColorBrush>
<SolidColorBrush>#3f51b4</SolidColorBrush>
<SolidColorBrush>#ccdb39</SolidColorBrush>
</x:Array>
<SolidColorBrush x:Key="AreaColors0">#f34336</SolidColorBrush>
<SolidColorBrush x:Key="AreaColors1">#fec007</SolidColorBrush>
<SolidColorBrush x:Key="AreaColors2">#4cae50</SolidColorBrush>
<SolidColorBrush x:Key="AreaColors3">#2195f2</SolidColorBrush>
<SolidColorBrush x:Key="AreaColors4">DarkSlateBlue</SolidColorBrush>
</ResourceDictionary>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
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