Skip to content
Snippets Groups Projects
Commit 77cd2281 authored by al.schwinn's avatar al.schwinn
Browse files

Bug 1183 - Only show blocks which are available for a selected device

parent 15d85466
No related branches found
No related tags found
No related merge requests found
...@@ -747,14 +747,18 @@ void diagnosticToolMainView::fillClassNameComboBox() ...@@ -747,14 +747,18 @@ void diagnosticToolMainView::fillClassNameComboBox()
{ {
Utils::logInfo(ui->console,"Loading deploy file: " + deployFile); Utils::logInfo(ui->console,"Loading deploy file: " + deployFile);
XMLParser parserDeploy(deployFile,true); XMLParser parserDeploy(deployFile,true);
boost::ptr_vector<ElementXML> classNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller/SilecsDesign"); boost::ptr_vector<ElementXML> classNodes;
if(classNodes.size() == 0) 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; return;
} }
QStringList list;
QStringList list;
boost::ptr_vector<ElementXML>::const_iterator classIter; boost::ptr_vector<ElementXML>::const_iterator classIter;
for(classIter = classNodes.begin(); classIter != classNodes.end(); classIter++) for(classIter = classNodes.begin(); classIter != classNodes.end(); classIter++)
{ {
...@@ -762,6 +766,8 @@ void diagnosticToolMainView::fillClassNameComboBox() ...@@ -762,6 +766,8 @@ void diagnosticToolMainView::fillClassNameComboBox()
if(!list.contains(className)) if(!list.contains(className))
list += className; list += className;
} }
QString headerName(HEADER_NAME.c_str());
list += headerName;
ui->classNameComboBox->clear(); ui->classNameComboBox->clear();
ui->classNameComboBox->addItems(list); ui->classNameComboBox->addItems(list);
} }
......
...@@ -87,23 +87,23 @@ Item *silecsModule::generateTree(string className, string deployFile) ...@@ -87,23 +87,23 @@ Item *silecsModule::generateTree(string className, string deployFile)
Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile); Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile);
XMLParser parserDeploy(deployFile,true); 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 = 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->setWhatsThis(0,QString::fromStdString(CLUSTER_TYPE));
root->setLinkedObject(silecsCluster); root->setLinkedObject(silecsCluster);
boost::ptr_vector<ElementXML> controllerNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller"); 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; boost::ptr_vector<ElementXML>::const_iterator controllerIter;
for(controllerIter = controllerNodes.begin(); controllerIter != controllerNodes.end(); controllerIter++) for(controllerIter = controllerNodes.begin(); controllerIter != controllerNodes.end(); controllerIter++)
{ {
...@@ -114,11 +114,14 @@ Item *silecsModule::generateTree(string className, string deployFile) ...@@ -114,11 +114,14 @@ Item *silecsModule::generateTree(string className, string deployFile)
break; break;
} }
Silecs::PLC *plc; Silecs::PLC *plc;
string parameterFile = "";
try try
{ {
ElementXML deployUnitNode = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Deploy-Unit");
string deployName = deployUnitNode.getAttribute("name");
std::size_t deployFolderPos = deployFile.find(deployName); std::size_t deployFolderPos = deployFile.find(deployName);
string deployProject = deployFile.substr(0,deployFolderPos) + 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); Utils::logInfo(messageConsole_,"Loading parameter file: " + parameterFile);
plc = silecsCluster->getPLC(plcName,parameterFile); plc = silecsCluster->getPLC(plcName,parameterFile);
...@@ -130,19 +133,26 @@ Item *silecsModule::generateTree(string className, string deployFile) ...@@ -130,19 +133,26 @@ Item *silecsModule::generateTree(string className, string deployFile)
} }
// add plc on the tree // add plc on the tree
Item *plcItem = Utils::addTreeItem(root,QString::fromStdString(plcName), Item *plcItem = Utils::addTreeItem(root,QString::fromStdString(plcName),"",QString::fromStdString(PLC_TYPE),plc,":/Images/PLC.png");
"",QString::fromStdString(PLC_TYPE),plc,":/Images/PLC.png");
// get devices for the current PLC boost::ptr_vector<ElementXML> instances;
deviceVectorType deviceMap = plc->getDeviceMap(); XMLParser parseParam(parameterFile,true);
try
deviceVectorType::iterator pDeviceIter; {
for(pDeviceIter = deviceMap.begin(); pDeviceIter != deviceMap.end(); ++pDeviceIter) 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"); Utils::logInfo(messageConsole_,"found device: '" + deviceName + "' in parameter-file");
Silecs::Device *device = plc->getDevice(deviceName);
// add device on the tree // add device on the tree
Item *deviceItem = Utils::addTreeItem(plcItem,QString::fromStdString(deviceName),"",QString::fromStdString(DEVICE_TYPE),device,":/Images/DEV.png"); Item *deviceItem = Utils::addTreeItem(plcItem,QString::fromStdString(deviceName),"",QString::fromStdString(DEVICE_TYPE),device,":/Images/DEV.png");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment