Salome HOME
Activation objects redesign.
[modules/shaper.git] / src / XGUI / XGUI_SelectionActivate.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_ISelectionActivate_H
22 #define XGUI_ISelectionActivate_H
23
24 #include "XGUI.h"
25
26 #include "ModuleBase_Definitions.h"
27 #include "ModuleBase_ISelectionActivate.h"
28
29 #include "SelectMgr_ListOfFilter.hxx"
30
31 #include <memory>
32
33 class AIS_InteractiveContext;
34 class AIS_InteractiveObject;
35 class ModelAPI_Object;
36
37 class XGUI_Displayer;
38
39 /// \ingroup GUI
40 /// A class which implements activation/deactivate selection modes and using selection filters.
41 class XGUI_SelectionActivate : public ModuleBase_ISelectionActivate
42 {
43 public:
44   /// Types of the activation place
45   enum SelectionPlace { Workshop, PropertyPanel, FacesPanel };
46
47 public:
48   /// Constructor
49   XGUI_EXPORT XGUI_SelectionActivate(ModuleBase_IWorkshop* theWorkshop);
50
51   /// Destructor
52   ~XGUI_SelectionActivate() {}
53
54   /// Returns place of activation modes that now is active
55   /// \return place
56   SelectionPlace activeSelectionPlace() const;
57
58   /// Updates active selection modes in the viewer depending on the application state
59   XGUI_EXPORT virtual void updateSelectionModes();
60
61   /// Updates active selection filters in the viewer depending on the application state
62   XGUI_EXPORT virtual void updateSelectionFilters();
63
64   /// Activates parameter filters in the workshop, deactivate active out of the container
65   /// Please find a possibility to use updateSelectionFilters instead of direct call this method.
66   /// \param theSelectionFilters a filtes
67   XGUI_EXPORT virtual void activateSelectionFilters
68     (const SelectMgr_ListOfFilter& theSelectionFilters);
69
70   /// Activate or deactivate selection and selection filters like the widget is active
71   /// \param theWidget a source widget of selection modes/filters
72   XGUI_EXPORT virtual void activateSelectionAndFilters(ModuleBase_ModelWidget* theWidget);
73
74   /// Returns list of currently active selection modes
75   /// Selection modes will be returned according to TopAbs_ShapeEnum
76   XGUI_EXPORT QIntList activeSelectionModes() const;
77
78   /// Returns true if the given object can be selected
79   /// \param theObject object to check
80   XGUI_EXPORT bool isActive(ObjectPtr theObject) const;
81
82   /// Activates in local context displayed outside of the context.
83   /// \param theModes - modes on which it has to be activated (can be empty)
84   /// \param theObjList - list of objects which has to be activated.
85   /// \param theUpdateViewer an update viewer flag
86   XGUI_EXPORT void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
87                                    const bool theUpdateViewer = true);
88
89   /// Fill container of current selection modes
90   /// \param theModes selection modes
91   XGUI_EXPORT void setSelectionModes(const QIntList& theModes);
92
93   /// Activate object in the selection modes
94   /// \param theIO an object
95   /// \param theUpdateViewer an update viewer flag
96   XGUI_EXPORT void activateOnDisplay(const Handle(AIS_InteractiveObject)& theIO,
97                                      const bool theUpdateViewer);
98
99   /// Activate interactive object
100   /// \param theIO an interactive object
101   /// \param theMode activation mode
102   /// \param theUpdateViewer update viewer flag
103   XGUI_EXPORT void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
104                                const bool theUpdateViewer) const;
105
106   /// Activate interactive object. It is necessary to call ClearOutdatedSelection
107   /// after deactivation
108   /// \param theIO an interactive object
109   /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
110   XGUI_EXPORT void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
111                                  const int theMode = -1) const;
112
113   /// Activates the interactive object in the local context.
114   /// \param theIO an interactive object
115   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
116   /// \return a flag is object activated or not
117   XGUI_EXPORT bool activate(const Handle(AIS_InteractiveObject)& theIO,
118                             const bool theUpdateViewer) const;
119
120   /// Deactivates the given object (not allow selection)
121   /// \param theObject object to deactivate
122   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
123   XGUI_EXPORT void deactivate(const std::shared_ptr<ModelAPI_Object>& theObject,
124                               const bool theUpdateViewer);
125
126   /// Returns true if the trihedron should be activated in current selection modes
127   bool isTrihedronActive() const { return myIsTrihedronActive; }
128
129   /// Set trihedron active (used in selection) or non active
130   XGUI_EXPORT void activateTrihedron(bool theIsActive);
131
132   /// Find a trihedron in a list of displayed presentations and deactivate it.
133   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
134   XGUI_EXPORT void deactivateTrihedron(const bool theUpdateViewer) const;
135
136   /// Get selection modes of trihedron and deactivate it in it.
137   XGUI_EXPORT void deactivateTrihedronInSelectionModes();
138
139 protected:
140   /// Returns selection modes of the widget
141   /// \param theWidget model widget
142   /// \param theModes selection modes
143   void getSelectionModes(ModuleBase_ModelWidget* theWidget, QIntList& theModes);
144
145   /// Returns selection filters of the widget
146   /// \param theWidget model widget
147   /// \param theSelectionFilters selection filters
148   void getSelectionFilters(ModuleBase_ModelWidget* theWidget,
149                            SelectMgr_ListOfFilter& theSelectionFilters);
150
151   /// Returns Trihedron object if it is displayed
152   Handle(AIS_InteractiveObject) getTrihedron() const;
153
154   /// Returns context of the 3D viewer
155   /// \return context instance
156   Handle(AIS_InteractiveContext) AISContext() const;
157
158   /// Returns displayer
159   /// \return displayer
160   XGUI_Displayer* getDisplayer() const;
161
162   /// Returns AIS object displayed in 3D viewer for the given model object
163   /// \param theObject source object
164   /// \returns interactive object
165   AISObjectPtr getDisplayedAISObject(std::shared_ptr<ModelAPI_Object> theObject) const;
166
167   /// Converts shape type (TopAbs_ShapeEnum) to selection mode
168   /// \param theShapeType a shape type from TopAbs_ShapeEnum
169   static int getSelectionMode(int theShapeType);
170
171 protected:
172   QIntList myActiveSelectionModes; ///< Current activated selection modes
173   bool myIsTrihedronActive; ///< Flag: use trihedgon for selection or not
174 };
175
176 #endif