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);
31 //=======================================================================
32 //function : Constructor
34 //=======================================================================
35 Graphic3d_CView::Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr)
36 : myBgColor (Quantity_NOC_BLACK),
37 myStructureManager (theMgr),
38 myCamera (new Graphic3d_Camera()),
39 myHiddenObjects (new Graphic3d_NMapOfTransient()),
40 myIsInComputedMode (Standard_False),
41 myIsActive (Standard_False),
42 myIsRemoved (Standard_False),
43 myShadingModel (Graphic3d_TOSM_FRAGMENT),
44 myVisualization (Graphic3d_TOV_WIREFRAME)
46 myId = myStructureManager->Identification (this);
49 //=======================================================================
50 //function : Destructor
52 //=======================================================================
53 Graphic3d_CView::~Graphic3d_CView()
57 myStructureManager->UnIdentification (this);
61 // =======================================================================
62 // function : Activate
64 // =======================================================================
65 void Graphic3d_CView::Activate()
69 myIsActive = Standard_True;
71 // Activation of a new view =>
72 // Display structures that can be displayed in this new view.
73 // All structures with status
74 // Displayed in ViewManager are returned and displayed in
75 // the view directly, if the structure is not already
76 // displayed and if the view accepts it in its context.
77 Graphic3d_MapOfStructure aDisplayedStructs;
78 myStructureManager->DisplayedStructures (aDisplayedStructs);
79 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
81 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
82 if (IsDisplayed (aStruct))
87 // If the structure can be displayed in the new context of the view, it is displayed.
88 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
89 if (anAnswer == Graphic3d_TOA_YES
90 || anAnswer == Graphic3d_TOA_COMPUTE)
100 // =======================================================================
101 // function : Deactivate
103 // =======================================================================
104 void Graphic3d_CView::Deactivate()
108 // Deactivation of a view =>
109 // Removal of structures displayed in this view.
110 // All structures with status
111 // Displayed in ViewManager are returned and removed from
112 // the view directly, if the structure is not already
113 // displayed and if the view accepts it in its context.
114 Graphic3d_MapOfStructure aDisplayedStructs;
115 myStructureManager->DisplayedStructures (aDisplayedStructs);
116 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
118 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
119 if (!IsDisplayed (aStruct))
124 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
125 if (anAnswer == Graphic3d_TOA_YES
126 || anAnswer == Graphic3d_TOA_COMPUTE)
133 myIsActive = Standard_False;
137 // ========================================================================
140 // ========================================================================
141 void Graphic3d_CView::Remove()
148 Graphic3d_MapOfStructure aDisplayedStructs (myStructsDisplayed);
150 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
152 Erase (aStructIter.Value());
155 myStructsToCompute.Clear();
156 myStructsComputed .Clear();
157 myStructsDisplayed.Clear();
159 if (!myStructureManager.IsNull())
161 myStructureManager->UnIdentification (this);
164 myIsActive = Standard_False;
165 myIsRemoved = Standard_True;
168 // ========================================================================
169 // function : SetComputedMode
171 // ========================================================================
172 void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode)
174 if (( theMode && myIsInComputedMode)
175 || (!theMode && !myIsInComputedMode))
180 myIsInComputedMode = theMode;
181 if (!myIsInComputedMode)
183 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
185 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
186 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
187 if (anAnswer != Graphic3d_TOA_COMPUTE)
192 const Standard_Integer anIndex = IsComputed (aStruct);
195 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
196 eraseStructure (aStructComp->CStructure());
197 displayStructure (aStruct->CStructure(), aStruct->DisplayPriority());
203 for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
205 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
206 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
207 if (anAnswer != Graphic3d_TOA_COMPUTE)
212 const Standard_Integer anIndex = IsComputed (aStruct);
215 eraseStructure (aStruct->CStructure());
216 displayStructure (myStructsComputed.Value (anIndex)->CStructure(), aStruct->DisplayPriority());
219 if (aStruct->IsHighlighted())
221 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
222 if (!aCompStruct->IsHighlighted())
224 aCompStruct->Highlight (aStruct->HighlightStyle(), Standard_False);
230 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aStruct->Transformation()) : aStruct->Compute (this);
231 aCompStruct->SetHLRValidation (Standard_True);
233 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
234 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
235 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
236 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
237 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
238 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
240 if (aStruct->IsHighlighted())
242 aCompStruct->Highlight (aStruct->HighlightStyle(), Standard_False);
245 Standard_Boolean hasResult = Standard_False;
246 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
247 const Standard_Integer aStructId = aStruct->Identification();
248 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
250 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
252 hasResult = Standard_True;
253 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
260 myStructsToCompute.Append (aStruct);
261 myStructsComputed .Append (aCompStruct);
264 aCompStruct->CalculateBoundBox();
265 eraseStructure (aStruct->CStructure());
266 displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
272 // =======================================================================
273 // function : ReCompute
275 // =======================================================================
276 void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
278 theStruct->CalculateBoundBox();
279 if (!theStruct->IsMutable()
280 && !theStruct->CStructure()->IsForHighlight
281 && !theStruct->CStructure()->IsInfinite)
283 const Graphic3d_ZLayerId aLayerId = theStruct->GetZLayer();
284 InvalidateBVHData (aLayerId);
289 || !theStruct->IsDisplayed())
294 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual());
295 if (anAnswer != Graphic3d_TOA_COMPUTE)
300 const Standard_Integer anIndex = IsComputed (theStruct);
306 // compute + validation
307 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
308 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
309 aCompStruct->SetTransformation (Handle(Geom_Transformation)());
310 theStruct->IsTransformed() ? theStruct->Compute (this, theStruct->Transformation(), aCompStruct)
311 : theStruct->Compute (this, aCompStruct);
312 aCompStruct->SetHLRValidation (Standard_True);
313 aCompStruct->CalculateBoundBox();
315 // of which type will be the computed?
316 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
317 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
318 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
319 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
320 if (toComputeWireframe)
322 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
324 else if (toComputeShading)
326 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
329 if (theStruct->IsHighlighted())
331 aCompStruct->Highlight (theStruct->HighlightStyle(), Standard_False);
334 // The previous calculation is removed and the new one is displayed
335 eraseStructure (aCompStructOld->CStructure());
336 displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority());
338 // why not just replace existing items?
339 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
340 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
342 // hlhsr and the new associated compute are added
343 myStructsToCompute.Append (theStruct);
344 myStructsComputed .Append (aCompStruct);
346 // hlhsr and the new associated compute are removed
347 myStructsToCompute.Remove (anIndex);
348 myStructsComputed .Remove (anIndex);
351 // =======================================================================
354 // =======================================================================
355 void Graphic3d_CView::Update (const Graphic3d_ZLayerId theLayerId)
357 InvalidateZLayerBoundingBox (theLayerId);
360 // =======================================================================
361 // function : ContainsFacet
363 // =======================================================================
364 Standard_Boolean Graphic3d_CView::ContainsFacet() const
366 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
368 if (aStructIter.Key()->ContainsFacet())
370 return Standard_True;
373 return Standard_False;
376 // =======================================================================
377 // function : ContainsFacet
379 // =======================================================================
380 Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
382 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
384 if (aStructIter.Key()->ContainsFacet())
386 return Standard_True;
389 return Standard_False;
392 // =======================================================================
393 // function : DisplayedStructures
395 // =======================================================================
396 void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
398 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
400 theStructures.Add (aStructIter.Key());
404 // =======================================================================
405 // function : MinMaxValues
407 // =======================================================================
408 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
417 Handle(Graphic3d_Camera) aCamera = Camera();
418 Standard_Integer aWinWidth = 0;
419 Standard_Integer aWinHeight = 0;
421 Window()->Size (aWinWidth, aWinHeight);
423 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
425 Bnd_Box aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
429 theToIncludeAuxiliary);
433 Standard_Integer aMaxZLayer = ZLayerMax();
434 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
436 Bnd_Box aBox = ZLayerBoundingBox (aLayerId,
440 theToIncludeAuxiliary);
447 // =======================================================================
448 // function : ConsiderZoomPersistenceObjects
450 // =======================================================================
451 Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
458 Handle(Graphic3d_Camera) aCamera = Camera();
459 Standard_Integer aWinWidth = 0;
460 Standard_Integer aWinHeight = 0;
462 Window()->Size (aWinWidth, aWinHeight);
464 Standard_Real aMaxCoef = 1.0;
465 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
467 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
470 for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
472 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
478 // =======================================================================
479 // function : MinMaxValues
481 // =======================================================================
482 Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
483 const Standard_Boolean theToIgnoreInfiniteFlag) const
486 const Standard_Integer aViewId = Identification();
488 Handle(Graphic3d_Camera) aCamera = Camera();
489 Standard_Integer aWinWidth = 0;
490 Standard_Integer aWinHeight = 0;
493 Window()->Size (aWinWidth, aWinHeight);
496 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
498 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
499 if (aStructure->IsEmpty()
500 || !aStructure->CStructure()->IsVisible (aViewId))
505 // "FitAll" operation ignores object with transform persistence parameter
506 if (!aStructure->TransformPersistence().IsNull())
508 // Panning and 2d persistence apply changes to projection or/and its translation components.
509 // It makes them incompatible with z-fitting algorithm. Ignored by now.
510 if (!theToIgnoreInfiniteFlag
511 || aStructure->TransformPersistence()->IsTrihedronOr2d())
517 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
519 if (aBox.IsWhole() || aBox.IsVoid())
524 if (!aStructure->TransformPersistence().IsNull())
526 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
527 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
528 aStructure->TransformPersistence()->Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
531 // To prevent float overflow at camera parameters calculation and further
532 // rendering, bounding boxes with at least one vertex coordinate out of
533 // float range are skipped by view fit algorithms
534 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
535 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
536 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
537 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
538 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
539 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
549 // =======================================================================
550 // function : acceptDisplay
552 // =======================================================================
553 Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
555 switch (theStructType)
557 case Graphic3d_TOS_ALL:
559 return Graphic3d_TOA_YES; // The structure accepts any type of view
561 case Graphic3d_TOS_SHADING:
563 return myVisualization == Graphic3d_TOV_SHADING
567 case Graphic3d_TOS_WIREFRAME:
569 return myVisualization == Graphic3d_TOV_WIREFRAME
573 case Graphic3d_TOS_COMPUTED:
575 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
576 ? Graphic3d_TOA_COMPUTE
580 return Graphic3d_TOA_NO;
583 // =======================================================================
584 // function : Compute
586 // =======================================================================
587 void Graphic3d_CView::Compute()
589 // force HLRValidation to False on all structures calculated in the view
590 for (Graphic3d_SequenceOfStructure::Iterator aStructIter (myStructsComputed); aStructIter.More(); aStructIter.Next())
592 aStructIter.Value()->SetHLRValidation (Standard_False);
600 // Change of orientation or of projection type =>
601 // Remove structures that were calculated for the previous orientation.
602 // Recalculation of new structures.
603 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
604 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
606 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
607 if (anAnswer == Graphic3d_TOA_COMPUTE)
609 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
613 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
615 Display (aStructIter.ChangeValue());
619 // =======================================================================
622 // =======================================================================
623 void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
624 const Standard_Boolean theWithDestruction)
626 const Standard_Integer anIndex = IsComputed (theStructure);
629 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
630 aCompStruct->GraphicClear (theWithDestruction);
631 aCompStruct->SetHLRValidation (Standard_False);
635 // =======================================================================
636 // function : Connect
638 // =======================================================================
639 void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
640 const Handle(Graphic3d_Structure)& theDaughter)
642 Standard_Integer anIndexM = IsComputed (theMother);
643 Standard_Integer anIndexD = IsComputed (theDaughter);
647 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
648 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
649 aStructM->GraphicConnect (aStructD);
653 // =======================================================================
654 // function : Disconnect
656 // =======================================================================
657 void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
658 const Handle(Graphic3d_Structure)& theDaughter)
660 Standard_Integer anIndexM = IsComputed (theMother);
661 Standard_Integer anIndexD = IsComputed (theDaughter);
665 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
666 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
667 aStructM->GraphicDisconnect (aStructD);
671 // =======================================================================
672 // function : Display
674 // =======================================================================
675 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
682 // If Display on a structure present in the list of calculated structures while it is not
683 // or more, of calculated type =>
684 // - removes it as well as the associated old computed
685 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
686 Standard_Integer anIndex = IsComputed (theStructure);
688 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
690 myStructsToCompute.Remove (anIndex);
691 myStructsComputed .Remove (anIndex);
695 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
696 if (anAnswer == Graphic3d_TOA_NO)
703 anAnswer = Graphic3d_TOA_YES;
706 if (anAnswer == Graphic3d_TOA_YES)
708 if (!myStructsDisplayed.Add (theStructure))
713 theStructure->CalculateBoundBox();
714 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
715 Update (theStructure->GetZLayer());
718 else if (anAnswer != Graphic3d_TOA_COMPUTE)
725 // Already computed, is COMPUTED still valid?
726 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
727 if (anOldStruct->HLRValidation())
729 // Case COMPUTED valid, to be displayed
730 if (!myStructsDisplayed.Add (theStructure))
735 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
736 Update (anOldStruct->GetZLayer());
741 // Case COMPUTED invalid
742 // Is there another valid representation?
743 // Find in the sequence of already calculated structures
744 // 1/ Structure having the same Owner as <AStructure>
745 // 2/ That is not <AStructure>
746 // 3/ The COMPUTED which of is valid
747 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
750 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
751 if (!myStructsDisplayed.Add (theStructure))
756 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
757 myStructsComputed.SetValue (anIndex, aNewStruct);
758 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
759 Update (aNewStruct->GetZLayer());
764 // Case COMPUTED invalid, WITHOUT a valid of replacement
765 // COMPUTED is removed if displayed
766 if (myStructsDisplayed.Contains (theStructure))
768 eraseStructure (anOldStruct->CStructure());
774 // Compute + Validation
775 Handle(Graphic3d_Structure) aStruct;
778 aStruct = myStructsComputed.Value (anIndex);
779 aStruct->SetTransformation (Handle(Geom_Transformation)());
780 if (theStructure->IsTransformed())
782 theStructure->Compute (this, theStructure->Transformation(), aStruct);
786 theStructure->Compute (this, aStruct);
791 aStruct = theStructure->IsTransformed()
792 ? theStructure->Compute (this, theStructure->Transformation())
793 : theStructure->Compute (this);
796 aStruct->SetHLRValidation (Standard_True);
798 // TOCOMPUTE and COMPUTED associated to sequences are added
799 myStructsToCompute.Append (theStructure);
800 myStructsComputed .Append (aStruct);
802 // The previous are removed if necessary
805 myStructsToCompute.Remove (anIndex);
806 myStructsComputed .Remove (anIndex);
809 // Of which type will be the computed?
810 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
811 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
812 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
813 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
814 if (!toComputeShading && !toComputeWireframe)
816 anAnswer = Graphic3d_TOA_NO;
820 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
821 anAnswer = acceptDisplay (aStruct->Visual());
824 if (theStructure->IsHighlighted())
826 aStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
829 // It is displayed only if the calculated structure
830 // has a proper type corresponding to the one of the view.
831 if (anAnswer == Graphic3d_TOA_NO)
836 myStructsDisplayed.Add (theStructure);
837 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
839 Update (aStruct->GetZLayer());
842 // =======================================================================
845 // =======================================================================
846 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
848 if (!IsDisplayed (theStructure))
853 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
856 anAnswer = Graphic3d_TOA_YES;
859 if (anAnswer != Graphic3d_TOA_COMPUTE)
861 eraseStructure (theStructure->CStructure());
863 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
865 const Standard_Integer anIndex = IsComputed (theStructure);
868 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
869 eraseStructure (aCompStruct->CStructure());
872 myStructsDisplayed.Remove (theStructure);
873 Update (theStructure->GetZLayer());
876 // =======================================================================
877 // function : Highlight
879 // =======================================================================
880 void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure)
882 const Standard_Integer anIndex = IsComputed (theStructure);
885 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
886 aCompStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
890 // =======================================================================
891 // function : SetTransform
893 // =======================================================================
894 void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
895 const Handle(Geom_Transformation)& theTrsf)
897 const Standard_Integer anIndex = IsComputed (theStructure);
900 // Test is somewhat light !
901 // trsf is transferred only if it is :
904 if (!theTrsf.IsNull()
905 && (theTrsf->Form() == gp_Translation
906 || theTrsf->Form() == gp_Scale
907 || theTrsf->Form() == gp_CompoundTrsf))
909 ReCompute (theStructure);
913 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
914 aCompStruct->GraphicTransform (theTrsf);
918 theStructure->CalculateBoundBox();
919 if (!theStructure->IsMutable()
920 && !theStructure->CStructure()->IsForHighlight
921 && !theStructure->CStructure()->IsInfinite)
923 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
924 InvalidateBVHData (aLayerId);
928 // =======================================================================
929 // function : UnHighlight
931 // =======================================================================
932 void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
934 Standard_Integer anIndex = IsComputed (theStructure);
937 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
938 aCompStruct->CStructure()->GraphicUnhighlight();
942 // ========================================================================
943 // function : IsComputed
945 // ========================================================================
946 Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
947 Handle(Graphic3d_Structure)& theComputedStruct) const
949 theComputedStruct.Nullify();
951 return Standard_False;
953 const Standard_Integer aNbStructs = myStructsToCompute.Length();
954 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
956 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
958 theComputedStruct = myStructsComputed (aStructIter);
959 return Standard_True;
962 return Standard_False;
965 // =======================================================================
966 // function : IsComputed
968 // =======================================================================
969 Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
971 const Standard_Integer aStructId = theStructure->Identification();
972 const Standard_Integer aNbStructs = myStructsToCompute.Length();
973 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
975 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
976 if (aStruct->Identification() == aStructId)
984 // =======================================================================
985 // function : IsDisplayed
987 // =======================================================================
988 Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
990 return myStructsDisplayed.Contains (theStructure);
993 // =======================================================================
994 // function : ChangePriority
996 // =======================================================================
997 void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
998 const Standard_Integer /*theOldPriority*/,
999 const Standard_Integer theNewPriority)
1002 || !IsDisplayed (theStructure))
1007 if (!myIsInComputedMode)
1009 changePriority (theStructure->CStructure(), theNewPriority);
1013 const Standard_Integer anIndex = IsComputed (theStructure);
1014 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
1015 ? myStructsComputed.Value (anIndex)->CStructure()
1016 : theStructure->CStructure();
1018 changePriority (aCStruct, theNewPriority);
1021 // =======================================================================
1022 // function : ChangeZLayer
1024 // =======================================================================
1025 void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1026 const Graphic3d_ZLayerId theLayerId)
1029 || !IsDisplayed (theStructure))
1034 if (!myIsInComputedMode)
1036 changeZLayer (theStructure->CStructure(), theLayerId);
1040 const Standard_Integer anIndex = IsComputed (theStructure);
1041 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1042 ? myStructsComputed.Value (anIndex)->CStructure()
1043 : theStructure->CStructure();
1045 changeZLayer (aCStruct, theLayerId);
1048 // =======================================================================
1049 // function : HaveTheSameOwner
1051 // =======================================================================
1052 Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1054 // Find in the sequence of already calculated structures
1055 // 1/ Structure with the same Owner as <AStructure>
1056 // 2/ Which is not <AStructure>
1057 // 3/ COMPUTED which of is valid
1058 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1059 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1061 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1062 if (aStructToComp->Owner() == theStructure->Owner()
1063 && aStructToComp->Identification() != theStructure->Identification())
1065 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1066 if (aStructComp->HLRValidation())
1075 // =======================================================================
1076 // function : CopySettings
1078 // =======================================================================
1079 void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1081 ChangeRenderingParams() = theOther->RenderingParams();
1082 SetBackground (theOther->Background());
1083 SetGradientBackground (theOther->GradientBackground());
1084 SetBackgroundImage (theOther->BackgroundImage());
1085 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1086 SetTextureEnv (theOther->TextureEnv());
1087 SetShadingModel (theOther->ShadingModel());
1088 SetBackfacingModel (theOther->BackfacingModel());
1089 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1090 SetLights (theOther->Lights());
1091 SetClipPlanes (theOther->ClipPlanes());
1094 // =======================================================================
1095 // function : SetShadingModel
1097 // =======================================================================
1098 void Graphic3d_CView::SetShadingModel (Graphic3d_TypeOfShadingModel theModel)
1100 if (theModel == Graphic3d_TOSM_DEFAULT)
1102 throw Standard_ProgramError ("Graphic3d_CView::SetShadingModel() - attempt to set invalid Shading Model!");
1105 myShadingModel = theModel;