/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
	Description:
	Cette classe consiste en un simulateur qui permet d'émuler les entrées/sorties
	Il offre aussi un générateur de scénarios pour simuler le passage d'un train et
	la génération de déclenchements.
	
*/

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

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

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

#include "ZTSimulator.h"
#include <QDialog>
#include "SimpleTextBoxWidget.h"
#include <QVBoxLayout>
#include "ZTPage.h"
#include <qmath.h>
#include "ZTconfigmgr.h"
#include <QFileDialog>
#include "TrainLogFileMgr.h"
#include "ZTData.h"
#include <QGraphicsProxyWidget>
#include <SwitchCDVItem.h>
#include <QTimer>


CZTSimulator::CZTSimulator(CSimulatorIOManager *IOMgrPtr)
{
    //static QGraphicsTextItem *Label;
//	Label = new QGraphicsTextItem("Simulateur",this);
	mIOMgrPtr = IOMgrPtr;
	mStationPtr = 0;
	mUSBDriveInterfacePtr = 0;


	mSimThread = new QThread;
	mSimWorkerThread = new CSimulatorThread();
	mSimWorkerThread->moveToThread(mSimThread);
	connect(mSimThread,SIGNAL(started()),mSimWorkerThread,SLOT(StartSim()));
	connect(mSimWorkerThread,SIGNAL(SimFinished()),this,SLOT(FileSimFinished()));
	mSimLogElement = 0;

	mFileSimLoopDelayTimer.setSingleShot(true);
	connect(&mFileSimLoopDelayTimer,SIGNAL(timeout()),this,SLOT(FileLoopDelayExpired()));
}

CZTSimulator::~CZTSimulator()
{
	delete mLazerProbesUpdateTimer;
	delete mSimulationElapsedTimer;
	mSimThread->quit();
	mSimThread->wait(1000);
	delete mSimThread;
	delete mSimWorkerThread;
	DestroyLogElement();
}

void CZTSimulator::Show()
{
	QGraphicsRectItem *BoundingRect = new QGraphicsRectItem(rect(),this);
	Q_UNUSED(BoundingRect)
}

void CZTSimulator::SetPGTreshold(qint32 Treshold)
{
	mPGTreshold = Treshold;
}

