Salome HOME
Issue #18398(Tuleap): Restore visual properties change functionality
[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   XGUI_Workshop* workshop() const { return myWorkshop; }
126
127
128 protected:
129   /// Reimplementation to emit a signal about the panel close
130   virtual void closeEvent(QCloseEvent* theEvent);
131
132 signals:
133   /// Signal about activating pane
134   void activated();
135   /// Signal about deactivating pane
136   void deactivated();
137   /// Signal is emitted by the top widget cross button click
138   void closed();
139
140 private:
141   /// Redisplay objects.
142   /// \param theObjects container of objects
143   /// \return true if some of objects was redisplayed
144   static bool redisplayObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
145
146   /// Container of objects participating in the panel, it is filled by internal container
147   /// \param theItems container of selected values
148   /// \param theObjects [out] container of objects
149   static void updateProcessedObjects(QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > theItems,
150                                      std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
151
152   /// Returns maps of shapes and presentations. If object is a body result then it returns
153   /// its ruslts. If it is a group then it returns result of shapes included into the gropup
154   /// The function doesn't clear content of input maps.
155   /// \param thePrs a selected presintation
156   /// \param theObjectsToShapes map of objects to shapes list
157   /// \param theObjectToPrs map of objects to presentations
158   void getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
159     std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectsToShapes,
160     std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
161
162   /// Returns true if transparency choice is checked
163   /// \return boolean value
164   bool useTransparency() const;
165
166   double transparency() const;
167
168 protected slots:
169   /// Deletes element in list of items
170   void onDeleteItem();
171
172   /// Upates hidden faces to be hidden or transparent
173   void onTransparencyChanged();
174
175   /// Closes faces panel restore all hidden faces by calling reset()
176   void onClosed();
177
178 private:
179   /// Flushes redisplay event and perform update of object browser icons
180   /// (objects might be hidden/shown)
181   void flushRedisplay() const;
182
183 protected:
184   QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
185   ModuleBase_ListView* myListView; ///< list control of processed faces
186   XGUI_Workshop* myWorkshop; ///< workshop
187
188   bool myIsActive; ///< current state about the panel is active
189   int myLastItemIndex; ///< last index to be used in the map of items for the next added item
190
191   QMap<int, ModuleBase_ViewerPrsPtr> myItems; ///< selected face items
192   std::set<std::shared_ptr<ModelAPI_Object> > myItemObjects; ///< cached objects of myItems
193   std::set<std::shared_ptr<ModelAPI_Object> > myHiddenObjects; ///< hidden objects
194   std::set<std::shared_ptr<ModelAPI_Object> > myHiddenGroups; ///< hidden objects
195 };
196
197 #endif