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