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