Click here to Skip to main content
15,891,248 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.Data;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DataPerformer;
using DataSetService;
using DataPerformer.Interfaces;


namespace DataTableSelection
{

    /// <summary>
    /// Iterator obtained from data set
    /// </summary>
    [Serializable()]
    public class DataSetIterator : CategoryObject, ISerializable, IIterator, IDataSetConsumer, IMeasurements
    {

        #region Fields

        /// <summary>
        /// Data set
        /// </summary>
        protected DataSet dataSet;

        /// <summary>
        /// Iterator table
        /// </summary>
        protected DataTable table;

        /// <summary>
        /// Current row
        /// </summary>
        protected DataRow row;

        /// <summary>
        /// Current row number
        /// </summary>
        protected int current = -1;

        /// <summary>
        /// Row reference
        /// </summary>
        protected DataRow[] rowm = new DataRow[] { null };

        /// <summary>
        /// Factory
        /// </summary>
        protected IDataSetFactory factory;

        /// <summary>
        /// List of measures
        /// </summary>
        protected List<IMeasure> mea = new List<IMeasure>();


        #endregion

        #region Constructors

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

        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public DataSetIterator(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion

        #region ISerializable Members

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion

        #region IIterator Members

        void IIterator.Reset()
        {
            current = 0;
            rowm[0] = table.Rows[0];
        }

        bool IIterator.Next()
        {
            if (table == null)
            {
                return false;
            }
            ++current;
            if (current >= table.Rows.Count)
            {
                return false;
            }
            row = table.Rows[current];
            rowm[0] = row;
            return true;
        }

        #endregion

        #region IDataSetConsumer Members

        void IDataSetConsumer.Add(DataSet dataSet)
        {
            if (this.dataSet != null & dataSet != null)
            {
                throw new Exception();
            }
            this.dataSet = dataSet;
            table = dataSet.Tables[0];
            Init();

        }

        void IDataSetConsumer.Remove(DataSet dataSet)
        {
            this.dataSet = null;
        }

        /// <summary>
        /// Factory
        /// </summary>
        public IDataSetFactory Factory
        {
            get
            {
                return factory;
            }
            set
            {
                factory = value;
            }
        }


        #endregion

        #region IMeasurements Members

        int IMeasurements.Count
        {
            get { return mea.Count; }
        }

        IMeasure IMeasurements.this[int n]
        {
            get { return mea[n]; }
        }

        void IMeasurements.UpdateMeasurements()
        {
        }

        bool IMeasurements.IsUpdated
        {
            get
            {
                return true;
            }
            set
            {
            }
        }

        #endregion


        #region Specific Members

        /// <summary>
        /// Initialization
        /// </summary>
        protected void Init()
        {
            if (table == null)
            {
                return;
            }
            mea.Clear();
            foreach (DataColumn c in table.Columns)
            {
                int ord = c.Ordinal;
                string name = c.ColumnName;
                object type = factory.GetObjectType(c);
                IMeasure m = new RowMeasure(name, type, rowm, ord);
                mea.Add(m);
            }
        }


        #endregion

        #region Measure
  
        class RowMeasure : IMeasure
        {
            string name;
            object type;
            DataRow[] row;
            int ordinal;

            Func<object> par;

            public RowMeasure(string name, object type, DataRow[] row, int ordinal)
            {
                this.name = name;
                this.type = type;
                this.row = row;
                this.ordinal = ordinal;
                par = get;
            }

            #region IMeasure Members

            Func<object> IMeasure.Parameter
            {
                get { return par; }
            }

            string IMeasure.Name
            {
                get { return name; }
            }

 
            object IMeasure.Type
            {
                get { return type; }
            }

            #endregion

            object get()
            {
                  return row[0][ordinal];
            }
        }
        #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