using System;
using System.Configuration;
using System.Drawing;
using System.ComponentModel;        
using System.Reflection;


namespace Geom
{
	/// <summary>
	/// The SdssConstants class holds all constants related to SDSS.
	/// </summary>

	public class SdssConstants
	{

		/// <summary>
		/// Revision from CVS
		/// </summary>
		public static string Revision
		{
			get 
			{
				return "$Revision: 1.1.1.1 $";
			}
		}

		public enum Release
		{
			[Description("DR?")]  DR	= -1,
			[Description("EDR")]  EDR	=  0,
			[Description("DR1")]  DR1	=  1, 
			[Description("DR2")]  DR2	=  2, 
			[Description("DR3")]  DR3	=  3, 
			[Description("DR4")]  DR4	=  4,			
			[Description("DR5")]  DR5	=  5			
		}

		private static string    _DataRelease = "";

		
		private static float	_FrameWidth		= 2048.0F;							// pixel
		private static float	_FrameHeight	= 1489.0F;							// pixel
		private static double	_FrameHalfDiag	= 8.4F;								// arcMinute

		//private static float	_ClipX			= 32.0F;							// clip from the edge for DR1
		
		private static float	_ClipXLeft		= 24.0F;							// clip from the left edge for DR2 and higher releases
		private static float	_ClipXRight		= 40.0F;							// clip from the left edge (patch for DR2)
	
		private static float	_ClipY			= 64.0F;							// clip from the edge
		private static int		_PixelsPerDegree	= 9088;						    // pixel
		private static double	_PixelsPerArcMin	= _PixelsPerDegree /60.0;		// 151.466667 = 9088 pixels per degree
		private static double	_plateRadiusArcMin	= 89.4;							// arcMinute
		private static double	_plateRadiusDeg		= 1.49;							// degrees

		private static byte		_sflag		= 1;									//  specObject
		private static byte		_pflag		= 2;									//  photoObject
		private static byte		_tflag		= 4;									//  targetObject
		private static byte		_mflag		= 8;									//  maskObject
		private static byte		_plateflag	= 16;									//	plateObject

		// Add the various survey names to this array to
		// check if its an SDSS Survey type
		private static string[] surveys = {"BESTDR4","BESTDR3","BESTDR2", "BESTDR1","MyBestDR4", "MyBestDR3", "MyBestDR2", "MyBestDR1", "BESTDR4_EFG", "BESTDR3_EFG"};
		
		public SdssConstants()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// This method is used to determine if the survey is an SDSS Survey or a 
		/// non-SDSS survey
		/// </summary>
		/// <param name="surveyName">name of the survey from the web.config file</param>
		/// <returns>true it is an SDSS survey, false otherwise </returns>
		public static bool isSDSSSurvey (string surveyName)
		{
			foreach  (string name in  surveys)
			{
				if (name.CompareTo (surveyName) == 0)
					return true;
			}            

			return false;
		}

		public static void setRelease (string releaseNo)
		{
			_DataRelease = ConfigurationSettings.AppSettings["DataRelease"].ToUpper();
		}

		public static Release eDataRelease
		{
			get 
			{
				if (sDataRelease.IndexOf("EDR")!= -1) return Release.EDR;
				if (sDataRelease.IndexOf("DR1")!= -1) return Release.DR1;
				if (sDataRelease.IndexOf("DR2")!= -1) return Release.DR2;
				if (sDataRelease.IndexOf("DR3")!= -1) return Release.DR3;
				if (sDataRelease.IndexOf("DR4")!= -1) return Release.DR4;
				if (sDataRelease.IndexOf("DR5")!= -1) return Release.DR5;

				return Release.DR;
			}
		}


		public static string sDataRelease
		{
			get 
			{
				return _DataRelease;
			}
		}

		public static float FrameWidth
		{
			get 
			{
				return _FrameWidth;
			}
		}

