0024391: Erased AIS object can not be displayed in AIS_InteractiveContext after AIS_I...
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19#include <PrsMgr_PresentationManager.ixx>
20#include <PrsMgr_PresentableObject.hxx>
21#include <PrsMgr_Presentation.hxx>
22#include <PrsMgr_Presentations.hxx>
23#include <PrsMgr_ModedPresentation.hxx>
24#include <TColStd_ListIteratorOfListOfTransient.hxx>
25
26
27PrsMgr_PresentationManager::PrsMgr_PresentationManager ():
28myImmediateMode(Standard_False){}
29
30
31void PrsMgr_PresentationManager::Display(
32 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
33 const Standard_Integer aMode)
34{
35 if (!HasPresentation(aPresentableObject,aMode)){
36 AddPresentation(aPresentableObject,aMode);
37 }
38 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
39 Update(aPresentableObject,aMode);
40 }
41
42 if(myImmediateMode)
43 Add(aPresentableObject,aMode);
44 else
45 Presentation(aPresentableObject,aMode)->Display();
46}
47
48void PrsMgr_PresentationManager::Erase(
49 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
50 const Standard_Integer aMode)
51{
eef7fc64 52 if (HasPresentation(aPresentableObject,aMode))
53 {
7fd59977 54 if(myImmediateMode)
eef7fc64 55 {
7fd59977 56 Remove(aPresentableObject,aMode);
eef7fc64 57 }
7fd59977 58 else
eef7fc64 59 {
60 Presentation(aPresentableObject,aMode)->Erase();
61 }
62
63 RemovePresentation (aPresentableObject,aMode);
64 }
7fd59977 65}
66
67void PrsMgr_PresentationManager::Clear(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
68 const Standard_Integer aMode)
69{
70 if (HasPresentation(aPresentableObject,aMode)){
71 if(myImmediateMode)
72 Remove(aPresentableObject,aMode);
73 else
74 Presentation(aPresentableObject,aMode)->Clear();}
75}
76
eb4320f2 77void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
78 const Standard_Integer theMode,
79 const Standard_Boolean theValue)
80{
81 Presentation(thePresentableObject, theMode)->SetVisible (theValue);
82}
7fd59977 83
84void PrsMgr_PresentationManager::Highlight(
85 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
86 const Standard_Integer aMode)
87{
88 if (!HasPresentation(aPresentableObject,aMode)){
89 AddPresentation(aPresentableObject,aMode);
90 }
91 else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
92 Update(aPresentableObject,aMode);
93 }
94 Presentation(aPresentableObject,aMode)->Highlight();
95
96 if(myImmediateMode)
97 Add(aPresentableObject,aMode);
98}
99
100void PrsMgr_PresentationManager::Unhighlight(
101 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
102 const Standard_Integer aMode)
103{
104 if (HasPresentation(aPresentableObject,aMode)){
105 Presentation(aPresentableObject,aMode)->Unhighlight();
106 if(myImmediateMode)
107 Remove(aPresentableObject,aMode);
108 }
109}
110
111
112void PrsMgr_PresentationManager::
113SetDisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
114 const Standard_Integer aMode,
115 const Standard_Integer theNewPrior) const
116{
117 if (HasPresentation(aPresentableObject,aMode))
118 Presentation(aPresentableObject,aMode)->SetDisplayPriority(theNewPrior);
119}
120
121Standard_Integer PrsMgr_PresentationManager::
122DisplayPriority(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
123 const Standard_Integer aMode) const
124{
125 if (HasPresentation(aPresentableObject,aMode))
126 return Presentation(aPresentableObject,aMode)->DisplayPriority();
127
128 return 0;
129}
130
131
132Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (
133 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
134 const Standard_Integer aMode) const {
135 if (HasPresentation(aPresentableObject,aMode))
136 return Presentation(aPresentableObject,aMode)->IsDisplayed();
137 return Standard_False;
138 }
139
140Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (
141 const Handle(PrsMgr_PresentableObject)& aPresentableObject,
142 const Standard_Integer aMode) const {
143 if (HasPresentation(aPresentableObject,aMode))
144 return Presentation(aPresentableObject,aMode)->IsHighlighted();
145 return Standard_False;
146 }
147
148void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Standard_Integer aMode ) const {
149 if(HasPresentation(aPresentableObject,aMode)) {
150 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
151 if (!P.IsNull()) {
152 P->Clear();
153 aPresentableObject->Fill(this,P,aMode);
154 P->SetUpdateStatus(Standard_False);
155 }
156 }
157}
158void PrsMgr_PresentationManager::BeginDraw() {
159 myImmediateMode = Standard_True;
160 myImmediateList.Clear();
161}
162
163
164void PrsMgr_PresentationManager::Add(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
165 const Standard_Integer aMode) {
166 if (myImmediateMode ) {
167 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
168 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
169 if(it.Value()==P) return;
170 }
171 myImmediateList.Append(P);
172 }
173}
174void PrsMgr_PresentationManager::Remove(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
175 const Standard_Integer aMode) {
176 if (myImmediateMode ) {
177 Handle(PrsMgr_Presentation) P = Presentation(aPresentableObject,aMode);
178 for (TColStd_ListIteratorOfListOfTransient it(myImmediateList);it.More();it.Next()){
179 if(it.Value()==P) {
180 myImmediateList.Remove(it);
181 return;
182 }
183 }
184 }
185}
186
187
188
189
190Standard_Boolean PrsMgr_PresentationManager::HasPresentation
191 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
192 const Standard_Integer aMode) const {
193
194 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
195 Standard_Boolean found = Standard_False;
196 Standard_Integer i=1; Standard_Integer l= S.Length();
197 while (i<= l && !found) {
198// modif WOK++ : operator == is ambiguous
199// found = aMode == S(i).Mode()
200// && this == S(i).Presentation()->PresentationManager();
201 const Handle (PrsMgr_Presentation)& popPrs = S(i).Presentation();
202 const Handle (PrsMgr_PresentationManager)& popPrsMgr = popPrs->PresentationManager();
203 if ( aMode == S(i).Mode() && this == popPrsMgr )
204 found = Standard_True;
205 i++;
206 }
207 return found;
208 }
209
210Handle (PrsMgr_Presentation)
211 PrsMgr_PresentationManager::Presentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
212 const Standard_Integer aMode) const
213{
214 Handle(PrsMgr_Presentation) P;
215 const PrsMgr_Presentations& S = aPresentableObject->Presentations();
216 Standard_Boolean found = Standard_False;
217 Standard_Integer i=1; Standard_Integer l= S.Length();
218 while (i<= l && !found) {
219 P = S(i).Presentation();
220 const Handle (PrsMgr_PresentationManager)& popPrsMgr = P->PresentationManager();
221 if (aMode == S(i).Mode() && this == popPrsMgr) {
222 found = Standard_True;
223
224
225 }
226 i++;
227 }
228
229 return P;
230}
231
232void PrsMgr_PresentationManager::AddPresentation
233 (const Handle(PrsMgr_PresentableObject)& aPresentableObject,
234 const Standard_Integer aMode) {
235
236 Handle(PrsMgr_Presentation) P = newPresentation(aPresentableObject);
237 aPresentableObject->Presentations().Append(PrsMgr_ModedPresentation(P,aMode));
238 aPresentableObject->Fill(this,P,aMode);
59f45b7c 239
240 // set layer index accordingly to object's presentations
241 Standard_Integer aZLayerId = GetZLayer (aPresentableObject);
242 if (aZLayerId >= 0)
243 P->SetZLayer (aZLayerId);
244
7fd59977 245 P->SetUpdateStatus(Standard_False);
246}
247
248void PrsMgr_PresentationManager::RemovePresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject,
249 const Standard_Integer aMode)
250{
251 PrsMgr_Presentations& S = aPresentableObject->Presentations();
252 Standard_Integer i = 1;
253 Standard_Integer n = S.Length();
254 while (i<= n) {
255 if (aMode == S(i).Mode()) {
256 S.Remove(i);
257 break;
258 }
259 i++;
260 }
261}
262
59f45b7c 263//=======================================================================
264//function : SetZLayer
265//purpose :
266//=======================================================================
267
268void PrsMgr_PresentationManager::SetZLayer
269 (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
270 const Standard_Integer theLayerId)
271{
272 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
273 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
274 {
275 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
276 if (aPrs->PresentationManager () == this)
277 aPrs->SetZLayer (theLayerId);
278 }
279}
280
281//=======================================================================
282//function : GetZLayer
283//purpose :
284//=======================================================================
285
286Standard_Integer PrsMgr_PresentationManager::GetZLayer
287 (const Handle(PrsMgr_PresentableObject)& thePresentableObject) const
288{
289 PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations();
290 for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++)
291 {
292 Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation ();
293 if (aPrs->PresentationManager () == this)
294 return aPrs->GetZLayer ();
295 }
296
297 return -1;
298}