/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
    Description du fichier si nécessaire.

*/

/* ************************************************************************** */
/* Revision:
### 20131021 JFM
    Verision d'origine.

### YYYMMDD Description du besoin ou du bug
    Description du changement.
 */

/* ************************************************************************** */


#ifndef ENGINEERINGPAGE_H
#define ENGINEERINGPAGE_H

#include "GlobalDefine.h"
#include <QGraphicsWidget>
#include "Guipage.h"
#include <QString>
#include "PushButton.h"
#include "ZTSimulator.h"
#include "TextButtonWidget.h"
#include "InputModule.h"

#include "PCIIOMgr.h"
#include "PasswordPrompt.h"
#include "ZTData.h"
#include <QCheckBox>
#include <QFileInfoList>
#include "USBDriveInterface.h"
#include "ToggleButtonWidget.h"
#include <QSpinBox>
#include "MixedModule.h"
#include "OutputModule.h"


class CZoneTest;

class CEngineeringPage : public CGuiPage
{
Q_OBJECT
public:
    ~CEngineeringPage();
	CEngineeringPage(QGraphicsWidget *Parent = 0);
	CPushButton *mToolsPushButton;
	CPasswordPrompt *mPasswordPrompt;
	bool mDisablePassword;


	void BindPointers(CZoneTest *ProgramHandle,CInputModule *InputModulePtr, COutputModule *OutputModulePtr, CPCIIOMgr *PCIIO,CZTSettingsData *ZTSettings,CUSBDriveInterface *USBInterface,CStation *StationPtr,CAnalogInputModule *AnalogInterface);
    void ZTLogFilesSettings(int NbLogFiles, bool KeepMPM10Logs, bool KeepZT1Logs, bool KeepZT2Logs);
    virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
	virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
	virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
	virtual void showEvent(QShowEvent *event);
	virtual void hideEvent(QHideEvent *event);
	virtual void ShowPage();
	void Init();

private:
	CZoneTest *mProgramHandle;
	CAnalogInputModule *mAnalogInterface;
	CInputModule *mInputModulePtr;
	COutputModule *mOutputModulePtr;

	CPCIIOMgr *mPCIIO;
	CZTSettingsData *mZTSettings;
	QGraphicsRectItem *mBackgroundRect;
	CStation *mStation;
    GenericInputMasks_t *mInputMasks;
    QList<CCDV*> *mCDVList;

	CTextButtonWidget *mCancelButton;
	CTextButtonWidget *mConvertCSVButton;
	CTextButtonWidget *mTestButton;
	CTextButtonWidget *mDeleteEngLogBtn;
    CTextButtonWidget *mModbusDataBtn;

	QGraphicsTextItem *mPCIIODataText;
	QGraphicsTextItem *mExternalInputDataText;
	QGraphicsTextItem *mRAMUsageText;
    QGraphicsTextItem *mIntLazerProbeValue;
    QGraphicsTextItem *mExtLazerProbeValue;
	QGraphicsTextItem *mAnalogSDFValue;
    QCheckBox *mExportZT1CSVChkBx,*mExportZT2CSVChkBx, *mHighResLogging;
    QCheckBox *mKeepAllMPM10Logs, *mKeepZT1Logs,*mKeepZT2Logs;
    QSpinBox *mNbLogFilesSpinBox;

    QGraphicsTextItem *mNbLogsText;
    CTextButtonWidget *mDeleteLogsButton;
	CTextButtonWidget *mArchiveLogsButton;
    CTextButtonWidget *mDeleteZTLogButton;

	CToggleButtonWidget *mPGCalibrationSwitch;
	QSpinBox *mPGTresholdValueSpinBox, *mPGNbPassagesForCalibSpinBox;
	CTextButtonWidget *mPGValueSetBtn, *mCopyCalibValueBtn;
	QGraphicsTextItem *mCalibResultText, *mActualPGTresholdValueText;


	CUSBDriveInterface *mUSBInterfacePtr;
	QGraphicsTextItem *mUSBFlashDetectionTxt;

	QTimer *mInfoUpdateTimer;

    QFileInfoList mLogFilesList;

	//Outputs control
	CToggleButtonWidget *OutputToggleBtn[GENERIC_OUTPUT_NB_ID];

    //Inputs monitor
    CLedWidget *mInputLeds[GENERIC_INPUT_NB_ID];
    QList<CLedWidget*> mInputLedsCDV;


	bool mAutoExportZT1CSV,mAutoExportZT2CSV;
	int mPGCalibTresholdValue;



    void RefreshLogsList();
    void DeleteAllLogs();
	void ArchiveLogFiles();

	CZT1LogData *mDummy[5000];




public slots:
	void ButtonClicked(CTextButtonWidget *);
	void UpdateInfo();
	void PasswordValid();
	void PasswordInvalid();
	void ZT1AutoCSVCheckBoxChanged(int);
	void ZT2AutoCSVCheckBoxChanged(int);
    void HighResLogCheckBoxChanged(int);
    void KeepZT1LogsCheckBoxChanged(int);
    void KeepZT2LogsCheckBoxChanged(int);
    void KeepAllMPM10LogsCheckBoxChanged(int);
	void OutputToggled(CToggleButtonWidget*);
    void LazerProbeDataAvailable(unsigned int,unsigned int);
	void PGCalibBtnToggled(CToggleButtonWidget*);
	void PGCalibFinished(int);
    void PGCalibUpdate(int,int);
    void MaxNbLogFilesChanged(int);

};

#endif // ENGINEERINGPAGE_H
