Click here to Skip to main content
15,898,222 members
Articles / Programming Languages / C#

Mapview

Rate me:
Please Sign up or sign in to vote.
2.28/5 (19 votes)
6 Jun 20042 min read 79.6K   3.1K   50  
Application is intended to create a 2D canvas from interactive, creating the vector graphics
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;


namespace GIS.Geometry
{
	public class EllipseObject : IMapviewObject,ICloneable, IPersist
	{
		#region Private Members of EllipseObject
		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 Color fillcolor=Color.Teal;
		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 normalcolor= Color.Yellow;
		private Color selectcolor= Color.Red;
		private Color disabledcolor= Color.Gray;
		private int linewidth=2;			
		public PointF[] points;
		private string xml="";
		#endregion
		#region Constructors of EllipseObject
		public PointF[] Vertices
		{
			get{return points;}
			set{points=value;}
		}
		public EllipseObject(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 EllipseObject(PointF pt1, PointF pt2)
		{
			x=pt1.X;
			y=pt1.Y;
			width=Math.Abs(pt2.X-pt1.X);
			height=Math.Abs(pt2.Y-pt1.Y);
		}

		public EllipseObject(PointF pt1, PointF pt2, PointF pt3, PointF pt4)
		{
			x=pt1.X;
			y=pt1.Y;
		}

		public EllipseObject(EllipseObject eo){}
		#endregion
		#region Properties of Ellipse Object
		
		[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 Ellipse Object
		public object Clone()
		{ 
			return new EllipseObject( this ); 
		}
		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 RectangleF BoundingBox()
//		{
//			return new RectangleF(x,y,width,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)
		{
			// create 0,0 and width,height points
			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.DrawEllipse(new Pen(disabledcolor,linewidth),(int)points[0].X,(int)points[0].Y,w,h);
				}
				else if(isselected)
				{
					graph.DrawEllipse(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.FillEllipse(new SolidBrush(fillcolor),(int)points[0].X,(int)points[0].Y,w,h);
					graph.DrawEllipse(new Pen(normalcolor,linewidth),(int)points[0].X,(int)points[0].Y,w,h);
				}
				else
				{
					graph.DrawEllipse(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 ToVML
		{
			get{return "<oval position=" + x + " " + y + " size=" + width + " " + height + " id=null href=null  target=null class=null title=null alt=null style='visibility: visible' opacity=1.0 chromakey=null stroke=true	strokecolor=" + normalcolor + " strokeweight=" +  linewidth + " fill=true fillcolor=" + fillcolor + " print=true coordsize=1000,1000 coordorigin=0 0 />";}
			set{xml=value;}
		}

		public string ToGML
		{
			get{return xml;}
			set{xml=value;}
		}

		public string ToSVG
		{
			get{return xml;}
			set{xml=value;}
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions