GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/gui/node-action.cc Lines: 1 47 2.1 %
Date: 2020-05-14 11:23:33 Branches: 2 81 2.5 %

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

3
}