1 // Copyright (C) 2007-2008 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.
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
22 // File : Plot2d_ViewWindow.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "Plot2d_ViewWindow.h"
26 #include "Plot2d_ViewFrame.h"
28 #include <SUIT_ViewManager.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_Desktop.h>
33 #include <QtxAction.h>
34 #include <QtxMultiAction.h>
35 #include <QtxActionToolMgr.h>
39 #include <QApplication>
43 #include <QPaintEvent>
44 #include <QActionGroup>
47 \class Plot2d_ViewWindow
48 \brief Plot2d view window.
53 \param theDesktop parent desktop window
54 \param theModel plt2d view model
56 Plot2d_ViewWindow::Plot2d_ViewWindow( SUIT_Desktop* theDesktop, Plot2d_Viewer* theModel )
57 : SUIT_ViewWindow( theDesktop )
60 myDumpImage = QImage();
62 myViewFrame = new Plot2d_ViewFrame( this, "plotView" );
63 setCentralWidget( myViewFrame );
68 connect( myViewFrame, SIGNAL( vpModeHorChanged() ), this, SLOT( onChangeHorMode() ) );
69 connect( myViewFrame, SIGNAL( vpModeVerChanged() ), this, SLOT( onChangeVerMode() ) );
70 connect( myViewFrame, SIGNAL( vpCurveChanged() ), this, SLOT( onChangeCurveMode() ) );
71 connect( myViewFrame, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ),
72 this, SIGNAL( contextMenuRequested( QContextMenuEvent* ) ) );
74 myViewFrame->installEventFilter( this );
80 Plot2d_ViewWindow::~Plot2d_ViewWindow()
85 \brief Get view model.
86 \return Plot2d view model
88 Plot2d_Viewer* Plot2d_ViewWindow::getModel()
94 \brief Put message to the status bar.
95 \param theMsg message text
97 void Plot2d_ViewWindow::putInfo( const QString& theMsg )
99 QStatusBar* aStatusBar = myDesktop->statusBar();
100 aStatusBar->showMessage( theMsg/*, 3000*/ );
104 \brief Get view frame window.
105 \return view frame window
107 Plot2d_ViewFrame* Plot2d_ViewWindow::getViewFrame()
113 \brief Get view window's toolbar.
116 QToolBar* Plot2d_ViewWindow::getToolBar()
118 return toolMgr()->toolBar( myToolBar );
122 \brief Fill popup menu with the actions,
123 \param thePopup popup menu
125 void Plot2d_ViewWindow::contextMenuPopup( QMenu* thePopup )
127 QtxActionToolMgr* mgr = toolMgr();
129 QMenu* scalingPopup = thePopup->addMenu( tr( "SCALING_POPUP" ) );
130 scalingPopup->addAction( mgr->action( PModeXLinearId ) );
131 scalingPopup->addAction( mgr->action( PModeXLogarithmicId ) );
132 scalingPopup->addSeparator();
133 scalingPopup->addAction( mgr->action( PModeYLinearId ) );
134 scalingPopup->addAction( mgr->action( PModeYLogarithmicId ) );
137 thePopup->addAction( tr( "TOT_PLOT2D_FITDATA" ), myViewFrame, SLOT( onFitData() ) );
140 QMenu* curTypePopup = thePopup->addMenu( tr( "CURVE_TYPE_POPUP" ) );
141 curTypePopup->addAction( mgr->action( CurvPointsId ) );
142 curTypePopup->addAction( mgr->action( CurvLinesId ) );
143 curTypePopup->addAction( mgr->action( CurvSplinesId ) );
146 thePopup->addAction( mgr->action( LegendId ) );
149 thePopup->addAction( mgr->action( CurvSettingsId ) );
153 \brief Custom event filter.
154 \param watched event receiver object
156 \return \c true if further event processing should be stopped
158 bool Plot2d_ViewWindow::eventFilter( QObject* watched, QEvent* e )
160 if ( watched == myViewFrame ) {
161 switch( e->type() ) {
162 case QEvent::MouseButtonPress:
163 emit mousePressed( this, (QMouseEvent*)e );
165 case QEvent::MouseButtonRelease:
166 emit mouseReleased( this, (QMouseEvent*)e );
168 case QEvent::MouseMove:
169 emit mouseMoving( this, (QMouseEvent*)e );
175 return SUIT_ViewWindow::eventFilter( watched, e );
179 \brief Create actions for the view window.
181 void Plot2d_ViewWindow::createActions()
183 QtxActionToolMgr* mgr = toolMgr();
185 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
188 aAction = new QtxAction( tr( "MNU_DUMP_VIEW" ),
189 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_DUMP" ) ),
190 tr( "MNU_DUMP_VIEW" ),
192 aAction->setStatusTip( tr( "DSC_DUMP_VIEW" ) );
193 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onDumpView() ) );
194 mgr->registerAction( aAction, DumpId );
196 // 2. Scaling operations
199 aAction = new QtxAction( tr( "MNU_FITALL" ),
200 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_ALL" ) ),
203 aAction->setStatusTip( tr( "DSC_FITALL" ) );
204 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitAll() ) );
205 mgr->registerAction( aAction, FitAllId );
208 aAction = new QtxAction( tr( "MNU_FITRECT" ),
209 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_FIT_AREA" ) ),
212 aAction->setStatusTip( tr( "DSC_FITRECT" ) );
213 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onFitRect() ) );
214 mgr->registerAction( aAction, FitRectId );
217 aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
218 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_ZOOM" ) ),
219 tr( "MNU_ZOOM_VIEW" ),
221 aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
222 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onZoom() ) );
223 mgr->registerAction( aAction, ZoomId );
225 // 2.4. Create multi-action for scaling operations
226 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
227 aScaleAction->insertAction( mgr->action( FitAllId ) );
228 aScaleAction->insertAction( mgr->action( FitRectId ) );
229 aScaleAction->insertAction( mgr->action( ZoomId ) );
230 mgr->registerAction( aScaleAction, ScaleOpId );
232 // 3. Moving operations
235 aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
236 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_PAN" ) ),
237 tr( "MNU_PAN_VIEW" ),
239 aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
240 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onPanning() ) );
241 mgr->registerAction( aAction, PanId );
243 // 3.2. Global Panning
244 aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
245 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_GLOBALPAN" ) ),
246 tr( "MNU_GLOBALPAN_VIEW" ),
248 aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
249 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onGlobalPanning() ) );
250 mgr->registerAction( aAction, GlobalPanId );
252 // 3.3. Create multi-action for moving operations
253 QtxMultiAction* aPanAction = new QtxMultiAction( this );
254 aPanAction->insertAction( mgr->action( PanId ) );
255 aPanAction->insertAction( mgr->action( GlobalPanId ) );
256 mgr->registerAction( aPanAction, MoveOpId );
258 // 4. Curve type operations
261 aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_POINTS" ),
262 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_POINTS" ) ),
263 tr( "MEN_PLOT2D_CURVES_POINTS" ),
265 aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_POINTS" ) );
266 aAction->setCheckable( true );
267 mgr->registerAction( aAction, CurvPointsId );
270 aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_LINES" ),
271 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_LINES" ) ),
272 tr( "MEN_PLOT2D_CURVES_LINES" ),
274 aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_LINES" ) );
275 aAction->setCheckable( true );
276 mgr->registerAction( aAction, CurvLinesId );
279 aAction = new QtxAction( tr( "TOT_PLOT2D_CURVES_SPLINES" ),
280 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CURVES_SPLINES" ) ),
281 tr( "MEN_PLOT2D_CURVES_SPLINES" ),
283 aAction->setStatusTip( tr( "PRP_PLOT2D_CURVES_SPLINES" ) );
284 aAction->setCheckable( true );
285 mgr->registerAction( aAction, CurvSplinesId );
287 // 4.4. Create action group for curve type operations
288 QActionGroup* aCurveGroup = new QActionGroup( this );
289 aCurveGroup->addAction( mgr->action( CurvPointsId ) );
290 aCurveGroup->addAction( mgr->action( CurvLinesId ) );
291 aCurveGroup->addAction( mgr->action( CurvSplinesId ) );
292 connect( aCurveGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( onCurves() ) );
294 // 5. Horizontal scaling mode operations
297 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_HOR" ),
298 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_HOR" ) ),
299 tr( "MEN_PLOT2D_MODE_LINEAR_HOR" ),
301 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
302 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
303 aAction->setCheckable( true );
304 mgr->registerAction( aAction, PModeXLinearId );
307 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_HOR" ),
308 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_HOR" ) ),
309 tr( "MEN_PLOT2D_MODE_LOGARITHMIC_HOR" ),
311 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" ) );
312 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewHorMode() ) );
313 aAction->setCheckable( true );
314 mgr->registerAction( aAction, PModeXLogarithmicId );
316 // 5.3. Create action group for horizontal scaling mode operations
317 QActionGroup* aHorGroup = new QActionGroup( this );
318 aHorGroup->addAction( mgr->action( PModeXLinearId ) );
319 aHorGroup->addAction( mgr->action( PModeXLogarithmicId ) );
321 // 6. Vertical scaling mode operations
324 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LINEAR_VER" ),
325 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LINEAR_VER" ) ),
326 tr( "MEN_PLOT2D_MODE_LINEAR_VER" ),
328 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LINEAR_VER" ) );
329 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
330 aAction->setCheckable( true );
331 mgr->registerAction( aAction, PModeYLinearId );
334 aAction = new QtxAction( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_VER" ),
335 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_MODE_LOGARITHMIC_VER" ) ),
336 tr( "MEN_PLOT2D_MODE_LOGARITHMIC_VER" ),
338 aAction->setStatusTip( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_VER" ) );
339 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewVerMode() ) );
340 aAction->setCheckable( true );
341 mgr->registerAction( aAction, PModeYLogarithmicId );
343 // 6.3. Create action group for vertical scaling mode operations
344 QActionGroup* aVerGroup = new QActionGroup( this );
345 aVerGroup->addAction( mgr->action( PModeYLinearId ) );
346 aVerGroup->addAction( mgr->action( PModeYLogarithmicId ) );
349 aAction = new QtxAction( tr( "TOT_PLOT2D_SHOW_LEGEND" ),
350 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SHOW_LEGEND" ) ),
351 tr( "MEN_PLOT2D_SHOW_LEGEND" ),
353 aAction->setStatusTip( tr( "PRP_PLOT2D_SHOW_LEGEND" ) );
354 connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onLegend() ) );
355 aAction->setCheckable( true );
356 mgr->registerAction( aAction, LegendId );
359 aAction = new QtxAction( tr( "TOT_PLOT2D_SETTINGS" ),
360 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_SETTINGS" ) ),
361 tr( "MEN_PLOT2D_SETTINGS" ),
363 aAction->setStatusTip( tr( "PRP_PLOT2D_SETTINGS" ) );
364 connect( aAction, SIGNAL( triggered( bool ) ), myViewFrame, SLOT( onSettings() ) );
365 mgr->registerAction( aAction, CurvSettingsId );
368 aAction = new QtxAction( tr( "MNU_CLONE_VIEW" ),
369 aResMgr->loadPixmap( "Plot2d", tr( "ICON_PLOT2D_CLONE_VIEW" ) ),
370 tr( "MNU_CLONE_VIEW" ),
372 aAction->setStatusTip( tr( "DSC_CLONE_VIEW" ) );
373 connect( aAction, SIGNAL( triggered( bool ) ), this, SIGNAL( cloneView() ) );
374 mgr->registerAction( aAction, CloneId );
376 // Set initial values
380 onChangeLegendMode();
384 \brief Create toolbar for the view window.
386 void Plot2d_ViewWindow::createToolBar()
388 QtxActionToolMgr* mgr = toolMgr();
389 myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ) );
390 mgr->append( DumpId, myToolBar );
391 mgr->append( ScaleOpId, myToolBar );
392 mgr->append( MoveOpId, myToolBar );
393 mgr->append( toolMgr()->separator(), myToolBar );
394 mgr->append( CurvPointsId, myToolBar );
395 mgr->append( CurvLinesId, myToolBar );
396 mgr->append( CurvSplinesId, myToolBar );
397 mgr->append( toolMgr()->separator(), myToolBar );
398 mgr->append( PModeXLinearId, myToolBar );
399 mgr->append( PModeXLogarithmicId, myToolBar );
400 mgr->append( toolMgr()->separator(), myToolBar );
401 mgr->append( PModeYLinearId, myToolBar );
402 mgr->append( PModeYLogarithmicId, myToolBar );
403 mgr->append( toolMgr()->separator(), myToolBar );
404 mgr->append( LegendId, myToolBar );
405 mgr->append( CurvSettingsId, myToolBar );
406 mgr->append( CloneId, myToolBar );
410 \brief Get the visual parameters of the view window.
411 \return visual parameters of this view window formatted to the string
413 QString Plot2d_ViewWindow::getVisualParameters()
415 return myViewFrame->getVisualParameters();
419 \brief Restore visual parameters of the view window from the formated string
420 \param parameters view window visual parameters
422 void Plot2d_ViewWindow::setVisualParameters( const QString& parameters )
424 myViewFrame->setVisualParameters( parameters );
428 \brief Grab the view window to the internal image.
430 void Plot2d_ViewWindow::RefreshDumpImage()
432 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
433 myDumpImage = px.toImage();
437 \brief Called when the scale mode for the horizontal axis is changed.
439 void Plot2d_ViewWindow::onChangeHorMode()
441 bool aHorLinear = myViewFrame->isModeHorLinear();
442 bool aVerLinear = myViewFrame->isModeVerLinear();
445 toolMgr()->action( PModeXLinearId )->setChecked( true );
447 toolMgr()->action( PModeXLogarithmicId )->setChecked( true );
449 toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
453 \brief Called when the scale mode for the vertical axis is changed.
455 void Plot2d_ViewWindow::onChangeVerMode()
457 bool aHorLinear = myViewFrame->isModeHorLinear();
458 bool aVerLinear = myViewFrame->isModeVerLinear();
461 toolMgr()->action( PModeYLinearId )->setChecked( true );
463 toolMgr()->action( PModeYLogarithmicId )->setChecked( true );
465 toolMgr()->action( GlobalPanId )->setEnabled( aHorLinear && aVerLinear );
469 \brief Called when the curve type is changed.
471 void Plot2d_ViewWindow::onChangeCurveMode()
473 switch ( myViewFrame->getCurveType() ) {
475 toolMgr()->action( CurvPointsId )->setChecked( true );
478 toolMgr()->action( CurvLinesId )->setChecked( true );
481 toolMgr()->action( CurvSplinesId )->setChecked( true );
489 \brief Called when the legend mode is changed.
491 void Plot2d_ViewWindow::onChangeLegendMode()
493 toolMgr()->action( LegendId )->setChecked( myViewFrame->isLegendShow() );
497 \brief Called when the "Fit all" action is activated.
499 void Plot2d_ViewWindow::onFitAll()
501 myViewFrame->onViewFitAll();
505 \brief Called when the "Fit rect" action is activated.
507 void Plot2d_ViewWindow::onFitRect()
509 myViewFrame->onViewFitArea();
513 \brief Called when the "Zoom" action is activated.
515 void Plot2d_ViewWindow::onZoom()
517 myViewFrame->onViewZoom();
521 \brief Called when the "Panning" action is activated.
523 void Plot2d_ViewWindow::onPanning()
525 myViewFrame->onViewPan();
529 \brief Called when the "Global panning" action is activated.
531 void Plot2d_ViewWindow::onGlobalPanning()
533 myViewFrame->onViewGlobalPan();
537 \brief Called when horizontal axis scale mode action is activated.
539 void Plot2d_ViewWindow::onViewHorMode()
541 myViewFrame->setHorScaleMode( toolMgr()->action( PModeXLinearId )->isChecked() ? 0 : 1 );
545 \brief Called when vertical axis scale mode action is activated.
547 void Plot2d_ViewWindow::onViewVerMode()
549 myViewFrame->setVerScaleMode( toolMgr()->action( PModeYLinearId )->isChecked() ? 0 : 1 );
553 \brief Called when the "Show legend" action is activated.
555 void Plot2d_ViewWindow::onLegend()
557 myViewFrame->showLegend( !myViewFrame->isLegendShow() );
558 onChangeLegendMode();
562 \brief Called when the "Change curve type" action is activated.
564 void Plot2d_ViewWindow::onCurves()
566 if( toolMgr()->action( CurvPointsId )->isChecked() )
567 myViewFrame->setCurveType( 0 );
568 else if ( toolMgr()->action( CurvLinesId )->isChecked() )
569 myViewFrame->setCurveType( 1 );
570 else if ( toolMgr()->action( CurvSplinesId )->isChecked() )
571 myViewFrame->setCurveType( 2 );
575 \brief Called when the "Dump view" action is activated.
577 void Plot2d_ViewWindow::onDumpView()
579 qApp->postEvent( myViewFrame, new QPaintEvent( QRect( 0, 0, myViewFrame->width(), myViewFrame->height() ) ) );
580 SUIT_ViewWindow::onDumpView();
584 \brief Dump the contents of the view window to the image.
585 \return image, containing all scene rendered in the window
587 QImage Plot2d_ViewWindow::dumpView()
589 if ( getToolBar()->underMouse() || myDumpImage.isNull() ) {
590 QPixmap px = QPixmap::grabWindow( myViewFrame->winId() );
598 \brief Dump scene rendered in the view window to the file.
600 \param fileName name of file
601 \param format image format ("BMP" [default], "JPEG", "JPG", "PNG")
603 bool Plot2d_ViewWindow::dumpViewToFormat( const QImage& img,
604 const QString& fileName,
605 const QString& format )
607 bool res = myViewFrame ? myViewFrame->print( fileName, format ) : false;
609 res = SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
615 \brief Get supported image files wildcards.
616 \return image files wildcards (list of wildcards, separated by ";;")
618 QString Plot2d_ViewWindow::filter() const
620 QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts );
621 filters << tr( "POSTSCRIPT_FILES" );
622 filters << tr( "ENCAPSULATED_POSTSCRIPT_FILES" );
623 return filters.join( ";;" );
627 \fn void Plot2d_ViewWindow::cloneView();
628 \brief Emitted when the "Clone View" action is activated.