Salome HOME
Issue #2355 hide all faces then show solid problem
[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 <ModelAPI_Object.h>
27
28 #include <ModuleBase_ActionType.h>
29 #include <ModuleBase_Definitions.h>
30 #include <ModuleBase_ViewerPrs.h>
31
32 #include <SelectMgr_ListOfFilter.hxx>
33
34 #include <QDockWidget>
35 #include <QObject>
36 #include <QMap>
37
38 #include <set>
39
40 class AIS_InteractiveObject;
41
42 class GeomAPI_AISObject;
43
44 class ModuleBase_IWorkshop;
45 class ModuleBase_ListView;
46
47 class QAction;
48 class QCheckBox;
49 class QEvent;
50
51 /**
52 * \ingroup GUI
53 * A Hide Faces panel for making it possible to hide faces in the 3D view.
54 * The panel has multi-selector filled by faces elements. When the control is active
55 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
56 * after selection and the corresponding item is appeared in the multi selector.
57 *
58 * In order to redisplay a face, it is enough to click delete on the name of this face
59 * in the multiselector.
60 * When the panel is opened, the multiselector is empty.
61 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
62 * The default position by of this dockable window is to the right of the view (in SALOME mode).
63 * If no feature is processed (in neutral point), this panel can be activated too.
64 * On feature edition start or finish, movement of the history line, undo/redo and other
65 * modification of the model, the multiselector is emptied.
66 */
67 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
68 {
69   Q_OBJECT
70 public:
71   /// Constructor
72   /// \param theParent is a parent of the property panel
73   XGUI_FacesPanel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop);
74   ~XGUI_FacesPanel() {}
75
76   /// Clear content of list widget
77   /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
78   virtual void reset(const bool isToFlushRedisplay);
79
80   /// Returns whether faces panel contains elements
81   /// \return boolean value
82   bool isEmpty() const;
83
84   /// Fills container with the panel selection mode: FACE
85   // \param theModes [out] a container of modes
86   void selectionModes(QIntList& theModes);
87
88   /// Appends into container of workshop selection filters
89   /// \param [out] selection filters
90   void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
91
92   /// Returns whether the panel is active or not
93   bool isActivePanel() const { return myIsActive; }
94
95   /// Stores the state if panel is active and highlight the panel in an active color
96   /// \param theIsActive state whether the panel should be activated or deactivated
97   void setActivePanel(const bool theIsActive);
98
99   /// Returns true if transparency choice is checked
100   /// \return boolean value
101   bool useTransparency() const;
102
103   /// Returns true if the object is in internal container of hidden objects by this panel
104   /// \param theObject a checked object
105   /// \return boolean value
106   bool isObjectHiddenByPanel(const std::shared_ptr<ModelAPI_Object>& theObject) const
107   { return myHiddenObjects.find(theObject) != myHiddenObjects.end(); }
108
109   /// Removed faces of the objects from the panel
110   /// \param container of objects
111   void restoreObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects);
112
113   /// Returns true if the event is processed. The default implementation is empty, returns false.
114   virtual bool processAction(ModuleBase_ActionType theActionType);
115
116   /// Append selected item in the list and customize presentations to hide faces
117   void processSelection();
118
119   /// Deletes item in a list of elements
120   /// \return whether the delete action is processed
121   bool processDelete();
122
123   /// Processing focus in/out for the faces control
124   /// \param theObject source object of event
125   /// \param theEvent an event
126   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
127
128   /// Hide/show faces of the object if:
129   /// - face selector is active
130   /// - object is mentioned in the list of selected elements
131   /// If the object is displayed, all panel faces selected on it will be moved into presentation
132   /// or, if redisplayed, fuction return if the object should be redisplayed or not
133   /// \param theObject a customized object
134   /// \param thePresentation visualized presentation of the object
135   /// \return true if the presentation is customized
136   bool customizeObject(const std::shared_ptr<ModelAPI_Object>& theObject,
137     const std::shared_ptr<GeomAPI_AISObject>& thePresentation);
138
139 protected:
140   /// Reimplementation to emit a signal about the panel close
141   virtual void closeEvent(QCloseEvent* theEvent);
142
143 signals:
144   /// Signal about activating pane
145   void activated();
146   /// Signal about deactivating pane
147   void deactivated();
148   /// Signal is emitted by the top widget cross button click
149   void closed();
150
151 private:
152   /// Redisplay objects.
153   /// \param theObjects container of objects
154   /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
155   /// \return true if some of objects was redisplayed
156   static bool redisplayObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
157                                const bool isToFlushRedisplay);
158
159   /// Display objects if the objects are in a container of hidden by this pane.
160   /// \param theObjects container of objects
161   /// \param theHiddenObjects hidden objects, if object is in the container, it should be removed
162   /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
163   /// \return true if some of objects was redisplayed
164   static bool displayHiddenObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
165                                    std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects,
166                                    const bool isToFlushRedisplay);
167
168   /// Iterates by items and hide objects where all sub-shapes are hidden
169   /// \return true if some of objects was redisplayed
170   bool hideEmptyObjects();
171
172   /// Container of objects participating in the panel, it is filled by internal container
173   /// \param theItems container of selected values
174   /// \param theObjects [out] container of objects
175   static void updateProcessedObjects(QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > theItems,
176                                      std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
177
178   /// Generates a presentation name in form: <object_name>/<face>_<face_index>
179   /// \param thePrs a presentation
180   /// \return string value
181   static QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
182
183 protected slots:
184   /// Deletes element in list of items
185   void onDeleteItem();
186
187   /// Upates hidden faces to be hidden or transparent
188   void onTransparencyChanged();
189
190   /// Closes faces panel restore all hidden faces by calling reset()
191   void onClosed();
192
193 protected:
194   QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
195   ModuleBase_ListView* myListView; ///< list control of processed faces
196   ModuleBase_IWorkshop* myWorkshop; ///< workshop
197
198   bool myIsActive; ///< current state about the panel is active
199   int myLastItemIndex; ///< last index to be used in the map of items for the next added item
200
201   QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > myItems; ///< selected face items
202   std::set<std::shared_ptr<ModelAPI_Object> > myItemObjects; ///< cached objects of myItems
203   std::set<std::shared_ptr<ModelAPI_Object> > myHiddenObjects; ///< hidden objects
204 };
205
206 #endif