0026792: Visualization, Graphic3d - Z-fit support for transform persistence is missin...
[occt.git] / src / Graphic3d / Graphic3d_CView.cxx
CommitLineData
c357e426 1// Copyright (c) 2015 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <Graphic3d_CView.hxx>
15#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
16#include <Graphic3d_StructureManager.hxx>
17
18//=======================================================================
19//function : Constructor
20//purpose :
21//=======================================================================
22Graphic3d_CView::Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr)
23: myStructureManager (theMgr),
24 myHiddenObjects (new Graphic3d_NMapOfTransient()),
25 myIsInComputedMode (Standard_False),
26 myIsActive (Standard_False),
27 myIsRemoved (Standard_False),
28 myVisualization (Graphic3d_TOV_WIREFRAME)
29{
30 myId = myStructureManager->Identification (this);
31}
32
33//=======================================================================
34//function : Destructor
35//purpose :
36//=======================================================================
37Graphic3d_CView::~Graphic3d_CView()
38{
39 if (!IsRemoved())
40 {
41 myStructureManager->UnIdentification (this);
42 }
43}
44
45// =======================================================================
46// function : Activate
47// purpose :
48// =======================================================================
49void Graphic3d_CView::Activate()
50{
51 if (!IsActive())
52 {
53 myIsActive = Standard_True;
54
55 // Activation of a new view =>
56 // Display structures that can be displayed in this new view.
57 // All structures with status
58 // Displayed in ViewManager are returned and displayed in
59 // the view directly, if the structure is not already
60 // displayed and if the view accepts it in its context.
61 Graphic3d_MapOfStructure aDisplayedStructs;
62 myStructureManager->DisplayedStructures (aDisplayedStructs);
63 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
64 {
65 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
66 if (IsDisplayed (aStruct))
67 {
68 continue;
69 }
70
71 // If the structure can be displayed in the new context of the view, it is displayed.
72 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
73 if (anAnswer == Graphic3d_TOA_YES
74 || anAnswer == Graphic3d_TOA_COMPUTE)
75 {
76 Display (aStruct, Aspect_TOU_WAIT);
77 }
78 }
79 }
80
81 Update (myStructureManager->UpdateMode());
82}
83
84// =======================================================================
85// function : Deactivate
86// purpose :
87// =======================================================================
88void Graphic3d_CView::Deactivate()
89{
90 if (IsActive())
91 {
92 // Deactivation of a view =>
93 // Removal of structures displayed in this view.
94 // All structures with status
95 // Displayed in ViewManager are returned and removed from
96 // the view directly, if the structure is not already
97 // displayed and if the view accepts it in its context.
98 Graphic3d_MapOfStructure aDisplayedStructs;
99 myStructureManager->DisplayedStructures (aDisplayedStructs);
100 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
101 {
102 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
103 if (!IsDisplayed (aStruct))
104 {
105 continue;
106 }
107
108 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
109 if (anAnswer == Graphic3d_TOA_YES
110 || anAnswer == Graphic3d_TOA_COMPUTE)
111 {
112 Erase (aStruct, Aspect_TOU_WAIT);
113 }
114 }
115
116 Update (myStructureManager->UpdateMode());
117 myIsActive = Standard_False;
118 }
119}
120
121// ========================================================================
122// function : Remove
123// purpose :
124// ========================================================================
125void Graphic3d_CView::Remove()
126{
127 if (IsRemoved())
128 {
129 return;
130 }
131
132 Graphic3d_MapOfStructure aDisplayedStructs (myStructsDisplayed);
133
134 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
135 {
136 Erase (aStructIter.Value(), Aspect_TOU_WAIT);
137 }
138
139 myStructsToCompute.Clear();
140 myStructsComputed .Clear();
141 myStructsDisplayed.Clear();
142
143 if (!myStructureManager.IsNull())
144 {
145 myStructureManager->UnIdentification (this);
146 }
147
148 myIsActive = Standard_False;
149 myIsRemoved = Standard_True;
150}
151
152// ========================================================================
153// function : SetComputedMode
154// purpose :
155// ========================================================================
156void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode)
157{
158 if (( theMode && myIsInComputedMode)
159 || (!theMode && !myIsInComputedMode))
160 {
161 return;
162 }
163
164 myIsInComputedMode = theMode;
165 if (!myIsInComputedMode)
166 {
167 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
168 {
169 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
170 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
171 if (anAnswer != Graphic3d_TOA_COMPUTE)
172 {
173 continue;
174 }
175
176 const Standard_Integer anIndex = IsComputed (aStruct);
177 if (anIndex != 0)
178 {
179 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
180 eraseStructure (aStructComp->CStructure());
181 displayStructure (aStruct->CStructure(), aStruct->DisplayPriority());
182 }
183 }
184 return;
185 }
186
187 for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
188 {
189 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
190 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
191 if (anAnswer != Graphic3d_TOA_COMPUTE)
192 {
193 continue;
194 }
195
196 const Standard_Integer anIndex = IsComputed (aStruct);
197 if (anIndex != 0)
198 {
199 eraseStructure (aStruct->CStructure());
200 displayStructure (myStructsComputed.Value (anIndex)->CStructure(), aStruct->DisplayPriority());
201
202 Display (aStruct, Aspect_TOU_WAIT);
203 if (aStruct->IsHighlighted())
204 {
205 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
206 if (!aCompStruct->IsHighlighted())
207 {
208 aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False);
209 }
210 }
211 }
212 else
213 {
214 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
215 aStruct->Transform (aTrsf);
216 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
217 aCompStruct->SetHLRValidation (Standard_True);
218
219 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
220 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
221 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
222 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
223 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
224 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
225
226 if (aStruct->IsHighlighted())
227 {
228 aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False);
229 }
230
231 Standard_Boolean hasResult = Standard_False;
232 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
233 const Standard_Integer aStructId = aStruct->Identification();
234 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
235 {
236 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
237 {
238 hasResult = Standard_True;
239 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
240 break;
241 }
242 }
243
244 if (!hasResult)
245 {
246 myStructsToCompute.Append (aStruct);
247 myStructsComputed .Append (aCompStruct);
248 }
249
250 eraseStructure (aStruct->CStructure());
251 displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
252 }
253 }
254 Update (myStructureManager->UpdateMode());
255}
256
257// =======================================================================
258// function : ReCompute
259// purpose :
260// =======================================================================
261void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
262{
263 theStruct->CalculateBoundBox();
264 if (!theStruct->IsMutable()
265 && !theStruct->CStructure()->IsForHighlight
266 && !theStruct->CStructure()->IsInfinite)
267 {
268 const Standard_Integer aLayerId = theStruct->DisplayPriority();
269 InvalidateBVHData (aLayerId);
270 }
271
272 if (!ComputedMode()
273 || !IsActive()
274 || !theStruct->IsDisplayed())
275 {
276 return;
277 }
278
279 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual());
280 if (anAnswer != Graphic3d_TOA_COMPUTE)
281 {
282 return;
283 }
284
285 const Standard_Integer anIndex = IsComputed (theStruct);
286 if (anIndex == 0)
287 {
288 return;
289 }
290
291 // compute + validation
292 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
293 for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
294 {
295 for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
296 {
297 anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
298 }
299 }
300 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
301 theStruct->Transform (aTrsf);
302
303 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
304 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
305 aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
306 theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
307 : theStruct->Compute (this, aCompStruct);
308 aCompStruct->SetHLRValidation (Standard_True);
309
310 // of which type will be the computed?
311 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
312 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
313 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
314 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
315 if (toComputeWireframe)
316 {
317 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
318 }
319 else if (toComputeShading)
320 {
321 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
322 }
323
324 if (theStruct->IsHighlighted())
325 {
326 aCompStruct->Highlight (Aspect_TOHM_COLOR, theStruct->HighlightColor(), Standard_False);
327 }
328
329 // The previous calculation is removed and the new one is displayed
330 eraseStructure (aCompStructOld->CStructure());
331 displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority());
332
333 // why not just replace existing items?
334 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
335 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
336
337 // hlhsr and the new associated compute are added
338 myStructsToCompute.Append (theStruct);
339 myStructsComputed .Append (aCompStruct);
340
341 // hlhsr and the new associated compute are removed
342 myStructsToCompute.Remove (anIndex);
343 myStructsComputed .Remove (anIndex);
344}
345
346// =======================================================================
347// function : Update
348// purpose :
349// =======================================================================
350void Graphic3d_CView::Update (const Aspect_TypeOfUpdate theUpdateMode)
351{
352 myMinMax.Invalidate();
353 if (theUpdateMode == Aspect_TOU_ASAP)
354 {
355 Compute();
356 Redraw();
357 }
358}
359
360// =======================================================================
361// function : ContainsFacet
362// purpose :
363// =======================================================================
364Standard_Boolean Graphic3d_CView::ContainsFacet() const
365{
366 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
367 {
368 if (aStructIter.Key()->ContainsFacet())
369 {
370 return Standard_True;
371 }
372 }
373 return Standard_False;
374}
375
376// =======================================================================
377// function : ContainsFacet
378// purpose :
379// =======================================================================
380Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
381{
382 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
383 {
384 if (aStructIter.Key()->ContainsFacet())
385 {
386 return Standard_True;
387 }
388 }
389 return Standard_False;
390}
391
392// =======================================================================
393// function : DisplayedStructures
394// purpose :
395// =======================================================================
396void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
397{
398 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
399 {
400 theStructures.Add (aStructIter.Key());
401 }
402}
403
c357e426 404// =======================================================================
405// function : MinMaxValues
406// purpose :
407// =======================================================================
408Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
409{
410 if (myMinMax.IsOutdated (theToIgnoreInfiniteFlag))
411 {
412 myMinMax.BoundingBox (theToIgnoreInfiniteFlag) = MinMaxValues (myStructsDisplayed, theToIgnoreInfiniteFlag);
413 myMinMax.IsOutdated (theToIgnoreInfiniteFlag) = Standard_False;
414 }
415
416 return myMinMax.BoundingBox (theToIgnoreInfiniteFlag);
417}
418
419// =======================================================================
420// function : MinMaxValues
421// purpose :
422// =======================================================================
423Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
424 const Standard_Boolean theToIgnoreInfiniteFlag) const
425{
426 Bnd_Box aResult;
427 const Standard_Integer aViewId = Identification();
97f937cc 428
429 Handle(Graphic3d_Camera) aCamera = Camera();
430 Standard_Integer aWinWidth = 0;
431 Standard_Integer aWinHeight = 0;
432 if (IsDefined())
433 {
434 Window()->Size (aWinWidth, aWinHeight);
435 }
436
c357e426 437 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
438 {
439 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
97f937cc 440 if (!aStructure->IsVisible() || aStructure->IsEmpty())
441 {
442 continue;
443 }
444 else if (!aStructure->CStructure()->ViewAffinity.IsNull()
445 && !aStructure->CStructure()->ViewAffinity->IsVisible (aViewId))
446 {
447 continue;
448 }
449
450 // "FitAll" operation ignores object with transform persistence parameter
451 if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None)
452 {
453 // Panning and 2d persistence apply changes to projection or/and its translation components.
454 // It makes them incompatible with z-fitting algorithm. Ignored by now.
455 if (!theToIgnoreInfiniteFlag ||
456 (aStructure->TransformPersistence().Flags & Graphic3d_TMF_2d) ||
457 (aStructure->TransformPersistence().Flags & Graphic3d_TMF_PanPers) ||
458 (aStructure->TransformPersistence().Flags & Graphic3d_TMF_TriedronPers))
459 {
460 continue;
461 }
462 }
463
464 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
465
466 if (aBox.IsWhole() || aBox.IsVoid())
c357e426 467 {
468 continue;
469 }
97f937cc 470
471 if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None)
472 {
473 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
474 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
475 aStructure->TransformPersistence().Apply (aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
476 }
477
478 // To prevent float overflow at camera parameters calculation and further
479 // rendering, bounding boxes with at least one vertex coordinate out of
480 // float range are skipped by view fit algorithms
481 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
482 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
483 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
484 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
485 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
486 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
c357e426 487 {
488 continue;
489 }
490
97f937cc 491 aResult.Add (aBox);
c357e426 492 }
493 return aResult;
494}
495
496// =======================================================================
497// function : acceptDisplay
498// purpose :
499// =======================================================================
500Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
501{
502 switch (theStructType)
503 {
504 case Graphic3d_TOS_ALL:
505 {
506 return Graphic3d_TOA_YES; // The structure accepts any type of view
507 }
508 case Graphic3d_TOS_SHADING:
509 {
510 return myVisualization == Graphic3d_TOV_SHADING
511 ? Graphic3d_TOA_YES
512 : Graphic3d_TOA_NO;
513 }
514 case Graphic3d_TOS_WIREFRAME:
515 {
516 return myVisualization == Graphic3d_TOV_WIREFRAME
517 ? Graphic3d_TOA_YES
518 : Graphic3d_TOA_NO;
519 }
520 case Graphic3d_TOS_COMPUTED:
521 {
522 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
523 ? Graphic3d_TOA_COMPUTE
524 : Graphic3d_TOA_NO;
525 }
526 }
527 return Graphic3d_TOA_NO;
528}
529
530// =======================================================================
531// function : Compute
532// purpose :
533// =======================================================================
534void Graphic3d_CView::Compute()
535{
536 // force HLRValidation to False on all structures calculated in the view
537 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
538 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
539 {
540 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
541 }
542
543 if (!ComputedMode())
544 {
545 return;
546 }
547
548 // Change of orientation or of projection type =>
549 // Remove structures that were calculated for the previous orientation.
550 // Recalculation of new structures.
551 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
552 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
553 {
554 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
555 if (anAnswer == Graphic3d_TOA_COMPUTE)
556 {
557 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
558 }
559 }
560
561 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
562 {
563 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
564 }
565}
566
567// =======================================================================
568// function : Clear
569// purpose :
570// =======================================================================
571void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
572 const Standard_Boolean theWithDestruction)
573{
574 const Standard_Integer anIndex = IsComputed (theStructure);
575 if (anIndex != 0)
576 {
577 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
578 aCompStruct->GraphicClear (theWithDestruction);
579 aCompStruct->SetHLRValidation (Standard_False);
580 }
581}
582
583// =======================================================================
584// function : Connect
585// purpose :
586// =======================================================================
587void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
588 const Handle(Graphic3d_Structure)& theDaughter)
589{
590 Standard_Integer anIndexM = IsComputed (theMother);
591 Standard_Integer anIndexD = IsComputed (theDaughter);
592 if (anIndexM != 0
593 && anIndexD != 0)
594 {
595 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
596 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
597 aStructM->GraphicConnect (aStructD);
598 }
599}
600
601// =======================================================================
602// function : Disconnect
603// purpose :
604// =======================================================================
605void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
606 const Handle(Graphic3d_Structure)& theDaughter)
607{
608 Standard_Integer anIndexM = IsComputed (theMother);
609 Standard_Integer anIndexD = IsComputed (theDaughter);
610 if (anIndexM != 0
611 && anIndexD != 0)
612 {
613 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
614 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
615 aStructM->GraphicDisconnect (aStructD);
616 }
617}
618
619// =======================================================================
620// function : Display
621// purpose :
622// =======================================================================
623void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
624{
625 Display (theStructure, myStructureManager->UpdateMode());
626}
627
628// =======================================================================
629// function : Display
630// purpose :
631// =======================================================================
632void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
633 const Aspect_TypeOfUpdate theUpdateMode)
634{
635 if (!IsActive())
636 {
637 return;
638 }
639
640 // If Display on a structure present in the list of calculated structures while it is not
641 // or more, of calculated type =>
642 // - removes it as well as the associated old computed
643 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
644 Standard_Integer anIndex = IsComputed (theStructure);
645 if (anIndex != 0
646 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
647 {
648 myStructsToCompute.Remove (anIndex);
649 myStructsComputed .Remove (anIndex);
650 anIndex = 0;
651 }
652
653 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
654 if (anAnswer == Graphic3d_TOA_NO)
655 {
656 return;
657 }
658
659 if (!ComputedMode())
660 {
661 anAnswer = Graphic3d_TOA_YES;
662 }
663
664 if (anAnswer == Graphic3d_TOA_YES)
665 {
666 if (!myStructsDisplayed.Add (theStructure))
667 {
668 return;
669 }
670
671 theStructure->CalculateBoundBox();
672 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
673 Update (theUpdateMode);
674 return;
675 }
676 else if (anAnswer != Graphic3d_TOA_COMPUTE)
677 {
678 return;
679 }
680
681 if (anIndex != 0)
682 {
683 // Already computed, is COMPUTED still valid?
684 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
685 if (anOldStruct->HLRValidation())
686 {
687 // Case COMPUTED valid, to be displayed
688 if (!myStructsDisplayed.Add (theStructure))
689 {
690 return;
691 }
692
693 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
694 Update (theUpdateMode);
695 return;
696 }
697 else
698 {
699 // Case COMPUTED invalid
700 // Is there another valid representation?
701 // Find in the sequence of already calculated structures
702 // 1/ Structure having the same Owner as <AStructure>
703 // 2/ That is not <AStructure>
704 // 3/ The COMPUTED which of is valid
705 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
706 if (aNewIndex != 0)
707 {
708 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
709 if (!myStructsDisplayed.Add (theStructure))
710 {
711 return;
712 }
713
714 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
715 myStructsComputed.SetValue (anIndex, aNewStruct);
716 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
717 Update (theUpdateMode);
718 return;
719 }
720 else
721 {
722 // Case COMPUTED invalid, WITHOUT a valid of replacement
723 // COMPUTED is removed if displayed
724 if (myStructsDisplayed.Contains (theStructure))
725 {
726 eraseStructure (anOldStruct->CStructure());
727 }
728 }
729 }
730 }
731
732 // Compute + Validation
733 Handle(Graphic3d_Structure) aStruct;
734 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
735 theStructure->Transform (aTrsf);
736 if (anIndex != 0)
737 {
738 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
739 for (Standard_Integer ii = 0; ii <= 3; ++ii)
740 {
741 for (Standard_Integer jj = 0; jj <= 3; ++jj)
742 {
743 anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
744 }
745 }
746
747 aStruct = myStructsComputed.Value (anIndex);
748 aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
749 if (theStructure->IsTransformed())
750 {
751 theStructure->Compute (this, aTrsf, aStruct);
752 }
753 else
754 {
755 theStructure->Compute (this, aStruct);
756 }
757 }
758 else
759 {
760 aStruct = theStructure->IsTransformed()
761 ? theStructure->Compute (this, aTrsf)
762 : theStructure->Compute (this);
763 }
764
765 aStruct->SetHLRValidation (Standard_True);
766
767 // TOCOMPUTE and COMPUTED associated to sequences are added
768 myStructsToCompute.Append (theStructure);
769 myStructsComputed .Append (aStruct);
770
771 // The previous are removed if necessary
772 if (anIndex != 0)
773 {
774 myStructsToCompute.Remove (anIndex);
775 myStructsComputed .Remove (anIndex);
776 }
777
778 // Of which type will be the computed?
779 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
780 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
781 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
782 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
783 if (!toComputeShading && !toComputeWireframe)
784 {
785 anAnswer = Graphic3d_TOA_NO;
786 }
787 else
788 {
789 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
790 anAnswer = acceptDisplay (aStruct->Visual());
791 }
792
793 if (theStructure->IsHighlighted())
794 {
795 aStruct->Highlight (Aspect_TOHM_COLOR, theStructure->HighlightColor(), Standard_False);
796 }
797
798 // It is displayed only if the calculated structure
799 // has a proper type corresponding to the one of the view.
800 if (anAnswer == Graphic3d_TOA_NO)
801 {
802 return;
803 }
804
805 myStructsDisplayed.Add (theStructure);
806 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
807
808 Update (theUpdateMode);
809}
810
811// =======================================================================
812// function : Erase
813// purpose :
814// =======================================================================
815void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
816{
817 Erase (theStructure, myStructureManager->UpdateMode());
818}
819
820// =======================================================================
821// function : Erase
822// purpose :
823// =======================================================================
824void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure,
825 const Aspect_TypeOfUpdate theUpdateMode)
826{
827 if (!IsDisplayed (theStructure))
828 {
829 return;
830 }
831
832 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
833 if (!ComputedMode())
834 {
835 anAnswer = Graphic3d_TOA_YES;
836 }
837
838 if (anAnswer != Graphic3d_TOA_COMPUTE)
839 {
840 eraseStructure (theStructure->CStructure());
841 }
842 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
843 {
844 const Standard_Integer anIndex = IsComputed (theStructure);
845 if (anIndex != 0)
846 {
847 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
848 eraseStructure (aCompStruct->CStructure());
849 }
850 }
851 myStructsDisplayed.Remove (theStructure);
852 Update (theUpdateMode);
853}
854
855// =======================================================================
856// function : Highlight
857// purpose :
858// =======================================================================
859void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure,
860 const Aspect_TypeOfHighlightMethod theMethod)
861{
862 const Standard_Integer anIndex = IsComputed (theStructure);
863 if (anIndex != 0)
864 {
865 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
866 aCompStruct->Highlight (theMethod, theStructure->HighlightColor(), Standard_False);
867 }
868}
869
870// =======================================================================
871// function : SetTransform
872// purpose :
873// =======================================================================
874void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
875 const TColStd_Array2OfReal& theTrsf)
876{
877 const Standard_Integer anIndex = IsComputed (theStructure);
878 if (anIndex != 0)
879 {
880 // Test is somewhat light !
881 // trsf is transferred only if it is :
882 // a translation
883 // a scale
884 if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
885 || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
886 || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
887 {
888 ReCompute (theStructure);
889 }
890 else
891 {
892 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
893 aCompStruct->GraphicTransform (theTrsf);
894 }
895 }
896
897 theStructure->CalculateBoundBox();
898 if (!theStructure->IsMutable()
899 && !theStructure->CStructure()->IsForHighlight
900 && !theStructure->CStructure()->IsInfinite)
901 {
902 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
903 InvalidateBVHData (aLayerId);
904 }
905}
906
907// =======================================================================
908// function : UnHighlight
909// purpose :
910// =======================================================================
911void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
912{
913 Standard_Integer anIndex = IsComputed (theStructure);
914 if (anIndex != 0)
915 {
916 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
917 aCompStruct->GraphicUnHighlight();
918 }
919}
920
921// ========================================================================
922// function : IsComputed
923// purpose :
924// ========================================================================
925Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
926 Handle(Graphic3d_Structure)& theComputedStruct) const
927{
928 theComputedStruct.Nullify();
929 if (!ComputedMode())
930 return Standard_False;
931
932 const Standard_Integer aNbStructs = myStructsToCompute.Length();
933 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
934 {
935 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
936 {
937 theComputedStruct = myStructsComputed (aStructIter);
938 return Standard_True;
939 }
940 }
941 return Standard_False;
942}
943
944// =======================================================================
945// function : IsComputed
946// purpose :
947// =======================================================================
948Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
949{
950 const Standard_Integer aStructId = theStructure->Identification();
951 const Standard_Integer aNbStructs = myStructsToCompute.Length();
952 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
953 {
954 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
955 if (aStruct->Identification() == aStructId)
956 {
957 return aStructIter;
958 }
959 }
960 return 0;
961}
962
963// =======================================================================
964// function : IsDisplayed
965// purpose :
966// =======================================================================
967Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
968{
969 return myStructsDisplayed.Contains (theStructure);
970}
971
972// =======================================================================
973// function : ChangePriority
974// purpose :
975// =======================================================================
976void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
977 const Standard_Integer /*theOldPriority*/,
978 const Standard_Integer theNewPriority)
979{
980 if (!IsActive()
981 || !IsDisplayed (theStructure))
982 {
983 return;
984 }
985
986 if (!myIsInComputedMode)
987 {
988 changePriority (theStructure->CStructure(), theNewPriority);
989 return;
990 }
991
992 const Standard_Integer anIndex = IsComputed (theStructure);
993 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
994 ? myStructsComputed.Value (anIndex)->CStructure()
995 : theStructure->CStructure();
996
997 changePriority (aCStruct, theNewPriority);
998}
999
1000// =======================================================================
1001// function : ChangeZLayer
1002// purpose :
1003// =======================================================================
1004void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1005 const Graphic3d_ZLayerId theLayerId)
1006{
1007 if (!IsActive()
1008 || !IsDisplayed (theStructure))
1009 {
1010 return;
1011 }
1012
1013 if (!myIsInComputedMode)
1014 {
1015 changeZLayer (theStructure->CStructure(), theLayerId);
1016 return;
1017 }
1018
1019 const Standard_Integer anIndex = IsComputed (theStructure);
1020 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1021 ? myStructsComputed.Value (anIndex)->CStructure()
1022 : theStructure->CStructure();
1023
1024 changeZLayer (aCStruct, theLayerId);
1025}
1026
1027// =======================================================================
1028// function : HaveTheSameOwner
1029// purpose :
1030// =======================================================================
1031Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1032{
1033 // Find in the sequence of already calculated structures
1034 // 1/ Structure with the same Owner as <AStructure>
1035 // 2/ Which is not <AStructure>
1036 // 3/ COMPUTED which of is valid
1037 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1038 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1039 {
1040 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1041 if (aStructToComp->Owner() == theStructure->Owner()
1042 && aStructToComp->Identification() != theStructure->Identification())
1043 {
1044 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1045 if (aStructComp->HLRValidation())
1046 {
1047 return aStructIter;
1048 }
1049 }
1050 }
1051 return 0;
1052}
1053
1054// =======================================================================
1055// function : CopySettings
1056// purpose :
1057// =======================================================================
1058void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1059{
1060 ChangeRenderingParams() = theOther->RenderingParams();
1061 SetAntialiasingEnabled (theOther->IsAntialiasingEnabled());
1062 SetBackground (theOther->Background());
1063 SetGradientBackground (theOther->GradientBackground());
1064 SetBackgroundImage (theOther->BackgroundImage());
1065 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1066 SetTextureEnv (theOther->TextureEnv());
1067 SetCullingEnabled (theOther->IsCullingEnabled());
1068 SetShadingModel (theOther->ShadingModel());
1069 SetSurfaceDetailType (theOther->SurfaceDetailType());
1070 SetBackfacingModel (theOther->BackfacingModel());
1071 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1072 SetBackZClippingOn (theOther->BackZClippingIsOn());
1073 SetFrontZClippingOn (theOther->FrontZClippingIsOn());
1074 SetZClippingBackPlane (theOther->ZClippingBackPlane());
1075 SetZClippingFrontPlane (theOther->ZClippingFrontPlane());
1076 SetDepthCueingOn (theOther->DepthCueingIsOn());
1077 SetDepthCueingBackPlane (theOther->DepthCueingBackPlane());
1078 SetDepthCueingFrontPlane (theOther->DepthCueingFrontPlane());
1079 SetGLLightEnabled (theOther->IsGLLightEnabled());
1080 SetLights (theOther->Lights());
1081 SetClipPlanes (theOther->ClipPlanes());
1082}