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