
#include "gc_config.h"

//const float gc_cfg::MAX_AZI_SCA = (M_PI / 3);
//const float gc_cfg::MAX_ELE_SCA = (M_PI / 3);
//const float gc_cfg::MAX_HOR_LIN = ((2 * M_PI) / 9);

#ifdef GC_GEOMETRY_SMART

namespace gc_cfg
{
pixel_num_t SC_X_DIMENSION= gc_cfg_k::K_X_DIMENSION;
pixel_num_t SC_Y_DIMENSION= gc_cfg_k::K_Y_DIMENSION;

pixel_num_t SC_X_OFFSET= gc_cfg_k::K_X_MOVWIN_OFFSET;
pixel_num_t SC_Y_OFFSET= gc_cfg_k::K_Y_MOVWIN_OFFSET;

pixel_num_t SC_X_ZERO_PPI= gc_cfg_k::K_X_CENTRE_DISPL;
pixel_num_t SC_Y_ZERO_PPI= gc_cfg_k::K_Y_ZERO_RANGE;


// Symbols parameters:
// Azimuth Scale & Caret
pixel_num_t X_AZI_SCA= gc_cfg_k::K_X_CENTRE_DISPL;
pixel_num_t Y_AZI_CAR= 436;
pixel_num_t Y_AZI_SCA_LO= 445;
pixel_num_t Y_AZI_SCA_UP= 39;
pixel_num_t PIX_AZI_SCA= K_PIX_AZI_SCA; //gc_cfg_k::K_X_CENTRE_DISPL - 1;

// Degraded Performance Indicator
pixel_num_t X_DEGR= gc_cfg_k::K_X_CENTRE_DISPL;
pixel_num_t Y_DEGR= 400;

// Stand by label
pixel_num_t X_STBY= gc_cfg_k::K_X_CENTRE_DISPL;
pixel_num_t Y_STBY= 206; //GC_REL_CENTER_Y_POS(206);

// WarmUp Time Indicator
pixel_num_t X_WARM_UP= gc_cfg_k::K_X_CENTRE_DISPL;
pixel_num_t Y_WARM_UP= 382; //GC_REL_BOTTOM_Y_POS(382);

// Elevation Scale & Caret
pixel_num_t X_ELE_CAR= 44;
pixel_num_t X_ELE_SCA= 41;
pixel_num_t Y_ELE_SCA= gc_cfg_k::K_Y_CENTRE_DISPL;
pixel_num_t PIX_ELE_SCA= K_PIX_ELE_SCA; //gc_cfg_k::K_Y_CENTRE_DISPL; //Y_ELE_SCA;

// Frequency Band Indicator
pixel_num_t X_BAND_IND= 441;
pixel_num_t X_CHAN_NUM= 437;
pixel_num_t Y_BAND_IND= 17;
pixel_num_t Y_CHAN_NUM= 10;

// Horizon Line
//enum { HOR_BAR     = 100;
//enum { HOR_GAP     =  30 };
//enum { HOR_H       =  15 };
//enum { PIX_MIN_HOR =   0 };
pixel_num_t HOR_BAR=K_HOR_BAR;//     = 100 };
pixel_num_t HOR_GAP=K_HOR_GAP;//     =  30 };
pixel_num_t HOR_H=K_HOR_H;//       =  15 };
pixel_num_t PIX_MIN_HOR=K_PIX_MIN_HOR;// =   0 };

// Ownship Text Block
#define K_X_OWN_ALT 322
#define K_X_OWN_CAS 162
#define K_X_OWN_HEA 241
#define K_Y_OWN_BLO 409


pixel_num_t X_OWN_ALT= K_X_OWN_ALT;
pixel_num_t X_OWN_CAS= K_X_OWN_CAS;
pixel_num_t X_OWN_HEA= K_X_OWN_HEA;
pixel_num_t Y_OWN_BLO= K_Y_OWN_BLO;

// Range/Velocity Scale
#define K_X_RNG_SCA 467

pixel_num_t X_RNG_SCA= K_X_RNG_SCA;
pixel_num_t Y_RNG_SCA= gc_cfg_k::K_Y_CENTRE_DISPL; //Y_CENTRE_DISPL;

// Azimuth Scan Limits
#define K_Y_AZ_SCA_LIM 241
pixel_num_t Y_AZ_SCA_LIM = K_Y_AZ_SCA_LIM;

//Altitude Line Track Indicator
#define K_X_ALT_LINE 462

pixel_num_t X_ALT_LINE = K_X_ALT_LINE;

// Gray Scale
pixel_num_t X_GREY= gc_cfg_k::K_X_CENTRE_DISPL; //X_CENTRE_DISPL;
pixel_num_t Y_GREY= 150;

// Time to Go to HPT
#define K_X_TIMTOGO_HPT 76
#define K_Y_TIMTOGO_HPT 28
pixel_num_t X_TIMTOGO_HPT = K_X_TIMTOGO_HPT; //76
pixel_num_t Y_TIMTOGO_HPT = K_Y_TIMTOGO_HPT; //28

// Waveform Scheduling Indicator
#define K_X_WAVE_IND 426
#define K_Y_WAVE_IND 10
pixel_num_t X_WAVE_IND= K_X_WAVE_IND;
pixel_num_t Y_WAVE_IND= K_Y_WAVE_IND;

// MTR Settings Indicator
#define K_X_MTR_IND 84
#define K_Y_MTR_IND 28
pixel_num_t X_MTR_IND = K_X_MTR_IND; //84
pixel_num_t Y_MTR_IND = K_Y_MTR_IND; //28

// Jammer Direction Tick
//#define K_Y_JAM_CENT 67

//pixel_num_t Y_JAM_CENT = K_Y_JAM_CENT ;

// Time to Go to Cursor AS
#define K_X_TIMTOGO_CUR 331
#define K_Y_TIMTOGO_CUR 425
pixel_num_t X_TIMTOGO_CUR = K_X_TIMTOGO_CUR; //331
pixel_num_t Y_TIMTOGO_CUR = K_Y_TIMTOGO_CUR; //425

// A/S HR Suitability cues
#define K_Y_HR_SUIT_CUES  470
pixel_num_t Y_HR_SUIT_CUES = K_Y_HR_SUIT_CUES;

// HPT Data Block
#define K_X_HPT_BLO 426
#define K_Y_HPT_GRTR 391
#define K_Y_HPT_CAS 409
#define K_Y_HPT_ASP 427
pixel_num_t X_HPT_BLO = K_X_HPT_BLO; //426
pixel_num_t Y_HPT_GRTR = K_Y_HPT_GRTR; //391
pixel_num_t Y_HPT_CAS = K_Y_HPT_CAS; //409
pixel_num_t Y_HPT_ASP = K_Y_HPT_ASP; //427

// A/S Tracked Target Data Block
#define K_X_STT_BLO 369
#define K_Y_STT_HEA 389
#define K_Y_STT_GRSP 407
pixel_num_t X_STT_BLO = K_X_STT_BLO; // 369
pixel_num_t Y_STT_HEA = K_Y_STT_HEA; // 389
pixel_num_t Y_STT_GRSP = K_Y_STT_GRSP; // 407

// A/S HR Patch Size Indicator
#define K_X_HR_PTCH_SIND 456
#define K_Y_HR_PTCH_SIND 40

pixel_num_t X_HR_PTCH_SIND = K_X_HR_PTCH_SIND;
pixel_num_t Y_HR_PTCH_SIND = K_Y_HR_PTCH_SIND;

// HR Time to Image
#define K_X_HR_TTIMG 360
#define K_Y_HR_TTIMG 41
pixel_num_t X_HR_TTIMG = K_X_HR_TTIMG;
pixel_num_t Y_HR_TTIMG = K_Y_HR_TTIMG;

// A/S HR Cursor Lat Lon
#define K_X_HR_CURS_LATLON 30
#define K_Y_HR_CURS_LATLON 370
pixel_num_t X_HR_CURS_LATLON = K_X_HR_CURS_LATLON;
pixel_num_t Y_HR_CURS_LATLON = K_Y_HR_CURS_LATLON;

float rescale_factor_=1;

} /*namespace gc_cfg*/

