Salome HOME
Update SketchPlugin_Projection feature (issue #1459)
[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
16 #include <QModelIndexList>
17 #include <AIS_ListOfInteractive.hxx>
18 #include <NCollection_List.hxx>
19 #include <TopoDS_Shape.hxx>
20
21 #include <QList>
22
23 class ModuleBase_ViewerPrs;
24 class Handle_SelectMgr_EntityOwner;
25
26 /**
27 * \ingroup GUI
28 * A class which provides access to selection.
29 * A selection can be obtained as from a viewer as from Object browser in various forms
30 */
31 class ModuleBase_ISelection
32 {
33  public:
34    /// Types of the selection place, where the selection is obtained
35    enum SelectionPlace { Browser, Viewer, AllControls };
36
37   /// Returns a list of viewer selected presentations
38   /// \return list of presentations
39   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getSelected(const SelectionPlace& thePlace = Browser) const = 0;
40
41   /// The values are appended to the first parameter list if the first list does not contain an item
42   /// with the same object
43   /// \param theValues a list of new values
44   /// \param theValuesTo a list, that will be changed
45   static void appendSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>> theValues,
46                              QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValuesTo);
47
48   /// Returns a list of viewer highlited presentations
49   /// \return list of presentations
50   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getHighlighted() const = 0;
51
52   /// Fills the viewer presentation parameters by the parameters from the owner
53   /// \param thePrs a container for selection
54   /// \param theOwner a selection owner
55   virtual void fillPresentation(std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
56                                 const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
57
58   /**
59    * Returns list of features currently selected in object browser
60    */
61   virtual QObjectPtrList selectedObjects() const = 0;
62
63   /// Set selected objects list
64   virtual void setSelectedObjects( const QObjectPtrList& ) const = 0;
65
66   /**
67    * Returns list of currently selected results
68    */
69   virtual QObjectPtrList selectedPresentations() const = 0;
70
71   //! Returns list of currently selected QModelIndexes
72   virtual QModelIndexList selectedIndexes() const = 0;
73
74   //! Returns list of currently selected AIS objects
75   //! \param theList returning list of selected AIS objects
76   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
77
78   //! Returns list of currently selected QModelIndexes
79   virtual ObjectPtr getSelectableObject(const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
80
81   //! Return the shape from the viewer presentation.
82   //! If the shape is equal to the shape of selected object, it returns an empty shape
83   //! \param thePrs a selected object
84   //! \return a shape
85   MODULEBASE_EXPORT ResultPtr getResult(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
86
87   //! Return the shape from the viewer presentation.
88   //! If the shape is equal to the shape of selected object, it returns an empty shape
89   //! \param thePrs a selected object
90   //! \return a shape
91   MODULEBASE_EXPORT GeomShapePtr getShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
92
93   //! Return the IO from the viewer presentation.
94   //! \param thePrs a selected object
95   //! \return an interactive object
96   virtual MODULEBASE_EXPORT Handle(AIS_InteractiveObject) getIO(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
97
98   //! Wraps the object list into the viewer prs list
99   //! \param theObjects a list of objects
100   //! \return a list of prs, where only object is not empty
101   static MODULEBASE_EXPORT QList<std::shared_ptr<ModuleBase_ViewerPrs>> getViewerPrs(
102                                                        const QObjectPtrList& theObjects);
103
104   /// Removes selection items where owners have equal vertices. The first
105   /// owner with the qual vertex stays in the list.
106   static MODULEBASE_EXPORT void filterSelectionOnEqualPoints
107                                               (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected);
108 private:
109   /// Returns true if the presentations have an owner with a vertex and these vertices are equal.
110   /// \param thePrs1 the first viewer selected presentation
111   /// \param thePrs2 the second viewer selected presentation
112   static bool isEqualVertices(const std::shared_ptr<ModuleBase_ViewerPrs> thePrs1,
113                               const std::shared_ptr<ModuleBase_ViewerPrs> thePrs2);
114 };
115
116 #endif