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