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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _SelectMgr_EntityOwner_HeaderFile
18 #define _SelectMgr_EntityOwner_HeaderFile
20 #include <Aspect_VKey.hxx>
21 #include <PrsMgr_PresentationManager.hxx>
22 #include <SelectMgr_SelectableObject.hxx>
23 #include <TopLoc_Location.hxx>
27 //! A framework to define classes of owners of sensitive primitives.
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.
30 class SelectMgr_EntityOwner : public Standard_Transient
32 DEFINE_STANDARD_RTTIEXT(SelectMgr_EntityOwner, Standard_Transient)
35 //! Initializes the selection priority aPriority.
36 Standard_EXPORT SelectMgr_EntityOwner(const Standard_Integer aPriority = 0);
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);
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);
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; }
52 //! Sets the selectable priority of the owner within range [0-9].
53 void SetPriority (Standard_Integer thePriority) { mypriority = thePriority; }
55 //! Returns true if there is a selectable object to serve as an owner.
56 Standard_Boolean HasSelectable() const { return mySelectable != NULL; }
58 //! Returns a selectable object detected in the working context.
59 virtual Handle(SelectMgr_SelectableObject) Selectable() const { return mySelectable; }
61 //! Sets the selectable object.
62 virtual void SetSelectable (const Handle(SelectMgr_SelectableObject)& theSelObj) { mySelectable = theSelObj.get(); }
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)
76 (void )thePoint; (void )theButton; (void )theModifiers; (void )theIsDoubleClick;
77 return Standard_False;
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
84 return mySelectable != NULL
85 && thePrsMgr->IsHighlighted (mySelectable, theMode);
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,
92 const Handle(Prs3d_Drawer)& theStyle,
93 const Standard_Integer theMode = 0);
95 //! Removes highlighting from the owner of a detected selectable object in the presentation manager.
96 //! This object could be the owner of a sensitive primitive.
97 //! @param thePrsMgr presentation manager
98 //! @param theMode obsolete argument for compatibility, should be ignored by implementations
99 virtual void Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
100 const Standard_Integer theMode = 0)
103 if (mySelectable != NULL)
105 thePrsMgr->Unhighlight (mySelectable);
109 //! Clears the owners matching the value of the selection
110 //! mode aMode from the presentation manager object aPM.
111 virtual void Clear (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
112 const Standard_Integer theMode = 0) /// TODO
118 //! Returns TRUE if selectable has transformation.
119 virtual Standard_Boolean HasLocation() const { return mySelectable != NULL && mySelectable->HasTransformation(); }
121 //! Returns transformation of selectable.
122 virtual TopLoc_Location Location() const
124 return mySelectable != NULL && mySelectable->HasTransformation()
125 ? TopLoc_Location(mySelectable->Transformation())
129 //! Change owner location (callback for handling change of location of selectable object).
130 virtual void SetLocation (const TopLoc_Location& theLocation)
135 //! @return Standard_True if the owner is selected.
136 Standard_Boolean IsSelected() const { return myIsSelected; }
138 //! Set the state of the owner.
139 //! @param theIsSelected [in] shows if owner is selected.
140 void SetSelected (const Standard_Boolean theIsSelected) { myIsSelected = theIsSelected; }
142 //! Returns selection state.
143 Standard_DEPRECATED ("Deprecated method - IsSelected() should be used instead")
144 Standard_Integer State() const { return myIsSelected ? 1 : 0; }
146 //! Set the state of the owner.
147 //! The method is deprecated. Use SetSelected() instead.
148 void State (const Standard_Integer theStatus) { myIsSelected = (theStatus == 1); }
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
153 return mySelectable == NULL
154 || mySelectable->IsAutoHilight();
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; }
161 //! Set Z layer ID and update all presentations.
162 virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId)
167 //! Implements immediate application of location transformation of parent object to dynamic highlight structure
168 virtual void UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
169 const Handle(PrsMgr_PresentationManager)& theManager,
170 const Standard_Integer theDispMode)
172 if (mySelectable != NULL)
174 theManager->UpdateHighlightTrsf (theViewer, mySelectable, theDispMode);
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
181 return mySelectable == theOther.get();
184 //! Returns TRUE if this owner points to a part of object and FALSE for entire object.
185 Standard_Boolean ComesFromDecomposition() const { return myFromDecomposition; }
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; }
190 //! Dumps the content of me into the stream
191 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
195 //! Sets the selectable object.
196 Standard_DEPRECATED ("Deprecated method - SetSelectable() should be used instead")
197 void Set (const Handle(SelectMgr_SelectableObject)& theSelObj) { SetSelectable (theSelObj); }
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); }
205 SelectMgr_SelectableObject* mySelectable; //!< raw pointer to selectable object
206 Standard_Integer mypriority; //!< selection priority (for result with the same depth)
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)
212 DEFINE_STANDARD_HANDLE(SelectMgr_EntityOwner, Standard_Transient)
214 // for porting old code
215 typedef SelectMgr_EntityOwner SelectBasics_EntityOwner;
217 #endif // _SelectMgr_EntityOwner_HeaderFile