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_ViewerPrs.h>
31 #include <QDockWidget>
37 class AIS_InteractiveObject;
39 class ModuleBase_IWorkshop;
40 class ModuleBase_ListView;
48 * A Hide Faces panel for making it possible to hide faces in the 3D view.
49 * The panel has multi-selector filled by faces elements. When the control is active
50 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
51 * after selection and the corresponding item is appeared in the multi selector.
53 * In order to redisplay a face, it is enough to click delete on the name of this face
54 * in the multiselector.
55 * When the panel is opened, the multiselector is empty.
56 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
57 * The default position by of this dockable window is to the right of the view (in SALOME mode).
58 * If no feature is processed (in neutral point), this panel can be activated too.
59 * On feature edition start or finish, movement of the history line, undo/redo and other
60 * modification of the model, the multiselector is emptied.
62 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
67 /// \param theParent is a parent of the property panel
68 XGUI_FacesPanel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop);
71 /// Clear content of list widget
72 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
73 virtual void reset(const bool isToFlushRedisplay);
75 /// Returns whether the panel is active or not
76 bool isActivePanel() const { return myIsActive; }
78 /// Stores the state if panel is active and highlight the panel in an active color
79 /// \param theIsActive state whether the panel should be activated or deactivated
80 void setActivePanel(const bool theIsActive);
82 /// Returns true if transparency choice is checked
83 /// \return boolean value
84 bool useTransparency() const;
86 /// Returns true if the object is in internal container of hidden objects by this panel
87 /// \param theObject a checked object
88 /// \return boolean value
89 bool isObjectHiddenByPanel(const std::shared_ptr<ModelAPI_Object>& theObject) const
90 { return myHiddenObjects.find(theObject) != myHiddenObjects.end(); }
92 /// Removed faces of the objects from the panel
93 /// \param container of objects
94 void restoreObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theHiddenObjects);
96 /// Returns true if the event is processed. The default implementation is empty, returns false.
97 virtual bool processAction(ModuleBase_ActionType theActionType);
99 /// Append selected item in the list and customize presentations to hide faces
100 void processSelection();
102 /// Deletes item in a list of elements
103 /// \return whether the delete action is processed
104 bool processDelete();
106 /// Processing focus in/out for the faces control
107 /// \param theObject source object of event
108 /// \param theEvent an event
109 virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
111 /// Hide/show faces of the object if:
112 /// - face selector is active
113 /// - object is mentioned in the list of selected elements
114 /// If the object is displayed, all panel faces selected on it will be moved into presentation
115 /// or, if redisplayed, fuction return if the object should be redisplayed or not
116 /// \param theObject a customized object
117 /// \param isDisplayed state if the object is displayed or redisplayed
118 /// \return true if the presentation is customized
119 bool customizeObject(const std::shared_ptr<ModelAPI_Object>& theObject, const bool isDisplayed);
122 /// Add panel selection filters to the current viewer
123 virtual void activateSelectionFilters() {}
125 /// Remove panel selection filters from the current viewer
126 virtual void deactivateSelectionFilters() {}
129 /// Reimplementation to emit a signal about the panel close
130 virtual void closeEvent(QCloseEvent* theEvent);
133 /// Signal about activating pane
135 /// Signal about deactivating pane
137 /// Signal is emitted by the top widget cross button click
141 /// Activate or deactivate selection and selection filters
142 void activateSelection(bool toActivate);
144 /// Redisplay or display objects. The viewer is not updated after redisplay.
145 /// \param theObjects container of objects
146 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
147 /// \return true if some of objects was redisplayed to update viewer
148 bool redisplayObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects,
149 const bool isToFlushRedisplay);
151 /// Change the presentation to have the selected presentation hidden
152 /// \param theIndex an index of selected item that should be hidden
153 /// \return true if presentation is changed
154 bool hideFace(const int theIndex);
156 /// Generates a presentation name in form: <object_name>/<face>_<face_index>
157 /// \param thePrs a presentation
158 /// \return string value
159 static QString generateName(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
162 /// Deletes element in list of items
165 /// Closes faces panel restore all hidden faces by calling reset()
169 QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
170 ModuleBase_ListView* myListView; ///< list control of processed faces
171 ModuleBase_IWorkshop* myWorkshop; ///< workshop
173 bool myIsActive; ///< current state about the panel is active
174 int myLastItemIndex; ///< last index to be used in the map of items for the next added item
176 QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > myItems; ///< selected face items
177 std::set<std::shared_ptr<ModelAPI_Object> > myHiddenObjects; ///< hidden objects