1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : Plot2d_ViewWindow.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "Plot2d_ViewWindow.h"
27 #include "Plot2d_ViewFrame.h"
29 #include <SUIT_ViewManager.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_MessageBox.h>
36 #include <QtxAction.h>
37 #include <QtxMultiAction.h>
38 #include <QtxActionToolMgr.h>
42 #include <QApplication>
46 #include <QPaintEvent>
47 #include <QActionGroup>
50 #include <QPrintDialog>
52 #include <qwt_plot_curve.h>
55 \class Plot2d_ViewWindow
56 \brief Plot2d view window.
61 \param theDesktop parent desktop window
62 \param theModel plt2d view model
64 Plot2d_ViewWindow::Plot2d_ViewWindow( SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel )
65 : SUIT_ViewWindow( theDesktop )
73 Plot2d_ViewWindow::~Plot2d_ViewWindow()
78 \brief Internal initialization.
80 void Plot2d_ViewWindow::initLayout()
82 myDumpImage = QImage();
83 myViewFrame = new Plot2d_ViewFrame( this, "plotView" );
84 setCentralWidget( myViewFrame );
89 connect( myViewFrame, SIGNAL( vpModeHorChanged() ), this, SLOT( onChangeHorMode() ) );
90 connect( myViewFrame, SIGNAL( vpModeVerChanged() ), this, SLOT( onChangeVerMode() ) );
91 connect( myViewFrame, SIGNAL( vpNormLModeChanged() ), this, SLOT( onChangeNormLMode() ) );
92 connect( myViewFrame, SIGNAL( vpNormRModeChanged() ), this, SLOT( onChangeNormRMode() ) );
93 connect( myViewFrame, SIGNAL( vpCurveChanged() ), this, SLOT( onChangeCurveMode() ) );
94 connect( myViewFrame, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ),
95 this, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ) );
97 myViewFrame->installEventFilter( this );
101 \brief Get view model.
102 \return Plot2d view model
104 Plot2d_Viewer* Plot2d_ViewWindow::getModel()
110 \brief Put message to the status bar.
111 \param theMsg message text
113 void Plot2d_ViewWindow::putInfo( const QString& theMsg )
115 QStatusBar* aStatusBar = myDesktop->statusBar();
116 aStatusBar->showMessage( theMsg/*, 3000*/ );
120 \brief Get view frame window.
121 \return view frame window
123 Plot2d_ViewFrame* Plot2d_ViewWindow::getViewFrame()
129 \brief Get view window's toolbar.
132 QToolBar* Plot2d_ViewWindow::getToolBar()
134 return toolMgr()->toolBar( myToolBar );
138 \brief Fill popup menu with the actions,
139 \param thePopup popup menu
141 void Plot2d_ViewWindow::contextMenuPopup( QMenu* thePopup )
143 QtxActionToolMgr* mgr = toolMgr();
145 QMenu* scalingPopup = thePopup->addMenu( tr( "SCALING_POPUP" ) );
146 scalingPopup->addAction( mgr->action( PModeXLinearId ) );
147 scalingPopup->addAction( mgr->action( PModeXLogarithmicId ) );
148 scalingPopup->addSeparator();
149 scalingPopup->addAction( mgr->action( PModeYLinearId ) );
150 scalingPopup->addAction( mgr->action( PModeYLogarithmicId ) );
153 thePopup->addAction( tr( "TOT_PLOT2D_FITDATA" ), myViewFrame, SLOT( onFitData() ) );
156 QMenu* curTypePopup = thePopup->addMenu( tr( "CURVE_TYPE_POPUP" ) );
157 curTypePopup->addAction( mgr->action( CurvPointsId ) );
158 curTypePopup->addAction( mgr->action( CurvLinesId ) );
159 curTypePopup->addAction( mgr->action( CurvSplinesId ) );
162 QMenu* normTypePopup = thePopup->addMenu( tr( "NORMALIZATION_TYPE_POPUP" ) );
163 normTypePopup->addAction( mgr->action( PModeNormLMinId ) );
164 normTypePopup->addAction( mgr->action( PModeNormLMaxId ) );
165 normTypePopup->addSeparator();
166 normTypePopup->addAction( mgr->action( PModeNormRMinId ) );
167 normTypePopup->addAction( mgr->action( PModeNormRMaxId ) );
171 thePopup->addAction( mgr->action( LegendId ) );
174 thePopup->addAction( mgr->action( CurvSettingsId ) );
178 \brief Custom event filter.
179 \param watched event receiver object
181 \return \c true if further event processing should be stopped
183 bool Plot2d_ViewWindow::eventFilter( QObject* watched, QEvent* e )
185 if ( watched == myViewFrame ) {
186 switch( e->type() ) {
187 case QEvent::MouseButtonPress:
188 emit mousePressed( this, (QMouseEvent*)e );
190 case QEvent::MouseButtonRelease:
191 emit mouseReleased( this, (QMouseEvent*)e );
193 case QEvent::MouseMove:
194 emit mouseMoving( this, (QMouseEvent*)e );
200 return SUIT_ViewWindow::eventFilter( watched, e );
204 \brief Create actions for the view window.
206 void Plot2d_ViewWindow::createActions()
208 QtxActionToolMgr* mgr = toolMgr();
210 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
213 aAction = new QtxAction( tr( "MNU_DUMP_VIEW" ),
214 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
215 tr( "MNU_DUMP_VIEW" ),
217 aAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
218 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
219 mgr->registerAction( aAction, DumpId );
221 // 2. Scaling operations
224 aAction = new QtxAction( tr( "MNU_FITALL" ),
225 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
228 aAction->setStatusTip( tr( "DSC_FITALL" ) );
229 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitAll() ) );
230 mgr->registerAction( aAction, FitAllId );
233 aAction = new QtxAction( tr( "MNU_FITRECT" ),
234 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
237 aAction->setStatusTip( tr( "DSC_FITRECT" ) );
238 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitRect() ) );
239 mgr->registerAction( aAction, FitRectId );
242 aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
243 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
244 tr( "MNU_ZOOM_VIEW" ),
246 aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
247 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onZoom() ) );
248 mgr->registerAction( aAction, ZoomId );
250 // 2.4. Create multi-action for scaling operations
251 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
252 aScaleAction->insertAction( mgr->action( FitAllId ) );
253 aScaleAction->insertAction( mgr->action( FitRectId ) );
254 aScaleAction->insertAction( mgr->action( ZoomId ) );
255 mgr->registerAction( aScaleAction, ScaleOpId );
257 // 3. Moving operations
260 aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
261 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
262 tr( "MNU_PAN_VIEW" ),
264 aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
265 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPanning() ) );
266 mgr->registerAction( aAction, PanId );
268 // 3.2. Global Panning
269 aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
270 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
271 tr( "MNU_GLOBALPAN_VIEW" ),
273 aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
274 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onGlobalPanning() ) );
275 mgr->registerAction( aAction, GlobalPanId );
277 // 3.3. Create multi-action for moving operations
278 QtxMultiAction* aPanAction = new QtxMultiAction( this );
279 aPanAction->insertAction( mgr->action( PanId ) );
280 aPanAction->insertAction( mgr->action( GlobalPanId ) );
281 mgr->registerAction( aPanAction, MoveOpId );
283 // 4. Curve type operations
286 aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_POINTS" ),
287 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_POINTS" ) ),
288 tr( "MEN_PLOT2D_CURVES_POINTS" ),
290 aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_POINTS" ) );
291 aAction->setCheckable( true );
292 mgr->registerAction( aAction, CurvPointsId );
295 aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_LINES" ),
296 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_LINES" ) ),
297 tr( "MEN_PLOT2D_CURVES_LINES" ),
299 aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_LINES" ) );
300 aAction->setCheckable( true );
301 mgr->registerAction( aAction, CurvLinesId );
304 aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_SPLINES" ),
305 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_SPLINES" ) ),
306 tr( "MEN_PLOT2D_CURVES_SPLINES" ),
308 aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_SPLINES" ) );
309 aAction->setCheckable( true );
310 mgr->registerAction( aAction, CurvSplinesId );
312 // 4.4. Create action group for curve type operations
313 QActionGroup* aCurveGroup = new QActionGroup( this );
314 aCurveGroup->addAction( mgr->action( CurvPointsId ) );
315 aCurveGroup->addAction( mgr->action( CurvLinesId ) );
316 aCurveGroup->addAction( mgr->action( CurvSplinesId ) );
317 connect( aCurveGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onCurves() ) );
319 // 5. Horizontal scaling mode operations
322 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_HOR" ),
323 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_HOR" ) ),
324 tr( "MEN_PLOT2D_MODE_LINEAR_HOR" ),
326 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
327 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
328 aAction->setCheckable( true );
329 mgr->registerAction( aAction, PModeXLinearId );
332 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" ),
333 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" ) ),
334 tr( "MEN_PLOT2D_MODE_LOGARITHMIC_HOR" ),
336 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" ) );
337 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
338 aAction->setCheckable( true );
339 mgr->registerAction( aAction, PModeXLogarithmicId );
341 // 5.3. Create action group for horizontal scaling mode operations
342 QActionGroup* aHorGroup = new QActionGroup( this );
343 aHorGroup->addAction( mgr->action( PModeXLinearId ) );
344 aHorGroup->addAction( mgr->action( PModeXLogarithmicId ) );
346 // 6. Vertical scaling mode operations
349 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_VER" ),
350 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_VER" ) ),
351 tr( "MEN_PLOT2D_MODE_LINEAR_VER" ),
353 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_VER" ) );
354 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
355 aAction->setCheckable( true );
356 mgr->registerAction( aAction, PModeYLinearId );
359 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_VER" ),
360 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_VER" ) ),
361 tr( "MEN_PLOT2D_MODE_LOGARITHMIC_VER" ),
363 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_VER" ) );
364 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
365 aAction->setCheckable( true );
366 mgr->registerAction( aAction, PModeYLogarithmicId );
368 // 6.3. Create action group for vertical scaling mode operations
369 QActionGroup* aVerGroup = new QActionGroup( this );
370 aVerGroup->addAction( mgr->action( PModeYLinearId ) );
371 aVerGroup->addAction( mgr->action( PModeYLogarithmicId ) );
373 // 7. Normalization mode operations
375 // 7.1. Normalize to the global minimum by left Y axis
376 aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_LMIN" ),
377 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_LMIN" ) ),
378 tr( "MEN_PLOT2D_NORMALIZE_MODE_LMIN" ),
380 aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_LMIN" ) );
381 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormLMode() ) );
382 aAction->setCheckable( true );
383 mgr->registerAction( aAction, PModeNormLMinId );
385 // 7.2. Normalize to the global maximum by right Y axis
386 aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_LMAX" ),
387 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_LMAX" ) ),
388 tr( "MEN_PLOT2D_NORMALIZE_MODE_LMAX" ),
390 aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_LMAX" ) );
391 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormLMode() ) );
392 aAction->setCheckable( true );
393 mgr->registerAction( aAction, PModeNormLMaxId );
395 // 7.3. Normalize to the global minimum by right Y axis
396 aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_RMIN" ),
397 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_RMIN" ) ),
398 tr( "MEN_PLOT2D_NORMALIZE_MODE_RMIN" ),
400 aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_RMIN" ) );
401 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormRMode() ) );
402 aAction->setCheckable( true );
403 mgr->registerAction( aAction, PModeNormRMinId );
405 // 7.4. Normalize to the global maximum by left Y axis
406 aAction = new QtxAction( tr( "TOT_PLOT2D_NORMALIZE_MODE_RMAX" ),
407 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_NORMALIZE_MODE_RMAX" ) ),
408 tr( "MEN_PLOT2D_NORMALIZE_MODE_RMAX" ),
410 aAction->setStatusTip( tr( "PRP_PLOT2D_NORMALIZE_MODE_RMAX" ) );
411 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewNormRMode() ) );
412 aAction->setCheckable( true );
413 mgr->registerAction( aAction, PModeNormRMaxId );
416 aAction = new QtxAction( tr( "TOT_PLOT2D_SHOW_LEGEND" ),
417 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SHOW_LEGEND" ) ),
418 tr( "MEN_PLOT2D_SHOW_LEGEND" ),
420 aAction->setStatusTip( tr( "PRP_PLOT2D_SHOW_LEGEND" ) );
421 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onLegend() ) );
422 aAction->setCheckable( true );
423 mgr->registerAction( aAction, LegendId );
426 aAction = new QtxAction( tr( "TOT_PLOT2D_SETTINGS" ),
427 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SETTINGS" ) ),
428 tr( "MEN_PLOT2D_SETTINGS" ),
431 aAction->setStatusTip( tr( "PRP_PLOT2D_SETTINGS" ) );
432 connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) );
433 mgr->registerAction( aAction, CurvSettingsId );
435 // 9. Analytical curves
436 aAction = new QtxAction( tr( "TOT_PLOT2D_ANALYTICAL_CURVES" ),
437 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ANALYTICAL_CURVES" ) ),
438 tr( "MEN_PLOT2D_ANALYTICAL_CURVES" ),
441 aAction->setStatusTip( tr( "PRP_PLOT2D_ANALYTICAL_CURVES" ) );
442 connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onAnalyticalCurve() ) );
443 mgr->registerAction( aAction, AnalyticalCurveId );
446 aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ),
447 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
448 tr( "MNU_CLONE_VIEW" ),
450 aAction->setStatusTip( tr( "DSC_CLONE_VIEW" ) );
451 connect( aAction, SIGNAL( triggered( bool ) ), this, SIGNAL( cloneView() ) );
452 mgr->registerAction( aAction, CloneId );
455 aAction = new QtxAction( tr( "MNU_PRINT_VIEW" ),
456 aResMgr->loadPixmap( "STD", tr( "ICON_PLOT2D_PRINT" ) ),
457 tr( "MNU_PRINT_VIEW" ),
459 aAction->setStatusTip( tr( "DSC_PRINT_VIEW" ) );
460 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPrintView() ) );
461 mgr->registerAction( aAction, PrintId );
463 // Set initial values
469 onChangeLegendMode();
473 \brief Create toolbar for the view window.
475 void Plot2d_ViewWindow::createToolBar()
477 QtxActionToolMgr* mgr = toolMgr();
478 myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ), // title (language-dependant)
479 QString( "Plot2dViewOperations" ), // name (language-independant)
480 false ); // disable floatable toolbar
481 mgr->append( DumpId, myToolBar );
482 mgr->append( ScaleOpId, myToolBar );
483 mgr->append( MoveOpId, myToolBar );
484 mgr->append( toolMgr()->separator(), myToolBar );
485 mgr->append( CurvPointsId, myToolBar );
486 mgr->append( CurvLinesId, myToolBar );
487 mgr->append( CurvSplinesId, myToolBar );
488 mgr->append( toolMgr()->separator(), myToolBar );
489 mgr->append( PModeNormLMaxId, myToolBar );
490 mgr->append( PModeNormLMinId, myToolBar );
491 mgr->append( toolMgr()->separator(), myToolBar );
492 mgr->append( PModeNormRMaxId, myToolBar );
493 mgr->append( PModeNormRMinId, myToolBar );
494 mgr->append( toolMgr()->separator(), myToolBar );
495 mgr->append( PModeXLinearId, myToolBar );
496 mgr->append( PModeXLogarithmicId, myToolBar );
497 mgr->append( toolMgr()->separator(), myToolBar );
498 mgr->append( PModeYLinearId, myToolBar );
499 mgr->append( PModeYLogarithmicId, myToolBar );
500 mgr->append( toolMgr()->separator(), myToolBar );
501 mgr->append( LegendId, myToolBar );
502 mgr->append( CurvSettingsId, myToolBar );
503 mgr->append( AnalyticalCurveId, myToolBar );
504 mgr->append( CloneId, myToolBar );
505 mgr->append( PrintId, myToolBar );
509 \brief Get the visual parameters of the view window.
510 \return visual parameters of this view window formatted to the string
512 QString Plot2d_ViewWindow::getVisualParameters()
514 return myViewFrame->getVisualParameters();
518 \brief Restore visual parameters of the view window from the formated string
519 \param parameters view window visual parameters
521 void Plot2d_ViewWindow::setVisualParameters( const QString& parameters )
523 myViewFrame->setVisualParameters( parameters );
527 \brief Grab the view window to the internal image.
529 void Plot2d_ViewWindow::RefreshDumpImage()
531 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
532 myDumpImage = px.toImage();
536 \brief Called when the scale mode for the horizontal axis is changed.
538 void Plot2d_ViewWindow::onChangeHorMode()
540 bool aHorLinear = myViewFrame->isModeHorLinear();
541 bool aVerLinear = myViewFrame->isModeVerLinear();
544 toolMgr()->action( PModeXLinearId )->setChecked( true );
546 toolMgr()->action( PModeXLogarithmicId )->setChecked( true );
548 toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
552 \brief Called when the scale mode for the vertical axis is changed.
554 void Plot2d_ViewWindow::onChangeVerMode()
556 bool aHorLinear = myViewFrame->isModeHorLinear();
557 bool aVerLinear = myViewFrame->isModeVerLinear();
560 toolMgr()->action( PModeYLinearId )->setChecked( true );
562 toolMgr()->action( PModeYLogarithmicId )->setChecked( true );
564 toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
568 \brief Called when the normalization mode (by left Y axis) for curves is changed.
570 void Plot2d_ViewWindow::onChangeNormLMode()
572 bool aNormMax = myViewFrame->isNormLMaxMode();
573 bool aNormMin = myViewFrame->isNormLMinMode();
576 toolMgr()->action( PModeNormLMaxId )->setChecked( true );
578 toolMgr()->action( PModeNormLMaxId )->setChecked( false );
580 toolMgr()->action( PModeNormLMinId )->setChecked( true );
582 toolMgr()->action( PModeNormLMinId )->setChecked( false );
586 \brief Called when the normalization mode (by left Y axis) for curves is changed.
588 void Plot2d_ViewWindow::onChangeNormRMode()
590 bool aNormMax = myViewFrame->isNormRMaxMode();
591 bool aNormMin = myViewFrame->isNormRMinMode();
594 toolMgr()->action( PModeNormRMaxId )->setChecked( true );
596 toolMgr()->action( PModeNormRMaxId )->setChecked( false );
598 toolMgr()->action( PModeNormRMinId )->setChecked( true );
600 toolMgr()->action( PModeNormRMinId )->setChecked( false );
604 \brief Called when the curve type is changed.
606 void Plot2d_ViewWindow::onChangeCurveMode()
608 switch ( myViewFrame->getCurveType() ) {
610 toolMgr()->action( CurvPointsId )->setChecked( true );
613 toolMgr()->action( CurvLinesId )->setChecked( true );
616 toolMgr()->action( CurvSplinesId )->setChecked( true );
624 \brief Called when the legend mode is changed.
626 void Plot2d_ViewWindow::onChangeLegendMode()
628 toolMgr()->action( LegendId )->setChecked( myViewFrame->isLegendShow() );
632 \brief Called when the "Fit all" action is activated.
634 void Plot2d_ViewWindow::onFitAll()
636 myViewFrame->onViewFitAll();
640 \brief Called when the "Fit rect" action is activated.
642 void Plot2d_ViewWindow::onFitRect()
644 myViewFrame->onViewFitArea();
648 \brief Called when the "Zoom" action is activated.
650 void Plot2d_ViewWindow::onZoom()
652 myViewFrame->onViewZoom();
656 \brief Called when the "Panning" action is activated.
658 void Plot2d_ViewWindow::onPanning()
660 myViewFrame->onViewPan();
664 \brief Called when the "Global panning" action is activated.
666 void Plot2d_ViewWindow::onGlobalPanning()
668 myViewFrame->onViewGlobalPan();
672 \brief Called when horizontal axis scale mode action is activated.
674 void Plot2d_ViewWindow::onViewHorMode()
676 myViewFrame->setHorScaleMode( toolMgr()->action( PModeXLinearId )->isChecked() ? 0 : 1 );
680 \brief Called when vertical axis scale mode action is activated.
682 void Plot2d_ViewWindow::onViewVerMode()
684 myViewFrame->setVerScaleMode( toolMgr()->action( PModeYLinearId )->isChecked() ? 0 : 1 );
688 \brief Called when normalization mode action (by left Y axis) is activated.
691 void Plot2d_ViewWindow::onViewNormLMode()
693 myViewFrame->setNormLMaxMode( toolMgr()->action( PModeNormLMaxId )->isChecked() ? true : false );
694 myViewFrame->setNormLMinMode( toolMgr()->action( PModeNormLMinId )->isChecked() ? true : false );
698 \brief Called when normalization mode action (by right Y axis) is activated.
701 void Plot2d_ViewWindow::onViewNormRMode()
703 myViewFrame->setNormRMaxMode( toolMgr()->action( PModeNormRMaxId )->isChecked() ? true : false );
704 myViewFrame->setNormRMinMode( toolMgr()->action( PModeNormRMinId )->isChecked() ? true : false );
708 \brief Called when the "Show legend" action is activated.
710 void Plot2d_ViewWindow::onLegend()
712 myViewFrame->showLegend( !myViewFrame->isLegendShow() );
713 onChangeLegendMode();
717 \brief Called when the "Change curve type" action is activated.
719 void Plot2d_ViewWindow::onCurves()
721 if( toolMgr()->action( CurvPointsId )->isChecked() )
722 myViewFrame->setCurveType( 0 );
723 else if ( toolMgr()->action( CurvLinesId )->isChecked() )
724 myViewFrame->setCurveType( 1 );
725 else if ( toolMgr()->action( CurvSplinesId )->isChecked() )
726 myViewFrame->setCurveType( 2 );
730 \brief Called when the "Dump view" action is activated.
732 void Plot2d_ViewWindow::onDumpView()
734 qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ) ) );
735 SUIT_ViewWindow::onDumpView();
739 \brief Dump the contents of the view window to the image.
740 \return image, containing all scene rendered in the window
742 QImage Plot2d_ViewWindow::dumpView()
744 if ( getToolBar()->underMouse() || myDumpImage.isNull() ) {
745 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
753 \brief Dump scene rendered in the view window to the file.
755 \param fileName name of file
756 \param format image format ("BMP" [default], "JPEG", "JPG", "PNG")
758 bool Plot2d_ViewWindow::dumpViewToFormat( const QImage& img,
759 const QString& fileName,
760 const QString& format )
762 bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
764 res = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
770 \brief Get supported image files wildcards.
771 \return image files wildcards (list of wildcards, separated by ";;")
773 QString Plot2d_ViewWindow::filter() const
775 QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts );
776 filters << tr( "PDF_FILES" );
777 filters << tr( "POSTSCRIPT_FILES" );
778 filters << tr( "ENCAPSULATED_POSTSCRIPT_FILES" );
779 return filters.join( ";;" );
783 \brief Called when the "Print view" action is activated.
785 void Plot2d_ViewWindow::onPrintView()
790 // stored settings for further starts
791 static QString aPrinterName;
792 static int aColorMode = -1;
793 static int anOrientation = -1;
797 // restore settinds from previous launching
800 if ( !aPrinterName.isEmpty() )
801 aPrinter.setPrinterName( aPrinterName );
804 // Nothing to do for the first printing. aPrinter contains default printer name by default
808 if ( aColorMode >= 0 )
809 aPrinter.setColorMode( (QPrinter::ColorMode)aColorMode );
812 // Black-and-wight printers are often used
813 aPrinter.setColorMode( QPrinter::GrayScale );
816 if ( anOrientation >= 0 )
817 aPrinter.setOrientation( (QPrinter::Orientation)anOrientation );
819 aPrinter.setOrientation( QPrinter::Landscape );
821 QPrintDialog printDlg( &aPrinter, this );
822 printDlg.setPrintRange( QAbstractPrintDialog::AllPages );
823 if ( printDlg.exec() != QDialog::Accepted )
826 // store printer settings for further starts
827 aPrinterName = aPrinter.printerName();
828 aColorMode = aPrinter.colorMode();
829 anOrientation = aPrinter.orientation();
834 bool needColorCorrection = aPrinter.colorMode() == QPrinter::GrayScale;
836 // work arround for printing on real printer
837 if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape )
839 aPrinter.setFullPage( false );
840 // set paper orientation and rotate painter
841 aPrinter.setOrientation( QPrinter::Portrait );
843 W = aPrinter.height();
844 H = aPrinter.width();
846 aPainter.begin( &aPrinter );
847 aPainter.translate( QPoint( H, 0 ) );
848 aPainter.rotate( 90 );
852 aPrinter.setFullPage( false );
853 aPainter.begin( &aPrinter );
854 W = aPrinter.width();
855 H = aPrinter.height();
858 QMap< QwtPlotCurve*, QPen > aCurvToPen;
859 QMap< QwtPlotCurve*, QwtSymbol* > aCurvToSymbol;
861 if ( needColorCorrection )
863 // Iterate through, store temporary their parameters and assign
864 // parameters proper for printing
866 CurveDict aCurveDict = myViewFrame->getCurves();
867 CurveDict::iterator it;
868 for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ )
870 QwtPlotCurve* aCurve = it.key();
875 QPen aPen = aCurve->pen();
876 aCurvToPen[ aCurve ] = aPen;
878 aPen.setColor( QColor( 0, 0, 0 ) );
879 aPen.setWidthF( 1.5 );
881 aCurve->setPen( aPen );
884 QwtSymbol* aSymbol = const_cast<QwtSymbol*>( aCurve->symbol() );
885 aCurvToSymbol[ aCurve ] = aSymbol;
886 aPen = aSymbol->pen();
887 aPen.setColor( QColor( 0, 0, 0 ) );
888 aPen.setWidthF( 1.5 );
889 aSymbol->setPen( aPen );
891 aCurve->setSymbol( aSymbol );
895 myViewFrame->printPlot( &aPainter, QRect( 0, 0, W, H ) );
898 // restore old pens and symbols
899 if ( needColorCorrection && !aCurvToPen.isEmpty() )
901 CurveDict aCurveDict = myViewFrame->getCurves();
902 CurveDict::iterator it;
903 for ( it = aCurveDict.begin(); it != aCurveDict.end(); it++ )
905 QwtPlotCurve* aCurve = it.key();
907 !aCurvToPen.contains( aCurve ) ||
908 !aCurvToSymbol.contains( aCurve ) )
911 aCurve->setPen( aCurvToPen[ aCurve ] );
912 aCurve->setSymbol( aCurvToSymbol[ aCurve ] );
918 \fn void Plot2d_ViewWindow::cloneView();
919 \brief Emitted when the "Clone View" action is activated.