Click here to Skip to main content
15,894,460 members
Articles / Programming Languages / C# 4.0

Grandiose projects 5. Audio support

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
3 Feb 2012CPOL8 min read 23.2K   2K   8  
Audio support for grandiose projects
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 System.IO;
using System.Runtime.Serialization.Formatters.Binary;

using Diagram.UI.Interfaces;

using DiagramUI;
using DiagramUI.Utils;

using DataPerformer.Interfaces;

using Chart.Drawing.Interfaces;

using Chart;
using Chart.Utils;
using Chart.Indicators;
using Chart.Drawing.Coordinators;
using Chart.Drawing;


namespace DataPerformerUI.UserControls
{
    /// <summary>
    /// Control for series with named coordinates
    /// </summary>
    public partial class UserControlNamedSeries : UserControl, ISeriesGetter, IEnabled
    {

        #region Fields

        INamedCoordinates nc;

        SeriesPainterControlPovider painterProvider;


        ISeriesPainterPovider painterInreface;

        ToolStripComboBox[] boxes;

        string x = null;
        string y = null;


        #endregion

        #region Ctor

        /// <summary>
        /// Default constructor
        /// </summary>
        public UserControlNamedSeries()
        {
            InitializeComponent();
            userControlChart.Prepare(new int[,] { { 80, 30 }, { 10, 40 } }, true);
            userControlChart.Coordinator = new Chart.Drawing.Coordinators.SimpleCoordinator(5, 5, userControlChart.Performer);
            userControlChart.SetObject(this);
            toolStripLabelCoord.Text = "";
        }

        #endregion

        #region IEnabled Members

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

        #endregion

        #region ISeriesGetter Members

        ISeries ISeriesGetter.Series
        {
            get { return DrawSeries; }
        }

        #endregion

        #region Public and Protected Members

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

        /// <summary>
        /// Chart performer
        /// </summary>
        public Chart.ChartPerformer Performer
        {
            get
            {
                return userControlChart.Performer;
            }
        }

        /// <summary>
        /// Series
        /// </summary>
        protected virtual Chart.Drawing.Interfaces.ISeries DrawSeries
        {
            get
            {
                DataPerformer.Series series = nc as DataPerformer.Series;
                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;
            }
        }

        #endregion

        #region Own members


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

        internal void SetToolStrip(bool tool)
        {
            if (!tool)
            {
                toolStripMain.Visible = false;
                return;
            }
            painterProvider = new SeriesPainterControlPovider(toolStripButtonType, pic, StaticPerformerDataPerformerUI.DefaultSeriesPaintingArray);
            painterInreface = painterProvider;
            userControlChart.SetMouseIndicator(toolStripLabelCoord);
            boxes = new ToolStripComboBox[] { toolStripComboBoxX, toolStripComboBoxY };
        }

        internal ToolStripComboBox[] Boxes
        {
            set
            {
                boxes = value;
            }
        }


        internal INamedCoordinates NamedCoordinates
        {
            get
            {
                return nc;
            }
            set
            {
                nc = value;
            }

        }

        internal void ShowAll()
        {
            if ((boxes[0].Items.Count == 0) | (boxes[1].Items.Count == 0))
            {
                Fill();
                return;
            }
            object[] ob = new object[] { boxes[0].SelectedItem, boxes[1].SelectedItem };
            if ((ob[0] == null) | (ob[1] == null))
            {
                return;
            }
            string xx = ob[0] + "";
            string yy = ob[1] + "";
            if (!xx.Equals(x) | !yy.Equals(y))
            {
                nc.Set(xx, yy);
                x = xx;
                y = yy;
            }
            nc.Update();
            ShowChart();
        }

        void ShowChart()
        {
            Chart.ChartPerformer performer = userControlChart.Performer;
            performer.RemoveAll();
            ISeriesPainter sp = painterInreface.Painter;
            if (sp != null)
            {
                DataPerformer.Series series = nc as DataPerformer.Series;
                SeriesGraph ser = new SeriesGraph(series);
                performer.AddSeries(ser, sp);
            }
            performer.RefreshAll();
        }

        internal void Fill()
        {
            nc.Fill(boxes[0], boxes[1]);
        }

        internal void Save()
        {
            try
            {
                DataPerformer.Series s = nc as DataPerformer.Series;
                s.Save(this);
            }
            catch (Exception e)
            {
                e.ShowError(10);
                MessageBox.Show(e.Message);
            }
        }


        #endregion

        #region Event Handlers

        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            Save();
        }

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

        #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