using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using FastReport.Utils;
namespace FastReport.Map
{
///
/// The base class for shape objects such as , and .
///
public class ShapeBase : Base, ICustomTypeDescriptor
{
#region Fields
private bool visible;
private bool useCustomStyle;
private ShapeStyle customStyle;
private float centerOffsetX;
private float centerOffsetY;
private float shapeOffsetX;
private float shapeOffsetY;
private float shapeScale;
private ShapeSpatialData spatialData;
private double value;
private double saveValue;
private int shapeIndex;
#endregion // Fields
#region Properties
///
/// Gets or sets the shape visibility.
///
[DefaultValue(true)]
[Category("Behavior")]
public bool Visible
{
get { return visible; }
set { visible = value; }
}
///
/// Gets or sets a value indicating that custom shape style is used.
///
///
/// If this property is false, the layer's DefaultShapeStyle is used.
///
[DefaultValue(false)]
[Category("Appearance")]
public bool UseCustomStyle
{
get { return useCustomStyle; }
set
{
useCustomStyle = value;
if (value)
customStyle = new ShapeStyle();
else
customStyle = null;
}
}
///
/// Gets a custom shape style.
///
///
/// To use this property, first set the property to true.
///
[Category("Appearance")]
public ShapeStyle CustomStyle
{
get { return customStyle; }
}
///
/// Gets or sets the center point X offset.
///
///
/// Use this property to adjust the label's position.
///
[Category("Appearance")]
[DefaultValue(0f)]
public float CenterOffsetX
{
get { return centerOffsetX; }
set { centerOffsetX = value; }
}
///
/// Gets or sets the center point Y offset.
///
///
/// Use this property to adjust the label's position.
///
[Category("Appearance")]
[DefaultValue(0f)]
public float CenterOffsetY
{
get { return centerOffsetY; }
set { centerOffsetY = value; }
}
///
/// Gets or sets the shape X offset.
///
///
/// Use this property to adjust the shape position.
///
[Category("Appearance")]
[DefaultValue(0f)]
public float ShapeOffsetX
{
get { return shapeOffsetX; }
set { shapeOffsetX = value; }
}
///
/// Gets or sets the shape Y offset.
///
///
/// Use this property to adjust the shape position.
///
[Category("Appearance")]
[DefaultValue(0f)]
public float ShapeOffsetY
{
get { return shapeOffsetY; }
set { shapeOffsetY = value; }
}
///
/// Gets or sets the scale factor for this shape.
///
///
/// Use this property to adjust the shape size.
///
[Category("Appearance")]
[DefaultValue(1f)]
public float ShapeScale
{
get { return shapeScale; }
set { shapeScale = value; }
}
///
/// Gets or sets the spatial data associated with this shape.
///
[Browsable(false)]
public ShapeSpatialData SpatialData
{
get { return spatialData; }
set { spatialData = value; }
}
///
/// Gets or sets the value.
///
[DefaultValue(double.NaN)]
[Category("Data")]
public double Value
{
get { return value; }
set { this.value = value; }
}
///
/// Gets a reference to the parent Map object.
///
[Browsable(false)]
public MapObject Map
{
get { return Layer.Map; }
}
///
/// Gets a reference to the parent Layer object.
///
[Browsable(false)]
public MapLayer Layer
{
get { return Parent as MapLayer; }
}
internal int ShapeIndex
{
get { return shapeIndex; }
set { shapeIndex = value; }
}
internal bool IsValueEmpty
{
get { return double.IsNaN(Value); }
}
internal string SpatialValue
{
get { return SpatialData.GetValue(Layer.SpatialColumn); }
}
#endregion // Properties
#region Public Methods
///
public override void Assign(Base source)
{
base.Assign(source);
ShapeBase src = source as ShapeBase;
Visible = src.Visible;
SpatialData.Assign(src.SpatialData);
Value = src.Value;
CenterOffsetX = src.CenterOffsetX;
CenterOffsetY = src.CenterOffsetY;
ShapeOffsetX = src.ShapeOffsetX;
ShapeOffsetY = src.ShapeOffsetY;
ShapeScale = src.ShapeScale;
UseCustomStyle = src.UseCustomStyle;
if (UseCustomStyle)
CustomStyle.Assign(src.CustomStyle);
}
///
/// Draws the shape.
///
/// Object that provides a data for paint event.
public virtual void Draw(FRPaintEventArgs e)
{
}
///
/// Draws the label.
///
/// Object that provides a data for paint event.
public virtual void DrawLabel(FRPaintEventArgs e)
{
}
///
/// Checks if the shape is under cursor.
///
/// The cursor coordinates.
/// true if the cursor is over the shape.
public virtual bool HitTest(PointF point)
{
return false;
}
///
/// Reduces the number of points in the shape.
///
/// The accuracy value.
public virtual void Simplify(double accuracy)
{
}
///
public override void Serialize(FRWriter writer)
{
ShapeBase c = writer.DiffObject as ShapeBase;
base.Serialize(writer);
if (Visible != c.Visible)
writer.WriteBool("Visible", Visible);
if (!SpatialData.IsEqual(c.SpatialData))
writer.WriteValue("SpatialData", SpatialData);
if (Value != c.Value)
writer.WriteDouble("Value", Value);
if (CenterOffsetX != c.CenterOffsetX)
writer.WriteFloat("CenterOffsetX", CenterOffsetX);
if (CenterOffsetY != c.CenterOffsetY)
writer.WriteFloat("CenterOffsetY", CenterOffsetY);
if (ShapeOffsetX != c.ShapeOffsetX)
writer.WriteFloat("ShapeOffsetX", ShapeOffsetX);
if (ShapeOffsetY != c.ShapeOffsetY)
writer.WriteFloat("ShapeOffsetY", ShapeOffsetY);
if (ShapeScale != c.ShapeScale)
writer.WriteFloat("ShapeScale", ShapeScale);
if (UseCustomStyle != c.UseCustomStyle)
writer.WriteBool("UseCustomStyle", UseCustomStyle);
if (UseCustomStyle)
CustomStyle.Serialize(writer, "CustomStyle", c.CustomStyle != null ? c.CustomStyle : new ShapeStyle());
}
///
/// Initializes a component before running a report.
///
public virtual void InitializeComponent()
{
}
///
/// Finalizes a component before running a report.
///
public virtual void FinalizeComponent()
{
}
///
/// Saves the state of this component.
///
public virtual void SaveState()
{
saveValue = Value;
}
///
/// Restores the state of this component.
///
public virtual void RestoreState()
{
Value = saveValue;
}
#endregion // Public Methods
#region ICustomTypeDescriptor Members
///
public PropertyDescriptorCollection GetProperties()
{
return GetProperties(null);
}
///
public PropertyDescriptorCollection GetProperties(Attribute[] attr)
{
PropertyDescriptorCollection typeProps = TypeDescriptor.GetProperties(this.GetType(), attr);
PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
foreach (PropertyDescriptor desc in typeProps)
{
properties.Add(desc);
}
foreach (string key in SpatialData.GetKeys())
{
properties.Add(new MetadataPropertyDescriptor(SpatialData, key, attr));
}
return properties;
}
///
public String GetClassName()
{
return TypeDescriptor.GetClassName(this, true);
}
///
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(this, true);
}
///
public String GetComponentName()
{
return TypeDescriptor.GetComponentName(this, true);
}
///
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
///
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(this, true);
}
///
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(this, true);
}
///
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(this, editorBaseType, true);
}
///
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(this, attributes, true);
}
///
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(this, true);
}
///
public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
#endregion
///
/// Initializes a new instance of the class.
///
public ShapeBase()
{
visible = true;
spatialData = new ShapeSpatialData();
value = double.NaN;
shapeScale = 1;
}
}
}