Back to index

salome-gui  6.5.0
OCCViewer_ViewPort3d.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "OCCViewer_ViewPort3d.h"
00024 
00025 #include "OCCViewer_VService.h"
00026 #include "OCCViewer_ViewWindow.h"
00027 #include "OCCViewer_ViewModel.h"
00028 
00029 #include <Basics_OCCTVersion.hxx>
00030 
00031 #include <SUIT_ViewManager.h>
00032 #include <SUIT_ViewModel.h>
00033 
00034 #include <QColor>
00035 #include <QFileInfo>
00036 #include <QString>
00037 #include <QRect>
00038 #include <QPaintEvent>
00039 #include <QResizeEvent>
00040 #include <QApplication>
00041 
00042 #include <Visual3d_View.hxx>
00043 #include <V3d_Viewer.hxx>
00044 #include <V3d_PerspectiveView.hxx>
00045 #include <V3d_OrthographicView.hxx>
00046 
00047 #include "utilities.h"
00048 
00049 #if defined WNT
00050 #include <WNT_Window.hxx>
00051 #else
00052 #include <Xw_Window.hxx>
00053 #endif
00054 
00055 static double rx = 0.;
00056 static double ry = 0.;
00057 static int sx = 0;
00058 static int sy = 0;
00059 static Standard_Boolean zRotation = Standard_False;
00060 
00061 //#include <Standard_Version.hxx>
00062 
00066 OCCViewer_ViewPort3d::OCCViewer_ViewPort3d( QWidget* parent, const Handle( V3d_Viewer)& viewer, V3d_TypeOfView  type )
00067   : OCCViewer_ViewPort( parent ),
00068     myScale( 1.0 ),
00069     myDegenerated( true ),
00070     myAnimate( false ),
00071     myBusy( true ),
00072     myIsAdvancedZoomingEnabled( false )
00073 {
00074   // VSR: 01/07/2010 commented to avoid SIGSEGV at SALOME exit
00075   //selectVisualId();
00076 
00077   if ( type == V3d_ORTHOGRAPHIC ) {
00078     myOrthoView = new V3d_OrthographicView( viewer );
00079     myActiveView = myOrthoView;
00080     myPerspView = 0;
00081   } else {
00082     myPerspView = new V3d_PerspectiveView( viewer );
00083     myActiveView = myPerspView;
00084   }
00085   if ( myDegenerated )
00086     activeView()->SetDegenerateModeOn();
00087   setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
00088 }
00089 
00093 OCCViewer_ViewPort3d::~OCCViewer_ViewPort3d()
00094 {
00095   Handle(V3d_View) aView = activeView();
00096   if (!aView.IsNull())
00097     aView->Remove();
00098 }
00099 
00104 /*void OCCViewer_ViewPort3d::setActive( V3d_TypeOfView type )
00105 {
00106   if ( activeView().IsNull() )
00107   return;
00108 
00109   if ( activeView()->Type() != type )
00110   {
00111   if ( type == V3d_ORTHOGRAPHIC )
00112   setView( myOrthoView );
00113   if ( type == V3d_PERSPECTIVE )
00114   setView( myPerspView );
00115   }
00116 }*/
00117 
00121 bool OCCViewer_ViewPort3d::mapView( const Handle(V3d_View)& view )
00122 {
00123   if ( !setWindow( view ) )
00124     return false;
00125 
00126   if ( !mapped( view ) ) {
00127     view->SetWindow( myWindow );
00128     if ( view != activeView() )
00129       view->View()->Deactivate();
00130   }
00131 
00132   /* create static trihedron (16551: EDF PAL 501) */
00133   OCCViewer_ViewWindow* aVW = dynamic_cast<OCCViewer_ViewWindow*>( parentWidget()->parentWidget()->parentWidget() );
00134   if ( aVW ) {
00135     OCCViewer_Viewer* aViewModel = dynamic_cast<OCCViewer_Viewer*>( aVW->getViewManager()->getViewModel() );
00136     if ( aViewModel && aViewModel->isStaticTrihedronDisplayed() ){
00137       view->ZBufferTriedronSetup();
00138       view->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
00139     }
00140   }
00141   return true;
00142 }
00143 
00144 
00145 
00149 Handle( V3d_View ) OCCViewer_ViewPort3d::setView( const Handle( V3d_View )& view )
00150 {
00151   /* map the new view */
00152   if ( view == activeView() || !mapView( view ) )
00153     return activeView();
00154 
00155   /* activate the new view*/
00156   Handle( V3d_View ) oldView = activeView();
00157   if ( !oldView.IsNull() ) {
00158     if (oldView->View()->IsDefined())
00159       oldView->View()->Deactivate();
00160     view->SetBackgroundColor( oldView->BackgroundColor() );
00161   }
00162 
00163   if ( myDegenerated )
00164     view->SetDegenerateModeOn();
00165   else
00166     view->SetDegenerateModeOff();
00167 
00168   view->View()->Activate();
00169   activeView() = view;
00170   return oldView;
00171 }
00172 
00176 Handle(V3d_View) OCCViewer_ViewPort3d::getView() const
00177 {
00178   return activeView();
00179 }
00180 
00184 Handle(V3d_Viewer) OCCViewer_ViewPort3d::getViewer() const
00185 {
00186   Handle(V3d_Viewer) viewer;
00187   if ( !activeView().IsNull() )
00188     viewer = activeView()->Viewer();
00189   return viewer;
00190 }
00191 
00197 bool OCCViewer_ViewPort3d::syncronize( const OCCViewer_ViewPort3d* ref )
00198 {
00199   OCCViewer_ViewPort3d* ref3d = (OCCViewer_ViewPort3d*)ref;
00200   Handle(V3d_View) refView = ref3d->getView();
00201   Handle(V3d_View) tgtView = getView();
00202 
00203   /* Syncronize view types */
00204   /*    if ( tgtView->Type() != refView->Type() )
00205         {
00206         setActive( refView->Type() );
00207         tgtView = getView();
00208         }*/
00209 
00210   /*  The following params are copied:
00211       - view type( ortho/persp )
00212       - position of view point
00213       - orientation of high point
00214       - position of the eye
00215       - projection vector
00216       - view center ( 2D )
00217       - view twist
00218       - view scale
00219   */
00220 
00221   /* we'll update after setting all params */
00222   tgtView->SetImmediateUpdate( Standard_False );
00223 
00224   /* perspective */
00225   if ( refView->Type() == V3d_PERSPECTIVE )
00226     tgtView->SetFocale( refView->Focale() );
00227 
00228   /* copy params */
00229   Standard_Real x, y, z;
00230   refView->At( x, y, z ); tgtView->SetAt( x, y, z );
00231   refView->Up( x, y, z ); tgtView->SetUp( x, y, z );
00232   refView->Eye( x, y, z ); tgtView->SetEye( x, y, z );
00233   refView->Proj( x, y, z ); tgtView->SetProj( x, y, z );
00234   refView->Center( x, y ); tgtView->SetCenter( x, y );
00235   tgtView->SetScale( refView->Scale() );
00236   tgtView->SetTwist( refView->Twist() );
00237 
00238   /* update */
00239   tgtView->Update();
00240   tgtView->SetImmediateUpdate( Standard_True );
00241   return true;
00242 }
00243 
00247 double OCCViewer_ViewPort3d::getZSize() const
00248 {
00249   if ( !activeView().IsNull() )
00250     return activeView()->ZSize();
00251   return 0;
00252 }
00253 
00257 void OCCViewer_ViewPort3d::setZSize( double zsize )
00258 {
00259   myActiveView->SetZSize( zsize );
00260   /*    if ( !myOrthoView.IsNull() )
00261         myOrthoView->SetZSize( zsize );
00262         if ( !myPerspView.IsNull() )
00263         myPerspView->SetZSize( zsize );*/
00264 }
00265 
00269 void OCCViewer_ViewPort3d::getAxialScale( double& xScale, double& yScale, double& zScale )
00270 {
00271   xScale = yScale = zScale = 1.;
00272 
00273   if ( !activeView().IsNull() )
00274     activeView()->AxialScale( xScale, yScale, zScale );
00275 }
00276 
00280 QColor OCCViewer_ViewPort3d::backgroundColor() const
00281 {
00282   return background().color();
00283 }
00284 
00288 void OCCViewer_ViewPort3d::setBackgroundColor( const QColor& color )
00289 {
00290   Qtx::BackgroundData bg = background();
00291   bg.setColor( color );
00292   setBackground( bg );
00293 }
00294 
00298 Qtx::BackgroundData OCCViewer_ViewPort3d::background() const
00299 {
00300   return myBackground;
00301 }
00302 
00306 void OCCViewer_ViewPort3d::setBackground( const Qtx::BackgroundData& bgData )
00307 {
00308   if ( bgData.isValid() ) {
00309     myBackground = bgData;
00310     updateBackground();
00311     emit vpChangeBackground( myBackground );
00312   }
00313 }
00314 
00315 void OCCViewer_ViewPort3d::updateBackground()
00316 {
00317   if ( activeView().IsNull() ) return;
00318   if ( !myBackground.isValid() ) return;
00319 
00320   // VSR: Important note on below code.
00321   // In OCCT (in version 6.5.2), things about the background drawing
00322   // are not straightforward and not clearly understandable:
00323   // - Horizontal gradient is drawn vertically (!), well ok, from top side to bottom one.
00324   // - Vertical gradient is drawn horizontally (!), from right side to left one (!!!).
00325   // - First and second diagonal gradients are confused.
00326   // - Image texture, once set, can not be removed (!).
00327   // - Texture image fill mode Aspect_FM_NONE is not taken into account (and means the same
00328   //   as Aspect_FM_CENTERED).
00329   // - The only way to cancel gradient background (and get back to single colored) is to
00330   //   set gradient background style to Aspect_GFM_NONE while passing two colors is also needed
00331   //   (see V3d_View::SetBgGradientColors() function).
00332   // - Also, it is impossible to draw texture image above the gradiented background (only above
00333   //   single-colored).
00334   // In OCCT 6.5.3 all above mentioned problems are fixed; so, above comment should be removed as soon
00335   // as SALOME is migrated to OCCT 6.5.3. The same concerns #ifdef statements in the below code
00336   switch ( myBackground.mode() ) {
00337   case Qtx::ColorBackground:
00338     {
00339       QColor c = myBackground.color();
00340       if ( c.isValid() ) {
00341        // Unset texture should be done here
00342        // ...
00343        Quantity_Color qCol( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
00344 #if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
00345        activeView()->SetBgGradientStyle( Aspect_GFM_NONE ); // cancel gradient background
00346        activeView()->SetBgImageStyle( Aspect_FM_NONE );     // cancel texture background
00347 #else
00348        // cancel gradient background (in OCC before v6.5.3 the only way to do this is to set it to NONE type passing arbitrary colors as parameters)
00349        activeView()->SetBgGradientColors( qCol, qCol, Aspect_GFM_NONE );
00350 #endif
00351        // then change background color
00352        activeView()->SetBackgroundColor( qCol );
00353        // update viewer
00354        activeView()->Update();
00355       }
00356       break;
00357     }
00358   case Qtx::SimpleGradientBackground:
00359     {
00360       QColor c1, c2;
00361       int type = myBackground.gradient( c1, c2 );
00362       if ( c1.isValid() && type >= OCCViewer_Viewer::HorizontalGradient && type <= OCCViewer_Viewer::LastGradient ) {
00363        // Unset texture should be done here
00364        // ...
00365        // Get colors and set-up gradiented background
00366        if ( !c2.isValid() ) c2 = c1;
00367        Quantity_Color qCol1( c1.red()/255., c1.green()/255., c1.blue()/255., Quantity_TOC_RGB );
00368        Quantity_Color qCol2( c2.red()/255., c2.green()/255., c2.blue()/255., Quantity_TOC_RGB );
00369        activeView()->SetBgImageStyle( Aspect_FM_NONE );    // cancel texture background
00370        switch ( type ) {
00371        case OCCViewer_Viewer::HorizontalGradient:
00372 #if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
00373          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
00374 #else
00375          // in OCCT before v6.5.3, to draw horizontal gradient it's necessary to use Aspect_GFM_VER type
00376          // and interchange the colors
00377          activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_VER, Standard_True );
00378 #endif
00379          break;
00380        case OCCViewer_Viewer::VerticalGradient:
00381 #if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
00382          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_VER, Standard_True );
00383 #else
00384          // in OCCT before v6.5.3, to draw vertical gradient it's necessary to use Aspect_GFM_HOR type
00385          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_HOR, Standard_True );
00386 #endif
00387          break;
00388        case OCCViewer_Viewer::Diagonal1Gradient:
00389 #if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
00390          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
00391 #else
00392          // in OCCT before v6.5.3, to draw 1st dialognal gradient it's necessary to use Aspect_GFM_DIAG2 type
00393          // and interchange the colors
00394          activeView()->SetBgGradientColors( qCol2, qCol1, Aspect_GFM_DIAG2, Standard_True );
00395 #endif
00396          break;
00397        case OCCViewer_Viewer::Diagonal2Gradient:
00398 #if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
00399          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG2, Standard_True );
00400 #else
00401          // in OCCT before v6.5.3, to draw 2nd dialognal gradient it's necessary to use Aspect_GFM_DIAG1 type
00402          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_DIAG1, Standard_True );
00403 #endif
00404          break;
00405        case OCCViewer_Viewer::Corner1Gradient:
00406          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER1, Standard_True );
00407          break;
00408        case OCCViewer_Viewer::Corner2Gradient:
00409          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER2, Standard_True );
00410          break;
00411        case OCCViewer_Viewer::Corner3Gradient:
00412          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER3, Standard_True );
00413          break;
00414        case OCCViewer_Viewer::Corner4Gradient:
00415          activeView()->SetBgGradientColors( qCol1, qCol2, Aspect_GFM_CORNER4, Standard_True );
00416          break;
00417        default:
00418          break;
00419        }
00420       }
00421       break;
00422     }
00423   case Qtx::CustomGradientBackground:
00424     {
00425       // NOT IMPLEMENTED YET
00426       break;
00427     }
00428   default:
00429     break;
00430   }
00431 #if OCC_VERSION_LARGE > 0x06050200 // available since OCCT 6.5.3
00432   // VSR: In OCCT before v6.5.3 below code can't be used because of very ugly bug - it has been impossible to
00433   // clear the background texture image as soon as it was once set to the viewer.
00434   if ( myBackground.isTextureShown() ) {
00435     QString fileName;
00436     int textureMode = myBackground.texture( fileName );
00437     QFileInfo fi( fileName );
00438     if ( !fileName.isEmpty() && fi.exists() ) {
00439       // set texture image: file name and fill mode
00440       switch ( textureMode ) {
00441       case Qtx::CenterTexture:
00442        activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_CENTERED );
00443        break;
00444       case Qtx::TileTexture:
00445        activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_TILED );
00446        break;
00447       case Qtx::StretchTexture:
00448        activeView()->SetBackgroundImage( fi.absoluteFilePath().toLatin1().constData(), Aspect_FM_STRETCH );
00449        break;
00450       default:
00451        break;
00452       }
00453       activeView()->Update();
00454     }
00455   }
00456 #endif
00457 }
00458 
00463 void OCCViewer_ViewPort3d::setAnimationMode(bool theDegenerated)
00464 {
00465   if ( !activeView().IsNull() ) {
00466     myAnimate = theDegenerated;
00467     activeView()->SetAnimationMode(true, theDegenerated);
00468   }
00469 }
00470 
00474 void OCCViewer_ViewPort3d::onUpdate()
00475 {
00476   if ( !activeView().IsNull() )
00477     activeView()->Update();
00478 }
00479 
00483 void OCCViewer_ViewPort3d::fitRect( const QRect& rect )
00484 {
00485   if ( !activeView().IsNull() ) {
00486     activeView()->WindowFit( rect.left(), rect.top(), rect.right(), rect.bottom() );
00487     emit vpTransformed( this );
00488   }
00489 }
00490 
00494 void OCCViewer_ViewPort3d::startZoomAtPoint( int x, int y )
00495 {
00496 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
00497   if ( !activeView().IsNull() && isAdvancedZoomingEnabled() )
00498     activeView()->StartZoomAtPoint( x, y );
00499 #endif
00500 }
00501 
00505 void OCCViewer_ViewPort3d::zoom( int x0, int y0, int x, int y )
00506 {
00507   if ( !activeView().IsNull() ) {
00508     // as OCCT respects a sign of only dx,
00509     // but we want both signes to be taken into account
00510     //activeView()->Zoom( x0, y0, x, y );
00511 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
00512     if ( isAdvancedZoomingEnabled() )
00513       activeView()->ZoomAtPoint( x0, y0, x, y );
00514     else
00515 #endif
00516       activeView()->Zoom( x0 + y0, 0, x + y, 0 );
00517     emit vpTransformed( this );
00518   }
00519 }
00520 
00524 void OCCViewer_ViewPort3d::setCenter( int x, int y )
00525 {
00526   if ( !activeView().IsNull() ) {
00527     activeView()->Place( x, y, myScale );
00528     emit vpTransformed( this );
00529   }
00530 }
00531 
00535 void OCCViewer_ViewPort3d::pan( int dx, int dy )
00536 {
00537   if ( !activeView().IsNull() ) {
00538     activeView()->Pan( dx, dy, 1.0 );
00539     emit vpTransformed( this );
00540   }
00541 }
00542 
00546 void OCCViewer_ViewPort3d::startRotation( int x, int y,
00547                                           int theRotationPointType,
00548                                           const gp_Pnt& theSelectedPoint )
00549 {
00550   if ( !activeView().IsNull() ) {
00551     myDegenerated = activeView()->DegenerateModeIsOn();
00552     activeView()->SetDegenerateModeOn();
00553     if (myAnimate) activeView()->SetAnimationModeOn();
00554 
00555     //double gx, gy, gz;
00556     //double gx = activeView()->gx;
00557     //activeView()->Gravity(gx,gy,gz);
00558 
00559     switch ( theRotationPointType ) {
00560     case OCCViewer_ViewWindow::GRAVITY:
00561       activeView()->StartRotation( x, y, 0.45 );
00562       break;
00563     case OCCViewer_ViewWindow::SELECTED:
00564       sx = x; sy = y;
00565 
00566       double X,Y;
00567       activeView()->Size(X,Y);
00568       rx = Standard_Real(activeView()->Convert(X));
00569       ry = Standard_Real(activeView()->Convert(Y));
00570 
00571       activeView()->Rotate( 0., 0., 0.,
00572                             theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
00573                             Standard_True );
00574 
00575       Quantity_Ratio zRotationThreshold;
00576       zRotation = Standard_False;
00577       zRotationThreshold = 0.45;
00578       if( zRotationThreshold > 0. ) {
00579         Standard_Real dx = Abs(sx - rx/2.);
00580         Standard_Real dy = Abs(sy - ry/2.);
00581         Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
00582         if( dx > dd || dy > dd ) zRotation = Standard_True;
00583       }
00584       break;
00585     default:
00586       break;
00587     }
00588     activeView()->DepthFitAll();
00589   }
00590 }
00591 
00595 void OCCViewer_ViewPort3d::rotate( int x, int y,
00596                                    int theRotationPointType,
00597                                    const gp_Pnt& theSelectedPoint )
00598 {
00599   if ( !activeView().IsNull() ) {
00600     switch ( theRotationPointType ) {
00601     case OCCViewer_ViewWindow::GRAVITY:
00602       activeView()->Rotation( x, y );
00603       break;
00604     case OCCViewer_ViewWindow::SELECTED:
00605       double dx, dy, dz;
00606       if( zRotation ) {
00607         dz = atan2(Standard_Real(x)-rx/2., ry/2.-Standard_Real(y)) -
00608           atan2(sx-rx/2.,ry/2.-sy);
00609         dx = dy = 0.;
00610       }
00611       else {
00612         dx = (Standard_Real(x) - sx) * M_PI/rx;
00613         dy = (sy - Standard_Real(y)) * M_PI/ry;
00614         dz = 0.;
00615       }
00616 
00617       activeView()->Rotate( dx, dy, dz,
00618                             theSelectedPoint.X(),theSelectedPoint.Y(), theSelectedPoint.Z(),
00619                             Standard_False );
00620       break;
00621     default:
00622       break;
00623     }
00624     emit vpTransformed( this );
00625   }
00626   //  setZSize( getZSize() );
00627 }
00628 
00632 void OCCViewer_ViewPort3d::endRotation()
00633 {
00634   if ( !activeView().IsNull() ) {
00635     if (myAnimate) activeView()->SetAnimationModeOff();
00636     if ( !myDegenerated )
00637       activeView()->SetDegenerateModeOff();
00638     activeView()->ZFitAll(1.);
00639     activeView()->SetZSize(0.);
00640     activeView()->Update();
00641     emit vpTransformed( this );
00642   }
00643 }
00644 
00648 void OCCViewer_ViewPort3d::paintEvent( QPaintEvent* e )
00649 {
00650 #ifndef WNT
00651   /* X11 : map before show doesn't work */
00652   if ( !mapped( activeView() ) )
00653     mapView( activeView() );
00654 #endif
00655   if ( !myWindow.IsNull() ) {
00656     QApplication::syncX();
00657     QRect rc = e->rect();
00658     if ( !myPaintersRedrawing )
00659       activeView()->Redraw( rc.x(), rc.y(), rc.width(), rc.height() );
00660   }
00661   OCCViewer_ViewPort::paintEvent( e );
00662   myBusy = false;
00663 }
00664 
00668 void OCCViewer_ViewPort3d::resizeEvent( QResizeEvent* e )
00669 {
00670 #ifdef WNT
00671   /* Win32 : map before first show to avoid flicker */
00672   if ( !mapped( activeView() ) )
00673     mapView( activeView() );
00674 #endif
00675   QApplication::syncX();
00676   if ( !activeView().IsNull() )
00677     activeView()->MustBeResized();
00678 }
00679 
00683 void OCCViewer_ViewPort3d::fitAll( bool keepScale, bool withZ, bool upd )
00684 {
00685   if ( activeView().IsNull() )
00686     return;
00687 
00688   if ( keepScale )
00689     myScale = activeView()->Scale();
00690 
00691   Standard_Real margin = 0.01;
00692   activeView()->FitAll( margin, withZ, upd );
00693   activeView()->SetZSize(0.);
00694   emit vpTransformed( this );
00695 }
00696 
00700 void OCCViewer_ViewPort3d::reset()
00701 {
00702   //  double zsize = getZSize();
00703   if ( !activeView().IsNull() ) {
00704     activeView()->Reset();
00705     emit vpTransformed( this );
00706   //    setZSize( zsize );
00707   }
00708 }
00709 
00713 void OCCViewer_ViewPort3d::rotateXY( double degrees )
00714 {
00715   if ( activeView().IsNull() )
00716     return;
00717 
00718   int x = width()/2, y = height()/2;
00719   double X, Y, Z;
00720   activeView()->Convert( x, y, X, Y, Z );
00721   activeView()->Rotate( 0, 0, degrees * M_PI / 180., X, Y, Z );
00722   emit vpTransformed( this );
00723 }
00724 
00728 void OCCViewer_ViewPort3d::setAxialScale( double xScale, double yScale, double zScale )
00729 {
00730   if ( activeView().IsNull() )
00731     return;
00732 
00733   activeView()->SetAxialScale( xScale, yScale, zScale );
00734   emit vpTransformed( this );
00735 }
00736 
00740 bool OCCViewer_ViewPort3d::setWindow( const Handle(V3d_View)& view )
00741 {
00742   if ( !myWindow.IsNull() )
00743     return true;
00744 
00745   if ( view.IsNull() )
00746     return false;
00747 
00748   int hwnd = (int)winId();
00749   if ( !hwnd )
00750     return false;
00751 
00752   /* set this widget as the drawing window */
00753   short lo = (short)hwnd;
00754   short hi = (short)( hwnd >> 16 );
00755 
00756   attachWindow( view, OCCViewer_VService::CreateWindow( view, (int)hi, (int)lo, Xw_WQ_SAMEQUALITY ) );
00757 
00758   myWindow = view->Window();
00759   return !myWindow.IsNull();
00760 }
00761 
00762 void OCCViewer_ViewPort3d::attachWindow( const Handle(V3d_View)& view,
00763                                          const Handle(Aspect_Window)& window)
00764 {
00765   if (!view.IsNull()) {
00766     view->SetWindow( window );
00767     updateBackground();
00768   }
00769 }
00770 
00774 Handle(V3d_View) OCCViewer_ViewPort3d::activeView() const
00775 {
00776   return myActiveView;
00777 }
00778 
00782 /*Handle(V3d_View) OCCViewer_ViewPort3d::inactiveView() const
00783   {
00784   return ( activeView() == myOrthoView ? myPerspView : myOrthoView );
00785   }*/
00786 
00790 bool OCCViewer_ViewPort3d::mapped( const Handle(V3d_View)& view ) const
00791 {
00792   return ( !view.IsNull() && view->View()->IsDefined() );
00793 }
00794 
00800 bool OCCViewer_ViewPort3d::synchronize( OCCViewer_ViewPort* view )
00801 {
00802   bool ok = false;
00803   OCCViewer_ViewPort3d* vp3d = qobject_cast<OCCViewer_ViewPort3d*>( view );
00804   if ( vp3d ) {
00805     bool blocked = blockSignals( false );
00806     Handle(V3d_View) aView3d = getView();
00807     Handle(V3d_View) aRefView3d = vp3d->getView();
00808     aView3d->SetImmediateUpdate( Standard_False );
00809     aView3d->SetViewMapping( aRefView3d->ViewMapping() );
00810     aView3d->SetViewOrientation( aRefView3d->ViewOrientation() );
00811     aView3d->ZFitAll();
00812     aView3d->SetImmediateUpdate( Standard_True );
00813     aView3d->Update();
00814     blockSignals( blocked );
00815     ok = true;
00816   }
00817   return ok;
00818 }
00819 
00820 /*
00821  * Show/Hide static triedron
00822  */
00823 void OCCViewer_ViewPort3d::updateStaticTriedronVisibility() {
00824   OCCViewer_ViewWindow* aVW = dynamic_cast<OCCViewer_ViewWindow*>( parentWidget()->parentWidget()->parentWidget() );
00825   if ( aVW ) {
00826     OCCViewer_Viewer* aViewModel = dynamic_cast<OCCViewer_Viewer*>( aVW->getViewManager()->getViewModel() );
00827     Handle(V3d_View) aView = activeView();
00828     if ( aViewModel ){
00829       if(aViewModel->isStaticTrihedronDisplayed()) {
00830        aView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.05, V3d_ZBUFFER );
00831       } else {
00832        aView->TriedronErase();
00833       }
00834       aView->Update();
00835     }
00836   }
00837 }