0033041: Coding - get rid of unused headers [TopTools to Xw]
[occt.git] / src / V3d / V3d_View.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_View.hxx>
15
16 #include <Aspect_CircularGrid.hxx>
17 #include <Aspect_GradientBackground.hxx>
18 #include <Aspect_Grid.hxx>
19 #include <Aspect_NeutralWindow.hxx>
20 #include <Aspect_RectangularGrid.hxx>
21 #include <Aspect_Window.hxx>
22 #include <Bnd_Box.hxx>
23 #include <gp_Ax3.hxx>
24 #include <gp_Dir.hxx>
25 #include <gp_Pln.hxx>
26 #include <Graphic3d_GraphicDriver.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
29 #include <Graphic3d_MapOfStructure.hxx>
30 #include <Graphic3d_Structure.hxx>
31 #include <Graphic3d_TextureEnv.hxx>
32 #include <Image_AlienPixMap.hxx>
33 #include <Message.hxx>
34 #include <Message_Messenger.hxx>
35 #include <NCollection_Array1.hxx>
36 #include <Precision.hxx>
37 #include <Quantity_Color.hxx>
38 #include <Standard_Assert.hxx>
39 #include <Standard_DivideByZero.hxx>
40 #include <Standard_ErrorHandler.hxx>
41 #include <Standard_ShortReal.hxx>
42 #include <Standard_Type.hxx>
43 #include <Standard_TypeMismatch.hxx>
44 #include <TColStd_Array2OfReal.hxx>
45 #include <V3d.hxx>
46 #include <V3d_BadValue.hxx>
47 #include <V3d_Light.hxx>
48 #include <V3d_StereoDumpOptions.hxx>
49 #include <V3d_UnMapped.hxx>
50 #include <V3d_Viewer.hxx>
51
52 IMPLEMENT_STANDARD_RTTIEXT(V3d_View,Standard_Transient)
53
54 #define DEUXPI (2. * M_PI)
55
56 namespace
57 {
58   static const Standard_Integer THE_NB_BOUND_POINTS = 8;
59 }
60
61 //=============================================================================
62 //function : Constructor
63 //purpose  :
64 //=============================================================================
65 V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType)
66 : myIsInvalidatedImmediate (Standard_True),
67   MyViewer (theViewer.operator->()),
68   SwitchSetFront (Standard_False),
69   myZRotation (Standard_False),
70   MyTrsf (1, 4, 1, 4)
71 {
72   myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
73
74   myView->SetBackground         (theViewer->GetBackgroundColor());
75   myView->SetGradientBackground (theViewer->GetGradientBackground());
76
77   ChangeRenderingParams() = theViewer->DefaultRenderingParams();
78
79   // camera init
80   Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
81   aCamera->SetFOVy (45.0);
82   aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05);
83   aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0);
84   aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC)
85     ? Graphic3d_Camera::Projection_Orthographic
86     : Graphic3d_Camera::Projection_Perspective);
87
88   myDefaultCamera = new Graphic3d_Camera();
89
90   myImmediateUpdate = Standard_False;
91   SetAutoZFitMode (Standard_True, 1.0);
92   SetBackFacingModel (V3d_TOBM_AUTOMATIC);
93   SetCamera (aCamera);
94   SetAxis (0.,0.,0.,1.,1.,1.);
95   SetVisualization (theViewer->DefaultVisualization());
96   SetTwist (0.);
97   SetAt (0.,0.,0.);
98   SetProj (theViewer->DefaultViewProj());
99   SetSize (theViewer->DefaultViewSize());
100   Standard_Real zsize = theViewer->DefaultViewSize();
101   SetZSize (2.*zsize);
102   SetDepth (theViewer->DefaultViewSize() / 2.0);
103   SetViewMappingDefault();
104   SetViewOrientationDefault();
105   theViewer->AddView (this);
106   Init();
107   myImmediateUpdate = Standard_True;
108 }
109
110 //=============================================================================
111 //function : Constructor
112 //purpose  :
113 //=============================================================================
114 V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
115 : myIsInvalidatedImmediate (Standard_True),
116   MyViewer (theViewer.operator->()),
117   SwitchSetFront(Standard_False),
118   myZRotation (Standard_False),
119   MyTrsf (1, 4, 1, 4)
120 {
121   myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
122
123   myView->CopySettings (theView->View());
124   myDefaultViewPoint = theView->myDefaultViewPoint;
125   myDefaultViewAxis  = theView->myDefaultViewAxis;
126
127   myDefaultCamera = new Graphic3d_Camera (theView->DefaultCamera());
128
129   myImmediateUpdate = Standard_False;
130   SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor());
131   theViewer->AddView (this);
132   Init();
133   myImmediateUpdate = Standard_True;
134 }
135
136 //=============================================================================
137 //function : Destructor
138 //purpose  :
139 //=============================================================================
140 V3d_View::~V3d_View()
141 {
142   if (myParentView != nullptr)
143   {
144     myParentView->RemoveSubview (this);
145     myParentView = nullptr;
146   }
147   {
148     NCollection_Sequence<Handle(V3d_View)> aSubviews = mySubviews;
149     mySubviews.Clear();
150     for (const Handle(V3d_View)& aViewIter : aSubviews)
151     {
152       //aViewIter->Remove();
153       aViewIter->myParentView = nullptr;
154       aViewIter->MyWindow.Nullify();
155       aViewIter->myView->Remove();
156       if (aViewIter->MyViewer != nullptr)
157       {
158         aViewIter->MyViewer->SetViewOff (aViewIter);
159       }
160     }
161   }
162
163   if (!myView->IsRemoved())
164   {
165     myView->Remove();
166   }
167 }
168
169 //=============================================================================
170 //function : SetMagnify
171 //purpose  :
172 //=============================================================================
173 void V3d_View::SetMagnify (const Handle(Aspect_Window)& theWindow,
174                            const Handle(V3d_View)& thePreviousView,
175                            const Standard_Integer theX1,
176                            const Standard_Integer theY1,
177                            const Standard_Integer theX2,
178                            const Standard_Integer theY2)
179 {
180   if (!myView->IsRemoved() && !myView->IsDefined())
181   {
182     Standard_Real aU1, aV1, aU2, aV2;
183     thePreviousView->Convert (theX1, theY1, aU1, aV1);
184     thePreviousView->Convert (theX2, theY2, aU2, aV2);
185     myView->SetWindow (Handle(Graphic3d_CView)(), theWindow, nullptr);
186     FitAll (aU1, aV1, aU2, aV2);
187     MyViewer->SetViewOn (this);
188     MyWindow = theWindow;
189     SetRatio();
190     Redraw();
191     SetViewMappingDefault();
192   }
193 }
194
195 //=============================================================================
196 //function : SetWindow
197 //purpose  :
198 //=============================================================================
199 void V3d_View::SetWindow (const Handle(Aspect_Window)&  theWindow,
200                           const Aspect_RenderingContext theContext)
201 {
202   if (myView->IsRemoved())
203   {
204     return;
205   }
206   if (myParentView != nullptr)
207   {
208     throw Standard_ProgramError ("V3d_View::SetWindow() called twice");
209   }
210
211   // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
212   MyWindow = theWindow;
213   myView->SetWindow (Handle(Graphic3d_CView)(), theWindow, theContext);
214   MyViewer->SetViewOn (this);
215   SetRatio();
216   if (myImmediateUpdate)
217   {
218     Redraw();
219   }
220 }
221
222 //=============================================================================
223 //function : SetWindow
224 //purpose  :
225 //=============================================================================
226 void V3d_View::SetWindow (const Handle(V3d_View)& theParentView,
227                           const Graphic3d_Vec2d& theSize,
228                           Aspect_TypeOfTriedronPosition theCorner,
229                           const Graphic3d_Vec2d& theOffset,
230                           const Graphic3d_Vec2i& theMargins)
231 {
232   if (myView->IsRemoved())
233   {
234     return;
235   }
236
237   Handle(V3d_View) aParentView = !theParentView->IsSubview()
238                                ? theParentView
239                                : theParentView->ParentView();
240   if (aParentView != myParentView)
241   {
242     if (myParentView != nullptr)
243     {
244       throw Standard_ProgramError ("V3d_View::SetWindow() called twice");
245     }
246
247     myParentView = aParentView.get();
248     aParentView->AddSubview (this);
249   }
250
251   Handle(Aspect_NeutralWindow) aWindow = new Aspect_NeutralWindow();
252   aWindow->SetVirtual (true);
253   aWindow->SetSize (4, 4);
254   myView->SetSubviewCorner (theCorner);
255   myView->SetSubviewSize (theSize);
256   myView->SetSubviewOffset (theOffset);
257   myView->SetSubviewMargins (theMargins);
258
259   MyWindow = aWindow;
260   myView->SetWindow (aParentView->View(), aWindow, 0);
261   MyViewer->SetViewOn (this);
262   SetRatio();
263 }
264
265 //=============================================================================
266 //function : Remove
267 //purpose  :
268 //=============================================================================
269 void V3d_View::Remove()
270 {
271   if (!MyGrid.IsNull())
272   {
273     MyGrid->Erase();
274   }
275   if (!myTrihedron.IsNull())
276   {
277     myTrihedron->Erase();
278   }
279
280   if (myParentView != nullptr)
281   {
282     myParentView->RemoveSubview (this);
283     myParentView = nullptr;
284   }
285   {
286     NCollection_Sequence<Handle(V3d_View)> aSubviews = mySubviews;
287     mySubviews.Clear();
288     for (const Handle(V3d_View)& aViewIter : aSubviews)
289     {
290       aViewIter->Remove();
291     }
292   }
293
294   if (MyViewer != nullptr)
295   {
296     MyViewer->DelView (this);
297     MyViewer = nullptr;
298   }
299   myView->Remove();
300   MyWindow.Nullify();
301 }
302
303 // =======================================================================
304 // function : AddSubview
305 // purpose  :
306 // =======================================================================
307 void V3d_View::AddSubview (const Handle(V3d_View)& theView)
308 {
309   mySubviews.Append (theView);
310 }
311
312 // =======================================================================
313 // function : RemoveSubview
314 // purpose  :
315 // =======================================================================
316 bool V3d_View::RemoveSubview (const V3d_View* theView)
317 {
318   for (NCollection_Sequence<Handle(V3d_View)>::Iterator aViewIter (mySubviews); aViewIter.More(); aViewIter.Next())
319   {
320     if (aViewIter.Value() == theView)
321     {
322       mySubviews.Remove (aViewIter);
323       return true;
324     }
325   }
326   return false;
327 }
328
329 // =============================================================================
330 // function : PickSubview
331 // purpose  :
332 // =============================================================================
333 Handle(V3d_View) V3d_View::PickSubview (const Graphic3d_Vec2i& thePnt) const
334 {
335   if (thePnt.x() < 0
336    || thePnt.x() >= MyWindow->Dimensions().x()
337    || thePnt.y() < 0
338    || thePnt.y() >= MyWindow->Dimensions().y())
339   {
340     return Handle(V3d_View)();
341   }
342
343   // iterate in opposite direction - from front to bottom views
344   for (Standard_Integer aSubviewIter = mySubviews.Upper(); aSubviewIter >= mySubviews.Lower(); --aSubviewIter)
345   {
346     const Handle(V3d_View)& aSubview = mySubviews.Value (aSubviewIter);
347     if (aSubview->View()->IsActive()
348      && thePnt.x() >= aSubview->View()->SubviewTopLeft().x()
349      && thePnt.x() < (aSubview->View()->SubviewTopLeft().x() + aSubview->Window()->Dimensions().x())
350      && thePnt.y() >= aSubview->View()->SubviewTopLeft().y()
351      && thePnt.y() < (aSubview->View()->SubviewTopLeft().y() + aSubview->Window()->Dimensions().y()))
352     {
353       return aSubview;
354     }
355   }
356
357   return this;
358 }
359
360 //=============================================================================
361 //function : Update
362 //purpose  :
363 //=============================================================================
364 void V3d_View::Update() const
365 {
366   if (!myView->IsDefined()
367    || !myView->IsActive())
368   {
369     return;
370   }
371
372   myIsInvalidatedImmediate = Standard_False;
373   myView->Update();
374   myView->Compute();
375   AutoZFit();
376   myView->Redraw();
377 }
378
379 //=============================================================================
380 //function : Redraw
381 //purpose  :
382 //=============================================================================
383 void V3d_View::Redraw() const
384 {
385   if (!myView->IsDefined()
386    || !myView->IsActive())
387   {
388     return;
389   }
390
391   myIsInvalidatedImmediate = Standard_False;
392   Handle(Graphic3d_StructureManager) aStructureMgr  = MyViewer->StructureManager();
393   for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
394   {
395     if (aStructureMgr->IsDeviceLost())
396     {
397       aStructureMgr->RecomputeStructures();
398     }
399
400     AutoZFit();
401
402     myView->Redraw();
403
404     if (!aStructureMgr->IsDeviceLost())
405     {
406       return;
407     }
408   }
409 }
410
411 //=============================================================================
412 //function : RedrawImmediate
413 //purpose  :
414 //=============================================================================
415 void V3d_View::RedrawImmediate() const
416 {
417   if (!myView->IsDefined()
418    || !myView->IsActive())
419   {
420     return;
421   }
422
423   myIsInvalidatedImmediate = Standard_False;
424   myView->RedrawImmediate();
425 }
426
427 //=============================================================================
428 //function : Invalidate
429 //purpose  :
430 //=============================================================================
431 void V3d_View::Invalidate() const
432 {
433   if (!myView->IsDefined())
434   {
435     return;
436   }
437
438   myView->Invalidate();
439 }
440
441 //=============================================================================
442 //function : IsInvalidated
443 //purpose  :
444 //=============================================================================
445 Standard_Boolean V3d_View::IsInvalidated() const
446 {
447   return !myView->IsDefined()
448        || myView->IsInvalidated();
449 }
450
451 // ========================================================================
452 // function : SetAutoZFitMode
453 // purpose  :
454 // ========================================================================
455 void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
456                                 const Standard_Real    theScaleFactor)
457 {
458   Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
459   myAutoZFitScaleFactor = theScaleFactor;
460   myAutoZFitIsOn = theIsOn;
461 }
462
463 //=============================================================================
464 //function : AutoZFit
465 //purpose  :
466 //=============================================================================
467 void V3d_View::AutoZFit() const
468 {
469   if (!AutoZFitMode())
470   {
471     return;
472   }
473
474   ZFitAll (myAutoZFitScaleFactor);
475 }
476
477 //=============================================================================
478 //function : ZFitAll
479 //purpose  :
480 //=============================================================================
481 void V3d_View::ZFitAll (const Standard_Real theScaleFactor) const
482 {
483   Bnd_Box aMinMaxBox   = myView->MinMaxValues (Standard_False); // applicative min max boundaries
484   Bnd_Box aGraphicBox  = myView->MinMaxValues (Standard_True);  // real graphical boundaries (not accounting infinite flag).
485
486   myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
487 }
488
489 //=============================================================================
490 //function : IsEmpty
491 //purpose  :
492 //=============================================================================
493 Standard_Boolean V3d_View::IsEmpty() const
494 {
495   Standard_Boolean TheStatus = Standard_True ;
496   if( myView->IsDefined() ) {
497     Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
498     if( Nstruct > 0 ) TheStatus = Standard_False ;
499   }
500   return (TheStatus) ;
501 }
502
503 //=============================================================================
504 //function : UpdateLights
505 //purpose  :
506 //=============================================================================
507 void V3d_View::UpdateLights() const
508 {
509   Handle(Graphic3d_LightSet) aLights = new Graphic3d_LightSet();
510   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
511   {
512     aLights->Add (anActiveLightIter.Value());
513   }
514   myView->SetLights (aLights);
515 }
516
517 //=============================================================================
518 //function : DoMapping
519 //purpose  :
520 //=============================================================================
521 void V3d_View::DoMapping()
522 {
523   if (!myView->IsDefined())
524   {
525     return;
526   }
527
528   myView->Window()->DoMapping();
529 }
530
531 //=============================================================================
532 //function : MustBeResized
533 //purpose  :
534 //=============================================================================
535 void V3d_View::MustBeResized()
536 {
537   if (!myView->IsDefined())
538   {
539     return;
540   }
541
542   myView->Resized();
543
544   SetRatio();
545   if (myImmediateUpdate)
546   {
547     Redraw();
548   }
549 }
550
551 //=============================================================================
552 //function : SetBackgroundColor
553 //purpose  :
554 //=============================================================================
555 void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType,
556                                    const Standard_Real theV1,
557                                    const Standard_Real theV2,
558                                    const Standard_Real theV3)
559 {
560   Standard_Real aV1 = Max (Min (theV1, 1.0), 0.0);
561   Standard_Real aV2 = Max (Min (theV2, 1.0), 0.0);
562   Standard_Real aV3 = Max (Min (theV3, 1.0), 0.0);
563
564   SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
565 }
566
567 //=============================================================================
568 //function : SetBackgroundColor
569 //purpose  :
570 //=============================================================================
571 void V3d_View::SetBackgroundColor (const Quantity_Color& theColor)
572 {
573   myView->SetBackground (Aspect_Background (theColor));
574
575   if (myImmediateUpdate)
576   {
577     Redraw();
578   }
579 }
580
581 //=============================================================================
582 //function : SetBgGradientColors
583 //purpose  :
584 //=============================================================================
585 void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
586                                     const Quantity_Color& theColor2,
587                                     const Aspect_GradientFillMethod theFillStyle,
588                                     const Standard_Boolean theToUpdate)
589 {
590   Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle);
591
592   myView->SetGradientBackground (aGradientBg);
593
594   if (myImmediateUpdate || theToUpdate)
595   {
596     Redraw();
597   }
598 }
599
600 //=============================================================================
601 //function : SetBgGradientStyle
602 //purpose  :
603 //=============================================================================
604 void V3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate)
605 {
606   Quantity_Color aColor1;
607   Quantity_Color aColor2;
608   GradientBackground().Colors (aColor1, aColor2);
609
610   SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
611 }
612
613 //=============================================================================
614 //function : SetBackgroundImage
615 //purpose  :
616 //=============================================================================
617 void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
618                                    const Aspect_FillMethod theFillStyle,
619                                    const Standard_Boolean theToUpdate)
620 {
621   Handle(Graphic3d_Texture2D) aTextureMap = new Graphic3d_Texture2D (theFileName);
622   aTextureMap->DisableModulate();
623   SetBackgroundImage (aTextureMap, theFillStyle, theToUpdate);
624 }
625
626 //=============================================================================
627 //function : SetBackgroundImage
628 //purpose  :
629 //=============================================================================
630 void V3d_View::SetBackgroundImage (const Handle(Graphic3d_Texture2D)& theTexture,
631                                    const Aspect_FillMethod theFillStyle,
632                                    const Standard_Boolean theToUpdate)
633 {
634   myView->SetBackgroundImage (theTexture);
635   myView->SetBackgroundImageStyle (theFillStyle);
636   if (myImmediateUpdate || theToUpdate)
637   {
638     Redraw();
639   }
640 }
641
642 //=============================================================================
643 //function : SetBgImageStyle
644 //purpose  :
645 //=============================================================================
646 void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate)
647 {
648   myView->SetBackgroundImageStyle (theFillStyle);
649
650   if (myImmediateUpdate || theToUpdate)
651   {
652     Redraw();
653   }
654 }
655
656 //=============================================================================
657 //function : SetBackgroundCubeMap
658 //purpose  :
659 //=============================================================================
660 void V3d_View::SetBackgroundCubeMap (const Handle(Graphic3d_CubeMap)& theCubeMap,
661                                      Standard_Boolean                 theToUpdatePBREnv,
662                                      Standard_Boolean                 theToUpdate)
663 {
664   myView->SetBackgroundImage (theCubeMap, theToUpdatePBREnv);
665   if (myImmediateUpdate || theToUpdate)
666   {
667     Redraw();
668   }
669 }
670
671 //=============================================================================
672 //function : SetBackgroundSkydome
673 //purpose  :
674 //=============================================================================
675 void V3d_View::SetBackgroundSkydome (const Aspect_SkydomeBackground& theAspect,
676                                      Standard_Boolean theToUpdatePBREnv)
677 {
678   myView->SetBackgroundSkydome (theAspect, theToUpdatePBREnv);
679 }
680
681 //=============================================================================
682 //function : IsImageBasedLighting
683 //purpose  :
684 //=============================================================================
685 Standard_Boolean V3d_View::IsImageBasedLighting() const
686 {
687   return !myView->IBLCubeMap().IsNull();
688 }
689
690 //=============================================================================
691 //function : SetImageBasedLighting
692 //purpose  :
693 //=============================================================================
694 void V3d_View::SetImageBasedLighting (Standard_Boolean theToEnableIBL,
695                                       Standard_Boolean theToUpdate)
696 {
697   myView->SetImageBasedLighting (theToEnableIBL);
698   if (myImmediateUpdate || theToUpdate)
699   {
700     Redraw();
701   }
702 }
703
704 //=============================================================================
705 //function : SetAxis
706 //purpose  :
707 //=============================================================================
708 void V3d_View::SetAxis (const Standard_Real theX,  const Standard_Real theY,  const Standard_Real theZ,
709                         const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
710 {
711   myDefaultViewPoint.SetCoord (theX, theY, theZ);
712   myDefaultViewAxis.SetCoord (theVx, theVy, theVz);
713 }
714
715 //=============================================================================
716 //function : SetShadingModel
717 //purpose  :
718 //=============================================================================
719 void V3d_View::SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel)
720 {
721   myView->SetShadingModel (theShadingModel);
722 }
723
724 //=============================================================================
725 //function : SetTextureEnv
726 //purpose  :
727 //=============================================================================
728 void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture)
729 {
730   myView->SetTextureEnv (theTexture);
731
732   if (myImmediateUpdate)
733   {
734     Redraw();
735   }
736 }
737
738 //=============================================================================
739 //function : SetVisualization
740 //purpose  :
741 //=============================================================================
742 void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType)
743 {
744   myView->SetVisualizationType (static_cast <Graphic3d_TypeOfVisualization> (theType));
745
746   if (myImmediateUpdate)
747   {
748     Redraw();
749   }
750 }
751
752 //=============================================================================
753 //function : SetFront
754 //purpose  :
755 //=============================================================================
756 void V3d_View::SetFront()
757 {
758   gp_Ax3 a = MyViewer->PrivilegedPlane();
759   Standard_Real xo, yo, zo, vx, vy, vz, xu, yu, zu;
760
761   a.Direction().Coord(vx,vy,vz);
762   a.YDirection().Coord(xu,yu,zu);
763   a.Location().Coord(xo,yo,zo);
764
765   Handle(Graphic3d_Camera) aCamera = Camera();
766
767   aCamera->SetCenter (gp_Pnt (xo, yo, zo));
768
769   if(SwitchSetFront)
770   {
771     aCamera->SetDirection (gp_Dir (vx, vy, vz));
772   }
773   else
774   {
775     aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
776   }
777
778   aCamera->SetUp (gp_Dir (xu, yu, zu));
779
780   SwitchSetFront = !SwitchSetFront;
781
782   ImmediateUpdate();
783 }
784
785 //=============================================================================
786 //function : Rotate
787 //purpose  :
788 //=============================================================================
789 void V3d_View::Rotate (const Standard_Real ax, 
790                        const Standard_Real ay, 
791                        const Standard_Real az, 
792                        const Standard_Boolean Start)
793 {
794   Standard_Real Ax = ax;
795   Standard_Real Ay = ay;
796   Standard_Real Az = az;
797
798   if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI;
799   else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI;
800   if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI;
801   else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI;
802   if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI;
803   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI;
804
805   Handle(Graphic3d_Camera) aCamera = Camera();
806
807   if (Start)
808   {
809     myCamStartOpUp     = aCamera->Up();
810     myCamStartOpDir    = aCamera->Direction();
811     myCamStartOpEye    = aCamera->Eye();
812     myCamStartOpCenter = aCamera->Center();
813   }
814
815   aCamera->SetUp (myCamStartOpUp);
816   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
817   aCamera->SetDirectionFromEye (myCamStartOpDir);
818
819   // rotate camera around 3 initial axes
820   gp_Dir aBackDir = -myCamStartOpDir;
821   gp_Dir aXAxis (myCamStartOpUp.Crossed (aBackDir));
822   gp_Dir aYAxis (aBackDir.Crossed (aXAxis));
823   gp_Dir aZAxis (aXAxis.Crossed (aYAxis));
824
825   gp_Trsf aRot[3], aTrsf;
826   aRot[0].SetRotation (gp_Ax1 (myCamStartOpCenter, aYAxis), -Ax);
827   aRot[1].SetRotation (gp_Ax1 (myCamStartOpCenter, aXAxis), Ay);
828   aRot[2].SetRotation (gp_Ax1 (myCamStartOpCenter, aZAxis), Az);
829   aTrsf.Multiply (aRot[0]);
830   aTrsf.Multiply (aRot[1]);
831   aTrsf.Multiply (aRot[2]);
832
833   aCamera->Transform (aTrsf);
834
835   ImmediateUpdate();
836 }
837
838 //=============================================================================
839 //function : Rotate
840 //purpose  :
841 //=============================================================================
842 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
843                       const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
844 {
845
846   Standard_Real Ax = ax ;
847   Standard_Real Ay = ay ;
848   Standard_Real Az = az ;
849
850   if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
851   else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
852   if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
853   else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
854   if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
855   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
856
857   Handle(Graphic3d_Camera) aCamera = Camera();
858
859   if (Start)
860   {
861     myGravityReferencePoint.SetCoord (X, Y, Z);
862     myCamStartOpUp     = aCamera->Up();
863     myCamStartOpDir    = aCamera->Direction();
864     myCamStartOpEye    = aCamera->Eye();
865     myCamStartOpCenter = aCamera->Center();
866   }
867
868   const Graphic3d_Vertex& aVref = myGravityReferencePoint;
869
870   aCamera->SetUp (myCamStartOpUp);
871   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
872   aCamera->SetDirectionFromEye (myCamStartOpDir);
873
874   // rotate camera around 3 initial axes
875   gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
876
877   gp_Dir aZAxis (aCamera->Direction().Reversed());
878   gp_Dir aYAxis (aCamera->Up());
879   gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); 
880
881   gp_Trsf aRot[3], aTrsf;
882   aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
883   aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
884   aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
885   aTrsf.Multiply (aRot[0]);
886   aTrsf.Multiply (aRot[1]);
887   aTrsf.Multiply (aRot[2]);
888
889   aCamera->Transform (aTrsf);
890
891   ImmediateUpdate();
892 }
893
894 //=============================================================================
895 //function : Rotate
896 //purpose  :
897 //=============================================================================
898 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
899 {
900   switch (Axe) {
901   case V3d_X :
902     Rotate(angle,0.,0.,Start);
903     break ;
904   case V3d_Y :
905     Rotate(0.,angle,0.,Start);
906     break ;
907   case V3d_Z :
908     Rotate(0.,0.,angle,Start);
909     break ;
910   }
911 }
912
913 //=============================================================================
914 //function : Rotate
915 //purpose  :
916 //=============================================================================
917 void V3d_View::Rotate (const V3d_TypeOfAxe theAxe, const Standard_Real theAngle,
918                        const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, const Standard_Boolean theStart)
919 {
920   Standard_Real anAngle = theAngle;
921
922   if (anAngle > 0.0) while (anAngle > DEUXPI) anAngle -= DEUXPI;
923   else if (anAngle < 0.0) while (anAngle < -DEUXPI) anAngle += DEUXPI;
924
925   Handle(Graphic3d_Camera) aCamera = Camera();
926
927   if (theStart)
928   {
929     myGravityReferencePoint.SetCoord (theX, theY, theZ);
930     myCamStartOpUp     = aCamera->Up();
931     myCamStartOpDir    = aCamera->Direction();
932     myCamStartOpEye    = aCamera->Eye();
933     myCamStartOpCenter = aCamera->Center();
934     switch (theAxe)
935     {
936       case V3d_X: myViewAxis = gp::DX(); break;
937       case V3d_Y: myViewAxis = gp::DY(); break;
938       case V3d_Z: myViewAxis = gp::DZ(); break;
939     }
940   }
941
942   const Graphic3d_Vertex& aVref = myGravityReferencePoint;
943
944   aCamera->SetUp (myCamStartOpUp);
945   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
946   aCamera->SetDirectionFromEye (myCamStartOpDir);
947
948   // rotate camera around passed axis
949   gp_Trsf aRotation;
950   gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
951   gp_Dir aRAxis ((theAxe == V3d_X) ? 1.0 : 0.0,
952                  (theAxe == V3d_Y) ? 1.0 : 0.0,
953                  (theAxe == V3d_Z) ? 1.0 : 0.0);
954
955   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), anAngle);
956
957   aCamera->Transform (aRotation);
958
959   ImmediateUpdate();
960 }
961
962 //=============================================================================
963 //function : Rotate
964 //purpose  :
965 //=============================================================================
966 void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
967 {
968   Standard_Real Angle = angle;
969
970   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
971   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
972
973   Handle(Graphic3d_Camera) aCamera = Camera();
974
975   if (Start)
976   {
977     myCamStartOpUp     = aCamera->Up();
978     myCamStartOpDir    = aCamera->Direction();
979     myCamStartOpEye    = aCamera->Eye();
980     myCamStartOpCenter = aCamera->Center();
981   }
982
983   aCamera->SetUp (myCamStartOpUp);
984   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
985   aCamera->SetDirectionFromEye (myCamStartOpDir);
986
987   gp_Trsf aRotation;
988   gp_Pnt aRCenter (myDefaultViewPoint);
989   gp_Dir aRAxis (myDefaultViewAxis);
990   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
991
992   aCamera->Transform (aRotation);
993
994   ImmediateUpdate();
995 }
996
997 //=============================================================================
998 //function : Turn
999 //purpose  :
1000 //=============================================================================
1001 void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
1002 {
1003   Standard_Real Ax = ax;
1004   Standard_Real Ay = ay;
1005   Standard_Real Az = az;
1006
1007   if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
1008   else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
1009   if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
1010   else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
1011   if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
1012   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
1013
1014   Handle(Graphic3d_Camera) aCamera = Camera();
1015
1016   if (Start)
1017   {
1018     myCamStartOpUp     = aCamera->Up();
1019     myCamStartOpDir    = aCamera->Direction();
1020     myCamStartOpEye    = aCamera->Eye();
1021     myCamStartOpCenter = aCamera->Center();
1022   }
1023
1024   aCamera->SetUp (myCamStartOpUp);
1025   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
1026   aCamera->SetDirectionFromEye (myCamStartOpDir);
1027
1028   // rotate camera around 3 initial axes
1029   gp_Pnt aRCenter = aCamera->Eye();
1030   gp_Dir aZAxis (aCamera->Direction().Reversed());
1031   gp_Dir aYAxis (aCamera->Up());
1032   gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); 
1033
1034   gp_Trsf aRot[3], aTrsf;
1035   aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
1036   aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
1037   aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
1038   aTrsf.Multiply (aRot[0]);
1039   aTrsf.Multiply (aRot[1]);
1040   aTrsf.Multiply (aRot[2]);
1041
1042   aCamera->Transform (aTrsf);
1043
1044   ImmediateUpdate();
1045 }
1046
1047 //=============================================================================
1048 //function : Turn
1049 //purpose  :
1050 //=============================================================================
1051 void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
1052 {
1053   switch (Axe) {
1054   case V3d_X :
1055     Turn(angle,0.,0.,Start);
1056     break ;
1057   case V3d_Y :
1058     Turn(0.,angle,0.,Start);
1059     break ;
1060   case V3d_Z :
1061     Turn(0.,0.,angle,Start);
1062     break ;
1063   }
1064 }
1065
1066 //=============================================================================
1067 //function : Turn
1068 //purpose  :
1069 //=============================================================================
1070 void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
1071 {
1072   Standard_Real Angle = angle ;
1073
1074   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1075   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1076
1077   Handle(Graphic3d_Camera) aCamera = Camera();
1078
1079   if (Start)
1080   {
1081     myCamStartOpUp     = aCamera->Up();
1082     myCamStartOpDir    = aCamera->Direction();
1083     myCamStartOpEye    = aCamera->Eye();
1084     myCamStartOpCenter = aCamera->Center();
1085   }
1086
1087   aCamera->SetUp (myCamStartOpUp);
1088   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
1089   aCamera->SetDirectionFromEye (myCamStartOpDir);
1090
1091   gp_Trsf aRotation;
1092   gp_Pnt aRCenter = aCamera->Eye();
1093   gp_Dir aRAxis (myDefaultViewAxis);
1094   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
1095
1096   aCamera->Transform (aRotation);
1097
1098   ImmediateUpdate();
1099 }
1100
1101 //=============================================================================
1102 //function : SetTwist
1103 //purpose  :
1104 //=============================================================================
1105 void V3d_View::SetTwist(const Standard_Real angle)
1106 {
1107   Standard_Real Angle = angle ;
1108
1109   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
1110   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
1111
1112   Handle(Graphic3d_Camera) aCamera = Camera();
1113
1114   const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1115   if (!screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1116    && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1117    && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1118   {
1119     throw V3d_BadValue ("V3d_ViewSetTwist, alignment of Eye,At,Up,");
1120   }
1121   
1122   gp_Pnt aRCenter = aCamera->Center();
1123   gp_Dir aZAxis (aCamera->Direction().Reversed());
1124
1125   gp_Trsf aTrsf;
1126   aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
1127
1128   aCamera->SetUp (gp_Dir (myYscreenAxis));
1129   aCamera->Transform (aTrsf);
1130
1131   ImmediateUpdate();
1132 }
1133
1134 //=============================================================================
1135 //function : SetEye
1136 //purpose  :
1137 //=============================================================================
1138 void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1139 {
1140   Standard_Real aTwistBefore = Twist();
1141
1142   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1143
1144   Handle(Graphic3d_Camera) aCamera = Camera();
1145
1146   aCamera->SetEye (gp_Pnt (X, Y, Z));
1147
1148   SetTwist (aTwistBefore);
1149
1150   SetImmediateUpdate (wasUpdateEnabled);
1151
1152   ImmediateUpdate();
1153 }
1154
1155 //=============================================================================
1156 //function : SetDepth
1157 //purpose  :
1158 //=============================================================================
1159 void V3d_View::SetDepth(const Standard_Real Depth)
1160 {
1161   V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
1162
1163   Handle(Graphic3d_Camera) aCamera = Camera();
1164
1165   if( Depth > 0. )
1166   {
1167     // Move eye using center (target) as anchor.
1168     aCamera->SetDistance (Depth);
1169   }
1170   else
1171   {
1172     // Move the view ref point instead of the eye.
1173     gp_Vec aDir (aCamera->Direction());
1174     gp_Pnt aCameraEye = aCamera->Eye();
1175     gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
1176
1177     aCamera->SetCenter (aCameraCenter);
1178   }
1179
1180   ImmediateUpdate();
1181 }
1182
1183 //=============================================================================
1184 //function : SetProj
1185 //purpose  :
1186 //=============================================================================
1187 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
1188 {
1189   V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
1190     "V3d_View::SetProj, null projection vector");
1191
1192   Standard_Real aTwistBefore = Twist();
1193
1194   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1195
1196   Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
1197
1198   SetTwist(aTwistBefore);
1199
1200   SetImmediateUpdate (wasUpdateEnabled);
1201
1202   ImmediateUpdate();
1203 }
1204
1205 //=============================================================================
1206 //function : SetProj
1207 //purpose  :
1208 //=============================================================================
1209 void V3d_View::SetProj (const V3d_TypeOfOrientation theOrientation,
1210                         const Standard_Boolean theIsYup)
1211 {
1212   Graphic3d_Vec3d anUp = theIsYup ? Graphic3d_Vec3d (0.0, 1.0, 0.0) : Graphic3d_Vec3d (0.0, 0.0, 1.0);
1213   if (theIsYup)
1214   {
1215     if (theOrientation == V3d_Ypos
1216      || theOrientation == V3d_Yneg)
1217     {
1218       anUp.SetValues (0.0, 0.0, -1.0);
1219     }
1220   }
1221   else
1222   {
1223     if (theOrientation == V3d_Zpos)
1224     {
1225       anUp.SetValues (0.0, 1.0, 0.0);
1226     }
1227     else if (theOrientation == V3d_Zneg)
1228     {
1229       anUp.SetValues (0.0, -1.0, 0.0);
1230     }
1231   }
1232
1233   const gp_Dir aBck = V3d::GetProjAxis (theOrientation);
1234
1235   // retain camera panning from origin when switching projection
1236   const Handle(Graphic3d_Camera)& aCamera = Camera();
1237   const gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin());
1238
1239   const Standard_Real aNewDist = aCamera->Eye().Distance (gp_Pnt (0, 0, 0));
1240   aCamera->SetEyeAndCenter (gp_XYZ (0, 0, 0) + aBck.XYZ() * aNewDist,
1241                             gp_XYZ (0, 0, 0));
1242   aCamera->SetDirectionFromEye (-aBck);
1243   aCamera->SetUp (gp_Dir (anUp.x(), anUp.y(), anUp.z()));
1244   aCamera->OrthogonalizeUp();
1245
1246   Panning (anOriginVCS.X(), anOriginVCS.Y());
1247
1248   ImmediateUpdate();
1249 }
1250
1251 //=============================================================================
1252 //function : SetAt
1253 //purpose  :
1254 //=============================================================================
1255 void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
1256 {
1257   Standard_Real aTwistBefore = Twist();
1258
1259   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1260
1261   Camera()->SetCenter (gp_Pnt (X, Y, Z));
1262
1263   SetTwist (aTwistBefore);
1264
1265   SetImmediateUpdate (wasUpdateEnabled);
1266
1267   ImmediateUpdate();
1268 }
1269
1270 //=============================================================================
1271 //function : SetUp
1272 //purpose  :
1273 //=============================================================================
1274 void V3d_View::SetUp (const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
1275 {
1276   Handle(Graphic3d_Camera) aCamera = Camera();
1277
1278   const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1279   const gp_Dir anUp (theVx, theVy, theVz);
1280   if (!screenAxis (aReferencePlane, anUp,     myXscreenAxis, myYscreenAxis, myZscreenAxis)
1281    && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1282    && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1283    && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1284   {
1285     throw V3d_BadValue ("V3d_View::Setup, alignment of Eye,At,Up");
1286   }
1287
1288   aCamera->SetUp (gp_Dir (myYscreenAxis));
1289
1290   ImmediateUpdate();
1291 }
1292
1293 //=============================================================================
1294 //function : SetUp
1295 //purpose  :
1296 //=============================================================================
1297 void V3d_View::SetUp (const V3d_TypeOfOrientation theOrientation)
1298 {
1299   Handle(Graphic3d_Camera) aCamera = Camera();
1300
1301   const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
1302   const gp_Dir anUp = V3d::GetProjAxis (theOrientation);
1303   if (!screenAxis (aReferencePlane, anUp,     myXscreenAxis, myYscreenAxis, myZscreenAxis)
1304    && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1305    && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
1306    && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
1307   {
1308     throw V3d_BadValue ("V3d_View::SetUp, alignment of Eye,At,Up");
1309   }
1310
1311   aCamera->SetUp (gp_Dir (myYscreenAxis));
1312
1313   ImmediateUpdate();
1314 }
1315
1316 //=============================================================================
1317 //function : SetViewOrientationDefault
1318 //purpose  :
1319 //=============================================================================
1320 void V3d_View::SetViewOrientationDefault()
1321 {
1322   myDefaultCamera->CopyOrientationData (Camera());
1323 }
1324
1325 //=======================================================================
1326 //function : SetViewMappingDefault
1327 //purpose  :
1328 //=======================================================================
1329 void V3d_View::SetViewMappingDefault()
1330 {
1331   myDefaultCamera->CopyMappingData (Camera());
1332 }
1333
1334 //=============================================================================
1335 //function : ResetViewOrientation
1336 //purpose  :
1337 //=============================================================================
1338 void V3d_View::ResetViewOrientation()
1339 {
1340   Camera()->CopyOrientationData (myDefaultCamera);
1341   ImmediateUpdate();
1342 }
1343
1344 //=======================================================================
1345 //function : ResetViewMapping
1346 //purpose  :
1347 //=======================================================================
1348 void V3d_View::ResetViewMapping()
1349 {
1350   Camera()->CopyMappingData (myDefaultCamera);
1351   ImmediateUpdate();
1352 }
1353
1354 //=============================================================================
1355 //function : Reset
1356 //purpose  :
1357 //=============================================================================
1358 void V3d_View::Reset (const Standard_Boolean theToUpdate)
1359 {
1360   Camera()->Copy (myDefaultCamera);
1361
1362   SwitchSetFront = Standard_False;
1363
1364   if (myImmediateUpdate || theToUpdate)
1365   {
1366     Update();
1367   }
1368 }
1369
1370 //=======================================================================
1371 //function : SetCenter
1372 //purpose  :
1373 //=======================================================================
1374 void V3d_View::SetCenter (const Standard_Integer theXp,
1375                           const Standard_Integer theYp)
1376 {
1377   Standard_Real aXv, aYv;
1378   Convert (theXp, theYp, aXv, aYv);
1379   Translate (Camera(), aXv, aYv);
1380
1381   ImmediateUpdate();
1382 }
1383
1384 //=============================================================================
1385 //function : SetSize
1386 //purpose  :
1387 //=============================================================================
1388 void V3d_View::SetSize (const Standard_Real theSize)
1389 {
1390   V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
1391
1392   Handle(Graphic3d_Camera) aCamera = Camera();
1393
1394   aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize);
1395
1396   ImmediateUpdate();
1397 }
1398
1399 //=============================================================================
1400 //function : SetZSize
1401 //purpose  :
1402 //=============================================================================
1403 void V3d_View::SetZSize (const Standard_Real theSize)
1404 {
1405   Handle(Graphic3d_Camera) aCamera = Camera();
1406
1407   Standard_Real Zmax = theSize / 2.;
1408
1409   Standard_Real aDistance = aCamera->Distance();
1410
1411   if (theSize <= 0.)
1412   {
1413     Zmax = aDistance;
1414   }
1415
1416   // ShortReal precision factor used to add meaningful tolerance to
1417   // ZNear, ZFar values in order to avoid equality after type conversion
1418   // to ShortReal matrices type.
1419   const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
1420
1421   Standard_Real aZFar  =  Zmax  + aDistance * 2.0;
1422   Standard_Real aZNear = -Zmax  + aDistance;
1423   aZNear              -= Abs (aZNear) * aPrecision;
1424   aZFar               += Abs (aZFar)  * aPrecision;
1425
1426   if (!aCamera->IsOrthographic())
1427   {
1428     if (aZFar < aPrecision)
1429     {
1430       // Invalid case when both values are negative
1431       aZNear = aPrecision;
1432       aZFar  = aPrecision * 2.0;
1433     }
1434     else if (aZNear < Abs (aZFar) * aPrecision)
1435     {
1436       // Z is less than 0.0, try to fix it using any appropriate z-scale
1437       aZNear = Abs (aZFar) * aPrecision;
1438     }
1439   }
1440
1441   // If range is too small
1442   if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
1443   {
1444     aZFar = aZNear + Abs (aZFar) * aPrecision;
1445   }
1446
1447   aCamera->SetZRange (aZNear, aZFar);
1448
1449   if (myImmediateUpdate)
1450   {
1451     Redraw();
1452   }
1453 }
1454
1455 //=============================================================================
1456 //function : SetZoom
1457 //purpose  :
1458 //=============================================================================
1459 void V3d_View::SetZoom (const Standard_Real theCoef,const Standard_Boolean theToStart)
1460 {
1461   V3d_BadValue_Raise_if (theCoef <= 0., "V3d_View::SetZoom, bad coefficient");
1462
1463   Handle(Graphic3d_Camera) aCamera = Camera();
1464
1465   if (theToStart)
1466   {
1467     myCamStartOpEye    = aCamera->Eye();
1468     myCamStartOpCenter = aCamera->Center();
1469   }
1470
1471   Standard_Real aViewWidth  = aCamera->ViewDimensions().X();
1472   Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
1473
1474   // ensure that zoom will not be too small or too big
1475   Standard_Real aCoef = theCoef;
1476   if (aViewWidth < aCoef * Precision::Confusion())
1477   {
1478     aCoef = aViewWidth / Precision::Confusion();
1479   }
1480   else if (aViewWidth > aCoef * 1e12)
1481   {
1482     aCoef = aViewWidth / 1e12;
1483   }
1484   if (aViewHeight < aCoef * Precision::Confusion())
1485   {
1486     aCoef = aViewHeight / Precision::Confusion();
1487   }
1488   else if (aViewHeight > aCoef * 1e12)
1489   {
1490     aCoef = aViewHeight / 1e12;
1491   }
1492
1493   aCamera->SetEye (myCamStartOpEye);
1494   aCamera->SetCenter (myCamStartOpCenter);
1495   aCamera->SetScale (aCamera->Scale() / aCoef);
1496
1497   ImmediateUpdate();
1498 }
1499
1500 //=============================================================================
1501 //function : SetScale
1502 //purpose  :
1503 //=============================================================================
1504 void V3d_View::SetScale( const Standard_Real Coef )
1505 {
1506   V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
1507
1508   Handle(Graphic3d_Camera) aCamera = Camera();
1509
1510   Standard_Real aDefaultScale = myDefaultCamera->Scale();
1511   aCamera->SetAspect (myDefaultCamera->Aspect());
1512   aCamera->SetScale (aDefaultScale / Coef);
1513
1514   ImmediateUpdate();
1515 }
1516
1517 //=============================================================================
1518 //function : SetAxialScale
1519 //purpose  :
1520 //=============================================================================
1521 void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
1522 {
1523   V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
1524
1525   Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
1526 }
1527
1528 //=============================================================================
1529 //function : SetRatio
1530 //purpose  :
1531 //=============================================================================
1532 void V3d_View::SetRatio()
1533 {
1534   if (MyWindow.IsNull())
1535   {
1536     return;
1537   }
1538
1539   Standard_Integer aWidth  = 0;
1540   Standard_Integer aHeight = 0;
1541   MyWindow->Size (aWidth, aHeight);
1542   if (aWidth > 0 && aHeight > 0)
1543   {
1544     Standard_Real aRatio = static_cast<Standard_Real> (aWidth) /
1545                            static_cast<Standard_Real> (aHeight);
1546
1547     Camera()       ->SetAspect (aRatio);
1548     myDefaultCamera->SetAspect (aRatio);
1549   }
1550 }
1551
1552 //=============================================================================
1553 //function : FitAll
1554 //purpose  :
1555 //=============================================================================
1556 void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean theToUpdate)
1557 {
1558   FitAll (myView->MinMaxValues(), theMargin, theToUpdate);
1559 }
1560
1561 //=============================================================================
1562 //function : FitAll
1563 //purpose  :
1564 //=============================================================================
1565 void V3d_View::FitAll (const Bnd_Box& theBox, const Standard_Real theMargin, const Standard_Boolean theToUpdate)
1566 {
1567   Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
1568
1569   if (myView->NumberOfDisplayedStructures() == 0)
1570   {
1571     return;
1572   }
1573
1574   if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion()))
1575   {
1576     return;
1577   }
1578
1579   if (myImmediateUpdate || theToUpdate)
1580   {
1581     Update();
1582   }
1583 }
1584
1585 //=============================================================================
1586 //function : DepthFitAll
1587 //purpose  :
1588 //=============================================================================
1589 void V3d_View::DepthFitAll(const Standard_Real Aspect,
1590                            const Standard_Real Margin)
1591 {
1592   Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
1593   Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
1594   Standard_Real Dx,Dy,Dz,Size;
1595
1596   Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
1597
1598   if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
1599     ImmediateUpdate();
1600     return ;
1601   }
1602
1603   Bnd_Box aBox = myView->MinMaxValues();
1604   if (aBox.IsVoid())
1605   {
1606     ImmediateUpdate();
1607     return ;
1608   }
1609     aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
1610     Project (Xmin,Ymin,Zmin,U,V,W) ;
1611     Project (Xmax,Ymax,Zmax,U1,V1,W1) ;
1612     Umin = Min(U,U1) ; Umax = Max(U,U1) ;
1613     Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
1614     Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
1615     Project (Xmin,Ymin,Zmax,U,V,W) ;
1616     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1617     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1618     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1619     Project (Xmax,Ymin,Zmax,U,V,W) ;
1620     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1621     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1622     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1623     Project (Xmax,Ymin,Zmin,U,V,W) ;
1624     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1625     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1626     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1627     Project (Xmax,Ymax,Zmin,U,V,W) ;
1628     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1629     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1630     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1631     Project (Xmin,Ymax,Zmax,U,V,W) ;
1632     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1633     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1634     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1635     Project (Xmin,Ymax,Zmin,U,V,W) ;
1636     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
1637     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
1638     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
1639
1640     // Adjust Z size
1641     Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
1642     Dz = 2.*Wmax + Margin * Wmax;
1643
1644     // Compute depth value
1645     Dx = Abs(Umax - Umin) ; Dy = Abs(Vmax - Vmin) ; // Dz = Abs(Wmax - Wmin);
1646     Dx += Margin * Dx; Dy += Margin * Dy;
1647     Size = Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);
1648     if( Size > 0. ) {
1649       SetZSize(Size) ;
1650       SetDepth( Aspect * Size / 2.);
1651     }
1652
1653     ImmediateUpdate();
1654 }
1655
1656 //=======================================================================
1657 //function : WindowFit
1658 //purpose  :
1659 //=======================================================================
1660 void V3d_View::WindowFit (const Standard_Integer theMinXp,
1661                           const Standard_Integer theMinYp,
1662                           const Standard_Integer theMaxXp,
1663                           const Standard_Integer theMaxYp)
1664 {
1665   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
1666
1667   Handle(Graphic3d_Camera) aCamera = Camera();
1668
1669   if (!aCamera->IsOrthographic())
1670   {
1671     // normalize view coordinates
1672     Standard_Integer aWinWidth, aWinHeight;
1673     MyWindow->Size (aWinWidth, aWinHeight);
1674
1675     // z coordinate of camera center
1676     Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z();
1677
1678     // camera projection coordinate are in NDC which are normalized [-1, 1]
1679     Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp  - 1.0;
1680     Standard_Real aUMax = (2.0 / aWinWidth) * theMaxXp  - 1.0;
1681     Standard_Real aVMin = (2.0 / aWinHeight) * theMinYp - 1.0;
1682     Standard_Real aVMax = (2.0 / aWinHeight) * theMaxYp - 1.0;
1683
1684     // compute camera panning
1685     gp_Pnt aScreenCenter (0.0, 0.0, aDepth);
1686     gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth);
1687     gp_Pnt aPanTo = aCamera->ConvertProj2View (aFitCenter);
1688     gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter);
1689     gp_Vec aPanVec (aPanFrom, aPanTo);
1690
1691     // compute section size
1692     gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
1693     gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
1694     gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft);
1695     gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight);
1696
1697     Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
1698     Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
1699
1700     Translate (aCamera, aPanVec.X(), -aPanVec.Y());
1701     Scale (aCamera, aUSize, aVSize);
1702   }
1703   else
1704   {
1705     Standard_Real aX1, aY1, aX2, aY2;
1706     Convert (theMinXp, theMinYp, aX1, aY1);
1707     Convert (theMaxXp, theMaxYp, aX2, aY2);
1708     FitAll (aX1, aY1, aX2, aY2);
1709   }
1710
1711   SetImmediateUpdate (wasUpdateEnabled);
1712
1713   ImmediateUpdate();
1714 }
1715
1716 //=======================================================================
1717 //function : ConvertToGrid
1718 //purpose  :
1719 //=======================================================================
1720 void V3d_View::ConvertToGrid(const Standard_Integer theXp,
1721                              const Standard_Integer theYp,
1722                              Standard_Real& theXg,
1723                              Standard_Real& theYg,
1724                              Standard_Real& theZg) const
1725 {
1726   Graphic3d_Vec3d anXYZ;
1727   Convert (theXp, theYp, anXYZ.x(), anXYZ.y(), anXYZ.z());
1728
1729   Graphic3d_Vertex aVrp;
1730   aVrp.SetCoord (anXYZ.x(), anXYZ.y(), anXYZ.z());
1731   if (MyViewer->IsGridActive())
1732   {
1733     Graphic3d_Vertex aNewVrp = Compute (aVrp);
1734     aNewVrp.Coord (theXg, theYg, theZg);
1735   }
1736   else
1737   {
1738     aVrp.Coord (theXg, theYg, theZg);
1739   }
1740 }
1741
1742 //=======================================================================
1743 //function : ConvertToGrid
1744 //purpose  :
1745 //=======================================================================
1746 void V3d_View::ConvertToGrid(const Standard_Real theX,
1747                              const Standard_Real theY,
1748                              const Standard_Real theZ,
1749                              Standard_Real& theXg,
1750                              Standard_Real& theYg,
1751                              Standard_Real& theZg) const
1752 {
1753   if (MyViewer->IsGridActive())
1754   {
1755     Graphic3d_Vertex aVrp (theX, theY, theZ);
1756     Graphic3d_Vertex aNewVrp = Compute (aVrp);
1757     aNewVrp.Coord (theXg, theYg, theZg);
1758   }
1759   else
1760   {
1761     theXg = theX; theYg = theY; theZg = theZ;
1762   }
1763 }
1764
1765 //=======================================================================
1766 //function : Convert
1767 //purpose  :
1768 //=======================================================================
1769 Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
1770 {
1771   Standard_Integer aDxw, aDyw ;
1772
1773   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1774
1775   MyWindow->Size (aDxw, aDyw);
1776   Standard_Real aValue;
1777
1778   gp_Pnt aViewDims = Camera()->ViewDimensions();
1779   aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
1780
1781   return aValue;
1782 }
1783
1784 //=======================================================================
1785 //function : Convert
1786 //purpose  :
1787 //=======================================================================
1788 void V3d_View::Convert(const Standard_Integer Xp,
1789                        const Standard_Integer Yp,
1790                        Standard_Real& Xv,
1791                        Standard_Real& Yv) const
1792 {
1793   Standard_Integer aDxw, aDyw;
1794
1795   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1796
1797   MyWindow->Size (aDxw, aDyw);
1798
1799   gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
1800   aPoint = Camera()->ConvertProj2View (aPoint);
1801
1802   Xv = aPoint.X();
1803   Yv = aPoint.Y();
1804 }
1805
1806 //=======================================================================
1807 //function : Convert
1808 //purpose  :
1809 //=======================================================================
1810 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
1811 {
1812   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1813
1814   Standard_Integer aDxw, aDyw;
1815   MyWindow->Size (aDxw, aDyw);
1816
1817   gp_Pnt aViewDims = Camera()->ViewDimensions();
1818   Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
1819
1820   return aValue;
1821 }
1822
1823 //=======================================================================
1824 //function : Convert
1825 //purpose  :
1826 //=======================================================================
1827 void V3d_View::Convert(const Standard_Real Xv,
1828                        const Standard_Real Yv,
1829                        Standard_Integer& Xp,
1830                        Standard_Integer& Yp) const
1831 {
1832   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1833
1834   Standard_Integer aDxw, aDyw;
1835   MyWindow->Size (aDxw, aDyw);
1836
1837   gp_Pnt aPoint (Xv, Yv, 0.0);
1838   aPoint = Camera()->ConvertView2Proj (aPoint);
1839   aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0);
1840
1841   Xp = RealToInt (aPoint.X());
1842   Yp = RealToInt (aPoint.Y());
1843 }
1844
1845 //=======================================================================
1846 //function : Convert
1847 //purpose  :
1848 //=======================================================================
1849 void V3d_View::Convert(const Standard_Integer theXp,
1850                        const Standard_Integer theYp,
1851                        Standard_Real& theX,
1852                        Standard_Real& theY,
1853                        Standard_Real& theZ) const
1854 {
1855   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1856   Standard_Integer aHeight = 0, aWidth = 0;
1857   MyWindow->Size (aWidth, aHeight);
1858
1859   const gp_Pnt anXYZ (2.0 * theXp / aWidth - 1.0,
1860                       2.0 * (aHeight - 1 - theYp) / aHeight - 1.0,
1861                       Camera()->IsZeroToOneDepth() ? 0.0 : -1.0);
1862   const gp_Pnt aResult = Camera()->UnProject (anXYZ);
1863   theX = aResult.X();
1864   theY = aResult.Y();
1865   theZ = aResult.Z();
1866 }
1867
1868 //=======================================================================
1869 //function : ConvertWithProj
1870 //purpose  :
1871 //=======================================================================
1872 void V3d_View::ConvertWithProj(const Standard_Integer theXp,
1873                                const Standard_Integer theYp,
1874                                Standard_Real& theX,
1875                                Standard_Real& theY,
1876                                Standard_Real& theZ,
1877                                Standard_Real& theDx,
1878                                Standard_Real& theDy,
1879                                Standard_Real& theDz) const
1880 {
1881   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1882   Standard_Integer aHeight = 0, aWidth = 0;
1883   MyWindow->Size (aWidth, aHeight);
1884
1885   const Standard_Real anX = 2.0 * theXp / aWidth - 1.0;
1886   const Standard_Real anY = 2.0 * (aHeight - 1 - theYp) / aHeight - 1.0;
1887   const Standard_Real  aZ = 2.0 * 0.0 - 1.0;
1888
1889   const Handle(Graphic3d_Camera)& aCamera = Camera();
1890   const gp_Pnt aResult1 = aCamera->UnProject (gp_Pnt (anX, anY, aZ));
1891   const gp_Pnt aResult2 = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
1892
1893   theX = aResult1.X();
1894   theY = aResult1.Y();
1895   theZ = aResult1.Z();
1896   Graphic3d_Vec3d aNormDir (theX - aResult2.X(),
1897                             theY - aResult2.Y(),
1898                             theZ - aResult2.Z());
1899   aNormDir.Normalize();
1900
1901   theDx = aNormDir.x();
1902   theDy = aNormDir.y();
1903   theDz = aNormDir.z();
1904 }
1905
1906 //=======================================================================
1907 //function : Convert
1908 //purpose  :
1909 //=======================================================================
1910 void V3d_View::Convert(const Standard_Real X,
1911                        const Standard_Real Y,
1912                        const Standard_Real Z,
1913                        Standard_Integer& Xp,
1914                        Standard_Integer& Yp) const
1915 {
1916   V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
1917   Standard_Integer aHeight, aWidth;
1918   MyWindow->Size (aWidth, aHeight);
1919
1920   gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z));
1921
1922   Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
1923   Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
1924 }
1925
1926 //=======================================================================
1927 //function : Project
1928 //purpose  :
1929 //=======================================================================
1930 void V3d_View::Project (const Standard_Real theX,
1931                         const Standard_Real theY,
1932                         const Standard_Real theZ,
1933                         Standard_Real& theXp,
1934                         Standard_Real& theYp) const
1935 {
1936   Standard_Real aZp;
1937   Project (theX, theY, theZ, theXp, theYp, aZp);
1938 }
1939
1940 //=======================================================================
1941 //function : Project
1942 //purpose  :
1943 //=======================================================================
1944 void V3d_View::Project (const Standard_Real theX,
1945                         const Standard_Real theY,
1946                         const Standard_Real theZ,
1947                         Standard_Real& theXp,
1948                         Standard_Real& theYp,
1949                         Standard_Real& theZp) const
1950 {
1951   Handle(Graphic3d_Camera) aCamera = Camera();
1952
1953   gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1954   Standard_Real aXSize = aViewSpaceDimensions.X();
1955   Standard_Real aYSize = aViewSpaceDimensions.Y();
1956   Standard_Real aZSize = aViewSpaceDimensions.Z();
1957
1958   gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1959
1960   // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1961   theXp = aPoint.X() * aXSize * 0.5;
1962   theYp = aPoint.Y() * aYSize * 0.5;
1963   theZp = Camera()->IsZeroToOneDepth()
1964         ? aPoint.Z() * aZSize
1965         : aPoint.Z() * aZSize * 0.5;
1966 }
1967
1968 //=======================================================================
1969 //function : BackgroundColor
1970 //purpose  :
1971 //=======================================================================
1972 void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,
1973                                Standard_Real& V1,
1974                                Standard_Real& V2,
1975                                Standard_Real& V3) const
1976 {
1977   Quantity_Color C = BackgroundColor() ;
1978   C.Values(V1,V2,V3,Type) ;
1979 }
1980
1981 //=======================================================================
1982 //function : BackgroundColor
1983 //purpose  :
1984 //=======================================================================
1985 Quantity_Color V3d_View::BackgroundColor() const
1986 {
1987   return myView->Background().Color() ;
1988 }
1989
1990 //=======================================================================
1991 //function : GradientBackgroundColors
1992 //purpose  :
1993 //=======================================================================
1994 void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const
1995 {
1996   myView->GradientBackground().Colors (theColor1, theColor2);
1997 }
1998
1999 //=======================================================================
2000 //function : GradientBackground
2001 //purpose  :
2002 //=======================================================================
2003 Aspect_GradientBackground V3d_View::GradientBackground() const
2004 {
2005   return myView->GradientBackground();
2006 }
2007
2008 //=======================================================================
2009 //function : Scale
2010 //purpose  :
2011 //=======================================================================
2012 Standard_Real V3d_View::Scale() const
2013 {
2014   return myDefaultCamera->Scale() / Camera()->Scale();
2015 }
2016
2017 //=======================================================================
2018 //function : AxialScale
2019 //purpose  :
2020 //=======================================================================
2021 void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
2022 {
2023   gp_Pnt anAxialScale = Camera()->AxialScale();
2024   Sx = anAxialScale.X();
2025   Sy = anAxialScale.Y();
2026   Sz = anAxialScale.Z();
2027 }
2028
2029 //=======================================================================
2030 //function : Size
2031 //purpose  :
2032 //=======================================================================
2033 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
2034 {
2035   gp_Pnt aViewDims = Camera()->ViewDimensions();
2036
2037   Width = aViewDims.X();
2038   Height = aViewDims.Y();
2039 }
2040
2041 //=======================================================================
2042 //function : ZSize
2043 //purpose  :
2044 //=======================================================================
2045 Standard_Real V3d_View::ZSize() const
2046 {
2047   gp_Pnt aViewDims = Camera()->ViewDimensions();
2048
2049   return aViewDims.Z();
2050 }
2051
2052 //=======================================================================
2053 //function : MinMax
2054 //purpose  :
2055 //=======================================================================
2056 Standard_Integer V3d_View::MinMax(Standard_Real& Umin,
2057                                   Standard_Real& Vmin,
2058                                   Standard_Real& Umax,
2059                                   Standard_Real& Vmax) const
2060 {
2061   Standard_Real Wmin,Wmax,U,V,W ;
2062   Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
2063   // CAL 6/11/98
2064   Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
2065
2066   if( Nstruct ) {
2067     Bnd_Box aBox = myView->MinMaxValues();
2068     aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
2069     Project (Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
2070     Project (Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
2071     Project (Xmin,Ymin,Zmax,U,V,W) ;
2072     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2073     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2074     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2075     Project (Xmax,Ymin,Zmax,U,V,W) ;
2076     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2077     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2078     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2079     Project (Xmax,Ymin,Zmin,U,V,W) ;
2080     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2081     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2082     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2083     Project (Xmax,Ymax,Zmin,U,V,W) ;
2084     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2085     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2086     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2087     Project (Xmin,Ymax,Zmax,U,V,W) ;
2088     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2089     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2090     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2091     Project (Xmin,Ymax,Zmin,U,V,W) ;
2092     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
2093     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
2094     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
2095   }
2096   return Nstruct ;
2097 }
2098
2099 //=======================================================================
2100 //function : MinMax
2101 //purpose  :
2102 //=======================================================================
2103 Standard_Integer V3d_View::MinMax(Standard_Real& Xmin,
2104                                   Standard_Real& Ymin,
2105                                   Standard_Real& Zmin,
2106                                   Standard_Real& Xmax,
2107                                   Standard_Real& Ymax,
2108                                   Standard_Real& Zmax) const
2109 {
2110   // CAL 6/11/98
2111   // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
2112   Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
2113
2114   if( Nstruct ) {
2115     Bnd_Box aBox = myView->MinMaxValues();
2116     aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
2117   }
2118   return Nstruct ;
2119 }
2120
2121 //=======================================================================
2122 //function : GravityPoint
2123 //purpose  :
2124 //=======================================================================
2125 gp_Pnt V3d_View::GravityPoint() const
2126 {
2127   Graphic3d_MapOfStructure aSetOfStructures;
2128   myView->DisplayedStructures (aSetOfStructures);
2129
2130   Standard_Boolean hasSelection = Standard_False;
2131   for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
2132        aStructIter.More(); aStructIter.Next())
2133   {
2134     if (aStructIter.Key()->IsHighlighted()
2135      && aStructIter.Key()->IsVisible())
2136     {
2137       hasSelection = Standard_True;
2138       break;
2139     }
2140   }
2141
2142   Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
2143   Standard_Integer aNbPoints = 0;
2144   gp_XYZ aResult (0.0, 0.0, 0.0);
2145   for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
2146        aStructIter.More(); aStructIter.Next())
2147   {
2148     const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2149     if (!aStruct->IsVisible()
2150       || aStruct->IsInfinite()
2151       || (hasSelection && !aStruct->IsHighlighted()))
2152     {
2153       continue;
2154     }
2155
2156     const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
2157     if (!aBox.IsValid())
2158     {
2159       continue;
2160     }
2161
2162     // skip transformation-persistent objects
2163     if (!aStruct->TransformPersistence().IsNull())
2164     {
2165       continue;
2166     }
2167
2168     // use camera projection to find gravity point
2169     Xmin = aBox.CornerMin().x();
2170     Ymin = aBox.CornerMin().y();
2171     Zmin = aBox.CornerMin().z();
2172     Xmax = aBox.CornerMax().x();
2173     Ymax = aBox.CornerMax().y();
2174     Zmax = aBox.CornerMax().z();
2175     gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
2176     {
2177       gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
2178       gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
2179       gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
2180       gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
2181     };
2182
2183     for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
2184     {
2185       const gp_Pnt& aBndPnt    = aPnts[aPntIt];
2186       const gp_Pnt  aProjected = Camera()->Project (aBndPnt);
2187       if (Abs (aProjected.X()) <= 1.0
2188        && Abs (aProjected.Y()) <= 1.0)
2189       {
2190         aResult += aBndPnt.XYZ();
2191         ++aNbPoints;
2192       }
2193     }
2194   }
2195
2196   if (aNbPoints == 0)
2197   {
2198     // fallback - just use bounding box of entire scene
2199     Bnd_Box aBox = myView->MinMaxValues();
2200     if (!aBox.IsVoid())
2201     {
2202       aBox.Get (Xmin, Ymin, Zmin,
2203                 Xmax, Ymax, Zmax);
2204       gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
2205       {
2206         gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
2207         gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
2208         gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
2209         gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
2210       };
2211
2212       for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
2213       {
2214         const gp_Pnt& aBndPnt = aPnts[aPntIt];
2215         aResult += aBndPnt.XYZ();
2216         ++aNbPoints;
2217       }
2218     }
2219   }
2220
2221   if (aNbPoints > 0)
2222   {
2223     aResult /= aNbPoints;
2224   }
2225
2226   return aResult;
2227 }
2228
2229 //=======================================================================
2230 //function : Eye
2231 //purpose  :
2232 //=======================================================================
2233 void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2234 {
2235   gp_Pnt aCameraEye = Camera()->Eye();
2236   X = aCameraEye.X();
2237   Y = aCameraEye.Y();
2238   Z = aCameraEye.Z();
2239 }
2240
2241 //=============================================================================
2242 //function : ProjReferenceAxe
2243 //purpose  :
2244 //=============================================================================
2245 void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix,
2246                                 const Standard_Integer Ypix,
2247                                 Standard_Real& XP,
2248                                 Standard_Real& YP,
2249                                 Standard_Real& ZP,
2250                                 Standard_Real& VX,
2251                                 Standard_Real& VY,
2252                                 Standard_Real& VZ) const
2253 {
2254   Standard_Real Xo,Yo,Zo;
2255
2256   Convert (Xpix, Ypix, XP, YP, ZP);
2257   if ( Type() == V3d_PERSPECTIVE ) 
2258   {
2259     FocalReferencePoint (Xo,Yo,Zo);
2260     VX = Xo - XP;
2261     VY = Yo - YP;
2262     VZ = Zo - ZP;
2263   }
2264   else 
2265   {
2266     Proj (VX,VY,VZ);
2267   }
2268 }
2269
2270 //=============================================================================
2271 //function : Depth
2272 //purpose  :
2273 //=============================================================================
2274 Standard_Real V3d_View::Depth() const
2275 {
2276   return Camera()->Distance();
2277 }
2278
2279 //=============================================================================
2280 //function : Proj
2281 //purpose  :
2282 //=============================================================================
2283 void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
2284 {
2285   gp_Dir aCameraDir = Camera()->Direction().Reversed();
2286   Dx = aCameraDir.X();
2287   Dy = aCameraDir.Y();
2288   Dz = aCameraDir.Z();
2289 }
2290
2291 //=============================================================================
2292 //function : At
2293 //purpose  :
2294 //=============================================================================
2295 void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
2296 {
2297   gp_Pnt aCameraCenter = Camera()->Center();
2298   X = aCameraCenter.X();
2299   Y = aCameraCenter.Y();
2300   Z = aCameraCenter.Z();
2301 }
2302
2303 //=============================================================================
2304 //function : Up
2305 //purpose  :
2306 //=============================================================================
2307 void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
2308 {
2309   gp_Dir aCameraUp = Camera()->Up();
2310   Vx = aCameraUp.X();
2311   Vy = aCameraUp.Y();
2312   Vz = aCameraUp.Z();
2313 }
2314
2315 //=============================================================================
2316 //function : Twist
2317 //purpose  :
2318 //=============================================================================
2319 Standard_Real V3d_View::Twist() const
2320 {
2321   gp_Vec Xaxis, Yaxis, Zaxis;
2322   const gp_Dir aReferencePlane (Camera()->Direction().Reversed());
2323   if (!screenAxis (aReferencePlane, gp::DZ(), Xaxis, Yaxis, Zaxis)
2324    && !screenAxis (aReferencePlane, gp::DY(), Xaxis, Yaxis, Zaxis)
2325    && !screenAxis (aReferencePlane, gp::DX(), Xaxis, Yaxis, Zaxis))
2326   {
2327     //
2328   }
2329
2330   // Compute Cross Vector From Up & Origin
2331   const gp_Dir aCameraUp = Camera()->Up();
2332   const gp_XYZ aP = Yaxis.XYZ().Crossed (aCameraUp.XYZ());
2333
2334   // compute Angle
2335   Standard_Real anAngle = ASin (Max (Min (aP.Modulus(), 1.0), -1.0));
2336   if (Yaxis.Dot (aCameraUp.XYZ()) < 0.0)
2337   {
2338     anAngle = M_PI - anAngle;
2339   }
2340   if (anAngle > 0.0
2341    && anAngle < M_PI)
2342   {
2343     const gp_Dir aProjDir = Camera()->Direction().Reversed();
2344     if (aP.Dot (aProjDir.XYZ()) < 0.0)
2345     {
2346       anAngle = DEUXPI - anAngle;
2347     }
2348   }
2349   return anAngle;
2350 }
2351
2352 //=============================================================================
2353 //function : ShadingModel
2354 //purpose  :
2355 //=============================================================================
2356 Graphic3d_TypeOfShadingModel V3d_View::ShadingModel() const
2357 {
2358   return myView->ShadingModel();
2359 }
2360
2361 //=============================================================================
2362 //function : TextureEnv
2363 //purpose  :
2364 //=============================================================================
2365 Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
2366 {
2367   return myView->TextureEnv();
2368 }
2369
2370 //=============================================================================
2371 //function : Visualization
2372 //purpose  :
2373 //=============================================================================
2374 V3d_TypeOfVisualization V3d_View::Visualization() const
2375 {
2376   return static_cast<V3d_TypeOfVisualization> (myView->VisualizationType());
2377 }
2378
2379 //=============================================================================
2380 //function : IfWindow
2381 //purpose  :
2382 //=============================================================================
2383 Standard_Boolean V3d_View::IfWindow() const
2384 {
2385   return myView->IsDefined();
2386 }
2387
2388 //=============================================================================
2389 //function : Type
2390 //purpose  :
2391 //=============================================================================
2392 V3d_TypeOfView V3d_View::Type() const
2393 {
2394   return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
2395 }
2396
2397 //=============================================================================
2398 //function : SetFocale
2399 //purpose  :
2400 //=============================================================================
2401 void V3d_View::SetFocale( const Standard_Real focale )
2402 {
2403   Handle(Graphic3d_Camera) aCamera = Camera();
2404
2405   if (aCamera->IsOrthographic())
2406   {
2407     return;
2408   }
2409
2410   Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0));
2411
2412   aCamera->SetFOVy (aFOVyRad * (360 / M_PI));
2413
2414   ImmediateUpdate();
2415 }
2416
2417 //=============================================================================
2418 //function : Focale
2419 //purpose  :
2420 //=============================================================================
2421 Standard_Real V3d_View::Focale() const
2422 {
2423   Handle(Graphic3d_Camera) aCamera = Camera();
2424
2425   if (aCamera->IsOrthographic())
2426   {
2427     return 0.0;
2428   }
2429
2430   return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0);
2431 }
2432
2433 //=============================================================================
2434 //function : screenAxis
2435 //purpose  :
2436 //=============================================================================
2437 Standard_Boolean V3d_View::screenAxis (const gp_Dir& theVpn, const gp_Dir& theVup,
2438                                        gp_Vec& theXaxe, gp_Vec& theYaxe, gp_Vec& theZaxe)
2439 {
2440   theXaxe = theVup.XYZ().Crossed (theVpn.XYZ());
2441   if (theXaxe.Magnitude() <= gp::Resolution())
2442   {
2443     return Standard_False;
2444   }
2445   theXaxe.Normalize();
2446
2447   theYaxe = theVpn.XYZ().Crossed (theXaxe.XYZ());
2448   if (theYaxe.Magnitude() <= gp::Resolution())
2449   {
2450     return Standard_False;
2451   }
2452   theYaxe.Normalize();
2453
2454   theZaxe = theVpn.XYZ();
2455   theZaxe.Normalize();
2456   return Standard_True;
2457 }
2458
2459 //=============================================================================
2460 //function : TrsPoint
2461 //purpose  :
2462 //=============================================================================
2463 gp_XYZ V3d_View::TrsPoint (const Graphic3d_Vertex& thePnt, const TColStd_Array2OfReal& theMat)
2464 {
2465   // CAL. S3892
2466   const Standard_Integer lr = theMat.LowerRow();
2467   const Standard_Integer ur = theMat.UpperRow();
2468   const Standard_Integer lc = theMat.LowerCol();
2469   const Standard_Integer uc = theMat.UpperCol();
2470   if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
2471   {
2472     return gp_XYZ (thePnt.X(), thePnt.Y(), thePnt.Z());
2473   }
2474
2475   Standard_Real X, Y, Z;
2476   thePnt.Coord (X,Y,Z);
2477   const Standard_Real XX = (theMat(lr,lc+3)   + X*theMat(lr,lc)   + Y*theMat(lr,lc+1)   + Z*theMat(lr,lc+2)) / theMat(lr+3,lc+3);
2478   const Standard_Real YY = (theMat(lr+1,lc+3) + X*theMat(lr+1,lc) + Y*theMat(lr+1,lc+1) + Z*theMat(lr+1,lc+2))/theMat(lr+3,lc+3);
2479   const Standard_Real ZZ = (theMat(lr+2,lc+3) + X*theMat(lr+2,lc) + Y*theMat(lr+2,lc+1) + Z*theMat(lr+2,lc+2))/theMat(lr+3,lc+3);
2480   return gp_XYZ (XX, YY, ZZ);
2481 }
2482
2483 //=======================================================================
2484 //function : Pan
2485 //purpose  :
2486 //=======================================================================
2487 void V3d_View::Pan (const Standard_Integer theDXp,
2488                     const Standard_Integer theDYp,
2489                     const Standard_Real    theZoomFactor,
2490                     const Standard_Boolean theToStart)
2491 {
2492   Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart);
2493 }
2494
2495 //=======================================================================
2496 //function : Panning
2497 //purpose  :
2498 //=======================================================================
2499 void V3d_View::Panning (const Standard_Real theDXv,
2500                         const Standard_Real theDYv,
2501                         const Standard_Real theZoomFactor,
2502                         const Standard_Boolean theToStart)
2503 {
2504   Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
2505
2506   Handle(Graphic3d_Camera) aCamera = Camera();
2507
2508   if (theToStart)
2509   {
2510     myCamStartOpDir    = aCamera->Direction();
2511     myCamStartOpEye    = aCamera->Eye();
2512     myCamStartOpCenter = aCamera->Center();
2513   }
2514
2515   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
2516
2517   gp_Pnt aViewDims = aCamera->ViewDimensions();
2518
2519   aCamera->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter);
2520   aCamera->SetDirectionFromEye (myCamStartOpDir);
2521   Translate (aCamera, -theDXv, -theDYv);
2522   Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
2523
2524   SetImmediateUpdate (wasUpdateEnabled);
2525
2526   ImmediateUpdate();
2527 }
2528
2529 //=======================================================================
2530 //function : Zoom
2531 //purpose  :
2532 //=======================================================================
2533 void V3d_View::Zoom (const Standard_Integer theXp1,
2534                      const Standard_Integer theYp1,
2535                      const Standard_Integer theXp2,
2536                      const Standard_Integer theYp2)
2537 {
2538   Standard_Integer aDx = theXp2 - theXp1;
2539   Standard_Integer aDy = theYp2 - theYp1;
2540   if (aDx != 0 || aDy != 0)
2541   {
2542     Standard_Real aCoeff = Sqrt( (Standard_Real)(aDx * aDx + aDy * aDy) ) / 100.0 + 1.0;
2543     aCoeff = (aDx > 0) ? aCoeff : 1.0 / aCoeff;
2544     SetZoom (aCoeff, Standard_True);
2545   }
2546 }
2547
2548 //=======================================================================
2549 //function : StartZoomAtPoint
2550 //purpose  :
2551 //=======================================================================
2552 void V3d_View::StartZoomAtPoint (const Standard_Integer theXp,
2553                                  const Standard_Integer theYp)
2554 {
2555   MyZoomAtPointX = theXp;
2556   MyZoomAtPointY = theYp;
2557 }
2558
2559 //=======================================================================
2560 //function : ZoomAtPoint
2561 //purpose  :
2562 //=======================================================================
2563 void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
2564                             const Standard_Integer theMouseStartY,
2565                             const Standard_Integer theMouseEndX,
2566                             const Standard_Integer theMouseEndY)
2567 {
2568   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
2569
2570   // zoom
2571   Standard_Real aDxy = Standard_Real ((theMouseEndX + theMouseEndY) - (theMouseStartX + theMouseStartY));
2572   Standard_Real aDZoom = Abs (aDxy) / 100.0 + 1.0;
2573   aDZoom = (aDxy > 0.0) ?  aDZoom : 1.0 / aDZoom;
2574
2575   V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
2576
2577   Handle(Graphic3d_Camera) aCamera = Camera();
2578
2579   Standard_Real aViewWidth  = aCamera->ViewDimensions().X();
2580   Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
2581
2582   // ensure that zoom will not be too small or too big.
2583   Standard_Real aCoef = aDZoom;
2584   if (aViewWidth < aCoef * Precision::Confusion())
2585   {
2586     aCoef = aViewWidth / Precision::Confusion();
2587   }
2588   else if (aViewWidth > aCoef * 1e12)
2589   {
2590     aCoef = aViewWidth / 1e12;
2591   }
2592   if (aViewHeight < aCoef * Precision::Confusion())
2593   {
2594     aCoef = aViewHeight / Precision::Confusion();
2595   }
2596   else if (aViewHeight > aCoef * 1e12)
2597   {
2598     aCoef = aViewHeight / 1e12;
2599   }
2600
2601   Standard_Real aZoomAtPointXv = 0.0;
2602   Standard_Real aZoomAtPointYv = 0.0;
2603   Convert (MyZoomAtPointX, MyZoomAtPointY, aZoomAtPointXv, aZoomAtPointYv);
2604
2605   Standard_Real aDxv = aZoomAtPointXv / aCoef;
2606   Standard_Real aDyv = aZoomAtPointYv / aCoef;
2607
2608   aCamera->SetScale (aCamera->Scale() / aCoef);
2609   Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
2610
2611   SetImmediateUpdate (wasUpdateEnabled);
2612
2613   ImmediateUpdate();
2614 }
2615
2616 //=============================================================================
2617 //function : AxialScale
2618 //purpose  :
2619 //=============================================================================
2620 void V3d_View::AxialScale (const Standard_Integer Dx,
2621                            const Standard_Integer Dy,
2622                            const V3d_TypeOfAxe Axis)
2623 {
2624   if( Dx != 0. || Dy != 0. ) {
2625     Standard_Real Sx, Sy, Sz;
2626     AxialScale( Sx, Sy, Sz );
2627     Standard_Real dscale = Sqrt(Dx*Dx + Dy*Dy) / 100. + 1;
2628     dscale = (Dx > 0) ?  dscale : 1./dscale;
2629     if( Axis == V3d_X ) Sx = dscale;
2630     if( Axis == V3d_Y ) Sy = dscale;
2631     if( Axis == V3d_Z ) Sz = dscale;
2632     SetAxialScale( Sx, Sy, Sz );
2633   }
2634 }
2635
2636 //=============================================================================
2637 //function : FitAll
2638 //purpose  :
2639 //=============================================================================
2640 void V3d_View::FitAll(const Standard_Real theXmin,
2641                       const Standard_Real theYmin,
2642                       const Standard_Real theXmax,
2643                       const Standard_Real theYmax)
2644 {
2645   Handle(Graphic3d_Camera) aCamera = Camera();
2646   Standard_Real anAspect = aCamera->Aspect();
2647
2648   Standard_Real aFitSizeU  = Abs (theXmax - theXmin);
2649   Standard_Real aFitSizeV  = Abs (theYmax - theYmin);
2650   Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
2651   if (aFitAspect >= anAspect)
2652   {
2653     aFitSizeV = aFitSizeU / anAspect;
2654   }
2655   else
2656   {
2657     aFitSizeU = aFitSizeV * anAspect;
2658   }
2659
2660   Translate (aCamera, (theXmin + theXmax) * 0.5, (theYmin + theYmax) * 0.5);
2661   Scale (aCamera, aFitSizeU, aFitSizeV);
2662
2663   ImmediateUpdate();
2664 }
2665
2666 //=============================================================================
2667 //function : StartRotation
2668 //purpose  :
2669 //=============================================================================
2670 void V3d_View::StartRotation(const Standard_Integer X,
2671                              const Standard_Integer Y,
2672                              const Standard_Real zRotationThreshold)
2673 {
2674   sx = X; sy = Y;
2675   Standard_Real x,y;
2676   Size(x,y);
2677   rx = Standard_Real(Convert(x));
2678   ry = Standard_Real(Convert(y));
2679   myRotateGravity = GravityPoint();
2680   Rotate (0.0, 0.0, 0.0,
2681           myRotateGravity.X(), myRotateGravity.Y(), myRotateGravity.Z(),
2682           Standard_True);
2683   myZRotation = Standard_False;
2684   if( zRotationThreshold > 0. ) {
2685     Standard_Real dx = Abs(sx - rx/2.);
2686     Standard_Real dy = Abs(sy - ry/2.);
2687     //  if( dx > rx/3. || dy > ry/3. ) myZRotation = Standard_True;
2688     Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
2689     if( dx > dd || dy > dd ) myZRotation = Standard_True;
2690   }
2691
2692 }
2693
2694 //=============================================================================
2695 //function : Rotation
2696 //purpose  :
2697 //=============================================================================
2698 void V3d_View::Rotation(const Standard_Integer X,
2699                         const Standard_Integer Y)
2700 {
2701   if( rx == 0. || ry == 0. ) {
2702     StartRotation(X,Y);
2703     return;
2704   }
2705   Standard_Real dx=0.,dy=0.,dz=0.;
2706   if( myZRotation ) {
2707     dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
2708       atan2(sx-rx/2.,ry/2.-sy);
2709   } else {
2710     dx = (Standard_Real(X) - sx) * M_PI / rx;
2711     dy = (sy - Standard_Real(Y)) * M_PI / ry;
2712   }
2713
2714   Rotate (dx, dy, dz,
2715           myRotateGravity.X(), myRotateGravity.Y(), myRotateGravity.Z(),
2716           Standard_False);
2717 }
2718
2719 //=============================================================================
2720 //function : SetComputedMode
2721 //purpose  :
2722 //=============================================================================
2723 void V3d_View::SetComputedMode (const Standard_Boolean theMode)
2724 {
2725   if (theMode)
2726   {
2727     if (myComputedMode)
2728     {
2729       myView->SetComputedMode (Standard_True);
2730     }
2731   }
2732   else
2733   {
2734     myView->SetComputedMode (Standard_False);
2735   }
2736 }
2737
2738 //=============================================================================
2739 //function : ComputedMode
2740 //purpose  :
2741 //=============================================================================
2742 Standard_Boolean V3d_View::ComputedMode() const
2743 {
2744   return myView->ComputedMode();
2745 }
2746
2747 //=============================================================================
2748 //function : SetBackFacingModel
2749 //purpose  :
2750 //=============================================================================
2751 void V3d_View::SetBackFacingModel (const Graphic3d_TypeOfBackfacingModel theModel)
2752 {
2753   myView->SetBackfacingModel (theModel);
2754   Redraw();
2755 }
2756
2757 //=============================================================================
2758 //function : BackFacingModel
2759 //purpose  :
2760 //=============================================================================
2761 Graphic3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
2762 {
2763   return myView->BackfacingModel();
2764 }
2765
2766 //=============================================================================
2767 //function : Init
2768 //purpose  :
2769 //=============================================================================
2770 void V3d_View::Init()
2771 {
2772   myComputedMode = MyViewer->ComputedMode();
2773   if (!myComputedMode || !MyViewer->DefaultComputedMode())
2774   {
2775     SetComputedMode (Standard_False);
2776   }
2777 }
2778
2779 //=============================================================================
2780 //function : Dump
2781 //purpose  :
2782 //=============================================================================
2783 Standard_Boolean V3d_View::Dump (const Standard_CString      theFile,
2784                                  const Graphic3d_BufferType& theBufferType)
2785 {
2786   Standard_Integer aWinWidth, aWinHeight;
2787   MyWindow->Size (aWinWidth, aWinHeight);
2788   Image_AlienPixMap anImage;
2789
2790   return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
2791 }
2792
2793 //=============================================================================
2794 //function : ToPixMap
2795 //purpose  :
2796 //=============================================================================
2797 Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
2798                                      const V3d_ImageDumpOptions& theParams)
2799 {
2800   Graphic3d_Vec2i aTargetSize (theParams.Width, theParams.Height);
2801   if (aTargetSize.x() != 0
2802    && aTargetSize.y() != 0)
2803   {
2804     // allocate image buffer for dumping
2805     if (theImage.IsEmpty()
2806      || theImage.SizeX() != Standard_Size(aTargetSize.x())
2807      || theImage.SizeY() != Standard_Size(aTargetSize.y()))
2808     {
2809       Image_Format aFormat = Image_Format_UNKNOWN;
2810       switch (theParams.BufferType)
2811       {
2812         case Graphic3d_BT_RGB:                 aFormat = Image_Format_RGB;   break;
2813         case Graphic3d_BT_RGBA:                aFormat = Image_Format_RGBA;  break;
2814         case Graphic3d_BT_Depth:               aFormat = Image_Format_GrayF; break;
2815         case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF;  break;
2816         case Graphic3d_BT_Red:                 aFormat = Image_Format_Gray;  break;
2817       }
2818
2819       if (!theImage.InitZero (aFormat, Standard_Size(aTargetSize.x()), Standard_Size(aTargetSize.y())))
2820       {
2821         Message::SendFail (TCollection_AsciiString ("Fail to allocate an image ") + aTargetSize.x() + "x" + aTargetSize.y() + " for view dump");
2822         return Standard_False;
2823       }
2824     }
2825   }
2826   if (theImage.IsEmpty())
2827   {
2828     Message::SendFail ("V3d_View::ToPixMap() has been called without image dimensions");
2829     return Standard_False;
2830   }
2831   aTargetSize.x() = (Standard_Integer )theImage.SizeX();
2832   aTargetSize.y() = (Standard_Integer )theImage.SizeY();
2833
2834   Handle(Standard_Transient) aFBOPtr;
2835   Handle(Standard_Transient) aPrevFBOPtr = myView->FBO();
2836   Graphic3d_Vec2i aFBOVPSize = aTargetSize;
2837
2838   bool isTiling = false;
2839   if (theParams.TileSize > 0)
2840   {
2841     if (aFBOVPSize.x() > theParams.TileSize
2842      || aFBOVPSize.y() > theParams.TileSize)
2843     {
2844       aFBOVPSize.x() = Min (aFBOVPSize.x(), theParams.TileSize);
2845       aFBOVPSize.y() = Min (aFBOVPSize.y(), theParams.TileSize);
2846       isTiling = true;
2847     }
2848   }
2849
2850   Graphic3d_Vec2i aPrevFBOVPSize;
2851   if (!aPrevFBOPtr.IsNull())
2852   {
2853     Graphic3d_Vec2i aPrevFBOSizeMax;
2854     myView->FBOGetDimensions (aPrevFBOPtr,
2855                               aPrevFBOVPSize.x(),  aPrevFBOVPSize.y(),
2856                               aPrevFBOSizeMax.x(), aPrevFBOSizeMax.y());
2857     if (aFBOVPSize.x() <= aPrevFBOSizeMax.x()
2858      && aFBOVPSize.y() <= aPrevFBOSizeMax.y())
2859     {
2860       aFBOPtr = aPrevFBOPtr;
2861     }
2862   }
2863
2864   if (aFBOPtr.IsNull())
2865   {
2866     Standard_Integer aMaxTexSizeX = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeX);
2867     Standard_Integer aMaxTexSizeY = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeY);
2868     if (theParams.TileSize > aMaxTexSizeX
2869      || theParams.TileSize > aMaxTexSizeY)
2870     {
2871       Message::SendFail (TCollection_AsciiString ("Image dump can not be performed - specified tile size (")
2872                        + theParams.TileSize + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")");
2873       return Standard_False;
2874     }
2875
2876     if (aFBOVPSize.x() > aMaxTexSizeX
2877      || aFBOVPSize.y() > aMaxTexSizeY)
2878     {
2879       if (MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_IsWorkaroundFBO))
2880       {
2881         Message::SendWarning ("Warning, workaround for Intel driver problem with empty FBO for images with big width is applied");
2882       }
2883       Message::SendInfo (TCollection_AsciiString ("Info, tiling image dump is used, image size (")
2884                        + aFBOVPSize.x() + "x" + aFBOVPSize.y() + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")");
2885       aFBOVPSize.x() = Min (aFBOVPSize.x(), aMaxTexSizeX);
2886       aFBOVPSize.y() = Min (aFBOVPSize.y(), aMaxTexSizeY);
2887       isTiling = true;
2888     }
2889
2890     // Try to create hardware accelerated buffer
2891     aFBOPtr = myView->FBOCreate (aFBOVPSize.x(), aFBOVPSize.y());
2892   }
2893   myView->SetFBO (aFBOPtr);
2894
2895   if (aFBOPtr.IsNull())
2896   {
2897     // try to use on-screen buffer
2898     Graphic3d_Vec2i aWinSize;
2899     MyWindow->Size (aWinSize.x(), aWinSize.y());
2900     if (aFBOVPSize.x() != aWinSize.x()
2901      || aFBOVPSize.y() != aWinSize.y())
2902     {
2903       isTiling = true;
2904     }
2905     aFBOVPSize = aWinSize;
2906
2907     Message::SendWarning ("Warning, on screen buffer is used for image dump - content might be invalid");
2908   }
2909
2910   // backup camera parameters
2911   Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
2912   Handle(Graphic3d_Camera) aCamera = Camera();
2913   aStoreMapping->Copy (aCamera);
2914   if (aCamera->IsStereo())
2915   {
2916     switch (theParams.StereoOptions)
2917     {
2918       case V3d_SDO_MONO:
2919       {
2920         aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
2921         break;
2922       }
2923       case V3d_SDO_LEFT_EYE:
2924       {
2925         aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
2926         break;
2927       }
2928       case V3d_SDO_RIGHT_EYE:
2929       {
2930         aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
2931         break;
2932       }
2933       case V3d_SDO_BLENDED:
2934       {
2935         break; // dump as is
2936       }
2937     }
2938   }
2939   if (theParams.ToAdjustAspect)
2940   {
2941     aCamera->SetAspect (Standard_Real(aTargetSize.x()) / Standard_Real(aTargetSize.y()));
2942   }
2943
2944   // render immediate structures into back buffer rather than front
2945   const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False);
2946
2947   Standard_Boolean isSuccess = Standard_True;
2948   if (!isTiling)
2949   {
2950     if (!aFBOPtr.IsNull())
2951     {
2952       myView->FBOChangeViewport (aFBOPtr, aTargetSize.x(), aTargetSize.y());
2953     }
2954     Redraw();
2955     isSuccess = isSuccess && myView->BufferDump (theImage, theParams.BufferType);
2956   }
2957   else
2958   {
2959     Image_PixMap aTilePixMap;
2960     aTilePixMap.SetTopDown (theImage.IsTopDown());
2961
2962     Graphic3d_Vec2i anOffset (0, 0);
2963     for (; anOffset.y() < aTargetSize.y(); anOffset.y() += aFBOVPSize.y())
2964     {
2965       anOffset.x() = 0;
2966       for (; anOffset.x() < aTargetSize.x(); anOffset.x() += aFBOVPSize.x())
2967       {
2968         Graphic3d_CameraTile aTileUncropped;
2969         aTileUncropped.Offset    = anOffset;
2970         aTileUncropped.TotalSize = aTargetSize;
2971         aTileUncropped.TileSize  = aFBOVPSize;
2972         const Graphic3d_CameraTile aTile = aTileUncropped.Cropped();
2973         if (aTile.TileSize.x() < 1
2974          || aTile.TileSize.y() < 1)
2975         {
2976           continue;
2977         }
2978
2979         const Standard_Integer aLeft   = aTile.Offset.x();
2980         Standard_Integer       aBottom = aTile.Offset.y();
2981         if (theImage.IsTopDown())
2982         {
2983           const Standard_Integer aTop = aTile.Offset.y() + aTile.TileSize.y();
2984           aBottom = aTargetSize.y() - aTop;
2985         }
2986         aTilePixMap.InitWrapper (theImage.Format(), theImage.ChangeData()
2987                                + theImage.SizeRowBytes() * aBottom + theImage.SizePixelBytes() * aLeft,
2988                                  aTile.TileSize.x(), aTile.TileSize.y(),
2989                                  theImage.SizeRowBytes());
2990
2991         if (!aFBOPtr.IsNull())
2992         {
2993           aCamera->SetTile (aTile);
2994           myView->FBOChangeViewport (aFBOPtr, aTile.TileSize.x(), aTile.TileSize.y());
2995         }
2996         else
2997         {
2998           // no API to resize viewport of on-screen buffer - render uncropped
2999           aCamera->SetTile (aTileUncropped);
3000         }
3001         Redraw();
3002         isSuccess = isSuccess && myView->BufferDump (aTilePixMap, theParams.BufferType);
3003         if (!isSuccess)
3004         {
3005           break;
3006         }
3007       }
3008       if (!isSuccess)
3009       {
3010         break;
3011       }
3012     }
3013   }
3014
3015   // restore state
3016   myView->SetImmediateModeDrawToFront (aPrevImmediateMode);
3017   aCamera->Copy (aStoreMapping);
3018   if (aFBOPtr != aPrevFBOPtr)
3019   {
3020     myView->FBORelease (aFBOPtr);
3021   }
3022   else if (!aPrevFBOPtr.IsNull())
3023   {
3024     myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSize.x(), aPrevFBOVPSize.y());
3025   }
3026   myView->SetFBO (aPrevFBOPtr);
3027   return isSuccess;
3028 }
3029
3030 //=============================================================================
3031 //function : ImmediateUpdate
3032 //purpose  :
3033 //=============================================================================
3034 void V3d_View::ImmediateUpdate() const
3035 {
3036   if (myImmediateUpdate)
3037   {
3038     Update();
3039   }
3040 }
3041
3042 //=============================================================================
3043 //function : SetImmediateUpdate
3044 //purpose  :
3045 //=============================================================================
3046 Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate)
3047 {
3048   Standard_Boolean aPreviousMode = myImmediateUpdate;
3049   myImmediateUpdate = theImmediateUpdate;
3050   return aPreviousMode;
3051 }
3052
3053 // =======================================================================
3054 // function : SetCamera
3055 // purpose  :
3056 // =======================================================================
3057 void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
3058 {
3059   myView->SetCamera (theCamera);
3060
3061   ImmediateUpdate();
3062 }
3063
3064 // =======================================================================
3065 // function : GetCamera
3066 // purpose  :
3067 // =======================================================================
3068 const Handle(Graphic3d_Camera)& V3d_View::Camera() const
3069 {
3070   return myView->Camera();
3071 }
3072
3073 // =======================================================================
3074 // function : FitMinMax
3075 // purpose  : Internal
3076 // =======================================================================
3077 Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
3078                                       const Bnd_Box& theBox,
3079                                       const Standard_Real theMargin,
3080                                       const Standard_Real theResolution,
3081                                       const Standard_Boolean theToEnlargeIfLine) const
3082 {
3083   if (!theCamera->FitMinMax (theBox, theResolution, theToEnlargeIfLine))
3084   {
3085     return Standard_False; // bounding box is out of bounds...
3086   }
3087
3088   const Standard_Real aZoomCoef = myView->ConsiderZoomPersistenceObjects();
3089   Scale (theCamera, theCamera->ViewDimensions().X() * (aZoomCoef + theMargin), theCamera->ViewDimensions().Y() * (aZoomCoef + theMargin));
3090   return Standard_True;
3091 }
3092
3093 // =======================================================================
3094 // function : Scale
3095 // purpose  : Internal
3096 // =======================================================================
3097 void V3d_View::Scale (const Handle(Graphic3d_Camera)& theCamera,
3098                       const Standard_Real theSizeXv,
3099                       const Standard_Real theSizeYv) const
3100 {
3101   Standard_Real anAspect = theCamera->Aspect();
3102   if (anAspect > 1.0)
3103   {
3104     theCamera->SetScale (Max (theSizeXv / anAspect, theSizeYv));
3105   }
3106   else
3107   {
3108     theCamera->SetScale (Max (theSizeXv, theSizeYv * anAspect));
3109   }
3110   Invalidate();
3111 }
3112
3113 // =======================================================================
3114 // function : Translate
3115 // purpose  : Internal
3116 // =======================================================================
3117 void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
3118                           const Standard_Real theDXv,
3119                           const Standard_Real theDYv) const
3120 {
3121   const gp_Pnt& aCenter = theCamera->Center();
3122   const gp_Dir& aDir = theCamera->Direction();
3123   const gp_Dir& anUp = theCamera->Up();
3124   gp_Ax3 aCameraCS (aCenter, aDir.Reversed(), aDir ^ anUp);
3125
3126   gp_Vec aCameraPanXv = gp_Vec (aCameraCS.XDirection()) * theDXv;
3127   gp_Vec aCameraPanYv = gp_Vec (aCameraCS.YDirection()) * theDYv;
3128   gp_Vec aCameraPan = aCameraPanXv + aCameraPanYv;
3129   gp_Trsf aPanTrsf;
3130   aPanTrsf.SetTranslation (aCameraPan);
3131
3132   theCamera->Transform (aPanTrsf);
3133   Invalidate();
3134 }
3135
3136 // =======================================================================
3137 // function : DiagnosticInformation
3138 // purpose  :
3139 // =======================================================================
3140 void V3d_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
3141                                       Graphic3d_DiagnosticInfo theFlags) const
3142 {
3143   myView->DiagnosticInformation (theDict, theFlags);
3144 }
3145
3146 //=======================================================================
3147 //function : StatisticInformation
3148 //purpose  :
3149 //=======================================================================
3150 void V3d_View::StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const
3151 {
3152   myView->StatisticInformation (theDict);
3153 }
3154
3155 // =======================================================================
3156 // function : StatisticInformation
3157 // purpose  :
3158 // =======================================================================
3159 TCollection_AsciiString V3d_View::StatisticInformation() const
3160 {
3161   return myView->StatisticInformation();
3162 }
3163
3164 //=============================================================================
3165 //function : RenderingParams
3166 //purpose  :
3167 //=============================================================================
3168 const Graphic3d_RenderingParams& V3d_View::RenderingParams() const
3169 {
3170   return myView->RenderingParams();
3171 }
3172
3173 //=============================================================================
3174 //function : ChangeRenderingParams
3175 //purpose  :
3176 //=============================================================================
3177 Graphic3d_RenderingParams& V3d_View::ChangeRenderingParams()
3178 {
3179   return myView->ChangeRenderingParams();
3180 }
3181
3182
3183 //=============================================================================
3184 //function : SetLightOn
3185 //purpose  :
3186 //=============================================================================
3187 void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight)
3188 {
3189   if (!myActiveLights.Contains (theLight))
3190   {
3191     myActiveLights.Append (theLight);
3192     UpdateLights();
3193   }
3194 }
3195
3196 //=============================================================================
3197 //function : SetLightOff
3198 //purpose  :
3199 //=============================================================================
3200 void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight)
3201 {
3202   if (MyViewer->IsGlobalLight (theLight))
3203     throw Standard_TypeMismatch("V3d_View::SetLightOff, the light is global");
3204   myActiveLights.Remove (theLight);
3205   UpdateLights();
3206 }
3207
3208 //=============================================================================
3209 //function : IsActiveLight
3210 //purpose  :
3211 //=============================================================================
3212 Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const
3213 {
3214   return !theLight.IsNull()
3215        && myActiveLights.Contains (theLight);
3216 }
3217
3218 //=============================================================================
3219 //function : SetLightOn
3220 //purpose  :
3221 //=============================================================================
3222 void V3d_View::SetLightOn()
3223 {
3224   for (V3d_ListOfLightIterator aDefLightIter (MyViewer->DefinedLightIterator()); aDefLightIter.More(); aDefLightIter.Next())
3225   {
3226     if (!myActiveLights.Contains (aDefLightIter.Value()))
3227     {
3228       myActiveLights.Append (aDefLightIter.Value());
3229     }
3230   }
3231   UpdateLights();
3232 }
3233
3234 //=============================================================================
3235 //function : SetLightOff
3236 //purpose  :
3237 //=============================================================================
3238 void V3d_View::SetLightOff()
3239 {
3240   for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More();)
3241   {
3242     if (!MyViewer->IsGlobalLight (anActiveLightIter.Value()))
3243     {
3244       myActiveLights.Remove (anActiveLightIter);
3245     }
3246     else
3247     {
3248       anActiveLightIter.Next();
3249     }
3250   }
3251   UpdateLights();
3252 }
3253
3254 //=============================================================================
3255 //function : IfMoreLights
3256 //purpose  :
3257 //=============================================================================
3258 Standard_Boolean V3d_View::IfMoreLights() const
3259 {
3260   return myActiveLights.Extent() < LightLimit();
3261 }
3262
3263 //=======================================================================
3264 //function : LightLimit
3265 //purpose  :
3266 //=======================================================================
3267 Standard_Integer V3d_View::LightLimit() const
3268 {
3269   return Viewer()->Driver()->InquireLightLimit();
3270 }
3271
3272 //=======================================================================
3273 //function : AddClipPlane
3274 //purpose  :
3275 //=======================================================================
3276 void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
3277 {
3278   Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
3279   if (aSeqOfPlanes.IsNull())
3280   {
3281     aSeqOfPlanes = new Graphic3d_SequenceOfHClipPlane();
3282   }
3283   else
3284   {
3285     for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
3286     {
3287       const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
3288       if (aPlane == thePlane)
3289       {
3290         // plane is already defined in view
3291         return;
3292       }
3293     }
3294   }
3295
3296   aSeqOfPlanes->Append (thePlane);
3297   SetClipPlanes (aSeqOfPlanes);
3298 }
3299
3300 //=======================================================================
3301 //function : RemoveClipPlane
3302 //purpose  :
3303 //=======================================================================
3304 void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
3305 {
3306   Handle(Graphic3d_SequenceOfHClipPlane) aSeqOfPlanes = ClipPlanes();
3307   if (aSeqOfPlanes.IsNull())
3308   {
3309     return;
3310   }
3311
3312   for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (*aSeqOfPlanes); aPlaneIt.More(); aPlaneIt.Next())
3313   {
3314     const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
3315     if (aPlane != thePlane)
3316     {
3317       continue;
3318     }
3319
3320     aSeqOfPlanes->Remove (aPlaneIt);
3321     SetClipPlanes (aSeqOfPlanes);
3322     return;
3323   }
3324 }
3325
3326 //=======================================================================
3327 //function : SetClipPlanes
3328 //purpose  :
3329 //=======================================================================
3330 void V3d_View::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
3331 {
3332   myView->SetClipPlanes (thePlanes);
3333 }
3334
3335 //=======================================================================
3336 //function : ClipPlanes
3337 //purpose  :
3338 //=======================================================================
3339 const Handle(Graphic3d_SequenceOfHClipPlane)& V3d_View::ClipPlanes() const
3340 {
3341   return myView->ClipPlanes();
3342 }
3343
3344 //=======================================================================
3345 //function : PlaneLimit
3346 //purpose  :
3347 //=======================================================================
3348 Standard_Integer V3d_View::PlaneLimit() const
3349 {
3350   return Viewer()->Driver()->InquirePlaneLimit();
3351 }
3352
3353 //=============================================================================
3354 //function : Move
3355 //purpose  :
3356 //=============================================================================
3357 void V3d_View::Move (const Standard_Real theDx,
3358                      const Standard_Real theDy,
3359                      const Standard_Real theDz,
3360                      const Standard_Boolean theStart)
3361 {
3362   Handle(Graphic3d_Camera) aCamera = Camera();
3363   if (theStart)
3364   {
3365     myCamStartOpEye = aCamera->Eye();
3366
3367     gp_Dir aReferencePlane (aCamera->Direction().Reversed());
3368     gp_Dir anUp (aCamera->Up());
3369     if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
3370     {
3371       throw V3d_BadValue ("V3d_View::Translate, alignment of Eye,At,Up");
3372     }
3373   }
3374
3375   Standard_Real XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
3376   myXscreenAxis.Coord (XX,XY,XZ);
3377   myYscreenAxis.Coord (YX,YY,YZ);
3378   myZscreenAxis.Coord (ZX,ZY,ZZ);
3379
3380   aCamera->SetEye (myCamStartOpEye);
3381
3382   aCamera->SetEye (aCamera->Eye().XYZ()
3383     + theDx * gp_Pnt (XX, XY, XZ).XYZ()
3384     + theDy * gp_Pnt (YX, YY, YZ).XYZ()
3385     + theDz * gp_Pnt (ZX, ZY, ZZ).XYZ()
3386     );
3387
3388   ImmediateUpdate();
3389 }
3390
3391 //=============================================================================
3392 //function : Move
3393 //purpose  :
3394 //=============================================================================
3395 void V3d_View::Move (const Standard_Real theLength, const Standard_Boolean theStart)
3396 {
3397   Handle(Graphic3d_Camera) aCamera = Camera();
3398   if (theStart)
3399   {
3400     myCamStartOpEye = aCamera->Eye();
3401   }
3402   aCamera->SetEye (myCamStartOpEye);
3403   aCamera->SetEye (aCamera->Eye().XYZ() + theLength * myDefaultViewAxis.XYZ());
3404
3405   ImmediateUpdate();
3406 }
3407
3408 //=============================================================================
3409 //function : Move
3410 //purpose  :
3411 //=============================================================================
3412 void V3d_View::Move (const V3d_TypeOfAxe theAxe,
3413                      const Standard_Real theLength,
3414                      const Standard_Boolean theStart)
3415 {
3416   switch (theAxe)
3417   {
3418     case V3d_X:
3419       Move (theLength,0.,0.,theStart);
3420       break;
3421     case V3d_Y:
3422       Move (0.,theLength,0.,theStart);
3423       break;
3424     case V3d_Z:
3425       Move (0.,0.,theLength,theStart);
3426       break;
3427   }
3428 }
3429
3430 //=============================================================================
3431 //function : Translate
3432 //purpose  :
3433 //=============================================================================
3434 void V3d_View::Translate (const Standard_Real theDx,
3435                           const Standard_Real theDy,
3436                           const Standard_Real theDz,
3437                           const Standard_Boolean theStart)
3438 {
3439   Handle(Graphic3d_Camera) aCamera = Camera();
3440   if (theStart)
3441   {
3442     myCamStartOpEye = aCamera->Eye();
3443     myCamStartOpCenter = aCamera->Center();
3444
3445     gp_Dir aReferencePlane (aCamera->Direction().Reversed());
3446     gp_Dir anUp (aCamera->Up());
3447     if (!screenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis))
3448     {
3449       throw V3d_BadValue ("V3d_View::Translate, alignment of Eye,At,Up");
3450     }
3451   }
3452
3453   aCamera->SetEye (myCamStartOpEye);
3454   aCamera->SetCenter (myCamStartOpCenter);
3455
3456   aCamera->SetCenter (aCamera->Center().XYZ()
3457     - theDx * myXscreenAxis.XYZ()
3458     - theDy * myYscreenAxis.XYZ()
3459     - theDz * myZscreenAxis.XYZ()
3460     );
3461
3462   aCamera->SetEye (aCamera->Eye().XYZ()
3463     - theDx * myXscreenAxis.XYZ()
3464     - theDy * myYscreenAxis.XYZ()
3465     - theDz * myZscreenAxis.XYZ()
3466     );
3467
3468   ImmediateUpdate();
3469 }
3470
3471 //=============================================================================
3472 //function : Translate
3473 //purpose  :
3474 //=============================================================================
3475 void V3d_View::Translate (const V3d_TypeOfAxe theAxe, const Standard_Real theLength,const Standard_Boolean theStart)
3476 {
3477   switch (theAxe)
3478   {
3479     case V3d_X:
3480       Translate (theLength,0.,0., theStart);
3481       break;
3482     case V3d_Y:
3483       Translate (0.,theLength,0., theStart);
3484       break;
3485     case V3d_Z:
3486       Translate (0.,0.,theLength, theStart);
3487       break;
3488   }
3489 }
3490
3491 //=======================================================================
3492 //function : Place
3493 //purpose  :
3494 //=======================================================================
3495 void V3d_View::Place (const Standard_Integer theXp,
3496                       const Standard_Integer theYp,
3497                       const Standard_Real theZoomFactor)
3498 {
3499   Standard_Integer aWinWidth  = 0;
3500   Standard_Integer aWinHeight = 0;
3501   View()->Window()->Size (aWinWidth, aWinHeight);
3502
3503   Standard_Integer aWinCXp = aWinWidth  / 2;
3504   Standard_Integer aWinCYp = aWinHeight / 2;
3505   Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale());
3506 }
3507
3508 //=======================================================================
3509 //function : Translate
3510 //purpose  :
3511 //=======================================================================
3512 void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart)
3513 {
3514   Handle(Graphic3d_Camera) aCamera = Camera();
3515   if (theStart)
3516   {
3517     myCamStartOpCenter = aCamera->Center() ;
3518   }
3519
3520   gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - myDefaultViewAxis.XYZ() * theLength);
3521   aCamera->SetCenter (aNewCenter);
3522
3523   ImmediateUpdate();
3524 }
3525
3526 //=============================================================================
3527 //function : SetGrid
3528 //purpose  :
3529 //=============================================================================
3530 void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid)
3531 {
3532   MyPlane       = aPlane;
3533   MyGrid        = aGrid;
3534
3535   Standard_Real xl, yl, zl;
3536   Standard_Real xdx, xdy, xdz;
3537   Standard_Real ydx, ydy, ydz;
3538   Standard_Real dx, dy, dz;
3539   aPlane.Location ().Coord (xl, yl, zl);
3540   aPlane.XDirection ().Coord (xdx, xdy, xdz);
3541   aPlane.YDirection ().Coord (ydx, ydy, ydz);
3542   aPlane.Direction ().Coord (dx, dy, dz);
3543
3544   Standard_Real CosAlpha = Cos (MyGrid->RotationAngle ());
3545   Standard_Real SinAlpha = Sin (MyGrid->RotationAngle ());
3546
3547   TColStd_Array2OfReal Trsf1 (1, 4, 1, 4);
3548   Trsf1 (4, 4) = 1.0;
3549   Trsf1 (4, 1) = Trsf1 (4, 2) = Trsf1 (4, 3) = 0.0;
3550   // Translation
3551   Trsf1 (1, 4) = xl,
3552   Trsf1 (2, 4) = yl,
3553   Trsf1 (3, 4) = zl;
3554   // Transformation change of marker
3555   Trsf1 (1, 1) = xdx,
3556   Trsf1 (2, 1) = xdy,
3557   Trsf1 (3, 1) = xdz,
3558   Trsf1 (1, 2) = ydx,
3559   Trsf1 (2, 2) = ydy,
3560   Trsf1 (3, 2) = ydz,
3561   Trsf1 (1, 3) = dx,
3562   Trsf1 (2, 3) = dy,
3563   Trsf1 (3, 3) = dz;
3564
3565   TColStd_Array2OfReal Trsf2 (1, 4, 1, 4);
3566   Trsf2 (4, 4) = 1.0;
3567   Trsf2 (4, 1) = Trsf2 (4, 2) = Trsf2 (4, 3) = 0.0;
3568   // Translation of the origin
3569   Trsf2 (1, 4) = -MyGrid->XOrigin (),
3570   Trsf2 (2, 4) = -MyGrid->YOrigin (),
3571   Trsf2 (3, 4) = 0.0;
3572   // Rotation Alpha around axis -Z
3573   Trsf2 (1, 1) = CosAlpha,
3574   Trsf2 (2, 1) = -SinAlpha,
3575   Trsf2 (3, 1) = 0.0,
3576   Trsf2 (1, 2) = SinAlpha,
3577   Trsf2 (2, 2) = CosAlpha,
3578   Trsf2 (3, 2) = 0.0,
3579   Trsf2 (1, 3) = 0.0,
3580   Trsf2 (2, 3) = 0.0,
3581   Trsf2 (3, 3) = 1.0;
3582
3583   Standard_Real valuetrsf;
3584   Standard_Real valueoldtrsf;
3585   Standard_Real valuenewtrsf;
3586   Standard_Integer i, j, k;
3587   // Calculation of the product of matrices
3588   for (i=1; i<=4; i++)
3589       for (j=1; j<=4; j++) {
3590     MyTrsf (i, j) = 0.0;
3591     for (k=1; k<=4; k++) {
3592         valueoldtrsf = Trsf1 (i, k);
3593         valuetrsf        = Trsf2 (k, j);
3594         valuenewtrsf = MyTrsf (i, j) + valueoldtrsf * valuetrsf;
3595         MyTrsf (i, j) = valuenewtrsf;
3596     }
3597      }
3598 }
3599
3600 //=============================================================================
3601 //function : SetGridActivity
3602 //purpose  :
3603 //=============================================================================
3604 void V3d_View::SetGridActivity (const Standard_Boolean AFlag)
3605 {
3606   if (AFlag) MyGrid->Activate ();
3607   else MyGrid->Deactivate ();
3608 }
3609
3610 //=============================================================================
3611 //function : toPolarCoords
3612 //purpose  :
3613 //=============================================================================
3614 void toPolarCoords (const Standard_Real theX, const Standard_Real theY,
3615                           Standard_Real& theR, Standard_Real& thePhi)
3616 {
3617   theR = Sqrt (theX * theX + theY * theY);
3618   thePhi = ATan2 (theY, theX);
3619 }
3620
3621 //=============================================================================
3622 //function : toCartesianCoords
3623 //purpose  :
3624 //=============================================================================
3625 void toCartesianCoords (const Standard_Real theR, const Standard_Real thePhi,
3626                               Standard_Real& theX, Standard_Real& theY)
3627 {
3628   theX = theR * Cos (thePhi);
3629   theY = theR * Sin (thePhi);
3630 }
3631
3632 //=============================================================================
3633 //function : Compute
3634 //purpose  :
3635 //=============================================================================
3636 Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex& theVertex) const
3637 {
3638   const Handle(Graphic3d_Camera)& aCamera = Camera();
3639   gp_Dir VPN = aCamera->Direction().Reversed(); // RefPlane
3640   gp_Dir GPN = MyPlane.Direction();
3641
3642   Standard_Real XPp = 0.0, YPp = 0.0;
3643   Project (theVertex.X(), theVertex.Y(), theVertex.Z(), XPp, YPp);
3644
3645   // Casw when the plane of the grid and the plane of the view
3646   // are perpendicular to MYEPSILON2 close radians
3647   #define MYEPSILON2 M_PI / 180.0 // Delta between 2 angles
3648   if (Abs (VPN.Angle (GPN) - M_PI / 2.) < MYEPSILON2)
3649   {
3650     return theVertex;
3651   }
3652
3653   const gp_XYZ aPnt0 = V3d_View::TrsPoint (Graphic3d_Vertex (0.0, 0.0, 0.0), MyTrsf);
3654
3655   // get grid axes in world space
3656   const gp_XYZ aPnt1 = V3d_View::TrsPoint (Graphic3d_Vertex (1.0, 0.0, 0.0), MyTrsf);
3657   gp_Vec aGridX (aPnt0, aPnt1);
3658   aGridX.Normalize();
3659
3660   const gp_XYZ aPnt2 = V3d_View::TrsPoint (Graphic3d_Vertex (0.0, 1.0, 0.0), MyTrsf);
3661   gp_Vec aGridY (aPnt0, aPnt2);
3662   aGridY.Normalize();
3663
3664   // project ray from camera onto grid plane
3665   const gp_Vec aProjection  = aCamera->IsOrthographic()
3666                             ? gp_Vec (aCamera->Direction())
3667                             : gp_Vec (aCamera->Eye(), gp_Pnt (theVertex.X(), theVertex.Y(), theVertex.Z())).Normalized();
3668   const gp_Vec aPointOrigin = gp_Vec (gp_Pnt (theVertex.X(), theVertex.Y(), theVertex.Z()), aPnt0);
3669   const Standard_Real aT    = aPointOrigin.Dot (MyPlane.Direction()) / aProjection.Dot (MyPlane.Direction());
3670   const gp_XYZ aPointOnPlane = gp_XYZ (theVertex.X(), theVertex.Y(), theVertex.Z()) + aProjection.XYZ() * aT;
3671
3672   if (Handle(Aspect_RectangularGrid) aRectGrid = Handle(Aspect_RectangularGrid)::DownCast (MyGrid))
3673   {
3674     // project point on plane to grid local space
3675     const gp_Vec aToPoint (aPnt0, aPointOnPlane);
3676     const Standard_Real anXSteps = Round (aGridX.Dot (aToPoint) / aRectGrid->XStep());
3677     const Standard_Real anYSteps = Round (aGridY.Dot (aToPoint) / aRectGrid->YStep());
3678
3679     // clamp point to grid
3680     const gp_Vec aResult = aGridX * anXSteps * aRectGrid->XStep()
3681                          + aGridY * anYSteps * aRectGrid->YStep()
3682                          + gp_Vec (aPnt0);
3683     return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
3684   }
3685   else if (Handle(Aspect_CircularGrid) aCircleGrid = Handle(Aspect_CircularGrid)::DownCast (MyGrid))
3686   {
3687     const Standard_Real anAlpha = M_PI / Standard_Real (aCircleGrid->DivisionNumber());
3688
3689     // project point on plane to grid local space
3690     const gp_Vec aToPoint (aPnt0, aPointOnPlane);
3691     Standard_Real aLocalX = aGridX.Dot (aToPoint);
3692     Standard_Real aLocalY = aGridY.Dot (aToPoint);
3693     Standard_Real anR = 0.0, aPhi = 0.0;
3694     toPolarCoords (aLocalX, aLocalY, anR, aPhi);
3695
3696     // clamp point to grid
3697     const Standard_Real anRSteps  = Round (anR / aCircleGrid->RadiusStep());
3698     const Standard_Real aPhiSteps = Round (aPhi / anAlpha);
3699     toCartesianCoords (anRSteps * aCircleGrid->RadiusStep(), aPhiSteps * anAlpha, aLocalX, aLocalY);
3700
3701     const gp_Vec aResult = aGridX * aLocalX + aGridY * aLocalY + gp_Vec (aPnt0);
3702     return Graphic3d_Vertex (aResult.X(), aResult.Y(), aResult.Z());
3703   }
3704   return Graphic3d_Vertex (0.0, 0.0, 0.0);
3705 }
3706
3707 //=============================================================================
3708 //function : ZBufferTriedronSetup
3709 //purpose  :
3710 //=============================================================================
3711 void V3d_View::ZBufferTriedronSetup (const Quantity_Color&  theXColor,
3712                                      const Quantity_Color&  theYColor,
3713                                      const Quantity_Color&  theZColor,
3714                                      const Standard_Real    theSizeRatio,
3715                                      const Standard_Real    theAxisDiametr,
3716                                      const Standard_Integer theNbFacettes)
3717 {
3718   const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
3719   aTrihedron->SetArrowsColor   (theXColor, theYColor, theZColor);
3720   aTrihedron->SetSizeRatio     (theSizeRatio);
3721   aTrihedron->SetNbFacets      (theNbFacettes);
3722   aTrihedron->SetArrowDiameter (theAxisDiametr);
3723 }
3724
3725 //=============================================================================
3726 //function : TriedronDisplay
3727 //purpose  :
3728 //=============================================================================
3729 void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
3730                                 const Quantity_Color& theColor,
3731                                 const Standard_Real theScale,
3732                                 const V3d_TypeOfVisualization theMode)
3733 {
3734   const Handle(V3d_Trihedron)& aTrihedron = Trihedron (true);
3735   aTrihedron->SetLabelsColor (theColor);
3736   aTrihedron->SetScale       (theScale);
3737   aTrihedron->SetPosition    (thePosition);
3738   aTrihedron->SetWireframe   (theMode == V3d_WIREFRAME);
3739
3740   aTrihedron->Display (*this);
3741 }
3742
3743 //=============================================================================
3744 //function : TriedronErase
3745 //purpose  :
3746 //=============================================================================
3747 void V3d_View::TriedronErase()
3748 {
3749   if (!myTrihedron.IsNull())
3750   {
3751     myTrihedron->Erase();
3752   }
3753 }
3754
3755 //=============================================================================
3756 //function : GetGraduatedTrihedron
3757 //purpose  :
3758 //=============================================================================
3759 const Graphic3d_GraduatedTrihedron& V3d_View::GetGraduatedTrihedron() const
3760 {
3761   return myView->GetGraduatedTrihedron();
3762 }
3763
3764 //=============================================================================
3765 //function : GraduatedTrihedronDisplay
3766 //purpose  :
3767 //=============================================================================
3768 void V3d_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
3769 {
3770   myView->GraduatedTrihedronDisplay (theTrihedronData);
3771 }
3772
3773 //=============================================================================
3774 //function : GraduatedTrihedronErase
3775 //purpose  :
3776 //=============================================================================
3777 void V3d_View::GraduatedTrihedronErase()
3778 {
3779   myView->GraduatedTrihedronErase();
3780 }
3781
3782 // =======================================================================
3783 // function : DumpJson
3784 // purpose  :
3785 // =======================================================================
3786 void V3d_View::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
3787 {
3788   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
3789
3790   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOldMouseX)
3791   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myOldMouseY)
3792   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpUp)
3793   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpDir)
3794   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpEye)
3795   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myCamStartOpCenter)
3796   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDefaultCamera.get())
3797   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myView.get())
3798   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myImmediateUpdate)
3799   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsInvalidatedImmediate)
3800   
3801   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, MyViewer)
3802   for (V3d_ListOfLight::Iterator anIterator (myActiveLights); anIterator.More(); anIterator.Next())
3803   {
3804     class Handle(Graphic3d_CLight)& anActiveLight = anIterator.Value();
3805     OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, anActiveLight)
3806   }
3807   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultViewAxis)
3808   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultViewPoint)
3809   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyWindow.get())
3810   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, sx)
3811   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, sy)
3812   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, rx)
3813   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, ry)
3814   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myRotateGravity)
3815   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myComputedMode)
3816   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, SwitchSetFront)
3817   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myZRotation)
3818   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, MyZoomAtPointX)
3819   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, MyZoomAtPointY)
3820   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myTrihedron.get())
3821   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGrid.get())
3822   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &MyPlane)
3823   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGridEchoStructure.get())
3824   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, MyGridEchoGroup.get())
3825   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myXscreenAxis)
3826   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myYscreenAxis)
3827   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myZscreenAxis)
3828   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myViewAxis)
3829   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myGravityReferencePoint)
3830   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoZFitIsOn)
3831   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoZFitScaleFactor)
3832 }