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 
20 #include <Aspect_VKey.hxx>
21 #include <PrsMgr_PresentationManager.hxx>
22 #include <SelectMgr_SelectableObject.hxx>
23 #include <TopLoc_Location.hxx>
24 
25 class V3d_Viewer;
26 
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
31 {
32   DEFINE_STANDARD_RTTIEXT(SelectMgr_EntityOwner, Standard_Transient)
33 public:
34 
35   //! Initializes the selection priority aPriority.
36   Standard_EXPORT SelectMgr_EntityOwner(const Standard_Integer aPriority = 0);
37 
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);
41 
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);
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.
Priority() const50   Standard_Integer Priority() const { return mypriority; }
51 
52   //! Sets the selectable priority of the owner within range [0-9].
SetPriority(Standard_Integer thePriority)53   void SetPriority (Standard_Integer thePriority) { mypriority = thePriority; }
54 
55   //! Returns true if there is a selectable object to serve as an owner.
HasSelectable() const56   Standard_Boolean HasSelectable() const { return mySelectable != NULL; }
57 
58   //! Returns a selectable object detected in the working context.
Selectable() const59   virtual Handle(SelectMgr_SelectableObject) Selectable() const { return mySelectable; }
60 
61   //! Sets the selectable object.
SetSelectable(const Handle (SelectMgr_SelectableObject)& theSelObj)62   virtual void SetSelectable (const Handle(SelectMgr_SelectableObject)& theSelObj) { mySelectable = theSelObj.get(); }
63 
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
HandleMouseClick(const Graphic3d_Vec2i & thePoint,Aspect_VKeyMouse theButton,Aspect_VKeyFlags theModifiers,bool theIsDoubleClick)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 
80   //! Returns true if the presentation manager highlights selections corresponding to the selection mode.
IsHilighted(const Handle (PrsMgr_PresentationManager)& thePrsMgr,const Standard_Integer theMode=0) const81   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   }
87 
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);
94 
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
Unhilight(const Handle (PrsMgr_PresentationManager)& thePrsMgr,const Standard_Integer theMode=0)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   }
108 
109   //! Clears the owners matching the value of the selection
110   //! mode aMode from the presentation manager object aPM.
Clear(const Handle (PrsMgr_PresentationManager)& thePrsMgr,const Standard_Integer theMode=0)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.
HasLocation() const119   virtual Standard_Boolean HasLocation() const { return mySelectable != NULL && mySelectable->HasTransformation(); }
120 
121   //! Returns transformation of selectable.
Location() const122   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).
SetLocation(const TopLoc_Location & theLocation)130   virtual void SetLocation (const TopLoc_Location& theLocation)
131   {
132     (void )theLocation;
133   }
134 
135   //! @return Standard_True if the owner is selected.
IsSelected() const136   Standard_Boolean IsSelected() const { return myIsSelected; }
137 
138   //! Set the state of the owner.
139   //! @param theIsSelected [in] shows if owner is selected.
SetSelected(const Standard_Boolean theIsSelected)140   void SetSelected (const Standard_Boolean theIsSelected) { myIsSelected = theIsSelected; }
141 
142   //! Returns selection state.
143   Standard_DEPRECATED ("Deprecated method - IsSelected() should be used instead")
State() const144   Standard_Integer State() const { return myIsSelected ? 1 : 0; }
145 
146   //! Set the state of the owner.
147   //! The method is deprecated. Use SetSelected() instead.
State(const Standard_Integer theStatus)148   void State (const Standard_Integer theStatus) { myIsSelected = (theStatus == 1); }
149 
150   //! if owner is not auto hilighted, for group contains many such owners will be called one method HilightSelected of SelectableObject
IsAutoHilight() const151   virtual Standard_Boolean IsAutoHilight() const
152   {
153     return mySelectable == NULL
154         || mySelectable->IsAutoHilight();
155   }
156 
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.
IsForcedHilight() const159   virtual Standard_Boolean IsForcedHilight() const { return Standard_False; }
160 
161   //! Set Z layer ID and update all presentations.
SetZLayer(const Graphic3d_ZLayerId theLayerId)162   virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId)
163   {
164     (void )theLayerId;
165   }
166 
167   //! Implements immediate application of location transformation of parent object to dynamic highlight structure
UpdateHighlightTrsf(const Handle (V3d_Viewer)& theViewer,const Handle (PrsMgr_PresentationManager)& theManager,const Standard_Integer theDispMode)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   }
177 
178   //! Returns true if pointer to selectable object of this owner is equal to the given one
IsSameSelectable(const Handle (SelectMgr_SelectableObject)& theOther) const179   Standard_Boolean IsSameSelectable (const Handle(SelectMgr_SelectableObject)& theOther) const
180   {
181     return mySelectable == theOther.get();
182   }
183 
184   //! Returns TRUE if this owner points to a part of object and FALSE for entire object.
ComesFromDecomposition() const185   Standard_Boolean ComesFromDecomposition() const { return myFromDecomposition; }
186 
187   //! Sets flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE).
SetComesFromDecomposition(const Standard_Boolean theIsFromDecomposition)188   void SetComesFromDecomposition (const Standard_Boolean theIsFromDecomposition) { myFromDecomposition = theIsFromDecomposition; }
189 
190   //! Dumps the content of me into the stream
191   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
192 
193 public:
194 
195   //! Sets the selectable object.
196   Standard_DEPRECATED ("Deprecated method - SetSelectable() should be used instead")
Set(const Handle (SelectMgr_SelectableObject)& theSelObj)197   void Set (const Handle(SelectMgr_SelectableObject)& theSelObj) { SetSelectable (theSelObj); }
198 
199   //! sets the selectable priority of the owner
200   Standard_DEPRECATED ("Deprecated method - SetPriority() should be used instead")
Set(const Standard_Integer thePriority)201   void Set (const Standard_Integer thePriority) { SetPriority (thePriority); }
202 
203 protected:
204 
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)
209 
210 };
211 
212 DEFINE_STANDARD_HANDLE(SelectMgr_EntityOwner, Standard_Transient)
213 
214 Standard_DEPRECATED("Deprecated alias - SelectMgr_EntityOwner should be used instead")
215 typedef SelectMgr_EntityOwner SelectBasics_EntityOwner;
216 
217 #endif // _SelectMgr_EntityOwner_HeaderFile
218