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

Drawing Component to build GIS and CAM applications

Rate me:
Please Sign up or sign in to vote.
4.72/5 (14 votes)
21 Nov 20055 min read 108K   8K   123  
An object oriented drawing component for building GIS and CAM applications with multiple views of geometrical model, multiple resolution handling, layers, optimized graphics and more.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Timers;
using System.IO;
using System.Diagnostics;
using CanvasControl;
using GDalGIS;

namespace CanvasDemo
{
	
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button openImage;
		
		private System.Windows.Forms.Button btnZoomIn;
		private System.Windows.Forms.Button btnZoomOut;
		private CanvasControl.Canvas canvas1;
		private System.Windows.Forms.HScrollBar hScrollBar1;
		private System.Windows.Forms.VScrollBar vScrollBar1;
		
		private SortedList m_frames;
		private System.Windows.Forms.Button btnNewRect;
		private System.Windows.Forms.Button btnNewPoly;
		private System.Windows.Forms.Button delete;
		private System.Windows.Forms.Button btnCreateLine;
		private System.Windows.Forms.TextBox entryFname;
		private CanvasControl.Canvas canvas2;
		private System.Windows.Forms.Button buttonGIS;
		private System.Windows.Forms.DataGrid dataGridGIS;
		private System.Windows.Forms.Button btnColor;
		private System.Windows.Forms.Button buttonFitWidget;
		private System.Windows.Forms.ListView listViewGIS;
		private System.Windows.Forms.StatusBar statusBar1;
		private GDalGIS.DataSource m_gdal_ds;
		private System.Windows.Forms.TextBox textBoxZoom;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBoxLayScale;
		private System.Windows.Forms.CheckBox checkBoxLayVis;
		private System.Windows.Forms.CheckBox checkBoxGrid;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.RadioButton radioButtonMove;
		private System.Windows.Forms.RadioButton radioButtonSelect;
		private System.Windows.Forms.RadioButton radioButtonFind;
		private System.Windows.Forms.RadioButton radioButtonCenter;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.TextBox textBoxGISLat;
		private System.Windows.Forms.TextBox textBoxGISLon;
		private System.Windows.Forms.Button buttonTrans;
		private System.Windows.Forms.TextBox textBoxUTM;
		string m_curr_item;
		private GDalGIS.SpatialReference m_spatial_src_ref;
		private GDalGIS.SpatialReference m_spatial_dst_ref;
		private System.Windows.Forms.Button buttonNaviZoomIn;
		private System.Windows.Forms.Button buttonNaviZoomOut;
		private System.Windows.Forms.CheckBox checkBoxCoordSys;
		private GDalGIS.CoordinateTransform m_coord_transform;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			
			canvas1.connectScrolls(hScrollBar1,vScrollBar1);
			
			m_frames = new SortedList();
			
			canvas1.CoordChangeEvent += new CanvasControl.Canvas.CoordChangeEventHandler(OnCoordChainged);
			canvas1.ItemNewEvent += new CanvasControl.Canvas.ItemEventHandler(OnNewCanvasItem);			
			canvas1.ItemEnterEvent += new CanvasControl.Canvas.ItemEventHandler(OnEnterCanvasItem);			
			canvas1.ItemFindEvent += new CanvasControl.Canvas.ItemEventHandler(OnFindCanvasItem);

			canvas2.setGeomModel(canvas1.getGeomModel());

			m_gdal_ds = new GDalGIS.DataSource();						
			m_gdal_ds.setCanvasModel(canvas1.getGeomModel());

			dataGridGIS.CurrentCellChanged += new
				System.EventHandler(this.dataGridGIS_CurrentCellChanged);
			
			listViewGIS.View = View.Details;
			listViewGIS.Columns.Add("File name", 20, HorizontalAlignment.Left);

			StatusBarPanel panel1 = new StatusBarPanel();
			panel1.Text = "coord";
			StatusBarPanel panel2 = new StatusBarPanel();
			panel1.Text = "item";

			StatusBarPanel panel3 = new StatusBarPanel();
			panel1.Text = "utm";

			statusBar1.Panels.Add(panel1);
			statusBar1.Panels.Add(panel2);
			statusBar1.Panels.Add(panel3);
			statusBar1.ShowPanels = true;

			GDalGIS.SpatialReference myref = new SpatialReference();

