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>
30 #include <ModuleBase_ResultPrs.h>
32 #include <SelectMgr_ListOfFilter.hxx>
33 #include <TopoDS_Shape.hxx>
35 #include <QDockWidget>
41 class AIS_InteractiveObject;
43 class GeomAPI_AISObject;
46 class ModuleBase_ListView;
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.
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.
68 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
73 /// \param theParent is a parent of the property panel
74 XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop);
77 /// Clear content of list widget
78 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
79 virtual void reset(const bool isToFlushRedisplay);
81 /// Returns whether faces panel contains elements
82 /// \return boolean value
85 /// Fills container with the panel selection mode: FACE
86 // \param theModes [out] a container of modes
87 void selectionModes(QIntList& theModes);
89 /// Appends into container of workshop selection filters
90 /// \param [out] selection filters
91 void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
93 /// Returns whether the panel is active or not
94 bool isActivePanel() const { return myIsActive; }
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);
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(); }
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);
110 /// Returns true if the event is processed. The default implementation is empty, returns false.
111 virtual bool processAction(ModuleBase_ActionType theActionType);
113 /// Append selected item in the list and customize presentations to hide faces
114 void processSelection();
116 /// Deletes item in a list of elements
117 /// \return whether the delete action is processed
118 bool processDelete();
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);
125 XGUI_Workshop* workshop() const { return myWorkshop; }
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 /// 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);
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);
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);
162 /// Returns true if transparency choice is checked
163 /// \return boolean value
164 bool useTransparency() const;
166 double transparency() const;
169 /// Deletes element in list of items
172 /// Upates hidden faces to be hidden or transparent
173 void onTransparencyChanged();
175 /// Closes faces panel restore all hidden faces by calling reset()
179 /// Flushes redisplay event and perform update of object browser icons
180 /// (objects might be hidden/shown)
181 void flushRedisplay() const;
184 QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
185 ModuleBase_ListView* myListView; ///< list control of processed faces
186 XGUI_Workshop* myWorkshop; ///< workshop
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
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