Salome HOME
Issue #2824: Constraints at wrong positions when editing the sketch
[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   /// Returns list of currently active selection modes
71   /// Selection modes will be returned according to TopAbs_ShapeEnum
72   XGUI_EXPORT QIntList activeSelectionModes() const;
73
74   /// Returns true if the given object can be selected
75   /// \param theObject object to check
76   XGUI_EXPORT bool isActive(ObjectPtr theObject) const;
77
78   /// Activates in local context displayed outside of the context.
79   /// \param theModes - modes on which it has to be activated (can be empty)
80   /// \param theObjList - list of objects which has to be activated.
81   /// \param theUpdateViewer an update viewer flag
82   XGUI_EXPORT void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
83                                    const bool theUpdateViewer = true);
84
85   /// Fill container of current selection modes
86   /// \param theModes selection modes
87   XGUI_EXPORT void setSelectionModes(const QIntList& theModes);
88
89   /// Activate object in the selection modes
90   /// \param theIO an object
91   /// \param theUpdateViewer an update viewer flag
92   XGUI_EXPORT void activateOnDisplay(const Handle(AIS_InteractiveObject)& theIO,
93                                      const bool theUpdateViewer);
94
95   /// Activate interactive object
96   /// \param theIO an interactive object
97   /// \param theMode activation mode
98   /// \param theUpdateViewer update viewer flag
99   XGUI_EXPORT void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
100                                const bool theUpdateViewer) const;
101
102   /// Activate interactive object. It is necessary to call ClearOutdatedSelection
103   /// after deactivation
104   /// \param theIO an interactive object
105   /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
106   XGUI_EXPORT void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO,
107                                  const int theMode = -1) const;
108
109   /// Activates the interactive object in the local context.
110   /// \param theIO an interactive object
111   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
112   /// \return a flag is object activated or not
113   XGUI_EXPORT bool activate(const Handle(AIS_InteractiveObject)& theIO,
114                             const bool theUpdateViewer) const;
115
116   /// Deactivates the given object (not allow selection)
117   /// \param theObject object to deactivate
118   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
119   XGUI_EXPORT void deactivate(const std::shared_ptr<ModelAPI_Object>& theObject,
120                               const bool theUpdateViewer);
121
122   /// Returns true if the trihedron should be activated in current selection modes
123   bool isTrihedronActive() const { return myIsTrihedronActive; }
124
125   /// Set trihedron active (used in selection) or non active
126   XGUI_EXPORT void activateTrihedron(bool theIsActive);
127
128   /// Find a trihedron in a list of displayed presentations and deactivate it.
129   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
130   XGUI_EXPORT void deactivateTrihedron(const bool theUpdateViewer) const;
131
132   /// Get selection modes of trihedron and deactivate it in it.
133   XGUI_EXPORT void deactivateTrihedronInSelectionModes();
134
135 protected:
136   /// Returns selection modes of the widget
137   /// \param theWidget model widget
138   /// \param theModes selection modes
139   void getSelectionModes(ModuleBase_ModelWidget* theWidget, QIntList& theModes);
140
141   /// Returns Trihedron object if it is displayed
142   Handle(AIS_InteractiveObject) getTrihedron() const;
143
144   /// Returns context of the 3D viewer
145   /// \return context instance
146   Handle(AIS_InteractiveContext) AISContext() const;
147
148   /// Returns displayer
149   /// \return displayer
150   XGUI_Displayer* getDisplayer() const;
151
152   /// Returns AIS object displayed in 3D viewer for the given model object
153   /// \param theObject source object
154   /// \returns interactive object
155   AISObjectPtr getDisplayedAISObject(std::shared_ptr<ModelAPI_Object> theObject) const;
156
157   /// Converts shape type (TopAbs_ShapeEnum) to selection mode
158   /// \param theShapeType a shape type from TopAbs_ShapeEnum
159   static int getSelectionMode(int theShapeType);
160
161 protected:
162   QIntList myActiveSelectionModes; ///< Current activated selection modes
163   bool myIsTrihedronActive; ///< Flag: use trihedgon for selection or not
164 };
165
166 #endif