GCC Code Coverage Report


Directory: ./
File: src/gui/tree-item.cc
Date: 2024-12-20 15:53:58
Exec Total Coverage
Lines: 0 54 0.0%
Branches: 0 80 0.0%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, LAAS-CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17 #include "gepetto/gui/tree-item.hh"
18
19 #include <gepetto/viewer/group-node.h>
20 #include <gepetto/viewer/node.h>
21
22 #include <QDebug>
23 #include <QFormLayout>
24 #include <QtGlobal>
25 #include <gepetto/gui/bodytreewidget.hh>
26 #include <gepetto/gui/dialog/configuration.hh>
27
28 #include "gepetto/gui/mainwindow.hh"
29 #include "gepetto/gui/windows-manager.hh"
30
31 namespace gepetto {
32 namespace gui {
33 using viewer::PropertyPtr_t;
34 using viewer::ScopedLock;
35
36 BodyTreeItem::BodyTreeItem(QObject* parent, NodePtr_t node)
37 : QObject(parent),
38 QStandardItem(QString::fromStdString(
39 node->getID().substr(node->getID().find_last_of("/") + 1))),
40 node_(node) {
41 setEditable(false);
42 }
43
44 void BodyTreeItem::initialize() {
45 connect(this, SIGNAL(requestInitialize()), SLOT(doInitialize()));
46 emit requestInitialize();
47 }
48
49 void BodyTreeItem::doInitialize() {
50 propertyEditors_ = node_->guiEditor();
51 BodyTreeWidget* bt = MainWindow::instance()->bodyTree();
52 if (propertyEditors_->thread() != bt->thread())
53 propertyEditors_->moveToThread(bt->thread());
54 disconnect(SIGNAL(requestInitialize()));
55 }
56
57 BodyTreeItem::~BodyTreeItem() {
58 if (propertyEditors_->parent() != NULL) delete propertyEditors_;
59 }
60
61 QStandardItem* BodyTreeItem::clone() const {
62 return new BodyTreeItem(QObject::parent(), node_);
63 }
64
65 NodePtr_t BodyTreeItem::node() const { return node_; }
66
67 void BodyTreeItem::populateContextMenu(QMenu* contextMenu) {
68 /// Landmark
69 QMenu* lm = contextMenu->addMenu(tr("Landmark"));
70 QAction* alm = lm->addAction(tr("Add"));
71 QAction* dlm = lm->addAction(tr("Remove"));
72 connect(alm, SIGNAL(triggered()), SLOT(addLandmark()));
73 connect(dlm, SIGNAL(triggered()), SLOT(deleteLandmark()));
74 /// Remove
75 QAction* remove = contextMenu->addAction(tr("Remove"));
76 connect(remove, SIGNAL(triggered()), SLOT(remove()));
77 QAction* removeAll = contextMenu->addAction(tr("Remove all"));
78 connect(removeAll, SIGNAL(triggered()), SLOT(removeAll()));
79 if (!parentGroup_.empty()) {
80 QAction* rfg = contextMenu->addAction(tr("Remove from group"));
81 connect(rfg, SIGNAL(triggered()), SLOT(removeFromGroup()));
82 }
83 }
84
85 void BodyTreeItem::setParentGroup(const std::string& parent) {
86 parentGroup_ = parent;
87 }
88
89 void BodyTreeItem::setViewingMode(QString mode) {
90 MainWindow::instance()->osg()->setWireFrameMode(node_->getID(),
91 mode.toLocal8Bit().data());
92 }
93
94 void BodyTreeItem::setVisibilityMode(QString mode) {
95 MainWindow::instance()->osg()->setVisibility(node_->getID(),
96 mode.toLocal8Bit().data());
97 }
98
99 void BodyTreeItem::removeFromGroup() {
100 if (parentGroup_.empty()) return;
101 MainWindow::instance()->osg()->removeFromGroup(node_->getID(), parentGroup_);
102 QStandardItem::parent()->removeRow(row());
103 }
104
105 void BodyTreeItem::removeAll() {
106 MainWindow* main = MainWindow::instance();
107 main->osg()->deleteNode(node_->getID(), true);
108 }
109
110 void BodyTreeItem::remove() {
111 MainWindow* main = MainWindow::instance();
112 main->osg()->deleteNode(node_->getID(), false);
113 }
114
115 void BodyTreeItem::addLandmark() {
116 MainWindow::instance()->osg()->addLandmark(node_->getID(), 0.05f);
117 }
118
119 void BodyTreeItem::deleteLandmark() {
120 MainWindow::instance()->osg()->deleteLandmark(node_->getID());
121 }
122 } // namespace gui
123 } // namespace gepetto
124