using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace wsControls
{
#region [ Classs ] wsPlot
public class wsPlot
{
//public static void DrawArc(Graphics g, Pen pen, PointF center, decimal radius, decimal startangle, decimal sweepangle)
//{
// decimal x = center.X - radius;
// decimal y = center.Y - radius;
// decimal w = radius + radius;
// decimal h = w;
// decimal start = (decimal)(startangle * Math.PI / 180);
// decimal sweep = (decimal)(sweepangle * Math.PI / 180);
// g.DrawArc(pen, x, y, w, h, start, sweep);
//}
public static void DrawConnection(Graphics g, Pen pen, float x1, float y1, float x2, float y2, float radius)
{
int offset = (int)pen.Width % 2 > 0 ? 0 : 1;
float xn, yn;
if (y2 > y1&&x2>x1)
{
yn = y2 - radius;
g.DrawLine(pen, x1, y1, x1, yn+offset);//|
g.DrawArc(pen, x1 - offset, yn - radius, radius + radius, radius + radius, 90, 90);//|_
xn = x1 + radius;
g.DrawLine(pen, x2, y2,xn - offset, y2);// _
}
else if (y2 < y1 && x2 > x1)
{
xn = x2 - radius;
yn = y1 - radius;
g.DrawLine(pen, x1, y1, xn, y1 + offset);//|
g.DrawArc(pen, xn-radius, y1-radius-radius, radius + radius, radius + radius, 90, -90);//|_|
g.DrawLine(pen, x2, y2, x2, yn+offset);// _
}
else if (y2 < y1 && x2 < x1)
{
xn = x1 - radius;
yn = y2 + radius;
g.DrawLine(pen, x1, yn - offset,x1, y1);//|
g.DrawArc(pen, xn - radius, y2, radius + radius, radius + radius, -90, 90);//|_|
g.DrawLine(pen, x2, y2, xn + offset, y2);// _
}
else if (y2 > y1 && x2 < x1)
{
xn = x2 + radius;
yn = y1 + radius;
g.DrawLine(pen, xn-offset, y1,x1, y1);//|
g.DrawArc(pen, x2, y1, radius + radius, radius + radius, 180, 90);//|_|
g.DrawLine(pen, x2, y2,x2, yn-offset);// _
}
}
float dx, dy;
float Pxmin, Pxmax;
float Pymin, Pymax;
public double[] Fi;
public float[] posx;
#region [ Property ] Width. Height
public int Width { get; set; }
public int Height { get; set; }
#endregion
public wsPlot(int width, int height, wsPlotProperty property)
{
ReSize(width, height, property);
}
#region [ Function ] Resize
public void ReSize(int width, int height, wsPlotProperty property)
{
Width = width;
Height = height;
Pxmin = property.LeftSpace;
Pxmax = width - property.RightSpace;
dx = (Pxmax - Pxmin) / 10f;
Pymin = property.TopSpace;
Pymax = height - property.BottomSpace;
dy = (Pymax - Pymin) / property.Ydiv;
}
#endregion
#region [ Function ] DrawBackground -- Grid & Text
public void DrawBackground(Graphics g, wsPlotProperty property)
{
DrawGrid(g, property);
UpdateText(g, property);
}
private void DrawGrid(Graphics g, wsPlotProperty property)
{
g.Clear(property.BackColor);
Pen gridpen = new Pen(property.GridColor);
float Px, Py;
for (int i = 0; i < 11; i++)
{
Px = (float)(Pxmin + i * dx);
g.DrawLine(gridpen, new PointF(Px, Pymin), new PointF(Px, Pymax));
}
for (int i = 0; i <= property.Ydiv; i++)
{
Py = Pymin + i * dy;
g.DrawLine(gridpen, new PointF(Pxmin, Py), new PointF(Pxmax, Py));
}
}
public string Format = "N2";
private void UpdateText(Graphics g, wsPlotProperty property)
{
Brush brush = new SolidBrush(property.ForeColor);
Font font = property.TitleFont;
//Title...
SizeF sf = g.MeasureString(property.Title, font);
g.DrawString(property.Title, font, brush,
new PointF((this.Width - sf.Width) / 2f, (Pymin - sf.Height) / 2F));
//Label Y...
font = property.Font;
sf = g.MeasureString(property.yLabel, font);
g.DrawString(property.yLabel, font, brush,
new PointF(Pxmin, (Pymin - 1 - sf.Height)));
//Label X...
sf = g.MeasureString(property.xLabel, font);
g.DrawString(property.xLabel, font, brush,
new PointF(Pxmin + 5*dx - sf.Width / 2f, Pymax + 1));
//X Scale...
string V = property.xMin.ToString(Format);
g.DrawString(V, font, brush, new PointF(Pxmin, Pymax + 1));
V = property.xMax.ToString(Format);
sf = g.MeasureString(V, font);
g.DrawString(V, font, brush, new PointF(Pxmax - sf.Width, Pymax + 1));
//Y Scale...
for (int i = 0; i <= property.Ydiv; i++)
{
V = (property.Refer - i * property.Scale).ToString(Format);
sf = g.MeasureString(V, font);
g.DrawString(V, font, brush,
new PointF(Pxmin - 1 - sf.Width, Pymin - sf.Height / 2 + i * dy));
}
brush.Dispose();
}
#endregion
#region [ Function ] Update Frequency & Position
public float[] GetPositionX(decimal[] f, wsPlotProperty property)
{
int ilength = f.Length;
float[] pos = new float[ilength];
decimal k =(decimal) dx * 10 / (property.xMax - property.xMin);
for (int i = 0; i < ilength; i++)
pos[i] = Pxmin + (float)((f[i] - property.xMin) * k);
return pos;
}
public float[] GetPositionX(int N, wsPlotProperty property)
{
int ilength = N;
float[] pos = new float[ilength];
decimal k = (decimal)dx * 10 / (ilength - 1);
for (int i = 0; i < ilength; i++)
pos[i] = Pxmin + (float)(i * k);
return pos;
}
#endregion
#region [ Function ] Add Trace
public PointF[] AddTrace(Graphics g, decimal[] data, Color color, string name, wsPlotProperty property)
{
PointF[] path = AddTrace(g, data, color, property);
//Trace name
SizeF sf = g.MeasureString(name, property.Font);
g.DrawString(name, property.Font, new SolidBrush(color), new PointF(Pxmax + 1, path[path.Length - 1].Y - sf.Height / 2));
return path;
}
public PointF[] AddTrace(Graphics g, decimal[] data, Color color, wsPlotProperty property)
{
decimal ymin = property.Refer - property.Ydiv * property.Scale;
int length = data.Length;
PointF[] path = new PointF[length];
for (int i = 0; i < length; i++)
{
path[i].X =(float) posx[i];
path[i].Y = Pymax - (float)((data[i] - ymin) *(decimal) dy / property.Scale);
if (path[i].Y < Pymin)
path[i].Y = Pymin;
else if (path[i].Y > Pymax)
path[i].Y = Pymax;
}
g.DrawLines(new Pen(color, 1F), path);
return path;
}
public PointF[] AddTrace(Graphics g, decimal[] data, Color color, wsPlotProperty property, int istart, int istop)
{
decimal ymin = property.Refer - property.Ydiv * property.Scale;
int length = istop - istart + 1;
PointF[] path = new PointF[length];
for (int i = 0; i < length; i++)
{
path[i].X = (float)posx[i];
path[i].Y = Pymax - (float)((data[i+istart] - ymin) * (decimal)dy / property.Scale);
if (path[i].Y < Pymin)
path[i].Y = Pymin;
else if (path[i].Y > Pymax)
path[i].Y = Pymax;
}
g.DrawLines(new Pen(color, 1F), path);
return path;
}
public PointF[] AddTrace(Graphics g, Collection<decimal>data, Color color, wsPlotProperty property)
{
decimal ymin = property.Refer - property.Ydiv * property.Scale;
int length = data.Count;
PointF[] path = new PointF[length];
for (int i = 0; i < length; i++)
{
path[i].X = (float)posx[i];
path[i].Y = Pymax - (float)((data[i] - ymin) * (decimal)dy / property.Scale);
if (path[i].Y < Pymin)
path[i].Y = Pymin;
else if (path[i].Y > Pymax)
path[i].Y = Pymax;
}
g.DrawLines(new Pen(color, 1F), path);
return path;
}
public PointF[] AddTrace(Graphics g, Collection<decimal> data, Color color, wsPlotProperty property, int istart, int istop)
{
decimal ymin = property.Refer - property.Ydiv * property.Scale;
int length = istop - istart + 1;
PointF[] path = new PointF[length];
for (int i = 0; i <length; i++)
{
path[i].X = (float)posx[i];
path[i].Y = Pymax - (float)((data[i+istart] - ymin) * (decimal)dy / property.Scale);
if (path[i].Y < Pymin)
path[i].Y = Pymin;
else if (path[i].Y > Pymax)
path[i].Y = Pymax;
}
g.DrawLines(new Pen(color, 1F), path);
return path;
}
public PointF[] AddTrace(Graphics g, decimal[] Fi, decimal[] data, Color color, wsPlotProperty property)
{
posx = GetPositionX(Fi, property);
int length = data.Length;
decimal ymin = property.Refer - property.Ydiv * property.Scale;
PointF[] path = new PointF[length];
for (int i = 0; i < length; i++)
{
path[i].X = posx[i];
path[i].Y = Pymax - (float)((data[i] - ymin) *(decimal) dy / property.Scale);
if (path[i].Y < Pymin)
path[i].Y = Pymin;
else if (path[i].Y > Pymax)
path[i].Y = Pymax;
}
g.DrawLines(new Pen(color, 1F), path);
return path;
}
#endregion
#region [ Function ] Add Marker
public void AddMarker(Graphics g, wsMarker marker, wsPlotProperty property)
{
SizeF sf = g.MeasureString(marker.Value, property.Font);
g.DrawString(marker.Value, property.Font, new SolidBrush(marker.Color),
new PointF(marker.PointF.X - sf.Width / 2F, marker.PointF.Y - dy / 3 - sf.Height));
}
public void AddMarker(Graphics g, PointF[] path, decimal[] trace, int[] indexes, wsPlotProperty property)
{
int markerysize = property.MarkerSize + property.MarkerSize;
Point[] markerpath;
GraphicsPath gpath;
Font font = new Font(property.MarkerFont.FontFamily, markerysize, FontStyle.Bold);
SizeF sf = g.MeasureString("1MHz dBm", font);
string mkrtext; string mkrtextfmt = "F" + property.MarkerDecimals.ToString();
float mpx;
float dpy = 4;
float mpy = Pymin - sf.Height - dpy / 2;
for (int i = 0; i < indexes.Length; i++)
{
if (indexes[i] >= trace.Length) continue;
markerpath = new Point[]
{
new Point((int)path[indexes[i]].X-property.MarkerSize,(int)path[indexes[i]].Y),
new Point((int)path[indexes[i]].X,(int)path[indexes[i]].Y-markerysize),
new Point((int)path[indexes[i]].X+property.MarkerSize,(int)path[indexes[i]].Y),
new Point((int)path[indexes[i]].X,(int)path[indexes[i]].Y+markerysize),
};
gpath = new GraphicsPath();
gpath.AddLines(markerpath);
gpath.CloseFigure();
if (property.MarkerFill)
g.FillPath(new SolidBrush(property.MarkerColor), gpath);
else
g.DrawPath(new Pen(property.MarkerColor, property.MarkerLineWidth), gpath);
//Marker Index
mkrtext = (i + 1).ToString();
sf = g.MeasureString(mkrtext, font);
g.DrawString(mkrtext, font, new SolidBrush(property.MarkerColor), new PointF(posx[indexes[i]] + property.MarkerSize, path[indexes[i]].Y - sf.Height));
//Marker X Text
mkrtext = "[Mkr" + mkrtext + "] " + wsArray.GetValue(property.xMin, property.xMax, posx.Length, indexes[i]).ToString() + " " + property.MarkerUnitX + ": "
+ trace[indexes[i]].ToString(mkrtextfmt) + " " + property.MarkerUnitY;
sf = g.MeasureString(mkrtext, font);
g.DrawString(mkrtext, font, new SolidBrush(property.MarkerColor), Pxmax - sf.Width, mpy); mpy += sf.Height + dpy;
}
}
public void AddMarker(Graphics g, PointF[] path, Collection<decimal> trace, int[] indexes, wsPlotProperty property)
{
int markerysize = property.MarkerSize + property.MarkerSize;
Point[] markerpath;
GraphicsPath gpath;
Font font = new Font(property.MarkerFont.FontFamily, markerysize, FontStyle.Bold);
SizeF sf = g.MeasureString("1MHz dBm", font);
string mkrtext; string mkrtextfmt = "F" + property.MarkerDecimals.ToString();
float mpx;
float dpy = 4;
float mpy = Pymin - sf.Height - dpy / 2;
for (int i = 0; i < indexes.Length; i++)
{
if (indexes[i] >= trace.Count) continue;
markerpath = new Point[]
{
new Point((int)path[indexes[i]].X-property.MarkerSize,(int)path[indexes[i]].Y),
new Point((int)path[indexes[i]].X,(int)path[indexes[i]].Y-markerysize),
new Point((int)path[indexes[i]].X+property.MarkerSize,(int)path[indexes[i]].Y),
new Point((int)path[indexes[i]].X,(int)path[indexes[i]].Y+markerysize),
};
gpath = new GraphicsPath();
gpath.AddLines(markerpath);
gpath.CloseFigure();
if (property.MarkerFill)
g.FillPath(new SolidBrush(property.MarkerColor), gpath);
else
g.DrawPath(new Pen(property.MarkerColor, property.MarkerLineWidth), gpath);
//Marker Index
mkrtext = (i + 1).ToString();
sf = g.MeasureString(mkrtext, font);
g.DrawString(mkrtext, font, new SolidBrush(property.MarkerColor), new PointF(posx[indexes[i]] + property.MarkerSize, path[indexes[i]].Y - sf.Height));
//Marker X Text
mkrtext = "[Mkr" + mkrtext + "] " + wsArray.GetValue(property.xMin, property.xMax, posx.Length, indexes[i]).ToString() + " " + property.MarkerUnitX + ": "
+ trace[indexes[i]].ToString(mkrtextfmt) + " " + property.MarkerUnitY;
sf = g.MeasureString(mkrtext, font);
g.DrawString(mkrtext, font, new SolidBrush(property.MarkerColor), Pxmax - sf.Width, mpy); mpy += sf.Height + dpy;
}
}
public void AddMarker(Graphics g, PointF[] path, int index, string mkrtext, wsPlotProperty property)
{
if (index >= path.Length) return;
int markerysize = property.MarkerSize + property.MarkerSize;
Point[] markerpath = new Point[]
{
new Point((int)path[index].X-property.MarkerSize,(int)path[index].Y),
new Point((int)path[index].X,(int)path[index].Y-markerysize),
new Point((int)path[index].X+property.MarkerSize,(int)path[index].Y),
new Point((int)path[index].X,(int)path[index].Y+markerysize),
};
GraphicsPath gpath = new GraphicsPath();
gpath.AddLines(markerpath);
gpath.CloseFigure();
if (property.MarkerFill)
g.FillPath(new SolidBrush(property.MarkerColor), gpath);
else
g.DrawPath(new Pen(property.MarkerColor), gpath);
Font font = new Font(property.MarkerFont.FontFamily, markerysize);
SizeF sf = g.MeasureString(index.ToString(), font);
g.DrawString(mkrtext, font, new SolidBrush(property.MarkerColor), new PointF(posx[index] + property.MarkerSize, path[index].Y - sf.Height));
}
public void AddMarker(Graphics g, PointF pos, string text, wsPlotProperty property)
{
int markerysize = property.MarkerSize + property.MarkerSize;
Point[] markerpath = new Point[]
{
new Point((int)pos.X-property.MarkerSize,(int)pos.Y),
new Point((int)pos.X,(int)pos.Y-markerysize),
new Point((int)pos.X+property.MarkerSize,(int)pos.Y),
new Point((int)pos.X,(int)pos.Y+markerysize),
};
GraphicsPath gpath = new GraphicsPath();
gpath.AddLines(markerpath);
gpath.CloseFigure();
if (property.MarkerFill)
g.FillPath(new SolidBrush(property.MarkerColor), gpath);
else
g.DrawPath(new Pen(property.MarkerColor), gpath);
Font font = new Font(property.MarkerFont.FontFamily, markerysize);
SizeF sf = g.MeasureString(text, font);
g.DrawString(text, font, new SolidBrush(property.MarkerColor), new PointF(pos.X + property.MarkerSize, pos.Y - sf.Height));
}
public void AddMarker(Graphics g, PointF pos, string text, Font font)
{
int markersize = 6;
int markerysize = markersize * 2;
Color markercolor = Color.Green;
bool markerfill = false;
Point[] markerpath = new Point[]
{
new Point((int)pos.X-markersize,(int)pos.Y),
new Point((int)pos.X,(int)pos.Y-markerysize),
new Point((int)pos.X+markersize,(int)pos.Y),
new Point((int)pos.X,(int)pos.Y+markerysize),
};
GraphicsPath gpath = new GraphicsPath();
gpath.AddLines(markerpath);
gpath.CloseFigure();
if (markerfill)
g.FillPath(new SolidBrush(markercolor), gpath);
else
g.DrawPath(new Pen(markercolor), gpath);
SizeF sf = g.MeasureString(text, font);
g.DrawString(text, font, new SolidBrush(markercolor), new PointF(pos.X + markersize, pos.Y - sf.Height));
}
#endregion
}
#endregion
#region [ Class ] wsPlotProperty with Type Converter
[TypeConverter(typeof(wsPlotPropertyTypeConverter)), Description("PlotProperty"), DisplayName("PlotProperty")]
public class wsPlotProperty
{
#region [ Constructor ]
public wsPlotProperty()
{
Title = "Spectrum Analyze";
TitleFont = new System.Drawing.Font("Arial", 12F, FontStyle.Bold);
Font = new System.Drawing.Font("Arial", 8F, FontStyle.Regular);
xLabel = "Frequency [ MHz ]";
yLabel = "dBm";
BackColor = Color.Black;
ForeColor = Color.Gold;
GridColor = Color.LightGray;
xMin = 0;
xMax = 100;
Refer = 0;
Ydiv = 10;
Scale = 10;
LeftSpace = 50;
RightSpace = 10;
TopSpace = 50;
BottomSpace = 30;
TraceColor = Color.Yellow;
Alpha = 192;
MarkerSize = 6;
MarkerColor = Color.Lime;
MarkerFill = false;
MarkerFont = new Font("Tahoma", 10f);
MarkerUnitX = "MHz";
MarkerUnitY = "dBm";
MarkerLineWidth = 2;
MarkerDecimals = 2;
}
#endregion
public event EventHandler BackgroundChanged;
#region [ Property ] Display: Tittle, TittleFont, Font, xLabel, yLabey, BackColor, ForeColor, GridColor
string title;
[Category("Diaplay"), DisplayName("标题")]
public string Title
{
get { return title; }
set
{
title = value;
if (BackgroundChanged != null) BackgroundChanged(this, new EventArgs());
}
}
[Category("Diaplay"), DisplayName("标题字体")]
public Font TitleFont { get; set; }
[Category("Diaplay"), DisplayName("字体")]
public Font Font { get; set; }
string xlabel;
[Category("Diaplay"), DisplayName("X坐标标示"), Description("X Axis Label Text"), Browsable(true)]
public string xLabel
{
get
{ return xlabel; }
set
{
xlabel = value;
if (BackgroundChanged != null) BackgroundChanged(this, new EventArgs());
}
}
string ylabel;
[Category("Diaplay"), DisplayName("Y坐标标示"), Description("Y Axis Label Text"), Browsable(true)]
public string yLabel
{
get
{ return ylabel; }
set
{
ylabel = value;
if (BackgroundChanged != null) BackgroundChanged(this, new EventArgs());
}
}
Color backcolor;
[Category("Diaplay"), DisplayName("背景色"), Description("Background Color")]
public Color BackColor
{
get
{
return backcolor;
}
set
{
backcolor = value;
if (BackgroundChanged != null) BackgroundChanged(this, new EventArgs());
}
}
Color forecolor;
[Category("Diaplay"), DisplayName("前景色"), Description("Foreground Color")]
public Color ForeColor
{
get
{
return forecolor;
}
set
{
forecolor = value;
if (BackgroundChanged != null) BackgroundChanged(this, new EventArgs());
}
}
Color gridcolor;
[Category("Diaplay"), DisplayName("分割线色"), Description("Grid Line Color")]
public Color GridColor
{
get
{ return gridcolor; }
set
{
gridcolor = value;
if (BackgroundChanged != null) BackgroundChanged(this, new EventArgs());
}
}
#endregion
public event EventHandler ScaleChanged;
decimal xmin;
#region [ Property ] Scale: xMin, xMax, Refer, Scale
[Category("Scale / Div"), DisplayName("X最小坐标值"), Description("Min Frequency"), Browsable(true)]
public decimal xMin
{
get
{
return xmin;
}
set
{
xmin = value;
if (ScaleChanged != null) ScaleChanged(this, new EventArgs());
}
}
decimal xmax;
[Category("Scale / Div"), DisplayName("X最大坐标值"), Description("Max Frequency"), Browsable(true)]
public decimal xMax
{
get
{
return xmax;
}
set
{
xmax = value;
if (ScaleChanged != null) ScaleChanged(this, new EventArgs());
}
}
decimal refer;
[Category("Scale / Div"), DisplayName("Y Reference")]
public decimal Refer
{
get
{
return refer;
}
set
{
refer = value;
if (ScaleChanged != null) ScaleChanged(this, new EventArgs());
}
}
int ydiv;
[Category("Scale / Div"),DisplayName("Y Div")]
public int Ydiv
{
get
{
return ydiv;
}
set
{
ydiv = value;
ydiv = ydiv < 1 ? 2 : ydiv;
if (ScaleChanged != null) ScaleChanged(this, new EventArgs());
}
}
decimal scale;
[Category("Scale / Div"), DisplayName("Y Scale/Div")]
public decimal Scale
{
get
{
return scale;
}
set
{
scale = value;
if (ScaleChanged != null) ScaleChanged(this, new EventArgs());
}
}
#endregion
#region [ Location ]
[Category("Location"), DefaultValue(75), Browsable(true),DisplayName("左侧间隙")]
public int LeftSpace { get; set; }
[Category("Location"), DefaultValue(75), Browsable(true), DisplayName("右侧间隙")]
public int RightSpace { get; set; }
[Category("Location"), DefaultValue(50), Browsable(true),DisplayName("顶部间隙")]
public int TopSpace { get; set; }
[Category("Location"), DefaultValue(50), Browsable(true), DisplayName("底部间隙")]
public int BottomSpace { get; set; }
#endregion
#region [Trace ]
[Category("Trace"), Browsable(true), DisplayName("Trace Color")]
public Color TraceColor { get; set; }
[Category("Trace"), Browsable(true), DisplayName("Alpha")]
public int Alpha { get; set; }
#endregion
#region [ Marker ]
[Category("Marker"), DefaultValue(6), Browsable(true), DisplayName("Marker Size")]
public int MarkerSize { get; set; }
[Category("Marker"), Browsable(true), DisplayName("Marker Color")]
public Color MarkerColor { get; set; }
[Category("Marker"), DefaultValue(1), Browsable(true), DisplayName("Marker Line Width")]
public float MarkerLineWidth { get; set; }
[Category("Marker"), DefaultValue(false), Browsable(true), DisplayName("Marker Fill")]
public bool MarkerFill { get; set; }
[Category("Marker"), Browsable(false)]
public Font MarkerFont { get; set; }
[Category("Marker"), DefaultValue(2), Browsable(true), DisplayName("Marker Decimal Places")]
public int MarkerDecimals { get; set; }
[Category("Marker"), DefaultValue("MHz"), Browsable(true), DisplayName("Marker Unit X ")]
public string MarkerUnitX { get; set; }
[Category("Marker"), DefaultValue("dBm"), Browsable(true), DisplayName("Marker Unit Y")]
public string MarkerUnitY { get; set; }
#endregion
public override string ToString()
{
return string.Empty;
}
#region [ Function ] From / To StringX
public StringX ToStringX()
{
string str = string.Empty;
char t = (char)220;
str += this.BackColor.ToArgb().ToString() + t;
str += this.ForeColor.ToArgb().ToString() + t;
str += this.GridColor.ToArgb().ToString() + t;
str += this.LeftSpace.ToString() + t;
str += this.RightSpace.ToString() + t;
str += this.Refer.ToString() + t;
str += this.Scale.ToString() + t;
str += this.Title + t;
str += this.TopSpace.ToString() + t;
str += this.BottomSpace.ToString() + t;
str += this.xLabel + t;
str += this.xMax.ToString() + t;
str += this.xMin.ToString() + t;
str += this.yLabel + t;
str += this.ydiv.ToString() + t;
str += this.TraceColor.ToArgb().ToString() + t;
str += this.Alpha.ToString() + t;
str += this.MarkerSize.ToString() + t;
str += this.MarkerColor.ToArgb().ToString() + t;
str += this.MarkerLineWidth.ToString() + t;
str += this.MarkerFill.ToString() + t;
str += this.MarkerDecimals.ToString() + t;
str += this.MarkerUnitX + t;
str += this.MarkerUnitY + t;
StringX sx = new StringX("Plot");
sx.String = str;
return sx;
}
public void FromStringX(StringX str)
{
string[] s = str.String.Split((char)220);
if(s.Length<17)
s = str.String.Split((char)252);
int i = 0;
this.BackColor = Color.FromArgb(Convert.ToInt32(s[i])); i++;
this.ForeColor = Color.FromArgb(Convert.ToInt32(s[i])); i++;
///////////////////
this.GridColor = Color.FromArgb(Convert.ToInt32(s[i])); i++;
this.LeftSpace = Convert.ToInt32(s[i]); i++;
this.RightSpace = Convert.ToInt32(s[i]); i++;
this.Refer = Convert.ToDecimal(s[i]); i++;
this.Scale = Convert.ToDecimal(s[i]); i++;
this.Title = s[i]; i++;
this.TopSpace = Convert.ToInt32(s[i]); i++;
this.BottomSpace = Convert.ToInt32(s[i]); i++;
this.xLabel = s[i]; i++;
this.xMax = Convert.ToDecimal(s[i]); i++;
this.xMin = Convert.ToDecimal(s[i]); i++;
this.yLabel = s[i]; i++;
this.Ydiv = Convert.ToInt32(s[i]); i++;
this.TraceColor = Color.FromArgb(Convert.ToInt32(s[i])); i++;
this.Alpha = Convert.ToInt32(s[i]); i++;
this.MarkerSize = Convert.ToInt32(s[i]); i++;
this.MarkerColor = Color.FromArgb(Convert.ToInt32(s[i])); i++;
this.MarkerLineWidth = Convert.ToSingle(s[i]); i++;
this.MarkerFill = Convert.ToBoolean(s[i]); i++;
this.MarkerDecimals = Convert.ToInt32(s[i]); i++;
this.MarkerUnitX = s[i]; i++;
this.MarkerUnitY = s[i]; i++;
}
#endregion
}
public class wsPlotPropertyTypeConverter : ExpandableObjectConverter
{
#region Can Convert
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(wsPlotProperty))
return true;
return base.CanConvertTo(context, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(StringX))
return true;
return base.CanConvertFrom(context, sourceType);
}
#endregion
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(StringX) && value is wsPlotProperty)
return ((wsPlotProperty)value).ToStringX();
return base.ConvertTo(context, culture, value, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value is StringX)
{
try
{
wsPlotProperty p = new wsPlotProperty();
p.FromStringX((StringX)value);
return p;
}
catch (Exception ex)
{
throw new ArgumentException(ex.ToString());
}
}
return base.ConvertFrom(context, culture, value);
}
}
#endregion
#region [ Class ] wsMarker
public class wsMarker
{
public PointF PointF { get; set; }
public Color Color { get; set; }
public string Value { get; set; }
public wsMarker(PointF pf, Color cor, string val)
{
PointF = pf;
Color = cor;
Value = val;
}
}
#endregion
}
08-23