using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace GIS.Geometry
{
public class RectangleObject : IMapviewObject,ICloneable, IPersist
{
#region Private members of Rectangle Object
public event GraphicEvents GraphicSelected;
private float x;
private float y;
private float width;
private float height;
private bool isselected = false;
private bool isfilled=true;
private bool visible=true;
private bool showtooptip=false;
private bool iscurrent=true;
private bool islocked=false;
private bool isdisabled=false;
private bool showhandle=false;
private int handlesize=6;
private Color fillcolor=Color.YellowGreen;
private Color normalcolor= Color.Yellow;
private Color selectcolor= Color.Red;
private Color disabledcolor= Color.Gray;
private int linewidth=2;
private string xml="";
private PointF[] points=new PointF[4];
#endregion
#region Constructors of Rectangle Object
public RectangleObject(float px,float py,float nx,float ny)
{
x = px;
y = py;
width = nx;
height = ny;
PointF[] points={new PointF(x,y),new PointF(x+nx,y),new PointF(x+nx,y+ny),new PointF(x,y+ny)};
}
public RectangleObject(PointF pt1, PointF pt2)
{
x=pt1.X;
y=pt1.Y;
width=Math.Abs(pt2.X-pt1.X);
height=Math.Abs(pt2.Y-pt1.Y);
PointF[] points={new PointF(pt1.X,pt1.Y),new PointF(width,y),new PointF (pt2.X,pt2.Y),new PointF(x,height)};
}
public RectangleObject(PointF pt1, PointF pt2, PointF pt3, PointF pt4)
{
x=pt1.X;
y=pt1.Y;
PointF[] points={new PointF(pt1.X,pt1.Y),new PointF(pt2.X, pt2.Y),new PointF(pt3.X,pt3.Y),new PointF(pt4.X, pt4.Y)};
}
public RectangleObject(RectangleObject ro){
PointF[] points=ro.Vertices;
}
#endregion
#region Properties of Rectangle Object
public PointF[] Vertices
{
get{return points;}
set{points=value;}
}
[Category("Colors" ),Description("The disabled graphic object will be drawn using this pen")]
public Color DisabledColor
{
get{return disabledcolor;}
set{disabledcolor=value;}
}
[Category("Colors" ),Description("The selected graphic object willbe drawn using this pen")]
public Color SelectColor
{
get{return selectcolor;}
set{selectcolor=value;}
}
[Category("Colors" ),Description("The graphic object willbe drawn using this pen")]
public Color NormalColor
{
get{return normalcolor;}
set{normalcolor=value;}
}
[DefaultValue(2),Category("Style"),Description("The gives the line thickness of the graphic object")]
public int LineWidth
{
get{return linewidth;}
set{linewidth=value;}
}
[Category("Appearance"),Description("The graphic object will be filled with a given color or pattern")]
public bool IsFilled{get{return isfilled;}set{isfilled=value;}
}
[Category("Appearance"), Description("Determines whether the object is visible or hidden")]
public bool Visible
{
get{return visible;}
set{visible=value;}
}
[Category("Appearance"), Description("Determines whether the tooltip information to be shown or not")]
public bool ShowToopTip
{
get{return showtooptip;}
set{showtooptip=value;}
}
[Category("Appearance"), Description("Determines whether the object is in current selected legend or not")]
public bool IsCurrent
{
get{return iscurrent;}
set{iscurrent=value;}
}
[Category("Appearance"), Description("Determines whether the object is locked from the current user or not")]
public bool IsLocked
{
get{return islocked;}
set{islocked=value;}
}
[Category("Appearance"), Description("Determines whether the object is disabled from editing")]
public bool IsDisabled
{
get{return isdisabled;}
set{isdisabled=value;}
}
[Category("Appearance"), Description("Determines whether the object is in edit mode")]
public bool IsEdit
{
get{return showhandle;}
set{isselected=true;
showhandle=value;}
}
#endregion
#region Methods of ICloneable
public object Clone()
{
return new RectangleObject( this );
}
#endregion
#region Method of Rectangle Object
public bool IsSelected()
{
return isselected;
}
public void Select(bool m)
{
isselected = m;
}
public bool IsObjectAt(PointF pnt,float dist)
{
RectangleF rect1 = new RectangleF(x-dist,y-dist,width+dist*2,
dist*2);
if(rect1.Contains(pnt))
return true;
RectangleF rect2 = new RectangleF(x-dist,y-dist+height,
width+dist*2,dist*2);
if(rect2.Contains(pnt))
return true;
RectangleF rect3 = new RectangleF(x-dist,y-dist,
dist*2,dist*2+height);
if(rect3.Contains(pnt))
return true;
RectangleF rect4 = new RectangleF(x-dist+width,y-dist,
dist*2,dist*2+height);
if(rect4.Contains(pnt))
return true;
return false;
}
public Rectangle BoundingBox()
{
return new Rectangle((int)x,(int)y,(int)width,(int)height);
}
public float X()
{
return x;
}
public float Y()
{
return y;
}
public void Move(PointF p)
{
x = p.X;
y = p.Y;
}
public void MoveBy(float xs,float ys)
{
x+=xs;
y+=ys;
}
public void Scale(int scale)
{
x*=scale;
y*=scale;
}
public void Rotate(float radians)
{
//
}
public void RotateAt(PointF pt)
{
//
}
public void RoateAt(Point pt)
{
//
}
public void Draw(Graphics graph,System.Drawing.Drawing2D.Matrix trans)
{
if (visible)
{
PointF [] points = {new PointF(x,y), new PointF(x+width,y+height)};
trans.TransformPoints(points);
int w = (int)(points[1].X - points[0].X);
int h = (int)(points[1].Y - points[0].Y);
if (isdisabled || islocked)
{
graph.DrawRectangle(new Pen(disabledcolor,linewidth),(int)points[0].X,(int)points[0].Y,w,h);
}
else if(isselected)
{
graph.DrawRectangle(new Pen(selectcolor,linewidth),(int)points[0].X,(int)points[0].Y,w,h);
if (showhandle)
{
for (int i=0; i<2; i++)
{
graph.FillRectangle(new SolidBrush(fillcolor),points[i].X-handlesize/2,points[i].Y-handlesize/2,handlesize,handlesize);
graph.DrawRectangle(new Pen(Color.Black,1),points[i].X-handlesize/2,points[i].Y-handlesize/2,handlesize,handlesize);
}
}
}
else if(isfilled)
{
graph.FillRectangle(new SolidBrush(fillcolor),(int)points[0].X,(int)points[0].Y,w,h);
graph.DrawRectangle(new Pen(normalcolor,linewidth),(int)points[0].X,(int)points[0].Y,w,h);
}
else
{
graph.DrawRectangle(new Pen(normalcolor,linewidth),(int)points[0].X,(int)points[0].Y,w,h);
}
}
}
#endregion
#region Methods of IPersist
public string ToXML
{
get{return xml;}
set{xml=value;}
}
public string ToGML
{
get{return xml;}
set{xml=value;}
}
public string ToVML
{
get{return xml;}
set{xml=value;}
}
public string ToSVG
{
get{return "<rect x=" + x + " y=" + y +" width=" + width +" height=" + height + " fill=" + fillcolor + " stroke=" + normalcolor +" stroke-width=" + linewidth +"/>";}
set{xml=value;}
}
}
#endregion
}