1 // Copyright (C) 2014-2020 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 <ModuleBase_ActionType.h>
26 #include <ModuleBase_Definitions.h>
27 #include <ModuleBase_ViewerPrs.h>
28 #include <ModuleBase_ResultPrs.h>
30 #include <ModelAPI_Object.h>
31 #include <ModelAPI_ResultGroup.h>
32 #include <ModelAPI_Feature.h>
34 #include <GeomAPI_AISObject.h>
36 #include <SelectMgr_ListOfFilter.hxx>
37 #include <TopoDS_Shape.hxx>
39 #include <QDockWidget>
45 class AIS_InteractiveObject;
47 class GeomAPI_AISObject;
50 class ModuleBase_ListView;
58 * A Hide Faces panel for making it possible to hide faces in the 3D view.
59 * The panel has multi-selector filled by faces elements. When the control is active
60 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
61 * after selection and the corresponding item is appeared in the multi selector.
63 * In order to redisplay a face, it is enough to click delete on the name of this face
64 * in the multiselector.
65 * When the panel is opened, the multiselector is empty.
66 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
67 * The default position by of this dockable window is to the right of the view (in SALOME mode).
68 * If no feature is processed (in neutral point), this panel can be activated too.
69 * On feature edition start or finish, movement of the history line, undo/redo and other
70 * modification of the model, the multiselector is emptied.
72 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
77 /// \param theParent is a parent of the property panel
78 XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop);
81 /// Clear content of list widget
82 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
83 virtual void reset(const bool isToFlushRedisplay);
85 /// Returns whether faces panel contains elements
86 /// \return boolean value
89 /// Fills container with the panel selection mode: FACE
90 // \param theModes [out] a container of modes
91 void selectionModes(QIntList& theModes);
93 /// Appends into container of workshop selection filters
94 /// \param [out] selection filters
95 void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
97 /// Returns whether the panel is active or not
98 bool isActivePanel() const { return myIsActive; }
100 /// Stores the state if panel is active and highlight the panel in an active color
101 /// \param theIsActive state whether the panel should be activated or deactivated
102 void setActivePanel(const bool theIsActive);
104 /// Returns true if the object is in internal container of hidden objects by this panel
105 /// \param theObject a checked object
106 /// \return boolean value
107 bool isObjectHiddenByPanel(const ObjectPtr& theObject) const
108 { return myHiddenObjects.find(theObject) != myHiddenObjects.end(); }
110 /// Removed faces of the objects from the panel
111 /// \param container of objects
112 void restoreObjects(const std::set<ObjectPtr >& theHiddenObjects);
114 /// Returns true if the event is processed. The default implementation is empty, returns false.
115 virtual bool processAction(ModuleBase_ActionType theActionType);
117 /// Append selected item in the list and customize presentations to hide faces
118 void processSelection();
120 /// Deletes item in a list of elements
121 /// \return whether the delete action is processed
122 bool processDelete();
124 /// Delete last(s) item(s) added since the recent activation of the faces panel
127 /// Processing focus in/out for the faces control
128 /// \param theObject source object of event
129 /// \param theEvent an event
130 virtual bool eventFilter(QObject* theObject, QEvent *theEvent);
132 XGUI_Workshop* workshop() const { return myWorkshop; }
135 /// Slot called on an object erase
136 void onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS);
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<ObjectPtr>& theObjects);
156 /// Container of objects participating in the panel, it is filled by internal container
157 /// \param theItems container of selected values
158 /// \param theObjects [out] container of objects
159 static void updateProcessedObjects(QMap<int, ModuleBase_ViewerPrsPtr> theItems,
160 std::set<ObjectPtr>& theObjects);
162 /// Returns maps of shapes and presentations. If object is a body result then it returns
163 /// its ruslts. If it is a group then it returns result of shapes included into the gropup
164 /// The function doesn't clear content of input maps.
165 /// \param thePrs a selected presintation
166 /// \param theObjectsToShapes map of objects to shapes list
167 /// \param theObjectToPrs map of objects to presentations
168 void getObjectsMapFromResult(ResultGroupPtr theResGroup, FeaturePtr theGroupFeature,
169 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectsToShapes,
170 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
172 void getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
173 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
174 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
176 /// Returns true if transparency choice is checked
177 /// \return boolean value
178 bool useTransparency() const;
180 double transparency() const;
182 void removeItems(std::set<int> theIds);
185 /// Deletes element in list of items
188 /// Upates hidden faces to be hidden or transparent
189 void onTransparencyChanged();
191 /// Closes faces panel restore all hidden faces by calling reset()
194 /// Flushes redisplay event and perform update of object browser icons
195 /// (objects might be hidden/shown)
196 void flushRedisplay() const;
200 QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
201 ModuleBase_ListView* myListView; ///< list control of processed faces
202 XGUI_Workshop* myWorkshop; ///< workshop
204 bool myIsActive; ///< current state about the panel is active
205 int myLastItemIndex; ///< last index to be used in the map of items for the next added item
206 std::vector<int> myUndoList; ///< indexes of items for undo
208 QMap<int, ModuleBase_ViewerPrsPtr> myItems; ///< selected face items
209 std::set<ObjectPtr > myItemObjects; ///< cached objects of myItems
210 std::set<ObjectPtr > myHiddenObjects; ///< hidden objects
211 std::set<ObjectPtr > myHiddenGroups; ///< hidden objects