/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _DEPTHALTITUDE_H
#define _DEPTHALTITUDE_H
static char DepthAltitude_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/DepthAltitude.h,v 1.6 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: DepthAltitude.h,v $
Revision 1.6  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.5  1997/09/10 08:47:25  oreilly
Load and save preferences

 * Revision 1.4  97/08/12  14:36:38  14:36:38  oreilly (Thomas C. O'Reilly)
 * Added depth rate
 * 
 * Revision 1.3  97/03/20  12:33:06  12:33:06  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.2  96/10/28  09:13:33  09:13:33  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
*/

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/XrtGraph.h>
#include <Vk/VkPopupMenu.h>
#include "DmGuiObject.h"
#include "CircularQueue.h"
#include "State.h"

// BOGUS depth alarm DM name for now!!!
#define VEHICLE_DEPTH_ALARM_DM "TIBURON.SENSOR.DEPTH.ALARM"

#define MissingDepthAltitude XRT_HUGE_VAL
enum
{
  VehicleDepth = 0, BottomDepth
};

typedef enum
{
  DepthMode, AltimeterMode

} DepthAltimeterMode;



#define fineScaleRange 20
#define mediumScaleRange 80
#define coarseScaleRange 200

/*
CLASS 
DepthAltitude

DESCRIPTION
Display depth and altitude as a function of time

AUTHOR
Tom O'Reilly
*/
class DepthAltitude : public DmGuiObject
{
  public:
  DepthAltitude(const char *name, Widget parent, 
                unsigned maxAltitude,        // i: upper limit of altimeter
		unsigned historyMinutes,     // i: History time in minutes
		unsigned period);            // i: Update period in millisecs 
                                             // MUST be periodic  

  ~DepthAltitude();
  
  
  const char *className()
  {
    return "DepthAltitude";
  }
  
  virtual void updateGui(DM_Item handle = 0);
  
  static const char *const modeMnem;
  static const char *const scaleMnem;

  int loadPreferences(DynArray<Preference *> *preferences, char *errorBuf);
  int savePreferences(DynArray<Preference *> *preferences, char *errorBuf);

  protected:

  struct DepthAltitudePoint
  {
    time_t time;
    Flt64 depth;
    Flt32 altitude;
  };
  
  void shiftYAxis(DepthAltitudePoint *point,
		  float *axisMin, float *axisMax, float axisRange);
  
  void rescaleYAxis(unsigned newAxisRange);
  
  Widget _graph;
  
  unsigned _depthAxisRange;
  unsigned _maxAltitude;
  DmFlt64Object *_dmDepth;
  DmFlt32Object *_dmDepthRate;
  DmFlt32Object *_dmAltitude;  
//  DmPositionObject *_dmPosition;
  float _depthAxisMin, _depthAxisMax;
  float _yAxisShiftFactor;
  Boolean _bottomDisplayed;

  static VkMenuDesc _menuPane[];
  static VkMenuDesc _scaleMenuPane[];
  static VkMenuDesc _modeMenuPane[];
  DepthAltimeterMode _mode;
  
  // Array of points is a circular queue
  CircularQueue<DepthAltitudePoint> *_points;  

  XrtData *_xrtData;

  char *_vehicleDataColor;
  char *_bottomDataColor;
  
  static XtResource _resources[];

  void showControls();

  void setMode(DepthAltimeterMode mode);
  
  private:
  static void buttonEventHandler(Widget w, 
				 XtPointer clientData, XEvent *event);
  
  static void coarseScaleCallback(Widget w, XtPointer clientData, 
				  XtPointer callData);

  static void mediumScaleCallback(Widget w, XtPointer clientData, 
				  XtPointer callData);

  static void fineScaleCallback(Widget w, XtPointer clientData, 
				XtPointer callData);

  static void depthModeCallback(Widget w, XtPointer clientData, 
				XtPointer callData);


  static void altimeterModeCallback(Widget w, XtPointer clientData, 
				    XtPointer callData);

  
};


#endif
