Click here to Skip to main content
15,895,142 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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

using DiagramUI;
using Diagram.UI.Interfaces;
using DiagramUI.Interfaces;

using DataPerformerUI.Labels;
using DataPerformer;
using ToolBox;

using Chart.Drawing.Interfaces;
using Chart.Drawing.Painters;

using Chart;
using Chart.Panels;
using Chart.Interfaces;
using Chart.Utils;

namespace DataPerformerUI.UserControls
{
    /// <summary>
    /// User control for series
    /// </summary>
    public partial class UserControlSeries : UserControl, ISeriesGetter, ISeriesSetter,
        IEnabled
    {

        #region Fields

        /// <summary>
        /// Series
        /// </summary>
        protected DataPerformer.Series series;

        /// <summary>
        /// Desktop
        /// </summary>
        protected IDesktop desktop;

        /// <summary>
        /// Chart performer
        /// </summary>
        protected ChartPerformer performer;


        private SeriesPainterControlPovider painterProvider;

        private ISeriesPainterPovider painterInreface;



        private Action<bool> upatateTable = (bool b) => { };

        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public UserControlSeries()
        {
            InitializeComponent();
            PreInit();
            toolStripLabelCoord.Text = "";
        }


        #endregion

        #region ISeriesGetter Members

        Chart.Drawing.Interfaces.ISeries ISeriesGetter.Series
        {
            get
            {
                return DrawSeries;
            }
        }

        #endregion

        #region ISeriesSetter Members

        ISeries ISeriesSetter.Series
        {
            set
            {
                series.Clear();
                IList<IPoint> l = value.Points;
                foreach (IPoint p in l)
                {
                    series.AddXY(p.X, p.Y);
                }
                Show();
            }
        }

        #endregion

        #region IEnabled Members

        bool IEnabled.Enabled
        {
            get
            {
                return false;
            }
            set
            {
                if (value)
                {
                    painterProvider.Array = painterProvider.Array;
                    Show();
                }
            }
        }

        #endregion

        #region Members

        /// <summary>
        /// Provider of painter
        /// </summary>
        public SeriesPainterControlPovider PainterProvider
        {
            get
            {
                return painterProvider;
            }
            set
            {
                painterProvider = value;
                painterInreface = value;
            }
        }


        /// <summary>
        /// Post operation
        /// </summary>
        public virtual void Post()
        {
            if (series != null)
            {
                ArrayList graphControls = series.Comments;
                ControlPanel.LoadControls(panelGraph, graphControls);
            }
            Show();
            panelGraph.Cursor = Cursors.Cross;
        }

        /// <summary>
        /// Series
        /// </summary>
        protected virtual Chart.Drawing.Interfaces.ISeries DrawSeries
        {
            get
            {
                Chart.Drawing.Series.PureSeries ps = new Chart.Drawing.Series.PureSeries();
                for (int i = 0; i < series.Count; i++)
                {
                    ps.AddXY(series[i, 0], series[i, 1]);
                }
                return ps;
            }
        }

        /// <summary>
        /// Comments
        /// </summary>
        public virtual ICollection[] Comments
        {
            get
            {
                if (painterProvider == null)
                {
                    return new ICollection[0];
                }
                return painterProvider.Array.GetComments();
            }
            set
            {
                if (painterProvider != null)
                {
                    painterProvider.Array.SetComments(value);
                }
                //return;
                /*if (panelBottom.Height < 2)
                {
                    panelBottom.Height = 50;
                    panelLeft.Width = 50;
                }
                userControlCommentsLeft.Comments = value[0];
                userControlCommentsBottom.Comments = value[1];*/
            }
        }

        /// <summary>
        /// Shows all series
        /// </summary>
        public void ShowAll()
        {
            Show();
        }


        /// <summary>
        /// Pre initialization
        /// </summary>
        protected virtual void PreInit()
        {
            pic.Text = ResourceService.Resources.GetControlResource("Color", DataPerformerUI.Utils.ControlUtilites.Resources);
            PanelChart panel = new PanelChart(new int[,] { { 80, 30 }, { 10, 40 } });
            panel.SetObject(this);
            panelGraph.DragEnter += fileDragEnter;
            panelGraph.DragDrop += fileDragDrop;
            performer = panel.Performer;
            panelGraph.Controls.Add(panel);
            panel.LoadResources();
            panel.Dock = DockStyle.Fill;
            performer.Resize();
            SimpleCoordinator coordinator = new SimpleCoordinator(5, 5, performer);
            performer.Coordinator = coordinator;
            EditorReceiver.AddEditorDrag(panelGraph);
            PictureReceiver.AddImageDrag(panelGraph);
        }

        /// <summary>
        /// Shows itself
        /// </summary>
        new protected virtual void Show()
        {
            performer.RemoveAll();
            ISeriesPainter sp = painterInreface.Painter;
            if (sp != null)
            {
                SeriesGraph ser = new SeriesGraph(series);
                performer.AddSeries(ser, sp);
            }
            performer.RefreshAll();
        }

        #endregion

        #region Private and Internal Members

        internal ChartPerformer Performer
        {
            get
            {
                return performer;
            }
        }


        internal virtual Series Series
        {
            get
            {
                return series;
            }
            set
            {
                series = value;
            }
        }

        internal void ShowStrip(bool show)
        {
            if (show)
            {
                performer.SetMouseIndicator(toolStripLabelCoord);
                painterProvider =
                new SeriesPainterControlPovider(toolStripButtonType,
                    pic, StaticPerformerDataPerformerUI.DefaultSeriesPaintingArray);
                painterInreface = painterProvider;

            }
            else
            {
                toolStripMain.Visible = false;
            }
        }





        internal object[] Array
        {
            set
            {
                painterProvider.Array = value;
            }
            get
            {
                return painterProvider.Array;
            }
        }


 
        internal void Save()
        {
            try
            {
                series.Save(this);
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
                MessageBox.Show(ex.Message);
            }
        }

        internal void Open()
        {
            try
            {
                series.Load(this);
                Show();
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
                MessageBox.Show(ex.Message);
            }
        }


         private void fileDragEnter(object sender, DragEventArgs e)
        {
            IDataObject d = e.Data;
            if (d.GetDataPresent("FileNameW"))
            {
                object[] o = d.GetData("FileNameW") as object[];
                string fn = o[0] as string;
                string ex = System.IO.Path.GetExtension(fn);
                if (ex.ToLower().Equals(".gra"))
                {
                    e.Effect = DragDropEffects.Copy;
                }
            }
        }

        private void fileDragDrop(object sender, DragEventArgs e)
        {
            IDataObject d = e.Data;
            if (d.GetDataPresent("FileNameW"))
            {
                object[] o = d.GetData("FileNameW") as object[];
                string fn = o[0] as string;
                string ex = System.IO.Path.GetExtension(fn);
                if (ex.ToLower().Equals(".gra"))
                {
                    series.Load(fn);
                    ShowAll();
                }
            }
        }

        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            Open();
        }


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

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            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