// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 

// Copyright Liam Girdwood 2003

#ifndef _SKY_PROJ_HH
#define _SKY_PROJ_HH

#include <libgnomecanvasmm/canvas.h>
#include <libgnomecanvasmm/group.h>
#include <libgnomecanvasmm/rect.h>
#include <vector>
#include "catalog.hh"
#include "grid.hh"
#include "constellation.hh"
#include "mercury.hh"
#include "venus.hh"
#include "mars.hh"
#include "jupiter.hh"
#include "saturn.hh"
#include "uranus.hh"
#include "neptune.hh"
#include "pluto.hh"

#define MAX_RA		360.0
#define MIN_RA		0.0
#define MAX_DEC		90.0
#define MIN_DEC		-90.0
#define MIN_FOV		0.1
#define MAX_FOV		180.0

#define MAG_BASE	4.0

#define MAG_CONST 0.01
#define BRIGHT_DIFF	1.0

#define OBJECT_GROUPS 25

/*! \namespace Vega
* \brief Nova Virtual Sky Engine
*/
namespace Vega
{

/*! \class SkyProj
* Sky projection base class.
*
* All sky projections are derived from this class.
*/
class SkyProj : public Gnome::Canvas::CanvasAA
{
	public:
		SkyProj();
		~SkyProj();
	
		/*! \enum Render Projection render type
		*/
		enum Render {
			FULL = 0, 	/*!< Render everything */
			BRIGHT,		/*!< Render only the bright objects */
			FAINT		/*!< Render only the faint/misc objects */
		};
			
		/*! \fn void show_sky();
		* \brief show the sky projection 
		*/
		void show_sky();
	
		/*! \fn render_sky(Render type);
		* \brief render the current sky projection  
		*/
		void render_sky(Render type);
	
		/*! \fn void move_ra (double pixels
		* \brief move sky centre ra
		*/
		void move_ra (double pixels);
	
		/*! \fn void move_ra (double pixels)
		* \brief move sky centre dec
		*/
		void move_dec (double pixels);
	
		/*! \fn double get_ra ();
		* \brief get sky centre ra
		*/
		double get_ra ();
	
		/*! \fn double get_dec ();
		* \brief get sky centre dec
		*/
		double get_dec ();
		
		/*! \fn double get_fov ();
		* \brief get sky field of view
		*/
		double get_fov ();
		
		/*! \fn double get_jd ();
		* \brief get sky JD
		*/
		double get_jd ();
		
		/*! \fn void set_jd (double jd);
		* \brief set sky JD
		*/
		void set_jd (double jd);
		
		/*! \fn void set_ra (double ra);
		* \brief set sky centre ra
		*/
		void set_ra (double ra);
	
		/*! \fn void set_dec (double dec);
		* \brief set sky centre dec
		*/
		void set_dec (double dec);
		
		/*! \fn void set_fov (double fov);
		* \brief set sky field of view
		*/
		void set_fov (double fov);
		
		/*! \fn virtual void get_position (double x, double y, double& ra, double& dec) = 0;
		* \brief get sky ra,dec at x,y projection coordinates
		*/
		virtual void get_position (double x, double y, double& ra, double& dec) = 0;
	
		/*! \fn bool zoom (double zoom);
		* \brief zoom sky in/out
		*/
		bool zoom (double zoom);

		/*! \fn void set_size(int width, int height);
		* \brief Set sky projection size
		*/
		void set_size(int width, int height);
	
		/*! \fn void add_bright_catalog(Pollux::Catalog* cat);
		* Add bright object catalog
		*/
		void add_bright_catalog(Pollux::Catalog* cat);
		
		/*! \fn void show_grid(bool show);
		* \brief Show sky grid
		*/
		void show_grid(bool show);
		
		/*! \fn void show_const_lines(bool show);
		* \brief Show constellation outlines
		*/
		void show_const_lines(bool show);
		
		/*! \fn void show_const_names(bool show);
		* \brief Show constellation outlines
		*/
		void show_const_names(bool show);
		
		/*! \fn void show_const_bounds(bool show);
		* \brief Show constellation boundaries
		*/
		void show_const_bounds(bool show);
		
		/*! \fn bool is_grid();
		* \brief Is sky grid shown
		*/
		bool is_grid();
		
		/*! \fn bool show_const_lines();
		* \brief Are constellation outlines shown
		*/
		bool is_const_lines();
		
		/*! \fn bool is_const_names();
		* \brief Are constellation outlines shown
		*/
		bool is_const_names();
		
		/*! \fn bool is_const_bounds();
		* \brief Are constellation boundaries shown
		*/
		bool is_const_bounds();
		
		
		void clone (SkyProj* proj);
		
	protected:
		
		/*! \fn virtual void render_basic() = 0;
		* Render the basic/compulsary sky objects
		*/
		virtual void render_basic() = 0;
	
		/*! \fn virtual void render_grid() = 0;
		* Draw sky grid
		*/
		virtual void render_grid() = 0;
	
		/*! \fn virtual void render_const_lines() = 0;
		* Draw constellation lines
		*/
		virtual void render_const_lines() = 0;
	
		/*! \fn virtual void render_const_bounds() = 0;
		* Draw Constellation boundaries
		*/	
		virtual void render_const_bounds() = 0;
		
		/*! \fn virtual void render_const_names() = 0;
		* Display Constellation Names
		*/	
		virtual void render_const_names() = 0;
	
