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