/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _ROVDIAGRAM_H
#define _ROVDIAGRAM_H
static char RovDiagram_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/RovDiagram.h,v 1.4 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: RovDiagram.h,v $
Revision 1.4  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.3  1997/05/07 17:41:42  oreilly
Delete contained DmInputDetector in destructor.

 * Revision 1.2  97/03/20  12:36:34  12:36:34  oreilly (Thomas C. O'Reilly)
 * *** empty log message ***
 * 
 * Revision 1.1  96/10/28  09:14:02  09:14:02  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/


#include <Vk/VkDoubleBuffer.h>
#include "DmGuiObject.h"
#include "DmInputDetector.h"

#define MaxRpm 2068.
#define NThrusters 6
#define NLights 6
#define ThrusterLineThickness 3
#define StrutLineThickness 2
 
#define AFT_LATERAL_RPM_DM "TIBURON.THRUSTER.AFT_LATERAL.VELOCITY"
#define AFT_LATERAL_ENABLE_DM "TIBURON.THRUSTER.AFT_LATERAL.ENABLE_STATUS"
#define FWD_LATERAL_RPM_DM "TIBURON.THRUSTER.FWD_LATERAL.VELOCITY"
#define FWD_LATERAL_ENABLE_DM "TIBURON.THRUSTER.FWD_LATERAL.ENABLE_STATUS"
#define PORT_HORIZ_RPM_DM "TIBURON.THRUSTER.PORT_HORIZ.VELOCITY"
#define PORT_HORIZ_ENABLE_DM "TIBURON.THRUSTER.PORT_HORIZ.ENABLE_STATUS"
#define STBD_HORIZ_RPM_DM "TIBURON.THRUSTER.STBD_HORIZ.VELOCITY"
#define STBD_HORIZ_ENABLE_DM "TIBURON.THRUSTER.STBD_HORIZ.ENABLE_STATUS"
#define PORT_VERT_RPM_DM "TIBURON.THRUSTER.PORT_VERT.VELOCITY"
#define PORT_VERT_ENABLE_DM "TIBURON.THRUSTER.PORT_VERT.ENABLE_STATUS"
#define STBD_VERT_RPM_DM "TIBURON.THRUSTER.STBD_VERT.VELOCITY"
#define STBD_VERT_ENABLE_DM "TIBURON.THRUSTER.STBD_VERT.ENABLE_STATUS"


/*
CLASS 
Thruster

DESCRIPTION
Display thruster state and RPM 

AUTHOR
Tom O'Reilly
*/
class Thruster
{
  public:

  typedef enum
  {
    Enabled, Disabled, Unknown

  } ThrusterStatus;
  
  Thruster(Display *display,
	   GC lineGC, GC forwardGC, GC reverseGC,
	   Pixel enabledColor, Pixel disabledColor);

  ~Thruster();
  
  // Set thrust RPM
  void setRPM(Int16 rpm);

  virtual void draw(Drawable canvas) = 0;
  virtual int centerX();
  virtual int centerY();
   
  int width()
  {
    return _width;
  }
  
  int height()
  {
    return _height;
  }
  
  void enable();
  void disable();
  
  
  protected:

  void setStatusStyle();
  Display *_display;
  Int16 _rpm, _prevRpm;
  GC _lineGC, _forwardGC, _reverseGC;
  int _originX;
  int _originY;
  int _width;
  int _height;
  ThrusterStatus _status, _prevStatus;
  float _thrustScaling;
  Pixel _enabledColor, _disabledColor;
};


/*
CLASS 
HorizontalThruster

DESCRIPTION
Display state and RPM of horizontal Thruster

AUTHOR
Tom O'Reilly
*/

class HorizontalThruster: public Thruster
{
  public:
  HorizontalThruster(Display *display,
		     GC lineGC, GC forwardGC, GC reverseGC,
		     Pixel enabledColor, Pixel disabledColor,
		     int centerX, int centerY, 
		     int height);

  ~HorizontalThruster();

  virtual void draw(Drawable canvas);

  protected:
};


/*
CLASS 
LateralThruster

DESCRIPTION
Display state and RPM of lateral Thruster

AUTHOR
Tom O'Reilly
*/
class LateralThruster: public Thruster
{
  public:
  LateralThruster(Display *display,
		  GC lineGC, GC forwardGC, GC reverseGC,
		  Pixel enabledColor, Pixel disabledColor,
		  int centerX, int centerY, 
		  int height, Boolean positiveToRight);

  ~LateralThruster();

  virtual void draw(Drawable canvas);
  

  protected:
  Boolean _positiveToRight;
};


/*
CLASS 
VerticalThruster

DESCRIPTION
Display state and RPM of vertical Thruster

AUTHOR
Tom O'Reilly
*/
class VerticalThruster : public Thruster
{
  public:
  VerticalThruster(Display *display,
		   GC lineGC, GC forwardGC, GC reverseGC,
		   Pixel enabledColor, Pixel disabledColor,
		   int centerX, int centerY, int radius);

  ~VerticalThruster();
  
  void draw(Drawable canvas);

  protected:
  int _diameter;
  int _strutOffset;
};


#define LightOff False
#define LightOn True

/*
CLASS 
Light

DESCRIPTION
Display state of vehicle light

AUTHOR
Tom O'Reilly
*/
class Light
{
  public:
  Light(Display *display, GC lineGC, GC lightGC,
	int centerX, int centerY, int radius, Pixel onColor, Pixel offColor);

  ~Light();

  void draw(Drawable canvas);
  void set(Boolean on);
  int centerX();
  int centerY();
  int width();
  int height();
  
  protected:
  Display *_display;
  GC _lineGC, _lightGC;
  int _originX, _originY;
  int _diameter;
  Boolean _on;
  Pixel _onColor, _offColor;
};


/*
CLASS 
VehicleDiagram

DESCRIPTION
Display state of vehicle lights and thrusters. Includes Light, 
HorizontalThruster, LateralThruster, and VerticalThruster objects.

AUTHOR
Tom O'Reilly
*/
class RovDiagram : public DmGuiObject, public VkDoubleBuffer
{
  public:

  enum 
  {
    PortHorizThruster = 0, StbdHorizThruster, 
    PortVertThruster, StbdVertThruster,
    FwdLatThruster, AftLatThruster

  };
  
  enum
  {
    PortAuxLight = 0, StbdAuxLight,
    PortDirectionalLight, StbdDirectionalLight,
    PortFixedLight, StbdFixedLight
  };
  
  
  RovDiagram(const char *name, Widget parent, int period);
  ~RovDiagram();
  
  virtual const char *className()
  {
    return "RovDiagram";
  }
  
  virtual void updateGui(DM_Item handle = 0);
  virtual void updateFromPeer(DmGuiObject *peer, void *clientData);
  
  void draw();
  
  protected:

  DmInputDetector *_enableDetector[NThrusters];

  struct ThrusterInfo
  {
    DmInt16Object *dmRpm;
    DmEnumObject *dmEnable;
    Int16 prevValue;
    Thruster *diagram;
  };

  struct LightInfo
  {
    DmEnumObject *dm;
    Light *diagram;
  };

  LightInfo _light[NLights];
  ThrusterInfo _thruster[NThrusters];
  
  Pixel _foreground, _background;
  Pixel _forwardColor, _reverseColor;
  Pixel _lightOnColor, _lightOffColor;
  Pixel _disabledColor;
  GC _lineGC, _forwardGC, _reverseGC, _lightGC;
  Display *_display;
  int _screenNum;

  Pixmap _vehicleBitmap;
  XPoint _vehicleBitmapOffset;
  
  static XtResource _resources[];
};



#endif
