File: ccPickingHub.h

package info (click to toggle)
cloudcompare 2.13.2%2Bgit20240821%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 151,196 kB
  • sloc: cpp: 687,219; ansic: 165,269; python: 31,109; xml: 25,906; sh: 940; makefile: 516; java: 229; asm: 204; fortran: 160; javascript: 73; perl: 18
file content (111 lines) | stat: -rw-r--r-- 4,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once
//##########################################################################
//#                                                                        #
//#                              CLOUDCOMPARE                              #
//#                                                                        #
//#  This program is free software; you can redistribute it and/or modify  #
//#  it under the terms of the GNU General Public License as published by  #
//#  the Free Software Foundation; version 2 or later of the License.      #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#                    COPYRIGHT: CloudCompare project                     #
//#                                                                        #
//##########################################################################

#include "CCPluginAPI.h"

//Local
#include "ccPickingListener.h"

//qCC_gl
#include <ccGLWindowInterface.h>

//Qt
#include <QObject>

//system
#include <set>

class QMdiSubWindow;
class ccHObject;
class ccMainAppInterface;

//! Point/triangle picking hub
class CCPLUGIN_LIB_API ccPickingHub : public QObject
{
	Q_OBJECT

public:
	
	//! Default constructor
	ccPickingHub(ccMainAppInterface* app, QObject* parent = nullptr);
	~ccPickingHub() override = default;

	//! Returns the number of currently registered listeners
	inline size_t listenerCount() const { return m_listeners.size(); }

	//! Adds a listener
	/** \param listener listener to be registered
		\param exclusive prevents new listeners from registering
		\param autoStartPicking automatically enables the picking mode on the active window (if any)
		\param mode sets the picking mode (warning: may be rejected if another listener is currently registered with another mode)
		\return success
	***/
	bool addListener(	ccPickingListener* listener,
						bool exclusive = false,
						bool autoStartPicking = true,
						ccGLWindowInterface::PICKING_MODE mode = ccGLWindowInterface::POINT_OR_TRIANGLE_PICKING);

	//! Removes a listener
	/** \param listener listener to be removed
		\param autoStopPickingIfLast automatically disables the picking mode on the active window (if any) if no other listener is registered
	***/
	void removeListener(ccPickingListener* listener, bool autoStopPickingIfLast = true);

	//	//! Sets the default picking mode
	//	/** \param mode picking mode
	//		\param autoEnableOnActivatedWindow whether picking mode should be enabled automatically on newly activated windows (if listeners are present only)
	//	**/
	//DGM: too dangerous, we can't change this behavior on the fly
	//void setPickingMode(ccGLWindowInterface::PICKING_MODE mode, bool autoEnableOnActivatedWindow = true);
	
	//! Manual start / stop of the picking mode on the active window
	void togglePickingMode(bool state);

	//! Returns the currently active window
	ccGLWindowInterface* activeWindow() const { return m_activeGLWindow; }

	//! Returns whether the picking mechanism is currently locked (i.e. an exclusive listener is registered)
	bool isLocked() const { return m_exclusive && !m_listeners.empty(); }

public:

	void onActiveWindowChanged(QMdiSubWindow*);
	void onActiveWindowDeleted(ccGLWindowInterface*);
	void processPickedItem(ccHObject*, unsigned, int, int, const CCVector3&, const CCVector3d&);

protected:

	//! Listeners
	std::set< ccPickingListener* > m_listeners;

	//! Associated application
	ccMainAppInterface* m_app;

	//! Active GL window
	ccGLWindowInterface* m_activeGLWindow;

	//! Default picking mode
	ccGLWindowInterface::PICKING_MODE m_pickingMode;

	//! Automatically enables the picking mechanism on activated GL windows
	bool m_autoEnableOnActivatedWindow;

	//! Exclusive mode
	bool m_exclusive;

};