selection-event.hh
Go to the documentation of this file.
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 #ifndef GEPETTO_GUI_SELECTION_EVENT_HH
18 #define GEPETTO_GUI_SELECTION_EVENT_HH
19 
20 #include <QString>
21 #include <QVector3D>
22 #include <QObject>
23 #include <QAtomicInt>
24 
25 #include <gepetto/viewer/node.h>
26 #include <gepetto/gui/fwd.hh>
27 
28 namespace gepetto {
29  namespace gui {
30  class SelectionEvent : public QObject {
31  Q_OBJECT
32 
33  public:
34  enum Type {
37  };
38 
39  SelectionEvent (const Type& t, NodePtr_t node = NodePtr_t(), Qt::KeyboardModifiers modKey = Qt::NoModifier)
40  : type_ (t)
41  , node_ (node)
42  , modKey_ (modKey)
43  , hasIntersection_ (false)
44  , c_ (-1)
45  {
46  if (node)
47  nodeName_ = QString::fromStdString(node->getID());
48  }
49 
50  SelectionEvent (const Type& t, Qt::KeyboardModifiers modKey)
51  : type_ (t)
52  , modKey_ (modKey)
53  , hasIntersection_ (false)
54  , c_ (-1)
55  {}
56 
57  void setupIntersection(const osgUtil::LineSegmentIntersector::Intersection& it);
58 
59  const NodePtr_t& node () const { return node_; }
60 
61  void modKey (const Qt::KeyboardModifiers& m) { modKey_ = m; }
62 
65  void setCounter(int c) { c_ = c; }
66 
67  public slots:
68  Type type () const { return type_; }
69  QString nodeName() const { return nodeName_; }
70  Qt::KeyboardModifiers modKey () const { return modKey_; }
71 
72  bool hasIntersection () { return hasIntersection_; }
73  QVector3D normal(bool local) const { return (local ? localNormal_ : worldNormal_); }
74  QVector3D point (bool local) const { return (local ? localPoint_ : worldPoint_ ); }
79  void done ();
80 
81  private:
82  Type type_;
83  QString nodeName_;
84  NodePtr_t node_;
85  Qt::KeyboardModifiers modKey_;
86 
87  bool hasIntersection_;
88  QVector3D localPoint_, localNormal_, worldPoint_, worldNormal_;
89  QAtomicInt c_;
90  };
91  } // namespace gui
92 } // namespace gepetto
93 
94 #endif // GEPETTO_GUI_SELECTION_EVENT_HH
Type type() const
Definition: selection-event.hh:68
QVector3D point(bool local) const
Definition: selection-event.hh:74
SelectionEvent(const Type &t, Qt::KeyboardModifiers modKey)
Definition: selection-event.hh:50
const NodePtr_t & node() const
Definition: selection-event.hh:59
void setCounter(int c)
Definition: selection-event.hh:65
QString nodeName() const
Definition: selection-event.hh:69
QVector3D normal(bool local) const
Definition: selection-event.hh:73
SelectionEvent(const Type &t, NodePtr_t node=NodePtr_t(), Qt::KeyboardModifiers modKey=Qt::NoModifier)
Definition: selection-event.hh:39
Definition: selection-event.hh:35
Definition: selection-event.hh:30
void setupIntersection(const osgUtil::LineSegmentIntersector::Intersection &it)
viewer::NodePtr_t NodePtr_t
Definition: fwd.hh:47
Definition: action-search-bar.hh:27
void modKey(const Qt::KeyboardModifiers &m)
Definition: selection-event.hh:61
Type
Definition: selection-event.hh:34
bool hasIntersection()
Definition: selection-event.hh:72
Definition: selection-event.hh:36
Qt::KeyboardModifiers modKey() const
Definition: selection-event.hh:70