/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _VALVESWITCHMAP_H
#define _VALVESWITCHMAP_H

#include <Vk/VkOptionMenu.h>
#include "DmGuiObject.h"
#include "ValveControl.h"

/*
CLASS 
ValveSwitchMap

DESCRIPTION
GUI to select which of a group of ValveControl objects is currently
mapped to pilot joystick trigger.

AUTHOR
Tom O'Reilly
*/
class ValveSwitchMap : public DmGuiObject
{
  public:
  
  ValveSwitchMap(const char *name, Widget parent, 
		 int nColumns,
		 const char *connectedValveItemName,
		 int nValves,
		 ValveControl **valves);

  ~ValveSwitchMap();

  virtual const char *className()
  {
    return "ValveSwitchMap";
  }

  virtual void updateGui(DM_Item handle = 0);
  

  // Connect specified valve to external switch  
  int connect(ValveControl *valve);

  // Reconnect last-connected valve
  int reconnect();

  // Disconnect specified valve from external switch if it is connected 
  int disconnect(ValveControl *valve);

  // Disable mapping of specified valve (0-based index). Return 0 on success,
  // -1 on error
  int disableMap(int valveNo);

  // Enable mapping of specified valve (0-based index). Return 0 on success,
  // -1 on error
  int enableMap(int valveNo);

  VkOptionMenu *menu;

  protected:

  int _nValves;
  ValveControl **_valves;
  ValveControl *_connectedValve;

  DmInt16Object *_dmConnectedValve;
  DmBooleanObject *_dmExternSwitchOpen;
  DmBooleanObject *_dmExternSwitchClose;
  
  // Called when user is starting to move a valve
  void startingValve(VkCallbackObject *obj,
		     void *clientData,
		     void *callData);

  // Called when user has stopped moving a valve
  void stoppedValve(VkCallbackObject *obj,
		    void *clientData,
		    void *callData);

  // Write valve number of connected valve to data manager item
  int writeConnectedValveNo(Int16 valveNo);

  void toggle(Widget w);
  
  private:
  static void toggleCallback(Widget w, 
			     XtPointer clientData,
			     XtPointer callData);
};



#endif
