diff --git a/config/AMDAIntegrationConfig.php b/config/AMDAIntegrationConfig.php index bb9389c..849a73c 100644 --- a/config/AMDAIntegrationConfig.php +++ b/config/AMDAIntegrationConfig.php @@ -130,6 +130,9 @@ define('NEWKERNEL_INFO_DIR', NEWKERNEL_BASE_PATH.'config/'); //Path to local parameters database for the new kernel define('PARAMS_LOCALDB_DIR', IHM_SRC_DIR.'generic_data/newKernelDDBase/'); +//Path to local parameters information files +define('PARAMS_LOCALINFO_DIR', IHM_SRC_DIR.'generic_data/ParamInfo/'); + //Path to dir that include DD.res file define('DDRES_DIR', NEWKERNEL_BASE_PATH.'app-debug/'); diff --git a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php index 3285871..6198758 100644 --- a/src/InputOutput/IHMImpl/Config/IHMConfigClass.php +++ b/src/InputOutput/IHMImpl/Config/IHMConfigClass.php @@ -10,7 +10,7 @@ class IHMConfigClass private static $genericDataDir = "generic_data/"; private static $functionsDir = "Functions/"; - + private static $constantsFile = "constants.xml"; private static $functionsFile = "functions.xml"; @@ -95,6 +95,11 @@ class IHMConfigClass { return PARAMS_LOCALDB_DIR; } + + public static function getLocalParamInfoPath() + { + return PARAMS_LOCALINFO_DIR; + } public static function getSharedTTPath() { diff --git a/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php b/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php index e63e09d..df1865b 100644 --- a/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php +++ b/src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php @@ -26,19 +26,35 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface 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"); + + + $paramInfoFilePath = IHMConfigClass::getLocalParamInfoPath().'info_'.$input->paramId.".xml"; + + if (!file_exists($paramInfoFilePath)) + throw new Exception("Cannot find parameter info file " . $paramInfoFilePath); + + $this->paramInfoData->setFilePath($paramInfoFilePath); break; default : throw new Exception("Para info request type '".$input->type."' not yet implemented"); } - 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->setParamId($input->paramId); - $this->paramInfoData->setParamPath($paramFilePath); return $this->paramInfoData; } @@ -48,86 +64,14 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface */ public function getOutput($data) { - $result = array("success" => false, "message" => "Cannot load plot init"); - switch ($data->getType()) { case ParamInfoTypeEnumClass::PLOTINIT : - if (($data->getResultNode() != NULL) && ($data->getResultNode()->getName() == "plot") && (count($data->getResultNode()->getChildren()) >= 1)) { - $result_data = array(); - - $panelNode = $data->getResultNode()->getChildren()[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 - ); - } - }*/ - } + $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 @@ -136,6 +80,94 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface return $result; } + private function getOutputParamInfo($data, &$result) { + if (($data->getResult() != NULL)) { + $result = array( + "success" => true, + "data" => $data->getResult() + ); + } + } + + private function getOutputPlotInit($data, &$result) { + if (($data->getResult() != NULL) && ($data->getResult()->getName() == "plot") && (count($data->getResult()->getChildren()) >= 1)) { + $result_data = array(); + + $panelNode = $data->getResult()->getChildren()[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(); diff --git a/src/Request/ParamInfoRequestClass.php b/src/Request/ParamInfoRequestClass.php index 83b8cbc..ab43ebc 100644 --- a/src/Request/ParamInfoRequestClass.php +++ b/src/Request/ParamInfoRequestClass.php @@ -14,9 +14,11 @@ class ParamInfoRequestClass extends RequestAbstractClass if (!isset($this->requestData)) return false; - //Force load of node files to init the NodeFactory - foreach (glob(dirname(__FILE__)."/ParamsRequestImpl/Nodes/Requests/*NodeClass.php") as $filename) { - require_once $filename; + if ($this->requestData->getType() == ParamInfoTypeEnumClass::PLOTINIT) { + //Force load of node files to init the NodeFactory + foreach (glob(dirname(__FILE__)."/ParamsRequestImpl/Nodes/Requests/*NodeClass.php") as $filename) { + require_once $filename; + } } return TRUE; @@ -30,15 +32,31 @@ class ParamInfoRequestClass extends RequestAbstractClass $dom = new DOMDocument("1.0","UTF-8"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; - $res = $dom->load($this->requestData->getParamPath()); + $res = $dom->load($this->requestData->getFilePath()); + $this->requestData->setSuccess(false); - + if (!$res) { - $this->requestData->setLastErrorMessage("Cannot load parameter file"); + $this->requestData->setLastErrorMessage("Cannot load file"); return false; } + switch ($this->requestData->getType()) { + case ParamInfoTypeEnumClass::PLOTINIT : + $this->runFromParamFile($dom); + break; + case ParamInfoTypeEnumClass::PARAMINFO : + $this->runFromParamInfoFile($dom); + break; + default : + $this->requestData->setLastErrorMessage("Unknown ParamInfo type"); + } + + return $this->requestData->getSuccess(); + } + + private function runFromParamFile($dom) { $paramNode = new ParamNodeClass(); try { @@ -60,14 +78,72 @@ class ParamInfoRequestClass extends RequestAbstractClass $this->requestData->setLastErrorMessage("Cannot parse plot node"); return false; } - $this->requestData->setResultNode($plotNode); + $this->requestData->setResult($plotNode); $this->requestData->setSuccess(true); - break; + return true; default : $this->requestData->setLastErrorMessage("Unknown param info request"); } - return $this->requestData->getSuccess(); + return false; + } + + private function runFromParamInfoFile($dom) { + $result = array(); + + // Dimensions + $dimsNodes = $dom->getElementsByTagName("dimensions"); + if ($dimsNodes->length > 0) { + $dimsNode = $dimsNodes->item(0); + $result['dimensions'] = array( + 'dim_1' => $dimsNode->getAttribute("dim_1"), + 'dim_2' => $dimsNode->getAttribute("dim_2") + ); + } + + // Components + $compNodes = $dom->getElementsByTagName("components"); + if ($compNodes->length > 0) { + $compNode = $compNodes->item(0); + $result['components'] = array(); + foreach ($compNode->getElementsByTagName("component") as $componentNode) { + $result['components'][] = array( + 'index_1' => $componentNode->getAttribute("index_1"), + 'index_2' => $componentNode->getAttribute("index_2"), + 'name' => $componentNode->getAttribute("name") + ); + } + } + + // Tables + $tablesNodes = $dom->getElementsByTagName("tables"); + if ($tablesNodes->length > 0) { + $tablesNode = $tablesNodes->item(0); + $result['tables'] = array(); + foreach ($tablesNode->getElementsByTagName("table") as $tableNode) { + $tableResult = array( + 'relatedDim' => $tableNode->getAttribute("relatedDim"), + 'name' => $tableNode->getAttribute("name"), + 'units' => $tableNode->getAttribute("units"), + 'channels' => array() + ); + + $channelNodes = $tableNode->getElementsByTagName("channel"); + foreach ($channelNodes as $channelNode) { + $tableResult['channels'][] = array( + 'min' => $channelNode->getAttribute("min"), + 'max' => $channelNode->getAttribute("max") + ); + } + + $result['tables'][] = $tableResult; + } + } + + $this->requestData->setResult($result); + $this->requestData->setSuccess(true); + + return true; } } ?> \ No newline at end of file diff --git a/src/Request/ParamInfoRequestDataClass.php b/src/Request/ParamInfoRequestDataClass.php index 9a03075..8758ae2 100644 --- a/src/Request/ParamInfoRequestDataClass.php +++ b/src/Request/ParamInfoRequestDataClass.php @@ -9,6 +9,7 @@ abstract class ParamInfoTypeEnumClass { const UNKNOWN = ""; const PLOTINIT = "plot_init"; + const PARAMINFO = "param_info"; } /** @@ -18,19 +19,19 @@ abstract class ParamInfoTypeEnumClass */ class ParamInfoRequestDataClass extends RequestDataClass { - private $paramPath = ""; + private $filePath = ""; private $paramId = ""; private $type = ParamInfoTypeEnumClass::UNKNOWN; - private $resultNode = NULL; + private $result = NULL; - public function getParamPath() + public function getFilePath() { - return $this->paramPath; + return $this->filePath; } - public function setParamPath($paramPath) + public function setFilePath($filePath) { - $this->paramPath = $paramPath; + $this->filePath = $filePath; } public function getType() @@ -43,14 +44,14 @@ class ParamInfoRequestDataClass extends RequestDataClass $this->type = $type; } - public function getResultNode() + public function getResult() { - return $this->resultNode; + return $this->result; } - public function setResultNode($resultNode) + public function setResult($result) { - $this->resultNode = $resultNode; + $this->result = $result; } public function getParamId() -- libgit2 0.21.2