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 myVisualization (Graphic3d_TOV_WIREFRAME)
43 myId = myStructureManager->Identification (this);
46 //=======================================================================
47 //function : Destructor
49 //=======================================================================
50 Graphic3d_CView::~Graphic3d_CView()
54 myStructureManager->UnIdentification (this);
58 // =======================================================================
59 // function : Activate
61 // =======================================================================
62 void Graphic3d_CView::Activate()
66 myIsActive = Standard_True;
68 // Activation of a new view =>
69 // Display structures that can be displayed in this new view.
70 // All structures with status
71 // Displayed in ViewManager are returned and displayed in
72 // the view directly, if the structure is not already
73 // displayed and if the view accepts it in its context.
74 Graphic3d_MapOfStructure aDisplayedStructs;
75 myStructureManager->DisplayedStructures (aDisplayedStructs);
76 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
78 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
79 if (IsDisplayed (aStruct))
84 // If the structure can be displayed in the new context of the view, it is displayed.
85 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
86 if (anAnswer == Graphic3d_TOA_YES
87 || anAnswer == Graphic3d_TOA_COMPUTE)
97 // =======================================================================
98 // function : Deactivate
100 // =======================================================================
101 void Graphic3d_CView::Deactivate()
105 // Deactivation of a view =>
106 // Removal of structures displayed in this view.
107 // All structures with status
108 // Displayed in ViewManager are returned and removed from
109 // the view directly, if the structure is not already
110 // displayed and if the view accepts it in its context.
111 Graphic3d_MapOfStructure aDisplayedStructs;
112 myStructureManager->DisplayedStructures (aDisplayedStructs);
113 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
115 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
116 if (!IsDisplayed (aStruct))
121 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
122 if (anAnswer == Graphic3d_TOA_YES
123 || anAnswer == Graphic3d_TOA_COMPUTE)
130 myIsActive = Standard_False;
134 // ========================================================================
137 // ========================================================================
138 void Graphic3d_CView::Remove()
145 Graphic3d_MapOfStructure aDisplayedStructs (myStructsDisplayed);
147 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
149 Erase (aStructIter.Value());
152 myStructsToCompute.Clear();
153 myStructsComputed .Clear();
154 myStructsDisplayed.Clear();
156 if (!myStructureManager.IsNull())
158 myStructureManager->UnIdentification (this);
161 myIsActive = Standard_False;
162 myIsRemoved = Standard_True;
165 // ========================================================================
166 // function : SetComputedMode
168 // ========================================================================
169 void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode)
171 if (( theMode && myIsInComputedMode)
172 || (!theMode && !myIsInComputedMode))
177 myIsInComputedMode = theMode;
178 if (!myIsInComputedMode)
180 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
182 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
183 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
184 if (anAnswer != Graphic3d_TOA_COMPUTE)
189 const Standard_Integer anIndex = IsComputed (aStruct);
192 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
193 eraseStructure (aStructComp->CStructure());
194 displayStructure (aStruct->CStructure(), aStruct->DisplayPriority());
200 for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
202 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
203 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual());
204 if (anAnswer != Graphic3d_TOA_COMPUTE)
209 const Standard_Integer anIndex = IsComputed (aStruct);
212 eraseStructure (aStruct->CStructure());
213 displayStructure (myStructsComputed.Value (anIndex)->CStructure(), aStruct->DisplayPriority());
216 if (aStruct->IsHighlighted())
218 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
219 if (!aCompStruct->IsHighlighted())
221 aCompStruct->Highlight (aStruct->HighlightStyle(), Standard_False);
227 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aStruct->Transformation()) : aStruct->Compute (this);
228 aCompStruct->SetHLRValidation (Standard_True);
230 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
231 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
232 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
233 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
234 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
235 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
237 if (aStruct->IsHighlighted())
239 aCompStruct->Highlight (aStruct->HighlightStyle(), Standard_False);
242 Standard_Boolean hasResult = Standard_False;
243 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
244 const Standard_Integer aStructId = aStruct->Identification();
245 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
247 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
249 hasResult = Standard_True;
250 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
257 myStructsToCompute.Append (aStruct);
258 myStructsComputed .Append (aCompStruct);
261 aCompStruct->CalculateBoundBox();
262 eraseStructure (aStruct->CStructure());
263 displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
269 // =======================================================================
270 // function : ReCompute
272 // =======================================================================
273 void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
275 theStruct->CalculateBoundBox();
276 if (!theStruct->IsMutable()
277 && !theStruct->CStructure()->IsForHighlight
278 && !theStruct->CStructure()->IsInfinite)
280 const Graphic3d_ZLayerId aLayerId = theStruct->GetZLayer();
281 InvalidateBVHData (aLayerId);
286 || !theStruct->IsDisplayed())
291 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual());
292 if (anAnswer != Graphic3d_TOA_COMPUTE)
297 const Standard_Integer anIndex = IsComputed (theStruct);
303 // compute + validation
304 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
305 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
306 aCompStruct->SetTransformation (Handle(Geom_Transformation)());
307 theStruct->IsTransformed() ? theStruct->Compute (this, theStruct->Transformation(), aCompStruct)
308 : theStruct->Compute (this, aCompStruct);
309 aCompStruct->SetHLRValidation (Standard_True);
310 aCompStruct->CalculateBoundBox();
312 // of which type will be the computed?
313 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
314 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
315 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
316 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
317 if (toComputeWireframe)
319 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
321 else if (toComputeShading)
323 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
326 if (theStruct->IsHighlighted())
328 aCompStruct->Highlight (theStruct->HighlightStyle(), Standard_False);
331 // The previous calculation is removed and the new one is displayed
332 eraseStructure (aCompStructOld->CStructure());
333 displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority());
335 // why not just replace existing items?
336 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
337 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
339 // hlhsr and the new associated compute are added
340 myStructsToCompute.Append (theStruct);
341 myStructsComputed .Append (aCompStruct);
343 // hlhsr and the new associated compute are removed
344 myStructsToCompute.Remove (anIndex);
345 myStructsComputed .Remove (anIndex);
348 // =======================================================================
351 // =======================================================================
352 void Graphic3d_CView::Update (const Graphic3d_ZLayerId theLayerId)
354 InvalidateZLayerBoundingBox (theLayerId);
357 // =======================================================================
358 // function : ContainsFacet
360 // =======================================================================
361 Standard_Boolean Graphic3d_CView::ContainsFacet() const
363 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
365 if (aStructIter.Key()->ContainsFacet())
367 return Standard_True;
370 return Standard_False;
373 // =======================================================================
374 // function : ContainsFacet
376 // =======================================================================
377 Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
379 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
381 if (aStructIter.Key()->ContainsFacet())
383 return Standard_True;
386 return Standard_False;
389 // =======================================================================
390 // function : DisplayedStructures
392 // =======================================================================
393 void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
395 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
397 theStructures.Add (aStructIter.Key());
401 // =======================================================================
402 // function : MinMaxValues
404 // =======================================================================
405 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
414 Handle(Graphic3d_Camera) aCamera = Camera();
415 Standard_Integer aWinWidth = 0;
416 Standard_Integer aWinHeight = 0;
418 Window()->Size (aWinWidth, aWinHeight);
420 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
422 Bnd_Box aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
426 theToIncludeAuxiliary);
430 Standard_Integer aMaxZLayer = ZLayerMax();
431 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
433 Bnd_Box aBox = ZLayerBoundingBox (aLayerId,
437 theToIncludeAuxiliary);
444 // =======================================================================
445 // function : ConsiderZoomPersistenceObjects
447 // =======================================================================
448 Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
455 Handle(Graphic3d_Camera) aCamera = Camera();
456 Standard_Integer aWinWidth = 0;
457 Standard_Integer aWinHeight = 0;
459 Window()->Size (aWinWidth, aWinHeight);
461 Standard_Real aMaxCoef = 1.0;
462 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
464 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
467 for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
469 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
475 // =======================================================================
476 // function : MinMaxValues
478 // =======================================================================
479 Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
480 const Standard_Boolean theToIgnoreInfiniteFlag) const
483 const Standard_Integer aViewId = Identification();
485 Handle(Graphic3d_Camera) aCamera = Camera();
486 Standard_Integer aWinWidth = 0;
487 Standard_Integer aWinHeight = 0;
490 Window()->Size (aWinWidth, aWinHeight);
493 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
495 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
496 if (aStructure->IsEmpty()
497 || !aStructure->CStructure()->IsVisible (aViewId))
502 // "FitAll" operation ignores object with transform persistence parameter
503 if (!aStructure->TransformPersistence().IsNull())
505 // Panning and 2d persistence apply changes to projection or/and its translation components.
506 // It makes them incompatible with z-fitting algorithm. Ignored by now.
507 if (!theToIgnoreInfiniteFlag
508 || aStructure->TransformPersistence()->IsTrihedronOr2d())
514 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
516 if (aBox.IsWhole() || aBox.IsVoid())
521 if (!aStructure->TransformPersistence().IsNull())
523 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
524 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
525 aStructure->TransformPersistence()->Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
528 // To prevent float overflow at camera parameters calculation and further
529 // rendering, bounding boxes with at least one vertex coordinate out of
530 // float range are skipped by view fit algorithms
531 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
532 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
533 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
534 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
535 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
536 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
546 // =======================================================================
547 // function : acceptDisplay
549 // =======================================================================
550 Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
552 switch (theStructType)
554 case Graphic3d_TOS_ALL:
556 return Graphic3d_TOA_YES; // The structure accepts any type of view
558 case Graphic3d_TOS_SHADING:
560 return myVisualization == Graphic3d_TOV_SHADING
564 case Graphic3d_TOS_WIREFRAME:
566 return myVisualization == Graphic3d_TOV_WIREFRAME
570 case Graphic3d_TOS_COMPUTED:
572 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
573 ? Graphic3d_TOA_COMPUTE
577 return Graphic3d_TOA_NO;
580 // =======================================================================
581 // function : Compute
583 // =======================================================================
584 void Graphic3d_CView::Compute()
586 // force HLRValidation to False on all structures calculated in the view
587 for (Graphic3d_SequenceOfStructure::Iterator aStructIter (myStructsComputed); aStructIter.More(); aStructIter.Next())
589 aStructIter.Value()->SetHLRValidation (Standard_False);
597 // Change of orientation or of projection type =>
598 // Remove structures that were calculated for the previous orientation.
599 // Recalculation of new structures.
600 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
601 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
603 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
604 if (anAnswer == Graphic3d_TOA_COMPUTE)
606 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
610 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
612 Display (aStructIter.ChangeValue());
616 // =======================================================================
619 // =======================================================================
620 void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
621 const Standard_Boolean theWithDestruction)
623 const Standard_Integer anIndex = IsComputed (theStructure);
626 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
627 aCompStruct->GraphicClear (theWithDestruction);
628 aCompStruct->SetHLRValidation (Standard_False);
632 // =======================================================================
633 // function : Connect
635 // =======================================================================
636 void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
637 const Handle(Graphic3d_Structure)& theDaughter)
639 Standard_Integer anIndexM = IsComputed (theMother);
640 Standard_Integer anIndexD = IsComputed (theDaughter);
644 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
645 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
646 aStructM->GraphicConnect (aStructD);
650 // =======================================================================
651 // function : Disconnect
653 // =======================================================================
654 void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
655 const Handle(Graphic3d_Structure)& theDaughter)
657 Standard_Integer anIndexM = IsComputed (theMother);
658 Standard_Integer anIndexD = IsComputed (theDaughter);
662 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
663 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
664 aStructM->GraphicDisconnect (aStructD);
668 // =======================================================================
669 // function : Display
671 // =======================================================================
672 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
679 // If Display on a structure present in the list of calculated structures while it is not
680 // or more, of calculated type =>
681 // - removes it as well as the associated old computed
682 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
683 Standard_Integer anIndex = IsComputed (theStructure);
685 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
687 myStructsToCompute.Remove (anIndex);
688 myStructsComputed .Remove (anIndex);
692 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
693 if (anAnswer == Graphic3d_TOA_NO)
700 anAnswer = Graphic3d_TOA_YES;
703 if (anAnswer == Graphic3d_TOA_YES)
705 if (!myStructsDisplayed.Add (theStructure))
710 theStructure->CalculateBoundBox();
711 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
712 Update (theStructure->GetZLayer());
715 else if (anAnswer != Graphic3d_TOA_COMPUTE)
722 // Already computed, is COMPUTED still valid?
723 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
724 if (anOldStruct->HLRValidation())
726 // Case COMPUTED valid, to be displayed
727 if (!myStructsDisplayed.Add (theStructure))
732 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
733 Update (anOldStruct->GetZLayer());
738 // Case COMPUTED invalid
739 // Is there another valid representation?
740 // Find in the sequence of already calculated structures
741 // 1/ Structure having the same Owner as <AStructure>
742 // 2/ That is not <AStructure>
743 // 3/ The COMPUTED which of is valid
744 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
747 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
748 if (!myStructsDisplayed.Add (theStructure))
753 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
754 myStructsComputed.SetValue (anIndex, aNewStruct);
755 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
756 Update (aNewStruct->GetZLayer());
761 // Case COMPUTED invalid, WITHOUT a valid of replacement
762 // COMPUTED is removed if displayed
763 if (myStructsDisplayed.Contains (theStructure))
765 eraseStructure (anOldStruct->CStructure());
771 // Compute + Validation
772 Handle(Graphic3d_Structure) aStruct;
775 aStruct = myStructsComputed.Value (anIndex);
776 aStruct->SetTransformation (Handle(Geom_Transformation)());
777 if (theStructure->IsTransformed())
779 theStructure->Compute (this, theStructure->Transformation(), aStruct);
783 theStructure->Compute (this, aStruct);
788 aStruct = theStructure->IsTransformed()
789 ? theStructure->Compute (this, theStructure->Transformation())
790 : theStructure->Compute (this);
793 aStruct->SetHLRValidation (Standard_True);
795 // TOCOMPUTE and COMPUTED associated to sequences are added
796 myStructsToCompute.Append (theStructure);
797 myStructsComputed .Append (aStruct);
799 // The previous are removed if necessary
802 myStructsToCompute.Remove (anIndex);
803 myStructsComputed .Remove (anIndex);
806 // Of which type will be the computed?
807 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
808 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
809 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
810 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
811 if (!toComputeShading && !toComputeWireframe)
813 anAnswer = Graphic3d_TOA_NO;
817 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
818 anAnswer = acceptDisplay (aStruct->Visual());
821 if (theStructure->IsHighlighted())
823 aStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
826 // It is displayed only if the calculated structure
827 // has a proper type corresponding to the one of the view.
828 if (anAnswer == Graphic3d_TOA_NO)
833 myStructsDisplayed.Add (theStructure);
834 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
836 Update (aStruct->GetZLayer());
839 // =======================================================================
842 // =======================================================================
843 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
845 if (!IsDisplayed (theStructure))
850 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
853 anAnswer = Graphic3d_TOA_YES;
856 if (anAnswer != Graphic3d_TOA_COMPUTE)
858 eraseStructure (theStructure->CStructure());
860 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
862 const Standard_Integer anIndex = IsComputed (theStructure);
865 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
866 eraseStructure (aCompStruct->CStructure());
869 myStructsDisplayed.Remove (theStructure);
870 Update (theStructure->GetZLayer());
873 // =======================================================================
874 // function : Highlight
876 // =======================================================================
877 void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure)
879 const Standard_Integer anIndex = IsComputed (theStructure);
882 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
883 aCompStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
887 // =======================================================================
888 // function : SetTransform
890 // =======================================================================
891 void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
892 const Handle(Geom_Transformation)& theTrsf)
894 const Standard_Integer anIndex = IsComputed (theStructure);
897 // Test is somewhat light !
898 // trsf is transferred only if it is :
901 if (!theTrsf.IsNull()
902 && (theTrsf->Form() == gp_Translation
903 || theTrsf->Form() == gp_Scale
904 || theTrsf->Form() == gp_CompoundTrsf))
906 ReCompute (theStructure);
910 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
911 aCompStruct->GraphicTransform (theTrsf);
915 theStructure->CalculateBoundBox();
916 if (!theStructure->IsMutable()
917 && !theStructure->CStructure()->IsForHighlight
918 && !theStructure->CStructure()->IsInfinite)
920 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
921 InvalidateBVHData (aLayerId);
925 // =======================================================================
926 // function : UnHighlight
928 // =======================================================================
929 void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
931 Standard_Integer anIndex = IsComputed (theStructure);
934 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
935 aCompStruct->CStructure()->GraphicUnhighlight();
939 // ========================================================================
940 // function : IsComputed
942 // ========================================================================
943 Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
944 Handle(Graphic3d_Structure)& theComputedStruct) const
946 theComputedStruct.Nullify();
948 return Standard_False;
950 const Standard_Integer aNbStructs = myStructsToCompute.Length();
951 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
953 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
955 theComputedStruct = myStructsComputed (aStructIter);
956 return Standard_True;
959 return Standard_False;
962 // =======================================================================
963 // function : IsComputed
965 // =======================================================================
966 Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
968 const Standard_Integer aStructId = theStructure->Identification();
969 const Standard_Integer aNbStructs = myStructsToCompute.Length();
970 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
972 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
973 if (aStruct->Identification() == aStructId)
981 // =======================================================================
982 // function : IsDisplayed
984 // =======================================================================
985 Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
987 return myStructsDisplayed.Contains (theStructure);
990 // =======================================================================
991 // function : ChangePriority
993 // =======================================================================
994 void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
995 const Standard_Integer /*theOldPriority*/,
996 const Standard_Integer theNewPriority)
999 || !IsDisplayed (theStructure))
1004 if (!myIsInComputedMode)
1006 changePriority (theStructure->CStructure(), theNewPriority);
1010 const Standard_Integer anIndex = IsComputed (theStructure);
1011 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
1012 ? myStructsComputed.Value (anIndex)->CStructure()
1013 : theStructure->CStructure();
1015 changePriority (aCStruct, theNewPriority);
1018 // =======================================================================
1019 // function : ChangeZLayer
1021 // =======================================================================
1022 void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1023 const Graphic3d_ZLayerId theLayerId)
1026 || !IsDisplayed (theStructure))
1031 if (!myIsInComputedMode)
1033 changeZLayer (theStructure->CStructure(), theLayerId);
1037 const Standard_Integer anIndex = IsComputed (theStructure);
1038 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1039 ? myStructsComputed.Value (anIndex)->CStructure()
1040 : theStructure->CStructure();
1042 changeZLayer (aCStruct, theLayerId);
1045 // =======================================================================
1046 // function : HaveTheSameOwner
1048 // =======================================================================
1049 Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1051 // Find in the sequence of already calculated structures
1052 // 1/ Structure with the same Owner as <AStructure>
1053 // 2/ Which is not <AStructure>
1054 // 3/ COMPUTED which of is valid
1055 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1056 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1058 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1059 if (aStructToComp->Owner() == theStructure->Owner()
1060 && aStructToComp->Identification() != theStructure->Identification())
1062 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1063 if (aStructComp->HLRValidation())
1072 // =======================================================================
1073 // function : CopySettings
1075 // =======================================================================
1076 void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1078 ChangeRenderingParams() = theOther->RenderingParams();
1079 SetBackground (theOther->Background());
1080 SetGradientBackground (theOther->GradientBackground());
1081 SetBackgroundImage (theOther->BackgroundImage());
1082 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1083 SetTextureEnv (theOther->TextureEnv());
1084 SetCullingEnabled (theOther->IsCullingEnabled());
1085 SetShadingModel (theOther->ShadingModel());
1086 SetBackfacingModel (theOther->BackfacingModel());
1087 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1088 SetLights (theOther->Lights());
1089 SetClipPlanes (theOther->ClipPlanes());