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