//////////////////////////////////////////////////////////////////////////////
//
//  Author      : Josh Grant
//  Date        : November 26th, 2001
//  File        : ParameterEditor.h
//  Description : Header file defining the ParameterEditor class
//
//////////////////////////////////////////////////////////////////////////////

#ifndef _PARAMETER_EDITOR_
#define _PARAMETER_EDITOR_

#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Inventor/SbBasic.h>
#include <Inventor/misc/SoCallbackList.h>
#include <Inventor/Xt/SoXtComponent.h>
#include <Inventor/fields/SoMFString.h>
#include <Inventor/fields/SoSFFloat.h>
#include <Inventor/fields/SoSFVec3f.h>
#include <Inventor/fields/SoSFString.h>

#include "SFScalarField.h"

//////////////////////////////////////////////////////////////////////////////
//
//  Class: ParameterEditor
//
//  A subclass of SoXtComponent used to create a simple interface for editing
//  the input parameters of the ScalarArithmitic engine, and the node
//  MarchingCubes. 
//
//////////////////////////////////////////////////////////////////////////////

class ParameterEditor : public SoXtComponent {
public:

  typedef void  PEScaleCB (Widget wdg,
		           ParameterEditor *editor,
		           XmScaleCallbackStruct *sd);

  typedef struct {
    SoSFFloat *xDim, *yDim, *zDim;
    SoSFFloat *isoval, *blendval, *vertBlend;
    SoSFVec3f *minBounds, *maxBounds;
    SoSFString *expression, *blendExpression;
    SoMFString *text;
    SFScalarField *data;
  } PE_t;

                    ParameterEditor    (Widget parent = NULL,
		                        const char *name = NULL,
		                        SbBool buildInsideParent = TRUE);

                    ~ParameterEditor ();

  // attach the the nodes we want to be edited
  void              attach             (ParameterEditor::PE_t *vars);

  // show the component
  virtual void      show               ();

  // hide the component
  virtual void      hide               ();

protected:
                    ParameterEditor    (Widget parent,
		                        const char *name,
		                        SbBool buildInsideParent,
		                        SbBool buildNow);

  // returns top widget ready for showing
  Widget            buildWidget        (Widget parent);

private:
  // pointers to editable nodes
  PE_t             *variables;

  // topmost widget
  Widget            mgrWidget;
  // text fields
  Widget            dims[3], minBounds[3], maxBounds[3], equation, blendEquation;
  // scale
  Widget            isoValue;
  Widget            blendValue;
  Widget            vertBlendValue;

  // called by all constructors
  void              constructorCommon  (SbBool buildNow);

  // sets all text field inputs to current values of node inputs
  void              setInputs          ();
  // sets all node inputs to current values of text fields
  void              sendInputs         ();
  // sets the text displayed in the viewer showing the current equation
  void              setText            ();
  void		    resetIsoRange	();
  
  // creates the scalar arithmitic controls
  Widget            buildArithControls (Widget parent,
					Arg args[], int n);
  // creates a scale Widget with a callback function attached to it  
  Widget            buildScaleWidget   (Widget parent,
					char *title,
					Arg args[], int n,
					Widget &scale,
					PEScaleCB *cb);

  // builds a row of 3 text fields based on the input parameters
  Widget            buildTextFields    (Widget parent,
			                char *title,
			                char *textTitles[3],
			                Widget textFields[3],
			                int width,
			                Arg args[], int n);
  // builds the expression text field
  Widget            buildExpression    (Widget parent,
			                char *title,
			                Arg args[], int n);

  // callback used by all text fields
  void static       textFieldCB        (Widget wdg,
					ParameterEditor *editor,
					XtPointer wdgData);
  // callback used by the scale, called everytime scale is moved
  void static       isoValueCB         (Widget wdg,
					ParameterEditor *editor,
					XmScaleCallbackStruct *sd);
  void static       blendValueCB       (Widget wdg,
					ParameterEditor *editor,
					XmScaleCallbackStruct *sd);
  void static       vertBlendValueCB   (Widget wdg,
					ParameterEditor *editor,
					XmScaleCallbackStruct *sd);
  // callback used by the expression widget to copy the clipboard
  void static       copyClipboard      (Widget wdg,
					ParameterEditor *editor,
					XtPointer wdgData);
};

#endif /* _PARAMETER_EDITOR_ */
