Click here to Skip to main content
15,895,462 members
Articles / Programming Languages / C#

Universal Framework for Science and Engineering - Part 2: Regression

Rate me:
Please Sign up or sign in to vote.
4.77/5 (19 votes)
11 Jul 20067 min read 51.2K   5K   76  
An article on universal scalable engineering framework applications.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using DataPerformer;
using CategoryTheory;
using DiagramUI;

namespace DataPerformerUI
{
    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;


        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()
        {
            Control panel = HeaderControl.Object.GetHeaderControl(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 = DataConsumer.GetName(obj, measurements)
                    + "." + measure.Name;
                DefaultForm.SelectCombo(cb, 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();
                    DefaultForm.FillCombo(box, 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]];
                    DefaultForm.SelectCombo(box, 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 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
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