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 | |
404c8936 |
156 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
157 | if (!aPrs.IsNull()) |
158 | { |
159 | aPrs->SetVisible (theValue); |
160 | } |
eb4320f2 |
161 | } |
7fd59977 |
162 | |
679ecdee |
163 | // ======================================================================= |
164 | // function : Unhighlight |
165 | // purpose : |
166 | // ======================================================================= |
167 | void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
168 | const Standard_Integer theMode) |
7fd59977 |
169 | { |
0717ddc1 |
170 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
171 | { |
172 | Unhighlight (anIter.Value(), theMode); |
173 | } |
174 | |
a1954302 |
175 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
176 | if (!aPrs.IsNull()) |
679ecdee |
177 | { |
a1954302 |
178 | aPrs->Unhighlight(); |
7fd59977 |
179 | } |
180 | } |
181 | |
679ecdee |
182 | // ======================================================================= |
183 | // function : SetDisplayPriority |
184 | // purpose : |
185 | // ======================================================================= |
186 | void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
187 | const Standard_Integer theMode, |
188 | const Standard_Integer theNewPrior) const |
189 | { |
0717ddc1 |
190 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
191 | { |
192 | SetDisplayPriority (anIter.Value(), theMode, theNewPrior); |
193 | } |
194 | |
a1954302 |
195 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
196 | if (!aPrs.IsNull()) |
679ecdee |
197 | { |
a1954302 |
198 | aPrs->SetDisplayPriority (theNewPrior); |
679ecdee |
199 | } |
200 | } |
7fd59977 |
201 | |
679ecdee |
202 | // ======================================================================= |
203 | // function : DisplayPriority |
204 | // purpose : |
205 | // ======================================================================= |
206 | Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
207 | const Standard_Integer theMode) const |
7fd59977 |
208 | { |
0717ddc1 |
209 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
210 | { |
211 | Standard_Integer aPriority = DisplayPriority (anIter.Value(), theMode); |
212 | if (aPriority != 0) |
213 | { |
214 | return aPriority; |
215 | } |
216 | } |
217 | |
a1954302 |
218 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
219 | return !aPrs.IsNull() |
220 | ? aPrs->DisplayPriority() |
221 | : 0; |
7fd59977 |
222 | } |
223 | |
679ecdee |
224 | // ======================================================================= |
225 | // function : IsDisplayed |
226 | // purpose : |
227 | // ======================================================================= |
228 | Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
229 | const Standard_Integer theMode) const |
7fd59977 |
230 | { |
0717ddc1 |
231 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
232 | { |
233 | if (IsDisplayed (anIter.Value(), theMode)) |
234 | { |
235 | return Standard_True; |
236 | } |
237 | } |
238 | |
a1954302 |
239 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
240 | return !aPrs.IsNull() |
241 | && aPrs->IsDisplayed(); |
7fd59977 |
242 | } |
243 | |
679ecdee |
244 | // ======================================================================= |
245 | // function : IsHighlighted |
246 | // purpose : |
247 | // ======================================================================= |
248 | Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
249 | const Standard_Integer theMode) const |
250 | { |
0717ddc1 |
251 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
252 | { |
253 | if (IsHighlighted (anIter.Value(), theMode)) |
254 | { |
255 | return Standard_True; |
256 | } |
257 | } |
258 | |
a1954302 |
259 | const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
260 | return !aPrs.IsNull() |
261 | && aPrs->IsHighlighted(); |
679ecdee |
262 | } |
7fd59977 |
263 | |
679ecdee |
264 | // ======================================================================= |
265 | // function : Update |
266 | // purpose : |
267 | // ======================================================================= |
268 | void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
269 | const Standard_Integer theMode) const |
270 | { |
0717ddc1 |
271 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
272 | { |
273 | Update (anIter.Value(), theMode); |
274 | } |
7fd59977 |
275 | |
679ecdee |
276 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode); |
277 | if (!aPrs.IsNull()) |
278 | { |
279 | aPrs->Clear(); |
280 | thePrsObj->Fill (this, aPrs, theMode); |
281 | aPrs->SetUpdateStatus (Standard_False); |
282 | } |
283 | } |
7fd59977 |
284 | |
679ecdee |
285 | // ======================================================================= |
286 | // function : BeginImmediateDraw |
287 | // purpose : |
288 | // ======================================================================= |
289 | void PrsMgr_PresentationManager::BeginImmediateDraw() |
290 | { |
291 | if (++myImmediateModeOn > 1) |
292 | { |
293 | return; |
7fd59977 |
294 | } |
679ecdee |
295 | |
296 | ClearImmediateDraw(); |
7fd59977 |
297 | } |
679ecdee |
298 | |
299 | // ======================================================================= |
300 | // function : ClearImmediateDraw |
301 | // purpose : |
302 | // ======================================================================= |
303 | void PrsMgr_PresentationManager::ClearImmediateDraw() |
304 | { |
c3282ec1 |
305 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
679ecdee |
306 | { |
c3282ec1 |
307 | anIter.Value()->Erase(); |
679ecdee |
308 | } |
309 | |
c3282ec1 |
310 | for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next()) |
679ecdee |
311 | { |
c3282ec1 |
312 | anIter.Value()->Erase(); |
679ecdee |
313 | } |
314 | |
7fd59977 |
315 | myImmediateList.Clear(); |
c3282ec1 |
316 | myViewDependentImmediateList.Clear(); |
317 | } |
318 | |
319 | // ======================================================================= |
320 | // function : displayImmediate |
321 | // purpose : Handles the structures from myImmediateList and its visibility |
322 | // in all views of the viewer given by setting proper affinity |
323 | // ======================================================================= |
324 | void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& theViewer) |
325 | { |
6a24c6de |
326 | for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next()) |
c3282ec1 |
327 | { |
6a24c6de |
328 | const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View(); |
c3282ec1 |
329 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
330 | { |
331 | const Handle(Prs3d_Presentation)& aPrs = anIter.Value(); |
332 | if (aPrs.IsNull()) |
333 | continue; |
334 | |
aa00364d |
335 | Handle(Graphic3d_Structure) aViewDepPrs; |
c3282ec1 |
336 | Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs); |
337 | if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs)) |
338 | { |
339 | aShadowPrs.Nullify(); |
aa00364d |
340 | aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, |
341 | Handle(Prs3d_Presentation)::DownCast (aViewDepPrs)); |
c3282ec1 |
342 | aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer()); |
3202bf1e |
343 | aShadowPrs->SetClipPlanes (aViewDepPrs->ClipPlanes()); |
c3282ec1 |
344 | aShadowPrs->CStructure()->IsForHighlight = 1; |
8e5fb5ea |
345 | aShadowPrs->Highlight (aPrs->HighlightStyle()); |
c3282ec1 |
346 | myViewDependentImmediateList.Append (aShadowPrs); |
347 | } |
c357e426 |
348 | // handles custom highlight presentations which were defined in overridden |
c3282ec1 |
349 | // HilightOwnerWithColor method of a custom AIS objects and maintain its |
350 | // visibility in different views on their own |
351 | else if (aShadowPrs.IsNull()) |
352 | { |
353 | aPrs->Display(); |
354 | continue; |
355 | } |
356 | |
357 | if (!aShadowPrs->IsDisplayed()) |
358 | { |
359 | aShadowPrs->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity(); |
360 | aShadowPrs->CStructure()->ViewAffinity->SetVisible (Standard_False); |
361 | aShadowPrs->Display(); |
362 | } |
363 | |
364 | Standard_Integer aViewId = aView->Identification(); |
365 | bool isParentVisible = aShadowPrs->ParentAffinity().IsNull() ? |
366 | Standard_True : aShadowPrs->ParentAffinity()->IsVisible (aViewId); |
367 | aShadowPrs->CStructure()->ViewAffinity->SetVisible (aViewId, isParentVisible); |
368 | } |
369 | } |
7fd59977 |
370 | } |
371 | |
679ecdee |
372 | // ======================================================================= |
373 | // function : EndImmediateDraw |
374 | // purpose : |
375 | // ======================================================================= |
c3282ec1 |
376 | void PrsMgr_PresentationManager::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer) |
679ecdee |
377 | { |
378 | if (--myImmediateModeOn > 0) |
379 | { |
380 | return; |
381 | } |
382 | |
c3282ec1 |
383 | displayImmediate (theViewer); |
384 | } |
385 | |
386 | // ======================================================================= |
387 | // function : RedrawImmediate |
388 | // purpose : Clears all immediate structures and redisplays with proper |
389 | // affinity |
390 | //======================================================================= |
391 | void PrsMgr_PresentationManager::RedrawImmediate (const Handle(V3d_Viewer)& theViewer) |
392 | { |
393 | if (myImmediateList.IsEmpty()) |
394 | return; |
395 | |
396 | // Clear previously displayed structures |
679ecdee |
397 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
398 | { |
c3282ec1 |
399 | anIter.Value()->Erase(); |
679ecdee |
400 | } |
c3282ec1 |
401 | for (PrsMgr_ListOfPresentations::Iterator anIter (myViewDependentImmediateList); anIter.More(); anIter.Next()) |
679ecdee |
402 | { |
c3282ec1 |
403 | anIter.Value()->Erase(); |
679ecdee |
404 | } |
c3282ec1 |
405 | myViewDependentImmediateList.Clear(); |
406 | |
407 | displayImmediate (theViewer); |
679ecdee |
408 | } |
7fd59977 |
409 | |
679ecdee |
410 | // ======================================================================= |
411 | // function : AddToImmediateList |
412 | // purpose : |
413 | //======================================================================= |
414 | void PrsMgr_PresentationManager::AddToImmediateList (const Handle(Prs3d_Presentation)& thePrs) |
415 | { |
416 | if (myImmediateModeOn < 1) |
417 | { |
418 | return; |
419 | } |
420 | |
421 | for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) |
422 | { |
423 | if (anIter.Value() == thePrs) |
424 | { |
425 | return; |
7fd59977 |
426 | } |
679ecdee |
427 | } |
428 | |
429 | myImmediateList.Append (thePrs); |
430 | } |
431 | |
432 | // ======================================================================= |
433 | // function : HasPresentation |
434 | // purpose : |
435 | // ======================================================================= |
436 | Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
437 | const Standard_Integer theMode) const |
438 | { |
0717ddc1 |
439 | if (!thePrsObj->HasOwnPresentations()) |
440 | return Standard_False; |
441 | |
679ecdee |
442 | const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
443 | for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter) |
444 | { |
445 | const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter); |
446 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
447 | if (theMode == aModedPrs.Mode() |
448 | && this == aPrsMgr) |
449 | { |
450 | return Standard_True; |
7fd59977 |
451 | } |
452 | } |
679ecdee |
453 | return Standard_False; |
7fd59977 |
454 | } |
455 | |
679ecdee |
456 | // ======================================================================= |
457 | // function : Presentation |
458 | // purpose : |
459 | // ======================================================================= |
460 | Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
a1954302 |
461 | const Standard_Integer theMode, |
a272ed94 |
462 | const Standard_Boolean theToCreate, |
463 | const Handle(PrsMgr_PresentableObject)& theSelObj) const |
679ecdee |
464 | { |
465 | const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
679ecdee |
466 | for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter) |
467 | { |
468 | const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter); |
469 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
470 | if (theMode == aModedPrs.Mode() |
471 | && this == aPrsMgr) |
472 | { |
473 | return aModedPrs.Presentation(); |
474 | } |
475 | } |
7fd59977 |
476 | |
a1954302 |
477 | if (!theToCreate) |
478 | { |
479 | return Handle(PrsMgr_Presentation)(); |
480 | } |
7fd59977 |
481 | |
af324faa |
482 | Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj); |
a1954302 |
483 | aPrs->SetZLayer (thePrsObj->ZLayer()); |
a272ed94 |
484 | aPrs->Presentation()->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj); |
679ecdee |
485 | thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode)); |
486 | thePrsObj->Fill (this, aPrs, theMode); |
7fd59977 |
487 | |
679ecdee |
488 | // set layer index accordingly to object's presentations |
679ecdee |
489 | aPrs->SetUpdateStatus (Standard_False); |
a1954302 |
490 | return aPrs; |
679ecdee |
491 | } |
7fd59977 |
492 | |
679ecdee |
493 | // ======================================================================= |
494 | // function : RemovePresentation |
495 | // purpose : |
496 | // ======================================================================= |
a1954302 |
497 | Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
498 | const Standard_Integer theMode) |
7fd59977 |
499 | { |
679ecdee |
500 | PrsMgr_Presentations& aPrsList = thePrsObj->Presentations(); |
501 | for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter) |
502 | { |
a1954302 |
503 | const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter); |
504 | const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager(); |
505 | if (theMode == aPrsList (aPrsIter).Mode() |
506 | && this == aPrsMgr) |
679ecdee |
507 | { |
508 | aPrsList.Remove (aPrsIter); |
a1954302 |
509 | return Standard_True; |
679ecdee |
510 | } |
511 | } |
a1954302 |
512 | return Standard_False; |
679ecdee |
513 | } |
7fd59977 |
514 | |
679ecdee |
515 | // ======================================================================= |
516 | // function : SetZLayer |
517 | // purpose : |
518 | // ======================================================================= |
519 | void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
520 | const Standard_Integer theLayerId) |
521 | { |
0717ddc1 |
522 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
523 | { |
524 | SetZLayer (anIter.Value(), theLayerId); |
525 | } |
526 | if (!thePrsObj->HasOwnPresentations()) |
527 | { |
528 | return; |
529 | } |
a1954302 |
530 | |
531 | thePrsObj->SetZLayer (theLayerId); |
679ecdee |
532 | } |
7fd59977 |
533 | |
679ecdee |
534 | // ======================================================================= |
535 | // function : GetZLayer |
536 | // purpose : |
537 | // ======================================================================= |
538 | Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const |
539 | { |
a1954302 |
540 | return thePrsObj->ZLayer(); |
679ecdee |
541 | } |
7fd59977 |
542 | |
679ecdee |
543 | // ======================================================================= |
544 | // function : Connect |
545 | // purpose : |
546 | // ======================================================================= |
547 | void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject, |
548 | const Handle(PrsMgr_PresentableObject)& theOtherObject, |
549 | const Standard_Integer theMode, |
550 | const Standard_Integer theOtherMode) |
551 | { |
a1954302 |
552 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObject, theMode, Standard_True); |
553 | Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True); |
554 | aPrs->Connect (aPrsOther); |
7fd59977 |
555 | } |
556 | |
679ecdee |
557 | // ======================================================================= |
558 | // function : Transform |
559 | // purpose : |
560 | // ======================================================================= |
561 | void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
562 | const Handle(Geom_Transformation)& theTransformation, |
563 | const Standard_Integer theMode) |
564 | { |
1f7f5a90 |
565 | Presentation (thePrsObj, theMode)->SetTransformation (theTransformation); |
679ecdee |
566 | } |
7fd59977 |
567 | |
7fd59977 |
568 | |
679ecdee |
569 | // ======================================================================= |
570 | // function : Color |
571 | // purpose : |
572 | // ======================================================================= |
573 | void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj, |
8e5fb5ea |
574 | const Handle(Graphic3d_HighlightStyle)& theStyle, |
a272ed94 |
575 | const Standard_Integer theMode, |
c3282ec1 |
576 | const Handle(PrsMgr_PresentableObject)& theSelObj, |
577 | const Standard_Integer theImmediateStructLayerId) |
7fd59977 |
578 | { |
0717ddc1 |
579 | for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next()) |
580 | { |
8e5fb5ea |
581 | Color (anIter.Value(), theStyle, theMode, NULL, theImmediateStructLayerId); |
0717ddc1 |
582 | } |
583 | if (!thePrsObj->HasOwnPresentations()) |
584 | { |
585 | return; |
586 | } |
587 | |
a272ed94 |
588 | Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True, theSelObj); |
679ecdee |
589 | if (aPrs->MustBeUpdated()) |
590 | { |
591 | Update (thePrsObj, theMode); |
592 | } |
59f45b7c |
593 | |
679ecdee |
594 | if (myImmediateModeOn > 0) |
595 | { |
596 | Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation()); |
c3282ec1 |
597 | aShadow->SetZLayer (theImmediateStructLayerId); |
3202bf1e |
598 | aShadow->SetClipPlanes (aPrs->Presentation()->ClipPlanes()); |
c3282ec1 |
599 | aShadow->CStructure()->IsForHighlight = 1; |
8e5fb5ea |
600 | aShadow->Highlight (theStyle); |
679ecdee |
601 | AddToImmediateList (aShadow); |
602 | } |
603 | else |
604 | { |
8e5fb5ea |
605 | aPrs->Highlight (theStyle); |
59f45b7c |
606 | } |
607 | } |
608 | |
5396886c |
609 | namespace |
610 | { |
611 | // ======================================================================= |
612 | // function : updatePrsTransformation |
1f7f5a90 |
613 | // purpose : Internal function that scans thePrsList for shadow presentations |
5396886c |
614 | // and applies transformation theTrsf to them in case if parent ID |
615 | // of shadow presentation is equal to theRefId |
616 | // ======================================================================= |
617 | void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList, |
618 | const Standard_Integer theRefId, |
1f7f5a90 |
619 | const Handle(Geom_Transformation)& theTrsf) |
5396886c |
620 | { |
621 | for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next()) |
622 | { |
623 | const Handle(Prs3d_Presentation)& aPrs = anIter.Value(); |
624 | if (aPrs.IsNull()) |
625 | continue; |
626 | |
627 | Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs); |
628 | if (aShadowPrs.IsNull() || aShadowPrs->ParentId() != theRefId) |
629 | continue; |
630 | |
1f7f5a90 |
631 | aShadowPrs->CStructure()->SetTransformation (theTrsf); |
5396886c |
632 | } |
633 | } |
634 | } |
635 | |
636 | // ======================================================================= |
637 | // function : UpdateHighlightTrsf |
638 | // purpose : |
639 | // ======================================================================= |
640 | void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer, |
641 | const Handle(PrsMgr_PresentableObject)& theObj, |
642 | const Standard_Integer theMode, |
643 | const Handle(PrsMgr_PresentableObject)& theSelObj) |
644 | { |
645 | if (theObj.IsNull()) |
646 | return; |
647 | |
7bbccb5f |
648 | Handle(PrsMgr_Presentation) aPrs = Presentation (!theSelObj.IsNull() ? theSelObj : theObj, theMode, Standard_False); |
649 | if (aPrs.IsNull()) |
650 | { |
651 | return; |
652 | } |
5396886c |
653 | |
7bbccb5f |
654 | Handle(Geom_Transformation) aTrsf = theObj->LocalTransformationGeom(); |
655 | const Standard_Integer aParentId = aPrs->Presentation()->CStructure()->Id; |
656 | updatePrsTransformation (myImmediateList, aParentId, aTrsf); |
5396886c |
657 | |
658 | if (!myViewDependentImmediateList.IsEmpty()) |
659 | { |
6a24c6de |
660 | for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next()) |
5396886c |
661 | { |
6a24c6de |
662 | const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View(); |
5396886c |
663 | Handle(Graphic3d_Structure) aViewDepParentPrs; |
664 | if (aView->IsComputed (aParentId, aViewDepParentPrs)) |
665 | { |
666 | updatePrsTransformation (myViewDependentImmediateList, |
667 | aViewDepParentPrs->CStructure()->Id, |
7bbccb5f |
668 | aTrsf); |
5396886c |
669 | } |
670 | } |
671 | } |
672 | } |