Click here to Skip to main content
15,884,176 members
Articles / Programming Languages / C#

Reconstruction of Charts from Images

Rate me:
Please Sign up or sign in to vote.
4.92/5 (13 votes)
18 Mar 2010CPOL7 min read 37.9K   4.1K   42  
Usage of universal framework for chart reconstruction
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 DiagramUI;

using DataPerformer;

namespace DataPerformerUI.UserControls
{
    /// <summary>
    /// Editor of proterties of Funcrion accumulor
    /// </summary>
    public partial class UserControlFuncAccumulator : UserControl
    {
        #region Fields

        private FunctionAccumulator acc;

        TextBox start;
        TextBox step;
        TextBox stepCount;

        NumericUpDown intDeg;

        event Action save;

        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public UserControlFuncAccumulator()
        {
            InitializeComponent();
            this.LoadResources();
            Create();
        }

        #endregion

        #region Public Members

        /// <summary>
        /// Accumulator
        /// </summary>
        public FunctionAccumulator Function
        {
            get
            {
                return acc;
            }
            set
            {
                if (value == null)
                {
                    return;
                }
                if (acc != null)
                {
                    throw new Exception();
                }
                acc = value;
                Post();
            }
        }


        #endregion

        #region Private Members


        void Create()
        {
            Type tt = typeof(TextBox);
            Type[] t = new Type[] { tt, tt, tt, typeof(NumericUpDown) };
            DiagramUI.UserControls.UserControlEditList u = userControlEditList;
            u.Types = t;
            start = u.GetControl<TextBox>(0);
            step = u.GetControl<TextBox>(1);
            stepCount = u.GetControl<TextBox>(2);
            intDeg = u.GetControl<NumericUpDown>(3);
        }

        internal event Action OnSave
        {
            add
            {
                save += value;
            }
            remove
            {
                save -= value;
            }
        }

        internal void Post()
        {
            double[] arg = acc.Arguments;
            if (arg == null)
            {
                return;
            }
            start.Text = arg[0] + "";
            step.Text = (arg[1] - arg[0]) + "";
            stepCount.Text = arg.Length + "";
            intDeg.Value = acc.Degree;
            toolStripButtonActive.Checked = acc.IsActive;
        }


        private void Save()
        {
            try
            {
                double st = Double.Parse(start.Text);
                double s = Double.Parse(step.Text);
                int n = Int32.Parse(stepCount.Text);
                double[] arg = new double[n];
                for (int i = 0; i < arg.Length; i++)
                {
                    arg[i] = st + i * s;
                }
                acc.Arguments = arg;
            }
            catch (Exception ex)
            {
                ex.Log();
                MessageBox.Show(ex.Message);
            }
        }

        #endregion

        #region Event Handlers

        private void toolStripButtonActive_Click(object sender, EventArgs e)
        {
            acc.IsActive = toolStripButtonActive.Checked;
        }

        private void toolStripButtonRefresh_Click(object sender, EventArgs e)
        {
            Save();
            if (save != null)
            {
                save();
            }
        }

        #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