Salome HOME
Fix for the issue #19726 : Placement failed because of wrong name in face selection.
[modules/shaper.git] / src / XGUI / XGUI_FacesPanel.h
1 // Copyright (C) 2014-2020  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   /// Processing focus in/out for the faces control
125   /// \param theObject source object of event
126   /// \param theEvent an event
127   virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
128
129   XGUI_Workshop* workshop() const { return myWorkshop; }
130
131 public slots:
132   /// Slot called on an object erase
133   void onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS);
134
135 protected:
136   /// Reimplementation to emit a signal about the panel close
137   virtual void closeEvent(QCloseEvent* theEvent);
138
139 signals:
140   /// Signal about activating pane
141   void activated();
142   /// Signal about deactivating pane
143   void deactivated();
144   /// Signal is emitted by the top widget cross button click
145   void closed();
146
147 private:
148   /// Redisplay objects.
149   /// \param theObjects container of objects
150   /// \return true if some of objects was redisplayed
151   static bool redisplayObjects(const std::set<ObjectPtr>& theObjects);
152
153   /// Container of objects participating in the panel, it is filled by internal container
154   /// \param theItems container of selected values
155   /// \param theObjects [out] container of objects
156   static void updateProcessedObjects(QMap<int, ModuleBase_ViewerPrsPtr> theItems,
157                                      std::set<ObjectPtr>& theObjects);
158
159   /// Returns maps of shapes and presentations. If object is a body result then it returns
160   /// its ruslts. If it is a group then it returns result of shapes included into the gropup
161   /// The function doesn't clear content of input maps.
162   /// \param thePrs a selected presintation
163   /// \param theObjectsToShapes map of objects to shapes list
164   /// \param theObjectToPrs map of objects to presentations
165   void getObjectsMapFromResult(ResultGroupPtr theResGroup, FeaturePtr theGroupFeature,
166     std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectsToShapes,
167     std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
168
169   void getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
170     std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
171     std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
172
173   /// Returns true if transparency choice is checked
174   /// \return boolean value
175   bool useTransparency() const;
176
177   double transparency() const;
178
179   void removeItems(std::set<int> theIds);
180
181 protected slots:
182   /// Deletes element in list of items
183   void onDeleteItem();
184
185   /// Upates hidden faces to be hidden or transparent
186   void onTransparencyChanged();
187
188   /// Closes faces panel restore all hidden faces by calling reset()
189   void onClosed();
190
191   /// Flushes redisplay event and perform update of object browser icons
192   /// (objects might be hidden/shown)
193   void flushRedisplay() const;
194
195 private:
196
197   QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
198   ModuleBase_ListView* myListView; ///< list control of processed faces
199   XGUI_Workshop* myWorkshop; ///< workshop
200
201   bool myIsActive; ///< current state about the panel is active
202   int myLastItemIndex; ///< last index to be used in the map of items for the next added item
203
204   QMap<int, ModuleBase_ViewerPrsPtr> myItems; ///< selected face items
205   std::set<ObjectPtr > myItemObjects; ///< cached objects of myItems
206   std::set<ObjectPtr > myHiddenObjects; ///< hidden objects
207   std::set<ObjectPtr > myHiddenGroups; ///< hidden objects
208 };
209
210 #endif