0032218: Visualization - move V3d_View::ShadingModel() property to Graphic3d_Renderin...
[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   myDefaultRenderingParams.ShadingModel = Graphic3d_TOSM_VERTEX;
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 (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
147   {
148     aDefViewIter.Value()->Redraw();
149   }
150 }
151
152 // ========================================================================
153 // function : RedrawImmediate
154 // purpose  :
155 // ========================================================================
156 void V3d_Viewer::RedrawImmediate() const
157 {
158   for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
159   {
160     aDefViewIter.Value()->RedrawImmediate();
161   }
162 }
163
164 // ========================================================================
165 // function : Invalidate
166 // purpose  :
167 // ========================================================================
168 void V3d_Viewer::Invalidate() const
169 {
170   for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
171   {
172     aDefViewIter.Value()->Invalidate();
173   }
174 }
175
176 // ========================================================================
177 // function : Remove
178 // purpose  :
179 // ========================================================================
180 void V3d_Viewer::Remove()
181 {
182   myStructureManager->Remove();
183 }
184
185 // ========================================================================
186 // function : Erase
187 // purpose  :
188 // ========================================================================
189 void V3d_Viewer::Erase() const
190 {
191   myStructureManager->Erase();
192 }
193
194 // ========================================================================
195 // function : UnHighlight
196 // purpose  :
197 // ========================================================================
198 void V3d_Viewer::UnHighlight() const
199 {
200   myStructureManager->UnHighlight();
201 }
202
203 void V3d_Viewer::SetDefaultViewSize (const Standard_Real theSize)
204 {
205   if (theSize <= 0.0)
206     throw V3d_BadValue("V3d_Viewer::SetDefaultViewSize, bad size");
207   myViewSize = theSize;
208 }
209
210 // ========================================================================
211 // function : IfMoreViews
212 // purpose  :
213 // ========================================================================
214 Standard_Boolean V3d_Viewer::IfMoreViews() const
215 {
216   return myDefinedViews.Size() < myStructureManager->MaxNumOfViews();
217 }
218
219 // ========================================================================
220 // function : AddView
221 // purpose  :
222 // ========================================================================
223 void V3d_Viewer::AddView (const Handle(V3d_View)& theView)
224 {
225   if (!myDefinedViews.Contains (theView))
226   {
227     myDefinedViews.Append (theView);
228   }
229 }
230
231 // ========================================================================
232 // function : DelView
233 // purpose  :
234 // ========================================================================
235 void V3d_Viewer::DelView (const Handle(V3d_View)& theView)
236 {
237   myActiveViews.Remove (theView);
238   myDefinedViews.Remove (theView);
239 }
240
241 //=======================================================================
242 //function : InsertLayerBefore
243 //purpose  :
244 //=======================================================================
245 Standard_Boolean V3d_Viewer::InsertLayerBefore (Graphic3d_ZLayerId& theNewLayerId,
246                                                 const Graphic3d_ZLayerSettings& theSettings,
247                                                 const Graphic3d_ZLayerId theLayerAfter)
248 {
249   if (myZLayerGenId.Next (theNewLayerId))
250   {
251     myLayerIds.Add (theNewLayerId);
252     myDriver->InsertLayerBefore (theNewLayerId, theSettings, theLayerAfter);
253     return Standard_True;
254   }
255   return Standard_False;
256 }
257
258 //=======================================================================
259 //function : InsertLayerAfter
260 //purpose  :
261 //=======================================================================
262 Standard_Boolean V3d_Viewer::InsertLayerAfter (Graphic3d_ZLayerId& theNewLayerId,
263                                                const Graphic3d_ZLayerSettings& theSettings,
264                                                const Graphic3d_ZLayerId theLayerBefore)
265 {
266   if (myZLayerGenId.Next (theNewLayerId))
267   {
268     myLayerIds.Add (theNewLayerId);
269     myDriver->InsertLayerAfter (theNewLayerId, theSettings, theLayerBefore);
270     return Standard_True;
271   }
272   return Standard_False;
273 }
274
275 //=======================================================================
276 //function : RemoveZLayer
277 //purpose  : 
278 //=======================================================================
279 Standard_Boolean V3d_Viewer::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
280 {
281   if (!myLayerIds.Contains (theLayerId)
282     || theLayerId < myZLayerGenId.Lower()
283     || theLayerId > myZLayerGenId.Upper())
284   {
285     return Standard_False;
286   }
287
288   myDriver->RemoveZLayer (theLayerId);
289   myLayerIds.Remove  (theLayerId);
290   myZLayerGenId.Free (theLayerId);
291
292   return Standard_True;
293 }
294
295 //=======================================================================
296 //function : GetAllZLayers
297 //purpose  :
298 //=======================================================================
299 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
300 {
301   myDriver->ZLayers (theLayerSeq);
302 }
303
304 //=======================================================================
305 //function : SetZLayerSettings
306 //purpose  :
307 //=======================================================================
308 void V3d_Viewer::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings)
309 {
310   myDriver->SetZLayerSettings (theLayerId, theSettings);
311 }
312
313 //=======================================================================
314 //function : ZLayerSettings
315 //purpose  :
316 //=======================================================================
317 const Graphic3d_ZLayerSettings& V3d_Viewer::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
318 {
319   return myDriver->ZLayerSettings (theLayerId);
320 }
321
322 //=======================================================================
323 //function : UpdateLights
324 //purpose  :
325 //=======================================================================
326 void V3d_Viewer::UpdateLights()
327 {
328   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
329   {
330     anActiveViewIter.Value()->UpdateLights();
331   }
332 }
333
334 //=======================================================================
335 //function : SetLightOn
336 //purpose  :
337 //=======================================================================
338 void V3d_Viewer::SetLightOn (const Handle(V3d_Light)& theLight)
339 {
340   if (!myActiveLights.Contains (theLight))
341   {
342     myActiveLights.Append (theLight);
343   }
344
345   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
346   {
347     anActiveViewIter.Value()->SetLightOn (theLight);
348   }
349 }
350
351 //=======================================================================
352 //function : SetLightOff
353 //purpose  :
354 //=======================================================================
355 void V3d_Viewer::SetLightOff (const Handle(V3d_Light)& theLight)
356 {
357   myActiveLights.Remove (theLight);
358   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
359   {
360     anActiveViewIter.Value()->SetLightOff (theLight);
361   }
362 }
363
364 //=======================================================================
365 //function : SetLightOn
366 //purpose  :
367 //=======================================================================
368 void V3d_Viewer::SetLightOn()
369 {
370   for (V3d_ListOfLight::Iterator aDefLightIter (myDefinedLights); aDefLightIter.More(); aDefLightIter.Next())
371   {
372     if (!myActiveLights.Contains (aDefLightIter.Value()))
373     {
374       myActiveLights.Append (aDefLightIter.Value());
375       for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
376       {
377         anActiveViewIter.Value()->SetLightOn (aDefLightIter.Value());
378       }
379     }
380   }
381 }
382
383 //=======================================================================
384 //function : SetLightOff
385 //purpose  :
386 //=======================================================================
387 void V3d_Viewer::SetLightOff()
388 {
389   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
390   {
391     for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
392     {
393       anActiveViewIter.Value()->SetLightOff (anActiveLightIter.Value());
394     }
395   }
396   myActiveLights.Clear();
397 }
398
399 //=======================================================================
400 //function : IsGlobalLight
401 //purpose  :
402 //=======================================================================
403 Standard_Boolean V3d_Viewer::IsGlobalLight (const Handle(V3d_Light)& theLight) const
404 {
405   return myActiveLights.Contains (theLight);
406 }
407
408 //=======================================================================
409 //function : AddLight
410 //purpose  :
411 //=======================================================================
412 void V3d_Viewer::AddLight (const Handle(V3d_Light)& theLight)
413 {
414   if (!myDefinedLights.Contains (theLight))
415   {
416     myDefinedLights.Append (theLight);
417   }
418 }
419
420 //=======================================================================
421 //function : DelLight
422 //purpose  :
423 //=======================================================================
424 void V3d_Viewer::DelLight (const Handle(V3d_Light)& theLight)
425 {
426   SetLightOff (theLight);
427   myDefinedLights.Remove (theLight);
428 }
429
430 //=======================================================================
431 //function : SetDefaultLights
432 //purpose  :
433 //=======================================================================
434 void V3d_Viewer::SetDefaultLights()
435 {
436   while (!myDefinedLights.IsEmpty())
437   {
438     Handle(V3d_Light) aLight = myDefinedLights.First();
439     DelLight (aLight);
440   }
441
442   Handle(V3d_DirectionalLight) aDirLight  = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE, Standard_True);
443   Handle(V3d_AmbientLight)     anAmbLight = new V3d_AmbientLight (Quantity_NOC_WHITE);
444   AddLight (aDirLight);
445   AddLight (anAmbLight);
446   SetLightOn (aDirLight);
447   SetLightOn (anAmbLight);
448 }
449
450 //=======================================================================
451 //function : SetPrivilegedPlane
452 //purpose  :
453 //=======================================================================
454 void V3d_Viewer::SetPrivilegedPlane (const gp_Ax3& thePlane)
455 {
456   myPrivilegedPlane = thePlane;
457   Handle(Aspect_Grid) aGrid = Grid (true);
458   aGrid->SetDrawMode (aGrid->DrawMode()); // aGrid->UpdateDisplay();
459   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
460   {
461     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
462   }
463
464   if (myDisplayPlane)
465   {
466     DisplayPrivilegedPlane (Standard_True, myDisplayPlaneLength);
467   }
468 }
469
470 //=======================================================================
471 //function : DisplayPrivilegedPlane
472 //purpose  :
473 //=======================================================================
474 void V3d_Viewer::DisplayPrivilegedPlane (const Standard_Boolean theOnOff, const Standard_Real theSize)
475 {
476   myDisplayPlane = theOnOff;
477   myDisplayPlaneLength = theSize;
478
479   if (!myDisplayPlane)
480   {
481     if (!myPlaneStructure.IsNull())
482     {
483       myPlaneStructure->Erase();
484     }
485     return;
486   }
487
488   if (myPlaneStructure.IsNull())
489   {
490     myPlaneStructure = new Graphic3d_Structure (StructureManager());
491     myPlaneStructure->SetInfiniteState (Standard_True);
492     myPlaneStructure->Display();
493   }
494   else
495   {
496     myPlaneStructure->Clear();
497   }
498
499   Handle(Graphic3d_Group) aGroup = myPlaneStructure->NewGroup();
500
501   Handle(Graphic3d_AspectLine3d) aLineAttrib = new Graphic3d_AspectLine3d (Quantity_NOC_GRAY60, Aspect_TOL_SOLID, 1.0);
502   aGroup->SetGroupPrimitivesAspect (aLineAttrib);
503
504   Handle(Graphic3d_AspectText3d) aTextAttrib = new Graphic3d_AspectText3d();
505   aTextAttrib->SetColor (Quantity_Color (Quantity_NOC_ROYALBLUE1));
506   aGroup->SetGroupPrimitivesAspect (aTextAttrib);
507
508   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments (6);
509
510   const gp_Pnt& p0 = myPrivilegedPlane.Location();
511
512   const gp_Pnt pX (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.XDirection().XYZ());
513   aPrims->AddVertex (p0);
514   aPrims->AddVertex (pX);
515   Handle(Graphic3d_Text) aText = new Graphic3d_Text (1.0f / 81.0f);
516   aText->SetText ("X");
517   aText->SetPosition (pX);
518   aGroup->AddText (aText);
519
520   const gp_Pnt pY (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.YDirection().XYZ());
521   aPrims->AddVertex (p0);
522   aPrims->AddVertex (pY);
523   aText = new Graphic3d_Text (1.0f / 81.0f);
524   aText->SetText ("Y");
525   aText->SetPosition (pY);
526   aGroup->AddText (aText);
527
528   const gp_Pnt pZ (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.Direction().XYZ());
529   aPrims->AddVertex (p0);
530   aPrims->AddVertex (pZ);
531   aText = new Graphic3d_Text (1.0f / 81.0f);
532   aText->SetText ("Z");
533   aText->SetPosition (pZ);
534   aGroup->AddText (aText);
535
536   aGroup->AddPrimitiveArray (aPrims);
537
538   myPlaneStructure->Display();
539 }
540
541 // =======================================================================
542 // function : Grid
543 // purpose  :
544 // =======================================================================
545 Handle(Aspect_Grid) V3d_Viewer::Grid (Aspect_GridType theGridType, bool theToCreate)
546 {
547   switch (theGridType)
548   {
549     case Aspect_GT_Circular:
550     {
551       if (myCGrid.IsNull() && theToCreate)
552       {
553         myCGrid = new V3d_CircularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
554       }
555       return Handle(Aspect_Grid) (myCGrid);
556     }
557     case Aspect_GT_Rectangular:
558     {
559       if (myRGrid.IsNull() && theToCreate)
560       {
561         myRGrid = new V3d_RectangularGrid (this, Quantity_Color(Quantity_NOC_GRAY50), Quantity_Color(Quantity_NOC_GRAY70));
562       }
563       return Handle(Aspect_Grid) (myRGrid);
564     }
565   }
566   return Handle(Aspect_Grid)();
567 }
568
569 // =======================================================================
570 // function : GridDrawMode
571 // purpose  :
572 // =======================================================================
573 Aspect_GridDrawMode V3d_Viewer::GridDrawMode()
574 {
575   Handle(Aspect_Grid) aGrid = Grid (false);
576   return !aGrid.IsNull() ? aGrid->DrawMode() : Aspect_GDM_Lines;
577 }
578
579 // =======================================================================
580 // function : ActivateGrid
581 // purpose  :
582 // =======================================================================
583 void V3d_Viewer::ActivateGrid (const Aspect_GridType     theType,
584                                const Aspect_GridDrawMode theMode)
585 {
586   if (Handle(Aspect_Grid) anOldGrid = Grid (false))
587   {
588     anOldGrid->Erase();
589   }
590
591   myGridType = theType;
592   Handle(Aspect_Grid) aGrid = Grid (true);
593   aGrid->SetDrawMode (theMode);
594   if (theMode != Aspect_GDM_None)
595   {
596     aGrid->Display();
597   }
598   aGrid->Activate();
599   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
600   {
601     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, aGrid);
602   }
603 }
604
605 // =======================================================================
606 // function : DeactivateGrid
607 // purpose  :
608 // =======================================================================
609 void V3d_Viewer::DeactivateGrid()
610 {
611   Handle(Aspect_Grid) aGrid = Grid (false);
612   if (aGrid.IsNull())
613   {
614     return;
615   }
616
617   aGrid->Erase();
618   aGrid->Deactivate();
619
620   myGridType = Aspect_GT_Rectangular;
621   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
622   {
623     anActiveViewIter.Value()->SetGridActivity (Standard_False);
624     if (myGridEcho
625     && !myGridEchoStructure.IsNull())
626     {
627       myGridEchoStructure->Erase();
628     }
629   }
630 }
631
632 // =======================================================================
633 // function : IsGridActive
634 // purpose  :
635 // =======================================================================
636 Standard_Boolean V3d_Viewer::IsGridActive()
637 {
638   Handle(Aspect_Grid) aGrid = Grid (false);
639   return !aGrid.IsNull() && aGrid->IsActive();
640 }
641
642 // =======================================================================
643 // function : RectangularGridValues
644 // purpose  :
645 // =======================================================================
646 void V3d_Viewer::RectangularGridValues (Standard_Real& theXOrigin,
647                                         Standard_Real& theYOrigin,
648                                         Standard_Real& theXStep,
649                                         Standard_Real& theYStep,
650                                         Standard_Real& theRotationAngle)
651 {
652   Grid (Aspect_GT_Rectangular, true);
653   theXOrigin       = myRGrid->XOrigin();
654   theYOrigin       = myRGrid->YOrigin();
655   theXStep         = myRGrid->XStep();
656   theYStep         = myRGrid->YStep();
657   theRotationAngle = myRGrid->RotationAngle();
658 }
659
660 // =======================================================================
661 // function : SetRectangularGridValues
662 // purpose  :
663 // =======================================================================
664 void V3d_Viewer::SetRectangularGridValues (const Standard_Real theXOrigin,
665                                            const Standard_Real theYOrigin,
666                                            const Standard_Real theXStep,
667                                            const Standard_Real theYStep,
668                                            const Standard_Real theRotationAngle)
669 {
670   Grid (Aspect_GT_Rectangular, true);
671   myRGrid->SetGridValues (theXOrigin, theYOrigin, theXStep, theYStep, theRotationAngle);
672   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
673   {
674     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myRGrid);
675   }
676 }
677
678 // =======================================================================
679 // function : CircularGridValues
680 // purpose  :
681 // =======================================================================
682 void V3d_Viewer::CircularGridValues (Standard_Real& theXOrigin,
683                                      Standard_Real& theYOrigin,
684                                      Standard_Real& theRadiusStep,
685                                      Standard_Integer& theDivisionNumber,
686                                      Standard_Real& theRotationAngle)
687 {
688   Grid (Aspect_GT_Circular, true);
689   theXOrigin        = myCGrid->XOrigin();
690   theYOrigin        = myCGrid->YOrigin();
691   theRadiusStep     = myCGrid->RadiusStep();
692   theDivisionNumber = myCGrid->DivisionNumber();
693   theRotationAngle  = myCGrid->RotationAngle();
694 }
695
696 // =======================================================================
697 // function : SetCircularGridValues
698 // purpose  :
699 // =======================================================================
700 void V3d_Viewer::SetCircularGridValues (const Standard_Real theXOrigin,
701                                         const Standard_Real theYOrigin,
702                                         const Standard_Real theRadiusStep,
703                                         const Standard_Integer theDivisionNumber,
704                                         const Standard_Real theRotationAngle)
705 {
706   Grid (Aspect_GT_Circular, true);
707   myCGrid->SetGridValues (theXOrigin, theYOrigin, theRadiusStep,
708                           theDivisionNumber, theRotationAngle);
709   for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
710   {
711     anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, myCGrid);
712   }
713 }
714
715 // =======================================================================
716 // function : RectangularGridGraphicValues
717 // purpose  :
718 // =======================================================================
719 void V3d_Viewer::RectangularGridGraphicValues (Standard_Real& theXSize,
720                                                Standard_Real& theYSize,
721                                                Standard_Real& theOffSet)
722 {
723   Grid (Aspect_GT_Rectangular, true);
724   myRGrid->GraphicValues (theXSize, theYSize, theOffSet);
725 }
726
727 // =======================================================================
728 // function : SetRectangularGridGraphicValues
729 // purpose  :
730 // =======================================================================
731 void V3d_Viewer::SetRectangularGridGraphicValues (const Standard_Real theXSize,
732                                                   const Standard_Real theYSize,
733                                                   const Standard_Real theOffSet)
734 {
735   Grid (Aspect_GT_Rectangular, true);
736   myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet);
737 }
738
739 // =======================================================================
740 // function : CircularGridGraphicValues
741 // purpose  :
742 // =======================================================================
743 void V3d_Viewer::CircularGridGraphicValues (Standard_Real& theRadius,
744                                             Standard_Real& theOffSet)
745 {
746   Grid (Aspect_GT_Circular, true);
747   myCGrid->GraphicValues (theRadius, theOffSet);
748 }
749
750 // =======================================================================
751 // function : SetCircularGridGraphicValues
752 // purpose  :
753 // =======================================================================
754 void V3d_Viewer::SetCircularGridGraphicValues (const Standard_Real theRadius,
755                                                const Standard_Real theOffSet)
756 {
757   Grid (Aspect_GT_Circular, true);
758   myCGrid->SetGraphicValues (theRadius, theOffSet);
759 }
760
761 // =======================================================================
762 // function : SetGridEcho
763 // purpose  :
764 // =======================================================================
765 void V3d_Viewer::SetGridEcho (const Standard_Boolean theToShowGrid)
766 {
767   if (myGridEcho == theToShowGrid)
768   {
769     return;
770   }
771
772   myGridEcho = theToShowGrid;
773   if (theToShowGrid
774    || myGridEchoStructure.IsNull())
775   {
776     return;
777   }
778
779   myGridEchoStructure->Erase();
780 }
781
782 // =======================================================================
783 // function : SetGridEcho
784 // purpose  :
785 // =======================================================================
786 void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker)
787 {
788   if (myGridEchoStructure.IsNull())
789   {
790     myGridEchoStructure = new Graphic3d_Structure (StructureManager());
791     myGridEchoGroup     = myGridEchoStructure->NewGroup();
792   }
793
794   myGridEchoAspect = theMarker;
795   myGridEchoGroup->SetPrimitivesAspect (theMarker);
796 }
797
798 // =======================================================================
799 // function : ShowGridEcho
800 // purpose  :
801 // =======================================================================
802 void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView,
803                                const Graphic3d_Vertex& theVertex)
804 {
805   if (!myGridEcho)
806   {
807     return;
808   }
809
810   if (myGridEchoStructure.IsNull())
811   {
812     myGridEchoStructure = new Graphic3d_Structure (StructureManager());
813     myGridEchoGroup = myGridEchoStructure->NewGroup();
814
815     myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0);
816     myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
817   }
818
819   if (theVertex.X() == myGridEchoLastVert.X()
820    && theVertex.Y() == myGridEchoLastVert.Y()
821    && theVertex.Z() == myGridEchoLastVert.Z())
822   {
823     return;
824   }
825
826   myGridEchoLastVert = theVertex;
827   myGridEchoGroup->Clear();
828   myGridEchoGroup->SetPrimitivesAspect (myGridEchoAspect);
829
830   Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1);
831   anArrayOfPoints->AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z());
832   myGridEchoGroup->AddPrimitiveArray (anArrayOfPoints);
833
834   myGridEchoStructure->SetZLayer (Graphic3d_ZLayerId_Topmost);
835   myGridEchoStructure->SetInfiniteState (Standard_True);
836   myGridEchoStructure->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity();
837   myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (Standard_False);
838   myGridEchoStructure->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), true);
839   myGridEchoStructure->Display();
840 }
841
842 // =======================================================================
843 // function : HideGridEcho
844 // purpose  :
845 // =======================================================================
846 void V3d_Viewer::HideGridEcho (const Handle(V3d_View)& theView)
847 {
848   if (myGridEchoStructure.IsNull())
849   {
850     return;
851   }
852
853   myGridEchoLastVert.SetCoord (ShortRealLast(), ShortRealLast(), ShortRealLast());
854   const Handle(Graphic3d_ViewAffinity)& anAffinity = myGridEchoStructure->CStructure()->ViewAffinity;
855   if (!anAffinity.IsNull() && anAffinity->IsVisible (theView->View()->Identification()))
856   {
857     myGridEchoStructure->Erase();
858   }
859 }
860
861 //=======================================================================
862 //function : DumpJson
863 //purpose  : 
864 //=======================================================================
865 void V3d_Viewer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
866 {
867   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
868   
869   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDriver.get())
870   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myStructureManager.get())
871   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myZLayerGenId)
872   
873   for (V3d_ListOfView::Iterator anIter (myDefinedViews); anIter.More(); anIter.Next())
874   {
875     const Handle(V3d_View)& aDefinedView = anIter.Value();
876     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedView.get())
877   }
878
879   for (V3d_ListOfView::Iterator anIter (myActiveViews); anIter.More(); anIter.Next())
880   {
881     const Handle(V3d_View)& anActiveView = anIter.Value();
882     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anActiveView.get())
883   }
884     
885   for (V3d_ListOfLight::Iterator anIter (myDefinedLights); anIter.More(); anIter.Next())
886   {
887     const Handle(Graphic3d_CLight)& aDefinedLight = anIter.Value();
888     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, aDefinedLight.get())
889   }
890
891   for (V3d_ListOfLight::Iterator anIter (myActiveLights); anIter.More(); anIter.Next())
892   {
893     const Handle(Graphic3d_CLight)& anActiveLight = anIter.Value();
894     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anActiveLight.get())
895   }
896
897   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myBackground)
898   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGradientBackground)
899
900   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewSize)
901   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewProj)
902   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myVisualization)
903   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultTypeOfView)
904   
905   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultRenderingParams)
906   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComputedMode)
907   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultComputedMode)
908
909   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPrivilegedPlane)
910   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myPlaneStructure.get())
911   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDisplayPlane)
912   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDisplayPlaneLength)
913   
914   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myRGrid.get())
915   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myCGrid.get())
916
917   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGridType)
918   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGridEcho)
919   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoStructure.get())
920   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoGroup.get())
921   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myGridEchoAspect.get())
922   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGridEchoLastVert)
923 }