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 #include "Plot2d_ViewFrame.h"
25 #include "Plot2d_Prs.h"
26 #include "Plot2d_Curve.h"
27 #include "Plot2d_PlotItems.h"
28 #include "Plot2d_FitDataDlg.h"
30 #include "Plot2d_ViewWindow.h"
32 #include "Plot2d_SetupViewDlg.h"
33 #ifndef NO_ANALYTICAL_CURVES
34 #include "Plot2d_AnalyticalCurveDlg.h"
35 #include "Plot2d_AnalyticalCurve.h"
37 #include "Plot2d_ToolTip.h"
40 #include "SUIT_Tools.h"
41 #include "SUIT_Session.h"
42 #include "SUIT_MessageBox.h"
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Application.h"
46 #include <QMessageBox>
49 #include <QApplication>
51 #include <QToolButton>
53 #include <QColorDialog>
57 #include <QPaintDevice>
59 #include <QMouseEvent>
60 #include <QContextMenuEvent>
64 #include <QXmlStreamWriter>
65 #include <QXmlStreamReader>
68 #include <qwt_plot_layout.h>
69 #include <qwt_plot_canvas.h>
70 #include <qwt_scale_div.h>
71 #include <qwt_plot_marker.h>
72 #include <qwt_plot_curve.h>
73 #include <qwt_plot_grid.h>
74 #include <qwt_scale_engine.h>
75 #include <qwt_plot_zoomer.h>
76 #include <qwt_curve_fitter.h>
77 #include <qwt_plot_renderer.h>
78 #include <qwt_legend.h>
79 #include <qwt_scale_widget.h>
84 #define DEFAULT_LINE_WIDTH 0 // (default) line width
85 #define DEFAULT_MARKER_SIZE 9 // default marker size
86 #define MIN_RECT_SIZE 11 // min sensibility area size
88 #define FITALL_EVENT ( QEvent::User + 9999 )
90 const char* imageZoomCursor[] = {
95 "................................",
96 "................................",
97 ".#######........................",
98 "..aaaaaaa.......................",
99 "................................",
100 ".............#####..............",
101 "...........##.aaaa##............",
102 "..........#.aa.....a#...........",
103 ".........#.a.........#..........",
104 ".........#a..........#a.........",
105 "........#.a...........#.........",
106 "........#a............#a........",
107 "........#a............#a........",
108 "........#a............#a........",
109 "........#a............#a........",
110 ".........#...........#.a........",
111 ".........#a..........#a.........",
112 ".........##.........#.a.........",
113 "........#####.....##.a..........",
114 ".......###aaa#####.aa...........",
115 "......###aa...aaaaa.......#.....",
116 ".....###aa................#a....",
117 "....###aa.................#a....",
118 "...###aa...............#######..",
119 "....#aa.................aa#aaaa.",
120 ".....a....................#a....",
121 "..........................#a....",
122 "...........................a....",
123 "................................",
124 "................................",
125 "................................",
126 "................................"};
128 const char* imageCrossCursor[] = {
133 "................................",
134 "................................",
135 "................................",
136 "................................",
137 "................................",
138 "................................",
139 "................................",
140 "...............#................",
141 "...............#a...............",
142 "...............#a...............",
143 "...............#a...............",
144 "...............#a...............",
145 "...............#a...............",
146 "...............#a...............",
147 "...............#a...............",
148 ".......#################........",
149 "........aaaaaaa#aaaaaaaaa.......",
150 "...............#a...............",
151 "...............#a...............",
152 "...............#a...............",
153 "...............#a...............",
154 "...............#a...............",
155 "...............#a...............",
156 "...............#a...............",
157 "................a...............",
158 "................................",
159 "................................",
160 "................................",
161 "................................",
162 "................................",
163 "................................",
164 "................................"};
179 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
180 : QWidget (parent, 0),
181 myOperation( NoOpId ),
183 myShowLegend( true ), myLegendPos( 1 ), myLegendSymbolType( 0 ), myLegendFont("Helvetic",12),
184 myLegendColor(Qt::black), mySelectedLegendFontColor( Qt::darkBlue ),
185 myMarkerSize( DEFAULT_MARKER_SIZE ),
186 myBackground( Qt::white ),
187 mySelectionColor( Qt::gray ),
188 myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
189 myTitleEnabled( true ), myXTitleEnabled( true ),
190 myYTitleEnabled( true ), myY2TitleEnabled (true),
191 myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
192 myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
193 myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
194 myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
195 myXMode( 0 ), myYMode( 0 ),myNormLMin(false), myNormLMax(false), myNormRMin(false), myNormRMax(false),
196 mySecondY( false ), myIsDefTitle( true )
198 setObjectName( title );
199 myRNormAlgo = new Plot2d_NormalizeAlgorithm(this);
200 myLNormAlgo = new Plot2d_NormalizeAlgorithm(this);
202 QVBoxLayout* aLayout = new QVBoxLayout( this );
203 aLayout->setMargin(0);
204 myPlot = new Plot2d_Plot2d( this );
205 new Plot2d_ToolTip( this );
207 aLayout->addWidget( myPlot );
216 Plot2d_ViewFrame::~Plot2d_ViewFrame()
220 Performs the initial setup.
222 void Plot2d_ViewFrame::Init()
224 /* Initial Setup - get from the preferences */
227 setCurveType( myCurveType, false );
228 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
229 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
230 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
232 setTitle( myTitleEnabled, myTitle, MainTitle, false );
233 setTitle( myXTitleEnabled, myXTitle, XTitle, false );
234 setTitle( myYTitleEnabled, myYTitle, YTitle, false );
237 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
238 setHorScaleMode( myXMode, false );
239 setVerScaleMode( myYMode, false );
240 setBackgroundColor( myBackground );
241 setSelectionColor( mySelectionColor );
242 setLegendPos( myLegendPos );
243 setLegendSymbolType( myLegendSymbolType );
244 setLegendFont( myLegendFont );
245 setLegendFontColor( myLegendColor );
246 setSelectedLegendFontColor( mySelectedLegendFontColor );
247 showLegend( myShowLegend, false );
250 QWidget* aParent = parentWidget();
252 resize( (int)(0.8 * aParent->width()), (int)(0.8 * aParent->height()) );
254 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
255 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
256 myXDistance = xMap.s2() - xMap.s1();
257 myYDistance = yMap.s2() - yMap.s1();
260 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
261 myYDistance2 = yMap2.s2() - yMap2.s1();
263 myPlot->canvas()->installEventFilter( this );
265 void Plot2d_ViewFrame::SetPreference()
268 setBackgroundColor( myBackground );
269 setSelectionColor( mySelectionColor );
270 setCurveType( myCurveType, true );
271 setMarkerSize( myMarkerSize, true );
272 showLegend( myShowLegend, true );
273 setLegendPos( myLegendPos );
274 setLegendSymbolType( myLegendSymbolType );
275 setLegendFont( myLegendFont );
276 setLegendFontColor( myLegendColor );
277 setSelectedLegendFontColor( mySelectedLegendFontColor );
281 Gets window's central widget
283 QWidget* Plot2d_ViewFrame::getViewWidget()
285 return (QWidget*)myPlot;
288 Actually this method just re-displays all curves which are presented in the viewer
290 void Plot2d_ViewFrame::DisplayAll()
294 foreach ( Plot2d_Object* o, olist )
295 updateObject( o, false );
297 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
300 Removes all curves from the view
302 void Plot2d_ViewFrame::EraseAll()
304 objectList anObjects;
305 getObjects( anObjects );
306 eraseObjects( anObjects, false );
309 // 1)- Erase all the intermittent segments who connect curves
311 int nbSeg = myIntermittentSegmentList.size();
314 for (int iseg=0; iseg < nbSeg; iseg++)
316 QwtPlotCurve *segment = myIntermittentSegmentList[iseg];
318 segment->detach(); // erase in QwtPlot window
321 myIntermittentSegmentList.clear();
324 // 3)- Erase all QwtPlotCurve associated with the Plot2d_Curve
326 int nbCur1 = myQwtPlotCurveList.size();
329 for (int icur=0; icur < nbCur1; icur++)
331 QwtPlotItem *curve0 = myQwtPlotCurveList[icur];
332 QwtPlotCurve *curve = static_cast<QwtPlotCurve*>(curve0);
339 myQwtPlotCurveList.clear();
342 // 4)- Erase all curves Plot2d_Curve
344 int nbCur = myPlot2dCurveList.size();
347 for (int icur=0; icur < nbCur; icur++)
349 Plot2d_Curve *curve = myPlot2dCurveList[icur];
356 myPlot2dCurveList.clear();
359 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
362 Redraws viewframe contents
364 void Plot2d_ViewFrame::Repaint()
371 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
373 if ( !prs || prs->IsNull() )
376 setEnableAxis( QwtPlot::yRight, prs->isSecondY() ); // VSR: is it correct? maybe we should only enable second Y axis if required
378 // display all objects from presentation
379 objectList anObjects = prs->getObjects();
380 displayObjects( anObjects );
381 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
382 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
383 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
384 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
390 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
392 if ( !prs || prs->IsNull() )
395 // erase all objects from presentation
396 objectList anObjects = prs->getObjects();
397 eraseObjects( anObjects );
398 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
401 bool Plot2d_ViewFrame::eventFilter( QObject* watched, QEvent* e )
403 if ( watched == myPlot->canvas() ) {
404 int aType = e->type();
406 case QEvent::MouseMove: {
407 QMouseEvent* me = (QMouseEvent*)e;
408 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
409 QMouseEvent m( QEvent::MouseMove, me->pos(), me->button(),
410 me->buttons(), me->modifiers() );
411 if ( plotMouseMoved( m ) )
416 case QEvent::MouseButtonPress: {
417 QMouseEvent* me = (QMouseEvent*)e;
418 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
419 QMouseEvent m( QEvent::MouseButtonPress, me->pos(), me->button(),
420 me->buttons(), me->modifiers() );
421 plotMousePressed( m );
425 case QEvent::MouseButtonRelease: {
426 QMouseEvent* me = (QMouseEvent*)e;
427 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
428 QMouseEvent m( QEvent::MouseButtonRelease, me->pos(), me->button(),
429 me->buttons(), me->modifiers() );
430 plotMouseReleased( m );
434 case QEvent::ContextMenu:
436 // Do nothing because context menu is called from MouseRelease
440 return QWidget::eventFilter( watched, e );
446 void Plot2d_ViewFrame::setTitle( const QString& title )
448 setTitle( myTitleEnabled, title, MainTitle, true );
449 myIsDefTitle = false;
455 QString Plot2d_ViewFrame::getTitle() const
461 Reads Plot2d view settings from the preferences
463 void Plot2d_ViewFrame::readPreferences()
466 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
468 myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
469 setCurveType( resMgr->integerValue( "Plot2d", "CurveType", myCurveType ) );
471 myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
472 myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
473 myLegendSymbolType = resMgr->integerValue( "Plot2d", "LegendSymbolType", myLegendSymbolType );
474 myLegendFont = resMgr->fontValue( "Plot2d", "LegendFont", myLegendFont );
475 myLegendColor = resMgr->colorValue( "Plot2d", "LegendFontColor", myLegendColor );
476 mySelectedLegendFontColor = resMgr->colorValue( "Plot2d", "SelectedLegendFontColor", mySelectedLegendFontColor );
477 myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
478 myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
479 mySelectionColor = resMgr->colorValue( "Plot2d", "SelectionColor", mySelectionColor );
481 myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
482 myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
483 myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
484 myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
486 myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
487 myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
488 myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
490 myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
491 myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
492 myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
494 myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
495 myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
497 myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
499 myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
500 myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
502 myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
504 setHorScaleMode( qMax( 0, qMin( 1, resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode ) ) ), false );
505 setVerScaleMode( qMax( 0, qMin( 1, resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode ) ) ), false );
506 setNormLMinMode( resMgr->booleanValue( "Plot2d", "VerNormLMinMode", myNormLMin ) );
507 setNormLMaxMode( resMgr->booleanValue( "Plot2d", "VerNormLMaxMode", myNormLMax ) );
508 setNormRMinMode( resMgr->booleanValue( "Plot2d", "VerNormRMinMode", myNormRMin ) );
509 setNormRMaxMode( resMgr->booleanValue( "Plot2d", "VerNormRMaxMode", myNormRMax ) );
510 QColor c = resMgr->colorValue( "Plot2d", "DeviationMarkerColor", QColor(255,0,0));
511 myPlot->setProperty(PLOT2D_DEVIATION_COLOR, c);
512 myPlot->setProperty(PLOT2D_DEVIATION_LW,
513 resMgr->integerValue( "Plot2d", "DeviationMarkerLineWidth", 1));
514 myPlot->setProperty(PLOT2D_DEVIATION_TS,
515 resMgr->integerValue( "Plot2d", "DeviationMarkerTickSize", 2));
520 Writes Plot2d view settings to the preferences
522 void Plot2d_ViewFrame::writePreferences()
525 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
527 resMgr->setValue( "Plot2d", "CurveType", myCurveType );
528 resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
529 resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
530 resMgr->setValue( "Plot2d", "LegendSymbolType", myLegendSymbolType );
531 resMgr->setValue( "Plot2d", "LegendFont", myLegendFont );
532 resMgr->setValue( "Plot2d", "LegendFontColor", myLegendColor );
533 resMgr->setValue( "Plot2d", "SelectedLegendFontColor", mySelectedLegendFontColor );
534 resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
535 resMgr->setValue( "Plot2d", "Background", myBackground );
536 resMgr->setValue( "Plot2d", "SelectionColor", mySelectionColor );
537 resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
538 resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
539 resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
540 resMgr->setValue( "Plot2d", "DeviationMarkerColor", myPlot->property(PLOT2D_DEVIATION_COLOR).value<QColor>() );
541 resMgr->setValue( "Plot2d", "DeviationMarkerLineWidth", myPlot->property(PLOT2D_DEVIATION_LW).toInt() );
542 resMgr->setValue( "Plot2d", "DeviationMarkerTickSize", myPlot->property(PLOT2D_DEVIATION_TS).toInt() );
544 resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
546 resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
547 resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
548 resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
549 resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
551 resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
552 resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
554 resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
555 resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
557 resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
561 resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
562 resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
563 resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
564 resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
567 resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
568 resMgr->setValue( "Plot2d", "VerNormLMinMode", myNormLMin );
569 resMgr->setValue( "Plot2d", "VerNormLMaxMode", myNormLMax );
570 resMgr->setValue( "Plot2d", "VerNormRMinMode", myNormRMin );
571 resMgr->setValue( "Plot2d", "VerNormRMaxMode", myNormRMax );
576 Prints mouse cursor coordinates into string
578 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
582 bool xFound = false, yFound = false;
583 double xCoord, yCoord;
584 const QwtScaleDiv& aXscale = myPlot->axisScaleDiv( QwtPlot::xBottom );
585 aTicks = aXscale.ticks( QwtScaleDiv::MajorTick );
586 for ( i = 0; i < aTicks.count(); i++ ) {
587 double majXmark = aTicks[i];
588 int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
589 if ( xmark-2 == pnt.x() ) {
596 aTicks = aXscale.ticks( QwtScaleDiv::MinorTick );
597 for ( i = 0; i < aTicks.count(); i++ ) {
598 double minXmark = aTicks[i];
599 int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
600 if ( xmark-2 == pnt.x() ) {
607 const QwtScaleDiv& aYscale = myPlot->axisScaleDiv( QwtPlot::yLeft );
608 aTicks = aYscale.ticks( QwtScaleDiv::MajorTick );
609 for ( i = 0; i < aTicks.count(); i++ ) {
610 double majYmark = aTicks[i];
611 int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
612 if ( ymark-2 == pnt.y() ) {
619 aTicks = aYscale.ticks( QwtScaleDiv::MinorTick );
620 for ( i = 0; i < aTicks.count(); i++ ) {
621 double minYmark = aTicks[i];
622 int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
623 if ( ymark-2 == pnt.y() ) {
631 QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).trimmed();
634 QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).trimmed();
640 bool yFound2 = false;
643 const QwtScaleDiv& aYscale2 = myPlot->axisScaleDiv( QwtPlot::yRight );
644 aTicks = aYscale2.ticks( QwtScaleDiv::MajorTick );
645 for ( i = 0; i < aTicks.count(); i++ ) {
646 double majYmark = aTicks[i];
647 int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
648 if ( ymark-2 == pnt.y() ) {
655 aTicks = aYscale2.ticks( QwtScaleDiv::MinorTick );
656 for ( i = 0; i < aTicks.count(); i++ ) {
657 double minYmark = aTicks[i];
658 int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
659 if ( ymark-2 == pnt.y() ) {
666 QString strY2 = QString::number( yFound2 ? yCoord2 :
667 myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).trimmed();
670 info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
673 info = tr("INF_COORDINATES").arg( strX ).arg( strY );
679 * Display curves of the list of lists by systems and components
680 * - the first level list contains NbSytems lists of second level
681 * - a second level list contains NbComponents curves
682 * | system 1 | system 2 | ..... | system N |
683 * | compo1 compo2 ... compoM | compo1 compo2 ... compoM | ..... | compo1 compo2 ... compoM |
685 * Draw points markers and create associated tooltips.
686 * Draw connection segments (intermittent line) between all the curves of a component.
687 * \return the list of underlying plot curve that defines the complex cuve at once. In case of success the vector is at least of size 1. The first one is the curve used by the legend.
689 QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
691 const QList< QList<bool> >& sides)
693 //std::cout << "Plot2d_ViewFrame::displayPlot2dCurveList() 1" << std::endl;
696 int nbSystem = sysCoCurveList.size();
698 // Composants number by system
699 int nbComponent = (sysCoCurveList.at(0)).size();
701 // Total number of curves
703 // 1)- Construction of a list by component and by system
705 // | component 1 | component 2 | ..... | component M |
706 // | syst1 syst2 ... systN | syst1 syst2 ... systN | ..... | syst1 syst2 ... systN |
708 QList<Plot2d_Curve*> plot2dCurveCoSysList;
709 QList<bool> sidesList;
710 for (int icom = 0; icom < nbComponent; icom++)
712 for (int isys = 0; isys < nbSystem; isys++)
714 // The system curves list
715 const QList<Plot2d_Curve*>& sysCurveList=sysCoCurveList.at(isys);
716 plot2dCurveCoSysList.append(sysCurveList.at(icom));
718 const QList<bool>& sysSideList=sides.at(isys);
719 sidesList.append(sysSideList.at(icom));
722 // 2)- Display list curves by a component's curves group
723 // Draw connection segments (intermittent line) between the curves
724 QVector< QVector<QwtPlotCurve *> > ret=displayPlot2dCurveList( plot2dCurveCoSysList, nbSystem, displayLegend, sidesList);
725 // 3)- Size of graduations labels and texts under X axis
726 QwtScaleWidget *wid = myPlot->axisWidget( QwtPlot::xBottom);
727 wid->setTitle(" "); // to make the names readable under X axis.
728 QFont xFont = myPlot->axisFont(QwtPlot::xBottom);
729 xFont.setPointSize(8);
730 myPlot->setAxisFont(QwtPlot::xBottom, xFont);
736 * Display list of curves by group of consecutive curves.
738 * Draw points markers and create associated tooltips
739 * Draw connection segments (intermittent line) between the curves
740 * \param [in] sides sorted as in \b curveList. If true->right if false->left
741 * \return the list of underlying plot curve that defines the complex cuve at once. In case of success the vector is at least of size 1. The first one is the curve used by the legend.
743 QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
745 bool displayLegend, const QList< bool >& sides)
747 // Consider the new legend's entries
748 // (PB: to update the legend we must remove it and put a new QwtAbstractLegend in the QwtPlot)
749 myPlot->insertLegend( (QwtAbstractLegend*)NULL); // we remove here, we shall put at the end
751 int nbAllCurves = curveList.size();
752 int nbGroups = nbAllCurves / groupSize;
753 QVector< QVector<QwtPlotCurve *> > vectCurve(nbGroups);
755 int icur1, icur2; // curves indices in a group
757 // I)- Compute X range and Y range for all the curves' points of all groups
758 // In the graphic view, set the Y range 's bounds for all groups of curves
760 // For all groups of curves
761 double XallGroupMin=std::numeric_limits<double>::max(), XallGroupMax=-std::numeric_limits<double>::max();
762 double YRightallGroupMin=std::numeric_limits<double>::max(), YRightallGroupMax=-std::numeric_limits<double>::max();
763 double YLeftallGroupMin=std::numeric_limits<double>::max(), YLeftallGroupMax=-std::numeric_limits<double>::max();
765 for (ig=0; ig < nbGroups; ig++) //*1*
767 icur2 = icur1 + groupSize -1;
769 // For all curves in one group
770 double XgroupMin = 0., XgroupMax = 0.;
771 double YgroupMin = 0., YgroupMax = 0.;
774 double XcurveMin = 0., XcurveMax = 0.;
775 double YcurveMin = 0., YcurveMax = 0.;
780 // Compute X range and Y range for all the curves' points in the group
782 for (icur=icur1; icur <= icur2; icur++) //*2*
784 Plot2d_Curve *plot2dCurve = curveList.at(icur);
787 nbPoints = plot2dCurve->getData( &Xval, &Yval); // dynamic allocation
789 for (int ip=0; ip < nbPoints; ip++)
791 if (ip == 0) // first point
793 XcurveMin = Xval[ip]; XcurveMax = Xval[ip];
794 YcurveMin = Yval[ip]; YcurveMax = Yval[ip];
798 if (Xval[ip] < XcurveMin) XcurveMin = Xval[ip];
799 else if (Xval[ip] > XcurveMax) XcurveMax = Xval[ip];
800 if (Yval[ip] < YcurveMin) YcurveMin = Yval[ip];
801 else if (Yval[ip] > YcurveMax) YcurveMax = Yval[ip];
807 if (icur == icur1) // first curve
809 XgroupMin = XcurveMin; XgroupMax = XcurveMax;
810 YgroupMin = YcurveMin; YgroupMax = YcurveMax;
814 if (XcurveMin < XgroupMin) XgroupMin = XcurveMin;
815 if (XcurveMax > XgroupMax) XgroupMax = XcurveMax;
816 if (YcurveMin < YgroupMin) YgroupMin = YcurveMin;
817 if (YcurveMax > YgroupMax) YgroupMax = YcurveMax;
821 if (XgroupMin < XallGroupMin) XallGroupMin = XgroupMin;
822 if (XgroupMax > XallGroupMax) XallGroupMax = XgroupMax;
825 if (YgroupMin < YRightallGroupMin) YRightallGroupMin = YgroupMin;
826 if (YgroupMax > YRightallGroupMax) YRightallGroupMax = YgroupMax;
830 if (YgroupMin < YLeftallGroupMin) YLeftallGroupMin = YgroupMin;
831 if (YgroupMax > YLeftallGroupMax) YLeftallGroupMax = YgroupMax;
833 // First curve of the following group
836 // Set the XY range 's bounds for all groups of curves
837 if(YRightallGroupMin!=std::numeric_limits<double>::max())
839 double deltaY = YRightallGroupMax - YRightallGroupMin;
840 YRightallGroupMin-=0.05*deltaY; YRightallGroupMax+= 0.05*deltaY;
841 myPlot->setAxisScale( QwtPlot::yRight, YRightallGroupMin,YRightallGroupMax);
843 if(YLeftallGroupMin!=std::numeric_limits<double>::max())
845 double deltaY = YLeftallGroupMax - YLeftallGroupMin;
846 YLeftallGroupMin-=0.05*deltaY; YLeftallGroupMax+= 0.05*deltaY;
847 myPlot->setAxisScale( QwtPlot::yLeft, YLeftallGroupMin, YLeftallGroupMax);
849 // II)- Drawing curves, points markers and connection segments
852 for (ig=0; ig < nbGroups; ig++)
854 // 1)- Graphical attributs of group's curves
856 // Graphical attributes of the first group's curve
858 Plot2d_Curve *plot2dCurve1 = curveList.at(icur1);
860 QColor color1 = plot2dCurve1->getColor();
861 Plot2d::LineType linetype1 = plot2dCurve1->getLine();
862 int lineWidth1 = plot2dCurve1->getLineWidth();
863 QwtSymbol::Style symbolStyle1 = plot2dCurve1->getMarkerStyle();
864 // We attribute to the current group's curve, the color, the line's kind
865 // and the marker's kind of the first group's curve
867 for (icur=icur1+1; icur<icur1+groupSize; icur++)
869 Plot2d_Curve *plot2dCurve = curveList.at(icur);
871 plot2dCurve->setColor(color1);
872 plot2dCurve->setLine(linetype1,lineWidth1);
873 plot2dCurve->setMarkerStyle(symbolStyle1);
876 // 2)- Display the group's curves
878 for (icur=icur1; icur<icur1+groupSize; icur++)
880 Plot2d_Curve *plot2dCurve = curveList.at(icur);
882 QString title = plot2dCurve->getVerTitle();
883 std::string std_title = title.toStdString();
884 // Create the graphic curve (QwtPlotCurve) et display it in the drawing zone
886 displayCurve(plot2dCurve);
888 // Get the graphic curve
889 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>(getPlotObject(plot2dCurve));
890 vectCurve[ig].push_back(plotCurve);
891 // Modify the points' markers
892 QwtSymbol* symbol = new QwtSymbol(plotCurve->symbol()->style(), plotCurve->symbol()->brush(),
893 plotCurve->symbol()->pen(), plotCurve->symbol()->size()) ;
894 symbol->setStyle(symbolStyle1);
895 symbol->setPen(QPen(color1,lineWidth1));
896 //symbol.setBrush( QBrush( color1));
897 //QSize size = 0.5*(symbol.size());
898 //symbol.setSize(size);
900 plotCurve->setPen(QPen(color1,lineWidth1));
901 plotCurve->setSymbol(symbol);
905 //std::cout << " courbe d'indice " << icur << " sans entree dans la legende" << std::endl;
907 // The curve must not have legend's entry
908 plotCurve->setItemAttribute( QwtPlotItem::Legend, false);
912 plotCurve->setItemAttribute( QwtPlotItem::Legend, true);
916 // 3)- Intermittent segments to connect all the group's curves
923 double Xseg[2], Yseg[2];
924 Plot2d_Curve *plot2dCurve1 = curveList.at(icur1);
925 bool side = sides.at(icur1);
926 // Last point of the first curve
927 nbPoints = plot2dCurve1->getData( &Xval, &Yval); // dynamic allocation
928 Xseg[0] = Xval[ nbPoints -1];
929 Yseg[0] = Yval[ nbPoints -1];
933 for (icur=icur1+1; icur<icur1+groupSize; icur++)
935 Plot2d_Curve *plot2dCurve = curveList.at(icur);
937 // First curve's point
938 nbPoints = plot2dCurve->getData( &Xval, &Yval);
942 vectCurve[ig].push_back(createSegment(Xseg,Yseg,2,Qt::DotLine,lineWidth1,color1,QwtSymbol::NoSymbol,side));
944 // Last curve's point
945 Xseg[0] = Xval[ nbPoints -1];
946 Yseg[0] = Yval[ nbPoints -1];
951 // First curve of the following group
957 // Consider the new legend's entries
958 if(!curveList.empty())
959 showLegend( true, true); // show, update
966 * Create and display an y=f(x) curve of points
968 * toDraw : true => Display the created curve
969 * Draw the points'markers and create associated tooltips
971 Plot2d_Curve* Plot2d_ViewFrame::createPlot2dCurve( QString & title,
973 QList<double> & xList,
974 QList<double> & yList,
975 QList<QString> & tooltipList,
976 Plot2d::LineType lineKind,
979 QwtSymbol::Style markerKind,
980 Plot2d_QwtPlotPicker* /*picker*/,
984 //std::cout << "Plot2d_ViewFrame::createPlot2dCurve()" << std::endl;
986 // Mathematical curve
987 Plot2d_Curve* plot2dCurve = new Plot2d_Curve();
989 // To deallocate in EraseAll()
990 myPlot2dCurveList.append( plot2dCurve);
992 int nbPoint = xList.size();
996 for (int ip=0; ip < nbPoint; ip++)
1000 tooltip = tooltipList.at(ip);
1002 plot2dCurve->addPoint( xVal, yVal, tooltip);
1005 plot2dCurve->setVerTitle( title);
1006 plot2dCurve->setVerUnits( unit);
1007 if (lineColor.isValid())
1009 plot2dCurve->setColor( lineColor);
1011 plot2dCurve->setLine( lineKind, lineWidth);
1012 plot2dCurve->setMarkerStyle( markerKind);
1013 plot2dCurve->setMarkerSize(1);
1015 // Graphical curve (QwtPlotCurve) in the drawing zone (QwtPlot) myPlot
1020 myPlot->insertLegend( (QwtAbstractLegend*)NULL);
1022 displayCurve( plot2dCurve);
1024 // Get the graphical curve
1025 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>( getPlotObject( plot2dCurve));
1029 if (lineColor.isValid())
1031 //std::cout << " valid color" << std::endl;
1032 theColor = lineColor;
1036 //std::cout << " valid color" << std::endl;
1037 QPen pen = plotCurve->pen();
1038 theColor = pen.color();
1041 // Modify points' markers
1042 QwtSymbol* symbol = new QwtSymbol( plotCurve->symbol()->style(), plotCurve->symbol()->brush(),
1043 plotCurve->symbol()->pen(), plotCurve->symbol()->size() ) ;
1044 symbol->setStyle( markerKind );
1046 if (markerKind != QwtSymbol::NoSymbol)
1048 symbol->setPen( QPen( theColor, lineWidth));
1049 symbol->setBrush( QBrush( theColor));
1050 QSize size = 2.0*(symbol->size()); //0.5
1051 symbol->setSize(size);
1054 plotCurve->setSymbol( symbol);
1055 plotCurve->setStyle( QwtPlotCurve::Lines);
1056 plotCurve->setPen( QPen( theColor, lineWidth));
1058 // The curve must not have legend's entry
1059 plotCurve->setItemAttribute( QwtPlotItem::Legend, false);
1068 QColor Plot2d_ViewFrame::getPlot2dCurveColor( Plot2d_Curve* plot2dCurve)
1071 // Get graphical curve
1072 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>( getPlotObject( plot2dCurve));
1074 QPen pen = plotCurve->pen();
1075 QColor color = pen.color();
1082 * Create and display a segment with nbPoint=2 points
1084 QwtPlotCurve *Plot2d_ViewFrame::createSegment( double *X, double *Y, int nbPoint,
1085 Qt::PenStyle lineKind,
1088 QwtSymbol::Style markerKind, bool side)
1090 QwtPlotCurve* aPCurve = new QwtPlotCurve( QString::null );
1092 aPCurve->setSamples( X, Y, nbPoint);
1094 aPCurve->setPen( QPen( lineColor, lineWidth, lineKind));
1095 QwtSymbol* aSymbol = new QwtSymbol();
1096 aSymbol->setStyle( markerKind );
1097 aPCurve->setSymbol( aSymbol );
1099 // The segment must not have legend's entry
1100 aPCurve->setItemAttribute( QwtPlotItem::Legend, false);
1102 aPCurve->attach(myPlot);
1103 aPCurve->setYAxis(side ? QwtPlot::yRight : QwtPlot::yLeft);
1104 // To deallocate in EraseAll()
1105 myIntermittentSegmentList.append(aPCurve);
1110 Adds curve into view
1112 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
1114 QwtPlotItem* anItem = displayObject( curve, update );
1115 // To deallocate in EraseAll()
1116 myQwtPlotCurveList.append( anItem);
1120 Adds curves into view
1122 void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
1125 foreach ( Plot2d_Curve* curve, curves )
1127 displayObjects( objects, update );
1133 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
1135 eraseObject( curve, update );
1141 void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
1144 foreach ( Plot2d_Curve* curve, curves )
1146 eraseObjects( objects, update );
1150 Updates curves attributes
1152 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
1154 updateObject( curve, update );
1157 void Plot2d_ViewFrame::processFiltering(bool update)
1159 CurveDict aCurves = getCurves();
1160 AlgoPlot2dInputData aLData, aRData;
1161 CurveDict::iterator it;
1162 for ( it = aCurves.begin(); it != aCurves.end(); it++ ) {
1163 Plot2d_Object* objItem = it.value();
1164 if (objItem->getYAxis() == QwtPlot::yRight)
1165 aRData.append(objItem);
1167 aLData.append(objItem);
1170 // Normalization by left Y axis
1171 if (!myNormLMin && !myNormLMax)
1172 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
1173 if(myNormLMin && myNormLMax)
1174 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
1176 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
1178 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMax);
1180 myLNormAlgo->setInput(aLData);
1181 myLNormAlgo->execute();
1183 // Normalization by right Y axis
1184 if (!myNormRMin && !myNormRMax)
1185 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
1186 if(myNormRMin && myNormRMax)
1187 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
1189 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
1191 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMax);
1193 myRNormAlgo->setInput(aRData);
1194 myRNormAlgo->execute();
1196 for ( it = aCurves.begin(); it != aCurves.end(); it++) {
1197 QwtPlotCurve* item = it.key();
1198 Plot2d_Object* objItem = it.value();
1199 updatePlotItem(objItem, item);
1206 Gets lsit of displayed curves
1208 int Plot2d_ViewFrame::getCurves( curveList& curves ) const
1212 CurveDict aCurves = getCurves();
1213 CurveDict::iterator it;
1214 for ( it = aCurves.begin(); it != aCurves.end(); it++ )
1215 curves << it.value();
1216 return curves.count();
1219 CurveDict Plot2d_ViewFrame::getCurves() const
1222 ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end();
1223 for ( ; it != aLast; it++ ) {
1224 QwtPlotItem* anItem = it.key();
1225 if ( anItem && anItem->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
1226 QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( anItem );
1227 Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( it.value() );
1228 if ( aPCurve && aCurve )
1229 curves.insert( aPCurve, aCurve );
1236 Adds object into view
1238 QwtPlotItem* Plot2d_ViewFrame::displayObject( Plot2d_Object* object, bool update )
1240 QwtPlotItem* anItem = 0;
1244 if ( object->getYAxis() == QwtPlot::yRight )
1247 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
1248 // it crashes if switched to X/Y logarithmic mode, when one or more points have
1249 // non-positive X/Y coordinate
1250 if ( myXMode && object->getMinX() <= 0. )
1251 setHorScaleMode( 0, false );
1252 if ( myYMode && object->getMinY() <= 0. )
1253 setVerScaleMode( 0, false );
1255 if ( object->isAutoAssign() )
1256 object->autoFill( myPlot );
1258 if ( hasPlotObject( object ) ) {
1259 processFiltering(update);
1260 updateObject( object, update );
1263 anItem = object->createPlotItem();
1264 anItem->attach( myPlot );
1265 myObjects.insert( anItem, object );
1266 //myPlot->setCurveYAxis(curveKey, curve->getYAxis());
1268 if ( object->rtti() == QwtPlotItem::Rtti_PlotCurve )
1270 Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( object );
1273 if ( aCurve->getMarkerSize() == 0 )
1274 aCurve->setMarkerSize( myMarkerSize );
1276 processFiltering(update);
1277 updatePlotItem( aCurve, anItem );
1278 setCurveType( getPlotCurve( aCurve ), myCurveType );
1282 updateTitles( false );
1283 myPlot->updateYAxisIdentifiers();
1286 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1292 Adds objects into view
1294 void Plot2d_ViewFrame::displayObjects( const objectList& objects, bool update )
1296 //myPlot->setUpdatesEnabled( false ); // call this function deprecate update of legend
1297 foreach ( Plot2d_Object* object, objects )
1298 displayObject( object, false );
1300 //myPlot->setUpdatesEnabled( true );
1309 void Plot2d_ViewFrame::eraseObject( Plot2d_Object* object, bool update )
1314 if ( hasPlotObject( object ) ) {
1315 QwtPlotItem* anObject = getPlotObject( object );
1316 eraseBasicObject(anObject,update);
1319 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1323 void Plot2d_ViewFrame::eraseBasicObject( QwtPlotItem *object, bool update )
1329 myObjects.remove(object);
1330 updateTitles(update);
1331 myPlot->updateYAxisIdentifiers();
1339 void Plot2d_ViewFrame::eraseObjects( const objectList& objects, bool update )
1341 foreach ( Plot2d_Object* object, objects )
1342 eraseObject( object, false );
1347 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1350 void Plot2d_ViewFrame::eraseBasicObjects( const QList<QwtPlotItem*> &objects, bool update)
1352 foreach ( QwtPlotItem* object, objects )
1353 eraseBasicObject( object, false );
1357 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1361 Updates objects attributes
1363 void Plot2d_ViewFrame::updateObject( Plot2d_Object* object, bool update )
1367 if ( hasPlotObject( object ) ) {
1368 QwtPlotItem* anItem = getPlotObject( object );
1371 updatePlotItem(object, anItem );
1372 anItem->setVisible( true );
1375 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1381 Gets lsit of displayed curves
1383 int Plot2d_ViewFrame::getObjects( objectList& objects ) const
1387 ObjectDict::const_iterator it;
1388 for ( it = myObjects.begin(); it != myObjects.end(); it++ )
1389 objects << it.value();
1390 return objects.count();
1394 Returns true if the curve is visible
1396 bool Plot2d_ViewFrame::isVisible( Plot2d_Object* object ) const
1398 return object && hasPlotObject( object ) && getPlotObject( object )->isVisible();
1404 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
1406 if ( !prs || prs->IsNull() )
1409 ObjectDict::iterator it = myObjects.begin();
1410 Plot2d_Object* anObj;
1411 for (; it != myObjects.end(); ++it ) {
1413 if ( hasPlotObject( anObj ) )
1414 getPlotObject( anObj )->setTitle( !anObj->getName().isEmpty() ?
1415 anObj->getName() : anObj->getVerTitle() );
1422 void Plot2d_ViewFrame::updateLegend() {
1423 const QwtPlotItemList& items = myPlot->itemList();
1424 QwtPlotItemIterator it;
1425 for ( it = items.begin(); it != items.end(); it++ ) {
1426 QwtPlotItem* item = *it;
1428 item->updateLegend( item, item->legendData() );
1434 Fits the view to see all data
1436 void Plot2d_ViewFrame::fitAll()
1438 // no need to set auto scaling, it will be disabled by setAxisScale() method call
1439 // myPlot->setAxisAutoScale( QwtPlot::yLeft );
1440 // myPlot->setAxisAutoScale( QwtPlot::xBottom );
1441 // myPlot->replot();
1443 double xmin, xmax, y1min, y1max, y2min, y2max;
1444 getFitRangeByCurves(xmin, xmax, y1min, y1max, y2min, y2max);
1445 getFitRangeByMarkers(xmin, xmax, y1min, y1max, y2min, y2max);
1447 myPlot->setAxisScale( QwtPlot::xBottom, xmin, xmax );
1448 myPlot->setAxisScale( QwtPlot::yLeft, y1min, y1max );
1451 myPlot->setAxisAutoScale( QwtPlot::yRight );
1453 myPlot->setAxisScale( QwtPlot::yRight, y2min, y2max );
1456 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1460 Fits the view to rectangle area (pixels)
1462 void Plot2d_ViewFrame::fitArea( const QRect& area )
1464 QRect rect = area.normalized();
1465 if ( rect.width() < MIN_RECT_SIZE ) {
1466 rect.setWidth( MIN_RECT_SIZE );
1467 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
1469 if ( rect.height() < MIN_RECT_SIZE ) {
1470 rect.setHeight( MIN_RECT_SIZE );
1471 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
1473 myPlot->setAxisScale( QwtPlot::yLeft,
1474 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
1475 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
1477 myPlot->setAxisScale( QwtPlot::yRight,
1478 myPlot->invTransform( QwtPlot::yRight, rect.top() ),
1479 myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
1480 myPlot->setAxisScale( QwtPlot::xBottom,
1481 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
1482 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
1484 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1488 "Fit Data" command for TUI interface
1490 void Plot2d_ViewFrame::fitData(const int mode,
1491 const double xMin, const double xMax,
1492 const double yMin, const double yMax,
1493 double y2Min, double y2Max)
1495 if ( mode == 0 || mode == 2 ) {
1496 myPlot->setAxisScale( QwtPlot::yLeft, yMin, yMax );
1498 myPlot->setAxisScale( QwtPlot::yRight, y2Min, y2Max );
1500 if ( mode == 0 || mode == 1 )
1501 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
1503 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1507 Gets current fit ranges for view frame
1509 void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax,
1510 double& yMin, double& yMax,
1511 double& y2Min, double& y2Max)
1513 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).transform( myPlot->canvasMap( QwtPlot::xBottom ).s1() );
1514 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).transform( myPlot->canvasMap( QwtPlot::xBottom ).s2() );
1515 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).transform( myPlot->canvasMap( QwtPlot::yLeft ).s1() );
1516 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).transform( myPlot->canvasMap( QwtPlot::yLeft ).s2() );
1517 xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
1518 xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
1519 yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
1520 yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
1524 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).transform( myPlot->canvasMap( QwtPlot::yRight ).s1() );
1525 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).transform( myPlot->canvasMap( QwtPlot::yRight ).s2() );
1526 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
1527 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
1532 Gets current fit ranges by Curves
1534 void Plot2d_ViewFrame::getFitRangeByCurves(double& xMin, double& xMax,
1535 double& yMin, double& yMax,
1536 double& y2Min, double& y2Max)
1538 bool emptyV1 = true, emptyV2 = true;
1539 if ( !myObjects.isEmpty() ) {
1540 ObjectDict::const_iterator it = myObjects.begin();
1541 for ( ; it != myObjects.end(); it++ ) {
1542 bool isV2 = it.value()->getYAxis() == QwtPlot::yRight;
1543 if ( !it.value()->isEmpty() ) {
1544 if ( emptyV1 && emptyV2 ) {
1556 isV2 ? emptyV2 = false : emptyV1 = false;
1557 xMin = qMin( xMin, it.value()->getMinX() );
1558 xMax = qMax( xMax, it.value()->getMaxX() );
1560 y2Min = qMin( y2Min, it.value()->getMinY() );
1561 y2Max = qMax( y2Max, it.value()->getMaxY() );
1564 yMin = qMin( yMin, it.value()->getMinY() );
1565 yMax = qMax( yMax, it.value()->getMaxY() );
1569 if ( xMin == xMax ) {
1570 xMin = xMin == 0. ? -1. : xMin - xMin/10.;
1571 xMax = xMax == 0. ? 1. : xMax + xMax/10.;
1573 if ( yMin == yMax ) {
1574 yMin = yMin == 0. ? -1. : yMin - yMin/10.;
1575 yMax = yMax == 0. ? 1 : yMax + yMax/10.;
1577 if ( y2Min == y2Max ) {
1578 y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
1579 y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
1583 if ( emptyV1 && emptyV2 ) {
1584 xMin = isModeHorLinear() ? 0. : 1.;
1585 xMax = isModeHorLinear() ? 1000. : 1e5;
1588 yMin = isModeVerLinear() ? 0. : 1.;
1589 yMax = isModeVerLinear() ? 1000. : 1e5;
1592 y2Min = isModeVerLinear() ? 0. : 1.;
1593 y2Max = isModeVerLinear() ? 1000. : 1e5;
1598 Gets current fit ranges by Markers
1599 All parameters are inout.
1601 void Plot2d_ViewFrame::getFitRangeByMarkers(double& xMin, double& xMax,
1602 double& yMin, double& yMax,
1603 double& y2Min, double& y2Max)
1605 Plot2d_QwtPlotPicker *picker=myPlot->getPicker();
1608 if(picker->pMarkers.empty())
1610 foreach(QwtPlotMarker *mrker,picker->pMarkers)
1612 bool isV2 = mrker->yAxis() == QwtPlot::yRight;
1613 xMin = qMin( xMin, mrker->xValue() );
1614 xMax = qMax( xMax, mrker->xValue() );
1616 y2Min = qMin( y2Min, mrker->yValue() );
1617 y2Max = qMax( y2Max, mrker->yValue() );
1620 yMin = qMin( yMin, mrker->yValue() );
1621 yMax = qMax( yMax, mrker->yValue() );
1623 if ( xMin == xMax ) {
1624 xMin = xMin == 0. ? -1. : xMin - xMin/10.;
1625 xMax = xMax == 0. ? 1. : xMax + xMax/10.;
1627 if ( yMin == yMax ) {
1628 yMin = yMin == 0. ? -1. : yMin - yMin/10.;
1629 yMax = yMax == 0. ? 1 : yMax + yMax/10.;
1631 if ( y2Min == y2Max ) {
1632 y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
1633 y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
1639 Tests if it is necessary to start operation on mouse action
1641 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
1643 int btn = (int)me.button() | (int)me.modifiers();
1644 const int zoomBtn = (int)Qt::ControlModifier | (int)Qt::LeftButton;
1645 const int panBtn = (int)Qt::ControlModifier | (int)Qt::MidButton;
1646 const int fitBtn = (int)Qt::ControlModifier | (int)Qt::RightButton;
1649 if ( btn == zoomBtn ) {
1650 QPixmap zoomPixmap (imageZoomCursor);
1651 QCursor zoomCursor (zoomPixmap);
1652 myPlot->canvas()->setCursor( zoomCursor );
1655 else if ( btn == panBtn ) {
1656 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
1659 else if ( btn == fitBtn ) {
1660 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1667 "Settings" toolbar action slot
1669 void Plot2d_ViewFrame::onSettings()
1671 #ifdef TEST_AUTOASSIGN
1672 typedef QMap<int,int> IList;
1673 typedef QMap<QString,int> SList;
1676 cols[ "red-min" ] = 1000;
1677 cols[ "red-max" ] = -1;
1678 cols[ "green-min" ] = 1000;
1679 cols[ "green-max" ] = -1;
1680 cols[ "blue-min" ] = 1000;
1681 cols[ "blue-max" ] = -1;
1682 for ( unsigned i = 0; i < 10000; i++ ) {
1683 QwtSymbol::Style typeMarker;
1685 Qt::PenStyle typeLine;
1686 myPlot->getNextMarker( typeMarker, color, typeLine );
1687 if ( mars.contains(typeMarker) )
1688 mars[ typeMarker ] = mars[ typeMarker ]+1;
1690 mars[ typeMarker ] = 0;
1691 if ( lins.contains(typeLine) )
1692 lins[ typeLine ] = lins[ typeLine ]+1;
1694 lins[ typeLine ] = 0;
1695 if ( cols[ "red-max" ] < color.red() )
1696 cols[ "red-max" ] = color.red();
1697 if ( cols[ "red-min" ] > color.red() )
1698 cols[ "red-min" ] = color.red();
1699 if ( cols[ "green-max" ] < color.green() )
1700 cols[ "green-max" ] = color.green();
1701 if ( cols[ "green-min" ] > color.green() )
1702 cols[ "green-min" ] = color.green();
1703 if ( cols[ "blue-max" ] < color.blue() )
1704 cols[ "blue-max" ] = color.blue();
1705 if ( cols[ "blue-min" ] > color.blue() )
1706 cols[ "blue-min" ] = color.blue();
1710 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
1711 dlg->setMainTitle( myTitleEnabled, myTitle );
1712 dlg->setXTitle( myXTitleEnabled, myXTitle );
1713 dlg->setYTitle( myYTitleEnabled, myYTitle );
1715 dlg->setY2Title( myY2TitleEnabled, myY2Title );
1716 dlg->setCurveType( myCurveType );
1717 dlg->setLegend( myShowLegend, myLegendPos, myLegendSymbolType, myLegendFont,
1718 myLegendColor, mySelectedLegendFontColor );
1719 dlg->setMarkerSize( myMarkerSize );
1720 dlg->setBackgroundColor( myBackground );
1721 dlg->setSelectionColor( mySelectionColor );
1722 dlg->setScaleMode(myXMode, myYMode);
1723 dlg->setLMinNormMode(myNormLMin);
1724 dlg->setLMaxNormMode(myNormLMax);
1725 dlg->setRMinNormMode(myNormRMin);
1726 dlg->setRMaxNormMode(myNormRMax);
1728 QVariant v = myPlot->property(PLOT2D_DEVIATION_LW);
1729 int lw = v.isValid() ? v.toInt() : 1;
1731 v = myPlot->property(PLOT2D_DEVIATION_TS);
1732 int ts = v.isValid() ? v.toInt() : 2;
1734 v = myPlot->property(PLOT2D_DEVIATION_COLOR);
1735 QColor cl = v.isValid() ? v.value<QColor>() : QColor(255,0,0);
1737 dlg->setDeviationMarkerLw(lw);
1738 dlg->setDeviationMarkerTs(ts);
1739 dlg->setDeviationMarkerCl(cl);
1742 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
1743 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
1744 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
1745 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
1746 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
1747 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
1748 if ( dlg->exec() == QDialog::Accepted ) {
1749 // horizontal axis title
1750 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
1751 // vertical left axis title
1752 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
1753 if (mySecondY) // vertical right axis title
1754 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
1757 if( dlg->isMainTitleEnabled() && myTitle != dlg->getMainTitle() )
1758 myIsDefTitle = false;
1759 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
1761 if ( myCurveType != dlg->getCurveType() ) {
1762 setCurveType( dlg->getCurveType(), false );
1765 if ( myShowLegend != dlg->isLegendEnabled() ) {
1766 showLegend( dlg->isLegendEnabled(), false );
1768 if ( myLegendPos != dlg->getLegendPos() ) {
1769 setLegendPos( dlg->getLegendPos() );
1771 if ( myLegendSymbolType != dlg->getLegendSymbolType() ) {
1772 setLegendSymbolType( dlg->getLegendSymbolType() );
1774 if ( myLegendFont != dlg->getLegendFont() ) {
1775 setLegendFont( dlg->getLegendFont() );
1777 if ( myLegendColor != dlg->getLegendColor() ) {
1778 setLegendFontColor( dlg->getLegendColor() );
1780 if ( mySelectedLegendFontColor != dlg->getSelectedLegendColor() ) {
1781 setSelectedLegendFontColor( dlg->getSelectedLegendColor() );
1785 if ( myMarkerSize != dlg->getMarkerSize() ) {
1786 setMarkerSize( dlg->getMarkerSize(), false );
1789 if ( myBackground != dlg->getBackgroundColor() ) {
1790 setBackgroundColor( dlg->getBackgroundColor() );
1793 if ( mySelectionColor != dlg->getSelectionColor() ) {
1794 setSelectionColor( dlg->getSelectionColor() );
1797 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
1798 aY2GridMajorEnabled, aY2GridMinorEnabled;
1799 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
1800 aY2GridMaxMajor, aY2GridMaxMinor;
1801 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
1802 aY2GridMajorEnabled, aY2GridMaxMajor);
1803 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
1804 aY2GridMinorEnabled, aY2GridMaxMinor);
1805 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
1806 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
1807 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
1808 if ( myXMode != dlg->getXScaleMode() ) {
1809 setHorScaleMode( dlg->getXScaleMode() );
1811 if ( myYMode != dlg->getYScaleMode() ) {
1812 setVerScaleMode( dlg->getYScaleMode() );
1814 if ( myNormLMin != dlg->getLMinNormMode() ) {
1815 setNormLMinMode( dlg->getLMinNormMode() );
1817 if ( myNormLMax != dlg->getLMaxNormMode() ) {
1818 setNormLMaxMode( dlg->getLMaxNormMode() );
1820 if ( myNormRMin != dlg->getRMinNormMode() ) {
1821 setNormRMinMode( dlg->getRMinNormMode() );
1823 if ( myNormRMax != dlg->getRMaxNormMode() ) {
1824 setNormRMaxMode( dlg->getRMaxNormMode() );
1827 myPlot->setProperty(PLOT2D_DEVIATION_COLOR,
1828 dlg->getDeviationMarkerCl());
1829 myPlot->setProperty(PLOT2D_DEVIATION_LW,
1830 dlg->getDeviationMarkerLw());
1831 myPlot->setProperty(PLOT2D_DEVIATION_TS,
1832 dlg->getDeviationMarkerTs());
1837 // update preferences
1838 if ( dlg->isSetAsDefault() )
1844 #ifndef NO_ANALYTICAL_CURVES
1846 "Analytical Curves" toolbar action slot
1848 void Plot2d_ViewFrame::onAnalyticalCurve()
1850 Plot2d_AnalyticalCurveDlg dlg( this, this );
1852 updateAnalyticalCurves();
1855 void Plot2d_ViewFrame::addAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
1857 myAnalyticalCurves.append(theCurve);
1860 void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
1862 theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
1866 Update Analytical curve
1868 void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool updateView)
1871 QwtScaleDiv div = myPlot->axisScaleDiv(QwtPlot::xBottom);
1872 c->setRangeBegin(div.lowerBound());
1873 c->setRangeEnd(div.upperBound());
1875 c->setMarkerSize(myMarkerSize);
1876 QwtPlotItem* item = c->plotItem();
1878 switch( c->getAction() ) {
1879 case Plot2d_AnalyticalCurve::ActAddInView:
1880 if( c->isActive() ) {
1881 c->updatePlotItem();
1882 item->attach( myPlot );
1883 item->itemChanged();
1886 c->setAction(Plot2d_AnalyticalCurve::ActNothing);
1889 case Plot2d_AnalyticalCurve::ActUpdateInView:
1891 c->updatePlotItem();
1898 c->setAction(Plot2d_AnalyticalCurve::ActNothing);
1900 case Plot2d_AnalyticalCurve::ActRemoveFromView:
1911 Update Analytical curves
1913 void Plot2d_ViewFrame::updateAnalyticalCurves()
1915 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
1916 AnalyticalCurveList toDelete;
1917 for( ; it != myAnalyticalCurves.end(); it++) {
1918 Plot2d_AnalyticalCurve* c = (*it);
1919 updateAnalyticalCurve(c);
1920 if(c && c->getAction() == Plot2d_AnalyticalCurve::ActRemoveFromView)
1921 toDelete.push_back(c);
1923 it = toDelete.begin();
1924 for( ; it != toDelete.end(); it++) {
1925 Plot2d_AnalyticalCurve* c = (*it);
1926 myAnalyticalCurves.removeAll(c);
1934 Return list of the alalytical curves.
1936 AnalyticalCurveList Plot2d_ViewFrame::getAnalyticalCurves() const
1938 return myAnalyticalCurves ;
1942 Get analytical curve by plot item.
1944 Plot2d_AnalyticalCurve* Plot2d_ViewFrame::getAnalyticalCurve(QwtPlotItem * theItem) {
1945 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
1946 for( ; it != myAnalyticalCurves.end(); it++) {
1947 if((*it)->plotItem() == theItem)
1955 "Fit Data" command slot
1957 void Plot2d_ViewFrame::onFitData()
1959 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
1960 double xMin,xMax,yMin,yMax,y2Min,y2Max;
1961 getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
1963 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1964 if ( dlg->exec() == QDialog::Accepted ) {
1965 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1966 fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max);
1969 #ifndef NO_ANALYTICAL_CURVES
1970 updateAnalyticalCurves();
1975 Change background color
1977 void Plot2d_ViewFrame::onChangeBackground()
1979 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1980 if ( selColor.isValid() ) {
1981 setBackgroundColor( selColor );
1988 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1990 myCurveType = curveType;
1991 CurveDict aCurves = getCurves();
1992 CurveDict::iterator it = aCurves.begin();
1993 for ( ; it != aCurves.end(); it++ ) {
1994 QwtPlotCurve* crv = it.key();
1996 setCurveType( crv, myCurveType );
1998 for(int i=0 ; i < myAnalyticalCurves.count(); i++) {
1999 QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( myAnalyticalCurves[i]->plotItem() );
2000 Plot2d_AnalyticalCurve* aCurve = dynamic_cast<Plot2d_AnalyticalCurve*>( myAnalyticalCurves[i] );
2001 if ( aPCurve && aCurve ) {
2002 setCurveType( aPCurve, myCurveType );
2007 emit vpCurveChanged();
2013 int Plot2d_ViewFrame::getCurveType() const
2020 \param curveKey - curve id
2021 \param title - new title
2023 void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title )
2025 setObjectTitle( curve, title );
2030 \param object - object id
2031 \param title - new title
2033 void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title )
2035 if ( object && hasPlotObject( object ) )
2036 getPlotObject( object )->setTitle( title );
2042 void Plot2d_ViewFrame::showLegend( bool show, bool update )
2044 myShowLegend = show;
2045 if ( myShowLegend ) {
2046 QwtAbstractLegend* absLegend = myPlot->legend();
2047 QwtLegend* legend = 0;
2049 legend = new Plot2d_QwtLegend( myPlot );
2050 legend->setDefaultItemMode(QwtLegendData::Clickable);
2051 connect( legend, SIGNAL( clicked (const QVariant&, int) ),
2052 this, SIGNAL( clicked (const QVariant&, int) ) );
2053 legend->setFrameStyle( QFrame::Box | QFrame::Sunken );
2056 legend = dynamic_cast<QwtLegend*>(absLegend);
2059 myPlot->insertLegend( legend );
2060 setLegendPos( myLegendPos );
2061 setLegendFont( myLegendFont );
2062 setLegendFontColor( myLegendColor );
2066 myPlot->insertLegend( 0 );
2068 if( show && update )
2076 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
2078 void Plot2d_ViewFrame::setLegendPos( int pos )
2081 QwtAbstractLegend* legend = myPlot->legend();
2085 myPlot->insertLegend( legend, QwtPlot::LeftLegend );
2088 myPlot->insertLegend( legend, QwtPlot::RightLegend );
2091 myPlot->insertLegend( legend, QwtPlot::TopLegend );
2094 myPlot->insertLegend( legend, QwtPlot::BottomLegend );
2101 Gets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
2103 int Plot2d_ViewFrame::getLegendPos() const
2109 Sets legend symbol type : 0 - marker on line, 1 - marker above line
2111 void Plot2d_ViewFrame::setLegendSymbolType( int type )
2113 myLegendSymbolType = type;
2114 myPlot->setLegendSymbolType( type );
2119 Gets legend symbol type : 0 - marker on line, 1 - marker above line
2121 int Plot2d_ViewFrame::getLegendSymbolType() const
2123 return myLegendSymbolType;
2129 void Plot2d_ViewFrame::setLegendFont( const QFont& fnt )
2132 QwtAbstractLegend* legend = myPlot->legend();
2134 legend->setFont(fnt);
2141 QFont Plot2d_ViewFrame::getLegendFont() const
2143 return myLegendFont;
2147 Sets legend font color
2149 void Plot2d_ViewFrame::setLegendFontColor( const QColor& col )
2151 myLegendColor = col;
2152 QwtAbstractLegend* legend = myPlot->legend();
2154 QPalette pal = legend->palette();
2155 pal.setColor( QPalette::Text, col );
2156 legend->setPalette( pal );
2161 Gets legend font color
2163 QColor Plot2d_ViewFrame::getLegendFontColor() const
2165 return myLegendColor;
2169 Sets selected legend font color
2171 void Plot2d_ViewFrame::setSelectedLegendFontColor( const QColor& col )
2173 mySelectedLegendFontColor = col;
2174 Plot2d_Object::setHighlightedLegendTextColor( col );
2178 Gets selected legend font color
2180 QColor Plot2d_ViewFrame::getSelectedLegendFontColor() const
2182 return mySelectedLegendFontColor;
2186 Sets new marker size
2188 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
2190 if ( myMarkerSize != size )
2192 myMarkerSize = size;
2193 CurveDict aCurves = getCurves();
2194 CurveDict::iterator it = aCurves.begin();
2195 for ( ; it != aCurves.end(); it++ ) {
2196 QwtPlotCurve* crv = it.key();
2199 QwtSymbol* aSymbol = new QwtSymbol( crv->symbol()->style(), crv->symbol()->brush(),
2200 crv->symbol()->pen(), QSize( myMarkerSize, myMarkerSize ) );
2201 crv->setSymbol( aSymbol );
2203 it.value()->setMarkerSize( myMarkerSize );
2212 Gets new marker size
2214 int Plot2d_ViewFrame::getMarkerSize() const
2216 return myMarkerSize;
2220 Sets background color
2222 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
2224 myBackground = color;
2225 myPlot->canvas()->setPalette( myBackground );
2226 myPlot->setPalette( myBackground );
2227 if ( myPlot->getLegend() ) {
2228 QPalette aPal = myPlot->getLegend()->palette();
2229 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
2230 aPal.setColor( QPalette::Base, myBackground );
2231 aPal.setColor( QPalette::Background, myBackground );
2233 myPlot->getLegend()->setPalette( aPal );
2240 Gets background color
2242 QColor Plot2d_ViewFrame::backgroundColor() const
2244 return myBackground;
2248 Sets selection color
2250 void Plot2d_ViewFrame::setSelectionColor( const QColor& color )
2252 mySelectionColor = color;
2253 Plot2d_Object::setSelectionColor( color );
2257 Gets selection color
2259 QColor Plot2d_ViewFrame::selectionColor() const
2261 return mySelectionColor;
2265 Sets hor.axis grid parameters
2267 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
2268 bool xMinorEnabled, const int xMinorMax,
2271 myXGridMajorEnabled = xMajorEnabled;
2272 myXGridMinorEnabled = xMinorEnabled;
2273 myXGridMaxMajor = xMajorMax;
2274 myXGridMaxMinor = xMinorMax;
2276 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
2277 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
2279 QwtPlotGrid* grid = myPlot->grid();
2280 if ( !myPlot->axisScaleDiv( QwtPlot::xBottom ).isEmpty() )
2281 grid->setXDiv( myPlot->axisScaleDiv( QwtPlot::xBottom ) );
2282 grid->enableX( myXGridMajorEnabled );
2283 grid->enableXMin( myXGridMinorEnabled );
2289 Sets ver.axis grid parameters
2291 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
2292 bool yMinorEnabled, const int yMinorMax,
2293 bool y2MajorEnabled, const int y2MajorMax,
2294 bool y2MinorEnabled, const int y2MinorMax,
2297 myYGridMajorEnabled = yMajorEnabled;
2298 myYGridMinorEnabled = yMinorEnabled;
2299 myYGridMaxMajor = yMajorMax;
2300 myYGridMaxMinor = yMinorMax;
2303 myY2GridMajorEnabled = y2MajorEnabled;
2304 myY2GridMinorEnabled = y2MinorEnabled;
2305 myY2GridMaxMajor = y2MajorMax;
2306 myY2GridMaxMinor = y2MinorMax;
2308 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
2309 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
2312 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
2313 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
2316 QwtPlotGrid* grid = myPlot->grid();
2317 if ( !myPlot->axisScaleDiv( QwtPlot::yLeft ).isEmpty() )
2318 grid->setYDiv( myPlot->axisScaleDiv( QwtPlot::yLeft ) );
2321 if (myYGridMajorEnabled) {
2322 grid->enableY( myYGridMajorEnabled );
2323 grid->enableYMin( myYGridMinorEnabled );
2325 else if (myY2GridMajorEnabled) {
2326 if ( !myPlot->axisScaleDiv( QwtPlot::yRight ).isEmpty() )
2327 grid->setYDiv( myPlot->axisScaleDiv( QwtPlot::yRight ) );
2328 grid->enableY( myY2GridMajorEnabled );
2329 grid->enableYMin( myY2GridMinorEnabled );
2332 grid->enableY( false );
2333 grid->enableYMin( false );
2337 grid->enableY( myYGridMajorEnabled );
2338 grid->enableYMin( myYGridMinorEnabled );
2345 Sets title for some axis
2347 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
2348 ObjectType type, bool update )
2352 myTitleEnabled = enabled;
2354 myPlot->setTitle( myTitleEnabled ? myTitle : QString() );
2357 myXTitleEnabled = enabled;
2359 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString() );
2362 myYTitleEnabled = enabled;
2364 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString() );
2367 myY2TitleEnabled = enabled;
2369 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString() );
2378 Sets title for some axis
2380 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
2385 title = myTitle; break;
2387 title = myXTitle; break;
2389 title = myYTitle; break;
2391 title = myY2Title; break;
2398 Sets font for Plot2d object : title or axis
2400 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
2404 myPlot->title().setFont(font);
2407 myPlot->axisTitle(QwtPlot::xBottom).setFont(font); break;
2409 myPlot->axisTitle(QwtPlot::yLeft).setFont(font); break;
2411 myPlot->axisTitle(QwtPlot::yRight).setFont(font); break;
2413 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
2415 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
2417 myPlot->setAxisFont(QwtPlot::yRight, font); break;
2424 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
2426 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
2428 if ( myXMode == mode )
2431 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
2432 // it crashes if switched to X/Y logarithmic mode, when one or more points have
2433 // non-positive X/Y coordinate
2434 if ( mode && !isXLogEnabled() ){
2436 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
2438 QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
2445 // set bounds of logarithmic scale
2446 if( myXMode != 0 ) {
2447 myPlot->setAxisScale( QwtPlot::xBottom, 1.0, 1e5 );
2448 myPlot->updateAxes();
2451 myPlot->setLogScale(QwtPlot::xBottom, myXMode != 0);
2455 emit vpModeHorChanged();
2459 Gets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
2461 int Plot2d_ViewFrame::getHorScaleMode() const
2467 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
2469 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
2471 if ( myYMode == mode )
2474 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
2475 // it crashes if switched to X/Y logarithmic mode, when one or more points have
2476 // non-positive X/Y coordinate
2477 if ( mode && !isYLogEnabled() ){
2479 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
2481 QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
2488 // set bounds of logarithmic scale
2490 myPlot->setAxisScale( QwtPlot::yLeft, 1.0, 1e5 );
2491 myPlot->updateAxes();
2494 myPlot->setLogScale(QwtPlot::yLeft, myYMode != 0);
2497 myPlot->setAxisScale( QwtPlot::yRight, 1.0, 1e5 );
2498 myPlot->updateAxes();
2500 myPlot->setLogScale( QwtPlot::yRight, myYMode != 0 );
2505 emit vpModeVerChanged();
2509 Gets scale mode for vertical axis: 0 - linear, 1 - logarithmic
2511 int Plot2d_ViewFrame::getVerScaleMode() const
2517 Sets normalization mode to the global maximum by left Y axis
2519 void Plot2d_ViewFrame::setNormLMaxMode( bool mode, bool update )
2521 if ( myNormLMax == mode )
2525 processFiltering(true);
2528 emit vpNormLModeChanged();
2532 Gets normalization mode to the global maximum by left Y axis
2534 bool Plot2d_ViewFrame::getNormLMaxMode() const
2540 Sets normalization mode to the global minimum by left Y axis
2542 void Plot2d_ViewFrame::setNormLMinMode( bool mode, bool update )
2544 if ( myNormLMin == mode )
2548 processFiltering(true);
2551 emit vpNormLModeChanged();
2555 Gets normalization mode to the global minimum by left Y axis
2557 bool Plot2d_ViewFrame::getNormLMinMode() const
2563 Sets normalization mode to the global maximum by right Y axis
2565 void Plot2d_ViewFrame::setNormRMaxMode( bool mode, bool update )
2567 if ( myNormRMax == mode )
2571 processFiltering(true);
2574 emit vpNormRModeChanged();
2578 Gets normalization mode to the global maximum by right Y axis
2580 bool Plot2d_ViewFrame::getNormRMaxMode() const
2586 Sets normalization mode to the global minimum by right Y axis
2588 void Plot2d_ViewFrame::setNormRMinMode( bool mode, bool update )
2590 if ( myNormRMin == mode )
2594 processFiltering(true);
2597 emit vpNormRModeChanged();
2601 Gets normalization mode to the global minimum by right Y axis
2603 bool Plot2d_ViewFrame::getNormRMinMode() const
2609 Return, scale mode for horizontal axis
2611 bool Plot2d_ViewFrame::isModeHorLinear()
2613 return (myXMode == 0 ? true : false);
2617 Return, scale mode for vertical axis
2619 bool Plot2d_ViewFrame::isModeVerLinear()
2621 return (myYMode == 0 ? true : false);
2625 Return \c True if curves are normalize to the global maximum by left Y axis
2627 bool Plot2d_ViewFrame::isNormLMaxMode()
2629 return (myNormLMax ? true : false);
2633 Return \c True if curves are normalize to the global minimum by left Y axis
2635 bool Plot2d_ViewFrame::isNormLMinMode()
2637 return (myNormLMin ? true : false);
2641 Return \c True if curves are normalize to the global maximum by right Y axis
2643 bool Plot2d_ViewFrame::isNormRMaxMode()
2645 return (myNormRMax ? true : false);
2649 Return \c True if curves are normalize to the global minimum by right Y axis
2651 bool Plot2d_ViewFrame::isNormRMinMode()
2653 return (myNormRMin ? true : false);
2657 Return \c True if legend is shown
2659 bool Plot2d_ViewFrame::isLegendShow() const
2661 return myShowLegend;
2665 Slot, called when user presses mouse button
2667 void Plot2d_ViewFrame::plotMousePressed( const QMouseEvent& me )
2670 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2672 aParent->putInfo(getInfo(me.pos()));
2674 if ( myOperation == NoOpId )
2675 myOperation = testOperation( me );
2676 if ( myOperation != NoOpId ) {
2678 if ( myOperation == GlPanId ) {
2679 myPlot->setAxisScale( QwtPlot::yLeft,
2680 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2,
2681 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2 );
2682 myPlot->setAxisScale( QwtPlot::xBottom,
2683 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
2684 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
2686 myPlot->setAxisScale( QwtPlot::yRight,
2687 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2,
2688 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2 );
2693 int btn = (int)me.button() | (int)me.modifiers();
2694 if (btn == Qt::RightButton) {
2695 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
2696 me.pos(), me.button(), me.buttons(), me.modifiers() );
2697 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
2698 parent()->eventFilter(this, aEvent);
2704 Slot, called when user moves mouse
2706 bool Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
2708 int dx = me.pos().x() - myPnt.x();
2709 int dy = me.pos().y() - myPnt.y();
2712 if ( myOperation != NoOpId) {
2713 if ( myOperation == ZoomId ) {
2714 this->incrementalZoom( dx, dy );
2718 else if ( myOperation == PanId ) {
2719 this->incrementalPan( dx, dy );
2726 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2728 aParent->putInfo(getInfo(me.pos()));
2734 Slot, called when user releases mouse
2736 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
2738 if ( myOperation == NoOpId && me.button() == Qt::RightButton && me.modifiers() != Qt::ControlModifier )
2740 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
2741 me.pos(), me.globalPos() );
2742 emit contextMenuRequested( &aEvent );
2745 #ifndef NO_ANALYTICAL_CURVES
2746 updateAnalyticalCurves();
2749 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
2750 myPlot->defaultPicker();
2753 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2755 aParent->putInfo(tr("INF_READY"));
2757 myOperation = NoOpId;
2760 Slot, called when user wheeling mouse
2762 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
2764 QwtPlotLayout* pl = myPlot->plotLayout();
2766 // compute zooming factor
2767 double aDelta = event->delta();
2768 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
2770 bool scaleXBottom = pl->scaleRect(QwtPlot::xBottom).contains( event->pos() ) ||
2771 pl->canvasRect().contains( event->pos() );
2772 bool scaleYLeft = pl->scaleRect(QwtPlot::yLeft).contains( event->pos() ) ||
2773 pl->canvasRect().contains( event->pos() );
2774 bool scaleYRight = mySecondY && ( pl->scaleRect(QwtPlot::yRight).contains( event->pos() ) ||
2775 pl->canvasRect().contains( event->pos() ) );
2777 // scale x bottom axis
2778 if ( scaleXBottom ) {
2779 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
2780 if ( xMap.s2() - xMap.s1() > 1.0e-12 || aScale > 1 )
2781 myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s1() + aScale*(xMap.s2() - xMap.s1()) );
2784 // scale y left axis
2786 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
2787 if ( yMap.s2() - yMap.s1() > 1.0e-12 || aScale > 1 )
2788 myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
2791 // scale y right axis (note: mySecondY value is checked above)
2792 if ( scaleYRight ) {
2793 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yRight );
2794 if ( yMap.s2() - yMap.s1() > 10e-12 || aScale > 1 )
2795 myPlot->setAxisScale( QwtPlot::yRight, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
2801 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
2802 // store current mouse position
2803 myPnt = event->pos();
2804 #ifndef NO_ANALYTICAL_CURVES
2805 // update analytical curves
2806 updateAnalyticalCurves();
2811 Returns qwt plot curve if it is existed in map of curves and 0 otherwise
2813 QwtPlotCurve* Plot2d_ViewFrame::getPlotCurve( Plot2d_Curve* curve ) const
2815 return dynamic_cast<QwtPlotCurve*>( getPlotObject( curve ) );
2818 Returns true if qwt plot curve is existed in map of curves and false otherwise
2820 bool Plot2d_ViewFrame::hasPlotCurve( Plot2d_Curve* curve ) const
2822 return hasPlotObject( curve );
2826 Returns qwt plot curve if it is existed in map of curves and 0 otherwise
2828 QwtPlotItem* Plot2d_ViewFrame::getPlotObject( Plot2d_Object* object ) const
2830 ObjectDict::const_iterator it = myObjects.begin();
2831 for ( ; it != myObjects.end(); it++ ) {
2832 if ( it.value() == object )
2838 Returns true if qwt plot curve is existed in map of curves and false otherwise
2840 bool Plot2d_ViewFrame::hasPlotObject( Plot2d_Object* object ) const
2842 ObjectDict::const_iterator it = myObjects.begin();
2843 for ( ; it != myObjects.end(); it++ ) {
2844 if ( it.value() == object )
2853 void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int /*curveType*/ )
2857 if ( myCurveType == 0 )
2858 curve->setStyle( QwtPlotCurve::Dots );//QwtCurve::NoCurve
2859 else if ( myCurveType == 1 ) {
2860 curve->setStyle( QwtPlotCurve::Lines );
2861 curve->setCurveAttribute( QwtPlotCurve::Fitted, false );
2863 else if ( myCurveType == 2 ) {
2864 curve->setStyle( QwtPlotCurve::Lines );
2865 QwtSplineCurveFitter* fitter = new QwtSplineCurveFitter();
2866 fitter->setSplineSize( 250 );
2867 curve->setCurveAttribute( QwtPlotCurve::Fitted, true );
2868 curve->setCurveFitter( fitter );
2873 View operations : Pan view
2875 void Plot2d_ViewFrame::onViewPan()
2877 // reset the previous operation
2878 myPlot->defaultPicker();
2880 QCursor panCursor (Qt::SizeAllCursor);
2881 myPlot->canvas()->setCursor( panCursor );
2882 myOperation = PanId;
2885 View operations : Zoom view
2887 void Plot2d_ViewFrame::onViewZoom()
2889 // reset the previous operation
2890 myPlot->defaultPicker();
2892 QPixmap zoomPixmap (imageZoomCursor);
2893 QCursor zoomCursor (zoomPixmap);
2894 myPlot->canvas()->setCursor( zoomCursor );
2895 myOperation = ZoomId;
2898 View operations : Fit All
2900 void Plot2d_ViewFrame::onViewFitAll()
2904 // reset the previous operation
2905 myPlot->defaultPicker();
2906 myPlot->canvas()->setCursor( QCursor(Qt::CrossCursor) );
2907 myOperation = NoOpId;
2910 View operations : Fit Area
2912 void Plot2d_ViewFrame::onViewFitArea()
2914 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
2915 myOperation = FitAreaId;
2916 myPlot->setPickerMousePattern( Qt::LeftButton );
2919 View operations : Global panning
2921 void Plot2d_ViewFrame::onViewGlobalPan()
2923 // reset the previous operation
2924 myPlot->defaultPicker();
2926 QPixmap globalPanPixmap (imageCrossCursor);
2927 QCursor glPanCursor (globalPanPixmap);
2928 myPlot->canvas()->setCursor( glPanCursor );
2929 myPlot->setLogScale(QwtPlot::xBottom, false);
2930 myPlot->setLogScale(QwtPlot::yLeft, false);
2932 myPlot->setLogScale(QwtPlot::yRight, false);
2934 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
2935 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
2937 myXDistance = xMap.s2() - xMap.s1();
2938 myYDistance = yMap.s2() - yMap.s1();
2941 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
2942 myYDistance2 = yMap2.s2() - yMap2.s1();
2944 // don't make fit all
2946 myOperation = GlPanId;
2950 Precaution for logarithmic X scale
2952 bool Plot2d_ViewFrame::isXLogEnabled() const
2954 bool allPositive = true;
2955 ObjectDict::const_iterator it = myObjects.begin();
2956 for ( ; allPositive && it != myObjects.end(); it++ )
2957 allPositive = ( it.value()->getMinX() > 0. );
2962 Precaution for logarithmic Y scale
2964 bool Plot2d_ViewFrame::isYLogEnabled() const
2966 bool allPositive = true;
2967 ObjectDict::const_iterator it = myObjects.begin();
2968 for ( ; allPositive && it != myObjects.end(); it++ )
2969 allPositive = ( it.value()->getMinY() > 0. );
2976 void Plot2d_ViewFrame::setEnableAxis( QwtPlot::Axis theAxis, bool isEnable )
2978 if ( myPlot->axisEnabled( theAxis ) == isEnable )
2980 myPlot->enableAxis( theAxis, isEnable );
2981 if ( theAxis == QwtPlot::yRight )
2982 mySecondY = isEnable;
2985 class Plot2d_QwtPlotZoomer : public QwtPlotZoomer
2988 Plot2d_QwtPlotZoomer( int xAxis, int yAxis, QWidget* canvas )
2989 : QwtPlotZoomer( xAxis, yAxis, canvas )
2991 qApp->installEventFilter( this );
2992 // now picker working after only a button pick.
2993 // after click on button FitArea in toolbar of the ViewFrame.
2995 ~Plot2d_QwtPlotZoomer() {};
3001 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
3002 : QwtPlot( parent ),
3005 // Create alternative scales
3006 setAxisScaleDraw( QwtPlot::yLeft, new Plot2d_ScaleDraw() );
3007 setAxisScaleDraw( QwtPlot::xBottom, new Plot2d_ScaleDraw() );
3008 setAxisScaleDraw( QwtPlot::yRight, new Plot2d_ScaleDraw() );
3010 myPlotZoomer = new Plot2d_QwtPlotZoomer( QwtPlot::xBottom, QwtPlot::yLeft, canvas() );
3011 myPlotZoomer->setTrackerMode( QwtPicker::AlwaysOff );
3012 myPlotZoomer->setRubberBand( QwtPicker::RectRubberBand );
3013 myPlotZoomer->setRubberBandPen( QColor( Qt::green ) );
3017 // auto scaling by default
3018 setAxisAutoScale( QwtPlot::yLeft );
3019 setAxisAutoScale( QwtPlot::yRight );
3020 setAxisAutoScale( QwtPlot::xBottom );
3024 myGrid = new QwtPlotGrid();
3025 QPen aMajPen = myGrid->majorPen();
3026 aMajPen.setStyle( Qt::DashLine );
3027 myGrid->setPen( aMajPen );
3029 myGrid->enableX( false );
3030 myGrid->enableXMin( false );
3031 myGrid->enableY( false );
3032 myGrid->enableYMin( false );
3034 myGrid->attach( this );
3036 setMouseTracking( false );
3037 canvas()->setMouseTracking( true );
3039 myPlotZoomer->setEnabled( true );
3040 myPlotZoomer->setZoomBase();
3042 setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
3045 Plot2d_Plot2d::~Plot2d_Plot2d()
3050 \set axis scale engine - linear or log10
3052 void Plot2d_Plot2d::setLogScale( int axisId, bool log10 )
3055 setAxisScaleEngine( axisId, new QwtLogScaleEngine() );
3057 setAxisScaleEngine( axisId, new QwtLinearScaleEngine() );
3061 Recalculates and redraws Plot 2d view
3063 void Plot2d_Plot2d::replot()
3065 // the following code is intended to enable only axes
3066 // that are really used by displayed objects
3067 bool enableXBottom = false, enableXTop = false;
3068 bool enableYLeft = false, enableYRight = false;
3069 const QwtPlotItemList& items = itemList();
3070 QwtPlotItemIterator it;
3071 for ( it = items.begin(); it != items.end(); it++ ) {
3072 QwtPlotItem* item = *it;
3074 enableXBottom |= item->xAxis() == QwtPlot::xBottom;
3075 enableXTop |= item->xAxis() == QwtPlot::xTop;
3076 enableYLeft |= item->yAxis() == QwtPlot::yLeft;
3077 enableYRight |= item->yAxis() == QwtPlot::yRight;
3080 enableAxis( QwtPlot::xBottom, enableXBottom );
3081 enableAxis( QwtPlot::xTop, enableXTop );
3082 enableAxis( QwtPlot::yLeft, enableYLeft );
3083 enableAxis( QwtPlot::yRight, enableYRight );
3085 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
3092 QwtAbstractLegend* Plot2d_Plot2d::getLegend()
3094 #if QWT_VERSION < 0x040200
3097 return legend(); /* mpv: porting to the Qwt 4.2.0 */
3102 \return the recommended size for the widget
3104 QSize Plot2d_Plot2d::sizeHint() const
3106 return QwtPlot::minimumSizeHint();
3110 return minimum size for qwt plot
3112 QSize Plot2d_Plot2d::minimumSizeHint() const
3114 return QSize( 0, 0 );
3115 // QSize aSize = QwtPlot::minimumSizeHint();
3116 // return QSize(aSize.width()*3/4, aSize.height());
3119 void Plot2d_Plot2d::defaultPicker()
3121 myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1,
3122 Qt::RightButton, Qt::ControlModifier ); // zooming button
3123 for ( int i = QwtEventPattern::MouseSelect2; i < QwtEventPattern::MouseSelect6; i++ )
3124 myPlotZoomer->setMousePattern( (QwtEventPattern::MousePatternCode)i, Qt::NoButton,
3128 void Plot2d_Plot2d::setPickerMousePattern( int button, int state )
3130 myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, (Qt::MouseButton)button,
3131 (Qt::KeyboardModifiers)state );
3135 * Set the point picker associated with a graphic view
3137 void Plot2d_Plot2d::setPicker( Plot2d_QwtPlotPicker *picker)
3143 * Create marker and tooltip associed with a point
3145 QwtPlotMarker* Plot2d_Plot2d::createMarkerAndTooltip( QwtSymbol* symbol,
3149 Plot2d_QwtPlotPicker *picker)
3151 QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
3153 aPlotMarker->setSymbol( symbol ); // symbol must have a color
3154 aPlotMarker->setLabelAlignment( Qt::AlignTop);
3155 aPlotMarker->setXValue(X);
3156 aPlotMarker->setYValue(Y);
3158 aPlotMarker->attach(this);
3160 // Associate a tooltip with the point's marker
3161 // PB: how to obtain a tooltip with a rectangular frame ?
3162 //QwtText tooltip ("X=" + QString::number(X) + " Y=" + QString::number(Y) );
3164 QwtText text (tooltip);
3165 //QColor tooltipColor( 245, 222, 179); // Wheat -RGB (0 a 255)
3166 QColor tooltipColor( 253, 245, 230); // OldLace
3167 text.setBackgroundBrush( QBrush(tooltipColor)); //, Qt::SolidPattern));
3170 picker->pMarkers.append( aPlotMarker);
3171 picker->pMarkersToolTip[ aPlotMarker] = text;
3176 QwtPlotGrid* Plot2d_Plot2d::grid() const
3181 QwtPlotZoomer* Plot2d_Plot2d::zoomer() const
3183 return myPlotZoomer;
3187 Updates identifiers of Y axis type in the legend.
3189 void Plot2d_Plot2d::updateYAxisIdentifiers()
3191 bool enableYLeft = false, enableYRight = false;
3192 const QwtPlotItemList& items = itemList();
3193 QwtPlotItemIterator it;
3194 for ( it = items.begin(); it != items.end(); it++ ) {
3195 QwtPlotItem* item = *it;
3197 enableYLeft |= item->yAxis() == QwtPlot::yLeft;
3198 enableYRight |= item->yAxis() == QwtPlot::yRight;
3202 // if several curves are attached to different axes
3203 // display corresponding identifiers in the legend,
3204 // otherwise hide them
3205 for ( it = items.begin(); it != items.end(); it++ ) {
3206 QwtPlotItem* item = *it;
3207 if ( Plot2d_QwtPlotCurve* aPCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( item ) )
3208 aPCurve->setYAxisIdentifierEnabled( enableYLeft && enableYRight );
3209 if ( item && item->isVisible() && legend() )
3210 item->updateLegend( item, item->legendData() );
3214 // Methods to manage axis graduations
3216 /* Create definition and graduations of axes
3218 void Plot2d_Plot2d::createAxisScaleDraw()
3220 myScaleDraw = new Plot2d_AxisScaleDraw( this);
3224 /* Stock X axis's ticks in the drawing zone
3226 void Plot2d_Plot2d::applyTicks()
3228 myScaleDraw->applyTicks();
3232 /* Unactivate automatic ticks drawing (call to method Plot2d_AxisScaleDraw::draw() )
3234 * - number call to ticks drawing (for information) : numcall
3236 void Plot2d_Plot2d::unactivAxisScaleDraw( int numcall)
3238 // Memorize X axis (myScaleDraw already exists) in the drawing zone
3239 //setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
3241 myScaleDraw->unactivTicksDrawing( numcall);
3245 /* Draw ticks and labels on X axis of the drawing zone
3246 * Draw systems' names under the X axis of the drawing zone
3247 * Draw vertical segments between X axis's intervals of the systems
3249 * - left and right margins for ticks : XLeftMargin, XRightMargin
3250 * - for each named system :
3251 * positions and labels for ticks on X axis : devicesPosLabelTicks
3253 * The true drawings will be realized by the method Plot2d_AxisScaleDraw::draw()
3256 void Plot2d_Plot2d::displayXTicksAndLabels(
3257 double XLeftMargin, double XRightMargin,
3258 const QList< QPair< QString, QMap<double, QString> > > & devicesPosLabelTicks)
3259 // name position label
3262 //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
3264 int nbDevices = devicesPosLabelTicks.size();
3266 //std::cout << " Nombre de systemes = " << nbDevices << std::endl;
3267 if (nbDevices == 0) return;
3269 // For drawing systems' names, their positions must be in the allTicks list
3270 // (cf class Plot2d_AxisScaleDraw)
3272 // Liste of ticks' positions and systems' names
3273 QList<double> allTicks;
3275 double devXmin, devXmax; // X interval of a system
3276 double gapXmin = 0., gapXmax = 0.; // X interval between two systems
3277 double devLabPos; // Label's position of a system
3278 double segmentPos; // Position of the vertical segment between current system and the next
3280 // 1)- Search for the system whose X interval is the most to the left
3283 double XminMin = 1.e+12;
3287 for (int idev=0; idev < nbDevices; idev++)
3289 QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
3291 QString deviceLabel = paire.first;
3293 // Ticks' map of the system
3294 QMap<double,QString> devPosLabelTicks = paire.second;
3296 QList<double> posTicks = devPosLabelTicks.keys();
3298 // List's items increasing sorting
3299 qSort( posTicks.begin(), posTicks.end() ); // iterators
3301 // X interval for the system
3302 devXmin = posTicks.first();
3303 devXmax = posTicks.last();
3305 if (devXmin < XminMin)
3313 // 2)- Ticks, systems' names, verticals segments
3315 for (int idev=0; idev < nbDevices; idev++)
3317 QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
3319 QString deviceLabel = paire.first;
3321 std::string std_label = deviceLabel.toStdString();
3322 //const char *c_label = std_label.c_str();
3323 //std::cout << " deviceLabel: |" << c_label << "|" << std::endl;
3325 // Ticks' map of the system
3326 QMap<double,QString> devPosLabelTicks = paire.second;
3328 int nbTicks = devPosLabelTicks.size();
3330 QList<double> posTicks = devPosLabelTicks.keys();
3332 // List's items increasing sorting
3333 qSort( posTicks.begin(), posTicks.end() ); // iterators
3335 // X interval for the system
3336 devXmin = posTicks.first();
3337 devXmax = posTicks.last();
3339 // Stock ticks' positions and labels on X axis
3343 for (int itic=0; itic < nbTicks; itic++)
3345 pos = posTicks.at(itic);
3346 label = devPosLabelTicks[pos];
3348 myScaleDraw->setLabelTick( pos, label, false);
3350 std::string std_label = label.toStdString();
3351 //const char *c_label = std_label.c_str();
3352 //std::cout << " tick " << itic << " : pos= " << pos << ", label= |" << c_label << "|" << std::endl;
3354 allTicks.append( posTicks);
3356 // Compute the position of the system's label
3357 if (idev == ileftDev)
3359 devLabPos = devXmin + 0.25*(devXmax - devXmin);
3363 devLabPos = devXmin + 0.50*(devXmax - devXmin);
3365 allTicks.append( devLabPos);
3367 // Stock position and name of the system under X axis
3368 myScaleDraw->setLabelTick( devLabPos, deviceLabel, true);
3372 // Create the vertical segment between the current system and the next
3374 segmentPos = gapXmin + 0.5*(gapXmax - gapXmin);
3376 createSeparationLine( segmentPos);
3381 // List's items increasing sorting
3382 qSort( allTicks.begin(), allTicks.end() ); // iterators
3384 // Stock the interval of X's values
3385 double lowerBound = allTicks.first() - XLeftMargin;
3386 double upperBound = allTicks.last() + XRightMargin;
3387 myScaleDraw->setInterval( lowerBound, upperBound);
3389 // For each system, stock the position of the X's ticks and those of the name
3390 myScaleDraw->setTicks( allTicks); // do not draw the ticks
3392 // Memorize the X axis in the drawing zone
3393 setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
3395 //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
3399 /* Create vertical segment between two curves
3401 void Plot2d_Plot2d::createSeparationLine( double Xpos)
3403 QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
3405 aPlotMarker->setLineStyle( QwtPlotMarker::VLine);
3406 aPlotMarker->setXValue( Xpos);
3407 aPlotMarker->setLinePen( QPen(Qt::black));
3408 aPlotMarker->attach(this); // Add to drawing zone
3409 // To deallocate in EraseAll()
3410 mySeparationLineList.append( aPlotMarker);
3413 void Plot2d_Plot2d::clearSeparationLineList()
3415 mySeparationLineList.clear();
3418 /* Set type of legend symbol
3420 void Plot2d_Plot2d::setLegendSymbolType( const int type )
3422 myLegendSymbolType = type;
3425 /* Get type of legend symbol
3427 int Plot2d_Plot2d::getLegendSymbolType()
3429 return myLegendSymbolType;
3433 Creates presentation of object
3434 Default implementation is empty
3436 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
3442 Copies preferences from other viewframe
3443 \param vf - other view frame
3445 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
3450 myCurveType = vf->myCurveType;
3451 myShowLegend = vf->myShowLegend;
3452 myLegendPos = vf->myLegendPos;
3453 myLegendSymbolType = vf->myLegendSymbolType;
3454 myLegendFont = vf->myLegendFont;
3455 mySelectedLegendFontColor = vf->mySelectedLegendFontColor;
3456 myMarkerSize = vf->myMarkerSize;
3457 myBackground = vf->myBackground;
3458 mySelectionColor = vf->mySelectionColor;
3459 myTitle = vf->myTitle;
3460 myXTitle = vf->myXTitle;
3461 myYTitle = vf->myYTitle;
3462 myY2Title = vf->myY2Title;
3463 myTitleEnabled = vf->myTitleEnabled;
3464 myXTitleEnabled = vf->myXTitleEnabled;
3465 myYTitleEnabled = vf->myYTitleEnabled;
3466 myY2TitleEnabled = vf->myY2TitleEnabled;
3467 myXGridMajorEnabled = vf->myXGridMajorEnabled;
3468 myYGridMajorEnabled = vf->myYGridMajorEnabled;
3469 myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
3470 myXGridMinorEnabled = vf->myXGridMinorEnabled;
3471 myYGridMinorEnabled = vf->myYGridMinorEnabled;
3472 myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
3473 myXGridMaxMajor = vf->myXGridMaxMajor;
3474 myYGridMaxMajor = vf->myYGridMaxMajor;
3475 myY2GridMaxMajor = vf->myY2GridMaxMajor;
3476 myXGridMaxMinor = vf->myXGridMaxMinor;
3477 myYGridMaxMinor = vf->myYGridMaxMinor;
3478 myY2GridMaxMinor = vf->myY2GridMaxMinor;
3479 myXMode = vf->myXMode;
3480 myYMode = vf->myYMode;
3481 mySecondY = vf->mySecondY;
3485 Updates titles according to curves
3487 #define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
3488 void Plot2d_ViewFrame::updateTitles( const bool update )
3490 ObjectDict::iterator it = myObjects.begin();
3491 QStringList aXTitles;
3492 QStringList aYTitles;
3493 QStringList aY2Titles;
3494 QStringList aXUnits;
3495 QStringList aYUnits;
3496 QStringList aY2Units;
3497 QStringList aTables;
3500 Plot2d_Object* anObject;
3501 for ( ; it != myObjects.end(); it++ ) {
3502 // collect titles and units from all curves...
3503 anObject = it.value();
3504 QString xTitle = anObject->getHorTitle().trimmed();
3505 QString yTitle = anObject->getVerTitle().trimmed();
3506 QString xUnits = anObject->getHorUnits().trimmed();
3507 QString yUnits = anObject->getVerUnits().trimmed();
3509 if ( anObject->getYAxis() == QwtPlot::yLeft ) {
3510 if ( !aYTitles.contains( yTitle ) )
3511 aYTitles.append( yTitle );
3512 if ( !aYUnits.contains( yUnits ) )
3513 aYUnits.append( yUnits );
3516 if ( !aY2Titles.contains( yTitle ) )
3517 aY2Titles.append( yTitle );
3518 if ( !aY2Units.contains( yUnits ) )
3519 aY2Units.append( yUnits );
3521 if ( !aXTitles.contains( xTitle ) )
3522 aXTitles.append( xTitle );
3523 if ( !aXUnits.contains( xUnits ) )
3524 aXUnits.append( xUnits );
3526 QString aName = anObject->getTableTitle();
3527 if( !aName.isEmpty() && !aTables.contains( aName ) )
3528 aTables.append( aName );
3531 // ... and update plot 2d view
3532 QString xUnits, yUnits, y2Units;
3533 if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() )
3534 xUnits = BRACKETIZE( aXUnits[0] );
3535 if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty())
3536 yUnits = BRACKETIZE( aYUnits[0] );
3537 if ( aY2Units.count() == 1 && !aY2Units[0].isEmpty())
3538 y2Units = BRACKETIZE( aY2Units[0] );
3539 QString xTitle, yTitle, y2Title;
3540 if ( aXTitles.count() == 1 && aXUnits.count() == 1 )
3541 xTitle = aXTitles[0];
3542 if ( aYTitles.count() == 1 )
3543 yTitle = aYTitles[0];
3544 if ( mySecondY && aY2Titles.count() == 1 )
3545 y2Title = aY2Titles[0];
3547 if ( !xTitle.isEmpty() && !xUnits.isEmpty() )
3549 if ( !yTitle.isEmpty() && !yUnits.isEmpty() )
3551 if ( !y2Title.isEmpty() && !y2Units.isEmpty() )
3554 setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, false );
3555 setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, false );
3557 setTitle( myY2TitleEnabled, y2Title + y2Units, Y2Title, false );
3559 setTitle( true, aTables.join("; "), MainTitle, false );
3561 // do update if necessary
3568 Outputs content of viewframe to file
3569 \param file - file name
3570 \param format - file format
3572 bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const
3581 QPaintDevice* pd = 0;
3582 if( format=="PS" || format=="EPS" || format == "PDF" )
3584 QPrinter* pr = new QPrinter( QPrinter::HighResolution );
3586 pr->setOutputFormat(QPrinter::PdfFormat);
3587 pr->setPageSize( QPrinter::A4 );
3588 pr->setOutputFileName( file );
3589 pr->setPrintProgram( "" );
3595 QwtPlotRenderer* pr = new QwtPlotRenderer();
3596 pr->renderTo( myPlot, *pd );
3607 * Print Plot2d window
3609 void Plot2d_ViewFrame::printPlot( QPainter* p, const QRectF& rect) const
3611 QwtPlotRenderer* pr = new QwtPlotRenderer();
3612 pr->render( myPlot, p, rect );
3616 \return string with all visual parameters
3618 QString Plot2d_ViewFrame::getVisualParameters()
3621 return getXmlVisualParameters();
3624 RNV: Old case, now visual parameters stored in the XML format.
3626 double xmin, xmax, ymin, ymax, y2min, y2max;
3627 getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
3629 //Store font in the visual parameters string as:
3631 // ...*FontFamily|FontSize|B|I|U|r:g:b*...
3633 retStr.sprintf( "%d*%d*%d*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%s|%i|%i|%i|%i|%i:%i:%i",
3634 myXMode, myYMode, mySecondY, xmin, xmax, ymin, ymax, y2min, y2max,
3635 qPrintable(myLegendFont.family()), myLegendFont.pointSize(),myLegendFont.bold(),
3636 myLegendFont.italic(), myLegendFont.underline(),myLegendColor.red(),
3637 myLegendColor.green(), myLegendColor.blue());
3639 //store all Analytical curves
3640 //store each curve in the following format
3641 // ...*Name|isActive|Expresion|NbInervals|isAutoAssign[|MarkerType|LineType|LineWidth|r:g:b]
3642 // parameters in the [ ] is optional in case if isAutoAssign == true
3643 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
3644 Plot2d_AnalyticalCurve* c = 0;
3646 for( ; it != myAnalyticalCurves.end(); it++) {
3649 QString curveString("");
3650 isAuto = c->isAutoAssign();
3651 curveString.sprintf("*%s|%i|%s|%i|%i",
3652 qPrintable(c->getName()),
3654 qPrintable(c->getExpression()),
3655 c->getNbIntervals(),
3658 retStr+=curveString;
3660 QString optCurveString("");
3661 optCurveString.sprintf("|%i|%i|%i|%i:%i:%i",
3662 (int)c->getMarker(),
3665 c->getColor().red(),
3666 c->getColor().green(),
3667 c->getColor().blue());
3668 retStr+=optCurveString;
3671 retStr += QString( "*%1" ).arg( Qtx::colorToString( backgroundColor() ) );
3677 Restores all visual parameters from string
3679 void Plot2d_ViewFrame::setVisualParameters( const QString& parameters )
3681 if(setXmlVisualParameters(parameters))
3685 QStringList paramsLst = parameters.split( '*' );
3686 if ( paramsLst.size() >= 9 ) {
3687 double ymin, ymax, y2min, y2max;
3688 myXMode = paramsLst[0].toInt();
3689 myYMode = paramsLst[1].toInt();
3690 mySecondY = (bool)paramsLst[2].toInt();
3691 xmin = paramsLst[3].toDouble();
3692 xmax = paramsLst[4].toDouble();
3693 ymin = paramsLst[5].toDouble();
3694 ymax = paramsLst[6].toDouble();
3695 y2min = paramsLst[7].toDouble();
3696 y2max = paramsLst[8].toDouble();
3699 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
3700 setHorScaleMode( myXMode, /*update=*/false );
3701 setVerScaleMode( myYMode, /*update=*/false );
3704 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
3705 myYDistance2 = yMap2.s2() - yMap2.s1();
3708 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3709 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3712 //Restore legend font
3713 if(paramsLst.size() >= 10) {
3714 QStringList fontList = paramsLst[9].split( '|' );
3715 if(fontList.size() == 6) {
3716 myLegendFont = QFont(fontList[0]);
3717 myLegendFont.setPointSize(fontList[1].toInt());
3718 myLegendFont.setBold(fontList[2].toInt());
3719 myLegendFont.setItalic(fontList[3].toInt());
3720 myLegendFont.setUnderline(fontList[4].toInt());
3721 QStringList colorList = fontList[5].split(":");
3722 setLegendFont( myLegendFont );
3724 if(colorList.size() == 3) {
3725 myLegendColor = QColor(colorList[0].toInt(),
3726 colorList[1].toInt(),
3727 colorList[2].toInt());
3728 setLegendFontColor( myLegendColor );
3733 #ifndef NO_ANALYTICAL_CURVES
3734 //Restore all Analytical curves
3735 int startCurveIndex = 10;
3736 if( paramsLst.size() >= startCurveIndex+1 ) {
3737 for( int i=startCurveIndex; i<paramsLst.size() ; i++ ) {
3738 QStringList curveLst = paramsLst[i].split("|");
3739 if( curveLst.size() == 5 || curveLst.size() == 9 ) {
3740 Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
3741 c->setName(curveLst[0]);
3742 c->setActive(curveLst[1].toInt());
3743 c->setExpression(curveLst[2]);
3744 c->setNbIntervals(curveLst[3].toLong());
3745 c->setAutoAssign(curveLst[4].toInt());
3746 if( !c->isAutoAssign() ) {
3747 c->setMarker((Plot2d::MarkerType)curveLst[5].toInt());
3748 c->setLine((Plot2d::LineType)curveLst[6].toInt());
3749 c->setLineWidth(curveLst[7].toInt());
3750 QStringList colorList = curveLst[8].split(":");
3751 if( colorList.size() == 3 ) {
3752 c->setColor(QColor(colorList[0].toInt(),
3753 colorList[1].toInt(),
3754 colorList[2].toInt()));
3757 c->autoFill( myPlot );
3759 addAnalyticalCurve(c);
3760 updateAnalyticalCurve(c);
3762 else if( curveLst.size() == 1 ) {
3763 // background color can be set here
3765 if ( Qtx::stringToColor( paramsLst[i], c ) )
3766 setBackgroundColor( c );
3775 Store visual parameters in xml format.
3777 QString Plot2d_ViewFrame::getXmlVisualParameters() {
3779 QXmlStreamWriter aWriter(&retStr);
3780 aWriter.setAutoFormatting(true);
3783 aWriter.writeStartDocument();
3784 aWriter.writeStartElement("ViewState");
3785 aWriter.writeStartElement("Range");
3786 double xmin, xmax, ymin, ymax, y2min, y2max;
3787 getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
3788 aWriter.writeAttribute("Xmin", QString("").sprintf("%.12e",xmin));
3789 aWriter.writeAttribute("Xmax", QString("").sprintf("%.12e",xmax));
3790 aWriter.writeAttribute("Ymin", QString("").sprintf("%.12e",ymin));
3791 aWriter.writeAttribute("Ymax", QString("").sprintf("%.12e",ymax));
3792 aWriter.writeAttribute("Y2min", QString("").sprintf("%.12e",y2min));
3793 aWriter.writeAttribute("Y2max", QString("").sprintf("%.12e",y2max));
3794 aWriter.writeEndElement();
3797 aWriter.writeStartElement("DisplayMode");
3798 aWriter.writeAttribute("SecondAxis", QString("").sprintf("%d",mySecondY));
3799 aWriter.writeStartElement("ScaleMode");
3800 aWriter.writeAttribute("Xscale", QString("").sprintf("%d",myXMode));
3801 aWriter.writeAttribute("Yscale", QString("").sprintf("%d",myYMode));
3802 aWriter.writeEndElement();
3803 aWriter.writeStartElement("NormalizationMode");
3804 aWriter.writeAttribute("LeftMin", QString("").sprintf("%d",myNormLMin));
3805 aWriter.writeAttribute("LeftMax", QString("").sprintf("%d",myNormLMax));
3806 aWriter.writeAttribute("RightMin", QString("").sprintf("%d",myNormRMin));
3807 aWriter.writeAttribute("RightMax", QString("").sprintf("%d",myNormRMax));
3808 aWriter.writeEndElement();
3809 aWriter.writeEndElement();
3812 aWriter.writeStartElement("Legend");
3813 aWriter.writeAttribute("Visibility", QString("").sprintf("%d", myShowLegend));
3814 aWriter.writeStartElement("LegendFont");
3815 aWriter.writeAttribute("Family", myLegendFont.family());
3816 aWriter.writeAttribute("Size", QString("").sprintf("%d",myLegendFont.pointSize()));
3817 aWriter.writeAttribute("Bold", QString("").sprintf("%d",myLegendFont.bold()));
3818 aWriter.writeAttribute("Italic", QString("").sprintf("%d",myLegendFont.italic()));
3819 aWriter.writeAttribute("Underline", QString("").sprintf("%d",myLegendFont.underline()));
3820 aWriter.writeAttribute("R", QString("").sprintf("%d",myLegendColor.red()));
3821 aWriter.writeAttribute("G", QString("").sprintf("%d",myLegendColor.green()));
3822 aWriter.writeAttribute("B", QString("").sprintf("%d",myLegendColor.blue()));
3823 aWriter.writeEndElement();
3824 aWriter.writeEndElement();
3826 #ifndef NO_ANALYTICAL_CURVES
3828 aWriter.writeStartElement("AnalyticalCurves");
3829 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
3830 Plot2d_AnalyticalCurve* c = 0;
3833 for( ; it != myAnalyticalCurves.end(); it++) {
3836 aWriter.writeStartElement(QString("AnalyticalCurve_%1").arg(id));
3837 isAuto = c->isAutoAssign();
3838 aWriter.writeAttribute("Name",c->getName());
3839 aWriter.writeAttribute("IsActive", QString("").sprintf("%d", c->isActive()));
3840 aWriter.writeAttribute("Expression", c->getExpression());
3841 aWriter.writeAttribute("NbIntervals", QString("").sprintf("%ld", c->getNbIntervals()));
3842 aWriter.writeAttribute("isAuto", QString("").sprintf("%d",isAuto));
3844 aWriter.writeAttribute("Marker", QString("").sprintf("%d",(int)c->getMarker()));
3845 aWriter.writeAttribute("Line", QString("").sprintf("%d",(int)c->getLine()));
3846 aWriter.writeAttribute("LineWidth", QString("").sprintf("%d",c->getLineWidth()));
3847 aWriter.writeAttribute("R", QString("").sprintf("%d",c->getColor().red()));
3848 aWriter.writeAttribute("G", QString("").sprintf("%d",c->getColor().green()));
3849 aWriter.writeAttribute("B", QString("").sprintf("%d",c->getColor().blue()));
3851 aWriter.writeEndElement();
3854 aWriter.writeEndElement(); //AnalyticalCurve
3858 aWriter.writeStartElement(QString("Background"));
3859 aWriter.writeStartElement(QString("BackgroundColor"));
3860 aWriter.writeAttribute("R", QString("").sprintf("%d",backgroundColor().red()));
3861 aWriter.writeAttribute("G", QString("").sprintf("%d",backgroundColor().green()));
3862 aWriter.writeAttribute("B", QString("").sprintf("%d",backgroundColor().blue()));
3863 aWriter.writeEndElement();
3864 aWriter.writeEndElement();
3867 aWriter.writeEndDocument();
3871 Restore visual parameters from xml format.
3873 bool Plot2d_ViewFrame::setXmlVisualParameters(const QString& parameters) {
3874 QXmlStreamReader aReader(parameters);
3875 double xmin = 0., xmax = 0., ymin = 0., ymax = 0., y2min = 0., y2max = 0.;
3876 bool leftMin,leftMax,rightMin,rightMax;
3877 leftMin = leftMax = rightMin = rightMax = false;
3878 while(!aReader.atEnd()) {
3880 if (aReader.isStartElement()) {
3881 QXmlStreamAttributes aAttr = aReader.attributes();
3882 if(aReader.name() == "Range") {
3883 xmin = aAttr.value("Xmin").toString().toDouble();
3884 xmax = aAttr.value("Xmax").toString().toDouble();
3885 ymin = aAttr.value("Ymin").toString().toDouble();
3886 ymax = aAttr.value("Ymax").toString().toDouble();
3887 y2min = aAttr.value("Y2min").toString().toDouble();
3888 y2max = aAttr.value("Y2max").toString().toDouble();
3889 } else if(aReader.name() == "DisplayMode") {
3890 mySecondY = aAttr.value("Y2max").toString().toDouble();
3891 } else if(aReader.name() == "ScaleMode") {
3892 myXMode = aAttr.value("Xscale").toString().toInt();
3893 myYMode = aAttr.value("Yscale").toString().toInt();
3894 } else if(aReader.name() == "NormalizationMode") {
3895 leftMin = (bool)aAttr.value("LeftMin").toString().toInt();
3896 leftMax = (bool)aAttr.value("LeftMax").toString().toInt();
3897 rightMin = (bool)aAttr.value("RightMin").toString().toInt();
3898 rightMax = (bool)aAttr.value("RightMax").toString().toInt();
3899 } else if(aReader.name() == "Legend") {
3900 myShowLegend = (bool)aAttr.value("Visibility").toString().toInt();
3901 } else if (aReader.name() == "LegendFont") {
3902 myLegendFont = QFont(aAttr.value("Family").toString());
3903 myLegendFont.setPointSize(aAttr.value("Size").toString().toInt());
3904 myLegendFont.setBold((bool)aAttr.value("Bold").toString().toInt());
3905 myLegendFont.setItalic((bool)aAttr.value("Italic").toString().toInt());
3906 myLegendFont.setUnderline((bool)aAttr.value("Underline").toString().toInt());
3907 myLegendColor = QColor(aAttr.value("R").toString().toInt(),
3908 aAttr.value("G").toString().toInt(),
3909 aAttr.value("B").toString().toInt());
3910 setLegendFontColor( myLegendColor );
3911 setLegendFont(myLegendFont);
3912 } else if(aReader.name().toString().indexOf("AnalyticalCurve_") >= 0) {
3913 #ifndef NO_ANALYTICAL_CURVES
3914 Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
3915 c->setName(aAttr.value("Name").toString());
3916 c->setActive((bool)aAttr.value("IsActive").toString().toInt());
3917 c->setExpression(aAttr.value("Expression").toString());
3918 c->setNbIntervals(aAttr.value("NbIntervals").toString().toLong());
3919 c->setAutoAssign((bool)aAttr.value("isAuto").toString().toInt());
3920 if( !c->isAutoAssign() ) {
3921 c->setMarker((Plot2d::MarkerType)aAttr.value("Marker").toString().toInt());
3922 c->setLine((Plot2d::LineType)aAttr.value("Line").toString().toInt());
3923 c->setLineWidth(aAttr.value("LineWidth").toString().toInt());
3924 c->setColor(QColor(aAttr.value("R").toString().toInt(),
3925 aAttr.value("G").toString().toInt(),
3926 aAttr.value("B").toString().toInt()));
3928 c->autoFill( myPlot );
3930 addAnalyticalCurve(c);
3931 updateAnalyticalCurve(c);
3933 } else if(aReader.name().toString() == "BackgroundColor") {
3934 setBackgroundColor(QColor(aAttr.value("R").toString().toInt(),
3935 aAttr.value("G").toString().toInt(),
3936 aAttr.value("B").toString().toInt()));
3941 if(aReader.hasError())
3945 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
3946 setHorScaleMode( myXMode, /*update=*/false );
3947 setVerScaleMode( myYMode, /*update=*/false );
3949 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
3950 myYDistance2 = yMap2.s2() - yMap2.s1();
3952 setNormLMinMode(leftMin);
3953 setNormLMaxMode(leftMax);
3954 setNormRMinMode(rightMin);
3955 setNormRMaxMode(rightMax);
3957 showLegend( myShowLegend, false );
3959 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3964 Incremental zooming operation
3966 void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) {
3967 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
3968 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
3970 myPlot->setAxisScale( QwtPlot::yLeft,
3971 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s1() )-incrY ),
3972 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() )-incrY ) );
3973 myPlot->setAxisScale( QwtPlot::xBottom,
3974 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s1() )-incrX ),
3975 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() )-incrX ) );
3977 QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
3978 myPlot->setAxisScale( QwtPlot::yRight,
3979 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s1() )-incrY ),
3980 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() )-incrY ) );
3986 Incremental panning operation
3988 void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) {
3989 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
3990 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
3992 myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(),
3993 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() ) + incrY ) );
3994 myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(),
3995 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() ) - incrX ) );
3997 QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
3998 myPlot->setAxisScale( QwtPlot::yRight, y2Map.s1(),
3999 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() ) + incrY ) );
4007 void Plot2d_ViewFrame::updatePlotItem(Plot2d_Object* theObject, QwtPlotItem* theItem) {
4008 theObject->updatePlotItem( theItem );
4009 Plot2d_Curve* c = dynamic_cast<Plot2d_Curve*>(theObject);
4010 QwtPlotCurve* cu = dynamic_cast<QwtPlotCurve*>(theItem);
4011 Plot2d_NormalizeAlgorithm* aNormAlgo;
4013 if(c->getYAxis() == QwtPlot::yRight)
4014 aNormAlgo = myRNormAlgo;
4016 aNormAlgo = myLNormAlgo;
4017 if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
4018 AlgoPlot2dOutputData aResultData = aNormAlgo->getOutput();
4019 AlgoPlot2dOutputData::iterator itTmp = aResultData.find(theObject);
4021 int size = itTmp.value().size();
4022 xNew = new double[size];
4023 yNew = new double[size];
4025 for (; j < size; ++j) {
4026 xNew[j] = itTmp.value().at(j).first;
4027 yNew[j] = itTmp.value().at(j).second;
4029 cu->setSamples(xNew, yNew,j);
4032 if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
4033 QString name = c->getName().isEmpty() ? c->getVerTitle() : c->getName();
4034 name = name + QString("(B=%1, K=%2)");
4035 name = name.arg(aNormAlgo->getBkoef(c)).arg(aNormAlgo->getKkoef(c));
4045 QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas() const
4047 return myPlot ? (QwtPlotCanvas*)myPlot->canvas() : 0;
4051 return closest curve if it exist, else 0
4053 Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, int& index ) const
4055 CurveDict aCurves = getCurves();
4056 CurveDict::iterator it = aCurves.begin();
4057 Plot2d_Curve* pCurve = 0;
4059 for ( ; it != aCurves.end(); it++ ) {
4060 QwtPlotCurve* aCurve = it.key();
4064 int i = aCurve->closestPoint( p, &d );
4065 if ( i > -1 && ( distance < 0 || d < distance ) ) {
4066 pCurve = it.value();
4074 #ifndef NO_ANALYTICAL_CURVES
4076 \brief Deselect all analytical curves.
4078 void Plot2d_ViewFrame::deselectAnalyticalCurves() {
4079 foreach(Plot2d_AnalyticalCurve* c, myAnalyticalCurves) {
4080 c->setSelected(false);
4086 \brief Deselect all objects, except analytical curves.
4088 void Plot2d_ViewFrame::deselectObjects() {
4089 ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end();
4090 for ( ; it != aLast; it++ ) {
4091 it.value()->setSelected(false);
4095 #define INCREMENT_FOR_OP 10
4098 Performs incremental panning to the left
4100 void Plot2d_ViewFrame::onPanLeft()
4102 this->incrementalPan( -INCREMENT_FOR_OP, 0 );
4103 #ifndef NO_ANALYTICAL_CURVES
4104 updateAnalyticalCurves();
4109 Performs incremental panning to the right
4111 void Plot2d_ViewFrame::onPanRight()
4113 this->incrementalPan( INCREMENT_FOR_OP, 0 );
4114 #ifndef NO_ANALYTICAL_CURVES
4115 updateAnalyticalCurves();
4120 Performs incremental panning to the top
4122 void Plot2d_ViewFrame::onPanUp()
4124 this->incrementalPan( 0, -INCREMENT_FOR_OP );
4125 #ifndef NO_ANALYTICAL_CURVES
4126 updateAnalyticalCurves();
4131 Performs incremental panning to the bottom
4133 void Plot2d_ViewFrame::onPanDown()
4135 this->incrementalPan( 0, INCREMENT_FOR_OP );
4136 #ifndef NO_ANALYTICAL_CURVES
4137 updateAnalyticalCurves();
4142 Performs incremental zooming in
4144 void Plot2d_ViewFrame::onZoomIn()
4146 this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP );
4147 #ifndef NO_ANALYTICAL_CURVES
4148 updateAnalyticalCurves();
4153 Performs incremental zooming out
4155 void Plot2d_ViewFrame::onZoomOut()
4157 this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP );
4158 #ifndef NO_ANALYTICAL_CURVES
4159 updateAnalyticalCurves();
4164 Schedules a FitAll operation by putting it to the application's
4165 event queue. This ensures that other important events (show, resize, etc.)
4166 are processed first.
4168 void Plot2d_ViewFrame::customEvent( QEvent* ce )
4170 if ( ce->type() == FITALL_EVENT )
4176 * Return Plot2d_Object by the QwtPlotItem
4179 Plot2d_Object* Plot2d_ViewFrame::getPlotObject( QwtPlotItem* plotItem ) const {
4181 ObjectDict::const_iterator it = myObjects.begin();
4182 for( ; it != myObjects.end(); ++it ) {
4183 if ( it.key() == plotItem ) {
4190 Plot2d_ScaleDraw::Plot2d_ScaleDraw( char f, int prec )
4198 QwtText Plot2d_ScaleDraw::label( double value ) const
4200 QwtScaleMap m = scaleMap();
4201 QString str1 = QwtScaleDraw::label( m.s1() ).text();
4202 QString str2 = QwtScaleDraw::label( m.s2() ).text();
4203 if ( str1 == str2 ) {
4204 double aDist = fabs(scaleMap().s2()-scaleMap().s1())/5;
4206 while (aDist < 1 ) {
4210 if ( precision > 0 && value > 0 )
4211 return QLocale::system().toString( value,'f', precision );
4214 return QwtScaleDraw::label( value );
4217 Plot2d_YScaleDraw::Plot2d_YScaleDraw()
4222 QwtText Plot2d_YScaleDraw::label( double value ) const
4224 // Axis labels format
4225 QString strD = QString( "%1").arg( value, 10, 'e', 3); // format 10.3e
4227 return QwtText( strD);
4230 /* Definition of X axis graduations
4232 const QString Plot2d_AxisScaleDraw::DEVICE_FONT = QString("Times");
4233 const int Plot2d_AxisScaleDraw::DEVICE_FONT_SIZE = 12;
4234 const int Plot2d_AxisScaleDraw::DEVICE_BY = 40;
4236 Plot2d_AxisScaleDraw::Plot2d_AxisScaleDraw( Plot2d_Plot2d* plot)
4241 setLabelAlignment(Qt::AlignRight);
4242 setLabelRotation(45.);
4246 myActivTicksDrawing = true;
4247 myNumTicksDrawingCall = 1;
4251 Plot2d_AxisScaleDraw::~Plot2d_AxisScaleDraw()
4256 /* Unactivate automatic ticks drawing
4258 void Plot2d_AxisScaleDraw::unactivTicksDrawing( int numcall)
4260 myActivTicksDrawing = false;
4261 myNumTicksDrawingCall = numcall;
4265 /* Draw X ticks and labels.
4266 * Draw systems names under X axis.
4267 * Overload the same name QwtScaleDraw method.
4268 * (PB: who call automaticaly this method)
4270 void Plot2d_AxisScaleDraw::draw( QPainter* painter, const QPalette & palette) const
4272 //std::cout << "Plot2d_AxisScaleDraw::draw() : activ= " << myActivTicksDrawing
4273 // << " numcall= " << myNumTicksDrawingCall << std::endl;
4275 if (!myActivTicksDrawing) return;
4277 //std::cout << "Plot2d_AxisScaleDraw::draw()" << std::endl;
4279 QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
4280 QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
4281 QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
4283 medium_ticks.clear();
4284 minor_ticks.clear();
4285 major_ticks.clear();
4287 major_ticks.append( myTicks);
4289 QwtScaleDiv aScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
4290 aScaleDiv.setTicks( QwtScaleDiv::MajorTick, major_ticks );
4291 aScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
4292 aScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
4293 myPlot->setAxisScaleDiv( QwtPlot::xBottom, aScaleDiv );
4295 QwtScaleDraw *scale = myPlot->axisScaleDraw(QwtPlot::xBottom);
4296 ((Plot2d_AxisScaleDraw*)(scale))->applyTicks();
4298 QwtScaleDraw::draw( painter, palette);
4300 for (int i = 0; i < myTicks.size(); i++)
4302 drawLabel( painter, myTicks[i]);
4305 //std::cout << "Ok for Plot2d_AxisScaleDraw::draw()" << std::endl;
4309 double Plot2d_AxisScaleDraw::extent( const QFont &font ) const
4311 QFontMetrics fm( font );
4312 return QwtScaleDraw::extent( font ) + fm.height() * 2;
4315 QwtText Plot2d_AxisScaleDraw::label( double value) const
4317 if (myLabelX.contains(value))
4318 return myLabelX[value];
4320 return QwtText(QString::number(value, 'f', 1));
4324 /* Stock position and label of a X tick
4326 void Plot2d_AxisScaleDraw::setLabelTick( double value, QString label, bool isDevice)
4328 //qDebug()<< "setLabelTick ( " << value << ","<< label <<" )";
4331 // For systems names under X axis
4332 myLabelDevice[value] = label;
4336 // For X axis graduations
4337 myLabelX[value] = label;
4342 /* Stock ticks positions of a system, and draw them
4344 void Plot2d_AxisScaleDraw::setTicks(const QList<double> aTicks)
4346 //std::cout << " Plot2d_AxisScaleDraw::setTicks()" << std::endl;
4353 void Plot2d_AxisScaleDraw::setInterval(double lowerBound, double upperBound)
4355 myLowerBound = lowerBound;
4356 myUpperBound = upperBound;
4357 myPlot->setAxisScale( QwtPlot::xBottom, myLowerBound, myUpperBound );
4361 /* Stock X ticks in drawing zone
4363 void Plot2d_AxisScaleDraw::applyTicks()
4365 //std::cout << " Plot2d_AxisScaleDraw::applyTicks()" << std::endl;
4367 QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
4368 QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
4369 QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
4371 medium_ticks.clear();
4372 minor_ticks.clear();
4374 QwtScaleDiv aQwtScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
4375 aQwtScaleDiv.setTicks( QwtScaleDiv::MajorTick, myTicks );
4376 aQwtScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
4377 aQwtScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
4378 myPlot->setAxisScaleDiv( QwtPlot::xBottom, aQwtScaleDiv );
4380 QwtScaleDiv* aScaleDiv = (QwtScaleDiv*) &scaleDiv();
4382 aScaleDiv->setTicks(QwtScaleDiv::MajorTick, myTicks);
4383 aScaleDiv->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
4384 aScaleDiv->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
4386 if (myLowerBound != -1 && myUpperBound != -1)
4387 aScaleDiv->setInterval(myLowerBound, myUpperBound);
4389 //for (int i = 0; i < myTicks.size(); i++){
4390 // QPoint p = labelPosition( i );
4391 // qDebug() << i<< ") applyTicks -> LABEL" <<p;
4396 void Plot2d_AxisScaleDraw::drawLabel( QPainter* painter, double value) const
4398 //std::cout << " Plot2d_AxisScaleDraw::drawLabel( " << value << " ) : "; //<< std::endl;
4400 //qDebug() << "drawLabel ( " <<value<<" )";
4401 if ( myLabelDevice.contains(value) )
4403 QString deviceLabel = myLabelDevice[value];
4405 std::string std_label = deviceLabel.toStdString();
4406 //const char *c_label = std_label.c_str();
4407 //std::cout << " deviceLabel= |" << c_label << "|" << std::endl;
4409 QPointF p = labelPosition( value );
4410 p += QPoint(0, DEVICE_BY);
4411 QFont prevf = painter->font();
4412 //QColor prevc = (painter->pen()).color();
4414 QFont devicef( DEVICE_FONT, DEVICE_FONT_SIZE, QFont::Bold);
4416 //painter->setPen( QColor("blue") );
4417 painter->setFont( devicef );
4418 painter->drawText( p, myLabelDevice[value] );
4419 //painter->setPen( prevc );
4420 painter->setFont( prevf );
4422 if ( myLabelX.contains(value) )
4424 QString xLabel = myLabelX[value];
4426 std::string std_label = xLabel.toStdString();
4427 //const char *c_label = std_label.c_str();
4428 //std::cout << " xLabel= |" << c_label << "|" << std::endl;
4430 QwtScaleDraw::drawLabel( painter, value );
4435 void Plot2d_AxisScaleDraw::drawTick( QPainter* painter, double value, int len) const
4437 //qDebug() << "drawTick ( " <<value<<" , "<<len<<" ) " ;
4438 //qDebug() << "myLabelX" << myLabelX;
4440 if ( myLabelX.contains(value) )
4442 QwtScaleDraw::drawTick( painter, value, len);
4447 /* Management of tooltips associated with markers for curves points or others points
4449 const double Plot2d_QwtPlotPicker::BOUND_HV_SIZE = 0.2;
4451 Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
4453 RubberBand rubberBand,
4454 DisplayMode trackerMode,
4455 QwtPlotCanvas *canvas)
4456 : QwtPlotPicker( xAxis,
4460 canvas) // of drawing zone QwtPlot
4464 Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
4466 QwtPlotCanvas *canvas)
4467 : QwtPlotPicker( xAxis,
4473 Plot2d_QwtPlotPicker::~Plot2d_QwtPlotPicker()
4476 // http://www.qtcentre.org/threads/22751-How-do-i-select-a-QwtPlotMarker-using-a-QPlotPicker
4478 /* Return the tooltip associated with a point when the mouse cursor pass near
4480 QwtText Plot2d_QwtPlotPicker::trackerText( const QPoint & pos ) const
4482 for (QList<QwtPlotMarker* >::const_iterator pMarkerIt = pMarkers.begin();pMarkerIt != pMarkers.end(); ++pMarkerIt )
4484 QwtPlotMarker* pMarker = *pMarkerIt;
4485 if ( pMarker != NULL )
4487 const QwtSymbol* symb=pMarker->symbol();
4488 const QSize& sz=symb->size();
4489 const QwtScaleMap yMapRef=plot()->canvasMap(QwtPlot::yLeft);
4490 const QwtScaleMap xMap=plot()->canvasMap(pMarker->xAxis());
4491 const QwtScaleMap yMap=plot()->canvasMap(pMarker->yAxis());
4492 QwtDoubleRect bound0=pMarker->boundingRect();
4493 int x1 = qRound(xMap.transform(bound0.left()));
4494 int x2 = qRound(xMap.transform(bound0.right()));
4495 int y1 = qRound(yMap.transform(bound0.top()));
4496 int y2 = qRound(yMap.transform(bound0.bottom()));
4503 QRect bound00=QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
4504 QPoint toto(xMap.transform(pos.x()),yMapRef.transform(pos.y()));
4505 bound00.setX(bound00.x()-sz.width());
4506 bound00.setY(bound00.y()-sz.height());
4507 bound00.setWidth(bound00.width()+sz.width());
4508 bound00.setHeight(bound00.height()+sz.height());
4509 if( bound00.contains(toto) )
4511 return pMarkersToolTip[pMarker];