Salome HOME
Issue #1834: Fix length of lines
[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>> 
41     getSelected(const SelectionPlace& thePlace = Browser) const = 0;
42
43   /// The values are appended to the first parameter list if the first list does not contain 
44   /// an item with the same object
45   /// \param theValues a list of new values
46   /// \param theValuesTo a list, that will be changed
47   static void appendSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>> theValues,
48                              QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValuesTo);
49
50   /// Returns a list of viewer highlited presentations
51   /// \return list of presentations
52   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getHighlighted() const = 0;
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 = 0;
59
60   /**
61    * Returns list of features currently selected in object browser
62    */
63   virtual QObjectPtrList selectedObjects() const = 0;
64
65   /// Set selected objects list
66   virtual void setSelectedObjects( const QObjectPtrList& ) const = 0;
67
68   /**
69    * Returns list of currently selected results
70    */
71   virtual QObjectPtrList selectedPresentations() const = 0;
72
73   //! Returns list of currently selected QModelIndexes
74   virtual QModelIndexList selectedIndexes() const = 0;
75
76   //! Returns list of currently selected AIS objects
77   //! \param theList returning list of selected AIS objects
78   virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const = 0;
79
80   //! Returns list of currently selected QModelIndexes
81   virtual ObjectPtr getSelectableObject(const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
82
83   //! Return the shape from the viewer presentation.
84   //! If the shape is equal to the shape of selected object, it returns an empty shape
85   //! \param thePrs a selected object
86   //! \return a shape
87   MODULEBASE_EXPORT ResultPtr getResult(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
88
89   //! Return the shape from the viewer presentation.
90   //! If the shape is equal to the shape of selected object, it returns an empty shape
91   //! \param thePrs a selected object
92   //! \return a shape
93   MODULEBASE_EXPORT GeomShapePtr getShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
94
95   //! Return the IO from the viewer presentation.
96   //! \param thePrs a selected object
97   //! \return an interactive object
98   virtual MODULEBASE_EXPORT 
99     Handle(AIS_InteractiveObject) getIO(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs) = 0;
100
101   //! Wraps the object list into the viewer prs list
102   //! \param theObjects a list of objects
103   //! \return a list of prs, where only object is not empty
104   static MODULEBASE_EXPORT QList<std::shared_ptr<ModuleBase_ViewerPrs>> getViewerPrs(
105                                                        const QObjectPtrList& theObjects);
106
107   /// Removes selection items where owners have equal vertices. The first
108   /// owner with the qual vertex stays in the list.
109   static MODULEBASE_EXPORT void filterSelectionOnEqualPoints
110                                       (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected);
111 private:
112   /// Find vertex shape build by a Brep owner of the presentation if it exists
113   /// \param thePrs a viewer presentation
114   /// \return GeomAPI wrap of vertex
115   static std::shared_ptr<GeomAPI_Vertex> getPresentationVertex(
116                                                const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
117 };
118
119 #endif