Click here to Skip to main content
15,885,767 members
Articles / Programming Languages / C#

Integration: Mechanics + Hydraulics + Navigation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (46 votes)
3 Feb 2011CPOL21 min read 61.5K   6.1K   88  
Sample of integration of branches of engineering.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Serialization;
using System.Windows.Forms;

using CategoryTheory;

using DiagramUI;

using DataPerformer;
using DataPerformer.Interfaces;
using DataPerformer.SeriesTypes;
using Chart.Drawing.Interfaces;


namespace DataPerformerUI
{
    /// <summary>
    /// Editor of measure for graph component
    /// </summary>
	public class PanelMeasureGraph : Panel
	{
        /// <summary>
        /// Measurements
        /// </summary>
		protected IMeasurements measurements;

        /// <summary>
        /// Colors for measurements
        /// </summary>
		protected ArrayList measurementControls;
		private string panelName;
        internal Dictionary<string, object[]> series = new Dictionary<string,object[]>();
		private Hashtable mea = new Hashtable();
        private Dictionary<Button, object> buttons = new Dictionary<Button, object>();
		private DataConsumer consumer;
        private Dictionary<string, Color> dic;
        //private Dictionary<string, bool> dicStep;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="measurements">Measurements</param>
        /// <param name="consumer">Data consumer</param>
        /// <param name="dic">Dictionary of colors</param>
        public PanelMeasureGraph(IMeasurements measurements, DataConsumer consumer,
            Dictionary<string, Color> dic)
		{
            this.measurements = measurements;
			this.consumer = consumer;
            this.dic = dic;
            //this.dicStep = dicStep;
			initialize();
		}


        new internal void Update()
        {
            buttons.Clear();
            series.Clear();
            foreach (object[] o in measurementControls)
            {
                CheckBox cb = o[0] as CheckBox;
                if (!cb.Checked)
                {
                    continue;
                }
                IMeasure y = o[1] as IMeasure;
                object t = y.Type;
                string sn = panelName + "." + y.Name;
                 OfficePickers.ColorPicker.ComboBoxColorPicker pic = o[3] as OfficePickers.ColorPicker.ComboBoxColorPicker;
                Button b = o[2] as Button;
                dic[sn] = pic.Color;
                object[] ob = new object[] { null, o[1], o[2], o[3] };
                series[sn] = ob;
                buttons[b] = ob;
            }
        }
		
		internal Dictionary<string, object[]> Series
		{
            get
            {
                return series;
             }
		}

        internal static Dictionary<string, object[]> GetSeries(Control control)
        {
            Dictionary<string, object[]> d = new Dictionary<string, object[]>();
            foreach (Control c in control.Controls)
            {
                if (!(c is PanelMeasureGraph))
                {
                    continue;
                }
                PanelMeasureGraph p = c as PanelMeasureGraph;
                p.Update();
                Dictionary<string, object[]> dic = p.Series;
                foreach (string key in dic.Keys)
                {
                    d[key] = dic[key];
                }
            }
            return d;
        }

        /// <summary>
        /// Creates table of measurements
        /// </summary>
        /// <param name="x">Input measure</param>
        /// <returns>Table of measurements</returns>
		public Hashtable CreateMeasurements(IMeasure x)
		{
			mea.Clear();
			foreach(object[] o in measurementControls)
			{
				CheckBox cb = o[0] as CheckBox;
				if (!cb.Checked)
				{
					continue;
				}
				IMeasure y = o[1] as IMeasure;
				object t = y.Type;
				Double a = 0;
				if (t.Equals(a))
				{
					continue;
				}
                try
                {
                    DoubleArrayFunction f = new DoubleArrayFunction(y.Type);
                    mea[o[0]] = new object[] { f, x, y };
                }
                catch (Exception ex)
                {
                    ex.Log();
                }
			}
			return mea;
		}
		
        /// <summary>
        /// Name of panel
        /// </summary>
		public string PanelName
		{
			get
			{
				return panelName;
			}
		}
		
        /// <summary>
        /// Gets argument measure from name
        /// </summary>
        /// <param name="name">The name</param>
        /// <returns>The measure</returns>
		public IMeasure GetArgument(string name)
		{
			foreach(object[] o in measurementControls)
			{
				IMeasure m = o[1] as IMeasure;
				if (name.Equals(panelName + "." + m.Name))
				{
					return m;
				}
			}
			return null;
		}

       
		
		/// <summary>
		/// Initialization
		/// </summary>
		private void initialize()
		{
			Control panel = HeaderControl.Object.GetHeaderControl(consumer, measurements);
            panelName = consumer.GetMeasurementName(measurements);
			Controls.Add(panel);
			measurementControls = new ArrayList();
			int y = panel.Height + 10;
			for (int i = 0; i < measurements.Count; i++)
			{
				IMeasure measure = measurements[i];
                Label l = new Label();
                OfficePickers.ColorPicker.ComboBoxColorPicker pic = new OfficePickers.ColorPicker.ComboBoxColorPicker();
				CheckBox cb = new CheckBox();
                string nm = measure.Name;
                cb.Text = nm;
                cb.Left = 20;
                cb.Top = y;
                string fn = panelName + "." + nm;
                if (dic.ContainsKey(fn))
                {
                    cb.Checked = true;
                    pic.Color = dic[fn];
                }
				pic.Left = cb.Left;
				pic.Top = cb.Bottom + 5;
				Button b = new Button();
				b.Top = pic.Top;
				b.Left = pic.Right + 10;
                b.Text = ResourceService.Resources.GetControlResource("Save", DataPerformerUI.Utils.ControlUtilites.Resources);
				b.Click += new EventHandler(onButtonSaveClick);
				measurementControls.Add(new object[]{cb, measure, b, pic, panelName});
                Controls.Add(pic);
                Controls.Add(cb);
                Controls.Add(b);
				y = b.Bottom + 5;
			}
			Width = 250;
			Height = y + 10;
		}

		private void onButtonSaveClick(Object sender, EventArgs e)
		{
            Button b = sender as Button;
            object o = b.Tag;
            if (o == null)
            {
                return;
            }
            Form form = null;
            if (o is DataPerformer.Series)
            {
                form = new FormGraphSave(o as DataPerformer.Series, consumer.GraphControls);
                form.Show();
            }
            if (o is object[])
            {
                object[] ob = o as object[];
                form = new FormSaveVectorFunction(ob);
            }
            if (form != null)
            {
                form.Show();
            }

			/*foreach (object[] o in measurementControls)
			{
				if (o[2] == sender)
				{
					if (!mea.ContainsKey(o[0]))
					{
						continue;
					}
					object[] ob = mea[o[0]] as object[];
					Form form = new FormSaveVectorFunction(ob);
					form.Show();
					return;
				}
			}
			foreach (object[] o in series.Values)
			{
				if (o[1] != sender)
				{
					continue;
				}
				Form form = new FormGraphSave(o[0] as DataPerformer.Series, consumer.GraphControls);
				form.Show();
			}*/
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions