b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
679ecdee |
15 | |
42cf5bc1 |
16 | #include <Geom_Transformation.hxx> |
679ecdee |
17 | #include <Graphic3d_GraphicDriver.hxx> |
42cf5bc1 |
18 | #include <Prs3d_Presentation.hxx> |
679ecdee |
19 | #include <Prs3d_PresentationShadow.hxx> |
42cf5bc1 |
20 | #include <PrsMgr_ModedPresentation.hxx> |
7fd59977 |
21 | #include <PrsMgr_PresentableObject.hxx> |
22 | #include <PrsMgr_Presentation.hxx> |
42cf5bc1 |
23 | #include <PrsMgr_PresentationManager.hxx> |
7fd59977 |
24 | #include <PrsMgr_Presentations.hxx> |
42cf5bc1 |
25 | #include <Standard_NoSuchObject.hxx> |
26 | #include <Standard_Type.hxx> |
7fd59977 |
27 | #include <TColStd_ListIteratorOfListOfTransient.hxx> |
679ecdee |
28 | #include <V3d_View.hxx> |
679ecdee |
29 | |
92efcf78 |
30 | IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentationManager,MMgt_TShared) |
31 | |
679ecdee |
32 | // ======================================================================= |
33 | // function : PrsMgr_PresentationManager |
34 | // purpose : |
35 | // ======================================================================= |
c357e426 |
36 | PrsMgr_PresentationManager::PrsMgr_PresentationManager (const Handle(Graphic3d_StructureManager)& theStructureManager) |
679ecdee |
37 | : myStructureManager (theStructureManager), |
8e5fb5ea |
38 | myImmediateModeOn (0) |
679ecdee |
39 | { |
40 | // |
41 | } |
7fd59977 |
42 | |
679ecdee |
43 | // ======================================================================= |
44 | // function : Display |
45 | // purpose : |
46 | // ======================================================================= |
47 | void PrsMgr_PresentationManager::Display (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
48 | const Standard_Integer theMode) |
7fd59977 |
49 | { |
0717ddc1 |
50 | if (thePrsObj->HasOwnPresentations()) |
679ecdee |
51 | { |
a1954302 |
52 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True); |
0717ddc1 |
53 | if (aPrs->MustBeUpdated()) |
54 | { |
55 | Update (thePrsObj, theMode); |
56 | } |
57 | |
58 | if (myImmediateModeOn > 0) |
59 | { |
60 | AddToImmediateList (aPrs->Presentation()); |
61 | } |
62 | else |
63 | { |
64 | aPrs->Display(); |
65 | } |
7fd59977 |
66 | } |
7fd59977 |
67 | else |
679ecdee |
68 | { |
0717ddc1 |
69 | thePrsObj->Compute (this, Handle(Prs3d_Presentation)(), theMode); |
70 | } |
71 | |
72 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
73 | { |
74 | Display (anIter.Value(), theMode); |
679ecdee |
75 | } |
7fd59977 |
76 | } |
77 | |
679ecdee |
78 | // ======================================================================= |
79 | // function : Erase |
80 | // purpose : |
81 | // ======================================================================= |
82 | void PrsMgr_PresentationManager::Erase (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
83 | const Standard_Integer theMode) |
7fd59977 |
84 | { |
0717ddc1 |
85 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
86 | { |
87 | Erase (anIter.Value(), theMode); |
88 | } |
89 | |
a1954302 |
90 | PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
e2d7642f |
91 | for (PrsMgr_Presentations::Iterator anIt (aPrsList); anIt.More();) |
eef7fc64 |
92 | { |
e2d7642f |
93 | const PrsMgr_ModedPresentation& aModedPrs = anIt.Value(); |
94 | if (aModedPrs.Presentation().IsNull()) |
a1954302 |
95 | { |
e2d7642f |
96 | anIt.Next(); |
97 | continue; |
98 | } |
99 | |
100 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
101 | if ((theMode == aModedPrs.Mode() || theMode == -1) |
102 | && (this == aPrsMgr)) |
103 | { |
104 | aModedPrs.Presentation()->Erase(); |
105 | |
106 | aPrsList.Remove (anIt); |
107 | |
108 | if (theMode != -1) |
a1954302 |
109 | { |
e2d7642f |
110 | return; |
a1954302 |
111 | } |
e2d7642f |
112 | } |
113 | else |
114 | { |
115 | anIt.Next(); |
a1954302 |
116 | } |
eef7fc64 |
117 | } |
7fd59977 |
118 | } |
119 | |
679ecdee |
120 | // ======================================================================= |
121 | // function : Clear |
122 | // purpose : |
123 | // ======================================================================= |
124 | void PrsMgr_PresentationManager::Clear (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
125 | const Standard_Integer theMode) |
7fd59977 |
126 | { |
0717ddc1 |
127 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
128 | { |
129 | Clear (anIter.Value(), theMode); |
130 | } |
131 | |
a1954302 |
132 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
133 | if (!aPrs.IsNull()) |
679ecdee |
134 | { |
a1954302 |
135 | aPrs->Clear(); |
679ecdee |
136 | } |
7fd59977 |
137 | } |
138 | |
679ecdee |
139 | // ======================================================================= |
140 | // function : SetVisibility |
141 | // purpose : |
142 | // ======================================================================= |
0717ddc1 |
143 | void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
eb4320f2 |
144 | const Standard_Integer theMode, |
145 | const Standard_Boolean theValue) |
146 | { |
0717ddc1 |
147 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
148 | { |
149 | SetVisibility (anIter.Value(), theMode, theValue); |
150 | } |
151 | if (!thePrsObj->HasOwnPresentations()) |
152 | { |
153 | return; |
154 | } |
155 | |
156 | Presentation (thePrsObj, theMode)->SetVisible (theValue); |
eb4320f2 |
157 | } |
7fd59977 |
158 | |
679ecdee |
159 | // ======================================================================= |
160 | // function : Unhighlight |
161 | // purpose : |
162 | // ======================================================================= |
163 | void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
164 | const Standard_Integer theMode) |
7fd59977 |
165 | { |
0717ddc1 |
166 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
167 | { |
168 | Unhighlight (anIter.Value(), theMode); |
169 | } |
170 | |
a1954302 |
171 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
172 | if (!aPrs.IsNull()) |
679ecdee |
173 | { |
a1954302 |
174 | aPrs->Unhighlight(); |
7fd59977 |
175 | } |
176 | } |
177 | |
679ecdee |
178 | // ======================================================================= |
179 | // function : SetDisplayPriority |
180 | // purpose : |
181 | // ======================================================================= |
182 | void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
183 | const Standard_Integer theMode, |
184 | const Standard_Integer theNewPrior) const |
185 | { |
0717ddc1 |
186 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
187 | { |
188 | SetDisplayPriority (anIter.Value(), theMode, theNewPrior); |
189 | } |
190 | |
a1954302 |
191 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
192 | if (!aPrs.IsNull()) |
679ecdee |
193 | { |
a1954302 |
194 | aPrs->SetDisplayPriority (theNewPrior); |
679ecdee |
195 | } |
196 | } |
7fd59977 |
197 | |
679ecdee |
198 | // ======================================================================= |
199 | // function : DisplayPriority |
200 | // purpose : |
201 | // ======================================================================= |
202 | Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
203 | const Standard_Integer theMode) const |
7fd59977 |
204 | { |
0717ddc1 |
205 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
206 | { |
207 | Standard_Integer aPriority = DisplayPriority (anIter.Value(), theMode); |
208 | if (aPriority != 0) |
209 | { |
210 | return aPriority; |
211 | } |
212 | } |
213 | |
a1954302 |
214 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
215 | return !aPrs.IsNull() |
216 | ? aPrs->DisplayPriority() |
217 | : 0; |
7fd59977 |
218 | } |
219 | |
679ecdee |
220 | // ======================================================================= |
221 | // function : IsDisplayed |
222 | // purpose : |
223 | // ======================================================================= |
224 | Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
225 | const Standard_Integer theMode) const |
7fd59977 |
226 | { |
0717ddc1 |
227 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
228 | { |
229 | if (IsDisplayed (anIter.Value(), theMode)) |
230 | { |
231 | return Standard_True; |
232 | } |
233 | } |
234 | |
a1954302 |
235 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
236 | return !aPrs.IsNull() |
237 | && aPrs->IsDisplayed(); |
7fd59977 |
238 | } |
239 | |
679ecdee |
240 | // ======================================================================= |
241 | // function : IsHighlighted |
242 | // purpose : |
243 | // ======================================================================= |
244 | Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
245 | const Standard_Integer theMode) const |
246 | { |
0717ddc1 |
247 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
248 | { |
249 | if (IsHighlighted (anIter.Value(), theMode)) |
250 | { |
251 | return Standard_True; |
252 | } |
253 | } |
254 | |
a1954302 |
255 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
256 | return !aPrs.IsNull() |
257 | && aPrs->IsHighlighted(); |
679ecdee |
258 | } |
7fd59977 |
259 | |
679ecdee |
260 | // ======================================================================= |
261 | // function : Update |
262 | // purpose : |
263 | // ======================================================================= |
264 | void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
265 | const Standard_Integer theMode) const |
266 | { |
0717ddc1 |
267 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
268 | { |
269 | Update (anIter.Value(), theMode); |
270 | } |
7fd59977 |
271 | |
679ecdee |
272 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
273 | if (!aPrs.IsNull()) |
274 | { |
275 | aPrs->Clear(); |
276 | thePrsObj->Fill (this, aPrs, theMode); |
277 | aPrs->SetUpdateStatus (Standard_False); |
278 | } |
279 | } |
7fd59977 |
280 | |
679ecdee |
281 | // ======================================================================= |
282 | // function : BeginImmediateDraw |
283 | // purpose : |
284 | // ======================================================================= |
285 | void PrsMgr_PresentationManager::BeginImmediateDraw() |
286 | { |
287 | if (++myImmediateModeOn > 1) |
288 | { |
289 | return; |
7fd59977 |
290 | } |
679ecdee |
291 | |
292 | ClearImmediateDraw(); |
7fd59977 |
293 | } |
679ecdee |
294 | |
295 | // ======================================================================= |
296 | // function : ClearImmediateDraw |
297 | // purpose : |
298 | // ======================================================================= |
299 | void PrsMgr_PresentationManager::ClearImmediateDraw() |
300 | { |
c3282ec1 |
301 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
679ecdee |
302 | { |
c3282ec1 |
303 | anIter.Value()->Erase(); |
679ecdee |
304 | } |
305 | |
c3282ec1 |
306 | for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next()) |
679ecdee |
307 | { |
c3282ec1 |
308 | anIter.Value()->Erase(); |
679ecdee |
309 | } |
310 | |
7fd59977 |
311 | myImmediateList.Clear(); |
c3282ec1 |
312 | myViewDependentImmediateList.Clear(); |
313 | } |
314 | |
315 | // ======================================================================= |
316 | // function : displayImmediate |
317 | // purpose : Handles the structures from myImmediateList and its visibility |
318 | // in all views of the viewer given by setting proper affinity |
319 | // ======================================================================= |
320 | void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& theViewer) |
321 | { |
6a24c6de |
322 | for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next()) |
c3282ec1 |
323 | { |
6a24c6de |
324 | const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View(); |
c3282ec1 |
325 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
326 | { |
327 | const Handle(Prs3d_Presentation)& aPrs = anIter.Value(); |
328 | if (aPrs.IsNull()) |
329 | continue; |
330 | |
aa00364d |
331 | Handle(Graphic3d_Structure) aViewDepPrs; |
c3282ec1 |
332 | Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs); |
333 | if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs)) |
334 | { |
335 | aShadowPrs.Nullify(); |
aa00364d |
336 | aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, |
337 | Handle(Prs3d_Presentation)::DownCast (aViewDepPrs)); |
c3282ec1 |
338 | aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer()); |
3202bf1e |
339 | aShadowPrs->SetClipPlanes (aViewDepPrs->ClipPlanes()); |
c3282ec1 |
340 | aShadowPrs->CStructure()->IsForHighlight = 1; |
8e5fb5ea |
341 | aShadowPrs->Highlight (aPrs->HighlightStyle()); |
c3282ec1 |
342 | myViewDependentImmediateList.Append (aShadowPrs); |
343 | } |
c357e426 |
344 | // handles custom highlight presentations which were defined in overridden |
c3282ec1 |
345 | // HilightOwnerWithColor method of a custom AIS objects and maintain its |
346 | // visibility in different views on their own |
347 | else if (aShadowPrs.IsNull()) |
348 | { |
349 | aPrs->Display(); |
350 | continue; |
351 | } |
352 | |
353 | if (!aShadowPrs->IsDisplayed()) |
354 | { |
355 | aShadowPrs->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity(); |
356 | aShadowPrs->CStructure()->ViewAffinity->SetVisible (Standard_False); |
357 | aShadowPrs->Display(); |
358 | } |
359 | |
360 | Standard_Integer aViewId = aView->Identification(); |
361 | bool isParentVisible = aShadowPrs->ParentAffinity().IsNull() ? |
362 | Standard_True : aShadowPrs->ParentAffinity()->IsVisible (aViewId); |
363 | aShadowPrs->CStructure()->ViewAffinity->SetVisible (aViewId, isParentVisible); |
364 | } |
365 | } |
7fd59977 |
366 | } |
367 | |
679ecdee |
368 | // ======================================================================= |
369 | // function : EndImmediateDraw |
370 | // purpose : |
371 | // ======================================================================= |
c3282ec1 |
372 | void PrsMgr_PresentationManager::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer) |
679ecdee |
373 | { |
374 | if (--myImmediateModeOn > 0) |
375 | { |
376 | return; |
377 | } |
378 | |
c3282ec1 |
379 | displayImmediate (theViewer); |
380 | } |
381 | |
382 | // ======================================================================= |
383 | // function : RedrawImmediate |
384 | // purpose : Clears all immediate structures and redisplays with proper |
385 | // affinity |
386 | //======================================================================= |
387 | void PrsMgr_PresentationManager::RedrawImmediate (const Handle(V3d_Viewer)& theViewer) |
388 | { |
389 | if (myImmediateList.IsEmpty()) |
390 | return; |
391 | |
392 | // Clear previously displayed structures |
679ecdee |
393 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
394 | { |
c3282ec1 |
395 | anIter.Value()->Erase(); |
679ecdee |
396 | } |
c3282ec1 |
397 | for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next()) |
679ecdee |
398 | { |
c3282ec1 |
399 | anIter.Value()->Erase(); |
679ecdee |
400 | } |
c3282ec1 |
401 | myViewDependentImmediateList.Clear(); |
402 | |
403 | displayImmediate (theViewer); |
679ecdee |
404 | } |
7fd59977 |
405 | |
679ecdee |
406 | // ======================================================================= |
407 | // function : AddToImmediateList |
408 | // purpose : |
409 | //======================================================================= |
410 | void PrsMgr_PresentationManager::AddToImmediateList (const Handle(Prs3d_Presentation)& thePrs) |
411 | { |
412 | if (myImmediateModeOn < 1) |
413 | { |
414 | return; |
415 | } |
416 | |
417 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
418 | { |
419 | if (anIter.Value() == thePrs) |
420 | { |
421 | return; |
7fd59977 |
422 | } |
679ecdee |
423 | } |
424 | |
425 | myImmediateList.Append (thePrs); |
426 | } |
427 | |
428 | // ======================================================================= |
429 | // function : HasPresentation |
430 | // purpose : |
431 | // ======================================================================= |
432 | Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
433 | const Standard_Integer theMode) const |
434 | { |
0717ddc1 |
435 | if (!thePrsObj->HasOwnPresentations()) |
436 | return Standard_False; |
437 | |
679ecdee |
438 | const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
439 | for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter) |
440 | { |
441 | const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter); |
442 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
443 | if (theMode == aModedPrs.Mode() |
444 | && this == aPrsMgr) |
445 | { |
446 | return Standard_True; |
7fd59977 |
447 | } |
448 | } |
679ecdee |
449 | return Standard_False; |
7fd59977 |
450 | } |
451 | |
679ecdee |
452 | // ======================================================================= |
453 | // function : Presentation |
454 | // purpose : |
455 | // ======================================================================= |
456 | Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
a1954302 |
457 | const Standard_Integer theMode, |
a272ed94 |
458 | const Standard_Boolean theToCreate, |
459 | const Handle(PrsMgr_PresentableObject)& theSelObj) const |
679ecdee |
460 | { |
461 | const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
679ecdee |
462 | for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter) |
463 | { |
464 | const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter); |
465 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
466 | if (theMode == aModedPrs.Mode() |
467 | && this == aPrsMgr) |
468 | { |
469 | return aModedPrs.Presentation(); |
470 | } |
471 | } |
7fd59977 |
472 | |
a1954302 |
473 | if (!theToCreate) |
474 | { |
475 | return Handle(PrsMgr_Presentation)(); |
476 | } |
7fd59977 |
477 | |
af324faa |
478 | Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj); |
a1954302 |
479 | aPrs->SetZLayer (thePrsObj->ZLayer()); |
a272ed94 |
480 | aPrs->Presentation()->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj); |
679ecdee |
481 | thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode)); |
482 | thePrsObj->Fill (this, aPrs, theMode); |
7fd59977 |
483 | |
679ecdee |
484 | // set layer index accordingly to object's presentations |
679ecdee |
485 | aPrs->SetUpdateStatus (Standard_False); |
a1954302 |
486 | return aPrs; |
679ecdee |
487 | } |
7fd59977 |
488 | |
679ecdee |
489 | // ======================================================================= |
490 | // function : RemovePresentation |
491 | // purpose : |
492 | // ======================================================================= |
a1954302 |
493 | Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
494 | const Standard_Integer theMode) |
7fd59977 |
495 | { |
679ecdee |
496 | PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
497 | for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter) |
498 | { |
a1954302 |
499 | const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter); |
500 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
501 | if (theMode == aPrsList (aPrsIter).Mode() |
502 | && this == aPrsMgr) |
679ecdee |
503 | { |
504 | aPrsList.Remove (aPrsIter); |
a1954302 |
505 | return Standard_True; |
679ecdee |
506 | } |
507 | } |
a1954302 |
508 | return Standard_False; |
679ecdee |
509 | } |
7fd59977 |
510 | |
679ecdee |
511 | // ======================================================================= |
512 | // function : SetZLayer |
513 | // purpose : |
514 | // ======================================================================= |
515 | void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
516 | const Standard_Integer theLayerId) |
517 | { |
0717ddc1 |
518 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
519 | { |
520 | SetZLayer (anIter.Value(), theLayerId); |
521 | } |
522 | if (!thePrsObj->HasOwnPresentations()) |
523 | { |
524 | return; |
525 | } |
a1954302 |
526 | |
527 | thePrsObj->SetZLayer (theLayerId); |
679ecdee |
528 | } |
7fd59977 |
529 | |
679ecdee |
530 | // ======================================================================= |
531 | // function : GetZLayer |
532 | // purpose : |
533 | // ======================================================================= |
534 | Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const |
535 | { |
a1954302 |
536 | return thePrsObj->ZLayer(); |
679ecdee |
537 | } |
7fd59977 |
538 | |
679ecdee |
539 | // ======================================================================= |
540 | // function : Connect |
541 | // purpose : |
542 | // ======================================================================= |
543 | void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject, |
544 | const Handle(PrsMgr_PresentableObject)& theOtherObject, |
545 | const Standard_Integer theMode, |
546 | const Standard_Integer theOtherMode) |
547 | { |
a1954302 |
548 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObject, theMode, Standard_True); |
549 | Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True); |
550 | aPrs->Connect (aPrsOther); |
7fd59977 |
551 | } |
552 | |
679ecdee |
553 | // ======================================================================= |
554 | // function : Transform |
555 | // purpose : |
556 | // ======================================================================= |
557 | void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
558 | const Handle(Geom_Transformation)& theTransformation, |
559 | const Standard_Integer theMode) |
560 | { |
1f7f5a90 |
561 | Presentation (thePrsObj, theMode)->SetTransformation (theTransformation); |
679ecdee |
562 | } |
7fd59977 |
563 | |
7fd59977 |
564 | |
679ecdee |
565 | // ======================================================================= |
566 | // function : Color |
567 | // purpose : |
568 | // ======================================================================= |
569 | void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
8e5fb5ea |
570 | const Handle(Graphic3d_HighlightStyle)& theStyle, |
a272ed94 |
571 | const Standard_Integer theMode, |
c3282ec1 |
572 | const Handle(PrsMgr_PresentableObject)& theSelObj, |
573 | const Standard_Integer theImmediateStructLayerId) |
7fd59977 |
574 | { |
0717ddc1 |
575 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
576 | { |
8e5fb5ea |
577 | Color (anIter.Value(), theStyle, theMode, NULL, theImmediateStructLayerId); |
0717ddc1 |
578 | } |
579 | if (!thePrsObj->HasOwnPresentations()) |
580 | { |
581 | return; |
582 | } |
583 | |
a272ed94 |
584 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True, theSelObj); |
679ecdee |
585 | if (aPrs->MustBeUpdated()) |
586 | { |
587 | Update (thePrsObj, theMode); |
588 | } |
59f45b7c |
589 | |
679ecdee |
590 | if (myImmediateModeOn > 0) |
591 | { |
592 | Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation()); |
c3282ec1 |
593 | aShadow->SetZLayer (theImmediateStructLayerId); |
3202bf1e |
594 | aShadow->SetClipPlanes (aPrs->Presentation()->ClipPlanes()); |
c3282ec1 |
595 | aShadow->CStructure()->IsForHighlight = 1; |
8e5fb5ea |
596 | aShadow->Highlight (theStyle); |
679ecdee |
597 | AddToImmediateList (aShadow); |
598 | } |
599 | else |
600 | { |
8e5fb5ea |
601 | aPrs->Highlight (theStyle); |
59f45b7c |
602 | } |
603 | } |
604 | |
5396886c |
605 | namespace |
606 | { |
607 | // ======================================================================= |
608 | // function : updatePrsTransformation |
1f7f5a90 |
609 | // purpose : Internal function that scans thePrsList for shadow presentations |
5396886c |
610 | // and applies transformation theTrsf to them in case if parent ID |
611 | // of shadow presentation is equal to theRefId |
612 | // ======================================================================= |
613 | void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList, |
614 | const Standard_Integer theRefId, |
1f7f5a90 |
615 | const Handle(Geom_Transformation)& theTrsf) |
5396886c |
616 | { |
617 | for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next()) |
618 | { |
619 | const Handle(Prs3d_Presentation)& aPrs = anIter.Value(); |
620 | if (aPrs.IsNull()) |
621 | continue; |
622 | |
623 | Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs); |
624 | if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId) |
625 | continue; |
626 | |
1f7f5a90 |
627 | aShadowPrs->CStructure()->SetTransformation (theTrsf); |
5396886c |
628 | } |
629 | } |
630 | } |
631 | |
632 | // ======================================================================= |
633 | // function : UpdateHighlightTrsf |
634 | // purpose : |
635 | // ======================================================================= |
636 | void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer, |
637 | const Handle(PrsMgr_PresentableObject)& theObj, |
638 | const Standard_Integer theMode, |
639 | const Handle(PrsMgr_PresentableObject)& theSelObj) |
640 | { |
641 | if (theObj.IsNull()) |
642 | return; |
643 | |
644 | const Handle(Prs3d_Presentation)& aBasePrs = Presentation (theObj, theMode, Standard_False)->Presentation(); |
645 | const Handle(Prs3d_Presentation)& aParentPrs = theSelObj.IsNull() ? |
646 | aBasePrs : Presentation (theSelObj, theMode, Standard_False)->Presentation(); |
647 | const Standard_Integer aParentId = aParentPrs->CStructure()->Id; |
648 | |
1f7f5a90 |
649 | updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation()); |
5396886c |
650 | |
651 | if (!myViewDependentImmediateList.IsEmpty()) |
652 | { |
6a24c6de |
653 | for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next()) |
5396886c |
654 | { |
6a24c6de |
655 | const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View(); |
5396886c |
656 | Handle(Graphic3d_Structure) aViewDepParentPrs; |
657 | if (aView->IsComputed (aParentId, aViewDepParentPrs)) |
658 | { |
659 | updatePrsTransformation (myViewDependentImmediateList, |
660 | aViewDepParentPrs->CStructure()->Id, |
1f7f5a90 |
661 | aBasePrs->CStructure()->Transformation()); |
5396886c |
662 | } |
663 | } |
664 | } |
665 | } |