Click here to Skip to main content
15,885,309 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.Generic;
using System.Text;
using System.Windows.Forms;

using DataPerformer;
using CategoryTheory;
using DiagramUI;
using DiagramUI.Utils;
using DataPerformer.Interfaces;

namespace DataPerformerUI
{
    /// <summary>
    /// Panerl which correspond to measurements
    /// </summary>
    public class PanelMeasurements : Panel
    {
        private ICollection<string> vars;

        private Dictionary<string, string> selected;

        private IAssociatedObject obj;

        private Dictionary<string, ComboBox> boxes = new Dictionary<string,ComboBox>();

        private IMeasurements measurements;


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="obj">Base object</param>
        /// <param name="measurements">Measurements</param>
        /// <param name="vars">Variables</param>
        /// <param name="selected">Selected measurements</param>
        public PanelMeasurements(IAssociatedObject obj, 
            IMeasurements measurements, object vars, Dictionary<string, string> selected)
        {
            this.obj = obj;
            this.measurements = measurements;
            this.selected = selected;
            init();
            Vars = vars;
            Selected = selected;
        }


        private void init()
        {
            IDataConsumer cons = null;
            if (obj is IDataConsumer)
            {
                cons = obj as IDataConsumer;
            }
            Control panel = HeaderControl.Object.GetHeaderControl(cons, measurements);
            Controls.Add(panel);
            int y = panel.Height + 10;

            for (int i = 0; i < measurements.Count; i++)
            {
                IMeasure measure = measurements[i];
                Label lab = new Label();
                lab.Top = y;
                lab.Left = 20;
                lab.Text = Measure.GetTypeName(measure.Type);
                y = lab.Bottom + 10;
                Controls.Add(lab);
                ComboBox cb = new ComboBox();
                cb.Location = new System.Drawing.Point(20, y);
                cb.Size = new System.Drawing.Size(121, 21);
                Label l = new Label();
                l.Text = (string)measure.Name.Clone();
                l.Location = new System.Drawing.Point(cb.Left + cb.Width + 10, y);
                l.Width = Width - 20;
                Controls.Add(cb);
                Controls.Add(l);
                y = cb.Bottom + 5;
                string argName = obj.GetName(measurements)
                    + "." + measure.Name;
                cb.SelectCombo(argName);
                boxes[argName] = cb;
            }
            Width = 100;
            Height = y + 10;
       }


        internal object Vars
        {
            set
            {
                if (value is ICollection<string>)
                {
                    vars = value as ICollection<string>;
                }
                if (value is string)
                {
                    string s = value as string;
                    vars = new List<string>();
                    foreach (char c in s)
                    {
                        vars.Add(c + "");
                    }
                }
                foreach (ComboBox box in boxes.Values)
                {
                    box.Items.Clear();
                    box.FillCombo(vars);
                }
            }
        }

        internal Dictionary<string, string> Selected
        {
            get
            {
                Dictionary<string, string> vn = new Dictionary<string, string>();
                foreach (string key in boxes.Keys)
                {
                    ComboBox box = boxes[key];
                    string s = box.SelectedItem + "";
                    if (s.Length == 0)
                    {
                        continue;
                    }
                    if (vn.ContainsKey(s))
                    {
                        throw new Exception("Measurement \"" + s + "\" already exists");
                    }
                    vn[s] = key;
                }
                return vn;
            }
            set
            {
                foreach (string key in value.Keys)
                {
                    string val = value[key];
                    if (!boxes.ContainsKey(val))
                    {
                        continue;
                    }
                    ComboBox box = boxes[value[key]];
                    box.SelectCombo(key);
                }
            }
        }
    }
}

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