From 77cd22811bc9c00e22853921a2e7c1b16b74035a Mon Sep 17 00:00:00 2001 From: aschwinn <al.schwinn@gsi.de> Date: Fri, 12 May 2017 10:56:31 +0200 Subject: [PATCH] Bug 1183 - Only show blocks which are available for a selected device --- .../diagnostictoolmainview.cpp | 14 +++-- .../src/silecs-diagnostic/silecsmodule.cpp | 54 +++++++++++-------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp index 142acd2..43c16d5 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp @@ -747,14 +747,18 @@ void diagnosticToolMainView::fillClassNameComboBox() { Utils::logInfo(ui->console,"Loading deploy file: " + deployFile); XMLParser parserDeploy(deployFile,true); - boost::ptr_vector<ElementXML> classNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller/SilecsDesign"); - if(classNodes.size() == 0) + boost::ptr_vector<ElementXML> classNodes; + try + { + classNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller/SilecsDesign"); + } + catch(const Silecs::SilecsException& ex2) { - Utils::logError(ui->console,"No classes found for this Deploy"); + Utils::logError(ui->console,"No classes found for this Deploy:" + deployFile); return; } - QStringList list; + QStringList list; boost::ptr_vector<ElementXML>::const_iterator classIter; for(classIter = classNodes.begin(); classIter != classNodes.end(); classIter++) { @@ -762,6 +766,8 @@ void diagnosticToolMainView::fillClassNameComboBox() if(!list.contains(className)) list += className; } + QString headerName(HEADER_NAME.c_str()); + list += headerName; ui->classNameComboBox->clear(); ui->classNameComboBox->addItems(list); } diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp index a716747..5933ed4 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp @@ -87,23 +87,23 @@ Item *silecsModule::generateTree(string className, string deployFile) Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile); XMLParser parserDeploy(deployFile,true); - ElementXML silecsDesign = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Controller/SilecsDesign[@silecs-design-name='" + className + "']"); - string classVersion = silecsDesign.getAttribute("silecs-design-version"); - ElementXML deployUnitNode = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Deploy-Unit"); - string deployName = deployUnitNode.getAttribute("name"); - - silecsCluster = silecsService->getCluster(className,classVersion); root = new Item(silecsCluster); - root->setText(0,QString::fromStdString(className+" v"+classVersion)); + if( className == HEADER_NAME ) + { + silecsCluster = silecsService->getCluster(HEADER_NAME,HEADER_VERSION); + root->setText(0,QString::fromStdString(HEADER_NAME+" v"+HEADER_VERSION)); + } + else + { + ElementXML silecsDesign = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Controller/SilecsDesign[@silecs-design-name='" + className + "']"); + string classVersion = silecsDesign.getAttribute("silecs-design-version"); + silecsCluster = silecsService->getCluster(className,classVersion); + root->setText(0,QString::fromStdString(className+" v"+classVersion)); + } root->setWhatsThis(0,QString::fromStdString(CLUSTER_TYPE)); root->setLinkedObject(silecsCluster); boost::ptr_vector<ElementXML> controllerNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller"); - if(controllerNodes.size() == 0) - { - Utils::logError(messageConsole_,"No controller defined"); - return root; - } boost::ptr_vector<ElementXML>::const_iterator controllerIter; for(controllerIter = controllerNodes.begin(); controllerIter != controllerNodes.end(); controllerIter++) { @@ -114,11 +114,14 @@ Item *silecsModule::generateTree(string className, string deployFile) break; } Silecs::PLC *plc; + string parameterFile = ""; try { + ElementXML deployUnitNode = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Deploy-Unit"); + string deployName = deployUnitNode.getAttribute("name"); std::size_t deployFolderPos = deployFile.find(deployName); string deployProject = deployFile.substr(0,deployFolderPos) + deployName; - string parameterFile = deployProject + "/generated/client/" + plcName + ".silecsparam"; + parameterFile = deployProject + "/generated/client/" + plcName + ".silecsparam"; Utils::logInfo(messageConsole_,"Loading parameter file: " + parameterFile); plc = silecsCluster->getPLC(plcName,parameterFile); @@ -130,19 +133,26 @@ Item *silecsModule::generateTree(string className, string deployFile) } // add plc on the tree - Item *plcItem = Utils::addTreeItem(root,QString::fromStdString(plcName), - "",QString::fromStdString(PLC_TYPE),plc,":/Images/PLC.png"); + Item *plcItem = Utils::addTreeItem(root,QString::fromStdString(plcName),"",QString::fromStdString(PLC_TYPE),plc,":/Images/PLC.png"); - // get devices for the current PLC - deviceVectorType deviceMap = plc->getDeviceMap(); - - deviceVectorType::iterator pDeviceIter; - for(pDeviceIter = deviceMap.begin(); pDeviceIter != deviceMap.end(); ++pDeviceIter) + boost::ptr_vector<ElementXML> instances; + XMLParser parseParam(parameterFile,true); + try + { + instances = parseParam.getElementsFromXPath_throwIfEmpty("/SILECS-Param/SILECS-Mapping/SILECS-Class[@name='" + className + "']/Instance"); + } + catch(const Silecs::SilecsException& ex2) { - std::string deviceName = pDeviceIter->first; + Utils::logError(messageConsole_,"Failed to fetch instances for class '" + className + "' from parameter-file '" + parameterFile + "':" + ex2.what()); + break; + } - Silecs::Device *device = pDeviceIter->second; + boost::ptr_vector<ElementXML>::iterator pInstanceIter; + for(pInstanceIter = instances.begin(); pInstanceIter != instances.end(); ++pInstanceIter) + { + std::string deviceName = pInstanceIter->getAttribute("label"); Utils::logInfo(messageConsole_,"found device: '" + deviceName + "' in parameter-file"); + Silecs::Device *device = plc->getDevice(deviceName); // add device on the tree Item *deviceItem = Utils::addTreeItem(plcItem,QString::fromStdString(deviceName),"",QString::fromStdString(DEVICE_TYPE),device,":/Images/DEV.png"); -- GitLab