1 // Created on: 2011-10-14
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef __IVTKOCC_SHAPEPICKERALGO_H__
17 #define __IVTKOCC_SHAPEPICKERALGO_H__
19 #include <IVtk_IShapePickerAlgo.hxx>
20 #include <IVtkOCC_ViewerSelector.hxx>
22 class IVtkOCC_ShapePickerAlgo;
23 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo )
25 //! @class IVtkOCC_ShapePickerAlgo
26 //! @brief OCC implementation of 3D shapes picking algorithm.
27 class IVtkOCC_ShapePickerAlgo : public IVtk_IShapePickerAlgo
30 typedef Handle(IVtkOCC_ShapePickerAlgo) Handle;
33 Standard_EXPORT IVtkOCC_ShapePickerAlgo();
36 Standard_EXPORT virtual ~IVtkOCC_ShapePickerAlgo();
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;
43 //! Get number of picked entities.
44 Standard_EXPORT virtual int NbPicked() Standard_OVERRIDE;
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;
52 public: //! @name Set selectable shapes and selection modes
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;
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;
74 public: //! @name Picking methods
76 Standard_EXPORT virtual bool Pick (const double theX, const double theY) Standard_OVERRIDE;
78 Standard_EXPORT virtual bool Pick (const double theXMin,
81 const double theYMax) Standard_OVERRIDE;
83 Standard_EXPORT virtual bool Pick (double** thePolyLine, const int theNbPoints) Standard_OVERRIDE;
85 public: //! @name Obtain picking results
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;
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;
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);
103 //! Return topmost picked 3D point or (Inf, Inf, Inf) if undefined.
104 const gp_Pnt& TopPickedPoint() const { return myTopPickedPoint; }
108 DEFINE_STANDARD_RTTIEXT(IVtkOCC_ShapePickerAlgo,IVtk_IShapePickerAlgo)
112 //! Internal method, resets picked data
115 //! Internal method, extracts picked shapes from ViewerSelector
116 //! and prepares the results in the form of IDs:
117 //! In case of top-level shape(s) selected, only myShapesPicked list is filled.
118 //! Otherwise, mySubShapesPicked map is filled in addition, to provide the information
119 //! about selected sub-shapes grouped by their top-level shapes.
120 //! @return true if some shapes has been picked, and false otherwise
121 //! @see IVtkOCC_ShapePickerAlgo::pick
122 bool processPicked();
124 IVtk_IView::Handle myView;
125 IVtk_ShapeIdList myShapesPicked;
126 IVtk_SubShapeMap mySubShapesPicked;
127 gp_Pnt myTopPickedPoint;
128 Handle(IVtkOCC_ViewerSelector) myViewerSelector;
131 #endif // __IVTKOCC_SHAPEPICKERALGO_H__