| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// |
| 2 |
|
|
// Copyright (c) CNRS |
| 3 |
|
|
// Authors: Joseph Mirabel and Heidy Dallard |
| 4 |
|
|
// |
| 5 |
|
|
|
| 6 |
|
|
#include "hppwidgetsplugin/configurationlistwidget.hh" |
| 7 |
|
|
|
| 8 |
|
|
#include <hppwidgetsplugin/hppwidgetsplugin.hh> |
| 9 |
|
|
|
| 10 |
|
|
#include "hpp/corbaserver/client.hh" |
| 11 |
|
|
#include "hppwidgetsplugin/ui_configurationlistwidget.h" |
| 12 |
|
|
|
| 13 |
|
|
namespace hpp { |
| 14 |
|
|
namespace gui { |
| 15 |
|
|
const int ConfigurationListWidget::ConfigRole = Qt::UserRole + 1; |
| 16 |
|
|
|
| 17 |
|
|
namespace { |
| 18 |
|
|
class ConfigItem : public QListWidgetItem { |
| 19 |
|
|
public: |
| 20 |
|
✗ |
ConfigItem(QString text, const hpp::floatSeq& q) |
| 21 |
|
✗ |
: QListWidgetItem(text), q_(q) {} |
| 22 |
|
|
|
| 23 |
|
|
hpp::floatSeq q_; |
| 24 |
|
|
}; |
| 25 |
|
|
} // namespace |
| 26 |
|
|
|
| 27 |
|
✗ |
QListWidgetItem* ConfigurationListWidget::makeItem( |
| 28 |
|
|
QString name, const hpp::floatSeq& config) { |
| 29 |
|
✗ |
QListWidgetItem* newItem = new ConfigItem(name, config); |
| 30 |
|
✗ |
newItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | |
| 31 |
|
✗ |
Qt::ItemIsDragEnabled | Qt::ItemIsEditable); |
| 32 |
|
✗ |
return newItem; |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
✗ |
hpp::floatSeq& ConfigurationListWidget::getConfig(QListWidgetItem* item) { |
| 36 |
|
✗ |
return static_cast<ConfigItem*>(item)->q_; |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
✗ |
ConfigurationListWidget::ConfigurationListWidget(HppWidgetsPlugin* plugin, |
| 40 |
|
✗ |
QWidget* parent) |
| 41 |
|
|
: QWidget(parent), |
| 42 |
|
✗ |
plugin_(plugin), |
| 43 |
|
✗ |
ui_(new ::Ui::ConfigurationListWidget), |
| 44 |
|
✗ |
previous_(NULL), |
| 45 |
|
✗ |
main_(gepetto::gui::MainWindow::instance()), |
| 46 |
|
✗ |
basename_("config_"), |
| 47 |
|
✗ |
count_(0) { |
| 48 |
|
✗ |
ui_->setupUi(this); |
| 49 |
|
|
|
| 50 |
|
✗ |
ui_->listConfigurations->bindDeleteKey(); |
| 51 |
|
✗ |
ui_->listInit->setSingleItemOnly(true); |
| 52 |
|
|
|
| 53 |
|
✗ |
connect(ui_->button_SaveConfig, SIGNAL(clicked()), this, |
| 54 |
|
|
SLOT(onSaveClicked())); |
| 55 |
|
✗ |
connect(name(), SIGNAL(returnPressed()), SLOT(onSaveClicked())); |
| 56 |
|
✗ |
connect(ui_->button_ResetGoalConfig, SIGNAL(clicked()), |
| 57 |
|
|
SLOT(resetGoalConfigs())); |
| 58 |
|
✗ |
connect(list(), |
| 59 |
|
|
SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, |
| 60 |
|
|
SLOT(updateCurrentConfig(QListWidgetItem*, QListWidgetItem*))); |
| 61 |
|
✗ |
connect(ui_->listGoals, |
| 62 |
|
|
SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, |
| 63 |
|
|
SLOT(updateCurrentConfig(QListWidgetItem*, QListWidgetItem*))); |
| 64 |
|
✗ |
connect(ui_->listInit, |
| 65 |
|
|
SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, |
| 66 |
|
|
SLOT(updateCurrentConfig(QListWidgetItem*, QListWidgetItem*))); |
| 67 |
|
✗ |
connect(ui_->listGoals, SIGNAL(configurationChanged()), SLOT(setConfigs())); |
| 68 |
|
✗ |
connect(list(), SIGNAL(configurationChanged()), SLOT(setConfigs())); |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
✗ |
ConfigurationListWidget::~ConfigurationListWidget() { delete ui_; } |
| 72 |
|
|
|
| 73 |
|
✗ |
QListWidget* ConfigurationListWidget::list() { return ui_->listConfigurations; } |
| 74 |
|
|
|
| 75 |
|
✗ |
void ConfigurationListWidget::onSaveClicked() { |
| 76 |
|
✗ |
hpp::floatSeq const* c = plugin_->getCurrentConfig(); |
| 77 |
|
✗ |
list()->addItem(makeItem(name()->text(), *c)); |
| 78 |
|
✗ |
name()->setText(basename_ + QString::number(count_)); |
| 79 |
|
✗ |
count_++; |
| 80 |
|
|
} |
| 81 |
|
|
|
| 82 |
|
✗ |
void ConfigurationListWidget::updateCurrentConfig(QListWidgetItem* current, |
| 83 |
|
|
QListWidgetItem*) { |
| 84 |
|
✗ |
if (current != 0) { |
| 85 |
|
✗ |
const hpp::floatSeq& c = getConfig(current); |
| 86 |
|
✗ |
plugin_->setCurrentConfig(c); |
| 87 |
|
✗ |
if (previous_ && previous_ != current->listWidget()) { |
| 88 |
|
✗ |
previous_->clearSelection(); |
| 89 |
|
✗ |
previous_->setCurrentRow(-1); // force saved index change |
| 90 |
|
|
} |
| 91 |
|
✗ |
previous_ = current->listWidget(); |
| 92 |
|
|
} |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
✗ |
void ConfigurationListWidget::resetGoalConfigs(bool doEmpty) { |
| 96 |
|
✗ |
plugin_->client()->problem()->resetGoalConfigs(); |
| 97 |
|
✗ |
if (doEmpty) { |
| 98 |
|
✗ |
while (ui_->listGoals->count()) { |
| 99 |
|
✗ |
QListWidgetItem* item = ui_->listGoals->takeItem(0); |
| 100 |
|
|
|
| 101 |
|
✗ |
list()->addItem(item); |
| 102 |
|
|
} |
| 103 |
|
✗ |
ui_->listGoals->setCurrentRow(-1); |
| 104 |
|
|
} |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
|
✗ |
void ConfigurationListWidget::setConfigs() { |
| 108 |
|
✗ |
resetGoalConfigs(false); |
| 109 |
|
✗ |
for (int i = 0; i < ui_->listGoals->count(); ++i) { |
| 110 |
|
✗ |
QListWidgetItem* item = ui_->listGoals->item(i); |
| 111 |
|
✗ |
plugin_->client()->problem()->addGoalConfig(getConfig(item)); |
| 112 |
|
|
} |
| 113 |
|
✗ |
if (ui_->listInit->count() == 1) |
| 114 |
|
✗ |
setInitConfig(getConfig(ui_->listInit->item(0))); |
| 115 |
|
|
} |
| 116 |
|
|
|
| 117 |
|
✗ |
void ConfigurationListWidget::setInitConfig(floatSeq& config) { |
| 118 |
|
✗ |
plugin_->client()->problem()->setInitialConfig(config); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
✗ |
void ConfigurationListWidget::fetchInitAndGoalConfigs() { |
| 122 |
|
✗ |
hpp::floatSeq_var init; |
| 123 |
|
✗ |
hpp::floatSeqSeq_var goals; |
| 124 |
|
|
try { |
| 125 |
|
✗ |
init = plugin_->client()->problem()->getInitialConfig(); |
| 126 |
|
✗ |
goals = plugin_->client()->problem()->getGoalConfigs(); |
| 127 |
|
✗ |
} catch (const hpp::Error& e) { |
| 128 |
|
✗ |
qDebug() << "Could not update init and goal config:" << e.msg; |
| 129 |
|
✗ |
return; |
| 130 |
|
|
} |
| 131 |
|
✗ |
ui_->listInit->clear(); |
| 132 |
|
✗ |
ui_->listInit->addItem(makeItem("init", init.in())); |
| 133 |
|
|
|
| 134 |
|
✗ |
ui_->listGoals->clear(); |
| 135 |
|
✗ |
for (CORBA::ULong i = 0; i < goals->length(); ++i) |
| 136 |
|
✗ |
ui_->listGoals->addItem(makeItem(QString("goal_%1").arg(i), goals.in()[i])); |
| 137 |
|
|
} |
| 138 |
|
|
|
| 139 |
|
✗ |
QLineEdit* ConfigurationListWidget::name() { return ui_->lineEdit_configName; } |
| 140 |
|
|
|
| 141 |
|
✗ |
QDataStream& operator>>(QDataStream& os, hpp::floatSeq& tab) { |
| 142 |
|
✗ |
int size = 0; |
| 143 |
|
|
double f; |
| 144 |
|
✗ |
while (!os.atEnd()) { |
| 145 |
|
✗ |
tab.length(size + 1); |
| 146 |
|
✗ |
os >> f; |
| 147 |
|
✗ |
tab[size] = f; |
| 148 |
|
✗ |
size += 1; |
| 149 |
|
|
} |
| 150 |
|
✗ |
return os; |
| 151 |
|
|
} |
| 152 |
|
|
|
| 153 |
|
✗ |
QDataStream& operator<<(QDataStream& os, const hpp::floatSeq& tab) { |
| 154 |
|
✗ |
for (unsigned i = 0; i < tab.length(); ++i) { |
| 155 |
|
✗ |
double f = tab[i]; |
| 156 |
|
✗ |
os << f; |
| 157 |
|
|
} |
| 158 |
|
✗ |
return os; |
| 159 |
|
|
} |
| 160 |
|
|
} // namespace gui |
| 161 |
|
|
} // namespace hpp |
| 162 |
|
|
|