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