192 lines
5.1 KiB
C#
192 lines
5.1 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using TBF.Resources;
|
|
using TBF.UiBridge;
|
|
using GraphLib;
|
|
|
|
namespace TBF.Screens
|
|
{
|
|
public partial class GraphsTabPageCtrl : UserControl
|
|
{
|
|
readonly int numGraphs;
|
|
DataSource[] dataSources;
|
|
|
|
public GraphsTabPageCtrl()
|
|
{
|
|
InitializeComponent();
|
|
button1.Text = Strings.ClearBtnText;
|
|
|
|
plotterDisplayEx.Smoothing = System.Drawing.Drawing2D.SmoothingMode.None;
|
|
|
|
dataSources = CreateDataSources(new string[] { "Flow", "Temperature", "Pressure", "Reg. valve position" });
|
|
numGraphs = dataSources.Length;
|
|
CalcDataGraphs(plotterDisplayEx, dataSources);
|
|
|
|
plotterDisplayEx.Refresh();
|
|
|
|
Bridge.ProcessDataHandler += delegate(object sender, ProcessDataEventArgs args)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
Invoke(new EventHandler<ProcessDataEventArgs>(OnProcessData), sender, args);
|
|
}
|
|
else OnProcessData(sender, args);
|
|
};
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
/// TODO: implement
|
|
}
|
|
|
|
void OnProcessData(object sender, ProcessDataEventArgs args)
|
|
{
|
|
|
|
//if (!paused && isRunning == true)
|
|
//{
|
|
//try
|
|
//{
|
|
// gPane.starting_idx += Math.Min(RichTextBoxFinds.BenchControl.StateMachine.;
|
|
// UpdateScrollBar();
|
|
// gPane.Invalidate();
|
|
//}
|
|
//catch { }
|
|
//}
|
|
}
|
|
|
|
DataSource[] CreateDataSources(string[] names)
|
|
{
|
|
DataSource[] ds = new DataSource[names.Length];
|
|
|
|
for (int i = 0; i < names.Length; i++)
|
|
{
|
|
ds[i] = new DataSource();
|
|
ds[i].Name = names[i];
|
|
ds[i].OnRenderXAxisLabel += RenderXLabel;
|
|
ds[i].OnRenderYAxisLabel = RenderYLabel;
|
|
ds[i].Length = 5800;
|
|
ds[i].AutoScaleY = false;
|
|
ds[i].SetDisplayRangeY(-250, 250);
|
|
ds[i].SetGridDistanceY(100);
|
|
}
|
|
|
|
return ds;
|
|
}
|
|
|
|
protected void CalcDataGraphs(PlotterDisplayEx display, DataSource[] dataSources)
|
|
{
|
|
this.SuspendLayout();
|
|
|
|
display.SetDisplayRangeX(0, 400);
|
|
display.PanelLayout = PlotterGraphPaneEx.LayoutMode.STACKED;
|
|
|
|
display.DataSources.Clear();
|
|
for (int j = 0; j < dataSources.Length; j++)
|
|
{
|
|
display.DataSources.Add(dataSources[j]);
|
|
}
|
|
|
|
ApplyColorSchema(display);
|
|
|
|
this.ResumeLayout();
|
|
display.Refresh();
|
|
}
|
|
|
|
private string RenderXLabel(DataSource s, int idx)
|
|
{
|
|
if (s.AutoScaleX)
|
|
{
|
|
//if (idx % 2 == 0)
|
|
return ((int)(s.Samples[idx].X)).ToString();
|
|
//else
|
|
// return string.Empty;
|
|
}
|
|
else
|
|
{
|
|
return string.Format("{0}\"", (int)(s.Samples[idx].X / 200));
|
|
}
|
|
}
|
|
|
|
private string RenderYLabel(DataSource s, float value)
|
|
{
|
|
return string.Format("{0:0.0}", value);
|
|
}
|
|
|
|
void ApplyColorSchema(PlotterDisplayEx display)
|
|
{
|
|
Color[] colors = { Color.DarkRed,
|
|
Color.DarkSlateGray,
|
|
Color.DarkCyan,
|
|
Color.DarkGreen,
|
|
Color.DarkBlue ,
|
|
Color.DarkMagenta,
|
|
Color.DeepPink };
|
|
|
|
for (int i = 0; i < numGraphs; i++)
|
|
{
|
|
display.DataSources[i].GraphColor = colors[i % 7];
|
|
}
|
|
|
|
display.BackgroundColorTop = Color.White;
|
|
display.BackgroundColorBot = Color.White;
|
|
display.SolidGridColor = Color.LightGray;
|
|
display.DashedGridColor = Color.LightGray;
|
|
}
|
|
|
|
protected void CalcSinusFunction_0(DataSource dataSrc, int idx)
|
|
{
|
|
for (int i = 0; i < dataSrc.Length; i++)
|
|
{
|
|
dataSrc.Samples[i].X = i;
|
|
dataSrc.Samples[i].Y = (float)(((float)200 * Math.Sin((idx + 1) * (i + 1.0) * 48 / dataSrc.Length)));
|
|
}
|
|
}
|
|
|
|
protected void CalcSinusFunction_1(DataSource dataSrc, int idx)
|
|
{
|
|
for (int i = 0; i < dataSrc.Length; i++)
|
|
{
|
|
dataSrc.Samples[i].X = i;
|
|
|
|
dataSrc.Samples[i].Y = (float)(((float)20 *
|
|
Math.Sin(20 * (idx + 1) * (i + 1) * Math.PI / dataSrc.Length)) *
|
|
Math.Sin(40 * (idx + 1) * (i + 1) * Math.PI / dataSrc.Length)) +
|
|
(float)(((float)200 *
|
|
Math.Sin(200 * (idx + 1) * (i + 1) * Math.PI / dataSrc.Length)));
|
|
}
|
|
}
|
|
|
|
protected void CalcSinusFunction_2(DataSource dataSrc, int idx)
|
|
{
|
|
for (int i = 0; i < dataSrc.Length; i++)
|
|
{
|
|
dataSrc.Samples[i].X = i;
|
|
|
|
dataSrc.Samples[i].Y = (float)(((float)20 *
|
|
Math.Sin(40 * (idx + 1) * i * Math.PI / dataSrc.Length)) *
|
|
Math.Sin(160 * (idx + 1) * i * Math.PI / dataSrc.Length)) +
|
|
(float)(((float)200 *
|
|
Math.Sin(4 * (idx + 1) * i * Math.PI / dataSrc.Length)));
|
|
}
|
|
}
|
|
|
|
protected void CalcSinusFunction_3(DataSource dataSrc, int idx, float time)
|
|
{
|
|
PointF[] samps = dataSrc.Samples;
|
|
for (int i = 0; i < samps.Length; i++)
|
|
{
|
|
samps[i].X = i;
|
|
samps[i].Y = 200 + (float)((200 * Math.Sin((idx + 1) * (time + i * 100) / 8000.0))) +
|
|
+(float)((40 * Math.Sin((idx + 1) * (time + i * 200) / 2000.0)));
|
|
/**
|
|
(float)( 4* Math.Sin( ((time + (i+8) * 100) / 900.0)))+
|
|
(float)(28 * Math.Sin(((time + (i + 8) * 100) / 290.0))); */
|
|
}
|
|
}
|
|
}
|
|
}
|