unsigned int CZTSimulator::Init(CZTPage *MainPagePtr, CStation *Station, CIOManager *IOMgrPtr,CPCIIOMgr *PCIIO,CAbstractLazerProbeMgr *LazerProbesMgr,CUSBDriveInterface *UsbDriveInterface, CAnalogInputModule *RealAnalogModule)
{
	mMainPagePtr = MainPagePtr;
	mStationPtr = Station;
	mPCIIO = (CSimulatorPCIIO*)PCIIO;
	mLazerProbesMgr = (CSimulatorLazerProbesMgr*)LazerProbesMgr;
	mIOMgrPtr = (CSimulatorIOManager*)IOMgrPtr;

	mInternalLazerProbe = (CSimulatorLazerProbe*)mLazerProbesMgr->GetLazerProbeHandle(LAZER_PROBE_TYPE_INTERNAL,1);
	mExternalLazerProbe = (CSimulatorLazerProbe*)mLazerProbesMgr->GetLazerProbeHandle(LAZER_PROBE_TYPE_EXTERNAL,1);
	mLazerProbesUpdateTimer = new QTimer();
	mLazerProbesUpdateTimer->setSingleShot(false);
//	mPGEValue = mPGIValue =  CZTConfigMgr::instance()->GetLaserSensorCalib() - 50;	//Init low

	mStationInputMasks = mStationPtr->GetInputMasks();	//the station inputs are kind of simulator outputs...
	mStationOutputMasks = mStationPtr->GetOutputMasks();

	mInputModule = (CSimulatorInputModule*) mIOMgrPtr->GetModule(IO_MODULE_INPUT_TYPE,1);
	mOutputModule = (CSImulatorOutputModule*) mIOMgrPtr->GetModule(IO_MODULE_OUTPUT_TYPE,1);
    mOutputModule->BindSimPtr(this);
	connect(mOutputModule,SIGNAL(UpdateOutputsDisplay(quint32)),this,SLOT(UpdateOutputsDisplay(quint32)));
	mMixedModule = (CSimulatorMixedModule*) mIOMgrPtr->GetModule(IO_MODULE_MIXED_TYPE,1);

	if(RealAnalogModule != 0)   //If external module is not detected, try the DataQ module
    {
	   mMixedModule->BindRealExternalMixedModule(RealAnalogModule);
    }
    else
    {
        mMixedModule->BindRealExternalMixedModule(0);
    }


	mSimWorkerThread->Init(mInputModule,mOutputModule,mPCIIO,mInternalLazerProbe,mExternalLazerProbe,mStationInputMasks);

	mUSBDriveInterfacePtr = UsbDriveInterface;

	//Create Simulator GUI:


	//Create CDV graphical items list,
	//adjust all their position on screen and
	//set parameters
	for(int i = 0; i < mStationPtr->GetCDVList()->size(); i++)
	{
		int x = 0, y = 20;
		CCDVItem *NewCDVGraphicalItem;
		if(mStationPtr->GetCDVList()->at(i)->GetCDVType() == CDV_NORMAL_TYPE)
		{
            NewCDVGraphicalItem = new CCDVItem(mStationPtr->GetCDVList()->at(i),this);
		}
		else
		{
			//NewCDVGraphicalItem = new CSwitchCDVItem(mStationPtr->GetCDVList()->at(i),this);
            NewCDVGraphicalItem = new CCDVItem(mStationPtr->GetCDVList()->at(i),this);
		}
		NewCDVGraphicalItem->SetParameters(mStationPtr->GetCDVList()->at(i)->GetLabel());
		mSimCDVItemsList.append(NewCDVGraphicalItem);
		NewCDVGraphicalItem->resize(70,20);
		x = (mStationPtr->GetCDVList()->at(i)->GetCDVGraphicalPos() * NewCDVGraphicalItem->geometry().width())+5;
		if(mStationPtr->GetCDVList()->at(i)->GetCDVWay() == 2)
			y = 50;
		NewCDVGraphicalItem->setPos(x,y);
		connect(NewCDVGraphicalItem,SIGNAL(CDVRightClicked(CCDVItem*)),this,SLOT(CDVItemRightClicked(CCDVItem*)));
		//start with all CDVs free
        mInputModule->SetInputBufFlags(mStationPtr->GetCDVList()->at(i)->GetInputMask());

	}

    //Buttons
    mITIZT1ToggleBtn = new CToggleTextButtonWidget(QString("Détruire\nITI ZT1"),QString("Commander\nITI ZT1"),QPixmap(),QPixmap(),50,100,15,0);
	mITIZT1ToggleBtn->setParentItem(this);
	mITIZT1ToggleBtn->setPos(5,110);
	connect(mITIZT1ToggleBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ItineraryToggleSwitchActivate(CToggleTextButtonWidget*)));
	connect(mITIZT1ToggleBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ItineraryToggleSwitchDeActivate(CToggleTextButtonWidget*)));

    if(mStationInputMasks->InputZT1_AltITIMask != 0)
    {
        mITIZT1AltToggleBtn = new CToggleTextButtonWidget(QString("Détruire\nITI ZT1(10/22)"),QString("Commander\nITI ZT1(10/22)"),QPixmap(),QPixmap(),50,100,13,0);
        mITIZT1AltToggleBtn->setParentItem(this);
        mITIZT1AltToggleBtn->setPos(115,110);
        connect(mITIZT1AltToggleBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ItineraryToggleSwitchActivate(CToggleTextButtonWidget*)));
        connect(mITIZT1AltToggleBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ItineraryToggleSwitchDeActivate(CToggleTextButtonWidget*)));
    }

    mITIZT2ToggleBtn = new CToggleTextButtonWidget(QString("Détruire\nITI ZT2"),QString("Commander\nITI ZT2"),QPixmap(),QPixmap(),50,100,15,0);
	mITIZT2ToggleBtn->setParentItem(this);
	mITIZT2ToggleBtn->setPos(5,170);
	connect(mITIZT2ToggleBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ItineraryToggleSwitchActivate(CToggleTextButtonWidget*)));
	connect(mITIZT2ToggleBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ItineraryToggleSwitchDeActivate(CToggleTextButtonWidget*)));

	mS1SimBtn = new CToggleTextButtonWidget(QString("S1"),QString("S1"),QPixmap(),QPixmap());
	mS1SimBtn->setParentItem(this);
	mS1SimBtn->setPos(300,110);
	connect(mS1SimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnActivate(CToggleTextButtonWidget*)));
	connect(mS1SimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnDeActivate(CToggleTextButtonWidget*)));

	mS2SimBtn = new CToggleTextButtonWidget(QString("S2"),QString("S2"),QPixmap(),QPixmap());
	mS2SimBtn->setParentItem(this);
	mS2SimBtn->setPos(250,110);
	connect(mS2SimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnActivate(CToggleTextButtonWidget*)));
	connect(mS2SimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnDeActivate(CToggleTextButtonWidget*)));

	mFNSimBtn = new CToggleTextButtonWidget(QString("FN"),QString("FN"),QPixmap(),QPixmap());
	mFNSimBtn->setParentItem(this);
	mFNSimBtn->setPos(350,110);
	connect(mFNSimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnActivate(CToggleTextButtonWidget*)));
	connect(mFNSimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnDeActivate(CToggleTextButtonWidget*)));

	mPPESimBtn = new CToggleTextButtonWidget(QString("PPE"),QString("PPE"),QPixmap(),QPixmap());
	mPPESimBtn->setParentItem(this);
	mPPESimBtn->setPos(400,110);
    connect(mPPESimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnActivate(CToggleTextButtonWidget*)));
	connect(mPPESimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnDeActivate(CToggleTextButtonWidget*)));

	mPPISimBtn = new CToggleTextButtonWidget(QString("PPI"),QString("PPI"),QPixmap(),QPixmap());
	mPPISimBtn->setParentItem(this);
	mPPISimBtn->setPos(450,110);
	connect(mPPISimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnActivate(CToggleTextButtonWidget*)));
	connect(mPPISimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnDeActivate(CToggleTextButtonWidget*)));

    mZT2S1SimBtn = new CToggleTextButtonWidget(QString("S1 ZT2"),QString("S1 ZT2"),QPixmap(),QPixmap());
    mZT2S1SimBtn->setParentItem(this);
    mZT2S1SimBtn->setPos(250,150);
    connect(mZT2S1SimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnActivate(CToggleTextButtonWidget*)));
    connect(mZT2S1SimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnDeActivate(CToggleTextButtonWidget*)));

    mZT2PPESimBtn = new CToggleTextButtonWidget(QString("PPE ZT2"),QString("PPE ZT2"),QPixmap(),QPixmap());
    mZT2PPESimBtn->setParentItem(this);
    mZT2PPESimBtn->setPos(325,150);
    connect(mZT2PPESimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnActivate(CToggleTextButtonWidget*)));
    connect(mZT2PPESimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnDeActivate(CToggleTextButtonWidget*)));

    mZT2PPISimBtn = new CToggleTextButtonWidget(QString("PPI ZT2"),QString("PPI ZT2"),QPixmap(),QPixmap());
    mZT2PPISimBtn->setParentItem(this);
    mZT2PPISimBtn->setPos(410,150);
    connect(mZT2PPISimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnActivate(CToggleTextButtonWidget*)));
    connect(mZT2PPISimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnDeActivate(CToggleTextButtonWidget*)));

    mAN1SimBtn = new CToggleTextButtonWidget(QString("AN1"),QString("AN1"),QPixmap(),QPixmap());
    mAN1SimBtn->setParentItem(this);
    mAN1SimBtn->setPos(250,190);
    connect(mAN1SimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnActivate(CToggleTextButtonWidget*)));
    connect(mAN1SimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT1SensorBtnDeActivate(CToggleTextButtonWidget*)));

    mAN2SimBtn = new CToggleTextButtonWidget(QString("AN2"),QString("AN2"),QPixmap(),QPixmap());
    mAN2SimBtn->setParentItem(this);
    mAN2SimBtn->setPos(300,190);
    connect(mAN2SimBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnActivate(CToggleTextButtonWidget*)));
    connect(mAN2SimBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(ZT2SensorBtnDeActivate(CToggleTextButtonWidget*)));


	mSimulationStartBtn = new CPushButton(this,"./Images/Play Normal.png");
	mSimulationStartBtn->setPos(320,225);
	mSimulationStartBtn->resize(50,50);
	connect(mSimulationStartBtn,SIGNAL(clicked(CPushButton*)),this,SLOT(SimulationScenarioButtonPressed(CPushButton*)));

	mSimFileOpenBtn = new CPushButton(this,"./Images/open-file-icon.png");
	mSimFileOpenBtn->setPos(250,225);
	mSimFileOpenBtn->resize(50,50);
	connect(mSimFileOpenBtn,SIGNAL(clicked(CPushButton*)),this,SLOT(SimulationScenarioButtonPressed(CPushButton*)));

	QGraphicsProxyWidget *Proxy = new QGraphicsProxyWidget(this);
    mLoopSimCheckbox = new QCheckBox("Loop Simulation");
	Proxy->setWidget(mLoopSimCheckbox);
    Proxy->setPos(5,325);
    mLoopSimCheckbox->show();

    Proxy = new QGraphicsProxyWidget(this);
    mProbesAliveCheckBox = new QCheckBox("Lazer defect.");
    Proxy->setWidget(mProbesAliveCheckBox);
    Proxy->setPos(5,225);
    connect(mProbesAliveCheckBox,SIGNAL(stateChanged(int)),this,SLOT(SimulDefectLazerCheckboxChanged(int)));

	mScenario = new CSimulationScenario;
	connect(mScenario,SIGNAL(ExecuteNextStep(CSimulationStep*)),this,SLOT(SimulationScenarioExecStep(CSimulationStep*)));
	connect(mScenario,SIGNAL(ScenarioCompleted()),this,SLOT(SimulationScenarioFinished()));
	mScenario->CreateScenario();

	connect(mLazerProbesUpdateTimer,SIGNAL(timeout()),this,SLOT(LazerProbesSimTimerExpired()));
	mSimulationElapsedTimer = new QElapsedTimer();

	Proxy = new QGraphicsProxyWidget(this);
	mUSBKeyEmuEnableCheckBox = new QCheckBox("Emulation\nClef USB");
	Proxy->setWidget(mUSBKeyEmuEnableCheckBox);
	Proxy->setPos(5,250);
	connect(mUSBKeyEmuEnableCheckBox,SIGNAL(stateChanged(int)),this,SLOT(USBEmulationCheckboxChanged(int)));

	mUSBKeyPresenceToggleBtn = new CToggleTextButtonWidget(QString("Branchée"),QString("Débranchée"),QPixmap(),QPixmap(),25,100);
	mUSBKeyPresenceToggleBtn->setParentItem(this);
	mUSBKeyPresenceToggleBtn->setPos(8,300);
	mUSBKeyPresenceToggleBtn->hide();
	connect(mUSBKeyPresenceToggleBtn,SIGNAL(ToggleBtnActivate(CToggleTextButtonWidget*)),this,SLOT(USBEmulationPresenceToggled(CToggleTextButtonWidget*)));
	connect(mUSBKeyPresenceToggleBtn,SIGNAL(ToggleBtnDeActivate(CToggleTextButtonWidget*)),this,SLOT(USBEmulationPresenceToggled(CToggleTextButtonWidget*)));


    int row = 300, col = 250;
    QString label;

    for(int Led = 0; Led < GENERIC_OUTPUT_NB_ID; Led++)
    {
        switch(Led)
        {
            case GENERIC_OUTPUT_VP1_ID:
            {
                label = "VP1";
                break;
            }
            case GENERIC_OUTPUT_VP2_ID:
            {
                label = "VP2";
                break;
            }
            case GENERIC_OUTPUT_VP3_ID:
            {
                label = "VP3";
                break;
            }
            case GENERIC_OUTPUT_VP4_ID:
            {
                label = "VP4";
                break;
            }
            case GENERIC_OUTPUT_VP5_ID:
            {
                label = "VP5";
                break;
            }
            case GENERIC_OUTPUT_VP6_ID:
            {
                label = "VP6";
                break;
            }
            case GENERIC_OUTPUT_DPE_ID:
            {
                label = "PPE";
                break;
            }
            case GENERIC_OUTPUT_DPI_ID:
            {
                label = "PPI";
                break;
            }
            case GENERIC_OUTPUT_V00_ID:
            {
                label = "V00";
                break;
            }
            case GENERIC_OUTPUT_VF1_ID:
            {
                label = "VF1";
                row += 50;
                col = 250;
                break;
            }
            case GENERIC_OUTPUT_VF2_ID:
            {
                label = "VF2";
                break;
            }
            case GENERIC_OUTPUT_VF3_ID:
            {
                label = "VF3";
                break;
            }
            case GENERIC_OUTPUT_VF4_ID:
            {
                label = "VF4";
                break;
            }
            case GENERIC_OUTPUT_VF5_ID:
            {
                label = "VF5";
                break;
            }
            case GENERIC_OUTPUT_DPG_ID:
            {
                label = "DPG";
                break;
            }
            case GENERIC_OUTPUT_DFR_ID:
            {
                label = "DFR";
                break;
            }
            case GENERIC_OUTPUT_RF_ID:
            {
                label = "RF";
                break;
            }
            case GENERIC_OUTPUT_VEL_ID:
            {
                label = "VEL";
                break;
            }
            case GENERIC_OUTPUT_VEL2_ID:
            {
                label = "VEL2";
                break;
            }
            case GENERIC_OUTPUT_WP1_ID:
            {
                label = "WP1";
                row += 50;
                col = 250;
                break;
            }
            case GENERIC_OUTPUT_WP2_ID:
            {
                label = "WP2";
                break;
            }
            case GENERIC_OUTPUT_WP3_ID:
            {
                label = "WP3";
                break;
            }
            case GENERIC_OUTPUT_WP4_ID:
            {
                label = "WP4";
                break;
            }
            case GENERIC_OUTPUT_WP5_ID:
            {
                label = "WP5";
                break;
            }
            case GENERIC_OUTPUT_WP6_ID:
            {
                label = "WP6";
                break;
            }
            case GENERIC_OUTPUT_DPI2_ID:
            {
                label = "PPI2";
                break;
            }
            case GENERIC_OUTPUT_DPE2_ID:
            {
                label = "PPE2";
                break;
            }
            case GENERIC_OUTPUT_V002_ID:
            {
                label = "V002";
                break;
            }
            case GENERIC_OUTPUT_RF2_ID:
            {
                label = "RF2";
                break;
            }
            case GENERIC_OUTPUT_PEQ1_ID:
            {
                label = "PEQ1";
                row = 300;
                col = 150;
                break;
            }
            case GENERIC_OUTPUT_PEQ2_ID:
            {
                row = 350;
                col = 150;
                label = "PEQ2";
                break;
            }
            case GENERIC_OUTPUT_WATCHDOG_ID:
            {
                row = 400;
                col = 150;
                label = "VIGIE";
                break;
            }
        }

        LedWidget[Led] = new CLedWidget(label,this);
        LedWidget[Led]->setPos(col,row);

		col += 35;
    }

    mPPISimBtn->ForceActivation(true);
    mPPESimBtn->ForceActivation(true);
    mZT2PPESimBtn->ForceActivation(true);
    mZT2PPISimBtn->ForceActivation(true);
	mFNSimBtn->ForceActivation(true);

    UpdateSimulatorDisplay();

	return RET_OK;
}

