/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _COMPASSFACE_H
#define _COMPASSFACE_H
static char CompassFace_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/CompassFace.h,v 1.3 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: CompassFace.h,v $
Revision 1.3  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.2  1997/03/20 12:32:59  oreilly
*** empty log message ***

 * Revision 1.1  96/10/28  09:13:28  09:13:28  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/


#include <Vk/VkDoubleBuffer.h>
#include "ErrorHandler.h"
#include "Math.h"
#include "CircularQueue.h"

// Full circle angle for XDrawArc
#define FullCircle 23040

#define NoAutoHeading MAXFLOAT

/*
CLASS 
CompassFace

DESCRIPTION
Face for "floating" compass dial, includes heading history trace

AUTHOR
Tom O'Reilly
*/
class CompassFace : public VkDoubleBuffer, public ErrorHandler
{
  public:
  
  CompassFace(const char *name, Widget parent, int nHistoryPoints); 

  ~CompassFace();

  virtual const char *className()
  {
    return "CompassFace";
  }
  
  virtual void draw();

  void setHeading(Radians heading);
  void setAutoHeading(Radians heading);
  void clearAutoHeading();
  void setSetpoint(Radians setpoint);
  
  Radians heading()
  {
    return _heading;
  }
  
  
  void addHistory(Radians heading);
  void clearHistory();
  

  protected:

  struct HistoryPoint 
  {
    double sinHeading;
    double cosHeading;
  };
   
  void drawDial();
  void drawHistory();
  virtual void resize();
  
  int physicalCoords(double x, double y, int *i, int *j);

  int equalizeScales()
  {
    _equalFactor = (float )_width / (float )_height;
    return 0;
  }

  // Angle between x axis and specified heading
  Radians dialAngle(double heading);

  Boolean bigTic(int degrees)  
  {
    return (!(degrees % _bigTicIncr));
  }
  
  Radians _heading;
  Radians _autoHeading;
  Radians _setpoint;
  
  CircularQueue<HistoryPoint> *_history;
  
  GC _faceGC;
  GC _headingGC;
  
  Display *_display;
  int _screenNum;

  Pixel _ticColor, _faceColor, _autoHeadingColor, _historyColor ;
  Pixel _setpointColor, _topShadowColor, _bottomShadowColor;
  XFontStruct *_fontInfo;
  
  Pixmap _smallTicMask;
  Pixmap _bigTicMask;

  int _bigTicIncr;
  int _smallTicIncr;
  int _headingTicLength;
  float _equalFactor;
  
  double _dialRadius;
  double _bigTicRadius;
  double _smallTicRadius;
  double _labelRadius;
  double _autoLabelRadius;
  
  double _historyRadiusIncr;
  
  double _xRange, _yRange;

  static XtResource _resources[];
};

#endif
