1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef XGUI_FacesPanel_H_
21 #define XGUI_FacesPanel_H_
25 #include <ModelAPI_Object.h>
27 #include <ModuleBase_ActionType.h>
28 #include <ModuleBase_Definitions.h>
29 #include <ModuleBase_ViewerPrs.h>
31 #include <SelectMgr_ListOfFilter.hxx>
33 #include <QDockWidget>
39 class AIS_InteractiveObject;
41 class GeomAPI_AISObject;
43 class ModuleBase_IWorkshop;
44 class ModuleBase_ListView;
52 * A Hide Faces panel for making it possible to hide faces in the 3D view.
53 * The panel has multi-selector filled by faces elements. When the control is active
54 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
55 * after selection and the corresponding item is appeared in the multi selector.
57 * In order to redisplay a face, it is enough to click delete on the name of this face
58 * in the multiselector.
59 * When the panel is opened, the multiselector is empty.
60 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
61 * The default position by of this dockable window is to the right of the view (in SALOME mode).
62 * If no feature is processed (in neutral point), this panel can be activated too.
63 * On feature edition start or finish, movement of the history line, undo/redo and other
64 * modification of the model, the multiselector is emptied.
66 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
71 /// \param theParent is a parent of the property panel
72 XGUI_FacesPanel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop);
75 /// Clear content of list widget
76 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
77 virtual void reset(const bool isToFlushRedisplay);
79 /// Returns whether faces panel contains elements
80 /// \return boolean value
83 /// Fills container with the panel selection mode: FACE
84 // \param theModes [out] a container of modes
85 void selectionModes(QIntList& theModes);
87 /// Appends into container of workshop selection filters
88 /// \param [out] selection filters
89 void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
91 /// Returns whether the panel is active or not
92 bool isActivePanel() const { return myIsActive; }
94 /// Stores the state if panel is active and highlight the panel in an active color
95 /// \param theIsActive state whether the panel should be activated or deactivated
96 void setActivePanel(const bool theIsActive);
98 /// Returns true if transparency choice is checked
99 /// \return boolean value
100 bool useTransparency() const;
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(); }
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);
112 /// Returns true if the event is processed. The default implementation is empty, returns false.
113 virtual bool processAction(ModuleBase_ActionType theActionType);
115 /// Append selected item in the list and customize presentations to hide faces
116 void processSelection();
118 /// Deletes item in a list of elements
119 /// \return whether the delete action is processed
120 bool processDelete();
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);
127 /// Hide/show faces of the object if:
128 /// - face selector is active
129 /// - object is mentioned in the list of selected elements
130 /// If the object is displayed, all panel faces selected on it will be moved into presentation
131 /// or, if redisplayed, fuction return if the object should be redisplayed or not
132 /// \param theObject a customized object
133 /// \param thePresentation visualized presentation of the object
134 /// \return true if the presentation is customized
135 bool customizeObject(const std::shared_ptr<ModelAPI_Object>& theObject,
136 const std::shared_ptr<GeomAPI_AISObject>& thePresentation);
139 /// Reimplementation to emit a signal about the panel close
140 virtual void closeEvent(QCloseEvent* theEvent);
143 /// Signal about activating pane
145 /// Signal about deactivating pane
147 /// Signal is emitted by the top widget cross button click
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<std::shared_ptr<ModelAPI_Object> >& theObjects);
156 /// Display objects if the objects are in a container of hidden by this pane.
157 /// \param theObjects container of objects
158 /// \param theHiddenObjects hidden objects, if object is in the container, it should be removed
159 /// \return true if some of objects was redisplayed
160 static bool displayHiddenObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
161 std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects);
163 /// Iterates by items and hide objects where all sub-shapes are hidden
164 /// \return true if some of objects was redisplayed
165 bool hideEmptyObjects();
167 /// Container of objects participating in the panel, it is filled by internal container
168 /// \param theItems container of selected values
169 /// \param theObjects [out] container of objects
170 static void updateProcessedObjects(QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > theItems,
171 std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
174 /// Deletes element in list of items
177 /// Upates hidden faces to be hidden or transparent
178 void onTransparencyChanged();
180 /// Closes faces panel restore all hidden faces by calling reset()
184 /// Flushes redisplay event and perform update of object browser icons
185 /// (objects might be hidden/shown)
186 void flushRedisplay() const;
189 QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
190 ModuleBase_ListView* myListView; ///< list control of processed faces
191 ModuleBase_IWorkshop* myWorkshop; ///< workshop
193 bool myIsActive; ///< current state about the panel is active
194 int myLastItemIndex; ///< last index to be used in the map of items for the next added item
196 QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > myItems; ///< selected face items
197 std::set<std::shared_ptr<ModelAPI_Object> > myItemObjects; ///< cached objects of myItems
198 std::set<std::shared_ptr<ModelAPI_Object> > myHiddenObjects; ///< hidden objects