void CZTSimulator::UpdateSimulatorDisplay()
{
	for(int i = 0; i < mSimCDVItemsList.size(); i++)
		mSimCDVItemsList.at(i)->UpdateState();
}

void CZTSimulator::CDVItemRightClicked(CCDVItem *ClickedItem)
{
	CCDV *CDVPtr = ClickedItem->GetCDV();

	switch(CDVPtr->GetCDVState())
	{
		case CDV_STATE_FREE:
		case CDV_STATE_ITI_CMD:
		{
			mInputModule->ClearInputBufFlags(CDVPtr->GetInputMask());
			break;
		}
		case CDV_STATE_OCCUPIED:
		{
			mInputModule->SetInputBufFlags(CDVPtr->GetInputMask());
			break;
		}
	}
}

void CZTSimulator::ItineraryToggleSwitchActivate(CToggleTextButtonWidget *Button)
{
	if(Button == mITIZT1ToggleBtn)
	{
        mInputModule->SetInputBufFlags(mStationInputMasks->InputZT1_StdITIMask);
	}
    else if(Button == mITIZT1AltToggleBtn)
    {
        mInputModule->SetInputBufFlags(mStationInputMasks->InputZT1_AltITIMask);
    }
	else if(Button == mITIZT2ToggleBtn)
	{
		mInputModule->SetInputBufFlags(mStationInputMasks->InputZT2ITIMask);
	}
	else
		return;

}