using namespace gc_cfg;

#define XY_REFERENCE	gc_cfg_k::K_XY_REFERENCE_DIMENSION

#define XY_RESCALE_THRESHOLD	400
#define CENTER_REFERENCE	(XY_REFERENCE/2)

static int y_gravity_bottom(int x, float rescale=1)
{
	int delta=(XY_REFERENCE-x);
	if (rescale<1)
		delta=delta*rescale;

	return gc_cfg::XY_LOGICAL_DISPLAY_DIMENSION-delta;
}

static int y_gravity_top(int x, float rescale=1)
{
	int delta=(x);
	if (rescale<1)
		delta=delta*rescale;

	return delta;
}

static int y_gravity_center(int x, float rescale=1)
{
	int delta=(x);
	if (rescale<1)
		delta=delta*rescale;

	return gc_cfg::X_CENTRE_DISPL-(CENTER_REFERENCE-delta);
}

static int x_gravity_right(int x, float rescale=1)
{
	int delta=(XY_REFERENCE-x);
	if (rescale<1)
		delta=delta*rescale;

	return gc_cfg::XY_LOGICAL_DISPLAY_DIMENSION-delta;
}

static int x_gravity_left(int x, float rescale=1)
{
	int delta=(x);
	if (rescale<1)
		delta=delta*rescale;

	return delta;
}