			m_spatial_src_ref = new SpatialReference();
			m_spatial_src_ref.SetWellKnownGeogCS("WGS84");
			
			m_spatial_dst_ref = new SpatialReference();
			m_spatial_dst_ref.SetProjCS("UTM Proj");
			m_spatial_dst_ref.SetWellKnownGeogCS("WGS84");
			m_spatial_dst_ref.SetUTM(17,1);

			m_coord_transform = new CoordinateTransform(m_spatial_src_ref,m_spatial_dst_ref);
			canvas1.getGeomModel().createLayer("citiesx020",Color.Blue,32,true);
		}

		private void dataGridGIS_CurrentCellChanged(object sender, 
			System.EventArgs e)
		{
			/*MessageBox.Show ("Col is " + dataGridGIS.CurrentCell.ColumnNumber
				+ ", Row is " + dataGridGIS.CurrentCell.RowNumber 
				+ ", Value is " + dataGridGIS[dataGridGIS.CurrentCell] );
				*/

			int id = m_gdal_ds.getShapeID(m_curr_item,dataGridGIS.CurrentCell.RowNumber);
			GeomModel.CanvasItem item = canvas1.GetItem(id);
			RectangleF rect = item.boundingBox();
			canvas1.recenter(new PointF(rect.X+rect.Width/2,
				rect.Y+rect.Height/2));
		}

		
		public void OnNewCanvasItem(object sender, GeomModel.ItemEventArgs e)
		{
			statusBar1.Panels[1].Text = e.indx.ToString();
		}

		public void OnEnterCanvasItem(object sender, GeomModel.ItemEventArgs e)
		{			
			statusBar1.Panels[1].Text = e.indx.ToString();
		}

		public void OnFindCanvasItem(object sender, GeomModel.ItemEventArgs e)
		{			
			statusBar1.Panels[1].Text = e.indx.ToString()+"!!!";
			GeomModel.CanvasItem item = canvas1.GetItem(e.indx);
			if(item == null)
				return;

			GeomModel.CanvasLayer lay = item.layer;
			if(lay == null)
				return;

			selectCurrentLayer(lay.name);
			int r = m_gdal_ds.getRowOfShape(lay.name,e.indx);			
			if(r == -1)
			{
				return;
			}

			dataGridGIS.CurrentCell = new DataGridCell(r,0);

		}

		public void OnCoordChainged(object sender, GeomModel.CoordEventArgs e)
		{
			statusBar1.Panels[0].Text = e.X.ToString() + "," + e.Y.ToString();
			
			double [] x_arr = new double [1];
			double [] y_arr = new double [1];
			double [] z_arr = new double [1];

			x_arr[0] = e.X;
			y_arr[0] = e.Y;
			z_arr[0] = 0;
			
			m_coord_transform.transform(x_arr,y_arr,z_arr);			
			
			statusBar1.Panels[2].Text = "utm=17; E=" 
				+ x_arr[0].ToString() + "; N=" 
				+ y_arr[0].ToString();
			
			statusBar1.Panels[2].Width = 300;

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.openImage = new System.Windows.Forms.Button();
			this.btnZoomIn = new System.Windows.Forms.Button();
			this.btnZoomOut = new System.Windows.Forms.Button();
			this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
			this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
			this.entryFname = new System.Windows.Forms.TextBox();
			this.btnNewRect = new System.Windows.Forms.Button();
			this.btnNewPoly = new System.Windows.Forms.Button();
			this.delete = new System.Windows.Forms.Button();
			this.btnCreateLine = new System.Windows.Forms.Button();
			this.canvas1 = new CanvasControl.Canvas();
			this.btnColor = new System.Windows.Forms.Button();
			this.canvas2 = new CanvasControl.Canvas();
			this.buttonGIS = new System.Windows.Forms.Button();
			this.textBoxGISLat = new System.Windows.Forms.TextBox();
			this.dataGridGIS = new System.Windows.Forms.DataGrid();
			this.buttonFitWidget = new System.Windows.Forms.Button();
			this.listViewGIS = new System.Windows.Forms.ListView();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.textBoxZoom = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.checkBoxLayVis = new System.Windows.Forms.CheckBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textBoxLayScale = new System.Windows.Forms.TextBox();
			this.checkBoxGrid = new System.Windows.Forms.CheckBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.radioButtonFind = new System.Windows.Forms.RadioButton();
			this.radioButtonCenter = new System.Windows.Forms.RadioButton();
			this.radioButtonSelect = new System.Windows.Forms.RadioButton();
			this.radioButtonMove = new System.Windows.Forms.RadioButton();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.textBoxGISLon = new System.Windows.Forms.TextBox();
			this.buttonTrans = new System.Windows.Forms.Button();
			this.textBoxUTM = new System.Windows.Forms.TextBox();
			this.buttonNaviZoomIn = new System.Windows.Forms.Button();
			this.buttonNaviZoomOut = new System.Windows.Forms.Button();
			this.checkBoxCoordSys = new System.Windows.Forms.CheckBox();
			((System.ComponentModel.ISupportInitialize)(this.dataGridGIS)).BeginInit();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox4.SuspendLayout();
			this.SuspendLayout();
			// 
			// openImage
			// 
			this.openImage.Location = new System.Drawing.Point(8, 8);
			this.openImage.Name = "openImage";
			this.openImage.Size = new System.Drawing.Size(80, 23);
			this.openImage.TabIndex = 6;
			this.openImage.Text = "open image";
			this.openImage.Click += new System.EventHandler(this.openImage_Click);
			// 
			// btnZoomIn
			// 
			this.btnZoomIn.Location = new System.Drawing.Point(8, 16);
			this.btnZoomIn.Name = "btnZoomIn";
			this.btnZoomIn.Size = new System.Drawing.Size(24, 24);
			this.btnZoomIn.TabIndex = 8;
			this.btnZoomIn.Text = "+";
			this.btnZoomIn.Click += new System.EventHandler(this.btnZoomIn_Click);
			// 
			// btnZoomOut
			// 
			this.btnZoomOut.Location = new System.Drawing.Point(80, 16);
			this.btnZoomOut.Name = "btnZoomOut";
			this.btnZoomOut.Size = new System.Drawing.Size(24, 24);
			this.btnZoomOut.TabIndex = 9;
			this.btnZoomOut.Text = "-";
			this.btnZoomOut.Click += new System.EventHandler(this.btnZoomOut_Click);
			// 
			// hScrollBar1
			// 
			this.hScrollBar1.Location = new System.Drawing.Point(8, 416);
			this.hScrollBar1.Name = "hScrollBar1";
			this.hScrollBar1.Size = new System.Drawing.Size(448, 17);
			this.hScrollBar1.TabIndex = 11;
			this.hScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.hScrollBar1_Scroll);
			// 
			// vScrollBar1
			// 
			this.vScrollBar1.Location = new System.Drawing.Point(456, 80);
			this.vScrollBar1.Name = "vScrollBar1";
			this.vScrollBar1.Size = new System.Drawing.Size(16, 336);
			this.vScrollBar1.TabIndex = 12;
			this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll);
			// 
			// entryFname
			// 
			this.entryFname.Location = new System.Drawing.Point(104, 8);
			this.entryFname.Name = "entryFname";
			this.entryFname.Size = new System.Drawing.Size(96, 20);
			this.entryFname.TabIndex = 15;
			this.entryFname.Text = "100";
			// 
			// btnNewRect
			// 
			this.btnNewRect.Location = new System.Drawing.Point(8, 16);
			this.btnNewRect.Name = "btnNewRect";
			this.btnNewRect.Size = new System.Drawing.Size(40, 23);
			this.btnNewRect.TabIndex = 16;
			this.btnNewRect.Text = "rect";
			this.btnNewRect.Click += new System.EventHandler(this.btnNewRect_Click);
			// 
			// btnNewPoly
			// 
			this.btnNewPoly.Location = new System.Drawing.Point(48, 16);
			this.btnNewPoly.Name = "btnNewPoly";
			this.btnNewPoly.Size = new System.Drawing.Size(48, 23);
			this.btnNewPoly.TabIndex = 17;
			this.btnNewPoly.Text = "poly";
			this.btnNewPoly.Click += new System.EventHandler(this.btnNewPoly_Click);
			// 
			// delete
			// 
			this.delete.Location = new System.Drawing.Point(400, 48);
			this.delete.Name = "delete";
			this.delete.Size = new System.Drawing.Size(48, 24);
			this.delete.TabIndex = 19;
			this.delete.Text = "delete";
			this.delete.Click += new System.EventHandler(this.delete_Click);
			// 
			// btnCreateLine
			// 
			this.btnCreateLine.Location = new System.Drawing.Point(96, 16);
			this.btnCreateLine.Name = "btnCreateLine";
			this.btnCreateLine.Size = new System.Drawing.Size(48, 23);
			this.btnCreateLine.TabIndex = 20;
			this.btnCreateLine.Text = "line";
			this.btnCreateLine.Click += new System.EventHandler(this.btnCreateLine_Click);
			// 
			// canvas1
			// 
			this.canvas1.BgColor = System.Drawing.Color.Gray;
			this.canvas1.CoordSys = CanvasControl.Canvas.CoordSystem.DownRight;
			this.canvas1.Location = new System.Drawing.Point(8, 80);
			this.canvas1.Name = "canvas1";
			this.canvas1.Size = new System.Drawing.Size(448, 336);
			this.canvas1.TabIndex = 23;
			// 
			// btnColor
			// 
			this.btnColor.Location = new System.Drawing.Point(80, 16);
			this.btnColor.Name = "btnColor";
			this.btnColor.Size = new System.Drawing.Size(32, 24);
			this.btnColor.TabIndex = 28;
			this.btnColor.Click += new System.EventHandler(this.btnColor_Click);
			// 
			// canvas2
			// 
			this.canvas2.BgColor = System.Drawing.Color.Gray;
			this.canvas2.CoordSys = CanvasControl.Canvas.CoordSystem.DownRight;
			this.canvas2.Location = new System.Drawing.Point(480, 296);
			this.canvas2.Name = "canvas2";
			this.canvas2.Size = new System.Drawing.Size(128, 120);
			this.canvas2.TabIndex = 29;
			// 
			// buttonGIS
			// 
			this.buttonGIS.Location = new System.Drawing.Point(240, 8);
			this.buttonGIS.Name = "buttonGIS";
			this.buttonGIS.TabIndex = 30;
			this.buttonGIS.Text = "open GIS";
			this.buttonGIS.Click += new System.EventHandler(this.buttonGIS_Click);
			// 
			// textBoxGISLat
			// 
			this.textBoxGISLat.Location = new System.Drawing.Point(392, 8);
			this.textBoxGISLat.Name = "textBoxGISLat";
			this.textBoxGISLat.Size = new System.Drawing.Size(48, 20);
			this.textBoxGISLat.TabIndex = 31;
			this.textBoxGISLat.Text = "";
			// 
			// dataGridGIS
			// 
			this.dataGridGIS.DataMember = "";
			this.dataGridGIS.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGridGIS.Location = new System.Drawing.Point(160, 432);
			this.dataGridGIS.Name = "dataGridGIS";
			this.dataGridGIS.Size = new System.Drawing.Size(456, 152);
			this.dataGridGIS.TabIndex = 32;
			this.dataGridGIS.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGridGIS_Navigate);
			// 
			// buttonFitWidget
			// 
			this.buttonFitWidget.Location = new System.Drawing.Point(480, 264);
			this.buttonFitWidget.Name = "buttonFitWidget";
			this.buttonFitWidget.Size = new System.Drawing.Size(64, 23);
			this.buttonFitWidget.TabIndex = 33;
			this.buttonFitWidget.Text = "fit2widget";
			this.buttonFitWidget.Click += new System.EventHandler(this.buttonFitWidget_Click);
			// 
			// listViewGIS
			// 
			this.listViewGIS.Location = new System.Drawing.Point(8, 432);
			this.listViewGIS.Name = "listViewGIS";
			this.listViewGIS.Size = new System.Drawing.Size(144, 152);
			this.listViewGIS.TabIndex = 35;
			this.listViewGIS.SelectedIndexChanged += new System.EventHandler(this.listViewGIS_SelectedIndexChanged);
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 592);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Size = new System.Drawing.Size(624, 22);
			this.statusBar1.TabIndex = 36;
			this.statusBar1.Text = "info:";
			// 
			// textBoxZoom
			// 
			this.textBoxZoom.Location = new System.Drawing.Point(40, 16);
			this.textBoxZoom.Name = "textBoxZoom";
			this.textBoxZoom.Size = new System.Drawing.Size(32, 20);
			this.textBoxZoom.TabIndex = 37;
			this.textBoxZoom.Text = "1";
			this.textBoxZoom.TextChanged += new System.EventHandler(this.textBoxZoom_TextChanged);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.checkBoxLayVis);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textBoxLayScale);
			this.groupBox1.Controls.Add(this.btnColor);
			this.groupBox1.Location = new System.Drawing.Point(480, 128);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(128, 120);
			this.groupBox1.TabIndex = 38;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "layer";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 23);
			this.label3.TabIndex = 33;
			this.label3.Text = "visiable";
			// 
			// checkBoxLayVis
			// 
			this.checkBoxLayVis.Location = new System.Drawing.Point(80, 80);
			this.checkBoxLayVis.Name = "checkBoxLayVis";
			this.checkBoxLayVis.Size = new System.Drawing.Size(8, 8);
			this.checkBoxLayVis.TabIndex = 32;
			this.checkBoxLayVis.Text = "checkBox1";
			this.checkBoxLayVis.CheckedChanged += new System.EventHandler(this.checkBoxLayVis_CheckedChanged);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 23);
			this.label2.TabIndex = 31;
			this.label2.Text = "scale";
			this.label2.Click += new System.EventHandler(this.label2_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(32, 16);
			this.label1.TabIndex = 30;
			this.label1.Text = "color";
			// 
			// textBoxLayScale
			// 
			this.textBoxLayScale.Location = new System.Drawing.Point(80, 48);
			this.textBoxLayScale.Name = "textBoxLayScale";
			this.textBoxLayScale.Size = new System.Drawing.Size(32, 20);
			this.textBoxLayScale.TabIndex = 29;
			this.textBoxLayScale.Text = "1";
			this.textBoxLayScale.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// checkBoxGrid
			// 
			this.checkBoxGrid.Location = new System.Drawing.Point(480, 96);
			this.checkBoxGrid.Name = "checkBoxGrid";
			this.checkBoxGrid.TabIndex = 39;
			this.checkBoxGrid.Text = "show grid";
			this.checkBoxGrid.CheckedChanged += new System.EventHandler(this.checkBoxGrid_CheckedChanged);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.radioButtonFind);
			this.groupBox2.Controls.Add(this.radioButtonCenter);
			this.groupBox2.Controls.Add(this.radioButtonSelect);
			this.groupBox2.Controls.Add(this.radioButtonMove);
			this.groupBox2.Location = new System.Drawing.Point(8, 32);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(192, 48);
			this.groupBox2.TabIndex = 40;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "selection";
			// 
			// radioButtonFind
			// 
			this.radioButtonFind.Appearance = System.Windows.Forms.Appearance.Button;
			this.radioButtonFind.Location = new System.Drawing.Point(144, 16);
			this.radioButtonFind.Name = "radioButtonFind";
			this.radioButtonFind.Size = new System.Drawing.Size(40, 24);
			this.radioButtonFind.TabIndex = 3;
			this.radioButtonFind.Text = "find";
			this.radioButtonFind.CheckedChanged += new System.EventHandler(this.radioButtonFind_CheckedChanged);
			// 
			// radioButtonCenter
			// 
			this.radioButtonCenter.Appearance = System.Windows.Forms.Appearance.Button;
			this.radioButtonCenter.Location = new System.Drawing.Point(96, 16);
			this.radioButtonCenter.Name = "radioButtonCenter";
			this.radioButtonCenter.Size = new System.Drawing.Size(48, 24);
			this.radioButtonCenter.TabIndex = 2;
			this.radioButtonCenter.Text = "center";
			this.radioButtonCenter.CheckedChanged += new System.EventHandler(this.radioButtonCenter_CheckedChanged);
			// 
			// radioButtonSelect
			// 
			this.radioButtonSelect.Appearance = System.Windows.Forms.Appearance.Button;
			this.radioButtonSelect.Location = new System.Drawing.Point(48, 16);
			this.radioButtonSelect.Name = "radioButtonSelect";
			this.radioButtonSelect.Size = new System.Drawing.Size(48, 24);
			this.radioButtonSelect.TabIndex = 1;
			this.radioButtonSelect.Text = "select";
			this.radioButtonSelect.CheckedChanged += new System.EventHandler(this.radioButtonSelect_CheckedChanged);
			// 
			// radioButtonMove
			// 
			this.radioButtonMove.Appearance = System.Windows.Forms.Appearance.Button;
			this.radioButtonMove.Location = new System.Drawing.Point(8, 16);
			this.radioButtonMove.Name = "radioButtonMove";
			this.radioButtonMove.Size = new System.Drawing.Size(40, 24);
			this.radioButtonMove.TabIndex = 0;
			this.radioButtonMove.Text = "move";
			this.radioButtonMove.CheckedChanged += new System.EventHandler(this.radioButtonMove_CheckedChanged);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.btnZoomIn);
			this.groupBox3.Controls.Add(this.btnZoomOut);
			this.groupBox3.Controls.Add(this.textBoxZoom);
			this.groupBox3.Location = new System.Drawing.Point(208, 32);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(112, 48);
			this.groupBox3.TabIndex = 41;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "zoom";
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.Add(this.btnNewRect);
			this.groupBox4.Controls.Add(this.btnNewPoly);
			this.groupBox4.Controls.Add(this.btnCreateLine);
			this.groupBox4.Location = new System.Drawing.Point(472, 32);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(152, 48);
			this.groupBox4.TabIndex = 42;
			this.groupBox4.TabStop = false;
			this.groupBox4.Text = "create";
			// 
			// textBoxGISLon
			// 
			this.textBoxGISLon.Location = new System.Drawing.Point(328, 8);
			this.textBoxGISLon.Name = "textBoxGISLon";
			this.textBoxGISLon.Size = new System.Drawing.Size(56, 20);
			this.textBoxGISLon.TabIndex = 43;
			this.textBoxGISLon.Text = "";
			// 
			// buttonTrans
			// 
			this.buttonTrans.Location = new System.Drawing.Point(448, 8);
			this.buttonTrans.Name = "buttonTrans";
			this.buttonTrans.Size = new System.Drawing.Size(56, 24);
			this.buttonTrans.TabIndex = 44;
			this.buttonTrans.Text = "to UTM";
			this.buttonTrans.Click += new System.EventHandler(this.buttonTrans_Click);
			// 
			// textBoxUTM
			// 
			this.textBoxUTM.Location = new System.Drawing.Point(520, 8);
			this.textBoxUTM.Name = "textBoxUTM";
			this.textBoxUTM.Size = new System.Drawing.Size(96, 20);
			this.textBoxUTM.TabIndex = 32;
			this.textBoxUTM.Text = "";
			// 
			// buttonNaviZoomIn
			// 
			this.buttonNaviZoomIn.Location = new System.Drawing.Point(552, 264);
			this.buttonNaviZoomIn.Name = "buttonNaviZoomIn";
			this.buttonNaviZoomIn.Size = new System.Drawing.Size(24, 24);
			this.buttonNaviZoomIn.TabIndex = 45;
			this.buttonNaviZoomIn.Text = "+";
			this.buttonNaviZoomIn.Click += new System.EventHandler(this.buttonNaviZoomIn_Click);
			// 
			// buttonNaviZoomOut
			// 
			this.buttonNaviZoomOut.Location = new System.Drawing.Point(584, 264);
			this.buttonNaviZoomOut.Name = "buttonNaviZoomOut";
			this.buttonNaviZoomOut.Size = new System.Drawing.Size(24, 24);
			this.buttonNaviZoomOut.TabIndex = 46;
			this.buttonNaviZoomOut.Text = "-";
			this.buttonNaviZoomOut.Click += new System.EventHandler(this.buttonNaviZoomOut_Click);
			// 
			// checkBoxCoordSys
			// 
			this.checkBoxCoordSys.Location = new System.Drawing.Point(344, 48);
			this.checkBoxCoordSys.Name = "checkBoxCoordSys";
			this.checkBoxCoordSys.Size = new System.Drawing.Size(40, 24);
			this.checkBoxCoordSys.TabIndex = 47;
			this.checkBoxCoordSys.Text = "Up";
			this.checkBoxCoordSys.CheckedChanged += new System.EventHandler(this.checkBoxCoordSys_CheckedChanged);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(624, 614);
			this.Controls.Add(this.checkBoxCoordSys);
			this.Controls.Add(this.buttonNaviZoomOut);
			this.Controls.Add(this.buttonNaviZoomIn);
			this.Controls.Add(this.buttonTrans);
			this.Controls.Add(this.textBoxGISLon);
			this.Controls.Add(this.textBoxGISLat);
			this.Controls.Add(this.entryFname);
			this.Controls.Add(this.textBoxUTM);
			this.Controls.Add(this.groupBox4);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.checkBoxGrid);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.statusBar1);
			this.Controls.Add(this.listViewGIS);
			this.Controls.Add(this.buttonFitWidget);
			this.Controls.Add(this.dataGridGIS);
			this.Controls.Add(this.buttonGIS);
			this.Controls.Add(this.canvas2);
			this.Controls.Add(this.canvas1);
			this.Controls.Add(this.delete);
			this.Controls.Add(this.vScrollBar1);
			this.Controls.Add(this.hScrollBar1);
			this.Controls.Add(this.openImage);
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.dataGridGIS)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
	
		private void openImage_Click(object sender, System.EventArgs e)
		{
			
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.InitialDirectory = "c:/";
			openFileDialog.ShowDialog();
			string fname = openFileDialog.FileName;
			entryFname.Text = fname;
			canvas1.LoadImage(fname);
			canvas2.fitToWidget();
		}

		private void btnZoomIn_Click(object sender, System.EventArgs e)
		{
			canvas1.ZoomIn();
			textBoxZoom.Text = canvas1.scale().ToString();
		}

		
		private void hScrollBar1_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
		{
			canvas1.ScrollHorizontal(e.NewValue);
		}

		private void btnZoomOut_Click(object sender, System.EventArgs e)
		{
			canvas1.ZoomOut();
			textBoxZoom.Text = canvas1.scale().ToString();
		}

		private void vScrollBar1_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
		{
			canvas1.ScrollVertical(e.NewValue);
		}

		private void btnNewRect_Click(object sender, System.EventArgs e)
		{
			canvas1.CreateRectangle();
		}

		private void btnSelect_Click(object sender, System.EventArgs e)
		{
			
		}

		private void delete_Click(object sender, System.EventArgs e)
		{
			canvas1.DeleteSelected();
		}

		private void btnCreateLine_Click(object sender, System.EventArgs e)
		{
			canvas1.CreateLine();
		}

		private void btnNewPoly_Click(object sender, System.EventArgs e)
		{
			canvas1.CreatePolygon();
		}

		private void btnMove_Click(object sender, System.EventArgs e)
		{
			canvas1.StartMoving();
		}

		private void btnColor_Click(object sender, System.EventArgs e)
		{
			ColorDialog colorDialog = new ColorDialog();	
			if(colorDialog.ShowDialog() != DialogResult.OK)
			{
				return;				
			}

			Color color = colorDialog.Color;
			btnColor.BackColor = color;
			GeomModel.CanvasLayer lay = canvas1.layerByName(m_curr_item);
			if( lay == null)
				return;
		
			lay.color = color; 
			/*
			int [] selected = canvas1.GetSelected();
			foreach(int i in selected)
			{
				GeomModel.CanvasItem item = canvas1.GetItem(i);
				item.Icolor = color;
				item.select(false);
			}
*/
			canvas1.Invalidate();
			canvas1.Update();

		}

		private void buttonGIS_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			
			openFileDialog.ShowDialog();
			string fname = openFileDialog.FileName;
			m_gdal_ds.open(fname);
			FileInfo f = new FileInfo(fname);
			
			ArrayList names_list = m_gdal_ds.getLayers();
			dataGridGIS.SetDataBinding(m_gdal_ds.getDS(),(string)names_list[0]);
			listViewGIS.Items.Add(new ListViewItem((string)names_list[0]));
			
			canvas1.fitToWidget();
			canvas2.fitToWidget();
		}

		private void buttonFitWidget_Click(object sender, System.EventArgs e)
		{
			canvas1.fitToWidget();
			canvas2.fitToWidget();
		}

		private void buttonCenter_Click(object sender, System.EventArgs e)
		{
			/*int id = System.Convert.ToInt32(textBox3.Text);
			GeomModel.CanvasItem item = canvas1.GetItem(id);
			RectangleF rect = item.boundingBox();
			canvas1.recenter(new PointF(rect.X+rect.Width/2,
								rect.Y+rect.Height/2));
								*/
		}

		private void listViewGIS_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (listViewGIS.SelectedItems.Count == 0)
				return;

			selectCurrentLayer(listViewGIS.SelectedItems[0].Text);			
		}

		private bool selectCurrentLayer(string lay_name)
		{
			m_curr_item = lay_name;

			dataGridGIS.SetDataBinding(m_gdal_ds.getDS(),m_curr_item);

			GeomModel.CanvasLayer lay = canvas1.layerByName(m_curr_item);
			if( lay == null)
				return false;

			checkBoxLayVis.Checked = lay.visiable;
			textBoxLayScale.Text = lay.visiableOnScale.ToString();
			btnColor.BackColor = lay.color;
			return true;
		}

		private void textBoxZoom_TextChanged(object sender, System.EventArgs e)
		{
			textBoxZoom.Text = canvas1.scale().ToString();
		}

		private void label1_Click(object sender, System.EventArgs e)
		{
		
		}

		private void label2_Click(object sender, System.EventArgs e)
		{
		
		}

		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
			GeomModel.CanvasLayer lay = canvas1.layerByName(m_curr_item);
			if( lay == null)
				return;
			
			lay.visiableOnScale = (int)Convert.ToDecimal(textBoxLayScale.Text);
			canvas1.Invalidate();
		}

		private void checkBoxLayVis_CheckedChanged(object sender, System.EventArgs e)
		{
			GeomModel.CanvasLayer lay = canvas1.layerByName(m_curr_item);
			if( lay == null)
				return;

			lay.visiable = checkBoxLayVis.Checked;
			lay.visiableOnScale = (int)Convert.ToDecimal(textBoxLayScale.Text);			
			canvas1.Invalidate();
		}

		private void checkBoxGrid_CheckedChanged(object sender, System.EventArgs e)
		{
			canvas1.getGeomModel().showGrid(checkBoxGrid.Checked);
			canvas2.getGeomModel().showGrid(checkBoxGrid.Checked);
			
		}

		private void dataGridGIS_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
		{
			
		}

		private void radioButtonMove_CheckedChanged(object sender, System.EventArgs e)
		{
			canvas1.StartMoving();
		}

		private void radioButtonSelect_CheckedChanged(object sender, System.EventArgs e)
		{
			canvas1.StartSelection();
		}

		private void radioButtonCenter_CheckedChanged(object sender, System.EventArgs e)
		{
			canvas1.setMode(Canvas.DrawingMode.Center);
		}

		private void radioButtonFind_CheckedChanged(object sender, System.EventArgs e)
		{
			canvas1.setMode(Canvas.DrawingMode.Find);
		}

		private void buttonTrans_Click(object sender, System.EventArgs e)
		{
			double [] x_arr = new double [1];
			double [] y_arr = new double [1];
			double [] z_arr = new double [1];
			
			x_arr[0] = (double)Convert.ToDecimal(textBoxGISLon.Text);
			y_arr[0] = (double)Convert.ToDecimal(textBoxGISLat.Text);
			z_arr[0] = 0;
			m_coord_transform.transform(x_arr,y_arr,z_arr);

			/*double x1 = x_arr[0];
			double y1 = y_arr[0];
			double z1 = z_arr[0];
			m_coord_transform.transformPnt(x1,y1,z1);
			*/
			textBoxUTM.Text = x_arr[0].ToString() + ":" + y_arr[0].ToString();
		}

		private void buttonNaviZoomIn_Click(object sender, System.EventArgs e)
		{
			canvas2.ZoomIn();
		}

		private void buttonNaviZoomOut_Click(object sender, System.EventArgs e)
		{
			canvas2.ZoomOut();
		}

		private void checkBoxCoordSys_CheckedChanged(object sender, System.EventArgs e)
		{
			if(checkBoxCoordSys.Checked)
				canvas1.CoordSys = Canvas.CoordSystem.UpRight;
			else
				canvas1.CoordSys = Canvas.CoordSystem.DownRight;
		}

		public class FrameInfo 
		{
			public FrameInfo(int ch,string fn)
			{
				chain = ch;
				fname = fn;
			}
			public int chain;
			public string fname;
		}


		
	}
}

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
Web Developer
Canada Canada
Baranovsky Eduard has been a software developer for more then 10 years. He has an experence in image processing, computer graphics and distributed systems design.

Comments and Discussions