void CZTSimulator::ItineraryToggleSwitchDeActivate(CToggleTextButtonWidget *Button)
{
	if(Button == mITIZT1ToggleBtn)
	{
        mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT1_StdITIMask);
	}
    else if(Button == mITIZT1AltToggleBtn)
    {
        mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT1_AltITIMask);
    }
	else if(Button == mITIZT2ToggleBtn)
	{
		mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT2ITIMask);
	}
	else
		return;

}

void CZTSimulator::ZT1SensorBtnActivate(CToggleTextButtonWidget *SensorBtn)
{
	if(SensorBtn == mS1SimBtn)
	{
		mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1S1Mask);
	}
	if(SensorBtn == mS2SimBtn)
	{
		mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1S2Mask);
	}
	if(SensorBtn == mFNSimBtn)
	{
		mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1FNMask);
	}
	if(SensorBtn == mPPESimBtn)
	{
		mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1PEMask);
	}
	if(SensorBtn == mPPISimBtn)
	{
		mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1PIMask);
	}
    if(SensorBtn == mAN1SimBtn)
    {
        mInputModule->SetInputBufFlags(mStationInputMasks->InputZT1ANMask);
    }
}

void CZTSimulator::ZT1SensorBtnDeActivate(CToggleTextButtonWidget *SensorBtn)
{
	if(SensorBtn == mS1SimBtn)
	{
		mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1S1Mask);
	}
	if(SensorBtn == mS2SimBtn)
	{
		mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1S2Mask);
	}
	if(SensorBtn == mFNSimBtn)
	{
		mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1FNMask);
	}
	if(SensorBtn == mPPESimBtn)
	{
		mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1PEMask);
	}
	if(SensorBtn == mPPISimBtn)
	{
		mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1PIMask);
	}
    if(SensorBtn == mAN1SimBtn)
    {
        mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT1ANMask);
    }
}

void CZTSimulator::ZT2SensorBtnActivate(CToggleTextButtonWidget *Btn)
{
    if(Btn == mZT2S1SimBtn)
    {
        mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT2S1Mask);
    }
    if(Btn == mZT2PPISimBtn)
    {
        mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT2PIMask);
    }
    if(Btn == mZT2PPESimBtn)
    {
        mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT2PEMask);
    }
    if(Btn == mAN2SimBtn)
    {
        mInputModule->SetInputBufFlags(mStationInputMasks->InputZT2ANMask);
    }
}
void CZTSimulator::ZT2SensorBtnDeActivate(CToggleTextButtonWidget *Btn)
{
    if(Btn == mZT2S1SimBtn)
    {
        mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT2S1Mask);
    }
    if(Btn == mZT2PPISimBtn)
    {
        mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT2PIMask);
    }
    if(Btn == mZT2PPESimBtn)
    {
        mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT2PEMask);
    }
    if(Btn == mAN2SimBtn)
    {
        mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT2ANMask);
    }
}

void CZTSimulator::SimulationScenarioButtonPressed(CPushButton *Btn)
{
	Q_UNUSED(Btn)

	if(Btn == mSimulationStartBtn)
	{
		if(mSimLogElement != 0)
		{
			mSimWorkerThread->SetLogElement(mSimLogElement);
			mSimThread->start(QThread::NormalPriority);
		}
		else
		{
			StartSim();
		}

	}
	else if(Btn == mSimFileOpenBtn)
	{
		QString SimFilePath = QFileDialog::getOpenFileName(0, tr("Fichier de passage"), "./Trains", tr("Passages (*.bin)"));

		if(SimFilePath.isEmpty() == false)
		{
			unsigned int ret;
			DestroyLogElement();

			mSimLogElement = CTrainLogFileMgr::instance()->OpenTrainLog(SimFilePath,ret,0,true);
		}

	}

//	mSimulationElapsedTimer->restart();
//	mLazerProbesUpdateTimer->start(SIM_LAZER_PROBES_UPDATE_TIMEOUT);
//	mScenario->Start();
}

