/*
NPlot - A plotting library for .NET
Main.cs
Copyright (C) 2003-2004
Matt Howlett, Paolo Pierini
Port to Gtk# Miguel de icaza
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the following text in
the documentation and / or other materials provided with the
distribution:
"This product includes software developed as part of
the NPlot charting library project available from:
http://www.nplot.com/"
------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using Gtk;
using System.Data;
using NPlot;
using System.IO;
using System.Reflection;
namespace NPlotDemo
{
///
/// The main demo window.
///
public class PlotSurface2DDemo : Gtk.Window
{
static void Main()
{
Application.Init ();
Window mf = new PlotSurface2DDemo ();
mf.Show ();
Application.Run ();
}
///
/// used to keep track of the current demo plot being displayed.
///
private int currentPlot = 0;
///
/// delegate for plot demo functions.
///
private delegate void PlotDemoDelegate();
///
/// list of the plot demos, initialized in the form constructor.
///
private PlotDemoDelegate [] PlotRoutines;
// Note that a NPlot.Windows.PlotSurface2D class
// is used here. This has exactly the same
// functionality as the NPlot.PlotSurface2D
// class, except that it is derived from Forms.UserControl
// and automatically paints itself in a windows.forms
// application. Windows.PlotSurface2D can also paint itself
// to other arbitrary Drawing.Graphics drawing surfaces
// using the Draw method. (see printing later).
Gtk.Button quitButton;
Gtk.Button nextPlotButton;
Gtk.Button prevPlotButton;
NPlot.Gtk.PlotSurface2D plotSurface;
double[] PlotQEExampleValues;
string[] PlotQEExampleTextValues;
public void PlotCircular()
{
this.plotSurface.Clear();
plotSurface.Add( new HorizontalLine( 0.0, Color.LightGray ) );
plotSurface.Add( new VerticalLine( 0.0, Color.LightGray ) );
const int N = 400;
const double start = -Math.PI * 7.0;
const double end = Math.PI * 7.0;
double[] xs = new double[N];
double[] ys = new double[N];
for (int i=0; i 1.0f);
}
// transform to the tilted twiss ellipse
for (int i =0; i= min && x[i] <= max)
{
int j;
j = Convert.ToInt32(Nbin * (x[i] - min) / range);
xh[j] += 1;
}
}
StepPlot sp= new StepPlot();
sp.OrdinateData = xh;
sp.AbscissaData = new StartStep( min, range / Nbin );
sp.Center = true;
plotSurface.Add(sp, PlotSurface2D.XAxisPosition.Bottom, PlotSurface2D.YAxisPosition.Right);
// axis formatting
LinearAxis ly2 = (LinearAxis)plotSurface.YAxis2;
ly2.WorldMin = 0.0f;
ly2.Label = "Beam Density [a.u.]";
ly2.NumberOfSmallTicks = 2;
sp.Pen = new Pen( Color.Green, 2 );
// Finally, refreshes the plot
plotSurface.Refresh();
}
// Fill the array containing the rms twiss ellipse data points
// ellipse is g*x^2+a*x*y+b*y^2=e
private void TwissEllipse(float a, float b, float g, float e, ref float [] x, ref float [] y)
{
float rot, sr, cr, brot;
if (a==0)
{
rot=0;
}
else
{
rot=(float)(.5*Math.Atan(2.0 * a / (g - b)));
}
sr = (float)Math.Sin(rot);
cr = (float)Math.Cos(rot);
brot = g * sr * sr - 2.0F * a * sr * cr + b * cr * cr;
int npt=x.Length;
float theta;
for (int i=0; i 18.0f)
{
PlotQEExampleTextValues[i] = "KCsTe";
}
else
{
PlotQEExampleTextValues[i] = "";
}
s[i] = i.ToString("00") + ".1";
}
PointPlot pp = new PointPlot();
pp.DataSource = PlotQEExampleValues;
pp.Marker = new Marker( Marker.MarkerType.Square, 10 );
pp.Marker.DropLine = true;
pp.Marker.Pen = Pens.CornflowerBlue;
pp.Marker.Filled = false;
plotSurface.Add( pp );
LabelPointPlot tp1 = new LabelPointPlot();
tp1.DataSource = PlotQEExampleValues;
tp1.TextData = PlotQEExampleTextValues;
tp1.LabelTextPosition = LabelPointPlot.LabelPositions.Above;
tp1.Marker = new Marker( Marker.MarkerType.None, 10 );
plotSurface.Add( tp1 );
LabelAxis la = new LabelAxis( plotSurface.XAxis1 );
for (int i=0; i
/// callback for quit button click
///
/// unused
/// unused
private void quitButton_Click(object sender, System.EventArgs e)
{
Application.Quit ();
}
///
/// callback for next button click
///
/// unused
/// unused
private void nextPlotButton_Click(object sender, System.EventArgs e)
{
currentPlot += 1;
if (currentPlot == PlotRoutines.Length)
{
currentPlot = 0;
}
int id = currentPlot+1;
PlotRoutines[currentPlot]();
}
///
/// Callback for prev button click.
///
/// unused
/// unused
private void prevPlotButton_Click(object sender, System.EventArgs e)
{
currentPlot--;
if( currentPlot == -1 ) currentPlot = PlotRoutines.Length-1;
PlotRoutines[currentPlot]();
}
}
}