templateParamsManager = new IHMParamTemplateClass();
$this->cacheExpressionParser = array();
}
public function addGeneratedParam($paramId, $expression, $sampling_mode, $sampling_step, $ref_param, $paramsData)
{
$expressionInfo = $this->parseExpression($expression, $paramsData->getWorkingPath());
if (!$expressionInfo['success']) {
throw new Exception($expressionInfo['message']);
}
//create a process param for the derived parameter
$this->addProcessParam($paramId, $expressionInfo["expression"], $expression,
$expressionInfo['params'], $sampling_mode, $sampling_step, $ref_param,
0, time(), "", "","", $paramsData);
}
/*
* @brief Add an existing parameter
*/
public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL)
{
if ($this->isDerivedParam($param))
return $this->addDerivedParam($param,$paramsData);
else if ($this->isUploadedParam($param))
return $this->addUploadedParam($param,$paramsData);
else if ($this->isImpexParam($param))
return $this->addImpexParam($param,$paramsData,$templateArgs);
else if($this->isTTCatParam($param))
return $this->addTTCatParam($param,$paramsData);
else
return $this->addLocalParam($param,$paramsData,$templateArgs, $tableLink);
return "";
}
public function statusStrToArray($statusStr){
$defs = explode("-",$statusStr);
if (!empty($statusStr)) {
foreach ($defs as $def) {
$def = trim($def);
$p = strpos($def, ":");
if ($p === FALSE) {
continue;
}
$vals = trim(substr($def, 0, $p));
$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);
if(empty($name))
$name = $vals;
}
$p2=strpos($vals, ",");
$minVal = "";
$maxVal = "";
if ($p2 !== FALSE) {
$minVal= trim(substr($vals, 1, $p2));
$maxVal = trim(substr($vals,$p2+1, -1));
}
else{
$minVal= $vals;
$maxVal = $vals;
}
$status[] = array(
"min" => floatval($minVal),
"max" => floatval($maxVal),
"name" => $name,
"color" => $color,
);
}
return $status;
}
}
/*
* @brief Add a process parameter
*/
public function addProcessParam($paramId,$expression,$expression_info,$params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif,$units,$ytitle,$statusStr,$paramsData)
{
$status = $this->statusStrToArray($statusStr);
$paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif, $units, $ytitle, $status);
foreach ($params as $param) {
$template_args = NULL;
if (array_key_exists("template_args", $param))
$template_args = $param["template_args"];
$this->addExistingParam($param["paramid"],$paramsData,$template_args);
}
if (!empty($ref_param)) {
$this->addExistingParam($ref_param, $paramsData,$template_args);
}
return true;
}
/*
* @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"]) {
$paramName = $paramId;
foreach(array("tt_","cat_","sharedtimeTable_","sharedcartalog_") as $prefix){
if(strpos($paramName, $prefix) === 0){
$paramName = substr($paramName, strlen($prefix));
break;
}
}
$info = $this->ttCatMgr->getTTCatInfoFromName($paramName);
if (!$info["success"]) {
throw new Exception($info["message"]);
}
}
$status = array();
$units = "";
$ytitle = "";
$flag = "";
if ($info["info"]["isCatalog"]) {
$parameters = $this->ttCatMgr->getCatalogParameters($info["info"]["id"]);
if (!$parameters["success"] || empty($parameters["parameters"])) {
throw new Exception("Error to extract first parameter of ".$info["info"]["id"]);
}
//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"];
$statusParam = $parameter["status"];
$desc_parts = array();
$defs = explode("-",$statusParam);
if (empty($statusParam)) {
//No status defined => Read catalog as TT
$info["info"]["isCatalog"] = FALSE;
$flag = "";
$units = "";
$ytitle = $info["info"]["name"];
$status = array(
array(
"min" => -PHP_FLOAT_MAX,
"max" => PHP_FLOAT_MAX,
"name" => "Inside",
//"color" => "[255,0,0]",
),
);
}
else {
$status = $this->statusStrToArray($statusParam);
}
}
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());
}
/*
* @brief Detect if it's a derived parameter
*/
private function isDerivedParam($param)
{
return preg_match("#^ws_#",$param);
}
/*
* @brief Detect if it's a TT/Cat parameter
*/
private function isTTCatParam($param)
{
return preg_match("#^tt_#",$param) || preg_match("#^cat_#",$param) ||
preg_match("#^sharedtimeTable_#",$param) || preg_match("#^sharedcatalog_#",$param);
}
/*
* @brief Detect if it's a uploaded parameter
*/
public function isUploadedParam($param)
{
return preg_match("#^wsd_#",$param);
}
/*
* @brief Detect if it's IMPEX parameter
*/
private function isImpexParam($param)
{
return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param);
}
/*
* @brief Split param components if defined
*/
private function splitParamComponents($param)
{
$indexes = array();
$pattern = "/(?P.*)\((?P.*)\)/";
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;
return array('param' => $paramId, 'indexes' => $indexes);
}
/*
* @brief Add a local parameter
*/
private function addLocalParam($param, $paramsData, $templateArgs, $tableLink)
{
//local parameter
$res = $this->splitParamComponents($param);
$indexes = $res['indexes'];
$paramId = $res['param'];
$calib_infos = array();
//check templated parameter
$real_param_id = $paramId;
$paramPath = "";
if ($this->templateParamsManager->isTemplatedParam($paramId)) {
$paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink);
$real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs);
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);
}
$paramsData->addParamToCopy($real_param_id,$paramPath);
$this->addLinkedLocalParams($paramId, $paramsData, $templateArgs);
return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos, "path" => $paramPath);
}
/*
* @brief Add linked parameter
*/
private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL)
{
$doc = new DOMDocument("1.0", "UTF-8");
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$real_param_id = $paramId;
if ($this->templateParamsManager->isTemplatedParam($paramId)) {
$paramPath = $this->templateParamsManager->getTemplatePath($paramId);
if (empty($paramPath) || !@$doc->load($paramPath))
throw new Exception('Cannot find parameter template file '.$paramId);
}
else {
$paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
if (empty($paramPath) || !@$doc->load($paramPath))
throw new Exception('Cannot find parameter local file '.$paramId);
}
//
$getNodes = $doc->getElementsByTagName('get');
if ($getNodes->length <= 0)
throw new Exception('Parameter local file '.$paramId.' dont have a getter node');
$getNode = $getNodes->item(0);
//
$amdaParamNodes = $doc->getElementsByTagName('amdaParam');
foreach($amdaParamNodes as $amdaParamNode)
{
$linkedParamId = $amdaParamNode->getAttribute('name');
if (empty($linkedParamId))
continue;
$template_id = $this->templateParamsManager->getTemplateId($linkedParamId);
$tempArgs = isset($templateArgs) ? $templateArgs : array();
if ($template_id !== FALSE) {
$linkedParamId = $template_id;
}
else {
$linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs);
$parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId);
if ($parsedParam !== FALSE) {
$linkedParamId = $parsedParam['paramid'];
foreach ($parsedParam['template_args'] as $key => $val) {
$tempArgs[$key] = $val;
}
}
}
$this->addExistingParam($linkedParamId, $paramsData, $templateArgs);
}
}
/*
* @brief Add derived parameter
*/
private function addDerivedParam($param,$paramsData)
{
$res = $this->splitParamComponents($param);
$indexes = $res['indexes'];
$param = $res['param'];
$time = time();
if (!isset($this->userParameterMgr))
$this->userParameterMgr = new IHMUserParamManagerClass();
//get derived parameter info
$res = $this->userParameterMgr->getDerivedParameterFromName($param);
if (!$res["success"])
throw new Exception('Error to load derived parameter file : '.$res["message"]);
if (isset($res["param"]["info"]["parsedExpression"])) {
//Re use existing parsed expression info
$expressionInfo = $res["param"]["info"]["parsedExpression"];
}
else {
//parse expression
$expressionInfo = $this->parseExpression($res["param"]["expression"], $paramsData->getWorkingPath());
if (!$expressionInfo['success']) {
throw new Exception($expressionInfo['message']);
}
$this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $expressionInfo['params']);
}
$paramId = $param;
$reference_param = $res["param"]["info"]["reference_param"];
if (!empty($res["param"]["info"]["reference_param"])) {
$res_split = $this->splitParamComponents($reference_param);
$reference_param = $res_split['param'];
}
// On plot, no need to plot "ws_" on derived parameter legend.
$newParamName="";
if(strpos($paramId, "ws_") === 0){
$newParamName=substr($paramId,3);
}
//create a process param for the derived parameter
$this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"],
$expressionInfo['params'], $res["param"]["info"]["sampling_mode"], $res["param"]["info"]["timestep"], $reference_param,
0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "",
!empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : $newParamName,
!empty($res["param"]["info"]["status"]) ? $res["param"]["info"]["status"] : "", $paramsData);
return array("id" => $paramId, "indexes" => $indexes, "calib_infos" => array());
}
/*
* @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"],
NULL,$res["param"]["dateModif"],"",true);
$newParamNode->getInfo()->setName($res["param"]["info"]['name']);
$newParamNode->getInfo()->setShortName($res["param"]["info"]['name']);
$newParamNode->getInfo()->setUnits($res["param"]["info"]['units']);
$tableDef = $res["param"]["info"]["tableDef"];
if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE'))
{
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']);
}
}
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);
}
}
/*
* @brief Add uploaded parameter
*/
private function addUploadedParam($param,$paramsData)
{
$res = $this->splitParamComponents($param);
$indexes = $res['indexes'];
$param = $res['param'];
if (!isset($this->userParameterMgr))
$this->userParameterMgr = new IHMUserParamManagerClass();
//get uploaded parameter info
$res = $this->userParameterMgr->getUploadedParameterFromName($param);
if (!$res["success"])
throw new Exception('Error to load uploaded parameter file : '.$res["message"]);
$paramId = $param;
$status = $this->statusStrToArray($res["param"]["info"]["status"]);
$newParamNode = $paramsData->addLocalParamToCreate($paramId,
$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"]["info"]["fillValue"],$res["param"]["dateModif"],$status);
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']);
}
$tableDef = $res["param"]["info"]["tableDef"];
if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE'))
{
$tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName'];
$tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits'];
switch ($tableDef['channelsDefType'])
{
case 'MINMAX' :
$minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName);
$minMaxTable->setUnits($tableUnits);
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' :
$boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName);
$boundTable->setUnits($tableUnits);
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' :
$centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName);
$centerTable->setUnits($tableUnits);
$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' :
$centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName);
$centerWidthTable->setUnits($tableUnits);
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;
}
}
return array("id" => $paramId, "indexes" => $indexes, "plotType" => $res["param"]["info"]["plotType"]);
}
public function applyFilter($paramsData, $paramData, &$paramInfo) {
$filter = (isset($paramData->{'param-drawing-object'}->{'filtering-activated'}) && ($paramData->{'param-drawing-object'}->{'filtering-activated'})) ? true : false;
if (!$filter) {
return;
}
$my_type = $paramData->{'type'};
switch ($paramData->{'type'}) {
case 0:
case 1:
case 2:
// vector
$dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'};
$dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'};
if (isset($paramData->{'param-drawing-object'}->{'filtering-level'})) {
switch ($paramData->{'param-drawing-object'}->{'filtering-level'}) {
case 1:
$factor = 6;
$nPoints = 100;
$level = "weak";
break;
case 2:
$factor = 5;
$nPoints = 100;
$level = "intermediate";
break;
case 3:
$factor = 4;
$nPoints = 100;
$level = "strong";
break;
default:
$factor = 6;
$nPoints = 100;
$level = "low";
}
} else {
$factor = 5;
$nPoints = 100;
}
if ($dim1_index != '*') {
$template_args = array(
'paramid' => $paramInfo['id'],
'factor' => $factor,
'nPoints' => $nPoints,
'index' => $dim1_index,
'level' => $level
);
$paramInfo = $this->addExistingParam('filter_spikes_component', $paramsData, $template_args);
} else {
$template_args = array(
'paramid' => $paramInfo['id'],
'factor' => $factor,
'nPoints' => $nPoints,
'level' => $level
);
$paramInfo = $this->addExistingParam('filter_spikes', $paramsData, $template_args);
}
break;
}
}
public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) {
$dim1_min = 0;
$dim1_max = 0;
$dim2_min = 0;
$dim2_max = 0;
$dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0));
$dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'};
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;
}
}
$dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0));
$dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'};
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;
}
}
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,
);
if ($paramData->{'dim1-sum-type'} == 2)
$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args);
else
$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args);
}
else if ($dim2_is_range) {
$template_args = array(
'paramid' => $paramInfo['id'],
'min' => $dim2_min,
'max' => $dim2_max,
'relateddim' => 1,
);
if ($paramData->{'dim2-sum-type'} == 2)
$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args);
else
$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args);
}
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) {
if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) {
throw new Exception("Not supported - Dimensions ranges for ".$paramInfo['id']." must have the same type for each dimensions");
}
$template_args = array(
'paramid' => $paramInfo['id'],
'min1' => $dim1_min,
'max1' => $dim1_max,
'relateddim1' => 0,
'min2' => $dim2_min,
'max2' => $dim2_max,
);
if ($paramData->{'dim1-sum-type'} == 2)
$paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args);
else
$paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args);
}
else if ($dim1_is_range) {
$template_args = array(
'paramid' => $paramInfo['id'],
'min' => $dim1_min,
'max' => $dim1_max,
'relateddim' => 0,
);
$tableLink = array(
'paramid' => $paramInfo['id'],
'relateddim' => 1,
);
if ($paramData->{'dim1-sum-type'} == 2)
$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink);
else
$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
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,
);
$tableLink = array(
'paramid' => $paramInfo['id'],
'relateddim' => 0,
);
if ($paramData->{'dim2-sum-type'} == 2)
$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink);
else
$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
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;
}
}
public function parseExpression($expression, $workingDir) {
$outputFileName = "parser_".md5($expression).".xml";
if (array_key_exists($outputFileName, $this->cacheExpressionParser)) {
return $this->cacheExpressionParser[$outputFileName];
}
$parserData = new ParserRequestDataClass();
$parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
$parserData->addExpression($expression);
$parserData->setWorkingPath($workingDir);
$parserData->setLocalParamsPath(IHMConfigClass::getLocalParamDBPath());
$parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath());
$parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath());
$parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath());
$parserData->setFunctionsArgsListFilePath(IHMConfigClass::getFunctionsArgsListFilePath());
$parserData->setOutputFileName($outputFileName);
$resultFilePath = $workingDir."/".$outputFileName;
$parserRequest = new ParserRequestClass();
$parserRequest->setData($parserData);
if (!$parserRequest->init() || !$parserRequest->run()) {
if (file_exists($resultFilePath)) {
unlink($resultFilePath);
}
return array('success' => FALSE, 'message' => 'Error to init or run expression parser');
}
//Load result file
$doc = new DOMDocument();
$doc->load($resultFilePath);
if (!$doc->load($resultFilePath)) {
if (file_exists($resultFilePath)) {
unlink($resultFilePath);
}
return array('success' => FALSE, 'message' => 'Error to load parser result file');
}
$expressionNodes = $doc->getElementsByTagName('expression');
if ($expressionNodes->length == 0) {
unlink($resultFilePath);
return array('success' => FALSE, 'message' => 'Cannot get expression nodes in parser result file');
}
$crtExpressionNode = NULL;
foreach ($expressionNodes as $expressionNode) {
$ihmExpressionNodes = $expressionNode->getElementsByTagName('ihm');
if ($ihmExpressionNodes->length == 0) {
continue;
}
if ($ihmExpressionNodes->item(0)->nodeValue == $expression) {
$crtExpressionNode = $expressionNode;
break;
}
}
if (!isset($crtExpressionNode)) {
unlink($resultFilePath);
return array('success' => FALSE, 'message' => 'Cannot retrieve expression in parser result file');
}
if ($crtExpressionNode->getAttribute('success') != "true") {
unlink($resultFilePath);
return array('success' => FALSE, 'message' => 'Syntax error in expression '.$expression);
}
$kernelExpressionNodes = $crtExpressionNode->getElementsByTagName('kernel');
if ($kernelExpressionNodes->length == 0) {
unlink($resultFilePath);
return array('success' => FALSE, 'message' => 'Cannot retrieve kernel expression in parser result file');
}
$kernelExpression = $kernelExpressionNodes->item(0)->nodeValue;
if (empty($kernelExpression)) {
unlink($resultFilePath);
return array('success' => FALSE, 'message' => 'Parser return an empty expression');
}
$params = array();
$paramsNodes = $crtExpressionNode->getElementsByTagName('params');
if ($paramsNodes->length != 0) {
$paramNodes = $paramsNodes->item(0)->getElementsByTagName('param');
if ($paramNodes->length != 0) {
foreach ($paramNodes as $paramNode) {
if (!empty($paramNode->nodeValue)) {
$params[] = array(
'paramid' => $paramNode->nodeValue
);
}
}
}
}
unlink($resultFilePath);
if (empty($params)) {
return array('success' => FALSE, 'message' => 'Expression should contain at least one parameter');
}
foreach ($params as &$param) {
$templated_param = $this->templateParamsManager->parseTemplatedParam($param['paramid']);
if ($templated_param !== FALSE) {
$param = $templated_param;
}
}
$this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params);
return $this->cacheExpressionParser[$outputFileName];
}
public function getTemplateParamsManager() {
return $this->templateParamsManager;
}
}