Click here to Skip to main content
15,886,059 members
Articles / Desktop Programming / WPF

Integration: Kinematics + Digital Image Processing + 3D Graphics

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
9 Sep 2012CPOL12 min read 25.4K   3.4K   18  
Further promotion of integration ideas
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using CategoryTheory;

using DiagramUI.Interfaces;
using DiagramUI.Labels;
using DiagramUI;




using TestCategory.Interfaces;

namespace DataPerformer.TestInterface.UI.UserConrols
{
    public partial class UserControlDataPerformerTest : UserControl
    {
        #region Fields

        TestData test;

        List<object> l = new List<object>();
        Dictionary<string, object[]> output;

        IComponentCollection collection;

        event Action<object, DataRow, TestData> onAdd = (object o, DataRow row, TestData td) => { };

        event Action<object, ICategoryObject, bool[]> isAdmissible = (object l, ICategoryObject o, bool[] b) => { b[0] = false; };

        private Func<TestData> createTest; 

        #endregion

        #region Ctor
        
        public UserControlDataPerformerTest()
        {
            InitializeComponent();
        }

        #endregion

        #region Public

        public event Action<object, DataRow, TestData> OnAdd
        {
            add { onAdd += value; }
            remove { onAdd -= value; }
        }

        public event Action<object, ICategoryObject, bool[]> OnAdmissible
        {
            add { isAdmissible += value; }
            remove { isAdmissible -= value; }
        }

        public Func<TestData> CreateTestData
        {
            get
            {
                return createTest;
            }
            set
            {
                createTest = value;
            }
        }
        
        #endregion

        #region Protected

        protected void Add(object o, DataRow row, TestData test)
        {
            IObjectLabel l = o as IObjectLabel;

            ICategoryObject co = l.Object;
            string name = l.GetName(collection);
 
            if (co is global::Regression.AliasRegression)
            {
                test.AddRegression(name, (uint)row[3], collection);
                return;
            }
            if (o is IProperties)
            {
                object ob = (o as IProperties).Properties;
                if (ob.GetType().Equals(typeof(DataPerformerUI.Labels.GraphLabel)))
                {
                    DataPerformerUI.Interfaces.IGraphLabel lab = ob as DataPerformerUI.Labels.GraphLabel;
                    DataPerformer.DataConsumer cons = co as DataPerformer.DataConsumer;
                    test.AddChart(name, cons.Start, cons.Step, cons.Steps, lab.Argument,
                        lab.Colors.Keys.ToArray<string>(), collection);
                    return;
                }
            }
            onAdd(o, row, test);
        }


        protected virtual bool IsAdmissible(object o, ICategoryObject cob)
        {
            if (cob is global::Regression.AliasRegression)
            {
                return true;
            }
            if (o is IProperties)
            {
                object ob = (o as IProperties).Properties;
                if (ob.GetType().Equals(typeof(DataPerformerUI.Labels.GraphLabel)))
                {
                    return true;
                }
            }
            bool[] b = new bool[1];
            isAdmissible(o, cob, b);
            return b[0];
        }


        protected void Add(object o, DataRow row)
        {
            Add(o, row, test);
        }

        #endregion

        #region Internal & Private

        internal bool HasTests(ITest test, IComponentCollection collection)
        {
            List<object> l = new List<object>();
            IEnumerable<object> c = collection.AllComponents;
            foreach (object o in c)
            {
                string name = "";
                IObjectLabel ol = null;
                ICategoryObject cob = null;
                if (o is IObjectLabel)
                {
                    ol = o as IObjectLabel;
                    cob = ol.Object;
                    name = ol.GetName(collection);
                }
                if (IsAdmissible(o, cob))
                {
                    return true;
                }
            }
            return false;
        }

        internal void Set(ITest test, IComponentCollection collection)
        {
            this.collection = collection;
            if (test != null)
            {
                this.test = test as TestData;
                output = this.test.Output;
            }
            IEnumerable<object> c = collection.AllComponents;
            foreach (object o in c)
            {
                string name = "";
                IObjectLabel ol = null;
                ICategoryObject cob = null;
                if (o is IObjectLabel)
                {
                    ol = o as IObjectLabel;
                    cob = ol.Object;
                    name = ol.GetName(collection);
                }
                if (IsAdmissible(o, cob))
                {
                    l.Add(o);
                }
           }
            List<string> ls = new List<string>();
            List<Control> controls = new List<Control>();
            uint i = 1;
            uint j = 1;
            foreach (object o in l)
            {
                int num;
                int count;
                Create(o, out num, out count);
                object[] ob = new object[] { i, (o as IObjectLabel).GetName(collection), (uint)num, (uint)count };
                dataTable.Rows.Add(ob);
                ++i;
            }
        }

        internal bool Set(int i)
        {
            if (i == 0)
            {
                return CreateTest();
            }
            if (i == 2)
            {
                test = null;
            }
            return true;

        }

        internal ITest Test
        {
            get
            {
                return test;
            }
        }

        private void Create(object o, out int num, out int count)
        {

            num = 0;
            count = 1;
            if (output != null)
            {
                string name = (o as IObjectLabel).GetName(collection);
                if (output.ContainsKey(name))
                {
                    object[] ob = output[name];
                    num = (int)ob[0] + 1;
                    if (ob.Length > 1)
                    {
                        count = (int)ob[1];
                    }
                }
            }
        }


        private bool CreateTest()
        {
            Dictionary<uint, DataRow> d = new Dictionary<uint, DataRow>();
            Dictionary<uint, int> di = new Dictionary<uint, int>();
            int i = 0;
            foreach (DataRow row in dataTable.Rows)
            {
                uint n = (uint)row[2];
                if (n > 0)
                {
                    if (di.ContainsKey(n))
                    {
                        return false;
                    }
                    di[n] = i;
                    d[n] = row;
                }
                ++i;
            }
            List<uint> ll = new List<uint>();
            ll.AddRange(di.Keys);
            ll.Sort();
            test = createTest();
            foreach (uint ik in ll)
            {
                Add(l[di[ik]], d[ik]);
            }
            test.Close();
            return true;
        }

        #endregion
    }
}

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