1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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>
82 #include <qwt_legend.h>
83 #include <qwt_scale_widget.h>
85 #define DEFAULT_LINE_WIDTH 0 // (default) line width
86 #define DEFAULT_MARKER_SIZE 9 // default marker size
87 #define MIN_RECT_SIZE 11 // min sensibility area size
89 #define FITALL_EVENT ( QEvent::User + 9999 )
91 const char* imageZoomCursor[] = {
96 "................................",
97 "................................",
98 ".#######........................",
99 "..aaaaaaa.......................",
100 "................................",
101 ".............#####..............",
102 "...........##.aaaa##............",
103 "..........#.aa.....a#...........",
104 ".........#.a.........#..........",
105 ".........#a..........#a.........",
106 "........#.a...........#.........",
107 "........#a............#a........",
108 "........#a............#a........",
109 "........#a............#a........",
110 "........#a............#a........",
111 ".........#...........#.a........",
112 ".........#a..........#a.........",
113 ".........##.........#.a.........",
114 "........#####.....##.a..........",
115 ".......###aaa#####.aa...........",
116 "......###aa...aaaaa.......#.....",
117 ".....###aa................#a....",
118 "....###aa.................#a....",
119 "...###aa...............#######..",
120 "....#aa.................aa#aaaa.",
121 ".....a....................#a....",
122 "..........................#a....",
123 "...........................a....",
124 "................................",
125 "................................",
126 "................................",
127 "................................"};
129 const char* imageCrossCursor[] = {
134 "................................",
135 "................................",
136 "................................",
137 "................................",
138 "................................",
139 "................................",
140 "................................",
141 "...............#................",
142 "...............#a...............",
143 "...............#a...............",
144 "...............#a...............",
145 "...............#a...............",
146 "...............#a...............",
147 "...............#a...............",
148 "...............#a...............",
149 ".......#################........",
150 "........aaaaaaa#aaaaaaaaa.......",
151 "...............#a...............",
152 "...............#a...............",
153 "...............#a...............",
154 "...............#a...............",
155 "...............#a...............",
156 "...............#a...............",
157 "...............#a...............",
158 "................a...............",
159 "................................",
160 "................................",
161 "................................",
162 "................................",
163 "................................",
164 "................................",
165 "................................"};
180 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
181 : QWidget (parent, 0),
182 myOperation( NoOpId ),
184 myShowLegend( true ), myLegendPos( 1 ), myLegendFont("Helvetic",12),
185 myLegendColor(Qt::black),
186 myMarkerSize( DEFAULT_MARKER_SIZE ),
187 myBackground( Qt::white ),
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 );
210 connect( myPlot, SIGNAL( legendClicked( QwtPlotItem* ) ),
211 this, SIGNAL( legendClicked( QwtPlotItem* ) ) );
214 /* connect( myPlot->axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ),
215 myPlot, SLOT( onScaleDivChanged() ) );
216 connect( myPlot->axisWidget( QwtPlot::yLeft ), SIGNAL( scaleDivChanged() ),
217 myPlot, SLOT( onScaleDivChanged() ) );
219 connect( myPlot->axisWidget( QwtPlot::yRight ), SIGNAL( scaleDivChanged() ),
220 myPlot, SLOT( onScaleDivChanged() ) );*/
228 Plot2d_ViewFrame::~Plot2d_ViewFrame()
232 Performs the initial setup.
234 void Plot2d_ViewFrame::Init()
236 /* Initial Setup - get from the preferences */
239 myPlot->setMargin( 5 );
240 setCurveType( myCurveType, false );
241 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
242 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
243 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
245 setTitle( myTitleEnabled, myTitle, MainTitle, false );
246 setTitle( myXTitleEnabled, myXTitle, XTitle, false );
247 setTitle( myYTitleEnabled, myYTitle, YTitle, false );
250 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
251 setHorScaleMode( myXMode, false );
252 setVerScaleMode( myYMode, false );
253 setBackgroundColor( myBackground );
254 setLegendPos( myLegendPos );
255 setLegendFont( myLegendFont );
256 setLegendFontColor( myLegendColor );
257 showLegend( myShowLegend, false );
260 QWidget* aParent = parentWidget();
262 resize( (int)(0.8 * aParent->width()), (int)(0.8 * aParent->height()) );
264 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
265 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
266 myXDistance = xMap.s2() - xMap.s1();
267 myYDistance = yMap.s2() - yMap.s1();
270 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
271 myYDistance2 = yMap2.s2() - yMap2.s1();
273 myPlot->canvas()->installEventFilter( this );
276 Gets window's central widget
278 QWidget* Plot2d_ViewFrame::getViewWidget()
280 return (QWidget*)myPlot;
283 Actually this method just re-displays all curves which are presented in the viewer
285 void Plot2d_ViewFrame::DisplayAll()
289 foreach ( Plot2d_Object* o, olist )
290 updateObject( o, false );
292 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
295 Removes all curves from the view
297 void Plot2d_ViewFrame::EraseAll()
299 objectList anObjects;
300 getObjects( anObjects );
301 eraseObjects( anObjects, false );
304 // 1)- Erase all the intermittent segments who connect curves
306 int nbSeg = myIntermittentSegmentList.size();
309 for (int iseg=0; iseg < nbSeg; iseg++)
311 QwtPlotCurve *segment = myIntermittentSegmentList[iseg];
313 segment->detach(); // erase in QwtPlot window
316 myIntermittentSegmentList.clear();
319 // 3)- Erase all QwtPlotCurve associated with the Plot2d_Curve
321 int nbCur1 = myQwtPlotCurveList.size();
324 for (int icur=0; icur < nbCur1; icur++)
326 QwtPlotItem *curve0 = myQwtPlotCurveList[icur];
327 QwtPlotCurve *curve = static_cast<QwtPlotCurve*>(curve0);
334 myQwtPlotCurveList.clear();
337 // 4)- Erase all curves Plot2d_Curve
339 int nbCur = myPlot2dCurveList.size();
342 for (int icur=0; icur < nbCur; icur++)
344 Plot2d_Curve *curve = myPlot2dCurveList[icur];
351 myPlot2dCurveList.clear();
354 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
357 Redraws viewframe contents
359 void Plot2d_ViewFrame::Repaint()
366 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
368 if ( !prs || prs->IsNull() )
371 setEnableAxis( QwtPlot::yRight, prs->isSecondY() ); // VSR: is it correct? maybe we should only enable second Y axis if required
373 // display all objects from presentation
374 objectList anObjects = prs->getObjects();
375 displayObjects( anObjects );
376 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
377 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
378 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
379 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
385 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
387 if ( !prs || prs->IsNull() )
390 // erase all objects from presentation
391 objectList anObjects = prs->getObjects();
392 eraseObjects( anObjects );
393 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
396 bool Plot2d_ViewFrame::eventFilter( QObject* watched, QEvent* e )
398 if ( watched == myPlot->canvas() ) {
399 int aType = e->type();
401 case QEvent::MouseMove: {
402 QMouseEvent* me = (QMouseEvent*)e;
403 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
404 QMouseEvent m( QEvent::MouseMove, me->pos(), me->button(),
405 me->buttons(), me->modifiers() );
406 if ( plotMouseMoved( m ) )
411 case QEvent::MouseButtonPress: {
412 QMouseEvent* me = (QMouseEvent*)e;
413 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
414 QMouseEvent m( QEvent::MouseButtonPress, me->pos(), me->button(),
415 me->buttons(), me->modifiers() );
416 plotMousePressed( m );
420 case QEvent::MouseButtonRelease: {
421 QMouseEvent* me = (QMouseEvent*)e;
422 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
423 QMouseEvent m( QEvent::MouseButtonRelease, me->pos(), me->button(),
424 me->buttons(), me->modifiers() );
425 plotMouseReleased( m );
429 case QEvent::ContextMenu:
431 // Do nothing because context menu is called from MouseRelease
435 return QWidget::eventFilter( watched, e );
441 void Plot2d_ViewFrame::setTitle( const QString& title )
443 setTitle( myTitleEnabled, title, MainTitle, true );
444 myIsDefTitle = false;
450 QString Plot2d_ViewFrame::getTitle() const
456 Reads Plot2d view settings from the preferences
458 void Plot2d_ViewFrame::readPreferences()
461 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
463 myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
464 setCurveType( resMgr->integerValue( "Plot2d", "CurveType", myCurveType ) );
466 myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
467 myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
468 myLegendFont = resMgr->fontValue( "Plot2d", "LegendFont", myLegendFont );
469 myLegendColor = resMgr->colorValue( "Plot2d", "LegendFontColor", myLegendColor );
470 myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
471 myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
473 myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
474 myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
475 myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
476 myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
478 myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
479 myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
480 myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
482 myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
483 myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
484 myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
486 myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
487 myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
489 myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
491 myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
492 myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
494 myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
496 setHorScaleMode( qMax( 0, qMin( 1, resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode ) ) ), false );
497 setVerScaleMode( qMax( 0, qMin( 1, resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode ) ) ), false );
498 setNormLMinMode( resMgr->booleanValue( "Plot2d", "VerNormLMinMode", myNormLMin ) );
499 setNormLMaxMode( resMgr->booleanValue( "Plot2d", "VerNormLMaxMode", myNormLMax ) );
500 setNormRMinMode( resMgr->booleanValue( "Plot2d", "VerNormRMinMode", myNormRMin ) );
501 setNormRMaxMode( resMgr->booleanValue( "Plot2d", "VerNormRMaxMode", myNormRMax ) );
502 QColor c = resMgr->colorValue( "Plot2d", "DeviationMarkerColor", QColor(255,0,0));
503 myPlot->setProperty(PLOT2D_DEVIATION_COLOR, c);
504 myPlot->setProperty(PLOT2D_DEVIATION_LW,
505 resMgr->integerValue( "Plot2d", "DeviationMarkerLineWidth", 1));
506 myPlot->setProperty(PLOT2D_DEVIATION_TS,
507 resMgr->integerValue( "Plot2d", "DeviationMarkerTickSize", 2));
512 Writes Plot2d view settings to the preferences
514 void Plot2d_ViewFrame::writePreferences()
517 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
519 resMgr->setValue( "Plot2d", "CurveType", myCurveType );
520 resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
521 resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
522 resMgr->setValue( "Plot2d", "LegendFont", myLegendFont );
523 resMgr->setValue( "Plot2d", "LegendFontColor", myLegendColor );
524 resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
525 resMgr->setValue( "Plot2d", "Background", myBackground );
526 resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
527 resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
528 resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
530 resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
532 resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
533 resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
534 resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
535 resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
537 resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
538 resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
540 resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
541 resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
543 resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
547 resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
548 resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
549 resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
550 resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
553 resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
554 resMgr->setValue( "Plot2d", "VerNormLMinMode", myNormLMin );
555 resMgr->setValue( "Plot2d", "VerNormLMaxMode", myNormLMax );
556 resMgr->setValue( "Plot2d", "VerNormRMinMode", myNormRMin );
557 resMgr->setValue( "Plot2d", "VerNormRMaxMode", myNormRMax );
562 Prints mouse cursor coordinates into string
564 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
568 bool xFound = false, yFound = false;
569 double xCoord, yCoord;
570 const QwtScaleDiv* aXscale = myPlot->axisScaleDiv( QwtPlot::xBottom );
571 aTicks = aXscale->ticks( QwtScaleDiv::MajorTick );
572 for ( i = 0; i < aTicks.count(); i++ ) {
573 double majXmark = aTicks[i];
574 int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
575 if ( xmark-2 == pnt.x() ) {
582 aTicks = aXscale->ticks( QwtScaleDiv::MinorTick );
583 for ( i = 0; i < aTicks.count(); i++ ) {
584 double minXmark = aTicks[i];
585 int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
586 if ( xmark-2 == pnt.x() ) {
593 const QwtScaleDiv* aYscale = myPlot->axisScaleDiv( QwtPlot::yLeft );
594 aTicks = aYscale->ticks( QwtScaleDiv::MajorTick );
595 for ( i = 0; i < aTicks.count(); i++ ) {
596 double majYmark = aTicks[i];
597 int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
598 if ( ymark-2 == pnt.y() ) {
605 aTicks = aYscale->ticks( QwtScaleDiv::MinorTick );
606 for ( i = 0; i < aTicks.count(); i++ ) {
607 double minYmark = aTicks[i];
608 int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
609 if ( ymark-2 == pnt.y() ) {
617 QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).trimmed();
620 QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).trimmed();
626 bool yFound2 = false;
629 const QwtScaleDiv* aYscale2 = myPlot->axisScaleDiv( QwtPlot::yRight );
630 aTicks = aYscale2->ticks( QwtScaleDiv::MajorTick );
631 for ( i = 0; i < aTicks.count(); i++ ) {
632 double majYmark = aTicks[i];
633 int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
634 if ( ymark-2 == pnt.y() ) {
641 aTicks = aYscale2->ticks( QwtScaleDiv::MinorTick );
642 for ( i = 0; i < aTicks.count(); i++ ) {
643 double minYmark = aTicks[i];
644 int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
645 if ( ymark-2 == pnt.y() ) {
652 QString strY2 = QString::number( yFound2 ? yCoord2 :
653 myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).trimmed();
656 info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
659 info = tr("INF_COORDINATES").arg( strX ).arg( strY );
665 * Display curves of the list of lists by systems and components
666 * - the first level list contains NbSytems lists of second level
667 * - a second level list contains NbComponents curves
668 * | system 1 | system 2 | ..... | system N |
669 * | compo1 compo2 ... compoM | compo1 compo2 ... compoM | ..... | compo1 compo2 ... compoM |
671 * Draw points markers and create associated tooltips.
672 * Draw connection segments (intermittent line) between all the curves of a component.
673 * \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.
675 QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
677 const QList< QList<bool> >& sides)
679 //std::cout << "Plot2d_ViewFrame::displayPlot2dCurveList() 1" << std::endl;
682 int nbSystem = sysCoCurveList.size();
684 // Composants number by system
685 int nbComponent = (sysCoCurveList.at(0)).size();
687 // Total number of curves
689 // 1)- Construction of a list by component and by system
691 // | component 1 | component 2 | ..... | component M |
692 // | syst1 syst2 ... systN | syst1 syst2 ... systN | ..... | syst1 syst2 ... systN |
694 QList<Plot2d_Curve*> plot2dCurveCoSysList;
695 QList<bool> sidesList;
696 for (int icom = 0; icom < nbComponent; icom++)
698 for (int isys = 0; isys < nbSystem; isys++)
700 // The system curves list
701 const QList<Plot2d_Curve*>& sysCurveList=sysCoCurveList.at(isys);
702 plot2dCurveCoSysList.append(sysCurveList.at(icom));
704 const QList<bool>& sysSideList=sides.at(isys);
705 sidesList.append(sysSideList.at(icom));
708 // 2)- Display list curves by a component's curves group
709 // Draw connection segments (intermittent line) between the curves
710 QVector< QVector<QwtPlotCurve *> > ret=displayPlot2dCurveList( plot2dCurveCoSysList, nbSystem, displayLegend, sidesList);
711 // 3)- Size of graduations labels and texts under X axis
712 QwtScaleWidget *wid = myPlot->axisWidget( QwtPlot::xBottom);
713 wid->setTitle(" "); // to make the names readable under X axis.
714 QFont xFont = myPlot->axisFont(QwtPlot::xBottom);
715 xFont.setPointSize(8);
716 myPlot->setAxisFont(QwtPlot::xBottom, xFont);
722 * Display list of curves by group of consecutive curves.
724 * Draw points markers and create associated tooltips
725 * Draw connection segments (intermittent line) between the curves
726 * \param [in] sides sorted as in \b curveList. If true->right if false->left
727 * \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.
729 QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
731 bool displayLegend, const QList< bool >& sides)
733 // Consider the new legend's entries
734 // (PB: to update the legend we must remove it and put a new QwtLegend in the QwtPlot)
735 myPlot->insertLegend( (QwtLegend*)NULL); // we remove here, we shall put at the end
737 int nbAllCurves = curveList.size();
738 int nbGroups = nbAllCurves / groupSize;
739 QVector< QVector<QwtPlotCurve *> > vectCurve(nbGroups);
741 int icur1, icur2; // curves indices in a group
743 // I)- Compute X range and Y range for all the curves' points of all groups
744 // In the graphic view, set the Y range 's bounds for all groups of curves
746 // For all groups of curves
747 double XallGroupMin=std::numeric_limits<double>::max(), XallGroupMax=-std::numeric_limits<double>::max();
748 double YRightallGroupMin=std::numeric_limits<double>::max(), YRightallGroupMax=-std::numeric_limits<double>::max();
749 double YLeftallGroupMin=std::numeric_limits<double>::max(), YLeftallGroupMax=-std::numeric_limits<double>::max();
751 for (ig=0; ig < nbGroups; ig++) //*1*
753 icur2 = icur1 + groupSize -1;
755 // For all curves in one group
756 double XgroupMin, XgroupMax;
757 double YgroupMin, YgroupMax;
760 double XcurveMin, XcurveMax;
761 double YcurveMin, YcurveMax;
766 // Compute X range and Y range for all the curves' points in the group
768 for (icur=icur1; icur <= icur2; icur++) //*2*
770 Plot2d_Curve *plot2dCurve = curveList.at(icur);
773 nbPoints = plot2dCurve->getData( &Xval, &Yval); // dynamic allocation
775 for (int ip=0; ip < nbPoints; ip++)
777 if (ip == 0) // first point
779 XcurveMin = Xval[ip]; XcurveMax = Xval[ip];
780 YcurveMin = Yval[ip]; YcurveMax = Yval[ip];
784 if (Xval[ip] < XcurveMin) XcurveMin = Xval[ip];
785 else if (Xval[ip] > XcurveMax) XcurveMax = Xval[ip];
786 if (Yval[ip] < YcurveMin) YcurveMin = Yval[ip];
787 else if (Yval[ip] > YcurveMax) YcurveMax = Yval[ip];
793 if (icur == icur1) // first curve
795 XgroupMin = XcurveMin; XgroupMax = XcurveMax;
796 YgroupMin = YcurveMin; YgroupMax = YcurveMax;
800 if (XcurveMin < XgroupMin) XgroupMin = XcurveMin;
801 if (XcurveMax > XgroupMax) XgroupMax = XcurveMax;
802 if (YcurveMin < YgroupMin) YgroupMin = YcurveMin;
803 if (YcurveMax > YgroupMax) YgroupMax = YcurveMax;
807 if (XgroupMin < XallGroupMin) XallGroupMin = XgroupMin;
808 if (XgroupMax > XallGroupMax) XallGroupMax = XgroupMax;
811 if (YgroupMin < YRightallGroupMin) YRightallGroupMin = YgroupMin;
812 if (YgroupMax > YRightallGroupMax) YRightallGroupMax = YgroupMax;
816 if (YgroupMin < YLeftallGroupMin) YLeftallGroupMin = YgroupMin;
817 if (YgroupMax > YLeftallGroupMax) YLeftallGroupMax = YgroupMax;
819 // First curve of the following group
822 // Set the XY range 's bounds for all groups of curves
823 if(YRightallGroupMin!=std::numeric_limits<double>::max())
825 double deltaY = YRightallGroupMax - YRightallGroupMin;
826 YRightallGroupMin-=0.05*deltaY; YRightallGroupMax+= 0.05*deltaY;
827 myPlot->setAxisScale( QwtPlot::yRight, YRightallGroupMin,YRightallGroupMax);
829 if(YLeftallGroupMin!=std::numeric_limits<double>::max())
831 double deltaY = YLeftallGroupMax - YLeftallGroupMin;
832 YLeftallGroupMin-=0.05*deltaY; YLeftallGroupMax+= 0.05*deltaY;
833 myPlot->setAxisScale( QwtPlot::yLeft, YLeftallGroupMin, YLeftallGroupMax);
835 // II)- Drawing curves, points markers and connection segments
838 for (ig=0; ig < nbGroups; ig++)
840 // 1)- Graphical attributs of group's curves
842 // Graphical attributes of the first group's curve
844 Plot2d_Curve *plot2dCurve1 = curveList.at(icur1);
846 QColor color1 = plot2dCurve1->getColor();
847 Plot2d::LineType linetype1 = plot2dCurve1->getLine();
848 int lineWidth1 = plot2dCurve1->getLineWidth();
849 QwtSymbol::Style symbolStyle1 = plot2dCurve1->getMarkerStyle();
850 // We attribute to the current group's curve, the color, the line's kind
851 // and the marker's kind of the first group's curve
853 for (icur=icur1+1; icur<icur1+groupSize; icur++)
855 Plot2d_Curve *plot2dCurve = curveList.at(icur);
857 plot2dCurve->setColor(color1);
858 plot2dCurve->setLine(linetype1,lineWidth1);
859 plot2dCurve->setMarkerStyle(symbolStyle1);
862 // 2)- Display the group's curves
864 for (icur=icur1; icur<icur1+groupSize; icur++)
866 Plot2d_Curve *plot2dCurve = curveList.at(icur);
868 QString title = plot2dCurve->getVerTitle();
869 std::string std_title = title.toStdString();
870 // Create the graphic curve (QwtPlotCurve) et display it in the drawing zone
872 displayCurve(plot2dCurve);
874 // Get the graphic curve
875 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>(getPlotObject(plot2dCurve));
876 vectCurve[ig].push_back(plotCurve);
877 // Modify the points' markers
878 QwtSymbol symbol(plotCurve->symbol()) ;
879 symbol.setStyle(symbolStyle1);
880 symbol.setPen(QPen(color1,lineWidth1));
881 //symbol.setBrush( QBrush( color1));
882 //QSize size = 0.5*(symbol.size());
883 //symbol.setSize(size);
885 plotCurve->setPen(QPen(color1,lineWidth1));
886 plotCurve->setSymbol(symbol);
890 //std::cout << " courbe d'indice " << icur << " sans entree dans la legende" << std::endl;
892 // The curve must not have legend's entry
893 plotCurve->setItemAttribute( QwtPlotItem::Legend, false);
897 plotCurve->setItemAttribute( QwtPlotItem::Legend, true);
901 // 3)- Intermittent segments to connect all the group's curves
908 double Xseg[2], Yseg[2];
909 Plot2d_Curve *plot2dCurve1 = curveList.at(icur1);
910 bool side = sides.at(icur1);
911 // Last point of the first curve
912 nbPoints = plot2dCurve1->getData( &Xval, &Yval); // dynamic allocation
913 Xseg[0] = Xval[ nbPoints -1];
914 Yseg[0] = Yval[ nbPoints -1];
918 for (icur=icur1+1; icur<icur1+groupSize; icur++)
920 Plot2d_Curve *plot2dCurve = curveList.at(icur);
922 // First curve's point
923 nbPoints = plot2dCurve->getData( &Xval, &Yval);
927 vectCurve[ig].push_back(createSegment(Xseg,Yseg,2,Qt::DotLine,lineWidth1,color1,QwtSymbol::NoSymbol,side));
929 // Last curve's point
930 Xseg[0] = Xval[ nbPoints -1];
931 Yseg[0] = Yval[ nbPoints -1];
936 // First curve of the following group
942 // Consider the new legend's entries
943 if(!curveList.empty())
944 showLegend( true, true); // show, update
951 * Create and display an y=f(x) curve of points
953 * toDraw : true => Display the created curve
954 * Draw the points'markers and create associated tooltips
956 Plot2d_Curve* Plot2d_ViewFrame::createPlot2dCurve( QString & title,
958 QList<double> & xList,
959 QList<double> & yList,
960 QList<QString> & tooltipList,
961 Plot2d::LineType lineKind,
964 QwtSymbol::Style markerKind,
965 Plot2d_QwtPlotPicker* picker,
969 //std::cout << "Plot2d_ViewFrame::createPlot2dCurve()" << std::endl;
971 // Mathematical curve
972 Plot2d_Curve* plot2dCurve = new Plot2d_Curve();
974 // To deallocate in EraseAll()
975 myPlot2dCurveList.append( plot2dCurve);
977 int nbPoint = xList.size();
981 for (int ip=0; ip < nbPoint; ip++)
985 tooltip = tooltipList.at(ip);
987 plot2dCurve->addPoint( xVal, yVal, tooltip);
990 plot2dCurve->setVerTitle( title);
991 plot2dCurve->setVerUnits( unit);
992 if (lineColor.isValid())
994 plot2dCurve->setColor( lineColor);
996 plot2dCurve->setLine( lineKind, lineWidth);
997 plot2dCurve->setMarkerStyle( markerKind);
998 plot2dCurve->setMarkerSize(1);
1000 // Graphical curve (QwtPlotCurve) in the drawing zone (QwtPlot) myPlot
1005 myPlot->insertLegend( (QwtLegend*)NULL);
1007 displayCurve( plot2dCurve);
1009 // Get the graphical curve
1010 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>( getPlotObject( plot2dCurve));
1014 if (lineColor.isValid())
1016 //std::cout << " valid color" << std::endl;
1017 theColor = lineColor;
1021 //std::cout << " valid color" << std::endl;
1022 QPen pen = plotCurve->pen();
1023 theColor = pen.color();
1026 // Modify points' markers
1027 QwtSymbol symbol (plotCurve->symbol()) ;
1028 symbol.setStyle( markerKind);
1030 if (markerKind != QwtSymbol::NoSymbol)
1032 symbol.setPen( QPen( theColor, lineWidth));
1033 symbol.setBrush( QBrush( theColor));
1034 QSize size = 2.0*(symbol.size()); //0.5
1035 symbol.setSize(size);
1038 plotCurve->setSymbol( symbol);
1039 plotCurve->setStyle( QwtPlotCurve::Lines);
1040 plotCurve->setPen( QPen( theColor, lineWidth));
1042 // The curve must not have legend's entry
1043 plotCurve->setItemAttribute( QwtPlotItem::Legend, false);
1052 QColor Plot2d_ViewFrame::getPlot2dCurveColor( Plot2d_Curve* plot2dCurve)
1055 // Get graphical curve
1056 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>( getPlotObject( plot2dCurve));
1058 QPen pen = plotCurve->pen();
1059 QColor color = pen.color();
1066 * Create and display a segment with nbPoint=2 points
1068 QwtPlotCurve *Plot2d_ViewFrame::createSegment( double *X, double *Y, int nbPoint,
1069 Qt::PenStyle lineKind,
1072 QwtSymbol::Style markerKind, bool side)
1074 QwtPlotCurve* aPCurve = new QwtPlotCurve();
1076 aPCurve->setData( X, Y, nbPoint);
1078 aPCurve->setPen( QPen( lineColor, lineWidth, lineKind));
1080 aSymbol.setStyle( markerKind);
1081 aPCurve->setSymbol( aSymbol);
1083 // The segment must not have legend's entry
1084 aPCurve->setItemAttribute( QwtPlotItem::Legend, false);
1086 aPCurve->attach(myPlot);
1087 aPCurve->setYAxis(side ? QwtPlot::yRight : QwtPlot::yLeft);
1088 // To deallocate in EraseAll()
1089 myIntermittentSegmentList.append(aPCurve);
1094 Adds curve into view
1096 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
1098 QwtPlotItem* anItem = displayObject( curve, update );
1099 // To deallocate in EraseAll()
1100 myQwtPlotCurveList.append( anItem);
1104 Adds curves into view
1106 void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
1109 foreach ( Plot2d_Curve* curve, curves )
1111 displayObjects( objects, update );
1117 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
1119 eraseObject( curve, update );
1125 void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
1128 foreach ( Plot2d_Curve* curve, curves )
1130 eraseObjects( objects, update );
1134 Updates curves attributes
1136 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
1138 updateObject( curve, update );
1141 void Plot2d_ViewFrame::processFiltering(bool update)
1143 CurveDict aCurves = getCurves();
1144 AlgoPlot2dInputData aLData, aRData;
1145 CurveDict::iterator it;
1146 for ( it = aCurves.begin(); it != aCurves.end(); it++ ) {
1147 Plot2d_Object* objItem = it.value();
1148 if (objItem->getYAxis() == QwtPlot::yRight)
1149 aRData.append(objItem);
1151 aLData.append(objItem);
1154 // Normalization by left Y axis
1155 if (!myNormLMin && !myNormLMax)
1156 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
1157 if(myNormLMin && myNormLMax)
1158 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
1160 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
1162 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMax);
1164 myLNormAlgo->setInput(aLData);
1165 myLNormAlgo->execute();
1167 // Normalization by right Y axis
1168 if (!myNormRMin && !myNormRMax)
1169 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
1170 if(myNormRMin && myNormRMax)
1171 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
1173 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
1175 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMax);
1177 myRNormAlgo->setInput(aRData);
1178 myRNormAlgo->execute();
1180 for ( it = aCurves.begin(); it != aCurves.end(); it++) {
1181 QwtPlotCurve* item = it.key();
1182 Plot2d_Object* objItem = it.value();
1183 updatePlotItem(objItem, item);
1190 Gets lsit of displayed curves
1192 int Plot2d_ViewFrame::getCurves( curveList& curves ) const
1196 CurveDict aCurves = getCurves();
1197 CurveDict::iterator it;
1198 for ( it = aCurves.begin(); it != aCurves.end(); it++ )
1199 curves << it.value();
1200 return curves.count();
1203 CurveDict Plot2d_ViewFrame::getCurves() const
1206 ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end();
1207 for ( ; it != aLast; it++ ) {
1208 QwtPlotItem* anItem = it.key();
1209 if ( anItem && anItem->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
1210 QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( anItem );
1211 Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( it.value() );
1212 if ( aPCurve && aCurve )
1213 curves.insert( aPCurve, aCurve );
1220 Adds object into view
1222 QwtPlotItem* Plot2d_ViewFrame::displayObject( Plot2d_Object* object, bool update )
1224 QwtPlotItem* anItem = 0;
1228 if ( object->getYAxis() == QwtPlot::yRight )
1231 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
1232 // it crashes if switched to X/Y logarithmic mode, when one or more points have
1233 // non-positive X/Y coordinate
1234 if ( myXMode && object->getMinX() <= 0. )
1235 setHorScaleMode( 0, false );
1236 if ( myYMode && object->getMinY() <= 0. )
1237 setVerScaleMode( 0, false );
1239 if ( object->isAutoAssign() )
1240 object->autoFill( myPlot );
1242 if ( hasPlotObject( object ) ) {
1243 processFiltering(update);
1244 updateObject( object, update );
1247 anItem = object->createPlotItem();
1248 anItem->attach( myPlot );
1249 myObjects.insert( anItem, object );
1250 //myPlot->setCurveYAxis(curveKey, curve->getYAxis());
1252 if ( object->rtti() == QwtPlotItem::Rtti_PlotCurve )
1254 Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( object );
1258 //aCurve->setMarkerSize( myMarkerSize );
1260 if (aCurve->getMarkerSize() == 0)
1262 aCurve->setMarkerSize( myMarkerSize );
1265 processFiltering(update);
1266 updatePlotItem( aCurve, anItem );
1267 setCurveType( getPlotCurve( aCurve ), myCurveType );
1271 updateTitles( false );
1272 myPlot->updateYAxisIdentifiers();
1275 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1281 Adds objects into view
1283 void Plot2d_ViewFrame::displayObjects( const objectList& objects, bool update )
1285 //myPlot->setUpdatesEnabled( false ); // call this function deprecate update of legend
1286 foreach ( Plot2d_Object* object, objects )
1287 displayObject( object, false );
1289 //myPlot->setUpdatesEnabled( true );
1298 void Plot2d_ViewFrame::eraseObject( Plot2d_Object* object, bool update )
1303 if ( hasPlotObject( object ) ) {
1304 QwtPlotItem* anObject = getPlotObject( object );
1305 eraseBasicObject(anObject,update);
1308 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1312 void Plot2d_ViewFrame::eraseBasicObject( QwtPlotItem *object, bool update )
1318 myObjects.remove(object);
1319 updateTitles(update);
1320 myPlot->updateYAxisIdentifiers();
1328 void Plot2d_ViewFrame::eraseObjects( const objectList& objects, bool update )
1330 foreach ( Plot2d_Object* object, objects )
1331 eraseObject( object, false );
1336 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1339 void Plot2d_ViewFrame::eraseBasicObjects( const QList<QwtPlotItem*> &objects, bool update)
1341 foreach ( QwtPlotItem* object, objects )
1342 eraseBasicObject( object, false );
1346 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1350 Updates objects attributes
1352 void Plot2d_ViewFrame::updateObject( Plot2d_Object* object, bool update )
1356 if ( hasPlotObject( object ) ) {
1357 QwtPlotItem* anItem = getPlotObject( object );
1360 updatePlotItem(object, anItem );
1361 anItem->setVisible( true );
1364 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1370 Gets lsit of displayed curves
1372 int Plot2d_ViewFrame::getObjects( objectList& objects ) const
1376 ObjectDict::const_iterator it;
1377 for ( it = myObjects.begin(); it != myObjects.end(); it++ )
1378 objects << it.value();
1379 return objects.count();
1383 Returns true if the curve is visible
1385 bool Plot2d_ViewFrame::isVisible( Plot2d_Object* object ) const
1387 return object && hasPlotObject( object ) && getPlotObject( object )->isVisible();
1393 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
1395 if ( !prs || prs->IsNull() )
1398 ObjectDict::iterator it = myObjects.begin();
1399 Plot2d_Object* anObj;
1400 for (; it != myObjects.end(); ++it ) {
1402 if ( hasPlotObject( anObj ) )
1403 getPlotObject( anObj )->setTitle( !anObj->getName().isEmpty() ?
1404 anObj->getName() : anObj->getVerTitle() );
1411 void Plot2d_ViewFrame::updateLegend() {
1412 if ( myPlot->getLegend() ) {
1413 ObjectDict::iterator it = myObjects.begin();
1414 for( ; it != myObjects.end(); ++it )
1415 it.key()->updateLegend(myPlot->getLegend());
1421 Fits the view to see all data
1423 void Plot2d_ViewFrame::fitAll()
1425 // Postpone fitAll operation until QwtPlot geometry
1426 // has been fully defined
1427 if ( !myPlot->polished() ){
1428 QApplication::postEvent( this, new QEvent( (QEvent::Type)FITALL_EVENT ) );
1432 // no need to set auto scaling, it wiil be disabled by setAxisScale() method call
1433 // myPlot->setAxisAutoScale( QwtPlot::yLeft );
1434 // myPlot->setAxisAutoScale( QwtPlot::xBottom );
1435 // myPlot->replot();
1437 double xmin, xmax, y1min, y1max, y2min, y2max;
1438 getFitRangeByCurves(xmin, xmax, y1min, y1max, y2min, y2max);
1439 getFitRangeByMarkers(xmin, xmax, y1min, y1max, y2min, y2max);
1441 myPlot->setAxisScale( QwtPlot::xBottom, xmin, xmax );
1442 myPlot->setAxisScale( QwtPlot::yLeft, y1min, y1max );
1445 myPlot->setAxisAutoScale( QwtPlot::yRight );
1447 myPlot->setAxisScale( QwtPlot::yRight, y2min, y2max );
1450 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1454 Fits the view to rectangle area (pixels)
1456 void Plot2d_ViewFrame::fitArea( const QRect& area )
1458 QRect rect = area.normalized();
1459 if ( rect.width() < MIN_RECT_SIZE ) {
1460 rect.setWidth( MIN_RECT_SIZE );
1461 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
1463 if ( rect.height() < MIN_RECT_SIZE ) {
1464 rect.setHeight( MIN_RECT_SIZE );
1465 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
1467 myPlot->setAxisScale( QwtPlot::yLeft,
1468 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
1469 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
1471 myPlot->setAxisScale( QwtPlot::yRight,
1472 myPlot->invTransform( QwtPlot::yRight, rect.top() ),
1473 myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
1474 myPlot->setAxisScale( QwtPlot::xBottom,
1475 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
1476 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
1478 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1482 "Fit Data" command for TUI interface
1484 void Plot2d_ViewFrame::fitData(const int mode,
1485 const double xMin, const double xMax,
1486 const double yMin, const double yMax,
1487 double y2Min, double y2Max)
1489 if ( mode == 0 || mode == 2 ) {
1490 myPlot->setAxisScale( QwtPlot::yLeft, yMin, yMax );
1492 myPlot->setAxisScale( QwtPlot::yRight, y2Min, y2Max );
1494 if ( mode == 0 || mode == 1 )
1495 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
1497 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1501 Gets current fit ranges for view frame
1503 void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax,
1504 double& yMin, double& yMax,
1505 double& y2Min, double& y2Max)
1507 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).transform( myPlot->canvasMap( QwtPlot::xBottom ).s1() );
1508 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).transform( myPlot->canvasMap( QwtPlot::xBottom ).s2() );
1509 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).transform( myPlot->canvasMap( QwtPlot::yLeft ).s1() );
1510 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).transform( myPlot->canvasMap( QwtPlot::yLeft ).s2() );
1511 xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
1512 xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
1513 yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
1514 yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
1518 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).transform( myPlot->canvasMap( QwtPlot::yRight ).s1() );
1519 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).transform( myPlot->canvasMap( QwtPlot::yRight ).s2() );
1520 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
1521 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
1526 Gets current fit ranges by Curves
1528 void Plot2d_ViewFrame::getFitRangeByCurves(double& xMin, double& xMax,
1529 double& yMin, double& yMax,
1530 double& y2Min, double& y2Max)
1532 bool emptyV1 = true, emptyV2 = true;
1533 if ( !myObjects.isEmpty() ) {
1534 ObjectDict::const_iterator it = myObjects.begin();
1535 for ( ; it != myObjects.end(); it++ ) {
1536 bool isV2 = it.value()->getYAxis() == QwtPlot::yRight;
1537 if ( !it.value()->isEmpty() ) {
1538 if ( emptyV1 && emptyV2 ) {
1550 isV2 ? emptyV2 = false : emptyV1 = false;
1551 xMin = qMin( xMin, it.value()->getMinX() );
1552 xMax = qMax( xMax, it.value()->getMaxX() );
1554 y2Min = qMin( y2Min, it.value()->getMinY() );
1555 y2Max = qMax( y2Max, it.value()->getMaxY() );
1558 yMin = qMin( yMin, it.value()->getMinY() );
1559 yMax = qMax( yMax, it.value()->getMaxY() );
1563 if ( xMin == xMax ) {
1564 xMin = xMin == 0. ? -1. : xMin - xMin/10.;
1565 xMax = xMax == 0. ? 1. : xMax + xMax/10.;
1567 if ( yMin == yMax ) {
1568 yMin = yMin == 0. ? -1. : yMin - yMin/10.;
1569 yMax = yMax == 0. ? 1 : yMax + yMax/10.;
1571 if ( y2Min == y2Max ) {
1572 y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
1573 y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
1577 if ( emptyV1 && emptyV2 ) {
1578 xMin = isModeHorLinear() ? 0. : 1.;
1579 xMax = isModeHorLinear() ? 1000. : 1e5;
1582 yMin = isModeVerLinear() ? 0. : 1.;
1583 yMax = isModeVerLinear() ? 1000. : 1e5;
1586 y2Min = isModeVerLinear() ? 0. : 1.;
1587 y2Max = isModeVerLinear() ? 1000. : 1e5;
1592 Gets current fit ranges by Markers
1593 All parameters are inout.
1595 void Plot2d_ViewFrame::getFitRangeByMarkers(double& xMin, double& xMax,
1596 double& yMin, double& yMax,
1597 double& y2Min, double& y2Max)
1599 Plot2d_QwtPlotPicker *picker=myPlot->getPicker();
1602 if(picker->pMarkers.empty())
1604 foreach(QwtPlotMarker *mrker,picker->pMarkers)
1606 bool isV2 = mrker->yAxis() == QwtPlot::yRight;
1607 xMin = qMin( xMin, mrker->xValue() );
1608 xMax = qMax( xMax, mrker->xValue() );
1610 y2Min = qMin( y2Min, mrker->yValue() );
1611 y2Max = qMax( y2Max, mrker->yValue() );
1614 yMin = qMin( yMin, mrker->yValue() );
1615 yMax = qMax( yMax, mrker->yValue() );
1617 if ( xMin == xMax ) {
1618 xMin = xMin == 0. ? -1. : xMin - xMin/10.;
1619 xMax = xMax == 0. ? 1. : xMax + xMax/10.;
1621 if ( yMin == yMax ) {
1622 yMin = yMin == 0. ? -1. : yMin - yMin/10.;
1623 yMax = yMax == 0. ? 1 : yMax + yMax/10.;
1625 if ( y2Min == y2Max ) {
1626 y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
1627 y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
1633 Tests if it is necessary to start operation on mouse action
1635 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
1637 int btn = me.button() | me.modifiers();
1638 const int zoomBtn = Qt::ControlModifier | Qt::LeftButton;
1639 const int panBtn = Qt::ControlModifier | Qt::MidButton;
1640 const int fitBtn = Qt::ControlModifier | Qt::RightButton;
1643 if ( btn == zoomBtn ) {
1644 QPixmap zoomPixmap (imageZoomCursor);
1645 QCursor zoomCursor (zoomPixmap);
1646 myPlot->canvas()->setCursor( zoomCursor );
1649 else if ( btn == panBtn ) {
1650 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
1653 else if ( btn == fitBtn ) {
1654 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1661 "Settings" toolbar action slot
1663 void Plot2d_ViewFrame::onSettings()
1665 #ifdef TEST_AUTOASSIGN
1666 typedef QMap<int,int> IList;
1667 typedef QMap<QString,int> SList;
1670 cols[ "red-min" ] = 1000;
1671 cols[ "red-max" ] = -1;
1672 cols[ "green-min" ] = 1000;
1673 cols[ "green-max" ] = -1;
1674 cols[ "blue-min" ] = 1000;
1675 cols[ "blue-max" ] = -1;
1676 for ( unsigned i = 0; i < 10000; i++ ) {
1677 QwtSymbol::Style typeMarker;
1679 Qt::PenStyle typeLine;
1680 myPlot->getNextMarker( typeMarker, color, typeLine );
1681 if ( mars.contains(typeMarker) )
1682 mars[ typeMarker ] = mars[ typeMarker ]+1;
1684 mars[ typeMarker ] = 0;
1685 if ( lins.contains(typeLine) )
1686 lins[ typeLine ] = lins[ typeLine ]+1;
1688 lins[ typeLine ] = 0;
1689 if ( cols[ "red-max" ] < color.red() )
1690 cols[ "red-max" ] = color.red();
1691 if ( cols[ "red-min" ] > color.red() )
1692 cols[ "red-min" ] = color.red();
1693 if ( cols[ "green-max" ] < color.green() )
1694 cols[ "green-max" ] = color.green();
1695 if ( cols[ "green-min" ] > color.green() )
1696 cols[ "green-min" ] = color.green();
1697 if ( cols[ "blue-max" ] < color.blue() )
1698 cols[ "blue-max" ] = color.blue();
1699 if ( cols[ "blue-min" ] > color.blue() )
1700 cols[ "blue-min" ] = color.blue();
1704 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
1705 dlg->setMainTitle( myTitleEnabled, myTitle );
1706 dlg->setXTitle( myXTitleEnabled, myXTitle );
1707 dlg->setYTitle( myYTitleEnabled, myYTitle );
1709 dlg->setY2Title( myY2TitleEnabled, myY2Title );
1710 dlg->setCurveType( myCurveType );
1711 dlg->setLegend( myShowLegend, myLegendPos, myLegendFont, myLegendColor );
1712 dlg->setMarkerSize( myMarkerSize );
1713 dlg->setBackgroundColor( myBackground );
1714 dlg->setScaleMode(myXMode, myYMode);
1715 dlg->setLMinNormMode(myNormLMin);
1716 dlg->setLMaxNormMode(myNormLMax);
1717 dlg->setRMinNormMode(myNormRMin);
1718 dlg->setRMaxNormMode(myNormRMax);
1720 QVariant v = myPlot->property(PLOT2D_DEVIATION_LW);
1721 int lw = v.isValid() ? v.toInt() : 1;
1723 v = myPlot->property(PLOT2D_DEVIATION_TS);
1724 int ts = v.isValid() ? v.toInt() : 2;
1726 v = myPlot->property(PLOT2D_DEVIATION_COLOR);
1727 QColor cl = v.isValid() ? v.value<QColor>() : QColor(255,0,0);
1729 dlg->setDeviationMarkerLw(lw);
1730 dlg->setDeviationMarkerTs(ts);
1731 dlg->setDeviationMarkerCl(cl);
1734 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
1735 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
1736 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
1737 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
1738 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
1739 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
1740 if ( dlg->exec() == QDialog::Accepted ) {
1741 // horizontal axis title
1742 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
1743 // vertical left axis title
1744 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
1745 if (mySecondY) // vertical right axis title
1746 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
1749 if( dlg->isMainTitleEnabled() && myTitle != dlg->getMainTitle() )
1750 myIsDefTitle = false;
1751 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
1753 if ( myCurveType != dlg->getCurveType() ) {
1754 setCurveType( dlg->getCurveType(), false );
1757 if ( myShowLegend != dlg->isLegendEnabled() ) {
1758 showLegend( dlg->isLegendEnabled(), false );
1760 if ( myLegendPos != dlg->getLegendPos() ) {
1761 setLegendPos( dlg->getLegendPos() );
1763 if ( myLegendFont != dlg->getLegendFont() ) {
1764 setLegendFont( dlg->getLegendFont() );
1766 if ( myLegendColor != dlg->getLegendColor() ) {
1767 setLegendFontColor( dlg->getLegendColor() );
1771 if ( myMarkerSize != dlg->getMarkerSize() ) {
1772 setMarkerSize( dlg->getMarkerSize(), false );
1775 if ( myBackground != dlg->getBackgroundColor() ) {
1776 setBackgroundColor( dlg->getBackgroundColor() );
1779 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
1780 aY2GridMajorEnabled, aY2GridMinorEnabled;
1781 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
1782 aY2GridMaxMajor, aY2GridMaxMinor;
1783 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
1784 aY2GridMajorEnabled, aY2GridMaxMajor);
1785 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
1786 aY2GridMinorEnabled, aY2GridMaxMinor);
1787 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
1788 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
1789 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
1790 if ( myXMode != dlg->getXScaleMode() ) {
1791 setHorScaleMode( dlg->getXScaleMode() );
1793 if ( myYMode != dlg->getYScaleMode() ) {
1794 setVerScaleMode( dlg->getYScaleMode() );
1796 if ( myNormLMin != dlg->getLMinNormMode() ) {
1797 setNormLMinMode( dlg->getLMinNormMode() );
1799 if ( myNormLMax != dlg->getLMaxNormMode() ) {
1800 setNormLMaxMode( dlg->getLMaxNormMode() );
1802 if ( myNormRMin != dlg->getRMinNormMode() ) {
1803 setNormRMinMode( dlg->getRMinNormMode() );
1805 if ( myNormRMax != dlg->getRMaxNormMode() ) {
1806 setNormRMaxMode( dlg->getRMaxNormMode() );
1809 myPlot->setProperty(PLOT2D_DEVIATION_COLOR,
1810 dlg->getDeviationMarkerCl());
1811 myPlot->setProperty(PLOT2D_DEVIATION_LW,
1812 dlg->getDeviationMarkerLw());
1813 myPlot->setProperty(PLOT2D_DEVIATION_TS,
1814 dlg->getDeviationMarkerTs());
1819 // update preferences
1820 if ( dlg->isSetAsDefault() )
1826 #ifndef NO_ANALYTICAL_CURVES
1828 "Analytical Curves" toolbar action slot
1830 void Plot2d_ViewFrame::onAnalyticalCurve()
1832 #ifndef DISABLE_PYCONSOLE
1833 Plot2d_AnalyticalCurveDlg dlg( this, this );
1835 updateAnalyticalCurves();
1839 void Plot2d_ViewFrame::addAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
1841 #ifndef DISABLE_PYCONSOLE
1842 myAnalyticalCurves.append(theCurve);
1846 void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
1848 #ifndef DISABLE_PYCONSOLE
1849 theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
1854 Update Analytical curve
1856 void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool updateView)
1858 #ifndef DISABLE_PYCONSOLE
1860 QwtScaleDiv* div = myPlot->axisScaleDiv(QwtPlot::xBottom);
1861 c->setRangeBegin(div->lowerBound());
1862 c->setRangeEnd(div->upperBound());
1864 c->setMarkerSize(myMarkerSize);
1865 QwtPlotItem* item = c->plotItem();
1867 switch( c->getAction() ) {
1868 case Plot2d_AnalyticalCurve::ActAddInView:
1869 if( c->isActive() ) {
1870 c->updatePlotItem();
1871 item->attach( myPlot );
1874 c->setAction(Plot2d_AnalyticalCurve::ActNothing);
1877 case Plot2d_AnalyticalCurve::ActUpdateInView:
1879 c->updatePlotItem();
1886 c->setAction(Plot2d_AnalyticalCurve::ActNothing);
1888 case Plot2d_AnalyticalCurve::ActRemoveFromView:
1891 myAnalyticalCurves.removeAll(c);
1902 Update Analytical curves
1904 void Plot2d_ViewFrame::updateAnalyticalCurves()
1906 #ifndef DISABLE_PYCONSOLE
1907 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
1908 for( ; it != myAnalyticalCurves.end(); it++) {
1909 updateAnalyticalCurve(*it);
1916 Return list of the alalytical curves.
1918 AnalyticalCurveList Plot2d_ViewFrame::getAnalyticalCurves() const
1920 return myAnalyticalCurves;
1924 Get analytical curve by plot item.
1926 Plot2d_AnalyticalCurve* Plot2d_ViewFrame::getAnalyticalCurve(QwtPlotItem * theItem) {
1927 #ifndef DISABLE_PYCONSOLE
1928 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
1929 for( ; it != myAnalyticalCurves.end(); it++) {
1930 if((*it)->plotItem() == theItem);
1939 "Fit Data" command slot
1941 void Plot2d_ViewFrame::onFitData()
1943 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
1944 double xMin,xMax,yMin,yMax,y2Min,y2Max;
1945 getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
1947 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1948 if ( dlg->exec() == QDialog::Accepted ) {
1949 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1950 fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max);
1953 #ifndef NO_ANALYTICAL_CURVES
1954 updateAnalyticalCurves();
1959 Change background color
1961 void Plot2d_ViewFrame::onChangeBackground()
1963 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1964 if ( selColor.isValid() ) {
1965 setBackgroundColor( selColor );
1972 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1974 myCurveType = curveType;
1975 CurveDict aCurves = getCurves();
1976 CurveDict::iterator it = aCurves.begin();
1977 for ( ; it != aCurves.end(); it++ ) {
1978 QwtPlotCurve* crv = it.key();
1980 setCurveType( crv, myCurveType );
1984 emit vpCurveChanged();
1990 int Plot2d_ViewFrame::getCurveType() const
1997 \param curveKey - curve id
1998 \param title - new title
2000 void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title )
2002 setObjectTitle( curve, title );
2007 \param object - object id
2008 \param title - new title
2010 void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title )
2012 if ( object && hasPlotObject( object ) )
2013 getPlotObject( object )->setTitle( title );
2019 void Plot2d_ViewFrame::showLegend( bool show, bool update )
2021 myShowLegend = show;
2022 if ( myShowLegend ) {
2023 QwtLegend* legend = myPlot->legend();
2025 legend = new QwtLegend( myPlot );
2026 legend->setFrameStyle( QFrame::Box | QFrame::Sunken );
2028 legend->setItemMode( QwtLegend::ClickableItem );
2029 myPlot->insertLegend( legend );
2030 setLegendPos( myLegendPos );
2031 setLegendFont( myLegendFont );
2032 setLegendFontColor( myLegendColor );
2035 myPlot->insertLegend( 0 );
2041 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
2043 void Plot2d_ViewFrame::setLegendPos( int pos )
2046 QwtLegend* legend = myPlot->legend();
2050 myPlot->insertLegend( legend, QwtPlot::LeftLegend );
2053 myPlot->insertLegend( legend, QwtPlot::RightLegend );
2056 myPlot->insertLegend( legend, QwtPlot::TopLegend );
2059 myPlot->insertLegend( legend, QwtPlot::BottomLegend );
2066 Gets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
2068 int Plot2d_ViewFrame::getLegendPos() const
2076 void Plot2d_ViewFrame::setLegendFont( const QFont& fnt )
2079 QwtLegend* legend = myPlot->legend();
2081 legend->setFont(fnt);
2088 QFont Plot2d_ViewFrame::getLegendFont() const
2090 return myLegendFont;
2094 Gets legend font color
2096 QColor Plot2d_ViewFrame::getLegendFontColor() const
2098 return myLegendColor;
2102 Sets legend font color
2104 void Plot2d_ViewFrame::setLegendFontColor( const QColor& col )
2106 myLegendColor = col;
2107 QwtLegend* legend = myPlot->legend();
2109 QPalette pal = legend->palette();
2110 pal.setColor( QPalette::Text, col );
2111 legend->setPalette( pal );
2116 Sets new marker size
2118 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
2120 if ( myMarkerSize != size )
2122 myMarkerSize = size;
2123 CurveDict aCurves = getCurves();
2124 CurveDict::iterator it = aCurves.begin();
2125 for ( ; it != aCurves.end(); it++ ) {
2126 QwtPlotCurve* crv = it.key();
2129 QwtSymbol aSymbol = crv->symbol();
2130 aSymbol.setSize( myMarkerSize, myMarkerSize );
2131 crv->setSymbol( aSymbol );
2133 it.value()->setMarkerSize( myMarkerSize );
2142 Gets new marker size
2144 int Plot2d_ViewFrame::getMarkerSize() const
2146 return myMarkerSize;
2150 Sets background color
2152 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
2154 myBackground = color;
2155 myPlot->canvas()->setPalette( myBackground );
2156 myPlot->setPalette( myBackground );
2157 if ( myPlot->getLegend() ) {
2158 QPalette aPal = myPlot->getLegend()->palette();
2159 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
2160 aPal.setColor( QPalette::Base, myBackground );
2161 aPal.setColor( QPalette::Background, myBackground );
2163 myPlot->getLegend()->setPalette( aPal );
2169 Gets background color
2171 QColor Plot2d_ViewFrame::backgroundColor() const
2173 return myBackground;
2176 Sets hor.axis grid parameters
2178 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
2179 bool xMinorEnabled, const int xMinorMax,
2182 myXGridMajorEnabled = xMajorEnabled;
2183 myXGridMinorEnabled = xMinorEnabled;
2184 myXGridMaxMajor = xMajorMax;
2185 myXGridMaxMinor = xMinorMax;
2187 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
2188 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
2190 QwtPlotGrid* grid = myPlot->grid();
2191 if ( myPlot->axisScaleDiv( QwtPlot::xBottom ) )
2192 grid->setXDiv( *myPlot->axisScaleDiv( QwtPlot::xBottom ) );
2193 grid->enableX( myXGridMajorEnabled );
2194 grid->enableXMin( myXGridMinorEnabled );
2200 Sets ver.axis grid parameters
2202 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
2203 bool yMinorEnabled, const int yMinorMax,
2204 bool y2MajorEnabled, const int y2MajorMax,
2205 bool y2MinorEnabled, const int y2MinorMax,
2208 myYGridMajorEnabled = yMajorEnabled;
2209 myYGridMinorEnabled = yMinorEnabled;
2210 myYGridMaxMajor = yMajorMax;
2211 myYGridMaxMinor = yMinorMax;
2214 myY2GridMajorEnabled = y2MajorEnabled;
2215 myY2GridMinorEnabled = y2MinorEnabled;
2216 myY2GridMaxMajor = y2MajorMax;
2217 myY2GridMaxMinor = y2MinorMax;
2219 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
2220 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
2223 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
2224 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
2227 QwtPlotGrid* grid = myPlot->grid();
2228 if ( myPlot->axisScaleDiv( QwtPlot::yLeft ) )
2229 grid->setYDiv( *myPlot->axisScaleDiv( QwtPlot::yLeft ) );
2232 if (myYGridMajorEnabled) {
2233 grid->enableY( myYGridMajorEnabled );
2234 grid->enableYMin( myYGridMinorEnabled );
2236 else if (myY2GridMajorEnabled) {
2237 if ( myPlot->axisScaleDiv( QwtPlot::yRight ) )
2238 grid->setYDiv( *myPlot->axisScaleDiv( QwtPlot::yRight ) );
2239 grid->enableY( myY2GridMajorEnabled );
2240 grid->enableYMin( myY2GridMinorEnabled );
2243 grid->enableY( false );
2244 grid->enableYMin( false );
2248 grid->enableY( myYGridMajorEnabled );
2249 grid->enableYMin( myYGridMinorEnabled );
2256 Sets title for some axis
2258 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
2259 ObjectType type, bool update )
2263 myTitleEnabled = enabled;
2265 myPlot->setTitle( myTitleEnabled ? myTitle : QString() );
2268 myXTitleEnabled = enabled;
2270 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString() );
2273 myYTitleEnabled = enabled;
2275 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString() );
2278 myY2TitleEnabled = enabled;
2280 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString() );
2289 Sets title for some axis
2291 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
2296 title = myTitle; break;
2298 title = myXTitle; break;
2300 title = myYTitle; break;
2302 title = myY2Title; break;
2309 Sets font for Plot2d object : title or axis
2311 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
2315 myPlot->title().setFont(font);
2318 myPlot->axisTitle(QwtPlot::xBottom).setFont(font); break;
2320 myPlot->axisTitle(QwtPlot::yLeft).setFont(font); break;
2322 myPlot->axisTitle(QwtPlot::yRight).setFont(font); break;
2324 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
2326 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
2328 myPlot->setAxisFont(QwtPlot::yRight, font); break;
2335 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
2337 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
2339 if ( myXMode == mode )
2342 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
2343 // it crashes if switched to X/Y logarithmic mode, when one or more points have
2344 // non-positive X/Y coordinate
2345 if ( mode && !isXLogEnabled() ){
2347 SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
2349 QMessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
2356 myPlot->setLogScale(QwtPlot::xBottom, myXMode != 0);
2360 emit vpModeHorChanged();
2364 Gets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
2366 int Plot2d_ViewFrame::getHorScaleMode() const
2372 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
2374 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
2376 if ( myYMode == mode )
2379 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
2380 // it crashes if switched to X/Y logarithmic mode, when one or more points have
2381 // non-positive X/Y coordinate
2382 if ( mode && !isYLogEnabled() ){
2384 SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
2386 QMessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
2392 myPlot->setLogScale(QwtPlot::yLeft, myYMode != 0);
2394 myPlot->setLogScale( QwtPlot::yRight, myYMode != 0 );
2398 emit vpModeVerChanged();
2402 Gets scale mode for vertical axis: 0 - linear, 1 - logarithmic
2404 int Plot2d_ViewFrame::getVerScaleMode() const
2410 Sets normalization mode to the global maximum by left Y axis
2412 void Plot2d_ViewFrame::setNormLMaxMode( bool mode, bool update )
2414 if ( myNormLMax == mode )
2418 processFiltering(true);
2421 emit vpNormLModeChanged();
2425 Gets normalization mode to the global maximum by left Y axis
2427 bool Plot2d_ViewFrame::getNormLMaxMode() const
2433 Sets normalization mode to the global minimum by left Y axis
2435 void Plot2d_ViewFrame::setNormLMinMode( bool mode, bool update )
2437 if ( myNormLMin == mode )
2441 processFiltering(true);
2444 emit vpNormLModeChanged();
2448 Gets normalization mode to the global minimum by left Y axis
2450 bool Plot2d_ViewFrame::getNormLMinMode() const
2456 Sets normalization mode to the global maximum by right Y axis
2458 void Plot2d_ViewFrame::setNormRMaxMode( bool mode, bool update )
2460 if ( myNormRMax == mode )
2464 processFiltering(true);
2467 emit vpNormRModeChanged();
2471 Gets normalization mode to the global maximum by right Y axis
2473 bool Plot2d_ViewFrame::getNormRMaxMode() const
2479 Sets normalization mode to the global minimum by right Y axis
2481 void Plot2d_ViewFrame::setNormRMinMode( bool mode, bool update )
2483 if ( myNormRMin == mode )
2487 processFiltering(true);
2490 emit vpNormRModeChanged();
2494 Gets normalization mode to the global minimum by right Y axis
2496 bool Plot2d_ViewFrame::getNormRMinMode() const
2502 Return, scale mode for horizontal axis
2504 bool Plot2d_ViewFrame::isModeHorLinear()
2506 return (myXMode == 0 ? true : false);
2510 Return, scale mode for vertical axis
2512 bool Plot2d_ViewFrame::isModeVerLinear()
2514 return (myYMode == 0 ? true : false);
2518 Return \c True if curves are normalize to the global maximum by left Y axis
2520 bool Plot2d_ViewFrame::isNormLMaxMode()
2522 return (myNormLMax ? true : false);
2526 Return \c True if curves are normalize to the global minimum by left Y axis
2528 bool Plot2d_ViewFrame::isNormLMinMode()
2530 return (myNormLMin ? true : false);
2534 Return \c True if curves are normalize to the global maximum by right Y axis
2536 bool Plot2d_ViewFrame::isNormRMaxMode()
2538 return (myNormRMax ? true : false);
2542 Return \c True if curves are normalize to the global minimum by right Y axis
2544 bool Plot2d_ViewFrame::isNormRMinMode()
2546 return (myNormRMin ? true : false);
2550 Return \c True if legend is shown
2552 bool Plot2d_ViewFrame::isLegendShow() const
2554 return myShowLegend;
2558 Slot, called when user presses mouse button
2560 void Plot2d_ViewFrame::plotMousePressed( const QMouseEvent& me )
2563 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2565 aParent->putInfo(getInfo(me.pos()));
2567 if ( myOperation == NoOpId )
2568 myOperation = testOperation( me );
2569 if ( myOperation != NoOpId ) {
2571 if ( myOperation == GlPanId ) {
2572 myPlot->setAxisScale( QwtPlot::yLeft,
2573 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2,
2574 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2 );
2575 myPlot->setAxisScale( QwtPlot::xBottom,
2576 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
2577 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
2579 myPlot->setAxisScale( QwtPlot::yRight,
2580 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2,
2581 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2 );
2586 int btn = me.button() | me.modifiers();
2587 if (btn == Qt::RightButton) {
2588 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
2589 me.pos(), me.button(), me.buttons(), me.modifiers() );
2590 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
2591 parent()->eventFilter(this, aEvent);
2597 Slot, called when user moves mouse
2599 bool Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
2601 int dx = me.pos().x() - myPnt.x();
2602 int dy = me.pos().y() - myPnt.y();
2605 if ( myOperation != NoOpId) {
2606 if ( myOperation == ZoomId ) {
2607 this->incrementalZoom( dx, dy );
2611 else if ( myOperation == PanId ) {
2612 this->incrementalPan( dx, dy );
2619 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2621 aParent->putInfo(getInfo(me.pos()));
2627 Slot, called when user releases mouse
2629 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
2631 if ( myOperation == NoOpId && me.button() == Qt::RightButton && me.modifiers() != Qt::ControlModifier )
2633 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
2634 me.pos(), me.globalPos() );
2635 emit contextMenuRequested( &aEvent );
2638 #ifndef NO_ANALYTICAL_CURVES
2639 updateAnalyticalCurves();
2642 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
2643 myPlot->defaultPicker();
2646 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2648 aParent->putInfo(tr("INF_READY"));
2650 myOperation = NoOpId;
2653 Slot, called when user wheeling mouse
2655 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
2657 QwtPlotLayout* pl = myPlot->plotLayout();
2659 // compute zooming factor
2660 double aDelta = event->delta();
2661 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
2663 bool scaleXBottom = pl->scaleRect(QwtPlot::xBottom).contains( event->pos() ) ||
2664 pl->canvasRect().contains( event->pos() );
2665 bool scaleYLeft = pl->scaleRect(QwtPlot::yLeft).contains( event->pos() ) ||
2666 pl->canvasRect().contains( event->pos() );
2667 bool scaleYRight = mySecondY && ( pl->scaleRect(QwtPlot::yRight).contains( event->pos() ) ||
2668 pl->canvasRect().contains( event->pos() ) );
2670 // scale x bottom axis
2671 if ( scaleXBottom ) {
2672 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
2673 if ( xMap.s2() - xMap.s1() > 1.0e-12 || aScale > 1 )
2674 myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s1() + aScale*(xMap.s2() - xMap.s1()) );
2677 // scale y left axis
2679 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
2680 if ( yMap.s2() - yMap.s1() > 1.0e-12 || aScale > 1 )
2681 myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
2684 // scale y right axis (note: mySecondY value is checked above)
2685 if ( scaleYRight ) {
2686 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yRight );
2687 if ( yMap.s2() - yMap.s1() > 10e-12 || aScale > 1 )
2688 myPlot->setAxisScale( QwtPlot::yRight, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
2694 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
2695 // store current mouse position
2696 myPnt = event->pos();
2697 #ifndef NO_ANALYTICAL_CURVES
2698 // update analytical curves
2699 updateAnalyticalCurves();
2704 Returns qwt plot curve if it is existed in map of curves and 0 otherwise
2706 QwtPlotCurve* Plot2d_ViewFrame::getPlotCurve( Plot2d_Curve* curve ) const
2708 return dynamic_cast<QwtPlotCurve*>( getPlotObject( curve ) );
2711 Returns true if qwt plot curve is existed in map of curves and false otherwise
2713 bool Plot2d_ViewFrame::hasPlotCurve( Plot2d_Curve* curve ) const
2715 return hasPlotObject( curve );
2719 Returns qwt plot curve if it is existed in map of curves and 0 otherwise
2721 QwtPlotItem* Plot2d_ViewFrame::getPlotObject( Plot2d_Object* object ) const
2723 ObjectDict::const_iterator it = myObjects.begin();
2724 for ( ; it != myObjects.end(); it++ ) {
2725 if ( it.value() == object )
2731 Returns true if qwt plot curve is existed in map of curves and false otherwise
2733 bool Plot2d_ViewFrame::hasPlotObject( Plot2d_Object* object ) const
2735 ObjectDict::const_iterator it = myObjects.begin();
2736 for ( ; it != myObjects.end(); it++ ) {
2737 if ( it.value() == object )
2746 void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int curveType )
2750 if ( myCurveType == 0 )
2751 curve->setStyle( QwtPlotCurve::Dots );//QwtCurve::NoCurve
2752 else if ( myCurveType == 1 ) {
2753 curve->setStyle( QwtPlotCurve::Lines );
2754 curve->setCurveAttribute( QwtPlotCurve::Fitted, false );
2756 else if ( myCurveType == 2 ) {
2757 curve->setStyle( QwtPlotCurve::Lines );
2758 QwtSplineCurveFitter* fitter = new QwtSplineCurveFitter();
2759 fitter->setSplineSize( 250 );
2760 curve->setCurveAttribute( QwtPlotCurve::Fitted, true );
2761 curve->setCurveFitter( fitter );
2766 View operations : Pan view
2768 void Plot2d_ViewFrame::onViewPan()
2770 // reset the previous operation
2771 myPlot->defaultPicker();
2773 QCursor panCursor (Qt::SizeAllCursor);
2774 myPlot->canvas()->setCursor( panCursor );
2775 myOperation = PanId;
2778 View operations : Zoom view
2780 void Plot2d_ViewFrame::onViewZoom()
2782 // reset the previous operation
2783 myPlot->defaultPicker();
2785 QPixmap zoomPixmap (imageZoomCursor);
2786 QCursor zoomCursor (zoomPixmap);
2787 myPlot->canvas()->setCursor( zoomCursor );
2788 myOperation = ZoomId;
2791 View operations : Fit All
2793 void Plot2d_ViewFrame::onViewFitAll()
2797 // reset the previous operation
2798 myPlot->defaultPicker();
2799 myPlot->canvas()->setCursor( QCursor(Qt::CrossCursor) );
2800 myOperation = NoOpId;
2803 View operations : Fit Area
2805 void Plot2d_ViewFrame::onViewFitArea()
2807 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
2808 myOperation = FitAreaId;
2809 myPlot->setPickerMousePattern( Qt::LeftButton );
2812 View operations : Global panning
2814 void Plot2d_ViewFrame::onViewGlobalPan()
2816 // reset the previous operation
2817 myPlot->defaultPicker();
2819 QPixmap globalPanPixmap (imageCrossCursor);
2820 QCursor glPanCursor (globalPanPixmap);
2821 myPlot->canvas()->setCursor( glPanCursor );
2822 myPlot->setLogScale(QwtPlot::xBottom, false);
2823 myPlot->setLogScale(QwtPlot::yLeft, false);
2825 myPlot->setLogScale(QwtPlot::yRight, false);
2827 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
2828 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
2830 myXDistance = xMap.s2() - xMap.s1();
2831 myYDistance = yMap.s2() - yMap.s1();
2834 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
2835 myYDistance2 = yMap2.s2() - yMap2.s1();
2837 // don't make fit all
2839 myOperation = GlPanId;
2843 Precaution for logarithmic X scale
2845 bool Plot2d_ViewFrame::isXLogEnabled() const
2847 bool allPositive = true;
2848 ObjectDict::const_iterator it = myObjects.begin();
2849 for ( ; allPositive && it != myObjects.end(); it++ )
2850 allPositive = ( it.value()->getMinX() > 0. );
2855 Precaution for logarithmic Y scale
2857 bool Plot2d_ViewFrame::isYLogEnabled() const
2859 bool allPositive = true;
2860 ObjectDict::const_iterator it = myObjects.begin();
2861 for ( ; allPositive && it != myObjects.end(); it++ )
2862 allPositive = ( it.value()->getMinY() > 0. );
2869 void Plot2d_ViewFrame::setEnableAxis( QwtPlot::Axis theAxis, bool isEnable )
2871 if ( myPlot->axisEnabled( theAxis ) == isEnable )
2873 myPlot->enableAxis( theAxis, isEnable );
2874 if ( theAxis == QwtPlot::yRight )
2875 mySecondY = isEnable;
2878 class Plot2d_QwtPlotZoomer : public QwtPlotZoomer
2881 Plot2d_QwtPlotZoomer( int xAxis, int yAxis, QwtPlotCanvas* canvas )
2882 : QwtPlotZoomer( xAxis, yAxis, canvas )
2884 qApp->installEventFilter( this );
2885 // now picker working after only a button pick.
2886 // after click on button FitArea in toolbar of the ViewFrame.
2888 ~Plot2d_QwtPlotZoomer() {};
2894 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
2895 : QwtPlot( parent ),
2896 myIsPolished( false ),
2899 // Create alternative scales
2900 setAxisScaleDraw( QwtPlot::yLeft, new Plot2d_ScaleDraw() );
2901 setAxisScaleDraw( QwtPlot::xBottom, new Plot2d_ScaleDraw() );
2902 setAxisScaleDraw( QwtPlot::yRight, new Plot2d_ScaleDraw() );
2904 myPlotZoomer = new Plot2d_QwtPlotZoomer( QwtPlot::xBottom, QwtPlot::yLeft, canvas() );
2905 myPlotZoomer->setSelectionFlags( QwtPicker::DragSelection | QwtPicker::CornerToCorner );
2906 myPlotZoomer->setTrackerMode( QwtPicker::AlwaysOff );
2907 myPlotZoomer->setRubberBand( QwtPicker::RectRubberBand );
2908 myPlotZoomer->setRubberBandPen( QColor( Qt::green ) );
2912 // auto scaling by default
2913 setAxisAutoScale( QwtPlot::yLeft );
2914 setAxisAutoScale( QwtPlot::yRight );
2915 setAxisAutoScale( QwtPlot::xBottom );
2919 myGrid = new QwtPlotGrid();
2920 QPen aMajPen = myGrid->majPen();
2921 aMajPen.setStyle( Qt::DashLine );
2922 myGrid->setPen( aMajPen );
2924 myGrid->enableX( false );
2925 myGrid->enableXMin( false );
2926 myGrid->enableY( false );
2927 myGrid->enableYMin( false );
2929 myGrid->attach( this );
2931 setMouseTracking( false );
2932 canvas()->setMouseTracking( true );
2934 myPlotZoomer->setEnabled( true );
2935 myPlotZoomer->setZoomBase();
2937 setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
2940 Plot2d_Plot2d::~Plot2d_Plot2d()
2945 \set axis scale engine - linear or log10
2947 void Plot2d_Plot2d::setLogScale( int axisId, bool log10 )
2950 setAxisScaleEngine( axisId, new QwtLog10ScaleEngine() );
2952 setAxisScaleEngine( axisId, new QwtLinearScaleEngine() );
2956 Recalculates and redraws Plot 2d view
2958 void Plot2d_Plot2d::replot()
2960 // the following code is intended to enable only axes
2961 // that are really used by displayed objects
2962 bool enableXBottom = false, enableXTop = false;
2963 bool enableYLeft = false, enableYRight = false;
2964 const QwtPlotItemList& items = itemList();
2965 QwtPlotItemIterator it;
2966 for ( it = items.begin(); it != items.end(); it++ ) {
2967 QwtPlotItem* item = *it;
2969 enableXBottom |= item->xAxis() == QwtPlot::xBottom;
2970 enableXTop |= item->xAxis() == QwtPlot::xTop;
2971 enableYLeft |= item->yAxis() == QwtPlot::yLeft;
2972 enableYRight |= item->yAxis() == QwtPlot::yRight;
2975 enableAxis( QwtPlot::xBottom, enableXBottom );
2976 enableAxis( QwtPlot::xTop, enableXTop );
2977 enableAxis( QwtPlot::yLeft, enableYLeft );
2978 enableAxis( QwtPlot::yRight, enableYRight );
2980 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
2987 QwtLegend* Plot2d_Plot2d::getLegend()
2989 #if QWT_VERSION < 0x040200
2992 return legend(); /* mpv: porting to the Qwt 4.2.0 */
2997 \return the recommended size for the widget
2999 QSize Plot2d_Plot2d::sizeHint() const
3001 return QwtPlot::minimumSizeHint();
3005 return minimum size for qwt plot
3007 QSize Plot2d_Plot2d::minimumSizeHint() const
3009 return QSize( 0, 0 );
3010 // QSize aSize = QwtPlot::minimumSizeHint();
3011 // return QSize(aSize.width()*3/4, aSize.height());
3014 void Plot2d_Plot2d::defaultPicker()
3016 myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1,
3017 Qt::RightButton, Qt::ControlModifier ); // zooming button
3018 for ( int i = QwtEventPattern::MouseSelect2; i < QwtEventPattern::MouseSelect6; i++ )
3019 myPlotZoomer->setMousePattern( i, Qt::NoButton, Qt::NoButton );
3022 void Plot2d_Plot2d::setPickerMousePattern( int button, int state )
3024 myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, button, state );
3028 * Set the point picker associated with a graphic view
3030 void Plot2d_Plot2d::setPicker( Plot2d_QwtPlotPicker *picker)
3036 * Create marker and tooltip associed with a point
3038 QwtPlotMarker* Plot2d_Plot2d::createMarkerAndTooltip( QwtSymbol symbol,
3042 Plot2d_QwtPlotPicker *picker)
3044 QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
3046 aPlotMarker->setSymbol( symbol ); // symbol must have a color
3047 aPlotMarker->setLabelAlignment( Qt::AlignTop);
3048 aPlotMarker->setXValue(X);
3049 aPlotMarker->setYValue(Y);
3051 aPlotMarker->attach(this);
3053 // Associate a tooltip with the point's marker
3054 // PB: how to obtain a tooltip with a rectangular frame ?
3055 //QwtText tooltip ("X=" + QString::number(X) + " Y=" + QString::number(Y) );
3057 QwtText text (tooltip);
3058 //QColor tooltipColor( 245, 222, 179); // Wheat -RGB (0 a 255)
3059 QColor tooltipColor( 253, 245, 230); // OldLace
3060 text.setBackgroundBrush( QBrush(tooltipColor)); //, Qt::SolidPattern));
3063 picker->pMarkers.append( aPlotMarker);
3064 picker->pMarkersToolTip[ aPlotMarker] = text;
3069 bool Plot2d_Plot2d::polished() const
3071 return myIsPolished;
3074 QwtPlotGrid* Plot2d_Plot2d::grid() const
3079 QwtPlotZoomer* Plot2d_Plot2d::zoomer() const
3081 return myPlotZoomer;
3085 Slot: checks the current labels format and change it if needed
3087 void Plot2d_Plot2d::onScaleDivChanged()
3089 QwtScaleWidget* aSW = 0;
3090 if ( ( aSW = dynamic_cast<QwtScaleWidget*>(sender()) ) ) {
3092 switch ( aSW->alignment() ) {
3093 case QwtScaleDraw::BottomScale:
3094 axisId = QwtPlot::xBottom;
3096 case QwtScaleDraw::LeftScale:
3097 axisId = QwtPlot::yLeft;
3099 case QwtScaleDraw::RightScale:
3100 axisId = QwtPlot::yRight;
3106 if ( axisId >= 0 ) {
3107 QwtScaleMap map = canvasMap(axisId);
3108 double aDist = fabs(map.s2()-map.s1()) / (axisMaxMajor(axisId)*axisMaxMinor(axisId));
3111 aDistStr.sprintf("%e",aDist);
3112 int aPrecision = aDistStr.right(aDistStr.length()-aDistStr.indexOf('e')-2).toInt();
3114 QwtScaleDraw* aQwtSD = axisScaleDraw(axisId);
3115 Plot2d_ScaleDraw* aPlot2dSD = dynamic_cast<Plot2d_ScaleDraw*>(aQwtSD);
3116 if ( ( !aPlot2dSD && aPrecision > 6 ) || ( aPlot2dSD && aPlot2dSD->precision() != aPrecision ) )
3117 setAxisScaleDraw( axisId, new Plot2d_ScaleDraw(*aQwtSD, 'f', aPrecision) );
3123 Updates identifiers of Y axis type in the legend.
3125 void Plot2d_Plot2d::updateYAxisIdentifiers()
3127 bool enableYLeft = false, enableYRight = false;
3128 const QwtPlotItemList& items = itemList();
3129 QwtPlotItemIterator it;
3130 for ( it = items.begin(); it != items.end(); it++ ) {
3131 QwtPlotItem* item = *it;
3133 enableYLeft |= item->yAxis() == QwtPlot::yLeft;
3134 enableYRight |= item->yAxis() == QwtPlot::yRight;
3138 // if several curves are attached to different axes
3139 // display corresponding identifiers in the legend,
3140 // otherwise hide them
3141 for ( it = items.begin(); it != items.end(); it++ ) {
3142 QwtPlotItem* item = *it;
3143 if ( Plot2d_QwtPlotCurve* aPCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( item ) )
3144 aPCurve->setYAxisIdentifierEnabled( enableYLeft && enableYRight );
3145 if ( item && item->isVisible() && legend() )
3146 item->updateLegend( legend() );
3151 Sets the flag saying that QwtPlot geometry has been fully defined.
3153 void Plot2d_Plot2d::polish()
3156 myIsPolished = true;
3159 // Methods to manage axis graduations
3161 /* Create definition and graduations of axes
3163 void Plot2d_Plot2d::createAxisScaleDraw()
3165 myScaleDraw = new Plot2d_AxisScaleDraw( this);
3169 /* Stock X axis's ticks in the drawing zone
3171 void Plot2d_Plot2d::applyTicks()
3173 myScaleDraw->applyTicks();
3177 /* Unactivate automatic ticks drawing (call to method Plot2d_AxisScaleDraw::draw() )
3179 * - number call to ticks drawing (for information) : numcall
3181 void Plot2d_Plot2d::unactivAxisScaleDraw( int numcall)
3183 // Memorize X axis (myScaleDraw already exists) in the drawing zone
3184 //setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
3186 myScaleDraw->unactivTicksDrawing( numcall);
3190 /* Draw ticks and labels on X axis of the drawing zone
3191 * Draw systems' names under the X axis of the drawing zone
3192 * Draw vertical segments between X axis's intervals of the systems
3194 * - left and right margins for ticks : XLeftMargin, XRightMargin
3195 * - for each named system :
3196 * positions and labels for ticks on X axis : devicesPosLabelTicks
3198 * The true drawings will be realized by the method Plot2d_AxisScaleDraw::draw()
3201 void Plot2d_Plot2d::displayXTicksAndLabels(
3202 double XLeftMargin, double XRightMargin,
3203 const QList< QPair< QString, QMap<double, QString> > > & devicesPosLabelTicks)
3204 // name position label
3207 //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
3209 int nbDevices = devicesPosLabelTicks.size();
3211 //std::cout << " Nombre de systemes = " << nbDevices << std::endl;
3212 if (nbDevices == 0) return;
3214 // For drawing systems' names, their positions must be in the allTicks list
3215 // (cf class Plot2d_AxisScaleDraw)
3217 // Liste of ticks' positions and systems' names
3218 QList<double> allTicks;
3220 double devXmin, devXmax; // X interval of a system
3221 double gapXmin, gapXmax; // X interval between two systems
3222 double devLabPos; // Label's position of a system
3223 double segmentPos; // Position of the vertical segment between current system and the next
3225 // 1)- Search for the system whose X interval is the most to the left
3228 double XminMin = 1.e+12;
3232 for (int idev=0; idev < nbDevices; idev++)
3234 QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
3236 QString deviceLabel = paire.first;
3238 // Ticks' map of the system
3239 QMap<double,QString> devPosLabelTicks = paire.second;
3241 QList<double> posTicks = devPosLabelTicks.keys();
3243 // List's items increasing sorting
3244 qSort( posTicks.begin(), posTicks.end() ); // iterators
3246 // X interval for the system
3247 devXmin = posTicks.first();
3248 devXmax = posTicks.last();
3250 if (devXmin < XminMin)
3258 // 2)- Ticks, systems' names, verticals segments
3260 for (int idev=0; idev < nbDevices; idev++)
3262 QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
3264 QString deviceLabel = paire.first;
3266 std::string std_label = deviceLabel.toStdString();
3267 //const char *c_label = std_label.c_str();
3268 //std::cout << " deviceLabel: |" << c_label << "|" << std::endl;
3270 // Ticks' map of the system
3271 QMap<double,QString> devPosLabelTicks = paire.second;
3273 int nbTicks = devPosLabelTicks.size();
3275 QList<double> posTicks = devPosLabelTicks.keys();
3277 // List's items increasing sorting
3278 qSort( posTicks.begin(), posTicks.end() ); // iterators
3280 // X interval for the system
3281 devXmin = posTicks.first();
3282 devXmax = posTicks.last();
3284 // Stock ticks' positions and labels on X axis
3288 for (int itic=0; itic < nbTicks; itic++)
3290 pos = posTicks.at(itic);
3291 label = devPosLabelTicks[pos];
3293 myScaleDraw->setLabelTick( pos, label, false);
3295 std::string std_label = label.toStdString();
3296 //const char *c_label = std_label.c_str();
3297 //std::cout << " tick " << itic << " : pos= " << pos << ", label= |" << c_label << "|" << std::endl;
3299 allTicks.append( posTicks);
3301 // Compute the position of the system's label
3302 if (idev == ileftDev)
3304 devLabPos = devXmin + 0.25*(devXmax - devXmin);
3308 devLabPos = devXmin + 0.50*(devXmax - devXmin);
3310 allTicks.append( devLabPos);
3312 // Stock position and name of the system under X axis
3313 myScaleDraw->setLabelTick( devLabPos, deviceLabel, true);
3317 // Create the vertical segment between the current system and the next
3319 segmentPos = gapXmin + 0.5*(gapXmax - gapXmin);
3321 createSeparationLine( segmentPos);
3326 // List's items increasing sorting
3327 qSort( allTicks.begin(), allTicks.end() ); // iterators
3329 // Stock the interval of X's values
3330 double lowerBound = allTicks.first() - XLeftMargin;
3331 double upperBound = allTicks.last() + XRightMargin;
3332 myScaleDraw->setInterval( lowerBound, upperBound);
3334 // For each system, stock the position of the X's ticks and those of the name
3335 myScaleDraw->setTicks( allTicks); // do not draw the ticks
3337 // Memorize the X axis in the drawing zone
3338 setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
3340 //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
3344 /* Create vertical segment between two curves
3346 void Plot2d_Plot2d::createSeparationLine( double Xpos)
3348 QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
3350 aPlotMarker->setLineStyle( QwtPlotMarker::VLine);
3351 aPlotMarker->setXValue( Xpos);
3352 aPlotMarker->setLinePen( QPen(Qt::black));
3353 aPlotMarker->attach(this); // Add to drawing zone
3354 // To deallocate in EraseAll()
3355 mySeparationLineList.append( aPlotMarker);
3358 void Plot2d_Plot2d::clearSeparationLineList()
3360 mySeparationLineList.clear();
3364 Creates presentation of object
3365 Default implementation is empty
3367 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
3373 Copies preferences from other viewframe
3374 \param vf - other view frame
3376 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
3381 myCurveType = vf->myCurveType;
3382 myShowLegend = vf->myShowLegend;
3383 myLegendPos = vf->myLegendPos;
3384 myMarkerSize = vf->myMarkerSize;
3385 myBackground = vf->myBackground;
3386 myTitle = vf->myTitle;
3387 myXTitle = vf->myXTitle;
3388 myYTitle = vf->myYTitle;
3389 myY2Title = vf->myY2Title;
3390 myTitleEnabled = vf->myTitleEnabled;
3391 myXTitleEnabled = vf->myXTitleEnabled;
3392 myYTitleEnabled = vf->myYTitleEnabled;
3393 myY2TitleEnabled = vf->myY2TitleEnabled;
3394 myXGridMajorEnabled = vf->myXGridMajorEnabled;
3395 myYGridMajorEnabled = vf->myYGridMajorEnabled;
3396 myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
3397 myXGridMinorEnabled = vf->myXGridMinorEnabled;
3398 myYGridMinorEnabled = vf->myYGridMinorEnabled;
3399 myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
3400 myXGridMaxMajor = vf->myXGridMaxMajor;
3401 myYGridMaxMajor = vf->myYGridMaxMajor;
3402 myY2GridMaxMajor = vf->myY2GridMaxMajor;
3403 myXGridMaxMinor = vf->myXGridMaxMinor;
3404 myYGridMaxMinor = vf->myYGridMaxMinor;
3405 myY2GridMaxMinor = vf->myY2GridMaxMinor;
3406 myXMode = vf->myXMode;
3407 myYMode = vf->myYMode;
3408 mySecondY = vf->mySecondY;
3412 Updates titles according to curves
3414 #define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
3415 void Plot2d_ViewFrame::updateTitles( const bool update )
3417 ObjectDict::iterator it = myObjects.begin();
3418 QStringList aXTitles;
3419 QStringList aYTitles;
3420 QStringList aY2Titles;
3421 QStringList aXUnits;
3422 QStringList aYUnits;
3423 QStringList aY2Units;
3424 QStringList aTables;
3427 Plot2d_Object* anObject;
3428 for ( ; it != myObjects.end(); it++ ) {
3429 // collect titles and units from all curves...
3430 anObject = it.value();
3431 QString xTitle = anObject->getHorTitle().trimmed();
3432 QString yTitle = anObject->getVerTitle().trimmed();
3433 QString xUnits = anObject->getHorUnits().trimmed();
3434 QString yUnits = anObject->getVerUnits().trimmed();
3436 if ( anObject->getYAxis() == QwtPlot::yLeft ) {
3437 if ( !aYTitles.contains( yTitle ) )
3438 aYTitles.append( yTitle );
3439 if ( !aYUnits.contains( yUnits ) )
3440 aYUnits.append( yUnits );
3443 if ( !aY2Titles.contains( yTitle ) )
3444 aY2Titles.append( yTitle );
3445 if ( !aY2Units.contains( yUnits ) )
3446 aY2Units.append( yUnits );
3448 if ( !aXTitles.contains( xTitle ) )
3449 aXTitles.append( xTitle );
3450 if ( !aXUnits.contains( xUnits ) )
3451 aXUnits.append( xUnits );
3453 QString aName = anObject->getTableTitle();
3454 if( !aName.isEmpty() && !aTables.contains( aName ) )
3455 aTables.append( aName );
3458 // ... and update plot 2d view
3459 QString xUnits, yUnits, y2Units;
3460 if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() )
3461 xUnits = BRACKETIZE( aXUnits[0] );
3462 if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty())
3463 yUnits = BRACKETIZE( aYUnits[0] );
3464 if ( aY2Units.count() == 1 && !aY2Units[0].isEmpty())
3465 y2Units = BRACKETIZE( aY2Units[0] );
3466 QString xTitle, yTitle, y2Title;
3467 if ( aXTitles.count() == 1 && aXUnits.count() == 1 )
3468 xTitle = aXTitles[0];
3469 if ( aYTitles.count() == 1 )
3470 yTitle = aYTitles[0];
3471 if ( mySecondY && aY2Titles.count() == 1 )
3472 y2Title = aY2Titles[0];
3474 if ( !xTitle.isEmpty() && !xUnits.isEmpty() )
3476 if ( !yTitle.isEmpty() && !yUnits.isEmpty() )
3478 if ( !y2Title.isEmpty() && !y2Units.isEmpty() )
3481 setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, false );
3482 setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, false );
3484 setTitle( myY2TitleEnabled, y2Title + y2Units, Y2Title, false );
3486 setTitle( true, aTables.join("; "), MainTitle, false );
3488 // do update if necessary
3495 Outputs content of viewframe to file
3496 \param file - file name
3497 \param format - file format
3499 bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const
3508 QPaintDevice* pd = 0;
3509 if( format=="PS" || format=="EPS" || format == "PDF" )
3511 QPrinter* pr = new QPrinter( QPrinter::HighResolution );
3513 pr->setOutputFormat(QPrinter::PdfFormat);
3514 pr->setPageSize( QPrinter::A4 );
3515 pr->setOutputFileName( file );
3516 pr->setPrintProgram( "" );
3522 myPlot->print( *pd );
3532 * Print Plot2d window
3534 void Plot2d_ViewFrame::printPlot( QPainter* p, const QRect& rect,
3535 const QwtPlotPrintFilter& filter ) const
3537 myPlot->print( p, rect, filter );
3541 \return string with all visual parameters
3543 QString Plot2d_ViewFrame::getVisualParameters()
3546 return getXmlVisualParameters();
3549 RNV: Old case, now visual parameters stored in the XML format.
3551 double xmin, xmax, ymin, ymax, y2min, y2max;
3552 getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
3554 //Store font in the visual parameters string as:
3556 // ...*FontFamily|FontSize|B|I|U|r:g:b*...
3558 retStr.sprintf( "%d*%d*%d*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%s|%i|%i|%i|%i|%i:%i:%i",
3559 myXMode, myYMode, mySecondY, xmin, xmax, ymin, ymax, y2min, y2max,
3560 qPrintable(myLegendFont.family()), myLegendFont.pointSize(),myLegendFont.bold(),
3561 myLegendFont.italic(), myLegendFont.underline(),myLegendColor.red(),
3562 myLegendColor.green(), myLegendColor.blue());
3564 //store all Analytical curves
3565 //store each curve in the following format
3566 // ...*Name|isActive|Expresion|NbInervals|isAutoAssign[|MarkerType|LineType|LineWidth|r:g:b]
3567 // parameters in the [ ] is optional in case if isAutoAssign == true
3568 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
3569 Plot2d_AnalyticalCurve* c = 0;
3571 for( ; it != myAnalyticalCurves.end(); it++) {
3574 QString curveString("");
3575 isAuto = c->isAutoAssign();
3576 curveString.sprintf("*%s|%i|%s|%i|%i",
3577 qPrintable(c->getName()),
3579 qPrintable(c->getExpression()),
3580 c->getNbIntervals(),
3583 retStr+=curveString;
3585 QString optCurveString("");
3586 optCurveString.sprintf("|%i|%i|%i|%i:%i:%i",
3587 (int)c->getMarker(),
3590 c->getColor().red(),
3591 c->getColor().green(),
3592 c->getColor().blue());
3593 retStr+=optCurveString;
3596 retStr += QString( "*%1" ).arg( Qtx::colorToString( backgroundColor() ) );
3602 Restores all visual parameters from string
3604 void Plot2d_ViewFrame::setVisualParameters( const QString& parameters )
3606 if(setXmlVisualParameters(parameters))
3610 QStringList paramsLst = parameters.split( '*' );
3611 if ( paramsLst.size() >= 9 ) {
3612 double ymin, ymax, y2min, y2max;
3613 myXMode = paramsLst[0].toInt();
3614 myYMode = paramsLst[1].toInt();
3615 mySecondY = (bool)paramsLst[2].toInt();
3616 xmin = paramsLst[3].toDouble();
3617 xmax = paramsLst[4].toDouble();
3618 ymin = paramsLst[5].toDouble();
3619 ymax = paramsLst[6].toDouble();
3620 y2min = paramsLst[7].toDouble();
3621 y2max = paramsLst[8].toDouble();
3624 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
3625 setHorScaleMode( myXMode, /*update=*/false );
3626 setVerScaleMode( myYMode, /*update=*/false );
3629 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
3630 myYDistance2 = yMap2.s2() - yMap2.s1();
3633 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3634 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3637 //Restore legend font
3638 if(paramsLst.size() >= 10) {
3639 QStringList fontList = paramsLst[9].split( '|' );
3640 if(fontList.size() == 6) {
3641 myLegendFont = QFont(fontList[0]);
3642 myLegendFont.setPointSize(fontList[1].toInt());
3643 myLegendFont.setBold(fontList[2].toInt());
3644 myLegendFont.setItalic(fontList[3].toInt());
3645 myLegendFont.setUnderline(fontList[4].toInt());
3646 QStringList colorList = fontList[5].split(":");
3647 setLegendFont( myLegendFont );
3649 if(colorList.size() == 3) {
3650 myLegendColor = QColor(colorList[0].toInt(),
3651 colorList[1].toInt(),
3652 colorList[2].toInt());
3653 setLegendFontColor( myLegendColor );
3658 #ifndef NO_ANALYTICAL_CURVES
3659 //Restore all Analytical curves
3660 int startCurveIndex = 10;
3661 if( paramsLst.size() >= startCurveIndex+1 ) {
3662 for( int i=startCurveIndex; i<paramsLst.size() ; i++ ) {
3663 QStringList curveLst = paramsLst[i].split("|");
3664 if( curveLst.size() == 5 || curveLst.size() == 9 ) {
3665 Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
3666 c->setName(curveLst[0]);
3667 c->setActive(curveLst[1].toInt());
3668 c->setExpression(curveLst[2]);
3669 c->setNbIntervals(curveLst[3].toLong());
3670 c->setAutoAssign(curveLst[4].toInt());
3671 if( !c->isAutoAssign() ) {
3672 c->setMarker((Plot2d::MarkerType)curveLst[5].toInt());
3673 c->setLine((Plot2d::LineType)curveLst[6].toInt());
3674 c->setLineWidth(curveLst[7].toInt());
3675 QStringList colorList = curveLst[8].split(":");
3676 if( colorList.size() == 3 ) {
3677 c->setColor(QColor(colorList[0].toInt(),
3678 colorList[1].toInt(),
3679 colorList[2].toInt()));
3682 c->autoFill( myPlot );
3684 addAnalyticalCurve(c);
3685 updateAnalyticalCurve(c);
3687 else if( curveLst.size() == 1 ) {
3688 // background color can be set here
3690 if ( Qtx::stringToColor( paramsLst[i], c ) )
3691 setBackgroundColor( c );
3700 Store visual parameters in xml format.
3702 QString Plot2d_ViewFrame::getXmlVisualParameters() {
3704 QXmlStreamWriter aWriter(&retStr);
3705 aWriter.setAutoFormatting(true);
3708 aWriter.writeStartDocument();
3709 aWriter.writeStartElement("ViewState");
3710 aWriter.writeStartElement("Range");
3711 double xmin, xmax, ymin, ymax, y2min, y2max;
3712 getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
3713 aWriter.writeAttribute("Xmin", QString("").sprintf("%.12e",xmin));
3714 aWriter.writeAttribute("Xmax", QString("").sprintf("%.12e",xmax));
3715 aWriter.writeAttribute("Ymin", QString("").sprintf("%.12e",ymin));
3716 aWriter.writeAttribute("Ymax", QString("").sprintf("%.12e",ymax));
3717 aWriter.writeAttribute("Y2min", QString("").sprintf("%.12e",y2min));
3718 aWriter.writeAttribute("Y2max", QString("").sprintf("%.12e",y2max));
3719 aWriter.writeEndElement();
3722 aWriter.writeStartElement("DisplayMode");
3723 aWriter.writeAttribute("SecondAxis", QString("").sprintf("%d",mySecondY));
3724 aWriter.writeStartElement("ScaleMode");
3725 aWriter.writeAttribute("Xscale", QString("").sprintf("%d",myXMode));
3726 aWriter.writeAttribute("Yscale", QString("").sprintf("%d",myYMode));
3727 aWriter.writeEndElement();
3728 aWriter.writeStartElement("NormalizationMode");
3729 aWriter.writeAttribute("LeftMin", QString("").sprintf("%d",myNormLMin));
3730 aWriter.writeAttribute("LeftMax", QString("").sprintf("%d",myNormLMax));
3731 aWriter.writeAttribute("RightMin", QString("").sprintf("%d",myNormRMin));
3732 aWriter.writeAttribute("RightMax", QString("").sprintf("%d",myNormRMax));
3733 aWriter.writeEndElement();
3734 aWriter.writeEndElement();
3737 aWriter.writeStartElement("Legend");
3738 aWriter.writeAttribute("Visibility", QString("").sprintf("%d", myShowLegend));
3739 aWriter.writeStartElement("LegendFont");
3740 aWriter.writeAttribute("Family", myLegendFont.family());
3741 aWriter.writeAttribute("Size", QString("").sprintf("%d",myLegendFont.pointSize()));
3742 aWriter.writeAttribute("Bold", QString("").sprintf("%d",myLegendFont.bold()));
3743 aWriter.writeAttribute("Italic", QString("").sprintf("%d",myLegendFont.italic()));
3744 aWriter.writeAttribute("Underline", QString("").sprintf("%d",myLegendFont.underline()));
3745 aWriter.writeAttribute("R", QString("").sprintf("%d",myLegendColor.red()));
3746 aWriter.writeAttribute("G", QString("").sprintf("%d",myLegendColor.green()));
3747 aWriter.writeAttribute("B", QString("").sprintf("%d",myLegendColor.blue()));
3748 aWriter.writeEndElement();
3749 aWriter.writeEndElement();
3751 #ifndef NO_ANALYTICAL_CURVES
3753 aWriter.writeStartElement("AnalyticalCurves");
3754 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
3755 Plot2d_AnalyticalCurve* c = 0;
3758 for( ; it != myAnalyticalCurves.end(); it++) {
3761 aWriter.writeStartElement(QString("AnalyticalCurve_%1").arg(id));
3762 isAuto = c->isAutoAssign();
3763 aWriter.writeAttribute("Name",c->getName());
3764 aWriter.writeAttribute("IsActive", QString("").sprintf("%d", c->isActive()));
3765 aWriter.writeAttribute("Expression", c->getExpression());
3766 aWriter.writeAttribute("NbIntervals", QString("").sprintf("%d", c->getNbIntervals()));
3767 aWriter.writeAttribute("isAuto", QString("").sprintf("%d",isAuto));
3769 aWriter.writeAttribute("Marker", QString("").sprintf("%d",(int)c->getMarker()));
3770 aWriter.writeAttribute("Line", QString("").sprintf("%d",(int)c->getLine()));
3771 aWriter.writeAttribute("LineWidth", QString("").sprintf("%d",c->getLineWidth()));
3772 aWriter.writeAttribute("R", QString("").sprintf("%d",c->getColor().red()));
3773 aWriter.writeAttribute("G", QString("").sprintf("%d",c->getColor().green()));
3774 aWriter.writeAttribute("B", QString("").sprintf("%d",c->getColor().blue()));
3776 aWriter.writeEndElement();
3779 aWriter.writeEndElement(); //AnalyticalCurve
3783 aWriter.writeStartElement(QString("Background"));
3784 aWriter.writeStartElement(QString("BackgroundColor"));
3785 aWriter.writeAttribute("R", QString("").sprintf("%d",backgroundColor().red()));
3786 aWriter.writeAttribute("G", QString("").sprintf("%d",backgroundColor().green()));
3787 aWriter.writeAttribute("B", QString("").sprintf("%d",backgroundColor().blue()));
3788 aWriter.writeEndElement();
3789 aWriter.writeEndElement();
3792 aWriter.writeEndDocument();
3796 Restore visual parameters from xml format.
3798 bool Plot2d_ViewFrame::setXmlVisualParameters(const QString& parameters) {
3799 QXmlStreamReader aReader(parameters);
3800 double xmin, xmax, ymin, ymax, y2min, y2max;
3801 bool leftMin,leftMax,rightMin,rightMax;
3802 leftMin = leftMax = rightMin = rightMax = false;
3803 while(!aReader.atEnd()) {
3805 if (aReader.isStartElement()) {
3806 QXmlStreamAttributes aAttr = aReader.attributes();
3807 if(aReader.name() == "Range") {
3808 xmin = aAttr.value("Xmin").toString().toDouble();
3809 xmax = aAttr.value("Xmax").toString().toDouble();
3810 ymin = aAttr.value("Ymin").toString().toDouble();
3811 ymax = aAttr.value("Ymax").toString().toDouble();
3812 y2min = aAttr.value("Y2min").toString().toDouble();
3813 y2max = aAttr.value("Y2max").toString().toDouble();
3814 } else if(aReader.name() == "DisplayMode") {
3815 mySecondY = aAttr.value("Y2max").toString().toDouble();
3816 } else if(aReader.name() == "ScaleMode") {
3817 myXMode = aAttr.value("Xscale").toString().toInt();
3818 myYMode = aAttr.value("Yscale").toString().toInt();
3819 } else if(aReader.name() == "NormalizationMode") {
3820 leftMin = (bool)aAttr.value("LeftMin").toString().toInt();
3821 leftMax = (bool)aAttr.value("LeftMax").toString().toInt();
3822 rightMin = (bool)aAttr.value("RightMin").toString().toInt();
3823 rightMax = (bool)aAttr.value("RightMax").toString().toInt();
3824 } else if(aReader.name() == "Legend") {
3825 myShowLegend = (bool)aAttr.value("Visibility").toString().toInt();
3826 } else if (aReader.name() == "LegendFont") {
3827 myLegendFont = QFont(aAttr.value("Family").toString());
3828 myLegendFont.setPointSize(aAttr.value("Size").toString().toInt());
3829 myLegendFont.setBold((bool)aAttr.value("Bold").toString().toInt());
3830 myLegendFont.setItalic((bool)aAttr.value("Italic").toString().toInt());
3831 myLegendFont.setUnderline((bool)aAttr.value("Underline").toString().toInt());
3832 myLegendColor = QColor(aAttr.value("R").toString().toInt(),
3833 aAttr.value("G").toString().toInt(),
3834 aAttr.value("B").toString().toInt());
3835 setLegendFontColor( myLegendColor );
3836 setLegendFont(myLegendFont);
3837 } else if(aReader.name().toString().indexOf("AnalyticalCurve_") >= 0) {
3838 #ifndef NO_ANALYTICAL_CURVES
3839 Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
3840 c->setName(aAttr.value("Name").toString());
3841 c->setActive((bool)aAttr.value("IsActive").toString().toInt());
3842 c->setExpression(aAttr.value("Expression").toString());
3843 c->setNbIntervals(aAttr.value("NbIntervals").toString().toLong());
3844 c->setAutoAssign((bool)aAttr.value("isAuto").toString().toInt());
3845 if( !c->isAutoAssign() ) {
3846 c->setMarker((Plot2d::MarkerType)aAttr.value("Marker").toString().toInt());
3847 c->setLine((Plot2d::LineType)aAttr.value("Line").toString().toInt());
3848 c->setLineWidth(aAttr.value("LineWidth").toString().toInt());
3849 c->setColor(QColor(aAttr.value("R").toString().toInt(),
3850 aAttr.value("G").toString().toInt(),
3851 aAttr.value("B").toString().toInt()));
3853 c->autoFill( myPlot );
3855 addAnalyticalCurve(c);
3856 updateAnalyticalCurve(c);
3858 } else if(aReader.name().toString() == "BackgroundColor") {
3859 setBackgroundColor(QColor(aAttr.value("R").toString().toInt(),
3860 aAttr.value("G").toString().toInt(),
3861 aAttr.value("B").toString().toInt()));
3866 if(aReader.hasError())
3870 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
3871 setHorScaleMode( myXMode, /*update=*/false );
3872 setVerScaleMode( myYMode, /*update=*/false );
3874 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
3875 myYDistance2 = yMap2.s2() - yMap2.s1();
3877 setNormLMinMode(leftMin);
3878 setNormLMaxMode(leftMax);
3879 setNormRMinMode(rightMin);
3880 setNormRMaxMode(rightMax);
3882 showLegend( myShowLegend, false );
3884 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3889 Incremental zooming operation
3891 void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) {
3892 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
3893 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
3895 myPlot->setAxisScale( QwtPlot::yLeft,
3896 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s1() )-incrY ),
3897 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() )-incrY ) );
3898 myPlot->setAxisScale( QwtPlot::xBottom,
3899 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s1() )-incrX ),
3900 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() )-incrX ) );
3902 QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
3903 myPlot->setAxisScale( QwtPlot::yRight,
3904 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s1() )-incrY ),
3905 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() )-incrY ) );
3911 Incremental panning operation
3913 void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) {
3914 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
3915 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
3917 myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(),
3918 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() ) + incrY ) );
3919 myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(),
3920 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() ) - incrX ) );
3922 QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
3923 myPlot->setAxisScale( QwtPlot::yRight, y2Map.s1(),
3924 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() ) + incrY ) );
3932 void Plot2d_ViewFrame::updatePlotItem(Plot2d_Object* theObject, QwtPlotItem* theItem) {
3933 theObject->updatePlotItem( theItem );
3934 Plot2d_Curve* c = dynamic_cast<Plot2d_Curve*>(theObject);
3935 QwtPlotCurve* cu = dynamic_cast<QwtPlotCurve*>(theItem);
3936 Plot2d_NormalizeAlgorithm* aNormAlgo;
3938 if(c->getYAxis() == QwtPlot::yRight)
3939 aNormAlgo = myRNormAlgo;
3941 aNormAlgo = myLNormAlgo;
3942 if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
3943 AlgoPlot2dOutputData aResultData = aNormAlgo->getOutput();
3944 AlgoPlot2dOutputData::iterator itTmp = aResultData.find(theObject);
3946 int size = itTmp.value().size();
3947 xNew = new double[size];
3948 yNew = new double[size];
3950 for (; j < size; ++j) {
3951 xNew[j] = itTmp.value().at(j).first;
3952 yNew[j] = itTmp.value().at(j).second;
3954 cu->setData(xNew, yNew,j);
3957 if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
3958 QString name = c->getName().isEmpty() ? c->getVerTitle() : c->getName();
3959 name = name + QString("(B=%1, K=%2)");
3960 name = name.arg(aNormAlgo->getBkoef(c)).arg(aNormAlgo->getKkoef(c));
3970 QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas() const
3972 return myPlot ? myPlot->canvas() : 0;
3976 return closest curve if it exist, else 0
3978 Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, int& index ) const
3980 CurveDict aCurves = getCurves();
3981 CurveDict::iterator it = aCurves.begin();
3982 Plot2d_Curve* pCurve = 0;
3984 for ( ; it != aCurves.end(); it++ ) {
3985 QwtPlotCurve* aCurve = it.key();
3989 int i = aCurve->closestPoint( p, &d );
3990 if ( i > -1 && ( distance < 0 || d < distance ) ) {
3991 pCurve = it.value();
3999 #ifndef NO_ANALYTICAL_CURVES
4001 \brief Deselect all analytical curves.
4003 void Plot2d_ViewFrame::deselectAnalyticalCurves() {
4004 foreach(Plot2d_AnalyticalCurve* c, myAnalyticalCurves) {
4005 c->setSelected(false);
4011 \brief Deselect all objects, except analytical curves.
4013 void Plot2d_ViewFrame::deselectObjects() {
4014 ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end();
4015 for ( ; it != aLast; it++ ) {
4016 it.value()->setSelected(false);
4020 #define INCREMENT_FOR_OP 10
4023 Performs incremental panning to the left
4025 void Plot2d_ViewFrame::onPanLeft()
4027 this->incrementalPan( -INCREMENT_FOR_OP, 0 );
4028 #ifndef NO_ANALYTICAL_CURVES
4029 updateAnalyticalCurves();
4034 Performs incremental panning to the right
4036 void Plot2d_ViewFrame::onPanRight()
4038 this->incrementalPan( INCREMENT_FOR_OP, 0 );
4039 #ifndef NO_ANALYTICAL_CURVES
4040 updateAnalyticalCurves();
4045 Performs incremental panning to the top
4047 void Plot2d_ViewFrame::onPanUp()
4049 this->incrementalPan( 0, -INCREMENT_FOR_OP );
4050 #ifndef NO_ANALYTICAL_CURVES
4051 updateAnalyticalCurves();
4056 Performs incremental panning to the bottom
4058 void Plot2d_ViewFrame::onPanDown()
4060 this->incrementalPan( 0, INCREMENT_FOR_OP );
4061 #ifndef NO_ANALYTICAL_CURVES
4062 updateAnalyticalCurves();
4067 Performs incremental zooming in
4069 void Plot2d_ViewFrame::onZoomIn()
4071 this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP );
4072 #ifndef NO_ANALYTICAL_CURVES
4073 updateAnalyticalCurves();
4078 Performs incremental zooming out
4080 void Plot2d_ViewFrame::onZoomOut()
4082 this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP );
4083 #ifndef NO_ANALYTICAL_CURVES
4084 updateAnalyticalCurves();
4089 Schedules a FitAll operation by putting it to the application's
4090 event queue. This ensures that other important events (show, resize, etc.)
4091 are processed first.
4093 void Plot2d_ViewFrame::customEvent( QEvent* ce )
4095 if ( ce->type() == FITALL_EVENT )
4101 * Return Plot2d_Object by the QwtPlotItem
4104 Plot2d_Object* Plot2d_ViewFrame::getPlotObject( QwtPlotItem* plotItem ) const {
4106 ObjectDict::const_iterator it = myObjects.begin();
4107 for( ; it != myObjects.end(); ++it ) {
4108 if ( it.key() == plotItem ) {
4115 Plot2d_ScaleDraw::Plot2d_ScaleDraw( char f, int prec )
4123 Plot2d_ScaleDraw::Plot2d_ScaleDraw( const QwtScaleDraw& scaleDraw, char f, int prec )
4124 : QwtScaleDraw(scaleDraw),
4131 QwtText Plot2d_ScaleDraw::label( double value ) const
4133 QwtScaleMap m = map();
4134 QString str1 = QwtScaleDraw::label( m.s1() ).text();
4135 QString str2 = QwtScaleDraw::label( m.s2() ).text();
4136 if ( str1 == str2 ) {
4137 double aDist = fabs(map().s2()-map().s1())/5;
4139 while (aDist < 1 ) {
4143 if ( precision > 0 && value > 0 )
4144 return QLocale::system().toString( value,'f', precision );
4147 return QwtScaleDraw::label( value );
4150 Plot2d_YScaleDraw::Plot2d_YScaleDraw()
4155 QwtText Plot2d_YScaleDraw::label( double value ) const
4157 // Axis labels format
4158 QString strD = QString( "%1").arg( value, 10, 'e', 3); // format 10.3e
4160 return QwtText( strD);
4163 /* Definition of X axis graduations
4165 const QString Plot2d_AxisScaleDraw::DEVICE_FONT = QString("Times");
4166 const int Plot2d_AxisScaleDraw::DEVICE_FONT_SIZE = 12;
4167 const int Plot2d_AxisScaleDraw::DEVICE_BY = 40;
4169 Plot2d_AxisScaleDraw::Plot2d_AxisScaleDraw( Plot2d_Plot2d* plot)
4174 setLabelAlignment(Qt::AlignRight);
4175 setLabelRotation(45.);
4179 myActivTicksDrawing = true;
4180 myNumTicksDrawingCall = 1;
4184 Plot2d_AxisScaleDraw::~Plot2d_AxisScaleDraw()
4189 /* Unactivate automatic ticks drawing
4191 void Plot2d_AxisScaleDraw::unactivTicksDrawing( int numcall)
4193 myActivTicksDrawing = false;
4194 myNumTicksDrawingCall = numcall;
4198 /* Draw X ticks and labels.
4199 * Draw systems names under X axis.
4200 * Overload the same name QwtScaleDraw method.
4201 * (PB: who call automaticaly this method)
4203 void Plot2d_AxisScaleDraw::draw( QPainter* painter, const QPalette & palette) const
4205 //std::cout << "Plot2d_AxisScaleDraw::draw() : activ= " << myActivTicksDrawing
4206 // << " numcall= " << myNumTicksDrawingCall << std::endl;
4208 if (!myActivTicksDrawing) return;
4210 //std::cout << "Plot2d_AxisScaleDraw::draw()" << std::endl;
4212 QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
4213 QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
4214 QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
4216 medium_ticks.clear();
4217 minor_ticks.clear();
4218 major_ticks.clear();
4220 major_ticks.append( myTicks);
4221 myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MajorTick, major_ticks);
4222 myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
4223 myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
4224 QwtScaleDraw *scale = myPlot->axisScaleDraw(QwtPlot::xBottom);
4225 ((Plot2d_AxisScaleDraw*)(scale))->applyTicks();
4227 QwtScaleDraw::draw( painter, palette);
4229 for (int i = 0; i < myTicks.size(); i++)
4231 drawLabel( painter, myTicks[i]);
4234 //std::cout << "Ok for Plot2d_AxisScaleDraw::draw()" << std::endl;
4238 QwtText Plot2d_AxisScaleDraw::label( double value) const
4240 if (myLabelX.contains(value))
4241 return myLabelX[value];
4243 return QwtText(QString::number(value, 'f', 1));
4247 /* Stock position and label of a X tick
4249 void Plot2d_AxisScaleDraw::setLabelTick( double value, QString label, bool isDevice)
4251 //qDebug()<< "setLabelTick ( " << value << ","<< label <<" )";
4254 // For systems names under X axis
4255 myLabelDevice[value] = label;
4259 // For X axis graduations
4260 myLabelX[value] = label;
4265 /* Stock ticks positions of a system, and draw them
4267 void Plot2d_AxisScaleDraw::setTicks(const QList<double> aTicks)
4269 //std::cout << " Plot2d_AxisScaleDraw::setTicks()" << std::endl;
4276 void Plot2d_AxisScaleDraw::setInterval(double lowerBound, double upperBound)
4278 myLowerBound = lowerBound;
4279 myUpperBound = upperBound;
4280 myPlot->setAxisScale( QwtPlot::xBottom, myLowerBound, myUpperBound );
4284 /* Stock X ticks in drawing zone
4286 void Plot2d_AxisScaleDraw::applyTicks()
4288 //std::cout << " Plot2d_AxisScaleDraw::applyTicks()" << std::endl;
4290 QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
4291 QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
4292 QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
4294 medium_ticks.clear();
4295 minor_ticks.clear();
4297 myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MajorTick, myTicks);
4298 myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
4299 myPlot->axisScaleDiv(QwtPlot::xBottom)->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
4301 QwtScaleDiv* aScaleDiv = (QwtScaleDiv*) &scaleDiv();
4303 aScaleDiv->setTicks(QwtScaleDiv::MajorTick, myTicks);
4304 aScaleDiv->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
4305 aScaleDiv->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
4307 if (myLowerBound != -1 && myUpperBound != -1)
4308 aScaleDiv->setInterval(myLowerBound, myUpperBound);
4310 //for (int i = 0; i < myTicks.size(); i++){
4311 // QPoint p = labelPosition( i );
4312 // qDebug() << i<< ") applyTicks -> LABEL" <<p;
4317 void Plot2d_AxisScaleDraw::drawLabel( QPainter* painter, double value) const
4319 //std::cout << " Plot2d_AxisScaleDraw::drawLabel( " << value << " ) : "; //<< std::endl;
4321 //qDebug() << "drawLabel ( " <<value<<" )";
4322 if ( myLabelDevice.contains(value) )
4324 QString deviceLabel = myLabelDevice[value];
4326 std::string std_label = deviceLabel.toStdString();
4327 //const char *c_label = std_label.c_str();
4328 //std::cout << " deviceLabel= |" << c_label << "|" << std::endl;
4330 QPoint p = labelPosition( value );
4331 p += QPoint(0, DEVICE_BY);
4332 QFont prevf = painter->font();
4333 //QColor prevc = (painter->pen()).color();
4335 QFont devicef( DEVICE_FONT, DEVICE_FONT_SIZE, QFont::Bold);
4337 //painter->setPen( QColor("blue") );
4338 painter->setFont( devicef );
4339 painter->drawText( p, myLabelDevice[value] );
4340 //painter->setPen( prevc );
4341 painter->setFont( prevf );
4343 if ( myLabelX.contains(value) )
4345 QString xLabel = myLabelX[value];
4347 std::string std_label = xLabel.toStdString();
4348 //const char *c_label = std_label.c_str();
4349 //std::cout << " xLabel= |" << c_label << "|" << std::endl;
4351 QwtScaleDraw::drawLabel( painter, value );
4356 void Plot2d_AxisScaleDraw::drawTick( QPainter* painter, double value, int len) const
4358 //qDebug() << "drawTick ( " <<value<<" , "<<len<<" ) " ;
4359 //qDebug() << "myLabelX" << myLabelX;
4361 if ( myLabelX.contains(value) )
4363 QwtScaleDraw::drawTick( painter, value, len);
4368 /* Management of tooltips associated with markers for curves points or others points
4370 const double Plot2d_QwtPlotPicker::BOUND_HV_SIZE = 0.2;
4372 Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
4375 RubberBand rubberBand,
4376 DisplayMode trackerMode,
4377 QwtPlotCanvas *canvas)
4378 : QwtPlotPicker( xAxis,
4383 canvas) // of drawing zone QwtPlot
4387 Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
4389 QwtPlotCanvas *canvas)
4390 : QwtPlotPicker( xAxis,
4396 Plot2d_QwtPlotPicker::~Plot2d_QwtPlotPicker()
4399 // http://www.qtcentre.org/threads/22751-How-do-i-select-a-QwtPlotMarker-using-a-QPlotPicker
4401 /* Return the tooltip associated with a point when the mouse cursor pass near
4403 QwtText Plot2d_QwtPlotPicker::trackerText( const QwtDoublePoint & pos ) const
4405 for (QList<QwtPlotMarker* >::const_iterator pMarkerIt = pMarkers.begin();pMarkerIt != pMarkers.end(); ++pMarkerIt )
4407 QwtPlotMarker* pMarker = *pMarkerIt;
4408 if ( pMarker != NULL )
4410 const QwtSymbol &symb=pMarker->symbol();
4411 const QSize& sz=symb.size();
4412 const QwtScaleMap yMapRef=plot()->canvasMap(QwtPlot::yLeft);
4413 const QwtScaleMap xMap=plot()->canvasMap(pMarker->xAxis());
4414 const QwtScaleMap yMap=plot()->canvasMap(pMarker->yAxis());
4415 QwtDoubleRect bound0=pMarker->boundingRect();
4416 QRect bound00=pMarker->transform(xMap,yMap,bound0);
4417 QPoint toto(xMap.transform(pos.x()),yMapRef.transform(pos.y()));
4418 bound00.setX(bound00.x()-sz.width());
4419 bound00.setY(bound00.y()-sz.height());
4420 bound00.setWidth(bound00.width()+sz.width());
4421 bound00.setHeight(bound00.height()+sz.height());
4422 if( bound00.contains(toto) )
4424 return pMarkersToolTip[pMarker];