/* **********************************************************************
 * *                                                                    *
 * *                   Bitex Shared Definitions                         *
 * *                                                                    *
 * **********************************************************************
 * File: utils/bitexx/bitex.h
 *
 *                 COPYRIGHT (c) 1996, 1997, 1998  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.
 */
#ifndef BITEX_H
#define BITEX_H

#ifdef BITEX_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

#define TOOLS_MODE_POINTER   1 
#define TOOLS_MODE_MOVE      2
#define TOOLS_MODE_DELETE    3 
#define TOOLS_MODE_CUT_PASTE 4 
#define TOOLS_MODE_STATUS    5
#define TOOLS_MODE_CONTROL   6
#define TOOLS_MODE_PANEL     7

#define WGT_TYPE_STAT_CONT  1
#define WGT_TYPE_PANEL     2

#define PANEL_ERROR_NOFAULT   1
#define PANEL_ERROR_FAULT     2
#define PANEL_ERROR_CRITICAL  3

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

/****************************************
** Globlal User Created Variables
** Set these variables in bitex.C
****************************************/
EXTERN Display      *applDisplay;
EXTERN int          applScreen;
EXTERN XtAppContext appContext;
EXTERN Colormap     Colormap_c;
EXTERN XVisualInfo  VisualInfo_c;


/* Shared variables
 */
EXTERN int    setupMode_c ;
EXTERN char   thisHostname_c[50];
EXTERN UINT2  lUpgradeMode_c;	// Upgrade bitex1 to bitex2
EXTERN int    dataChanged_c ;
EXTERN UINT2  bDebug;

struct bitex_top_info
{
  UINT2 ifield_cnt ;		/* Number of fields (max BITE_NUM_FIELD_DEFS) */
  UINT1 iunit_cnt ;		/* Number of units, (max BITE_MAX_UNITS) */
  char ipad3x1[1] ;
  struct bitex_unit_info units[BITE_MAX_UNITS] ;
} ;
EXTERN struct bitex_top_info bite_info_c;

struct StatContWgtDef
{
  struct bitexWgt_StatContDef statCont ;
  UINT2  lJustCut ;		//Set TRUE when cutting and then FALSE when pasteing
  Widget indicatorLabelWgt ;
  Widget dynamicLabelWgt ;
  Widget staticLabelWgt ;
} ;
struct StatContDef
{
  struct StatContWgtDef wgt;
  struct bitex_field_def field;
} ;
EXTERN struct StatContDef statContDef[BITE_NUM_FIELD_DEFS];

struct PanelWgt
{
  struct bitexWgt_Panel panel ;
  Widget panelLabelWgt ;
} ;
EXTERN struct PanelWgt panelWgt[BITEX_MAX_PANEL_DIAGS] ;

class BitexAS
{
  private :
    struct antHistInfo *pInfo;
  public :
    void   init(void);
    void   infoUpdate(UINT2 lforce_update_a);
    Widget getBitexApplShell(void);
    struct antHistInfo *getAntHistInfo(void);
};
EXTERN BitexAS bitexAS;

class Tools 
{
  private :
  public :
  void create(Widget parent);
  void popup(UINT4 ix_a, UINT4 iy_a); 
  void popdown(void); 
  UINT4 getMode(void); 

};
EXTERN Tools tools; 

class PanelOptions
{
  private :
  public :
  void create(Widget parent);
  void popup(UINT4 panel_wgt_struct_idx_a, UINT4 ix_a, UINT4 iy_a,  XtPointer clientData_a); 
  void popdown(void); 
};
EXTERN PanelOptions panelOptions; 

class BiteConfig
{
  private :
  public :
  void  create(Widget parent);
  void  popup(void);
  void  popdown(void);
  UINT2 isManaged(void);
  void  updateIOandAge(void);
  void  updateConfigParams(struct bitex_top_info bite_info_a);
};
EXTERN BiteConfig biteConfig; 

class FieldConfig
{
  private :
  public :
  void  create(Widget parent);
  void  popup(UINT4 field_num_a); 
  void  popdown(void);
  UINT2 isManaged(void);
  void  updateCurrentConfigParams(void);
};
EXTERN FieldConfig fieldConfig; 

