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 eraseStructure (aStruct->CStructure());
262 displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority());
268 // =======================================================================
269 // function : ReCompute
271 // =======================================================================
272 void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
274 theStruct->CalculateBoundBox();
275 if (!theStruct->IsMutable()
276 && !theStruct->CStructure()->IsForHighlight
277 && !theStruct->CStructure()->IsInfinite)
279 const Graphic3d_ZLayerId aLayerId = theStruct->GetZLayer();
280 InvalidateBVHData (aLayerId);
285 || !theStruct->IsDisplayed())
290 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual());
291 if (anAnswer != Graphic3d_TOA_COMPUTE)
296 const Standard_Integer anIndex = IsComputed (theStruct);
302 // compute + validation
303 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
304 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
305 aCompStruct->SetTransformation (Handle(Geom_Transformation)());
306 theStruct->IsTransformed() ? theStruct->Compute (this, theStruct->Transformation(), aCompStruct)
307 : theStruct->Compute (this, aCompStruct);
308 aCompStruct->SetHLRValidation (Standard_True);
310 // of which type will be the computed?
311 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
312 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
313 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
314 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
315 if (toComputeWireframe)
317 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
319 else if (toComputeShading)
321 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
324 if (theStruct->IsHighlighted())
326 aCompStruct->Highlight (theStruct->HighlightStyle(), Standard_False);
329 // The previous calculation is removed and the new one is displayed
330 eraseStructure (aCompStructOld->CStructure());
331 displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority());
333 // why not just replace existing items?
334 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
335 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
337 // hlhsr and the new associated compute are added
338 myStructsToCompute.Append (theStruct);
339 myStructsComputed .Append (aCompStruct);
341 // hlhsr and the new associated compute are removed
342 myStructsToCompute.Remove (anIndex);
343 myStructsComputed .Remove (anIndex);
346 // =======================================================================
349 // =======================================================================
350 void Graphic3d_CView::Update (const Graphic3d_ZLayerId theLayerId)
352 InvalidateZLayerBoundingBox (theLayerId);
355 // =======================================================================
356 // function : ContainsFacet
358 // =======================================================================
359 Standard_Boolean Graphic3d_CView::ContainsFacet() const
361 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
363 if (aStructIter.Key()->ContainsFacet())
365 return Standard_True;
368 return Standard_False;
371 // =======================================================================
372 // function : ContainsFacet
374 // =======================================================================
375 Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
377 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
379 if (aStructIter.Key()->ContainsFacet())
381 return Standard_True;
384 return Standard_False;
387 // =======================================================================
388 // function : DisplayedStructures
390 // =======================================================================
391 void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
393 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
395 theStructures.Add (aStructIter.Key());
399 // =======================================================================
400 // function : MinMaxValues
402 // =======================================================================
403 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
412 Handle(Graphic3d_Camera) aCamera = Camera();
413 Standard_Integer aWinWidth = 0;
414 Standard_Integer aWinHeight = 0;
416 Window()->Size (aWinWidth, aWinHeight);
418 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
420 Bnd_Box aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
424 theToIncludeAuxiliary);
428 Standard_Integer aMaxZLayer = ZLayerMax();
429 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
431 Bnd_Box aBox = ZLayerBoundingBox (aLayerId,
435 theToIncludeAuxiliary);
442 // =======================================================================
443 // function : ConsiderZoomPersistenceObjects
445 // =======================================================================
446 Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
453 Handle(Graphic3d_Camera) aCamera = Camera();
454 Standard_Integer aWinWidth = 0;
455 Standard_Integer aWinHeight = 0;
457 Window()->Size (aWinWidth, aWinHeight);
459 Standard_Real aMaxCoef = 1.0;
460 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
462 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
465 for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
467 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
473 // =======================================================================
474 // function : MinMaxValues
476 // =======================================================================
477 Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
478 const Standard_Boolean theToIgnoreInfiniteFlag) const
481 const Standard_Integer aViewId = Identification();
483 Handle(Graphic3d_Camera) aCamera = Camera();
484 Standard_Integer aWinWidth = 0;
485 Standard_Integer aWinHeight = 0;
488 Window()->Size (aWinWidth, aWinHeight);
491 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
493 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
494 if (aStructure->IsEmpty()
495 || !aStructure->CStructure()->IsVisible (aViewId))
500 // "FitAll" operation ignores object with transform persistence parameter
501 if (!aStructure->TransformPersistence().IsNull())
503 // Panning and 2d persistence apply changes to projection or/and its translation components.
504 // It makes them incompatible with z-fitting algorithm. Ignored by now.
505 if (!theToIgnoreInfiniteFlag
506 || aStructure->TransformPersistence()->IsTrihedronOr2d())
512 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
514 if (aBox.IsWhole() || aBox.IsVoid())
519 if (!aStructure->TransformPersistence().IsNull())
521 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
522 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
523 aStructure->TransformPersistence()->Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
526 // To prevent float overflow at camera parameters calculation and further
527 // rendering, bounding boxes with at least one vertex coordinate out of
528 // float range are skipped by view fit algorithms
529 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
530 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
531 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
532 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
533 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
534 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
544 // =======================================================================
545 // function : acceptDisplay
547 // =======================================================================
548 Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
550 switch (theStructType)
552 case Graphic3d_TOS_ALL:
554 return Graphic3d_TOA_YES; // The structure accepts any type of view
556 case Graphic3d_TOS_SHADING:
558 return myVisualization == Graphic3d_TOV_SHADING
562 case Graphic3d_TOS_WIREFRAME:
564 return myVisualization == Graphic3d_TOV_WIREFRAME
568 case Graphic3d_TOS_COMPUTED:
570 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
571 ? Graphic3d_TOA_COMPUTE
575 return Graphic3d_TOA_NO;
578 // =======================================================================
579 // function : Compute
581 // =======================================================================
582 void Graphic3d_CView::Compute()
584 // force HLRValidation to False on all structures calculated in the view
585 for (Graphic3d_SequenceOfStructure::Iterator aStructIter (myStructsComputed); aStructIter.More(); aStructIter.Next())
587 aStructIter.Value()->SetHLRValidation (Standard_False);
595 // Change of orientation or of projection type =>
596 // Remove structures that were calculated for the previous orientation.
597 // Recalculation of new structures.
598 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
599 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
601 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
602 if (anAnswer == Graphic3d_TOA_COMPUTE)
604 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
608 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
610 Display (aStructIter.ChangeValue());
614 // =======================================================================
617 // =======================================================================
618 void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
619 const Standard_Boolean theWithDestruction)
621 const Standard_Integer anIndex = IsComputed (theStructure);
624 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
625 aCompStruct->GraphicClear (theWithDestruction);
626 aCompStruct->SetHLRValidation (Standard_False);
630 // =======================================================================
631 // function : Connect
633 // =======================================================================
634 void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
635 const Handle(Graphic3d_Structure)& theDaughter)
637 Standard_Integer anIndexM = IsComputed (theMother);
638 Standard_Integer anIndexD = IsComputed (theDaughter);
642 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
643 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
644 aStructM->GraphicConnect (aStructD);
648 // =======================================================================
649 // function : Disconnect
651 // =======================================================================
652 void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
653 const Handle(Graphic3d_Structure)& theDaughter)
655 Standard_Integer anIndexM = IsComputed (theMother);
656 Standard_Integer anIndexD = IsComputed (theDaughter);
660 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
661 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
662 aStructM->GraphicDisconnect (aStructD);
666 // =======================================================================
667 // function : Display
669 // =======================================================================
670 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
677 // If Display on a structure present in the list of calculated structures while it is not
678 // or more, of calculated type =>
679 // - removes it as well as the associated old computed
680 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
681 Standard_Integer anIndex = IsComputed (theStructure);
683 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
685 myStructsToCompute.Remove (anIndex);
686 myStructsComputed .Remove (anIndex);
690 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
691 if (anAnswer == Graphic3d_TOA_NO)
698 anAnswer = Graphic3d_TOA_YES;
701 if (anAnswer == Graphic3d_TOA_YES)
703 if (!myStructsDisplayed.Add (theStructure))
708 theStructure->CalculateBoundBox();
709 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
710 Update (theStructure->GetZLayer());
713 else if (anAnswer != Graphic3d_TOA_COMPUTE)
720 // Already computed, is COMPUTED still valid?
721 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
722 if (anOldStruct->HLRValidation())
724 // Case COMPUTED valid, to be displayed
725 if (!myStructsDisplayed.Add (theStructure))
730 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
731 Update (anOldStruct->GetZLayer());
736 // Case COMPUTED invalid
737 // Is there another valid representation?
738 // Find in the sequence of already calculated structures
739 // 1/ Structure having the same Owner as <AStructure>
740 // 2/ That is not <AStructure>
741 // 3/ The COMPUTED which of is valid
742 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
745 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
746 if (!myStructsDisplayed.Add (theStructure))
751 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
752 myStructsComputed.SetValue (anIndex, aNewStruct);
753 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
754 Update (aNewStruct->GetZLayer());
759 // Case COMPUTED invalid, WITHOUT a valid of replacement
760 // COMPUTED is removed if displayed
761 if (myStructsDisplayed.Contains (theStructure))
763 eraseStructure (anOldStruct->CStructure());
769 // Compute + Validation
770 Handle(Graphic3d_Structure) aStruct;
773 aStruct = myStructsComputed.Value (anIndex);
774 aStruct->SetTransformation (Handle(Geom_Transformation)());
775 if (theStructure->IsTransformed())
777 theStructure->Compute (this, theStructure->Transformation(), aStruct);
781 theStructure->Compute (this, aStruct);
786 aStruct = theStructure->IsTransformed()
787 ? theStructure->Compute (this, theStructure->Transformation())
788 : theStructure->Compute (this);
791 aStruct->SetHLRValidation (Standard_True);
793 // TOCOMPUTE and COMPUTED associated to sequences are added
794 myStructsToCompute.Append (theStructure);
795 myStructsComputed .Append (aStruct);
797 // The previous are removed if necessary
800 myStructsToCompute.Remove (anIndex);
801 myStructsComputed .Remove (anIndex);
804 // Of which type will be the computed?
805 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
806 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
807 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
808 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
809 if (!toComputeShading && !toComputeWireframe)
811 anAnswer = Graphic3d_TOA_NO;
815 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
816 anAnswer = acceptDisplay (aStruct->Visual());
819 if (theStructure->IsHighlighted())
821 aStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
824 // It is displayed only if the calculated structure
825 // has a proper type corresponding to the one of the view.
826 if (anAnswer == Graphic3d_TOA_NO)
831 myStructsDisplayed.Add (theStructure);
832 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
834 Update (aStruct->GetZLayer());
837 // =======================================================================
840 // =======================================================================
841 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
843 if (!IsDisplayed (theStructure))
848 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
851 anAnswer = Graphic3d_TOA_YES;
854 if (anAnswer != Graphic3d_TOA_COMPUTE)
856 eraseStructure (theStructure->CStructure());
858 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
860 const Standard_Integer anIndex = IsComputed (theStructure);
863 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
864 eraseStructure (aCompStruct->CStructure());
867 myStructsDisplayed.Remove (theStructure);
868 Update (theStructure->GetZLayer());
871 // =======================================================================
872 // function : Highlight
874 // =======================================================================
875 void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure)
877 const Standard_Integer anIndex = IsComputed (theStructure);
880 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
881 aCompStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
885 // =======================================================================
886 // function : SetTransform
888 // =======================================================================
889 void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
890 const Handle(Geom_Transformation)& theTrsf)
892 const Standard_Integer anIndex = IsComputed (theStructure);
895 // Test is somewhat light !
896 // trsf is transferred only if it is :
899 if (!theTrsf.IsNull()
900 && (theTrsf->Form() == gp_Translation
901 || theTrsf->Form() == gp_Scale
902 || theTrsf->Form() == gp_CompoundTrsf))
904 ReCompute (theStructure);
908 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
909 aCompStruct->GraphicTransform (theTrsf);
913 theStructure->CalculateBoundBox();
914 if (!theStructure->IsMutable()
915 && !theStructure->CStructure()->IsForHighlight
916 && !theStructure->CStructure()->IsInfinite)
918 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
919 InvalidateBVHData (aLayerId);
923 // =======================================================================
924 // function : UnHighlight
926 // =======================================================================
927 void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
929 Standard_Integer anIndex = IsComputed (theStructure);
932 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
933 aCompStruct->CStructure()->GraphicUnhighlight();
937 // ========================================================================
938 // function : IsComputed
940 // ========================================================================
941 Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
942 Handle(Graphic3d_Structure)& theComputedStruct) const
944 theComputedStruct.Nullify();
946 return Standard_False;
948 const Standard_Integer aNbStructs = myStructsToCompute.Length();
949 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
951 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
953 theComputedStruct = myStructsComputed (aStructIter);
954 return Standard_True;
957 return Standard_False;
960 // =======================================================================
961 // function : IsComputed
963 // =======================================================================
964 Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
966 const Standard_Integer aStructId = theStructure->Identification();
967 const Standard_Integer aNbStructs = myStructsToCompute.Length();
968 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
970 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
971 if (aStruct->Identification() == aStructId)
979 // =======================================================================
980 // function : IsDisplayed
982 // =======================================================================
983 Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
985 return myStructsDisplayed.Contains (theStructure);
988 // =======================================================================
989 // function : ChangePriority
991 // =======================================================================
992 void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
993 const Standard_Integer /*theOldPriority*/,
994 const Standard_Integer theNewPriority)
997 || !IsDisplayed (theStructure))
1002 if (!myIsInComputedMode)
1004 changePriority (theStructure->CStructure(), theNewPriority);
1008 const Standard_Integer anIndex = IsComputed (theStructure);
1009 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
1010 ? myStructsComputed.Value (anIndex)->CStructure()
1011 : theStructure->CStructure();
1013 changePriority (aCStruct, theNewPriority);
1016 // =======================================================================
1017 // function : ChangeZLayer
1019 // =======================================================================
1020 void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1021 const Graphic3d_ZLayerId theLayerId)
1024 || !IsDisplayed (theStructure))
1029 if (!myIsInComputedMode)
1031 changeZLayer (theStructure->CStructure(), theLayerId);
1035 const Standard_Integer anIndex = IsComputed (theStructure);
1036 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1037 ? myStructsComputed.Value (anIndex)->CStructure()
1038 : theStructure->CStructure();
1040 changeZLayer (aCStruct, theLayerId);
1043 // =======================================================================
1044 // function : HaveTheSameOwner
1046 // =======================================================================
1047 Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1049 // Find in the sequence of already calculated structures
1050 // 1/ Structure with the same Owner as <AStructure>
1051 // 2/ Which is not <AStructure>
1052 // 3/ COMPUTED which of is valid
1053 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1054 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1056 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1057 if (aStructToComp->Owner() == theStructure->Owner()
1058 && aStructToComp->Identification() != theStructure->Identification())
1060 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1061 if (aStructComp->HLRValidation())
1070 // =======================================================================
1071 // function : CopySettings
1073 // =======================================================================
1074 void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1076 ChangeRenderingParams() = theOther->RenderingParams();
1077 SetBackground (theOther->Background());
1078 SetGradientBackground (theOther->GradientBackground());
1079 SetBackgroundImage (theOther->BackgroundImage());
1080 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1081 SetTextureEnv (theOther->TextureEnv());
1082 SetCullingEnabled (theOther->IsCullingEnabled());
1083 SetShadingModel (theOther->ShadingModel());
1084 SetBackfacingModel (theOther->BackfacingModel());
1085 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1086 SetLights (theOther->Lights());
1087 SetClipPlanes (theOther->ClipPlanes());