		/*! \fn void render_bright_objects(Render type);
		* Draw Bright objects < mag 4
		*/
		void render_bright_objects(Render type);
		
		/*! \fn void render_background();
		* Draw sky background
		*/
		void render_background();
		
		/*! \fn void render_remaining_objects();
		* Draw Bright objects > mag 4
		*/
		void render_remaining_objects();
		
		/*! \fn virtual bool is_visible(double x, double y) = 0;
		* Is the object visible ?
		*/
		virtual bool is_visible(double x, double y) = 0;
	
		virtual void render_planets() = 0;
		
		// Field of View
		double m_centre_ra;		/*!< FOV centre RA */
		double m_centre_dec;	/*!< FOV centre DEC */
		double m_fov;			/*!< FOV size in degrees */
	
		// Canvas sizes
		double m_canvas_width;	/*!< Drawing area x size */
		double m_canvas_height;	/*!< Drawing area y size */
		double m_canvas_ratio; 	/*!< Ratio of x to y */
	
		// Virtual Sky clipping box
		double m_clip_ra_min;		/*!< Minimum RA */
		double m_clip_ra_max;		/*!< Maximum RA */
		double m_clip_dec_min;		/*!< Minimum DEC */
		double m_clip_dec_max;		/*!< Maximum DEC */
		double m_clip_ra_min_overlap;	/*!< Minimum RA */
		double m_clip_ra_max_overlap;	/*!< Maximum RA */
		double m_clip_dec_min_overlap;	/*!< Minimum DEC */
		double m_clip_dec_max_overlap;	/*!< Maximum DEC */
		double m_clip_mag_min;	/*!< Minimum mag */
		double m_clip_mag_max;	/*!< Maximum mag */
		
		// sky position
		double m_clip_centre_ra;		/*!< Sky centre RA */
		double m_clip_centre_dec;		/*!< Sky centre DEC */
		
		// sky scale
		double m_ra_ppd;		/*!< RA pixels per degree */
		double m_dec_ppd;		/*!< DEC pixels per degree */
		
		// sky overlap offsets
		bool m_is_ra_over;		/*!< RA Sky coordinates overlap */
		bool m_is_ra_under;		/*!< DEC Sky coordinates overlap */
		double m_ra_offset;		/*!< Overlap RA offset */
		double m_dec_offset;	/*!< Overlap DEC offset */
	 
	 	// sky artifacts
	 	bool m_show_const_lines;	/*!< Show constellation lines */
		bool m_show_const_bounds;	/*!< Show constellation boundaries */
		bool m_show_const_names;	/*!< Show constellation names */
		bool m_show_planets;        /*!< Show planets */
		bool m_show_grid;			/*!< Show grid */
		bool m_spherical;			/*!< Render spherical sky view */
		double m_JD;				/*!< JD of projection */
		
		// planets
		Castor::Mercury m_mercury; 	/*!< The planet Mercury */
		Castor::Venus m_venus; 	/*!< The planet Venus */
		Castor::Mars m_mars; 	/*!< The planet Mars */
		Castor::Jupiter m_jupiter; 	/*!< The planet Jupiter */
		Castor::Saturn m_saturn; 	/*!< The planet Saturn */
		Castor::Uranus m_uranus; 	/*!< The planet Uranus */
		Castor::Neptune m_neptune; 	/*!< The planet Neptune */
		Castor::Pluto m_pluto; 		/*!< The planet Pluto */
		
		/*! \fn void calc_fov_bounds()
		* \brief Calculate the ra,dec bounds and field of view
		*/
		void calc_fov_bounds();
	
		/*! \fn virtual void transform(double& x, double& y, double ra_offset) = 0;
		* \brief transform an objects real coordinates to projection coordinates
		*/
		virtual void transform(double& x, double& y, double ra_offset) = 0;
		
		/*! \fn double calc_size (Castor::AstroObject* object);
		* \brief calculate object canvas size based on mag and fov
		*/
		double calc_size (Castor::AstroObject* object);
		
		/*! \fn void render_main_sector(Render type);
		* \brief Render objects in main sector.
		*/
		void render_main_sector(Render type);
		
		/*! \fn void render_overlap_sector(Render type);
		* \brief Render objects in overlap sector.
		*/
		void render_overlap_sector(Render type);
		
		// Catalogs
		Pollux::Catalog* m_bright_cat;
		
		// grid and constellation
		Grid m_grid;						/*!< Virtual sky grid */
		Constellation m_constellation;		/*!< Virtual sky constellations */
		
		// VSky Canvas objects
		Gnome::Canvas::Group* m_root;			/*!< Root group */
		Gnome::Canvas::Group* m_object_group;	/*!< Astro Objects */
		Gnome::Canvas::Group* m_bg_group;		/*!< Projection Background Grp */
		Gnome::Canvas::Group* m_grid_group;		/*!< Projection Grid Grp */
		Gnome::Canvas::Group* m_const_group;	/*!< Projection Constellation Grp */
		Gnome::Canvas::Rect* m_bg_rect;			/*!< Background Rectangle */
	
	private:
		/*! \fn calc_ra_overlap()
		* \brief calculate the RA overlap size and clipping area.
		*/
		void calc_ra_overlap();	
};

};

#endif


syntax highlighted by Code2HTML, v. 0.9.1