0024904: Visualization - Integration of VIS component:
[occt.git] / src / IVtkOCC / IVtkOCC_ShapePickerAlgo.hxx
1 // Created on: 2011-10-14 
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS 
4 // 
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef __IVTKOCC_SHAPEPICKERALGO_H__
17 #define __IVTKOCC_SHAPEPICKERALGO_H__
18
19 #include <IVtk_IShapePickerAlgo.hxx>
20 #include <IVtkOCC_ViewerSelector.hxx>
21
22 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo )
23
24 //! @class IVtkOCC_ShapePickerAlgo 
25 //! @brief OCC implementation of 3D shapes picking algorithm.
26 class IVtkOCC_ShapePickerAlgo : public IVtk_IShapePickerAlgo
27 {
28 public:
29   typedef Handle(IVtkOCC_ShapePickerAlgo) Handle;
30
31   //! Constructor
32   Standard_EXPORT IVtkOCC_ShapePickerAlgo();
33
34   //! Destructor
35   Standard_EXPORT virtual ~IVtkOCC_ShapePickerAlgo();
36
37   //! Sets the picker's view interface.
38   //! The picker uses the view to obtain parameters of
39   //! the 3D view projection.
40   Standard_EXPORT virtual void SetView (const IVtk_IView::Handle& theView);
41
42   //! Informs the picker that some parameters of the view
43   //! has been modified so it is necessary to recompute internal selection data.
44   //! It makes sense to call this method automatically as soon as 
45   //! the underlying VTK object emits its ModifiedEvent.
46   Standard_EXPORT virtual void Modified();
47
48   //! Get number of picked entities.
49   Standard_EXPORT virtual int  NbPicked();
50
51   //! Get activated selection modes for a shape.
52   //! @param [in] theShape a shape with activated selection mode(s)
53   //! @return list of active selection modes
54   Standard_EXPORT virtual IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
55
56 public: //! @name Set selectable shapes and selection modes
57
58   //! Activates/deactivates the given selection mode for the shape.
59   //! If mode == SM_None, the shape becomes non-selectable and 
60   //! is removed from the internal selection data.
61   //! @param [in] theShape Shape for which the selection mode should be activated
62   //! @param [in] theMode Selection mode to be activated
63   //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
64   Standard_EXPORT virtual void SetSelectionMode (const IVtk_IShape::Handle& theShape,
65                                                  const IVtk_SelectionMode theMode,
66                                                  const bool theIsTurnOn = true);
67
68   //! Activates/deactivates the given selection mode for the shape.
69   //! If mode == SM_None, the shape becomes non-selectable and 
70   //! is removed from the internal selection data.
71   //! @param [in] theShapes List of shapes for which the selection mode should be activated
72   //! @param [in] theMode Selection mode to be activated
73   //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
74   Standard_EXPORT virtual void SetSelectionMode (const IVtk_ShapePtrList& theShapes,
75                                                  const IVtk_SelectionMode theMode,
76                                                  const bool theIsTurnOn = true);
77
78 public: //! @name Picking methods
79
80   Standard_EXPORT virtual bool Pick (const double theX, const double theY);
81
82   Standard_EXPORT virtual bool Pick (const double theXMin,
83                                      const double theYMin,
84                                      const double theXMax,
85                                      const double theYMax);
86
87   Standard_EXPORT virtual bool Pick (double** thePolyLine, const int theNbPoints);
88
89 public: //! @name Obtain picking results
90
91   //! @return the list of picked top-level shape IDs,
92   //! in the order of increasing depth (the ID of the shape closest to the eye 
93   //! is the first in the list)
94   Standard_EXPORT virtual const IVtk_ShapeIdList& ShapesPicked() const;
95
96   //! @param [in] theId Top-level shape ID
97   //! @param [out] theShapeList the list of picked sub-shape IDs for the given top-level shape ID,
98   //! in the order of increasing depth (the ID of the sub-shape closest to the eye 
99   //! is the first in the list)
100   Standard_EXPORT virtual void SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const;
101
102 public:
103
104   DEFINE_STANDARD_RTTI(IVtkOCC_ShapePickerAlgo)
105
106 private:
107
108   //! Internal method, resets picked data
109   void clearPicked();
110
111   //! Internal method, extracts picked shapes from ViewerSelector
112   //! and prepares the results in the form of IDs:
113   //! In case of top-level shape(s) selected, only myShapesPicked list is filled.
114   //! Otherwise, mySubShapesPicked map is filled in addition, to provide the information
115   //! about selected sub-shapes grouped by their top-level shapes.
116   //! @return true if some shapes has been picked, and false otherwise
117   //! @see IVtkOCC_ShapePickerAlgo::pick
118   bool processPicked();
119
120   IVtk_IView::Handle             myView;
121   IVtk_ShapeIdList               myShapesPicked;
122   IVtk_SubShapeMap               mySubShapesPicked;
123   Handle(IVtkOCC_ViewerSelector) myViewerSelector;
124 };
125
126 #endif // __IVTKOCC_SHAPEPICKERALGO_H__