ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvPickingHub.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "CVPluginAPI.h"
11 
12 // Local
13 #include "ecvPickingListener.h"
14 
15 // CV_DB_LIB
16 #include <ecvDisplayTools.h>
17 
18 // Qt
19 #include <QObject>
20 
21 // system
22 #include <set>
23 
24 class ccHObject;
25 class QMdiSubWindow;
27 
29 class CVPLUGIN_LIB_API ccPickingHub : public QObject {
30  Q_OBJECT
31 
32 public:
34  ccPickingHub(ecvMainAppInterface* app, QObject* parent = nullptr);
35  ~ccPickingHub() override = default;
36 
38  inline size_t listenerCount() const { return m_listeners.size(); }
39 
41 
48  bool addListener(ccPickingListener* listener,
49  bool exclusive = false,
50  bool autoStartPicking = true,
53 
55 
59  void removeListener(ccPickingListener* listener,
60  bool autoStopPickingIfLast = true);
61 
62  // //! Sets the default picking mode
63  // /** \param mode picking mode
64  // \param autoEnableOnActivatedWindow whether picking mode should
65  // be enabled automatically on newly activated windows (if listeners are
66  // present only)
67  // **/
68  // DGM: too dangerous, we can't change this behavior on the fly
69 
71  void togglePickingMode(bool state);
72 
74  QWidget* activeWindow() const { return m_activeWindow; }
75 
78  bool isLocked() const { return m_exclusive && !m_listeners.empty(); }
79 
80 public slots:
81 
82  void onActiveWindowChanged(QMdiSubWindow*);
83  void onActiveWindowDeleted(QObject*);
84  void processPickedItem(ccHObject*, unsigned, int, int, const CCVector3&);
85 
86 protected:
88  std::set<ccPickingListener*> m_listeners;
89 
92 
94  QWidget* m_activeWindow;
95 
98 
101 
104 };
#define CVPLUGIN_LIB_API
Definition: CVPluginAPI.h:15
#define slots
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Point/triangle picking hub.
Definition: ecvPickingHub.h:29
std::set< ccPickingListener * > m_listeners
Listeners.
Definition: ecvPickingHub.h:88
bool m_exclusive
Exclusive mode.
bool isLocked() const
Definition: ecvPickingHub.h:78
bool m_autoEnableOnActivatedWindow
Automatically enables the picking mechanism on activated GL windows.
ecvDisplayTools::PICKING_MODE m_pickingMode
Default picking mode.
Definition: ecvPickingHub.h:97
~ccPickingHub() override=default
QWidget * m_activeWindow
Active window.
Definition: ecvPickingHub.h:94
ecvMainAppInterface * m_app
Associated application.
Definition: ecvPickingHub.h:91
size_t listenerCount() const
Returns the number of currently registered listeners.
Definition: ecvPickingHub.h:38
QWidget * activeWindow() const
Returns the currently active window.
Definition: ecvPickingHub.h:74
Point/triangle picking listener interface.
PICKING_MODE
Picking mode.
Main application interface (for plugins)