f52150d6c8ffcf20a70c977f9458b8c6f6d1894e
[occt.git] / src / SelectMgr / SelectMgr_EntityOwner.hxx
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 <Graphic3d_ZLayerId.hxx>
21 #include <Prs3d_Drawer.hxx>
22 #include <PrsMgr_PresentationManager3d.hxx>
23 #include <SelectBasics_EntityOwner.hxx>
24 #include <SelectMgr_SelectableObject.hxx>
25 #include <Standard.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_Type.hxx>
29 #include <Quantity_NameOfColor.hxx>
30
31 class V3d_Viewer;
32
33 //! A framework to define classes of owners of sensitive primitives.
34 //! The owner is the link between application and
35 //! selection data structures.
36 //! For the application to make its own objects selectable,
37 //! it must define owner classes inheriting this framework.
38 class SelectMgr_EntityOwner : public SelectBasics_EntityOwner
39 {
40   DEFINE_STANDARD_RTTIEXT(SelectMgr_EntityOwner, SelectBasics_EntityOwner)
41 public:
42
43   //! Initializes the selection priority aPriority.
44   Standard_EXPORT SelectMgr_EntityOwner(const Standard_Integer aPriority = 0);
45
46   //! Constructs a framework with the selectable object
47   //! anSO being attributed the selection priority aPriority.
48   Standard_EXPORT SelectMgr_EntityOwner(const Handle(SelectMgr_SelectableObject)& aSO, const Standard_Integer aPriority = 0);
49
50   //! Constructs a framework from existing one
51   //! anSO being attributed the selection priority aPriority.
52   Standard_EXPORT SelectMgr_EntityOwner(const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Integer aPriority = 0);
53   
54   //! Returns true if there is a selectable object to serve as an owner.
55   Standard_Boolean HasSelectable() const { return mySelectable != NULL; }
56
57   //! Returns a selectable object detected in the working context.
58   Standard_EXPORT virtual Handle(SelectMgr_SelectableObject) Selectable() const;
59
60   //! Sets the selectable object.
61   Standard_EXPORT virtual void SetSelectable (const Handle(SelectMgr_SelectableObject)& theSelObj);
62
63   //! Returns true if the presentation manager aPM
64   //! highlights selections corresponding to the selection mode aMode.
65   Standard_EXPORT virtual Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& aPM, const Standard_Integer aMode = 0) const;
66   
67   //! Highlights selectable object's presentation with mode theMode in presentation manager
68   //! with given highlight style. Also a check for auto-highlight is performed - if
69   //! selectable object manages highlighting on its own, execution will be passed to
70   //! SelectMgr_SelectableObject::HilightOwnerWithColor method
71   Standard_EXPORT virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
72                                                  const Handle(Prs3d_Drawer)& theStyle,
73                                                  const Standard_Integer theMode = 0);
74
75   //! Removes highlighting from the owner of a detected selectable object in the presentation manager.
76   //! This object could be the owner of a sensitive primitive.
77   //! @param thePrsMgr presentation manager
78   //! @param theMode   obsolete argument for compatibility, should be ignored by implementations
79   Standard_EXPORT virtual void Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Standard_Integer theMode = 0);
80
81   //! Clears the owners matching the value of the selection
82   //! mode aMode from the presentation manager object aPM.
83   Standard_EXPORT virtual void Clear (const Handle(PrsMgr_PresentationManager)& aPM, const Standard_Integer aMode = 0);
84   
85   Standard_EXPORT virtual Standard_Boolean HasLocation() const Standard_OVERRIDE;
86   
87   Standard_EXPORT virtual void SetLocation (const TopLoc_Location& aLoc) Standard_OVERRIDE;
88   
89   Standard_EXPORT virtual void ResetLocation() Standard_OVERRIDE;
90   
91   Standard_EXPORT virtual TopLoc_Location Location() const Standard_OVERRIDE;
92   
93   //! Set the state of the owner.
94   //! @param theIsSelected [in] shows if owner is selected.
95   void SetSelected (const Standard_Boolean theIsSelected) { myIsSelected = theIsSelected; }
96
97   //! @return Standard_True if the owner is selected.
98   Standard_Boolean IsSelected() const { return myIsSelected; }
99
100   //! Set the state of the owner.
101   //! The method is deprecated. Use SetSelected() instead.
102   void State (const Standard_Integer theStatus) { myIsSelected = (theStatus == 1); }
103
104   Standard_Integer State() const { return myIsSelected ? 1 : 0; }
105
106   //! if owner is not auto hilighted, for group contains many such owners
107   //! will be called one method HilightSelected of SelectableObject
108   Standard_EXPORT virtual Standard_Boolean IsAutoHilight() const;
109   
110   //! if this method returns TRUE the owner will allways call method
111   //! Hilight for SelectableObject when the owner is detected. By default
112   //! it always return FALSE.
113   Standard_EXPORT virtual Standard_Boolean IsForcedHilight() const;
114   
115   //! Set Z layer ID and update all presentations.
116   Standard_EXPORT virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId);
117
118   //! Implements immediate application of location transformation of parent object to dynamic highlight structure
119   Standard_EXPORT virtual void UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
120                                                     const Handle(PrsMgr_PresentationManager3d)& theManager,
121                                                     const Standard_Integer theDispMode);
122
123   //! Returns true if pointer to selectable object of this owner is equal to the given one
124   Standard_Boolean IsSameSelectable (const Handle(SelectMgr_SelectableObject)& theOther) const
125   {
126     return mySelectable == theOther.get();
127   }
128
129   //! Returns TRUE if this owner points to a part of object and FALSE for entire object.
130   Standard_Boolean ComesFromDecomposition() const { return myFromDecomposition; }
131
132   //! Sets flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE).
133   void SetComesFromDecomposition (const Standard_Boolean theIsFromDecomposition) { myFromDecomposition = theIsFromDecomposition; }
134
135 public:
136
137   //! Sets the selectable object.
138   void Set (const Handle(SelectMgr_SelectableObject)& theSelObj) { SetSelectable (theSelObj); }
139
140 protected:
141
142   SelectMgr_SelectableObject* mySelectable;        //!< raw pointer to selectable object
143   Standard_Boolean            myIsSelected;        //!< flag indicating selected state
144   Standard_Boolean            myFromDecomposition; //!< flag indicating this owner points to a part of object (TRUE) or to entire object (FALSE)
145
146 };
147
148 DEFINE_STANDARD_HANDLE(SelectMgr_EntityOwner, SelectBasics_EntityOwner)
149
150 #endif // _SelectMgr_EntityOwner_HeaderFile