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 DEFINE_STANDARD_HANDLE( IVtkOCC_ShapePickerAlgo, IVtk_IShapePickerAlgo )
24 //! @class IVtkOCC_ShapePickerAlgo
25 //! @brief OCC implementation of 3D shapes picking algorithm.
26 class IVtkOCC_ShapePickerAlgo : public IVtk_IShapePickerAlgo
29 typedef Handle(IVtkOCC_ShapePickerAlgo) Handle;
32 Standard_EXPORT IVtkOCC_ShapePickerAlgo();
35 Standard_EXPORT virtual ~IVtkOCC_ShapePickerAlgo();
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);
42 //! Get number of picked entities.
43 Standard_EXPORT virtual int NbPicked();
45 //! Get activated selection modes for a shape.
46 //! @param [in] theShape a shape with activated selection mode(s)
47 //! @return list of active selection modes
48 Standard_EXPORT virtual IVtk_SelectionModeList GetSelectionModes (const IVtk_IShape::Handle& theShape) const;
50 public: //! @name Set selectable shapes and selection modes
52 //! Activates/deactivates the given selection mode for the shape.
53 //! If mode == SM_None, the shape becomes non-selectable and
54 //! is removed from the internal selection data.
55 //! @param [in] theShape Shape for which the selection mode should be activated
56 //! @param [in] theMode Selection mode to be activated
57 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
58 Standard_EXPORT virtual void SetSelectionMode (const IVtk_IShape::Handle& theShape,
59 const IVtk_SelectionMode theMode,
60 const bool theIsTurnOn = true);
62 //! Activates/deactivates the given selection mode for the shape.
63 //! If mode == SM_None, the shape becomes non-selectable and
64 //! is removed from the internal selection data.
65 //! @param [in] theShapes List of shapes for which the selection mode should be activated
66 //! @param [in] theMode Selection mode to be activated
67 //! @param [in] theIsTurnOn Flag to turn on/off the selection mode
68 Standard_EXPORT virtual void SetSelectionMode (const IVtk_ShapePtrList& theShapes,
69 const IVtk_SelectionMode theMode,
70 const bool theIsTurnOn = true);
72 public: //! @name Picking methods
74 Standard_EXPORT virtual bool Pick (const double theX, const double theY);
76 Standard_EXPORT virtual bool Pick (const double theXMin,
79 const double theYMax);
81 Standard_EXPORT virtual bool Pick (double** thePolyLine, const int theNbPoints);
83 public: //! @name Obtain picking results
85 //! @return the list of picked top-level shape IDs,
86 //! in the order of increasing depth (the ID of the shape closest to the eye
87 //! is the first in the list)
88 Standard_EXPORT virtual const IVtk_ShapeIdList& ShapesPicked() const;
90 //! @param [in] theId Top-level shape ID
91 //! @param [out] theShapeList the list of picked sub-shape IDs for the given top-level shape ID,
92 //! in the order of increasing depth (the ID of the sub-shape closest to the eye
93 //! is the first in the list)
94 Standard_EXPORT virtual void SubShapesPicked (const IVtk_IdType theId, IVtk_ShapeIdList& theShapeList) const;
98 DEFINE_STANDARD_RTTI(IVtkOCC_ShapePickerAlgo)
102 //! Internal method, resets picked data
105 //! Internal method, extracts picked shapes from ViewerSelector
106 //! and prepares the results in the form of IDs:
107 //! In case of top-level shape(s) selected, only myShapesPicked list is filled.
108 //! Otherwise, mySubShapesPicked map is filled in addition, to provide the information
109 //! about selected sub-shapes grouped by their top-level shapes.
110 //! @return true if some shapes has been picked, and false otherwise
111 //! @see IVtkOCC_ShapePickerAlgo::pick
112 bool processPicked();
114 IVtk_IView::Handle myView;
115 IVtk_ShapeIdList myShapesPicked;
116 IVtk_SubShapeMap mySubShapesPicked;
117 Handle(IVtkOCC_ViewerSelector) myViewerSelector;
120 #endif // __IVTKOCC_SHAPEPICKERALGO_H__