/*
* Title:	PhaseTableWin.h
* Author:	M.Thomas BEAM Ltd
* Date:		2007-04-03
*
* Contents:	Pupe Simulation mode setup
*
* Mod Rec:
*
*/

#ifndef PHASETABLEWIN_H
#define PHASETABLEWIN_H

#include <BString.h>
#include <qhbox.h>
#include <Control.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <qpushbutton.h>
#include <qtextedit.h>
#include <qlistbox.h>
#include <qtable.h>
#include <qlayout.h>
#include <qvbox.h>
#include <qgroupbox.h>
#include <qvgroupbox.h>
#include <qdialog.h>

#include <BQComboBox.h>

#include <TmsD.h>
#include <TmsC.h>
#include <TmsS.h>
#include <TmsLib.h>
#include <TmsCycleParam.h>
#include <TmsStateGui.h>

class DetailViewGui : public QDialog {
        Q_OBJECT
public:
			DetailViewGui();
	void		init(Tms::CycleParamEdit& cycleParam, int reset);
private:
	TmsStateGui*	ostateGui;
};

class CycleParamStateGui : public Tms::CycleParamState {
public:
	UInt32	enable;
};


/*! Configure System and setup user interface window. 
*
*/
class PhaseTableWin : public QWidget {
        Q_OBJECT
public:
        PhaseTableWin(QWidget* w,Control& c);
	~PhaseTableWin();

public slots:
	void	show();

private slots:
	void    update();			///< update Gui element to reflect current data
	BError  updateCycleTypes(); 		///< Updates known Server cycle types list
	void    updateCycleInfo(); 		///< Updates GUI to reflect selected cycle type
	void    updateCycleParamState(); 	///< Update GUI to reflect Cycle Param data
	
	

	void	loadFromFile();			///< Load cycle info from file
	void	loadFromTms();			///< Load cycle info from the server
	void	saveFile();			///< Save cycle defs file on file system
	void	saveTms();			///< Save cycle defs on remote TMS server
	void	deleteTms();			///< Delete cycle defs from remote TMS server
	void	updateDetails();		///< Updates the details
	void	viewDetails();			///< Save cycle defs file on file system

	void	addOffsets();			///< Add offest to all items in the phase delay table
	void	loadDefaults();			///< Load defaults for phase delays
	
	
	void 	enableStateEdit();
	void	setCyclePhaseParams();

	void	selectFile();			///< Invoke dialog to select a cycle definition file

	void	cycleStateComboPressed();
	void	addNextState();
	void	delLastState();

private:
	void	refreshParamState(Tms::CycleParamState s);
	
	void	createGridGroupBox(QVGroupBox*& g,BString title,QWidget*& w,QGridLayout*& l);
	void	addEditorToGrid(QGridLayout* g,QWidget* w,BString label,QWidget* editor,int row,int col);
	
	
	void		setParams();
	
	
	QString		uIntToStr(UInt32 v);
	QString		doubleToStr(double v);
	QString		uIntToHexStr(UInt32 v);
	
	void		warningDialog(BString title, BError err);
	int		confirmDialog(BString title, BString msg);

	Control&		ocontrol;
	
	QLineEdit*		ocycleType;
	QLineEdit*		oinfo;
	QLineEdit*		opllCycleStartFrequency;
	QLineEdit*		opllInitialFrequency;
	QLineEdit*		opllInitialFrequencyDelay;
	QLineEdit*		opllFrefGain;
	QLineEdit*		opllGain;
	QLineEdit*		opllDdsMinimum;
	QLineEdit*		opllDdsMaximum;

	QSpinBox*		ooffset;

	QLineEdit*		ofilename;

	QPushButton*		oselectFile;
	QPushButton*		oloadFromFile;
	QPushButton*		oloadFromTms;

	
	QPushButton*		oupload;
	QPushButton*		osaveFile;
	QPushButton*		odelete;
	QPushButton*		oupdate;
	QPushButton*		oviewDetails;
	QPushButton*		oloadDefaults;
	QPushButton*		oaddOffsets;
	
	QListBox*		ocycleTypes;
	QTable*			ophaseDelays;
	

	QPushButton*		oaddNextState;
	QPushButton*		odelLastState;
	
	BQComboBox*		ophaseNames;
	
	QVGroupBox * 		ostateSetups;
	QCheckBox*		oenableModifications;

	QLineEdit*		obunchMask;
	QLineEdit*		omean1Mask;
	QLineEdit*		omean2Mask;
	QLineEdit*		oloHarmonic;
	QLineEdit*		oloPhase;
	QCheckBox*		ouseLoFref;
	QCheckBox*		oacquireData;
	QLineEdit*		ogateWidth;
	QLineEdit*		ogatePhase;
	QLineEdit*		oblrWidth;
	QLineEdit*		oblrPhase;

	BList<Tms::CycleParamState> 	ocycleStates;
	Tms::CycleParamEdit	oparams;
	DetailViewGui*		odetailViewGui;
};
#endif
