0025695: Visualization, AIS_InteractiveContext - define default HilightMode
[occt.git] / src / StdSelect / StdSelect_BRepOwner.cxx
CommitLineData
b311480e 1// Created on: 1995-03-08
2// Created by: Mister rmi
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
f838dac4 17#include <StdSelect_BRepOwner.hxx>
7fd59977 18
19#include <Graphic3d_StructureManager.hxx>
7f917335 20#include <Prs3d_Drawer.hxx>
42cf5bc1 21#include <PrsMgr_PresentationManager.hxx>
7f917335 22#include <SelectBasics_EntityOwner.hxx>
42cf5bc1 23#include <SelectMgr_SelectableObject.hxx>
24#include <Standard_Type.hxx>
42cf5bc1 25#include <StdSelect_Shape.hxx>
26#include <TopLoc_Location.hxx>
27#include <TopoDS_Shape.hxx>
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(StdSelect_BRepOwner,SelectMgr_EntityOwner)
30
7fd59977 31//==================================================
f838dac4 32// Function: StdSelect_BRepOwner
7fd59977 33// Purpose :
34//==================================================
f838dac4 35StdSelect_BRepOwner::StdSelect_BRepOwner (const Standard_Integer thePriority)
36: SelectMgr_EntityOwner (thePriority),
37 myCurMode (0)
7fd59977 38{
f838dac4 39 //
7fd59977 40}
41
f838dac4 42//==================================================
43// Function: StdSelect_BRepOwner
44// Purpose :
45//==================================================
46StdSelect_BRepOwner::StdSelect_BRepOwner (const TopoDS_Shape& theShape,
47 const Standard_Integer thePriority,
48 const Standard_Boolean theComesFromDecomposition)
49: SelectMgr_EntityOwner (thePriority),
50 myShape (theShape),
51 myCurMode (0)
7fd59977 52{
f838dac4 53 myFromDecomposition = theComesFromDecomposition;
7fd59977 54}
55
f838dac4 56//==================================================
57// Function: StdSelect_BRepOwner
58// Purpose :
59//==================================================
60StdSelect_BRepOwner::StdSelect_BRepOwner (const TopoDS_Shape& theShape,
61 const Handle (SelectMgr_SelectableObject)& theOrigin,
62 const Standard_Integer thePriority,
63 const Standard_Boolean theComesFromDecomposition)
64: SelectMgr_EntityOwner (theOrigin, thePriority),
65 myShape (theShape),
66 myCurMode (0)
7fd59977 67{
f838dac4 68 myFromDecomposition = theComesFromDecomposition;
7fd59977 69}
70
71//=======================================================================
72//function : IsHilighted
73//purpose :
74//=======================================================================
75Standard_Boolean StdSelect_BRepOwner::
76IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
77 const Standard_Integer aMode) const
78{
7fd59977 79 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
7fd59977 80 if(myPrsSh.IsNull())
81 return PM->IsHighlighted(Selectable(),M);
82 return PM->IsHighlighted(myPrsSh,M);
83}
84
85//=======================================================================
8e5fb5ea 86//function : HilightWithColor
87//purpose :
7fd59977 88//=======================================================================
8e5fb5ea 89void StdSelect_BRepOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
f838dac4 90 const Handle(Prs3d_Drawer)& theStyle,
8e5fb5ea 91 const Standard_Integer theMode)
7fd59977 92{
f838dac4 93 if (!HasSelectable())
29d43f9c 94 {
f838dac4 95 return;
96 }
7f917335 97
f838dac4 98 const Standard_Integer aDispMode = (theMode < 0) ? myCurMode : theMode;
99 Handle(SelectMgr_SelectableObject) aSel = Selectable();
100 const Graphic3d_ZLayerId aHiLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : aSel->ZLayer();
101 if (!myFromDecomposition)
102 {
103 thePM->Color (aSel, theStyle, aDispMode, NULL, aHiLayer);
104 return;
105 }
a1954302 106
f838dac4 107 // do the update flag check
108 if (!myPrsSh.IsNull())
109 {
110 TColStd_ListOfInteger aModesList;
111 myPrsSh->ToBeUpdated (aModesList);
112 if (!aModesList.IsEmpty())
113 myPrsSh.Nullify();
7fd59977 114 }
f838dac4 115
116 // generate new presentable shape
117 if (myPrsSh.IsNull())
59f45b7c 118 {
f838dac4 119 if (HasLocation())
a272ed94 120 {
f838dac4 121 TopLoc_Location lbid = Location() * myShape.Location();
122 TopoDS_Shape ShBis = myShape.Located(lbid);
123 myPrsSh = new StdSelect_Shape (ShBis, theStyle);
a272ed94 124 }
59f45b7c 125 else
a272ed94 126 {
f838dac4 127 myPrsSh = new StdSelect_Shape (myShape, theStyle);
a272ed94 128 }
59f45b7c 129 }
f838dac4 130
131 // initialize presentation attributes of child presentation
132 myPrsSh->SetZLayer (aSel->ZLayer());
133 myPrsSh->SetTransformPersistence (aSel->TransformPersistence());
134 myPrsSh->Attributes()->SetLink (theStyle);
135 myPrsSh->Attributes()->SetColor (theStyle->Color());
136 myPrsSh->Attributes()->SetTransparency (theStyle->Transparency());
137 myPrsSh->Attributes()->SetBasicFillAreaAspect (theStyle->BasicFillAreaAspect());
138
139 // highlight with color and set layer
140 thePM->Color (myPrsSh, theStyle, aDispMode, aSel, aHiLayer);
7fd59977 141}
142
f838dac4 143void StdSelect_BRepOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Standard_Integer )
7fd59977 144{
f838dac4 145 if (myPrsSh.IsNull() || !myFromDecomposition)
146 {
147 thePrsMgr->Unhighlight (Selectable());
148 }
7fd59977 149 else
f838dac4 150 {
151 thePrsMgr->Unhighlight (myPrsSh);
152 }
7fd59977 153}
154
155void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
156 const Standard_Integer aMode)
157{
7fd59977 158 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
6153bb63 159 if (!myPrsSh.IsNull())
7fd59977 160 PM->Clear(myPrsSh,M);
161 myPrsSh.Nullify();
162}
163
164void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
165{
166 SelectMgr_EntityOwner::SetLocation(aLoc);
29d43f9c
A
167 // we must not nullify the myPrsSh here, because unhilight method
168 // will be working with wrong entity in this case, the best is to
169 // set the update flag and then recompute myPrsSh on hilighting
170 if (!myPrsSh.IsNull())
171 myPrsSh->SetToUpdate();
7fd59977 172}
59f45b7c 173
7fd59977 174void StdSelect_BRepOwner::ResetLocation()
175{
176 SelectMgr_EntityOwner::ResetLocation();
29d43f9c
A
177 // we must not nullify the myPrsSh here, because unhilight method
178 // will be working with wrong entity in this case, the best is to
179 // set the update flag and then recompute myPrsSh on hilighting
180 if (!myPrsSh.IsNull())
181 myPrsSh->SetToUpdate();
59f45b7c 182}
29d43f9c 183
59f45b7c 184//=======================================================================
5396886c 185//function : UpdateHighlightTrsf
186//purpose :
187//=======================================================================
188void StdSelect_BRepOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
189 const Handle(PrsMgr_PresentationManager3d)& theManager,
190 const Standard_Integer theDispMode)
191{
192 if (myPrsSh.IsNull() && Selectable().IsNull())
193 return;
194
195 theManager->UpdateHighlightTrsf (theViewer, Selectable(), theDispMode, myPrsSh);
196}