static int len_rescale(int x, int min, float rescale=1)
{
	if (rescale<1)
		x=x*rescale;
	if (x<min)
		x=min;
	return x;
}

int gc_cfg::rescale_dimension(int x)
{
	return (float(x)*gc_cfg::rescale_factor_)+0.5;
}

void gc_config_geometry_resize(int /*phy_dx*/, int /*phy_dy*/, int rdr_dxy, int /*x_offset*/, int /*y_offset*/)
	//phy and offset not used - always position on the top-left corner and calculate the best phy based on rdr dxy
{
	SC_X_DIMENSION= gc_cfg::X_DIMENSION;
	SC_Y_DIMENSION= gc_cfg::Y_DIMENSION;

	SC_X_OFFSET= gc_cfg::X_MOVWIN_OFFSET;
	SC_Y_OFFSET= gc_cfg::Y_MOVWIN_OFFSET;

	SC_X_ZERO_PPI= gc_cfg::X_CENTRE_DISPL;
	SC_Y_ZERO_PPI= gc_cfg::Y_ZERO_RANGE;


	float rescale=(rdr_dxy<XY_RESCALE_THRESHOLD) ? (rdr_dxy/float(XY_REFERENCE)) : 1;

	gc_cfg::rescale_factor_=(rdr_dxy/float(XY_REFERENCE));

	// Symbols parameters:
	// Azimuth Scale & Caret
	X_AZI_SCA= gc_cfg::X_CENTRE_DISPL;
	Y_AZI_CAR= y_gravity_bottom(436, rescale);
	Y_AZI_SCA_LO= y_gravity_bottom(445, rescale);
	Y_AZI_SCA_UP= 39;
	PIX_AZI_SCA= gc_cfg::X_CENTRE_DISPL - 1;
	Y_AZ_SCA_LIM = y_gravity_bottom(K_Y_AZ_SCA_LIM);

	// Degraded Performance Indicator
	X_DEGR= gc_cfg::X_CENTRE_DISPL;
	Y_DEGR= y_gravity_center(400);

	// Stand by label
	X_STBY= gc_cfg::X_CENTRE_DISPL;
	Y_STBY= y_gravity_center(206); //GC_REL_CENTER_Y_POS(206);

	// WarmUp Time Indicator
	X_WARM_UP= gc_cfg::X_CENTRE_DISPL;
	Y_WARM_UP= y_gravity_center(382); //GC_REL_BOTTOM_Y_POS(382);

	// Elevation Scale & Caret
	X_ELE_CAR= len_rescale(44, 4, rescale);
	X_ELE_SCA= len_rescale(41, 4, rescale);
	Y_ELE_SCA= gc_cfg::Y_CENTRE_DISPL;
	PIX_ELE_SCA= gc_cfg::Y_CENTRE_DISPL; //Y_ELE_SCA;

	// Frequency Band Indicator
	X_BAND_IND= x_gravity_right(441);
	X_CHAN_NUM= x_gravity_right(437);
	Y_BAND_IND= y_gravity_top(17);
	Y_CHAN_NUM= y_gravity_top(10);

	// Waveform Scheduling Indicator
	X_WAVE_IND= x_gravity_right(K_X_WAVE_IND);
	Y_WAVE_IND= y_gravity_top(K_Y_WAVE_IND);

	// Horizon Line
	//enum { HOR_BAR     = 100;
	//enum { HOR_GAP     =  30 };
	//enum { HOR_H       =  15 };
	//enum { PIX_MIN_HOR =   0 };
	HOR_BAR=len_rescale(K_HOR_BAR, 15, rescale);//     = 100 };
	HOR_GAP=len_rescale(K_HOR_GAP, 6, rescale);//     =  30 };
	HOR_H=len_rescale(K_HOR_H, 3, rescale);//       =  15 };
	//PIX_MIN_HOR=len_rescale(K_PIX_MIN_HOR, rescale);// =   0 };

	// Ownship Text Block
	X_OWN_ALT= gc_cfg::rescale_dimension(K_X_OWN_ALT);;
	X_OWN_CAS= gc_cfg::rescale_dimension(K_X_OWN_CAS);;
//	X_OWN_HEA= 241;
	X_OWN_HEA= gc_cfg::rescale_dimension(K_X_OWN_HEA);
//	Y_OWN_BLO= 409;
	Y_OWN_BLO= y_gravity_bottom(K_Y_OWN_BLO);

	// Range/Velocity Scale
//	X_RNG_SCA= 467;
	X_RNG_SCA= x_gravity_right(K_X_RNG_SCA);
	Y_RNG_SCA= gc_cfg::Y_CENTRE_DISPL; //Y_CENTRE_DISPL;

	//Altitude Line Track Indicator
	X_ALT_LINE = x_gravity_right(K_X_ALT_LINE);

	// Gray Scale
//	X_GREY= gc_cfg::Y_CENTRE_DISPL; //X_CENTRE_DISPL;
//	Y_GREY= 150;

//	// Jammer Direction Tick
//	Y_JAM_CENT = y_gravity_bottom(K_Y_JAM_CENT) ;

	// A/S HR Suitability cues
	Y_HR_SUIT_CUES = y_gravity_bottom(K_Y_HR_SUIT_CUES);

	// A/S HR Patch Size Indicator
	X_HR_PTCH_SIND = x_gravity_right(K_X_HR_PTCH_SIND);
	Y_HR_PTCH_SIND = y_gravity_top(K_Y_HR_PTCH_SIND);

	// HR Time to Image
	X_HR_TTIMG = x_gravity_right(K_X_HR_TTIMG);
	Y_HR_TTIMG = y_gravity_top(K_Y_HR_TTIMG);

	// A/S HR Cursor Lat Lon
	X_HR_CURS_LATLON = x_gravity_left(K_X_HR_CURS_LATLON);
	Y_HR_CURS_LATLON = y_gravity_bottom(K_Y_HR_CURS_LATLON);

	// Gray Scale
	X_GREY= gc_cfg_k::K_X_CENTRE_DISPL; //X_CENTRE_DISPL;
	Y_GREY= y_gravity_center(150);

	// Degraded Performance Indicator
//	X_DEGR= gc_cfg_k::K_X_CENTRE_DISPL;
//	Y_DEGR= y_gravity_center(400);

	// A/S Tracked Target Data Block
//	//TODO: continuare Target Data Block...
	X_STT_BLO = x_gravity_right(K_X_STT_BLO); // 369
	Y_STT_HEA = y_gravity_bottom(K_Y_STT_HEA); // 389
	Y_STT_GRSP = y_gravity_bottom(K_Y_STT_GRSP); // 407


	// HPT Data Block
	X_HPT_BLO = x_gravity_right(K_X_HPT_BLO);
	Y_HPT_GRTR = y_gravity_bottom(K_Y_HPT_GRTR);
	Y_HPT_CAS = y_gravity_bottom(K_Y_HPT_CAS);
	Y_HPT_ASP = y_gravity_bottom(K_Y_HPT_ASP);


	// Time to Go to HPT
	X_TIMTOGO_HPT = x_gravity_left(K_X_TIMTOGO_HPT);
	Y_TIMTOGO_HPT = y_gravity_top(K_Y_TIMTOGO_HPT);

	// MTR Settings Indicator
	X_MTR_IND = x_gravity_left(K_X_MTR_IND);
	Y_MTR_IND = y_gravity_top(K_Y_MTR_IND);

	// Time to Go to Cursor AS
	X_TIMTOGO_CUR = x_gravity_right(K_X_TIMTOGO_CUR);
	Y_TIMTOGO_CUR = y_gravity_bottom(K_Y_TIMTOGO_CUR);

}

#endif