class Interrogate
{
  private :
  public :
  void  create(Widget parent);
  void  popup(void); 
  void  popdown(void);
  UINT2 isManaged(void);
  void  update(void);
};
EXTERN Interrogate interrogate; 

// These routines are private and can only be accessed
// from the Panel class
class Widgets 
{
  private :
    UINT4   iXStartMove;
  UINT4   iYStartMove;

  public :
    void   createStatCont(Widget main_diag_wgt_a, UINT4 idx_a,
			  struct StatContDef *stat_cont_def_a);
  void   createPanel(Widget main_diag_wgt_a, UINT4 idx,
		     struct PanelWgt *panel_wgt_a);
  void   setStatCont(Widget main_diag_wgt_a,
		     struct StatContDef stat_cont_def_a);
  void   updateStatCont(Widget main_diag_wgt_a,
			struct StatContDef stat_cont_def_a,
			struct bite_field_state field_state_a);
  void   updatePanel(Widget main_diag_wgt_a,
		     struct PanelWgt panel_wgt_a, UINT1 istatus_a);
  void   deleteDestroy(Widget form_wgt, UINT4 itype_a, UINT4 idx_a);
  void   cut(Widget form_wgt, UINT4 itype_a, UINT4 idx_a);
  void   setStartMove(Widget form_wgt, int x, int y);
  void   move(Widget form_wgt, UINT4 itype_a, 
	      UINT4 idx_a, int x, int y);
};


class Panel : private Widgets
{
  private :
    UINT4   iDiagX;
  UINT4   iDiagY;
  UINT4   iDiagWid;
  UINT4   iDiagHgt;
  Widget  mainDiagWgt;
  Widget  ioCountFormWgt;
  Widget  inCountTxtFWgt;
  Widget  outCountTxtFWgt;
  Widget  ageTxtFWgt;
  Widget  daWgt;
  Window  wnd;
  XImage  *bgImage;
  GC      blackGC;
  GC      whiteGC;
  UINT2   lSetupGraphics;
  UINT2   lDisplayIOCount;
  public :
    Panel(void);
  UINT4  panelWgtStructIdx;
  UINT4  thisPanelNum;
  char   sPanelTitle[BITEX_PANEL_TITLE_SIZE];
  void   createDiag(UINT4 cur_panel_wgt_idx);
  void   deleteDiag(void);
  void   popupDiag(void); 
  void   popdownDiag(void); 
  void   setupGraphics();
  UINT2  diagIsAlloced(void);
  Widget getMainDiagWgt(void);
  void   draw();
  void   copyImageToWnd(UINT4 ix_a, UINT4 iy_a, UINT4 iw_a, UINT4 ih_a);
  void   destroyMakeAvail(void);
  void   setIcon(void);
  void   setSizePosition(void);
  UINT4  getNewPanelNum(void);
  void   createStatContWgts(UINT4 idx_a,
			    struct StatContDef *stat_cont_def_a);
  void   createPanelWgts(UINT4 idx,
			 struct PanelWgt *panel_wgt_a);
  void   setStatContWgts(struct StatContDef stat_cont_def_a);
  void   updateStatContWgts(struct StatContDef stat_cont_def_a,
			    struct bite_field_state field_state_a);
  void   updatePanelWgts(struct PanelWgt panel_wgt_a, UINT1 istatus_a);
  void   getDialogPosition(UINT4 *ix_a, UINT4 *iy_a);
  void   setMinWidHgtMainDiag(void);
  void   setTitle();
  void   displayIOCount(void);
  void   updateIOCount(UINT4 incount_a, UINT4 ioutcount_a, UINT4 iage_a);
};
EXTERN  Panel panel[BITEX_MAX_PANEL_DIAGS];

