You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

390 line
11 KiB

  1. #include "CableTestPage.h"
  2. #include "ui_CableTestPage.h"
  3. #include "CableTestBench.h"
  4. #include <QTextCodec>
  5. #include "CableParametersData.h"
  6. #include <QScrollBar>
  7. CCableTestPage::CCableTestPage(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::CCableTestPage)
  10. {
  11. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  12. ui->setupUi(this);
  13. mProgramHandle = 0;
  14. ui->mStationNameCombo->insertItem(0,"Frontenac",QVariant("1S52"));
  15. ui->mStationNameCombo->insertItem(1,"Côte-Vertu",QVariant("2S22"));
  16. ui->mStationNameCombo->insertItem(2,"Angrignon",QVariant("1S18"));
  17. ui->mStationNameCombo->insertItem(3,"Garage Angrignon",QVariant("1G17"));
  18. ui->mStationNameCombo->insertItem(4,"Atwater",QVariant("1S34"));
  19. ui->mStationNameCombo->insertItem(5,"Lionel-Groulx",QVariant("1S32"));
  20. ui->mStationNameCombo->insertItem(6,"Viau",QVariant("1S60"));
  21. mInspectionNotDonePixmap = QPixmap("./images/todo.png").scaled(ui->mInspectionDoneIcon->geometry().width(),ui->mInspectionDoneIcon->geometry().height());
  22. mInspectionDonePixmap = QPixmap("./images/done1.png").scaled(ui->mInspectionDoneIcon->geometry().width(),ui->mInspectionDoneIcon->geometry().height());
  23. ui->mInspectionDoneIcon->setPixmap(mInspectionNotDonePixmap);
  24. connect(ui->mExecInspVisuelleBtn,SIGNAL(clicked()),this,SLOT(InspVisuelleBtnClicked()));
  25. connect(ui->mConnectorSelectWidget,SIGNAL(ConnectorSelected(CConnectorDefs::eConnectorType)),this,SLOT(ConnectorSelectionChanged(CConnectorDefs::eConnectorType)));
  26. ui->mInputTestVisualisationWidget->SetConnectorPinCount(0);
  27. ui->mOutputTestVisualisationWidget->SetConnectorPinCount(0);
  28. mGuiRefreshTimer.setSingleShot(false);
  29. mGuiRefreshTimer.setInterval(200);
  30. connect(ui->mStartTestBtn,SIGNAL(clicked()),this,SLOT(StartTestBtnClicked()));
  31. connect(ui->mReinitTestBtn,SIGNAL(clicked()),this,SLOT(ResetTestBtnClicked()));
  32. connect(ui->mNewCableBtn,SIGNAL(clicked()),this,SLOT(NewCableBtnClicked()));
  33. connect(ui->mStartManualTestBtn,SIGNAL(clicked()),this,SLOT(StartManualTestBtnClicked()));
  34. connect(ui->mOutputTestVisualisationWidget,SIGNAL(PinClicked(int)),this,SLOT(OutputConnectorPinClicked(int)));
  35. connect(&mGuiRefreshTimer,SIGNAL(timeout()),this,SLOT(GuiRefreshTimerExpired()));
  36. connect(ui->mSaveReportBtn,SIGNAL(clicked()),this,SLOT(SaveReportBtnClicked()));
  37. connect(ui->mOpenReportBtn,SIGNAL(clicked()),this,SLOT(OpenReportBtnClicked()));
  38. connect(ui->mIdentCableEditBox,SIGNAL(textEdited(QString)),this,SLOT(CableConfigTextChanged()));
  39. connect(ui->mNomTesteurEditBox,SIGNAL(textEdited(QString)),this,SLOT(CableConfigTextChanged()));
  40. mDefaultCableName = "CABLE_XX_NO_AA_BB.c";
  41. mDefaultInspectorName = "JFMartel";
  42. ui->mStartTestBtn->setEnabled(false);
  43. ui->mStartManualTestBtn->setEnabled(false);
  44. ui->mOutputTestVisualisationWidget->DisablePinClicks();
  45. QPalette pal;
  46. pal.setColor(QPalette::WindowText,Qt::red);
  47. ui->mVisualInspectionStepLabel->setPalette(pal);
  48. ui->mVisualInspectionStepLabel->setText("2. Inspection visuelle: À FAIRE");
  49. ui->mCableIdentStepLabel->setPalette(pal);
  50. ui->mCableIdentStepLabel->setText("1. Identification du câble: À REMPLIR");
  51. ui->mConnectorSelStepLabel->setPalette(pal);
  52. ui->mConnectorSelStepLabel->setText("3. Sélection du connecteur d'entrée: À SÉLECTIONNER");
  53. ResetCable();
  54. }
  55. CCableTestPage::~CCableTestPage()
  56. {
  57. delete ui;
  58. }
  59. void CCableTestPage::InspVisuelleBtnClicked()
  60. {
  61. mProgramHandle->ExecVisualInspectionRequest();
  62. }
  63. int CCableTestPage::SetVisualInspectionDone(bool Done)
  64. {
  65. if(Done)
  66. {
  67. ui->mInspectionDoneIcon->setPixmap(mInspectionDonePixmap);
  68. ui->mExecInspVisuelleBtn->setText(QString("Réviser Inspection").toUtf8());
  69. QPalette pal;
  70. pal.setColor(QPalette::WindowText,Qt::darkGreen);
  71. ui->mVisualInspectionStepLabel->setPalette(pal);
  72. ui->mVisualInspectionStepLabel->setText("2. Inspection visuelle: OK");
  73. }
  74. else
  75. {
  76. ui->mInspectionDoneIcon->setPixmap(mInspectionNotDonePixmap);
  77. ui->mExecInspVisuelleBtn->setText("Effectuer Inspection");
  78. QPalette pal;
  79. pal.setColor(QPalette::WindowText,Qt::red);
  80. ui->mVisualInspectionStepLabel->setPalette(pal);
  81. ui->mVisualInspectionStepLabel->setText("2. Inspection visuelle: À FAIRE");
  82. }
  83. return RET_OK;
  84. }
  85. int CCableTestPage::SetConnectorSelStep(bool done)
  86. {
  87. QPalette pal;
  88. if(done)
  89. {
  90. pal.setColor(QPalette::WindowText,Qt::darkGreen);
  91. ui->mConnectorSelStepLabel->setPalette(pal);
  92. ui->mConnectorSelStepLabel->setText("3. Sélection du connecteur d'entrée: OK");
  93. }
  94. else
  95. {
  96. pal.setColor(QPalette::WindowText,Qt::red);
  97. ui->mConnectorSelStepLabel->setPalette(pal);
  98. ui->mConnectorSelStepLabel->setText("3. Sélection du connecteur d'entrée: À SÉLECTIONNER");
  99. }
  100. return RET_OK;
  101. }
  102. int CCableTestPage::SetCableConfigureStep(bool done)
  103. {
  104. QPalette pal;
  105. if(done)
  106. {
  107. pal.setColor(QPalette::WindowText,Qt::darkGreen);
  108. ui->mCableIdentStepLabel->setPalette(pal);
  109. ui->mCableIdentStepLabel->setText("1. Identification du câble: OK");
  110. }
  111. else
  112. {
  113. pal.setColor(QPalette::WindowText,Qt::red);
  114. ui->mCableIdentStepLabel->setPalette(pal);
  115. ui->mCableIdentStepLabel->setText("1. Identification du câble: À REMPLIR");
  116. }
  117. return RET_OK;
  118. }
  119. void CCableTestPage::ConnectorSelectionChanged(CConnectorDefs::eConnectorType ConType)
  120. {
  121. CCable* Cable;
  122. Cable = mProgramHandle->SetSelectedConnector(ConType);
  123. if(Cable != 0)
  124. {
  125. ui->mInputTestVisualisationWidget->SetConnectorPinCount(Cable->GetInputConnector()->GetPinCount());
  126. ui->mOutputTestVisualisationWidget->SetConnectorPinCount(Cable->GetOutputConnector()->GetPinCount());
  127. }
  128. }
  129. void CCableTestPage::StartTestBtnClicked()
  130. {
  131. mProgramHandle->StartPauseAutomaticTestRequest();
  132. }
  133. void CCableTestPage::StartManualTestBtnClicked()
  134. {
  135. mProgramHandle->StartStopManualTestRequest();
  136. }
  137. void CCableTestPage::ResetTestBtnClicked()
  138. {
  139. mProgramHandle->ResetAutomaticTestRequest();
  140. }
  141. void CCableTestPage::NewCableBtnClicked()
  142. {
  143. mProgramHandle->NewCableRequest();
  144. }
  145. int CCableTestPage::ResetCable()
  146. {
  147. //reset pins state visualization area
  148. ui->mInputTestVisualisationWidget->ClearConnectorsLists();
  149. ui->mOutputTestVisualisationWidget->ClearConnectorsLists();
  150. //Reset cable config zone
  151. // ui->mIdentCableEditBox->setText(mDefaultCableName);
  152. // ui->mNomTesteurEditBox->setText(mDefaultInspectorName);
  153. //Reset Inspection Visuelle result (main program will clear the form)
  154. SetVisualInspectionDone(false);
  155. // SetCableConfigureStep(false);
  156. SetConnectorSelStep(false);
  157. //Clear connector selection zone
  158. ui->mConnectorSelectWidget->ClearAllConnectorsSelections();
  159. ui->mTestLogTextBox->clear();
  160. ui->mSaveReportBtn->setEnabled(false);
  161. ui->mOpenReportBtn->setEnabled(false);
  162. SetAutoTestResult("");
  163. return RET_OK;
  164. }
  165. int CCableTestPage::EnableStartTestBtn()
  166. {
  167. ui->mStartTestBtn->setEnabled(true);
  168. ui->mStartManualTestBtn->setEnabled(true);
  169. return RET_OK;
  170. }
  171. int CCableTestPage::DisableStartTestBtn()
  172. {
  173. ui->mStartTestBtn->setEnabled(false);
  174. ui->mStartManualTestBtn->setEnabled(false);
  175. return RET_OK;
  176. }
  177. int CCableTestPage::CableAutomaticTestStarted()
  178. {
  179. ui->mStartManualTestBtn->setEnabled(false);
  180. DisableGuiForTest();
  181. ui->mStartTestBtn->setText("Interrompre Test");
  182. SetAutoTestResult("En Cours...",Qt::black);
  183. return RET_OK;
  184. }
  185. int CCableTestPage::CableAutomaticTestPaused()
  186. {
  187. ui->mStartTestBtn->setText("Reprendre Test");
  188. return RET_OK;
  189. }
  190. int CCableTestPage::CableTestEnded()
  191. {
  192. EnableGuiAfterTest();
  193. ui->mOutputTestVisualisationWidget->DisablePinClicks();
  194. ui->mStartManualTestBtn->setEnabled(true);
  195. ui->mStartTestBtn->setEnabled(true);
  196. ui->mStartTestBtn->setText("Démarrer Test");
  197. ui->mStartManualTestBtn->setText("Démarrer");
  198. ui->mReinitTestBtn->setEnabled(true);
  199. ui->mSaveReportBtn->setEnabled(true);
  200. return RET_OK;
  201. }
  202. int CCableTestPage::CableManualTestStarted()
  203. {
  204. ui->mStartTestBtn->setEnabled(false);
  205. ui->mOutputTestVisualisationWidget->EnablePinClicks();
  206. DisableGuiForTest();
  207. ui->mStartManualTestBtn->setText("Terminer");
  208. ui->mReinitTestBtn->setEnabled(false);
  209. ui->mSaveReportBtn->setEnabled(false);
  210. return RET_OK;
  211. }
  212. int CCableTestPage::DisableGuiForTest()
  213. {
  214. ui->mNewCableBtn->setEnabled(false);
  215. ui->mConnectorSelectWidget->setEnabled(false);
  216. ui->mIdentCableEditBox->setEnabled(false);
  217. ui->mExecInspVisuelleBtn->setEnabled(false);
  218. ui->mNomTesteurEditBox->setEnabled(false);
  219. ui->mTypeCableCombo->setEnabled(false);
  220. ui->mStationNameCombo->setEnabled(false);
  221. return RET_OK;
  222. }
  223. int CCableTestPage::EnableGuiAfterTest()
  224. {
  225. ui->mNewCableBtn->setEnabled(true);
  226. ui->mConnectorSelectWidget->setEnabled(true);
  227. ui->mIdentCableEditBox->setEnabled(true);
  228. ui->mExecInspVisuelleBtn->setEnabled(true);
  229. ui->mNomTesteurEditBox->setEnabled(true);
  230. ui->mTypeCableCombo->setEnabled(true);
  231. ui->mStationNameCombo->setEnabled(true);
  232. return RET_OK;
  233. }
  234. void CCableTestPage::OutputConnectorPinClicked(int PinNbr)
  235. {
  236. mProgramHandle->ManualPinToggleRequest(PinNbr);
  237. }
  238. void CCableTestPage::GuiRefreshTimerExpired()
  239. {
  240. mProgramHandle->RefreshConnectorsStateRequest();
  241. }
  242. int CCableTestPage::SetOutputConnectorState(QBitArray PinStates)
  243. {
  244. return ui->mOutputTestVisualisationWidget->SetConnectorPinStates(PinStates);
  245. }
  246. int CCableTestPage::SetInputConnectorState(QBitArray PinStates)
  247. {
  248. return ui->mInputTestVisualisationWidget->SetConnectorPinStates(PinStates);
  249. }
  250. void CCableTestPage::showEvent(QShowEvent *event)
  251. {
  252. qDebug("Refresh timer started");
  253. mGuiRefreshTimer.start();
  254. }
  255. void CCableTestPage::hideEvent(QHideEvent *event)
  256. {
  257. qDebug("Refresh timer stopped");
  258. mGuiRefreshTimer.stop();
  259. }
  260. int CCableTestPage::FillReportCableParametersData(CCableParametersData *ReportPtr)
  261. {
  262. ReportPtr->SetCableParams(ui->mStationNameCombo->currentText(),
  263. ui->mStationNameCombo->itemData(ui->mStationNameCombo->currentIndex()).toString(),
  264. ui->mIdentCableEditBox->text(),
  265. ui->mTypeCableCombo->currentText(),
  266. ui->mNomTesteurEditBox->text());
  267. return RET_OK;
  268. }
  269. void CCableTestPage::AddTestLogEntry(QString Entry)
  270. {
  271. ui->mTestLogTextBox->insertPlainText(Entry);
  272. ui->mTestLogTextBox->verticalScrollBar()->setValue(ui->mTestLogTextBox->verticalScrollBar()->maximum());
  273. }
  274. void CCableTestPage::SaveReportBtnClicked()
  275. {
  276. mProgramHandle->SaveReportRequest();
  277. }
  278. void CCableTestPage::OpenReportBtnClicked()
  279. {
  280. mProgramHandle->OpenReportRequest();
  281. }
  282. int CCableTestPage::EnableOpenReportBtn()
  283. {
  284. ui->mOpenReportBtn->setEnabled(true);
  285. return RET_OK;
  286. }
  287. int CCableTestPage::SetAutoTestResult(QString Result, QColor color)
  288. {
  289. QPalette pal;
  290. pal.setColor(QPalette::WindowText,color);
  291. ui->mAutoTestResultLabel->setPalette(pal);
  292. ui->mAutoTestResultLabel->setText(Result);
  293. return RET_OK;
  294. }
  295. bool CCableTestPage::IsCableConfigured()
  296. {
  297. if(ui->mIdentCableEditBox->text().isEmpty())
  298. {
  299. return false;
  300. }
  301. if(ui->mNomTesteurEditBox->text().isEmpty())
  302. {
  303. return false;
  304. }
  305. return true;
  306. }
  307. void CCableTestPage::CableConfigTextChanged()
  308. {
  309. mProgramHandle->CableConfigChanged();
  310. }