/* **********************************************************************
 * *                                                                    *
 * *                   IRIS Real Time Display                           *
 * *                                                                    *
 * **********************************************************************
 * File: utils/rtdisp/rtdisp.h
 *
 *       COPYRIGHT (c) 1996, 1997, 1998, 2000, 2001, 2002, 2003 BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 *
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

#define SIGMET_RTDISP_H

#ifdef RTDISP_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

#define RNG_RING_OFF     1
#define RNG_RING_ON      2
#define RNG_RING_NUMS    3
#define RNG_RING_LAT_LON 4

#define DA_MEDIUM_HGT       694 
#define DA_MEDIUM_WID       694
#define DA_MEDIUM_WID_RHI   940 
#define DA_LARGE_HGT        940
#define DA_LARGE_WID        940
#define DA_LARGE_WID_RHI   1150
#define DA_XLARGE_HGT      1150 
#define DA_XLARGE_WID      1150 
#define DA_XLARGE_WID_RHI  1350 
#define RTD_WID_OFFSET  236
#define RTD_HGT_OFFSET  43

#define TEXT_COLOR_WHITE   0
#define TEXT_COLOR_GREEN   1
#define TEXT_COLOR_RED     2

#define MAX_NUM_SITES     5

#define SITE_STATUS_OK      1
#define SITE_STATUS_IDLE    2
#define SITE_STATUS_FAULT   3

/*****************************************
** Global Legacy Variables
** Set these variables in rtdisp.C
****************************************/
EXTERN Widget       UxTopLevel;
EXTERN Display      *UxDisplay;
EXTERN int          UxScreen;
EXTERN XtAppContext UxAppContext;

/****************************************
** Globlal User Created Variables
** Set these variables in rtdisp.C
****************************************/
EXTERN Display      *applDisplay;
EXTERN int          applScreen;
EXTERN XtAppContext appContext;

/*******************************************************
**
** Variables
**
************************************************/
EXTERN XImage   *rtdImage_c;
EXTERN GC       gc_c;
EXTERN Window   rtdDrawArea_win;
EXTERN Colormap Colormap_c;
EXTERN XVisualInfo VisualInfo_c;
EXTERN UINT4 iStandardVtvMapClient_c[256];  /* Client side mapping table */
EXTERN  struct iris_setup  iris_c;
EXTERN  struct color_setup color_c;
/* The standard IRIS colormap.  Actual colormap in use will be
 * different for higher colors.
 */
EXTERN  struct color_def StandardColormap_c[256]; 

EXTERN  struct overlay_inventory8 *pOverlay_c;
EXTERN SINT4  iOverlaySize_c, iOverlayId_c;

#ifdef SIGMET_SIG_RTDISP_H
struct SiteInfo
{
   struct rtd_v1_vol_header header;
   UINT4  iTimeCnt;
   UINT2  lAlloced;
   UINT2  iStatus;
};
#endif  /* #ifdef SIGMET_SIG_RTDISP_H */


struct color_scale_mod_def
{
  struct color_scale_def       current; 
  UINT2  uniform_icolcnt;
  UINT2  uniform_iset_number;
  UINT4  cust_scale_idx;
};

#ifdef SIGMET_MISC_LIB_H
#ifdef SIGMET_TVSUBS_LIB_H
#ifdef SIGMET_SIG_RTDISP_H

struct SavedSharedData
{
  char   sVersion[8];
  char   sSelectedSiteName3[4];          // 3-char site name, null terminated
  UINT4  iRngUnits;
  UINT4  overlayLayerMask;
  UINT4  overlayRngRings;
  char   overlayName[30];
  UINT2  iRangeOptMenuPos;
  UINT4  iDataType;
  UINT4  iDrawAreaWidth;
  UINT4  iDrawAreaHeight;
  UINT4  iPortNum;
  UINT4  iRngVals[2][4];                 // rng idx 0 == km, idx 1 == naut mi
  UINT4  iTextColorIdx;
  struct latlon8 Old_latlon;
  struct rtray_config config;
  struct color_scale_mod_def refl;
  struct color_scale_mod_def velocity;
  struct color_scale_mod_def width;
};


struct SharedDataStruct 
{
  struct SavedSharedData saved;
  UINT1  rtdImageBuffer[4*DA_XLARGE_HGT*DA_XLARGE_WID_RHI]; // 4bytes/pixel max
  UINT2  lReceivingData;
  BIN2   iAzimuth;
  BIN2   iElevation;
  UINT2  lDataParamChanged; 
  UINT2  lImageSizeChanged;             /*  */
  UINT2  lOverlayChanged;               /* Major overlay change, blank screen */
  UINT2  lOverlayMoved;                 /* Overlay has moved a little, do not blank*/
  UINT2  lVelUnChanged; 
  UINT2  lPortChanged; 
  FLT4   fVelUn[2];                     
  char   colScaleLeftLab[16][8];
  char   colScaleRightLab[16][8];
  UINT4  colScalePixVal[2][16];
  union  level_control dataToVTVMap;
  struct ymds_time ymdsTime;
  struct rtd_v1_vol_header header;          
  struct SiteInfo site[MAX_NUM_SITES];
};

