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