IHMInputOutputParamInfoClass.php
13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
/**
* @class IHMInputOutputParamInfoClass
* @brief Class that's implement an InputOutputInterface used to treat a get param info request
* @details
*/
class IHMInputOutputParamInfoClass implements InputOutputInterface
{
private $paramInfoData = null;
private $paramTemplateMgr = null;
/*
* @brief Constructor
*/
function __construct()
{
$this->paramTemplateMgr = new IHMParamTemplateClass();
}
/*
* @brief translate input data from IHM client to AMDA_Integration module for a get param info request
*/
public function getInputData($input,$function,$requestId="")
{
$this->paramInfoData = new ParamInfoRequestDataClass();
switch ($input->type) {
case 'plot_init' :
$this->paramInfoData->setType(ParamInfoTypeEnumClass::PLOTINIT);
if (!isset($input->paramId) || empty($input->paramId))
throw new Exception("Param info request need a param id as argument");
$paramFilePath = IHMConfigClass::getLocalParamDBPath().$input->paramId.".xml";
if (!file_exists($paramFilePath))
throw new Exception("Cannot find parameter definition file");
$this->paramInfoData->setFilePath($paramFilePath);
break;
case 'param_info' :
$this->paramInfoData->setType(ParamInfoTypeEnumClass::PARAMINFO);
if (!isset($input->paramId) || empty($input->paramId))
throw new Exception("Param info request need a param id as argument");
$templatedParams = $this->paramTemplateMgr->getParamTemplates();
if (array_key_exists($input->paramId, $templatedParams))
$this->paramInfoData->setTemplateInfo($templatedParams[$input->paramId]);
$paramInfoFilePath = IHMConfigClass::getLocalParamInfoPath().'info_'.$input->paramId.".xml";
if (!file_exists($paramInfoFilePath))
throw new Exception("Cannot find parameter info file");
$this->paramInfoData->setFilePath($paramInfoFilePath);
break;
default :
throw new Exception("Para info request type '".$input->type."' not yet implemented");
}
$this->paramInfoData->setParamId($input->paramId);
return $this->paramInfoData;
}
/*
* @brief translate output data from AMDA_Integration module to IHM client for a get param info request
*/
public function getOutput($data)
{
switch ($data->getType()) {
case ParamInfoTypeEnumClass::PLOTINIT :
$result = array("success" => false, "message" => "Cannot get plot init");
$this->getOutputPlotInit($data, $result);
break;
case ParamInfoTypeEnumClass::PARAMINFO :
$result = array("success" => false, "message" => "Cannot get param info");
$this->getOutputParamInfo($data, $result);
break;
default:
//Nothing ToDo
}
return $result;
}
private function getOutputParamInfo($data, &$result) {
if (($data->getResult() != NULL)) {
$result = array(
"success" => true,
"data" => $data->getResult()
);
if ($data->getTemplateInfo() != NULL) {
$result["template"] = $data->getTemplateInfo();
}
}
}
private function getOutputPlotInit($data, &$result) {
if (($data->getResult() != NULL) && ($data->getResult()->getName() == "plot") && (count($data->getResult()->getChildren()) >= 1)) {
$result_data = array();
$panelNodes = $data->getResult()->getChildren();
$panelNode = $panelNodes[0];
$plotNode = NULL;
if (count($panelNode->getChildren()) >= 1) {
foreach ($panelNode->getChildren() as $crtNode) {
if (!in_array($crtNode->getName(), array('timePlot', 'epochPlot', 'xyPlot', 'instantPlot', 'statusPlot', 'tickPlot')))
continue;
$plotNode = $crtNode;
break;
}
if (isset($plotNode)) {
$result_data['panel'] = array();
switch ($plotNode->getName()) {
case 'timePlot' :
$result_data['panel']['plotType'] = 'timePlot';
break;
case 'epochPlot' :
$result_data['panel']['plotType'] = 'epochPlot';
break;
case 'xyPlot' :
$result_data['panel']['plotType'] = 'xyPlot';
$result_data['panel']['isotropic'] = ($plotNode->getIsIsotropic() == "true");
$result_data['additionalObjects'] = $this->unmarshallAdditionalObjectsData($plotNode);
break;
case 'instantPlot' :
$result_data['panel']['plotType'] = 'instantPlot';
break;
case 'statusPlot' :
$result_data['panel']['plotType'] = 'statusPlot';
break;
case 'tickPlot' :
$result_data['panel']['plotType'] = 'tickPlot';
break;
}
$result_data['draw'] = $this->unmarshallDrawData($plotNode, $data->getParamId());
}
$result = array(
"success" => true,
"data" => $result_data
);
//var_dump($result);
}
/*if (count($paramsNode->getChildren()) >= 1) {
$paramNode = $paramsNode->getChildren()[0];
if (count($paramNode->getChildren()) >= 1) {
$drawNode = $paramNode->getChildren()[0];
switch ($drawNode->getName()) {
case 'serie' :
$data['drawType'] = 'serie';
break;
case 'orbitserie' :
$data['drawType'] = 'orbit-serie';
break;
}
$result = array(
"success" => true,
"data" => $data
);
}
}*/
}
}
private function unmarshallDrawData($plotNode, $paramId) {
$result_data = array();
if (!isset($plotNode))
return $result_data;
$paramsNode = $plotNode->getParams();
if (!isset($paramsNode))
return $result_data;
$paramNode = $paramsNode->getParamById($paramId);
if (!isset($paramNode) || (count($paramNode->getChildren()) < 1))
return $result_data;
$mainDrawNode = NULL;
$otherDrawNodes = array();
foreach ($paramNode->getChildren() as $crtDrawNode) {
if (in_array($crtDrawNode->getName(), array('serie', 'spectro', 'yserie', 'orbitserie')))
$mainDrawNode = $crtDrawNode;
else
$otherDrawNodes[$mainDrawNode->getName()] = $crtDrawNode;
}
if (!isset($mainDrawNode))
return $result_data;
switch ($mainDrawNode->getName()) {
case 'serie' :
$result_data['type'] = 'serie';
$this->unmarshallBaseSerieData($mainDrawNode, $result_data);
//if (array_key_exists('colorserie', $otherDrawNodes))
// $this->unmarshallColorSerieData($mainDrawNode, $result_data);
break;
case 'spectro' :
$result_data['type'] = 'spectro';
$this->unmarshallSpectroData($mainDrawNode, $result_data);
break;
case 'yserie' :
if (!array_key_exists('xserie', $otherDrawNodes))
return $result_data;
$this->unmarshallBaseSerieData($mainDrawNode, $result_data);
//$this->unmarshallXSerieData($mainDrawNode, $result_data);
//if (array_key_exists('colorserie', $otherDrawNodes))
// $this->unmarshallColorSerieData($mainDrawNode, $result_data);
break;
case 'orbitserie' :
$result_data['type'] = 'orbit-serie';
$result_data['serie-projection'] = $mainDrawNode->getProjection();
$this->unmarshallBaseSerieData($mainDrawNode, $result_data);
//if (array_key_exists('colorserie', $otherDrawNodes))
// $this->unmarshallColorSerieData($mainDrawNode, $result_data);
break;
default :
return $result_data;
}
return $result_data;
}
private function unmarshallSpectroData($drawNode, &$result_array) {
if (!isset($drawNode))
return;
$yAxis = $drawNode->getAttribute(REQUESTOUTPUTPLOTSPECTRO_YAXIS);
if (!empty($yAxis))
$result_array['spectro-yaxis'] = $yAxis;
$min = $drawNode->getAttribute(REQUESTOUTPUTPLOTSPECTRO_MIN);
if (!empty($min))
$result_array['spectro-value-min'] = $min;
$max = $drawNode->getAttribute(REQUESTOUTPUTPLOTSPECTRO_MAX);
if (!empty($max))
$result_array['spectro-value-max'] = $max;
}
private function unmarshallAdditionalObjectsData($plotNode) {
$result_data = array();
if (!isset($plotNode))
return $result_data;
$additionalObjectsNode = $plotNode->getAdditionalObjects();
//curvePlot
$result_data['curves'] = array();
$curveObjectsNode = $additionalObjectsNode->getCurveObjects();
foreach ($curveObjectsNode as $curveNode) {
$crt_curve_data = array();
$crt_curve_data['curve-serie-id'] = $curveNode->getSerieId();
$this->unmarshallLineData($curveNode, "curve-line-", $crt_curve_data);
if ($curveNode->isFunctionDefined()) {
$crt_curve_data['curve-name'] = $curveNode->getFunction()->getFunctionName();
$crt_curve_data['curve-attributes'] = array();
foreach ($curveNode->getFunction()->getAttributes()->getChildren() as $attributeNode) {
$crt_attribute_data = array();
$crt_attribute_data['curve-param-name'] = $attributeNode->getAttribute(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTENAME);
$crt_attribute_data['curve-param-value'] = $attributeNode->getAttribute(REQUESTOUTPUTPLOTCURVEOBJECTFUNCTION_ATTRIBUTEVALUE);
$crt_curve_data['curve-attributes'][] = $crt_attribute_data;
}
}
$result_data['curves'][] = $crt_curve_data;
}
return $result_data;
}
private function unmarshallBaseSerieData($drawNode, &$result_array) {
if (!isset($drawNode))
return;
$result_array['serie-id'] = $drawNode->getId();
$result_array['serie-yaxis'] = $drawNode->getYAxisId();
if ($drawNode->isLineDefined()) {
$result_array['serie-lines-activated'] = true;
$this->unmarshallLineData($drawNode->getLine(), "serie-lines-", $result_array);
}
if ($drawNode->isSymbolDefined()) {
$result_array['serie-symbols-activated'] = true;
$this->unmarshallSymbolData($drawNode->getSymbol(), "serie-symbols-", $result_array);
}
$colorSerieId = $drawNode->getColorSerieId();
if (!empty($colorSerieId)) {
//ToDo
}
if ($drawNode->isTimeTicksDefined()) {
$result_array['serie-timetick-activated'] = true;
$result_array['serie-timetick-step'] = $drawNode->getTimeTicks()->getStep();
$result_array['serie-timetick-nbmajor'] = $drawNode->getTimeTicks()->getNumber();
$result_array['serie-timetick-nbminor'] = $drawNode->getTimeTicks()->getMinor();
$result_array['serie-timetick-color'] = $this->toHexColor($drawNode->getTimeTicks()->getColor());
if (!empty($result_array['serie-timetick-nbmajor']) && intval($result_array['serie-timetick-nbmajor']) > 0)
$result_array['serie-timetick-type'] = 'nb-major';
else if (!empty($result_array['serie-timetick-step']) && intval($result_array['serie-timetick-step']) > 0)
$result_array['serie-timetick-type'] = 'time-step';
else
$result_array['serie-timetick-type'] = 'auto';
if ($drawNode->getTimeTicks()->isSymbolDefined()) {
$this->unmarshallSymbolData($drawNode->getTimeTicks()->getSymbol(), "serie-timetick-symbols-", $result_array);
}
if ($drawNode->getTimeTicks()->isFirstSymbolDefined()) {
$result_array['serie-timetick-firstsymbols-activated'] = true;
$this->unmarshallSymbolData($drawNode->getTimeTicks()->getFirstSymbol(), "serie-timetick-firstsymbols-", $result_array);
}
if ($drawNode->getTimeTicks()->isFontDefined()) {
$result_array['serie-timetick-font-activated'] = true;
$this->unmarshallFontData($drawNode->getTimeTicks()->getFont(), "serie-timetick-font-", $result_array);
}
}
if ($drawNode->isIntervalTicksDefined()) {
$result_array['serie-intervaltick-activated'] = true;
$result_array['serie-intervaltick-mode'] = $drawNode->getIntervalTicks()->getMode();
$result_array['serie-intervaltick-color'] = $this->toHexColor($drawNode->getIntervalTicks()->getColor());
if ($drawNode->getIntervalTicks()->isSymbolDefined()) {
$this->unmarshallSymbolData($drawNode->getIntervalTicks()->getSymbol(), "serie-intervaltick-", $result_array);
}
if ($drawNode->getIntervalTicks()->isFontDefined()) {
$result_array['serie-intervaltick-font-activated'] = true;
$this->unmarshallFontData($drawNode->getIntervalTicks()->getFont(), "serie-intervaltick-font-", $result_array);
}
}
}
private function unmarshallLineData($lineNode, $prefix, &$result_array) {
$result_array[$prefix.'style'] = $lineNode->getStyle();
$result_array[$prefix.'width'] = $lineNode->getWidth();
$result_array[$prefix.'color'] = $this->toHexColor($lineNode->getColor());
}
private function unmarshallSymbolData($symbolNode, $prefix, &$result_array) {
$result_array[$prefix.'type'] = $symbolNode->getType();
$result_array[$prefix.'size'] = $symbolNode->getSize();
$result_array[$prefix.'color'] = $this->toHexColor($symbolNode->getColor());
}
private function unmarshallFontData($fontNode, $prefix, &$result_array) {
$result_array[$prefix.'name'] = $fontNode->getFontName();
$result_array[$prefix.'size'] = $fontNode->getSize();
$result_array[$prefix.'bold'] = ($fontNode->getWeight() == RequestOutputPlotFontWeight::BOLD);
$result_array[$prefix.'italic'] = ($fontNode->getStyle() == RequestOutputPlotFontStyle::ITALIC);
}
private function toHexColor($color) {
$temp = str_replace(array('[', ']', ' '), '', $color);
$arr = explode(',', $temp);
if (count ($arr) != 3)
return '#000000';
return '#'.sprintf('%02x', $arr[0]).sprintf('%02x', $arr[1]).sprintf('%02x', $arr[2]);
}
}
?>