		public static float FrameHeight
		{
			get 
			{
				return _FrameHeight;
			}
		}

		public static double FrameHalfDiag
		{
			get 
			{
				return _FrameHalfDiag;
			}
		}


	
		public static float ClipXRight
		{
			get 
			{
				return _ClipXRight;
			}
		}
		public static float ClipXLeft
		{
			get 
			{
				return _ClipXLeft;
			}
		}

		public static float ClipX
		{
			get 
			{
				
				if (eDataRelease == Release.DR1) 
				{			
					return 32.0F;
				}
				else //For DR2 we don't use ClipX only ClipXLeft and ClipXRight
				{
					return 24.0F;
				}
			}
		}


		public static float ClipY
		{
			get 
			{
				return _ClipY;
			}
		}

		public static int PixelsPerDegree
		{
			get 
			{
				return  _PixelsPerDegree;
			}
		}
		
		public static double PixelsPerArcMin
		{
			get 
			{
				return _PixelsPerArcMin;
			}
		}
		
		public static double plateRadiusArcMin
		{
			get 
			{
				return _plateRadiusArcMin;
			}
		}

		public static double plateRadiusDeg
		{

			get 
			{
				return _plateRadiusDeg;
			}
		}

		public static byte sflag 
		{
			get 
			{
				return _sflag;
			}
		}

		public static byte pflag 
		{
			get 
			{
				return _pflag;
			}
		}

		public static byte tflag 
		{
			get
			{
				return _tflag ;
			}
		}
		
		public static byte mflag
		{
			get
			{
				return _mflag;		
			}
		}

		public static byte plateflag 
		{
			get 
			{
				return _plateflag;
			}
		}
	

		/// <summary>
		/// FieldGeometry. Returns the four corners of the field in unscaled pixel 
		/// coordinates with optional clipping
		///  </summary>
		public static PointF[]	FieldGeometry(bool clip)
		{
			float fX1, fX2;
			float fY1, fY2;

			// compute the pixel coordinates of corners with optional clipping
			int clipit	= (clip?1:0);
						
			// Patch for DR2			
			if ((eDataRelease == Release.DR2) || (eDataRelease == Release.DR3) || (eDataRelease == Release.DR4)|| (eDataRelease == Release.DR5))
			{				
				fX1	= (float) (ClipXLeft * clipit);				
				fX2	= (float) (FrameWidth  - ClipXRight * clipit);				
			} 
			else 
			{
				fX1	= (float) (ClipX * clipit);
				fX2	= (float) (FrameWidth  - ClipX * clipit);				
			}
			
			fY1	= (float) (ClipY * clipit);
			fY2	= (float) (FrameHeight - ClipY * clipit);

			// create array for the four corners
			PointF[] p = new PointF[4];

			p[0] = new PointF(fX1, fY1);
			p[1] = new PointF(fX2, fY1);
			p[2] = new PointF(fX2, fY2);
			p[3] = new PointF(fX1, fY2);

			return p;
		}


	}	
}
/* Revision History

        $Log: SDSSConstants.cs,v $
        Revision 1.1.1.1  2006/11/14 02:56:46  gupchup
        no message

        Revision 1.1.1.1  2006/04/25 16:07:23  gupchup
        Code base that merges original imgcutout code and WCS frame format imgcutout code

        Revision 1.6  2005/02/24 21:32:35  nieto
        Changed to show correct DR3 label (repeats DR2Patch for DR3)

        Revision 1.5  2004/02/23 14:07:36  nieto
        Major changes in order to:

        	- Improve Message/Exception errors.
        	- Added a new Web Method that accepts query to mark objects:
        		SQL query
        		List of objects
        		Mark String like SR(10, 30) Stars with magnitude
        				 between 10 and 30 in the R band

        Revision 1.3  2003/04/08 17:12:00  nieto
        Trying to include projection.cs class in project

        Revision 1.2  2003/03/19 18:49:55  nieto
        more clean up

*/