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