0024977: There are compilation errors in products csharp sample
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
... / ...
CommitLineData
1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#include <PrsMgr_PresentationManager.ixx>
16
17#include <Graphic3d_GraphicDriver.hxx>
18#include <Prs3d_PresentationShadow.hxx>
19#include <PrsMgr_PresentableObject.hxx>
20#include <PrsMgr_Presentation.hxx>
21#include <PrsMgr_Presentations.hxx>
22#include <PrsMgr_ModedPresentation.hxx>
23#include <TColStd_ListIteratorOfListOfTransient.hxx>
24#include <V3d_View.hxx>
25#include <Visual3d_View.hxx>
26#include <Visual3d_Layer.hxx>
27
28// =======================================================================
29// function : PrsMgr_PresentationManager
30// purpose :
31// =======================================================================
32PrsMgr_PresentationManager::PrsMgr_PresentationManager (const Handle(Graphic3d_StructureManager)& theStructureManager)
33: myStructureManager (theStructureManager),
34 myImmediateModeOn (0)
35{
36 //
37}
38
39// =======================================================================
40// function : Display
41// purpose :
42// =======================================================================
43void PrsMgr_PresentationManager::Display (const Handle(PrsMgr_PresentableObject)& thePrsObj,
44 const Standard_Integer theMode)
45{
46 if (!HasPresentation (thePrsObj, theMode))
47 {
48 AddPresentation (thePrsObj, theMode);
49 }
50
51 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
52 if (aPrs->MustBeUpdated())
53 {
54 Update (thePrsObj, theMode);
55 }
56
57 if (myImmediateModeOn > 0)
58 {
59 AddToImmediateList (aPrs->Presentation());
60 }
61 else
62 {
63 aPrs->Display();
64 }
65}
66
67// =======================================================================
68// function : Erase
69// purpose :
70// =======================================================================
71void PrsMgr_PresentationManager::Erase (const Handle(PrsMgr_PresentableObject)& thePrsObj,
72 const Standard_Integer theMode)
73{
74 if (HasPresentation (thePrsObj, theMode))
75 {
76 Presentation (thePrsObj, theMode)->Erase();
77 RemovePresentation (thePrsObj, theMode);
78 }
79}
80
81// =======================================================================
82// function : Clear
83// purpose :
84// =======================================================================
85void PrsMgr_PresentationManager::Clear (const Handle(PrsMgr_PresentableObject)& thePrsObj,
86 const Standard_Integer theMode)
87{
88 if (HasPresentation (thePrsObj, theMode))
89 {
90 Presentation (thePrsObj, theMode)->Clear();
91 }
92}
93
94// =======================================================================
95// function : SetVisibility
96// purpose :
97// =======================================================================
98void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableObject)& thePresentableObject,
99 const Standard_Integer theMode,
100 const Standard_Boolean theValue)
101{
102 Presentation(thePresentableObject, theMode)->SetVisible (theValue);
103}
104
105// =======================================================================
106// function : Highlight
107// purpose :
108// =======================================================================
109void PrsMgr_PresentationManager::Highlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
110 const Standard_Integer theMode)
111{
112 if (!HasPresentation (thePrsObj, theMode))
113 {
114 AddPresentation (thePrsObj, theMode);
115 }
116
117 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
118 if (aPrs->MustBeUpdated())
119 {
120 Update (thePrsObj, theMode);
121 }
122
123 if (myImmediateModeOn > 0)
124 {
125 Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
126 aShadow->Highlight();
127 AddToImmediateList (aShadow);
128 }
129 else
130 {
131 aPrs->Highlight();
132 }
133}
134
135// =======================================================================
136// function : Unhighlight
137// purpose :
138// =======================================================================
139void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
140 const Standard_Integer theMode)
141{
142 if (HasPresentation (thePrsObj, theMode))
143 {
144 Presentation (thePrsObj, theMode)->Unhighlight();
145 }
146}
147
148// =======================================================================
149// function : SetDisplayPriority
150// purpose :
151// =======================================================================
152void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
153 const Standard_Integer theMode,
154 const Standard_Integer theNewPrior) const
155{
156 if (HasPresentation (thePrsObj, theMode))
157 {
158 Presentation (thePrsObj, theMode)->SetDisplayPriority (theNewPrior);
159 }
160}
161
162// =======================================================================
163// function : DisplayPriority
164// purpose :
165// =======================================================================
166Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
167 const Standard_Integer theMode) const
168{
169 return HasPresentation (thePrsObj, theMode)
170 ? Presentation (thePrsObj, theMode)->DisplayPriority()
171 : 0;
172}
173
174// =======================================================================
175// function : IsDisplayed
176// purpose :
177// =======================================================================
178Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj,
179 const Standard_Integer theMode) const
180{
181 return HasPresentation (thePrsObj, theMode)
182 && Presentation (thePrsObj, theMode)->IsDisplayed();
183}
184
185// =======================================================================
186// function : IsHighlighted
187// purpose :
188// =======================================================================
189Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj,
190 const Standard_Integer theMode) const
191{
192 return HasPresentation (thePrsObj, theMode)
193 && Presentation (thePrsObj, theMode)->IsHighlighted();
194}
195
196// =======================================================================
197// function : Update
198// purpose :
199// =======================================================================
200void PrsMgr_PresentationManager::Update (const Handle(PrsMgr_PresentableObject)& thePrsObj,
201 const Standard_Integer theMode) const
202{
203 if (!HasPresentation(thePrsObj, theMode))
204 {
205 return;
206 }
207
208 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
209 if (!aPrs.IsNull())
210 {
211 aPrs->Clear();
212 thePrsObj->Fill (this, aPrs, theMode);
213 aPrs->SetUpdateStatus (Standard_False);
214 }
215}
216
217// =======================================================================
218// function : BeginImmediateDraw
219// purpose :
220// =======================================================================
221void PrsMgr_PresentationManager::BeginImmediateDraw()
222{
223 if (++myImmediateModeOn > 1)
224 {
225 return;
226 }
227
228 ClearImmediateDraw();
229}
230
231// =======================================================================
232// function : ClearImmediateDraw
233// purpose :
234// =======================================================================
235void PrsMgr_PresentationManager::ClearImmediateDraw()
236{
237 if (myImmediateView.IsNull())
238 {
239 myImmediateList.Clear();
240 return;
241 }
242
243 for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
244 {
245 myImmediateView->View()->EraseImmediate (anIter.Value());
246 }
247
248 myImmediateList.Clear();
249 myImmediateView.Nullify();
250}
251
252// =======================================================================
253// function : EndImmediateDraw
254// purpose :
255// =======================================================================
256void PrsMgr_PresentationManager::EndImmediateDraw (const Handle(V3d_View)& theView)
257{
258 if (--myImmediateModeOn > 0)
259 {
260 return;
261 }
262
263 for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
264 {
265 theView->View()->DisplayImmediate (anIter.Value(), Standard_True);
266 }
267 if (!myImmediateList.IsEmpty())
268 {
269 myImmediateView = theView;
270 }
271}
272
273// =======================================================================
274// function : AddToImmediateList
275// purpose :
276//=======================================================================
277void PrsMgr_PresentationManager::AddToImmediateList (const Handle(Prs3d_Presentation)& thePrs)
278{
279 if (myImmediateModeOn < 1)
280 {
281 return;
282 }
283
284 for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
285 {
286 if (anIter.Value() == thePrs)
287 {
288 return;
289 }
290 }
291
292 myImmediateList.Append (thePrs);
293}
294
295// =======================================================================
296// function : HasPresentation
297// purpose :
298// =======================================================================
299Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
300 const Standard_Integer theMode) const
301{
302 const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
303 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
304 {
305 const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter);
306 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
307 if (theMode == aModedPrs.Mode()
308 && this == aPrsMgr)
309 {
310 return Standard_True;
311 }
312 }
313 return Standard_False;
314}
315
316// =======================================================================
317// function : Presentation
318// purpose :
319// =======================================================================
320Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
321 const Standard_Integer theMode) const
322{
323 const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
324 if (aPrsList.IsEmpty())
325 {
326 return Handle(PrsMgr_Presentation)();
327 }
328
329 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
330 {
331 const PrsMgr_ModedPresentation& aModedPrs = aPrsList.Value (aPrsIter);
332 const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
333 if (theMode == aModedPrs.Mode()
334 && this == aPrsMgr)
335 {
336 return aModedPrs.Presentation();
337 }
338 }
339
340 // To be changed within dedicated patch
341 ///return Handle(PrsMgr_Presentation)();
342 return aPrsList.Last().Presentation();
343}
344
345// =======================================================================
346// function : AddPresentation
347// purpose :
348// =======================================================================
349void PrsMgr_PresentationManager::AddPresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
350 const Standard_Integer theMode)
351{
352 Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj);
353 thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode));
354 thePrsObj->Fill (this, aPrs, theMode);
355
356 // set layer index accordingly to object's presentations
357 const Standard_Integer aZLayerId = GetZLayer (thePrsObj);
358 if (aZLayerId >= 0)
359 {
360 aPrs->SetZLayer (aZLayerId);
361 }
362 aPrs->SetUpdateStatus (Standard_False);
363}
364
365// =======================================================================
366// function : RemovePresentation
367// purpose :
368// =======================================================================
369void PrsMgr_PresentationManager::RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObj,
370 const Standard_Integer theMode)
371{
372 PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
373 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
374 {
375 if (theMode == aPrsList (aPrsIter).Mode())
376 // && this == aPrsMgr) ??
377 {
378 aPrsList.Remove (aPrsIter);
379 break;
380 }
381 }
382}
383
384// =======================================================================
385// function : SetZLayer
386// purpose :
387// =======================================================================
388void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj,
389 const Standard_Integer theLayerId)
390{
391 PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
392 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
393 {
394 Handle(PrsMgr_Presentation) aPrs = aPrsList.ChangeValue (aPrsIter).Presentation();
395 if (aPrs->PresentationManager() == this)
396 {
397 aPrs->SetZLayer (theLayerId);
398 }
399 }
400}
401
402// =======================================================================
403// function : GetZLayer
404// purpose :
405// =======================================================================
406Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
407{
408 const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
409 for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
410 {
411 Handle(PrsMgr_Presentation) aPrs = aPrsList.Value (aPrsIter).Presentation();
412 if (aPrs->PresentationManager() == this)
413 {
414 return aPrs->GetZLayer();
415 }
416 }
417 return -1;
418}
419
420// =======================================================================
421// function : Connect
422// purpose :
423// =======================================================================
424void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
425 const Handle(PrsMgr_PresentableObject)& theOtherObject,
426 const Standard_Integer theMode,
427 const Standard_Integer theOtherMode)
428{
429 if (!HasPresentation (thePrsObject, theMode))
430 {
431 AddPresentation (thePrsObject, theMode);
432 }
433 if (!HasPresentation (theOtherObject, theOtherMode))
434 {
435 AddPresentation (theOtherObject, theOtherMode);
436 }
437 Presentation (thePrsObject, theMode)->Connect (Presentation (theOtherObject, theMode));
438}
439
440// =======================================================================
441// function : Transform
442// purpose :
443// =======================================================================
444void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj,
445 const Handle(Geom_Transformation)& theTransformation,
446 const Standard_Integer theMode)
447{
448 Presentation (thePrsObj, theMode)->Transform (theTransformation);
449}
450
451// =======================================================================
452// function : Place
453// purpose :
454// =======================================================================
455void PrsMgr_PresentationManager::Place (const Handle(PrsMgr_PresentableObject)& thePrsObj,
456 const Quantity_Length theX,
457 const Quantity_Length theY,
458 const Quantity_Length theZ,
459 const Standard_Integer theMode)
460{
461 Presentation (thePrsObj, theMode)->Place (theX, theY, theZ);
462}
463
464// =======================================================================
465// function : Multiply
466// purpose :
467// =======================================================================
468void PrsMgr_PresentationManager::Multiply (const Handle(PrsMgr_PresentableObject)& thePrsObj,
469 const Handle(Geom_Transformation)& theTransformation,
470 const Standard_Integer theMode)
471{
472 Presentation (thePrsObj, theMode)->Multiply (theTransformation);
473}
474
475// =======================================================================
476// function : Move
477// purpose :
478// =======================================================================
479void PrsMgr_PresentationManager::Move (const Handle(PrsMgr_PresentableObject)& thePrsObj,
480 const Quantity_Length theX,
481 const Quantity_Length theY,
482 const Quantity_Length theZ,
483 const Standard_Integer theMode)
484{
485 Presentation (thePrsObj, theMode)->Move (theX, theY, theZ);
486}
487
488// =======================================================================
489// function : Color
490// purpose :
491// =======================================================================
492void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj,
493 const Quantity_NameOfColor theColor,
494 const Standard_Integer theMode)
495{
496 if (!HasPresentation (thePrsObj, theMode))
497 {
498 AddPresentation (thePrsObj, theMode);
499 }
500
501 Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
502 if (aPrs->MustBeUpdated())
503 {
504 Update (thePrsObj, theMode);
505 }
506
507 if (myImmediateModeOn > 0)
508 {
509 Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
510 aShadow->Color (theColor);
511 AddToImmediateList (aShadow);
512 }
513 else
514 {
515 aPrs->Color (theColor);
516 }
517}
518
519// =======================================================================
520// function : BoundBox
521// purpose :
522// =======================================================================
523void PrsMgr_PresentationManager::BoundBox (const Handle(PrsMgr_PresentableObject)& thePrsObject,
524 const Standard_Integer theMode)
525{
526 if (!HasPresentation (thePrsObject, theMode))
527 {
528 AddPresentation (thePrsObject, theMode);
529 }
530 else if (Presentation (thePrsObject, theMode)->MustBeUpdated())
531 {
532 Update (thePrsObject, theMode);
533 }
534 Presentation (thePrsObject, theMode)->BoundBox();
535}
536
537// =======================================================================
538// function : SetShadingAspect
539// purpose :
540// =======================================================================
541void PrsMgr_PresentationManager::SetShadingAspect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
542 const Quantity_NameOfColor theColor,
543 const Graphic3d_NameOfMaterial theMaterial,
544 const Standard_Integer theMode)
545{
546 Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
547 anAspect->SetColor (theColor);
548 anAspect->SetMaterial (theMaterial);
549 SetShadingAspect (thePrsObject, anAspect, theMode);
550}
551
552// =======================================================================
553// function : SetShadingAspect
554// purpose :
555// =======================================================================
556void PrsMgr_PresentationManager::SetShadingAspect (const Handle(PrsMgr_PresentableObject)& thePrsObject,
557 const Handle(Prs3d_ShadingAspect)& theShadingAspect,
558 const Standard_Integer theMode)
559{
560 if (HasPresentation (thePrsObject, theMode))
561 {
562 Presentation (thePrsObject, theMode)->SetShadingAspect (theShadingAspect);
563 }
564}