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

The Time Machine

Rate me:
Please Sign up or sign in to vote.
4.91/5 (13 votes)
9 May 2012CPOL6 min read 34K   1.2K   32  
Long time strategy of software design and development
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DiagramUI;
using BaseTypes;
using DataPerformer.Interfaces;

namespace DataPerformer
{
    /// <summary>
    /// Combination of two series
    /// </summary>
    [Serializable()]
    public class DoubleSeries : Series, IDataConsumer, INamedCoordinates, IPostSetArrow
    {
        #region Fields

        /// <summary>
        /// Change input event
        /// </summary>
        private event Action onChangeInput = () => { };
        
        /// <summary>
        /// Coordinate measurements
        /// </summary>
        protected IMeasure[] coordinates = new IMeasure[2];


        List<IMeasurements> measurementsData = new List<IMeasurements>();

        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public DoubleSeries()
        {
        }


        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        protected DoubleSeries(SerializationInfo info, StreamingContext context)
        {
            x = info.GetValue("X", typeof(string)) as string;
            y = info.GetValue("Y", typeof(string)) as string;
        }

        #endregion

        #region Overriden Members

        /// <summary>
        /// ISerializable interface implementation
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("X", x, typeof(string));
            info.AddValue("Y", y, typeof(string));
        }

        #endregion

        #region IDataConsumer Members

        void IDataConsumer.Add(IMeasurements measurements)
        {
            measurementsData.Add(measurements);
        }

        void IDataConsumer.Remove(IMeasurements measurements)
        {
            measurementsData.Remove(measurements);
        }

        void IDataConsumer.UpdateChildrenData()
        {
            foreach (IMeasurements m in measurementsData)
            {
                m.UpdateMeasurements();
            }
        }

        int IDataConsumer.Count
        {
            get { return measurementsData.Count; }
        }

        IMeasurements IDataConsumer.this[int n]
        {
            get { return measurementsData[n]; }
        }

        void IDataConsumer.Reset()
        {
            this.FullReset();
        }

        event Action IDataConsumer.OnChangeInput
        {
            add { onChangeInput += value; }
            remove { onChangeInput -= value; }
        }

        #endregion

        #region INamedCoordinates Members

        IList<string> INamedCoordinates.GetNames(string coordinateName)
        {
            return this.Names;
        }

        string INamedCoordinates.X
        {
            get { return this.X; }
        }

        string INamedCoordinates.Y
        {
            get { return this.Y; }
        }

        void INamedCoordinates.Set(string x, string y)
        {
            this.Set(x, y);
        }

        void INamedCoordinates.Update()
        {
        }


        #endregion

        #region IPostSetArrow Members

        void IPostSetArrow.PostSetArrow()
        {
            Set();
            Post();
        }

        #endregion

        #region Specific Members

        /// <summary>
        /// Sets names of variables
        /// </summary>
        /// <param name="x">The X - coordinate name</param>
        /// <param name="y">The Y - coordinate name</param>
        public void Set(string x, string y)
        {
            this.x = x;
            this.y = y;
            Set();
        }

        /// <summary>
        /// Names of measurements
        /// </summary>
        public IList<string> Names
        {
            get
            {
                Double a = 0;
                List<string> names = new List<string>();
                IDataConsumer c = this;
                for (int i = 0; i < c.Count; i++)
                {
                    IMeasurements mea = c[i];
                    IAssociatedObject ao = mea as IAssociatedObject;
                    string s = this.GetRelativeName(ao) + ".";
                    for (int j = 0; j < mea.Count; j++)
                    {
                        IMeasure m = mea[j];
                        object rt = m.Type;
                        if (!(rt is ArrayReturnType))
                        {
                            continue;
                        }
                        ArrayReturnType art = rt as ArrayReturnType;
                        if (!art.ElementType.Equals(a))
                        {
                            continue;
                        }
                        if (art.Dimension.Length != 1)
                        {
                            continue;
                        }
                        string name = s + m.Name;
                        names.Add(name);
                    }
                }
                return names;
            }
        }

        /// <summary>
        /// Sets all its settings
        /// </summary>
        protected void Set()
        {
            points = new List<double[]>();
            IDataConsumer consumer = this;
            for (int i = 0; i < consumer.Count; i++)
            {
                IMeasurements m = consumer[i];
                IAssociatedObject ao = m as IAssociatedObject;
                string on = this.GetRelativeName(ao) + ".";
                for (int j = 0; j < m.Count; j++)
                {
                    IMeasure mea = m[j];
                    string s = on + mea.Name;
                    if (s.Equals(x))
                    {
                        coordinates[0] = mea;
                        continue;
                    }
                    if (s.Equals(y))
                    {
                        coordinates[1] = mea;
                    }
                }
            }
            consumer.Reset();
            consumer.UpdateChildrenData();
            object ox = coordinates[0].Parameter();
            if (ox is DBNull | ox == null)
            {
                return;
            }
            object oy = coordinates[1].Parameter();
            if (oy is DBNull | oy == null)
            {
                return;
            }
            Array ax = ox as Array;
            Array ay = oy as Array;
            for (int i = 0; i < ax.GetLength(0) & i < ay.GetLength(0); i++)
            {
                double xx = (double)ax.GetValue(i);
                double yy = (double)ay.GetValue(i);
                points.Add(new double[] { xx, yy });
            }
        }

    /*    public List<string> AllMeasurements
        {
            get
            {
                Double a = 0;
                IDataConsumer c = this;
                List<string> list = new List<string>();
                for (int i = 0; i < c.Count; i++)
                {
                    IMeasurements m = c[i];
                    IAssociatedObject ao = m as IAssociatedObject;
                    string on = PureDesktop.GetRelativeName(this, ao) + ".";
                    for (int j = 0; j < m.Count; j++)
                    {
                        IMeasure mea = m[j];
                        if (mea.Type.Equals(a))
                        {
                            string s = on + mea.Name;
                            list.Add(s);
                        }
                    }
                }
                return list;
            }
        }*/



        #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