using System;
using System.ComponentModel;
using System.Collections.Generic;
using FastReport.Utils;
using System.Drawing;
using System.Drawing.Design;
namespace FastReport.Gauge
{
///
/// Represents a gauge object.
///
public partial class GaugeObject : ReportComponentBase
{
#region Fields
private double maximum;
private double minimum;
private double value;
private GaugeScale scale;
private GaugePointer pointer;
private GaugeLabel label;
private string expression;
#endregion // Fields
#region Properties
///
/// Gets or sets the minimal value of gauge.
///
[Category("Layout")]
public double Minimum
{
get { return minimum; }
set
{
if (value < maximum)
{
minimum = value;
if (this.value < minimum)
{
this.value = minimum;
}
}
}
}
///
/// Gets or sets the maximal value of gauge.
///
[Category("Layout")]
public double Maximum
{
get { return maximum; }
set
{
if (value > minimum)
{
maximum = value;
if (this.value > maximum)
{
this.value = maximum;
}
}
}
}
///
/// Gets or sets the current value of gauge.
///
[Category("Layout")]
public double Value
{
get { return value; }
set
{
if ((value >= minimum) && (value <= maximum))
{
this.value = value;
}
else if (value < minimum)
{
this.value = minimum;
}
else if (value > maximum)
{
this.value = maximum;
}
}
}
///
/// Gets or sets scale of gauge.
///
[Category("Appearance")]
[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
[Editor("FastReport.TypeEditors.ScaleEditor, FastReport", typeof(UITypeEditor))]
public GaugeScale Scale
{
get { return scale; }
set { scale = value; }
}
///
/// Gets or sets pointer of gauge.
///
[Category("Appearance")]
[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
[Editor("FastReport.TypeEditors.PointerEditor, FastReport", typeof(UITypeEditor))]
public GaugePointer Pointer
{
get { return pointer; }
set { pointer = value; }
}
///
/// Gets or sets gauge label.
///
[Category("Appearance")]
[TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
[Editor("FastReport.TypeEditors.LabelEditor, FastReport", typeof(UITypeEditor))]
public virtual GaugeLabel Label
{
get { return label; }
set { label = value; }
}
///
/// Gets or sets an expression that determines the value of gauge object.
///
[Category("Data")]
[Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
public string Expression
{
get { return expression; }
set { expression = value; }
}
///
/// Gets a value that specifies is gauge vertical or not.
///
[Browsable(false)]
public bool Vertical
{
get { return Width < Height; }
}
#endregion // Properties
#region Constructors
///
/// Initializes a new instance of the class.
///
public GaugeObject()
{
minimum = 0;
maximum = 100;
value = 10;
scale = new GaugeScale(this);
pointer = new GaugePointer(this);
label = new GaugeLabel(this);
expression = "";
}
///
/// Initializes a new instance of the class.
///
/// Minimum value of gauge.
/// Maximum value of gauge.
/// Current value of gauge.
public GaugeObject(double minimum, double maximum, double value)
{
this.minimum = minimum;
this.maximum = maximum;
this.value = value;
scale = new GaugeScale(this);
pointer = new GaugePointer(this);
label = new GaugeLabel(this);
expression = "";
}
///
/// Initializes a new instance of the class.
///
/// Minimum value of gauge.
/// Maximum value of gauge.
/// Current value of gauge.
/// Scale of gauge.
/// Pointer of gauge.
public GaugeObject(double minimum, double maximum, double value, GaugeScale scale, GaugePointer pointer)
{
this.minimum = minimum;
this.maximum = maximum;
this.value = value;
this.scale = scale;
this.pointer = pointer;
label = new GaugeLabel(this);
expression = "";
}
#endregion // Constructors
#region Report Engine
///
public override string[] GetExpressions()
{
List expressions = new List();
expressions.AddRange(base.GetExpressions());
if (!String.IsNullOrEmpty(Expression))
{
expressions.Add(Expression);
}
return expressions.ToArray();
}
///
public override void GetData()
{
base.GetData();
if (!String.IsNullOrEmpty(Expression))
{
object val = Report.Calc(Expression);
if (val != null)
{
try
{
Value = Converter.StringToFloat(val.ToString());
}
catch
{
Value = 0.0;
}
}
}
}
#endregion // Report Engine
#region Public Methods
///
public override void Assign(Base source)
{
base.Assign(source);
GaugeObject src = source as GaugeObject;
Maximum = src.Maximum;
Minimum = src.Minimum;
Value = src.Value;
Expression = src.Expression;
Scale.Assign(src.Scale);
Pointer.Assign(src.Pointer);
Label.Assign(src.Label);
}
///
/// Draws the gauge.
///
/// Draw event arguments.
public override void Draw(FRPaintEventArgs e)
{
base.Draw(e);
scale.Draw(e);
pointer.Draw(e);
Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
}
///
public override void Serialize(FRWriter writer)
{
GaugeObject c = writer.DiffObject as GaugeObject;
base.Serialize(writer);
if (Maximum != c.Maximum)
{
writer.WriteDouble("Maximum", Maximum);
}
if (Minimum != c.Minimum)
{
writer.WriteDouble("Minimum", Minimum);
}
if (Value != c.Value)
{
writer.WriteDouble("Value", Value);
}
if (Expression != c.Expression)
{
writer.WriteStr("Expression", Expression);
}
if (Scale != c.Scale)
{
Scale.Serialize(writer, "Scale", c.Scale);
}
if (Pointer != c.Pointer)
{
Pointer.Serialize(writer, "Pointer", c.Pointer);
}
if (Label != c.Label)
{
Label.Serialize(writer, "Label", c.Label);
}
}
///
/// Clone Gauge Object
///
/// clone of this object
public GaugeObject Clone()
{
var clone = Activator.CreateInstance(this.GetType()) as GaugeObject;
clone.Assign(this);
return clone;
}
#endregion // Public Methods
}
}