Salome HOME
#1658 New widget supporting nested option buttons
[modules/shaper.git] / src / ModuleBase / ModuleBase_ISelection.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_ISelection.h
4 // Created:     2 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #ifndef ModuleBase_ISelection_H
8 #define ModuleBase_ISelection_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_Definitions.h"
12
13 #include <ModelAPI_Result.h>
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_Vertex.h>
16
17 #include <QModelIndexList>
18 #include <AIS_ListOfInteractive.hxx>
19 #include <NCollection_List.hxx>
20 #include <TopoDS_Shape.hxx>
21
22 #include <QList>
23
24 class ModuleBase_ViewerPrs;
25 class Handle_SelectMgr_EntityOwner;
26
27 /**
28 * \ingroup GUI
29 * A class which provides access to selection.
30 * A selection can be obtained as from a viewer as from Object browser in various forms
31 */
32 class ModuleBase_ISelection
33 {
34  public:
35    /// Types of the selection place, where the selection is obtained
36    enum SelectionPlace { Browser, Viewer, AllControls };
37
38   /// Returns a list of viewer selected presentations
39   /// \return list of presentations
40   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getSelected(const SelectionPlace& thePlace = Browser) const = 0;
41
42   /// The values are appended to the first parameter list if the first list does not contain an item
43   /// with the same object
44   /// \param theValues a list of new values
45   /// \param theValuesTo a list, that will be changed
46   static void appendSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>> theValues,
47                              QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValuesTo);
48
49   /// Returns a list of viewer highlited presentations
50   /// \return list of presentations
51   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getHighlighted() const = 0;
52
53   /// Fills the viewer presentation parameters by the parameters from the owner
54   /// \param thePrs a container for selection
55   /// \param theOwner a selection owner
56   virtual void fillPresentation(std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
57                                 const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
58
59   /**
60    * Returns list of features currently selected in object browser
61    */
62   virtual QObjectPtrList selectedObjects() const = 0;
63
64   /// Set selected objects list
65   virtual void setSelectedObjects( const QObjectPtrList& ) const = 0;
66
67   /**
68    * Returns list of currently selected results
69    */
70   virtual QObjectPtrList selectedPresentations() const = 0;
71
72   //! Returns list of currently selected QModelIndexes
73   virtual QModelIndexList selectedIndexes() const = 0;
74
75   //! Returns list of currently selected AIS objects
76   //! \param theList returning list of selected AIS objects
77   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
78
79   //! Returns list of currently selected QModelIndexes
80   virtual ObjectPtr getSelectableObject(const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
81
82   //! Return the shape from the viewer presentation.
83   //! If the shape is equal to the shape of selected object, it returns an empty shape
84   //! \param thePrs a selected object
85   //! \return a shape
86   MODULEBASE_EXPORT ResultPtr getResult(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
87
88   //! Return the shape from the viewer presentation.
89   //! If the shape is equal to the shape of selected object, it returns an empty shape
90   //! \param thePrs a selected object
91   //! \return a shape
92   MODULEBASE_EXPORT GeomShapePtr getShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
93
94   //! Return the IO from the viewer presentation.
95   //! \param thePrs a selected object
96   //! \return an interactive object
97   virtual MODULEBASE_EXPORT Handle(AIS_InteractiveObject) getIO(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
98
99   //! Wraps the object list into the viewer prs list
100   //! \param theObjects a list of objects
101   //! \return a list of prs, where only object is not empty
102   static MODULEBASE_EXPORT QList<std::shared_ptr<ModuleBase_ViewerPrs>> getViewerPrs(
103                                                        const QObjectPtrList& theObjects);
104
105   /// Removes selection items where owners have equal vertices. The first
106   /// owner with the qual vertex stays in the list.
107   static MODULEBASE_EXPORT void filterSelectionOnEqualPoints
108                                               (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected);
109 private:
110   /// Find vertex shape build by a Brep owner of the presentation if it exists
111   /// \param thePrs a viewer presentation
112   /// \return GeomAPI wrap of vertex
113   static std::shared_ptr<GeomAPI_Vertex> getPresentationVertex(
114                                                const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
115 };
116
117 #endif