Blame view

src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php 24.1 KB
22521f1c   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
<?php

/**
 * @class IHMParamManagerClass
 * @brief Parameter manager
 * @details
 */
class IHMParamManagerClass
{
	protected $userParameterLoader = null;
	protected $expressionParser = null;
bf27ba04   Benjamin Renard   Add templated par...
12
	protected $templateParamsManager = null;
ffc5cb81   Elena.Budnik   temporary commit
13
	protected $paramImpexMgr     = null;
52c1e291   Benjamin Renard   Generate TT and c...
14
	protected $ttCatMgr = null;
22521f1c   Benjamin Renard   First commit
15
16
17
18
19
20
	
	/*
	 * @brief Constructor
	*/
	function __construct()
	{
bf27ba04   Benjamin Renard   Add templated par...
21
		$this->templateParamsManager = new IHMParamTemplateClass();
22521f1c   Benjamin Renard   First commit
22
23
	}

cd28a380   Benjamin Renard   Generate param in...
24
25
26
27
28
29
30
31
32
33
34
35
	public function addGeneratedParam($paramId, $expression, $sampling, $paramsData)
	{
		if (!isset($this->expressionParser))
			$this->expressionParser = new IHMExpressionParserClass();
		$expressionInfo = $this->expressionParser->parse($expression);

                //create a process param for the derived parameter
                $this->addProcessParam($paramId, $expressionInfo["expression"], $expression,
                                $expressionInfo['params'], $sampling,
                                0, time(), "", "", $paramsData);
	}

22521f1c   Benjamin Renard   First commit
36
37
38
	/*
	 * @brief Add an existing parameter
	*/
52859c27   Benjamin Renard   Give the possibil...
39
	public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL)
d1a35428   Benjamin Renard   Update template a...
40
	{
22521f1c   Benjamin Renard   First commit
41
42
43
44
		if ($this->isDerivedParam($param))
			return $this->addDerivedParam($param,$paramsData);
		else if ($this->isUploadedParam($param))
			return $this->addUploadedParam($param,$paramsData);
ffc5cb81   Elena.Budnik   temporary commit
45
46
		else if ($this->isImpexParam($param))
			return $this->addImpexParam($param,$paramsData,$templateArgs);	
22521f1c   Benjamin Renard   First commit
47
		else
52859c27   Benjamin Renard   Give the possibil...
48
			return $this->addLocalParam($param,$paramsData,$templateArgs, $tableLink);
22521f1c   Benjamin Renard   First commit
49
50
51
52
53
54
		return "";
	}

	/*
	 * @brief Add a process parameter
	*/
c0535e83   Benjamin Renard   Use units and yTi...
55
56
57
	public function addProcessParam($paramId,$expression,$expression_info,$params,$sampling,$gap,$dateModif,$units,$ytitle,$paramsData)
	{
		$paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling, $gap,$dateModif, $units, $ytitle); 
ffc5cb81   Elena.Budnik   temporary commit
58
	 
e4545ed5   Benjamin Renard   Implement templat...
59
		foreach ($params as $param) {
ffc5cb81   Elena.Budnik   temporary commit
60
61
			$template_args = NULL; 
			 
e4545ed5   Benjamin Renard   Implement templat...
62
63
			if (array_key_exists("template_args", $param))
				$template_args = $param["template_args"];
ffc5cb81   Elena.Budnik   temporary commit
64
	 		 
e4545ed5   Benjamin Renard   Implement templat...
65
66
			$this->addExistingParam($param["paramid"],$paramsData,$template_args);
		}
22521f1c   Benjamin Renard   First commit
67
68
69
70
71

		return true;
	}

	/*
52c1e291   Benjamin Renard   Generate TT and c...
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
	 *  @brief Add a TT or catalog parameter
	 */
	public function addTTCatParam($paramId, $paramsData)
	{
		if (!isset($this->ttCatMgr)) {
			$this->ttCatMgr = new IHMTTCatLoaderClass();
		}
		$info = $this->ttCatMgr->getTTCatInfoFromId($paramId);

		if (!$info["success"]) {
			throw new Exception($info["message"]);
		}

		$status = array();
		$units = "";
		$ytitle = "";
		$flag = "";

		if ($info["info"]["isCatalog"]) {
			$parameters = $this->ttCatMgr->getCatalogParameters($paramId);
			if (!$parameters["success"] || empty($parameters["parameters"])) {
				throw new Exception("Error to extract first parameter of ".$paramId);
			}
			//For the moment, use the first parameter
			$parameter = $parameters["parameters"][0];
			$units     = $parameter["units"];
			$ytitle    = !empty($parameter["name"]) ? $parameter["name"] : $parameter["id"];
			$flag      = $parameter["id"];
			$description = $parameter["description"];
			$desc_parts = array();
			foreach (explode("-",$description) as $def) {
				$def = trim($def);
				$p = strpos($def, ":");
				if ($p === FALSE) {
					continue;
				}
				$val = substr($def, 0, $p);
				$val = trim($val);
				$name = substr($def, $p+1);
				$name = trim($name);
				$color = "";
				$p = strpos($name, "[");
				if ($p !== FALSE) {
					$color = substr($name, $p);
					$color = trim($color);
					$name = substr($name, 0, $p);
					$name = trim($name);
				}
				$status[] = array(
					"min" => floatval($val),
					"max" => floatval($val),
					"name" => $name,
					"color" => $color,
				);
			}
		}
		else {
			$status = array(
				array(
					"min" => 1,
					"max" => 1,
					"name" => "Inside",
					"color" => "[255,0,0]",
				)
			);
			$ytitle = $info["info"]["name"];
		}

		$paramsData->addTTCatParamToCreate($paramId, $info["info"]["path"], $info["info"]["isShared"], filemtime($info["info"]["path"]), $units, $ytitle, $status, $flag);
		return array("id" => $paramId, "indexes" => array(), "calib_infos" => array());
	} 

	/*
22521f1c   Benjamin Renard   First commit
145
146
147
148
149
150
151
152
153
154
	 * @brief Detect if it's a derived parameter
	*/
	private function isDerivedParam($param)
	{
		return preg_match("#^ws_#",$param);
	}

	/*
	 * @brief Detect if it's a uploaded parameter
	*/
dcdacd5c   Benjamin Renard   Fill plot type in...
155
	public function isUploadedParam($param)
22521f1c   Benjamin Renard   First commit
156
157
158
	{
		return preg_match("#^wsd_#",$param);
	}
ffc5cb81   Elena.Budnik   temporary commit
159
160
161
162
163
164
165
166
	
	/*
	 * @brief Detect if it's IMPEX parameter
	*/
	private function isImpexParam($param)
	{
		return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param);
	}
22521f1c   Benjamin Renard   First commit
167
168
169
170

	/*
	 * @brief Add a local parameter
	*/
52859c27   Benjamin Renard   Give the possibil...
171
	private function addLocalParam($param, $paramsData, $templateArgs, $tableLink)
22521f1c   Benjamin Renard   First commit
172
173
174
175
176
177
178
179
180
181
182
183
184
185
	{
		//local parameter
		$indexes     = array();
		$calib_infos = array();
		//check for components
		$pattern = "/(?P<param>.*)\((?P<components>.*)\)/";
		preg_match_all($pattern, $param, $matches);
		if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0))
		{
			$paramId       = $matches["param"][0];
			$indexes = explode(",",$matches["components"][0]);
		}
		else
			$paramId = $param;
ffc5cb81   Elena.Budnik   temporary commit
186
	 
bf27ba04   Benjamin Renard   Add templated par...
187
188
189
		//check templated parameter
		$real_param_id = $paramId;
		if ($this->templateParamsManager->isTemplatedParam($paramId)) {
52859c27   Benjamin Renard   Give the possibil...
190
			$paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink);
bf27ba04   Benjamin Renard   Add templated par...
191
			$real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs);
bf27ba04   Benjamin Renard   Add templated par...
192
193
194
195
196
197
198
199
			if (empty($paramPath) || !file_exists($paramPath))
				throw new Exception('Cannot generate parameter template file '.$paramId);
		}
		else {
			$paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
			if (!file_exists($paramPath))
				throw new Exception('Cannot find parameter local file '.$paramId);
		}
22521f1c   Benjamin Renard   First commit
200

bf27ba04   Benjamin Renard   Add templated par...
201
		$paramsData->addParamToCopy($real_param_id,$paramPath);
22521f1c   Benjamin Renard   First commit
202

bf27ba04   Benjamin Renard   Add templated par...
203
		$this->addLinkedLocalParams($paramId, $paramsData, $templateArgs);
22521f1c   Benjamin Renard   First commit
204
			
bf27ba04   Benjamin Renard   Add templated par...
205
		return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos);
22521f1c   Benjamin Renard   First commit
206
207
208
209
210
	}

	/*
	 * @brief Add linked parameter
	*/
bf27ba04   Benjamin Renard   Add templated par...
211
	private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL)
22521f1c   Benjamin Renard   First commit
212
	{
952dd7c7   elena   catalog integration
213
214
		$doc = new DOMDocument("1.0", "UTF-8");
		$doc->preserveWhiteSpace = false;
22521f1c   Benjamin Renard   First commit
215
216
		$doc->formatOutput = true;

cd3326be   Benjamin Renard   Fix function used...
217
		$real_param_id = $paramId;
bf27ba04   Benjamin Renard   Add templated par...
218
		if ($this->templateParamsManager->isTemplatedParam($paramId)) {
cd3326be   Benjamin Renard   Fix function used...
219
			$paramPath = $this->templateParamsManager->getTemplatePath($paramId);
8ade06fe   Benjamin Renard   Improve config load
220
			if (empty($paramPath) || !@$doc->load($paramPath))
f1252b32   Benjamin Renard   Add template for ...
221
				throw new Exception('Cannot find parameter template file '.$paramId);
bf27ba04   Benjamin Renard   Add templated par...
222
223
224
		}
		else {
			$paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
8ade06fe   Benjamin Renard   Improve config load
225
			if (empty($paramPath) || !@$doc->load($paramPath))
f1252b32   Benjamin Renard   Add template for ...
226
				throw new Exception('Cannot find parameter local file '.$paramId);
bf27ba04   Benjamin Renard   Add templated par...
227
228
		}
			
22521f1c   Benjamin Renard   First commit
229
230
231
232
233
234
235
236
237
238
239
240
241
242
		//<get>
		$getNodes = $doc->getElementsByTagName('get');

		if ($getNodes->length <= 0)
			throw new Exception('Parameter local file '.$paramId.' dont have a getter node');

		$getNode = $getNodes->item(0);

		//<amdaParam name="imf"/>
		$amdaParamNodes = $doc->getElementsByTagName('amdaParam');

		foreach($amdaParamNodes as $amdaParamNode)
		{
			$linkedParamId = $amdaParamNode->getAttribute('name');
cd3326be   Benjamin Renard   Fix function used...
243
			if (empty($linkedParamId))
22521f1c   Benjamin Renard   First commit
244
				continue;
7911f4bc   Benjamin Renard   Another bug with ...
245
			$template_id = $this->templateParamsManager->getTemplateId($linkedParamId);
d1a35428   Benjamin Renard   Update template a...
246
			$tempArgs = isset($templateArgs) ? $templateArgs : array();
7911f4bc   Benjamin Renard   Another bug with ...
247
248
249
			if ($template_id !== FALSE) {
				$linkedParamId = $template_id;
			}
7d35612a   Benjamin Renard   Fix ParamManager ...
250
251
			else {
				$linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs);
97d1c981   Benjamin Renard   Fix bug with a te...
252
253
254
				$parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId);
				if ($parsedParam !== FALSE) {
					$linkedParamId = $parsedParam['paramid'];
d1a35428   Benjamin Renard   Update template a...
255
256
257
					foreach ($parsedParam['template_args'] as $key => $val) {
						$tempArgs[$key] = $val;
					}
97d1c981   Benjamin Renard   Fix bug with a te...
258
				}
7d35612a   Benjamin Renard   Fix ParamManager ...
259
			}
7911f4bc   Benjamin Renard   Another bug with ...
260
261

			if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) {
d1a35428   Benjamin Renard   Update template a...
262
263
				$linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $tempArgs);
				$real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $tempArgs);
cd3326be   Benjamin Renard   Fix function used...
264
265
			}
			else {
7911f4bc   Benjamin Renard   Another bug with ...
266
267
				$real_linked_param_id = $linkedParamId;
				$linkedParamPath = IHMConfigClass::getLocalParamDBPath().$real_linked_param_id.".xml";
bf27ba04   Benjamin Renard   Add templated par...
268
			}
7911f4bc   Benjamin Renard   Another bug with ...
269
270
			$paramsData->addParamToCopy($real_linked_param_id,$linkedParamPath);
			$this->addLinkedLocalParams($linkedParamId, $paramsData);
22521f1c   Benjamin Renard   First commit
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
		}
	}

	/*
	 * @brief Add derived parameter
	*/
	private function addDerivedParam($param,$paramsData)
	{
		if (!isset($this->userParameterLoader))
			$this->userParameterLoader = new IHMUserParamLoaderClass();
		
		//get derived parameter info
		$res = $this->userParameterLoader->getDerivedParameterFromName($param);
		
		if (!$res["success"])
			throw new Exception('Error to load derived parameter file : '.$res["message"]);

		//parse expression
		if (!isset($this->expressionParser))
952dd7c7   elena   catalog integration
290
			$this->expressionParser = new IHMExpressionParserClass();
22521f1c   Benjamin Renard   First commit
291
292
		$expressionInfo = $this->expressionParser->parse($res["param"]["expression"]);
		
952dd7c7   elena   catalog integration
293
294
295
		$paramId = $param;
		
		//create a process param for the derived parameter
e9165342   Benjamin Renard   Write data mining...
296
		$this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"],
952dd7c7   elena   catalog integration
297
				$expressionInfo['params'], $res["param"]["timestep"],
c0535e83   Benjamin Renard   Use units and yTi...
298
299
				0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "",
				!empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData);
22521f1c   Benjamin Renard   First commit
300
301
302
		
		return array("id" => $paramId, "indexes" => array(), "calib_infos" => array());
	}
d1a35428   Benjamin Renard   Update template a...
303

ffc5cb81   Elena.Budnik   temporary commit
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
	/*
	 * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS
	*/
	private function addImpexParam($param,$paramsData,$templateArgs = NULL)	
	{		 	
		if (!isset($this->paramImpexMgr))
			$this->paramImpexMgr = new ImpexParamManager();
			
		$parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs);
		
		$requestNodes = $paramsData->getRequestNodes();
		 
		// it is PARAMSGEN 
		if (!$requestNodes) {
			return array("id" => $parameterID); 
		}
	 
		$timesNode = $requestNodes[0]->getTimesNode();
		$intervals = $timesNode->getIntervals();
		$originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml";
	  
		if (!file_exists($originFile)) {
			// create IMPEX parameter info and data				
			$res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs);
			
			if (!$res["success"])
				throw new Exception('Error to create IMPEX parameter : '.$res["message"]);
				
			$newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], 
				$res["param"]["info"]["viId"], $res["param"]["info"]["realVar"],
				$res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"],
				$res["param"]["info"]["type"],$res["param"]["info"]["size"],
				$res["param"]["dateModif"],true);
				
577d5c04   Elena.Budnik   IMPEX integration
338
339
340
341
				$newParamNode->getInfo()->setName($res["param"]["info"]['name']);
				$newParamNode->getInfo()->setShortName($res["param"]["info"]['name']);
				$newParamNode->getInfo()->setUnits($res["param"]["info"]['units']);
				
ffc5cb81   Elena.Budnik   temporary commit
342
343
344
				$tableDef = $res["param"]["info"]["tableDef"];
				if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE'))
				{
577d5c04   Elena.Budnik   IMPEX integration
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
					switch ($tableDef['channelsDefType'])
					{
						case 'BOUND'  :
							$boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]);
							$boundTable->setUnits($res["param"]["info"]["yUnits"]);
							switch ($tableDef['tableDefType'])
							{
								case 'SELECT' :
									$boundTable->setBoundsName($tableDef['data']['bound']);
									$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']);
									break;
								default :
									throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']);
							}
							break;
						case 'CENTER' :
							$centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]);
							$centerTable->setUnits($res["param"]["info"]["yUnits"]);
							$centerTable->setSize($tableDef['data']['width']);
							switch ($tableDef['tableDefType'])
							{
								case 'SELECT' :
									$centerTable->setCenterName($tableDef['data']['center']);
									$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']);
									break;
								default :
									throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']);
							}
						break;
						default :
							throw new Exception("Unknown tableDefType ".$tableDef['channelsDefType']);
					}
ffc5cb81   Elena.Budnik   temporary commit
377
378
379
380
381
382
383
384
385
386
387
388
389
				}
				
				return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]);
			}
		else {		     
			 // add IMPEX parameter data
			 $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs);			 
			 $paramsData->addParamToCopy($parameterID, $originFile);
			 
			 return array("id" => $parameterID);
		} 
	}
	
22521f1c   Benjamin Renard   First commit
390
391
392
393
394
	/*
	 * @brief Add uploaded parameter
	*/
	private function addUploadedParam($param,$paramsData)
	{
944199fe   Benjamin Renard   Use table definit...
395
396
397
398
399
400
401
402
		if (!isset($this->userParameterLoader))
			$this->userParameterLoader = new IHMUserParamLoaderClass();
		
		//get uploaded parameter info
		$res = $this->userParameterLoader->getUploadedParameterFromName($param);
		
		if (!$res["success"])
			throw new Exception('Error to load uploaded parameter file : '.$res["message"]);
67c43328   Benjamin Renard   Fix uploaded para...
403
404

		$paramId = $param;
944199fe   Benjamin Renard   Use table definit...
405
		
67c43328   Benjamin Renard   Fix uploaded para...
406
		$newParamNode = $paramsData->addLocalParamToCreate($paramId, 
944199fe   Benjamin Renard   Use table definit...
407
408
				$res["param"]["info"]["viId"], $res["param"]["info"]["realVar"],
				$res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"],
e8ff4ba7   Elena.Budnik   integration of as...
409
				$res["param"]["info"]["type"],$res["param"]["info"]["size"],
944199fe   Benjamin Renard   Use table definit...
410
				$res["param"]["dateModif"]);
e8ff4ba7   Elena.Budnik   integration of as...
411

8289ec06   Benjamin Renard   Y-Title and Units...
412
413
414
415
416
417
418
419
		if (!empty($res["param"]["info"]["yTitle"])) {
			$newParamNode->getInfo()->setName($res["param"]["info"]['yTitle']);
			$newParamNode->getInfo()->setShortName($res["param"]["info"]['yTitle']);
		}
		if (!empty($res["param"]["info"]['units'])) {
			$newParamNode->getInfo()->setUnits($res["param"]["info"]['units']);
		}

944199fe   Benjamin Renard   Use table definit...
420
421
422
423
		
		$tableDef = $res["param"]["info"]["tableDef"];
		if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE'))
		{
df380a21   Benjamin Renard   Fix table name de...
424
425
			$tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName'];
			$tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits'];
944199fe   Benjamin Renard   Use table definit...
426
427
428
			switch ($tableDef['channelsDefType'])
			{
				case 'MINMAX' :
df380a21   Benjamin Renard   Fix table name de...
429
430
					$minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName);
					$minMaxTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$minMaxTable->setMinName($tableDef['data']['min']);
							$minMaxTable->setMaxName($tableDef['data']['max']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']);
							break;
						case 'MANUAL' :
							$minMaxTable->setMinName('min');
							$minMaxTable->setMaxName('max');
							$clbMinNode = $newParamNode->addClbManual('min');
							$clbMinValues = explode(',', $tableDef['data']['min']);
							foreach ($clbMinValues as $value)
								$clbMinNode->addClbValue($value);
							$clbMaxNode = $newParamNode->addClbManual('max');
							$clbMaxValues = explode(',', $tableDef['data']['max']);
							foreach ($clbMaxValues as $value)
								$clbMaxNode->addClbValue($value);
						break;
					}
					break;
				case 'BOUND'  :
df380a21   Benjamin Renard   Fix table name de...
454
455
					$boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName);
					$boundTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$boundTable->setBoundsName($tableDef['data']['bound']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']);
							break;
						case 'MANUAL' :
							$boundTable->setBoundsName('bound');
							$clbBoundNode = $newParamNode->addClbManual('bound');
							$clbBoundValues = explode(',', $tableDef['data']['bound']);
							foreach ($clbBoundValues as $value)
								$clbBoundNode->addClbValue($value);
							break;
					}
					break;
				case 'CENTER' :
df380a21   Benjamin Renard   Fix table name de...
472
473
					$centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName);
					$centerTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
					$centerTable->setSize($tableDef['data']['width']);
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$centerTable->setCenterName($tableDef['data']['center']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']);
							break;
						case 'MANUAL' :
							$centerTable->setCenterName('center');
							$clbCenterNode = $newParamNode->addClbManual('center');
							$clbCenterValues = explode(',', $tableDef['data']['center']);
							foreach ($clbCenterValues as $value)
								$clbCenterNode->addClbValue($value);
							break;
					}
					break;
				case 'CENTERWIDTH' :
