GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/gui/tree-item.cc Lines: 1 56 1.8 %
Date: 2020-05-14 11:23:33 Branches: 2 84 2.4 %

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 <QtGlobal>
20
#include <QDebug>
21
#include <QFormLayout>
22
23
#include <gepetto/viewer/node.h>
24
#include <gepetto/viewer/group-node.h>
25
26
#include "gepetto/gui/mainwindow.hh"
27
#include "gepetto/gui/windows-manager.hh"
28
#include <gepetto/gui/bodytreewidget.hh>
29
#include <gepetto/gui/dialog/configuration.hh>
30
31
namespace gepetto {
32
  namespace gui {
33
    using viewer::ScopedLock;
34
    using viewer::PropertyPtr_t;
35
36
    BodyTreeItem::BodyTreeItem(QObject *parent, NodePtr_t node) :
37
      QObject (parent),
38
      QStandardItem (QString::fromStdString (node->getID().substr(node->getID().find_last_of("/") + 1))),
39
      node_ (node)
40
    {
41
      setEditable(false);
42
    }
43
44
    void BodyTreeItem::initialize ()
45
    {
46
      connect(this, SIGNAL(requestInitialize()), SLOT(doInitialize()));
47
      emit requestInitialize();
48
    }
49
50
    void BodyTreeItem::doInitialize ()
51
    {
52
      propertyEditors_ = node_->guiEditor();
53
      BodyTreeWidget* bt = MainWindow::instance()->bodyTree();
54
      if (propertyEditors_->thread() != bt->thread())
55
        propertyEditors_->moveToThread(bt->thread());
56
      disconnect(SIGNAL(requestInitialize()));
57
    }
58
59
    BodyTreeItem::~BodyTreeItem()
60
    {
61
      if (propertyEditors_->parent() != NULL)
62
        delete propertyEditors_;
63
    }
64
65
    QStandardItem* BodyTreeItem::clone() const
66
    {
67
      return new BodyTreeItem (QObject::parent(), node_);
68
    }
69
70
    NodePtr_t BodyTreeItem::node() const
71
    {
72
      return node_;
73
    }
74
75
    void BodyTreeItem::populateContextMenu(QMenu *contextMenu)
76
    {
77
      /// Landmark
78
      QMenu* lm = contextMenu->addMenu (tr("Landmark"));
79
      QAction* alm = lm->addAction (tr("Add"));
80
      QAction* dlm = lm->addAction (tr("Remove"));
81
      connect (alm, SIGNAL (triggered()), SLOT (addLandmark()));
82
      connect (dlm, SIGNAL (triggered()), SLOT (deleteLandmark()));
83
      /// Remove
84
      QAction* remove = contextMenu->addAction (tr("Remove"));
85
      connect (remove, SIGNAL (triggered()), SLOT (remove()));
86
      QAction* removeAll = contextMenu->addAction (tr("Remove all"));
87
      connect (removeAll, SIGNAL (triggered()), SLOT (removeAll()));
88
      if (!parentGroup_.empty()) {
89
        QAction* rfg = contextMenu->addAction (tr("Remove from group"));
90
        connect (rfg, SIGNAL (triggered()), SLOT (removeFromGroup ()));
91
      }
92
    }
93
94
    void BodyTreeItem::setParentGroup(const std::string &parent)
95
    {
96
      parentGroup_ = parent;
97
    }
98
99
    void BodyTreeItem::setViewingMode(QString mode)
100
    {
101
      MainWindow::instance()->osg()->setWireFrameMode (node_->getID(),
102
          mode.toLocal8Bit().data());
103
    }
104
105
    void BodyTreeItem::setVisibilityMode(QString mode)
106
    {
107
      MainWindow::instance()->osg()->setVisibility (node_->getID(),
108
          mode.toLocal8Bit().data());
109
    }
110
111
    void BodyTreeItem::removeFromGroup()
112
    {
113
      if (parentGroup_.empty()) return;
114
      MainWindow::instance()->osg()->removeFromGroup (node_->getID(), parentGroup_);
115
      QStandardItem::parent()->removeRow(row());
116
    }
117
118
    void BodyTreeItem::removeAll()
119
    {
120
      MainWindow* main = MainWindow::instance();
121
      main->osg()->deleteNode(node_->getID(), true);
122
    }
123
124
    void BodyTreeItem::remove()
125
    {
126
      MainWindow* main = MainWindow::instance();
127
      main->osg()->deleteNode(node_->getID(), false);
128
    }
129
130
    void BodyTreeItem::addLandmark()
131
    {
132
      MainWindow::instance()->osg()->addLandmark(node_->getID(), 0.05f);
133
    }
134
135
    void BodyTreeItem::deleteLandmark()
136
    {
137
      MainWindow::instance()->osg()->deleteLandmark(node_->getID());
138
    }
139
  } // namespace gui
140

3
} // namespace gepetto