void CZTSimulator::DestroyLogElement()
{
	if(mSimLogElement == 0)
		return;

	if(mSimLogElement->mZTLogType == ZT1_LOG_TYPE)
	{
		CZT1LogElement *temp = (CZT1LogElement*)mSimLogElement;
		delete temp;
//		for(int i = 0; i < temp->mZTLogData.size(); i++)
//			delete temp->mZTLogData.at(i);
//		temp->mZTLogData.clear();
	}
	if(mSimLogElement->mZTLogType == ZT2_LOG_TYPE)
	{
		CZT2LogElement *temp = (CZT2LogElement*)mSimLogElement;
		delete temp;
/*		for(int i = 0; i < temp->mZTLogData.size(); i++)
			delete temp->mZTLogData.at(i);
		temp->mZTLogData.clear()*/;
	}

	delete mSimLogElement;
	mSimLogElement = 0;
}

void CZTSimulator::StartSim()
{
	mInternalLazerProbe->SetData(mPGIValue);
	mExternalLazerProbe->SetData(mPGEValue);
	mSimulationElapsedTimer->restart();
	//mLazerProbesUpdateTimer->start(SIM_LAZER_PROBES_UPDATE_TIMEOUT);
	mScenario->Start();
}

void CZTSimulator::SimulationScenarioExecStep(CSimulationStep *Step)
{

//    static quint32 temp = 1;
//    mOutputModule->ClearOutputFlags(temp);
//    temp <<= 1;
	switch(Step->StepAction)
	{
		case STEP_ACTION_DELAY:
		{
			break;
		}
		case STEP_ACTION_ACTIVATE_S1:
		{
			mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1S1Mask);
			break;
		}
		case STEP_ACTION_DEACTIVATE_S1:
		{
			mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1S1Mask);
			break;
		}
		case STEP_ACTION_ACTIVATE_S2:
		{
			mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1S2Mask);
			break;
		}
		case STEP_ACTION_DEACTIVATE_S2:
		{
			mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1S2Mask);
			break;
		}
		case STEP_ACTION_ACTIVATE_FN:
		{
			mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1FNMask);
			break;
		}
		case STEP_ACTION_DEACTIVATE_FN:
		{
			mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1FNMask);
			break;
		}
		case STEP_ACTION_ACTIVATE_PPI:
		{
            mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1PIMask);
			break;
		}
		case STEP_ACTION_DEACTIVATE_PPI:
		{
            mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1PIMask);
			break;
		}
		case STEP_ACTION_ACTIVATE_PPE:
		{
            mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT1PEMask);
			break;
		}
		case STEP_ACTION_DEACTIVATE_PPE:
		{
            mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT1PEMask);
			break;
		}
		case STEP_ACTION_ACTIVATE_PGI:
		{
            mPGIValue = (mPGTreshold * mPGTreshold) + 50;
			mInternalLazerProbe->SetData(mPGIValue);
			break;
		}
		case STEP_ACTION_DEACTIVATE_PGI:
		{
            mPGIValue = mPGTreshold;
			mInternalLazerProbe->SetData(mPGIValue);
			break;
		}
		case STEP_ACTION_ACTIVATE_PGE:
		{
            mPGEValue = (mPGTreshold * mPGTreshold) + 50;
			mExternalLazerProbe->SetData(mPGEValue);
			break;
		}
		case STEP_ACTION_DEACTIVATE_PGE:
		{
            mPGEValue = mPGTreshold;
			mExternalLazerProbe->SetData(mPGEValue);
			break;
		}
		case STEP_ACTION_REGISTER_ZT1_ITI:
		{
			mInputModule->SetInputBufFlags(mStationInputMasks->InputZT1ITIMask);
			break;
		}
		case STEP_ACTION_DESTROY_ZT1_ITI:
		{
			mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT1ITIMask);
			break;
		}
		case STEP_ACTION_REGISTER_ZT2_ITI:
		{
			mInputModule->SetInputBufFlags(mStationInputMasks->InputZT2ITIMask);
			break;
		}
		case STEP_ACTION_DESTROY_ZT2_ITI:
		{
			mInputModule->ClearInputBufFlags(mStationInputMasks->InputZT2ITIMask);
			break;
		}
		case STEP_ACTION_OCCUPY_ZT1_APPROACH:
		{
			CCDV *ApproachCDVPtr = mStationPtr->GetZT1ApproachCDV();
			for(int i = 0; i < mSimCDVItemsList.size(); i++)
			{
				if(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask() == ApproachCDVPtr->GetInputMask())
				{
					mInputModule->ClearInputBufFlags(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask());
					break;
				}
			}

			break;
		}
		case STEP_ACTION_FREE_ZT1_APPROACH:
		{
			CCDV *ApproachCDVPtr = mStationPtr->GetZT1ApproachCDV();
			for(int i = 0; i < mSimCDVItemsList.size(); i++)
			{
				if(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask() == ApproachCDVPtr->GetInputMask())
				{
					mInputModule->SetInputBufFlags(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask());
					break;
				}
			}
			break;
		}
		case STEP_ACTION_OCCUPY_ZT1:
		{
			CCDV *ZT1CDVPtr = mStationPtr->GetZT1CDV();
			for(int i = 0; i < mSimCDVItemsList.size(); i++)
			{
				if(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask() == ZT1CDVPtr->GetInputMask())
				{
					mInputModule->ClearInputBufFlags(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask());
					break;
				}
			}
			break;
		}
		case STEP_ACTION_FREE_ZT1:
		{
			CCDV *ZT1CDVPtr = mStationPtr->GetZT1CDV();
			for(int i = 0; i < mSimCDVItemsList.size(); i++)
			{
				if(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask() == ZT1CDVPtr->GetInputMask())
				{
					mInputModule->SetInputBufFlags(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask());
					break;
				}
			}
			break;
		}
		case STEP_ACTION_OCCUPY_ZT2_APPROACH:
		{
			break;
		}
		case STEP_ACTION_FREE_ZT2_APPROACH:
		{
			break;
		}
		case STEP_ACTION_OCCUPY_ZT2:
		{
			CCDV *ZT2CDVPtr = mStationPtr->GetZT2CDV();
			for(int i = 0; i < mSimCDVItemsList.size(); i++)
			{
				if(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask() == ZT2CDVPtr->GetInputMask())
				{
					mInputModule->ClearInputBufFlags(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask());
					break;
				}
			}
			break;
		}
		case STEP_ACTION_FREE_ZT2:
		{
			CCDV *ZT2CDVPtr = mStationPtr->GetZT2CDV();
			for(int i = 0; i < mSimCDVItemsList.size(); i++)
			{
				if(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask() == ZT2CDVPtr->GetInputMask())
				{
					mInputModule->SetInputBufFlags(mSimCDVItemsList.at(i)->GetCDV()->GetInputMask());
					break;
				}
			}
			break;
		}
        case STEP_ACTION_ACTIVATE_ZT2_S1:
        {
            mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT2S1Mask);
            break;
        }
        case STEP_ACTION_DEACTIVATE_ZT2_S1:
        {
            mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT2S1Mask);
            break;
        }
        case STEP_ACTION_ACTIVATE_ZT2_PPI:
        {
            mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT2PIMask);
            break;
        }
        case STEP_ACTION_DEACTIVATE_ZT2_PPI:
        {
             mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT2PIMask);
            break;
        }
        case STEP_ACTION_ACTIVATE_ZT2_PPE:
        {
             mPCIIO->ClearInputBufFlags(mStationInputMasks->InputZT2PEMask);
            break;
        }
        case STEP_ACTION_DEACTIVATE_ZT2_PPE:
        {
            mPCIIO->SetInputBufFlags(mStationInputMasks->InputZT2PEMask);
            break;
        }
		case STEP_ACTION_SCENARIO_END:
		{
			break;
		}
	}

}
void CZTSimulator::SimulationScenarioFinished()
{
	mLazerProbesUpdateTimer->stop();
    if(mLoopSimCheckbox->checkState() == Qt::Checked)
	{
		StartSim();
	}

}

