You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Controls/Mesnac.Controls.Default/MCTeeChart.cs

995 lines
27 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Mesnac.Controls.Base;
using System.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart;
using System.Windows.Forms;
namespace Mesnac.Controls.Default
{
[ToolboxBitmap(typeof(TChart), "Images.TChart.bmp")]
public partial class MCTeeChart : Steema.TeeChart.TChart
{
#region 类型定义
/// <summary>
/// 曲线类别
/// </summary>
public enum CurveTypes
{
/// <summary>
/// 超过设定点数累加
/// </summary>
Accumulate = 0,
/// <summary>
/// 超过设定点数平移
/// </summary>
Pan = 1
}
#endregion
#region 字段定义
private const int LINENUM = 12; //支持的最大曲线数
private int _num = 180; //保持的点数
private CurveTypes _curveType = CurveTypes.Accumulate; //曲线类别
private bool _isShowTime = false; //是否显示时间刻度
private bool _isShowLegend = true; //是否显示图例
private string _timeformat = "{0:HH:mm:ss}"; //时间格式
FastLine[] list = new FastLine[LINENUM]; //曲线集合
private bool _isUseMixTime = false; //是否关联密炼时间
private int _mixTime = 0; //密炼时间
private string _mixTimeName = String.Empty; //密炼时间动画
#endregion
#region 构造方法
public MCTeeChart()
{
InitializeComponent();
this.InitMethod();
}
public MCTeeChart(IContainer container)
{
container.Add(this);
InitializeComponent();
this.InitMethod();
}
#endregion
#region 辅助方法
/// <summary>
/// 初始化方法
/// </summary>
public void InitMethod()
{
this.Series.Clear();
this.Legend.Alignment = LegendAlignments.Right;
this.Legend.Visible = true;
this.Axes.Bottom.Automatic = false; //默认已累加方式显示曲线
this.Axes.Bottom.Maximum = this._num;
this.Aspect.ElevationFloat = 345D;
this.Aspect.RotationFloat = 345D;
this.Aspect.View3D = false;
this.Axes.Bottom.Grid.ZPosition = 0D;
this.Axes.Depth.Automatic = true;
this.Axes.Depth.Grid.ZPosition = 0D;
this.Axes.DepthTop.Automatic = true;
this.Axes.DepthTop.Grid.ZPosition = 0D;
this.Axes.Left.Automatic = true;
this.Axes.Left.Grid.ZPosition = 0D;
this.Axes.Right.Automatic = true;
this.Axes.Right.Grid.ZPosition = 0D;
this.Axes.Top.Automatic = true;
this.Axes.Top.Grid.ZPosition = 0D;
this.Cursor = System.Windows.Forms.Cursors.Default;
this.Header.Lines = new string[] {""};
this.Legend.Shadow.Visible = true;
this.Legend.Title.Font.Bold = true;
this.Legend.Title.Pen.Visible = false;
this.Legend.Visible = false;
this.Location = new System.Drawing.Point(100, 0);
this.Walls.Back.AutoHide = false;
this.Walls.Bottom.AutoHide = false;
this.Walls.Left.AutoHide = false;
this.Walls.Right.AutoHide = false;
this.Walls.Right.Visible = true;
this.MouseDown += new MouseEventHandler(MultiCurve_MouseDown);
this.MouseLeave += new EventHandler(MultiCurve_MouseLeave);
this.MouseMove += new MouseEventHandler(MultiCurve_MouseMove);
}
private void SetCurveName(string value, int i)
{
if (String.IsNullOrWhiteSpace(value))
{
if (list[i] != null)
{
this.Series.Remove(list[i]);
list[i].Dispose();
list[i] = null;
}
}
else
{
if (list[i] == null)
{
list[i] = new FastLine();
list[i].ShowInLegend = this._isShowLegend;
this.Series.Add(list[i]);
}
list[i].Title = value;
list[i].Visible = true;
}
}
#endregion
#region 拖动
const int Band = 5;
const int MinWidth = 50;
const int MinHeight = 60;
/// <summary>
/// 鼠标在事件源的位置
/// </summary>
private Point p = new Point();
private enum EnumMousePointPosition
{
MouseSizeNone = 0, //无
MouseDrag = 9 // 鼠标拖动
}
private EnumMousePointPosition m_MousePointPosition;
void MultiCurve_MouseMove(object sender, MouseEventArgs e)
{
Control lCtrl = (sender as Control);
if (e.Button == MouseButtons.Left)
{
switch (m_MousePointPosition)
{
case EnumMousePointPosition.MouseDrag:
if (this.Left > 930)
{
this.Left = 929;
return;
}
if (this.Top > 374)
{
this.Top = 373;
return;
}
this.Left = this.Left + e.X - p.X;
this.Top = this.Top + e.Y - p.Y;
break;
default:
break;
}
if (lCtrl.Width < MinWidth) lCtrl.Width = MinWidth;
if (lCtrl.Height < MinHeight) lCtrl.Height = MinHeight;
}
else
{
m_MousePointPosition = MousePointPosition(lCtrl.Size, e); //'判断光标的位置状态
switch (m_MousePointPosition) //'改变光标
{
case EnumMousePointPosition.MouseSizeNone:
this.Cursor = Cursors.Arrow; //'箭头
break;
case EnumMousePointPosition.MouseDrag:
this.Cursor = Cursors.SizeAll; //'四方向
break;
default:
break;
}
}
}
void MultiCurve_MouseLeave(object sender, EventArgs e)
{
m_MousePointPosition = EnumMousePointPosition.MouseSizeNone;
this.Cursor = Cursors.Arrow;
}
void MultiCurve_MouseDown(object sender, MouseEventArgs e)
{
p.X = e.X;
p.Y = e.Y;
}
private EnumMousePointPosition MousePointPosition(Size size, System.Windows.Forms.MouseEventArgs e)
{
if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height))
{
if (e.X >= Band)
{
if (e.X <= -1 * Band + size.Width)
{
if (e.Y >= Band)
{
if (e.Y <= -1 * Band + size.Height)
{
return EnumMousePointPosition.MouseDrag;
}
else
{
return EnumMousePointPosition.MouseSizeNone;
}
}
}
}
}
else
{ return EnumMousePointPosition.MouseSizeNone; }
return EnumMousePointPosition.MouseSizeNone;
}
#endregion
#region bHaveAction
private bool _bHaveAction;
public bool bHaveAction
{
get
{
return _bHaveAction;
}
set
{
_bHaveAction = value;
}
}
#endregion
#region 基本属性
/// <summary>
/// 数据源
/// </summary>
[TypeConverter(typeof(DataSourceConverter))]
public string MCDataSourceID
{
get;
set;
}
[Description("曲线的标题,可修改."), Category("Appearance")]
public string Title
{
get
{
return this.Text;
}
set
{
this.Text = value == null ? String.Empty : value;
}
}
/// <summary>
/// 是否显示时间刻度
/// </summary>
[Description("是否显示时间"), Category("Appearance")]
public bool IsShowTime
{
get { return this._isShowTime; }
set { this._isShowTime = value; }
}
/// <summary>
/// 是否显示图例
/// </summary>
[Description("显示图例"), Category("Appearance")]
public bool IsShowLegend
{
get { return _isShowLegend; }
set
{
_isShowLegend = value;
foreach (FastLine line in this.list)
{
if (line != null)
{
line.ShowInLegend = _isShowLegend;
}
}
}
}
/// <summary>
/// 保持的点数
/// </summary>
[Description("保持的点数"), Category("Appearance")]
public int Num
{
get { return this._num; }
set
{
this._num = value;
if (this._num < 10)
{
this._num = 10;
}
if (this._num > 1000)
{
this._num = 1000;
}
this.Axes.Bottom.Maximum = this._num;
}
}
/// <summary>
/// 曲线状态
/// </summary>
[Description("曲线状态"), Category("Appearance")]
public CurveTypes CurveType
{
get { return _curveType; }
set
{
_curveType = value;
if (_curveType == CurveTypes.Pan)
{
this.Axes.Bottom.Automatic = true;
}
else
{
this.Axes.Bottom.Automatic = false;
this.Axes.Bottom.Maximum = this._num;
}
}
}
/// <summary>
/// 是否关联密炼时间
/// </summary>
[Description("关联密炼时间"), Category("Behavior")]
public bool IsUseMixTime
{
get { return _isUseMixTime; }
set { _isUseMixTime = value; }
}
/// <summary>
/// 密炼时间
/// </summary>
[Description("密炼时间"), Category("Data")]
public int MixTime
{
get { return _mixTime; }
set { _mixTime = value; }
}
#endregion
#region 曲线名称属性定义
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName1
{
get
{
return list[0] == null ? String.Empty : list[0].Title;
}
set
{
SetCurveName(value, 0);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName2
{
get
{
return list[1] == null ? String.Empty : list[1].Title;
}
set
{
SetCurveName(value, 1);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName3
{
get
{
return list[2] == null ? String.Empty : list[2].Title;
}
set
{
SetCurveName(value, 2);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName4
{
get
{
return list[3] == null ? String.Empty : list[3].Title;
}
set
{
SetCurveName(value, 3);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName5
{
get
{
return list[4] == null ? String.Empty : list[4].Title;
}
set
{
SetCurveName(value, 4);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName6
{
get
{
return list[5] == null ? String.Empty : list[5].Title;
}
set
{
SetCurveName(value, 5);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName7
{
get
{
return list[6] == null ? String.Empty : list[6].Title;
}
set
{
SetCurveName(value, 6);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName8
{
get
{
return list[7] == null ? String.Empty : list[7].Title;
}
set
{
SetCurveName(value, 7);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName9
{
get
{
return list[8] == null ? String.Empty : list[8].Title;
}
set
{
SetCurveName(value, 8);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName10
{
get
{
return list[9] == null ? String.Empty : list[9].Title;
}
set
{
SetCurveName(value, 9);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName11
{
get
{
return list[10] == null ? String.Empty : list[10].Title;
}
set
{
SetCurveName(value, 10);
}
}
[Category("Data"), Description("曲线的名称,可修改.")]
public string CurveName12
{
get
{
return list[11] == null ? String.Empty : list[11].Title;
}
set
{
SetCurveName(value, 11);
}
}
#endregion
#region 动画属性
/// <summary>
/// 密炼时间动画属性
/// </summary>
public string MixTimeName
{
get { return _mixTimeName; }
set { _mixTimeName = value; }
}
private string[] _pointName = new string[LINENUM];
public string PointName1
{
get { return this._pointName[0]; }
set { this._pointName[0] = value; }
}
public string PointName2
{
get { return this._pointName[1]; }
set { this._pointName[1] = value; }
}
public string PointName3
{
get { return this._pointName[2]; }
set { this._pointName[2] = value; }
}
public string PointName4
{
get { return this._pointName[3]; }
set { this._pointName[3] = value; }
}
public string PointName5
{
get { return this._pointName[4]; }
set { this._pointName[4] = value; }
}
public string PointName6
{
get { return this._pointName[5]; }
set { this._pointName[5] = value; }
}
public string PointName7
{
get { return this._pointName[6]; }
set { this._pointName[6] = value; }
}
public string PointName8
{
get { return this._pointName[7]; }
set { this._pointName[7] = value; }
}
public string PointName9
{
get { return this._pointName[8]; }
set { this._pointName[8] = value; }
}
public string PointName10
{
get { return this._pointName[9]; }
set { this._pointName[9] = value; }
}
public string PointName11
{
get { return this._pointName[10]; }
set { this._pointName[10] = value; }
}
public string PointName12
{
get { return this._pointName[11]; }
set { this._pointName[11] = value; }
}
private void SetPointValue(double value, int i)
{
if (this._isUseMixTime && this._mixTime == 0)
{
this.Clear();
}
else
{
if (this.list[i] == null)
{
list[i] = new FastLine();
list[i].ShowInLegend = this._isShowLegend; //是否显示图例
list[i].Color = this.GetDefaultColor(i); //获取默认颜色
this.Series.Add(list[i]);
}
if (this._curveType == CurveTypes.Pan)
{
if (this.list[i].Count >= this._num)
{
this.list[i].Delete(0, 1, true);
}
}
else
{
if (this.list[i].Count >= this._num)
{
this.Num += 10;
}
}
if (this._isShowTime)
{
this.list[i].Add(value, String.Format(this._timeformat, DateTime.Now));
}
else
{
this.list[i].Add(value);
}
}
}
/// <summary>
/// 获取默认颜色
/// </summary>
/// <param name="i">曲线索引</param>
/// <returns>返回默认颜色</returns>
private Color GetDefaultColor(int i)
{
Color[] _colors = { Color.Red, Color.Green, Color.Purple, Color.Blue, Color.Black, Color.FromArgb(0x7b, 0x68, 0xee), Color.FromArgb(0xcd, 0x5c, 0x5c), Color.FromArgb(0xdb, 0x70, 0x93), Color.FromArgb(0x5f, 0x9e, 0xa0), Color.FromArgb(0xdd, 0xa0, 0xdd), Color.FromArgb(0x90, 0xee, 0x90), Color.FromArgb(0xff, 0x00, 0xff), Color.FromArgb(0x48, 0xd1, 0xcc) };
if (i >= _colors.Length - 1)
{
return Color.Red;
}
return _colors[i];
}
public void Clear()
{
for (int i = 0; i < list.Length; i++)
{
//this.list[i].Delete(0, this.list[i].Count, true);
if (this.list[i] != null)
this.list[i].Clear();
}
}
public double PointValue1
{
set
{
SetPointValue(value, 0);
}
}
public double PointValue2
{
set
{
SetPointValue(value, 1);
}
}
public double PointValue3
{
set
{
SetPointValue(value, 2);
}
}
public double PointValue4
{
set
{
SetPointValue(value, 3);
}
}
public double PointValue5
{
set
{
SetPointValue(value, 4);
}
}
public double PointValue6
{
set
{
SetPointValue(value, 5);
}
}
public double PointValue7
{
set
{
SetPointValue(value, 6);
}
}
public double PointValue8
{
set
{
SetPointValue(value, 7);
}
}
public double PointValue9
{
set
{
SetPointValue(value, 8);
}
}
public double PointValue10
{
set
{
SetPointValue(value, 9);
}
}
public double PointValue11
{
set
{
SetPointValue(value, 10);
}
}
public double PointValue12
{
set
{
SetPointValue(value, 11);
}
}
#endregion
#region 颜色设置
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue1
{
get
{
if (this.list[0] != null)
return this.list[0].LinePen.Color;
else
return this.GetDefaultColor(0); //默认红色
}
set
{
if (this.list[0] != null)
{
this.list[0].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue2
{
get
{
if (this.list[1] != null)
return this.list[1].LinePen.Color;
else
return this.GetDefaultColor(1); //默认绿色
}
set
{
if (this.list[1] != null)
{
this.list[1].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue3
{
get
{
if (this.list[2] != null)
return this.list[2].LinePen.Color;
else
return this.GetDefaultColor(2); //默认紫色
}
set
{
if (this.list[2] != null)
{
this.list[2].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue4
{
get
{
if (this.list[3] != null)
return this.list[3].LinePen.Color;
else
return this.GetDefaultColor(3); //默认蓝色
}
set
{
if (this.list[3] != null)
{
this.list[3].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue5
{
get
{
if (this.list[4] != null)
return this.list[4].LinePen.Color;
else
return this.GetDefaultColor(4); //默认黑色
}
set
{
if (this.list[4] != null)
{
this.list[4].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue6
{
get
{
if (this.list[5] != null)
return this.list[5].LinePen.Color;
else
return this.GetDefaultColor(5);
}
set
{
if (this.list[5] != null)
{
this.list[5].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue7
{
get
{
if (this.list[6] != null)
return this.list[6].LinePen.Color;
else
return this.GetDefaultColor(6);
}
set
{
if (this.list[6] != null)
{
this.list[6].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue8
{
get
{
if (this.list[7] != null)
return this.list[7].LinePen.Color;
else
return this.GetDefaultColor(7);
}
set
{
if (this.list[7] != null)
{
this.list[7].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue9
{
get
{
if (this.list[8] != null)
return this.list[8].LinePen.Color;
else
return this.GetDefaultColor(8);
}
set
{
if (this.list[8] != null)
{
this.list[8].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue10
{
get
{
if (this.list[9] != null)
return this.list[9].LinePen.Color;
else
return this.GetDefaultColor(9);
}
set
{
if (this.list[9] != null)
{
this.list[9].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue11
{
get
{
if (this.list[10] != null)
return this.list[10].LinePen.Color;
else
return this.GetDefaultColor(10);
}
set
{
if (this.list[10] != null)
{
this.list[10].LinePen.Color = value;
}
}
}
[Category("Data"), Description("曲线颜色,可修改.")]
public Color ColorValue12
{
get
{
if (this.list[11] != null)
return this.list[11].LinePen.Color;
else
return this.GetDefaultColor(11);
}
set
{
if (this.list[11] != null)
{
this.list[11].LinePen.Color = value;
}
}
}
#endregion
}
}