Click here to Skip to main content
15,892,809 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 38K   4.1K   42  
Usage of universal framework for chart reconstruction
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using System.Xml;

using DockableControls;
using DataWarehouse.Utils;
using DataWarehouse.Interfaces;
using Common.UI;

namespace DataWarehouse
{
    /// <summary>
    /// Database tree
    /// </summary>
    public partial class FormDatabaseTree : Content
    {
        #region Fields
        string ext;
        DatabaseInterface data;
        Image image;
        #endregion

        #region Ctor

        private FormDatabaseTree()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Costructor
        /// </summary>
        /// <param name="data">Database interface</param>
        /// <param name="ext">Extension</param>
        /// <param name="image">Tree image</param>
        public FormDatabaseTree(DatabaseInterface data, string ext, Image image)
            : this()
        {
            this.LoadControlResources();
            this.data = data;
            this.image = image;
            ImageList l = new ImageList();
            l.Images.Add(ResourceImage.CLSDFOLD);
            l.Images.Add(ResourceImage.OPENFOLD);
            l.Images.Add(image);
            treeViewMain.ImageList = l;
          //  treeViewMain.ImageIndex = 0;
          //  treeViewMain.SelectedImageIndex = 1;
            this.ext = ext;
            init();
            fill();
        }

        #endregion


        #region Members

        void fill()
        {
          IDirectory[] dir =  data.GetRoots(new string[] { ext });
          foreach (IDirectory d in dir)
          {
              treeViewMain.Nodes.Add(GetNode(d));
          }
        }

        private static TreeNode GetNode(IDirectory dir)
        {
            List<TreeNode> ln = new List<TreeNode>();
            IEnumerable<IDirectory> ed = dir;
            List<IDirectory> ld = new List<IDirectory>();
            ld.AddRange(ed);
            ld.Sort(NodeComparer.Singleton);
            foreach (IDirectory dird in ld)
            {
                TreeNode tn = GetNode(dird);
                ln.Add(tn);
            }
            List<ILeaf> ll = new List<ILeaf>();
            IEnumerable<ILeaf> el = dir;
            ll.AddRange(el);
            ll.Sort(NodeComparer.Singleton as IComparer<ILeaf>);
            foreach (ILeaf leaf in ll)
            {
                TreeNode tnl = new TreeNode(leaf.Name, 2, 2);
                tnl.Tag = leaf;
                ln.Add(tnl);
            }
            TreeNode node = new TreeNode(dir.Name, 0, 1, ln.ToArray());
            return node;
        }

        private void init()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            AllowDrop = true;

            //Prepare richTextbox's context menu.
            ContextMenu theMenu;
            MenuItem menuItem;

            theMenu = new ContextMenu();

            menuItem = new MenuItem("Undo");
            //            menuItem.Click += new EventHandler(OnTexBoxMenu_Undo);
            theMenu.MenuItems.Add(menuItem);

            menuItem = new MenuItem("-");
            theMenu.MenuItems.Add(menuItem);

            /*menuItem = new MenuItem("Cut");
            menuItem.Click += new EventHandler(OnTexBoxMenu_Cut);
            theMenu.MenuItems.Add(menuItem);*/
            /*
                        menuItem = new MenuItem("Copy");
                        menuItem.Click += new EventHandler(OnTexBoxMenu_Copy);
                        theMenu.MenuItems.Add(menuItem);

                        menuItem = new MenuItem("Paste");
                        menuItem.Click += new EventHandler(OnTexBoxMenu_Paste);
                        theMenu.MenuItems.Add(menuItem);

                        menuItem = new MenuItem("Delete");
                        menuItem.Click += new EventHandler(OnTexBoxMenu_Delete);
                        theMenu.MenuItems.Add(menuItem);

                        menuItem = new MenuItem("-");
                        theMenu.MenuItems.Add(menuItem);

                        menuItem = new MenuItem("Select All");
                        menuItem.Click += new EventHandler(OnTexBoxMenu_SelectAll);
                        theMenu.MenuItems.Add(menuItem);

                        theMenu.Popup += new EventHandler(OnTexBoxMenu_Popup);

                        _textBox.ContextMenu = theMenu;

                        Controls.Add(_textBox);

                        _upScroll.Enabled = false;
                        _dnScroll.Enabled = false;
            */
            this.AllowedStates = ((DockableControls.ContentStates)(((((DockableControls.ContentStates.Float | DockableControls.ContentStates.DockLeft)
                | DockableControls.ContentStates.DockRight)
                | DockableControls.ContentStates.DockTop)
                | DockableControls.ContentStates.DockBottom)));
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(180, 300);
            this.DockPadding.Bottom = 3;
            this.DockPadding.Top = 3;
            this.HideOnClose = true;
            this.ShowHint = DockableControls.DockState.DockRight;

        }


        #endregion



        private void treeViewMain_MouseDown(object sender, MouseEventArgs e)
        {
            TreeNode node = treeViewMain.GetNodeAt(e.Location);
            if (node == null)
            {
                return;
            }
            object o = node.Tag;
            if (o == null)
            {
                return;
            }
            if (!(o is ILeaf))
            {
                return;
            }
            IStreamCreator sc = new DatabaseStreamCreator(o as ILeaf);
            treeViewMain.DoDragDrop(sc, DragDropEffects.All);
        }

        private void refresh()
        {
            try
            {
                treeViewMain.Nodes[0].Remove();
                fill();
            }
            catch (Exception)
            {
            }
        }

        private void toolStripButtonRefresh_Click(object sender, EventArgs e)
        {
            refresh();
        }

    }
}

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