1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : Plot2d_ViewFrame.cxx
6 // Author : Vadim SANDLER
10 #include "Plot2d_ViewFrame.h"
11 #include "Plot2d_SetupViewDlg.h"
12 #include "QAD_Desktop.h"
13 #include "QAD_ResourceMgr.h"
14 #include "QAD_FileDlg.h"
15 #include "QAD_Tools.h"
16 #include "QAD_MessageBox.h"
17 #include "QAD_Config.h"
18 #include "SALOME_Selection.h"
19 #include "Plot2d_CurveContainer.h"
20 #include "Plot2d_Curve.h"
21 #include "Plot2d_FitDataDlg.h"
22 #include "utilities.h"
23 #include "qapplication.h"
25 #include <qtoolbutton.h>
28 #include <qwt_plot_canvas.h>
30 #include "utilities.h"
33 #include <SALOMEconfig.h>
34 #include CORBA_SERVER_HEADER(SALOMEDS)
35 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
37 #define DEFAULT_LINE_WIDTH 0 // (default) line width
38 #define DEFAULT_MARKER_SIZE 9 // default marker size
39 #define MIN_RECT_SIZE 11 // min sensibility area size
42 const char* imageZoomCursor[] = {
47 "................................",
48 "................................",
49 ".#######........................",
50 "..aaaaaaa.......................",
51 "................................",
52 ".............#####..............",
53 "...........##.aaaa##............",
54 "..........#.aa.....a#...........",
55 ".........#.a.........#..........",
56 ".........#a..........#a.........",
57 "........#.a...........#.........",
58 "........#a............#a........",
59 "........#a............#a........",
60 "........#a............#a........",
61 "........#a............#a........",
62 ".........#...........#.a........",
63 ".........#a..........#a.........",
64 ".........##.........#.a.........",
65 "........#####.....##.a..........",
66 ".......###aaa#####.aa...........",
67 "......###aa...aaaaa.......#.....",
68 ".....###aa................#a....",
69 "....###aa.................#a....",
70 "...###aa...............#######..",
71 "....#aa.................aa#aaaa.",
72 ".....a....................#a....",
73 "..........................#a....",
74 "...........................a....",
75 "................................",
76 "................................",
77 "................................",
78 "................................"};
81 //=================================================================================
82 // Plot2d_ViewFrame implementation
83 //=================================================================================
88 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
89 : QAD_ViewFrame( parent, title ),
90 myOperation( NoOpId ),
92 myShowLegend( true ), myLegendPos( 1 ),
93 myMarkerSize( DEFAULT_MARKER_SIZE ),
94 myTitle( "" ), myXTitle( "" ), myYTitle( "" ),
95 myBackground( white ),
96 myTitleEnabled( true ), myXTitleEnabled( true ), myYTitleEnabled( true ),
97 myXGridMajorEnabled( true ), myYGridMajorEnabled( true ),
98 myXGridMinorEnabled( false ), myYGridMinorEnabled( false ),
99 myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ),
100 myXMode( 0 ), myYMode( 0 )
103 myCurves.setAutoDelete( true );
105 myPlot = new Plot2d_Plot2d( this );
106 setCentralWidget( myPlot );
110 connect( myPlot, SIGNAL( plotMouseMoved( const QMouseEvent& ) ),
111 this, SLOT( plotMouseMoved( const QMouseEvent& ) ) );
112 connect( myPlot, SIGNAL( plotMousePressed( const QMouseEvent& ) ),
113 this, SLOT( plotMousePressed( const QMouseEvent& ) ) );
114 connect( myPlot, SIGNAL( plotMouseReleased( const QMouseEvent& ) ),
115 this, SLOT( plotMouseReleased( const QMouseEvent& ) ) );
116 connect( myPlot, SIGNAL( legendClicked( long ) ),
117 this, SLOT( onLegendClicked( long ) ) );
119 /* Initial Setup - get from the preferences */
122 myPlot->setMargin( 5 );
123 setCurveType( myCurveType, false );
124 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
125 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor, false );
126 setMainTitle( myTitleEnabled, myTitle, false );
127 setXTitle( myXTitleEnabled, myXTitle, false );
128 setYTitle( myYTitleEnabled, myYTitle, false );
129 setHorScaleMode( myXMode, false );
130 setVerScaleMode( myYMode, false );
131 setBackgroundColor( myBackground );
132 setLegendPos( myLegendPos );
133 showLegend( myShowLegend, false );
137 resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) );
143 Plot2d_ViewFrame::~Plot2d_ViewFrame()
146 qApp->removeEventFilter( this );
149 Creates popup menu actions
151 void Plot2d_ViewFrame::createActions()
153 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
154 /* Linear/logarithmic mode */
156 QActionPGroup* modeHorGrp = new QActionPGroup( this );
157 modeHorGrp->setExclusive( TRUE );
158 QActionP* linearXAction = new QActionP ( tr( "TOT_PLOT2D_MODE_LINEAR_HOR"),
159 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_MODE_LINEAR_HOR") ) ,
160 tr( "MEN_PLOT2D_MODE_LINEAR_HOR" ), 0, modeHorGrp );
161 linearXAction->setStatusTip ( tr( "PRP_PLOT2D_MODE_LINEAR_HOR" ) );
162 linearXAction->setToggleAction( true );
163 myActions.insert( ModeXLinearId, linearXAction );
164 QActionP* logXAction = new QActionP ( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_HOR"),
165 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_MODE_LOGARITHMIC_HOR") ) ,
166 tr( "MEN_PLOT2D_MODE_LOGARITHMIC_HOR" ), 0, modeHorGrp );
167 logXAction->setStatusTip ( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_HOR" ) );
168 logXAction->setToggleAction( true );
169 myActions.insert( ModeXLogarithmicId, logXAction );
170 connect( modeHorGrp, SIGNAL( selected( QActionP* ) ), this, SLOT( onHorMode() ) );
173 QActionPGroup* modeVerGrp = new QActionPGroup( this );
174 modeVerGrp->setExclusive( TRUE );
175 QActionP* linearYAction = new QActionP ( tr( "TOT_PLOT2D_MODE_LINEAR_VER"),
176 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_MODE_LINEAR_VER") ) ,
177 tr( "MEN_PLOT2D_MODE_LINEAR_VER" ), 0, modeVerGrp );
178 linearYAction->setStatusTip ( tr( "PRP_PLOT2D_MODE_LINEAR_VER" ) );
179 linearYAction->setToggleAction( true );
180 myActions.insert( ModeYLinearId, linearYAction );
181 QActionP* logYAction = new QActionP ( tr( "TOT_PLOT2D_MODE_LOGARITHMIC_VER"),
182 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_MODE_LOGARITHMIC_VER") ) ,
183 tr( "MEN_PLOT2D_MODE_LOGARITHMIC_VER" ), 0, modeVerGrp );
184 logYAction->setStatusTip ( tr( "PRP_PLOT2D_MODE_LOGARITHMIC_VER" ) );
185 logYAction->setToggleAction( true );
186 myActions.insert( ModeYLogarithmicId, logYAction );
187 connect( modeVerGrp, SIGNAL( selected( QActionP* ) ), this, SLOT( onVerMode() ) );
190 QActionP* legendAction = new QActionP ( tr( "TOT_PLOT2D_SHOW_LEGEND"),
191 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_SHOW_LEGEND") ) ,
192 tr( "MEN_PLOT2D_SHOW_LEGEND" ), 0, this );
193 legendAction->setStatusTip ( tr( "PRP_PLOT2D_SHOW_LEGEND" ) );
194 legendAction->setToggleAction( true );
195 myActions.insert( LegendId, legendAction );
196 connect( legendAction, SIGNAL( activated() ), this, SLOT( onLegend() ) );
199 QActionPGroup* curveGrp = new QActionPGroup( this );
200 curveGrp->setExclusive( TRUE );
201 QActionP* pointsAction = new QActionP ( tr( "TOT_PLOT2D_CURVES_POINTS"),
202 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_CURVES_POINTS") ) ,
203 tr( "MEN_PLOT2D_CURVES_POINTS" ), 0, curveGrp );
204 pointsAction->setStatusTip ( tr( "PRP_PLOT2D_CURVES_POINTS" ) );
205 pointsAction->setToggleAction( true );
206 myActions.insert( CurvePointsId, pointsAction );
207 QActionP* linesAction = new QActionP ( tr( "TOT_PLOT2D_CURVES_LINES"),
208 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_CURVES_LINES") ) ,
209 tr( "MEN_PLOT2D_CURVES_LINES" ), 0, curveGrp );
210 linesAction->setStatusTip ( tr( "PRP_PLOT2D_CURVES_LINES" ) );
211 linesAction->setToggleAction( true );
212 myActions.insert( CurveLinesId, linesAction );
213 QActionP* splinesAction = new QActionP ( tr( "TOT_PLOT2D_CURVES_SPLINES"),
214 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_CURVES_SPLINES") ) ,
215 tr( "MEN_PLOT2D_CURVES_SPLINES" ), 0, curveGrp );
216 splinesAction->setStatusTip ( tr( "PRP_PLOT2D_CURVES_SPLINES" ) );
217 splinesAction->setToggleAction( true );
218 myActions.insert( CurveSplinesId, splinesAction );
219 connect( curveGrp, SIGNAL( selected( QActionP* ) ), this, SLOT( onCurves() ) );
222 QActionP* settingsAction = new QActionP ( tr( "TOT_PLOT2D_SETTINGS"),
223 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_SETTINGS") ) ,
224 tr( "MEN_PLOT2D_SETTINGS" ), 0, this );
225 settingsAction->setStatusTip ( tr( "PRP_PLOT2D_SETTINGS" ) );
226 myActions.insert( SettingsId, settingsAction );
227 connect( settingsAction, SIGNAL( activated() ), this, SLOT( onSettings() ) );
230 QActionP* fitDataAction = new QActionP ( tr( "TOT_PLOT2D_FITDATA"),
231 rmgr->loadPixmap( "SALOMEGUI", tr("ICON_PLOT2D_FITDATA") ) ,
232 tr( "MEN_PLOT2D_FITDATA" ), 0, this );
233 fitDataAction->setStatusTip ( tr( "PRP_PLOT2D_FITDATA" ) );
234 myActions.insert( FitDataId, fitDataAction );
235 connect( fitDataAction, SIGNAL( activated() ), this, SLOT( onFitData() ) );
238 Gets window's central widget
240 QWidget* Plot2d_ViewFrame::getViewWidget()
242 return (QWidget*)myPlot;
244 /* Popup management : sets Popup server */
245 void Plot2d_ViewFrame::setPopupServer( QAD_Application* App )
247 // QAD_PopupClientServer::setPopupServer( (QAD_PopupServer*)App );
252 void Plot2d_ViewFrame::onCreatePopup()
257 QPopupMenu* scalingPopup = new QPopupMenu( myPopup );
258 myActions[ ModeXLinearId ]->addTo( scalingPopup );
259 myActions[ ModeXLogarithmicId ]->addTo( scalingPopup );
260 scalingPopup->insertSeparator();
261 myActions[ ModeYLinearId ]->addTo( scalingPopup );
262 myActions[ ModeYLogarithmicId ]->addTo( scalingPopup );
263 myActions[ FitDataId ]->addTo( myPopup );
264 myPopup->insertItem( tr( "SCALING_POPUP" ), scalingPopup );
266 QPopupMenu* curTypePopup = new QPopupMenu( myPopup );
267 myActions[ CurvePointsId ]->addTo( curTypePopup );
268 myActions[ CurveLinesId ]->addTo( curTypePopup );
269 myActions[ CurveSplinesId ]->addTo( curTypePopup );
270 myPopup->insertItem( tr( "CURVE_TYPE_POPUP" ), curTypePopup );
272 myPopup->insertSeparator();
273 myActions[ LegendId ]->addTo( myPopup );
275 myPopup->insertSeparator();
276 myActions[ SettingsId ]->addTo( myPopup );
280 Renames curve if it is found
282 void Plot2d_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
284 Plot2d_Curve* curve = getCurveByIO( IObject );
286 curve->setVerTitle( newName );
287 int key = hasCurve( curve );
289 myPlot->setCurveTitle( key, newName );
290 // int legendIndex = myPlot->getLegend()->findFirstKey( key );
291 // if ( legendIndex != myPlot->getLegend()->itemCnt() )
292 // myPlot->getLegend()->setText( legendIndex, aSymbol );
298 Returns true if interactive object is presented in the viewer
300 bool Plot2d_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
302 if( getCurveByIO( IObject ) != NULL )
305 if(!IObject.IsNull()){
306 QIntDictIterator<Plot2d_Curve> it(myCurves);
307 for(; it.current();++it){
308 if(it.current()->hasIO() && it.current()->getTableIO()->isSame(IObject))
315 Returns true if interactive object is presented in the viewer and displayed
317 bool Plot2d_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
319 Plot2d_Curve* curve = getCurveByIO( IObject );
321 int key = hasCurve( curve );
323 return myPlot->curve( key )->enabled();
328 Return interactive obeject if is presented in the viewer
330 Handle(SALOME_InteractiveObject) Plot2d_ViewFrame::FindIObject( const char* Entry )
332 Handle(SALOME_InteractiveObject) o;
333 QIntDictIterator<Plot2d_Curve> it( myCurves );
334 for ( ; it.current(); ++it ) {
335 if ( it.current()->hasIO() && !strcmp( it.current()->getIO()->getEntry(), Entry ) ) {
336 o = it.current()->getIO();
343 Actually this method just re-displays curves which refers to the <IObject>
345 void Plot2d_ViewFrame::Display( const Handle(SALOME_InteractiveObject)& IObject, bool update )
347 Plot2d_Curve* curve = getCurveByIO( IObject );
349 updateCurve( curve, update );
352 Actually this method just erases all curves which don't refer to <IOBject>
353 and re-displays curve which is of <IObject>
355 void Plot2d_ViewFrame::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject )
357 Plot2d_Curve* curve = getCurveByIO( IObject );
358 QList<Plot2d_Curve> clist;
360 for ( int i = 0; i < clist.count(); i++ ) {
361 if ( clist.at( i ) != curve )
364 updateCurve( curve, false );
369 Removes from the viewer the curves which refer to <IObject>
371 void Plot2d_ViewFrame::Erase( const Handle(SALOME_InteractiveObject)& IObject, bool update )
373 Plot2d_Curve* curve = getCurveByIO( IObject );
375 eraseCurve( curve, update );
378 Actually this method just re-displays all curves which are presented in the viewer
380 void Plot2d_ViewFrame::DisplayAll()
382 QList<Plot2d_Curve> clist;
384 for ( int i = 0; i < clist.count(); i++ ) {
385 updateCurve( clist.at( i ), false );
390 Removes all curves from the view
392 void Plot2d_ViewFrame::EraseAll()
399 Redraws viewframe contents
401 void Plot2d_ViewFrame::Repaint()
408 bool Plot2d_ViewFrame::eventFilter( QObject* o, QEvent* e )
410 if ( ( e->type() == QEvent::MouseButtonPress || e->type() == QEvent::KeyPress ) && o != myPlot->canvas() ) {
411 myOperation = NoOpId;
412 qApp->removeEventFilter( this );
414 return QMainWindow::eventFilter( o, e );
419 void Plot2d_ViewFrame::setTitle( const QString& title )
421 setMainTitle( myTitleEnabled, title, true );
424 Reads Plot2d view settings from the preferences
426 void Plot2d_ViewFrame::readPreferences()
428 if ( QAD_CONFIG->hasSetting( "Plot2d:CurveType" ) ) { // curve type
429 myCurveType = QAD_CONFIG->getSetting( "Plot2d:CurveType" ).toInt();
430 if ( myCurveType < 0 || myCurveType > 2 ) myCurveType = 1;
432 if ( QAD_CONFIG->hasSetting( "Plot2d:ShowLegend" ) ) {
433 myShowLegend = QAD_CONFIG->getSetting( "Plot2d:ShowLegend" ) == QString( "true" ); // show legend
435 if ( QAD_CONFIG->hasSetting( "Plot2d:LegendPos" ) ) { // legend position
436 myLegendPos = QAD_CONFIG->getSetting( "Plot2d:LegendPos" ).toInt();
437 if ( myLegendPos < 0 || myLegendPos > 3 ) myLegendPos = 1;
439 if ( QAD_CONFIG->hasSetting( "Plot2d:MarkerSize" ) ) { // marker size
440 myMarkerSize = QAD_CONFIG->getSetting( "Plot2d:MarkerSize" ).toInt();
442 if ( QAD_CONFIG->hasSetting( "Plot2d:Background" ) ) { // background color
443 QString bgString = QAD_CONFIG->getSetting( "Plot2d:Background" );
444 QStringList bgData = QStringList::split( ":", bgString, true );
445 int bgRed = 0, bgGreen = 0, bgBlue = 0;
446 if ( bgData.count() > 0 ) bgRed = bgData[ 0 ].toInt();
447 if ( bgData.count() > 1 ) bgGreen = bgData[ 1 ].toInt();
448 if ( bgData.count() > 2 ) bgBlue = bgData[ 2 ].toInt();
449 myBackground = QColor( bgRed, bgGreen, bgBlue );
451 if ( QAD_CONFIG->hasSetting( "Plot2d:ShowTitle" ) ) { // main title
452 myTitleEnabled = QAD_CONFIG->getSetting( "Plot2d:ShowTitle" ) == QString( "true" );
454 if ( QAD_CONFIG->hasSetting( "Plot2d:ShowHorTitle" ) ) { // hor.axis title
455 myXTitleEnabled = QAD_CONFIG->getSetting( "Plot2d:ShowHorTitle" ) == QString( "true" );
457 if ( QAD_CONFIG->hasSetting( "Plot2d:ShowVerTitle" ) ) { // ver.axisn title
458 myYTitleEnabled = QAD_CONFIG->getSetting( "Plot2d:ShowVerTitle" ) == QString( "true" );
460 if ( QAD_CONFIG->hasSetting( "Plot2d:EnableHorMajorGrid" ) ) { // grid
461 myXGridMajorEnabled = QAD_CONFIG->getSetting( "Plot2d:EnableHorMajorGrid" ) == QString( "true" );
463 if ( QAD_CONFIG->hasSetting( "Plot2d:EnableVerMajorGrid" ) ) {
464 myYGridMajorEnabled = QAD_CONFIG->getSetting( "Plot2d:EnableVerMajorGrid" ) == QString( "true" );
466 if ( QAD_CONFIG->hasSetting( "Plot2d:EnableHorMinorGrid" ) ) {
467 myXGridMinorEnabled = QAD_CONFIG->getSetting( "Plot2d:EnableHorMinorGrid" ) == QString( "true" );
469 if ( QAD_CONFIG->hasSetting( "Plot2d:EnableVerMinorGrid" ) ) {
470 myYGridMinorEnabled = QAD_CONFIG->getSetting( "Plot2d:EnableVerMinorGrid" ) == QString( "true" );
472 if ( QAD_CONFIG->hasSetting( "Plot2d:HorMajorGridMax" ) ) {
473 myXGridMaxMajor = QAD_CONFIG->getSetting( "Plot2d:HorMajorGridMax" ).toInt();
475 if ( QAD_CONFIG->hasSetting( "Plot2d:VerMajorGridMax" ) ) {
476 myYGridMaxMajor = QAD_CONFIG->getSetting( "Plot2d:VerMajorGridMax" ).toInt();
478 if ( QAD_CONFIG->hasSetting( "Plot2d:HorMinorGridMax" ) ) {
479 myXGridMaxMinor = QAD_CONFIG->getSetting( "Plot2d:HorMinorGridMax" ).toInt();
481 if ( QAD_CONFIG->hasSetting( "Plot2d:VerMinorGridMax" ) ) {
482 myYGridMaxMinor = QAD_CONFIG->getSetting( "Plot2d:VerMinorGridMax" ).toInt();
484 if ( QAD_CONFIG->hasSetting( "Plot2d:HorScaleMode" ) ) { // scale mode
485 myXMode = QAD_CONFIG->getSetting( "Plot2d:HorScaleMode" ).toInt();
486 if ( myXMode < 0 || myXMode > 1 ) myXMode = 0;
488 if ( QAD_CONFIG->hasSetting( "Plot2d:VerScaleMode" ) ) {
489 myYMode = QAD_CONFIG->getSetting( "Plot2d:VerScaleMode" ).toInt();
490 if ( myYMode < 0 || myYMode > 1 ) myYMode = 0;
494 Writes Plot2d view settings to the preferences
496 void Plot2d_ViewFrame::writePreferences()
498 QAD_CONFIG->addSetting( "Plot2d:CurveType", myCurveType ); // curve type
499 QAD_CONFIG->addSetting( "Plot2d:ShowLegend", myShowLegend ? "true" : "false" ); // show legend
500 QAD_CONFIG->addSetting( "Plot2d:LegendPos", myLegendPos ); // legend position
501 QAD_CONFIG->addSetting( "Plot2d:MarkerSize", myMarkerSize ); // marker size
503 bgData.append( QString::number( myBackground.red() ) );
504 bgData.append( QString::number( myBackground.green() ) );
505 bgData.append( QString::number( myBackground.blue() ) );
506 QAD_CONFIG->addSetting( "Plot2d:Background", bgData.join( ":" ) ); // background color
507 QAD_CONFIG->addSetting( "Plot2d:ShowTitle", myTitleEnabled ? "true" : "false" ); // titles
508 QAD_CONFIG->addSetting( "Plot2d:ShowHorTitle", myXTitleEnabled ? "true" : "false" );
509 QAD_CONFIG->addSetting( "Plot2d:ShowVerTitle", myYTitleEnabled ? "true" : "false" );
510 QAD_CONFIG->addSetting( "Plot2d:EnableHorMajorGrid", myXGridMajorEnabled ? "true" : "false" ); // grid
511 QAD_CONFIG->addSetting( "Plot2d:EnableVerMajorGrid", myYGridMajorEnabled ? "true" : "false" );
512 QAD_CONFIG->addSetting( "Plot2d:EnableHorMinorGrid", myXGridMinorEnabled ? "true" : "false" );
513 QAD_CONFIG->addSetting( "Plot2d:EnableVerMinorGrid", myYGridMinorEnabled ? "true" : "false" );
514 QAD_CONFIG->addSetting( "Plot2d:HorMajorGridMax", myXGridMaxMajor );
515 QAD_CONFIG->addSetting( "Plot2d:VerMajorGridMax", myYGridMaxMajor );
516 QAD_CONFIG->addSetting( "Plot2d:HorMinorGridMax", myXGridMaxMinor );
517 QAD_CONFIG->addSetting( "Plot2d:VerMinorGridMax", myYGridMaxMinor );
518 QAD_CONFIG->addSetting( "Plot2d:HorScaleMode", myXMode ); // scale mode
519 QAD_CONFIG->addSetting( "Plot2d:VerScaleMode", myYMode );
522 Prints mouse cursor coordinates into string
524 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
527 info.sprintf( "X : %g\tY : %g",
528 myPlot->invTransform( QwtPlot::xBottom, pnt.x() ),
529 myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) );
530 info = tr( "INF_COORDINATES" ) + " : " + info;
534 Converts Plot2d_Curve's marker style to Qwt marker style [ static ]
536 static QwtSymbol::Style plot2qwtMarker( Plot2d_Curve::MarkerType m )
538 QwtSymbol::Style ms = QwtSymbol::None;
540 case Plot2d_Curve::Circle:
541 ms = QwtSymbol::Ellipse; break;
542 case Plot2d_Curve::Rectangle:
543 ms = QwtSymbol::Rect; break;
544 case Plot2d_Curve::Diamond:
545 ms = QwtSymbol::Diamond; break;
546 case Plot2d_Curve::DTriangle:
547 ms = QwtSymbol::DTriangle; break;
548 case Plot2d_Curve::UTriangle:
549 ms = QwtSymbol::UTriangle; break;
550 case Plot2d_Curve::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
551 ms = QwtSymbol::RTriangle; break;
552 case Plot2d_Curve::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
553 ms = QwtSymbol::LTriangle; break;
554 case Plot2d_Curve::Cross:
555 ms = QwtSymbol::Cross; break;
556 case Plot2d_Curve::XCross:
557 ms = QwtSymbol::XCross; break;
558 case Plot2d_Curve::None:
560 ms = QwtSymbol::None; break;
565 Converts Qwt marker style to Plot2d_Curve's marker style [ static ]
567 static Plot2d_Curve::MarkerType qwt2plotMarker( QwtSymbol::Style m )
569 Plot2d_Curve::MarkerType ms = Plot2d_Curve::None;
571 case QwtSymbol::Ellipse:
572 ms = Plot2d_Curve::Circle; break;
573 case QwtSymbol::Rect:
574 ms = Plot2d_Curve::Rectangle; break;
575 case QwtSymbol::Diamond:
576 ms = Plot2d_Curve::Diamond; break;
577 case QwtSymbol::DTriangle:
578 ms = Plot2d_Curve::DTriangle; break;
579 case QwtSymbol::UTriangle:
580 ms = Plot2d_Curve::UTriangle; break;
581 case QwtSymbol::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
582 ms = Plot2d_Curve::LTriangle; break;
583 case QwtSymbol::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
584 ms = Plot2d_Curve::RTriangle; break;
585 case QwtSymbol::Cross:
586 ms = Plot2d_Curve::Cross; break;
587 case QwtSymbol::XCross:
588 ms = Plot2d_Curve::XCross; break;
589 case QwtSymbol::None:
591 ms = Plot2d_Curve::None; break;
596 Converts Plot2d_Curve's line style to Qwt line style [ static ]
598 static Qt::PenStyle plot2qwtLine( Plot2d_Curve::LineType p )
600 Qt::PenStyle ps = Qt::NoPen;
602 case Plot2d_Curve::Solid:
603 ps = Qt::SolidLine; break;
604 case Plot2d_Curve::Dash:
605 ps = Qt::DashLine; break;
606 case Plot2d_Curve::Dot:
607 ps = Qt::DotLine; break;
608 case Plot2d_Curve::DashDot:
609 ps = Qt::DashDotLine; break;
610 case Plot2d_Curve::DashDotDot:
611 ps = Qt::DashDotDotLine; break;
612 case Plot2d_Curve::NoPen:
614 ps = Qt::NoPen; break;
619 Converts Qwt line style to Plot2d_Curve's line style [ static ]
621 static Plot2d_Curve::LineType qwt2plotLine( Qt::PenStyle p )
623 Plot2d_Curve::LineType ps = Plot2d_Curve::NoPen;
626 ps = Plot2d_Curve::Solid; break;
628 ps = Plot2d_Curve::Dash; break;
630 ps = Plot2d_Curve::Dot; break;
631 case Qt::DashDotLine:
632 ps = Plot2d_Curve::DashDot; break;
633 case Qt::DashDotDotLine:
634 ps = Plot2d_Curve::DashDotDot; break;
637 ps = Plot2d_Curve::NoPen; break;
644 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
648 if ( hasCurve( curve ) ) {
649 updateCurve( curve, update );
652 long curveKey = myPlot->insertCurve( curve->getVerTitle() );
653 myCurves.insert( curveKey, curve );
654 if ( curve->isAutoAssign() ) {
655 QwtSymbol::Style typeMarker;
657 Qt::PenStyle typeLine;
658 myPlot->getNextMarker( typeMarker, color, typeLine );
659 myPlot->setCurvePen( curveKey, QPen( color, DEFAULT_LINE_WIDTH, typeLine ) );
660 myPlot->setCurveSymbol( curveKey, QwtSymbol( typeMarker,
663 QSize( myMarkerSize, myMarkerSize ) ) );
664 curve->setColor( color );
665 curve->setLine( qwt2plotLine( typeLine ) );
666 curve->setMarker( qwt2plotMarker( typeMarker ) );
669 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
670 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
671 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
672 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
673 QBrush( curve->getColor() ),
674 QPen( curve->getColor() ),
675 QSize( myMarkerSize, myMarkerSize ) ) );
677 if ( myCurveType == 0 )
678 myPlot->setCurveStyle( curveKey, QwtCurve::NoCurve );
679 else if ( myCurveType == 1 )
680 myPlot->setCurveStyle( curveKey, QwtCurve::Lines );
681 else if ( myCurveType == 2 )
682 myPlot->setCurveStyle( curveKey, QwtCurve::Spline );
683 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
690 Adds curves into view
692 void Plot2d_ViewFrame::displayCurves( Plot2d_CurveContainer& curves, bool update )
694 myPlot->setUpdatesEnabled( false );
695 for ( int i = 0; i < curves.count(); i++ ) {
696 displayCurve( curves.curve( i ), false );
699 myPlot->setUpdatesEnabled( true );
706 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
710 int curveKey = hasCurve( curve );
712 myPlot->removeCurve( curveKey );
713 myCurves.remove( curveKey );
722 void Plot2d_ViewFrame::eraseCurves( Plot2d_CurveContainer& curves, bool update )
724 for ( int i = 0; i < curves.count(); i++ ) {
725 eraseCurve( curves.curve( i ), false );
732 Updates curves attributes
734 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
738 int curveKey = hasCurve( curve );
740 if ( !curve->isAutoAssign() ) {
741 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
742 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
743 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
744 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
745 QBrush( curve->getColor() ),
746 QPen( curve->getColor() ),
747 QSize( myMarkerSize, myMarkerSize ) ) );
749 myPlot->setCurveTitle( curveKey, curve->getVerTitle() );
750 myPlot->curve( curveKey )->setEnabled( true );
757 Returns curve key if is is displayed in the viewer and 0 otherwise
759 int Plot2d_ViewFrame::hasCurve( Plot2d_Curve* curve )
761 QIntDictIterator<Plot2d_Curve> it( myCurves );
762 for ( ; it.current(); ++it ) {
763 if ( it.current() == curve )
764 return it.currentKey();
768 Plot2d_Curve* Plot2d_ViewFrame::getCurveByIO( const Handle(SALOME_InteractiveObject)& theIObject )
770 if ( !theIObject.IsNull() ) {
771 QIntDictIterator<Plot2d_Curve> it( myCurves );
772 for ( ; it.current(); ++it ) {
773 if ( it.current()->hasIO() && it.current()->getIO()->isSame( theIObject ) )
780 Gets lsit of displayed curves
782 int Plot2d_ViewFrame::getCurves( QList<Plot2d_Curve>& clist )
785 clist.setAutoDelete( false );
786 QIntDictIterator<Plot2d_Curve> it( myCurves );
787 for ( ; it.current(); ++it ) {
788 clist.append( it.current() );
790 return clist.count();
794 Updates titles according to curves
796 #define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
797 void Plot2d_ViewFrame::updateTitles()
799 QAD_Study* activeStudy = QAD_Application::getDesktop()->getActiveStudy();
800 QIntDictIterator<Plot2d_Curve> it( myCurves );
801 QStringList aXTitles;
802 QStringList aYTitles;
807 while ( it.current() ) {
808 // collect titles and units from all curves...
809 QString xTitle = it.current()->getHorTitle().stripWhiteSpace();
810 QString yTitle = it.current()->getVerTitle().stripWhiteSpace();
811 QString xUnits = it.current()->getHorUnits().stripWhiteSpace();
812 QString yUnits = it.current()->getVerUnits().stripWhiteSpace();
814 aYTitles.append( yTitle );
815 if ( aXTitles.find( xTitle ) == aXTitles.end() )
816 aXTitles.append( xTitle );
817 if ( aXUnits.find( xUnits ) == aXUnits.end() )
818 aXUnits.append( xUnits );
819 if ( aYUnits.find( yUnits ) == aYUnits.end() )
820 aYUnits.append( yUnits );
822 if ( activeStudy && it.current()->hasTableIO() ) {
823 SALOMEDS::SObject_var SO = activeStudy->getStudyDocument()->FindObjectID( it.current()->getTableIO()->getEntry() );
824 if ( !SO->_is_nil() ) {
825 SALOMEDS::GenericAttribute_var anAttr;
826 if ( SO->FindAttribute( anAttr, "AttributeName" ) ) {
827 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
828 QString aName = aNameAttr->Value();
829 if ( !aName.isEmpty() && aTables.find( aName ) == aTables.end() )
830 aTables.append( aName );
838 // ... and update plot 2d view
839 QString xUnits, yUnits;
840 if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() )
841 xUnits = BRACKETIZE( aXUnits[0] );
842 if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty())
843 yUnits = BRACKETIZE( aYUnits[0] );
844 QString xTitle, yTitle;
845 if ( aXTitles.count() == 1 && aXUnits.count() == 1 )
846 xTitle = aXTitles[0];
847 if ( aYTitles.count() == 1 )
848 yTitle = aYTitles[0];
850 if ( !xTitle.isEmpty() && !xUnits.isEmpty() )
852 if ( !yTitle.isEmpty() && !yUnits.isEmpty() )
855 setXTitle( myXTitleEnabled, xTitle + xUnits );
856 setYTitle( myYTitleEnabled, yTitle + yUnits );
857 setTitle( aTables.join("; ") );
860 Fits the view to see all data
862 void Plot2d_ViewFrame::fitAll()
864 myPlot->setAxisAutoScale( QwtPlot::yLeft );
865 myPlot->setAxisAutoScale( QwtPlot::xBottom );
869 Fits the view to rectangle area (pixels)
871 void Plot2d_ViewFrame::fitArea( const QRect& area )
873 QRect rect = area.normalize();
874 if ( rect.width() < MIN_RECT_SIZE ) {
875 rect.setWidth( MIN_RECT_SIZE );
876 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
878 if ( rect.height() < MIN_RECT_SIZE ) {
879 rect.setHeight( MIN_RECT_SIZE );
880 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
882 myPlot->setAxisScale( QwtPlot::yLeft,
883 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
884 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
885 myPlot->setAxisScale( QwtPlot::xBottom,
886 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
887 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
891 Tests if it is necessary to start operation on mouse action
893 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
895 int btn = me.button() | me.state();
896 int zoomBtn = ControlButton | LeftButton;
897 int panBtn = ControlButton | MidButton;
898 int fitBtn = ControlButton | RightButton;
900 if ( btn == zoomBtn )
909 Mode toolbar buttons slot - horizontal axis (<Linear>/<Logarithmic>)
911 void Plot2d_ViewFrame::onHorMode()
913 if ( myActions[ ModeXLinearId ]->isOn() )
914 setHorScaleMode( 0 );
915 else if ( myActions[ ModeXLogarithmicId ]->isOn() )
916 setHorScaleMode( 1 );
919 Mode toolbar buttons slot - vertical axis (<Linear>/<Logarithmic>)
921 void Plot2d_ViewFrame::onVerMode()
923 if ( myActions[ ModeYLinearId ]->isOn() )
924 setVerScaleMode( 0 );
925 else if ( myActions[ ModeYLogarithmicId ]->isOn() )
926 setVerScaleMode( 1 );
929 "Show/hide legend" toolbar action slot
931 void Plot2d_ViewFrame::onLegend()
933 showLegend( myActions[ LegendId ]->isOn() );
936 "Curve type" toolbar action slot
938 void Plot2d_ViewFrame::onCurves()
940 if ( myActions[ CurvePointsId ]->isOn() )
942 else if ( myActions[ CurveLinesId ]->isOn() )
944 else if ( myActions[ CurveSplinesId ]->isOn() )
948 "Settings" toolbar action slot
950 void Plot2d_ViewFrame::onSettings()
952 #ifdef TEST_AUTOASSIGN
953 typedef QMap<int,int> IList;
954 typedef QMap<QString,int> SList;
957 cols[ "red-min" ] = 1000;
958 cols[ "red-max" ] = -1;
959 cols[ "green-min" ] = 1000;
960 cols[ "green-max" ] = -1;
961 cols[ "blue-min" ] = 1000;
962 cols[ "blue-max" ] = -1;
963 for ( unsigned i = 0; i < 10000; i++ ) {
964 QwtSymbol::Style typeMarker;
966 Qt::PenStyle typeLine;
967 myPlot->getNextMarker( typeMarker, color, typeLine );
968 if ( mars.contains(typeMarker) )
969 mars[ typeMarker ] = mars[ typeMarker ]+1;
971 mars[ typeMarker ] = 0;
972 if ( lins.contains(typeLine) )
973 lins[ typeLine ] = lins[ typeLine ]+1;
975 lins[ typeLine ] = 0;
976 if ( cols[ "red-max" ] < color.red() )
977 cols[ "red-max" ] = color.red();
978 if ( cols[ "red-min" ] > color.red() )
979 cols[ "red-min" ] = color.red();
980 if ( cols[ "green-max" ] < color.green() )
981 cols[ "green-max" ] = color.green();
982 if ( cols[ "green-min" ] > color.green() )
983 cols[ "green-min" ] = color.green();
984 if ( cols[ "blue-max" ] < color.blue() )
985 cols[ "blue-max" ] = color.blue();
986 if ( cols[ "blue-min" ] > color.blue() )
987 cols[ "blue-min" ] = color.blue();
989 for (IList::Iterator it = mars.begin(); it != mars.end(); ++it)
990 MESSAGE("markers( " << it.key() << ") = " << it.data() );
991 for (IList::Iterator it = lins.begin(); it != lins.end(); ++it)
992 MESSAGE("lines( " << it.key() << ") = " << it.data() );
993 for (SList::Iterator it = cols.begin(); it != cols.end(); ++it)
994 MESSAGE("colors( " << it.key() << ") = " << it.data() );
997 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true );
998 dlg->setMainTitle( myTitleEnabled, myTitle );
999 dlg->setXTitle( myXTitleEnabled, myXTitle );
1000 dlg->setYTitle( myYTitleEnabled, myYTitle );
1001 dlg->setCurveType( myCurveType );
1002 dlg->setLegend( myShowLegend, myLegendPos );
1003 dlg->setMarkerSize( myMarkerSize );
1004 dlg->setBackgroundColor( myBackground );
1005 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
1006 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ) );
1007 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
1008 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ) );
1009 dlg->setScaleMode( myXMode, myYMode );
1011 if ( dlg->exec() == QDialog::Accepted ) {
1012 // horizontal axis title
1013 setXTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), false );
1014 // vertical axis title
1015 setYTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), false );
1017 setMainTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), true );
1019 if ( myCurveType != dlg->getCurveType() ) {
1020 setCurveType( dlg->getCurveType(), false );
1023 if ( myShowLegend != dlg->isLegendEnabled() ) {
1024 showLegend( dlg->isLegendEnabled(), false );
1026 if ( myLegendPos != dlg->getLegendPos() ) {
1027 setLegendPos( dlg->getLegendPos() );
1030 if ( myMarkerSize != dlg->getMarkerSize() ) {
1031 setMarkerSize( dlg->getMarkerSize(), false );
1034 if ( myBackground != dlg->getBackgroundColor() ) {
1035 setBackgroundColor( dlg->getBackgroundColor() );
1038 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled;
1039 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor;
1040 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor );
1041 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor );
1042 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
1043 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor, false );
1045 if ( myXMode != dlg->getXScaleMode() ) {
1046 setHorScaleMode( dlg->getXScaleMode() );
1048 if ( myYMode != dlg->getYScaleMode() ) {
1049 setVerScaleMode( dlg->getYScaleMode() );
1053 // update preferences
1054 if ( dlg->isSetAsDefault() )
1060 "Fit Data" command slot
1062 void Plot2d_ViewFrame::onFitData()
1064 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this );
1065 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1();
1066 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2();
1067 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1();
1068 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2();
1069 double xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
1070 double xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
1071 double yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
1072 double yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
1074 dlg->setRange( xMin, xMax, yMin, yMax );
1075 if ( dlg->exec() == QDialog::Accepted ) {
1076 int mode = dlg->getRange( xMin, xMax, yMin, yMax );
1077 if ( mode == 0 || mode == 2 )
1078 myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin );
1079 if ( mode == 0 || mode == 1 )
1080 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
1088 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1090 myCurveType = curveType;
1091 if ( curveType == 0 )
1092 myActions[ CurvePointsId ]->setOn( true );
1093 else if ( curveType == 1 )
1094 myActions[ CurveLinesId ]->setOn( true );
1095 else if ( curveType == 2 )
1096 myActions[ CurveSplinesId ]->setOn( true );
1098 QArray<long> keys = myPlot->curveKeys();
1099 for ( int i = 0; i < keys.count(); i++ ) {
1100 if ( myCurveType == 0 )
1101 myPlot->setCurveStyle( keys[i], QwtCurve::NoCurve );
1102 else if ( myCurveType == 1 )
1103 myPlot->setCurveStyle( keys[i], QwtCurve::Lines );
1104 else if ( myCurveType == 2 )
1105 myPlot->setCurveStyle( keys[i], QwtCurve::Spline );
1113 void Plot2d_ViewFrame::showLegend( bool show, bool update )
1115 myShowLegend = show;
1116 myActions[ LegendId ]->setOn( myShowLegend );
1118 myPlot->setAutoLegend( myShowLegend );
1119 myPlot->enableLegend( myShowLegend );
1125 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
1127 void Plot2d_ViewFrame::setLegendPos( int pos )
1132 myPlot->setLegendPos( Qwt::Left );
1135 myPlot->setLegendPos( Qwt::Right );
1138 myPlot->setLegendPos( Qwt::Top );
1141 myPlot->setLegendPos( Qwt::Bottom );
1146 Sets new marker size
1148 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
1150 if ( myMarkerSize != size ) {
1151 myMarkerSize = size;
1152 QArray<long> keys = myPlot->curveKeys();
1153 for ( int i = 0; i < keys.count(); i++ ) {
1154 QwtPlotCurve* crv = myPlot->curve( keys[i] );
1156 QwtSymbol aSymbol = crv->symbol();
1157 aSymbol.setSize( myMarkerSize, myMarkerSize );
1158 crv->setSymbol( aSymbol );
1159 int legendIndex = myPlot->getLegend()->findFirstKey( keys[i] );
1160 if ( legendIndex != myPlot->getLegend()->itemCnt() )
1161 myPlot->getLegend()->setSymbol( legendIndex, aSymbol );
1169 Sets background color
1171 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
1173 myBackground = color;
1174 //myPlot->setCanvasBackground( myBackground );
1175 myPlot->canvas()->setPalette( myBackground );
1176 myPlot->setPalette( myBackground );
1177 QPalette aPal = myPlot->getLegend()->palette();
1178 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
1179 QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
1180 aPal.setColor( cg, QColorGroup::Base, myBackground );
1181 aPal.setColor( cg, QColorGroup::Background, myBackground );
1183 myPlot->getLegend()->setPalette( aPal );
1186 Gets background color
1188 QColor Plot2d_ViewFrame::backgroundColor() const
1190 return myBackground;
1193 Sets hor.axis grid parameters
1195 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
1196 bool xMinorEnabled, const int xMinorMax,
1199 myXGridMajorEnabled = xMajorEnabled;
1200 myXGridMinorEnabled = xMinorEnabled;
1201 myXGridMaxMajor = xMajorMax;
1202 myXGridMaxMinor = xMinorMax;
1203 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1204 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1205 myPlot->enableGridX( myXGridMajorEnabled );
1206 myPlot->enableGridXMin( myXGridMinorEnabled );
1211 Sets ver.axis grid parameters
1213 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
1214 bool yMinorEnabled, const int yMinorMax,
1217 myYGridMajorEnabled = yMajorEnabled;
1218 myYGridMinorEnabled = yMinorEnabled;
1219 myYGridMaxMajor = yMajorMax;
1220 myYGridMaxMinor = yMinorMax;
1221 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1222 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1223 myPlot->enableGridY( myYGridMajorEnabled );
1224 myPlot->enableGridYMin( myYGridMinorEnabled );
1231 void Plot2d_ViewFrame::setMainTitle( bool enabled, const QString& title, bool update )
1233 myTitleEnabled = enabled;
1235 myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1242 void Plot2d_ViewFrame::setXTitle( bool enabled, const QString& title, bool update )
1244 myXTitleEnabled = enabled;
1246 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1253 void Plot2d_ViewFrame::setYTitle( bool enabled, const QString& title, bool update )
1255 myYTitleEnabled = enabled;
1257 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1262 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1264 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1267 if ( myXMode == 0 ) { // linear
1268 myActions[ ModeXLogarithmicId ]->setOn( false );
1269 myActions[ ModeXLinearId ]->setOn( true );
1270 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1272 else { // logarithmic
1273 myActions[ ModeXLinearId ]->setOn( false );
1274 myActions[ ModeXLogarithmicId ]->setOn( true );
1275 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1278 // myPlot->replot();
1282 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1284 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1287 if ( myYMode == 0 ) { // linear
1288 myActions[ ModeYLogarithmicId ]->setOn( false );
1289 myActions[ ModeYLinearId ]->setOn( true );
1290 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1292 else { // logarithmic
1293 myActions[ ModeYLinearId ]->setOn( false );
1294 myActions[ ModeYLogarithmicId ]->setOn( true );
1295 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1298 // myPlot->replot();
1302 Slot, called when Legend item is clicked
1304 void Plot2d_ViewFrame::onLegendClicked( long key )
1306 Plot2d_Curve* curve = myCurves[ key ];
1307 if ( curve && curve->hasIO() ) {
1308 SALOME_Selection* Sel = SALOME_Selection::Selection( QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
1309 Sel->ClearIObjects();
1310 Sel->AddIObject( curve->getIO(), true );
1315 Slot, called when user presses mouse button
1317 void Plot2d_ViewFrame::plotMousePressed( const QMouseEvent& me )
1319 if ( myOperation == NoOpId )
1320 myOperation = testOperation( me );
1321 if ( myOperation != NoOpId ) {
1323 if ( myOperation == ZoomId ) {
1324 myPlot->canvas()->setCursor( QCursor( QPixmap( imageZoomCursor ) ) );
1326 else if ( myOperation == PanId ) {
1327 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
1329 else if ( myOperation == FitAreaId ) {
1330 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1331 myPlot->setOutlineStyle( Qwt::Rect );
1335 int btn = me.button() | me.state();
1336 if ( btn == RightButton ) {
1339 QAD_Tools::checkPopup( myPopup );
1340 if ( myPopup->count()>0 ) {
1341 myPopup->exec( QCursor::pos() );
1347 myPlot->setOutlineStyle( Qwt::Cross );
1348 QAD_Application::getDesktop()->putInfo( getInfo( me.pos() ) );
1353 Slot, called when user moves mouse
1355 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1357 int dx = me.pos().x() - myPnt.x();
1358 int dy = me.pos().y() - myPnt.y();
1360 if ( myOperation != NoOpId) {
1361 if ( myOperation == ZoomId ) {
1362 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1363 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1365 myPlot->setAxisScale( QwtPlot::yLeft,
1366 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1367 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1368 myPlot->setAxisScale( QwtPlot::xBottom,
1369 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1370 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1374 else if ( myOperation == PanId ) {
1375 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1376 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1378 myPlot->setAxisScale( QwtPlot::yLeft,
1379 myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
1380 myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1381 myPlot->setAxisScale( QwtPlot::xBottom,
1382 myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1383 myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
1389 QAD_Application::getDesktop()->putInfo( getInfo( me.pos() ) );
1393 Slot, called when user releases mouse
1395 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1397 if ( myOperation == FitAreaId ) {
1398 QRect rect( myPnt, me.pos() );
1401 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1402 myPlot->setOutlineStyle( Qwt::Triangle );
1403 QAD_Application::getDesktop()->putInfo( tr( "INF_READY" ) );
1404 myOperation = NoOpId;
1407 View operations : Pan view
1409 void Plot2d_ViewFrame::onViewPan()
1411 myOperation = PanId;
1412 qApp->installEventFilter( this );
1415 View operations : Zoom view
1417 void Plot2d_ViewFrame::onViewZoom()
1419 myOperation = ZoomId;
1420 qApp->installEventFilter( this );
1423 View operations : Fot All
1425 void Plot2d_ViewFrame::onViewFitAll()
1430 View operations : Fit Area
1432 void Plot2d_ViewFrame::onViewFitArea()
1434 myOperation = FitAreaId;
1435 qApp->installEventFilter( this );
1438 View operations : Global panning
1440 void Plot2d_ViewFrame::onViewGlobalPan()
1441 { MESSAGE( "Plot2d_ViewFrame::onViewGlobalPan : NOT SUPPORTED" ); }
1443 View operations : Rotate view
1445 void Plot2d_ViewFrame::onViewRotate()
1446 { MESSAGE( "Plot2d_ViewFrame::onViewRotate : NOT SUPPORTED" ); }
1448 View operations : Reset view
1450 void Plot2d_ViewFrame::onViewReset()
1451 { MESSAGE( "Plot2d_ViewFrame::onViewReset : NOT SUPPORTED" ); }
1453 View operations : View front
1455 void Plot2d_ViewFrame::onViewFront()
1456 { MESSAGE( "Plot2d_ViewFrame::onViewFront : NOT SUPPORTED" ); }
1458 View operations : View back
1460 void Plot2d_ViewFrame::onViewBack()
1461 { MESSAGE( "Plot2d_ViewFrame::onViewBack : NOT SUPPORTED" ); }
1463 View operations : View right
1465 void Plot2d_ViewFrame::onViewRight()
1466 { MESSAGE( "Plot2d_ViewFrame::onViewRight : NOT SUPPORTED" ); }
1468 View operations : View left
1470 void Plot2d_ViewFrame::onViewLeft()
1471 { MESSAGE( "Plot2d_ViewFrame::onViewLeft : NOT SUPPORTED" ); }
1473 View operations : View bottom
1475 void Plot2d_ViewFrame::onViewBottom()
1476 { MESSAGE( "Plot2d_ViewFrame::onViewBottom : NOT SUPPORTED" ); }
1478 View operations : View top
1480 void Plot2d_ViewFrame::onViewTop()
1481 { MESSAGE( "Plot2d_ViewFrame::onViewTop : NOT SUPPORTED" ); }
1483 View operations : Show/hide trihedron
1485 void Plot2d_ViewFrame::onViewTrihedron()
1486 { MESSAGE( "Plot2d_ViewFrame::onViewTrihedron : NOT SUPPORTED" ); }
1489 //=================================================================================
1490 // Plot2d_Plot2d implementation
1491 //=================================================================================
1496 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1500 enableOutline( true );
1501 setOutlineStyle( Qwt::Triangle );
1502 setOutlinePen( green );
1504 setAutoLegend( false );
1505 setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1506 enableLegend( false );
1508 enableGridX( false );
1509 enableGridXMin( false );
1510 enableGridY( false );
1511 enableGridYMin( false );
1512 // auto scaling by default
1513 setAxisAutoScale( QwtPlot::yLeft );
1514 setAxisAutoScale( QwtPlot::xBottom );
1517 Recalculates and redraws Plot 2d view
1519 void Plot2d_Plot2d::replot()
1521 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
1525 Checks if two colors are close to each other [ static ]
1526 uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1528 const long COLOR_DISTANCE = 100;
1529 const int MAX_ATTEMPTS = 10;
1530 static bool closeColors( const QColor& color1, const QColor& color2 )
1532 long tol = abs( color2.red() - color1.red() ) +
1533 abs( color2.green() - color1.green() ) +
1534 abs( color2.blue() - color1.blue() );
1536 return ( tol <= COLOR_DISTANCE );
1539 Gets new unique marker for item if possible
1541 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
1546 int aRed = (int)( 256.0 * random() / RAND_MAX); // generate random color
1547 int aGreen = (int)( 256.0 * random() / RAND_MAX); // ...
1548 int aBlue = (int)( 256.0 * random() / RAND_MAX); // ...
1549 int aMarker = (int)( 9.0 * random() / RAND_MAX) + 1; // 9 markers types ( not including empty )
1550 int aLine = (int)( 5.0 * random() / RAND_MAX) + 1; // 5 line types ( not including empty )
1552 typeMarker = ( QwtSymbol::Style )aMarker;
1553 color = QColor( aRed, aGreen, aBlue );
1554 typeLine = ( Qt::PenStyle )aLine;
1557 if ( cnt == MAX_ATTEMPTS )
1560 bOk = !existMarker( typeMarker, color, typeLine );
1563 static int aMarker = -1;
1564 static int aColor = -1;
1565 static int aLine = -1;
1567 if ( myColors.isEmpty() ) {
1568 // creating colors list
1569 myColors.append( Qt::white );
1570 myColors.append( Qt::blue );
1571 myColors.append( Qt::gray );
1572 myColors.append( Qt::darkGreen );
1573 myColors.append( Qt::magenta );
1574 myColors.append( Qt::darkGray );
1575 myColors.append( Qt::red );
1576 myColors.append( Qt::darkBlue );
1577 myColors.append( Qt::darkYellow );
1578 myColors.append( Qt::cyan );
1579 myColors.append( Qt::darkRed );
1580 myColors.append( Qt::darkCyan );
1581 myColors.append( Qt::yellow );
1582 myColors.append( Qt::darkMagenta );
1583 myColors.append( Qt::green );
1584 myColors.append( Qt::black );
1587 int nbMarkers = 11; // QwtSymbol supports 11 marker types
1588 int nbLines = 6; // Qt supports 6 line types
1589 int nbColors = myColors.count(); // number of default colors supported
1591 aMarker = ( aMarker + 1 ) % nbMarkers;
1592 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1593 aColor = ( aColor + 1 ) % nbColors;
1594 aLine = ( aLine + 1 ) % nbLines;
1595 if ( aLine == Qt::NoPen ) aLine++;
1597 typeMarker = ( QwtSymbol::Style )aMarker;
1598 color = myColors[ aColor ];
1599 typeLine = ( Qt::PenStyle )aLine;
1600 if ( !existMarker( typeMarker, color, typeLine ) )
1604 for ( i = 0; i < nbMarkers; i++ ) {
1605 aMarker = ( aMarker + 1 ) % nbMarkers;
1606 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1607 for ( j = 0; j < nbColors; j++ ) {
1608 aColor = ( aColor + 1 ) % nbColors;
1609 for ( k = 0; k < nbLines; k++ ) {
1610 aLine = ( aLine + 1 ) % nbLines;
1611 if ( aLine == Qt::NoPen ) aLine++;
1612 if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1613 typeMarker = ( QwtSymbol::Style )aMarker;
1614 color = myColors[ aColor ];
1615 typeLine = ( Qt::PenStyle )aLine;
1624 Checks if marker belongs to any enitity
1626 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
1628 // getting all curves
1629 QArray<long> keys = curveKeys();
1632 if ( closeColors( color, backgroundColor() ) )
1634 for ( int i = 0; i < keys.count(); i++ ) {
1635 QwtPlotCurve* crv = curve( keys[i] );
1637 QwtSymbol::Style aStyle = crv->symbol().style();
1638 QColor aColor = crv->pen().color();
1639 Qt::PenStyle aLine = crv->pen().style();
1640 // if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1641 if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )