Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / XGUI / XGUI_SelectionMgr.h
1 // Copyright (C) 2014-2017  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<mailto: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 <QObject>
27 #include <QModelIndexList>
28
29 #include <AIS_ListOfInteractive.hxx>
30 #include <NCollection_List.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <SelectMgr_IndexedMapOfOwner.hxx>
33
34 class XGUI_Workshop;
35 class XGUI_ObjectsBrowser;
36 class XGUI_Selection;
37
38 /**\class XGUI_SelectionMgr
39  * \ingroup GUI
40  * \brief Selection manager. Provides selection event on selection in 
41  * Object Browser and Viewer
42  */
43 class XGUI_EXPORT XGUI_SelectionMgr : public QObject
44 {
45 Q_OBJECT
46  public:
47    /// Constructor
48    /// \param theParent a parent workshop
49   XGUI_SelectionMgr(XGUI_Workshop* theParent);
50   virtual ~XGUI_SelectionMgr();
51
52   /// Returns current selection
53   XGUI_Selection* selection() const
54   {
55     return mySelection;
56   }
57
58   //! Connects the manager to all viewers accessible by Workshop
59   void connectViewers();
60
61   //! Selects the owners in the context.
62   //! \param theSelectedOwners a container of owners
63   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
64   void setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
65                          bool isUpdateViewer);
66
67   //! Clears selection in Viewer and object Browser
68   void clearSelection();
69
70   //! Sets values selected in both, ObjectBrowser and V3d viewer
71   //! Selection is not synchronized between these controls.
72   //! \param theValues a container of values to be selected.
73   void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs> >& theValues);
74
75   /// Updates selection, which are depend on the selection in the given place
76   /// \param thePlace a widget where selection has happened.
77   void updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace);
78
79 signals:
80   //! Emited when selection in a one of viewers was changed
81   void selectionChanged();
82
83  public slots:
84    /// Reaction on selectio0n in Object browser
85   void onObjectBrowserSelection();
86
87    /// Reaction on selectio0n in Viewer
88   void onViewerSelection();
89
90 private:
91   /// Interates through the values to prepare container of objects that may be selected in OB
92   /// \param theValues selection information
93   /// \param theObjecs an output container
94   void convertToObjectBrowserSelection(
95        const QList<std::shared_ptr<ModuleBase_ViewerPrs> >& theValues, QObjectPtrList& theObjects);
96
97 private:
98    /// Reference to workshop
99   XGUI_Workshop* myWorkshop;
100
101   /// Current selection object
102   XGUI_Selection* mySelection;
103 };
104
105 #endif