File size: 4,388 Bytes
68ce2fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 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 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
/*
Author(s): Praneeth Sadda
Created on: 2012-05-14
(C) Copyright 2012-2026 Johns Hopkins University (JHU), All Rights Reserved.
--- begin cisst license - do not edit ---
This software is provided "as is" under an open source license, with
no warranty. The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.
--- end cisst license ---
*/
#include <cisstMultiTask/mtsQtCommandSelector.h>
#include <QStringList>
mtsQtCommandSelector::mtsQtCommandSelector(mtsManagerLocal* componentManager, QWidget* parent)
: QTreeWidget(parent), LocalManager(componentManager)
{
setColumnCount(2);
QStringList headerLabels;
headerLabels << "Name" << "Type";
setHeaderLabels(headerLabels);
setSortingEnabled(true);
BuildTree(LocalManager);
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CurrentItemChanged));
connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(ItemActivated));
}
void mtsQtCommandSelector::BuildTree(mtsManagerLocal* componentManager) {
clear();
QTreeWidgetItem* processItem;
QTreeWidgetItem* componentItem;
QTreeWidgetItem* interfaceItem;
QTreeWidgetItem* commandItem;
QStringList strings;
std::vector<std::string> processNames;
std::vector<std::string> componentNames;
std::vector<std::string> interfaceRequiredNames;
std::vector<std::string> interfaceProvidedNames;
std::vector<std::string> commandNames;
componentManager->GetNamesOfProcesses(processNames);
// Processes
for(std::vector<std::string>::const_iterator processName = processNames.begin(); processName < processNames.end(); ++processName) {
strings << processName->c_str() << "Process";
processItem = new QTreeWidgetItem(strings);
addTopLevelItem(processItem);
strings.clear();
// Components
componentNames.clear();
componentManager->GetNamesOfComponents(*processName, componentNames);
for(std::vector<std::string>::const_iterator componentName = componentNames.begin(); componentName < componentNames.end(); ++componentName) {
strings << componentName->c_str() << "Component";
componentItem = new QTreeWidgetItem(strings);
processItem->addChild(componentItem);
strings.clear();
// Interfaces
interfaceRequiredNames.clear();
interfaceProvidedNames.clear();
// Provided or output
componentManager->GetNamesOfInterfaces(*processName, *componentName, interfaceRequiredNames, interfaceProvidedNames);
for(std::vector<std::string>::const_iterator interfaceName = interfaceProvidedNames.begin();
interfaceName < interfaceProvidedNames.end(); ++interfaceName) {
strings << interfaceName->c_str() << "Interface";
interfaceItem = new QTreeWidgetItem(strings);
componentItem->addChild(interfaceItem);
strings.clear();
// Commands
commandNames.clear();
// Note that following no longer accepts processName (as of June 2026)
//componentManager->GetNamesOfCommands(*processName, *componentName, *interfaceName, commandNames);
componentManager->GetNamesOfCommands(commandNames, *componentName, *interfaceName);
for(std::vector<std::string>::const_iterator commandName = commandNames.begin(); commandName < commandNames.end(); ++commandName) {
strings << commandName->c_str() << "Command";
commandItem = new QTreeWidgetItem(strings);
interfaceItem->addChild(commandItem);
strings.clear();
}
}
}
}
}
void mtsQtCommandSelector::Refresh(void) {
BuildTree(LocalManager);
}
void mtsQtCommandSelector::CurrentItemChanged(QTreeWidgetItem* CMN_UNUSED(current),
QTreeWidgetItem* CMN_UNUSED(previous)) {
}
void mtsQtCommandSelector::ItemActivated(QTreeWidgetItem* item, int CMN_UNUSED(column)) {
emit CommandSelected(item->text(0));
}
|