GCC Code Coverage Report


Directory: ./
File: src/gui/node-action.cc
Date: 2024-08-14 11:04:57
Exec Total Coverage
Lines: 0 48 0.0%
Branches: 0 75 0.0%

Line Branch Exec Source
1 // Copyright (c) 2017, Joseph Mirabel
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/viewer/node.h>
18 #include <gepetto/viewer/window-manager.h>
19
20 #include <gepetto/gui/mainwindow.hh>
21 #include <gepetto/gui/node-action.hh>
22 #include <gepetto/gui/osgwidget.hh>
23 #include <gepetto/gui/selection-handler.hh>
24 #include <gepetto/gui/windows-manager.hh>
25
26 namespace gepetto {
27 namespace gui {
28 NodeActionBase::NodeActionBase(const QString& text, NodePtr_t node,
29 QWidget* parent)
30 : QAction(text, parent), node_(node) {
31 connect(this, SIGNAL(triggered(bool)), SLOT(_act(bool)));
32 }
33
34 NodePtr_t NodeActionBase::node() const {
35 if (node_) return node_;
36 QString s = MainWindow::instance()->selectionHandler()->mode()->currentBody();
37 return MainWindow::instance()->osg()->getNode(s.toStdString(), false);
38 }
39
40 void NodeActionBase::_act(bool checked) { act(checked); }
41
42 NodeAction::NodeAction(const NodeAction::Type& t, const QString& text,
43 NodePtr_t node, QWidget* parent)
44 : NodeActionBase(text, node, parent), type_(t), window_(NULL) {}
45
46 NodeAction::NodeAction(const NodeAction::Type& t, const QString& text,
47 QWidget* parent)
48 : NodeActionBase(text, NodePtr_t(), parent), type_(t), window_(NULL) {}
49
50 NodeAction::NodeAction(const QString& text, NodePtr_t node, OSGWidget* window,
51 QWidget* parent)
52 : NodeActionBase(text, node, parent),
53 type_(ATTACH_TO_WINDOW),
54 window_(window) {}
55
56 NodeAction::NodeAction(const QString& text, OSGWidget* window, QWidget* parent)
57 : NodeActionBase(text, NodePtr_t(), parent),
58 type_(ATTACH_CAMERA_TO_NODE),
59 window_(window) {}
60
61 void NodeAction::act(bool) {
62 NodePtr_t n = node();
63 if (!n) return;
64 MainWindow* main = MainWindow::instance();
65 switch (type_) {
66 case VISIBILITY_ON:
67 n->setVisibilityMode(viewer::VISIBILITY_ON);
68 break;
69 case VISIBILITY_OFF:
70 n->setVisibilityMode(viewer::VISIBILITY_OFF);
71 break;
72 case ALWAYS_ON_TOP:
73 n->setVisibilityMode(viewer::ALWAYS_ON_TOP);
74 break;
75 case ATTACH_TO_WINDOW:
76 window_->osg()->addSceneToWindow(n->getID(), window_->windowID());
77 break;
78 case ATTACH_CAMERA_TO_NODE:
79 window_->osg()->osgFrameMutex().lock();
80 window_->window()->attachCameraToNode(n);
81 window_->osg()->osgFrameMutex().unlock();
82 break;
83 case REMOVE_NODE:
84 main->osg()->deleteNode(n->getID(), false);
85 break;
86 }
87 }
88 } // namespace gui
89 } // namespace gepetto
90