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