0031458: Visualization - refine classes across Prs3d and StdPrs packages
[occt.git] / src / SelectMgr / SelectMgr_EntityOwner.hxx
CommitLineData
42cf5bc1 1// Created on: 1995-05-23
2// Created by: Robert COUBLANC
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _SelectMgr_EntityOwner_HeaderFile
18#define _SelectMgr_EntityOwner_HeaderFile
19
2108d9a2 20#include <Aspect_VKey.hxx>
0ef04197 21#include <PrsMgr_PresentationManager.hxx>
f838dac4 22#include <SelectMgr_SelectableObject.hxx>
0ef04197 23#include <TopLoc_Location.hxx>
42cf5bc1 24
f838dac4 25class V3d_Viewer;
42cf5bc1 26
27//! A framework to define classes of owners of sensitive primitives.
0ef04197 28//! The owner is the link between application and selection data structures.
29//! For the application to make its own objects selectable, it must define owner classes inheriting this framework.
30class SelectMgr_EntityOwner : public Standard_Transient
42cf5bc1 31{
0ef04197 32 DEFINE_STANDARD_RTTIEXT(SelectMgr_EntityOwner, Standard_Transient)
42cf5bc1 33public:
34
42cf5bc1 35 //! Initializes the selection priority aPriority.
36 Standard_EXPORT SelectMgr_EntityOwner(const Standard_Integer aPriority = 0);
f838dac4 37
42cf5bc1 38 //! Constructs a framework with the selectable object
39 //! anSO being attributed the selection priority aPriority.
40 Standard_EXPORT SelectMgr_EntityOwner(const Handle(SelectMgr_SelectableObject)& aSO, const Standard_Integer aPriority = 0);
f838dac4 41
42cf5bc1 42 //! Constructs a framework from existing one
43 //! anSO being attributed the selection priority aPriority.
44 Standard_EXPORT SelectMgr_EntityOwner(const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Integer aPriority = 0);
0ef04197 45
46 //! Return selection priority (within range [0-9]) for results with the same depth; 0 by default.
47 //! Example - selection of shapes:
48 //! the owners are selectable objects (presentations) a user can give vertex priority [3], edges [2] faces [1] shape [0],
49 //! so that if during selection one vertex one edge and one face are simultaneously detected, the vertex will only be hilighted.
50 Standard_Integer Priority() const { return mypriority; }
51
52 //! Sets the selectable priority of the owner within range [0-9].
53 void SetPriority (Standard_Integer thePriority) { mypriority = thePriority; }
54
42cf5bc1 55 //! Returns true if there is a selectable object to serve as an owner.
f838dac4 56 Standard_Boolean HasSelectable() const { return mySelectable != NULL; }
57
42cf5bc1 58 //! Returns a selectable object detected in the working context.
0ef04197 59 virtual Handle(SelectMgr_SelectableObject) Selectable() const { return mySelectable; }
f838dac4 60
61 //! Sets the selectable object.
0ef04197 62 virtual void SetSelectable (const Handle(SelectMgr_SelectableObject)& theSelObj) { mySelectable = theSelObj.get(); }
f838dac4 63
2108d9a2 64 //! Handle mouse button click event.
65 //! Does nothing by default and returns FALSE.
66 //! @param thePoint mouse cursor position
67 //! @param theButton clicked button
68 //! @param theModifiers key modifiers
69 //! @param theIsDoubleClick flag indicating double mouse click
70 //! @return TRUE if object handled click
71 virtual Standard_Boolean HandleMouseClick (const Graphic3d_Vec2i& thePoint,
72 Aspect_VKeyMouse theButton,
73 Aspect_VKeyFlags theModifiers,
74 bool theIsDoubleClick)
75 {
76 (void )thePoint; (void )theButton; (void )theModifiers; (void )theIsDoubleClick;
77 return Standard_False;
78 }
79
0ef04197 80 //! Returns true if the presentation manager highlights selections corresponding to the selection mode.
81 virtual Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
82 const Standard_Integer theMode = 0) const
83 {
84 return mySelectable != NULL
85 && thePrsMgr->IsHighlighted (mySelectable, theMode);
86 }
42cf5bc1 87
0ef04197 88 //! Highlights selectable object's presentation with display mode in presentation manager with given highlight style.
89 //! Also a check for auto-highlight is performed - if selectable object manages highlighting on its own,
90 //! execution will be passed to SelectMgr_SelectableObject::HilightOwnerWithColor method.
91 Standard_EXPORT virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
f838dac4 92 const Handle(Prs3d_Drawer)& theStyle,
8e5fb5ea 93 const Standard_Integer theMode = 0);
f838dac4 94
95 //! Removes highlighting from the owner of a detected selectable object in the presentation manager.
42cf5bc1 96 //! This object could be the owner of a sensitive primitive.
f838dac4 97 //! @param thePrsMgr presentation manager
98 //! @param theMode obsolete argument for compatibility, should be ignored by implementations
0ef04197 99 virtual void Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
100 const Standard_Integer theMode = 0)
101 {
102 (void )theMode;
103 if (mySelectable != NULL)
104 {
105 thePrsMgr->Unhighlight (mySelectable);
106 }
107 }
f838dac4 108
42cf5bc1 109 //! Clears the owners matching the value of the selection
110 //! mode aMode from the presentation manager object aPM.
0ef04197 111 virtual void Clear (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
112 const Standard_Integer theMode = 0) /// TODO
113 {
114 (void )thePrsMgr;
115 (void )theMode;
116 }
117
118 //! Returns TRUE if selectable has transformation.
119 virtual Standard_Boolean HasLocation() const { return mySelectable != NULL && mySelectable->HasTransformation(); }
120
121 //! Returns transformation of selectable.
122 virtual TopLoc_Location Location() const
123 {
124 return mySelectable != NULL && mySelectable->HasTransformation()
125 ? TopLoc_Location(mySelectable->Transformation())
126 : TopLoc_Location();
127 }
128
129 //! Change owner location (callback for handling change of location of selectable object).
130 virtual void SetLocation (const TopLoc_Location& theLocation)
131 {
132 (void )theLocation;
133 }
134
135 //! @return Standard_True if the owner is selected.
136 Standard_Boolean IsSelected() const { return myIsSelected; }
137
42cf5bc1 138 //! Set the state of the owner.
139 //! @param theIsSelected [in] shows if owner is selected.
f838dac4 140 void SetSelected (const Standard_Boolean theIsSelected) { myIsSelected = theIsSelected; }
141
0ef04197 142 //! Returns selection state.
143 Standard_DEPRECATED ("Deprecated method - IsSelected() should be used instead")
144 Standard_Integer State() const { return myIsSelected ? 1 : 0; }
f838dac4 145
42cf5bc1 146 //! Set the state of the owner.
147 //! The method is deprecated. Use SetSelected() instead.
f838dac4 148 void State (const Standard_Integer theStatus) { myIsSelected = (theStatus == 1); }
149
0ef04197 150 //! if owner is not auto hilighted, for group contains many such owners will be called one method HilightSelected of SelectableObject
151 virtual Standard_Boolean IsAutoHilight() const
152 {
153 return mySelectable == NULL
154 || mySelectable->IsAutoHilight();
155 }
f838dac4 156
0ef04197 157 //! if this method returns TRUE the owner will always call method Hilight for SelectableObject when the owner is detected.
158 //! By default it always return FALSE.
159 virtual Standard_Boolean IsForcedHilight() const { return Standard_False; }
42cf5bc1 160
161 //! Set Z layer ID and update all presentations.
0ef04197 162 virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId)
163 {
164 (void )theLayerId;
165 }
42cf5bc1 166
5396886c 167 //! Implements immediate application of location transformation of parent object to dynamic highlight structure
0ef04197 168 virtual void UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
169 const Handle(PrsMgr_PresentationManager)& theManager,
170 const Standard_Integer theDispMode)
171 {
172 if (mySelectable != NULL)
173 {
174 theManager->UpdateHighlightTrsf (theViewer, mySelectable, theDispMode);
175 }
176 }
42cf5bc1 177
8e5fb5ea 178 //! Returns true if pointer to selectable object of this owner is equal to the given one
179 Standard_Boolean IsSameSelectable (const Handle(SelectMgr_SelectableObject)& theOther) const
180 {
181 return mySelectable == theOther.get();
182 }
183
f838dac4 184 //! Returns TRUE if this owner points to a part of object and FALSE for entire object.
185 Standard_Boolean ComesFromDecomposition() const { return myFromDecomposition; }
42cf5bc1 186
f838dac4 187 //! Sets flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE).
188 void SetComesFromDecomposition (const Standard_Boolean theIsFromDecomposition) { myFromDecomposition = theIsFromDecomposition; }
42cf5bc1 189
0904aa63 190 //! Dumps the content of me into the stream
bc73b006 191 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0904aa63 192
f838dac4 193public:
42cf5bc1 194
f838dac4 195 //! Sets the selectable object.
0ef04197 196 Standard_DEPRECATED ("Deprecated method - SetSelectable() should be used instead")
f838dac4 197 void Set (const Handle(SelectMgr_SelectableObject)& theSelObj) { SetSelectable (theSelObj); }
42cf5bc1 198
0ef04197 199 //! sets the selectable priority of the owner
200 Standard_DEPRECATED ("Deprecated method - SetPriority() should be used instead")
201 void Set (const Standard_Integer thePriority) { SetPriority (thePriority); }
202
f838dac4 203protected:
42cf5bc1 204
f838dac4 205 SelectMgr_SelectableObject* mySelectable; //!< raw pointer to selectable object
0ef04197 206 Standard_Integer mypriority; //!< selection priority (for result with the same depth)
f838dac4 207 Standard_Boolean myIsSelected; //!< flag indicating selected state
208 Standard_Boolean myFromDecomposition; //!< flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE)
42cf5bc1 209
210};
211
0ef04197 212DEFINE_STANDARD_HANDLE(SelectMgr_EntityOwner, Standard_Transient)
213
214// for porting old code
215typedef SelectMgr_EntityOwner SelectBasics_EntityOwner;
42cf5bc1 216
217#endif // _SelectMgr_EntityOwner_HeaderFile