df380a21   Benjamin Renard   Fix table name de...
491
492
					$centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName);
					$centerWidthTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$centerWidthTable->setCenterName($tableDef['data']['center']);
							$centerWidthTable->setWidthName($tableDef['data']['width']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']);
							break;
						case 'MANUAL' :
							$centerWidthTable->setCenterName('center');
							$centerWidthTable->setWidthName('width');
							$clbCenterNode = $newParamNode->addClbManual('center');
							$clbWidthNode = $newParamNode->addClbManual('width');
							$clbCenterValues = explode(',', $tableDef['data']['center']);
							foreach ($clbCenterValues as $value)
								$clbCenterNode->addClbValue($value);
							$clbWidthValues = explode(',', $tableDef['data']['width']);
							foreach ($clbWidthValues as $value)
								$clbWidthNode->addClbValue($value);
							break;
					}
					break;
			}
		}
		
67c43328   Benjamin Renard   Fix uploaded para...
518
		return array("id" => $paramInfo, "plotType" => $res["param"]["info"]["plotType"]);
22521f1c   Benjamin Renard   First commit
519
	}
93c50989   Benjamin Renard   Support Tab2D par...
520
521

	public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) {
db7ea505   Benjamin Renard   Fix min max range...
522
523
524
525
526
		$dim1_min = 0;
		$dim1_max = 0;
		$dim2_min = 0;
		$dim2_max = 0;

76792c0e   Benjamin Renard   Sum parameters un...
527
		$dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0));
2c9760b6   Benjamin Renard   Fix empty index d...
528
		$dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'};
db7ea505   Benjamin Renard   Fix min max range...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
		if ($dim1_is_range) {
			switch ($paramData->{'dim1-sum-type'}) {
				case 1:
					//Sum between a range of value
					$dim1_min = !empty($paramData->{'dim1-min-value'}) ? $paramData->{'dim1-min-value'} : 0;
					$dim1_max = !empty($paramData->{'dim1-max-value'}) ? $paramData->{'dim1-max-value'} : 0;
					break;
				case 2:
					//Sum between indexes
					$dim1_min = !empty($paramData->{'dim1-min-index'}) ? $paramData->{'dim1-min-index'} : 0;
					$dim1_max = !empty($paramData->{'dim1-max-index'}) ? $paramData->{'dim1-max-index'} : 0;
					break;
			}
		}
93c50989   Benjamin Renard   Support Tab2D par...
543

76792c0e   Benjamin Renard   Sum parameters un...
544
		$dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0));
2c9760b6   Benjamin Renard   Fix empty index d...
545
		$dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'};
db7ea505   Benjamin Renard   Fix min max range...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
		if ($dim2_is_range) {
			switch ($paramData->{'dim2-sum-type'}) {
				case 1:
					//Sum between a range of value
					$dim2_min = !empty($paramData->{'dim2-min-value'}) ? $paramData->{'dim2-min-value'} : 0;
					$dim2_max = !empty($paramData->{'dim2-max-value'}) ? $paramData->{'dim2-max-value'} : 0;
					break;
				case 2:
					//Sum between indexes
					$dim2_min = !empty($paramData->{'dim2-min-index'}) ? $paramData->{'dim2-min-index'} : 0;
					$dim2_max = !empty($paramData->{'dim2-max-index'}) ? $paramData->{'dim2-max-index'} : 0;
					break;
			}
		}
