0025501: TNaming::Displace calls itself recursively with default parameter.
[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
7fd59977 17#include <StdSelect_BRepOwner.ixx>
18#include <SelectBasics_EntityOwner.hxx>
19
20#include <StdPrs_WFShape.hxx>
21
22#include <Graphic3d_StructureManager.hxx>
23
24//==================================================
25// Function:
26// Purpose :
27//==================================================
28StdSelect_BRepOwner::StdSelect_BRepOwner(const Standard_Integer aPriority):
29SelectMgr_EntityOwner(aPriority),
30myFromDecomposition(Standard_False),
31myCurMode(0)
32{
33}
34
35StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
36 const Standard_Integer aPriority,
37 const Standard_Boolean ComesFromDecomposition):
38SelectMgr_EntityOwner(aPriority),
39myFromDecomposition(ComesFromDecomposition),
40myShape(aShape),
41myCurMode(0)
42{
43}
44
45StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
46 const Handle (SelectMgr_SelectableObject)& theOrigin,
47 const Standard_Integer aPriority,
48 const Standard_Boolean ComesFromDecomposition):
49SelectMgr_EntityOwner(theOrigin,aPriority),
50myFromDecomposition(ComesFromDecomposition),
51myShape(aShape),
52myCurMode(0)
53{
54}
55
56//=======================================================================
57//function : IsHilighted
58//purpose :
59//=======================================================================
60Standard_Boolean StdSelect_BRepOwner::
61IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
62 const Standard_Integer aMode) const
63{
7fd59977 64 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
7fd59977 65 if(myPrsSh.IsNull())
66 return PM->IsHighlighted(Selectable(),M);
67 return PM->IsHighlighted(myPrsSh,M);
68}
69
70//=======================================================================
71//function : Hilight/Unhilight Methods...
72//purpose :
73//=======================================================================
74void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM,
75 const Standard_Integer aMode)
76{
77
7fd59977 78 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
a1954302 79 Handle(SelectMgr_SelectableObject) aSel = Selectable();
29d43f9c
A
80 if (myFromDecomposition)
81 {
82 // do the update flag check
83 if (!myPrsSh.IsNull())
84 {
85 TColStd_ListOfInteger aModesList;
86 myPrsSh->ToBeUpdated (aModesList);
87 if (!aModesList.IsEmpty())
88 myPrsSh.Nullify();
89 }
90
59f45b7c 91 // generate new presentable shape
a1954302 92 if (myPrsSh.IsNull())
93 {
29d43f9c 94 myPrsSh = new StdSelect_Shape (myShape);
a1954302 95 }
59f45b7c 96 if (!aSel.IsNull())
97 {
a1954302 98 myPrsSh->SetZLayer (aSel->ZLayer());
59f45b7c 99 }
a1954302 100
101 // highlight and set layer
102 PM->Highlight (myPrsSh, M);
103
59f45b7c 104 }
7fd59977 105 else
59f45b7c 106 {
107 if(myPrsSh.IsNull())
a1954302 108 PM->Highlight(aSel,M);
59f45b7c 109 else
110 PM->Highlight(myPrsSh,M);
111 }
7fd59977 112}
113
114void StdSelect_BRepOwner::Hilight()
115{}
116
117void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManager3d)& PM,
118 const Quantity_NameOfColor aCol,
119 const Standard_Integer aMode)
120{
7fd59977 121 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
a1954302 122 Handle(SelectMgr_SelectableObject) aSel = Selectable();
29d43f9c
A
123 if (myFromDecomposition)
124 {
125 // do the update flag check
126 if (!myPrsSh.IsNull())
127 {
128 TColStd_ListOfInteger aModesList;
129 myPrsSh->ToBeUpdated (aModesList);
130 if (!aModesList.IsEmpty())
131 myPrsSh.Nullify();
132 }
133
59f45b7c 134 // generate new presentable shape
135 if(myPrsSh.IsNull())
136 {
137 if(HasLocation())
138 {
139 TopLoc_Location lbid = Location() * myShape.Location();
140 TopoDS_Shape ShBis = myShape.Located(lbid);
141 myPrsSh = new StdSelect_Shape(ShBis);
7fd59977 142 }
143 else
59f45b7c 144 myPrsSh = new StdSelect_Shape(myShape);
145 }
59f45b7c 146 if (!aSel.IsNull())
147 {
a1954302 148 myPrsSh->SetZLayer (aSel->ZLayer());
7fd59977 149 }
a1954302 150
151 // highlight with color and set layer
a272ed94 152 PM->Color (myPrsSh, aCol, M, aSel);
7fd59977 153 }
7fd59977 154 else
59f45b7c 155 {
a272ed94 156 if (!myPrsSh.IsNull())
157 {
158 PM->Color (myPrsSh, aCol, M, aSel);
159 }
59f45b7c 160 else
a272ed94 161 {
162 PM->Color (aSel, aCol, M);
163 }
59f45b7c 164 }
7fd59977 165}
166
167void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM,
168 const Standard_Integer aMode)
169{
7fd59977 170 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
7fd59977 171 if(myPrsSh.IsNull() || !myFromDecomposition)
172 PM->Unhighlight(Selectable(),M);
173 else
174 PM->Unhighlight(myPrsSh,M);
175}
176
177void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
178 const Standard_Integer aMode)
179{
7fd59977 180 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
6153bb63 181 if (!myPrsSh.IsNull())
7fd59977 182 PM->Clear(myPrsSh,M);
183 myPrsSh.Nullify();
184}
185
186void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
187{
188 SelectMgr_EntityOwner::SetLocation(aLoc);
29d43f9c
A
189 // we must not nullify the myPrsSh here, because unhilight method
190 // will be working with wrong entity in this case, the best is to
191 // set the update flag and then recompute myPrsSh on hilighting
192 if (!myPrsSh.IsNull())
193 myPrsSh->SetToUpdate();
7fd59977 194}
59f45b7c 195
7fd59977 196void StdSelect_BRepOwner::ResetLocation()
197{
198 SelectMgr_EntityOwner::ResetLocation();
29d43f9c
A
199 // we must not nullify the myPrsSh here, because unhilight method
200 // will be working with wrong entity in this case, the best is to
201 // set the update flag and then recompute myPrsSh on hilighting
202 if (!myPrsSh.IsNull())
203 myPrsSh->SetToUpdate();
59f45b7c 204}
29d43f9c 205
59f45b7c 206//=======================================================================
207//function : SetZLayer
208//purpose :
209//=======================================================================
a1954302 210void StdSelect_BRepOwner::SetZLayer (const Graphic3d_ZLayerId theLayerId)
59f45b7c 211{
212 if (!myPrsSh.IsNull())
a1954302 213 {
214 myPrsSh->SetZLayer (theLayerId);
215 }
7fd59977 216}