//EXTERN volatile struct SharedDataStruct *pSharedData;
EXTERN struct SharedDataStruct *pSharedData;
#endif  /* #ifdef SIGMET_SIG_RTDISP_H */
#endif  /* #ifdef SIGMET_XSIG_LIB_H */
#endif  /* #ifdef SIGMET_MISC_LIB_H */

EXTERN SINT4    iSharedDataSize;
EXTERN SINT4    ishid_c;
EXTERN int      childPid;

////////////////////////////////////////////////////
// 
// Classes
// 
///////////////////////////////////////////////////

class RtdAS
{
  private :
  public :
  void initRTD(void);
  void refreshImage(void);
  void setSiteName3TxtF(char *site_id);
  void setRngValsOM(void);
  void setColorScaleAndLabels(void);
};
EXTERN RtdAS rtdAS;

class Color 
{
  private :
  public :
  void create(Widget parent_wgt);
  void popup(void);
  void popdown(void);
};
EXTERN Color color;

class Overlay 
{
  private :
  public :
  void create(Widget parent_wgt);
  void popup(void);
  void popdown(void);
};
EXTERN Overlay overlay;

class Rng 
{
  private :
  public :
  void create(Widget parent_wgt);
  void popup(void);
  void popdown(void);
};
EXTERN Rng rng;

class SiteStat 
{
  private :
  public :
  void create(Widget parent_wgt);
  void popup(void);
  void popdown(void);
  void updateSiteList(void);
};
EXTERN SiteStat siteStat;

class Zr 
{
  private :
  public :
  void create(Widget parent_wgt);
  void popup(void);
  void popdown(void);

};
EXTERN Zr zr;

class RhiOpt 
{
  private :
  public :
  void create(Widget parent_wgt);
  void popup(void);
  void popdown(void);

};
EXTERN RhiOpt rhiOpt;


/*******************************************************
**
** Prototypes
**
************************************************/
/*************************************************
** rtdinsert 
*************************************************/
void setupMemColormap(void);
void forkInsertProcess(void);

/*************************************************
** rtdfunc
*************************************************/
class RtdFunc
{
  private :
  MESSAGE openConfFile( volatile const char *sfilename_a,
    volatile struct SharedDataStruct *pSharedData_a );
  MESSAGE saveConfFile( volatile const char *sfilename_a,
    volatile const struct SharedDataStruct *pSharedData_a );
  public :
  /* rtdAS.C */
  void  makeAsciiFiles(void);
  SINT2 openFile(const char *filename);
  void  saveAsFile(char *filename);
  void  levelizeColormap(void); // Called from both child and parent process */ 
  SINT2 getNumOfColors(void);
  void  setDataType(UINT4 data_type);
  UINT4 getDataType(void);
  void  setRange(UINT2 rng_opt_menu_pos);
  UINT2 getRangeMenuPos(void);
  void  setRangeUnits(UINT4 rng_units);
  UINT4 getRangeUnits(void);
  UINT2 getIdxFromCurUnits(void);
  void  setSweepLine(UINT2 lsweep_line_on);
  UINT2 getSweepLine(void);
  void  setSweepLineColor(UINT4 isweep_color_pixel);
  void  setTextColorIdx(UINT4 text_color_idx);
  UINT4 getTextColorIdx(void);

  /* rng.C */
  void setRngVals(UINT4 rng_vals[2][4]);
  void getRngVals(UINT4 rng_vals[2][4]);

  /* rhiOpt.C */
  void  setMaxHeight(FLT4 fmax_hgt_a);
  FLT4  getMaxHeight(void);
  void  setRhiScan(UINT2 lrhi_scan_a);
  UINT2 getRhiScan(void);
  void  setRhiLowerLeft(UINT2 lrhi_lower_left_a);
  UINT2 getRhiLowerLeft(void);

  /* overlay.C */
  void  setOverlayRngRings(UINT4 overlay_rng_ring);
  UINT4 getOverlayRngRings(void);
  void  setOverlayName(char *overlay_name);
  char *getOverlayName(void);
  void  setOverlayLayerMask(UINT4 overlay_layer_mask);
  UINT4 getOverlayLayerMask(void);

  /*color.C */
  void setColorVals(struct color_scale_mod_def refl_color,
                  struct color_scale_mod_def velocity_color,
                  struct color_scale_mod_def width_color);
  void getColorVals(struct color_scale_mod_def *refl_color,
                  struct color_scale_mod_def *velocity_color,
                  struct color_scale_mod_def *width_color);
  FLT4 firstLevel( const UINT4 idata_a, const FLT4 fnum_in);
  FLT4 levelStep( const UINT4 idata_a, const FLT4 fnum_in);

  /*siteStat.C */
  void  setSiteName3(char *sitename3);
  UINT4 getNumSites(void);
  void  getSiteInfo(UINT4 idx_a, UINT2 *alloced_a, char *site_info_a);
  void  updateSiteList(void);
  void  setPortNum(UINT4 iport_num_a);
  UINT4 getPortNum(void);
};
EXTERN RtdFunc rtdFunc;

#undef EXTERN

