/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _ALARMEDITOR_H
#define _ALARMEDITOR_H
static char AlarmEditor_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/AlarmEditor.h,v 1.4 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: AlarmEditor.h,v $
Revision 1.4  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.3  1997/10/03 09:23:19  oreilly
Added PsuAlarmText

 * Revision 1.2  97/08/12  14:14:34  14:14:34  oreilly (Thomas C. O'Reilly)
 * Display thresholds and monitored item for GraduatedAlarms
 * 
 * Revision 1.1  96/10/28  09:13:12  09:13:12  oreilly (Thomas C. O'Reilly)
 * Initial revision
 * 
*/

#include <Vk/VkComponent.h>
#include "SystemAlarms.h"
#include "MonitoredValue.h"
#include "LabeledText.h"
#include "DmText.h"
#include "PsuAlarmText.h"

// MaxAlarmValue is the maximum number of values associated with any
// of the Alarm classes
#define MaxAlarmValue 8



/*
CLASS 
ValueBox

DESCRIPTION
Manages creation and destruction of GUI elements and DmObjects
associated with Alarm objects.

AUTHOR
Tom O'Reilly
*/
class ValueBox : public VkComponent
{
  public:

  ValueBox(const char *name, Widget parent);
  ~ValueBox();
  
  virtual const char *className()
  {
    return "ValueBox";
  }
  
  ///////////////////////////////////////////////////////////////////
  // Delete any associated GUI elements and DmObjects
  void clear();

  protected:

  ///////////////////////////////////////////////////////////////////
  // Display specified error message
  void setErrorLabel(char *buf);

  ///////////////////////////////////////////////////////////////////
  // Try to find DM_Item of specified name and type
  DM_Item findItem(const char *itemName, DM_Type *type);

  Widget _mgr;
  Widget _errorLabel;
  DmGuiObject *_value;
  DmObject *_dmObject;
  Pixel _errorFg, _errorBg;
};


/*
CLASS 
ThresholdBox

DESCRIPTION
Contains DmText which displays threshold value associated with IbcAlarm.
If threshold item is not found, displays error message.
Used by AlarmEditor.

AUTHOR
Tom O'Reilly
*/
class ThresholdBox : public ValueBox
{
  public:
  ThresholdBox(const char *name, Widget parent);
  ~ThresholdBox();
  
  virtual const char *className()
  {
    return "ThresholdBox";
  }
  
  int createThreshold(IbcAlarm *alarm, int value);
};


/*
CLASS 
MonitoredValueBox

DESCRIPTION
Contains AlarmedText which displays value monitored by GraduatedAlarm.
If item is not found, displays error message. Used by AlarmEditor.
 
AUTHOR
Tom O'Reilly
*/
class MonitoredValueBox : public ValueBox
{
  public:
  MonitoredValueBox(const char *name, Widget parent);
  ~MonitoredValueBox();
  
  virtual const char *className()
  {
    return "MonitoredValueBox";
  }
  
  int createValue(GraduatedAlarm *alarm);
};


/*
CLASS 
PsuValue

DESCRIPTION
Displays status corresponding to value of PsuAlarm. Used by AlarmEditor.

AUTHOR
Tom O'Reilly
*/
class PsuValue : public VkComponent
{
  public:
  
  PsuValue(const char *name, Widget parent);
  ~PsuValue();

  const char *className()
  {
    return "PsuValue";
  }

  void clear();
  int createDescription(PsuAlarm *alarm);

  protected:
  PsuAlarmText *_alarmText;
};


class AlarmSetupPanel;


/*
CLASS 
AlarmEditor

DESCRIPTION
AlarmEditor provides GUI for setting attributes of individual Alarm 
objects

AUTHOR
Tom O'Reilly
*/
class AlarmEditor : public VkComponent
{
  friend class AlarmSetupPanel;
  
  public: 
  AlarmEditor(const char *name, Widget parent);
  ~AlarmEditor();
  
  const char *className()
  {
    return "AlarmEditor";
  }
  
  // Update selected Alarm object with user input values
  void updateAlarmItem();

  // Select specified alarm item in scrolled list and display attributes
  void selectItem(char *name);

  protected:
  Widget _listWidget;
  Widget _entryMgr;
  Widget _itemName;
  Widget _itemType;
  LabeledText *_mnemonic;
  Widget _defaultPriority;
  Widget _ackAllChanges;
  SystemAlarms *_alarms;
  Widget _valueHeader;
  Widget _thresholdHeader;

  Widget _valueLabel[MaxAlarmValue];
  Widget _priorityToggleBox[MaxAlarmValue];
  ThresholdBox *_thresholdBox[MaxAlarmValue];
  DmText *_threshold[MaxAlarmValue];
  
  MonitoredValue *_monitoredValue;
  PsuValue *_psuValue;
  
  // Interface function for qsort
  static int stringCompare(const void *p1, const void *p2);
  
  void displayItem(char *name);
  
  private:

  static void listSelectCallback(Widget w, XtPointer clientData,
				 XtPointer callData);

};


#endif