void CZTSimulator::LazerProbesSimTimerExpired()
{
    static qreal inc=1;
    //qreal sine = qSin(mSimulationElapsedTimer->elapsed());
    qreal sine = qSin(++inc/10);
    sine += 1;
    sine /= 2;
//	int Calib = 500000;//CZTConfigMgr::instance()->GetLaserSensorCalib();
    //int value = (int)(Calib*sine);

	//mPGEValue = mPGIValue = value;
	//mPGEValue = mPGIValue = 0;

	mInternalLazerProbe->SetData(mPGIValue);
	mExternalLazerProbe->SetData(mPGEValue);
}

void CZTSimulator::FileSimFinished()
{
	mSimThread->quit();
	mSimThread->wait();

    if(mLoopSimCheckbox->checkState() == Qt::Checked)
	{
		mFileSimLoopDelayTimer.start(1000);
//		mSimThread->start(QThread::NormalPriority);
	}
}

void CZTSimulator::UpdateOutputsDisplay(quint32 Outputs)
{
    if((Outputs & mStationOutputMasks->OutputVP1Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VP1_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VP1_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVP2Mask) != 0)
    {

        LedWidget[GENERIC_OUTPUT_VP2_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VP2_ID]->LedOFF();

    }
    if((Outputs & mStationOutputMasks->OutputVP3Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VP3_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VP3_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVP4Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VP4_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VP4_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVP5Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VP5_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VP5_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVP6Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VP6_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VP6_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVF1Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VF1_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VF1_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVF2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VF2_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VF2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVF3Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VF3_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VF3_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVF4Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VF4_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VF4_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVF5Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VF5_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VF5_ID]->LedOFF();
    }

    if((Outputs & mStationOutputMasks->OutputWP1Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WP1_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WP1_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputWP2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WP2_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WP2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputWP3Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WP3_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WP3_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputWP4Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WP4_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WP4_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputWP5Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WP5_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WP5_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputWP6Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WP6_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WP6_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputDPEMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_DPE_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_DPE_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputDPIMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_DPI_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_DPI_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputV00Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_V00_ID]->LedON();


    }
    else
    {
        LedWidget[GENERIC_OUTPUT_V00_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputDPGMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_DPG_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_DPG_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputDFRMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_DFR_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_DFR_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputRFMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_RF_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_RF_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputRF2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_RF2_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_RF2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVELMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VEL_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VEL_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputVEL2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_VEL2_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_VEL2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputDPI2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_DPI2_ID]->LedON();

    }
    else
    {
        LedWidget[GENERIC_OUTPUT_DPI2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputDPE2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_DPE2_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_DPE2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputV002Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_V002_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_V002_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputPEQ1Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_PEQ1_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_PEQ1_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputPEQ2Mask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_PEQ2_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_PEQ2_ID]->LedOFF();
    }
    if((Outputs & mStationOutputMasks->OutputWatchdogMask) != 0)
    {
        LedWidget[GENERIC_OUTPUT_WATCHDOG_ID]->LedON();
    }
    else
    {
        LedWidget[GENERIC_OUTPUT_WATCHDOG_ID]->LedOFF();
    }
}


