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)
89 Display (aStruct, Aspect_TOU_WAIT);
94 Update (myStructureManager->UpdateMode());
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)
125 Erase (aStruct, Aspect_TOU_WAIT);
129 Update (myStructureManager->UpdateMode());
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(), Aspect_TOU_WAIT);
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());
215 Display (aStruct, Aspect_TOU_WAIT);
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());
265 Update (myStructureManager->UpdateMode());
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 Aspect_TypeOfUpdate theUpdateMode,
351 const Graphic3d_ZLayerId theLayerId)
353 InvalidateZLayerBoundingBox (theLayerId);
355 if (theUpdateMode == Aspect_TOU_ASAP)
362 // =======================================================================
363 // function : ContainsFacet
365 // =======================================================================
366 Standard_Boolean Graphic3d_CView::ContainsFacet() const
368 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
370 if (aStructIter.Key()->ContainsFacet())
372 return Standard_True;
375 return Standard_False;
378 // =======================================================================
379 // function : ContainsFacet
381 // =======================================================================
382 Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
384 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
386 if (aStructIter.Key()->ContainsFacet())
388 return Standard_True;
391 return Standard_False;
394 // =======================================================================
395 // function : DisplayedStructures
397 // =======================================================================
398 void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
400 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
402 theStructures.Add (aStructIter.Key());
406 // =======================================================================
407 // function : MinMaxValues
409 // =======================================================================
410 Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
419 Handle(Graphic3d_Camera) aCamera = Camera();
420 Standard_Integer aWinWidth = 0;
421 Standard_Integer aWinHeight = 0;
423 Window()->Size (aWinWidth, aWinHeight);
425 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
427 Bnd_Box aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
431 theToIncludeAuxiliary);
435 Standard_Integer aMaxZLayer = ZLayerMax();
436 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
438 Bnd_Box aBox = ZLayerBoundingBox (aLayerId,
442 theToIncludeAuxiliary);
449 // =======================================================================
450 // function : ConsiderZoomPersistenceObjects
452 // =======================================================================
453 Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
460 Handle(Graphic3d_Camera) aCamera = Camera();
461 Standard_Integer aWinWidth = 0;
462 Standard_Integer aWinHeight = 0;
464 Window()->Size (aWinWidth, aWinHeight);
466 Standard_Real aMaxCoef = 1.0;
467 for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
469 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight));
472 for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
474 aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight));
480 // =======================================================================
481 // function : MinMaxValues
483 // =======================================================================
484 Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
485 const Standard_Boolean theToIgnoreInfiniteFlag) const
488 const Standard_Integer aViewId = Identification();
490 Handle(Graphic3d_Camera) aCamera = Camera();
491 Standard_Integer aWinWidth = 0;
492 Standard_Integer aWinHeight = 0;
495 Window()->Size (aWinWidth, aWinHeight);
498 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
500 const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
501 if (aStructure->IsEmpty()
502 || !aStructure->CStructure()->IsVisible (aViewId))
507 // "FitAll" operation ignores object with transform persistence parameter
508 if (!aStructure->TransformPersistence().IsNull())
510 // Panning and 2d persistence apply changes to projection or/and its translation components.
511 // It makes them incompatible with z-fitting algorithm. Ignored by now.
512 if (!theToIgnoreInfiniteFlag
513 || aStructure->TransformPersistence()->IsTrihedronOr2d())
519 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
521 if (aBox.IsWhole() || aBox.IsVoid())
526 if (!aStructure->TransformPersistence().IsNull())
528 const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
529 const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
530 aStructure->TransformPersistence()->Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
533 // To prevent float overflow at camera parameters calculation and further
534 // rendering, bounding boxes with at least one vertex coordinate out of
535 // float range are skipped by view fit algorithms
536 if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
537 Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
538 Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
539 Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
540 Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
541 Abs (aBox.CornerMin().Z()) >= ShortRealLast())
551 // =======================================================================
552 // function : acceptDisplay
554 // =======================================================================
555 Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const
557 switch (theStructType)
559 case Graphic3d_TOS_ALL:
561 return Graphic3d_TOA_YES; // The structure accepts any type of view
563 case Graphic3d_TOS_SHADING:
565 return myVisualization == Graphic3d_TOV_SHADING
569 case Graphic3d_TOS_WIREFRAME:
571 return myVisualization == Graphic3d_TOV_WIREFRAME
575 case Graphic3d_TOS_COMPUTED:
577 return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME)
578 ? Graphic3d_TOA_COMPUTE
582 return Graphic3d_TOA_NO;
585 // =======================================================================
586 // function : Compute
588 // =======================================================================
589 void Graphic3d_CView::Compute()
591 // force HLRValidation to False on all structures calculated in the view
592 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
593 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
595 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
603 // Change of orientation or of projection type =>
604 // Remove structures that were calculated for the previous orientation.
605 // Recalculation of new structures.
606 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
607 for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
609 const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual());
610 if (anAnswer == Graphic3d_TOA_COMPUTE)
612 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
616 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
618 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
622 // =======================================================================
625 // =======================================================================
626 void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure,
627 const Standard_Boolean theWithDestruction)
629 const Standard_Integer anIndex = IsComputed (theStructure);
632 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
633 aCompStruct->GraphicClear (theWithDestruction);
634 aCompStruct->SetHLRValidation (Standard_False);
638 // =======================================================================
639 // function : Connect
641 // =======================================================================
642 void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother,
643 const Handle(Graphic3d_Structure)& theDaughter)
645 Standard_Integer anIndexM = IsComputed (theMother);
646 Standard_Integer anIndexD = IsComputed (theDaughter);
650 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
651 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
652 aStructM->GraphicConnect (aStructD);
656 // =======================================================================
657 // function : Disconnect
659 // =======================================================================
660 void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother,
661 const Handle(Graphic3d_Structure)& theDaughter)
663 Standard_Integer anIndexM = IsComputed (theMother);
664 Standard_Integer anIndexD = IsComputed (theDaughter);
668 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
669 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
670 aStructM->GraphicDisconnect (aStructD);
674 // =======================================================================
675 // function : Display
677 // =======================================================================
678 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure)
680 Display (theStructure, myStructureManager->UpdateMode());
683 // =======================================================================
684 // function : Display
686 // =======================================================================
687 void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
688 const Aspect_TypeOfUpdate theUpdateMode)
695 // If Display on a structure present in the list of calculated structures while it is not
696 // or more, of calculated type =>
697 // - removes it as well as the associated old computed
698 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
699 Standard_Integer anIndex = IsComputed (theStructure);
701 && theStructure->Visual() != Graphic3d_TOS_COMPUTED)
703 myStructsToCompute.Remove (anIndex);
704 myStructsComputed .Remove (anIndex);
708 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
709 if (anAnswer == Graphic3d_TOA_NO)
716 anAnswer = Graphic3d_TOA_YES;
719 if (anAnswer == Graphic3d_TOA_YES)
721 if (!myStructsDisplayed.Add (theStructure))
726 theStructure->CalculateBoundBox();
727 displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
728 Update (theUpdateMode, theStructure->GetZLayer());
731 else if (anAnswer != Graphic3d_TOA_COMPUTE)
738 // Already computed, is COMPUTED still valid?
739 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
740 if (anOldStruct->HLRValidation())
742 // Case COMPUTED valid, to be displayed
743 if (!myStructsDisplayed.Add (theStructure))
748 displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
749 Update (theUpdateMode, anOldStruct->GetZLayer());
754 // Case COMPUTED invalid
755 // Is there another valid representation?
756 // Find in the sequence of already calculated structures
757 // 1/ Structure having the same Owner as <AStructure>
758 // 2/ That is not <AStructure>
759 // 3/ The COMPUTED which of is valid
760 const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure);
763 // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed
764 if (!myStructsDisplayed.Add (theStructure))
769 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
770 myStructsComputed.SetValue (anIndex, aNewStruct);
771 displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
772 Update (theUpdateMode, aNewStruct->GetZLayer());
777 // Case COMPUTED invalid, WITHOUT a valid of replacement
778 // COMPUTED is removed if displayed
779 if (myStructsDisplayed.Contains (theStructure))
781 eraseStructure (anOldStruct->CStructure());
787 // Compute + Validation
788 Handle(Graphic3d_Structure) aStruct;
791 aStruct = myStructsComputed.Value (anIndex);
792 aStruct->SetTransformation (Handle(Geom_Transformation)());
793 if (theStructure->IsTransformed())
795 theStructure->Compute (this, theStructure->Transformation(), aStruct);
799 theStructure->Compute (this, aStruct);
804 aStruct = theStructure->IsTransformed()
805 ? theStructure->Compute (this, theStructure->Transformation())
806 : theStructure->Compute (this);
809 aStruct->SetHLRValidation (Standard_True);
811 // TOCOMPUTE and COMPUTED associated to sequences are added
812 myStructsToCompute.Append (theStructure);
813 myStructsComputed .Append (aStruct);
815 // The previous are removed if necessary
818 myStructsToCompute.Remove (anIndex);
819 myStructsComputed .Remove (anIndex);
822 // Of which type will be the computed?
823 const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME
824 && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING;
825 const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING
826 && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
827 if (!toComputeShading && !toComputeWireframe)
829 anAnswer = Graphic3d_TOA_NO;
833 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
834 anAnswer = acceptDisplay (aStruct->Visual());
837 if (theStructure->IsHighlighted())
839 aStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
842 // It is displayed only if the calculated structure
843 // has a proper type corresponding to the one of the view.
844 if (anAnswer == Graphic3d_TOA_NO)
849 myStructsDisplayed.Add (theStructure);
850 displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
852 Update (theUpdateMode, aStruct->GetZLayer());
855 // =======================================================================
858 // =======================================================================
859 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure)
861 Erase (theStructure, myStructureManager->UpdateMode());
864 // =======================================================================
867 // =======================================================================
868 void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure,
869 const Aspect_TypeOfUpdate theUpdateMode)
871 if (!IsDisplayed (theStructure))
876 Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual());
879 anAnswer = Graphic3d_TOA_YES;
882 if (anAnswer != Graphic3d_TOA_COMPUTE)
884 eraseStructure (theStructure->CStructure());
886 else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode)
888 const Standard_Integer anIndex = IsComputed (theStructure);
891 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
892 eraseStructure (aCompStruct->CStructure());
895 myStructsDisplayed.Remove (theStructure);
896 Update (theUpdateMode, theStructure->GetZLayer());
899 // =======================================================================
900 // function : Highlight
902 // =======================================================================
903 void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure)
905 const Standard_Integer anIndex = IsComputed (theStructure);
908 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
909 aCompStruct->Highlight (theStructure->HighlightStyle(), Standard_False);
913 // =======================================================================
914 // function : SetTransform
916 // =======================================================================
917 void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure,
918 const Handle(Geom_Transformation)& theTrsf)
920 const Standard_Integer anIndex = IsComputed (theStructure);
923 // Test is somewhat light !
924 // trsf is transferred only if it is :
927 if (!theTrsf.IsNull()
928 && (theTrsf->Form() == gp_Translation
929 || theTrsf->Form() == gp_Scale
930 || theTrsf->Form() == gp_CompoundTrsf))
932 ReCompute (theStructure);
936 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
937 aCompStruct->GraphicTransform (theTrsf);
941 theStructure->CalculateBoundBox();
942 if (!theStructure->IsMutable()
943 && !theStructure->CStructure()->IsForHighlight
944 && !theStructure->CStructure()->IsInfinite)
946 const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer();
947 InvalidateBVHData (aLayerId);
951 // =======================================================================
952 // function : UnHighlight
954 // =======================================================================
955 void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure)
957 Standard_Integer anIndex = IsComputed (theStructure);
960 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
961 aCompStruct->CStructure()->GraphicUnhighlight();
965 // ========================================================================
966 // function : IsComputed
968 // ========================================================================
969 Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId,
970 Handle(Graphic3d_Structure)& theComputedStruct) const
972 theComputedStruct.Nullify();
974 return Standard_False;
976 const Standard_Integer aNbStructs = myStructsToCompute.Length();
977 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
979 if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId)
981 theComputedStruct = myStructsComputed (aStructIter);
982 return Standard_True;
985 return Standard_False;
988 // =======================================================================
989 // function : IsComputed
991 // =======================================================================
992 Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const
994 const Standard_Integer aStructId = theStructure->Identification();
995 const Standard_Integer aNbStructs = myStructsToCompute.Length();
996 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
998 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
999 if (aStruct->Identification() == aStructId)
1007 // =======================================================================
1008 // function : IsDisplayed
1010 // =======================================================================
1011 Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const
1013 return myStructsDisplayed.Contains (theStructure);
1016 // =======================================================================
1017 // function : ChangePriority
1019 // =======================================================================
1020 void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure,
1021 const Standard_Integer /*theOldPriority*/,
1022 const Standard_Integer theNewPriority)
1025 || !IsDisplayed (theStructure))
1030 if (!myIsInComputedMode)
1032 changePriority (theStructure->CStructure(), theNewPriority);
1036 const Standard_Integer anIndex = IsComputed (theStructure);
1037 const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0
1038 ? myStructsComputed.Value (anIndex)->CStructure()
1039 : theStructure->CStructure();
1041 changePriority (aCStruct, theNewPriority);
1044 // =======================================================================
1045 // function : ChangeZLayer
1047 // =======================================================================
1048 void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1049 const Graphic3d_ZLayerId theLayerId)
1052 || !IsDisplayed (theStructure))
1057 if (!myIsInComputedMode)
1059 changeZLayer (theStructure->CStructure(), theLayerId);
1063 const Standard_Integer anIndex = IsComputed (theStructure);
1064 Handle(Graphic3d_CStructure) aCStruct = anIndex != 0
1065 ? myStructsComputed.Value (anIndex)->CStructure()
1066 : theStructure->CStructure();
1068 changeZLayer (aCStruct, theLayerId);
1071 // =======================================================================
1072 // function : HaveTheSameOwner
1074 // =======================================================================
1075 Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const
1077 // Find in the sequence of already calculated structures
1078 // 1/ Structure with the same Owner as <AStructure>
1079 // 2/ Which is not <AStructure>
1080 // 3/ COMPUTED which of is valid
1081 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
1082 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
1084 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
1085 if (aStructToComp->Owner() == theStructure->Owner()
1086 && aStructToComp->Identification() != theStructure->Identification())
1088 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
1089 if (aStructComp->HLRValidation())
1098 // =======================================================================
1099 // function : CopySettings
1101 // =======================================================================
1102 void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
1104 ChangeRenderingParams() = theOther->RenderingParams();
1105 SetBackground (theOther->Background());
1106 SetGradientBackground (theOther->GradientBackground());
1107 SetBackgroundImage (theOther->BackgroundImage());
1108 SetBackgroundImageStyle (theOther->BackgroundImageStyle());
1109 SetTextureEnv (theOther->TextureEnv());
1110 SetCullingEnabled (theOther->IsCullingEnabled());
1111 SetShadingModel (theOther->ShadingModel());
1112 SetBackfacingModel (theOther->BackfacingModel());
1113 SetCamera (new Graphic3d_Camera (theOther->Camera()));
1114 SetLights (theOther->Lights());
1115 SetClipPlanes (theOther->ClipPlanes());