From a55770c6934ff05d2a7180eadd2422a9b2e3c81c Mon Sep 17 00:00:00 2001 From: jfmartel Date: Fri, 22 Sep 2017 14:54:46 -0400 Subject: [PATCH] Add a flashing event in the events bar when a ZT1 or ZT2 train passage is inhibited by CC (Modbus). --- Configuration/ZTSettings.ztc | Bin 30 -> 30 bytes sources/Event.cpp | 3 ++- sources/Event.h | 3 ++- sources/EventMgr.cpp | 17 ++++++++++++++++- sources/EventMgr.h | 2 ++ sources/GuiElements/EventItem.cpp | 23 ++++++++++++++++++----- sources/GuiElements/EventItem.h | 10 +++++++++- sources/GuiElements/EventsBar.cpp | 2 +- sources/ZTStateMachine.cpp | 14 ++++++++++++-- sources/ZTStateMachine.h | 5 +++-- sources/Zonetest.cpp | 28 +++++++++++++++++++++++++++- sources/Zonetest.h | 4 +++- 12 files changed, 95 insertions(+), 16 deletions(-) diff --git a/Configuration/ZTSettings.ztc b/Configuration/ZTSettings.ztc index 1383fd4d3acc85f08a3888c6b88b58b38e4d670c..10ab104e374e6604a912404bb08621055ef9906c 100644 GIT binary patch literal 30 WcmdnB_A~<{5?}y -CEventItem::CEventItem(QString Label,bool Animated,QGraphicsItem *Parent) +CEventItem::CEventItem(QString Label, bool Animated, QGraphicsItem *Parent, int Color) { setParentItem(Parent); -// mCDVFreeBrush = new QBrush(Qt::gray); -// mCDVITICommandedBrush = new QBrush(Qt::darkGreen); -// mCDVOccupiedBrush = new QBrush(Qt::yellow); + + if(Color != EVENT_ITEM_COLOR_RED && Color != EVENT_ITEM_COLOR_GREEN) + { + Color = EVENT_ITEM_COLOR_RED; + } + + mColor = Color; setGeometry(0,0,40,25); mCurBrush = new QBrush(Qt::lightGray); @@ -75,7 +79,16 @@ void CEventItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option QRectF EventRect = rect(); if(mAnimated) - mCurBrush->setColor(QColor(255,mAlpha,mAlpha,255)); + { + if(mColor == EVENT_ITEM_COLOR_RED) + { + mCurBrush->setColor(QColor(255,mAlpha,mAlpha,255)); + } + else + { + mCurBrush->setColor(QColor(mAlpha,255,mAlpha,255)); + } + } painter->setBrush(*mCurBrush); painter->setPen(Qt::black); diff --git a/sources/GuiElements/EventItem.h b/sources/GuiElements/EventItem.h index 0508d42..944106b 100644 --- a/sources/GuiElements/EventItem.h +++ b/sources/GuiElements/EventItem.h @@ -39,7 +39,14 @@ class CEventItem : public QGraphicsWidget Q_OBJECT public: - CEventItem(QString Label,bool Animated,QGraphicsItem *Parent = 0); + enum eEventColor + { + EVENT_ITEM_COLOR_RED, + EVENT_ITEM_COLOR_GREEN + }; + + + CEventItem(QString Label,bool Animated,QGraphicsItem *Parent = 0, int Color = EVENT_ITEM_COLOR_RED); ~CEventItem(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); @@ -59,6 +66,7 @@ private: bool mAnimated; QTimeLine *mAnimationTimeline; unsigned int mAlpha; + int mColor; signals: void EventItemRightClicked(CEventItem*); diff --git a/sources/GuiElements/EventsBar.cpp b/sources/GuiElements/EventsBar.cpp index 10a22be..1c111cc 100644 --- a/sources/GuiElements/EventsBar.cpp +++ b/sources/GuiElements/EventsBar.cpp @@ -72,7 +72,7 @@ void CEventsBar::UpdateEventsList() for(int i = 0; i < mEventsList->size(); i++) { - CEventItem *NewItem = new CEventItem(mEventsList->at(i)->mEventLabel,mEventsList->at(i)->mItemAnimated,this); + CEventItem *NewItem = new CEventItem(mEventsList->at(i)->mEventLabel,mEventsList->at(i)->mItemAnimated,this,mEventsList->at(i)->mEventColor); mEventsItemList.append(NewItem); } UpdateDisplay(); diff --git a/sources/ZTStateMachine.cpp b/sources/ZTStateMachine.cpp index 5703513..63746d4 100644 --- a/sources/ZTStateMachine.cpp +++ b/sources/ZTStateMachine.cpp @@ -36,13 +36,16 @@ #include "math.h" #include "MaintenancePage.h" #include "RamMonitor.h" +#include "Zonetest.h" //#include "ModbusCCDefs.h" -CZTStateMachine::CZTStateMachine(QObject *parent) : +CZTStateMachine::CZTStateMachine(CZoneTest *ZTPtr, QObject *parent) : QObject(parent) { QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); + mProgramPtr = ZTPtr; + mZT1State = ZT1_WAIT_FOR_CI_STATE; mZT2State = ZT2_WAIT_FOR_CI_STATE; mZTState = ZT_INIT_STATE; @@ -320,10 +323,12 @@ unsigned int CZTStateMachine::ZT1StateMachine(unsigned int Event, unsigned int S if(mCIZT1Active == false) { mZT1State = ZT1_WAIT_FOR_CI_STATE; + mProgramPtr->SetZT1InhibitionState(false); } if(!mZTStationPtr->IsZT1CDVOccupied() && !mZTStationPtr->IsZT1SubsequentCDVOccupied()) { mZT1State = ZT1_WAIT_FOR_TRAIN_STATE; + mProgramPtr->SetZT1InhibitionState(false); } break; @@ -355,8 +360,10 @@ unsigned int CZTStateMachine::ZT1StateMachine(unsigned int Event, unsigned int S mZT1TrainComposition = mModbusCCMgr->GetZT1TrainComposition(); mZTPagePTr->SetZT1TrainData(mTrainTypeDetected,mZT1TrainComposition); } + + mProgramPtr->SetZT1InhibitionState(true); } - } + } if(abort == false) { @@ -1131,6 +1138,8 @@ unsigned int CZTStateMachine::ZT2StateMachine(unsigned int Event, unsigned int S mZT2TrainType = (unsigned)mModbusCCMgr->GetZT2TrainType(); mZT2TrainComposition = mModbusCCMgr->GetZT2TrainComposition(); mZTPagePTr->SetZT2TrainData(mZT2TrainType,mZT2TrainComposition); + + mProgramPtr->SetZT2InhibitionState(true); } } @@ -1203,6 +1212,7 @@ unsigned int CZTStateMachine::ZT2StateMachine(unsigned int Event, unsigned int S { CZTLog::instance()->AddLogString("CDV ZT2 Libéré. ZT2 prête",true); mZT2State = ZT2_WAIT_FOR_CI_STATE; + mProgramPtr->SetZT2InhibitionState(false); } break; } diff --git a/sources/ZTStateMachine.h b/sources/ZTStateMachine.h index c69d061..e250d52 100644 --- a/sources/ZTStateMachine.h +++ b/sources/ZTStateMachine.h @@ -96,13 +96,13 @@ enum ePostDetectionRet RET_POST_DETECTION_MAX_RET }; - +class CZoneTest; class CZTStateMachine : public QObject { Q_OBJECT public: - explicit CZTStateMachine(QObject *parent = 0); + explicit CZTStateMachine(CZoneTest *ZTPtr,QObject *parent = 0); ~CZTStateMachine(); unsigned int ZTStateMachine(unsigned int Event, unsigned int SubEvent = 0); //Exécution de la SM principale void BindPointers(CStation *ptr,CInputModule *InputModule,COutputModule *OutputModule,CZTPage *ZTPagePTr,CPCIIOMgr *PCIIOPtr,CAbstractLazerProbe *PGIntProbePtr, CAbstractLazerProbe *PGExtProbePTr,CLogMgr *LogMgr,CTKTransportInterface *TKTransport,CZTSimulator *ZTSimPtr = 0,CAnalogInputModule *DataQInterface = 0); //Assignation de pointeurs @@ -171,6 +171,7 @@ private: int mAnalogReading; + CZoneTest *mProgramPtr; CStation *mZTStationPtr; CAnalogInputModule *mSDFAnalogMonitorInterface; CInputModule *mInputModule; diff --git a/sources/Zonetest.cpp b/sources/Zonetest.cpp index c18153c..0fb91e6 100644 --- a/sources/Zonetest.cpp +++ b/sources/Zonetest.cpp @@ -76,7 +76,7 @@ CZoneTest::CZoneTest(): connect(mZTStateMachineTimer, SIGNAL(timeout()), this, SLOT(SMTimerExpired())); panel.installEventFilter(this); //Install an event filter for CZoneTest to manage some events from GUI - mZTStateMachine = new CZTStateMachine(); + mZTStateMachine = new CZTStateMachine(this); mZTSimulator = 0; mIOManager = 0; mLazerProbesManager = 0; @@ -1222,6 +1222,32 @@ unsigned int CZoneTest::SetZTFunctionsConfig(const CTCPZTFunctionsStatus &Functi return RET_OK; } +int CZoneTest::SetZT1InhibitionState(bool InhibitionON) +{ + if(InhibitionON) + { + mEventMgr->AddSingleEvent(EVENT_ZT1_INHIBITION); + } + else + { + mEventMgr->RemoveSingleEvent(EVENT_ZT1_INHIBITION); + } + return RET_OK; +} + +int CZoneTest::SetZT2InhibitionState(bool InhibitionON) +{ + if(InhibitionON) + { + mEventMgr->AddSingleEvent(EVENT_ZT2_INHIBITION); + } + else + { + mEventMgr->RemoveSingleEvent(EVENT_ZT2_INHIBITION); + } + return RET_OK; +} + void CZoneTest::ApplicationQuit(bool PowerButton) { diff --git a/sources/Zonetest.h b/sources/Zonetest.h index 5f5b072..c0d42bb 100644 --- a/sources/Zonetest.h +++ b/sources/Zonetest.h @@ -143,7 +143,9 @@ public: unsigned int DeleteZTLogRequest(); unsigned int SetZTFunctionsConfig(const CTCPZTFunctionsStatus &FunctionsConfig); - + //ZTStateMachine requests + int SetZT1InhibitionState(bool InhibitionON); + int SetZT2InhibitionState(bool InhibitionON);