Example showing drawing using GINOSURF

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using GinoGraphics;

namespace surfex1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox pictureBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(292, 273);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			this.pictureBox1.Resize += new System.EventHandler(this.pictureBox1_Resize);
			this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.pictureBox1});
			this.Name = "Form1";
			this.Text = "Form1";
			this.Resize += new System.EventHandler(this.Form1_Resize);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void pictureBox1_Click(object sender, System.EventArgs e)
		{

		}

		private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			GWORKSPACE	work = new GWORKSPACE();
			GFNTFILSTY	font_style = new GFNTFILSTY(FontFillStyle.GOUTFILL,FillStyle.GSOLID,(LineStyle)Colour.GRED,FillStyle.GNOFILL,0);
			GDIM	paper = new GDIM();
			GLIMIT	picture = new GLIMIT(0.0,1000.0,0.0,750.0);
			GLIMIT  viewport = new GLIMIT();
			GLIMIT	data_limit = new GLIMIT(999.0,-999.0,999.0,-999.0);
			GLIMIT	map_frame = new GLIMIT(100.0,900.0,300.0,650.0);
			GLIMIT	frame1 = new GLIMIT(10.0,990.0,50.0,740.0);
			GLIMIT	frame2 = new GLIMIT(15.0,985.0,55.0,735.0);
			GLIMIT	cross_frame = new GLIMIT();
			GPOINT[] cross_sec = new GPOINT[4];
			GPOINT[] map_line = new GPOINT[4];
			GPOINT   temp_pt = new GPOINT();
			GPOINT3[] data;
			int[]    linestyle = new int[4] {2,2,2,2};

			/*  Contour map and cross section */
			/*  using the data files gstd3.dat */

			/* ************************************************* */

			double xinc = 10.0,
				yinc = 0.0,
				cinc = 10.0;

			double[,] gridz;
			double[]   height = new double[4];
			double     dist;
			int   i,ip=0,npts,colour=0,NUL=0;
			IntPtr hdc;

			int NUMX = 60;
			int NUMY = 48;
			int NCONT = 8;


			/*  Read contour data from GSTD3.DAT */

			string    fileName = "GSTD3.DAT";
			FileInfo  fileInfo = new FileInfo(fileName);

			StreamReader r = fileInfo.OpenText();
			string    textLine;

            // ((textLine = r.ReadLine()) != null)

						textLine = r.ReadLine();
						npts = int.Parse(textLine);
			//fscanf(fp,"%d\n",&npts);
			hdc = e.Graphics.GetHdc();
			//npts = 55;
			data = new GPOINT3[npts];

			data[0] = new GPOINT3(0.00,    4.00,   85.00);
			data[1] = new GPOINT3(3.00,   54.00,   73.00);
			data[2] = new GPOINT3(0.00,   68.00,   27.00);
			data[3] = new GPOINT3(1.00,  110.00,    8.00);
			data[4] = new GPOINT3(11.00,   80.00,   29.00);
			data[5] = new GPOINT3(13.00,   40.00,   84.00);
			data[6] = new GPOINT3(24.00,   39.00,   71.00);
			data[7] = new GPOINT3(23.00,   88.00,   61.00);
			data[8] = new GPOINT3(39.00,   92.00,   67.00);
			data[9] = new GPOINT3(40.00,   57.00,   65.00);
			data[10] = new GPOINT3(   46.00,  120.00,   66.00);
			data[11] = new GPOINT3(   67.00,   80.00,   56.00);
			data[12] = new GPOINT3(   53.00,   21.00,   47.00);
			data[13] = new GPOINT3(   74.00,   13.00,   65.00);
			data[14] = new GPOINT3(   70.00,   96.00,   64.00);
			data[15] = new GPOINT3(   90.00,  103.00,   47.00);
			data[16] = new GPOINT3(   82.00,   50.00,   56.00);
			data[17] = new GPOINT3(   99.00,   28.00,   73.00);
			data[18] = new GPOINT3(   92.00,    0.00,   94.00);
			data[19] = new GPOINT3(  119.00,   51.00,   57.00);
			data[20] = new GPOINT3(  110.00,   88.00,   73.00);
			data[21] = new GPOINT3(  122.00,  110.00,   74.00);
			data[22] = new GPOINT3(  125.00,    4.00,   57.00);
			data[23] = new GPOINT3(  150.00,   36.00,   26.00);
			data[24] = new GPOINT3(  146.00,   72.00,   74.00);
			data[25] = new GPOINT3(  130.00,   91.00,  104.00);
			data[26] = new GPOINT3(  137.00,  116.00,   76.00);
			data[27] = new GPOINT3(   24.00,   20.00,   66.00);
			data[28] = new GPOINT3(    1.00,   26.00,   94.00);
			data[29] = new GPOINT3(    9.00,   68.00,   71.00);
			data[30] = new GPOINT3(    5.00,   90.00,   17.00);
			data[31] = new GPOINT3(   15.00,  120.00,   20.00);
			data[32] = new GPOINT3(   17.00,   75.00,   71.00);
			data[33] = new GPOINT3(   28.00,    0.00,   62.00);
			data[34] = new GPOINT3(   28.00,   74.00,   74.00);
			data[35] = new GPOINT3(   21.00,   98.00,   29.00);
			data[36] = new GPOINT3(   43.00,   30.00,   54.00);
			data[37] = new GPOINT3(   47.00,   71.00,   64.00);
			data[38] = new GPOINT3(   60.00,  107.00,   74.00);
			data[39] = new GPOINT3(   62.00,   40.00,   46.00);
			data[40] = new GPOINT3(   53.00,    1.00,   49.00);
			data[41] = new GPOINT3(   76.00,   55.00,   50.00);
			data[42] = new GPOINT3(   77.00,  114.00,   66.00);
			data[43] = new GPOINT3(   91.00,   65.00,   57.00);
			data[44] = new GPOINT3(   91.00,   48.00,   60.00);
			data[45] = new GPOINT3(   96.00,   18.00,   80.00);
			data[46] = new GPOINT3(  110.00,   34.00,   64.00);
			data[47] = new GPOINT3(  116.00,   64.00,   62.00);
			data[48] = new GPOINT3(  115.00,  115.00,   66.00);
			data[49] = new GPOINT3(  122.00,   29.00,   55.00);
			data[50] = new GPOINT3(  149.00,   14.00,   27.00);
			data[51] = new GPOINT3(  136.00,   41.00,   42.00);
			data[52] = new GPOINT3(  139.00,   84.00,   77.00);
			data[53] = new GPOINT3(  136.00,  103.00,   94.00);
			data[54] = new GPOINT3(  148.00,  118.00,   67.00);

			for (i=0; i<npts; i++) 
			{
				//data[i] = new GPOINT3();
				//fscanf(fp,"%f%f%f\n",&data[i].x,&data[i].y,&data[i].z);
				data_limit.xmin = Math.Min(data_limit.xmin,data[i].x);
				data_limit.xmax = Math.Max(data_limit.xmax,data[i].x);
				data_limit.ymin = Math.Min(data_limit.ymin,data[i].y);
				data_limit.ymax = Math.Max(data_limit.ymax,data[i].y);
			}

						r.Close();

			/*  Create array of pointers for random grid */

			gridz = new double[NUMX,NUMY];

			/*  Enter GINO-C */

			Gino.OpenGino();

			/* Nominate the device */
			Gino.Mwinao(NUL,(int)hdc);

			Gino.EnqDrawingLimits(out paper,out ip);
			viewport.xmin=0.0;
			viewport.xmax=paper.xpap;
			viewport.ymin=0.0;
			viewport.ymax=paper.ypap;
			Gino.SetViewport2D(picture, viewport);
			Gino.NewDrawing();
			Gino.SetCharSize(7.5,7.5);
			Gino.EnqLineColour(out colour);

			/*  Generate gridded data from random data */

			Surf.OpenSurf();
			Surf.SetRandomPointMarker(DataPointAnnotation.GSYMBOLS,(int)GinoGraphics.Marker.GCROSS);
			Surf.GenerateRandomGrid(npts,data,data_limit,NUMX,NUMY,gridz,ref work);

      

			/*  Draw contour map with approx 8 contours */

			Surf.SetContourMapFrame(map_frame);
			Surf.SetSurfAxesAnnotation(SurfAxis.GALLAXES,5,1,0);
			Surf.SetContourAnnotation(0,250.0,5.0,5,1,0,(Colour)colour,0);
			Surf.SetContourMapLineStyles((LineStyle)colour,LineStyle.GORANGE,LineStyle.GGREEN,2);
			Surf.SetContourMapFrameScale(xinc,yinc,cinc,SurfAxesScaling.GEQUAL,Rounding.GEXACT);
			Surf.DrawGriddedContourMap(data_limit,NUMX,NUMY,gridz,NCONT,ContourSwitch.GSTRAIGHT,ref work);

			/*  Draw cross-section line on contour map and */
			/*  obtain ends of cross-section in picture coordinates */

			cross_sec[0] = new GPOINT(10.0,20.0);
			cross_sec[1] = new GPOINT(49.0,40.0);
			cross_sec[2] = new GPOINT(101.0,60.0);
			cross_sec[3] = new GPOINT(130.0,100.0);

			Gino.SetLineColour(Colour.GRED);
			Surf.AddContourPolyline(4,cross_sec);
			Gino.SetFontFillStyle(font_style);
			Gino.SetCharSize(15.0,15.0);
			for (i=0; i<4; i++) 
			{
				map_line[i] = new GPOINT();
				Surf.TransformMapCoord(cross_sec[i].x,cross_sec[i].y,out map_line[i]);
				Gino.MoveTo2D(map_line[i].x,map_line[i].y);
				Gino.SetLineColour((Colour)colour);
				Gino.DrawMarker(78033+i);
				Surf.ReturnContourSpotHeight(cross_sec[i].x,cross_sec[i].y,out height[i],ref work);
			}

			/*  Draw cross-section */

			Gino.SetCharSize(7.5,7.5);
			Surf.SetContourLimits(0.0,100.0);
			cross_frame.xmin=map_line[0].x;
			cross_frame.xmax=map_line[3].x;
			cross_frame.ymin=120.0;
			cross_frame.ymax=260.0;
			Surf.SetCrossSectionFrame(cross_frame);
			Surf.SetCrossSectionFrameType(0);
			Surf.DrawPolylineCrossSection(4,cross_sec,linestyle,ref work);

			/*  Draw symbols on cross section */

			Gino.SetLineColour((Colour)colour);
			Gino.SetCharSize(45.0,45.0);
			dist=0.0;
			for (i=0; i<4; i++) 
			{
				if(i > 0) 
				{
					dist=dist+Math.Sqrt((cross_sec[i].x-cross_sec[i-1].x)*(cross_sec[i].x-cross_sec[i-1].x) +
						(cross_sec[i].y-cross_sec[i-1].y)*(cross_sec[i].y-cross_sec[i-1].y));
				}
				Surf.TransformCrossSectionCoord(dist,height[i],out temp_pt);
				Gino.MoveTo2D(temp_pt.x,temp_pt.y+20.0);
				Gino.DrawMarker(72102);
			}

			/*  Draw frame and title */

			Gino.SetLineColour(Colour.GCYAN);
			Gino.FillRect((int)FillStyle.GHOLLOW,(int)G.GCURRENT,frame1);
			Gino.FillRect((int)FillStyle.GHOLLOW,(int)G.GCURRENT,frame2);
			Gino.MoveTo2D(305.0,20.0);
			Gino.SetCharSize(15.0,15.0);
			Gino.DisplayStr("GINOSURF Example Program 1");
			Gino.SetStrJustify(Justification.GCENTRE);
			Gino.MoveTo2D(500.0,700.0);
			Gino.DisplayStr("Pylon Clearance Terrain Profile ");

			/*  Close down GINOSURF, the device and GINO */

			Surf.CloseSurf();
//			Gino.SuspendDevice();
//			Gino.CloseGino();
			e.Graphics.ReleaseHdc(hdc);

			/*  Free up workspace */

			Surf.FreeWorkspace(ref work);

		}

		private void Form1_Resize(object sender, System.EventArgs e)
		{
			pictureBox1.Refresh();
		}

		private void pictureBox1_Resize(object sender, System.EventArgs e)
		{
		
		}

		
	}
}