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