0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[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 class IVtkOCC_ShapePickerAlgo;
23 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo )
24
25 //! @class IVtkOCC_ShapePickerAlgo 
26 //! @brief OCC implementation of 3D shapes picking algorithm.
27 class IVtkOCC_ShapePickerAlgo : public IVtk_IShapePickerAlgo
28 {
29 public:
30   typedef Handle(IVtkOCC_ShapePickerAlgo) Handle;
31
32   //! Constructor
33   Standard_EXPORT IVtkOCC_ShapePickerAlgo();
34
35   //! Destructor
36   Standard_EXPORT virtual ~IVtkOCC_ShapePickerAlgo();
37
38   //! Sets the picker's view interface.
39   //! The picker uses the view to obtain parameters of
40   //! the 3D view projection.
41   Standard_EXPORT virtual void SetView (const IVtk_IView::Handle& theView) Standard_OVERRIDE;
42
43   //! Get number of picked entities.
44   Standard_EXPORT virtual int  NbPicked() Standard_OVERRIDE;
45
46   //! Get activated selection modes for a shape.
47   //! @param [in] theShape a shape with activated selection mode(s)
48   //! @return list of active selection modes
49   Standard_EXPORT virtual IVtk_SelectionModeList 
50     GetSelectionModes (const IVtk_IShape::Handle& theShape) const Standard_OVERRIDE;
51
52 public: //! @name Set selectable shapes and selection modes
53
54   //! Activates/deactivates the given selection mode for the shape.
55   //! If mode == SM_None, the shape becomes non-selectable and 
56   //! is removed from the internal selection data.
57   //! @param [in] theShape Shape for which the selection mode should be activated
58   //! @param [in] theMode Selection mode to be activated
59   //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
60   Standard_EXPORT virtual void SetSelectionMode (const IVtk_IShape::Handle& theShape,
61                                                  const IVtk_SelectionMode theMode,
62                                                  const bool theIsTurnOn = true) Standard_OVERRIDE;
63
64   //! Activates/deactivates the given selection mode for the shape.
65   //! If mode == SM_None, the shape becomes non-selectable and 
66   //! is removed from the internal selection data.
67   //! @param [in] theShapes List of shapes for which the selection mode should be activated
68   //! @param [in] theMode Selection mode to be activated
69   //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
70   Standard_EXPORT virtual void SetSelectionMode (const IVtk_ShapePtrList& theShapes,
71                                                  const IVtk_SelectionMode theMode,
72                                                  const bool theIsTurnOn = true) Standard_OVERRIDE;
73
74 public: //! @name Picking methods
75
76   Standard_EXPORT virtual bool Pick (const double theX, const double theY) Standard_OVERRIDE;
77
78   Standard_EXPORT virtual bool Pick (const double theXMin,
79                                      const double theYMin,
80                                      const double theXMax,
81                                      const double theYMax) Standard_OVERRIDE;
82
83   Standard_EXPORT virtual bool Pick (double** thePolyLine, const int theNbPoints) Standard_OVERRIDE;
84
85 public: //! @name Obtain picking results
86
87   //! @return the list of picked top-level shape IDs,
88   //! in the order of increasing depth (the ID of the shape closest to the eye 
89   //! is the first in the list)
90   Standard_EXPORT virtual const IVtk_ShapeIdList& ShapesPicked() const Standard_OVERRIDE;
91
92   //! @param [in] theId Top-level shape ID
93   //! @param [out] theShapeList the list of picked sub-shape IDs for the given top-level shape ID,
94   //! in the order of increasing depth (the ID of the sub-shape closest to the eye 
95   //! is the first in the list)
96   Standard_EXPORT virtual void 
97     SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const Standard_OVERRIDE;
98
99   //! Remove selectable object from the picker (from internal maps).
100   //! @param [in] theShape the selectable shape
101   Standard_EXPORT virtual void RemoveSelectableObject(const IVtk_IShape::Handle& theShape);
102
103 public:
104
105   DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
106
107 private:
108
109   //! Internal method, resets picked data
110   void clearPicked();
111
112   //! Internal method, extracts picked shapes from ViewerSelector
113   //! and prepares the results in the form of IDs:
114   //! In case of top-level shape(s) selected, only myShapesPicked list is filled.
115   //! Otherwise, mySubShapesPicked map is filled in addition, to provide the information
116   //! about selected sub-shapes grouped by their top-level shapes.
117   //! @return true if some shapes has been picked, and false otherwise
118   //! @see IVtkOCC_ShapePickerAlgo::pick
119   bool processPicked();
120
121   IVtk_IView::Handle             myView;
122   IVtk_ShapeIdList               myShapesPicked;
123   IVtk_SubShapeMap               mySubShapesPicked;
124   Handle(IVtkOCC_ViewerSelector) myViewerSelector;
125 };
126
127 #endif // __IVTKOCC_SHAPEPICKERALGO_H__