
#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;


//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_Y_CENTRE_DISPL; //X_CENTRE_DISPL;
pixel_num_t Y_GREY= 150;

#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;


float rescale_factor_=1;

} /*namespace gc_cfg*/

using namespace gc_cfg;

#define XY_REFERENCE	484
#define XY_RESCALE_THRESHOLD	400
#define CENTER_REFERENCE	(484/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 pyh_dx, int phy_dy, int rdr_dxy, int x_offset, int y_offset)
{
	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;

	// Degraded Performance Indicator
	X_DEGR= gc_cfg::X_CENTRE_DISPL;
	Y_DEGR= y_gravity_bottom(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= 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);

	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;
}

#endif
