Salome HOME
Merge remote-tracking branch 'origin/rnv/vtk_opengl2_backend' into V8_1_BR
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewPort3d.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "OCCViewer_ViewPort3d.h"
24
25 #include "OCCViewer_VService.h"
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewModel.h"
28
29 #include <SUIT_ViewManager.h>
30 #include <SUIT_ViewModel.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33
34 #include <QColor>
35 #include <QFileInfo>
36 #include <QString>
37 #include <QRect>
38 #include <QPaintEvent>
39 #include <QResizeEvent>
40 #include <QApplication>
41 #include <QTimer>
42
43 #if OCC_VERSION_MAJOR < 7
44   #include <Visual3d_View.hxx>
45 #endif
46
47 #if OCC_VERSION_LARGE > 0x06070100
48 #include <V3d_View.hxx>
49 #else
50 #include <V3d_PerspectiveView.hxx>
51 #include <V3d_OrthographicView.hxx>
52 #endif
53
54 #include "utilities.h"
55
56 #if defined WIN32
57 #include <WNT_Window.hxx>
58 #else
59 //#include <Xw_Window.hxx>
60 #endif
61
62 static double rx = 0.;
63 static double ry = 0.;
64 static int sx = 0;
65 static int sy = 0;
66 static Standard_Boolean zRotation = Standard_False;
67
68 //#include <Standard_Version.hxx>
69
70 /*!
71   Constructor
72 */
73 OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_Viewer)& viewer, V3d_TypeOfView  type )
74   : OCCViewer_ViewPort( parent ),
75     myScale( 1.0 ),
76     myBusy( true ),
77     myIsAdvancedZoomingEnabled( false )
78 {
79   // VSR: 01/07/2010 commented to avoid SIGSEGV at SALOME exit
80   //selectVisualId();
81
82 #if OCC_VERSION_LARGE > 0x06070100
83   myActiveView = new V3d_View( viewer, type );
84 #else
85   if ( type == V3d_ORTHOGRAPHIC ) {
86     myOrthoView = new V3d_OrthographicView( viewer );
87     myActiveView = myOrthoView;
88     myPerspView = 0;
89   } else {
90     myPerspView = new V3d_PerspectiveView( viewer );
91     myActiveView = myPerspView;
92   }
93 #endif
94
95   setDefaultParams();
96
97   myCursor = NULL;
98 }
99
100 /*!
101   Destructor
102 */
103 OCCViewer_ViewPort3d::~OCCViewer_ViewPort3d()
104 {
105   if ( myCursor )
106   {
107     delete myCursor;
108     myCursor = NULL;
109   }
110
111   emit vpClosed(this);
112   Handle(V3d_View) aView = activeView();
113   if (!aView.IsNull())
114     aView->Remove();
115 }
116
117 /*!
118   Activates the desired 'type' of view in the viewer
119   ( view of 'type' is created if it doesn't exist ). [ public ]
120 */
121 /*void OCCViewer_ViewPort3d::setActive( V3d_TypeOfView type )
122 {
123   if ( activeView().IsNull() )
124   return;
125
126   if ( activeView()->Type() != type )
127   {
128   if ( type == V3d_ORTHOGRAPHIC )
129   setView( myOrthoView );
130   if ( type == V3d_PERSPECTIVE )
131   setView( myPerspView );
132   }
133 }*/
134
135 /*!
136   Maps CasCade 'view' to this viewport. [ private ]
137 */
138 bool OCCViewer_ViewPort3d::mapView( const Handle(V3d_View)& view )
139 {
140   if ( !setWindow( view ) )
141     return false;
142
143   if ( !mapped( view ) ) {
144     view->SetWindow( myWindow );
145     if ( view != activeView() )
146       view->View()->Deactivate();
147   }
148
149   emit( vpMapped(this) );
150
151   return true;
152 }
153
154
155
156 /*!
157   Sets new CASCADE view on viewport. Returns the previous active view. [ public ]
158 */
159 Handle( V3d_View ) OCCViewer_ViewPort3d::setView( const Handle( V3d_View )& view )
160 {
161   /* map the new view */
162   if ( view == activeView() || !mapView( view ) )
163     return activeView();
164
165   /* activate the new view*/
166   Handle( V3d_View ) oldView = activeView();
167   if ( !oldView.IsNull() ) {
168     if (oldView->View()->IsDefined())
169       oldView->View()->Deactivate();
170     view->SetBackgroundColor( oldView->BackgroundColor() );
171   }
172
173   view->View()->Activate();
174   activeView() = view;
175   return oldView;
176 }
177
178 /*!
179   Returns CasCade 3D view. [ public ]
180 */
181 Handle(V3d_View) OCCViewer_ViewPort3d::getView() const
182 {
183   return activeView();
184 }
185
186 /*!
187   Returns CasCade 3D viewer [ public ]
188 */
189 Handle(V3d_Viewer) OCCViewer_ViewPort3d::getViewer() const
190 {
191   Handle(V3d_Viewer) viewer;
192   if ( !activeView().IsNull() )
193     viewer = activeView()->Viewer();
194   return viewer;
195 }
196
197 /*!
198   Syncronizes visual state of this viewport with 'ref'
199   ( scale, projection, eye etc ) Returns 'true' if copied OK,
200   'false' otherwise. [ virtual public ]
201 */
202 bool OCCViewer_ViewPort3d::syncronize( const OCCViewer_ViewPort3d* ref )
203 {
204   OCCViewer_ViewPort3d* ref3d = (OCCViewer_ViewPort3d*)ref;
205   Handle(V3d_View) refView = ref3d->getView();
206   Handle(V3d_View) tgtView = getView();
207
208   /* Syncronize view types */
209   /*    if ( tgtView->Type() != refView->Type() )
210         {
211         setActive( refView->Type() );
212         tgtView = getView();
213         }*/
214
215   /*  The following params are copied:
216       - view type( ortho/persp )
217       - position of view point
218       - orientation of high point
219       - position of the eye
220       - projection vector
221       - view center ( 2D )
222       - view twist
223       - view scale
224   */
225
226   /* we'll update after setting all params */
227   tgtView->SetImmediateUpdate( Standard_False );
228
229   /* perspective */
230   if ( refView->Type() == V3d_PERSPECTIVE )
231     tgtView->SetFocale( refView->Focale() );
232
233   /* copy params */
234   Standard_Real x, y, z;
235   refView->At( x, y, z ); tgtView->SetAt( x, y, z );
236   refView->Up( x, y, z ); tgtView->SetUp( x, y, z );
237   refView->Eye( x, y, z ); tgtView->SetEye( x, y, z );
238   refView->Proj( x, y, z ); tgtView->SetProj( x, y, z );
239 #if OCC_VERSION_LARGE <= 0x06070100
240   refView->Center( x, y ); tgtView->SetCenter( x, y );
241 #endif
242   tgtView->SetScale( refView->Scale() );
243   tgtView->SetTwist( refView->Twist() );
244
245   /* update */
246   tgtView->Update();
247   tgtView->SetImmediateUpdate( Standard_True );
248   tgtView->ZFitAll();
249   return true;
250 }
251
252 /*!
253   Returns Z-size of this view. [ public ]
254 */
255 double OCCViewer_ViewPort3d::getZSize() const
256 {
257   if ( !activeView().IsNull() )
258     return activeView()->ZSize();
259   return 0;
260 }
261
262 /*!
263   Sets Z-size of this view ( for both orthographic and perspective ). [ public ]
264 */
265 void OCCViewer_ViewPort3d::setZSize( double zsize )
266 {
267   myActiveView->SetZSize( zsize );
268   /*    if ( !myOrthoView.IsNull() )
269         myOrthoView->SetZSize( zsize );
270         if ( !myPerspView.IsNull() )
271         myPerspView->SetZSize( zsize );*/
272 }
273
274 /*!
275   Get axial scale to the view
276 */
277 void OCCViewer_ViewPort3d::getAxialScale( double& xScale, double& yScale, double& zScale )
278 {
279   xScale = yScale = zScale = 1.;
280
281   if ( !activeView().IsNull() )
282     activeView()->AxialScale( xScale, yScale, zScale );
283 }
284
285 /*!
286   Returns the background color [ virtual public ] [ obsolete ]
287 */
288 QColor OCCViewer_ViewPort3d::backgroundColor() const
289 {
290   return background().color();
291 }
292
293 /*!
294   Sets the background color [ virtual public ] [ obsolete ]
295 */
296 void OCCViewer_ViewPort3d::setBackgroundColor( const QColor& color )
297 {
298   Qtx::BackgroundData bg = background();
299   bg.setColor( color );
300   setBackground( bg );
301 }
302
303 /*!
304   Returns the background data
305 */
306 Qtx::BackgroundData OCCViewer_ViewPort3d::background() const
307 {
308   return myBackground;
309 }
310
311 /*!
312   Sets the background data
313 */
314 void OCCViewer_ViewPort3d::setBackground( const Qtx::BackgroundData& bgData )
315 {
316   if ( bgData.isValid() ) {
317     myBackground = bgData;
318     updateBackground();
319     emit vpChangeBackground( myBackground );
320   }
321 }
322
323 void OCCViewer_ViewPort3d::updateBackground()
324 {
325   if ( activeView().IsNull() ) return;
326   if ( !myBackground.isValid() ) return;
327
328   switch ( myBackground.mode() ) {
329   case Qtx::ColorBackground:
330     {
331       QColor c = myBackground.color();
332       if ( c.isValid() ) {
333         // Unset texture should be done here
334         // ...
335         Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
336         activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
337         activeView()->SetBgImageStyle( Aspect_FM_NONE );     // cancel texture background
338         // then change background color
339         activeView()->SetBackgroundColor( qCol );
340         // update viewer
341         activeView()->Update();
342       }
343       break;
344     }
345   case Qtx::SimpleGradientBackground:
346     {
347       QColor c1, c2;
348       int type = myBackground.gradient( c1, c2 );
349       if ( c1.isValid() && type >= OCCViewer_Viewer::HorizontalGradient && type <= OCCViewer_Viewer::LastGradient ) {
350         // Unset texture should be done here
351         // ...
352         // Get colors and set-up gradiented background
353         if ( !c2.isValid() ) c2 = c1;
354         Quantity_Color qCol1( c1.red()/255., c1.green()/255., c1.blue()/255., Quantity_TOC_RGB );
355         Quantity_Color qCol2( c2.red()/255., c2.green()/255., c2.blue()/255., Quantity_TOC_RGB );
356         activeView()->SetBgImageStyle( Aspect_FM_NONE );    // cancel texture background
357         switch ( type ) {
358         case OCCViewer_Viewer::HorizontalGradient:
359           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
360           break;
361         case OCCViewer_Viewer::VerticalGradient:
362           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
363           break;
364         case OCCViewer_Viewer::Diagonal1Gradient:
365           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
366           break;
367         case OCCViewer_Viewer::Diagonal2Gradient:
368           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True );
369           break;
370         case OCCViewer_Viewer::Corner1Gradient:
371           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
372           break;
373         case OCCViewer_Viewer::Corner2Gradient:
374           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER2, Standard_True );
375           break;
376         case OCCViewer_Viewer::Corner3Gradient:
377           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER3, Standard_True );
378           break;
379         case OCCViewer_Viewer::Corner4Gradient:
380           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER4, Standard_True );
381           break;
382         default:
383           break;
384         }
385       }
386       break;
387     }
388   case Qtx::CustomGradientBackground:
389     {
390       // NOT IMPLEMENTED YET
391       break;
392     }
393   default:
394     break;
395   }
396   if ( myBackground.isTextureShown() ) {
397     QString fileName;
398     int textureMode = myBackground.texture( fileName );
399     QFileInfo fi( fileName );
400     if ( !fileName.isEmpty() && fi.exists() ) {
401       // set texture image: file name and fill mode
402       switch ( textureMode ) {
403       case Qtx::CenterTexture:
404         activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
405         break;
406       case Qtx::TileTexture:
407         activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
408         break;
409       case Qtx::StretchTexture:
410         activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
411         break;
412       default:
413         break;
414       }
415       activeView()->Update();
416     }
417   }
418 }
419
420 /*!
421   Updates the active viewport. [ virtual public ]
422 */
423 void OCCViewer_ViewPort3d::onUpdate()
424 {
425   if ( !activeView().IsNull() )
426     activeView()->Update();
427 }
428
429 /*!
430   Called at 'window fit' transformation. [ virtual protected ]
431 */
432 void OCCViewer_ViewPort3d::fitRect( const QRect& rect )
433 {
434   if ( !activeView().IsNull() ) {
435     activeView()->WindowFit( rect.left(), rect.top(), rect.right(), rect.bottom() );
436     emit vpTransformed( this );
437   }
438 }
439
440 /*!
441   Inits 'zoom' transformation. [ protected ]
442 */
443 void OCCViewer_ViewPort3d::startZoomAtPoint( int x, int y )
444 {
445   if ( !activeView().IsNull() && isAdvancedZoomingEnabled() )
446     activeView()->StartZoomAtPoint( x, y );
447 }
448
449 /*!
450   Called at 'zoom' transformation. [ virtual protected ]
451 */
452 void OCCViewer_ViewPort3d::zoom( int x0, int y0, int x, int y )
453 {
454   if ( !activeView().IsNull() ) {
455     // as OCCT respects a sign of only dx,
456     // but we want both signes to be taken into account
457     //activeView()->Zoom( x0, y0, x, y );
458     if ( isAdvancedZoomingEnabled() )
459       activeView()->ZoomAtPoint( x0, y0, x, y );
460     else
461       activeView()->Zoom( x0 + y0, 0, x + y, 0 );
462     emit vpTransformed( this );
463   }
464 }
465
466 /*!
467   Centers the viewport. [ virtual protected ]
468 */
469 void OCCViewer_ViewPort3d::setCenter( int x, int y )
470 {
471   if ( !activeView().IsNull() ) {
472     activeView()->Place( x, y, myScale );
473     emit vpTransformed( this );
474   }
475 }
476
477 /*!
478   Called at 'pan' transformation. [ virtual protected ]
479 */
480 void OCCViewer_ViewPort3d::pan( int dx, int dy )
481 {
482   if ( !activeView().IsNull() ) {
483     activeView()->Pan( dx, dy, 1.0 );
484     emit vpTransformed( this );
485   }
486 }
487
488 /*!
489   Inits 'rotation' transformation. [ protected ]
490 */
491 void OCCViewer_ViewPort3d::startRotation( int x, int y,
492                                           int theRotationPointType,
493                                           const gp_Pnt& theSelectedPoint )
494 {
495   if ( !activeView().IsNull() ) {
496     //double gx, gy, gz;
497     //double gx = activeView()->gx;
498     //activeView()->Gravity(gx,gy,gz);
499
500     switch ( theRotationPointType ) {
501     case OCCViewer_ViewWindow::BBCENTER:
502       activeView()->StartRotation( x, y, 0.45 );
503       break;
504     case OCCViewer_ViewWindow::SELECTED:
505       sx = x; sy = y;
506
507       double X,Y;
508       activeView()->Size(X,Y);
509       rx = Standard_Real(activeView()->Convert(X));
510       ry = Standard_Real(activeView()->Convert(Y));
511
512       activeView()->Rotate( 0., 0., 0.,
513                             theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
514                             Standard_True );
515
516       Quantity_Ratio zRotationThreshold;
517       zRotation = Standard_False;
518       zRotationThreshold = 0.45;
519       if( zRotationThreshold > 0. ) {
520         Standard_Real dx = Abs(sx - rx/2.);
521         Standard_Real dy = Abs(sy - ry/2.);
522         Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
523         if( dx > dd || dy > dd ) zRotation = Standard_True;
524       }
525       break;
526     default:
527       break;
528     }
529     // VSR: 10.06.2015: next line commented out - causes ugly blinking on starting rotation with Perspective projection mode
530     //activeView()->DepthFitAll();
531   }
532 }
533
534 /*!
535   Rotates the viewport. [ protected ]
536 */
537 void OCCViewer_ViewPort3d::rotate( int x, int y,
538                                    int theRotationPointType,
539                                    const gp_Pnt& theSelectedPoint )
540 {
541   if ( !activeView().IsNull() ) {
542     switch ( theRotationPointType ) {
543     case OCCViewer_ViewWindow::BBCENTER:
544       activeView()->Rotation( x, y );
545       break;
546     case OCCViewer_ViewWindow::SELECTED:
547       double dx, dy, dz;
548       if( zRotation ) {
549         dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) -
550           atan2(sx-rx/2.,ry/2.-sy);
551         dx = dy = 0.;
552       }
553       else {
554         dx = (Standard_Real(x) - sx) * M_PI/rx;
555         dy = (sy - Standard_Real(y)) * M_PI/ry;
556         dz = 0.;
557       }
558
559       activeView()->Rotate( dx, dy, dz,
560                             theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
561                             Standard_False );
562       break;
563     default:
564       break;
565     }
566     emit vpTransformed( this );
567   }
568   //  setZSize( getZSize() );
569 }
570
571 /*!
572   Resets the viewport after 'rotation'. [ protected ]
573 */
574 void OCCViewer_ViewPort3d::endRotation()
575 {
576   if ( !activeView().IsNull() ) {
577     activeView()->ZFitAll( 1.0 );
578 #if OCC_VERSION_LARGE <= 0x06070100
579     activeView()->SetZSize( 0.0 );
580 #endif
581     activeView()->Update();
582     emit vpTransformed( this );
583   }
584 }
585
586 /*!
587   Repaints the viewport. [ virtual protected ]
588 */
589 void OCCViewer_ViewPort3d::paintEvent( QPaintEvent* e )
590 {
591 #ifndef WIN32
592   /* X11 : map before show doesn't work */
593   if ( !mapped( activeView() ) )
594     mapView( activeView() );
595 #endif
596   if ( !myWindow.IsNull() ) {
597 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
598     QApplication::syncX();
599 #endif
600     if ( !myPaintersRedrawing ) {
601 #if OCC_VERSION_MAJOR < 7
602       QRect rc = e->rect();
603       activeView()->Redraw( rc.x(), rc.y(), rc.width(), rc.height() );
604 #else
605       activeView()->Redraw();
606 #endif
607     }
608   }
609   OCCViewer_ViewPort::paintEvent( e );
610   myBusy = false;
611 }
612
613 /*!
614   Resizes the viewport. [ virtual protected ]
615 */
616 void OCCViewer_ViewPort3d::resizeEvent( QResizeEvent* e )
617 {
618 #if defined WIN32 || QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
619   /* Win32 : map before first show to avoid flicker */
620   if ( !mapped( activeView() ) )
621     mapView( activeView() );
622 #endif
623 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
624     QApplication::syncX();
625 #endif
626   QTimer::singleShot( 0, this, SLOT( repaintViewAfterMove() ) );
627 }
628
629 /*!
630   Moved the viewport
631 */
632 void OCCViewer_ViewPort3d::repaintViewAfterMove( )
633 {
634   if ( !activeView().IsNull() ){
635     activeView()->MustBeResized();
636   }
637 }
638
639 /*!
640   Fits all objects in view. [ virtual protected ]
641 */
642 void OCCViewer_ViewPort3d::fitAll( bool keepScale, bool withZ, bool upd )
643 {
644   if ( activeView().IsNull() )
645     return;
646
647   if ( keepScale )
648     myScale = activeView()->Scale();
649
650   Standard_Real margin = 0.01;
651   
652 #if OCC_VERSION_LARGE > 0x06070100
653   activeView()->FitAll( margin, upd );
654   if(withZ)
655     activeView()->ZFitAll();
656 #else 
657   activeView()->FitAll( margin, withZ, upd );
658 #endif
659   activeView()->SetZSize(0.);
660   emit vpTransformed( this );
661 }
662
663 /*!
664   Resets the view. [ virtual protected ]
665 */
666 void OCCViewer_ViewPort3d::reset()
667 {
668   //  double zsize = getZSize();
669   if ( !activeView().IsNull() ) {
670     activeView()->Reset();
671     emit vpTransformed( this );
672   //    setZSize( zsize );
673   }
674 }
675
676 /*!
677   Rotate the view in the view plane (orthogonal to the view vector)
678 */
679 void OCCViewer_ViewPort3d::rotateXY( double degrees )
680 {
681   if ( activeView().IsNull() )
682     return;
683
684   int x = width()/2, y = height()/2;
685   double X, Y, Z;
686   activeView()->Convert( x, y, X, Y, Z );
687   activeView()->Rotate( 0, 0, degrees * M_PI / 180., X, Y, Z );
688   emit vpTransformed( this );
689 }
690
691 /*!
692   Set axial scale to the view
693 */
694 void OCCViewer_ViewPort3d::setAxialScale( double xScale, double yScale, double zScale )
695 {
696   if ( activeView().IsNull() )
697     return;
698
699   activeView()->SetAxialScale( xScale, yScale, zScale );
700   emit vpTransformed( this );
701 }
702
703 /*!
704   Passed the handle of native window of the component to CASCADE view. [ private ]
705 */
706 bool OCCViewer_ViewPort3d::setWindow( const Handle(V3d_View)& view )
707 {
708   if ( !myWindow.IsNull() )
709     return true;
710
711   if ( view.IsNull() )
712     return false;
713
714   attachWindow( view, OCCViewer_VService::CreateWindow( view, winId() ) );
715
716   myWindow = view->Window();
717   return !myWindow.IsNull();
718 }
719
720 void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view,
721                                          const Handle(Aspect_Window)& window)
722 {
723   if (!view.IsNull()) {
724     view->SetWindow( window );
725     updateBackground();
726   }
727 }
728
729 /*!
730   Returns the current active view. [ private ]
731 */
732 Handle(V3d_View) OCCViewer_ViewPort3d::activeView() const
733 {
734   return myActiveView;
735 }
736
737 /*!
738   Returns the current inactive view [ private ]
739 */
740 /*Handle(V3d_View) OCCViewer_ViewPort3d::inactiveView() const
741   {
742   return ( activeView() == myOrthoView ? myPerspView : myOrthoView );
743   }*/
744
745 /*!
746   Returns 'true' if the given view is mapped to window. [ private ]
747 */
748 bool OCCViewer_ViewPort3d::mapped( const Handle(V3d_View)& view ) const
749 {
750   return ( !view.IsNull() && view->View()->IsDefined() );
751 }
752
753 /*!
754   Performs synchronization of view parameters with the specified view.
755   Returns \c true if synchronization is done successfully or \c false otherwise.
756   Default implementation does nothing (return \c false)
757 */
758 bool OCCViewer_ViewPort3d::synchronize( OCCViewer_ViewPort* view )
759 {
760   bool ok = false;
761   OCCViewer_ViewPort3d* vp3d = qobject_cast<OCCViewer_ViewPort3d*>( view );
762   if ( vp3d ) {
763     bool blocked = blockSignals( false );
764     Handle(V3d_View) aView3d = getView();
765     Handle(V3d_View) aRefView3d = vp3d->getView();
766     aView3d->SetImmediateUpdate( Standard_False );
767 #if OCC_VERSION_LARGE > 0x06070100
768     aView3d->Camera()->Copy( aRefView3d->Camera() );
769 #else
770     aView3d->SetViewMapping( aRefView3d->ViewMapping() );
771     aView3d->SetViewOrientation( aRefView3d->ViewOrientation() );
772 #endif
773     aView3d->ZFitAll();
774     aView3d->SetImmediateUpdate( Standard_True );
775     aView3d->Update();
776     blockSignals( blocked );
777     ok = true;
778   }
779   return ok;
780 }
781
782 /*
783  * Show/Hide static triedron
784  */
785 void OCCViewer_ViewPort3d::showStaticTrihedron( bool on )
786 {
787   Handle(V3d_View) aView = activeView();
788   if ( !aView ) return;
789   
790   if ( on ) {
791     aView->ZBufferTriedronSetup();
792     aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
793   } else {
794     aView->TriedronErase();
795   }
796   aView->Update();
797 }
798
799 /*
800  * Create default cursor with a specific shape
801  */
802 void OCCViewer_ViewPort3d::setDefaultCursor( Qt::CursorShape theCursorShape )
803 {
804   if ( !myCursor )
805     myCursor = new QCursor();
806
807   myCursor->setShape( theCursorShape );
808 }
809
810 /*
811  * Get default cursor with a specific shape
812  */
813 QCursor* OCCViewer_ViewPort3d::getDefaultCursor() const
814 {
815   return myCursor;
816 }
817
818 /*
819  * Set default parameters from preferences
820  */
821 void OCCViewer_ViewPort3d::setDefaultParams()
822 {
823   setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
824
825   // get ray tracing parameters from preferences
826   int aDepth = SUIT_Session::session()->resourceMgr()->integerValue( "OCCViewer", "rt_depth", 3 );
827   bool aReflection = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_reflection", true );
828   bool anAntialiasing = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_antialiasing", false );
829   bool aShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_shadow", true );
830   bool aTransparentShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_trans_shadow", true );
831
832   Graphic3d_RenderingParams& aParams = myActiveView->ChangeRenderingParams();
833   aParams.RaytracingDepth = aDepth;
834   aParams.IsReflectionEnabled = aReflection;
835   aParams.IsAntialiasingEnabled = anAntialiasing;
836   aParams.IsShadowEnabled = aShadow;
837   aParams.IsTransparentShadowEnabled = aTransparentShadow;
838   myActiveView->Redraw();
839 }