Salome HOME
refs #1458: disable chained panning on operations
[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 #if OCC_VERSION_LARGE <= 0x07000000
249   tgtView->ZFitAll();
250 #endif
251   return true;
252 }
253
254 #if OCC_VERSION_LARGE <= 0x07000000
255 /*!
256   Returns Z-size of this view. [ public ]
257 */
258 double OCCViewer_ViewPort3d::getZSize() const
259 {
260   if ( !activeView().IsNull() )
261     return activeView()->ZSize();
262   return 0;
263 }
264
265 /*!
266   Sets Z-size of this view ( for both orthographic and perspective ). [ public ]
267 */
268 void OCCViewer_ViewPort3d::setZSize( double zsize )
269 {
270   myActiveView->SetZSize( zsize );
271   /*    if ( !myOrthoView.IsNull() )
272         myOrthoView->SetZSize( zsize );
273         if ( !myPerspView.IsNull() )
274         myPerspView->SetZSize( zsize );*/
275 }
276 #endif
277
278 /*!
279   Get axial scale to the view
280 */
281 void OCCViewer_ViewPort3d::getAxialScale( double& xScale, double& yScale, double& zScale )
282 {
283   xScale = yScale = zScale = 1.;
284
285   if ( !activeView().IsNull() )
286     activeView()->AxialScale( xScale, yScale, zScale );
287 }
288
289 /*!
290   Returns the background color [ virtual public ] [ obsolete ]
291 */
292 QColor OCCViewer_ViewPort3d::backgroundColor() const
293 {
294   return background().color();
295 }
296
297 /*!
298   Sets the background color [ virtual public ] [ obsolete ]
299 */
300 void OCCViewer_ViewPort3d::setBackgroundColor( const QColor& color )
301 {
302   Qtx::BackgroundData bg = background();
303   bg.setColor( color );
304   setBackground( bg );
305 }
306
307 /*!
308   Returns the background data
309 */
310 Qtx::BackgroundData OCCViewer_ViewPort3d::background() const
311 {
312   return myBackground;
313 }
314
315 /*!
316   Sets the background data
317 */
318 void OCCViewer_ViewPort3d::setBackground( const Qtx::BackgroundData& bgData )
319 {
320   if ( bgData.isValid() ) {
321     myBackground = bgData;
322     updateBackground();
323     emit vpChangeBackground( myBackground );
324   }
325 }
326
327 void OCCViewer_ViewPort3d::updateBackground()
328 {
329   if ( activeView().IsNull() ) return;
330   if ( !myBackground.isValid() ) return;
331
332   switch ( myBackground.mode() ) {
333   case Qtx::ColorBackground:
334     {
335       QColor c = myBackground.color();
336       if ( c.isValid() ) {
337         // Unset texture should be done here
338         // ...
339         Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
340         activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
341         activeView()->SetBgImageStyle( Aspect_FM_NONE );     // cancel texture background
342         // then change background color
343         activeView()->SetBackgroundColor( qCol );
344         // update viewer
345         activeView()->Update();
346       }
347       break;
348     }
349   case Qtx::SimpleGradientBackground:
350     {
351       QColor c1, c2;
352       int type = myBackground.gradient( c1, c2 );
353       if ( c1.isValid() && type >= OCCViewer_Viewer::HorizontalGradient && type <= OCCViewer_Viewer::LastGradient ) {
354         // Unset texture should be done here
355         // ...
356         // Get colors and set-up gradiented background
357         if ( !c2.isValid() ) c2 = c1;
358         Quantity_Color qCol1( c1.red()/255., c1.green()/255., c1.blue()/255., Quantity_TOC_RGB );
359         Quantity_Color qCol2( c2.red()/255., c2.green()/255., c2.blue()/255., Quantity_TOC_RGB );
360         activeView()->SetBgImageStyle( Aspect_FM_NONE );    // cancel texture background
361         switch ( type ) {
362         case OCCViewer_Viewer::HorizontalGradient:
363           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
364           break;
365         case OCCViewer_Viewer::VerticalGradient:
366           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
367           break;
368         case OCCViewer_Viewer::Diagonal1Gradient:
369           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
370           break;
371         case OCCViewer_Viewer::Diagonal2Gradient:
372           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True );
373           break;
374         case OCCViewer_Viewer::Corner1Gradient:
375           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
376           break;
377         case OCCViewer_Viewer::Corner2Gradient:
378           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER2, Standard_True );
379           break;
380         case OCCViewer_Viewer::Corner3Gradient:
381           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER3, Standard_True );
382           break;
383         case OCCViewer_Viewer::Corner4Gradient:
384           activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER4, Standard_True );
385           break;
386         default:
387           break;
388         }
389       }
390       break;
391     }
392   case Qtx::CustomGradientBackground:
393     {
394       // NOT IMPLEMENTED YET
395       break;
396     }
397   default:
398     break;
399   }
400   if ( myBackground.isTextureShown() ) {
401     QString fileName;
402     int textureMode = myBackground.texture( fileName );
403     QFileInfo fi( fileName );
404     if ( !fileName.isEmpty() && fi.exists() ) {
405       // set texture image: file name and fill mode
406       switch ( textureMode ) {
407       case Qtx::CenterTexture:
408         activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
409         break;
410       case Qtx::TileTexture:
411         activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
412         break;
413       case Qtx::StretchTexture:
414         activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
415         break;
416       default:
417         break;
418       }
419       activeView()->Update();
420     }
421   }
422 }
423
424 /*!
425   Updates the active viewport. [ virtual public ]
426 */
427 void OCCViewer_ViewPort3d::onUpdate()
428 {
429   if ( !activeView().IsNull() )
430     activeView()->Update();
431 }
432
433 /*!
434   Called at 'window fit' transformation. [ virtual protected ]
435 */
436 void OCCViewer_ViewPort3d::fitRect( const QRect& rect )
437 {
438   if ( !activeView().IsNull() ) {
439     activeView()->WindowFit( rect.left(), rect.top(), rect.right(), rect.bottom() );
440     emit vpTransformed( this );
441   }
442 }
443
444 /*!
445   Inits 'zoom' transformation. [ protected ]
446 */
447 void OCCViewer_ViewPort3d::startZoomAtPoint( int x, int y )
448 {
449   if ( !activeView().IsNull() && isAdvancedZoomingEnabled() )
450     activeView()->StartZoomAtPoint( x, y );
451 }
452
453 /*!
454   Called at 'zoom' transformation. [ virtual protected ]
455 */
456 void OCCViewer_ViewPort3d::zoom( int x0, int y0, int x, int y )
457 {
458   if ( !activeView().IsNull() ) {
459     // as OCCT respects a sign of only dx,
460     // but we want both signes to be taken into account
461     //activeView()->Zoom( x0, y0, x, y );
462     if ( isAdvancedZoomingEnabled() )
463       activeView()->ZoomAtPoint( x0, y0, x, y );
464     else
465       activeView()->Zoom( x0 + y0, 0, x + y, 0 );
466     emit vpTransformed( this );
467   }
468 }
469
470 /*!
471   Centers the viewport. [ virtual protected ]
472 */
473 void OCCViewer_ViewPort3d::setCenter( int x, int y )
474 {
475   if ( !activeView().IsNull() ) {
476     activeView()->Place( x, y, myScale );
477     emit vpTransformed( this );
478   }
479 }
480
481 /*!
482   Called at 'pan' transformation. [ virtual protected ]
483 */
484 void OCCViewer_ViewPort3d::pan( int dx, int dy )
485 {
486   if ( !activeView().IsNull() ) {
487     activeView()->Pan( dx, dy, 1.0 );
488     emit vpTransformed( this );
489   }
490 }
491
492 /*!
493   Inits 'rotation' transformation. [ protected ]
494 */
495 void OCCViewer_ViewPort3d::startRotation( int x, int y,
496                                           int theRotationPointType,
497                                           const gp_Pnt& theSelectedPoint )
498 {
499   if ( !activeView().IsNull() ) {
500     //double gx, gy, gz;
501     //double gx = activeView()->gx;
502     //activeView()->Gravity(gx,gy,gz);
503
504     switch ( theRotationPointType ) {
505     case OCCViewer_ViewWindow::BBCENTER:
506       activeView()->StartRotation( x, y, 0.45 );
507       break;
508     case OCCViewer_ViewWindow::SELECTED:
509       sx = x; sy = y;
510
511       double X,Y;
512       activeView()->Size(X,Y);
513       rx = Standard_Real(activeView()->Convert(X));
514       ry = Standard_Real(activeView()->Convert(Y));
515
516       activeView()->Rotate( 0., 0., 0.,
517                             theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
518                             Standard_True );
519
520       Quantity_Ratio zRotationThreshold;
521       zRotation = Standard_False;
522       zRotationThreshold = 0.45;
523       if( zRotationThreshold > 0. ) {
524         Standard_Real dx = Abs(sx - rx/2.);
525         Standard_Real dy = Abs(sy - ry/2.);
526         Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
527         if( dx > dd || dy > dd ) zRotation = Standard_True;
528       }
529       break;
530     default:
531       break;
532     }
533     // VSR: 10.06.2015: next line commented out - causes ugly blinking on starting rotation with Perspective projection mode
534     //activeView()->DepthFitAll();
535   }
536 }
537
538 /*!
539   Rotates the viewport. [ protected ]
540 */
541 void OCCViewer_ViewPort3d::rotate( int x, int y,
542                                    int theRotationPointType,
543                                    const gp_Pnt& theSelectedPoint )
544 {
545   if ( !activeView().IsNull() ) {
546     switch ( theRotationPointType ) {
547     case OCCViewer_ViewWindow::BBCENTER:
548       activeView()->Rotation( x, y );
549       break;
550     case OCCViewer_ViewWindow::SELECTED:
551       double dx, dy, dz;
552       if( zRotation ) {
553         dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) -
554           atan2(sx-rx/2.,ry/2.-sy);
555         dx = dy = 0.;
556       }
557       else {
558         dx = (Standard_Real(x) - sx) * M_PI/rx;
559         dy = (sy - Standard_Real(y)) * M_PI/ry;
560         dz = 0.;
561       }
562
563       activeView()->Rotate( dx, dy, dz,
564                             theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
565                             Standard_False );
566       break;
567     default:
568       break;
569     }
570     emit vpTransformed( this );
571   }
572   //  setZSize( getZSize() );
573 }
574
575 /*!
576   Resets the viewport after 'rotation'. [ protected ]
577 */
578 void OCCViewer_ViewPort3d::endRotation()
579 {
580   if ( !activeView().IsNull() ) {
581 #if OCC_VERSION_LARGE <= 0x07000000
582     activeView()->ZFitAll( 1.0 );
583     activeView()->SetZSize( 0.0 );
584 #endif
585     activeView()->Update();
586     emit vpTransformed( this );
587   }
588 }
589
590 /*!
591   Repaints the viewport. [ virtual protected ]
592 */
593 void OCCViewer_ViewPort3d::paintEvent( QPaintEvent* e )
594 {
595 #ifndef WIN32
596   /* X11 : map before show doesn't work */
597   if ( !mapped( activeView() ) )
598     mapView( activeView() );
599 #endif
600   if ( !myWindow.IsNull() ) {
601 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
602     QApplication::syncX();
603 #endif
604     if ( !myPaintersRedrawing ) {
605 #if OCC_VERSION_MAJOR < 7
606       QRect rc = e->rect();
607       activeView()->Redraw( rc.x(), rc.y(), rc.width(), rc.height() );
608 #else
609       activeView()->Redraw();
610 #endif
611     }
612   }
613   OCCViewer_ViewPort::paintEvent( e );
614   myBusy = false;
615 }
616
617 /*!
618   Resizes the viewport. [ virtual protected ]
619 */
620 void OCCViewer_ViewPort3d::resizeEvent( QResizeEvent* e )
621 {
622 #if defined WIN32 || QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
623   /* Win32 : map before first show to avoid flicker */
624   if ( !mapped( activeView() ) )
625     mapView( activeView() );
626 #endif
627 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
628     QApplication::syncX();
629 #endif
630   QTimer::singleShot( 0, this, SLOT( repaintViewAfterMove() ) );
631   emit vpResizeEvent( e );
632 }
633
634 /*!
635   Moved the viewport
636 */
637 void OCCViewer_ViewPort3d::repaintViewAfterMove( )
638 {
639   if ( !activeView().IsNull() ){
640     activeView()->MustBeResized();
641   }
642 }
643
644 /*!
645   Fits all objects in view. [ virtual protected ]
646 */
647 void OCCViewer_ViewPort3d::fitAll( bool keepScale, bool withZ, bool upd )
648 {
649   if ( activeView().IsNull() )
650     return;
651
652   if ( keepScale )
653     myScale = activeView()->Scale();
654
655   Standard_Real margin = 0.01;
656   
657 #if OCC_VERSION_LARGE > 0x06070100
658   activeView()->FitAll( margin, upd );
659 #if OCC_VERSION_LARGE <= 0x07000000
660   if(withZ)
661     activeView()->ZFitAll();
662 #endif  
663 #else
664   activeView()->FitAll( margin, withZ, upd );
665   activeView()->SetZSize(0.);
666 #endif
667   emit vpTransformed( this );
668 }
669
670 /*!
671   Resets the view. [ virtual protected ]
672 */
673 void OCCViewer_ViewPort3d::reset()
674 {
675   //  double zsize = getZSize();
676   if ( !activeView().IsNull() ) {
677     activeView()->Reset();
678     emit vpTransformed( this );
679   //    setZSize( zsize );
680   }
681 }
682
683 /*!
684   Rotate the view in the view plane (orthogonal to the view vector)
685 */
686 void OCCViewer_ViewPort3d::rotateXY( double degrees )
687 {
688   if ( activeView().IsNull() )
689     return;
690
691   int x = width()/2, y = height()/2;
692   double X, Y, Z;
693   activeView()->Convert( x, y, X, Y, Z );
694   activeView()->Rotate( 0, 0, degrees * M_PI / 180., X, Y, Z );
695   emit vpTransformed( this );
696 }
697
698 /*!
699   Set axial scale to the view
700 */
701 void OCCViewer_ViewPort3d::setAxialScale( double xScale, double yScale, double zScale )
702 {
703   if ( activeView().IsNull() )
704     return;
705
706   activeView()->SetAxialScale( xScale, yScale, zScale );
707   emit vpTransformed( this );
708 }
709
710 /*!
711   Passed the handle of native window of the component to CASCADE view. [ private ]
712 */
713 bool OCCViewer_ViewPort3d::setWindow( const Handle(V3d_View)& view )
714 {
715   if ( !myWindow.IsNull() )
716     return true;
717
718   if ( view.IsNull() )
719     return false;
720
721   attachWindow( view, OCCViewer_VService::CreateWindow( view, winId() ) );
722
723   myWindow = view->Window();
724   return !myWindow.IsNull();
725 }
726
727 void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view,
728                                          const Handle(Aspect_Window)& window)
729 {
730   if (!view.IsNull()) {
731     view->SetWindow( window );
732     updateBackground();
733   }
734 }
735
736 /*!
737   Returns the current active view. [ private ]
738 */
739 Handle(V3d_View) OCCViewer_ViewPort3d::activeView() const
740 {
741   return myActiveView;
742 }
743
744 /*!
745   Returns the current inactive view [ private ]
746 */
747 /*Handle(V3d_View) OCCViewer_ViewPort3d::inactiveView() const
748   {
749   return ( activeView() == myOrthoView ? myPerspView : myOrthoView );
750   }*/
751
752 /*!
753   Returns 'true' if the given view is mapped to window. [ private ]
754 */
755 bool OCCViewer_ViewPort3d::mapped( const Handle(V3d_View)& view ) const
756 {
757   return ( !view.IsNull() && view->View()->IsDefined() );
758 }
759
760 /*!
761   Performs synchronization of view parameters with the specified view.
762   Returns \c true if synchronization is done successfully or \c false otherwise.
763   Default implementation does nothing (return \c false)
764 */
765 bool OCCViewer_ViewPort3d::synchronize( OCCViewer_ViewPort* view )
766 {
767   bool ok = false;
768   OCCViewer_ViewPort3d* vp3d = qobject_cast<OCCViewer_ViewPort3d*>( view );
769   if ( vp3d ) {
770     bool blocked = blockSignals( false );
771     Handle(V3d_View) aView3d = getView();
772     Handle(V3d_View) aRefView3d = vp3d->getView();
773     aView3d->SetImmediateUpdate( Standard_False );
774 #if OCC_VERSION_LARGE > 0x06070100
775     aView3d->Camera()->Copy( aRefView3d->Camera() );
776 #else
777     aView3d->SetViewMapping( aRefView3d->ViewMapping() );
778     aView3d->SetViewOrientation( aRefView3d->ViewOrientation() );
779 #endif
780 #if OCC_VERSION_LARGE <= 0x07000000
781     aView3d->ZFitAll();
782 #endif
783     aView3d->SetImmediateUpdate( Standard_True );
784     aView3d->Update();
785     blockSignals( blocked );
786     ok = true;
787   }
788   return ok;
789 }
790
791 /*
792  * Show/Hide static triedron
793  */
794 void OCCViewer_ViewPort3d::showStaticTrihedron( bool on )
795 {
796   Handle(V3d_View) aView = activeView();
797   if ( !aView ) return;
798   
799   if ( on ) {
800     aView->ZBufferTriedronSetup();
801     aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
802   } else {
803     aView->TriedronErase();
804   }
805   aView->Update();
806 }
807
808 /*
809  * Create default cursor with a specific shape
810  */
811 void OCCViewer_ViewPort3d::setDefaultCursor( Qt::CursorShape theCursorShape )
812 {
813   if ( !myCursor )
814     myCursor = new QCursor();
815
816   myCursor->setShape( theCursorShape );
817 }
818
819 /*
820  * Get default cursor with a specific shape
821  */
822 QCursor* OCCViewer_ViewPort3d::getDefaultCursor() const
823 {
824   return myCursor;
825 }
826
827 /*
828  * Set default parameters from preferences
829  */
830 void OCCViewer_ViewPort3d::setDefaultParams()
831 {
832   setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
833
834   // get ray tracing parameters from preferences
835   int aDepth = SUIT_Session::session()->resourceMgr()->integerValue( "OCCViewer", "rt_depth", 3 );
836   bool aReflection = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_reflection", true );
837   bool anAntialiasing = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_antialiasing", false );
838   bool aShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_shadow", true );
839   bool aTransparentShadow = SUIT_Session::session()->resourceMgr()->booleanValue( "OCCViewer", "rt_trans_shadow", true );
840
841   Graphic3d_RenderingParams& aParams = myActiveView->ChangeRenderingParams();
842   aParams.RaytracingDepth = aDepth;
843   aParams.IsReflectionEnabled = aReflection;
844   aParams.IsAntialiasingEnabled = anAntialiasing;
845   aParams.IsShadowEnabled = aShadow;
846   aParams.IsTransparentShadowEnabled = aTransparentShadow;
847   myActiveView->Redraw();
848 }