Ejemplo n.º 1
0
        /// <summary>
        /// Plot with new source and new destination chart
        /// </summary>
        /// <exception cref="System.ArgumentNullException" caption="ArgumentNullException">Chart control or FunctionParameters cannot be null</exception>
        /// <exception cref="System.ArgumentException" caption="ArgumentException">Code or Formula of source cannot be empty</exception>
        /// <exception cref="System.NotSupportedException" caption="NotSupportedException">Chart not supported</exception>
        /// <example>
        ///     <code lang="CS" description="The following example plot given function on given chart">
        /// NugenCCalcComponent2D nugenCCalcComponent1 = new NugenCCalcComponent2D();
        /// nugenCCalcComponent1.Plot(c1Chart, new Explicit2DParameters("x*x"));
        /// </code>
        /// </example>
        public void Plot(object chartControl, Function2DParameters functionParameters)
        {
            if (DesignMode)
            {
                return;
            }

            OnBeforePlot();

            if (chartControl == null)
            {
                throw new ArgumentNullException("ChartControl");
            }

            if (functionParameters == null)
            {
                throw new ArgumentNullException("functionParameters");
            }

            if (functionParameters.Code == "")
            {
                throw new ArgumentException("Code or Formula of source cannot be empty");
            }


            IChartAdapter2D adapter = null;

            if (chartControl != _chartControl)
            {
                adapter = (IChartAdapter2D)GetChartAdapter(chartControl);
                adapter.SetChartControl(chartControl);
            }
            else
            {
                adapter = (IChartAdapter2D)_currentAdapter;
            }

            if (adapter == null)
            {
                throw new NotSupportedException("Chart not supported");
            }


            Function function = functionParameters.Function;

            if (function is Constant)
            {
                if (functionParameters is Explicit2DParameters)
                {
                    PlotConstantFunction(adapter, (Explicit2DParameters)functionParameters);
                }

                if (functionParameters is Implicit2DParameters)
                {
                    PlotConstantFunction(adapter, (Implicit2DParameters)functionParameters);
                }
            }

            if (function is Explicit2DFunction)
            {
                if (functionParameters is Explicit2DParameters)
                {
                    PlotExplicitFunction(adapter, (Explicit2DParameters)functionParameters);
                }

                if (functionParameters is Implicit2DParameters)
                {
                    PlotExplicitFunction(adapter, (Implicit2DParameters)functionParameters);
                }
            }

            if (function is Implicit2DFunction)
            {
                PlotImplicit2DFunction(adapter, (Implicit2DParameters)functionParameters);
            }

            if (function is Parameter2DFunction)
            {
                PlotParametric2DFunction(adapter, (Parametric2DParameters)functionParameters);
            }
            OnAfterPlot();
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Plot with new source and new destination chart
		/// </summary>
		/// <exception cref="System.ArgumentNullException" caption="ArgumentNullException">Chart control or FunctionParameters cannot be null</exception>
		/// <exception cref="System.ArgumentException" caption="ArgumentException">Code or Formula of source cannot be empty</exception>
		/// <exception cref="System.NotSupportedException" caption="NotSupportedException">Chart not supported</exception>
		/// <example>
		/// 	<code lang="CS" description="The following example plot given function on given chart">
		/// NugenCCalcComponent2D nugenCCalcComponent1 = new NugenCCalcComponent2D();  
		/// nugenCCalcComponent1.Plot(c1Chart, new Explicit2DParameters("x*x"));
		/// </code>
		/// </example>
		public void Plot(object chartControl, Function2DParameters functionParameters)
		{
			if (DesignMode)
				return;

			OnBeforePlot();

			if (chartControl == null)
				throw new ArgumentNullException("ChartControl");

			if (functionParameters == null)
				throw new ArgumentNullException("functionParameters");

			if (functionParameters.Code == "")
			{
				throw new ArgumentException("Code or Formula of source cannot be empty");
			}


			IChartAdapter2D adapter = null;
			if (chartControl != _chartControl)
			{
				adapter = (IChartAdapter2D)GetChartAdapter(chartControl);
				adapter.SetChartControl(chartControl);
			}
			else
				adapter = (IChartAdapter2D)_currentAdapter;

			if (adapter == null)
				throw new NotSupportedException("Chart not supported");


			Function function = functionParameters.Function;

			if (function is Constant)
			{
				if (functionParameters is Explicit2DParameters)
					PlotConstantFunction(adapter, (Explicit2DParameters)functionParameters);

				if (functionParameters is Implicit2DParameters)
					PlotConstantFunction(adapter, (Implicit2DParameters)functionParameters);
			}

			if (function is Explicit2DFunction)
			{
				if (functionParameters is Explicit2DParameters)
					PlotExplicitFunction(adapter, (Explicit2DParameters)functionParameters);

				if (functionParameters is Implicit2DParameters)
					PlotExplicitFunction(adapter, (Implicit2DParameters)functionParameters);
			}

			if (function is Implicit2DFunction)
			{
				PlotImplicit2DFunction(adapter, (Implicit2DParameters)functionParameters);
			}

			if (function is Parameter2DFunction)
			{
				PlotParametric2DFunction(adapter, (Parametric2DParameters)functionParameters);
			}
			OnAfterPlot();
		}
Ejemplo n.º 3
0
		private void PlotFunction(Function2DParameters functionParameters)
		{
			if (nugenCCalcComponent1.FunctionParameters == null)
			{
				MessageBox.Show(this,
					"Please, select some function", "MathX Demo 2D", MessageBoxButtons.OK, MessageBoxIcon.Warning);
				return;
			}
	
			try
			{
				nugenCCalcComponent1.FunctionParameters = functionParameters;
				object area = c1Chart.GetType().InvokeMember("ChartArea", BindingFlags.GetProperty,
					null, c1Chart, null);

				object size = area.GetType().InvokeMember("Size", BindingFlags.GetProperty,
					null, area, null);
				
				if (nugenCCalcComponent1.FunctionParameters is Implicit2DParameters)
				{
					((Implicit2DParameters)nugenCCalcComponent1.FunctionParameters).AreaSize = (Size)size;
				}
				//

				nugenCCalcComponent1.Plot();
			}
			catch (Exception ex)
			{
				MessageBox.Show(this, "Error: " + ex.Message, "Math X Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}