1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_FacesPanel_H_
22 #define XGUI_FacesPanel_H_
26 #include <ModelAPI_Object.h>
28 #include <ModuleBase_ActionType.h>
29 #include <ModuleBase_Definitions.h>
30 #include <ModuleBase_ViewerPrs.h>
32 #include <SelectMgr_ListOfFilter.hxx>
34 #include <QDockWidget>
40 class AIS_InteractiveObject;
42 class GeomAPI_AISObject;
44 class ModuleBase_IWorkshop;
45 class ModuleBase_ListView;
53 * A Hide Faces panel for making it possible to hide faces in the 3D view.
54 * The panel has multi-selector filled by faces elements. When the control is active
55 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
56 * after selection and the corresponding item is appeared in the multi selector.
58 * In order to redisplay a face, it is enough to click delete on the name of this face
59 * in the multiselector.
60 * When the panel is opened, the multiselector is empty.
61 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
62 * The default position by of this dockable window is to the right of the view (in SALOME mode).
63 * If no feature is processed (in neutral point), this panel can be activated too.
64 * On feature edition start or finish, movement of the history line, undo/redo and other
65 * modification of the model, the multiselector is emptied.
67 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
72 /// \param theParent is a parent of the property panel
73 XGUI_FacesPanel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop);
76 /// Clear content of list widget
77 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
78 virtual void reset(const bool isToFlushRedisplay);
80 /// Fills container with the panel selection mode: FACE
81 // \param theModes [out] a container of modes
82 void selectionModes(QIntList& theModes);
84 /// Appends into container of workshop selection filters
85 /// \param [out] selection filters
86 void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
88 /// Returns whether the panel is active or not
89 bool isActivePanel() const { return myIsActive; }
91 /// Stores the state if panel is active and highlight the panel in an active color
92 /// \param theIsActive state whether the panel should be activated or deactivated
93 void setActivePanel(const bool theIsActive);
95 /// Returns true if transparency choice is checked
96 /// \return boolean value
97 bool useTransparency() const;
99 /// Returns true if the object is in internal container of hidden objects by this panel
100 /// \param theObject a checked object
101 /// \return boolean value
102 bool isObjectHiddenByPanel(const std::shared_ptr<ModelAPI_Object>& theObject) const
103 { return myHiddenObjects.find(theObject) != myHiddenObjects.end(); }
105 /// Removed faces of the objects from the panel
106 /// \param container of objects
107 void restoreObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects);
109 /// Returns true if the event is processed. The default implementation is empty, returns false.
110 virtual bool processAction(ModuleBase_ActionType theActionType);
112 /// Append selected item in the list and customize presentations to hide faces
113 void processSelection();
115 /// Deletes item in a list of elements
116 /// \return whether the delete action is processed
117 bool processDelete();
119 /// Processing focus in/out for the faces control
120 /// \param theObject source object of event
121 /// \param theEvent an event
122 virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
124 /// Hide/show faces of the object if:
125 /// - face selector is active
126 /// - object is mentioned in the list of selected elements
127 /// If the object is displayed, all panel faces selected on it will be moved into presentation
128 /// or, if redisplayed, fuction return if the object should be redisplayed or not
129 /// \param theObject a customized object
130 /// \param thePresentation visualized presentation of the object
131 /// \return true if the presentation is customized
132 bool customizeObject(const std::shared_ptr<ModelAPI_Object>& theObject,
133 const std::shared_ptr<GeomAPI_AISObject>& thePresentation);
136 /// Reimplementation to emit a signal about the panel close
137 virtual void closeEvent(QCloseEvent* theEvent);
140 /// Signal about activating pane
142 /// Signal about deactivating pane
144 /// Signal is emitted by the top widget cross button click
148 /// Redisplay objects.
149 /// \param theObjects container of objects
150 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
151 /// \return true if some of objects was redisplayed
152 static bool redisplayObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
153 const bool isToFlushRedisplay);
155 /// Display objects if the objects are in a container of hidden by this pane.
156 /// \param theObjects container of objects
157 /// \param theHiddenObjects hidden objects, if object is in the container, it should be removed
158 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
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,
162 const bool isToFlushRedisplay);
164 /// Iterates by items and hide objects where all sub-shapes are hidden
165 /// \return true if some of objects was redisplayed
166 bool hideEmptyObjects();
168 /// Container of objects participating in the panel, it is filled by internal container
169 /// \param theItems container of selected values
170 /// \param theObjects [out] container of objects
171 static void updateProcessedObjects(QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > theItems,
172 std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
174 /// Generates a presentation name in form: <object_name>/<face>_<face_index>
175 /// \param thePrs a presentation
176 /// \return string value
177 static QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
180 /// Deletes element in list of items
183 /// Upates hidden faces to be hidden or transparent
184 void onTransparencyChanged();
186 /// Closes faces panel restore all hidden faces by calling reset()
190 QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
191 ModuleBase_ListView* myListView; ///< list control of processed faces
192 ModuleBase_IWorkshop* myWorkshop; ///< workshop
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
197 QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > 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