ClassFlowControll.cpp 4.9 KB

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