Salome HOME
Merge branch 'BR_EDF_2018_Lot1'
[modules/shaper.git] / src / XGUI / XGUI_Selection.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_Selection_H
22 #define XGUI_Selection_H
23
24 #include "XGUI.h"
25
26 #include <ModuleBase_Definitions.h>
27 #include <ModuleBase_ISelection.h>
28
29 #include <QModelIndexList>
30 #include <AIS_ListOfInteractive.hxx>
31 #include <NCollection_List.hxx>
32 #include <TopoDS_Shape.hxx>
33
34 #include <SelectMgr_IndexedMapOfOwner.hxx>
35
36 class XGUI_Workshop;
37 class SelectMgr_EntityOwner;
38 class ModuleBase_ViewerPrs;
39
40 /// \ingroup GUI
41 /// Implementation of \ref ModuleBase_ISelection interface.
42 class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
43 {
44  public:
45    /// Constructor
46    /// \param theWorkshop reference to workshop instance
47   XGUI_Selection(XGUI_Workshop* theWorkshop);
48
49   /// Returns a list of viewer selected presentations
50   /// \return list of presentations
51   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>>
52     getSelected(const SelectionPlace& thePlace = Browser) const;
53
54   /// Fills the viewer presentation parameters by the parameters from the owner
55   /// \param thePrs a container for selection
56   /// \param theOwner a selection owner
57   virtual void fillPresentation(std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
58                                 const Handle(SelectMgr_EntityOwner)& theOwner) const;
59
60   /// Returns a list of viewer highlited presentations
61   /// \return list of presentations
62   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getHighlighted() const;
63
64   /// Returns list of currently selected objects in object browser
65   virtual QObjectPtrList selectedObjects() const;
66
67   /// Returns list of currently selected results
68   virtual QObjectPtrList selectedPresentations() const;
69
70   /// Returns list of currently selected QModelIndexes
71   virtual QModelIndexList selectedIndexes() const;
72
73   /// Returns list of currently selected owners
74   /// \return list of owners
75   void selectedOwners(SelectMgr_IndexedMapOfOwner& theSelectedOwners) const;
76
77   /// Returns a list of selection entity owners of the interactive object
78   /// It depends on the modes, in which the object is activated in the context
79   /// \param theObject an object
80   /// \param theOwners a map of entity owners
81   void entityOwners(const Handle(AIS_InteractiveObject)& theObject,
82                     SelectMgr_IndexedMapOfOwner& theOwners) const;
83
84   /// Return the IO from the viewer presentation.
85   /// \param thePrs a selected object
86   /// \return an interactive object
87   virtual Handle(AIS_InteractiveObject) getIO(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
88
89 protected:
90   /// Return a selectable object by the entity owner. It founds AIS object in the viewer
91   /// and returns the corresponded object
92   /// \param theOwner an entity owner
93   /// \return a found object or NULL
94   ObjectPtr getSelectableObject(const Handle(SelectMgr_EntityOwner)& theOwner) const;
95
96   /// Fills the list of presentations by objects selected in the viewer.
97   /// \param thePresentations an output list of presentation
98   void getSelectedInViewer(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& thePresentations) const;
99
100   /// Fills the list of presentations by objects selected in the object browser.
101   /// ViewerPrs contains only object parameter not empty.
102   /// If the given list of presentations already has a viewer presentation with the same object
103   /// as selected in the browser, a new item is not appended to the list of presentations.
104   /// \param thePresentations an output list of presentation
105   void getSelectedInBrowser(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& thePresentations) const;
106
107   /// Generates a vertex or edge by the give IO if it is an AIS created on trihedron
108   /// \param theIO a selected object
109   /// \return created shape or empty shape
110 #ifdef BEFORE_TRIHEDRON_PATCH
111   TopoDS_Shape findAxisShape(Handle(AIS_InteractiveObject) theIO) const;
112 #endif
113
114 private:
115   XGUI_Workshop* myWorkshop; ///< current workshop
116 };
117
118 #endif