Back to index

salome-gui  6.5.0
Plot2d_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   : Plot2d_ViewWindow.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #include "Plot2d_ViewWindow.h"
00027 #include "Plot2d_ViewFrame.h"
00028 
00029 #include <SUIT_ViewManager.h>
00030 #include <SUIT_ResourceMgr.h>
00031 #include <SUIT_Session.h>
00032 #include <SUIT_Desktop.h>
00033 #include <SUIT_MessageBox.h>
00034 
00035 #include <Qtx.h>
00036 #include <QtxAction.h>
00037 #include <QtxMultiAction.h>
00038 #include <QtxActionToolMgr.h>
00039 
00040 #include <QStatusBar>
00041 #include <QLayout>
00042 #include <QApplication>
00043 #include <QMenu>
00044 #include <QImage>
00045 #include <QToolBar>
00046 #include <QPaintEvent>
00047 #include <QActionGroup>
00048 #include <QPainter>
00049 #include <QPrinter>
00050 #include <QPrintDialog>
00051 
00052 #include <qwt_plot_curve.h>
00053 
00064 Plot2d_ViewWindow::Plot2d_ViewWindow( SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel )
00065 : SUIT_ViewWindow( theDesktop )
00066 {
00067   myModel = theModel;
00068 }
00069 
00073 Plot2d_ViewWindow::~Plot2d_ViewWindow()
00074 {
00075 }
00076 
00080 void Plot2d_ViewWindow::initLayout()
00081 {
00082   myDumpImage = QImage();
00083   myViewFrame = new Plot2d_ViewFrame( this, "plotView" );
00084   setCentralWidget( myViewFrame );
00085 
00086   createActions();
00087   createToolBar();
00088 
00089   connect( myViewFrame, SIGNAL( vpModeHorChanged() ), this, SLOT( onChangeHorMode() ) );
00090   connect( myViewFrame, SIGNAL( vpModeVerChanged() ), this, SLOT( onChangeVerMode() ) );
00091   connect( myViewFrame, SIGNAL( vpNormLModeChanged() ), this, SLOT( onChangeNormLMode() ) );
00092   connect( myViewFrame, SIGNAL( vpNormRModeChanged() ), this, SLOT( onChangeNormRMode() ) );
00093   connect( myViewFrame, SIGNAL( vpCurveChanged() ),   this, SLOT( onChangeCurveMode() ) );
00094   connect( myViewFrame, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ),
00095            this,        SIGNAL( contextMenuRequested( QContextMenuEvent* ) ) );
00096 
00097   myViewFrame->installEventFilter( this );
00098 }
00099 
00104 Plot2d_Viewer* Plot2d_ViewWindow::getModel()
00105 {
00106   return myModel;
00107 }
00108 
00113 void Plot2d_ViewWindow::putInfo( const QString& theMsg )
00114 {
00115   QStatusBar* aStatusBar = myDesktop->statusBar();
00116   aStatusBar->showMessage( theMsg/*, 3000*/ );
00117 }
00118 
00123 Plot2d_ViewFrame* Plot2d_ViewWindow::getViewFrame()
00124 { 
00125   return myViewFrame;
00126 }
00127 
00132 QToolBar* Plot2d_ViewWindow::getToolBar()
00133 {
00134   return toolMgr()->toolBar( myToolBar );
00135 }
00136 
00141 void Plot2d_ViewWindow::contextMenuPopup( QMenu* thePopup )
00142 {
00143   QtxActionToolMgr* mgr = toolMgr();
00144   // scaling
00145   QMenu* scalingPopup = thePopup->addMenu( tr( "SCALING_POPUP" ) );
00146   scalingPopup->addAction( mgr->action( PModeXLinearId ) );
00147   scalingPopup->addAction( mgr->action( PModeXLogarithmicId ) );
00148   scalingPopup->addSeparator();
00149   scalingPopup->addAction( mgr->action( PModeYLinearId ) );
00150   scalingPopup->addAction( mgr->action( PModeYLogarithmicId ) );
00151 
00152   // fit data
00153   thePopup->addAction( tr( "TOT_PLOT2D_FITDATA" ), myViewFrame, SLOT( onFitData() ) );
00154 
00155   // curve type
00156   QMenu* curTypePopup = thePopup->addMenu( tr( "CURVE_TYPE_POPUP" ) );
00157   curTypePopup->addAction( mgr->action( CurvPointsId ) );
00158   curTypePopup->addAction( mgr->action( CurvLinesId ) );
00159   curTypePopup->addAction( mgr->action( CurvSplinesId ) );
00160 
00161   //Normalization type
00162   QMenu* normTypePopup = thePopup->addMenu( tr( "NORMALIZATION_TYPE_POPUP" ) );
00163   normTypePopup->addAction( mgr->action( PModeNormLMinId ) );
00164   normTypePopup->addAction( mgr->action( PModeNormLMaxId ) );
00165   normTypePopup->addSeparator();
00166   normTypePopup->addAction( mgr->action( PModeNormRMinId ) );
00167   normTypePopup->addAction( mgr->action( PModeNormRMaxId ) );
00168 
00169 
00170   // legend
00171   thePopup->addAction( mgr->action( LegendId ) );
00172 
00173   // settings
00174   thePopup->addAction( mgr->action( CurvSettingsId ) );
00175 }
00176 
00183 bool Plot2d_ViewWindow::eventFilter( QObject* watched, QEvent* e )
00184 {
00185   if ( watched == myViewFrame ) {
00186     switch( e->type() ) {
00187     case QEvent::MouseButtonPress:
00188       emit mousePressed( this, (QMouseEvent*)e );
00189       return true;
00190     case QEvent::MouseButtonRelease:
00191       emit mouseReleased( this, (QMouseEvent*)e );
00192       return true;
00193     case QEvent::MouseMove:
00194       emit mouseMoving( this, (QMouseEvent*)e );
00195       return true;
00196     default:
00197       break;
00198     }
00199   }
00200   return SUIT_ViewWindow::eventFilter( watched, e );
00201 }
00202 
00206 void Plot2d_ViewWindow::createActions()
00207 {
00208   QtxActionToolMgr* mgr = toolMgr();
00209   QtxAction* aAction;
00210   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00211 
00212   // 1. Dump View
00213   aAction = new QtxAction( tr( "MNU_DUMP_VIEW" ),
00214                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
00215                            tr( "MNU_DUMP_VIEW" ),
00216                            0, this);
00217   aAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
00218   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
00219   mgr->registerAction( aAction, DumpId );
00220 
00221   // 2. Scaling operations
00222 
00223   // 2.1. Fit All
00224   aAction = new QtxAction( tr( "MNU_FITALL" ),
00225                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
00226                            tr( "MNU_FITALL" ),
00227                            0, this);
00228   aAction->setStatusTip( tr( "DSC_FITALL" ) );
00229   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitAll() ) );
00230   mgr->registerAction( aAction, FitAllId );
00231 
00232   // 2.2. Fit Rect
00233   aAction = new QtxAction( tr( "MNU_FITRECT" ),
00234                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
00235                            tr( "MNU_FITRECT" ),
00236                            0, this);
00237   aAction->setStatusTip( tr( "DSC_FITRECT" ) );
00238   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitRect() ) );
00239   mgr->registerAction( aAction, FitRectId );
00240 
00241   // 2.3. Zoom
00242   aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
00243                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
00244                            tr( "MNU_ZOOM_VIEW" ),
00245                            0, this);
00246   aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
00247   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onZoom() ) );
00248   mgr->registerAction( aAction, ZoomId );
00249 
00250   // 2.4. Create multi-action for scaling operations
00251   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
00252   aScaleAction->insertAction( mgr->action( FitAllId  ) );
00253   aScaleAction->insertAction( mgr->action( FitRectId ) );
00254   aScaleAction->insertAction( mgr->action( ZoomId    ) );
00255   mgr->registerAction( aScaleAction, ScaleOpId );
00256 
00257   // 3. Moving operations
00258 
00259   // 3.1. Panning
00260   aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
00261                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
00262                            tr( "MNU_PAN_VIEW" ), 
00263                            0, this);
00264   aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
00265   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPanning() ) );
00266   mgr->registerAction( aAction, PanId );
00267 
00268   // 3.2. Global Panning
00269   aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
00270                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
00271                            tr( "MNU_GLOBALPAN_VIEW" ),
00272                            0, this);
00273   aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
00274   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onGlobalPanning() ) );
00275   mgr->registerAction( aAction, GlobalPanId );
00276 
00277   // 3.3. Create multi-action for moving operations
00278   QtxMultiAction* aPanAction = new QtxMultiAction( this );
00279   aPanAction->insertAction( mgr->action( PanId ) );
00280   aPanAction->insertAction( mgr->action( GlobalPanId ) );
00281   mgr->registerAction( aPanAction, MoveOpId );
00282 
00283   // 4. Curve type operations
00284   
00285   // 4.1. Points
00286   aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_POINTS" ),
00287                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_POINTS" ) ),
00288                            tr( "MEN_PLOT2D_CURVES_POINTS" ),
00289                            0, this );
00290   aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_POINTS" ) );
00291   aAction->setCheckable( true );
00292   mgr->registerAction( aAction, CurvPointsId );
00293 
00294   // 4.2. Lines
00295   aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_LINES" ),
00296                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_LINES" ) ),
00297                            tr( "MEN_PLOT2D_CURVES_LINES" ),
00298                            0, this );
00299   aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_LINES" ) );
00300   aAction->setCheckable( true );
00301   mgr->registerAction( aAction, CurvLinesId );
00302 
00303   // 4.3. Splines
00304   aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_SPLINES" ),
00305                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_SPLINES" ) ),
00306                            tr( "MEN_PLOT2D_CURVES_SPLINES" ),
00307                            0, this );
00308   aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_SPLINES" ) );
00309   aAction->setCheckable( true );
00310   mgr->registerAction( aAction, CurvSplinesId );
00311 
00312   // 4.4. Create action group for curve type operations
00313   QActionGroup* aCurveGroup = new QActionGroup( this );
00314   aCurveGroup->addAction( mgr->action( CurvPointsId ) );
00315   aCurveGroup->addAction( mgr->action( CurvLinesId ) );
00316   aCurveGroup->addAction( mgr->action( CurvSplinesId ) );
00317   connect( aCurveGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onCurves() ) );
00318 
00319   // 5. Horizontal scaling mode operations
00320 
00321   // 5.1. Linear
00322   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_HOR" ),
00323                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_HOR" ) ),
00324                            tr( "MEN_PLOT2D_MODE_LINEAR_HOR" ),
00325                            0, this );
00326   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
00327   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
00328   aAction->setCheckable( true );
00329   mgr->registerAction( aAction, PModeXLinearId );
00330   
00331   // 5.2. Logarithmic
00332   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" ),
00333                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" ) ),
00334                            tr( "MEN_PLOT2D_MODE_LOGARITHMIC_HOR" ),
00335                            0, this );
00336   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" ) );
00337   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
00338   aAction->setCheckable( true );
00339   mgr->registerAction( aAction, PModeXLogarithmicId );
00340 
00341   // 5.3. Create action group for horizontal scaling mode operations
00342   QActionGroup* aHorGroup = new QActionGroup( this );
00343   aHorGroup->addAction( mgr->action( PModeXLinearId ) );
00344   aHorGroup->addAction( mgr->action( PModeXLogarithmicId ) );
00345 
00346   // 6. Vertical scaling mode operations
00347 
00348   // 6.1. Linear
00349   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_VER" ),
00350                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_VER" ) ),
00351                            tr( "MEN_PLOT2D_MODE_LINEAR_VER" ),
00352                            0, this );
00353   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_VER" ) );
00354   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
00355   aAction->setCheckable( true );
00356   mgr->registerAction( aAction, PModeYLinearId );
00357 
00358   // 6.2. Logarithmic
00359   aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_VER" ),
00360                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_VER" ) ),
00361                            tr( "MEN_PLOT2D_MODE_LOGARITHMIC_VER" ),
00362                            0, this );
00363   aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_VER" ) );
00364   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
00365   aAction->setCheckable( true );
00366   mgr->registerAction( aAction, PModeYLogarithmicId );
00367 
00368   // 6.3. Create action group for vertical scaling mode operations
00369   QActionGroup* aVerGroup = new QActionGroup( this );
00370   aVerGroup->addAction( mgr->action( PModeYLinearId ) );
00371   aVerGroup->addAction( mgr->action( PModeYLogarithmicId ) );
00372 
00373   // 7. Normalization mode operations
00374 
00375   // 7.1. Normalize to the global minimum by left Y axis
00376   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_LMIN" ),
00377                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_LMIN" ) ),
00378                            tr( "MEN_PLOT2D_NORMALIZE_MODE_LMIN" ),
00379                            0, this );
00380   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_LMIN" ) );
00381   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormLMode() ) );
00382   aAction->setCheckable( true );
00383   mgr->registerAction( aAction, PModeNormLMinId );
00384 
00385   // 7.2. Normalize to the global maximum by right Y axis
00386   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_LMAX" ),
00387                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_LMAX" ) ),
00388                            tr( "MEN_PLOT2D_NORMALIZE_MODE_LMAX" ),
00389                            0, this );
00390   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_LMAX" ) );
00391   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormLMode() ) );
00392   aAction->setCheckable( true );
00393   mgr->registerAction( aAction, PModeNormLMaxId );
00394 
00395     // 7.3. Normalize to the global minimum by right Y axis
00396   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_RMIN" ),
00397                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_RMIN" ) ),
00398                            tr( "MEN_PLOT2D_NORMALIZE_MODE_RMIN" ),
00399                            0, this );
00400   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_RMIN" ) );
00401   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormRMode() ) );
00402   aAction->setCheckable( true );
00403   mgr->registerAction( aAction, PModeNormRMinId );
00404 
00405   // 7.4. Normalize to the global maximum by left Y axis
00406   aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_RMAX" ),
00407                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_RMAX" ) ),
00408                            tr( "MEN_PLOT2D_NORMALIZE_MODE_RMAX" ),
00409                            0, this );
00410   aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_RMAX" ) );
00411   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormRMode() ) );
00412   aAction->setCheckable( true );
00413   mgr->registerAction( aAction, PModeNormRMaxId );
00414 
00415   // 8. Legend
00416   aAction = new QtxAction( tr( "TOT_PLOT2D_SHOW_LEGEND" ),
00417                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SHOW_LEGEND" ) ),
00418                            tr( "MEN_PLOT2D_SHOW_LEGEND" ),
00419                            0, this );
00420   aAction->setStatusTip( tr( "PRP_PLOT2D_SHOW_LEGEND" ) );
00421   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onLegend() ) );
00422   aAction->setCheckable( true );
00423   mgr->registerAction( aAction, LegendId );
00424 
00425   // 9. Settings
00426   aAction = new QtxAction( tr( "TOT_PLOT2D_SETTINGS" ),
00427                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SETTINGS" ) ),
00428                            tr( "MEN_PLOT2D_SETTINGS" ),
00429                            0, this );
00430 
00431   aAction->setStatusTip( tr( "PRP_PLOT2D_SETTINGS" ) );
00432   connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) );
00433   mgr->registerAction( aAction, CurvSettingsId );
00434 
00435   // 9. Analytical curves
00436 #ifndef DISABLE_PYCONSOLE
00437   aAction = new QtxAction( tr( "TOT_PLOT2D_ANALYTICAL_CURVES" ),
00438                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ANALYTICAL_CURVES" ) ),
00439                            tr( "MEN_PLOT2D_ANALYTICAL_CURVES" ),
00440                            0, this );
00441 
00442   aAction->setStatusTip( tr( "PRP_PLOT2D_ANALYTICAL_CURVES" ) );
00443   connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onAnalyticalCurve() ) );
00444   mgr->registerAction( aAction, AnalyticalCurveId );
00445 #endif
00446 
00447   // 10. Clone
00448   aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ),
00449                            aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
00450                            tr( "MNU_CLONE_VIEW" ),
00451                            0, this);
00452   aAction->setStatusTip( tr( "DSC_CLONE_VIEW" ) );
00453   connect( aAction, SIGNAL( triggered( bool ) ), this, SIGNAL( cloneView() ) );
00454   mgr->registerAction( aAction, CloneId );
00455 
00456   // 11. Print 
00457   aAction = new QtxAction( tr( "MNU_PRINT_VIEW" ),
00458                         aResMgr->loadPixmap( "STD", tr( "ICON_PLOT2D_PRINT" ) ),
00459                            tr( "MNU_PRINT_VIEW" ),
00460                         0, this);
00461   aAction->setStatusTip( tr( "DSC_PRINT_VIEW" ) );
00462   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPrintView() ) );
00463   mgr->registerAction( aAction, PrintId );
00464 
00465   // Set initial values
00466   onChangeCurveMode();
00467   onChangeHorMode();
00468   onChangeVerMode();
00469   onChangeNormLMode();
00470   onChangeNormRMode();
00471   onChangeLegendMode();
00472 }
00473 
00477 void Plot2d_ViewWindow::createToolBar()
00478 {
00479   QtxActionToolMgr* mgr = toolMgr();
00480   myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ), false );
00481   mgr->append( DumpId, myToolBar );
00482   mgr->append( ScaleOpId, myToolBar );
00483   mgr->append( MoveOpId, myToolBar );
00484   mgr->append( toolMgr()->separator(), myToolBar );
00485   mgr->append( CurvPointsId, myToolBar );
00486   mgr->append( CurvLinesId, myToolBar );
00487   mgr->append( CurvSplinesId, myToolBar );
00488   mgr->append( toolMgr()->separator(), myToolBar );
00489   mgr->append( PModeNormLMaxId, myToolBar );
00490   mgr->append( PModeNormLMinId, myToolBar );
00491   mgr->append( toolMgr()->separator(), myToolBar );
00492   mgr->append( PModeNormRMaxId, myToolBar );
00493   mgr->append( PModeNormRMinId, myToolBar );
00494   mgr->append( toolMgr()->separator(), myToolBar );
00495   mgr->append( PModeXLinearId, myToolBar );
00496   mgr->append( PModeXLogarithmicId, myToolBar );
00497   mgr->append( toolMgr()->separator(), myToolBar );
00498   mgr->append( PModeYLinearId, myToolBar );
00499   mgr->append( PModeYLogarithmicId, myToolBar );
00500   mgr->append( toolMgr()->separator(), myToolBar );
00501   mgr->append( LegendId, myToolBar );
00502   mgr->append( CurvSettingsId, myToolBar );
00503   mgr->append( AnalyticalCurveId, myToolBar );
00504   mgr->append( CloneId, myToolBar );
00505   mgr->append( PrintId, myToolBar );
00506 }
00507 
00512 QString Plot2d_ViewWindow::getVisualParameters()
00513 {
00514   return myViewFrame->getVisualParameters();
00515 }
00516 
00521 void Plot2d_ViewWindow::setVisualParameters( const QString& parameters )
00522 {
00523   myViewFrame->setVisualParameters( parameters );
00524 }
00525 
00529 void Plot2d_ViewWindow::RefreshDumpImage()
00530 {
00531   QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
00532   myDumpImage = px.toImage();
00533 }
00534 
00538 void Plot2d_ViewWindow::onChangeHorMode()
00539 {
00540   bool aHorLinear = myViewFrame->isModeHorLinear();
00541   bool aVerLinear = myViewFrame->isModeVerLinear();
00542 
00543   if ( aHorLinear )
00544     toolMgr()->action( PModeXLinearId )->setChecked( true );
00545   else
00546     toolMgr()->action( PModeXLogarithmicId )->setChecked( true );
00547 
00548   toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
00549 }
00550 
00554 void Plot2d_ViewWindow::onChangeVerMode()
00555 {
00556   bool aHorLinear = myViewFrame->isModeHorLinear();
00557   bool aVerLinear = myViewFrame->isModeVerLinear();
00558 
00559   if ( aVerLinear )
00560     toolMgr()->action( PModeYLinearId )->setChecked( true );
00561   else
00562     toolMgr()->action( PModeYLogarithmicId )->setChecked( true );
00563 
00564   toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
00565 }
00566 
00570 void Plot2d_ViewWindow::onChangeNormLMode()
00571 {
00572   bool aNormMax = myViewFrame->isNormLMaxMode();
00573   bool aNormMin = myViewFrame->isNormLMinMode();
00574 
00575   if ( aNormMax )
00576     toolMgr()->action( PModeNormLMaxId )->setChecked( true );
00577   else
00578     toolMgr()->action( PModeNormLMaxId )->setChecked( false );
00579   if ( aNormMin )
00580     toolMgr()->action( PModeNormLMinId )->setChecked( true );
00581   else
00582     toolMgr()->action( PModeNormLMinId )->setChecked( false );
00583 }
00584 
00588 void Plot2d_ViewWindow::onChangeNormRMode()
00589 {
00590   bool aNormMax = myViewFrame->isNormRMaxMode();
00591   bool aNormMin = myViewFrame->isNormRMinMode();
00592 
00593   if ( aNormMax )
00594     toolMgr()->action( PModeNormRMaxId )->setChecked( true );
00595   else
00596     toolMgr()->action( PModeNormRMaxId )->setChecked( false );
00597   if ( aNormMin )
00598     toolMgr()->action( PModeNormRMinId )->setChecked( true );
00599   else
00600     toolMgr()->action( PModeNormRMinId )->setChecked( false );
00601 }
00602 
00606 void Plot2d_ViewWindow::onChangeCurveMode()
00607 {
00608   switch ( myViewFrame->getCurveType() ) {
00609   case 0:
00610     toolMgr()->action( CurvPointsId )->setChecked( true );
00611     break;
00612   case 1:
00613     toolMgr()->action( CurvLinesId )->setChecked( true );
00614     break;
00615   case 2:
00616     toolMgr()->action( CurvSplinesId )->setChecked( true );
00617     break;
00618   default:
00619     break;
00620   }
00621 }
00622 
00626 void Plot2d_ViewWindow::onChangeLegendMode()
00627 {
00628   toolMgr()->action( LegendId )->setChecked( myViewFrame->isLegendShow() );
00629 }
00630 
00634 void Plot2d_ViewWindow::onFitAll()
00635 {
00636   myViewFrame->onViewFitAll();
00637 }
00638 
00642 void Plot2d_ViewWindow::onFitRect()
00643 {
00644   myViewFrame->onViewFitArea();
00645 }
00646 
00650 void Plot2d_ViewWindow::onZoom()
00651 {
00652   myViewFrame->onViewZoom();
00653 }
00654 
00658 void Plot2d_ViewWindow::onPanning()
00659 {
00660   myViewFrame->onViewPan();
00661 }
00662 
00666 void Plot2d_ViewWindow::onGlobalPanning()
00667 {
00668   myViewFrame->onViewGlobalPan();
00669 }
00670 
00674 void Plot2d_ViewWindow::onViewHorMode()
00675 {
00676   myViewFrame->setHorScaleMode( toolMgr()->action( PModeXLinearId )->isChecked() ? 0 : 1 );
00677 }
00678 
00682 void Plot2d_ViewWindow::onViewVerMode()
00683 {
00684   myViewFrame->setVerScaleMode( toolMgr()->action( PModeYLinearId )->isChecked() ? 0 : 1 );
00685 }
00686 
00691 void Plot2d_ViewWindow::onViewNormLMode()
00692 {
00693   myViewFrame->setNormLMaxMode( toolMgr()->action( PModeNormLMaxId )->isChecked() ? true : false );
00694   myViewFrame->setNormLMinMode( toolMgr()->action( PModeNormLMinId )->isChecked() ? true : false );
00695 }
00696 
00701 void Plot2d_ViewWindow::onViewNormRMode()
00702 {
00703   myViewFrame->setNormRMaxMode( toolMgr()->action( PModeNormRMaxId )->isChecked() ? true : false );
00704   myViewFrame->setNormRMinMode( toolMgr()->action( PModeNormRMinId )->isChecked() ? true : false );
00705 }
00706 
00710 void Plot2d_ViewWindow::onLegend()
00711 {
00712   myViewFrame->showLegend( !myViewFrame->isLegendShow() );
00713   onChangeLegendMode();
00714 }
00715 
00719 void Plot2d_ViewWindow::onCurves()
00720 {
00721   if( toolMgr()->action( CurvPointsId )->isChecked() )
00722     myViewFrame->setCurveType( 0 );
00723   else if ( toolMgr()->action( CurvLinesId )->isChecked() )
00724     myViewFrame->setCurveType( 1 );
00725   else if ( toolMgr()->action( CurvSplinesId )->isChecked() )
00726     myViewFrame->setCurveType( 2 );
00727 }
00728  
00732 void Plot2d_ViewWindow::onDumpView()
00733 {
00734   qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ) ) );
00735   SUIT_ViewWindow::onDumpView();
00736 }
00737 
00742 QImage Plot2d_ViewWindow::dumpView()
00743 {
00744   if ( getToolBar()->underMouse() || myDumpImage.isNull() ) {
00745     QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
00746     return px.toImage();
00747   }
00748   
00749   return myDumpImage;
00750 }
00751 
00758 bool Plot2d_ViewWindow::dumpViewToFormat( const QImage&  img,
00759                                           const QString& fileName, 
00760                                           const QString& format )
00761 {
00762   bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
00763   if( !res )
00764     res = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
00765 
00766   return res;
00767 }
00768 
00773 QString Plot2d_ViewWindow::filter() const
00774 {
00775   QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts );
00776   filters << tr( "POSTSCRIPT_FILES" );
00777   filters << tr( "ENCAPSULATED_POSTSCRIPT_FILES" );
00778   return filters.join( ";;" );
00779 }
00780 
00784 void Plot2d_ViewWindow::onPrintView()
00785 {
00786   if ( !myViewFrame )
00787     return;
00788 
00789 #if !defined(WIN32) && !defined(QT_NO_CUPS)
00790 #if QT_VERSION < 0x040303
00791   if ( !Qtx::hasAnyPrinters() ) {
00792     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
00793                               tr( "WRN_NO_PRINTERS" ) );
00794     return;
00795   }
00796 #endif
00797 #endif
00798 
00799   // stored settings for further starts
00800   static QString aPrinterName;
00801   static int aColorMode = -1;
00802   static int anOrientation = -1;
00803 
00804   QPrinter aPrinter;
00805 
00806   // restore settinds from previous launching
00807 
00808   // printer name
00809   if ( !aPrinterName.isEmpty() )
00810     aPrinter.setPrinterName( aPrinterName );
00811   else 
00812   {
00813     // Nothing to do for the first printing. aPrinter contains default printer name by default
00814   }
00815 
00816   // color mode
00817   if ( aColorMode >= 0 )
00818     aPrinter.setColorMode( (QPrinter::ColorMode)aColorMode );
00819   else 
00820   {
00821     // Black-and-wight printers are often used
00822     aPrinter.setColorMode( QPrinter::GrayScale );
00823   }
00824 
00825   if ( anOrientation >= 0 )
00826     aPrinter.setOrientation( (QPrinter::Orientation)anOrientation );
00827   else
00828     aPrinter.setOrientation( QPrinter::Landscape );
00829 
00830   QPrintDialog printDlg( &aPrinter, this );
00831   printDlg.setPrintRange( QAbstractPrintDialog::AllPages );
00832   if ( printDlg.exec() != QDialog::Accepted ) 
00833     return;
00834 
00835   // store printer settings for further starts
00836   aPrinterName = aPrinter.printerName();
00837   aColorMode = aPrinter.colorMode();
00838   anOrientation = aPrinter.orientation();
00839   
00840   int W, H;
00841   QPainter aPainter;
00842 
00843   bool needColorCorrection = aPrinter.colorMode() == QPrinter::GrayScale;
00844 
00845   // work arround for printing on real printer
00846   if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape )
00847   {
00848     aPrinter.setFullPage( false );
00849     // set paper orientation and rotate painter
00850     aPrinter.setOrientation( QPrinter::Portrait );
00851 
00852     W = aPrinter.height();
00853     H = aPrinter.width();
00854 
00855     aPainter.begin( &aPrinter );
00856     aPainter.translate( QPoint( H, 0 ) );
00857     aPainter.rotate( 90 );
00858   }
00859   else 
00860   {
00861     aPrinter.setFullPage( false );
00862     aPainter.begin( &aPrinter );
00863     W = aPrinter.width();
00864     H = aPrinter.height();
00865   }
00866 
00867   QMap< QwtPlotCurve*, QPen > aCurvToPen;
00868   QMap< QwtPlotCurve*, QwtSymbol > aCurvToSymbol;
00869 
00870   if ( needColorCorrection )
00871   {
00872     // Iterate through, store temporary their parameters and assign 
00873     // parameters proper for printing
00874 
00875     CurveDict aCurveDict = myViewFrame->getCurves();
00876     CurveDict::iterator it;
00877     for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) 
00878     {
00879       QwtPlotCurve* aCurve = it.key();
00880       if ( !aCurve )
00881         continue;
00882 
00883       // pen
00884       QPen aPen = aCurve->pen();
00885       aCurvToPen[ aCurve ] = aPen;
00886 
00887       aPen.setColor( QColor( 0, 0, 0 ) );
00888       aPen.setWidthF( 1.5 );
00889 
00890       aCurve->setPen( aPen );
00891 
00892       // symbol
00893       QwtSymbol aSymbol = aCurve->symbol();
00894       aCurvToSymbol[ aCurve ] = aSymbol;
00895       aPen = aSymbol.pen();
00896       aPen.setColor( QColor( 0, 0, 0 ) );
00897       aPen.setWidthF( 1.5 );
00898       aSymbol.setPen( aPen );
00899 
00900       aCurve->setSymbol( aSymbol );
00901     }
00902   }
00903 
00904   myViewFrame->printPlot( &aPainter, QRect( 0, 0, W, H ) );
00905   aPainter.end();
00906 
00907   // restore old pens and symbols
00908   if ( needColorCorrection && !aCurvToPen.isEmpty() )
00909   {
00910     CurveDict aCurveDict = myViewFrame->getCurves();
00911     CurveDict::iterator it;
00912     for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ ) 
00913     {
00914       QwtPlotCurve* aCurve = it.key();
00915       if ( !aCurve || 
00916            !aCurvToPen.contains( aCurve ) ||
00917            !aCurvToSymbol.contains( aCurve ) )
00918         continue;
00919 
00920       aCurve->setPen( aCurvToPen[ aCurve ] );
00921       aCurve->setSymbol( aCurvToSymbol[ aCurve ] );
00922     }
00923   }
00924 }
00925