1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Graphic3d_CView.hxx>
15 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
16 #include <Graphic3d_StructureManager.hxx>
18 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CView,Graphic3d_DataStructureManager)
22 static const int THE_DEFAULT_LAYERS[] = { Graphic3d_ZLayerId_Top,
23 Graphic3d_ZLayerId_Topmost,
24 Graphic3d_ZLayerId_BotOSD,
25 Graphic3d_ZLayerId_TopOSD };
27 static const int THE_NB_DEFAULT_LAYERS = sizeof(THE_DEFAULT_LAYERS) / sizeof(*THE_DEFAULT_LAYERS);
29 void combineBox (Bnd_Box& aCombined, const Graphic3d_BndBox4f& theBox)
33 aCombined.Add (gp_Pnt (theBox.CornerMin().x(),
34 theBox.CornerMin().y(),
35 theBox.CornerMin().z()));
36 aCombined.Add (gp_Pnt (theBox.CornerMax().x(),
37 theBox.CornerMax().y(),
38 theBox.CornerMax().z()));
43 //=======================================================================
44 //function : Constructor
46 //=======================================================================
47 Graphic3d_CView::Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr)
48 : myStructureManager (theMgr),
49 myHiddenObjects (new Graphic3d_NMapOfTransient()),
50 myIsInComputedMode (Standard_False),
51 myIsActive (Standard_False),
52 myIsRemoved (Standard_False),
53 myVisualization (Graphic3d_TOV_WIREFRAME)
55 myId = myStructureManager->Identification (this);
58 //=======================================================================
59 //function : Destructor
61 //=======================================================================
62 Graphic3d_CView::~Graphic3d_CView()
66 myStructureManager->UnIdentification (this);
70 // =======================================================================
71 // function : Activate
73 // =======================================================================
74 void Graphic3d_CView::Activate()
78 myIsActive = Standard_True;
80 // Activation of a new view =>
81 // Display structures that can be displayed in this new view.
82 // All structures with status
83 // Displayed in ViewManager are returned and displayed in
84 // the view directly, if the structure is not already
85 // displayed and if the view accepts it in its context.
86 Graphic3d_MapOfStructure aDisplayedStructs;
87 myStructureManager->DisplayedStructures (aDisplayedStructs);
88 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
90 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
91 if (IsDisplayed (aStruct))
96 // If the structure can be displayed in the new context of the view, it is displayed.
97 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
98 if (anAnswer == Graphic3d_TOA_YES
99 || anAnswer == Graphic3d_TOA_COMPUTE)
101 Display (aStruct, Aspect_TOU_WAIT);
106 Update (myStructureManager->UpdateMode());
109 // =======================================================================
110 // function : Deactivate
112 // =======================================================================
113 void Graphic3d_CView::Deactivate()
117 // Deactivation of a view =>
118 // Removal of structures displayed in this view.
119 // All structures with status
120 // Displayed in ViewManager are returned and removed from
121 // the view directly, if the structure is not already
122 // displayed and if the view accepts it in its context.
123 Graphic3d_MapOfStructure aDisplayedStructs;
124 myStructureManager->DisplayedStructures (aDisplayedStructs);
125 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
127 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
128 if (!IsDisplayed (aStruct))
133 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
134 if (anAnswer == Graphic3d_TOA_YES
135 || anAnswer == Graphic3d_TOA_COMPUTE)
137 Erase (aStruct, Aspect_TOU_WAIT);
141 Update (myStructureManager->UpdateMode());
142 myIsActive = Standard_False;
146 // ========================================================================
149 // ========================================================================
150 void Graphic3d_CView::Remove()
157 Graphic3d_MapOfStructure aDisplayedStructs (myStructsDisplayed);
159 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
161 Erase (aStructIter.Value(), Aspect_TOU_WAIT);
164 myStructsToCompute.Clear();
165 myStructsComputed .Clear();
166 myStructsDisplayed.Clear();
168 if (!myStructureManager.IsNull())
170 myStructureManager->UnIdentification (this);
173 myIsActive = Standard_False;
174 myIsRemoved = Standard_True;
177 // ========================================================================
178 // function : SetComputedMode
180 // ========================================================================
181 void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode)
183 if (( theMode && myIsInComputedMode)
184 || (!theMode && !myIsInComputedMode))
189 myIsInComputedMode = theMode;
190 if (!myIsInComputedMode)
192 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
194 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
195 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
196 if (anAnswer != Graphic3d_TOA_COMPUTE)
201 const Standard_Integer anIndex = IsComputed (aStruct);
204 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
205 eraseStructure (aStructComp->CStructure());
206 displayStructure (aStruct->CStructure(), aStruct->DisplayPriority());
212 for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
214 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
215 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
216 if (anAnswer != Graphic3d_TOA_COMPUTE)
221 const Standard_Integer anIndex = IsComputed (aStruct);
224 eraseStructure (aStruct->CStructure());
225 displayStructure (myStructsComputed.Value (anIndex)->CStructure(), aStruct->DisplayPriority());
227 Display (aStruct, Aspect_TOU_WAIT);
228 if (aStruct->IsHighlighted())
230 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
231 if (!aCompStruct->IsHighlighted())
233 aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False);
239 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
240 aStruct->Transform (aTrsf);
241 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
242 aCompStruct->SetHLRValidation (Standard_True);
244 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
245 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
246 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
247 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
248 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
249 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
251 if (aStruct->IsHighlighted())
253 aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False);
256 Standard_Boolean hasResult = Standard_False;
257 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
258 const Standard_Integer aStructId = aStruct->Identification();
259 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
261 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
263 hasResult = Standard_True;
264 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
271 myStructsToCompute.Append (aStruct);
272 myStructsComputed .Append (aCompStruct);
275 eraseStructure (aStruct->CStructure());
276 displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
279 Update (myStructureManager->UpdateMode());
282 // =======================================================================
283 // function : ReCompute
285 // =======================================================================
286 void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
288 theStruct->CalculateBoundBox();
289 if (!theStruct->IsMutable()
290 && !theStruct->CStructure()->IsForHighlight
291 && !theStruct->CStructure()->IsInfinite)
293 const Standard_Integer aLayerId = theStruct->DisplayPriority();
294 InvalidateBVHData (aLayerId);
299 || !theStruct->IsDisplayed())
304 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual());
305 if (anAnswer != Graphic3d_TOA_COMPUTE)
310 const Standard_Integer anIndex = IsComputed (theStruct);
316 // compute + validation
317 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
318 for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
320 for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
322 anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
325 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
326 theStruct->Transform (aTrsf);
328 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
329 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
330 aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
331 theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
332 : theStruct->Compute (this, aCompStruct);
333 aCompStruct->SetHLRValidation (Standard_True);
335 // of which type will be the computed?
336 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
337 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
338 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
339 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
340 if (toComputeWireframe)
342 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
344 else if (toComputeShading)
346 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
349 if (theStruct->IsHighlighted())
351 aCompStruct->Highlight (Aspect_TOHM_COLOR, theStruct->HighlightColor(), Standard_False);
354 // The previous calculation is removed and the new one is displayed
355 eraseStructure (aCompStructOld->CStructure());
356 displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority());
358 // why not just replace existing items?
359 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
360 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
362 // hlhsr and the new associated compute are added
363 myStructsToCompute.Append (theStruct);
364 myStructsComputed .Append (aCompStruct);
366 // hlhsr and the new associated compute are removed
367 myStructsToCompute.Remove (anIndex);
368 myStructsComputed .Remove (anIndex);
371 // =======================================================================
374 // =======================================================================
375 void Graphic3d_CView::Update (const Aspect_TypeOfUpdate theUpdateMode,
376 const Graphic3d_ZLayerId theLayerId)
378 InvalidateZLayerBoundingBox (theLayerId);
380 if (theUpdateMode == Aspect_TOU_ASAP)
387 // =======================================================================
388 // function : ContainsFacet
390 // =======================================================================
391 Standard_Boolean Graphic3d_CView::ContainsFacet() const
393 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
395 if (aStructIter.Key()->ContainsFacet())
397 return Standard_True;
400 return Standard_False;
403 // =======================================================================
404 // function : ContainsFacet
406 // =======================================================================
407 Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
409 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
411 if (aStructIter.Key()->ContainsFacet())
413 return Standard_True;
416 return Standard_False;
419 // =======================================================================
420 // function : DisplayedStructures
422 // =======================================================================
423 void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
425 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
427 theStructures.Add (aStructIter.Key());
431 // =======================================================================
432 // function : MinMaxValues
434 // =======================================================================
435 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
444 Handle(Graphic3d_Camera) aCamera = Camera();
445 Standard_Integer aWinWidth = 0;
446 Standard_Integer aWinHeight = 0;
448 Window()->Size (aWinWidth, aWinHeight);
450 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
452 Graphic3d_BndBox4f aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
456 theToIncludeAuxiliary);
457 combineBox (aResult, aBox);
460 Standard_Integer aMaxZLayer = ZLayerMax();
461 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
463 Graphic3d_BndBox4f aBox = ZLayerBoundingBox (aLayerId,
467 theToIncludeAuxiliary);
468 combineBox (aResult, aBox);
474 // =======================================================================
475 // function : ConsiderZoomPersistenceObjects
477 // =======================================================================
478 Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
485 Handle(Graphic3d_Camera) aCamera = Camera();
486 Standard_Integer aWinWidth = 0;
487 Standard_Integer aWinHeight = 0;
489 Window()->Size (aWinWidth, aWinHeight);
491 Standard_Real aMaxCoef = 1.0;
492 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
494 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
497 for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
499 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
505 // =======================================================================
506 // function : MinMaxValues
508 // =======================================================================
509 Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
510 const Standard_Boolean theToIgnoreInfiniteFlag) const
513 const Standard_Integer aViewId = Identification();
515 Handle(Graphic3d_Camera) aCamera = Camera();
516 Standard_Integer aWinWidth = 0;
517 Standard_Integer aWinHeight = 0;
520 Window()->Size (aWinWidth, aWinHeight);
523 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
525 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
526 if (aStructure->IsEmpty()
527 || !aStructure->CStructure()->IsVisible (aViewId))
532 // "FitAll" operation ignores object with transform persistence parameter
533 if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None)
535 // Panning and 2d persistence apply changes to projection or/and its translation components.
536 // It makes them incompatible with z-fitting algorithm. Ignored by now.
537 if (!theToIgnoreInfiniteFlag ||
538 (aStructure->TransformPersistence().Flags & Graphic3d_TMF_2d) ||
539 (aStructure->TransformPersistence().Flags & Graphic3d_TMF_PanPers) ||
540 (aStructure->TransformPersistence().Flags & Graphic3d_TMF_TriedronPers))
546 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
548 if (aBox.IsWhole() || aBox.IsVoid())
553 if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None)
555 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
556 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
557 aStructure->TransformPersistence().Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
560 // To prevent float overflow at camera parameters calculation and further
561 // rendering, bounding boxes with at least one vertex coordinate out of
562 // float range are skipped by view fit algorithms
563 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
564 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
565 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
566 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
567 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
568 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
578 // =======================================================================
579 // function : acceptDisplay
581 // =======================================================================
582 Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
584 switch (theStructType)
586 case Graphic3d_TOS_ALL:
588 return Graphic3d_TOA_YES; // The structure accepts any type of view
590 case Graphic3d_TOS_SHADING:
592 return myVisualization == Graphic3d_TOV_SHADING
596 case Graphic3d_TOS_WIREFRAME:
598 return myVisualization == Graphic3d_TOV_WIREFRAME
602 case Graphic3d_TOS_COMPUTED:
604 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
605 ? Graphic3d_TOA_COMPUTE
609 return Graphic3d_TOA_NO;
612 // =======================================================================
613 // function : Compute
615 // =======================================================================
616 void Graphic3d_CView::Compute()
618 // force HLRValidation to False on all structures calculated in the view
619 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
620 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
622 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
630 // Change of orientation or of projection type =>
631 // Remove structures that were calculated for the previous orientation.
632 // Recalculation of new structures.
633 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
634 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
636 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
637 if (anAnswer == Graphic3d_TOA_COMPUTE)
639 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
643 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
645 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
649 // =======================================================================
652 // =======================================================================
653 void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
654 const Standard_Boolean theWithDestruction)
656 const Standard_Integer anIndex = IsComputed (theStructure);
659 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
660 aCompStruct->GraphicClear (theWithDestruction);
661 aCompStruct->SetHLRValidation (Standard_False);
665 // =======================================================================
666 // function : Connect
668 // =======================================================================
669 void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
670 const Handle(Graphic3d_Structure)& theDaughter)
672 Standard_Integer anIndexM = IsComputed (theMother);
673 Standard_Integer anIndexD = IsComputed (theDaughter);
677 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
678 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
679 aStructM->GraphicConnect (aStructD);
683 // =======================================================================
684 // function : Disconnect
686 // =======================================================================
687 void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
688 const Handle(Graphic3d_Structure)& theDaughter)
690 Standard_Integer anIndexM = IsComputed (theMother);
691 Standard_Integer anIndexD = IsComputed (theDaughter);
695 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
696 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
697 aStructM->GraphicDisconnect (aStructD);
701 // =======================================================================
702 // function : Display
704 // =======================================================================
705 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
707 Display (theStructure, myStructureManager->UpdateMode());
710 // =======================================================================
711 // function : Display
713 // =======================================================================
714 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
715 const Aspect_TypeOfUpdate theUpdateMode)
722 // If Display on a structure present in the list of calculated structures while it is not
723 // or more, of calculated type =>
724 // - removes it as well as the associated old computed
725 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
726 Standard_Integer anIndex = IsComputed (theStructure);
728 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
730 myStructsToCompute.Remove (anIndex);
731 myStructsComputed .Remove (anIndex);
735 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
736 if (anAnswer == Graphic3d_TOA_NO)
743 anAnswer = Graphic3d_TOA_YES;
746 if (anAnswer == Graphic3d_TOA_YES)
748 if (!myStructsDisplayed.Add (theStructure))
753 theStructure->CalculateBoundBox();
754 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
755 Update (theUpdateMode, theStructure->GetZLayer());
758 else if (anAnswer != Graphic3d_TOA_COMPUTE)
765 // Already computed, is COMPUTED still valid?
766 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
767 if (anOldStruct->HLRValidation())
769 // Case COMPUTED valid, to be displayed
770 if (!myStructsDisplayed.Add (theStructure))
775 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
776 Update (theUpdateMode, anOldStruct->GetZLayer());
781 // Case COMPUTED invalid
782 // Is there another valid representation?
783 // Find in the sequence of already calculated structures
784 // 1/ Structure having the same Owner as <AStructure>
785 // 2/ That is not <AStructure>
786 // 3/ The COMPUTED which of is valid
787 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
790 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
791 if (!myStructsDisplayed.Add (theStructure))
796 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
797 myStructsComputed.SetValue (anIndex, aNewStruct);
798 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
799 Update (theUpdateMode, aNewStruct->GetZLayer());
804 // Case COMPUTED invalid, WITHOUT a valid of replacement
805 // COMPUTED is removed if displayed
806 if (myStructsDisplayed.Contains (theStructure))
808 eraseStructure (anOldStruct->CStructure());
814 // Compute + Validation
815 Handle(Graphic3d_Structure) aStruct;
816 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
817 theStructure->Transform (aTrsf);
820 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
821 for (Standard_Integer ii = 0; ii <= 3; ++ii)
823 for (Standard_Integer jj = 0; jj <= 3; ++jj)
825 anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
829 aStruct = myStructsComputed.Value (anIndex);
830 aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
831 if (theStructure->IsTransformed())
833 theStructure->Compute (this, aTrsf, aStruct);
837 theStructure->Compute (this, aStruct);
842 aStruct = theStructure->IsTransformed()
843 ? theStructure->Compute (this, aTrsf)
844 : theStructure->Compute (this);
847 aStruct->SetHLRValidation (Standard_True);
849 // TOCOMPUTE and COMPUTED associated to sequences are added
850 myStructsToCompute.Append (theStructure);
851 myStructsComputed .Append (aStruct);
853 // The previous are removed if necessary
856 myStructsToCompute.Remove (anIndex);
857 myStructsComputed .Remove (anIndex);
860 // Of which type will be the computed?
861 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
862 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
863 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
864 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
865 if (!toComputeShading && !toComputeWireframe)
867 anAnswer = Graphic3d_TOA_NO;
871 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
872 anAnswer = acceptDisplay (aStruct->Visual());
875 if (theStructure->IsHighlighted())
877 aStruct->Highlight (Aspect_TOHM_COLOR, theStructure->HighlightColor(), Standard_False);
880 // It is displayed only if the calculated structure
881 // has a proper type corresponding to the one of the view.
882 if (anAnswer == Graphic3d_TOA_NO)
887 myStructsDisplayed.Add (theStructure);
888 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
890 Update (theUpdateMode, aStruct->GetZLayer());
893 // =======================================================================
896 // =======================================================================
897 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
899 Erase (theStructure, myStructureManager->UpdateMode());
902 // =======================================================================
905 // =======================================================================
906 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure,
907 const Aspect_TypeOfUpdate theUpdateMode)
909 if (!IsDisplayed (theStructure))
914 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
917 anAnswer = Graphic3d_TOA_YES;
920 if (anAnswer != Graphic3d_TOA_COMPUTE)
922 eraseStructure (theStructure->CStructure());
924 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
926 const Standard_Integer anIndex = IsComputed (theStructure);
929 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
930 eraseStructure (aCompStruct->CStructure());
933 myStructsDisplayed.Remove (theStructure);
934 Update (theUpdateMode, theStructure->GetZLayer());
937 // =======================================================================
938 // function : Highlight
940 // =======================================================================
941 void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure,
942 const Aspect_TypeOfHighlightMethod theMethod)
944 const Standard_Integer anIndex = IsComputed (theStructure);
947 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
948 aCompStruct->Highlight (theMethod, theStructure->HighlightColor(), Standard_False);
952 // =======================================================================
953 // function : SetTransform
955 // =======================================================================
956 void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
957 const TColStd_Array2OfReal& theTrsf)
959 const Standard_Integer anIndex = IsComputed (theStructure);
962 // Test is somewhat light !
963 // trsf is transferred only if it is :
966 if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
967 || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
968 || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
970 ReCompute (theStructure);
974 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
975 aCompStruct->GraphicTransform (theTrsf);
979 theStructure->CalculateBoundBox();
980 if (!theStructure->IsMutable()
981 && !theStructure->CStructure()->IsForHighlight
982 && !theStructure->CStructure()->IsInfinite)
984 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
985 InvalidateBVHData (aLayerId);
989 // =======================================================================
990 // function : UnHighlight
992 // =======================================================================
993 void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
995 Standard_Integer anIndex = IsComputed (theStructure);
998 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
999 aCompStruct->GraphicUnHighlight();
1003 // ========================================================================
1004 // function : IsComputed
1006 // ========================================================================
1007 Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
1008 Handle(Graphic3d_Structure)& theComputedStruct) const
1010 theComputedStruct.Nullify();
1011 if (!ComputedMode())
1012 return Standard_False;
1014 const Standard_Integer aNbStructs = myStructsToCompute.Length();
1015 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1017 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
1019 theComputedStruct = myStructsComputed (aStructIter);
1020 return Standard_True;
1023 return Standard_False;
1026 // =======================================================================
1027 // function : IsComputed
1029 // =======================================================================
1030 Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
1032 const Standard_Integer aStructId = theStructure->Identification();
1033 const Standard_Integer aNbStructs = myStructsToCompute.Length();
1034 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1036 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
1037 if (aStruct->Identification() == aStructId)
1045 // =======================================================================
1046 // function : IsDisplayed
1048 // =======================================================================
1049 Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
1051 return myStructsDisplayed.Contains (theStructure);
1054 // =======================================================================
1055 // function : ChangePriority
1057 // =======================================================================
1058 void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
1059 const Standard_Integer /*theOldPriority*/,
1060 const Standard_Integer theNewPriority)
1063 || !IsDisplayed (theStructure))
1068 if (!myIsInComputedMode)
1070 changePriority (theStructure->CStructure(), theNewPriority);
1074 const Standard_Integer anIndex = IsComputed (theStructure);
1075 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
1076 ? myStructsComputed.Value (anIndex)->CStructure()
1077 : theStructure->CStructure();
1079 changePriority (aCStruct, theNewPriority);
1082 // =======================================================================
1083 // function : ChangeZLayer
1085 // =======================================================================
1086 void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1087 const Graphic3d_ZLayerId theLayerId)
1090 || !IsDisplayed (theStructure))
1095 if (!myIsInComputedMode)
1097 changeZLayer (theStructure->CStructure(), theLayerId);
1101 const Standard_Integer anIndex = IsComputed (theStructure);
1102 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1103 ? myStructsComputed.Value (anIndex)->CStructure()
1104 : theStructure->CStructure();
1106 changeZLayer (aCStruct, theLayerId);
1109 // =======================================================================
1110 // function : HaveTheSameOwner
1112 // =======================================================================
1113 Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1115 // Find in the sequence of already calculated structures
1116 // 1/ Structure with the same Owner as <AStructure>
1117 // 2/ Which is not <AStructure>
1118 // 3/ COMPUTED which of is valid
1119 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1120 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1122 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1123 if (aStructToComp->Owner() == theStructure->Owner()
1124 && aStructToComp->Identification() != theStructure->Identification())
1126 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1127 if (aStructComp->HLRValidation())
1136 // =======================================================================
1137 // function : CopySettings
1139 // =======================================================================
1140 void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1142 ChangeRenderingParams() = theOther->RenderingParams();
1143 SetBackground (theOther->Background());
1144 SetGradientBackground (theOther->GradientBackground());
1145 SetBackgroundImage (theOther->BackgroundImage());
1146 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1147 SetTextureEnv (theOther->TextureEnv());
1148 SetCullingEnabled (theOther->IsCullingEnabled());
1149 SetShadingModel (theOther->ShadingModel());
1150 SetBackfacingModel (theOther->BackfacingModel());
1151 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1152 SetGLLightEnabled (theOther->IsGLLightEnabled());
1153 SetLights (theOther->Lights());
1154 SetClipPlanes (theOther->ClipPlanes());