Back to index

salome-gui  6.5.0
OCCViewer_ViewWindow.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 // File   : OCCViewer_ViewWindow.cxx
00024 // Author :
00025 
00026 #include "OCCViewer_ViewWindow.h"
00027 #include "OCCViewer_ViewModel.h"
00028 #include "OCCViewer_ViewPort3d.h"
00029 #include "OCCViewer_ViewManager.h"
00030 #include "OCCViewer_ViewSketcher.h"
00031 #include "OCCViewer_CreateRestoreViewDlg.h"
00032 #include "OCCViewer_ClippingDlg.h"
00033 #include "OCCViewer_SetRotationPointDlg.h"
00034 #include "OCCViewer_AxialScaleDlg.h"
00035 #include "OCCViewer_CubeAxesDlg.h"
00036 
00037 #include <Basics_OCCTVersion.hxx>
00038 
00039 #include <SUIT_Desktop.h>
00040 #include <SUIT_Session.h>
00041 #include <SUIT_ViewManager.h>
00042 #include <SUIT_Tools.h>
00043 #include <SUIT_ResourceMgr.h>
00044 #include <SUIT_MessageBox.h>
00045 #include <SUIT_Application.h>
00046 
00047 #include <QtxActionToolMgr.h>
00048 #include <QtxMultiAction.h>
00049 #include <QtxRubberBand.h>
00050 
00051 #include <OpenGLUtils_FrameBuffer.h>
00052 
00053 #include <QPainter>
00054 #include <QTime>
00055 #include <QImage>
00056 #include <QKeyEvent>
00057 #include <QMouseEvent>
00058 #include <QApplication>
00059 #include <QMenu>
00060 
00061 #include <AIS_ListOfInteractive.hxx>
00062 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00063 #include <AIS_Shape.hxx>
00064 
00065 #include <BRep_Tool.hxx>
00066 #include <BRepBndLib.hxx>
00067 #include <TopoDS.hxx>
00068 
00069 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
00070 #include <Graphic3d_MapOfStructure.hxx>
00071 #include <Graphic3d_Structure.hxx>
00072 #include <Graphic3d_ExportFormat.hxx>
00073 
00074 #include <Visual3d_View.hxx>
00075 #include <V3d_Plane.hxx>
00076 #include <V3d_Light.hxx>
00077 
00078 #include <gp_Dir.hxx>
00079 #include <gp_Pln.hxx>
00080 #include <TColgp_Array1OfPnt2d.hxx>
00081 
00082 #include <Standard_Version.hxx>
00083 
00084 #include "utilities.h"
00085 
00086 // // OpenCV includes
00087 // #include <cv.h>
00088 // #include <highgui.h>
00089 
00090 static QEvent* l_mbPressEvent = 0;
00091 
00092 #ifdef WIN32
00093 # include <QWindowsStyle>
00094 #endif
00095 
00096 #include <GL/gl.h>
00097 
00098 const char* imageZoomCursor[] = {
00099 "32 32 3 1",
00100 ". c None",
00101 "a c #000000",
00102 "# c #ffffff",
00103 "................................",
00104 "................................",
00105 ".#######........................",
00106 "..aaaaaaa.......................",
00107 "................................",
00108 ".............#####..............",
00109 "...........##.aaaa##............",
00110 "..........#.aa.....a#...........",
00111 ".........#.a.........#..........",
00112 ".........#a..........#a.........",
00113 "........#.a...........#.........",
00114 "........#a............#a........",
00115 "........#a............#a........",
00116 "........#a............#a........",
00117 "........#a............#a........",
00118 ".........#...........#.a........",
00119 ".........#a..........#a.........",
00120 ".........##.........#.a.........",
00121 "........#####.....##.a..........",
00122 ".......###aaa#####.aa...........",
00123 "......###aa...aaaaa.......#.....",
00124 ".....###aa................#a....",
00125 "....###aa.................#a....",
00126 "...###aa...............#######..",
00127 "....#aa.................aa#aaaa.",
00128 ".....a....................#a....",
00129 "..........................#a....",
00130 "...........................a....",
00131 "................................",
00132 "................................",
00133 "................................",
00134 "................................"};
00135 
00136 const char* imageRotateCursor[] = {
00137 "32 32 3 1",
00138 ". c None",
00139 "a c #000000",
00140 "# c #ffffff",
00141 "................................",
00142 "................................",
00143 "................................",
00144 "................................",
00145 "........#.......................",
00146 ".......#.a......................",
00147 "......#######...................",
00148 ".......#aaaaa#####..............",
00149 "........#..##.a#aa##........##..",
00150 ".........a#.aa..#..a#.....##.aa.",
00151 ".........#.a.....#...#..##.aa...",
00152 ".........#a.......#..###.aa.....",
00153 "........#.a.......#a..#aa.......",
00154 "........#a.........#..#a........",
00155 "........#a.........#a.#a........",
00156 "........#a.........#a.#a........",
00157 "........#a.........#a.#a........",
00158 ".........#.........#a#.a........",
00159 "........##a........#a#a.........",
00160 "......##.a#.......#.#.a.........",
00161 "....##.aa..##.....##.a..........",
00162 "..##.aa.....a#####.aa...........",
00163 "...aa.........aaa#a.............",
00164 "................#.a.............",
00165 "...............#.a..............",
00166 "..............#.a...............",
00167 "...............a................",
00168 "................................",
00169 "................................",
00170 "................................",
00171 "................................",
00172 "................................"};
00173 
00174 const char* imageCrossCursor[] = {
00175   "32 32 3 1",
00176   ". c None",
00177   "a c #000000",
00178   "# c #ffffff",
00179   "................................",
00180   "................................",
00181   "................................",
00182   "................................",
00183   "................................",
00184   "................................",
00185   "................................",
00186   "...............#................",
00187   "...............#a...............",
00188   "...............#a...............",
00189   "...............#a...............",
00190   "...............#a...............",
00191   "...............#a...............",
00192   "...............#a...............",
00193   "...............#a...............",
00194   ".......#################........",
00195   "........aaaaaaa#aaaaaaaaa.......",
00196   "...............#a...............",
00197   "...............#a...............",
00198   "...............#a...............",
00199   "...............#a...............",
00200   "...............#a...............",
00201   "...............#a...............",
00202   "...............#a...............",
00203   "................a...............",
00204   "................................",
00205   "................................",
00206   "................................",
00207   "................................",
00208   "................................",
00209   "................................",
00210   "................................"};
00211 
00212 
00218 OCCViewer_ViewWindow::OCCViewer_ViewWindow( SUIT_Desktop*     theDesktop,
00219                                             OCCViewer_Viewer* theModel )
00220 : SUIT_ViewWindow( theDesktop )
00221 {
00222   myModel = theModel;
00223   myRestoreFlag = 0;
00224   myEnableDrawMode = false;
00225   myDrawRect=false;
00226   updateEnabledDrawMode();
00227   myClippingDlg = 0;
00228   myScalingDlg = 0;
00229   mySetRotationPointDlg = 0;
00230   myRectBand = 0;
00231   
00232   IsSketcherStyle = false;
00233 
00234   mypSketcher = 0;
00235   myCurSketch = -1;
00236   my2dMode = No2dMode;
00237 
00238   myInteractionStyle = SUIT_ViewModel::STANDARD;
00239 
00240   clearViewAspects();
00241   
00242 }
00243 
00247 OCCViewer_ViewWindow::~OCCViewer_ViewWindow()
00248 {
00249   endDrawRect();
00250   qDeleteAll( mySketchers );
00251 }
00252 
00256 void OCCViewer_ViewWindow::initLayout()
00257 {
00258   myViewPort = new OCCViewer_ViewPort3d( this, myModel->getViewer3d(), V3d_ORTHOGRAPHIC );
00259   myViewPort->installEventFilter(this);
00260   setCentralWidget(myViewPort);
00261   myOperation = NOTHING;
00262 
00263   myCurrPointType = GRAVITY;
00264   myPrevPointType = GRAVITY;
00265   mySelectedPoint = gp_Pnt(0.,0.,0.);
00266   myRotationPointSelection = false;
00267 
00268   setTransformRequested ( NOTHING );
00269   setTransformInProcess ( false );
00270 
00271   createActions();
00272   createToolBar();
00273 
00274   switch (my2dMode) {
00275   case XYPlane:
00276     onTopView();
00277     break;
00278   case XZPlane:
00279     onLeftView();
00280     break;
00281   case YZPlane:
00282     onFrontView();
00283     break;
00284   }
00285 
00286   // Graduated axes dialog
00287   QtxAction* anAction = dynamic_cast<QtxAction*>( toolMgr()->action( GraduatedAxesId ) );
00288   myCubeAxesDlg = new OCCViewer_CubeAxesDlg( anAction, this, "OCCViewer_CubeAxesDlg" );
00289   myCubeAxesDlg->initialize();
00290 }
00291 
00292 OCCViewer_ViewWindow* OCCViewer_ViewWindow::getView( const int mode ) const
00293 {
00294   return mode == get2dMode() ? const_cast<OCCViewer_ViewWindow*>( this ) : 0;
00295 }
00296 
00303 OCCViewer_ViewWindow::OperationType
00304 OCCViewer_ViewWindow::getButtonState( QMouseEvent* theEvent, int theInteractionStyle )
00305 {
00306   OperationType aOp = NOTHING;
00307   SUIT_ViewModel::InteractionStyle aStyle = (SUIT_ViewModel::InteractionStyle)theInteractionStyle;
00308   if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ZOOM]) &&
00309       (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ZOOM]) )
00310     aOp = ZOOMVIEW;
00311   else if( (theEvent->modifiers() == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::PAN]) &&
00312            (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::PAN]) )
00313     aOp = PANVIEW;
00314   else if( (theEvent->modifiers()  == SUIT_ViewModel::myStateMap[aStyle][SUIT_ViewModel::ROTATE]) &&
00315            (theEvent->buttons() == SUIT_ViewModel::myButtonMap[aStyle][SUIT_ViewModel::ROTATE]) &&
00316            (my2dMode == No2dMode))
00317     aOp = ROTATE;
00318 
00319   return aOp;
00320 }
00321 
00328 bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
00329 {
00330   if ( watched == myViewPort ) {
00331     int aType = e->type();
00332     switch(aType) {
00333     case QEvent::MouseButtonPress:
00334       vpMousePressEvent((QMouseEvent*) e);
00335       return true;
00336 
00337     case QEvent::MouseButtonRelease:
00338       vpMouseReleaseEvent((QMouseEvent*) e);
00339       return true;
00340 
00341     case QEvent::MouseMove:
00342       vpMouseMoveEvent((QMouseEvent*) e);
00343       return true;
00344 
00345     case QEvent::MouseButtonDblClick:
00346       emit mouseDoubleClicked(this, (QMouseEvent*)e);
00347       return true;
00348 
00349     case QEvent::Wheel:
00350       {
00351         QWheelEvent* aEvent = (QWheelEvent*) e;
00352        myViewPort->startZoomAtPoint( aEvent->x(), aEvent->y() );
00353        double delta = (double)( aEvent->delta() ) / ( 15 * 8 );
00354        int x  = aEvent->x();
00355        int y  = aEvent->y();
00356        int x1 = (int)( aEvent->x() + width()*delta/100 );
00357        int y1 = (int)( aEvent->y() + height()*delta/100 );
00358        myViewPort->zoom( x, y, x1, y1 );
00359       }
00360       return true;
00361 
00362     case QEvent::ContextMenu:
00363       {
00364         QContextMenuEvent * aEvent = (QContextMenuEvent*)e;
00365         if ( aEvent->reason() != QContextMenuEvent::Mouse )
00366           emit contextMenuRequested( aEvent );
00367       }
00368       return true;
00369 
00370     case QEvent::KeyPress:
00371       emit keyPressed(this, (QKeyEvent*) e);
00372       return true;
00373 
00374     default:
00375       break;
00376     }
00377   }
00378   return SUIT_ViewWindow::eventFilter(watched, e);
00379 }
00380 
00384 void OCCViewer_ViewWindow::updateEnabledDrawMode()
00385 {
00386   if ( myModel )
00387     myEnableDrawMode = myModel->isSelectionEnabled() && myModel->isMultiSelectionEnabled();
00388 }
00389 
00394 void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
00395 {
00396   myStartX = theEvent->x();
00397   myStartY = theEvent->y();
00398   int anInteractionStyle = interactionStyle();
00399 
00400   // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
00401   // which are assigned for pan and rotate - these operations are activated immediately after pressing 
00402   // of the first button, so it is necessary to switch to zoom when the second button is pressed
00403   bool aSwitchToZoom = false;
00404   if ( anInteractionStyle == SUIT_ViewModel::KEY_FREE && 
00405        ( myOperation == PANVIEW || myOperation == ROTATE ) ) {
00406     aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
00407   }
00408 
00409   switch ( myOperation ) {
00410   case WINDOWFIT:
00411     if ( theEvent->button() == Qt::LeftButton )
00412       emit vpTransformationStarted ( WINDOWFIT );
00413     break;
00414 
00415   case PANGLOBAL:
00416     if ( theEvent->button() == Qt::LeftButton )
00417       emit vpTransformationStarted ( PANGLOBAL );
00418     break;
00419 
00420   case ZOOMVIEW:
00421     if ( theEvent->button() == Qt::LeftButton ) {
00422       myViewPort->startZoomAtPoint( myStartX, myStartY );
00423       emit vpTransformationStarted ( ZOOMVIEW );
00424     }
00425     break;
00426 
00427   case PANVIEW:
00428     if ( aSwitchToZoom ) {
00429       myViewPort->startZoomAtPoint( myStartX, myStartY );
00430       activateZoom();
00431     }
00432     else if ( theEvent->button() == Qt::LeftButton )
00433       emit vpTransformationStarted ( PANVIEW );
00434     break;
00435 
00436   case ROTATE:
00437     if ( aSwitchToZoom ) {
00438       myViewPort->startZoomAtPoint( myStartX, myStartY );
00439       activateZoom();
00440     }
00441     else if ( theEvent->button() == Qt::LeftButton ) {
00442       myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
00443       emit vpTransformationStarted ( ROTATE );
00444     }
00445     break;
00446 
00447   default:
00448   /*  Try to activate a transformation */
00449     switch ( getButtonState(theEvent, anInteractionStyle) ) {
00450     case ZOOMVIEW:
00451       myViewPort->startZoomAtPoint( myStartX, myStartY );
00452       activateZoom();
00453       break;
00454     case PANVIEW:
00455             activatePanning();
00456       break;
00457     case ROTATE:
00458             activateRotation();
00459             myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
00460       break;
00461     default:
00462       if ( myRotationPointSelection )
00463       {
00464         if ( theEvent->button() == Qt::LeftButton )
00465         {
00466           Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
00467           ic->Select();
00468           for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
00469           {
00470             TopoDS_Shape aShape = ic->SelectedShape();
00471             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
00472             {
00473               gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
00474               if ( mySetRotationPointDlg )
00475               {
00476                 myRotationPointSelection = false;
00477                 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
00478               }
00479             }
00480             else
00481             {
00482               myCurrPointType = myPrevPointType;
00483               break;
00484             }
00485           }
00486           if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
00487           if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
00488           ic->CloseAllContexts();
00489           myOperation = NOTHING;
00490           myViewPort->setCursor( myCursor );
00491           myCursorIsHand = false;
00492           myRotationPointSelection = false;
00493         }
00494       }
00495       else
00496         emit mousePressed(this, theEvent);
00497       break;
00498     }
00499     /* notify that we start a transformation */
00500     if ( transformRequested() )
00501             emit vpTransformationStarted ( myOperation );
00502   }
00503   if ( transformRequested() )
00504     setTransformInProcess( true );
00505 
00506   /* we may need it for sketching... */
00507   if ( l_mbPressEvent )
00508     delete l_mbPressEvent;
00509   l_mbPressEvent = new QMouseEvent( *theEvent );
00510 }
00511 
00512 
00518 void OCCViewer_ViewWindow::activateZoom()
00519 {
00520   if ( !transformRequested() && !myCursorIsHand )
00521     myCursor = cursor();                /* save old cursor */
00522 
00523   if ( myOperation != ZOOMVIEW ) {
00524     QPixmap zoomPixmap (imageZoomCursor);
00525     QCursor zoomCursor (zoomPixmap);
00526     if( setTransformRequested ( ZOOMVIEW ) )
00527       myViewPort->setCursor( zoomCursor );
00528   }
00529 }
00530 
00531 
00537 void OCCViewer_ViewWindow::activatePanning()
00538 {
00539   if ( !transformRequested() && !myCursorIsHand )
00540     myCursor = cursor();                // save old cursor
00541 
00542   if ( myOperation != PANVIEW ) {
00543     QCursor panCursor (Qt::SizeAllCursor);
00544     if( setTransformRequested ( PANVIEW ) )
00545       myViewPort->setCursor( panCursor );
00546   }
00547 }
00548 
00554 void OCCViewer_ViewWindow::activateRotation()
00555 {
00556   if ( !transformRequested() && !myCursorIsHand )
00557     myCursor = cursor();                // save old cursor
00558 
00559   if ( myOperation != ROTATE ) {
00560     QPixmap rotatePixmap (imageRotateCursor);
00561     QCursor rotCursor (rotatePixmap);
00562     if( setTransformRequested ( ROTATE ) )
00563       myViewPort->setCursor( rotCursor );
00564   }
00565 }
00566 
00574 bool OCCViewer_ViewWindow::computeGravityCenter( double& theX, double& theY, double& theZ )
00575 {
00576   Handle(Visual3d_View) aView = myViewPort->getView()->View();
00577 
00578   Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
00579   Standard_Real Umin,Vmin,Umax,Vmax ;
00580   Standard_Integer Nstruct,Npoint ;
00581   Graphic3d_MapOfStructure MySetOfStructures;
00582 
00583   aView->DisplayedStructures (MySetOfStructures);
00584   Nstruct = MySetOfStructures.Extent() ;
00585 
00586   Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
00587   aView->ViewMapping().WindowLimit(Umin,Vmin,Umax,Vmax) ;
00588   Npoint = 0 ; theX = theY = theZ = 0. ;
00589   for( ; MyIterator.More(); MyIterator.Next()) {
00590     if (!(MyIterator.Key())->IsEmpty()) {
00591       (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
00592                                          Xmax,Ymax,Zmax) ;
00593 
00594       Standard_Real LIM = ShortRealLast() -1.;
00595       if (!    (fabs(Xmin) > LIM || fabs(Ymin) > LIM || fabs(Zmin) > LIM
00596                 ||  fabs(Xmax) > LIM || fabs(Ymax) > LIM || fabs(Zmax) > LIM )) {
00597 
00598         aView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
00599         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00600           Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmin ;
00601         }
00602         aView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
00603         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00604           Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmin ;
00605         }
00606         aView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
00607         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00608           Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmin ;
00609         }
00610         aView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
00611         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00612           Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmin ;
00613         }
00614         aView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
00615         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00616           Npoint++ ; theX += Xmin ; theY += Ymin ; theZ += Zmax ;
00617         }
00618         aView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
00619         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00620           Npoint++ ; theX += Xmax ; theY += Ymin ; theZ += Zmax ;
00621         }
00622         aView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
00623         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00624           Npoint++ ; theX += Xmin ; theY += Ymax ; theZ += Zmax ;
00625         }
00626         aView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
00627         if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
00628           Npoint++ ; theX += Xmax ; theY += Ymax ; theZ += Zmax ;
00629         }
00630       }
00631     }
00632   }
00633   if( Npoint > 0 ) {
00634     theX /= Npoint ; theY /= Npoint ; theZ /= Npoint ;
00635   }
00636   return true;
00637 }
00638 
00642 void OCCViewer_ViewWindow::activateSetRotationGravity()
00643 {
00644   if ( myRotationPointSelection )
00645   {
00646     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
00647     ic->CloseAllContexts();
00648     myOperation = NOTHING;
00649     myViewPort->setCursor( myCursor );
00650     myCursorIsHand = false;
00651     myRotationPointSelection = false;
00652   }
00653 
00654   myPrevPointType = myCurrPointType;
00655   myCurrPointType = GRAVITY;
00656 
00657   Standard_Real Xcenter, Ycenter, Zcenter;
00658   if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
00659     mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
00660 }
00661 
00666 void OCCViewer_ViewWindow::updateGravityCoords()
00667 {
00668   if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
00669   {
00670     Standard_Real Xcenter, Ycenter, Zcenter;
00671     if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
00672       mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
00673   }
00674 }
00675 
00682 void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY, double theZ )
00683 {
00684   if ( myRotationPointSelection )
00685   {
00686     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
00687     ic->CloseAllContexts();
00688     myOperation = NOTHING;
00689     myViewPort->setCursor( myCursor );
00690     myCursorIsHand = false;
00691     myRotationPointSelection = false;
00692   }
00693 
00694   myPrevPointType = myCurrPointType;
00695   myCurrPointType = SELECTED;
00696   mySelectedPoint.SetCoord(theX,theY,theZ);
00697 }
00698 
00702 void OCCViewer_ViewWindow::activateStartPointSelection()
00703 {
00704   myPrevPointType = myCurrPointType;
00705   myCurrPointType = SELECTED;
00706 
00707   // activate selection ------>
00708   Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
00709 
00710   ic->OpenLocalContext();
00711 
00712   AIS_ListOfInteractive aList;
00713   ic->DisplayedObjects( aList );
00714   for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() )
00715   {
00716     Handle(AIS_InteractiveObject) anObj = it.Value();
00717     if ( !anObj.IsNull() && anObj->HasPresentation() &&
00718          anObj->IsKind( STANDARD_TYPE(AIS_Shape) ) )
00719     {
00720       ic->Load(anObj,-1);
00721       ic->Activate(anObj,AIS_Shape::SelectionMode(TopAbs_VERTEX));
00722      }
00723   }
00724   // activate selection <------
00725 
00726   if ( !myCursorIsHand )
00727   {
00728     QCursor handCursor (Qt::PointingHandCursor);
00729     myCursorIsHand = true;
00730     myCursor = cursor();
00731     myViewPort->setCursor( handCursor );
00732   }
00733   myRotationPointSelection = true;
00734 }
00735 
00741 void OCCViewer_ViewWindow::activateGlobalPanning()
00742 {
00743   Handle(V3d_View) aView3d = myViewPort->getView();
00744   if ( !aView3d.IsNull() ) {
00745     QPixmap globalPanPixmap (imageCrossCursor);
00746     QCursor glPanCursor (globalPanPixmap);
00747     myCurScale = aView3d->Scale();
00748     aView3d->FitAll(0.01, false);
00749     myCursor = cursor();                // save old cursor
00750     myViewPort->fitAll(); // fits view before selecting a new scene center
00751     if( setTransformRequested( PANGLOBAL ) )
00752       myViewPort->setCursor( glPanCursor );
00753   }
00754 }
00755 
00761 void OCCViewer_ViewWindow::activateWindowFit()
00762 {
00763   if ( !transformRequested() && !myCursorIsHand )
00764     myCursor = cursor();                /* save old cursor */
00765 
00766   if ( myOperation != WINDOWFIT ) {
00767     QCursor handCursor (Qt::PointingHandCursor);
00768     if( setTransformRequested ( WINDOWFIT ) )
00769     {
00770       myViewPort->setCursor ( handCursor );
00771       myCursorIsHand = true;
00772     }
00773   }
00774 }
00775 
00779 bool OCCViewer_ViewWindow::setTransformRequested( OperationType op )
00780 {
00781   bool ok = transformEnabled( op );
00782   myOperation = ok ? op : NOTHING;
00783   myViewPort->setMouseTracking( myOperation == NOTHING );  
00784   return ok;
00785 }
00786 
00791 void OCCViewer_ViewWindow::vpMouseMoveEvent( QMouseEvent* theEvent )
00792 {
00793   myCurrX = theEvent->x();
00794   myCurrY = theEvent->y();
00795   switch (myOperation) {
00796   case ROTATE:
00797     myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
00798     break;
00799 
00800   case ZOOMVIEW:
00801     myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
00802     myStartX = myCurrX;
00803     myStartY = myCurrY;
00804     break;
00805 
00806   case PANVIEW:
00807     myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
00808     myStartX = myCurrX;
00809     myStartY = myCurrY;
00810     break;
00811 
00812 /*    case WINDOWFIT:
00813     myDrawRect = true;
00814     repaint();
00815     break;
00816 */
00817   case PANGLOBAL:
00818     break;
00819 
00820   default:
00821     if ( myRotationPointSelection || isSketcherStyle() )
00822     {
00823       emit mouseMoving( this, theEvent );
00824     }
00825     else
00826     {
00827       int aState = theEvent->modifiers();
00828       int aButton = theEvent->buttons();
00829       int anInteractionStyle = interactionStyle();
00830       if ( anInteractionStyle == SUIT_ViewModel::STANDARD && 
00831            aButton == Qt::LeftButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) {
00832         myDrawRect = myEnableDrawMode;
00833         if ( myDrawRect ) {
00834           drawRect();
00835           if ( !myCursorIsHand )        {   // we are going to sketch a rectangle
00836             QCursor handCursor (Qt::PointingHandCursor);
00837             myCursorIsHand = true;
00838             myCursor = cursor();
00839             myViewPort->setCursor( handCursor );
00840           }
00841         }
00842         emit mouseMoving( this, theEvent );
00843       }
00844       else if ( anInteractionStyle == SUIT_ViewModel::STANDARD && 
00845                 aButton == Qt::RightButton && ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) {
00846         OCCViewer_ViewSketcher* sketcher = 0;
00847         QList<OCCViewer_ViewSketcher*>::Iterator it;
00848         for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
00849         {
00850           OCCViewer_ViewSketcher* sk = (*it);
00851           if( sk->isDefault() && sk->sketchButton() == aButton )
00852             sketcher = sk;
00853         }
00854         if ( sketcher && myCurSketch == -1 )
00855         {
00856           activateSketching( sketcher->type() );
00857           if ( mypSketcher )
00858           {
00859             myCurSketch = mypSketcher->sketchButton();
00860 
00861             if ( l_mbPressEvent )
00862             {
00863               QApplication::sendEvent( getViewPort(), l_mbPressEvent );
00864               delete l_mbPressEvent;
00865               l_mbPressEvent = 0;
00866             }
00867             QApplication::sendEvent( getViewPort(), theEvent );
00868           }
00869         }
00870       }
00871       else
00872         emit mouseMoving( this, theEvent );
00873     }
00874   }
00875 }
00876 
00881 void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
00882 {
00883   switch ( myOperation ) {
00884   case NOTHING:
00885     {
00886       int prevState = myCurSketch;
00887       if(theEvent->button() == Qt::RightButton)
00888       {
00889         QList<OCCViewer_ViewSketcher*>::Iterator it;
00890         for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it )
00891         {
00892           OCCViewer_ViewSketcher* sk = (*it);
00893           if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
00894             myCurSketch = -1;
00895         }
00896       }
00897 
00898       emit mouseReleased(this, theEvent);
00899       if(theEvent->button() == Qt::RightButton && prevState == -1)
00900       {
00901         QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
00902                                   theEvent->pos(), theEvent->globalPos() );
00903         emit contextMenuRequested( &aEvent );
00904       }
00905     }
00906     break;
00907   case ROTATE:
00908     myViewPort->endRotation();
00909     resetState();
00910     break;
00911 
00912   case PANVIEW:
00913   case ZOOMVIEW:
00914     resetState();
00915     break;
00916 
00917   case PANGLOBAL:
00918     if ( theEvent->button() == Qt::LeftButton ) {
00919       myViewPort->setCenter( theEvent->x(), theEvent->y() );
00920       myViewPort->getView()->SetScale(myCurScale);
00921       resetState();
00922     }
00923     break;
00924 
00925   case WINDOWFIT:
00926     if ( theEvent->button() == Qt::LeftButton ) {
00927       myCurrX = theEvent->x();
00928       myCurrY = theEvent->y();
00929       drawRect();
00930       QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
00931       if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
00932       endDrawRect();
00933       resetState();
00934     }
00935     break;
00936   }
00937 
00938   // NOTE: viewer 3D detects a rectangle of selection using this event
00939   // so we must emit it BEFORE resetting the selection rectangle
00940 
00941   if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
00942     drawRect();
00943     endDrawRect();
00944     resetState();
00945     myViewPort->update();
00946   }
00947 
00948   if ( l_mbPressEvent )
00949   {
00950     delete l_mbPressEvent;
00951     l_mbPressEvent = 0;
00952   }
00953 }
00954 
00959 void OCCViewer_ViewWindow::resetState()
00960 {
00961   myDrawRect = false;
00962 
00963   if ( myRotationPointSelection )
00964   {
00965     QCursor handCursor (Qt::PointingHandCursor);
00966     myViewPort->setCursor( handCursor );
00967   }
00968   else
00969   {
00970     if ( transformRequested() || myCursorIsHand )
00971       myViewPort->setCursor( myCursor );
00972     myCursorIsHand = false;
00973   }
00974 
00975   if ( transformRequested() )
00976     emit vpTransformationFinished (myOperation);
00977 
00978   setTransformInProcess( false );
00979   setTransformRequested( NOTHING );
00980 }
00981 
00982 
00986 void OCCViewer_ViewWindow::drawRect()
00987 {
00988   if ( !myRectBand ) {
00989     myRectBand = new QtxRectRubberBand( myViewPort );
00990     //QPalette palette;
00991     //palette.setColor(myRectBand->foregroundRole(), Qt::white);
00992     //myRectBand->setPalette(palette);
00993   }
00994   //myRectBand->hide();
00995   
00996   myRectBand->setUpdatesEnabled ( false );
00997   QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
00998   myRectBand->initGeometry( aRect );
00999 
01000   if ( !myRectBand->isVisible() )
01001     myRectBand->show();
01002 
01003   myRectBand->setUpdatesEnabled ( true );
01004   //myRectBand->repaint();
01005 
01006   //myRectBand->setVisible( aRect.isValid() );
01007   //if ( myRectBand->isVisible() )
01008   //  myRectBand->repaint();
01009   //else
01010   //  myRectBand->show();
01011   //myRectBand->repaint();
01012 }
01013 
01017 void OCCViewer_ViewWindow::endDrawRect()
01018 {
01019   //delete myRectBand;
01020   //myRectBand = 0;
01021   if ( myRectBand )
01022     {
01023       myRectBand->clearGeometry();
01024       myRectBand->hide();
01025     }
01026 }
01027 
01031 void OCCViewer_ViewWindow::createActions()
01032 {
01033   if( !toolMgr()->isEmpty() )
01034     return;
01035   
01036   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
01037 
01038   QtxAction* aAction;
01039 
01040   // Dump view
01041   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_DUMP" ) ),
01042                            tr( "MNU_DUMP_VIEW" ), 0, this);
01043   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
01044   connect(aAction, SIGNAL(triggered()), this, SLOT(onDumpView()));
01045   toolMgr()->registerAction( aAction, DumpId );
01046 
01047   // FitAll
01048   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITALL" ) ),
01049                            tr( "MNU_FITALL" ), 0, this);
01050   aAction->setStatusTip(tr("DSC_FITALL"));
01051   connect(aAction, SIGNAL(triggered()), this, SLOT(onFitAll()));
01052   toolMgr()->registerAction( aAction, FitAllId );
01053 
01054   // FitRect
01055   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FITAREA" ) ),
01056                            tr( "MNU_FITRECT" ), 0, this);
01057   aAction->setStatusTip(tr("DSC_FITRECT"));
01058   connect(aAction, SIGNAL(triggered()), this, SLOT(activateWindowFit()));
01059   toolMgr()->registerAction( aAction, FitRectId );
01060   
01061   // Zoom
01062   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ZOOM" ) ),
01063                            tr( "MNU_ZOOM_VIEW" ), 0, this);
01064   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
01065   connect(aAction, SIGNAL(triggered()), this, SLOT(activateZoom()));
01066   toolMgr()->registerAction( aAction, ZoomId );
01067 
01068   // Panning
01069   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_PAN" ) ),
01070                            tr( "MNU_PAN_VIEW" ), 0, this);
01071   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
01072   connect(aAction, SIGNAL(triggered()), this, SLOT(activatePanning()));
01073   toolMgr()->registerAction( aAction, PanId );
01074 
01075   // Global Panning
01076   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_GLOBALPAN" ) ),
01077                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
01078   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
01079   connect(aAction, SIGNAL(triggered()), this, SLOT(activateGlobalPanning()));
01080   toolMgr()->registerAction( aAction, GlobalPanId );
01081 
01082   // Rotation Point
01083   mySetRotationPointAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATION_POINT" ) ),
01084                            tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
01085   mySetRotationPointAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
01086   mySetRotationPointAction->setCheckable( true );
01087   connect(mySetRotationPointAction, SIGNAL(toggled( bool )), this, SLOT(onSetRotationPoint( bool )));
01088   toolMgr()->registerAction( mySetRotationPointAction, ChangeRotationPointId );
01089 
01090   // Rotation
01091   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ROTATE" ) ),
01092                            tr( "MNU_ROTATE_VIEW" ), 0, this);
01093   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
01094   connect(aAction, SIGNAL(triggered()), this, SLOT(activateRotation()));
01095   toolMgr()->registerAction( aAction, RotationId );
01096 
01097   // Projections
01098   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_FRONT" ) ),
01099                            tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
01100   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
01101   connect(aAction, SIGNAL(triggered()), this, SLOT(onFrontView()));
01102   this->addAction(aAction);
01103   toolMgr()->registerAction( aAction, FrontId );
01104 
01105   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BACK" ) ),
01106                            tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
01107   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
01108   connect(aAction, SIGNAL(triggered()), this, SLOT(onBackView()));
01109   this->addAction(aAction);
01110   toolMgr()->registerAction( aAction, BackId );
01111 
01112   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TOP" ) ),
01113                            tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
01114   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
01115   connect(aAction, SIGNAL(triggered()), this, SLOT(onTopView()));
01116   this->addAction(aAction);
01117   toolMgr()->registerAction( aAction, TopId );
01118 
01119   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_BOTTOM" ) ),
01120                            tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
01121   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
01122   connect(aAction, SIGNAL(triggered()), this, SLOT(onBottomView()));
01123   this->addAction(aAction);
01124   toolMgr()->registerAction( aAction, BottomId );
01125   
01126   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_LEFT" ) ),
01127                            tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
01128   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
01129   connect(aAction, SIGNAL(triggered()), this, SLOT(onLeftView()));
01130   this->addAction(aAction);
01131   toolMgr()->registerAction( aAction, LeftId );
01132 
01133   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RIGHT" ) ),
01134                            tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
01135   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
01136   connect(aAction, SIGNAL(triggered()), this, SLOT(onRightView()));
01137   this->addAction(aAction);
01138   toolMgr()->registerAction( aAction, RightId );
01139 
01140   // rotate anticlockwise
01141   aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_ANTICLOCKWISE" ) ),
01142                            tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
01143   aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
01144   connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
01145   this->addAction(aAction);
01146   toolMgr()->registerAction( aAction, AntiClockWiseId );
01147 
01148   // rotate clockwise
01149   aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_CLOCKWISE" ) ),
01150                            tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
01151   aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
01152   connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
01153   this->addAction(aAction);
01154   toolMgr()->registerAction( aAction, ClockWiseId );
01155 
01156   // Reset
01157   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_RESET" ) ),
01158                            tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
01159   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
01160   connect(aAction, SIGNAL(triggered()), this, SLOT(onResetView()));
01161   this->addAction(aAction);
01162   toolMgr()->registerAction( aAction, ResetId );
01163 
01164   // Clone
01165   aAction = new QtxAction(tr("MNU_CLONE_VIEW"),
01166                           aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_CLONE_VIEW")),
01167                           tr("MNU_CLONE_VIEW"), 0, this);
01168   aAction->setStatusTip(tr("DSC_CLONE_VIEW"));
01169   connect(aAction, SIGNAL(triggered()), this, SLOT(onCloneView()));
01170   toolMgr()->registerAction( aAction, CloneId );
01171 
01172   myClippingAction = new QtxAction(tr("MNU_CLIPPING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" ) ),
01173                            tr( "MNU_CLIPPING" ), 0, this);
01174   myClippingAction->setStatusTip(tr("DSC_CLIPPING"));
01175   myClippingAction->setCheckable( true );
01176   connect(myClippingAction, SIGNAL(toggled( bool )), this, SLOT(onClipping( bool )));
01177   toolMgr()->registerAction( myClippingAction, ClippingId );
01178 
01179   aAction = new QtxAction(tr("MNU_SHOOT_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SHOOT_VIEW" ) ),
01180                            tr( "MNU_SHOOT_VIEW" ), 0, this);
01181   aAction->setStatusTip(tr("DSC_SHOOT_VIEW"));
01182   connect(aAction, SIGNAL(triggered()), this, SLOT(onMemorizeView()));
01183   toolMgr()->registerAction( aAction, MemId );
01184 
01185   aAction = new QtxAction(tr("MNU_PRESETS_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_PRESETS_VIEW" ) ),
01186                            tr( "MNU_PRESETS_VIEW" ), 0, this);
01187   aAction->setStatusTip(tr("DSC_PRESETS_VIEW"));
01188   connect(aAction, SIGNAL(triggered()), this, SLOT(onRestoreView()));
01189   toolMgr()->registerAction( aAction, RestoreId );
01190 
01191   if (myModel->trihedronActivated()) {
01192     aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_VIEW_TRIHEDRON" ) ),
01193                              tr( "MNU_SHOW_TRIHEDRE" ), 0, this);
01194     aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
01195     connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihedronShow()));
01196     toolMgr()->registerAction( aAction, TrihedronShowId );
01197   }
01198 
01199   // Scale
01200   aAction = new QtxAction(tr("MNU_SCALING"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SCALING" ) ),
01201                            tr( "MNU_SCALING" ), 0, this);
01202   aAction->setStatusTip(tr("DSC_SCALING"));
01203   connect(aAction, SIGNAL(triggered()), this, SLOT(onAxialScale()));
01204   toolMgr()->registerAction( aAction, AxialScaleId );
01205 
01206   // Graduated axes 
01207   aAction = new QtxAction(tr("MNU_GRADUATED_AXES"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_GRADUATED_AXES" ) ),
01208                            tr( "MNU_GRADUATED_AXES" ), 0, this);
01209   aAction->setStatusTip(tr("DSC_GRADUATED_AXES"));
01210   connect(aAction, SIGNAL(triggered()), this, SLOT(onGraduatedAxes()));
01211   toolMgr()->registerAction( aAction, GraduatedAxesId );
01212 
01213   // Active only ambient light or not
01214   aAction = new QtxAction(tr("MNU_AMBIENT"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_AMBIENT" ) ),
01215                            tr( "MNU_AMBIENT" ), 0, this);
01216   aAction->setStatusTip(tr("DSC_AMBIENT"));
01217   connect(aAction, SIGNAL(triggered()), this, SLOT(onAmbientToogle()));
01218   toolMgr()->registerAction( aAction, AmbientId );
01219 
01220   // Switch between interaction styles
01221   aAction = new QtxAction(tr("MNU_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_STYLE_SWITCH" ) ),
01222                           tr( "MNU_STYLE_SWITCH" ), 0, this);
01223   aAction->setStatusTip(tr("DSC_STYLE_SWITCH"));
01224   aAction->setCheckable(true);
01225   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
01226   toolMgr()->registerAction( aAction, SwitchInteractionStyleId );
01227 
01228   // Switch between zooming styles
01229   aAction = new QtxAction(tr("MNU_ZOOMING_STYLE_SWITCH"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_ZOOMING_STYLE_SWITCH" ) ),
01230                           tr( "MNU_ZOOMING_STYLE_SWITCH" ), 0, this);
01231   aAction->setStatusTip(tr("DSC_ZOOMING_STYLE_SWITCH"));
01232   aAction->setCheckable(true);
01233   connect(aAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
01234   toolMgr()->registerAction( aAction, SwitchZoomingStyleId );
01235 
01236   // Maximized view
01237   aAction = new QtxAction(tr("MNU_MINIMIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ),
01238                           tr( "MNU_MINIMIZE_VIEW" ), 0, this );
01239   aAction->setStatusTip(tr("DSC_MINIMIZE_VIEW"));
01240   connect(aAction, SIGNAL(triggered()), this, SLOT(onMaximizedView()));
01241   toolMgr()->registerAction( aAction, MaximizedId );
01242 
01243   // Synchronize view
01244   aAction = new QtxAction(tr("MNU_SYNCHRONIZE_VIEW"), aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_SYNC" ) ),
01245                           tr( "MNU_SYNCHRONIZE_VIEW" ), 0, this );
01246   aAction->setStatusTip(tr("DSC_SYNCHRONIZE_VIEW"));
01247   aAction->setMenu( new QMenu( this ) );
01248   aAction->setCheckable(true);
01249   connect(aAction->menu(), SIGNAL(aboutToShow()), this, SLOT(updateSyncViews()));
01250   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSynchronizeView(bool)));
01251   toolMgr()->registerAction( aAction, SynchronizeId );
01252 }
01253 
01257 void OCCViewer_ViewWindow::createToolBar()
01258 {
01259   QString aToolbarName;
01260   switch (my2dMode) {
01261   case XYPlane:
01262     aToolbarName = tr( "LBL_XYTOOLBAR_LABEL" );
01263     break;
01264   case XZPlane:
01265     aToolbarName = tr( "LBL_XZTOOLBAR_LABEL" );
01266     break;
01267   case YZPlane:
01268     aToolbarName = tr( "LBL_YZTOOLBAR_LABEL" );
01269     break;
01270   default:
01271     aToolbarName = tr( "LBL_3DTOOLBAR_LABEL" );
01272   }
01273   
01274   int tid = toolMgr()->createToolBar( aToolbarName, false );
01275 
01276   toolMgr()->append( DumpId, tid );
01277   toolMgr()->append( SwitchInteractionStyleId, tid );
01278 #if OCC_VERSION_LARGE > 0x0603000A // available only with OCC-6.3-sp11 and higher version
01279   toolMgr()->append( SwitchZoomingStyleId, tid );
01280 #endif
01281   if( myModel->trihedronActivated() )
01282     toolMgr()->append( TrihedronShowId, tid );
01283 
01284   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
01285   aScaleAction->insertAction( toolMgr()->action( FitAllId ) );
01286   aScaleAction->insertAction( toolMgr()->action( FitRectId ) );
01287   aScaleAction->insertAction( toolMgr()->action( ZoomId ) );
01288   toolMgr()->append( aScaleAction, tid );
01289 
01290   QtxMultiAction* aPanningAction = new QtxMultiAction( this );
01291   aPanningAction->insertAction( toolMgr()->action( PanId ) );
01292   aPanningAction->insertAction( toolMgr()->action( GlobalPanId ) );
01293   toolMgr()->append( aPanningAction, tid );
01294 
01295   if (my2dMode == No2dMode) {
01296     toolMgr()->append( ChangeRotationPointId, tid );
01297     toolMgr()->append( RotationId, tid );
01298 
01299     QtxMultiAction* aViewsAction = new QtxMultiAction( this );
01300     aViewsAction->insertAction( toolMgr()->action( FrontId ) );
01301     aViewsAction->insertAction( toolMgr()->action( BackId ) );
01302     aViewsAction->insertAction( toolMgr()->action( TopId ) );
01303     aViewsAction->insertAction( toolMgr()->action( BottomId ) );
01304     aViewsAction->insertAction( toolMgr()->action( LeftId ) );
01305     aViewsAction->insertAction( toolMgr()->action( RightId ) );
01306     toolMgr()->append( aViewsAction, tid );
01307 
01308     toolMgr()->append( AntiClockWiseId, tid );
01309     toolMgr()->append( ClockWiseId, tid );
01310 
01311     toolMgr()->append( ResetId, tid );
01312   }
01313 
01314   QtxMultiAction* aMemAction = new QtxMultiAction( this );
01315   aMemAction->insertAction( toolMgr()->action( MemId ) );
01316   aMemAction->insertAction( toolMgr()->action( RestoreId ) );
01317   toolMgr()->append( aMemAction, tid );
01318 
01319   toolMgr()->append( toolMgr()->separator(), tid );
01320   toolMgr()->append( CloneId, tid );
01321   
01322   toolMgr()->append( toolMgr()->separator(), tid );
01323   toolMgr()->append( ClippingId, tid );
01324   toolMgr()->append( AxialScaleId, tid );
01325 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
01326   toolMgr()->append( GraduatedAxesId, tid );
01327 #endif
01328   toolMgr()->append( AmbientId, tid );
01329 
01330   toolMgr()->append( MaximizedId, tid );
01331   toolMgr()->append( SynchronizeId, tid );
01332 }
01333 
01337 void OCCViewer_ViewWindow::onViewFitAll()
01338 {
01339   myViewPort->fitAll();
01340 }
01341 
01345 void OCCViewer_ViewWindow::onFrontView()
01346 {
01347   emit vpTransformationStarted ( FRONTVIEW );
01348   Handle(V3d_View) aView3d = myViewPort->getView();
01349   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xpos);
01350   onViewFitAll();
01351   emit vpTransformationFinished ( FRONTVIEW );
01352 }
01353 
01357 void OCCViewer_ViewWindow::onBackView()
01358 {
01359   emit vpTransformationStarted ( BACKVIEW );
01360   Handle(V3d_View) aView3d = myViewPort->getView();
01361   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Xneg);
01362   onViewFitAll();
01363   emit vpTransformationFinished ( BACKVIEW );
01364 }
01365 
01369 void OCCViewer_ViewWindow::onTopView()
01370 {
01371   emit vpTransformationStarted ( TOPVIEW );
01372   Handle(V3d_View) aView3d = myViewPort->getView();
01373   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zpos);
01374   onViewFitAll();
01375   emit vpTransformationFinished ( TOPVIEW );
01376 }
01377 
01381 void OCCViewer_ViewWindow::onBottomView()
01382 {
01383   emit vpTransformationStarted ( BOTTOMVIEW );
01384   Handle(V3d_View) aView3d = myViewPort->getView();
01385   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Zneg);
01386   onViewFitAll();
01387   emit vpTransformationFinished ( BOTTOMVIEW );
01388 }
01389 
01393 void OCCViewer_ViewWindow::onLeftView()
01394 {
01395   emit vpTransformationStarted ( LEFTVIEW );
01396   Handle(V3d_View) aView3d = myViewPort->getView();
01397   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Yneg);
01398   onViewFitAll();
01399   emit vpTransformationFinished ( LEFTVIEW );
01400 }
01401 
01405 void OCCViewer_ViewWindow::onRightView()
01406 {
01407   emit vpTransformationStarted ( RIGHTVIEW );
01408   Handle(V3d_View) aView3d = myViewPort->getView();
01409   if ( !aView3d.IsNull() ) aView3d->SetProj (V3d_Ypos);
01410   onViewFitAll();
01411   emit vpTransformationFinished ( RIGHTVIEW );
01412 }
01413 
01417 void OCCViewer_ViewWindow::onClockWiseView()
01418 {
01419   emit vpTransformationStarted ( CLOCKWISEVIEW );
01420   myViewPort->rotateXY( 90. );
01421   emit vpTransformationFinished ( CLOCKWISEVIEW );
01422 }
01423 
01427 void OCCViewer_ViewWindow::onAntiClockWiseView()
01428 {
01429   emit vpTransformationStarted ( ANTICLOCKWISEVIEW );
01430   myViewPort->rotateXY( -90. );
01431   emit vpTransformationFinished ( ANTICLOCKWISEVIEW );
01432 }
01433 
01439 void OCCViewer_ViewWindow::onResetView()
01440 {
01441   emit vpTransformationStarted( RESETVIEW );
01442   bool upd = myViewPort->getView()->SetImmediateUpdate( false );
01443   myViewPort->getView()->Reset( false );
01444   myViewPort->fitAll( false, true, false );
01445   myViewPort->getView()->SetImmediateUpdate( upd );
01446   myViewPort->getView()->Update();
01447   emit vpTransformationFinished( RESETVIEW );
01448 }
01449 
01453 void OCCViewer_ViewWindow::onFitAll()
01454 {
01455   emit vpTransformationStarted( FITALLVIEW );
01456   myViewPort->fitAll();
01457   emit vpTransformationFinished( FITALLVIEW );
01458 }
01459 
01464 void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
01465 {
01466   if (on)
01467   {
01468     if (!mySetRotationPointDlg)
01469     {
01470       mySetRotationPointDlg = new OCCViewer_SetRotationPointDlg (this);
01471       mySetRotationPointDlg->SetAction(mySetRotationPointAction);
01472     }
01473 
01474     if (!mySetRotationPointDlg->isVisible())
01475     {
01476       //if (mySetRotationPointDlg->IsFirstShown())
01477       if (myCurrPointType == GRAVITY)
01478       {
01479         Standard_Real Xcenter, Ycenter, Zcenter;
01480         if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
01481           mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
01482       }
01483       mySetRotationPointDlg->show();
01484     }
01485   }
01486   else
01487   {
01488     if (mySetRotationPointDlg->isVisible())
01489       mySetRotationPointDlg->hide();
01490   }
01491 }
01492 
01496 void OCCViewer_ViewWindow::onCloneView()
01497 {
01498   SUIT_ViewWindow* vw = myManager->createViewWindow();
01499   //vw->show();
01500   emit viewCloned( vw );
01501 }
01502 
01510 void OCCViewer_ViewWindow::onClipping( bool on )
01511 {
01512   /*
01513   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
01514   if ( on )
01515     myActionsMap[ ClippingId ]->setIcon(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING_PRESSED" )));
01516   else
01517     myActionsMap[ ClippingId ]->setIcon(aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_CLIPPING" )));
01518   */
01519   OCCViewer_ViewWindow* aParent = dynamic_cast<OCCViewer_ViewWindow*>(parent()->parent());
01520   if (!aParent)
01521     aParent = this;
01522   if ( on )
01523     {
01524       if ( !myClippingDlg )
01525         {
01526           myClippingDlg = new OCCViewer_ClippingDlg( aParent );
01527           myClippingDlg->SetAction( myClippingAction );
01528         }
01529     
01530       if ( !myClippingDlg->isVisible() )
01531         myClippingDlg->show();
01532     }
01533   else
01534     {
01535       if ( myClippingDlg->isVisible() )
01536         myClippingDlg->hide();
01537       aParent->setCuttingPlane(false);
01538     }
01539 }
01540 
01544 void OCCViewer_ViewWindow::onAxialScale()
01545 {
01546   if ( !myScalingDlg )
01547     myScalingDlg = new OCCViewer_AxialScaleDlg( this );
01548   
01549   if ( !myScalingDlg->isVisible() )
01550     myScalingDlg->show();
01551 }
01552 
01556 void OCCViewer_ViewWindow::onGraduatedAxes()
01557 {
01558   myCubeAxesDlg->Update();
01559   myCubeAxesDlg->show();
01560 }
01561 
01562 void OCCViewer_ViewWindow::onAmbientToogle()
01563 {
01564   Handle(V3d_Viewer) viewer = myViewPort->getViewer();
01565   viewer->InitDefinedLights();
01566   while(viewer->MoreDefinedLights())
01567     {
01568       Handle(V3d_Light) light = viewer->DefinedLight();
01569       if(light->Type() != V3d_AMBIENT)
01570         {
01571           Handle(V3d_View) aView3d = myViewPort->getView();
01572           if( aView3d->IsActiveLight(light) ) viewer->SetLightOff(light);
01573           else viewer->SetLightOn(light);
01574         }
01575       viewer->NextDefinedLights();
01576     }
01577   viewer->Update();
01578 }
01579 
01583 void OCCViewer_ViewWindow::onMemorizeView()
01584 {
01585   appendViewAspect( getViewParams() );
01586 }
01587 
01591 void OCCViewer_ViewWindow::onRestoreView()
01592 {
01593   OCCViewer_CreateRestoreViewDlg* aDlg = new OCCViewer_CreateRestoreViewDlg( centralWidget(), this );
01594   connect( aDlg, SIGNAL( dlgOk() ), this, SLOT( setRestoreFlag() ) );
01595   aDlg->exec();
01596   updateViewAspects( aDlg->parameters() );
01597   if( myRestoreFlag && aDlg->parameters().count() )
01598     performRestoring( aDlg->currentItem() );
01599 }
01600 
01605 void OCCViewer_ViewWindow::performRestoring( const viewAspect& anItem, bool baseParamsOnly )
01606 {
01607   Handle(V3d_View) aView3d = myViewPort->getView();
01608 
01609   Standard_Boolean prev = aView3d->SetImmediateUpdate( Standard_False );
01610   aView3d->SetScale( anItem.scale );
01611   aView3d->SetCenter( anItem.centerX, anItem.centerY );
01612   aView3d->SetTwist( anItem.twist );
01613   aView3d->SetAt( anItem.atX, anItem.atY, anItem.atZ );
01614   aView3d->SetImmediateUpdate( prev );
01615   aView3d->SetEye( anItem.eyeX, anItem.eyeY, anItem.eyeZ );
01616   aView3d->SetProj( anItem.projX, anItem.projY, anItem.projZ );
01617   aView3d->SetAxialScale( anItem.scaleX, anItem.scaleY, anItem.scaleZ );
01618 
01619   if ( !baseParamsOnly ) {
01620 
01621     myModel->setTrihedronShown( anItem.isVisible );
01622     myModel->setTrihedronSize( anItem.size );
01623         
01624 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
01625     // graduated trihedron
01626     bool anIsVisible = anItem.gtIsVisible;
01627     OCCViewer_AxisWidget::AxisData anAxisData[3];
01628     anAxisData[0].DrawName = anItem.gtDrawNameX;
01629     anAxisData[1].DrawName = anItem.gtDrawNameZ;
01630     anAxisData[2].DrawName = anItem.gtDrawNameZ;
01631     anAxisData[0].Name = anItem.gtNameX;
01632     anAxisData[1].Name = anItem.gtNameZ;
01633     anAxisData[2].Name = anItem.gtNameZ;
01634     anAxisData[0].NameColor = QColor( anItem.gtNameColorRX,
01635                                   anItem.gtNameColorGX,
01636                                   anItem.gtNameColorBX );
01637     anAxisData[1].NameColor = QColor( anItem.gtNameColorRY,
01638                                   anItem.gtNameColorGY,
01639                                   anItem.gtNameColorBY );
01640     anAxisData[2].NameColor = QColor( anItem.gtNameColorRZ,
01641                                   anItem.gtNameColorGZ,
01642                                   anItem.gtNameColorBZ );
01643     anAxisData[0].DrawValues = anItem.gtDrawValuesX;
01644     anAxisData[1].DrawValues = anItem.gtDrawValuesY;
01645     anAxisData[2].DrawValues = anItem.gtDrawValuesZ;
01646     anAxisData[0].NbValues = anItem.gtNbValuesX;
01647     anAxisData[1].NbValues = anItem.gtNbValuesY;
01648     anAxisData[2].NbValues = anItem.gtNbValuesZ;
01649     anAxisData[0].Offset = anItem.gtOffsetX;
01650     anAxisData[1].Offset = anItem.gtOffsetY;
01651     anAxisData[2].Offset = anItem.gtOffsetZ;
01652     anAxisData[0].Color = QColor( anItem.gtColorRX,
01653                               anItem.gtColorGX,
01654                               anItem.gtColorBX );
01655     anAxisData[1].Color = QColor( anItem.gtColorRY,
01656                               anItem.gtColorGY,
01657                               anItem.gtColorBY );
01658     anAxisData[2].Color = QColor( anItem.gtColorRZ,
01659                               anItem.gtColorGZ,
01660                               anItem.gtColorBZ );
01661     anAxisData[0].DrawTickmarks = anItem.gtDrawTickmarksX;
01662     anAxisData[1].DrawTickmarks = anItem.gtDrawTickmarksY;
01663     anAxisData[2].DrawTickmarks = anItem.gtDrawTickmarksZ;
01664     anAxisData[0].TickmarkLength = anItem.gtTickmarkLengthX;
01665     anAxisData[1].TickmarkLength = anItem.gtTickmarkLengthY;
01666     anAxisData[2].TickmarkLength = anItem.gtTickmarkLengthZ;
01667 
01668     myCubeAxesDlg->SetData( anIsVisible, anAxisData );
01669     myCubeAxesDlg->ApplyData( aView3d );
01670 #endif
01671 
01672   } // if ( !baseParamsOnly )
01673 
01674   myRestoreFlag = 0;
01675 }
01676 
01680 void OCCViewer_ViewWindow::setRestoreFlag()
01681 {
01682   myRestoreFlag = 1;
01683 }
01684 
01688 void OCCViewer_ViewWindow::onTrihedronShow()
01689 {
01690   myModel->toggleTrihedron();
01691 }
01692 
01696 void OCCViewer_ViewWindow::onSwitchInteractionStyle( bool on )
01697 {
01698   myInteractionStyle = on ? (int)SUIT_ViewModel::KEY_FREE : (int)SUIT_ViewModel::STANDARD;
01699 
01700   // update action state if method is called outside
01701   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchInteractionStyleId ) );
01702   if ( a->isChecked() != on )
01703     a->setChecked( on );
01704 }
01705 
01709 void OCCViewer_ViewWindow::onSwitchZoomingStyle( bool on )
01710 {
01711   myViewPort->setAdvancedZoomingEnabled( on );
01712 
01713   // update action state if method is called outside
01714   QtxAction* a = dynamic_cast<QtxAction*>( toolMgr()->action( SwitchZoomingStyleId ) );
01715   if ( a->isChecked() != on )
01716     a->setChecked( on );
01717 }
01718 
01723 int OCCViewer_ViewWindow::interactionStyle() const
01724 {
01725   return myInteractionStyle;
01726 }
01727 
01732 void OCCViewer_ViewWindow::setInteractionStyle( const int theStyle )
01733 {
01734   onSwitchInteractionStyle( theStyle == (int)SUIT_ViewModel::KEY_FREE );
01735 }
01736 
01741 int OCCViewer_ViewWindow::zoomingStyle() const
01742 {
01743   return myViewPort->isAdvancedZoomingEnabled() ? 1 : 0;
01744 }
01745 
01750 void OCCViewer_ViewWindow::setZoomingStyle( const int theStyle )
01751 {
01752   onSwitchZoomingStyle( theStyle == 1 );
01753 }
01754 
01759 QImage OCCViewer_ViewWindow::dumpView()
01760 {
01761   Handle(V3d_View) view = myViewPort->getView();
01762   if ( view.IsNull() )
01763     return QImage();
01764   
01765   int aWidth = myViewPort->width();
01766   int aHeight = myViewPort->height();
01767   QApplication::syncX();
01768   view->Redraw(); // In order to reactivate GL context
01769   //view->Update();
01770 
01771   OpenGLUtils_FrameBuffer aFrameBuffer;
01772   if( aFrameBuffer.init( aWidth, aHeight ) )
01773   {
01774     QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
01775    
01776     glPushAttrib( GL_VIEWPORT_BIT );
01777     glViewport( 0, 0, aWidth, aHeight );
01778     aFrameBuffer.bind();
01779 
01780     // draw scene
01781     view->Redraw();
01782 
01783     aFrameBuffer.unbind();
01784     glPopAttrib();
01785 
01786     aFrameBuffer.bind();
01787     glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
01788     aFrameBuffer.unbind();
01789 
01790     anImage = anImage.rgbSwapped();
01791     anImage = anImage.mirrored();
01792     return anImage;
01793   }
01794   // if frame buffers are unsupported, use old functionality
01795   //view->Redraw();
01796 
01797   unsigned char* data = new unsigned char[ aWidth*aHeight*4 ];
01798 
01799   QPoint p = myViewPort->mapFromParent(myViewPort->geometry().topLeft());
01800 
01801   glReadPixels( p.x(), p.y(), aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE,
01802                 data);
01803 
01804   QImage anImage( data, aWidth, aHeight, QImage::Format_ARGB32 );
01805   anImage = anImage.mirrored();
01806   anImage = anImage.rgbSwapped();
01807   return anImage;
01808 }
01809 
01810 bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img, 
01811                                              const QString& fileName, 
01812                                              const QString& format )
01813 {
01814   if ( format != "PS" && format != "EPS")
01815     return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
01816 
01817   Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
01818 
01819   if (format == "PS")
01820     a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
01821   else if (format == "EPS")
01822     a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_EnhPostScript);
01823 
01824   return true;
01825 }
01826 
01827 
01828 QString OCCViewer_ViewWindow::filter() const
01829 {
01830   return tr( "OCC_IMAGE_FILES" );
01831 }
01832 
01833 
01844 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x,  const double y,  const double z,
01845                                             const double dx, const double dy, const double dz )
01846 {
01847   Handle(V3d_View) view = myViewPort->getView();
01848   if ( view.IsNull() )
01849     return;
01850 
01851   if ( on ) {
01852     Handle(V3d_Viewer) viewer = myViewPort->getViewer();
01853 
01854     // try to use already existing plane or create a new one
01855     Handle(V3d_Plane) clipPlane;
01856     view->InitActivePlanes();
01857 
01858     // calculate new a,b,c,d values for the plane
01859     gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
01860     double a, b, c, d;
01861     pln.Coefficients(a, b, c, d);
01862 
01863 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
01864     if (view->MoreActivePlanes()) {
01865       clipPlane = view->ActivePlane();
01866       clipPlane->SetPlane(a, b, c, d);
01867     }
01868     else
01869       clipPlane = new V3d_Plane (a, b, c, d);
01870 #else
01871     if (view->MoreActivePlanes())
01872       clipPlane = view->ActivePlane();
01873     else
01874       clipPlane = new V3d_Plane (viewer);
01875 
01876     clipPlane->SetPlane(a, b, c, d);
01877 #endif
01878 
01879     view->SetPlaneOn(clipPlane);
01880   }
01881   else
01882     view->SetPlaneOff();
01883 
01884   view->Update();
01885   view->Redraw();
01886 }
01887 
01888 void OCCViewer_ViewWindow::setCuttingPlane( bool on, const gp_Pln pln )
01889 {
01890   gp_Dir aDir = pln.Axis().Direction();
01891   gp_Pnt aPnt = pln.Location();
01892   setCuttingPlane(on, aPnt.X(), aPnt.Y(), aPnt.Z(), aDir.X(), aDir.Y(), aDir.Z());
01893 }
01894 
01895 
01900 bool OCCViewer_ViewWindow::isCuttingPlane()
01901 {
01902   Handle(V3d_View) view = myViewPort->getView();
01903   view->InitActivePlanes();
01904   return (view->MoreActivePlanes());
01905 }
01906 
01911 viewAspect OCCViewer_ViewWindow::getViewParams() const
01912 {
01913   double centerX, centerY, projX, projY, projZ, twist;
01914   double atX, atY, atZ, eyeX, eyeY, eyeZ;
01915   double aScaleX, aScaleY, aScaleZ;
01916 
01917   Handle(V3d_View) aView3d = myViewPort->getView();
01918 
01919   aView3d->Center( centerX, centerY );
01920   aView3d->Proj( projX, projY, projZ );
01921   aView3d->At( atX, atY, atZ );
01922   aView3d->Eye( eyeX, eyeY, eyeZ );
01923   twist = aView3d->Twist();
01924 
01925   aView3d->AxialScale(aScaleX,aScaleY,aScaleZ);
01926 
01927   bool isShown = myModel->isTrihedronVisible();
01928   double size = myModel->trihedronSize();
01929 
01930   QString aName = QTime::currentTime().toString() + QString::fromLatin1( " h:m:s" );
01931 
01932   viewAspect params;
01933   params.scale    = aView3d->Scale();
01934   params.centerX  = centerX;
01935   params.centerY  = centerY;
01936   params.projX    = projX;
01937   params.projY    = projY;
01938   params.projZ    = projZ;
01939   params.twist    = twist;
01940   params.atX      = atX;
01941   params.atY      = atY;
01942   params.atZ      = atZ;
01943   params.eyeX     = eyeX;
01944   params.eyeY     = eyeY;
01945   params.eyeZ     = eyeZ;
01946   params.scaleX   = aScaleX;
01947   params.scaleY   = aScaleY;
01948   params.scaleZ   = aScaleZ;
01949   params.name     = aName;
01950   params.isVisible= isShown;
01951   params.size     = size;
01952 
01953 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 and higher version
01954   // graduated trihedron
01955   bool anIsVisible = false;
01956   OCCViewer_AxisWidget::AxisData anAxisData[3];
01957   myCubeAxesDlg->GetData( anIsVisible, anAxisData );
01958 
01959   params.gtIsVisible = anIsVisible;
01960   params.gtDrawNameX = anAxisData[0].DrawName;
01961   params.gtDrawNameY = anAxisData[1].DrawName;
01962   params.gtDrawNameZ = anAxisData[2].DrawName;
01963   params.gtNameX = anAxisData[0].Name;
01964   params.gtNameY = anAxisData[1].Name;
01965   params.gtNameZ = anAxisData[2].Name;
01966   params.gtNameColorRX = anAxisData[0].NameColor.red();
01967   params.gtNameColorGX = anAxisData[0].NameColor.green();
01968   params.gtNameColorBX = anAxisData[0].NameColor.blue();
01969   params.gtNameColorRY = anAxisData[1].NameColor.red();
01970   params.gtNameColorGY = anAxisData[1].NameColor.green();
01971   params.gtNameColorBY = anAxisData[1].NameColor.blue();
01972   params.gtNameColorRZ = anAxisData[2].NameColor.red();
01973   params.gtNameColorGZ = anAxisData[2].NameColor.green();
01974   params.gtNameColorBZ = anAxisData[2].NameColor.blue();
01975   params.gtDrawValuesX = anAxisData[0].DrawValues;
01976   params.gtDrawValuesY = anAxisData[1].DrawValues;
01977   params.gtDrawValuesZ = anAxisData[2].DrawValues;
01978   params.gtNbValuesX = anAxisData[0].NbValues;
01979   params.gtNbValuesY = anAxisData[1].NbValues;
01980   params.gtNbValuesZ = anAxisData[2].NbValues;
01981   params.gtOffsetX = anAxisData[0].Offset;
01982   params.gtOffsetY = anAxisData[1].Offset;
01983   params.gtOffsetZ = anAxisData[2].Offset;
01984   params.gtColorRX = anAxisData[0].Color.red();
01985   params.gtColorGX = anAxisData[0].Color.green();
01986   params.gtColorBX = anAxisData[0].Color.blue();
01987   params.gtColorRY = anAxisData[1].Color.red();
01988   params.gtColorGY = anAxisData[1].Color.green();
01989   params.gtColorBY = anAxisData[1].Color.blue();
01990   params.gtColorRZ = anAxisData[2].Color.red();
01991   params.gtColorGZ = anAxisData[2].Color.green();
01992   params.gtColorBZ = anAxisData[2].Color.blue();
01993   params.gtDrawTickmarksX = anAxisData[0].DrawTickmarks;
01994   params.gtDrawTickmarksY = anAxisData[1].DrawTickmarks;
01995   params.gtDrawTickmarksZ = anAxisData[2].DrawTickmarks;
01996   params.gtTickmarkLengthX = anAxisData[0].TickmarkLength;
01997   params.gtTickmarkLengthY = anAxisData[1].TickmarkLength;
01998   params.gtTickmarkLengthZ = anAxisData[2].TickmarkLength;
01999 #endif
02000 
02001   return params;
02002 }
02003 
02004 
02009 QString OCCViewer_ViewWindow::getVisualParameters()
02010 {
02011   viewAspect params = getViewParams();
02012 
02013   QStringList data;
02014 
02015   data << QString( "scale=%1" )    .arg( params.scale,   0, 'e', 12 );
02016   data << QString( "centerX=%1" )  .arg( params.centerX, 0, 'e', 12 );
02017   data << QString( "centerY=%1" )  .arg( params.centerY, 0, 'e', 12 );
02018   data << QString( "projX=%1" )    .arg( params.projX,   0, 'e', 12 );
02019   data << QString( "projY=%1" )    .arg( params.projY,   0, 'e', 12 );
02020   data << QString( "projZ=%1" )    .arg( params.projZ,   0, 'e', 12 );
02021   data << QString( "twist=%1" )    .arg( params.twist,   0, 'e', 12 );
02022   data << QString( "atX=%1" )      .arg( params.atX,     0, 'e', 12 );
02023   data << QString( "atY=%1" )      .arg( params.atY,     0, 'e', 12 );
02024   data << QString( "atZ=%1" )      .arg( params.atZ,     0, 'e', 12 );
02025   data << QString( "eyeX=%1" )     .arg( params.eyeX,    0, 'e', 12 );
02026   data << QString( "eyeY=%1" )     .arg( params.eyeY,    0, 'e', 12 );
02027   data << QString( "eyeZ=%1" )     .arg( params.eyeZ,    0, 'e', 12 );
02028   data << QString( "scaleX=%1" )   .arg( params.scaleX,  0, 'e', 12 );
02029   data << QString( "scaleY=%1" )   .arg( params.scaleY,  0, 'e', 12 );
02030   data << QString( "scaleZ=%1" )   .arg( params.scaleZ,  0, 'e', 12 );
02031   data << QString( "isVisible=%1" ).arg( params.isVisible );
02032   data << QString( "size=%1" )     .arg( params.size,    0, 'f',  2 );
02033 
02034 #if OCC_VERSION_LARGE > 0x06030009 // available only with OCC-6.3-sp10 or newer version
02035   // graduated trihedron
02036   data << QString( "gtIsVisible=%1" )      .arg( params.gtIsVisible );
02037   data << QString( "gtDrawNameX=%1" )      .arg( params.gtDrawNameX );
02038   data << QString( "gtDrawNameY=%1" )      .arg( params.gtDrawNameY );
02039   data << QString( "gtDrawNameZ=%1" )      .arg( params.gtDrawNameZ );
02040   data << QString( "gtNameX=%1" )          .arg( params.gtNameX );
02041   data << QString( "gtNameY=%1" )          .arg( params.gtNameY );
02042   data << QString( "gtNameZ=%1" )          .arg( params.gtNameZ );
02043   data << QString( "gtNameColorRX=%1" )    .arg( params.gtNameColorRX );
02044   data << QString( "gtNameColorGX=%1" )    .arg( params.gtNameColorGX );
02045   data << QString( "gtNameColorBX=%1" )    .arg( params.gtNameColorBX );
02046   data << QString( "gtNameColorRY=%1" )    .arg( params.gtNameColorRY );
02047   data << QString( "gtNameColorGY=%1" )    .arg( params.gtNameColorGY );
02048   data << QString( "gtNameColorBY=%1" )    .arg( params.gtNameColorBY );
02049   data << QString( "gtNameColorRZ=%1" )    .arg( params.gtNameColorRZ );
02050   data << QString( "gtNameColorGZ=%1" )    .arg( params.gtNameColorGZ );
02051   data << QString( "gtNameColorBZ=%1" )    .arg( params.gtNameColorBZ );
02052   data << QString( "gtDrawValuesX=%1" )    .arg( params.gtDrawValuesX );
02053   data << QString( "gtDrawValuesY=%1" )    .arg( params.gtDrawValuesY );
02054   data << QString( "gtDrawValuesZ=%1" )    .arg( params.gtDrawValuesZ );
02055   data << QString( "gtNbValuesX=%1" )      .arg( params.gtNbValuesX );
02056   data << QString( "gtNbValuesY=%1" )      .arg( params.gtNbValuesY );
02057   data << QString( "gtNbValuesZ=%1" )      .arg( params.gtNbValuesZ );
02058   data << QString( "gtOffsetX=%1" )        .arg( params.gtOffsetX );
02059   data << QString( "gtOffsetY=%1" )        .arg( params.gtOffsetY );
02060   data << QString( "gtOffsetZ=%1" )        .arg( params.gtOffsetZ );
02061   data << QString( "gtColorRX=%1" )        .arg( params.gtColorRX );
02062   data << QString( "gtColorGX=%1" )        .arg( params.gtColorGX );
02063   data << QString( "gtColorBX=%1" )        .arg( params.gtColorBX );
02064   data << QString( "gtColorRY=%1" )        .arg( params.gtColorRY );
02065   data << QString( "gtColorGY=%1" )        .arg( params.gtColorGY );
02066   data << QString( "gtColorBY=%1" )        .arg( params.gtColorBY );
02067   data << QString( "gtColorRZ=%1" )        .arg( params.gtColorRZ );
02068   data << QString( "gtColorGZ=%1" )        .arg( params.gtColorGZ );
02069   data << QString( "gtColorBZ=%1" )        .arg( params.gtColorBZ );
02070   data << QString( "gtDrawTickmarksX=%1" ) .arg( params.gtDrawTickmarksX );
02071   data << QString( "gtDrawTickmarksY=%1" ) .arg( params.gtDrawTickmarksY );
02072   data << QString( "gtDrawTickmarksZ=%1" ) .arg( params.gtDrawTickmarksZ );
02073   data << QString( "gtTickmarkLengthX=%1" ).arg( params.gtTickmarkLengthX );
02074   data << QString( "gtTickmarkLengthY=%1" ).arg( params.gtTickmarkLengthY );
02075   data << QString( "gtTickmarkLengthZ=%1" ).arg( params.gtTickmarkLengthZ );
02076 #endif
02077   QString bg = Qtx::backgroundToString( background() ).replace( "=", "$" );
02078   data << QString( "background=%1" ).arg( bg );
02079 
02080   return data.join("*");
02081 }
02082 
02087 void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
02088 {
02089   viewAspect params;
02090 
02091   QStringList data = parameters.split( '*' );
02092   Qtx::BackgroundData bgData;
02093   if ( parameters.contains( '=' )  ) // new format - "scale=1.000e+00*centerX=0.000e+00..."
02094   {
02095     foreach( QString param, data ) {
02096       QString paramName  = param.section( '=', 0, 0 ).trimmed();
02097       QString paramValue = param.section( '=', 1, 1 ).trimmed();
02098       if      ( paramName == "scale" )             params.scale             = paramValue.toDouble();
02099       else if ( paramName == "centerX" )           params.centerX           = paramValue.toDouble();
02100       else if ( paramName == "centerY" )           params.centerY           = paramValue.toDouble();
02101       else if ( paramName == "projX" )             params.projX             = paramValue.toDouble();
02102       else if ( paramName == "projY" )             params.projY             = paramValue.toDouble();
02103       else if ( paramName == "projZ" )             params.projZ             = paramValue.toDouble();
02104       else if ( paramName == "twist" )             params.twist             = paramValue.toDouble();
02105       else if ( paramName == "atX" )               params.atX               = paramValue.toDouble();
02106       else if ( paramName == "atY" )               params.atY               = paramValue.toDouble();
02107       else if ( paramName == "atZ" )               params.atZ               = paramValue.toDouble();
02108       else if ( paramName == "eyeX" )              params.eyeX              = paramValue.toDouble();
02109       else if ( paramName == "eyeY" )              params.eyeY              = paramValue.toDouble();
02110       else if ( paramName == "eyeZ" )              params.eyeZ              = paramValue.toDouble();
02111       else if ( paramName == "scaleX" )            params.scaleX            = paramValue.toDouble();
02112       else if ( paramName == "scaleY" )            params.scaleY            = paramValue.toDouble();
02113       else if ( paramName == "scaleZ" )            params.scaleZ            = paramValue.toDouble();
02114       else if ( paramName == "isVisible" )         params.isVisible         = paramValue.toInt();
02115       else if ( paramName == "size" )              params.size              = paramValue.toDouble();
02116       // graduated trihedron
02117       else if ( paramName == "gtIsVisible" )       params.gtIsVisible       = paramValue.toInt();
02118       else if ( paramName == "gtDrawNameX" )       params.gtDrawNameX       = paramValue.toInt();
02119       else if ( paramName == "gtDrawNameY" )       params.gtDrawNameY       = paramValue.toInt();
02120       else if ( paramName == "gtDrawNameZ" )       params.gtDrawNameZ       = paramValue.toInt();
02121       else if ( paramName == "gtNameX" )           params.gtNameX           = paramValue;
02122       else if ( paramName == "gtNameY" )           params.gtNameY           = paramValue;
02123       else if ( paramName == "gtNameZ" )           params.gtNameZ           = paramValue;
02124       else if ( paramName == "gtNameColorRX" )     params.gtNameColorRX     = paramValue.toInt();
02125       else if ( paramName == "gtNameColorGX" )     params.gtNameColorGX     = paramValue.toInt();
02126       else if ( paramName == "gtNameColorBX" )     params.gtNameColorBX     = paramValue.toInt();
02127       else if ( paramName == "gtNameColorRY" )     params.gtNameColorRY     = paramValue.toInt();
02128       else if ( paramName == "gtNameColorGY" )     params.gtNameColorGY     = paramValue.toInt();
02129       else if ( paramName == "gtNameColorBY" )     params.gtNameColorBY     = paramValue.toInt();
02130       else if ( paramName == "gtNameColorRZ" )     params.gtNameColorRZ     = paramValue.toInt();
02131       else if ( paramName == "gtNameColorGZ" )     params.gtNameColorGZ     = paramValue.toInt();
02132       else if ( paramName == "gtNameColorBZ" )     params.gtNameColorBZ     = paramValue.toInt();
02133       else if ( paramName == "gtDrawValuesX" )     params.gtDrawValuesX     = paramValue.toInt();
02134       else if ( paramName == "gtDrawValuesY" )     params.gtDrawValuesY     = paramValue.toInt();
02135       else if ( paramName == "gtDrawValuesZ" )     params.gtDrawValuesZ     = paramValue.toInt();
02136       else if ( paramName == "gtNbValuesX" )       params.gtNbValuesX       = paramValue.toInt();
02137       else if ( paramName == "gtNbValuesY" )       params.gtNbValuesY       = paramValue.toInt();
02138       else if ( paramName == "gtNbValuesZ" )       params.gtNbValuesZ       = paramValue.toInt();
02139       else if ( paramName == "gtOffsetX" )         params.gtOffsetX         = paramValue.toInt();
02140       else if ( paramName == "gtOffsetY" )         params.gtOffsetY         = paramValue.toInt();
02141       else if ( paramName == "gtOffsetZ" )         params.gtOffsetZ         = paramValue.toInt();
02142       else if ( paramName == "gtColorRX" )         params.gtColorRX         = paramValue.toInt();
02143       else if ( paramName == "gtColorGX" )         params.gtColorGX         = paramValue.toInt();
02144       else if ( paramName == "gtColorBX" )         params.gtColorBX         = paramValue.toInt();
02145       else if ( paramName == "gtColorRY" )         params.gtColorRY         = paramValue.toInt();
02146       else if ( paramName == "gtColorGY" )         params.gtColorGY         = paramValue.toInt();
02147       else if ( paramName == "gtColorBY" )         params.gtColorBY         = paramValue.toInt();
02148       else if ( paramName == "gtColorRZ" )         params.gtColorRZ         = paramValue.toInt();
02149       else if ( paramName == "gtColorGZ" )         params.gtColorGZ         = paramValue.toInt();
02150       else if ( paramName == "gtColorBZ" )         params.gtColorBZ         = paramValue.toInt();
02151       else if ( paramName == "gtDrawTickmarksX" )  params.gtDrawTickmarksX  = paramValue.toInt();
02152       else if ( paramName == "gtDrawTickmarksY" )  params.gtDrawTickmarksY  = paramValue.toInt();
02153       else if ( paramName == "gtDrawTickmarksZ" )  params.gtDrawTickmarksZ  = paramValue.toInt();
02154       else if ( paramName == "gtTickmarkLengthX" ) params.gtTickmarkLengthX = paramValue.toInt();
02155       else if ( paramName == "gtTickmarkLengthY" ) params.gtTickmarkLengthY = paramValue.toInt();
02156       else if ( paramName == "gtTickmarkLengthZ" ) params.gtTickmarkLengthZ = paramValue.toInt();
02157       else if ( paramName == "background" )        {
02158        QString bg = paramValue.replace( "$", "=" );
02159        bgData = Qtx::stringToBackground( bg );
02160       }
02161     }
02162   }
02163   else // old format - "1.000e+00*0.000e+00..."
02164   {
02165     int idx = 0;
02166     params.scale     = data.count() > idx ? data[idx++].toDouble() : 1.0;
02167     params.centerX   = data.count() > idx ? data[idx++].toDouble() : 0.0;
02168     params.centerY   = data.count() > idx ? data[idx++].toDouble() : 0.0;
02169     params.projX     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
02170     params.projY     = data.count() > idx ? data[idx++].toDouble() : -sqrt(1./3);
02171     params.projZ     = data.count() > idx ? data[idx++].toDouble() : sqrt(1./3);
02172     params.twist     = data.count() > idx ? data[idx++].toDouble() : 0.0;
02173     params.atX       = data.count() > idx ? data[idx++].toDouble() : 0.0;
02174     params.atY       = data.count() > idx ? data[idx++].toDouble() : 0.0;
02175     params.atZ       = data.count() > idx ? data[idx++].toDouble() : 0.0;
02176     params.eyeX      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
02177     params.eyeY      = data.count() > idx ? data[idx++].toDouble() : -sqrt(250000./3);
02178     params.eyeZ      = data.count() > idx ? data[idx++].toDouble() : sqrt(250000./3);
02179     params.scaleX    = data.count() > idx ? data[idx++].toDouble() : 1.0;
02180     params.scaleY    = data.count() > idx ? data[idx++].toDouble() : 1.0;
02181     params.scaleZ    = data.count() > idx ? data[idx++].toDouble() : 1.0;
02182     params.isVisible = data.count() > idx ? data[idx++].toInt()    : 1;
02183     params.size      = data.count() > idx ? data[idx++].toDouble() : 100.0;
02184   }
02185   performRestoring( params );
02186   setBackground( bgData );
02187 }
02188 
02196 void OCCViewer_ViewWindow::showEvent( QShowEvent* theEvent )
02197 {
02198   emit Show( theEvent );
02199 }
02200 
02208 void OCCViewer_ViewWindow::hideEvent( QHideEvent* theEvent )
02209 {
02210   emit Hide( theEvent );
02211 }
02212 
02213 
02217 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::createSketcher( int type )
02218 {
02219   if ( type == Rect )
02220     return new OCCViewer_RectSketcher( this, type );
02221   if ( type == Polygon )
02222     return new OCCViewer_PolygonSketcher( this, type );
02223   return 0;
02224 }
02225 
02226 void OCCViewer_ViewWindow::initSketchers()
02227 {
02228   if ( mySketchers.isEmpty() )
02229   {
02230     mySketchers.append( createSketcher( Rect ) );
02231     mySketchers.append( createSketcher( Polygon ) );
02232   }
02233 }
02234 
02235 OCCViewer_ViewSketcher* OCCViewer_ViewWindow::getSketcher( const int typ )
02236 {
02237   OCCViewer_ViewSketcher* sketcher = 0;
02238   QList<OCCViewer_ViewSketcher*>::Iterator it;
02239   for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it )
02240   {
02241     OCCViewer_ViewSketcher* sk = (*it);
02242     if ( sk->type() == typ )
02243       sketcher = sk;
02244   }
02245   return sketcher;
02246 }
02247 
02251 void OCCViewer_ViewWindow::activateSketching( int type )
02252 {
02253   OCCViewer_ViewPort3d* vp = getViewPort();
02254   if ( !vp )
02255     return;
02256 
02257   if ( !vp->isSketchingEnabled() )
02258     return;
02259 
02260   /* Finish current sketching */
02261   if ( type == NoSketching )
02262   {
02263     if ( mypSketcher )
02264     {
02265       onSketchingFinished();
02266       mypSketcher->deactivate();
02267       mypSketcher = 0;
02268     }
02269   }
02270   /* Activate new sketching */
02271   else
02272   {
02273     activateSketching( NoSketching );  /* concurrency not suported */
02274     mypSketcher = getSketcher( type );
02275     if ( mypSketcher )
02276     {
02277       mypSketcher->activate();
02278       onSketchingStarted();
02279     }
02280   }
02281 }
02282 
02286 void OCCViewer_ViewWindow::onSketchingStarted()
02287 {
02288 }
02289 
02293 void OCCViewer_ViewWindow::onSketchingFinished()
02294 {
02295   MESSAGE("OCCViewer_ViewWindow::onSketchingFinished()")
02296   if ( mypSketcher && mypSketcher->result() == OCCViewer_ViewSketcher::Accept )
02297   {
02298     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
02299     bool append = bool( mypSketcher->buttonState() & Qt::ShiftModifier );
02300     switch( mypSketcher->type() )
02301     {
02302     case Rect:
02303       {
02304         QRect* aRect = (QRect*)mypSketcher->data();
02305         if( aRect )
02306         {
02307           int aLeft = aRect->left();
02308           int aRight = aRect->right();
02309           int aTop = aRect->top();
02310           int aBottom = aRect->bottom();
02311 //           myRect = aRect;
02312 
02313           if( append )
02314             ic->ShiftSelect( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
02315           else
02316             ic->Select( aLeft, aBottom, aRight, aTop, getViewPort()->getView(), Standard_False );
02317         }
02318       }
02319       break;
02320     case Polygon:
02321       {
02322         QPolygon* aPolygon = (QPolygon*)mypSketcher->data();
02323         if( aPolygon )
02324         {
02325           int size = aPolygon->size();
02326           TColgp_Array1OfPnt2d anArray( 1, size );
02327 
02328           QPolygon::Iterator it = aPolygon->begin();
02329           QPolygon::Iterator itEnd = aPolygon->end();
02330           for( int index = 1; it != itEnd; ++it, index++ )
02331           {
02332             QPoint aPoint = *it;
02333             anArray.SetValue( index, gp_Pnt2d( aPoint.x(), aPoint.y() ) );
02334           }
02335 
02336           if( append )
02337             ic->ShiftSelect( anArray, getViewPort()->getView(), Standard_False );
02338           else
02339             ic->Select( anArray, getViewPort()->getView(), Standard_False );
02340         }
02341       }
02342       break;
02343     default:
02344       break;
02345     }
02346 
02347     OCCViewer_ViewManager* aViewMgr = ( OCCViewer_ViewManager* )getViewManager();
02348     aViewMgr->getOCCViewer()->performSelectionChanged();
02349   }
02350 }
02351 
02352 OCCViewer_ViewPort3d* OCCViewer_ViewWindow::getViewPort()
02353 {
02354   return myViewPort;
02355 }
02356 
02357 bool OCCViewer_ViewWindow::transformRequested() const
02358 {
02359   return ( myOperation != NOTHING );
02360 }
02361 
02362 bool OCCViewer_ViewWindow::transformInProcess() const
02363 {
02364   return myEventStarted;
02365 }
02366 
02367 void OCCViewer_ViewWindow::setTransformInProcess( bool bOn )
02368 {
02369   myEventStarted = bOn;
02370 }
02371 
02375 void OCCViewer_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
02376 {
02377   if ( id != NOTHING ) myStatus.insert( id, on );
02378 }
02379 
02383 bool OCCViewer_ViewWindow::transformEnabled( const OperationType id ) const
02384 {
02385   return myStatus.contains( id ) ? myStatus[ id ] : true;
02386 }
02387 
02388 void OCCViewer_ViewWindow::onMaximizedView()
02389 {
02390   setMaximized(!isMaximized());
02391 }
02392 
02393 
02394 void OCCViewer_ViewWindow::setMaximized(bool toMaximize, bool toSendSignal)
02395 {
02396   QAction* anAction =  toolMgr()->action( MaximizedId );
02397   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
02398   if ( toMaximize ) {
02399     anAction->setText( tr( "MNU_MINIMIZE_VIEW" ) );  
02400     anAction->setToolTip( tr( "MNU_MINIMIZE_VIEW" ) );  
02401     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MINIMIZE" ) ) );
02402     anAction->setStatusTip( tr( "DSC_MINIMIZE_VIEW" ) );
02403     if (toSendSignal) {
02404       emit maximized( this, true );
02405     }
02406   }
02407   else {
02408     anAction->setText( tr( "MNU_MAXIMIZE_VIEW" ) );  
02409     anAction->setToolTip( tr( "MNU_MAXIMIZE_VIEW" ) );  
02410     anAction->setIcon( aResMgr->loadPixmap( "OCCViewer", tr( "ICON_OCCVIEWER_MAXIMIZE" ) ) );
02411     anAction->setStatusTip( tr( "DSC_MAXIMIZE_VIEW" ) );
02412     if (toSendSignal) {
02413       emit maximized( this, false );
02414     }
02415   }
02416 }
02417 
02418 
02419 bool OCCViewer_ViewWindow::isMaximized() const
02420 {
02421   return !(toolMgr()->action( MaximizedId )->text() == tr( "MNU_MAXIMIZE_VIEW" ));
02422 }
02423 
02424 void OCCViewer_ViewWindow::setSketcherStyle( bool enable )
02425 { 
02426   IsSketcherStyle = enable; 
02427 }
02428 
02429 bool OCCViewer_ViewWindow::isSketcherStyle() const 
02430 { 
02431   return IsSketcherStyle; 
02432 }
02433 
02434 
02435 void OCCViewer_ViewWindow::set2dMode(Mode2dType theType)
02436 {
02437   my2dMode = theType;
02438 }
02439 
02440 // obsolete   
02441 QColor OCCViewer_ViewWindow::backgroundColor() const
02442 {
02443   return myViewPort ? myViewPort->backgroundColor() : Qt::black;
02444 }
02445    
02446 // obsolete
02447 void OCCViewer_ViewWindow::setBackgroundColor( const QColor& theColor )
02448 {
02449   if ( myViewPort ) myViewPort->setBackgroundColor( theColor );
02450 }
02451 
02452 Qtx::BackgroundData OCCViewer_ViewWindow::background() const
02453 {
02454   return myViewPort ? myViewPort->background() : Qtx::BackgroundData();
02455 }
02456    
02457 void OCCViewer_ViewWindow::setBackground( const Qtx::BackgroundData& theBackground )
02458 {
02459   if ( myViewPort ) myViewPort->setBackground( theBackground );
02460 }
02461 
02465 void OCCViewer_ViewWindow::clearViewAspects()
02466 {
02467   myViewAspects.clear();
02468 }
02469 
02473 const viewAspectList& OCCViewer_ViewWindow::getViewAspects()
02474 {
02475   return myViewAspects;
02476 }
02477 
02482 void OCCViewer_ViewWindow::appendViewAspect( const viewAspect& aParams )
02483 {
02484   myViewAspects.append( aParams );
02485 }
02486 
02491 void OCCViewer_ViewWindow::updateViewAspects( const viewAspectList& aViewList )
02492 {
02493   myViewAspects = aViewList;
02494 }
02495 
02496 void OCCViewer_ViewWindow::synchronizeView( OCCViewer_ViewWindow* viewWindow, int id )
02497 {
02498   OCCViewer_ViewWindow* otherViewWindow = 0;
02499   QList<OCCViewer_ViewWindow*> compatibleViews;
02500 
02501   bool isSync = viewWindow->toolMgr()->action( SynchronizeId )->isChecked();
02502 
02503   int vwid = viewWindow->getId();
02504   
02505   SUIT_Application* app = SUIT_Session::session()->activeApplication();
02506   if ( !app ) return;
02507 
02508   QList<SUIT_ViewManager*> wmlist;
02509   app->viewManagers( viewWindow->getViewManager()->getType(), wmlist );
02510 
02511   foreach( SUIT_ViewManager* wm, wmlist ) {
02512     QVector<SUIT_ViewWindow*> vwlist = wm->getViews();
02513 
02514     foreach( SUIT_ViewWindow* vw, vwlist ) {
02515       OCCViewer_ViewWindow* occVW = dynamic_cast<OCCViewer_ViewWindow*>( vw );
02516       if ( !occVW ) continue;
02517 
02518       // check only compatible types
02519       occVW = occVW->getView( viewWindow->get2dMode() );
02520       if ( occVW ) {
02521        if ( occVW->getId() == id ) 
02522          otherViewWindow = occVW;
02523        else if ( occVW != viewWindow )
02524          compatibleViews.append( occVW );
02525       }
02526     }
02527   }
02528 
02529   if ( isSync && id ) {
02530     // remove all possible disconnections
02531     foreach( OCCViewer_ViewWindow* vw, compatibleViews ) {
02532       // disconnect target view
02533       vw->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), viewWindow->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02534       viewWindow->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), vw->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02535       if ( otherViewWindow ) {
02536        // disconnect source view
02537        vw->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), otherViewWindow->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02538        otherViewWindow->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), vw->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02539       }
02540       QAction* a = vw->toolMgr()->action( SynchronizeId );
02541       if ( a ) {
02542        int anid = a->data().toInt();
02543        if ( a->isChecked() && ( anid == id || anid == vwid ) ) {
02544          bool blocked = a->blockSignals( true );
02545          a->setChecked( false );
02546          a->blockSignals( blocked );
02547        }
02548       }
02549     }
02550     if ( otherViewWindow ) {
02551       // reconnect source and target view
02552       otherViewWindow->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), viewWindow->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02553       viewWindow->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), otherViewWindow->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02554       otherViewWindow->getViewPort()->connect( viewWindow->getViewPort(), SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02555       viewWindow->getViewPort()->connect( otherViewWindow->getViewPort(), SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02556       // synchronize target view with source view
02557       viewWindow->getViewPort()->synchronize( otherViewWindow->getViewPort() );
02558       viewWindow->toolMgr()->action( SynchronizeId )->setData( otherViewWindow->getId() );
02559       QAction* anOtherAcion = otherViewWindow->toolMgr()->action( SynchronizeId );
02560       if (anOtherAcion) {
02561         anOtherAcion->setData( viewWindow->getId() );
02562         if ( !anOtherAcion->isChecked() ) {
02563                bool blocked = anOtherAcion->blockSignals( true );
02564                anOtherAcion->setChecked( true );
02565                anOtherAcion->blockSignals( blocked );
02566         }
02567       }
02568     }
02569   }
02570   else if ( otherViewWindow ) {
02571     // reconnect source and target view
02572     otherViewWindow->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), viewWindow->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02573     viewWindow->getViewPort()->disconnect( SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ), otherViewWindow->getViewPort(), SLOT( synchronize( OCCViewer_ViewPort* ) ) );
02574     viewWindow->getViewPort()->synchronize( otherViewWindow->getViewPort() );
02575     viewWindow->toolMgr()->action( SynchronizeId )->setData( otherViewWindow->getId() );
02576     QAction* anOtherAcion = otherViewWindow->toolMgr()->action( SynchronizeId );
02577     if (anOtherAcion) {
02578       if ( anOtherAcion->data().toInt() == viewWindow->getId() && anOtherAcion->isChecked() ) {
02579         bool blocked = anOtherAcion->blockSignals( true );
02580         anOtherAcion->setChecked( false );
02581         anOtherAcion->blockSignals( blocked );
02582       }
02583     }
02584   }
02585 }
02586 
02590 void OCCViewer_ViewWindow::onSynchronizeView(bool checked)
02591 {
02592   QAction* a = qobject_cast<QAction*>( sender() );
02593   if ( a ) {
02594     synchronizeView( this, a->data().toInt() );
02595   }
02596 }
02597 
02601 void OCCViewer_ViewWindow::updateSyncViews()
02602 {
02603   QAction* anAction = toolMgr()->action( SynchronizeId );
02604   if ( anAction && anAction->menu() ) {
02605     int currentId = anAction->data().toInt();
02606     anAction->menu()->clear();
02607     SUIT_Application* app = SUIT_Session::session()->activeApplication();
02608     if ( app ) { 
02609       QList<SUIT_ViewManager*> wmlist;
02610       app->viewManagers( getViewManager()->getType(), wmlist );
02611       foreach( SUIT_ViewManager* wm, wmlist ) {
02612        QVector<SUIT_ViewWindow*> vwlist = wm->getViews();
02613        foreach ( SUIT_ViewWindow* vw, vwlist ) {
02614          OCCViewer_ViewWindow* occVW = dynamic_cast<OCCViewer_ViewWindow*>( vw );
02615          if ( !occVW || occVW == this ) continue;
02616          // list only compatible types
02617          OCCViewer_ViewWindow* subWindow = occVW->getView( get2dMode() );
02618          if ( subWindow && subWindow != this ) {
02619            QAction* a = anAction->menu()->addAction( occVW->windowTitle() );
02620            if ( subWindow->getId() == currentId ) {
02621              QFont f = a->font();
02622              f.setBold( true );
02623              a->setFont( f );
02624            }
02625            a->setData( subWindow->getId() );
02626            connect( a, SIGNAL( triggered(bool) ), this, SLOT( onSynchronizeView(bool) ) );
02627          }
02628        }
02629       }
02630     }
02631     if ( anAction->menu()->actions().isEmpty() ) {
02632       anAction->setData( 0 );
02633       anAction->menu()->addAction( tr( "MNU_SYNC_NO_VIEW" ) );
02634     }
02635   }
02636 }