class PanelFunc
{
 private:
  Pixmap statGrnPm;
  Pixmap statRedPm;
  Pixmap statYelPm;
  Pixmap statOffPm;
  Pixmap contOutGrnPm;
  Pixmap contOutRedPm;
  Pixmap contOutYelPm;
  Pixmap contOutOffPm;
  Pixmap contInGrnPm;
  Pixmap contInRedPm;
  Pixmap contInYelPm;
  Pixmap contInOffPm;
  Pixmap panelGrnPm;
  Pixmap panelRedPm;
  Pixmap panelYelPm;
  Pixmap panelOffPm;
  void  createNewBitexFromOld(void);
  public :
    PanelFunc(void);
  void  createPixmaps();
  Pixmap getStatGrnPm(void);
  Pixmap getStatRedPm(void);
  Pixmap getStatYelPm(void);
  Pixmap getStatOffPm(void);
  Pixmap getContOutGrnPm(void);
  Pixmap getContOutRedPm(void);
  Pixmap getContOutYelPm(void);
  Pixmap getContOutOffPm(void);
  Pixmap getContInGrnPm(void);
  Pixmap getContInRedPm(void);
  Pixmap getContInYelPm(void);
  Pixmap getContInOffPm(void);
  Pixmap getPanelGrnPm(void);
  Pixmap getPanelRedPm(void);
  Pixmap getPanelYelPm(void);
  Pixmap getPanelOffPm(void);
  void  save(void);
  void  load(void);
};
EXTERN PanelFunc panelFunc;



#define MAX_HIST_DIAG 10
#define VERTICAL_SPAN_MAX_CNT 20
class HistDiag 
{
  private :
    UINT4   iWinWid;          //Saved Param
    UINT4   iWinHgt;          //Saved Param
    UINT4   iColorIdx;        //Saved Param
    UINT4   iTimeSpanArrayIdx; 
    UINT2   lSave;
    UINT4   iVerticalSpanArrayIdx;
    UINT4   iTimeOffset;
    SINT4   iVerticalOffset;
    UINT4   iScrollYPos;
    UINT4   iFieldNum;
    UINT2   lPageIncDec;
    Widget  mainDiagWgt;
    Widget  daWgt;
    Widget  daFormWgt;
    Widget  titleLabWgt;
    Widget  timeSpanTxtFWgt;
    Widget  verticalSpanLabWgt;
    Widget  verticalSpanSclWgt;
    Widget  verticalSpanTxtFWgt;
    Widget  curTimeTxtFWgt;
    Widget  timeOffsetSBWgt;
    Widget  verticalOffsetSBWgt;
    Window  wnd;
    Pixmap  pm;
    struct  ymds_time endTime;
    GC      whiteGC;
    GC      blackGC;
    GC      redGC;
    GC      copyGC;
    GC      colorGC;
    GC      fontGC;
    GC      fontRedGC;
    UINT4   iVerticalSpanCount;
    FLT4    fVerticalSpanArray[VERTICAL_SPAN_MAX_CNT];
    void    createDiag(char *diagTitle_a);
    void    loadParams(void);
    void    drawStatus(void);
    void    drawQBite(void);
    void    setVerticalSpanArray(void);
  public :
    HistDiag(void);
    UINT2  createDrawData(UINT4 iwin_num_a, UINT4 ifield_num_a, 
      char *spanel_title_a);
    UINT2  avail(void);
    void   saveParams(void);
    void   setSaveFlag(void);
    void   setTimeSpan(int itime_scl_idx_a);
    void   setVerticalSpan(int ivertical_span_array_idx_a);
    void   setTimeOffset(int itime_offset, int lpage_inc_dec);
    void   setVerticalOffset(int ivertical_offset_a);
    void   setNewEndTime(void);
    Widget getMainDiagWgt(void);
    void   draw(void);
    void   copyPmToWnd(UINT4 ix_a, UINT4 iy_a, UINT4 iw_a, UINT4 ih_a);
    void   changeColor(UINT4 icolor_idx_a);
    void   destroyMakeAvail(void);
};
EXTERN  HistDiag histDiag[MAX_HIST_DIAG];


/*******************************************************
**
** Prototypes
**
************************************************/

/*************************************************
** biteFunc.C
*************************************************/
UINT2 bitexFunc_checkBiteDrvEqualsConfFile(void);
void bitexFunc_checkBiteDriverData(void) ;
void bitexFunc_getBiteDriverData(void);
void bitexFunc_setBiteDriverData(void);
void bitexFunc_saveBiteData(void);
void bitexFunc_loadBiteData(void);
void bitexFunc_loadBiteData(void);
void bitexFunc_biteGetDefAndCheck(UINT2 lforce_a);
void bitexFunc_clearAllJustCut();

#undef EXTERN
#endif
