Click here to Skip to main content
15,881,248 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 107.6K   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.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using CanvasControl;
using GeomModel;



namespace VisiBlocks
{
	/// <summary>
	/// Summary description for UserControl1.
	/// </summary>
	public class VisiChartControl : System.Windows.Forms.UserControl
	{
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.Button btnSelect;
		private System.Windows.Forms.Button btnDelete;
		private System.Windows.Forms.ListView listView2;
		private System.Windows.Forms.Button okBtn;

		//Hashtable m_curves;
		//VisiDataSection m_data_section;
		//ChartCanvas m_canv;
		VisiChartView m_chart_view;

		private System.Windows.Forms.ColumnHeader field;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		string m_curr_item;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Splitter splitter1;
		
//		public delegate void selectEventHandler(object sender, SelectEventArgs e);
	//	public event selectEventHandler selectEvent;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public VisiChartControl (VisiChartView chart_view)			
		{
			m_chart_view = chart_view;
			//MessageBox.Show("VisiChartControl() ...");

			//m_data_section = ds;
			//m_canv = canv;

			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitComponent call
			//ArrayList fnames = m_data_section.getNumericFields();
			
			foreach(string name in m_chart_view.NumericFields)
			{
				listView1.Items.Add(name);
			}

			foreach(string name in m_chart_view.Curves)
			{
				listView2.Items.Add(name);
			}
		}

		public void setCurves(ArrayList curves)
		{
			//m_curves = curves;
			listView2.Items.Clear();

			foreach(string new_item in curves)
			{
				listView2.Items.Add(new_item);
			}
		}

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

		#region Component 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.listView1 = new System.Windows.Forms.ListView();
			this.field = new System.Windows.Forms.ColumnHeader();
			this.btnSelect = new System.Windows.Forms.Button();
			this.btnDelete = new System.Windows.Forms.Button();
			this.listView2 = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.okBtn = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.panel2 = new System.Windows.Forms.Panel();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.panel1.SuspendLayout();
			this.panel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// listView1
			// 
			this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						this.field});
			this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.listView1.Location = new System.Drawing.Point(0, 0);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(184, 168);
			this.listView1.TabIndex = 0;
			this.listView1.View = System.Windows.Forms.View.Details;
			// 
			// field
			// 
			this.field.Text = "field name";
			this.field.Width = 75;
			// 
			// btnSelect
			// 
			this.btnSelect.Location = new System.Drawing.Point(144, 8);
			this.btnSelect.Name = "btnSelect";
			this.btnSelect.Size = new System.Drawing.Size(24, 23);
			this.btnSelect.TabIndex = 1;
			this.btnSelect.Text = "->";
			this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click);
			// 
			// btnDelete
			// 
			this.btnDelete.Location = new System.Drawing.Point(120, 8);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.Size = new System.Drawing.Size(24, 23);
			this.btnDelete.TabIndex = 2;
			this.btnDelete.Text = "<-";
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// listView2
			// 
			this.listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						this.columnHeader1});
			this.listView2.Dock = System.Windows.Forms.DockStyle.Right;
			this.listView2.Location = new System.Drawing.Point(184, 0);
			this.listView2.Name = "listView2";
			this.listView2.Size = new System.Drawing.Size(136, 168);
			this.listView2.TabIndex = 3;
			this.listView2.View = System.Windows.Forms.View.Details;
			this.listView2.SelectedIndexChanged += new System.EventHandler(this.listView2_SelectedIndexChanged);
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "field name";
			// 
			// okBtn
			// 
			this.okBtn.Location = new System.Drawing.Point(8, 8);
			this.okBtn.Name = "okBtn";
			this.okBtn.Size = new System.Drawing.Size(48, 23);
			this.okBtn.TabIndex = 10;
			this.okBtn.Text = "OK";
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.splitter1);
			this.panel1.Controls.Add(this.listView1);
			this.panel1.Controls.Add(this.listView2);
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(320, 168);
			this.panel1.TabIndex = 11;
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.btnDelete);
			this.panel2.Controls.Add(this.btnSelect);
			this.panel2.Controls.Add(this.okBtn);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel2.Location = new System.Drawing.Point(0, 174);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(320, 40);
			this.panel2.TabIndex = 12;
			// 
			// splitter1
			// 
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Right;
			this.splitter1.Location = new System.Drawing.Point(181, 0);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 168);
			this.splitter1.TabIndex = 4;
			this.splitter1.TabStop = false;
			// 
			// VisiChartControl
			// 
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.Name = "VisiChartControl";
			this.Size = new System.Drawing.Size(320, 214);
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnSelect_Click(object sender, System.EventArgs e)
		{
			foreach(ListViewItem item in listView1.SelectedItems)
			{
				ListViewItem new_item = (ListViewItem)item.Clone();				
				//if(!selected_lv.Items.Contains(item))
				if(!this.m_chart_view.Curves.Contains(item.Text))
				{
					listView2.Items.Add(new_item);

					m_chart_view.AddCurve(new_item.Text);
					

				}
				
			}	
			//m_canv.Update();
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			foreach(ListViewItem item in listView2.SelectedItems)
			{				
				this.m_chart_view.DeleteCurve(item.Text);
				listView2.Items.Remove(item);
			}	
		}

		private void listView2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			ListView.SelectedListViewItemCollection selected_items = listView2.SelectedItems;
			
			if( selected_items.Count == 0 )
				return;

			m_curr_item = selected_items[0].Text;


		}

		

		
	}


	
}

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