0032886: Visualization, V3d_View - introduce interface for creating a subview
[occt.git] / src / V3d / V3d_Viewer.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <V3d_Viewer.hxx>
15
16 #include <Aspect_Grid.hxx>
17 #include <Aspect_IdentDefinitionError.hxx>
18 #include <Graphic3d_ArrayOfPoints.hxx>
19 #include <Graphic3d_ArrayOfSegments.hxx>
20 #include <Graphic3d_AspectLine3d.hxx>
21 #include <Graphic3d_AspectMarker3d.hxx>
22 #include <Graphic3d_AspectText3d.hxx>
23 #include <Graphic3d_GraphicDriver.hxx>
24 #include <Graphic3d_Group.hxx>
25 #include <Graphic3d_Structure.hxx>
26 #include <Graphic3d_Text.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <V3d.hxx>
29 #include <V3d_BadValue.hxx>
30 #include <V3d_CircularGrid.hxx>
31 #include <V3d_AmbientLight.hxx>
32 #include <V3d_DirectionalLight.hxx>
33 #include <V3d_RectangularGrid.hxx>
34 #include <V3d_View.hxx>
35
36 IMPLEMENT_STANDARD_RTTIEXT(V3d_Viewer, Standard_Transient)
37
38 // ========================================================================
39 // function : V3d_Viewer
40 // purpose  :
41 // ========================================================================
42 V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver)
43 : myDriver (theDriver),
44   myStructureManager (new Graphic3d_StructureManager (theDriver)),
45   myZLayerGenId (1, IntegerLast()),
46   myBackground (Quantity_NOC_GRAY30),
47   myViewSize (1000.0),
48   myViewProj (V3d_XposYnegZpos),
49   myVisualization (V3d_ZBUFFER),
50   myDefaultTypeOfView (V3d_ORTHOGRAPHIC),
51   myComputedMode (Standard_True),
52   myDefaultComputedMode (Standard_False),
53   myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
54   myDisplayPlane (Standard_False),
55   myDisplayPlaneLength (1000.0),
56   myGridType (Aspect_GT_Rectangular),
57   myGridEcho (Standard_True),
58   myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast())
59 {
60   //
61 }
62
63 // ========================================================================
64 // function : CreateView
65 // purpose  :
66 // ========================================================================
67 Handle(V3d_View) V3d_Viewer::CreateView ()
68 {
69   return new V3d_View(this, myDefaultTypeOfView);
70 }
71
72 // ========================================================================
73 // function : SetViewOn
74 // purpose  :
75 // ========================================================================
76 void V3d_Viewer::SetViewOn()
77 {
78   for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
79   {
80     SetViewOn (aDefViewIter.Value());
81   }
82 }
83
84 // ========================================================================
85 // function : SetViewOff
86 // purpose  :
87 // ========================================================================
88 void V3d_Viewer::SetViewOff()
89 {
90   for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
91   {
92     SetViewOff (aDefViewIter.Value());
93   }
94 }
95
96 // ========================================================================
97 // function : SetViewOn
98 // purpose  :
99 // ========================================================================
100 void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView)
101 {
102   Handle(Graphic3d_CView) aViewImpl = theView->View();
103   if (!aViewImpl->IsDefined() || myActiveViews.Contains (theView))
104   {
105     return;
106   }
107
108   myActiveViews.Append (theView);
109   aViewImpl->Activate();
110   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
111   {
112     theView->SetLightOn (anActiveLightIter.Value());
113   }
114   if (Handle(Aspect_Grid) aGrid = Grid (false))
115   {
116     theView->SetGrid (myPrivilegedPlane, aGrid);
117     theView->SetGridActivity (aGrid->IsActive());
118   }
119   if (theView->SetImmediateUpdate (Standard_False))
120   {
121     theView->Redraw();
122     theView->SetImmediateUpdate (Standard_True);
123   }
124 }
125
126 // ========================================================================
127 // function : SetViewOff
128 // purpose  :
129 // ========================================================================
130 void V3d_Viewer::SetViewOff (const Handle(V3d_View)& theView)
131 {
132   Handle(Graphic3d_CView) aViewImpl = theView->View();
133   if (aViewImpl->IsDefined() && myActiveViews.Contains (theView))
134   {
135     myActiveViews.Remove (theView);
136     aViewImpl->Deactivate() ;
137   }
138 }
139
140 // ========================================================================
141 // function : Redraw
142 // purpose  :
143 // ========================================================================
144 void V3d_Viewer::Redraw() const
145 {
146   for (int aSubViewPass = 0; aSubViewPass < 2; ++aSubViewPass)
147   {
148     // redraw subviews first
149     const bool isSubViewPass = (aSubViewPass == 0);
150     for (const Handle(V3d_View)& aViewIter : myDefinedViews)
151     {
152       if (isSubViewPass
153        && aViewIter->IsSubview())
154       {
155         aViewIter->Redraw();
156       }
157       else if (!isSubViewPass
158             && !aViewIter->IsSubview())
159       {
160         aViewIter->Redraw();
161       }
162     }
163   }
164 }
165
166 // ========================================================================
167 // function : RedrawImmediate
168 // purpose  :
169 // ========================================================================
170 void V3d_Viewer::RedrawImmediate() const
171 {
172   for (int aSubViewPass = 0; aSubViewPass < 2; ++aSubViewPass)
173   {
174     // redraw subviews first
175     const bool isSubViewPass = (aSubViewPass == 0);
176     for (const Handle(V3d_View)& aViewIter : myDefinedViews)
177     {
178       if (isSubViewPass
179        && aViewIter->IsSubview())
180       {
181         aViewIter->RedrawImmediate();
182       }
183       else if (!isSubViewPass
184             && !aViewIter->IsSubview())
185       {
186         aViewIter->RedrawImmediate();
187       }
188     }
189   }
190 }
191
192 // ========================================================================
193 // function : Invalidate
194 // purpose  :
195 // ========================================================================
196 void V3d_Viewer::Invalidate() const
197 {
198   for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
199   {
200     aDefViewIter.Value()->Invalidate();
201   }
202 }
203
204 // ========================================================================
205 // function : Remove
206 // purpose  :
207 // ========================================================================
208 void V3d_Viewer::Remove()
209 {
210   myStructureManager->Remove();
211 }
212
213 // ========================================================================
214 // function : Erase
215 // purpose  :
216 // ========================================================================
217 void V3d_Viewer::Erase() const
218 {
219   myStructureManager->Erase();
220 }
221
222 // ========================================================================
223 // function : UnHighlight
224 // purpose  :
225 // ========================================================================
226 void V3d_Viewer::UnHighlight() const
227 {
228   myStructureManager->UnHighlight();
229 }
230
231 void V3d_Viewer::SetDefaultViewSize (const Standard_Real theSize)
232 {
233   if (theSize <= 0.0)
234     throw V3d_BadValue("V3d_Viewer::SetDefaultViewSize, bad size");
235   myViewSize = theSize;
236 }
237
238 // ========================================================================
239 // function : IfMoreViews
240 // purpose  :
241 // ========================================================================
242 Standard_Boolean V3d_Viewer::IfMoreViews() const
243 {
244   return myDefinedViews.Size() < myStructureManager->MaxNumOfViews();
245 }
246
247 // ========================================================================
248 // function : AddView
249 // purpose  :
250 // ========================================================================
251 void V3d_Viewer::AddView (const Handle(V3d_View)& theView)
252 {
253   if (!myDefinedViews.Contains (theView))
254   {
255     myDefinedViews.Append (theView);
256   }
257 }
258
259 // ========================================================================
260 // function : DelView
261 // purpose  :
262 // ========================================================================
263 void V3d_Viewer::DelView (const V3d_View* theView)
264 {
265   for (V3d_ListOfView::Iterator aViewIter (myActiveViews); aViewIter.More(); aViewIter.Next())
266   {
267     if (aViewIter.Value() == theView)
268     {
269       myActiveViews.Remove (aViewIter);
270       break;
271     }
272   }
273   for (V3d_ListOfView::Iterator aViewIter (myDefinedViews); aViewIter.More(); aViewIter.Next())
274   {
275     if (aViewIter.Value() == theView)
276     {
277       myDefinedViews.Remove (aViewIter);
278       break;
279     }
280   }
281 }
282
283 //=======================================================================
284 //function : InsertLayerBefore
285 //purpose  :
286 //=======================================================================
287 Standard_Boolean V3d_Viewer::InsertLayerBefore (Graphic3d_ZLayerId& theNewLayerId,
288                                                 const Graphic3d_ZLayerSettings& theSettings,
289                                                 const Graphic3d_ZLayerId theLayerAfter)
290 {
291   if (myZLayerGenId.Next (theNewLayerId))
292   {
293     myLayerIds.Add (theNewLayerId);
294     myDriver->InsertLayerBefore (theNewLayerId, theSettings, theLayerAfter);
295     return Standard_True;
296   }
297   return Standard_False;
298 }
299
300 //=======================================================================
301 //function : InsertLayerAfter
302 //purpose  :
303 //=======================================================================
304 Standard_Boolean V3d_Viewer::InsertLayerAfter (Graphic3d_ZLayerId& theNewLayerId,
305                                                const Graphic3d_ZLayerSettings& theSettings,
306                                                const Graphic3d_ZLayerId theLayerBefore)
307 {
308   if (myZLayerGenId.Next (theNewLayerId))
309   {
310     myLayerIds.Add (theNewLayerId);
311     myDriver->InsertLayerAfter (theNewLayerId, theSettings, theLayerBefore);
312     return Standard_True;
313   }
314   return Standard_False;
315 }
316
317 //=======================================================================
318 //function : RemoveZLayer
319 //purpose  : 
320 //=======================================================================
321 Standard_Boolean V3d_Viewer::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
322 {
323   if (!myLayerIds.Contains (theLayerId)
324     || theLayerId < myZLayerGenId.Lower()
325     || theLayerId > myZLayerGenId.Upper())
326   {
327     return Standard_False;
328   }
329
330   myDriver->RemoveZLayer (theLayerId);
331   myLayerIds.Remove  (theLayerId);
332   myZLayerGenId.Free (theLayerId);
333
334   return Standard_True;
335 }
336
337 //=======================================================================
338 //function : GetAllZLayers
339 //purpose  :
340 //=======================================================================
341 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
342 {
343   myDriver->ZLayers (theLayerSeq);
344 }
345
346 //=======================================================================
347 //function : SetZLayerSettings
348 //purpose  :
349 //=======================================================================
350 void V3d_Viewer::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings)
351 {
352   myDriver->SetZLayerSettings (theLayerId, theSettings);
353 }
354
355 //=======================================================================
356 //function : ZLayerSettings
357 //purpose  :
358 //=======================================================================
359 const Graphic3d_ZLayerSettings& V3d_Viewer::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
360 {
361   return myDriver->ZLayerSettings (theLayerId);
362 }
363
364 //=======================================================================
365 //function : UpdateLights
366 //purpose  :
367 //=======================================================================
368 void V3d_Viewer::UpdateLights()
369 {
370   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
371   {
372     anActiveViewIter.Value()->UpdateLights();
373   }
374 }
375
376 //=======================================================================
377 //function : SetLightOn
378 //purpose  :
379 //=======================================================================
380 void V3d_Viewer::SetLightOn (const Handle(V3d_Light)& theLight)
381 {
382   if (!myActiveLights.Contains (theLight))
383   {
384     myActiveLights.Append (theLight);
385   }
386
387   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
388   {
389     anActiveViewIter.Value()->SetLightOn (theLight);
390   }
391 }
392
393 //=======================================================================
394 //function : SetLightOff
395 //purpose  :
396 //=======================================================================
397 void V3d_Viewer::SetLightOff (const Handle(V3d_Light)& theLight)
398 {
399   myActiveLights.Remove (theLight);
400   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
401   {
402     anActiveViewIter.Value()->SetLightOff (theLight);
403   }
404 }
405
406 //=======================================================================
407 //function : SetLightOn
408 //purpose  :
409 //=======================================================================
410 void V3d_Viewer::SetLightOn()
411 {
412   for (V3d_ListOfLight::Iterator aDefLightIter (myDefinedLights); aDefLightIter.More(); aDefLightIter.Next())
413   {
414     if (!myActiveLights.Contains (aDefLightIter.Value()))
415     {
416       myActiveLights.Append (aDefLightIter.Value());
417       for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
418       {
419         anActiveViewIter.Value()->SetLightOn (aDefLightIter.Value());
420       }
421     }
422   }
423 }
424
425 //=======================================================================
426 //function : SetLightOff
427 //purpose  :
428 //=======================================================================
429 void V3d_Viewer::SetLightOff()
430 {
431   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
432   {
433     for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
434     {
435       anActiveViewIter.Value()->SetLightOff (anActiveLightIter.Value());
436     }
437   }
438   myActiveLights.Clear();
439 }
440
441 //=======================================================================
442 //function : IsGlobalLight
443 //purpose  :
444 //=======================================================================
445 Standard_Boolean V3d_Viewer::IsGlobalLight (const Handle(V3d_Light)& theLight) const
446 {
447   return myActiveLights.Contains (theLight);
448 }
449
450 //=======================================================================
451 //function : AddLight
452 //purpose  :
453 //=======================================================================
454 void V3d_Viewer::AddLight (const Handle(V3d_Light)& theLight)
455 {
456   if (!myDefinedLights.Contains (theLight))
457   {
458     myDefinedLights.Append (theLight);
459   }
460 }
461
462 //=======================================================================
463 //function : DelLight
464 //purpose  :
465 //=======================================================================
466 void V3d_Viewer::DelLight (const Handle(V3d_Light)& theLight)
467 {
468   SetLightOff (theLight);
469   myDefinedLights.Remove (theLight);
470 }
471
472 //=======================================================================
473 //function : SetDefaultLights
474 //purpose  :
475 //=======================================================================
476 void V3d_Viewer::SetDefaultLights()
477 {
478   while (!myDefinedLights.IsEmpty())
479   {
480     Handle(V3d_Light) aLight = myDefinedLights.First();
481     DelLight (aLight);
482   }
483
484   Handle(V3d_DirectionalLight) aDirLight = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE);
485   aDirLight->SetName ("headlight");
486   aDirLight->SetHeadlight (true);
487   Handle(V3d_AmbientLight) anAmbLight = new V3d_AmbientLight (Quantity_NOC_WHITE);
488   anAmbLight->SetName ("amblight");
489   AddLight (aDirLight);
490   AddLight (anAmbLight);
491   SetLightOn (aDirLight);
492   SetLightOn (anAmbLight);
493 }
494
495 //=======================================================================
496 //function : SetPrivilegedPlane
497 //purpose  :
498 //=======================================================================
499 void V3d_Viewer::SetPrivilegedPlane (const gp_Ax3& thePlane)
500 {
501   myPrivilegedPlane = thePlane;
502   Handle(Aspect_Grid) aGrid = Grid (true);
503   aGrid->SetDrawMode (aGrid->DrawMode()); // aGrid->UpdateDisplay();
504   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
505   {
506     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
507   }
508
509   if (myDisplayPlane)
510   {
511     DisplayPrivilegedPlane (Standard_True, myDisplayPlaneLength);
512   }
513 }
514
515 //=======================================================================
516 //function : DisplayPrivilegedPlane
517 //purpose  :
518 //=======================================================================
519 void V3d_Viewer::DisplayPrivilegedPlane (const Standard_Boolean theOnOff, const Standard_Real theSize)
520 {
521   myDisplayPlane = theOnOff;
522   myDisplayPlaneLength = theSize;
523
524   if (!myDisplayPlane)
525   {
526     if (!myPlaneStructure.IsNull())
527     {
528       myPlaneStructure->Erase();
529     }
530     return;
531   }
532
533   if (myPlaneStructure.IsNull())
534   {
535     myPlaneStructure = new Graphic3d_Structure (StructureManager());
536     myPlaneStructure->SetInfiniteState (Standard_True);
537     myPlaneStructure->Display();
538   }
539   else
540   {
541     myPlaneStructure->Clear();
542   }
543
544   Handle(Graphic3d_Group) aGroup = myPlaneStructure->NewGroup();
545
546   Handle(Graphic3d_AspectLine3d) aLineAttrib = new Graphic3d_AspectLine3d (Quantity_NOC_GRAY60, Aspect_TOL_SOLID, 1.0);
547   aGroup->SetGroupPrimitivesAspect (aLineAttrib);
548
549   Handle(Graphic3d_AspectText3d) aTextAttrib = new Graphic3d_AspectText3d();
550   aTextAttrib->SetColor (Quantity_Color (Quantity_NOC_ROYALBLUE1));
551   aGroup->SetGroupPrimitivesAspect (aTextAttrib);
552
553   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments (6);
554
555   const gp_Pnt& p0 = myPrivilegedPlane.Location();
556
557   const gp_Pnt pX (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.XDirection().XYZ());
558   aPrims->AddVertex (p0);
559   aPrims->AddVertex (pX);
560   Handle(Graphic3d_Text) aText = new Graphic3d_Text (1.0f / 81.0f);
561   aText->SetText ("X");
562   aText->SetPosition (pX);
563   aGroup->AddText (aText);
564
565   const gp_Pnt pY (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.YDirection().XYZ());
566   aPrims->AddVertex (p0);
567   aPrims->AddVertex (pY);
568   aText = new Graphic3d_Text (1.0f / 81.0f);
569   aText->SetText ("Y");
570   aText->SetPosition (pY);
571   aGroup->AddText (aText);
572
573   const gp_Pnt pZ (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.Direction().XYZ());
574   aPrims->AddVertex (p0);
575   aPrims->AddVertex (pZ);
576   aText = new Graphic3d_Text (1.0f / 81.0f);
577   aText->SetText ("Z");
578   aText->SetPosition (pZ);
579   aGroup->AddText (aText);
580
581   aGroup->AddPrimitiveArray (aPrims);
582
583   myPlaneStructure->Display();
584 }
585
586 // =======================================================================
587 // function : Grid
588 // purpose  :
589 // =======================================================================
590 Handle(Aspect_Grid) V3d_Viewer::Grid (Aspect_GridType theGridType, bool theToCreate)
591 {
592   switch (theGridType)
593   {
594     case Aspect_GT_Circular:
595     {
596       if (myCGrid.IsNull() && theToCreate)
597       {
598         myCGrid = new V3d_CircularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
599       }
600       return Handle(Aspect_Grid) (myCGrid);
601     }
602     case Aspect_GT_Rectangular:
603     {
604       if (myRGrid.IsNull() && theToCreate)
605       {
606         myRGrid = new V3d_RectangularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
607       }
608       return Handle(Aspect_Grid) (myRGrid);
609     }
610   }
611   return Handle(Aspect_Grid)();
612 }
613
614 // =======================================================================
615 // function : GridDrawMode
616 // purpose  :
617 // =======================================================================
618 Aspect_GridDrawMode V3d_Viewer::GridDrawMode()
619 {
620   Handle(Aspect_Grid) aGrid = Grid (false);
621   return !aGrid.IsNull() ? aGrid->DrawMode() : Aspect_GDM_Lines;
622 }
623
624 // =======================================================================
625 // function : ActivateGrid
626 // purpose  :
627 // =======================================================================
628 void V3d_Viewer::ActivateGrid (const Aspect_GridType     theType,
629                                const Aspect_GridDrawMode theMode)
630 {
631   if (Handle(Aspect_Grid) anOldGrid = Grid (false))
632   {
633     anOldGrid->Erase();
634   }
635
636   myGridType = theType;
637   Handle(Aspect_Grid) aGrid = Grid (true);
638   aGrid->SetDrawMode (theMode);
639   if (theMode != Aspect_GDM_None)
640   {
641     aGrid->Display();
642   }
643   aGrid->Activate();
644   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
645   {
646     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
647   }
648 }
649
650 // =======================================================================
651 // function : DeactivateGrid
652 // purpose  :
653 // =======================================================================
654 void V3d_Viewer::DeactivateGrid()
655 {
656   Handle(Aspect_Grid) aGrid = Grid (false);
657   if (aGrid.IsNull())
658   {
659     return;
660   }
661
662   aGrid->Erase();
663   aGrid->Deactivate();
664
665   myGridType = Aspect_GT_Rectangular;
666   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
667   {
668     anActiveViewIter.Value()->SetGridActivity (Standard_False);
669     if (myGridEcho
670     && !myGridEchoStructure.IsNull())
671     {
672       myGridEchoStructure->Erase();
673     }
674   }
675 }
676
677 // =======================================================================
678 // function : IsGridActive
679 // purpose  :
680 // =======================================================================
681 Standard_Boolean V3d_Viewer::IsGridActive()
682 {
683   Handle(Aspect_Grid) aGrid = Grid (false);
684   return !aGrid.IsNull() && aGrid->IsActive();
685 }
686
687 // =======================================================================
688 // function : RectangularGridValues
689 // purpose  :
690 // =======================================================================
691 void V3d_Viewer::RectangularGridValues (Standard_Real& theXOrigin,
692                                         Standard_Real& theYOrigin,
693                                         Standard_Real& theXStep,
694                                         Standard_Real& theYStep,
695                                         Standard_Real& theRotationAngle)
696 {
697   Grid (Aspect_GT_Rectangular, true);
698   theXOrigin       = myRGrid->XOrigin();
699   theYOrigin       = myRGrid->YOrigin();
700   theXStep         = myRGrid->XStep();
701   theYStep         = myRGrid->YStep();
702   theRotationAngle = myRGrid->RotationAngle();
703 }
704
705 // =======================================================================
706 // function : SetRectangularGridValues
707 // purpose  :
708 // =======================================================================
709 void V3d_Viewer::SetRectangularGridValues (const Standard_Real theXOrigin,
710                                            const Standard_Real theYOrigin,
711                                            const Standard_Real theXStep,
712                                            const Standard_Real theYStep,
713                                            const Standard_Real theRotationAngle)
714 {
715   Grid (Aspect_GT_Rectangular, true);
716   myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
717   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
718   {
719     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myRGrid);
720   }
721 }
722
723 // =======================================================================
724 // function : CircularGridValues
725 // purpose  :
726 // =======================================================================
727 void V3d_Viewer::CircularGridValues (Standard_Real& theXOrigin,
728                                      Standard_Real& theYOrigin,
729                                      Standard_Real& theRadiusStep,
730                                      Standard_Integer& theDivisionNumber,
731                                      Standard_Real& theRotationAngle)
732 {
733   Grid (Aspect_GT_Circular, true);
734   theXOrigin        = myCGrid->XOrigin();
735   theYOrigin        = myCGrid->YOrigin();
736   theRadiusStep     = myCGrid->RadiusStep();
737   theDivisionNumber = myCGrid->DivisionNumber();
738   theRotationAngle  = myCGrid->RotationAngle();
739 }
740
741 // =======================================================================
742 // function : SetCircularGridValues
743 // purpose  :
744 // =======================================================================
745 void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin,
746                                         const Standard_Real theYOrigin,
747                                         const Standard_Real theRadiusStep,
748                                         const Standard_Integer theDivisionNumber,
749                                         const Standard_Real theRotationAngle)
750 {
751   Grid (Aspect_GT_Circular, true);
752   myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
753                           theDivisionNumber, theRotationAngle);
754   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
755   {
756     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myCGrid);
757   }
758 }
759
760 // =======================================================================
761 // function : RectangularGridGraphicValues
762 // purpose  :
763 // =======================================================================
764 void V3d_Viewer::RectangularGridGraphicValues (Standard_Real& theXSize,
765                                                Standard_Real& theYSize,
766                                                Standard_Real& theOffSet)
767 {
768   Grid (Aspect_GT_Rectangular, true);
769   myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
770 }
771
772 // =======================================================================
773 // function : SetRectangularGridGraphicValues
774 // purpose  :
775 // =======================================================================
776 void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize,
777                                                   const Standard_Real theYSize,
778                                                   const Standard_Real theOffSet)
779 {
780   Grid (Aspect_GT_Rectangular, true);
781   myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
782 }
783
784 // =======================================================================
785 // function : CircularGridGraphicValues
786 // purpose  :
787 // =======================================================================
788 void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius,
789                                             Standard_Real& theOffSet)
790 {
791   Grid (Aspect_GT_Circular, true);
792   myCGrid->GraphicValues (theRadius, theOffSet);
793 }
794
795 // =======================================================================
796 // function : SetCircularGridGraphicValues
797 // purpose  :
798 // =======================================================================
799 void V3d_Viewer::SetCircularGridGraphicValues (const Standard_Real theRadius,
800                                                const Standard_Real theOffSet)
801 {
802   Grid (Aspect_GT_Circular, true);
803   myCGrid->SetGraphicValues (theRadius, theOffSet);
804 }
805
806 // =======================================================================
807 // function : SetGridEcho
808 // purpose  :
809 // =======================================================================
810 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
811 {
812   if (myGridEcho == theToShowGrid)
813   {
814     return;
815   }
816
817   myGridEcho = theToShowGrid;
818   if (theToShowGrid
819    || myGridEchoStructure.IsNull())
820   {
821     return;
822   }
823
824   myGridEchoStructure->Erase();
825 }
826
827 // =======================================================================
828 // function : SetGridEcho
829 // purpose  :
830 // =======================================================================
831 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
832 {
833   if (myGridEchoStructure.IsNull())
834   {
835     myGridEchoStructure = new Graphic3d_Structure (StructureManager());
836     myGridEchoGroup     = myGridEchoStructure->NewGroup();
837   }
838
839   myGridEchoAspect = theMarker;
840   myGridEchoGroup->SetPrimitivesAspect (theMarker);
841 }
842
843 // =======================================================================
844 // function : ShowGridEcho
845 // purpose  :
846 // =======================================================================
847 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
848                                const Graphic3d_Vertex& theVertex)
849 {
850   if (!myGridEcho)
851   {
852     return;
853   }
854
855   if (myGridEchoStructure.IsNull())
856   {
857     myGridEchoStructure = new Graphic3d_Structure (StructureManager());
858     myGridEchoGroup = myGridEchoStructure->NewGroup();
859
860     myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
861     myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
862   }
863
864   if (theVertex.X() == myGridEchoLastVert.X()
865    && theVertex.Y() == myGridEchoLastVert.Y()
866    && theVertex.Z() == myGridEchoLastVert.Z())
867   {
868     return;
869   }
870
871   myGridEchoLastVert = theVertex;
872   myGridEchoGroup->Clear();
873   myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
874
875   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
876   anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
877   myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
878
879   myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost);
880   myGridEchoStructure->SetInfiniteState (Standard_True);
881   myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
882   myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
883   myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true);
884   myGridEchoStructure->Display();
885 }
886
887 // =======================================================================
888 // function : HideGridEcho
889 // purpose  :
890 // =======================================================================
891 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
892 {
893   if (myGridEchoStructure.IsNull())
894   {
895     return;
896   }
897
898   myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
899   const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
900   if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
901   {
902     myGridEchoStructure->Erase();
903   }
904 }
905
906 //=======================================================================
907 //function : DumpJson
908 //purpose  : 
909 //=======================================================================
910 void V3d_Viewer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
911 {
912   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
913   
914   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDriver.get())
915   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myStructureManager.get())
916   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myZLayerGenId)
917   
918   for (V3d_ListOfView::Iterator anIter (myDefinedViews); anIter.More(); anIter.Next())
919   {
920     const Handle(V3d_View)& aDefinedView = anIter.Value();
921     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedView.get())
922   }
923
924   for (V3d_ListOfView::Iterator anIter (myActiveViews); anIter.More(); anIter.Next())
925   {
926     const Handle(V3d_View)& anActiveView = anIter.Value();
927     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anActiveView.get())
928   }
929     
930   for (V3d_ListOfLight::Iterator anIter (myDefinedLights); anIter.More(); anIter.Next())
931   {
932     const Handle(Graphic3d_CLight)& aDefinedLight = anIter.Value();
933     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedLight.get())
934   }
935
936   for (V3d_ListOfLight::Iterator anIter (myActiveLights); anIter.More(); anIter.Next())
937   {
938     const Handle(Graphic3d_CLight)& anActiveLight = anIter.Value();
939     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anActiveLight.get())
940   }
941
942   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBackground)
943   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGradientBackground)
944
945   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewSize)
946   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewProj)
947   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myVisualization)
948   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultTypeOfView)
949   
950   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultRenderingParams)
951   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComputedMode)
952   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultComputedMode)
953
954   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPrivilegedPlane)
955   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myPlaneStructure.get())
956   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDisplayPlane)
957   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDisplayPlaneLength)
958   
959   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myRGrid.get())
960   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myCGrid.get())
961
962   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGridType)
963   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGridEcho)
964   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoStructure.get())
965   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoGroup.get())
966   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoAspect.get())
967   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGridEchoLastVert)
968 }