/* ===========================================================================
 *
 * utils/overlay/overlay.h    Global variables and functions for OVERLAY
 *
 *     COPYRIGHT (c)  1992, 1994, 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. 

=============================================================================*/

#ifdef OVERLAY_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

//#define DEBUG_PRINTF


#define DEG_CHAR          176

#define WIDTH  (800)
#define HEIGHT (720)

#define MODE_NONE      1
#define MODE_ADD_TEXT  2
#define MODE_DEL_TEXT  3
#define MODE_ADD_ICON  4
#define MODE_DEL_ICON  5
#define MODE_ADD_FILL  6
#define MODE_DEL_FILL  7
#define MODE_ADD_GIF   8
#define MODE_DEL_GIF   9

#define LAYER_NONE     99

#define ICON_WIDTH_PB  110
#define ICON_HEIGHT_PB  20 

//#define LAYER_WIDTH_PB  140
#define LAYER_WIDTH_PB   200
#define LAYER_HEIGHT_PB  20 

#define LAYER_TOOL_WIDTH_PB  200
#define LAYER_TOOL_HEIGHT_PB  20 

struct Options_str
{
    char  sOverlayPath[PATHNAME_SIZE]; /* Overlay Path */
    char  sOverlayFile[16];            /* Overlay filename */
    char  sCatchFile[16];              /* Catch filename */
    int   iWindowDepth;
    FLT4  fWidthKm;
    FLT4  fNorthPos;        /* Radar position offset in km */
    FLT4  fEastPos;
    UINT4 iLayerMask;       /* 32 bits.  Each bit represents 1 layer */
    UINT1 lFillPoints;
    UINT1 lRangeRings;
    UINT1 lZoom;
    UINT1 lProtected;
    UINT1 lNoUnderlay;
    UINT1 lLatLon;
    UINT4 iProjType;
    UINT4 iImageWidth;
    UINT4 iImageHeight;
};

class Overlay
{
 private:
   GC       copyGC;
   GC       blackGC;
   GC       whiteGC;
   GC       fontGC;
   Window   dAWin;
   UINT4    iMaxOverlayWidth;
   UINT4    iMaxOverlayHeight;
   Cursor   hourGlassCursor;
 public:
    UINT2   lVerbose; 
    UINT2   lHasArgvFilename; 
    SINT4   iDrawAreaWidth;    // Drawing Area Width
    SINT4   iDrawAreaHeight;   // Drawing Area Height 
    void    init(void);
    char    *getHostname();
    void    setTitle(void);
    void    setHourglassCursor(void);
    void    setDefaultCursor(void);
    Window  getWindow(void);
    GC      getCopyGC(void);
    GC      getBlackGC(void);
    GC      getWhiteGC(void);
    GC      getFontGC(void);
    void    getMaxOverlayWidthHeight(UINT4 *iwidth_a, UINT4 *iheight_a);
};
EXTERN Overlay overlay;

class OptionsTool 
{
 private:
 public:
    void  create(swidget parent);
    void  popup(void);
    void  popdown(void);
    void  updateOptions(void);
};
EXTERN OptionsTool optionsTool;

class OpenFileTool 
{
 private:
 public:
    void  create(swidget parent);
    void  popup(void);
    void  popdown(void);
};
EXTERN OpenFileTool openFileTool;


class AddTool 
{
 private:
 public:
    void   create(swidget parent);
    void   popup(void);
    void   popdown(void);
    UINT2  lIsManaged();
    void   updateLayers(UINT2 lreset_option_menu_a);
    void   updateLonLat(struct latlon8 earth_a);
    void   updateUnderlayCenterLonLat(struct latlon8 center_a);
    void   updateUnderlayProjRefLonLat(struct latlon8 proj_ref_a);
    void   updateUnderlayOM();
    Cursor getCurCursor(void);
    UINT4  getModeType(void);
    UINT4  getFillColorDefine(void);
    UINT4  getLayerIdx(void);
    UINT4  getIconIdx(void);
    UINT4  getFontSize(void);
    char   *getTextStr(void);
    UINT4  getTextJust(void);
    UINT4  getScreenRel(void);
    UINT4  getHighlight(void);
    char   *getUnderlayFilename(void);
    UINT4  getUnderlayProjType(void);
    FLT8   getUnderlayScale(void);
    struct latlon8 getUnderlayCenter(void);
    struct latlon8 getUnderlayProjRef(void);
    UINT2  isUnderlayAlreadyAdded(void);
};
EXTERN AddTool addTool;

class LayerTool 
{
 private:
 public:
    void  create(swidget parent);
    void  popup(void);
    void  popdown(void);
    void  updateLayers(void);
};
EXTERN LayerTool layerTool;


class HeaderTool 
{
 private:
 public:
    void  create(swidget parent);
    void  popup(void);
    void  popdown(void);
    void  updateInfo(void);
};
EXTERN HeaderTool headerTool;



class Options
{
 private:
    struct Options_str options_str;
 public:
    Options(void);
    void loadDefaults(void);
    void setOverlayAndCatchFiles(const char *overlay_path_a, 
          const char *overlay_file_a, const char *catch_file_a);
    void setOptions(struct Options_str options_str_a);
    void setOffsets(FLT4 east_offset_a, FLT4 north_offset_a);
    void setImageWidthHeight(UINT4 iwidth_a, UINT4 iheight_a);
    void getAllOptions(struct Options_str *options_str_a);
    void setLayerMask(void);
    void saveFile(void);
    void loadFile(void);
};
EXTERN Options options;


#ifdef SIGMET_PROJECTION_H
class NewImage 
{
 private:
  int      iVisualDepth;
  XVisualInfo VisualInfo;
  struct   color_def StandardMap[256];
  UINT4    iStandardVtvMapClient[256] ;
  UINT1    imageBuffer[4*WIDTH*HEIGHT];
  struct   mpj_projection8 proj;
  struct   mpj_region8     region;
  struct   layer_dir      layers;
  struct   layer_dir      undoLayers;
  struct   overlay_file_header8 overHeader;
  struct   overlay_file_header8 undoOverHeader;
  struct   catch_file_header8 catchHeader;
  Colormap colormap;
  UINT1    *pOverlayHeap;
  UINT1    *pUndoOverlayHeap;
  SINT4    iOverlayHeapSize;
  SINT4    iUndoOverlayHeapSize;
  UINT1    *pCatchHeap;                    /* Must be freed when done */
  UINT1    OverlayLoad (void);               /* Must be freed when done*/
  UINT1    OverlayPin (void);
  UINT2    lImageIsLoaded;
  MESSAGE  drawVTVImage (UINT4* pimage_a, const FLT4 fradpos_a[2]);
  Pixel    blackPixel;
  Pixel    whitePixel;
  struct   overlay_point8 *pClosestFill;
  struct   overlay_text8  *pClosestTextIcon;
 public:
  void     initImageInfo(void);
  void     saveOverlayImage(void);
  void     loadAndDrawOverlayImage(void);
  void     drawOverlayImage(void);
  void     drawOverlayImageDelay(void);
  void     exposeOverlayImage(int ix_a, int iy_a, int iw_a, int ih_a);
  void     getEarthFromPixel(FLT8 fx_a, FLT8 fy_a, struct latlon8 *pEarth_a );
  void     getPixelFromEarth(FLT8 *fx_a, FLT8 *fy_a, struct latlon8 *pEarth_a);
  UINT2    lGetImageIsLoaded(void);
  UINT4    getFillColorFromDefine(const UINT4 ifile_color_define_a);
  void     setLayerName(UINT4 idx_a, char slayer_name_a[LAYER_NAME_SIZE]);
  void     getLayerName(UINT4 idx_a, char slayer_name_a[LAYER_NAME_SIZE]);
  void     setLayerColorDefine(UINT4 idx_a, UINT4 ilayer_color_define_a);
  UINT4    getLayerColorDefine(UINT4 idx_a);
  UINT4    getLayerColorFromDefine(const UINT4 ilayer_color_define_a);
  UINT4    getNumLayers(void);
  UINT2    getNewLayerIdx(UINT4 *inew_layer_idx);
  void     getHeaderInfo(FLT4 *fill_range_a, 
			 FLT4 *fill_center_lat_a, FLT4 *fill_center_lon_a, 
			 FLT4 *draw_center_lat_a, FLT4 *draw_center_lon_a);
  void     createFromIconListACursorPixmap(UINT4 idx_a, Pixmap *pixmap_a,
					   Pixmap *pixmap_mask_a,
					   UINT4 *iwidth_a, UINT4 *iheight_a,
                                           UINT4 *ix_hot_a, UINT4 *iy_hot_a);
  Pixmap   createFromIconListALabelPixmap(UINT4 idx_a, Pixel fg_a, Pixel bg_a);
  Pixmap   createFromLayerListALabelPixmap(UINT4 idx_a, UINT4 iwidth_a, 
					   UINT4 iheight_a, Pixel fg_a, Pixel bg_a);
  Pixmap   createColorLabelPixmap(UINT4 icolor_pixel_a,
				  UINT4 iwidth_a, UINT4 iheight_a);
  void     createFontCursorPixmap(UINT4 font_point_size_a, char text_a[40], 
				  Pixmap *pixmap_a, Pixmap *pixmap_mask_a, 
				  UINT4 *iwidth_a, UINT4 *iheight_a,
				  UINT4 *ihotx_a, UINT4 *ihoty_a);
  char     *getUsedUnderlayFilename(UINT4 iunderlay_idx_a);
  void     writeGIFImage(void);
  Pixel    getBlackPixel(void);
  Pixel    getWhitePixel(void);
  void     addOverlayPointLatLon(struct latlon8 earth_a);
  void     addOverlayPoint(FLT8 fx_a, FLT8 fy_a);
  void     deleteOverlayPoint(void);
  void     undoOverlayPoint(void);
  UINT2    getClosestTextIconPoint( FLT8 fx_a, FLT8 fy_a,
				    UINT4 *ix_closest_a, UINT4 *iy_closest_a,
				    struct latlon8 *earth_a);
  UINT2    getClosestFillPoint(FLT8 fx_a, FLT8 fy_a, 
			       UINT4 *ix_closest_a, UINT4 *iy_closest_a,
			       struct latlon8 *earth_a);
  UINT2    getUnderlayParams(const char *filename_a, 
			       struct latlon8 *center_a,
			       UINT1 *iproj_type_a, struct latlon8 *proj_ref_a,
                               FLT8   *fscale_a); 
  void     deleteOverlayLayer(UINT4 del_layer_idx_a);
  void     mergeOverlayLayer(UINT4 del_layer_idx_a, 
			     UINT4 merge_into_layer_idx_a);
  void     changeSelectedUnderlayCenter(struct latlon8 center_a);
  void     saveUndoParams(void);
  
};
EXTERN NewImage newImage; 
#endif  /* #ifdef SIGMET_PROJECTION_H */


#undef EXTERN
