Salome HOME
Merge remote-tracking branch 'remotes/origin/HigherLevelObjectsHistory'
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.h
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef XGUI_SelectionMgr_H
21 #define XGUI_SelectionMgr_H
22
23 #include "XGUI.h"
24 #include <ModuleBase_Definitions.h>
25 #include <ModuleBase_ISelection.h>
26 #include <ModelAPI_Feature.h>
27 #include <QObject>
28 #include <QModelIndexList>
29
30 #include <AIS_InteractiveObject.hxx>
31 #include <AIS_ListOfInteractive.hxx>
32 #include <NCollection_List.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <SelectMgr_IndexedMapOfOwner.hxx>
35
36 class XGUI_Workshop;
37 class XGUI_ObjectsBrowser;
38 class XGUI_Selection;
39
40 /**\class XGUI_SelectionMgr
41  * \ingroup GUI
42  * \brief Selection manager. Provides selection event on selection in 
43  * Object Browser and Viewer
44  */
45 class XGUI_EXPORT XGUI_SelectionMgr : public QObject
46 {
47 Q_OBJECT
48  public:
49    /// Constructor
50    /// \param theParent a parent workshop
51   XGUI_SelectionMgr(XGUI_Workshop* theParent);
52   virtual ~XGUI_SelectionMgr();
53
54   /// Returns current selection
55   XGUI_Selection* selection() const
56   {
57     return mySelection;
58   }
59
60   //! Connects the manager to all viewers accessible by Workshop
61   void connectViewers();
62
63   //! Selects the owners in the context.
64   //! \param theSelectedOwners a container of owners
65   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
66   void setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
67                          bool isUpdateViewer);
68
69   //! Clears selection in Viewer and object Browser
70   void clearSelection();
71
72   //! Sets values selected in both, ObjectBrowser and V3d viewer
73   //! Selection is not synchronized between these controls.
74   //! \param theValues a container of values to be selected.
75   void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs> >& theValues);
76
77   //! Find all selected owners of the object and remove the owners from selection
78   //! \param theObject an interactive object
79   void deselectPresentation(const Handle(AIS_InteractiveObject) theObject);
80
81   /// Updates selection, which are depend on the selection in the given place
82   /// \param thePlace a widget where selection has happened.
83   void updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace);
84
85   /// Returns list of selected features (ignores other selected objects and parts)
86   std::list<FeaturePtr> getSelectedFeatures();
87
88 signals:
89   //! Emited when selection in a one of viewers was changed
90   void selectionChanged();
91
92  public slots:
93    /// Reaction on selectio0n in Object browser
94   void onObjectBrowserSelection();
95
96    /// Reaction on selectio0n in Viewer
97   void onViewerSelection();
98
99 private:
100   /// Interates through the values to prepare container of objects that may be selected in OB
101   /// \param theValues selection information
102   /// \param theObjecs an output container
103   void convertToObjectBrowserSelection(
104        const QList<std::shared_ptr<ModuleBase_ViewerPrs> >& theValues, QObjectPtrList& theObjects);
105
106   QList<TopoDS_Shape> findAllShapes(const ResultPtr& theResult) const;
107
108 private:
109    /// Reference to workshop
110   XGUI_Workshop* myWorkshop;
111
112   /// Current selection object
113   XGUI_Selection* mySelection;
114 };
115
116 #endif