void CZTSimulator::FileLoopDelayExpired()
{
	mSimThread->start(QThread::NormalPriority);
}

void CZTSimulator::USBEmulationCheckboxChanged(int state)
{
	if(state == Qt::Checked)
	{
		mUSBKeyPresenceToggleBtn->show();
		mUSBDriveInterfacePtr->EnableDriveEmulation(true);
	}
	else
	{
		mUSBKeyPresenceToggleBtn->hide();
		mUSBDriveInterfacePtr->EnableDriveEmulation(false);
	}
}

void CZTSimulator::USBEmulationPresenceToggled(CToggleTextButtonWidget *btn)
{
	if(btn->GetActivationState() == true)
	{
		qDebug("Branchée");
		mUSBDriveInterfacePtr->EmulateDrivePresence(true);
	}
	else
	{
		qDebug("Débranchée");
		mUSBDriveInterfacePtr->EmulateDrivePresence(false);
	}
}

void CZTSimulator::SimulDefectLazerCheckboxChanged(int state)
{
    if(state == Qt::Checked)
    {
        mInternalLazerProbe->SetProbeDead();
        mExternalLazerProbe->SetProbeDead();
    }
    else
    {
        mInternalLazerProbe->SetProbeAlive();
        mExternalLazerProbe->SetProbeAlive();
    }
}

