Salome HOME
First integration of a new PV3D viewer.
[modules/gui.git] / src / SPV3D / SPV3D_CADSelection.h
1 // Copyright (C) 2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #pragma once
21
22 #include <pqSelectionReaction.h>
23
24 #include <vtkSmartPointer.h>
25 #include <vtkWeakPointer.h>
26
27 #include <QCursor>
28 #include <QPointer>
29 #include <QTimer>
30 #include <QPushButton>
31 #include <QComboBox>
32
33 class vtkObject;
34 class pqView;
35 class pqRenderView;
36 class vtkIntArray;
37 class pqDataRepresentation;
38 class vtkSMRepresentationProxy;
39 class vtkSMSourceProxy;
40
41 /**
42  * SPV3D_CADSelection handles various selection modes available on
43  * RenderViews. Simply create multiple instances of
44  * SPV3D_CADSelection to handle selection modes for that RenderView.
45  * SPV3D_CADSelection uses internal static members to ensure that
46  * at most 1 view (and 1 type of selection) is in selection-mode at any given
47  * time.
48  */
49 class SPV3D_CADSelection : public QObject
50 {
51   Q_OBJECT
52
53 public:
54   enum SelectionMode
55   {
56     SELECT_SOLIDS,
57     SELECT_FACES,
58     SELECT_EDGES,
59     SELECT_VERTICES
60   };
61
62   /**
63    * If \c view is nullptr, this reaction will track the active-view maintained by
64    * pqActiveObjects.
65    */
66   SPV3D_CADSelection(QObject *parent, pqRenderView* view, SelectionMode mode);
67   
68   ~SPV3D_CADSelection() override;
69
70   /**
71    * Set the selectionMode
72    */
73   void SetMode(const SPV3D_CADSelection::SelectionMode mode);
74   
75 public Q_SLOTS:
76   /**
77    * For checkable actions, this calls this->beginSelection() or
78    * this->endSelection() is val is true or false, respectively. For
79    * non-checkable actions, this call this->beginSelection() and
80    * this->endSelection() in that order.
81    */
82   virtual void actionTriggered(bool val);
83   
84 private Q_SLOTS:
85   /**
86    * Called when this object was created with nullptr as the view and the active
87    * view changes.
88    */
89   void setView(pqView* view);
90
91   /**
92    * Called when the active representation changes.
93    */
94   void setRepresentation(pqDataRepresentation* representation);
95
96   /**
97    * starts the selection i.e. setup render view in selection mode.
98    */
99   void beginSelection();
100
101   /**
102    * finishes the selection. Doesn't cause the selection, just returns the
103    * render view to previous interaction mode.
104    */
105   void endSelection();
106
107   void updateEnableState();
108
109   ///@{
110   /**
111    * Disable preselection during rotation using the right button.
112    */
113   void onRightButtonPress();
114   void onRightButtonRelease();
115   ///@}
116
117 private:
118
119   /**
120    * callback called when the vtkPVRenderView is done with selection.
121    */
122   void selectionChanged(vtkObject*, unsigned long, void* calldata);
123
124   /**
125    * callback called for mouse move events when in 'interactive selection'
126    * modes.
127    */
128   void onMouseMove();
129
130   /**
131    * callback called for click events when in 'interactive selection' modes.
132    */
133   void onLeftButtonRelease();
134
135   // Get the current state of selection modifier
136   int getSelectionModifier();
137
138   /**
139    * makes fast selection.
140    */
141   void fastSelection(bool presel = false);
142
143   /**
144    * cleans up observers.
145    */
146   void cleanupObservers();
147
148   Q_DISABLE_COPY(SPV3D_CADSelection)
149   QPointer<pqRenderView> View;
150   QPointer<pqDataRepresentation> Representation;
151   QMetaObject::Connection RepresentationConnection;
152   vtkSMRepresentationProxy* CurrentRepresentation = nullptr;
153   SelectionMode Mode;
154   int PreviousRenderViewMode;
155   vtkWeakPointer<vtkObject> ObservedObject;
156   unsigned long ObserverIds[4];
157   int MousePosition[2];
158   QComboBox* selectionComboBox;
159   bool DisablePreSelection = false;
160 };