25 #include <MemoryX/gui-plugins/SceneEditor/ui_GroupExplorerDialog.h>
26 #include "../../scene3D/SceneGroupManager.h"
27 #include <QStandardItem>
29 #include <Inventor/nodes/SoSeparator.h>
30 #include <Inventor/nodes/SoCone.h>
31 #include <Inventor/SbRotation.h>
32 #include <QInputDialog>
34 #include "../../controller/CreateGroupOperation.h"
35 #include "../../controller/DeleteGroupOperation.h"
36 #include "../../controller/RenameGroupOperation.h"
37 #include "../../controller/RemoveFromGroupOperation.h"
46 viewer.reset(
new SoQtExaminerViewer(ui->viewInSceneWidget));
47 viewer->setDecoration(
false);
48 viewer->setHeadlight(
true);
49 viewer->setBackgroundColor(SbColor(100 / 255.0f, 100 / 255.0f, 100 / 255.0f));
50 viewer->setSceneGraph(
new SoSeparator());
52 connect(ui->buttonBox, SIGNAL(rejected()),
this, SLOT(close()));
53 connect(ui->groupListWidget, SIGNAL(clicked(QModelIndex)),
this, SLOT(groupClicked(QModelIndex)));
54 connect(ui->objectListWidget, SIGNAL(clicked(QModelIndex)),
this, SLOT(objectClicked(QModelIndex)));
55 connect(ui->objectListWidget, SIGNAL(itemSelectionChanged()),
this, SLOT(checkButtons()));
56 connect(ui->addGroupButton, SIGNAL(clicked()),
this, SLOT(groupAddClicked()));
57 connect(ui->deleteGroupButton, SIGNAL(clicked()),
this, SLOT(groupRemoveClicked()));
58 connect(ui->changeNameButton, SIGNAL(clicked()),
this, SLOT(groupRenameClicked()));
59 connect(ui->deleteObjectButton, SIGNAL(clicked()),
this, SLOT(objectRemoveClicked()));
60 connect(ui->groupNameLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(checkButtons()));
69 void gui::dialog::GroupExplorerDialog::showEvent(QShowEvent* event)
77 void gui::dialog::GroupExplorerDialog::groupClicked(QModelIndex
index)
79 if (ui->groupListWidget->currentItem()->text() != activeGroup)
84 activeGroup = ui->groupListWidget->currentItem()->text();
91 void gui::dialog::GroupExplorerDialog::objectClicked(QModelIndex
index)
93 activeObject = ui->objectListWidget->currentItem()->toolTip();
99 void gui::dialog::GroupExplorerDialog::groupAddClicked()
109 while (
controller->getScene()->getGroupManager()->getGroupById(tr(
"New Group ").toStdString() +
std::to_string(nameIndex)) != NULL);
111 std::string groupName = tr(
"New Group ").toStdString() +
std::to_string(nameIndex);
113 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
118 operations->push_back(operation);
121 activeGroup = QString::fromStdString(groupName);
129 ui->groupNameLineEdit->setFocus();
130 ui->groupNameLineEdit->selectAll();
131 ui->changeNameButton->setDefault(
true);
135 void gui::dialog::GroupExplorerDialog::groupRemoveClicked()
139 if (!
controller->getScene()->getGroupManager()->getGroupById(activeGroup.toStdString()))
144 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
150 activeGroup.toStdString(),
151 object->getObjectId()));
152 operations->push_back(operation);
157 activeGroup.toStdString()));
158 operations->push_back(operation);
171 void gui::dialog::GroupExplorerDialog::objectRemoveClicked()
175 QList<QListWidgetItem*> allItemsToDelete = ui->objectListWidget->selectedItems();
176 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
178 for (QList<QListWidgetItem*>::iterator it = allItemsToDelete.begin(); it != allItemsToDelete.end(); ++it)
182 activeGroup.toStdString(),
183 (*it)->toolTip().toStdString()));
184 operations->push_back(operation);
197 void gui::dialog::GroupExplorerDialog::groupRenameClicked()
201 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
205 activeGroup.toStdString(),
206 ui->groupNameLineEdit->text().toStdString()));
207 operations->push_back(operation);
210 activeGroup = ui->groupNameLineEdit->text();
221 if (
controller->getScene()->getGroupManager()->getGroupById(groupId.toStdString()))
223 activeGroup = groupId;
232 ui->groupListWidget->setFocus();
236 void gui::dialog::GroupExplorerDialog::reloadGroups()
241 ui->groupListWidget->clear();
242 allGroups =
controller->getScene()->getGroupManager()->getAllGroups();
244 for (std::vector<scene3D::SceneGroupPtr>::iterator it = allGroups.begin(); it != allGroups.end(); ++it)
246 ui->groupListWidget->addItem(QString::fromStdString((*it)->getGroupId()));
249 if (!activeGroup.isNull() && !activeGroup.isEmpty())
252 ui->groupListWidget->setCurrentItem(ui->groupListWidget->findItems(activeGroup, Qt::MatchFixedString).first());
257 void gui::dialog::GroupExplorerDialog::reloadObjects()
262 ui->objectListWidget->clear();
265 if (clickedGroup != NULL)
267 std::vector<scene3D::SceneObjectPtr> allObjects = clickedGroup->getAllObjects();
269 for (std::vector<scene3D::SceneObjectPtr>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
271 std::string objectId = (*it)->getObjectId();
272 std::string classId = (*it)->getClassId();
273 QListWidgetItem* item =
new QListWidgetItem(QString::fromStdString(classId));
274 item->setToolTip(QString::fromStdString(objectId));
275 ui->objectListWidget->insertItem(ui->objectListWidget->count(), item);
279 ui->groupNameLineEdit->setText(activeGroup);
283 void gui::dialog::GroupExplorerDialog::reloadProperties()
288 ui->propertiesTableWidget->clear();
289 ui->propertiesTableWidget->reset();
290 viewer->setSceneGraph(
new SoSeparator());
295 std::map<std::string, std::string> attributes = sceneObject->getAllAttributes();
297 ui->propertiesTableWidget->setRowCount(3);
298 ui->propertiesTableWidget->setItem(0, 0,
new QTableWidgetItem(tr(
"Object ID")));
299 ui->propertiesTableWidget->setItem(0, 1,
new QTableWidgetItem(QString::fromStdString(sceneObject->getObjectId())));
300 ui->propertiesTableWidget->setItem(1, 0,
new QTableWidgetItem(tr(
"Class ID")));
301 ui->propertiesTableWidget->setItem(1, 1,
new QTableWidgetItem(QString::fromStdString(sceneObject->getClassId())));
302 ui->propertiesTableWidget->setItem(2, 0,
new QTableWidgetItem(tr(
"Collection ID")));
303 ui->propertiesTableWidget->setItem(2, 1,
new QTableWidgetItem(QString::fromStdString(sceneObject->getCollection())));
308 for (std::map<std::string, std::string>::iterator it = attributes.begin(); it != attributes.end(); ++it)
310 row = ui->propertiesTableWidget->rowCount();
311 QTableWidgetItem* key =
new QTableWidgetItem(QString::fromStdString(it->first));
312 QTableWidgetItem*
value =
new QTableWidgetItem(QString::fromStdString(it->second));
313 ui->propertiesTableWidget->insertRow(row);
314 ui->propertiesTableWidget->setItem(row, 0, key);
315 ui->propertiesTableWidget->setItem(row, 1,
value);
316 ui->propertiesTableWidget->resizeRowToContents(row);
319 ui->propertiesTableWidget->resizeColumnToContents(1);
321 showPreviewImage(
controller->getMemoryXController()->getPriorKnowlegdeController()->getObjectClassPtr(sceneObject->getClassId(), sceneObject->getCollection()));
326 void gui::dialog::GroupExplorerDialog::checkButtons()
330 ui->changeNameButton->setEnabled(!(
331 ui->groupNameLineEdit->text().isEmpty() ||
332 ui->groupNameLineEdit->text() == activeGroup ||
333 controller->getScene()->getGroupManager()->getGroupById(ui->groupNameLineEdit->text().toStdString()) != NULL));
334 ui->deleteGroupButton->setEnabled(activeGroup !=
"");
335 ui->deleteObjectButton->setEnabled(activeObject !=
"");
336 ui->groupNameLineEdit->setEnabled(activeGroup !=
"");
345 SoNode* visualisation =
controller->getMemoryXController()->getPriorKnowlegdeController()->getCoinVisualisation(objectClass,
false);
348 SoSeparator* root =
controller->getScene()->getPreviewGenerator()->createAnimatedPreview(visualisation);
350 viewer->setSceneGraph(root);
351 viewer->getCamera()->viewAll(root, viewer->getViewportRegion());
357 this->ui->retranslateUi(
this);