首次上传
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using MECF.Framework.UI.Client.ClientBase;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core
|
||||
{
|
||||
public class BusyIndicateableUiViewModelBase : UiViewModelBase
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private bool _isBusy;
|
||||
private string _busyIndicatorMessage;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 返回ViewModel绑定的视图对象。
|
||||
/// </summary>
|
||||
public UserControl View { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回忙信息。
|
||||
/// </summary>
|
||||
public string BusyIndicatorContent
|
||||
{
|
||||
get => _busyIndicatorMessage;
|
||||
set
|
||||
{
|
||||
_busyIndicatorMessage = value;
|
||||
NotifyOfPropertyChange(nameof(BusyIndicatorContent));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回视图是否正忙。
|
||||
/// </summary>
|
||||
public bool IsBusy
|
||||
{
|
||||
get => _isBusy;
|
||||
set
|
||||
{
|
||||
_isBusy = value;
|
||||
NotifyOfPropertyChange(nameof(IsBusy));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void OnViewLoaded(object _view)
|
||||
{
|
||||
base.OnViewLoaded(_view);
|
||||
View = (UserControl)_view;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消操作。
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public virtual void Cancel()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Media;
|
||||
using SciChart.Charting.Visuals.RenderableSeries;
|
||||
using SciChart.Data.Numerics;
|
||||
using Sicentury.Core.Tree;
|
||||
using DrawingColor = System.Drawing.Color;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core.Charting
|
||||
{
|
||||
/// <summary>
|
||||
/// 需要显示在图表中的项目列表。
|
||||
/// </summary>
|
||||
public class ChartingLineSeriesCollection : ObservableCollection<IRenderableSeries>
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private Queue<Color> _colorQueue;
|
||||
private readonly Random _colorRandom;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ChartingLineSeriesCollection(string displayName)
|
||||
{
|
||||
_colorQueue = GetNewColorPatternQueue();
|
||||
_colorRandom = new Random();
|
||||
DisplayName = displayName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string DisplayName { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 获取颜色列队。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static Queue<Color> GetNewColorPatternQueue()
|
||||
{
|
||||
var colorList = new List<DrawingColor>(new DrawingColor[]
|
||||
{
|
||||
DrawingColor.Red, DrawingColor.Orange, DrawingColor.Yellow, DrawingColor.Green, DrawingColor.Blue,
|
||||
DrawingColor.Pink, DrawingColor.Purple, DrawingColor.Aqua,
|
||||
DrawingColor.Bisque, DrawingColor.Brown, DrawingColor.BurlyWood, DrawingColor.CadetBlue,
|
||||
DrawingColor.CornflowerBlue, DrawingColor.DarkBlue, DrawingColor.DarkCyan, DrawingColor.DarkGray,
|
||||
DrawingColor.DarkGreen, DrawingColor.DarkKhaki,
|
||||
DrawingColor.DarkMagenta, DrawingColor.DarkOliveGreen, DrawingColor.DarkOrange,
|
||||
DrawingColor.DarkSeaGreen, DrawingColor.DarkSlateBlue, DrawingColor.DarkSlateGray,
|
||||
DrawingColor.DarkViolet, DrawingColor.DeepPink,
|
||||
DrawingColor.DeepSkyBlue, DrawingColor.DimGray, DrawingColor.DodgerBlue, DrawingColor.ForestGreen,
|
||||
DrawingColor.Gold,
|
||||
DrawingColor.Gray, DrawingColor.GreenYellow, DrawingColor.HotPink, DrawingColor.Indigo,
|
||||
DrawingColor.Khaki, DrawingColor.LightBlue,
|
||||
DrawingColor.LightCoral, DrawingColor.LightGreen, DrawingColor.LightPink, DrawingColor.LightSalmon,
|
||||
DrawingColor.LightSkyBlue,
|
||||
DrawingColor.LightSlateGray, DrawingColor.LightSteelBlue, DrawingColor.LimeGreen,
|
||||
DrawingColor.MediumOrchid, DrawingColor.MediumPurple,
|
||||
DrawingColor.MediumSeaGreen, DrawingColor.MediumSlateBlue, DrawingColor.MediumSpringGreen,
|
||||
DrawingColor.MediumTurquoise, DrawingColor.Moccasin, DrawingColor.NavajoWhite, DrawingColor.Olive,
|
||||
DrawingColor.OliveDrab, DrawingColor.OrangeRed,
|
||||
DrawingColor.Orchid, DrawingColor.PaleGoldenrod, DrawingColor.PaleGreen,
|
||||
DrawingColor.PeachPuff, DrawingColor.Peru, DrawingColor.Plum, DrawingColor.PowderBlue,
|
||||
DrawingColor.RosyBrown, DrawingColor.RoyalBlue,
|
||||
DrawingColor.SaddleBrown, DrawingColor.Salmon, DrawingColor.SeaGreen, DrawingColor.Sienna,
|
||||
DrawingColor.SkyBlue, DrawingColor.SlateBlue, DrawingColor.SlateGray, DrawingColor.SpringGreen,
|
||||
DrawingColor.Teal, DrawingColor.Aquamarine,
|
||||
DrawingColor.Tomato, DrawingColor.Turquoise, DrawingColor.Violet, DrawingColor.Wheat,
|
||||
DrawingColor.YellowGreen
|
||||
});
|
||||
|
||||
return new Queue<Color>(colorList.Select(x => Color.FromRgb(x.R, x.G, x.B)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 复位色板。
|
||||
/// </summary>
|
||||
/// <param name="isRandomColor"></param>
|
||||
private void ResetColorQueue(bool isRandomColor = false)
|
||||
{
|
||||
if (isRandomColor)
|
||||
{
|
||||
_colorQueue.Clear();
|
||||
for (var i = 0; i < 200; i++)
|
||||
{
|
||||
_colorQueue.Enqueue(Color.FromRgb(
|
||||
(byte)_colorRandom.Next(0, 255),
|
||||
(byte)_colorRandom.Next(0, 255),
|
||||
(byte)_colorRandom.Next(0, 255)));
|
||||
}
|
||||
}
|
||||
else
|
||||
_colorQueue = GetNewColorPatternQueue();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从色板中获取一个颜色。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private Color GetColor()
|
||||
{
|
||||
if (!_colorQueue.Any())
|
||||
ResetColorQueue();
|
||||
|
||||
var dc = _colorQueue.Dequeue();
|
||||
return Color.FromRgb(dc.R, dc.G, dc.B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置图表序列的颜色。
|
||||
/// </summary>
|
||||
public void ResetColors()
|
||||
{
|
||||
ResetColorQueue();
|
||||
foreach (var series in this)
|
||||
{
|
||||
series.Stroke = GetColor();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 追加新的查询数据到列表。
|
||||
/// </summary>
|
||||
/// <param name="collection"></param>
|
||||
/// <param name="antiAliasing"></param>
|
||||
/// <param name="resamplingMode"></param>
|
||||
/// <returns>成功追加的项目。</returns>
|
||||
public List<IRenderableSeries> Append(List<TreeNode> collection, bool antiAliasing = true,
|
||||
ResamplingMode resamplingMode = ResamplingMode.MinMax)
|
||||
{
|
||||
var existed = this.Select(x => ((SicFastLineSeries)x).BackendParameterNode);
|
||||
var toBeAdded = collection.Except(existed).ToList();
|
||||
|
||||
foreach (var node in toBeAdded)
|
||||
{
|
||||
var line = new SicFastLineSeries(node.FullName)
|
||||
{
|
||||
AntiAliasing = antiAliasing,
|
||||
ResamplingMode = resamplingMode,
|
||||
BackendParameterNode = node
|
||||
};
|
||||
|
||||
node.ClearStatistic();
|
||||
|
||||
Add(line);
|
||||
}
|
||||
|
||||
// 清除本次追加的曲线数据,否则不可添加新数据点。
|
||||
var toBeCleaned =
|
||||
this.Where(x =>
|
||||
collection.Select(t => t.FullName)
|
||||
.Contains(x.DataSeries.SeriesName))
|
||||
.Cast<SicFastLineSeries>()
|
||||
.ToList();
|
||||
foreach (var line in toBeCleaned)
|
||||
{
|
||||
line.DataSeries.Clear();
|
||||
line.BackendParameterNode?.ClearStatistic();
|
||||
}
|
||||
|
||||
return toBeCleaned.Cast<IRenderableSeries>().ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定的<see cref="TreeNode"/>列表重新整理项目。
|
||||
/// <para>该方法提供一种快速更新列表的方法,尽量避免DataGrid刷新造成的UI卡顿问题。</para>
|
||||
/// </summary>a
|
||||
/// <param name="collection"></param>
|
||||
/// <param name="antiAliasing"></param>
|
||||
/// <param name="resamplingMode"></param>
|
||||
public void ReArrange(List<TreeNode> collection, bool antiAliasing = true,
|
||||
ResamplingMode resamplingMode = ResamplingMode.MinMax)
|
||||
{
|
||||
// 剔除本次没有选择但存在于列表中的项目。
|
||||
|
||||
// 筛选本次选择并已存在于列表中的项目
|
||||
var toBeKept = this.Where(x =>
|
||||
collection.Select(t => t.FullName).Contains(x.DataSeries.SeriesName));
|
||||
|
||||
// 删除本次没有选择的项目。
|
||||
var toBeRemoved = this.Except(toBeKept).ToList();
|
||||
foreach (var t in toBeRemoved)
|
||||
this.Remove(t);
|
||||
|
||||
// 筛选未存在于列表中的ParameterNode
|
||||
var toBeAdded = collection
|
||||
.Except(collection.Where(x => this.Select(s => s.DataSeries.SeriesName).Contains(x.FullName))).ToList();
|
||||
|
||||
foreach (var node in toBeAdded)
|
||||
{
|
||||
var line2D = new SicFastLineSeries(node.FullName)
|
||||
{
|
||||
AntiAliasing = antiAliasing,
|
||||
ResamplingMode = resamplingMode,
|
||||
BackendParameterNode = node
|
||||
};
|
||||
Add(line2D);
|
||||
}
|
||||
|
||||
this.ToList().ForEach(x =>
|
||||
{
|
||||
x.DataSeries.Clear();
|
||||
((SicFastLineSeries)x)?.BackendParameterNode?.ClearStatistic();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void SetFifoParam()
|
||||
{
|
||||
var dataSeries = this.Select(x => x.DataSeries).ToList();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrided Methods
|
||||
|
||||
|
||||
protected override void InsertItem(int index, IRenderableSeries item)
|
||||
{
|
||||
if(item != null)
|
||||
item.Stroke = GetColor();
|
||||
|
||||
base.InsertItem(index, item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\DataLogs\Core\SicFastLineDataSeries.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-02
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details Cross-Thread operation allowed.
|
||||
*
|
||||
* *****************************************************************************/
|
||||
|
||||
using System;
|
||||
using DocumentFormat.OpenXml.Office2013.Drawing.ChartStyle;
|
||||
using SciChart.Charting.Model.DataSeries;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core.Charting
|
||||
{
|
||||
public class SicFastLineDataSeries : XyDataSeries<DateTime, double>
|
||||
{
|
||||
|
||||
#region Variables
|
||||
|
||||
private double _factor = 1.0;
|
||||
private double _offset = 0.0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public double Factor
|
||||
{
|
||||
get => _factor;
|
||||
set
|
||||
{
|
||||
_factor = value;
|
||||
UpdateChartSeriesValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public double Offset
|
||||
{
|
||||
get => _offset;
|
||||
set
|
||||
{
|
||||
_offset = value;
|
||||
UpdateChartSeriesValue();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// /
|
||||
/// </summary>
|
||||
public void UpdateChartSeriesValue()
|
||||
{
|
||||
using (SuspendUpdates())
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
var y = (Metadata[i] as ParameterNodePoint)?.Value;
|
||||
if (y == null)
|
||||
continue;
|
||||
|
||||
Update(i, (double)y * Factor + Offset);
|
||||
}
|
||||
|
||||
|
||||
//var dataSeries = DataSeries as XyDataSeries<DateTime, double>;
|
||||
//for (var index = 0; index < dataSeries.Count; ++index)
|
||||
// dataSeries.Update(index, _queueRawData.ElementAt(index).Item2 * _dataFactor + _dataOffset);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\DataLogs\Core\SicFastLineSeries.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-02
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details Cross-Thread operation allowed.
|
||||
*
|
||||
* *****************************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Media;
|
||||
using SciChart.Charting.Visuals.RenderableSeries;
|
||||
using Sicentury.Core.Tree;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core.Charting
|
||||
{
|
||||
public class SicFastLineSeries : FastLineRenderableSeries, INotifyPropertyChanged
|
||||
{
|
||||
private double _dataFactor = 1.0;
|
||||
private double _dataOffset = 0.0;
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SicFastLineSeries(string dataName)
|
||||
: this(dataName, dataName, Colors.Black)
|
||||
{
|
||||
}
|
||||
|
||||
public SicFastLineSeries(string dataName, string displayName, Color seriesColor, int? fifoCapacity = null)
|
||||
{
|
||||
UniqueId = Guid.NewGuid().ToString();
|
||||
Stroke = seriesColor;
|
||||
IsVisible = true;
|
||||
LineThickness = 1.0;
|
||||
|
||||
XAxisId = "DefaultAxisId";
|
||||
YAxisId = "DefaultAxisId";
|
||||
|
||||
DataFactor = 1.0;
|
||||
DataOffset = 0.0;
|
||||
|
||||
DataSeries = new SicFastLineDataSeries()
|
||||
{
|
||||
SeriesName = dataName,
|
||||
FifoCapacity = fifoCapacity,
|
||||
Factor = DataFactor,
|
||||
Offset = DataOffset
|
||||
};
|
||||
|
||||
//! 注意目前的程序要求 DataSeries.SeriesName 必须等于 DataName.
|
||||
DisplayName = displayName;
|
||||
DataName = dataName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public string UniqueId { get; }
|
||||
|
||||
public string DataName { get; }
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get => DataSeries.SeriesName;
|
||||
set => DataSeries.SeriesName = value;
|
||||
}
|
||||
|
||||
public double LineThickness
|
||||
{
|
||||
get => StrokeThickness;
|
||||
set
|
||||
{
|
||||
var num = Convert.ToInt32(value);
|
||||
if (num < 1)
|
||||
num = 1;
|
||||
if (num > 100)
|
||||
num = 100;
|
||||
StrokeThickness = num;
|
||||
InvokePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public double DataFactor
|
||||
{
|
||||
get => _dataFactor;
|
||||
set
|
||||
{
|
||||
if (Math.Abs(_dataFactor - value) <= 0.001)
|
||||
return;
|
||||
_dataFactor = value;
|
||||
GetDataSeries().Factor = _dataFactor;
|
||||
InvokePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public double DataOffset
|
||||
{
|
||||
get => _dataOffset;
|
||||
set
|
||||
{
|
||||
if (Math.Abs(_dataOffset - value) <= 0.001)
|
||||
return;
|
||||
_dataOffset = value;
|
||||
GetDataSeries().Offset = _dataOffset;
|
||||
InvokePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public TreeNode BackendParameterNode { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 获取XyDataSeries类型的DataSeries对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public SicFastLineDataSeries GetDataSeries()
|
||||
{
|
||||
return DataSeries as SicFastLineDataSeries;
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
DataSeries.Clear();
|
||||
}
|
||||
|
||||
|
||||
private void InvokePropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(propertyName))
|
||||
return;
|
||||
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return DataName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using SciChart.Charting.Visuals.RenderableSeries;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core.EventArgs
|
||||
{
|
||||
public class RenderableSeriesDeletingEventArgs : CancelEventArgs
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public RenderableSeriesDeletingEventArgs(IEnumerable<IRenderableSeries> seriesCollection)
|
||||
{
|
||||
Source = new List<IRenderableSeries>(seriesCollection);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public List<IRenderableSeries> Source { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using SciChart.Charting.Model.DataSeries;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core
|
||||
{
|
||||
public class ParameterNodePoint : IPointMetadata
|
||||
{
|
||||
#region Variables
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal ParameterNodePoint(DateTime time, double value)
|
||||
{
|
||||
Time = time;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
internal DateTime Time { get; }
|
||||
|
||||
internal double Value { get; }
|
||||
|
||||
public bool IsSelected { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<UserControl
|
||||
x:Class="MECF.Framework.UI.Client.CenterViews.Core.UserControls.DataViewChart"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:userControls="clr-namespace:MECF.Framework.UI.Client.CenterViews.Core.UserControls"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid>
|
||||
<s:SciChartSurface
|
||||
x:Name="sciChart"
|
||||
Padding="0,0,0,0"
|
||||
s:ThemeManager.Theme="ExpressionLight"
|
||||
BorderBrush="Gray"
|
||||
DebugWhyDoesntSciChartRender="False"
|
||||
Focusable="False"
|
||||
IsEnabled="{Binding IsEnabled, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}"
|
||||
IsTabStop="False"
|
||||
RenderableSeries="{Binding RenderableSeries, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}">
|
||||
|
||||
<!-- Create an X Axis -->
|
||||
<s:SciChartSurface.XAxis>
|
||||
<s:DateTimeAxis
|
||||
AutoRange="{Binding AutoRange, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}"
|
||||
DrawMinorGridLines="False"
|
||||
DrawMinorTicks="False"
|
||||
FontSize="12"
|
||||
Id="DefaultAxisId"
|
||||
SubDayTextFormatting="yyyy-MM-dd HH:mm:ss"
|
||||
TextFormatting="yyyy-MM-dd HH:mm"
|
||||
TitleFontSize="15"
|
||||
TitleFontWeight="Normal"
|
||||
VisibleRange="{Binding VisibleRangeTime, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}" />
|
||||
|
||||
</s:SciChartSurface.XAxis>
|
||||
|
||||
<!-- Create a Y Axis -->
|
||||
<s:SciChartSurface.YAxis>
|
||||
<s:NumericAxis
|
||||
MinWidth="35"
|
||||
MaxWidth="35"
|
||||
HorizontalAlignment="Center"
|
||||
AutoRange="{Binding AutoRange, RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}"
|
||||
AxisAlignment="Right"
|
||||
CursorTextFormatting="0.######"
|
||||
DrawLabels="True"
|
||||
DrawMajorBands="False"
|
||||
DrawMajorGridLines="True"
|
||||
DrawMajorTicks="False"
|
||||
DrawMinorGridLines="False"
|
||||
DrawMinorTicks="False"
|
||||
Focusable="False"
|
||||
Id="DefaultAxisId"
|
||||
MajorDelta="0.1"
|
||||
MinorDelta="0.1">
|
||||
|
||||
<!--
|
||||
VisibleRange="{Binding VisibleRangeValue,
|
||||
RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}}"
|
||||
-->
|
||||
<s:NumericAxis.GrowBy>
|
||||
<s:DoubleRange Max="0.1" Min="0.1" />
|
||||
</s:NumericAxis.GrowBy>
|
||||
</s:NumericAxis>
|
||||
</s:SciChartSurface.YAxis>
|
||||
|
||||
<s:SciChartSurface.ChartModifier>
|
||||
<s:ModifierGroup>
|
||||
<s:RubberBandXyZoomModifier
|
||||
ExecuteOn="MouseLeftButton"
|
||||
IsAnimated="False"
|
||||
IsEnabled="True"
|
||||
IsXAxisOnly="False"
|
||||
ReceiveHandledEvents="True"
|
||||
ZoomExtentsY="True" />
|
||||
|
||||
<s:CursorModifier
|
||||
IsEnabled="True"
|
||||
ShowAxisLabels="True"
|
||||
ShowTooltip="False"
|
||||
ShowTooltipOn="MouseOver"
|
||||
SourceMode="AllSeries" />
|
||||
|
||||
<s:LegendModifier GetLegendDataFor="AllSeries" ShowLegend="False" />
|
||||
|
||||
<s:ZoomExtentsModifier
|
||||
ExecuteOn="MouseDoubleClick"
|
||||
IsAnimated="False"
|
||||
XyDirection="XYDirection" />
|
||||
|
||||
<s:ZoomPanModifier
|
||||
ClipModeX="None"
|
||||
ExecuteOn="MouseRightButton"
|
||||
IsEnabled="True"
|
||||
XyDirection="XYDirection"
|
||||
ZoomExtentsY="False" />
|
||||
|
||||
<s:RolloverModifier
|
||||
DrawVerticalLine="False"
|
||||
FontFamily="Arial,SimSun"
|
||||
FontSize="9"
|
||||
IsEnabled="True"
|
||||
ShowAxisLabels="False"
|
||||
UseInterpolation="False" />
|
||||
|
||||
<s:MouseWheelZoomModifier XyDirection="XYDirection" />
|
||||
|
||||
</s:ModifierGroup>
|
||||
</s:SciChartSurface.ChartModifier>
|
||||
</s:SciChartSurface>
|
||||
|
||||
<Border
|
||||
x:Name="btnFixCurveToScreen"
|
||||
Margin="10,10,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
Cursor="Hand"
|
||||
Opacity="0.2"
|
||||
PreviewMouseUp="BtnFixCurveToScreen_OnPreviewMouseUp"
|
||||
ToolTip="Fit to Screen">
|
||||
<Path
|
||||
Width="35"
|
||||
Height="35"
|
||||
Data="M20,2H4C2.89,2 2,2.89 2,4V20C2,21.11 2.89,22 4,22H20C21.11,22 22,21.11 22,20V4C22,2.89 21.11,2 20,2M12,4L15,7H13V9H11V7H9M7,15L4,12L7,9V11H9V13H7M12,20L9,17H11V15H13V17H15M17,15V13H15V11H17V9L20,12"
|
||||
Fill="Black"
|
||||
Stretch="Uniform" />
|
||||
<Border.Style>
|
||||
<Style>
|
||||
<Setter Property="Border.Opacity" Value="0.3" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Border.IsMouseOver" Value="True">
|
||||
<Setter Property="Border.Opacity" Value="1" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
|
||||
<Border
|
||||
x:Name="btnScreenShot"
|
||||
Margin="10,60,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Background="Transparent"
|
||||
Cursor="Hand"
|
||||
Opacity="0.4"
|
||||
ToolTip="Fit to Screen">
|
||||
<Button Width="35" Height="35" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="0">
|
||||
<i:Interaction.Behaviors>
|
||||
<userControls:PhotoShotBehavior Target="{Binding ElementName=sciChart}"/>
|
||||
</i:Interaction.Behaviors>
|
||||
<Button.Background>
|
||||
<ImageBrush ImageSource="pack://application:,,,/Resources/Images/screenshot.png" Stretch="Uniform"/>
|
||||
</Button.Background>
|
||||
</Button>
|
||||
<Border.Style>
|
||||
<Style>
|
||||
<Setter Property="Border.Opacity" Value="0.8" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Border.IsMouseOver" Value="True">
|
||||
<Setter Property="Border.Opacity" Value="1" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\Core\UserControls\DataViewChart.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-03
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details
|
||||
* *****************************************************************************/
|
||||
|
||||
|
||||
using Aitex.Core.RT.Device.Devices;
|
||||
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
||||
using MECF.Framework.UI.Client.CenterViews.Core.Charting;
|
||||
using SciChart.Charting.Common.Extensions;
|
||||
using SciChart.Charting.Visuals;
|
||||
using SciChart.Charting.Visuals.Axes;
|
||||
using SciChart.Charting.Visuals.RenderableSeries;
|
||||
using SciChart.Core.Framework;
|
||||
using SciChart.Data.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataViewChart.xaml
|
||||
/// </summary>
|
||||
public partial class DataViewChart : UserControl
|
||||
{
|
||||
public DataViewChart()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
#region Dependency Properties
|
||||
|
||||
public static readonly DependencyProperty RenderableSeriesProperty = DependencyProperty.Register(
|
||||
"RenderableSeries", typeof(ObservableCollection<IRenderableSeries>), typeof(DataViewChart), new PropertyMetadata(default(ObservableCollection<IRenderableSeries>)));
|
||||
|
||||
public ObservableCollection<IRenderableSeries> RenderableSeries
|
||||
{
|
||||
get => (ObservableCollection<IRenderableSeries>)GetValue(RenderableSeriesProperty);
|
||||
set => SetValue(RenderableSeriesProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AutoRangeProperty = DependencyProperty.Register(
|
||||
"AutoRange", typeof(AutoRange), typeof(DataViewChart), new PropertyMetadata(default(AutoRange)));
|
||||
|
||||
public AutoRange AutoRange
|
||||
{
|
||||
get => (AutoRange)GetValue(AutoRangeProperty);
|
||||
set => SetValue(AutoRangeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty VisibleRangeTimeProperty = DependencyProperty.Register(
|
||||
"VisibleRangeTime", typeof(IRange), typeof(DataViewChart), new PropertyMetadata(default(IRange)));
|
||||
|
||||
public IRange VisibleRangeTime
|
||||
{
|
||||
get => (IRange)GetValue(VisibleRangeTimeProperty);
|
||||
set => SetValue(VisibleRangeTimeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty VisibleRangeValueProperty = DependencyProperty.Register(
|
||||
"VisibleRangeValue", typeof(IRange), typeof(DataViewChart), new PropertyMetadata(default(IRange)));
|
||||
|
||||
public IRange VisibleRangeValue
|
||||
{
|
||||
get => (IRange)GetValue(VisibleRangeValueProperty);
|
||||
set => SetValue(VisibleRangeValueProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public void ZoomExtents()
|
||||
{
|
||||
sciChart.ZoomExtents();
|
||||
}
|
||||
|
||||
public IUpdateSuspender SuspendSuspendUpdates()
|
||||
{
|
||||
return sciChart.SuspendUpdates();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
private void BtnFixCurveToScreen_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
sciChart.ZoomExtents();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
<UserControl
|
||||
x:Class="MECF.Framework.UI.Client.CenterViews.Core.UserControls.DataViewDataGrid"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
|
||||
xmlns:converter="clr-namespace:MECF.Framework.UI.Client.Ctrlib.Converter"
|
||||
xmlns:converters="clr-namespace:Aitex.Core.UI.Converters;assembly=MECF.Framework.UI.Core"
|
||||
xmlns:converters1="clr-namespace:Sicentury.Core.Converters;assembly=Sicentury.Core"
|
||||
xmlns:cv="clr-namespace:MECF.Framework.UI.Core.Converters;assembly=MECF.Framework.UI.Core"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:extendedControls="clr-namespace:MECF.Framework.UI.Core.ExtendedControls;assembly=MECF.Framework.UI.Core"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:local="clr-namespace:MECF.Framework.UI.Client.CenterViews.Core.UserControls"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:micro="clr-namespace:Caliburn.Micro"
|
||||
xmlns:lex="http://wpflocalizeextension.codeplex.com"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="2000"
|
||||
mc:Ignorable="d"
|
||||
lex:LocalizeDictionary.DesignCulture="en"
|
||||
lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common">
|
||||
|
||||
<!--
|
||||
DataContext MUST BE "ChartingLineSeriesCollection"
|
||||
-->
|
||||
<UserControl.Resources>
|
||||
<converters:LineColorConverter x:Key="colorConverter" />
|
||||
<cv:BoolCollapsedConverter x:Key="BoolVisibility" />
|
||||
<converters1:ParameterNodeStatisticToStringConverter x:Key="DoubleToString" />
|
||||
</UserControl.Resources>
|
||||
<DataGrid
|
||||
AlternationCount="2"
|
||||
AutoGenerateColumns="False"
|
||||
BorderThickness="1"
|
||||
CanUserAddRows="False"
|
||||
CanUserResizeColumns="True"
|
||||
CanUserResizeRows="False"
|
||||
CanUserSortColumns="False"
|
||||
ColumnHeaderHeight="30"
|
||||
FontFamily="Arial"
|
||||
FontSize="12"
|
||||
IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=IsEnabled}"
|
||||
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=ItemsSource}">
|
||||
<DataGrid.Resources>
|
||||
<extendedControls:BindingProxy x:Key="proxy" Data="{Binding RelativeSource={RelativeSource AncestorType=local:DataViewDataGrid, Mode=FindAncestor}}" />
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn MinWidth="60">
|
||||
<DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
<CheckBox x:Name="cbVisibleInColumnHeader" IsChecked="{Binding Data.IsVisibleInColumnHeader, Mode=TwoWay, Delay=1, Source={StaticResource proxy}}" />
|
||||
<TextBlock
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
|
||||
Margin="3,0,0,0"
|
||||
VerticalAlignment="Bottom"
|
||||
Text="{lex:Loc ID_TXT_Visible}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox
|
||||
x:Name="cbVisibleInRow"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding IsVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
|
||||
MinWidth="100" Header="{lex:Loc ID_TXT_Name}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Margin="5,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding DataName}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
|
||||
MinWidth="100" Header="{lex:Loc ID_TXT_Color}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Border
|
||||
x:Name="btnChangeSeriesColor"
|
||||
Width="30"
|
||||
Height="20"
|
||||
Margin="0,1"
|
||||
Background="{Binding Stroke, Converter={StaticResource colorConverter}}"
|
||||
Cursor="Hand"
|
||||
PreviewMouseUp="BtnChangeSeriesColor_OnPreviewMouseUp" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
|
||||
MinWidth="100" Header="{lex:Loc ID_TXT_Factor}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding DataFactor}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
<DataGridTemplateColumn.CellEditingTemplate>
|
||||
<DataTemplate>
|
||||
<controls:TextBoxEx
|
||||
Width="80"
|
||||
Margin="5,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
AllowBackgroundChange="False"
|
||||
FontFamily="Arial"
|
||||
FontSize="14"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding DataFactor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellEditingTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
|
||||
MinWidth="100" Header="{lex:Loc ID_TXT_Offset}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding DataOffset}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
<DataGridTemplateColumn.CellEditingTemplate>
|
||||
<DataTemplate>
|
||||
<controls:TextBoxEx
|
||||
Width="80"
|
||||
Margin="5,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
AllowBackgroundChange="False"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding DataOffset, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellEditingTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
|
||||
MinWidth="60" Header="{lex:Loc ID_TXT_Width}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding LineThickness}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
<DataGridTemplateColumn.CellEditingTemplate>
|
||||
<DataTemplate>
|
||||
<controls:TextBoxEx
|
||||
Width="80"
|
||||
Margin="5,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
AllowBackgroundChange="False"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding LineThickness, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellEditingTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
MinWidth="100"
|
||||
Header="{lex:Loc ID_TXT_Min}"
|
||||
Visibility="{Binding Data.IsShowStatisticColumn, Converter={StaticResource BoolVisibility}, Source={StaticResource proxy}}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding BackendParameterNode.MinValue, Converter={StaticResource DoubleToString}}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
MinWidth="100"
|
||||
Header="{lex:Loc ID_TXT_Max}"
|
||||
Visibility="{Binding Data.IsShowStatisticColumn, Converter={StaticResource BoolVisibility}, Source={StaticResource proxy}}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding BackendParameterNode.MaxValue, Converter={StaticResource DoubleToString}}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
MinWidth="100"
|
||||
Header="{lex:Loc ID_TXT_Average}"
|
||||
Visibility="{Binding Data.IsShowStatisticColumn, Converter={StaticResource BoolVisibility}, Source={StaticResource proxy}}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource FG_Black}"
|
||||
Text="{Binding BackendParameterNode.AverageValue, Converter={StaticResource DoubleToString}}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn MinWidth="120">
|
||||
<DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<Button
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
x:Name="btnExportAll"
|
||||
Width="85"
|
||||
Height="22"
|
||||
Padding="0"
|
||||
Click="BtnExportAll_OnClick"
|
||||
Content="{lex:Loc ID_BTN_ExportAll_Content}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
x:Name="btnExport"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Cursor="Hand"
|
||||
Foreground="DarkBlue"
|
||||
PreviewMouseUp="BtnExport_OnPreviewMouseUp"
|
||||
Text="{lex:Loc ID_BTN_Export_Content}"
|
||||
TextDecorations="Underline" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn MinWidth="120">
|
||||
<DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<Button
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
x:Name="btnDeleteAll"
|
||||
Width="85"
|
||||
Height="22"
|
||||
Padding="0"
|
||||
Click="BtnDeleteAll_OnClick"
|
||||
Content="{lex:Loc ID_BTN_DeleteAll_Content}" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
x:Name="btnDelete"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Cursor="Hand"
|
||||
Foreground="DarkBlue"
|
||||
PreviewMouseUp="BtnDelete_OnPreviewMouseUp"
|
||||
Text="{lex:Loc ID_BTN_Delete_Content}"
|
||||
TextDecorations="Underline" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn MinWidth="120">
|
||||
<DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<Button
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
x:Name="btnSaveAllImage"
|
||||
Width="85"
|
||||
Height="22"
|
||||
Padding="0"
|
||||
Click="BtnSaveAllImage_OnClick"
|
||||
Content="SaveAllImage" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
lex:ResxLocalizationProvider.DefaultDictionary="lang_datalogviews"
|
||||
x:Name="btnSaveImage"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Cursor="Hand"
|
||||
Foreground="DarkBlue"
|
||||
PreviewMouseUp="BtnSaveImage_OnPreviewMouseUp"
|
||||
Text="SaveImage"
|
||||
TextDecorations="Underline" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Width="*" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</UserControl>
|
||||
+963
@@ -0,0 +1,963 @@
|
||||
/************************************************************************
|
||||
*@file FrameworkLocal\UIClient\CenterViews\Core\UserControls\DataViewDataGrid.cs
|
||||
* @author Su Liang
|
||||
* @Date 2022-08-01
|
||||
*
|
||||
* @copyright © Sicentury Inc.
|
||||
*
|
||||
* @brief Reconstructed to support rich functions.
|
||||
*
|
||||
* @details
|
||||
* *****************************************************************************/
|
||||
|
||||
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
||||
using MECF.Framework.Common.Aitex.Core.RT.EMS;
|
||||
using MECF.Framework.UI.Client.CenterViews.Core.Charting;
|
||||
using MECF.Framework.UI.Client.CenterViews.Core.EventArgs;
|
||||
using MECF.Framework.UI.Client.CenterViews.Maintain;
|
||||
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
||||
using SciChart.Charting.ChartModifiers;
|
||||
using SciChart.Charting.Visuals;
|
||||
using SciChart.Charting.Visuals.Annotations;
|
||||
using SciChart.Charting.Visuals.Axes;
|
||||
using SciChart.Charting.Visuals.RenderableSeries;
|
||||
using Sicentury.Core.EventArgs;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interactivity;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Application = System.Windows.Application;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace MECF.Framework.UI.Client.CenterViews.Core.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataViewDataGrid.xaml
|
||||
/// </summary>
|
||||
public partial class DataViewDataGrid
|
||||
{
|
||||
|
||||
#region Variables
|
||||
|
||||
/// <summary>
|
||||
/// 正在导出数据事件。
|
||||
/// </summary>
|
||||
public event EventHandler Exporting;
|
||||
|
||||
/// <summary>
|
||||
/// 导出数据完毕事件。
|
||||
/// <para>导出过程异常仍触发此事件。</para>
|
||||
/// </summary>
|
||||
public event EventHandler Exported;
|
||||
|
||||
/// <summary>
|
||||
/// 触发图表截图事件
|
||||
/// </summary>
|
||||
public event EventHandler PhotoShot;
|
||||
|
||||
/// <summary>
|
||||
/// 正在删除曲线事件。
|
||||
/// </summary>
|
||||
public event EventHandler<RenderableSeriesDeletingEventArgs> Deleting;
|
||||
|
||||
/// <summary>
|
||||
/// 删除曲线完成事件。
|
||||
/// </summary>
|
||||
public event EventHandler<RenderableSeriesDeletingEventArgs> Deleted;
|
||||
|
||||
/// <summary>
|
||||
/// 常时操作的进度信息更新事件。
|
||||
/// </summary>
|
||||
public event EventHandler<ProgressUpdatingEventArgs> ProgressMessageUpdating;
|
||||
|
||||
/// <summary>
|
||||
/// 取消操作。
|
||||
/// </summary>
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
/// <summary>
|
||||
/// 在UI线程上报告进度。
|
||||
/// </summary>
|
||||
private readonly IProgress<ProgressUpdatingEventArgs> _progress;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public DataViewDataGrid()
|
||||
{
|
||||
_progress = new Progress<ProgressUpdatingEventArgs>(e => { ProgressMessageUpdating?.Invoke(this, e); });
|
||||
}
|
||||
|
||||
private void ItemsSourceOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
RegisterPropertiesChangedEvent(e.NewItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
RegisterPropertiesChangedEvent(e.NewItems);
|
||||
UnRegisterPropertiesChangedEvent(e.OldItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
UnRegisterPropertiesChangedEvent(e.OldItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
UnRegisterPropertiesChangedEvent(e.OldItems);
|
||||
RegisterPropertiesChangedEvent(e.NewItems);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Move:
|
||||
default:
|
||||
// Ignore.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterPropertiesChangedEvent(IList collection)
|
||||
{
|
||||
foreach (var item in collection)
|
||||
{
|
||||
if (item is SicFastLineSeries series)
|
||||
{
|
||||
series.PropertyChanged += SeriesOnPropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UnRegisterPropertiesChangedEvent(IList collection)
|
||||
{
|
||||
foreach (var item in collection)
|
||||
{
|
||||
if (item is SicFastLineSeries series)
|
||||
{
|
||||
series.PropertyChanged -= SeriesOnPropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SeriesOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(IRenderableSeries.IsVisible))
|
||||
{
|
||||
// 设置标题栏中CheckBox的IsChecked属性
|
||||
var group =
|
||||
ItemsSource.ToList()
|
||||
.Cast<SicFastLineSeries>()
|
||||
.GroupBy(x => x.IsVisible)
|
||||
.ToList();
|
||||
|
||||
if (group.Count() > 1)
|
||||
{
|
||||
IsVisibleInColumnHeader = null;
|
||||
}
|
||||
else if (group.Count() == 1)
|
||||
{
|
||||
var visible = group[0].Key;
|
||||
IsVisibleInColumnHeader = visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
|
||||
"ItemsSource", typeof(ChartingLineSeriesCollection), typeof(DataViewDataGrid),
|
||||
new PropertyMetadata(default(ChartingLineSeriesCollection), (sender, e) =>
|
||||
{
|
||||
//if (!(sender is DataViewDataGrid dg))
|
||||
// return;
|
||||
|
||||
//if (e.NewValue is ChartingLineSeriesCollection newColl)
|
||||
//{
|
||||
// newColl.CollectionChanged += dg.ItemsSourceOnCollectionChanged;
|
||||
// dg.RegisterPropertiesChangedEvent(newColl);
|
||||
//}
|
||||
|
||||
//if (e.OldValue is ChartingLineSeriesCollection oldColl)
|
||||
//{
|
||||
// oldColl.CollectionChanged -= dg.ItemsSourceOnCollectionChanged;
|
||||
// dg.UnRegisterPropertiesChangedEvent(oldColl);
|
||||
//}
|
||||
|
||||
}));
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回DataGrid数据源。
|
||||
/// </summary>
|
||||
public ChartingLineSeriesCollection ItemsSource
|
||||
{
|
||||
get => (ChartingLineSeriesCollection)GetValue(ItemsSourceProperty);
|
||||
set => SetValue(ItemsSourceProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly DependencyProperty IsShowStatisticColumnProperty = DependencyProperty.Register(
|
||||
nameof(IsShowStatisticColumn),
|
||||
typeof(bool),
|
||||
typeof(DataViewDataGrid),
|
||||
new PropertyMetadata(default(bool)));
|
||||
|
||||
/// <summary>
|
||||
/// 设置或返回是否显示统计数据列。
|
||||
/// </summary>
|
||||
public bool IsShowStatisticColumn
|
||||
{
|
||||
get => (bool)GetValue(IsShowStatisticColumnProperty);
|
||||
set => SetValue(IsShowStatisticColumnProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsVisibleInColumnHeaderProperty = DependencyProperty.Register(
|
||||
"IsVisibleInColumnHeader",
|
||||
typeof(bool?),
|
||||
typeof(DataViewDataGrid),
|
||||
new PropertyMetadata(default(bool?), (sender, e) =>
|
||||
{
|
||||
if (!(sender is DataViewDataGrid dg))
|
||||
return;
|
||||
|
||||
if (e.Property.Name != nameof(IsVisibleInColumnHeader))
|
||||
return;
|
||||
|
||||
if (!(e.NewValue is bool visible))
|
||||
return;
|
||||
|
||||
// 如果CheckBox被选中状态,则本次点击后隐藏所有序列。
|
||||
|
||||
foreach (var series in dg.ItemsSource)
|
||||
{
|
||||
series.IsVisible = visible;
|
||||
}
|
||||
}));
|
||||
|
||||
public bool? IsVisibleInColumnHeader
|
||||
{
|
||||
get => (bool?)GetValue(IsVisibleInColumnHeaderProperty);
|
||||
set => SetValue(IsVisibleInColumnHeaderProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
protected override void OnInitialized(System.EventArgs e)
|
||||
{
|
||||
InitializeComponent();
|
||||
base.OnInitialized(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消操作。
|
||||
/// </summary>
|
||||
public void CancelOperation()
|
||||
{
|
||||
if (_cancellationTokenSource?.Token.CanBeCanceled == true)
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
private void OnProgressMessageUpdating(int currentProgress, int totalProgress, string message)
|
||||
{
|
||||
_progress.Report(new ProgressUpdatingEventArgs(currentProgress, totalProgress, message));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// 导出全部曲线数据。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void BtnExportAll_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!(ItemsSource is ChartingLineSeriesCollection collection))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (collection.Count == 0)
|
||||
{
|
||||
MessageBox.Show($"Please select the data you want to export.", "Export", MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
#if EXPORT_TO_CSV
|
||||
var dlg = new SaveFileDialog
|
||||
{
|
||||
DefaultExt = ".xlsx", // Default file extension
|
||||
Filter = "Excel数据表格文件(*.csv)|*.csv", // Filter files by extension
|
||||
FileName = $"{collection.DisplayName}_{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
};
|
||||
#else
|
||||
var dlg = new SaveFileDialog
|
||||
{
|
||||
DefaultExt = ".xlsx", // Default file extension
|
||||
Filter = "Excel数据表格文件(*.xlsx)|*.xlsx", // Filter files by extension
|
||||
FileName = $"{DisplayName}_{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
var ret = dlg.ShowDialog(); // Show open file dialog box
|
||||
if (ret == DialogResult.OK) // Process open file dialog box results
|
||||
{
|
||||
Exporting?.Invoke(this, System.EventArgs.Empty);
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Restart();
|
||||
|
||||
#if EXPORT_TO_CSV
|
||||
var columns = new List<string>();
|
||||
#else
|
||||
var ds = new DataSet();
|
||||
ds.Tables.Add(new DataTable(dlg.FileName));
|
||||
ds.Tables[0].Columns.Add("Time");
|
||||
ds.Tables[0].Columns[0].DataType = typeof(DateTime);
|
||||
#endif
|
||||
|
||||
var timeValue = new Dictionary<DateTime, double[]>();
|
||||
var dataSeriesCollection =
|
||||
collection.Cast<SicFastLineSeries>().Select(x => x.GetDataSeries()).ToList();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
for (var i = 0; i < dataSeriesCollection.Count; i++)
|
||||
{
|
||||
|
||||
OnProgressMessageUpdating(
|
||||
50,
|
||||
100,
|
||||
$"Exporting {dataSeriesCollection[i].SeriesName} {i}/{dataSeriesCollection.Count} ...");
|
||||
|
||||
var points = dataSeriesCollection[i].Metadata
|
||||
.Cast<ParameterNodePoint>().ToList();
|
||||
|
||||
for (var n = 0; n < points.Count; n++)
|
||||
{
|
||||
var p = points[n];
|
||||
|
||||
if (!timeValue.ContainsKey(p.Time))
|
||||
timeValue[p.Time] = new double[collection.Count];
|
||||
|
||||
timeValue[p.Time][i] = p.Value;
|
||||
|
||||
if (_cancellationTokenSource.Token.IsCancellationRequested)
|
||||
break;
|
||||
}
|
||||
|
||||
#if EXPORT_TO_CSV
|
||||
columns.Add((collection[i] as SicFastLineSeries)?.DataName ?? "Unknown Col");
|
||||
#else
|
||||
ds.Tables[0].Columns.Add((SelectedData[i] as SicFastLineSeries)?.DataName);
|
||||
ds.Tables[0].Columns[i + 1].DataType = typeof(double);
|
||||
#endif
|
||||
if (_cancellationTokenSource.Token.IsCancellationRequested)
|
||||
break;
|
||||
}
|
||||
|
||||
}, _cancellationTokenSource.Token).ContinueWith(t =>
|
||||
{
|
||||
if (t.IsCanceled || t.IsFaulted)
|
||||
return;
|
||||
#if EXPORT_TO_CSV
|
||||
var csvBuilder = new StringBuilder();
|
||||
csvBuilder.Append("Time,");
|
||||
csvBuilder.AppendLine(string.Join(",", columns));
|
||||
|
||||
var totalPoints = (double)timeValue.Count;
|
||||
var processedPoints = 0d;
|
||||
var lastPercent = 0d;
|
||||
foreach (var tv in timeValue)
|
||||
{
|
||||
csvBuilder.Append($" {tv.Key:yyyy/MM/dd HH:mm:ss.fff}");
|
||||
csvBuilder.Append(",");
|
||||
csvBuilder.AppendLine(string.Join(",", tv.Value));
|
||||
|
||||
if (_cancellationTokenSource?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
|
||||
processedPoints++;
|
||||
var currentPercent = (int)(processedPoints / totalPoints * 100);
|
||||
if (currentPercent > lastPercent)
|
||||
{
|
||||
/*
|
||||
* 不要太频繁更新进度,否则会导致UI卡顿,每增长1%更新一次进度。
|
||||
* currentPercent和lastPercent必须是整数,以将进度更新的频率控制在要求内。
|
||||
*/
|
||||
OnProgressMessageUpdating(
|
||||
60,
|
||||
100,
|
||||
$"Building report content ({currentPercent}%) ...");
|
||||
lastPercent = currentPercent;
|
||||
}
|
||||
}
|
||||
|
||||
OnProgressMessageUpdating(
|
||||
90,
|
||||
100,
|
||||
$"Writing to file ...");
|
||||
using (_cancellationTokenSource.Token.Register(Thread.CurrentThread.Abort))
|
||||
{
|
||||
File.WriteAllText(dlg.FileName, csvBuilder.ToString());
|
||||
}
|
||||
#else
|
||||
|
||||
OnProgressMessageUpdating(
|
||||
60,
|
||||
100,
|
||||
$"Building report content ...");
|
||||
|
||||
foreach (var item in timeValue)
|
||||
{
|
||||
var row = ds.Tables[0].NewRow();
|
||||
row[0] = item.Key;
|
||||
for (var j = 0; j < item.Value.Length; j++)
|
||||
{
|
||||
row[j + 1] = item.Value[j];
|
||||
}
|
||||
|
||||
ds.Tables[0].Rows.Add(row);
|
||||
}
|
||||
|
||||
|
||||
OnProgressMessageUpdating(
|
||||
90,
|
||||
100,
|
||||
$"Writing to file ...");
|
||||
using (_cancellationTokenSource.Token.Register(Thread.CurrentThread.Abort))
|
||||
{
|
||||
if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out var reason))
|
||||
{
|
||||
MessageBox.Show($"Export failed, {reason}", "Export", MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
});
|
||||
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"Export costs {sw.ElapsedMilliseconds}ms");
|
||||
Debug.WriteLine($"Total Lines {timeValue.Count}");
|
||||
|
||||
if (_cancellationTokenSource?.Token.IsCancellationRequested == true)
|
||||
return;
|
||||
|
||||
Exported?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
MessageBox.Show($"Exporting succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
// 操作取消。
|
||||
}
|
||||
catch (AggregateException ae)
|
||||
{
|
||||
var ex = ae.Flatten().InnerExceptions;
|
||||
throw ex.FirstOrDefault() ?? ae;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Unable to export data, {ex.Message}", "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Exported?.Invoke(this, System.EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出单条曲线数据。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private async void BtnExport_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (!(ItemsSource is ChartingLineSeriesCollection collection))
|
||||
return;
|
||||
|
||||
if (!(sender is TextBlock btn))
|
||||
return;
|
||||
|
||||
if (!(btn.DataContext is SicFastLineSeries series))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
#if EXPORT_TO_CSV
|
||||
var dlg = new SaveFileDialog
|
||||
{
|
||||
DefaultExt = ".xlsx", // Default file extension
|
||||
Filter = "Excel数据表格文件(*.csv)|*.csv", // Filter files by extension
|
||||
FileName = $"{series.DisplayName}_{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
};
|
||||
#else
|
||||
var dlg = new SaveFileDialog
|
||||
{
|
||||
DefaultExt = ".xlsx", // Default file extension
|
||||
Filter = "Excel数据表格文件(*.xlsx)|*.xlsx", // Filter files by extension
|
||||
FileName = $"{DisplayName}_{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
};
|
||||
|
||||
#endif
|
||||
var result = dlg.ShowDialog(); // Show open file dialog box
|
||||
if (result == DialogResult.OK) // Process open file dialog box results
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
Exporting?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Restart();
|
||||
|
||||
#if EXPORT_TO_CSV
|
||||
var columns = new List<string>();
|
||||
#else
|
||||
var ds = new DataSet();
|
||||
ds.Tables.Add(new DataTable(cp.DataName));
|
||||
ds.Tables[0].Columns.Add("Time");
|
||||
ds.Tables[0].Columns[0].DataType = typeof(DateTime);
|
||||
ds.Tables[0].Columns.Add(cp.DataName);
|
||||
ds.Tables[0].Columns[1].DataType = typeof(double);
|
||||
#endif
|
||||
|
||||
var ds = series?.GetDataSeries();
|
||||
var points = ds?.Metadata.Cast<ParameterNodePoint>().ToList();
|
||||
|
||||
if (points == null)
|
||||
{
|
||||
MessageBox.Show($"Unable to find meta points from the series {series.DataName}.", "Error",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var csvBuilder = new StringBuilder();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
using (_cancellationTokenSource.Token.Register(Thread.CurrentThread.Abort))
|
||||
{
|
||||
#if EXPORT_TO_CSV
|
||||
csvBuilder.AppendLine($"Time,{ds.SeriesName}"); // table header
|
||||
#endif
|
||||
OnProgressMessageUpdating(
|
||||
50,
|
||||
100,
|
||||
$"Exporting data ...");
|
||||
|
||||
for (var i = 0; i < points.Count; i++)
|
||||
{
|
||||
var p = points[i];
|
||||
#if EXPORT_TO_CSV
|
||||
csvBuilder.AppendLine($" {p.Time:yyyy/MM/dd HH:mm:ss.fff},{p.Value}");
|
||||
#else
|
||||
var row = ds.Tables[0].NewRow();
|
||||
row[0] = p.Time;
|
||||
row[1] = p.Value;
|
||||
ds.Tables[0].Rows.Add(row);
|
||||
#endif
|
||||
}
|
||||
|
||||
OnProgressMessageUpdating(
|
||||
90,
|
||||
100,
|
||||
$"Writing to file ...");
|
||||
#if EXPORT_TO_CSV
|
||||
|
||||
File.WriteAllText(dlg.FileName, csvBuilder.ToString());
|
||||
#else
|
||||
if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out var reason))
|
||||
{
|
||||
MessageBox.Show($"Export failed, {reason}", "Export", MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
});
|
||||
|
||||
sw.Stop();
|
||||
Debug.WriteLine($"Export costs {sw.ElapsedMilliseconds}ms");
|
||||
Debug.WriteLine($"Total Lines {points?.Count}");
|
||||
|
||||
Exported?.Invoke(this, System.EventArgs.Empty);
|
||||
|
||||
MessageBox.Show($"Export succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
// 操作取消。
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Unable to export data, {ex.Message}", "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Exported?.Invoke(this, System.EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除全部曲线。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnDeleteAll_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!(ItemsSource is ChartingLineSeriesCollection collection))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var list = collection.Cast<SicFastLineSeries>().ToList();
|
||||
var args = new RenderableSeriesDeletingEventArgs(list);
|
||||
|
||||
Deleting?.Invoke(this, args);
|
||||
if (args.Cancel)
|
||||
return;
|
||||
|
||||
var total = collection.Count;
|
||||
for (var i = total - 1; i >= 0; i--)
|
||||
{
|
||||
list[i].BackendParameterNode.IsSelected = false;
|
||||
}
|
||||
|
||||
collection.Clear();
|
||||
|
||||
Deleted?.Invoke(this, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"It's failed to delete all series, {ex.Message}", "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除单条曲线。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnDelete_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (!(ItemsSource is ChartingLineSeriesCollection collection))
|
||||
return;
|
||||
|
||||
if (!(sender is TextBlock btn))
|
||||
return;
|
||||
|
||||
if (!(btn.DataContext is SicFastLineSeries series))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var args = new RenderableSeriesDeletingEventArgs(
|
||||
new List<SicFastLineSeries>(new[] { series }));
|
||||
|
||||
Deleting?.Invoke(this, args);
|
||||
if (args.Cancel)
|
||||
return;
|
||||
|
||||
series.BackendParameterNode.IsSelected = false;
|
||||
collection.Remove(series);
|
||||
|
||||
Deleted?.Invoke(this, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"It's failed to delete series, {ex.Message}", "Error", MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存全部截图
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnSaveAllImage_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
var dialog = new SaveFileDialog()
|
||||
{
|
||||
DefaultExt = ".png", // Default file extension
|
||||
Filter = "图片文件(*.png)|*.png", // Filter files by extension
|
||||
FileName = $"Chartexport{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
path = Path.GetDirectoryName(dialog.FileName);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
if (!(ItemsSource is ChartingLineSeriesCollection collection))
|
||||
return;
|
||||
|
||||
foreach (var item in collection)
|
||||
{
|
||||
if (item is SicFastLineSeries series)
|
||||
{
|
||||
var ee = new Tuple<string, string>(series.DataName, path);
|
||||
PhotoShot?.Invoke(ee, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存单条曲线截图。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnSaveImage_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
var dialog = new SaveFileDialog()
|
||||
{
|
||||
DefaultExt = ".png", // Default file extension
|
||||
Filter = "图片文件(*.png)|*.png", // Filter files by extension
|
||||
FileName = $"Chartexport{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
path = Path.GetDirectoryName(dialog.FileName);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
if (!(ItemsSource is ChartingLineSeriesCollection collection))
|
||||
return;
|
||||
if (!(sender is TextBlock btn))
|
||||
return;
|
||||
|
||||
if (!(btn.DataContext is SicFastLineSeries series))
|
||||
return;
|
||||
var ee = new Tuple<string, string>(series.DataName, path);
|
||||
PhotoShot?.Invoke(ee, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更换曲线颜色。
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void BtnChangeSeriesColor_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var dlg = new System.Windows.Forms.ColorDialog();
|
||||
if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
|
||||
return;
|
||||
|
||||
if (!(sender is Border bdr))
|
||||
return;
|
||||
|
||||
if (bdr.DataContext is SicFastLineSeries series)
|
||||
series.Stroke = new System.Windows.Media.Color()
|
||||
{ A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class PhotoShotBehavior : Behavior<System.Windows.Controls.Control>
|
||||
{
|
||||
|
||||
public SciChartSurface Target
|
||||
{
|
||||
get { return (SciChartSurface)GetValue(TargetProperty); }
|
||||
set { SetValue(TargetProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TargetProperty =
|
||||
DependencyProperty.Register("Target", typeof(SciChartSurface), typeof(PhotoShotBehavior), new PropertyMetadata(null));
|
||||
|
||||
public DataViewChart Target2
|
||||
{
|
||||
get { return (DataViewChart)GetValue(Target2Property); }
|
||||
set { SetValue(TargetProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty Target2Property =
|
||||
DependencyProperty.Register("Target2", typeof(DataViewChart), typeof(PhotoShotBehavior), new PropertyMetadata(null));
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
if (AssociatedObject is DataViewDataGrid dg)
|
||||
{
|
||||
dg.PhotoShot += ShotAPhoto;
|
||||
}
|
||||
else if (AssociatedObject is System.Windows.Controls.Button btn)
|
||||
{
|
||||
btn.Click += ShotPhoto;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ShotPhoto(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Target == null)
|
||||
return;
|
||||
|
||||
BitmapSource b = Target.ExportToBitmapSource();
|
||||
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
SaveBitmapToFile(b, Path.Combine(desktopPath, $"chart_export{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.png"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将BitmapSource保存为文件
|
||||
/// </summary>
|
||||
private void SaveBitmapToFile(BitmapSource bitmapSource, string fileName)
|
||||
{
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
|
||||
|
||||
using (var fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
|
||||
{
|
||||
encoder.Save(fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShotAPhoto(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!(sender is Tuple<string, string> s))
|
||||
return;
|
||||
if (Target == null && Target2 == null)
|
||||
return;
|
||||
if (Target != null)
|
||||
{
|
||||
SaveAImage(s.Item2, s.Item1, Target);
|
||||
}
|
||||
else if (Target2 != null)
|
||||
{
|
||||
SaveAImage(s.Item2, s.Item1, Target2.sciChart);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SaveAImage(string path, string line, SciChartSurface chart)
|
||||
{
|
||||
string name = "";
|
||||
foreach (var item in chart.RenderableSeries)
|
||||
{
|
||||
if (item is SicFastLineSeries fline)
|
||||
{
|
||||
if (fline.DataName == line)
|
||||
{
|
||||
fline.IsVisible = true;
|
||||
name = $"{fline.DataName}\r\nMin:{fline.BackendParameterNode.MinValue};Max:{fline.BackendParameterNode.MaxValue};Avg:{fline.BackendParameterNode.AverageValue}";
|
||||
continue;
|
||||
}
|
||||
fline.IsVisible = false;
|
||||
}
|
||||
else item.IsVisible = false;
|
||||
}
|
||||
|
||||
chart.ZoomExtents();
|
||||
|
||||
//立即更新视图;scichart需要设置RenderPriority为立即重绘,之后在修改回来
|
||||
chart.RenderPriority = RenderPriority.Immediate;
|
||||
chart.InvalidateElement();
|
||||
chart.RenderPriority = RenderPriority.Normal;
|
||||
|
||||
BitmapSource b = chart.ExportToBitmapSource();
|
||||
|
||||
if (name != "")
|
||||
{
|
||||
AddTextAndSave(b, name, Path.Combine(path, $"{line}_Chartexport{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.png"));
|
||||
}
|
||||
else
|
||||
SaveBitmapToFile(b, Path.Combine(path, $"{line}_Chartexport{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.png"));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在 BitmapSource 上添加文字并保存为文件
|
||||
/// </summary>
|
||||
/// <param name="source">原始图片源</param>
|
||||
/// <param name="text">要添加的文字</param>
|
||||
/// <param name="outputPath">输出文件路径 (例如: "C:\\temp\\output.png")</param>
|
||||
public void AddTextAndSave(BitmapSource source, string text, string outputPath)
|
||||
{
|
||||
// 1. 将 BitmapSource 转换为 System.Drawing.Bitmap
|
||||
using (Bitmap bitmap = BitmapSourceToBitmap(source))
|
||||
{
|
||||
// 2. 创建 Graphics 对象进行绘图
|
||||
using (Graphics g = Graphics.FromImage(bitmap))
|
||||
{
|
||||
// 开启抗锯齿,让文字边缘更平滑
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||||
|
||||
// 3. 定义字体和画刷
|
||||
using (Font font = new Font("Microsoft YaHei", 30, System.Drawing.FontStyle.Bold, GraphicsUnit.Pixel))
|
||||
using (System.Drawing.Brush brush = new SolidBrush(System.Drawing.Color.FromArgb(255, 255, 255, 0))) // 黄色文字
|
||||
{
|
||||
// 4. 定义绘制位置 (x=50, y=50)
|
||||
PointF point = new PointF(50f, 50f);
|
||||
|
||||
// 5. 绘制文字
|
||||
g.DrawString(text, font, brush, point);
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 保存文件
|
||||
// 根据文件扩展名自动判断格式,这里以 PNG 为例
|
||||
bitmap.Save(outputPath, ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 辅助方法:将 BitmapSource 转换为 Bitmap
|
||||
/// </summary>
|
||||
private Bitmap BitmapSourceToBitmap(BitmapSource source)
|
||||
{
|
||||
BitmapEncoder encoder = new BmpBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(source));
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
encoder.Save(ms);
|
||||
return new Bitmap(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user