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