using DevExpress.Charts.Native;
|
using DevExpress.XtraCharts;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
|
namespace TProduct.WinFrmUI.TPump
|
{
|
public partial class FeatTestRealTimeChart : DevExpress.XtraEditors.XtraUserControl
|
{
|
internal ChartControl ChartControl { get { return chart; } }
|
protected TProduct.Model.TestProjectItemView _testItem = null;
|
protected Eventech.Model.UnitP power_unit = Eventech.Model.UnitP.KW;
|
protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
|
protected Eventech.Model.UnitH head_unit = Eventech.Model.UnitH.M;
|
protected Eventech.Model.UnitH press_unit = Eventech.Model.UnitH.MPa;
|
public FeatTestRealTimeChart()
|
{
|
InitializeComponent();
|
|
power_unit = TProduct.UserSetting.Setting.PumpTest.UnitPower;
|
flow_unit = TProduct.UserSetting.Setting.PumpTest.UnitFlow;
|
head_unit = TProduct.UserSetting.Setting.PumpTest.UnitHead;
|
press_unit = TProduct.UserSetting.Setting.PumpTest.UnitPress;
|
|
//ChartControl.BeginInit();
|
//dataGenerator = new SensorDataGenerator();
|
//dataGenerator.GenerateInitialData();
|
//ChartControl.DataSource = dataGenerator.DataSource;
|
//ColorizeSeries();
|
//dataGenerator.Start();
|
//this.synchronousTimer = new System.Windows.Forms.Timer(this.components);
|
//this.synchronousTimer.Interval = 15;
|
//this.synchronousTimer.Tick += new System.EventHandler(this.synchronousTimer_Tick);
|
////
|
//synchronousTimer.Enabled = true;
|
//ChartControl.EndInit();
|
//SwiftPlotDiagramAxisX axisX = ((SwiftPlotDiagram)ChartControl.Diagram).AxisX;
|
//axisX.VisualRange.SetMinMaxValues((DateTime)axisX.WholeRange.MaxValue - new TimeSpan(0, 0, 10), ((DateTime)axisX.WholeRange.MaxValue).AddSeconds(1));
|
}
|
|
public class FeatTestRealTimeItem
|
{
|
public DateTime TimeStamp { get; set; }
|
public double Power { get; set; }
|
public double Flow { get; set; }
|
public double InletPress { get; set; }
|
public double OutletPress { get; set; }
|
public double WenDu { get; set; }//温度
|
public double KaiDu { get; set; }//开度
|
internal FeatTestRealTimeItem() { }
|
internal FeatTestRealTimeItem(
|
DateTime timeStamp,
|
double power,
|
double flow,
|
double inlet_press,
|
double outlet_press,
|
double wendu,
|
double kaidu)
|
{
|
this.TimeStamp = timeStamp;
|
this.Power = power;
|
this.Flow = flow;
|
this.InletPress = inlet_press;
|
this.OutletPress = outlet_press;
|
this.WenDu = wendu;
|
this.KaiDu = kaidu;
|
}
|
}
|
|
|
private void RealTimeChart_Load(object sender, EventArgs e)
|
{
|
|
}
|
void Chart_CustomPaint(object sender, CustomPaintEventArgs e)
|
{
|
|
}
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint进口压力 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint出口压力 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint流量 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint功率 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint温度 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint开度 = null;
|
|
MonitorValveIngRecordHelper _monitorValveIngRecordHelper = null;
|
|
private bool isShowPress = true;
|
private bool isShowWenDu = true;
|
//private bool isShowPower = true;
|
private bool isShowKaiDu = true;
|
|
internal bool SetBindingData(
|
List<TProduct.Model.WorkBenchMonitorPoint> monitorPoints,
|
MonitorValveIngRecordHelper monitorValveIngRecordHelper)
|
{
|
_dataSouce = new ObservableCollection<FeatTestRealTimeItem>();
|
chart.DataSource = _dataSouce;
|
|
var diagram = this.chart.Diagram as SwiftPlotDiagram;
|
|
|
_monitorPoint进口压力 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
|
x.Property == Model.MonitorTypeProperty.进口);
|
_monitorPoint出口压力 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
|
x.Property == Model.MonitorTypeProperty.出口);
|
|
if(_monitorPoint进口压力==null|| _monitorPoint进口压力.DispInRealChart != 1)
|
{
|
this.chart.Series["SeriesInletPress"].Visible = false;
|
isShowPress = false;
|
}
|
else
|
{
|
isShowPress = true ;
|
}
|
if (_monitorPoint出口压力 == null || _monitorPoint出口压力.DispInRealChart != 1)
|
{
|
this.chart.Series["SeriesOutletPress"].Visible = false;
|
isShowPress = false;
|
}
|
else
|
{
|
isShowPress = true;
|
}
|
if (isShowPress == false)
|
{
|
diagram.Panes[1].Visibility = ChartElementVisibility.Hidden;
|
diagram.SecondaryAxesY["AxisPress"].Visibility = DevExpress.Utils.DefaultBoolean.False;
|
}
|
|
_monitorPoint流量 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.流量);
|
_monitorPoint功率 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.功率);
|
_monitorPoint温度 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.介质温度 );
|
if(_monitorPoint温度 == null || _monitorPoint温度.DispInRealChart != 1)
|
{
|
isShowWenDu = false;
|
diagram.SecondaryAxesY["AxisWendu"].Visibility = DevExpress.Utils.DefaultBoolean.False;
|
this.chart.Series["SeriesWendu"].Visible = false;
|
}
|
else
|
{
|
isShowWenDu = true ;
|
}
|
|
|
_monitorPoint开度 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.阀门开度);
|
if (_monitorPoint开度 == null || _monitorPoint开度.DispInRealChart != 1)
|
{
|
isShowWenDu = false;
|
diagram.SecondaryAxesY["AxisKaidu"].Visibility = DevExpress.Utils.DefaultBoolean.False;
|
this.chart.Series["SeriesKaidu"].Visible = false;
|
}
|
else
|
{
|
isShowKaiDu = true;
|
}
|
|
this._monitorValveIngRecordHelper = monitorValveIngRecordHelper;
|
|
return true;
|
}
|
|
ObservableCollection<FeatTestRealTimeItem> _dataSouce = null;
|
System.Windows.Forms.Timer synchronousTimer;
|
public void Start()
|
{
|
if (synchronousTimer != null)
|
synchronousTimer.Stop();
|
MaxDataPointsCount = TProduct.UserSetting.Setting.PumpTest.RealTimeChartMaxPtCount;
|
if (MaxDataPointsCount < 100)
|
MaxDataPointsCount = 200;
|
synchronousTimer = new System.Windows.Forms.Timer();
|
synchronousTimer.Interval = 1500;
|
synchronousTimer.Tick += new System.EventHandler(this.synchronousTimer_Tick);
|
synchronousTimer.Enabled = false;
|
synchronousTimer.Start();
|
|
}
|
int MaxDataPointsCount = 3600;
|
|
void synchronousTimer_Tick(object sender, EventArgs e)
|
{
|
var value_list = this._monitorValveIngRecordHelper.GetRealValueList();
|
FeatTestRealTimeItem point = new FeatTestRealTimeItem();
|
point.TimeStamp = DateTime.Now;
|
if (_monitorPoint进口压力 != null)
|
{
|
var v进口压力 = value_list.Find(x => x.ID == this._monitorPoint进口压力.ID);
|
if (v进口压力 != null && v进口压力.Value != null)
|
point.InletPress = Eventech.Common.UnitHHelper.fromMPa(this.press_unit,
|
v进口压力.Value.Value);
|
}
|
if (_monitorPoint出口压力 != null)
|
{
|
var v出口压力 = value_list.Find(x => x.ID == this._monitorPoint出口压力.ID);
|
if (v出口压力 != null && v出口压力.Value != null)
|
point.OutletPress = Eventech.Common.UnitHHelper.fromMPa(this.press_unit,
|
v出口压力.Value.Value);
|
}
|
if (_monitorPoint功率 != null)
|
{
|
var v功率 = value_list.Find(x => x.ID == this._monitorPoint功率.ID);
|
if (v功率 != null && v功率.Value != null)
|
point.Power = Eventech.Common.UnitPHelper.fromKW(this.power_unit,
|
v功率.Value.Value);
|
}
|
if (_monitorPoint流量 != null)
|
{
|
var v流量 = value_list.Find(x => x.ID == this._monitorPoint流量.ID);
|
if (v流量 != null && v流量.Value != null)
|
point.Flow = Eventech.Common.UnitQHelper.fromM3H(this.flow_unit,
|
v流量.Value.Value);
|
}
|
if( _monitorPoint温度 != null && this.isShowWenDu)
|
{
|
var v温度 = value_list.Find(x => x.ID == this._monitorPoint温度.ID);
|
if (v温度 != null && v温度.Value != null)
|
point.WenDu = v温度.Value.Value ;
|
}
|
if (_monitorPoint开度 != null && this.isShowKaiDu)
|
{
|
var v开度 = value_list.Find(x => x.ID == this._monitorPoint开度.ID);
|
if (v开度 != null && v开度.Value != null)
|
point.KaiDu = v开度.Value.Value;
|
}
|
{
|
_dataSouce.Add(point);
|
if (_dataSouce.Count > MaxDataPointsCount)
|
_dataSouce.RemoveAt(0);
|
}
|
|
}
|
public void Stop()
|
{
|
if (synchronousTimer != null)
|
{
|
synchronousTimer.Stop();
|
synchronousTimer = null;
|
}
|
}
|
|
private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
_dataSouce.Clear();
|
}
|
}
|
}
|