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