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 <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 <SelectMgr_ListOfFilter.hxx>
35 #include <TopoDS_Shape.hxx>
37 #include <QDockWidget>
43 class AIS_InteractiveObject;
45 class GeomAPI_AISObject;
48 class ModuleBase_ListView;
56 * A Hide Faces panel for making it possible to hide faces in the 3D view.
57 * The panel has multi-selector filled by faces elements. When the control is active
58 * it is possible to select faces in the viewer. The selected faces are hidden/transparent
59 * after selection and the corresponding item is appeared in the multi selector.
61 * In order to redisplay a face, it is enough to click delete on the name of this face
62 * in the multiselector.
63 * When the panel is opened, the multiselector is empty.
64 * When the panel is closed, the multiselector is emptied and the faces are displayed again.
65 * The default position by of this dockable window is to the right of the view (in SALOME mode).
66 * If no feature is processed (in neutral point), this panel can be activated too.
67 * On feature edition start or finish, movement of the history line, undo/redo and other
68 * modification of the model, the multiselector is emptied.
70 class XGUI_EXPORT XGUI_FacesPanel : public QDockWidget
75 /// \param theParent is a parent of the property panel
76 XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop);
79 /// Clear content of list widget
80 /// \param isToFlushRedisplay flag if redisplay should be flushed immediatelly
81 virtual void reset(const bool isToFlushRedisplay);
83 /// Returns whether faces panel contains elements
84 /// \return boolean value
87 /// Fills container with the panel selection mode: FACE
88 // \param theModes [out] a container of modes
89 void selectionModes(QIntList& theModes);
91 /// Appends into container of workshop selection filters
92 /// \param [out] selection filters
93 void selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters);
95 /// Returns whether the panel is active or not
96 bool isActivePanel() const { return myIsActive; }
98 /// Stores the state if panel is active and highlight the panel in an active color
99 /// \param theIsActive state whether the panel should be activated or deactivated
100 void setActivePanel(const bool theIsActive);
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 XGUI_Workshop* workshop() const { return myWorkshop; }
131 /// Reimplementation to emit a signal about the panel close
132 virtual void closeEvent(QCloseEvent* theEvent);
135 /// Signal about activating pane
137 /// Signal about deactivating pane
139 /// Signal is emitted by the top widget cross button click
143 /// Redisplay objects.
144 /// \param theObjects container of objects
145 /// \return true if some of objects was redisplayed
146 static bool redisplayObjects(const std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
148 /// Container of objects participating in the panel, it is filled by internal container
149 /// \param theItems container of selected values
150 /// \param theObjects [out] container of objects
151 static void updateProcessedObjects(QMap<int, std::shared_ptr<ModuleBase_ViewerPrs> > theItems,
152 std::set<std::shared_ptr<ModelAPI_Object> >& theObjects);
154 /// Returns maps of shapes and presentations. If object is a body result then it returns
155 /// its ruslts. If it is a group then it returns result of shapes included into the gropup
156 /// The function doesn't clear content of input maps.
157 /// \param thePrs a selected presintation
158 /// \param theObjectsToShapes map of objects to shapes list
159 /// \param theObjectToPrs map of objects to presentations
160 void getObjectsMapFromResult(ResultGroupPtr theResGroup, FeaturePtr theGroupFeature,
161 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectsToShapes,
162 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
164 void getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
165 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
166 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs);
168 /// Returns true if transparency choice is checked
169 /// \return boolean value
170 bool useTransparency() const;
172 double transparency() const;
175 /// Deletes element in list of items
178 /// Upates hidden faces to be hidden or transparent
179 void onTransparencyChanged();
181 /// Closes faces panel restore all hidden faces by calling reset()
185 /// Flushes redisplay event and perform update of object browser icons
186 /// (objects might be hidden/shown)
187 void flushRedisplay() const;
190 QCheckBox* myHiddenOrTransparent; ///< if checked - transparent, else hidden
191 ModuleBase_ListView* myListView; ///< list control of processed faces
192 XGUI_Workshop* 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, ModuleBase_ViewerPrsPtr> 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
200 std::set<std::shared_ptr<ModelAPI_Object> > myHiddenGroups; ///< hidden objects