ClassFlowControll.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include "ClassFlowControll.h"
  2. #include "ClassLogFile.h"
  3. #include "Helper.h"
  4. std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
  5. {
  6. for (int i = 0; i < FlowControll.size(); ++i)
  7. if (FlowControll[i]->name().compare("ClassFlowDigit") == 0)
  8. return ((ClassFlowDigit*) (FlowControll[i]))->GetHTMLInfo();
  9. std::vector<HTMLInfo*> empty;
  10. return empty;
  11. }
  12. std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog()
  13. {
  14. for (int i = 0; i < FlowControll.size(); ++i)
  15. if (FlowControll[i]->name().compare("ClassFlowAnalog") == 0)
  16. return ((ClassFlowAnalog*) (FlowControll[i]))->GetHTMLInfo();
  17. std::vector<HTMLInfo*> empty;
  18. return empty;
  19. }
  20. void ClassFlowControll::SetInitialParameter(void)
  21. {
  22. AutoStart = false;
  23. AutoIntervall = 10;
  24. }
  25. bool ClassFlowControll::isAutoStart(long &_intervall)
  26. {
  27. _intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms
  28. return AutoStart;
  29. }
  30. ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
  31. {
  32. ClassFlow* cfc = NULL;
  33. _type = trim(_type);
  34. if (_type.compare("[MakeImage]") == 0)
  35. cfc = new ClassFlowMakeImage(&FlowControll);
  36. if (_type.compare("[Alignment]") == 0)
  37. cfc = new ClassFlowAlignment(&FlowControll);
  38. if (_type.compare("[Analog]") == 0)
  39. cfc = new ClassFlowAnalog(&FlowControll);
  40. if (_type.compare("[Digits]") == 0)
  41. cfc = new ClassFlowDigit(&FlowControll);
  42. if (_type.compare("[PostProcessing]") == 0)
  43. {
  44. cfc = new ClassFlowPostProcessing(&FlowControll);
  45. flowpostprocessing = (ClassFlowPostProcessing*) cfc;
  46. }
  47. if (cfc) // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
  48. FlowControll.push_back(cfc);
  49. if (_type.compare("[AutoTimer]") == 0)
  50. cfc = this;
  51. return cfc;
  52. }
  53. void ClassFlowControll::InitFlow(std::string config)
  54. {
  55. int aktFlow;
  56. bool handeled;
  57. string line;
  58. flowpostprocessing = NULL;
  59. ClassFlow* cfc;
  60. FILE* pFile;
  61. config = FormatFileName(config);
  62. pFile = fopen(config.c_str(), "r");
  63. line = "";
  64. handeled = true;
  65. char zw[1024];
  66. if (pFile != NULL)
  67. {
  68. fgets(zw, 1024, pFile);
  69. printf("%s", zw);
  70. line = std::string(zw);
  71. }
  72. while ((line.size() > 0) && !(feof(pFile)))
  73. {
  74. cfc = CreateClassFlow(line);
  75. if (cfc)
  76. {
  77. cfc->ReadParameter(pFile, line);
  78. }
  79. else
  80. {
  81. fgets(zw, 1024, pFile);
  82. printf("%s", zw);
  83. line = std::string(zw);
  84. }
  85. }
  86. fclose(pFile);
  87. }
  88. bool ClassFlowControll::doFlow(string time)
  89. {
  90. bool result = true;
  91. for (int i = 0; i < FlowControll.size(); ++i)
  92. {
  93. string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
  94. LogFile.WriteToFile(zw);
  95. result = result && FlowControll[i]->doFlow(time);
  96. }
  97. return result;
  98. }
  99. string ClassFlowControll::getReadout(bool _rawvalue = false)
  100. {
  101. if (flowpostprocessing)
  102. return flowpostprocessing->getReadout();
  103. string zw = "";
  104. string result = "";
  105. for (int i = 0; i < FlowControll.size(); ++i)
  106. {
  107. zw = FlowControll[i]->getReadout();
  108. if (zw.length() > 0)
  109. {
  110. if (result.length() == 0)
  111. result = zw;
  112. else
  113. result = result + "\t" + zw;
  114. }
  115. }
  116. return result;
  117. }
  118. string ClassFlowControll::GetPrevalue()
  119. {
  120. if (flowpostprocessing)
  121. {
  122. return flowpostprocessing->GetPreValue();
  123. }
  124. return std::string();
  125. }
  126. std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
  127. {
  128. float zw;
  129. char* p;
  130. _newvalue = trim(_newvalue);
  131. // printf("Input UpdatePreValue: %s\n", _newvalue.c_str());
  132. if (_newvalue.compare("0.0") == 0)
  133. {
  134. zw = 0;
  135. }
  136. else
  137. {
  138. zw = strtof(_newvalue.c_str(), &p);
  139. if (zw == 0)
  140. return "- Error in String to Value Conversion!!! Must be of format value=123.456";
  141. }
  142. if (flowpostprocessing)
  143. {
  144. flowpostprocessing->SavePreValue(zw);
  145. return _newvalue;
  146. }
  147. return std::string();
  148. }
  149. bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
  150. {
  151. std::vector<string> zerlegt;
  152. aktparamgraph = trim(aktparamgraph);
  153. if (aktparamgraph.size() == 0)
  154. if (!this->GetNextParagraph(pfile, aktparamgraph))
  155. return false;
  156. if (aktparamgraph.compare("[AutoTimer]") != 0) // Paragraph passt nich zu MakeImage
  157. return false;
  158. while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
  159. {
  160. zerlegt = this->ZerlegeZeile(aktparamgraph);
  161. if ((zerlegt[0] == "AutoStart") && (zerlegt.size() > 1))
  162. {
  163. if (toUpper(zerlegt[1]) == "TRUE")
  164. {
  165. AutoStart = true;
  166. }
  167. }
  168. if ((zerlegt[0] == "Intervall") && (zerlegt.size() > 1))
  169. {
  170. AutoIntervall = std::stof(zerlegt[1]);
  171. }
  172. }
  173. return true;
  174. }