93c50989   Benjamin Renard   Support Tab2D par...
560
561
562
563
564
565
566
567
568
569
570
571
572
573

		switch ($paramData->{'type'}) {
			case 0:
				//scalar - nothing to do
				break;
			case 1:
				//Tab1D
				if ($dim1_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim1_min,
						'max' => $dim1_max,
						'relateddim' => 0,
					);
76792c0e   Benjamin Renard   Sum parameters un...
574
					if ($paramData->{'dim1-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
575
576
577
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args);
93c50989   Benjamin Renard   Support Tab2D par...
578
579
580
581
582
583
584
585
				}
				else if ($dim2_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim2_min,
						'max' => $dim2_max,
						'relateddim' => 1,
					);
76792c0e   Benjamin Renard   Sum parameters un...
586
					if ($paramData->{'dim2-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
587
588
589
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args);
93c50989   Benjamin Renard   Support Tab2D par...
590
591
592
593
594
595
596
597
598
599
600
				}
				else if ($dim1_index != '*') {
					$paramInfo['indexes'][] = $dim1_index;
				}
				else if ($dim2_index != '*') {
					$paramInfo['indexes'][] = $dim2_index;
				}
				break;
			case 2:
				//Tab2D
				if ($dim1_is_range && $dim2_is_range) {
76792c0e   Benjamin Renard   Sum parameters un...
601
					if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) {
54219b37   Benjamin Renard   Add support for s...
602
603
						throw new Exception("Not supported - Dimensions ranges for ".$paramInfo['id']." must have the same type for each dimensions");
					}
93c50989   Benjamin Renard   Support Tab2D par...
604
605
606
607
608
609
610
611
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min1' => $dim1_min,
						'max1' => $dim1_max,
						'relateddim1' => 0,
						'min2' => $dim2_min,
						'max2' => $dim2_max,
					);
76792c0e   Benjamin Renard   Sum parameters un...
612
					if ($paramData->{'dim1-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
613
614
615
						$paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args);
93c50989   Benjamin Renard   Support Tab2D par...
616
617
618
619
620
621
622
623
				}
				else if ($dim1_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim1_min,
						'max' => $dim1_max,
						'relateddim' => 0,
					);
52859c27   Benjamin Renard   Give the possibil...
624
625
626
627
					$tableLink = array(
						'paramid' => $paramInfo['id'],
						'relateddim' => 1,
					);
76792c0e   Benjamin Renard   Sum parameters un...
628
					if ($paramData->{'dim1-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
629
630
631
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
93c50989   Benjamin Renard   Support Tab2D par...
632
633
634
635
636
637
638
639
640
641
642
					if ($dim2_index != '*') {
						$paramInfo['indexes'][] = $dim2_index;
					}
				}
				else if ($dim2_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim2_min,
						'max' => $dim2_max,
						'relateddim' => 1,
					);
52859c27   Benjamin Renard   Give the possibil...
643
644
645
646
					$tableLink = array(
						'paramid' => $paramInfo['id'],
						'relateddim' => 0,
					);
76792c0e   Benjamin Renard   Sum parameters un...
647
					if ($paramData->{'dim2-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
648
649
650
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
93c50989   Benjamin Renard   Support Tab2D par...
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
					if ($dim1_index != '*') {
						$paramInfo['indexes'][] = $dim1_index;
					}
				}
				else if (($dim1_index != '*') && ($dim2_index != '*')) {
					$paramInfo['indexes'][] = "[".$dim1_index.",".$dim2_index."]";
				}
				else if ($dim1_index != '*') {
					$paramInfo['indexes'][] = "[".$dim1_index.",*]";
				}
				else if ($dim2_index != '*') {
					$paramInfo['indexes'][] = "[*,".$dim2_index."]";
				}
				else if ($force_total_2d) {
					//total over 2 dims
					$template_args = array(
						'paramid' => $paramInfo['id'],
					);
					$paramInfo = $this->addExistingParam('total_2D', $paramsData, $template_args);
				}
				break;
		}
	}
22521f1c   Benjamin Renard   First commit
674
}