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 : myStructureManager (theMgr),
37 myHiddenObjects (new Graphic3d_NMapOfTransient()),
38 myIsInComputedMode (Standard_False),
39 myIsActive (Standard_False),
40 myIsRemoved (Standard_False),
41 myShadingModel (Graphic3d_TOSM_FRAGMENT),
42 myVisualization (Graphic3d_TOV_WIREFRAME)
44 myId = myStructureManager->Identification (this);
47 //=======================================================================
48 //function : Destructor
50 //=======================================================================
51 Graphic3d_CView::~Graphic3d_CView()
55 myStructureManager->UnIdentification (this);
59 // =======================================================================
60 // function : Activate
62 // =======================================================================
63 void Graphic3d_CView::Activate()
67 myIsActive = Standard_True;
69 // Activation of a new view =>
70 // Display structures that can be displayed in this new view.
71 // All structures with status
72 // Displayed in ViewManager are returned and displayed in
73 // the view directly, if the structure is not already
74 // displayed and if the view accepts it in its context.
75 Graphic3d_MapOfStructure aDisplayedStructs;
76 myStructureManager->DisplayedStructures (aDisplayedStructs);
77 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
79 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
80 if (IsDisplayed (aStruct))
85 // If the structure can be displayed in the new context of the view, it is displayed.
86 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
87 if (anAnswer == Graphic3d_TOA_YES
88 || anAnswer == Graphic3d_TOA_COMPUTE)
98 // =======================================================================
99 // function : Deactivate
101 // =======================================================================
102 void Graphic3d_CView::Deactivate()
106 // Deactivation of a view =>
107 // Removal of structures displayed in this view.
108 // All structures with status
109 // Displayed in ViewManager are returned and removed from
110 // the view directly, if the structure is not already
111 // displayed and if the view accepts it in its context.
112 Graphic3d_MapOfStructure aDisplayedStructs;
113 myStructureManager->DisplayedStructures (aDisplayedStructs);
114 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
116 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
117 if (!IsDisplayed (aStruct))
122 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
123 if (anAnswer == Graphic3d_TOA_YES
124 || anAnswer == Graphic3d_TOA_COMPUTE)
131 myIsActive = Standard_False;
135 // ========================================================================
138 // ========================================================================
139 void Graphic3d_CView::Remove()
146 Graphic3d_MapOfStructure aDisplayedStructs (myStructsDisplayed);
148 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
150 Erase (aStructIter.Value());
153 myStructsToCompute.Clear();
154 myStructsComputed .Clear();
155 myStructsDisplayed.Clear();
157 if (!myStructureManager.IsNull())
159 myStructureManager->UnIdentification (this);
162 myIsActive = Standard_False;
163 myIsRemoved = Standard_True;
166 // ========================================================================
167 // function : SetComputedMode
169 // ========================================================================
170 void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode)
172 if (( theMode && myIsInComputedMode)
173 || (!theMode && !myIsInComputedMode))
178 myIsInComputedMode = theMode;
179 if (!myIsInComputedMode)
181 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
183 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
184 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
185 if (anAnswer != Graphic3d_TOA_COMPUTE)
190 const Standard_Integer anIndex = IsComputed (aStruct);
193 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
194 eraseStructure (aStructComp->CStructure());
195 displayStructure (aStruct->CStructure(), aStruct->DisplayPriority());
201 for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
203 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
204 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
205 if (anAnswer != Graphic3d_TOA_COMPUTE)
210 const Standard_Integer anIndex = IsComputed (aStruct);
213 eraseStructure (aStruct->CStructure());
214 displayStructure (myStructsComputed.Value (anIndex)->CStructure(), aStruct->DisplayPriority());
217 if (aStruct->IsHighlighted())
219 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
220 if (!aCompStruct->IsHighlighted())
222 aCompStruct->Highlight (aStruct->HighlightStyle(), Standard_False);
228 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aStruct->Transformation()) : aStruct->Compute (this);
229 aCompStruct->SetHLRValidation (Standard_True);
231 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
232 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
233 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
234 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
235 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
236 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
238 if (aStruct->IsHighlighted())
240 aCompStruct->Highlight (aStruct->HighlightStyle(), Standard_False);
243 Standard_Boolean hasResult = Standard_False;
244 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
245 const Standard_Integer aStructId = aStruct->Identification();
246 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
248 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
250 hasResult = Standard_True;
251 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
258 myStructsToCompute.Append (aStruct);
259 myStructsComputed .Append (aCompStruct);
262 aCompStruct->CalculateBoundBox();
263 eraseStructure (aStruct->CStructure());
264 displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
270 // =======================================================================
271 // function : ReCompute
273 // =======================================================================
274 void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
276 theStruct->CalculateBoundBox();
277 if (!theStruct->IsMutable()
278 && !theStruct->CStructure()->IsForHighlight
279 && !theStruct->CStructure()->IsInfinite)
281 const Graphic3d_ZLayerId aLayerId = theStruct->GetZLayer();
282 InvalidateBVHData (aLayerId);
287 || !theStruct->IsDisplayed())
292 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual());
293 if (anAnswer != Graphic3d_TOA_COMPUTE)
298 const Standard_Integer anIndex = IsComputed (theStruct);
304 // compute + validation
305 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
306 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
307 aCompStruct->SetTransformation (Handle(Geom_Transformation)());
308 theStruct->IsTransformed() ? theStruct->Compute (this, theStruct->Transformation(), aCompStruct)
309 : theStruct->Compute (this, aCompStruct);
310 aCompStruct->SetHLRValidation (Standard_True);
311 aCompStruct->CalculateBoundBox();
313 // of which type will be the computed?
314 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
315 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
316 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
317 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
318 if (toComputeWireframe)
320 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
322 else if (toComputeShading)
324 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
327 if (theStruct->IsHighlighted())
329 aCompStruct->Highlight (theStruct->HighlightStyle(), Standard_False);
332 // The previous calculation is removed and the new one is displayed
333 eraseStructure (aCompStructOld->CStructure());
334 displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority());
336 // why not just replace existing items?
337 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
338 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
340 // hlhsr and the new associated compute are added
341 myStructsToCompute.Append (theStruct);
342 myStructsComputed .Append (aCompStruct);
344 // hlhsr and the new associated compute are removed
345 myStructsToCompute.Remove (anIndex);
346 myStructsComputed .Remove (anIndex);
349 // =======================================================================
352 // =======================================================================
353 void Graphic3d_CView::Update (const Graphic3d_ZLayerId theLayerId)
355 InvalidateZLayerBoundingBox (theLayerId);
358 // =======================================================================
359 // function : ContainsFacet
361 // =======================================================================
362 Standard_Boolean Graphic3d_CView::ContainsFacet() const
364 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
366 if (aStructIter.Key()->ContainsFacet())
368 return Standard_True;
371 return Standard_False;
374 // =======================================================================
375 // function : ContainsFacet
377 // =======================================================================
378 Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
380 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
382 if (aStructIter.Key()->ContainsFacet())
384 return Standard_True;
387 return Standard_False;
390 // =======================================================================
391 // function : DisplayedStructures
393 // =======================================================================
394 void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
396 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
398 theStructures.Add (aStructIter.Key());
402 // =======================================================================
403 // function : MinMaxValues
405 // =======================================================================
406 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
415 Handle(Graphic3d_Camera) aCamera = Camera();
416 Standard_Integer aWinWidth = 0;
417 Standard_Integer aWinHeight = 0;
419 Window()->Size (aWinWidth, aWinHeight);
421 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
423 Bnd_Box aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
427 theToIncludeAuxiliary);
431 Standard_Integer aMaxZLayer = ZLayerMax();
432 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
434 Bnd_Box aBox = ZLayerBoundingBox (aLayerId,
438 theToIncludeAuxiliary);
445 // =======================================================================
446 // function : ConsiderZoomPersistenceObjects
448 // =======================================================================
449 Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
456 Handle(Graphic3d_Camera) aCamera = Camera();
457 Standard_Integer aWinWidth = 0;
458 Standard_Integer aWinHeight = 0;
460 Window()->Size (aWinWidth, aWinHeight);
462 Standard_Real aMaxCoef = 1.0;
463 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
465 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
468 for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
470 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
476 // =======================================================================
477 // function : MinMaxValues
479 // =======================================================================
480 Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
481 const Standard_Boolean theToIgnoreInfiniteFlag) const
484 const Standard_Integer aViewId = Identification();
486 Handle(Graphic3d_Camera) aCamera = Camera();
487 Standard_Integer aWinWidth = 0;
488 Standard_Integer aWinHeight = 0;
491 Window()->Size (aWinWidth, aWinHeight);
494 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
496 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
497 if (aStructure->IsEmpty()
498 || !aStructure->CStructure()->IsVisible (aViewId))
503 // "FitAll" operation ignores object with transform persistence parameter
504 if (!aStructure->TransformPersistence().IsNull())
506 // Panning and 2d persistence apply changes to projection or/and its translation components.
507 // It makes them incompatible with z-fitting algorithm. Ignored by now.
508 if (!theToIgnoreInfiniteFlag
509 || aStructure->TransformPersistence()->IsTrihedronOr2d())
515 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
517 if (aBox.IsWhole() || aBox.IsVoid())
522 if (!aStructure->TransformPersistence().IsNull())
524 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
525 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
526 aStructure->TransformPersistence()->Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
529 // To prevent float overflow at camera parameters calculation and further
530 // rendering, bounding boxes with at least one vertex coordinate out of
531 // float range are skipped by view fit algorithms
532 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
533 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
534 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
535 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
536 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
537 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
547 // =======================================================================
548 // function : acceptDisplay
550 // =======================================================================
551 Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
553 switch (theStructType)
555 case Graphic3d_TOS_ALL:
557 return Graphic3d_TOA_YES; // The structure accepts any type of view
559 case Graphic3d_TOS_SHADING:
561 return myVisualization == Graphic3d_TOV_SHADING
565 case Graphic3d_TOS_WIREFRAME:
567 return myVisualization == Graphic3d_TOV_WIREFRAME
571 case Graphic3d_TOS_COMPUTED:
573 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
574 ? Graphic3d_TOA_COMPUTE
578 return Graphic3d_TOA_NO;
581 // =======================================================================
582 // function : Compute
584 // =======================================================================
585 void Graphic3d_CView::Compute()
587 // force HLRValidation to False on all structures calculated in the view
588 for (Graphic3d_SequenceOfStructure::Iterator aStructIter (myStructsComputed); aStructIter.More(); aStructIter.Next())
590 aStructIter.Value()->SetHLRValidation (Standard_False);
598 // Change of orientation or of projection type =>
599 // Remove structures that were calculated for the previous orientation.
600 // Recalculation of new structures.
601 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
602 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
604 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
605 if (anAnswer == Graphic3d_TOA_COMPUTE)
607 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
611 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
613 Display (aStructIter.ChangeValue());
617 // =======================================================================
620 // =======================================================================
621 void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
622 const Standard_Boolean theWithDestruction)
624 const Standard_Integer anIndex = IsComputed (theStructure);
627 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
628 aCompStruct->GraphicClear (theWithDestruction);
629 aCompStruct->SetHLRValidation (Standard_False);
633 // =======================================================================
634 // function : Connect
636 // =======================================================================
637 void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
638 const Handle(Graphic3d_Structure)& theDaughter)
640 Standard_Integer anIndexM = IsComputed (theMother);
641 Standard_Integer anIndexD = IsComputed (theDaughter);
645 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
646 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
647 aStructM->GraphicConnect (aStructD);
651 // =======================================================================
652 // function : Disconnect
654 // =======================================================================
655 void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
656 const Handle(Graphic3d_Structure)& theDaughter)
658 Standard_Integer anIndexM = IsComputed (theMother);
659 Standard_Integer anIndexD = IsComputed (theDaughter);
663 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
664 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
665 aStructM->GraphicDisconnect (aStructD);
669 // =======================================================================
670 // function : Display
672 // =======================================================================
673 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
680 // If Display on a structure present in the list of calculated structures while it is not
681 // or more, of calculated type =>
682 // - removes it as well as the associated old computed
683 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
684 Standard_Integer anIndex = IsComputed (theStructure);
686 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
688 myStructsToCompute.Remove (anIndex);
689 myStructsComputed .Remove (anIndex);
693 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
694 if (anAnswer == Graphic3d_TOA_NO)
701 anAnswer = Graphic3d_TOA_YES;
704 if (anAnswer == Graphic3d_TOA_YES)
706 if (!myStructsDisplayed.Add (theStructure))
711 theStructure->CalculateBoundBox();
712 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
713 Update (theStructure->GetZLayer());
716 else if (anAnswer != Graphic3d_TOA_COMPUTE)
723 // Already computed, is COMPUTED still valid?
724 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
725 if (anOldStruct->HLRValidation())
727 // Case COMPUTED valid, to be displayed
728 if (!myStructsDisplayed.Add (theStructure))
733 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
734 Update (anOldStruct->GetZLayer());
739 // Case COMPUTED invalid
740 // Is there another valid representation?
741 // Find in the sequence of already calculated structures
742 // 1/ Structure having the same Owner as <AStructure>
743 // 2/ That is not <AStructure>
744 // 3/ The COMPUTED which of is valid
745 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
748 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
749 if (!myStructsDisplayed.Add (theStructure))
754 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
755 myStructsComputed.SetValue (anIndex, aNewStruct);
756 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
757 Update (aNewStruct->GetZLayer());
762 // Case COMPUTED invalid, WITHOUT a valid of replacement
763 // COMPUTED is removed if displayed
764 if (myStructsDisplayed.Contains (theStructure))
766 eraseStructure (anOldStruct->CStructure());
772 // Compute + Validation
773 Handle(Graphic3d_Structure) aStruct;
776 aStruct = myStructsComputed.Value (anIndex);
777 aStruct->SetTransformation (Handle(Geom_Transformation)());
778 if (theStructure->IsTransformed())
780 theStructure->Compute (this, theStructure->Transformation(), aStruct);
784 theStructure->Compute (this, aStruct);
789 aStruct = theStructure->IsTransformed()
790 ? theStructure->Compute (this, theStructure->Transformation())
791 : theStructure->Compute (this);
794 aStruct->SetHLRValidation (Standard_True);
796 // TOCOMPUTE and COMPUTED associated to sequences are added
797 myStructsToCompute.Append (theStructure);
798 myStructsComputed .Append (aStruct);
800 // The previous are removed if necessary
803 myStructsToCompute.Remove (anIndex);
804 myStructsComputed .Remove (anIndex);
807 // Of which type will be the computed?
808 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
809 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
810 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
811 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
812 if (!toComputeShading && !toComputeWireframe)
814 anAnswer = Graphic3d_TOA_NO;
818 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
819 anAnswer = acceptDisplay (aStruct->Visual());
822 if (theStructure->IsHighlighted())
824 aStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
827 // It is displayed only if the calculated structure
828 // has a proper type corresponding to the one of the view.
829 if (anAnswer == Graphic3d_TOA_NO)
834 myStructsDisplayed.Add (theStructure);
835 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
837 Update (aStruct->GetZLayer());
840 // =======================================================================
843 // =======================================================================
844 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
846 if (!IsDisplayed (theStructure))
851 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
854 anAnswer = Graphic3d_TOA_YES;
857 if (anAnswer != Graphic3d_TOA_COMPUTE)
859 eraseStructure (theStructure->CStructure());
861 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
863 const Standard_Integer anIndex = IsComputed (theStructure);
866 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
867 eraseStructure (aCompStruct->CStructure());
870 myStructsDisplayed.Remove (theStructure);
871 Update (theStructure->GetZLayer());
874 // =======================================================================
875 // function : Highlight
877 // =======================================================================
878 void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure)
880 const Standard_Integer anIndex = IsComputed (theStructure);
883 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
884 aCompStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
888 // =======================================================================
889 // function : SetTransform
891 // =======================================================================
892 void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
893 const Handle(Geom_Transformation)& theTrsf)
895 const Standard_Integer anIndex = IsComputed (theStructure);
898 // Test is somewhat light !
899 // trsf is transferred only if it is :
902 if (!theTrsf.IsNull()
903 && (theTrsf->Form() == gp_Translation
904 || theTrsf->Form() == gp_Scale
905 || theTrsf->Form() == gp_CompoundTrsf))
907 ReCompute (theStructure);
911 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
912 aCompStruct->GraphicTransform (theTrsf);
916 theStructure->CalculateBoundBox();
917 if (!theStructure->IsMutable()
918 && !theStructure->CStructure()->IsForHighlight
919 && !theStructure->CStructure()->IsInfinite)
921 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
922 InvalidateBVHData (aLayerId);
926 // =======================================================================
927 // function : UnHighlight
929 // =======================================================================
930 void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
932 Standard_Integer anIndex = IsComputed (theStructure);
935 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
936 aCompStruct->CStructure()->GraphicUnhighlight();
940 // ========================================================================
941 // function : IsComputed
943 // ========================================================================
944 Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
945 Handle(Graphic3d_Structure)& theComputedStruct) const
947 theComputedStruct.Nullify();
949 return Standard_False;
951 const Standard_Integer aNbStructs = myStructsToCompute.Length();
952 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
954 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
956 theComputedStruct = myStructsComputed (aStructIter);
957 return Standard_True;
960 return Standard_False;
963 // =======================================================================
964 // function : IsComputed
966 // =======================================================================
967 Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
969 const Standard_Integer aStructId = theStructure->Identification();
970 const Standard_Integer aNbStructs = myStructsToCompute.Length();
971 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
973 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
974 if (aStruct->Identification() == aStructId)
982 // =======================================================================
983 // function : IsDisplayed
985 // =======================================================================
986 Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
988 return myStructsDisplayed.Contains (theStructure);
991 // =======================================================================
992 // function : ChangePriority
994 // =======================================================================
995 void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
996 const Standard_Integer /*theOldPriority*/,
997 const Standard_Integer theNewPriority)
1000 || !IsDisplayed (theStructure))
1005 if (!myIsInComputedMode)
1007 changePriority (theStructure->CStructure(), theNewPriority);
1011 const Standard_Integer anIndex = IsComputed (theStructure);
1012 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
1013 ? myStructsComputed.Value (anIndex)->CStructure()
1014 : theStructure->CStructure();
1016 changePriority (aCStruct, theNewPriority);
1019 // =======================================================================
1020 // function : ChangeZLayer
1022 // =======================================================================
1023 void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1024 const Graphic3d_ZLayerId theLayerId)
1027 || !IsDisplayed (theStructure))
1032 if (!myIsInComputedMode)
1034 changeZLayer (theStructure->CStructure(), theLayerId);
1038 const Standard_Integer anIndex = IsComputed (theStructure);
1039 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1040 ? myStructsComputed.Value (anIndex)->CStructure()
1041 : theStructure->CStructure();
1043 changeZLayer (aCStruct, theLayerId);
1046 // =======================================================================
1047 // function : HaveTheSameOwner
1049 // =======================================================================
1050 Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1052 // Find in the sequence of already calculated structures
1053 // 1/ Structure with the same Owner as <AStructure>
1054 // 2/ Which is not <AStructure>
1055 // 3/ COMPUTED which of is valid
1056 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1057 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1059 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1060 if (aStructToComp->Owner() == theStructure->Owner()
1061 && aStructToComp->Identification() != theStructure->Identification())
1063 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1064 if (aStructComp->HLRValidation())
1073 // =======================================================================
1074 // function : CopySettings
1076 // =======================================================================
1077 void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1079 ChangeRenderingParams() = theOther->RenderingParams();
1080 SetBackground (theOther->Background());
1081 SetGradientBackground (theOther->GradientBackground());
1082 SetBackgroundImage (theOther->BackgroundImage());
1083 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1084 SetTextureEnv (theOther->TextureEnv());
1085 SetShadingModel (theOther->ShadingModel());
1086 SetBackfacingModel (theOther->BackfacingModel());
1087 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1088 SetLights (theOther->Lights());
1089 SetClipPlanes (theOther->ClipPlanes());
1092 // =======================================================================
1093 // function : SetShadingModel
1095 // =======================================================================
1096 void Graphic3d_CView::SetShadingModel (Graphic3d_TypeOfShadingModel theModel)
1098 if (theModel == Graphic3d_TOSM_DEFAULT)
1100 throw Standard_ProgramError ("Graphic3d_CView::SetShadingModel() - attempt to set invalid Shading Model!");
1103 myShadingModel = theModel;