1 // Copyright (c) 1999-2014 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 <V3d_Viewer.hxx>
16 #include <Aspect_IdentDefinitionError.hxx>
17 #include <Graphic3d_ArrayOfPoints.hxx>
18 #include <Graphic3d_ArrayOfSegments.hxx>
19 #include <Graphic3d_AspectMarker3d.hxx>
20 #include <Graphic3d_AspectText3d.hxx>
21 #include <Graphic3d_GraphicDriver.hxx>
22 #include <Graphic3d_Group.hxx>
23 #include <Graphic3d_Structure.hxx>
24 #include <Graphic3d_Text.hxx>
25 #include <Standard_ErrorHandler.hxx>
27 #include <V3d_BadValue.hxx>
28 #include <V3d_CircularGrid.hxx>
29 #include <V3d_AmbientLight.hxx>
30 #include <V3d_DirectionalLight.hxx>
31 #include <V3d_RectangularGrid.hxx>
32 #include <V3d_View.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(V3d_Viewer, Standard_Transient)
36 // ========================================================================
37 // function : V3d_Viewer
39 // ========================================================================
40 V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver)
41 : myDriver (theDriver),
42 myStructureManager (new Graphic3d_StructureManager (theDriver)),
43 myZLayerGenId (1, IntegerLast()),
44 myBackground (Quantity_NOC_GRAY30),
46 myViewProj (V3d_XposYnegZpos),
47 myVisualization (V3d_ZBUFFER),
48 myDefaultTypeOfView (V3d_ORTHOGRAPHIC),
49 myComputedMode (Standard_True),
50 myDefaultComputedMode (Standard_False),
51 myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
52 myDisplayPlane (Standard_False),
53 myDisplayPlaneLength (1000.0),
54 myGridType (Aspect_GT_Rectangular),
55 myGridEcho (Standard_True),
56 myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast())
61 // ========================================================================
62 // function : CreateView
64 // ========================================================================
65 Handle(V3d_View) V3d_Viewer::CreateView ()
67 return new V3d_View(this, myDefaultTypeOfView);
70 // ========================================================================
71 // function : SetViewOn
73 // ========================================================================
74 void V3d_Viewer::SetViewOn()
76 for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
78 SetViewOn (aDefViewIter.Value());
82 // ========================================================================
83 // function : SetViewOff
85 // ========================================================================
86 void V3d_Viewer::SetViewOff()
88 for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
90 SetViewOff (aDefViewIter.Value());
94 // ========================================================================
95 // function : SetViewOn
97 // ========================================================================
98 void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView)
100 Handle(Graphic3d_CView) aViewImpl = theView->View();
101 if (!aViewImpl->IsDefined() || myActiveViews.Contains (theView))
106 myActiveViews.Append (theView);
107 aViewImpl->Activate();
108 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
110 theView->SetLightOn (anActiveLightIter.Value());
112 if (Handle(Aspect_Grid) aGrid = Grid (false))
114 theView->SetGrid (myPrivilegedPlane, aGrid);
115 theView->SetGridActivity (aGrid->IsActive());
117 if (theView->SetImmediateUpdate (Standard_False))
120 theView->SetImmediateUpdate (Standard_True);
124 // ========================================================================
125 // function : SetViewOff
127 // ========================================================================
128 void V3d_Viewer::SetViewOff (const Handle(V3d_View)& theView)
130 Handle(Graphic3d_CView) aViewImpl = theView->View();
131 if (aViewImpl->IsDefined() && myActiveViews.Contains (theView))
133 myActiveViews.Remove (theView);
134 aViewImpl->Deactivate() ;
138 // ========================================================================
141 // ========================================================================
142 void V3d_Viewer::Redraw() const
144 for (int aSubViewPass = 0; aSubViewPass < 2; ++aSubViewPass)
146 // redraw subviews first
147 const bool isSubViewPass = (aSubViewPass == 0);
148 for (const Handle(V3d_View)& aViewIter : myDefinedViews)
151 && aViewIter->IsSubview())
155 else if (!isSubViewPass
156 && !aViewIter->IsSubview())
164 // ========================================================================
165 // function : RedrawImmediate
167 // ========================================================================
168 void V3d_Viewer::RedrawImmediate() const
170 for (int aSubViewPass = 0; aSubViewPass < 2; ++aSubViewPass)
172 // redraw subviews first
173 const bool isSubViewPass = (aSubViewPass == 0);
174 for (const Handle(V3d_View)& aViewIter : myDefinedViews)
177 && aViewIter->IsSubview())
179 aViewIter->RedrawImmediate();
181 else if (!isSubViewPass
182 && !aViewIter->IsSubview())
184 aViewIter->RedrawImmediate();
190 // ========================================================================
191 // function : Invalidate
193 // ========================================================================
194 void V3d_Viewer::Invalidate() const
196 for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
198 aDefViewIter.Value()->Invalidate();
202 // ========================================================================
205 // ========================================================================
206 void V3d_Viewer::Remove()
208 myStructureManager->Remove();
211 // ========================================================================
214 // ========================================================================
215 void V3d_Viewer::Erase() const
217 myStructureManager->Erase();
220 // ========================================================================
221 // function : UnHighlight
223 // ========================================================================
224 void V3d_Viewer::UnHighlight() const
226 myStructureManager->UnHighlight();
229 void V3d_Viewer::SetDefaultViewSize (const Standard_Real theSize)
232 throw V3d_BadValue("V3d_Viewer::SetDefaultViewSize, bad size");
233 myViewSize = theSize;
236 // ========================================================================
237 // function : IfMoreViews
239 // ========================================================================
240 Standard_Boolean V3d_Viewer::IfMoreViews() const
242 return myDefinedViews.Size() < myStructureManager->MaxNumOfViews();
245 // ========================================================================
246 // function : AddView
248 // ========================================================================
249 void V3d_Viewer::AddView (const Handle(V3d_View)& theView)
251 if (!myDefinedViews.Contains (theView))
253 myDefinedViews.Append (theView);
257 // ========================================================================
258 // function : DelView
260 // ========================================================================
261 void V3d_Viewer::DelView (const V3d_View* theView)
263 for (V3d_ListOfView::Iterator aViewIter (myActiveViews); aViewIter.More(); aViewIter.Next())
265 if (aViewIter.Value() == theView)
267 myActiveViews.Remove (aViewIter);
271 for (V3d_ListOfView::Iterator aViewIter (myDefinedViews); aViewIter.More(); aViewIter.Next())
273 if (aViewIter.Value() == theView)
275 myDefinedViews.Remove (aViewIter);
281 //=======================================================================
282 //function : InsertLayerBefore
284 //=======================================================================
285 Standard_Boolean V3d_Viewer::InsertLayerBefore (Graphic3d_ZLayerId& theNewLayerId,
286 const Graphic3d_ZLayerSettings& theSettings,
287 const Graphic3d_ZLayerId theLayerAfter)
289 if (myZLayerGenId.Next (theNewLayerId))
291 myLayerIds.Add (theNewLayerId);
292 myDriver->InsertLayerBefore (theNewLayerId, theSettings, theLayerAfter);
293 return Standard_True;
295 return Standard_False;
298 //=======================================================================
299 //function : InsertLayerAfter
301 //=======================================================================
302 Standard_Boolean V3d_Viewer::InsertLayerAfter (Graphic3d_ZLayerId& theNewLayerId,
303 const Graphic3d_ZLayerSettings& theSettings,
304 const Graphic3d_ZLayerId theLayerBefore)
306 if (myZLayerGenId.Next (theNewLayerId))
308 myLayerIds.Add (theNewLayerId);
309 myDriver->InsertLayerAfter (theNewLayerId, theSettings, theLayerBefore);
310 return Standard_True;
312 return Standard_False;
315 //=======================================================================
316 //function : RemoveZLayer
318 //=======================================================================
319 Standard_Boolean V3d_Viewer::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
321 if (!myLayerIds.Contains (theLayerId)
322 || theLayerId < myZLayerGenId.Lower()
323 || theLayerId > myZLayerGenId.Upper())
325 return Standard_False;
328 myDriver->RemoveZLayer (theLayerId);
329 myLayerIds.Remove (theLayerId);
330 myZLayerGenId.Free (theLayerId);
332 return Standard_True;
335 //=======================================================================
336 //function : GetAllZLayers
338 //=======================================================================
339 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
341 myDriver->ZLayers (theLayerSeq);
344 //=======================================================================
345 //function : SetZLayerSettings
347 //=======================================================================
348 void V3d_Viewer::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings)
350 myDriver->SetZLayerSettings (theLayerId, theSettings);
353 //=======================================================================
354 //function : ZLayerSettings
356 //=======================================================================
357 const Graphic3d_ZLayerSettings& V3d_Viewer::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
359 return myDriver->ZLayerSettings (theLayerId);
362 //=======================================================================
363 //function : UpdateLights
365 //=======================================================================
366 void V3d_Viewer::UpdateLights()
368 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
370 anActiveViewIter.Value()->UpdateLights();
374 //=======================================================================
375 //function : SetLightOn
377 //=======================================================================
378 void V3d_Viewer::SetLightOn (const Handle(V3d_Light)& theLight)
380 if (!myActiveLights.Contains (theLight))
382 myActiveLights.Append (theLight);
385 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
387 anActiveViewIter.Value()->SetLightOn (theLight);
391 //=======================================================================
392 //function : SetLightOff
394 //=======================================================================
395 void V3d_Viewer::SetLightOff (const Handle(V3d_Light)& theLight)
397 myActiveLights.Remove (theLight);
398 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
400 anActiveViewIter.Value()->SetLightOff (theLight);
404 //=======================================================================
405 //function : SetLightOn
407 //=======================================================================
408 void V3d_Viewer::SetLightOn()
410 for (V3d_ListOfLight::Iterator aDefLightIter (myDefinedLights); aDefLightIter.More(); aDefLightIter.Next())
412 if (!myActiveLights.Contains (aDefLightIter.Value()))
414 myActiveLights.Append (aDefLightIter.Value());
415 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
417 anActiveViewIter.Value()->SetLightOn (aDefLightIter.Value());
423 //=======================================================================
424 //function : SetLightOff
426 //=======================================================================
427 void V3d_Viewer::SetLightOff()
429 for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
431 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
433 anActiveViewIter.Value()->SetLightOff (anActiveLightIter.Value());
436 myActiveLights.Clear();
439 //=======================================================================
440 //function : IsGlobalLight
442 //=======================================================================
443 Standard_Boolean V3d_Viewer::IsGlobalLight (const Handle(V3d_Light)& theLight) const
445 return myActiveLights.Contains (theLight);
448 //=======================================================================
449 //function : AddLight
451 //=======================================================================
452 void V3d_Viewer::AddLight (const Handle(V3d_Light)& theLight)
454 if (!myDefinedLights.Contains (theLight))
456 myDefinedLights.Append (theLight);
460 //=======================================================================
461 //function : DelLight
463 //=======================================================================
464 void V3d_Viewer::DelLight (const Handle(V3d_Light)& theLight)
466 SetLightOff (theLight);
467 myDefinedLights.Remove (theLight);
470 //=======================================================================
471 //function : SetDefaultLights
473 //=======================================================================
474 void V3d_Viewer::SetDefaultLights()
476 while (!myDefinedLights.IsEmpty())
478 Handle(V3d_Light) aLight = myDefinedLights.First();
482 Handle(V3d_DirectionalLight) aDirLight = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE);
483 aDirLight->SetName ("headlight");
484 aDirLight->SetHeadlight (true);
485 Handle(V3d_AmbientLight) anAmbLight = new V3d_AmbientLight (Quantity_NOC_WHITE);
486 anAmbLight->SetName ("amblight");
487 AddLight (aDirLight);
488 AddLight (anAmbLight);
489 SetLightOn (aDirLight);
490 SetLightOn (anAmbLight);
493 //=======================================================================
494 //function : SetPrivilegedPlane
496 //=======================================================================
497 void V3d_Viewer::SetPrivilegedPlane (const gp_Ax3& thePlane)
499 myPrivilegedPlane = thePlane;
500 Handle(Aspect_Grid) aGrid = Grid (true);
501 aGrid->SetDrawMode (aGrid->DrawMode()); // aGrid->UpdateDisplay();
502 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
504 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
509 DisplayPrivilegedPlane (Standard_True, myDisplayPlaneLength);
513 //=======================================================================
514 //function : DisplayPrivilegedPlane
516 //=======================================================================
517 void V3d_Viewer::DisplayPrivilegedPlane (const Standard_Boolean theOnOff, const Standard_Real theSize)
519 myDisplayPlane = theOnOff;
520 myDisplayPlaneLength = theSize;
524 if (!myPlaneStructure.IsNull())
526 myPlaneStructure->Erase();
531 if (myPlaneStructure.IsNull())
533 myPlaneStructure = new Graphic3d_Structure (StructureManager());
534 myPlaneStructure->SetInfiniteState (Standard_True);
535 myPlaneStructure->Display();
539 myPlaneStructure->Clear();
542 Handle(Graphic3d_Group) aGroup = myPlaneStructure->NewGroup();
544 Handle(Graphic3d_AspectLine3d) aLineAttrib = new Graphic3d_AspectLine3d (Quantity_NOC_GRAY60, Aspect_TOL_SOLID, 1.0);
545 aGroup->SetGroupPrimitivesAspect (aLineAttrib);
547 Handle(Graphic3d_AspectText3d) aTextAttrib = new Graphic3d_AspectText3d();
548 aTextAttrib->SetColor (Quantity_Color (Quantity_NOC_ROYALBLUE1));
549 aGroup->SetGroupPrimitivesAspect (aTextAttrib);
551 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments (6);
553 const gp_Pnt& p0 = myPrivilegedPlane.Location();
555 const gp_Pnt pX (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.XDirection().XYZ());
556 aPrims->AddVertex (p0);
557 aPrims->AddVertex (pX);
558 Handle(Graphic3d_Text) aText = new Graphic3d_Text (1.0f / 81.0f);
559 aText->SetText ("X");
560 aText->SetPosition (pX);
561 aGroup->AddText (aText);
563 const gp_Pnt pY (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.YDirection().XYZ());
564 aPrims->AddVertex (p0);
565 aPrims->AddVertex (pY);
566 aText = new Graphic3d_Text (1.0f / 81.0f);
567 aText->SetText ("Y");
568 aText->SetPosition (pY);
569 aGroup->AddText (aText);
571 const gp_Pnt pZ (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.Direction().XYZ());
572 aPrims->AddVertex (p0);
573 aPrims->AddVertex (pZ);
574 aText = new Graphic3d_Text (1.0f / 81.0f);
575 aText->SetText ("Z");
576 aText->SetPosition (pZ);
577 aGroup->AddText (aText);
579 aGroup->AddPrimitiveArray (aPrims);
581 myPlaneStructure->Display();
584 // =======================================================================
587 // =======================================================================
588 Handle(Aspect_Grid) V3d_Viewer::Grid (Aspect_GridType theGridType, bool theToCreate)
592 case Aspect_GT_Circular:
594 if (myCGrid.IsNull() && theToCreate)
596 myCGrid = new V3d_CircularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
598 return Handle(Aspect_Grid) (myCGrid);
600 case Aspect_GT_Rectangular:
602 if (myRGrid.IsNull() && theToCreate)
604 myRGrid = new V3d_RectangularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
606 return Handle(Aspect_Grid) (myRGrid);
609 return Handle(Aspect_Grid)();
612 // =======================================================================
613 // function : GridDrawMode
615 // =======================================================================
616 Aspect_GridDrawMode V3d_Viewer::GridDrawMode()
618 Handle(Aspect_Grid) aGrid = Grid (false);
619 return !aGrid.IsNull() ? aGrid->DrawMode() : Aspect_GDM_Lines;
622 // =======================================================================
623 // function : ActivateGrid
625 // =======================================================================
626 void V3d_Viewer::ActivateGrid (const Aspect_GridType theType,
627 const Aspect_GridDrawMode theMode)
629 if (Handle(Aspect_Grid) anOldGrid = Grid (false))
634 myGridType = theType;
635 Handle(Aspect_Grid) aGrid = Grid (true);
636 aGrid->SetDrawMode (theMode);
637 if (theMode != Aspect_GDM_None)
642 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
644 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
648 // =======================================================================
649 // function : DeactivateGrid
651 // =======================================================================
652 void V3d_Viewer::DeactivateGrid()
654 Handle(Aspect_Grid) aGrid = Grid (false);
663 myGridType = Aspect_GT_Rectangular;
664 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
666 anActiveViewIter.Value()->SetGridActivity (Standard_False);
668 && !myGridEchoStructure.IsNull())
670 myGridEchoStructure->Erase();
675 // =======================================================================
676 // function : IsGridActive
678 // =======================================================================
679 Standard_Boolean V3d_Viewer::IsGridActive()
681 Handle(Aspect_Grid) aGrid = Grid (false);
682 return !aGrid.IsNull() && aGrid->IsActive();
685 // =======================================================================
686 // function : RectangularGridValues
688 // =======================================================================
689 void V3d_Viewer::RectangularGridValues (Standard_Real& theXOrigin,
690 Standard_Real& theYOrigin,
691 Standard_Real& theXStep,
692 Standard_Real& theYStep,
693 Standard_Real& theRotationAngle)
695 Grid (Aspect_GT_Rectangular, true);
696 theXOrigin = myRGrid->XOrigin();
697 theYOrigin = myRGrid->YOrigin();
698 theXStep = myRGrid->XStep();
699 theYStep = myRGrid->YStep();
700 theRotationAngle = myRGrid->RotationAngle();
703 // =======================================================================
704 // function : SetRectangularGridValues
706 // =======================================================================
707 void V3d_Viewer::SetRectangularGridValues (const Standard_Real theXOrigin,
708 const Standard_Real theYOrigin,
709 const Standard_Real theXStep,
710 const Standard_Real theYStep,
711 const Standard_Real theRotationAngle)
713 Grid (Aspect_GT_Rectangular, true);
714 myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
715 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
717 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myRGrid);
721 // =======================================================================
722 // function : CircularGridValues
724 // =======================================================================
725 void V3d_Viewer::CircularGridValues (Standard_Real& theXOrigin,
726 Standard_Real& theYOrigin,
727 Standard_Real& theRadiusStep,
728 Standard_Integer& theDivisionNumber,
729 Standard_Real& theRotationAngle)
731 Grid (Aspect_GT_Circular, true);
732 theXOrigin = myCGrid->XOrigin();
733 theYOrigin = myCGrid->YOrigin();
734 theRadiusStep = myCGrid->RadiusStep();
735 theDivisionNumber = myCGrid->DivisionNumber();
736 theRotationAngle = myCGrid->RotationAngle();
739 // =======================================================================
740 // function : SetCircularGridValues
742 // =======================================================================
743 void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin,
744 const Standard_Real theYOrigin,
745 const Standard_Real theRadiusStep,
746 const Standard_Integer theDivisionNumber,
747 const Standard_Real theRotationAngle)
749 Grid (Aspect_GT_Circular, true);
750 myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
751 theDivisionNumber, theRotationAngle);
752 for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
754 anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myCGrid);
758 // =======================================================================
759 // function : RectangularGridGraphicValues
761 // =======================================================================
762 void V3d_Viewer::RectangularGridGraphicValues (Standard_Real& theXSize,
763 Standard_Real& theYSize,
764 Standard_Real& theOffSet)
766 Grid (Aspect_GT_Rectangular, true);
767 myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
770 // =======================================================================
771 // function : SetRectangularGridGraphicValues
773 // =======================================================================
774 void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize,
775 const Standard_Real theYSize,
776 const Standard_Real theOffSet)
778 Grid (Aspect_GT_Rectangular, true);
779 myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
782 // =======================================================================
783 // function : CircularGridGraphicValues
785 // =======================================================================
786 void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius,
787 Standard_Real& theOffSet)
789 Grid (Aspect_GT_Circular, true);
790 myCGrid->GraphicValues (theRadius, theOffSet);
793 // =======================================================================
794 // function : SetCircularGridGraphicValues
796 // =======================================================================
797 void V3d_Viewer::SetCircularGridGraphicValues (const Standard_Real theRadius,
798 const Standard_Real theOffSet)
800 Grid (Aspect_GT_Circular, true);
801 myCGrid->SetGraphicValues (theRadius, theOffSet);
804 // =======================================================================
805 // function : SetGridEcho
807 // =======================================================================
808 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
810 if (myGridEcho == theToShowGrid)
815 myGridEcho = theToShowGrid;
817 || myGridEchoStructure.IsNull())
822 myGridEchoStructure->Erase();
825 // =======================================================================
826 // function : SetGridEcho
828 // =======================================================================
829 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
831 if (myGridEchoStructure.IsNull())
833 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
834 myGridEchoGroup = myGridEchoStructure->NewGroup();
837 myGridEchoAspect = theMarker;
838 myGridEchoGroup->SetPrimitivesAspect (theMarker);
841 // =======================================================================
842 // function : ShowGridEcho
844 // =======================================================================
845 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
846 const Graphic3d_Vertex& theVertex)
853 if (myGridEchoStructure.IsNull())
855 myGridEchoStructure = new Graphic3d_Structure (StructureManager());
856 myGridEchoGroup = myGridEchoStructure->NewGroup();
858 myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
859 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
862 if (theVertex.X() == myGridEchoLastVert.X()
863 && theVertex.Y() == myGridEchoLastVert.Y()
864 && theVertex.Z() == myGridEchoLastVert.Z())
869 myGridEchoLastVert = theVertex;
870 myGridEchoGroup->Clear();
871 myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
873 Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
874 anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
875 myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
877 myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost);
878 myGridEchoStructure->SetInfiniteState (Standard_True);
879 myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
880 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
881 myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true);
882 myGridEchoStructure->Display();
885 // =======================================================================
886 // function : HideGridEcho
888 // =======================================================================
889 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
891 if (myGridEchoStructure.IsNull())
896 myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
897 const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
898 if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
900 myGridEchoStructure->Erase();
904 //=======================================================================
905 //function : DumpJson
907 //=======================================================================
908 void V3d_Viewer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
910 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
912 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDriver.get())
913 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myStructureManager.get())
914 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myZLayerGenId)
916 for (V3d_ListOfView::Iterator anIter (myDefinedViews); anIter.More(); anIter.Next())
918 const Handle(V3d_View)& aDefinedView = anIter.Value();
919 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedView.get())
922 for (V3d_ListOfView::Iterator anIter (myActiveViews); anIter.More(); anIter.Next())
924 const Handle(V3d_View)& anActiveView = anIter.Value();
925 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anActiveView.get())
928 for (V3d_ListOfLight::Iterator anIter (myDefinedLights); anIter.More(); anIter.Next())
930 const Handle(Graphic3d_CLight)& aDefinedLight = anIter.Value();
931 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedLight.get())
934 for (V3d_ListOfLight::Iterator anIter (myActiveLights); anIter.More(); anIter.Next())
936 const Handle(Graphic3d_CLight)& anActiveLight = anIter.Value();
937 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anActiveLight.get())
940 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBackground)
941 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGradientBackground)
943 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewSize)
944 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewProj)
945 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myVisualization)
946 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultTypeOfView)
948 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultRenderingParams)
949 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComputedMode)
950 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultComputedMode)
952 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPrivilegedPlane)
953 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myPlaneStructure.get())
954 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDisplayPlane)
955 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDisplayPlaneLength)
957 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myRGrid.get())
958 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myCGrid.get())
960 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGridType)
961 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGridEcho)
962 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoStructure.get())
963 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoGroup.get())
964 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoAspect.get())
965 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGridEchoLastVert)