]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_FacesPanel.h
Salome HOME
#2309 Possibility to hide faces
[modules/shaper.git] / src / XGUI / XGUI_FacesPanel.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_FacesPanel_H_
22 #define XGUI_FacesPanel_H_
23
24 #include "XGUI.h"
25
26 #include <ModuleBase_ActionType.h>
27
28 #include <QDockWidget>
29 #include <QObject>
30 #include <QMap>
31
32 #include <set>
33
34 class AIS_InteractiveObject;
35
36 class ModelAPI_Object;
37 class ModuleBase_IWorkshop;
38 class ModuleBase_ListView;
39 class ModuleBase_ViewerPrs;
40
41 class QAction;
42 class QCheckBox;
43 class QEvent;
44
45 /**
46 * \ingroup GUI
47 * A Hide Faces panel for making it possible to hide faces in the 3D view.
48 * The panel has multi-selector filled by faces elements. When the control is active
49 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
50 * after selection and the corresponding item is appeared in the multi selector.
51 *
52 * In order to redisplay a face, it is enough to click delete on the name of this face
53 * in the multiselector.
54 * When the panel is opened, the multiselector is empty.
55 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
56 * The default position by of this dockable window is to the right of the view (in SALOME mode).
57 * If no feature is processed (in neutral point), this panel can be activated too.
58 * On feature edition start or finish, movement of the history line, undo/redo and other
59 * modification of the model, the multiselector is emptied.
60 */
61 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
62 {
63   Q_OBJECT
64 public:
65   /// Constructor
66   /// \param theParent is a parent of the property panel
67   XGUI_FacesPanel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop);
68   ~XGUI_FacesPanel() {}
69
70   /// Clear content of list widget
71   /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
72   virtual void reset(const bool isToFlushRedisplay);
73
74   /// Returns whether the panel is active or not
75   bool isActivePanel() const { return myIsActive; }
76
77   /// Stores the state if panel is active and highlight the panel in an active color
78   /// \param theIsActive state whether the panel should be activated or deactivated
79   void setActivePanel(const bool theIsActive);
80
81   /// Returns true if the object is in internal container of hidden objects by this panel
82   /// \param theObject a checked object
83   /// \return boolean value
84   bool isObjectHiddenByPanel(const std::shared_ptr<ModelAPI_Object>& theObject) const
85   { return myHiddenObjects.find(theObject) != myHiddenObjects.end(); }
86
87   /// Removed faces of the objects from the panel
88   /// \param container of objects
89   void restoreObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects);
90
91   /// Returns true if the event is processed. The default implementation is empty, returns false.
92   virtual bool processAction(ModuleBase_ActionType theActionType);
93
94   /// Append selected item in the list and customize presentations to hide faces
95   void processSelection();
96
97   /// Deletes item in a list of elements
98   /// \return whether the delete action is processed
99   bool processDelete();
100
101   /// Processing focus in/out for the faces control
102   /// \param theObject source object of event
103   /// \param theEvent an event
104   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
105
106   /// Hide/show faces of the object if:
107   /// - face selector is active
108   /// - object is mentioned in the list of selected elements
109   /// If the object is displayed, all panel faces selected on it will be moved into presentation
110   /// or, if redisplayed, fuction return if the object should be redisplayed or not
111   /// \param theObject a customized object
112   /// \param isDisplayed state if the object is displayed or redisplayed
113   /// \return true if the presentation is customized
114   bool customizeObject(const std::shared_ptr<ModelAPI_Object>& theObject, const bool isDisplayed);
115
116 protected:
117   /// Add panel selection filters to the current viewer
118   virtual void activateSelectionFilters() {}
119
120   /// Remove panel selection filters from the current viewer
121   virtual void deactivateSelectionFilters() {}
122
123 protected:
124   /// Reimplementation to emit a signal about the panel close
125   virtual void closeEvent(QCloseEvent* theEvent);
126
127 signals:
128   /// Signal about activating pane
129   void activated();
130   /// Signal about deactivating pane
131   void deactivated();
132   /// Signal is emitted by the top widget cross button click
133   void closed();
134
135 private:
136   /// Activate or deactivate selection and selection filters
137   void activateSelection(bool toActivate);
138
139   /// Redisplay or display objects. The viewer is not updated after redisplay.
140   /// \param theObjects container of objects
141   /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
142   /// \return true if some of objects was redisplayed to update viewer
143   bool redisplayObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
144                         const bool isToFlushRedisplay);
145
146   /// Change the presentation to have the selected presentation hidden
147   /// \param theIndex an index of selected item that should be hidden
148   /// \return true if presentation is changed
149   bool hideFace(const int theIndex);
150
151   /// Generates a presentation name in form: <object_name>/<face>_<face_index>
152   /// \param thePrs a presentation
153   /// \return string value
154   static QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
155
156 protected slots:
157   /// Deletes element in list of items
158   void onDeleteItem();
159
160   /// Closes faces panel restore all hidden faces by calling reset()
161   void onClosed();
162
163 protected:
164   QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
165   ModuleBase_ListView* myListView; ///< list control of processed faces
166   ModuleBase_IWorkshop* myWorkshop; ///< workshop
167
168   bool myIsActive; ///< current state about the panel is active
169   int myLastItemIndex; ///< last index to be used in the map of items for the next added item
170
171   QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > myItems; ///< selected face items
172   std::set<std::shared_ptr<ModelAPI_Object> > myHiddenObjects; ///< hidden objects
173 };
174
175 #endif