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