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.
 
 
 
 

175 rivejä
5.8 KiB

  1. #include "TestReport.h"
  2. #include <QDateTime>
  3. #include <QFile>
  4. #include <QTextStream>
  5. #include <QMessageBox>
  6. #include <QTextCodec>
  7. CTestReport::CTestReport()
  8. {
  9. mSoftwareVersion = QString(TEST_BENCH_VERSION);
  10. CreateNewTestReport();
  11. mReportFileDirectory = "./Rapports/";
  12. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  13. }
  14. CVisualInspectionResult * CTestReport::GetInspectionResult()
  15. {
  16. return &mVisualInspectionResultReport;
  17. }
  18. CCableParametersData *CTestReport::GetReportCableParameters()
  19. {
  20. return &mCableParameters;
  21. }
  22. int CTestReport::CreateNewTestReport()
  23. {
  24. mVisualInspectionResultReport.ClearResults();
  25. mCableParameters.ResetData();
  26. mAutomatedTestReport.ClearAutomatedTestReport();
  27. mTestLog.clear();
  28. mLastReportName.clear();
  29. return RET_OK;
  30. }
  31. int CTestReport::AddLogEntry(QString NewEntry, bool IncludeTime, bool Propagate)
  32. {
  33. if(NewEntry.isEmpty())
  34. {
  35. return RET_ERROR;
  36. }
  37. if(IncludeTime)
  38. {
  39. QString Time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz - ");
  40. NewEntry.prepend(Time);
  41. }
  42. qDebug(NewEntry.toAscii().data());
  43. if(NewEntry.endsWith(QChar('\n')) == false)
  44. {
  45. NewEntry.append(QChar('\n'));
  46. }
  47. if(Propagate)
  48. {
  49. emit NewTestLogEntry(NewEntry);
  50. }
  51. mTestLog.append(NewEntry);
  52. return RET_OK;
  53. }
  54. CAutomatedTestReport *CTestReport::GetAutomatedTestReport()
  55. {
  56. return &mAutomatedTestReport;
  57. }
  58. int CTestReport::SaveReportToFile()
  59. {
  60. QFile *ReportFile;
  61. //QTextStream ReportStream;
  62. QString Filename = QDateTime::currentDateTime().toString("yyMMdd_hhmmss_");
  63. Filename.append(mCableParameters.mStationCodeName);
  64. Filename.append(mCableParameters.mCableIdentification);
  65. Filename.append(".txt");
  66. Filename.prepend(mReportFileDirectory);
  67. ReportFile = new QFile(Filename);
  68. if (!ReportFile->open(QIODevice::ReadWrite |QIODevice::Truncate | QIODevice::Text))
  69. {
  70. AddLogEntry(QString("Impossible de sauvegarder le rapport %1").arg(Filename),false);
  71. QMessageBox::critical(NULL,"Erreur de sauvegarde",QString("Impossible de sauvegarder le fichier rapport \n%1").arg(Filename));
  72. return RET_ERROR;
  73. }
  74. mLastReportName = Filename;
  75. QTextStream ReportStream(ReportFile);
  76. ReportStream.setCodec(QTextCodec::codecForName("UTF-8"));
  77. ReportStream << QString("Rapport de test - Câble SEI\n");
  78. ReportStream << QString("Date de l'essai: ") << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "\n";
  79. ReportStream << "Version du logiciel de test: " << mSoftwareVersion << "\n\n";
  80. ReportStream << "-----------------------------------------\n";
  81. ReportStream << QString("Paramètres du câble: \n");
  82. ReportStream << QString("Identification du câble: ") << mCableParameters.mCableIdentification << "\n";
  83. ReportStream << "Station: " << mCableParameters.mStationCodeName << " - "<< mCableParameters.mStationName << "\n";
  84. ReportStream << "Type: " << mCableParameters.mCableType << "\n";
  85. ReportStream << QString("Opérateur du test: ") << mCableParameters.mTestOperatorName << "\n";
  86. ReportStream << QString("Connecteur d'entrée: ") << mCableParameters.mInputConnectorType << "\n";
  87. ReportStream << "Connecteur de sortie: " << mCableParameters.mOutputConnectorType << "\n\n";
  88. ReportStream << "-----------------------------------------\n";
  89. ReportStream << QString("Résultats de l'inspection visuelle:\n");
  90. ReportStream << QString("Section 5.2 exécutée: ") << mVisualInspectionResultReport.mVerif52ExecResultText << "\n";
  91. ReportStream << QString("Section 5.3 exécutée: ") << mVisualInspectionResultReport.mVerif53ExecResultText << "\n";
  92. ReportStream << QString("Section 5.4 exécutée: ") << mVisualInspectionResultReport.mVerif54ExecResultText << "\n";
  93. ReportStream << QString("Section 5.5 exécutée: ") << mVisualInspectionResultReport.mVerif55ExecResultText << "\n";
  94. ReportStream << QString("Section 5.6 exécutée: ") << mVisualInspectionResultReport.mVerif56ExecResultText << "\n\n";
  95. ReportStream << "Notes d'inspection:\n\n";
  96. ReportStream << mVisualInspectionResultReport.mVerifNotesText << "\n\n";
  97. ReportStream << "-----------------------------------------\n";
  98. ReportStream << QString("Résultats du test automatique du câble:\n");
  99. ReportStream << QString("Lorsqu'applicable, les valeurs entre crochets [] correspondent aux contacts en défaut.\n\n");
  100. ReportStream.setFieldWidth(15);
  101. ReportStream.setFieldAlignment(QTextStream::AlignCenter);
  102. ReportStream << "No. Contact" << QString("Continuité") << "Isolation" << "Assignation" << QString("2è test") << qSetFieldWidth(0) << "\n";
  103. for(int pin = 1; pin <= mAutomatedTestReport.mPinCount; pin++)
  104. {
  105. ReportStream.setFieldWidth(15);
  106. ReportStream.setFieldAlignment(QTextStream::AlignCenter);
  107. ReportStream << QString("%1").arg(pin) <<
  108. mAutomatedTestReport.GetPinContinuityResult(pin) <<
  109. mAutomatedTestReport.GetPinIsolationResult(pin) <<
  110. mAutomatedTestReport.GetPinConcordanceResult(pin) <<
  111. mAutomatedTestReport.GetPinSecondTestResult(pin) << qSetFieldWidth(0) <<
  112. " \n";
  113. }
  114. ReportStream << QString("\n\n\n Signature de l'opérateur de test: _________________________________________\n\n");
  115. ReportStream << "-----------------------------------------\n";
  116. ReportStream << "Log du test:\n";
  117. ReportStream << mTestLog;
  118. ReportFile->close();
  119. delete ReportFile;
  120. return RET_OK;
  121. }
  122. bool CTestReport::IsAutoTestReportReady()
  123. {
  124. if(mAutomatedTestReport.GetPinCount() == 0)
  125. {
  126. return false;
  127. }
  128. return true;
  129. }
  130. bool CTestReport::GetGlobalAutoTestResult()
  131. {
  132. return mAutomatedTestReport.IsAutomatedTestSuccess();
  133. }
  134. QString CTestReport::GetLastReportFileName()
  135. {
  136. return mLastReportName;
  137. }