1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "Plot2d_ViewFrame.h"
25 #include "Plot2d_Prs.h"
26 #include "Plot2d_Curve.h"
27 #include "Plot2d_PlotItems.h"
28 #include "Plot2d_FitDataDlg.h"
30 #include "Plot2d_ViewWindow.h"
32 #include "Plot2d_SetupViewDlg.h"
33 #ifndef NO_ANALYTICAL_CURVES
34 #include "Plot2d_AnalyticalCurveDlg.h"
35 #include "Plot2d_AnalyticalCurve.h"
37 #include "Plot2d_ToolTip.h"
40 #include "SUIT_Tools.h"
41 #include "SUIT_Session.h"
42 #include "SUIT_MessageBox.h"
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Application.h"
46 #include <QMessageBox>
49 #include <QApplication>
51 #include <QToolButton>
53 #include <QColorDialog>
57 #include <QPaintDevice>
59 #include <QMouseEvent>
60 #include <QContextMenuEvent>
64 #include <QXmlStreamWriter>
65 #include <QXmlStreamReader>
68 #include <qwt_plot_layout.h>
69 #include <qwt_plot_canvas.h>
70 #include <qwt_scale_div.h>
71 #include <qwt_plot_marker.h>
72 #include <qwt_plot_curve.h>
73 #include <qwt_plot_grid.h>
74 #include <qwt_scale_engine.h>
75 #include <qwt_plot_zoomer.h>
76 #include <qwt_curve_fitter.h>
77 #include <qwt_plot_renderer.h>
83 #include <qwt_legend.h>
84 #include <qwt_scale_widget.h>
86 #define DEFAULT_LINE_WIDTH 0 // (default) line width
87 #define DEFAULT_MARKER_SIZE 9 // default marker size
88 #define MIN_RECT_SIZE 11 // min sensibility area size
90 #define FITALL_EVENT ( QEvent::User + 9999 )
92 const char* imageZoomCursor[] = {
97 "................................",
98 "................................",
99 ".#######........................",
100 "..aaaaaaa.......................",
101 "................................",
102 ".............#####..............",
103 "...........##.aaaa##............",
104 "..........#.aa.....a#...........",
105 ".........#.a.........#..........",
106 ".........#a..........#a.........",
107 "........#.a...........#.........",
108 "........#a............#a........",
109 "........#a............#a........",
110 "........#a............#a........",
111 "........#a............#a........",
112 ".........#...........#.a........",
113 ".........#a..........#a.........",
114 ".........##.........#.a.........",
115 "........#####.....##.a..........",
116 ".......###aaa#####.aa...........",
117 "......###aa...aaaaa.......#.....",
118 ".....###aa................#a....",
119 "....###aa.................#a....",
120 "...###aa...............#######..",
121 "....#aa.................aa#aaaa.",
122 ".....a....................#a....",
123 "..........................#a....",
124 "...........................a....",
125 "................................",
126 "................................",
127 "................................",
128 "................................"};
130 const char* imageCrossCursor[] = {
135 "................................",
136 "................................",
137 "................................",
138 "................................",
139 "................................",
140 "................................",
141 "................................",
142 "...............#................",
143 "...............#a...............",
144 "...............#a...............",
145 "...............#a...............",
146 "...............#a...............",
147 "...............#a...............",
148 "...............#a...............",
149 "...............#a...............",
150 ".......#################........",
151 "........aaaaaaa#aaaaaaaaa.......",
152 "...............#a...............",
153 "...............#a...............",
154 "...............#a...............",
155 "...............#a...............",
156 "...............#a...............",
157 "...............#a...............",
158 "...............#a...............",
159 "................a...............",
160 "................................",
161 "................................",
162 "................................",
163 "................................",
164 "................................",
165 "................................",
166 "................................"};
181 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
182 : QWidget (parent, 0),
183 myOperation( NoOpId ),
185 myShowLegend( true ), myLegendPos( 1 ), myLegendSymbolType( 0 ), myLegendFont("Helvetic",12),
186 myLegendColor(Qt::black), mySelectedLegendFontColor( Qt::darkBlue ),
187 myMarkerSize( DEFAULT_MARKER_SIZE ),
188 myBackground( Qt::white ),
189 mySelectionColor( Qt::gray ),
190 myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
191 myTitleEnabled( true ), myXTitleEnabled( true ),
192 myYTitleEnabled( true ), myY2TitleEnabled (true),
193 myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
194 myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
195 myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
196 myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
197 myXMode( 0 ), myYMode( 0 ),myNormLMin(false), myNormLMax(false), myNormRMin(false), myNormRMax(false),
198 mySecondY( false ), myIsDefTitle( true )
200 setObjectName( title );
201 myRNormAlgo = new Plot2d_NormalizeAlgorithm(this);
202 myLNormAlgo = new Plot2d_NormalizeAlgorithm(this);
204 QVBoxLayout* aLayout = new QVBoxLayout( this );
205 aLayout->setMargin(0);
206 myPlot = new Plot2d_Plot2d( this );
207 new Plot2d_ToolTip( this );
209 aLayout->addWidget( myPlot );
218 Plot2d_ViewFrame::~Plot2d_ViewFrame()
222 Performs the initial setup.
224 void Plot2d_ViewFrame::Init()
226 /* Initial Setup - get from the preferences */
229 setCurveType( myCurveType, false );
230 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
231 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
232 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
234 setTitle( myTitleEnabled, myTitle, MainTitle, false );
235 setTitle( myXTitleEnabled, myXTitle, XTitle, false );
236 setTitle( myYTitleEnabled, myYTitle, YTitle, false );
239 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
240 setHorScaleMode( myXMode, false );
241 setVerScaleMode( myYMode, false );
242 setBackgroundColor( myBackground );
243 setSelectionColor( mySelectionColor );
244 setLegendPos( myLegendPos );
245 setLegendSymbolType( myLegendSymbolType );
246 setLegendFont( myLegendFont );
247 setLegendFontColor( myLegendColor );
248 setSelectedLegendFontColor( mySelectedLegendFontColor );
249 showLegend( myShowLegend, false );
252 QWidget* aParent = parentWidget();
254 resize( (int)(0.8 * aParent->width()), (int)(0.8 * aParent->height()) );
256 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
257 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
258 myXDistance = xMap.s2() - xMap.s1();
259 myYDistance = yMap.s2() - yMap.s1();
262 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
263 myYDistance2 = yMap2.s2() - yMap2.s1();
265 myPlot->canvas()->installEventFilter( this );
267 void Plot2d_ViewFrame::SetPreference()
270 setBackgroundColor( myBackground );
271 setSelectionColor( mySelectionColor );
272 setCurveType( myCurveType, true );
273 setMarkerSize( myMarkerSize, true );
274 showLegend( myShowLegend, true );
275 setLegendPos( myLegendPos );
276 setLegendSymbolType( myLegendSymbolType );
277 setLegendFont( myLegendFont );
278 setLegendFontColor( myLegendColor );
279 setSelectedLegendFontColor( mySelectedLegendFontColor );
283 Gets window's central widget
285 QWidget* Plot2d_ViewFrame::getViewWidget()
287 return (QWidget*)myPlot;
290 Actually this method just re-displays all curves which are presented in the viewer
292 void Plot2d_ViewFrame::DisplayAll()
296 foreach ( Plot2d_Object* o, olist )
297 updateObject( o, false );
299 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
302 Removes all curves from the view
304 void Plot2d_ViewFrame::EraseAll()
306 objectList anObjects;
307 getObjects( anObjects );
308 eraseObjects( anObjects, false );
311 // 1)- Erase all the intermittent segments who connect curves
313 int nbSeg = myIntermittentSegmentList.size();
316 for (int iseg=0; iseg < nbSeg; iseg++)
318 QwtPlotCurve *segment = myIntermittentSegmentList[iseg];
320 segment->detach(); // erase in QwtPlot window
323 myIntermittentSegmentList.clear();
326 // 3)- Erase all QwtPlotCurve associated with the Plot2d_Curve
328 int nbCur1 = myQwtPlotCurveList.size();
331 for (int icur=0; icur < nbCur1; icur++)
333 QwtPlotItem *curve0 = myQwtPlotCurveList[icur];
334 QwtPlotCurve *curve = static_cast<QwtPlotCurve*>(curve0);
341 myQwtPlotCurveList.clear();
344 // 4)- Erase all curves Plot2d_Curve
346 int nbCur = myPlot2dCurveList.size();
349 for (int icur=0; icur < nbCur; icur++)
351 Plot2d_Curve *curve = myPlot2dCurveList[icur];
358 myPlot2dCurveList.clear();
361 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
364 Redraws viewframe contents
366 void Plot2d_ViewFrame::Repaint()
373 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
375 if ( !prs || prs->IsNull() )
378 setEnableAxis( QwtPlot::yRight, prs->isSecondY() ); // VSR: is it correct? maybe we should only enable second Y axis if required
380 // display all objects from presentation
381 objectList anObjects = prs->getObjects();
382 displayObjects( anObjects );
383 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
384 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
385 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
386 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
392 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
394 if ( !prs || prs->IsNull() )
397 // erase all objects from presentation
398 objectList anObjects = prs->getObjects();
399 eraseObjects( anObjects );
400 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
403 bool Plot2d_ViewFrame::eventFilter( QObject* watched, QEvent* e )
405 if ( watched == myPlot->canvas() ) {
406 int aType = e->type();
408 case QEvent::MouseMove: {
409 QMouseEvent* me = (QMouseEvent*)e;
410 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
411 QMouseEvent m( QEvent::MouseMove, me->pos(), me->button(),
412 me->buttons(), me->modifiers() );
413 if ( plotMouseMoved( m ) )
418 case QEvent::MouseButtonPress: {
419 QMouseEvent* me = (QMouseEvent*)e;
420 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
421 QMouseEvent m( QEvent::MouseButtonPress, me->pos(), me->button(),
422 me->buttons(), me->modifiers() );
423 plotMousePressed( m );
427 case QEvent::MouseButtonRelease: {
428 QMouseEvent* me = (QMouseEvent*)e;
429 if ( me && ( me->buttons() != 0 || me->button() != 0 ) ) {
430 QMouseEvent m( QEvent::MouseButtonRelease, me->pos(), me->button(),
431 me->buttons(), me->modifiers() );
432 plotMouseReleased( m );
436 case QEvent::ContextMenu:
438 // Do nothing because context menu is called from MouseRelease
442 return QWidget::eventFilter( watched, e );
448 void Plot2d_ViewFrame::setTitle( const QString& title )
450 setTitle( myTitleEnabled, title, MainTitle, true );
451 myIsDefTitle = false;
457 QString Plot2d_ViewFrame::getTitle() const
463 Reads Plot2d view settings from the preferences
465 void Plot2d_ViewFrame::readPreferences()
468 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
470 myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
471 setCurveType( resMgr->integerValue( "Plot2d", "CurveType", myCurveType ) );
473 myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
474 myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
475 myLegendSymbolType = resMgr->integerValue( "Plot2d", "LegendSymbolType", myLegendSymbolType );
476 myLegendFont = resMgr->fontValue( "Plot2d", "LegendFont", myLegendFont );
477 myLegendColor = resMgr->colorValue( "Plot2d", "LegendFontColor", myLegendColor );
478 mySelectedLegendFontColor = resMgr->colorValue( "Plot2d", "SelectedLegendFontColor", mySelectedLegendFontColor );
479 myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
480 myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
481 mySelectionColor = resMgr->colorValue( "Plot2d", "SelectionColor", mySelectionColor );
483 myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
484 myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
485 myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
486 myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
488 myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
489 myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
490 myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
492 myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
493 myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
494 myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
496 myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
497 myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
499 myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
501 myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
502 myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
504 myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
506 setHorScaleMode( qMax( 0, qMin( 1, resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode ) ) ), false );
507 setVerScaleMode( qMax( 0, qMin( 1, resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode ) ) ), false );
508 setNormLMinMode( resMgr->booleanValue( "Plot2d", "VerNormLMinMode", myNormLMin ) );
509 setNormLMaxMode( resMgr->booleanValue( "Plot2d", "VerNormLMaxMode", myNormLMax ) );
510 setNormRMinMode( resMgr->booleanValue( "Plot2d", "VerNormRMinMode", myNormRMin ) );
511 setNormRMaxMode( resMgr->booleanValue( "Plot2d", "VerNormRMaxMode", myNormRMax ) );
512 QColor c = resMgr->colorValue( "Plot2d", "DeviationMarkerColor", QColor(255,0,0));
513 myPlot->setProperty(PLOT2D_DEVIATION_COLOR, c);
514 myPlot->setProperty(PLOT2D_DEVIATION_LW,
515 resMgr->integerValue( "Plot2d", "DeviationMarkerLineWidth", 1));
516 myPlot->setProperty(PLOT2D_DEVIATION_TS,
517 resMgr->integerValue( "Plot2d", "DeviationMarkerTickSize", 2));
522 Writes Plot2d view settings to the preferences
524 void Plot2d_ViewFrame::writePreferences()
527 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
529 resMgr->setValue( "Plot2d", "CurveType", myCurveType );
530 resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
531 resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
532 resMgr->setValue( "Plot2d", "LegendSymbolType", myLegendSymbolType );
533 resMgr->setValue( "Plot2d", "LegendFont", myLegendFont );
534 resMgr->setValue( "Plot2d", "LegendFontColor", myLegendColor );
535 resMgr->setValue( "Plot2d", "SelectedLegendFontColor", mySelectedLegendFontColor );
536 resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
537 resMgr->setValue( "Plot2d", "Background", myBackground );
538 resMgr->setValue( "Plot2d", "SelectionColor", mySelectionColor );
539 resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
540 resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
541 resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
542 resMgr->setValue( "Plot2d", "DeviationMarkerColor", myPlot->property(PLOT2D_DEVIATION_COLOR).value<QColor>() );
543 resMgr->setValue( "Plot2d", "DeviationMarkerLineWidth", myPlot->property(PLOT2D_DEVIATION_LW).toInt() );
544 resMgr->setValue( "Plot2d", "DeviationMarkerTickSize", myPlot->property(PLOT2D_DEVIATION_TS).toInt() );
546 resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
548 resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
549 resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
550 resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
551 resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
553 resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
554 resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
556 resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
557 resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
559 resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
563 resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
564 resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
565 resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
566 resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
569 resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
570 resMgr->setValue( "Plot2d", "VerNormLMinMode", myNormLMin );
571 resMgr->setValue( "Plot2d", "VerNormLMaxMode", myNormLMax );
572 resMgr->setValue( "Plot2d", "VerNormRMinMode", myNormRMin );
573 resMgr->setValue( "Plot2d", "VerNormRMaxMode", myNormRMax );
578 Prints mouse cursor coordinates into string
580 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
584 bool xFound = false, yFound = false;
585 double xCoord, yCoord;
586 const QwtScaleDiv& aXscale = myPlot->axisScaleDiv( QwtPlot::xBottom );
587 aTicks = aXscale.ticks( QwtScaleDiv::MajorTick );
588 for ( i = 0; i < aTicks.count(); i++ ) {
589 double majXmark = aTicks[i];
590 int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
591 if ( xmark-2 == pnt.x() ) {
598 aTicks = aXscale.ticks( QwtScaleDiv::MinorTick );
599 for ( i = 0; i < aTicks.count(); i++ ) {
600 double minXmark = aTicks[i];
601 int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
602 if ( xmark-2 == pnt.x() ) {
609 const QwtScaleDiv& aYscale = myPlot->axisScaleDiv( QwtPlot::yLeft );
610 aTicks = aYscale.ticks( QwtScaleDiv::MajorTick );
611 for ( i = 0; i < aTicks.count(); i++ ) {
612 double majYmark = aTicks[i];
613 int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
614 if ( ymark-2 == pnt.y() ) {
621 aTicks = aYscale.ticks( QwtScaleDiv::MinorTick );
622 for ( i = 0; i < aTicks.count(); i++ ) {
623 double minYmark = aTicks[i];
624 int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
625 if ( ymark-2 == pnt.y() ) {
633 QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).trimmed();
636 QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).trimmed();
642 bool yFound2 = false;
645 const QwtScaleDiv& aYscale2 = myPlot->axisScaleDiv( QwtPlot::yRight );
646 aTicks = aYscale2.ticks( QwtScaleDiv::MajorTick );
647 for ( i = 0; i < aTicks.count(); i++ ) {
648 double majYmark = aTicks[i];
649 int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
650 if ( ymark-2 == pnt.y() ) {
657 aTicks = aYscale2.ticks( QwtScaleDiv::MinorTick );
658 for ( i = 0; i < aTicks.count(); i++ ) {
659 double minYmark = aTicks[i];
660 int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
661 if ( ymark-2 == pnt.y() ) {
668 QString strY2 = QString::number( yFound2 ? yCoord2 :
669 myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).trimmed();
672 info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
675 info = tr("INF_COORDINATES").arg( strX ).arg( strY );
681 * Display curves of the list of lists by systems and components
682 * - the first level list contains NbSytems lists of second level
683 * - a second level list contains NbComponents curves
684 * | system 1 | system 2 | ..... | system N |
685 * | compo1 compo2 ... compoM | compo1 compo2 ... compoM | ..... | compo1 compo2 ... compoM |
687 * Draw points markers and create associated tooltips.
688 * Draw connection segments (intermittent line) between all the curves of a component.
689 * \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.
691 QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( const QList< QList<Plot2d_Curve*> >& sysCoCurveList,
693 const QList< QList<bool> >& sides)
695 //std::cout << "Plot2d_ViewFrame::displayPlot2dCurveList() 1" << std::endl;
698 int nbSystem = sysCoCurveList.size();
700 // Composants number by system
701 int nbComponent = (sysCoCurveList.at(0)).size();
703 // Total number of curves
705 // 1)- Construction of a list by component and by system
707 // | component 1 | component 2 | ..... | component M |
708 // | syst1 syst2 ... systN | syst1 syst2 ... systN | ..... | syst1 syst2 ... systN |
710 QList<Plot2d_Curve*> plot2dCurveCoSysList;
711 QList<bool> sidesList;
712 for (int icom = 0; icom < nbComponent; icom++)
714 for (int isys = 0; isys < nbSystem; isys++)
716 // The system curves list
717 const QList<Plot2d_Curve*>& sysCurveList=sysCoCurveList.at(isys);
718 plot2dCurveCoSysList.append(sysCurveList.at(icom));
720 const QList<bool>& sysSideList=sides.at(isys);
721 sidesList.append(sysSideList.at(icom));
724 // 2)- Display list curves by a component's curves group
725 // Draw connection segments (intermittent line) between the curves
726 QVector< QVector<QwtPlotCurve *> > ret=displayPlot2dCurveList( plot2dCurveCoSysList, nbSystem, displayLegend, sidesList);
727 // 3)- Size of graduations labels and texts under X axis
728 QwtScaleWidget *wid = myPlot->axisWidget( QwtPlot::xBottom);
729 wid->setTitle(" "); // to make the names readable under X axis.
730 QFont xFont = myPlot->axisFont(QwtPlot::xBottom);
731 xFont.setPointSize(8);
732 myPlot->setAxisFont(QwtPlot::xBottom, xFont);
738 * Display list of curves by group of consecutive curves.
740 * Draw points markers and create associated tooltips
741 * Draw connection segments (intermittent line) between the curves
742 * \param [in] sides sorted as in \b curveList. If true->right if false->left
743 * \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.
745 QVector< QVector<QwtPlotCurve *> > Plot2d_ViewFrame::displayPlot2dCurveList( const QList<Plot2d_Curve*>& curveList,
747 bool displayLegend, const QList< bool >& sides)
749 // Consider the new legend's entries
750 // (PB: to update the legend we must remove it and put a new QwtAbstractLegend in the QwtPlot)
751 myPlot->insertLegend( (QwtAbstractLegend*)NULL); // we remove here, we shall put at the end
753 int nbAllCurves = curveList.size();
754 int nbGroups = nbAllCurves / groupSize;
755 QVector< QVector<QwtPlotCurve *> > vectCurve(nbGroups);
757 int icur1, icur2; // curves indices in a group
759 // I)- Compute X range and Y range for all the curves' points of all groups
760 // In the graphic view, set the Y range 's bounds for all groups of curves
762 // For all groups of curves
763 double XallGroupMin=std::numeric_limits<double>::max(), XallGroupMax=-std::numeric_limits<double>::max();
764 double YRightallGroupMin=std::numeric_limits<double>::max(), YRightallGroupMax=-std::numeric_limits<double>::max();
765 double YLeftallGroupMin=std::numeric_limits<double>::max(), YLeftallGroupMax=-std::numeric_limits<double>::max();
767 for (ig=0; ig < nbGroups; ig++) //*1*
769 icur2 = icur1 + groupSize -1;
771 // For all curves in one group
772 double XgroupMin, XgroupMax;
773 double YgroupMin, YgroupMax;
776 double XcurveMin, XcurveMax;
777 double YcurveMin, YcurveMax;
782 // Compute X range and Y range for all the curves' points in the group
784 for (icur=icur1; icur <= icur2; icur++) //*2*
786 Plot2d_Curve *plot2dCurve = curveList.at(icur);
789 nbPoints = plot2dCurve->getData( &Xval, &Yval); // dynamic allocation
791 for (int ip=0; ip < nbPoints; ip++)
793 if (ip == 0) // first point
795 XcurveMin = Xval[ip]; XcurveMax = Xval[ip];
796 YcurveMin = Yval[ip]; YcurveMax = Yval[ip];
800 if (Xval[ip] < XcurveMin) XcurveMin = Xval[ip];
801 else if (Xval[ip] > XcurveMax) XcurveMax = Xval[ip];
802 if (Yval[ip] < YcurveMin) YcurveMin = Yval[ip];
803 else if (Yval[ip] > YcurveMax) YcurveMax = Yval[ip];
809 if (icur == icur1) // first curve
811 XgroupMin = XcurveMin; XgroupMax = XcurveMax;
812 YgroupMin = YcurveMin; YgroupMax = YcurveMax;
816 if (XcurveMin < XgroupMin) XgroupMin = XcurveMin;
817 if (XcurveMax > XgroupMax) XgroupMax = XcurveMax;
818 if (YcurveMin < YgroupMin) YgroupMin = YcurveMin;
819 if (YcurveMax > YgroupMax) YgroupMax = YcurveMax;
823 if (XgroupMin < XallGroupMin) XallGroupMin = XgroupMin;
824 if (XgroupMax > XallGroupMax) XallGroupMax = XgroupMax;
827 if (YgroupMin < YRightallGroupMin) YRightallGroupMin = YgroupMin;
828 if (YgroupMax > YRightallGroupMax) YRightallGroupMax = YgroupMax;
832 if (YgroupMin < YLeftallGroupMin) YLeftallGroupMin = YgroupMin;
833 if (YgroupMax > YLeftallGroupMax) YLeftallGroupMax = YgroupMax;
835 // First curve of the following group
838 // Set the XY range 's bounds for all groups of curves
839 if(YRightallGroupMin!=std::numeric_limits<double>::max())
841 double deltaY = YRightallGroupMax - YRightallGroupMin;
842 YRightallGroupMin-=0.05*deltaY; YRightallGroupMax+= 0.05*deltaY;
843 myPlot->setAxisScale( QwtPlot::yRight, YRightallGroupMin,YRightallGroupMax);
845 if(YLeftallGroupMin!=std::numeric_limits<double>::max())
847 double deltaY = YLeftallGroupMax - YLeftallGroupMin;
848 YLeftallGroupMin-=0.05*deltaY; YLeftallGroupMax+= 0.05*deltaY;
849 myPlot->setAxisScale( QwtPlot::yLeft, YLeftallGroupMin, YLeftallGroupMax);
851 // II)- Drawing curves, points markers and connection segments
854 for (ig=0; ig < nbGroups; ig++)
856 // 1)- Graphical attributs of group's curves
858 // Graphical attributes of the first group's curve
860 Plot2d_Curve *plot2dCurve1 = curveList.at(icur1);
862 QColor color1 = plot2dCurve1->getColor();
863 Plot2d::LineType linetype1 = plot2dCurve1->getLine();
864 int lineWidth1 = plot2dCurve1->getLineWidth();
865 QwtSymbol::Style symbolStyle1 = plot2dCurve1->getMarkerStyle();
866 // We attribute to the current group's curve, the color, the line's kind
867 // and the marker's kind of the first group's curve
869 for (icur=icur1+1; icur<icur1+groupSize; icur++)
871 Plot2d_Curve *plot2dCurve = curveList.at(icur);
873 plot2dCurve->setColor(color1);
874 plot2dCurve->setLine(linetype1,lineWidth1);
875 plot2dCurve->setMarkerStyle(symbolStyle1);
878 // 2)- Display the group's curves
880 for (icur=icur1; icur<icur1+groupSize; icur++)
882 Plot2d_Curve *plot2dCurve = curveList.at(icur);
884 QString title = plot2dCurve->getVerTitle();
885 std::string std_title = title.toStdString();
886 // Create the graphic curve (QwtPlotCurve) et display it in the drawing zone
888 displayCurve(plot2dCurve);
890 // Get the graphic curve
891 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>(getPlotObject(plot2dCurve));
892 vectCurve[ig].push_back(plotCurve);
893 // Modify the points' markers
894 QwtSymbol* symbol = new QwtSymbol(plotCurve->symbol()->style(), plotCurve->symbol()->brush(),
895 plotCurve->symbol()->pen(), plotCurve->symbol()->size()) ;
896 symbol->setStyle(symbolStyle1);
897 symbol->setPen(QPen(color1,lineWidth1));
898 //symbol.setBrush( QBrush( color1));
899 //QSize size = 0.5*(symbol.size());
900 //symbol.setSize(size);
902 plotCurve->setPen(QPen(color1,lineWidth1));
903 plotCurve->setSymbol(symbol);
907 //std::cout << " courbe d'indice " << icur << " sans entree dans la legende" << std::endl;
909 // The curve must not have legend's entry
910 plotCurve->setItemAttribute( QwtPlotItem::Legend, false);
914 plotCurve->setItemAttribute( QwtPlotItem::Legend, true);
918 // 3)- Intermittent segments to connect all the group's curves
925 double Xseg[2], Yseg[2];
926 Plot2d_Curve *plot2dCurve1 = curveList.at(icur1);
927 bool side = sides.at(icur1);
928 // Last point of the first curve
929 nbPoints = plot2dCurve1->getData( &Xval, &Yval); // dynamic allocation
930 Xseg[0] = Xval[ nbPoints -1];
931 Yseg[0] = Yval[ nbPoints -1];
935 for (icur=icur1+1; icur<icur1+groupSize; icur++)
937 Plot2d_Curve *plot2dCurve = curveList.at(icur);
939 // First curve's point
940 nbPoints = plot2dCurve->getData( &Xval, &Yval);
944 vectCurve[ig].push_back(createSegment(Xseg,Yseg,2,Qt::DotLine,lineWidth1,color1,QwtSymbol::NoSymbol,side));
946 // Last curve's point
947 Xseg[0] = Xval[ nbPoints -1];
948 Yseg[0] = Yval[ nbPoints -1];
953 // First curve of the following group
959 // Consider the new legend's entries
960 if(!curveList.empty())
961 showLegend( true, true); // show, update
968 * Create and display an y=f(x) curve of points
970 * toDraw : true => Display the created curve
971 * Draw the points'markers and create associated tooltips
973 Plot2d_Curve* Plot2d_ViewFrame::createPlot2dCurve( QString & title,
975 QList<double> & xList,
976 QList<double> & yList,
977 QList<QString> & tooltipList,
978 Plot2d::LineType lineKind,
981 QwtSymbol::Style markerKind,
982 Plot2d_QwtPlotPicker* picker,
986 //std::cout << "Plot2d_ViewFrame::createPlot2dCurve()" << std::endl;
988 // Mathematical curve
989 Plot2d_Curve* plot2dCurve = new Plot2d_Curve();
991 // To deallocate in EraseAll()
992 myPlot2dCurveList.append( plot2dCurve);
994 int nbPoint = xList.size();
998 for (int ip=0; ip < nbPoint; ip++)
1000 xVal = xList.at(ip);
1001 yVal = yList.at(ip);
1002 tooltip = tooltipList.at(ip);
1004 plot2dCurve->addPoint( xVal, yVal, tooltip);
1007 plot2dCurve->setVerTitle( title);
1008 plot2dCurve->setVerUnits( unit);
1009 if (lineColor.isValid())
1011 plot2dCurve->setColor( lineColor);
1013 plot2dCurve->setLine( lineKind, lineWidth);
1014 plot2dCurve->setMarkerStyle( markerKind);
1015 plot2dCurve->setMarkerSize(1);
1017 // Graphical curve (QwtPlotCurve) in the drawing zone (QwtPlot) myPlot
1022 myPlot->insertLegend( (QwtAbstractLegend*)NULL);
1024 displayCurve( plot2dCurve);
1026 // Get the graphical curve
1027 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>( getPlotObject( plot2dCurve));
1031 if (lineColor.isValid())
1033 //std::cout << " valid color" << std::endl;
1034 theColor = lineColor;
1038 //std::cout << " valid color" << std::endl;
1039 QPen pen = plotCurve->pen();
1040 theColor = pen.color();
1043 // Modify points' markers
1044 QwtSymbol* symbol = new QwtSymbol( plotCurve->symbol()->style(), plotCurve->symbol()->brush(),
1045 plotCurve->symbol()->pen(), plotCurve->symbol()->size() ) ;
1046 symbol->setStyle( markerKind );
1048 if (markerKind != QwtSymbol::NoSymbol)
1050 symbol->setPen( QPen( theColor, lineWidth));
1051 symbol->setBrush( QBrush( theColor));
1052 QSize size = 2.0*(symbol->size()); //0.5
1053 symbol->setSize(size);
1056 plotCurve->setSymbol( symbol);
1057 plotCurve->setStyle( QwtPlotCurve::Lines);
1058 plotCurve->setPen( QPen( theColor, lineWidth));
1060 // The curve must not have legend's entry
1061 plotCurve->setItemAttribute( QwtPlotItem::Legend, false);
1070 QColor Plot2d_ViewFrame::getPlot2dCurveColor( Plot2d_Curve* plot2dCurve)
1073 // Get graphical curve
1074 QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve *>( getPlotObject( plot2dCurve));
1076 QPen pen = plotCurve->pen();
1077 QColor color = pen.color();
1084 * Create and display a segment with nbPoint=2 points
1086 QwtPlotCurve *Plot2d_ViewFrame::createSegment( double *X, double *Y, int nbPoint,
1087 Qt::PenStyle lineKind,
1090 QwtSymbol::Style markerKind, bool side)
1092 QwtPlotCurve* aPCurve = new QwtPlotCurve( QString::null );
1094 aPCurve->setSamples( X, Y, nbPoint);
1096 aPCurve->setPen( QPen( lineColor, lineWidth, lineKind));
1097 QwtSymbol* aSymbol = new QwtSymbol();
1098 aSymbol->setStyle( markerKind );
1099 aPCurve->setSymbol( aSymbol );
1101 // The segment must not have legend's entry
1102 aPCurve->setItemAttribute( QwtPlotItem::Legend, false);
1104 aPCurve->attach(myPlot);
1105 aPCurve->setYAxis(side ? QwtPlot::yRight : QwtPlot::yLeft);
1106 // To deallocate in EraseAll()
1107 myIntermittentSegmentList.append(aPCurve);
1112 Adds curve into view
1114 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
1116 QwtPlotItem* anItem = displayObject( curve, update );
1117 // To deallocate in EraseAll()
1118 myQwtPlotCurveList.append( anItem);
1122 Adds curves into view
1124 void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
1127 foreach ( Plot2d_Curve* curve, curves )
1129 displayObjects( objects, update );
1135 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
1137 eraseObject( curve, update );
1143 void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
1146 foreach ( Plot2d_Curve* curve, curves )
1148 eraseObjects( objects, update );
1152 Updates curves attributes
1154 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
1156 updateObject( curve, update );
1159 void Plot2d_ViewFrame::processFiltering(bool update)
1161 CurveDict aCurves = getCurves();
1162 AlgoPlot2dInputData aLData, aRData;
1163 CurveDict::iterator it;
1164 for ( it = aCurves.begin(); it != aCurves.end(); it++ ) {
1165 Plot2d_Object* objItem = it.value();
1166 if (objItem->getYAxis() == QwtPlot::yRight)
1167 aRData.append(objItem);
1169 aLData.append(objItem);
1172 // Normalization by left Y axis
1173 if (!myNormLMin && !myNormLMax)
1174 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
1175 if(myNormLMin && myNormLMax)
1176 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
1178 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
1180 myLNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMax);
1182 myLNormAlgo->setInput(aLData);
1183 myLNormAlgo->execute();
1185 // Normalization by right Y axis
1186 if (!myNormRMin && !myNormRMax)
1187 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeNone);
1188 if(myNormRMin && myNormRMax)
1189 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMinMax);
1191 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMin);
1193 myRNormAlgo->setNormalizationMode(Plot2d_NormalizeAlgorithm::NormalizeToMax);
1195 myRNormAlgo->setInput(aRData);
1196 myRNormAlgo->execute();
1198 for ( it = aCurves.begin(); it != aCurves.end(); it++) {
1199 QwtPlotCurve* item = it.key();
1200 Plot2d_Object* objItem = it.value();
1201 updatePlotItem(objItem, item);
1208 Gets lsit of displayed curves
1210 int Plot2d_ViewFrame::getCurves( curveList& curves ) const
1214 CurveDict aCurves = getCurves();
1215 CurveDict::iterator it;
1216 for ( it = aCurves.begin(); it != aCurves.end(); it++ )
1217 curves << it.value();
1218 return curves.count();
1221 CurveDict Plot2d_ViewFrame::getCurves() const
1224 ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end();
1225 for ( ; it != aLast; it++ ) {
1226 QwtPlotItem* anItem = it.key();
1227 if ( anItem && anItem->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
1228 QwtPlotCurve* aPCurve = dynamic_cast<QwtPlotCurve*>( anItem );
1229 Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( it.value() );
1230 if ( aPCurve && aCurve )
1231 curves.insert( aPCurve, aCurve );
1238 Adds object into view
1240 QwtPlotItem* Plot2d_ViewFrame::displayObject( Plot2d_Object* object, bool update )
1242 QwtPlotItem* anItem = 0;
1246 if ( object->getYAxis() == QwtPlot::yRight )
1249 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
1250 // it crashes if switched to X/Y logarithmic mode, when one or more points have
1251 // non-positive X/Y coordinate
1252 if ( myXMode && object->getMinX() <= 0. )
1253 setHorScaleMode( 0, false );
1254 if ( myYMode && object->getMinY() <= 0. )
1255 setVerScaleMode( 0, false );
1257 if ( object->isAutoAssign() )
1258 object->autoFill( myPlot );
1260 if ( hasPlotObject( object ) ) {
1261 processFiltering(update);
1262 updateObject( object, update );
1265 anItem = object->createPlotItem();
1266 anItem->attach( myPlot );
1267 myObjects.insert( anItem, object );
1268 //myPlot->setCurveYAxis(curveKey, curve->getYAxis());
1270 if ( object->rtti() == QwtPlotItem::Rtti_PlotCurve )
1272 Plot2d_Curve* aCurve = dynamic_cast<Plot2d_Curve*>( object );
1275 if ( aCurve->getMarkerSize() == 0 )
1276 aCurve->setMarkerSize( myMarkerSize );
1278 processFiltering(update);
1279 updatePlotItem( aCurve, anItem );
1280 setCurveType( getPlotCurve( aCurve ), myCurveType );
1284 updateTitles( false );
1285 myPlot->updateYAxisIdentifiers();
1288 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1294 Adds objects into view
1296 void Plot2d_ViewFrame::displayObjects( const objectList& objects, bool update )
1298 //myPlot->setUpdatesEnabled( false ); // call this function deprecate update of legend
1299 foreach ( Plot2d_Object* object, objects )
1300 displayObject( object, false );
1302 //myPlot->setUpdatesEnabled( true );
1311 void Plot2d_ViewFrame::eraseObject( Plot2d_Object* object, bool update )
1316 if ( hasPlotObject( object ) ) {
1317 QwtPlotItem* anObject = getPlotObject( object );
1318 eraseBasicObject(anObject,update);
1321 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1325 void Plot2d_ViewFrame::eraseBasicObject( QwtPlotItem *object, bool update )
1331 myObjects.remove(object);
1332 updateTitles(update);
1333 myPlot->updateYAxisIdentifiers();
1341 void Plot2d_ViewFrame::eraseObjects( const objectList& objects, bool update )
1343 foreach ( Plot2d_Object* object, objects )
1344 eraseObject( object, false );
1349 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1352 void Plot2d_ViewFrame::eraseBasicObjects( const QList<QwtPlotItem*> &objects, bool update)
1354 foreach ( QwtPlotItem* object, objects )
1355 eraseBasicObject( object, false );
1359 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1363 Updates objects attributes
1365 void Plot2d_ViewFrame::updateObject( Plot2d_Object* object, bool update )
1369 if ( hasPlotObject( object ) ) {
1370 QwtPlotItem* anItem = getPlotObject( object );
1373 updatePlotItem(object, anItem );
1374 anItem->setVisible( true );
1377 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1383 Gets lsit of displayed curves
1385 int Plot2d_ViewFrame::getObjects( objectList& objects ) const
1389 ObjectDict::const_iterator it;
1390 for ( it = myObjects.begin(); it != myObjects.end(); it++ )
1391 objects << it.value();
1392 return objects.count();
1396 Returns true if the curve is visible
1398 bool Plot2d_ViewFrame::isVisible( Plot2d_Object* object ) const
1400 return object && hasPlotObject( object ) && getPlotObject( object )->isVisible();
1406 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
1408 if ( !prs || prs->IsNull() )
1411 ObjectDict::iterator it = myObjects.begin();
1412 Plot2d_Object* anObj;
1413 for (; it != myObjects.end(); ++it ) {
1415 if ( hasPlotObject( anObj ) )
1416 getPlotObject( anObj )->setTitle( !anObj->getName().isEmpty() ?
1417 anObj->getName() : anObj->getVerTitle() );
1424 void Plot2d_ViewFrame::updateLegend() {
1425 const QwtPlotItemList& items = myPlot->itemList();
1426 QwtPlotItemIterator it;
1427 for ( it = items.begin(); it != items.end(); it++ ) {
1428 QwtPlotItem* item = *it;
1430 item->updateLegend( item, item->legendData() );
1436 Fits the view to see all data
1438 void Plot2d_ViewFrame::fitAll()
1440 // no need to set auto scaling, it will be disabled by setAxisScale() method call
1441 // myPlot->setAxisAutoScale( QwtPlot::yLeft );
1442 // myPlot->setAxisAutoScale( QwtPlot::xBottom );
1443 // myPlot->replot();
1445 double xmin, xmax, y1min, y1max, y2min, y2max;
1446 getFitRangeByCurves(xmin, xmax, y1min, y1max, y2min, y2max);
1447 getFitRangeByMarkers(xmin, xmax, y1min, y1max, y2min, y2max);
1449 myPlot->setAxisScale( QwtPlot::xBottom, xmin, xmax );
1450 myPlot->setAxisScale( QwtPlot::yLeft, y1min, y1max );
1453 myPlot->setAxisAutoScale( QwtPlot::yRight );
1455 myPlot->setAxisScale( QwtPlot::yRight, y2min, y2max );
1458 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(false);
1462 Fits the view to rectangle area (pixels)
1464 void Plot2d_ViewFrame::fitArea( const QRect& area )
1466 QRect rect = area.normalized();
1467 if ( rect.width() < MIN_RECT_SIZE ) {
1468 rect.setWidth( MIN_RECT_SIZE );
1469 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
1471 if ( rect.height() < MIN_RECT_SIZE ) {
1472 rect.setHeight( MIN_RECT_SIZE );
1473 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
1475 myPlot->setAxisScale( QwtPlot::yLeft,
1476 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
1477 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
1479 myPlot->setAxisScale( QwtPlot::yRight,
1480 myPlot->invTransform( QwtPlot::yRight, rect.top() ),
1481 myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
1482 myPlot->setAxisScale( QwtPlot::xBottom,
1483 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
1484 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
1486 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1490 "Fit Data" command for TUI interface
1492 void Plot2d_ViewFrame::fitData(const int mode,
1493 const double xMin, const double xMax,
1494 const double yMin, const double yMax,
1495 double y2Min, double y2Max)
1497 if ( mode == 0 || mode == 2 ) {
1498 myPlot->setAxisScale( QwtPlot::yLeft, yMin, yMax );
1500 myPlot->setAxisScale( QwtPlot::yRight, y2Min, y2Max );
1502 if ( mode == 0 || mode == 1 )
1503 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
1505 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
1509 Gets current fit ranges for view frame
1511 void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax,
1512 double& yMin, double& yMax,
1513 double& y2Min, double& y2Max)
1515 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).transform( myPlot->canvasMap( QwtPlot::xBottom ).s1() );
1516 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).transform( myPlot->canvasMap( QwtPlot::xBottom ).s2() );
1517 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).transform( myPlot->canvasMap( QwtPlot::yLeft ).s1() );
1518 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).transform( myPlot->canvasMap( QwtPlot::yLeft ).s2() );
1519 xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
1520 xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
1521 yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
1522 yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
1526 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).transform( myPlot->canvasMap( QwtPlot::yRight ).s1() );
1527 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).transform( myPlot->canvasMap( QwtPlot::yRight ).s2() );
1528 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
1529 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
1534 Gets current fit ranges by Curves
1536 void Plot2d_ViewFrame::getFitRangeByCurves(double& xMin, double& xMax,
1537 double& yMin, double& yMax,
1538 double& y2Min, double& y2Max)
1540 bool emptyV1 = true, emptyV2 = true;
1541 if ( !myObjects.isEmpty() ) {
1542 ObjectDict::const_iterator it = myObjects.begin();
1543 for ( ; it != myObjects.end(); it++ ) {
1544 bool isV2 = it.value()->getYAxis() == QwtPlot::yRight;
1545 if ( !it.value()->isEmpty() ) {
1546 if ( emptyV1 && emptyV2 ) {
1558 isV2 ? emptyV2 = false : emptyV1 = false;
1559 xMin = qMin( xMin, it.value()->getMinX() );
1560 xMax = qMax( xMax, it.value()->getMaxX() );
1562 y2Min = qMin( y2Min, it.value()->getMinY() );
1563 y2Max = qMax( y2Max, it.value()->getMaxY() );
1566 yMin = qMin( yMin, it.value()->getMinY() );
1567 yMax = qMax( yMax, it.value()->getMaxY() );
1571 if ( xMin == xMax ) {
1572 xMin = xMin == 0. ? -1. : xMin - xMin/10.;
1573 xMax = xMax == 0. ? 1. : xMax + xMax/10.;
1575 if ( yMin == yMax ) {
1576 yMin = yMin == 0. ? -1. : yMin - yMin/10.;
1577 yMax = yMax == 0. ? 1 : yMax + yMax/10.;
1579 if ( y2Min == y2Max ) {
1580 y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
1581 y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
1585 if ( emptyV1 && emptyV2 ) {
1586 xMin = isModeHorLinear() ? 0. : 1.;
1587 xMax = isModeHorLinear() ? 1000. : 1e5;
1590 yMin = isModeVerLinear() ? 0. : 1.;
1591 yMax = isModeVerLinear() ? 1000. : 1e5;
1594 y2Min = isModeVerLinear() ? 0. : 1.;
1595 y2Max = isModeVerLinear() ? 1000. : 1e5;
1600 Gets current fit ranges by Markers
1601 All parameters are inout.
1603 void Plot2d_ViewFrame::getFitRangeByMarkers(double& xMin, double& xMax,
1604 double& yMin, double& yMax,
1605 double& y2Min, double& y2Max)
1607 Plot2d_QwtPlotPicker *picker=myPlot->getPicker();
1610 if(picker->pMarkers.empty())
1612 foreach(QwtPlotMarker *mrker,picker->pMarkers)
1614 bool isV2 = mrker->yAxis() == QwtPlot::yRight;
1615 xMin = qMin( xMin, mrker->xValue() );
1616 xMax = qMax( xMax, mrker->xValue() );
1618 y2Min = qMin( y2Min, mrker->yValue() );
1619 y2Max = qMax( y2Max, mrker->yValue() );
1622 yMin = qMin( yMin, mrker->yValue() );
1623 yMax = qMax( yMax, mrker->yValue() );
1625 if ( xMin == xMax ) {
1626 xMin = xMin == 0. ? -1. : xMin - xMin/10.;
1627 xMax = xMax == 0. ? 1. : xMax + xMax/10.;
1629 if ( yMin == yMax ) {
1630 yMin = yMin == 0. ? -1. : yMin - yMin/10.;
1631 yMax = yMax == 0. ? 1 : yMax + yMax/10.;
1633 if ( y2Min == y2Max ) {
1634 y2Min = y2Min == 0. ? -1. : y2Min - y2Min/10.;
1635 y2Max = y2Max == 0. ? 1 : y2Max + y2Max/10.;
1641 Tests if it is necessary to start operation on mouse action
1643 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
1645 int btn = me.button() | me.modifiers();
1646 const int zoomBtn = Qt::ControlModifier | Qt::LeftButton;
1647 const int panBtn = Qt::ControlModifier | Qt::MidButton;
1648 const int fitBtn = Qt::ControlModifier | Qt::RightButton;
1651 if ( btn == zoomBtn ) {
1652 QPixmap zoomPixmap (imageZoomCursor);
1653 QCursor zoomCursor (zoomPixmap);
1654 myPlot->canvas()->setCursor( zoomCursor );
1657 else if ( btn == panBtn ) {
1658 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
1661 else if ( btn == fitBtn ) {
1662 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1669 "Settings" toolbar action slot
1671 void Plot2d_ViewFrame::onSettings()
1673 #ifdef TEST_AUTOASSIGN
1674 typedef QMap<int,int> IList;
1675 typedef QMap<QString,int> SList;
1678 cols[ "red-min" ] = 1000;
1679 cols[ "red-max" ] = -1;
1680 cols[ "green-min" ] = 1000;
1681 cols[ "green-max" ] = -1;
1682 cols[ "blue-min" ] = 1000;
1683 cols[ "blue-max" ] = -1;
1684 for ( unsigned i = 0; i < 10000; i++ ) {
1685 QwtSymbol::Style typeMarker;
1687 Qt::PenStyle typeLine;
1688 myPlot->getNextMarker( typeMarker, color, typeLine );
1689 if ( mars.contains(typeMarker) )
1690 mars[ typeMarker ] = mars[ typeMarker ]+1;
1692 mars[ typeMarker ] = 0;
1693 if ( lins.contains(typeLine) )
1694 lins[ typeLine ] = lins[ typeLine ]+1;
1696 lins[ typeLine ] = 0;
1697 if ( cols[ "red-max" ] < color.red() )
1698 cols[ "red-max" ] = color.red();
1699 if ( cols[ "red-min" ] > color.red() )
1700 cols[ "red-min" ] = color.red();
1701 if ( cols[ "green-max" ] < color.green() )
1702 cols[ "green-max" ] = color.green();
1703 if ( cols[ "green-min" ] > color.green() )
1704 cols[ "green-min" ] = color.green();
1705 if ( cols[ "blue-max" ] < color.blue() )
1706 cols[ "blue-max" ] = color.blue();
1707 if ( cols[ "blue-min" ] > color.blue() )
1708 cols[ "blue-min" ] = color.blue();
1712 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
1713 dlg->setMainTitle( myTitleEnabled, myTitle );
1714 dlg->setXTitle( myXTitleEnabled, myXTitle );
1715 dlg->setYTitle( myYTitleEnabled, myYTitle );
1717 dlg->setY2Title( myY2TitleEnabled, myY2Title );
1718 dlg->setCurveType( myCurveType );
1719 dlg->setLegend( myShowLegend, myLegendPos, myLegendSymbolType, myLegendFont,
1720 myLegendColor, mySelectedLegendFontColor );
1721 dlg->setMarkerSize( myMarkerSize );
1722 dlg->setBackgroundColor( myBackground );
1723 dlg->setSelectionColor( mySelectionColor );
1724 dlg->setScaleMode(myXMode, myYMode);
1725 dlg->setLMinNormMode(myNormLMin);
1726 dlg->setLMaxNormMode(myNormLMax);
1727 dlg->setRMinNormMode(myNormRMin);
1728 dlg->setRMaxNormMode(myNormRMax);
1730 QVariant v = myPlot->property(PLOT2D_DEVIATION_LW);
1731 int lw = v.isValid() ? v.toInt() : 1;
1733 v = myPlot->property(PLOT2D_DEVIATION_TS);
1734 int ts = v.isValid() ? v.toInt() : 2;
1736 v = myPlot->property(PLOT2D_DEVIATION_COLOR);
1737 QColor cl = v.isValid() ? v.value<QColor>() : QColor(255,0,0);
1739 dlg->setDeviationMarkerLw(lw);
1740 dlg->setDeviationMarkerTs(ts);
1741 dlg->setDeviationMarkerCl(cl);
1744 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
1745 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
1746 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
1747 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
1748 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
1749 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
1750 if ( dlg->exec() == QDialog::Accepted ) {
1751 // horizontal axis title
1752 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
1753 // vertical left axis title
1754 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
1755 if (mySecondY) // vertical right axis title
1756 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
1759 if( dlg->isMainTitleEnabled() && myTitle != dlg->getMainTitle() )
1760 myIsDefTitle = false;
1761 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
1763 if ( myCurveType != dlg->getCurveType() ) {
1764 setCurveType( dlg->getCurveType(), false );
1767 if ( myShowLegend != dlg->isLegendEnabled() ) {
1768 showLegend( dlg->isLegendEnabled(), false );
1770 if ( myLegendPos != dlg->getLegendPos() ) {
1771 setLegendPos( dlg->getLegendPos() );
1773 if ( myLegendSymbolType != dlg->getLegendSymbolType() ) {
1774 setLegendSymbolType( dlg->getLegendSymbolType() );
1776 if ( myLegendFont != dlg->getLegendFont() ) {
1777 setLegendFont( dlg->getLegendFont() );
1779 if ( myLegendColor != dlg->getLegendColor() ) {
1780 setLegendFontColor( dlg->getLegendColor() );
1782 if ( mySelectedLegendFontColor != dlg->getSelectedLegendColor() ) {
1783 setSelectedLegendFontColor( dlg->getSelectedLegendColor() );
1787 if ( myMarkerSize != dlg->getMarkerSize() ) {
1788 setMarkerSize( dlg->getMarkerSize(), false );
1791 if ( myBackground != dlg->getBackgroundColor() ) {
1792 setBackgroundColor( dlg->getBackgroundColor() );
1795 if ( mySelectionColor != dlg->getSelectionColor() ) {
1796 setSelectionColor( dlg->getSelectionColor() );
1799 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
1800 aY2GridMajorEnabled, aY2GridMinorEnabled;
1801 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
1802 aY2GridMaxMajor, aY2GridMaxMinor;
1803 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
1804 aY2GridMajorEnabled, aY2GridMaxMajor);
1805 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
1806 aY2GridMinorEnabled, aY2GridMaxMinor);
1807 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
1808 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
1809 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
1810 if ( myXMode != dlg->getXScaleMode() ) {
1811 setHorScaleMode( dlg->getXScaleMode() );
1813 if ( myYMode != dlg->getYScaleMode() ) {
1814 setVerScaleMode( dlg->getYScaleMode() );
1816 if ( myNormLMin != dlg->getLMinNormMode() ) {
1817 setNormLMinMode( dlg->getLMinNormMode() );
1819 if ( myNormLMax != dlg->getLMaxNormMode() ) {
1820 setNormLMaxMode( dlg->getLMaxNormMode() );
1822 if ( myNormRMin != dlg->getRMinNormMode() ) {
1823 setNormRMinMode( dlg->getRMinNormMode() );
1825 if ( myNormRMax != dlg->getRMaxNormMode() ) {
1826 setNormRMaxMode( dlg->getRMaxNormMode() );
1829 myPlot->setProperty(PLOT2D_DEVIATION_COLOR,
1830 dlg->getDeviationMarkerCl());
1831 myPlot->setProperty(PLOT2D_DEVIATION_LW,
1832 dlg->getDeviationMarkerLw());
1833 myPlot->setProperty(PLOT2D_DEVIATION_TS,
1834 dlg->getDeviationMarkerTs());
1839 // update preferences
1840 if ( dlg->isSetAsDefault() )
1846 #ifndef NO_ANALYTICAL_CURVES
1848 "Analytical Curves" toolbar action slot
1850 void Plot2d_ViewFrame::onAnalyticalCurve()
1852 Plot2d_AnalyticalCurveDlg dlg( this, this );
1854 updateAnalyticalCurves();
1857 void Plot2d_ViewFrame::addAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
1859 myAnalyticalCurves.append(theCurve);
1862 void Plot2d_ViewFrame::removeAnalyticalCurve( Plot2d_AnalyticalCurve* theCurve)
1864 theCurve->setAction(Plot2d_AnalyticalCurve::ActRemoveFromView);
1868 Update Analytical curve
1870 void Plot2d_ViewFrame::updateAnalyticalCurve(Plot2d_AnalyticalCurve* c, bool updateView)
1873 QwtScaleDiv div = myPlot->axisScaleDiv(QwtPlot::xBottom);
1874 c->setRangeBegin(div.lowerBound());
1875 c->setRangeEnd(div.upperBound());
1877 c->setMarkerSize(myMarkerSize);
1878 QwtPlotItem* item = c->plotItem();
1880 switch( c->getAction() ) {
1881 case Plot2d_AnalyticalCurve::ActAddInView:
1882 if( c->isActive() ) {
1883 c->updatePlotItem();
1884 item->attach( myPlot );
1885 item->itemChanged();
1888 c->setAction(Plot2d_AnalyticalCurve::ActNothing);
1891 case Plot2d_AnalyticalCurve::ActUpdateInView:
1893 c->updatePlotItem();
1900 c->setAction(Plot2d_AnalyticalCurve::ActNothing);
1902 case Plot2d_AnalyticalCurve::ActRemoveFromView:
1905 myAnalyticalCurves.removeAll(c);
1915 Update Analytical curves
1917 void Plot2d_ViewFrame::updateAnalyticalCurves()
1919 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
1920 for( ; it != myAnalyticalCurves.end(); it++) {
1921 updateAnalyticalCurve(*it);
1927 Return list of the alalytical curves.
1929 AnalyticalCurveList Plot2d_ViewFrame::getAnalyticalCurves() const
1931 return myAnalyticalCurves;
1935 Get analytical curve by plot item.
1937 Plot2d_AnalyticalCurve* Plot2d_ViewFrame::getAnalyticalCurve(QwtPlotItem * theItem) {
1938 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
1939 for( ; it != myAnalyticalCurves.end(); it++) {
1940 if((*it)->plotItem() == theItem);
1948 "Fit Data" command slot
1950 void Plot2d_ViewFrame::onFitData()
1952 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
1953 double xMin,xMax,yMin,yMax,y2Min,y2Max;
1954 getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
1956 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1957 if ( dlg->exec() == QDialog::Accepted ) {
1958 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1959 fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max);
1962 #ifndef NO_ANALYTICAL_CURVES
1963 updateAnalyticalCurves();
1968 Change background color
1970 void Plot2d_ViewFrame::onChangeBackground()
1972 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1973 if ( selColor.isValid() ) {
1974 setBackgroundColor( selColor );
1981 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1983 myCurveType = curveType;
1984 CurveDict aCurves = getCurves();
1985 CurveDict::iterator it = aCurves.begin();
1986 for ( ; it != aCurves.end(); it++ ) {
1987 QwtPlotCurve* crv = it.key();
1989 setCurveType( crv, myCurveType );
1993 emit vpCurveChanged();
1999 int Plot2d_ViewFrame::getCurveType() const
2006 \param curveKey - curve id
2007 \param title - new title
2009 void Plot2d_ViewFrame::setCurveTitle( Plot2d_Curve* curve, const QString& title )
2011 setObjectTitle( curve, title );
2016 \param object - object id
2017 \param title - new title
2019 void Plot2d_ViewFrame::setObjectTitle( Plot2d_Object* object, const QString& title )
2021 if ( object && hasPlotObject( object ) )
2022 getPlotObject( object )->setTitle( title );
2028 void Plot2d_ViewFrame::showLegend( bool show, bool update )
2030 myShowLegend = show;
2031 if ( myShowLegend ) {
2032 QwtAbstractLegend* absLegend = myPlot->legend();
2033 QwtLegend* legend = 0;
2035 legend = new Plot2d_QwtLegend( myPlot );
2036 legend->setDefaultItemMode(QwtLegendData::Clickable);
2037 connect( legend, SIGNAL( clicked (const QVariant&, int) ),
2038 this, SIGNAL( clicked (const QVariant&, int) ) );
2039 legend->setFrameStyle( QFrame::Box | QFrame::Sunken );
2042 legend = dynamic_cast<QwtLegend*>(absLegend);
2045 myPlot->insertLegend( legend );
2046 setLegendPos( myLegendPos );
2047 setLegendFont( myLegendFont );
2048 setLegendFontColor( myLegendColor );
2052 myPlot->insertLegend( 0 );
2054 if( show && update )
2062 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
2064 void Plot2d_ViewFrame::setLegendPos( int pos )
2067 QwtAbstractLegend* legend = myPlot->legend();
2071 myPlot->insertLegend( legend, QwtPlot::LeftLegend );
2074 myPlot->insertLegend( legend, QwtPlot::RightLegend );
2077 myPlot->insertLegend( legend, QwtPlot::TopLegend );
2080 myPlot->insertLegend( legend, QwtPlot::BottomLegend );
2087 Gets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
2089 int Plot2d_ViewFrame::getLegendPos() const
2095 Sets legend symbol type : 0 - marker on line, 1 - marker above line
2097 void Plot2d_ViewFrame::setLegendSymbolType( int type )
2099 myLegendSymbolType = type;
2100 myPlot->setLegendSymbolType( type );
2105 Gets legend symbol type : 0 - marker on line, 1 - marker above line
2107 int Plot2d_ViewFrame::getLegendSymbolType() const
2109 return myLegendSymbolType;
2115 void Plot2d_ViewFrame::setLegendFont( const QFont& fnt )
2118 QwtAbstractLegend* legend = myPlot->legend();
2120 legend->setFont(fnt);
2127 QFont Plot2d_ViewFrame::getLegendFont() const
2129 return myLegendFont;
2133 Sets legend font color
2135 void Plot2d_ViewFrame::setLegendFontColor( const QColor& col )
2137 myLegendColor = col;
2138 QwtAbstractLegend* legend = myPlot->legend();
2140 QPalette pal = legend->palette();
2141 pal.setColor( QPalette::Text, col );
2142 legend->setPalette( pal );
2147 Gets legend font color
2149 QColor Plot2d_ViewFrame::getLegendFontColor() const
2151 return myLegendColor;
2155 Sets selected legend font color
2157 void Plot2d_ViewFrame::setSelectedLegendFontColor( const QColor& col )
2159 mySelectedLegendFontColor = col;
2160 Plot2d_Object::setHighlightedLegendTextColor( col );
2164 Gets selected legend font color
2166 QColor Plot2d_ViewFrame::getSelectedLegendFontColor() const
2168 return mySelectedLegendFontColor;
2172 Sets new marker size
2174 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
2176 if ( myMarkerSize != size )
2178 myMarkerSize = size;
2179 CurveDict aCurves = getCurves();
2180 CurveDict::iterator it = aCurves.begin();
2181 for ( ; it != aCurves.end(); it++ ) {
2182 QwtPlotCurve* crv = it.key();
2185 QwtSymbol* aSymbol = new QwtSymbol( crv->symbol()->style(), crv->symbol()->brush(),
2186 crv->symbol()->pen(), QSize( myMarkerSize, myMarkerSize ) );
2187 crv->setSymbol( aSymbol );
2189 it.value()->setMarkerSize( myMarkerSize );
2198 Gets new marker size
2200 int Plot2d_ViewFrame::getMarkerSize() const
2202 return myMarkerSize;
2206 Sets background color
2208 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
2210 myBackground = color;
2211 myPlot->canvas()->setPalette( myBackground );
2212 myPlot->setPalette( myBackground );
2213 if ( myPlot->getLegend() ) {
2214 QPalette aPal = myPlot->getLegend()->palette();
2215 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
2216 aPal.setColor( QPalette::Base, myBackground );
2217 aPal.setColor( QPalette::Background, myBackground );
2219 myPlot->getLegend()->setPalette( aPal );
2226 Gets background color
2228 QColor Plot2d_ViewFrame::backgroundColor() const
2230 return myBackground;
2234 Sets selection color
2236 void Plot2d_ViewFrame::setSelectionColor( const QColor& color )
2238 mySelectionColor = color;
2239 Plot2d_Object::setSelectionColor( color );
2243 Gets selection color
2245 QColor Plot2d_ViewFrame::selectionColor() const
2247 return mySelectionColor;
2251 Sets hor.axis grid parameters
2253 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
2254 bool xMinorEnabled, const int xMinorMax,
2257 myXGridMajorEnabled = xMajorEnabled;
2258 myXGridMinorEnabled = xMinorEnabled;
2259 myXGridMaxMajor = xMajorMax;
2260 myXGridMaxMinor = xMinorMax;
2262 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
2263 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
2265 QwtPlotGrid* grid = myPlot->grid();
2266 if ( !myPlot->axisScaleDiv( QwtPlot::xBottom ).isEmpty() )
2267 grid->setXDiv( myPlot->axisScaleDiv( QwtPlot::xBottom ) );
2268 grid->enableX( myXGridMajorEnabled );
2269 grid->enableXMin( myXGridMinorEnabled );
2275 Sets ver.axis grid parameters
2277 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
2278 bool yMinorEnabled, const int yMinorMax,
2279 bool y2MajorEnabled, const int y2MajorMax,
2280 bool y2MinorEnabled, const int y2MinorMax,
2283 myYGridMajorEnabled = yMajorEnabled;
2284 myYGridMinorEnabled = yMinorEnabled;
2285 myYGridMaxMajor = yMajorMax;
2286 myYGridMaxMinor = yMinorMax;
2289 myY2GridMajorEnabled = y2MajorEnabled;
2290 myY2GridMinorEnabled = y2MinorEnabled;
2291 myY2GridMaxMajor = y2MajorMax;
2292 myY2GridMaxMinor = y2MinorMax;
2294 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
2295 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
2298 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
2299 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
2302 QwtPlotGrid* grid = myPlot->grid();
2303 if ( !myPlot->axisScaleDiv( QwtPlot::yLeft ).isEmpty() )
2304 grid->setYDiv( myPlot->axisScaleDiv( QwtPlot::yLeft ) );
2307 if (myYGridMajorEnabled) {
2308 grid->enableY( myYGridMajorEnabled );
2309 grid->enableYMin( myYGridMinorEnabled );
2311 else if (myY2GridMajorEnabled) {
2312 if ( !myPlot->axisScaleDiv( QwtPlot::yRight ).isEmpty() )
2313 grid->setYDiv( myPlot->axisScaleDiv( QwtPlot::yRight ) );
2314 grid->enableY( myY2GridMajorEnabled );
2315 grid->enableYMin( myY2GridMinorEnabled );
2318 grid->enableY( false );
2319 grid->enableYMin( false );
2323 grid->enableY( myYGridMajorEnabled );
2324 grid->enableYMin( myYGridMinorEnabled );
2331 Sets title for some axis
2333 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
2334 ObjectType type, bool update )
2338 myTitleEnabled = enabled;
2340 myPlot->setTitle( myTitleEnabled ? myTitle : QString() );
2343 myXTitleEnabled = enabled;
2345 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString() );
2348 myYTitleEnabled = enabled;
2350 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString() );
2353 myY2TitleEnabled = enabled;
2355 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString() );
2364 Sets title for some axis
2366 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
2371 title = myTitle; break;
2373 title = myXTitle; break;
2375 title = myYTitle; break;
2377 title = myY2Title; break;
2384 Sets font for Plot2d object : title or axis
2386 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
2390 myPlot->title().setFont(font);
2393 myPlot->axisTitle(QwtPlot::xBottom).setFont(font); break;
2395 myPlot->axisTitle(QwtPlot::yLeft).setFont(font); break;
2397 myPlot->axisTitle(QwtPlot::yRight).setFont(font); break;
2399 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
2401 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
2403 myPlot->setAxisFont(QwtPlot::yRight, font); break;
2410 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
2412 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
2414 if ( myXMode == mode )
2417 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
2418 // it crashes if switched to X/Y logarithmic mode, when one or more points have
2419 // non-positive X/Y coordinate
2420 if ( mode && !isXLogEnabled() ){
2422 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
2424 QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_XLOG_NOT_ALLOWED"));
2431 // set bounds of logarithmic scale
2432 if( myXMode != 0 ) {
2433 myPlot->setAxisScale( QwtPlot::xBottom, 1.0, 1e5 );
2434 myPlot->updateAxes();
2437 myPlot->setLogScale(QwtPlot::xBottom, myXMode != 0);
2441 emit vpModeHorChanged();
2445 Gets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
2447 int Plot2d_ViewFrame::getHorScaleMode() const
2453 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
2455 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
2457 if ( myYMode == mode )
2460 // san -- Protection against QwtCurve bug in Qwt 0.4.x:
2461 // it crashes if switched to X/Y logarithmic mode, when one or more points have
2462 // non-positive X/Y coordinate
2463 if ( mode && !isYLogEnabled() ){
2465 SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
2467 QMessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_YLOG_NOT_ALLOWED"));
2474 // set bounds of logarithmic scale
2476 myPlot->setAxisScale( QwtPlot::yLeft, 1.0, 1e5 );
2477 myPlot->updateAxes();
2480 myPlot->setLogScale(QwtPlot::yLeft, myYMode != 0);
2483 myPlot->setAxisScale( QwtPlot::yRight, 1.0, 1e5 );
2484 myPlot->updateAxes();
2486 myPlot->setLogScale( QwtPlot::yRight, myYMode != 0 );
2491 emit vpModeVerChanged();
2495 Gets scale mode for vertical axis: 0 - linear, 1 - logarithmic
2497 int Plot2d_ViewFrame::getVerScaleMode() const
2503 Sets normalization mode to the global maximum by left Y axis
2505 void Plot2d_ViewFrame::setNormLMaxMode( bool mode, bool update )
2507 if ( myNormLMax == mode )
2511 processFiltering(true);
2514 emit vpNormLModeChanged();
2518 Gets normalization mode to the global maximum by left Y axis
2520 bool Plot2d_ViewFrame::getNormLMaxMode() const
2526 Sets normalization mode to the global minimum by left Y axis
2528 void Plot2d_ViewFrame::setNormLMinMode( bool mode, bool update )
2530 if ( myNormLMin == mode )
2534 processFiltering(true);
2537 emit vpNormLModeChanged();
2541 Gets normalization mode to the global minimum by left Y axis
2543 bool Plot2d_ViewFrame::getNormLMinMode() const
2549 Sets normalization mode to the global maximum by right Y axis
2551 void Plot2d_ViewFrame::setNormRMaxMode( bool mode, bool update )
2553 if ( myNormRMax == mode )
2557 processFiltering(true);
2560 emit vpNormRModeChanged();
2564 Gets normalization mode to the global maximum by right Y axis
2566 bool Plot2d_ViewFrame::getNormRMaxMode() const
2572 Sets normalization mode to the global minimum by right Y axis
2574 void Plot2d_ViewFrame::setNormRMinMode( bool mode, bool update )
2576 if ( myNormRMin == mode )
2580 processFiltering(true);
2583 emit vpNormRModeChanged();
2587 Gets normalization mode to the global minimum by right Y axis
2589 bool Plot2d_ViewFrame::getNormRMinMode() const
2595 Return, scale mode for horizontal axis
2597 bool Plot2d_ViewFrame::isModeHorLinear()
2599 return (myXMode == 0 ? true : false);
2603 Return, scale mode for vertical axis
2605 bool Plot2d_ViewFrame::isModeVerLinear()
2607 return (myYMode == 0 ? true : false);
2611 Return \c True if curves are normalize to the global maximum by left Y axis
2613 bool Plot2d_ViewFrame::isNormLMaxMode()
2615 return (myNormLMax ? true : false);
2619 Return \c True if curves are normalize to the global minimum by left Y axis
2621 bool Plot2d_ViewFrame::isNormLMinMode()
2623 return (myNormLMin ? true : false);
2627 Return \c True if curves are normalize to the global maximum by right Y axis
2629 bool Plot2d_ViewFrame::isNormRMaxMode()
2631 return (myNormRMax ? true : false);
2635 Return \c True if curves are normalize to the global minimum by right Y axis
2637 bool Plot2d_ViewFrame::isNormRMinMode()
2639 return (myNormRMin ? true : false);
2643 Return \c True if legend is shown
2645 bool Plot2d_ViewFrame::isLegendShow() const
2647 return myShowLegend;
2651 Slot, called when user presses mouse button
2653 void Plot2d_ViewFrame::plotMousePressed( const QMouseEvent& me )
2656 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2658 aParent->putInfo(getInfo(me.pos()));
2660 if ( myOperation == NoOpId )
2661 myOperation = testOperation( me );
2662 if ( myOperation != NoOpId ) {
2664 if ( myOperation == GlPanId ) {
2665 myPlot->setAxisScale( QwtPlot::yLeft,
2666 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2,
2667 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2 );
2668 myPlot->setAxisScale( QwtPlot::xBottom,
2669 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
2670 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
2672 myPlot->setAxisScale( QwtPlot::yRight,
2673 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2,
2674 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2 );
2679 int btn = me.button() | me.modifiers();
2680 if (btn == Qt::RightButton) {
2681 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
2682 me.pos(), me.button(), me.buttons(), me.modifiers() );
2683 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
2684 parent()->eventFilter(this, aEvent);
2690 Slot, called when user moves mouse
2692 bool Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
2694 int dx = me.pos().x() - myPnt.x();
2695 int dy = me.pos().y() - myPnt.y();
2698 if ( myOperation != NoOpId) {
2699 if ( myOperation == ZoomId ) {
2700 this->incrementalZoom( dx, dy );
2704 else if ( myOperation == PanId ) {
2705 this->incrementalPan( dx, dy );
2712 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2714 aParent->putInfo(getInfo(me.pos()));
2720 Slot, called when user releases mouse
2722 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
2724 if ( myOperation == NoOpId && me.button() == Qt::RightButton && me.modifiers() != Qt::ControlModifier )
2726 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
2727 me.pos(), me.globalPos() );
2728 emit contextMenuRequested( &aEvent );
2731 #ifndef NO_ANALYTICAL_CURVES
2732 updateAnalyticalCurves();
2735 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
2736 myPlot->defaultPicker();
2739 Plot2d_ViewWindow* aParent = dynamic_cast<Plot2d_ViewWindow*>(parent());
2741 aParent->putInfo(tr("INF_READY"));
2743 myOperation = NoOpId;
2746 Slot, called when user wheeling mouse
2748 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
2750 QwtPlotLayout* pl = myPlot->plotLayout();
2752 // compute zooming factor
2753 double aDelta = event->delta();
2754 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
2756 bool scaleXBottom = pl->scaleRect(QwtPlot::xBottom).contains( event->pos() ) ||
2757 pl->canvasRect().contains( event->pos() );
2758 bool scaleYLeft = pl->scaleRect(QwtPlot::yLeft).contains( event->pos() ) ||
2759 pl->canvasRect().contains( event->pos() );
2760 bool scaleYRight = mySecondY && ( pl->scaleRect(QwtPlot::yRight).contains( event->pos() ) ||
2761 pl->canvasRect().contains( event->pos() ) );
2763 // scale x bottom axis
2764 if ( scaleXBottom ) {
2765 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
2766 if ( xMap.s2() - xMap.s1() > 1.0e-12 || aScale > 1 )
2767 myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s1() + aScale*(xMap.s2() - xMap.s1()) );
2770 // scale y left axis
2772 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
2773 if ( yMap.s2() - yMap.s1() > 1.0e-12 || aScale > 1 )
2774 myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
2777 // scale y right axis (note: mySecondY value is checked above)
2778 if ( scaleYRight ) {
2779 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yRight );
2780 if ( yMap.s2() - yMap.s1() > 10e-12 || aScale > 1 )
2781 myPlot->setAxisScale( QwtPlot::yRight, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) );
2787 if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase();
2788 // store current mouse position
2789 myPnt = event->pos();
2790 #ifndef NO_ANALYTICAL_CURVES
2791 // update analytical curves
2792 updateAnalyticalCurves();
2797 Returns qwt plot curve if it is existed in map of curves and 0 otherwise
2799 QwtPlotCurve* Plot2d_ViewFrame::getPlotCurve( Plot2d_Curve* curve ) const
2801 return dynamic_cast<QwtPlotCurve*>( getPlotObject( curve ) );
2804 Returns true if qwt plot curve is existed in map of curves and false otherwise
2806 bool Plot2d_ViewFrame::hasPlotCurve( Plot2d_Curve* curve ) const
2808 return hasPlotObject( curve );
2812 Returns qwt plot curve if it is existed in map of curves and 0 otherwise
2814 QwtPlotItem* Plot2d_ViewFrame::getPlotObject( Plot2d_Object* object ) const
2816 ObjectDict::const_iterator it = myObjects.begin();
2817 for ( ; it != myObjects.end(); it++ ) {
2818 if ( it.value() == object )
2824 Returns true if qwt plot curve is existed in map of curves and false otherwise
2826 bool Plot2d_ViewFrame::hasPlotObject( Plot2d_Object* object ) const
2828 ObjectDict::const_iterator it = myObjects.begin();
2829 for ( ; it != myObjects.end(); it++ ) {
2830 if ( it.value() == object )
2839 void Plot2d_ViewFrame::setCurveType( QwtPlotCurve* curve, int curveType )
2843 if ( myCurveType == 0 )
2844 curve->setStyle( QwtPlotCurve::Dots );//QwtCurve::NoCurve
2845 else if ( myCurveType == 1 ) {
2846 curve->setStyle( QwtPlotCurve::Lines );
2847 curve->setCurveAttribute( QwtPlotCurve::Fitted, false );
2849 else if ( myCurveType == 2 ) {
2850 curve->setStyle( QwtPlotCurve::Lines );
2851 QwtSplineCurveFitter* fitter = new QwtSplineCurveFitter();
2852 fitter->setSplineSize( 250 );
2853 curve->setCurveAttribute( QwtPlotCurve::Fitted, true );
2854 curve->setCurveFitter( fitter );
2859 View operations : Pan view
2861 void Plot2d_ViewFrame::onViewPan()
2863 // reset the previous operation
2864 myPlot->defaultPicker();
2866 QCursor panCursor (Qt::SizeAllCursor);
2867 myPlot->canvas()->setCursor( panCursor );
2868 myOperation = PanId;
2871 View operations : Zoom view
2873 void Plot2d_ViewFrame::onViewZoom()
2875 // reset the previous operation
2876 myPlot->defaultPicker();
2878 QPixmap zoomPixmap (imageZoomCursor);
2879 QCursor zoomCursor (zoomPixmap);
2880 myPlot->canvas()->setCursor( zoomCursor );
2881 myOperation = ZoomId;
2884 View operations : Fit All
2886 void Plot2d_ViewFrame::onViewFitAll()
2890 // reset the previous operation
2891 myPlot->defaultPicker();
2892 myPlot->canvas()->setCursor( QCursor(Qt::CrossCursor) );
2893 myOperation = NoOpId;
2896 View operations : Fit Area
2898 void Plot2d_ViewFrame::onViewFitArea()
2900 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
2901 myOperation = FitAreaId;
2902 myPlot->setPickerMousePattern( Qt::LeftButton );
2905 View operations : Global panning
2907 void Plot2d_ViewFrame::onViewGlobalPan()
2909 // reset the previous operation
2910 myPlot->defaultPicker();
2912 QPixmap globalPanPixmap (imageCrossCursor);
2913 QCursor glPanCursor (globalPanPixmap);
2914 myPlot->canvas()->setCursor( glPanCursor );
2915 myPlot->setLogScale(QwtPlot::xBottom, false);
2916 myPlot->setLogScale(QwtPlot::yLeft, false);
2918 myPlot->setLogScale(QwtPlot::yRight, false);
2920 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
2921 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
2923 myXDistance = xMap.s2() - xMap.s1();
2924 myYDistance = yMap.s2() - yMap.s1();
2927 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
2928 myYDistance2 = yMap2.s2() - yMap2.s1();
2930 // don't make fit all
2932 myOperation = GlPanId;
2936 Precaution for logarithmic X scale
2938 bool Plot2d_ViewFrame::isXLogEnabled() const
2940 bool allPositive = true;
2941 ObjectDict::const_iterator it = myObjects.begin();
2942 for ( ; allPositive && it != myObjects.end(); it++ )
2943 allPositive = ( it.value()->getMinX() > 0. );
2948 Precaution for logarithmic Y scale
2950 bool Plot2d_ViewFrame::isYLogEnabled() const
2952 bool allPositive = true;
2953 ObjectDict::const_iterator it = myObjects.begin();
2954 for ( ; allPositive && it != myObjects.end(); it++ )
2955 allPositive = ( it.value()->getMinY() > 0. );
2962 void Plot2d_ViewFrame::setEnableAxis( QwtPlot::Axis theAxis, bool isEnable )
2964 if ( myPlot->axisEnabled( theAxis ) == isEnable )
2966 myPlot->enableAxis( theAxis, isEnable );
2967 if ( theAxis == QwtPlot::yRight )
2968 mySecondY = isEnable;
2971 class Plot2d_QwtPlotZoomer : public QwtPlotZoomer
2974 Plot2d_QwtPlotZoomer( int xAxis, int yAxis, QWidget* canvas )
2975 : QwtPlotZoomer( xAxis, yAxis, canvas )
2977 qApp->installEventFilter( this );
2978 // now picker working after only a button pick.
2979 // after click on button FitArea in toolbar of the ViewFrame.
2981 ~Plot2d_QwtPlotZoomer() {};
2987 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
2988 : QwtPlot( parent ),
2991 // Create alternative scales
2992 setAxisScaleDraw( QwtPlot::yLeft, new Plot2d_ScaleDraw() );
2993 setAxisScaleDraw( QwtPlot::xBottom, new Plot2d_ScaleDraw() );
2994 setAxisScaleDraw( QwtPlot::yRight, new Plot2d_ScaleDraw() );
2996 myPlotZoomer = new Plot2d_QwtPlotZoomer( QwtPlot::xBottom, QwtPlot::yLeft, canvas() );
2997 myPlotZoomer->setTrackerMode( QwtPicker::AlwaysOff );
2998 myPlotZoomer->setRubberBand( QwtPicker::RectRubberBand );
2999 myPlotZoomer->setRubberBandPen( QColor( Qt::green ) );
3003 // auto scaling by default
3004 setAxisAutoScale( QwtPlot::yLeft );
3005 setAxisAutoScale( QwtPlot::yRight );
3006 setAxisAutoScale( QwtPlot::xBottom );
3010 myGrid = new QwtPlotGrid();
3011 QPen aMajPen = myGrid->majorPen();
3012 aMajPen.setStyle( Qt::DashLine );
3013 myGrid->setPen( aMajPen );
3015 myGrid->enableX( false );
3016 myGrid->enableXMin( false );
3017 myGrid->enableY( false );
3018 myGrid->enableYMin( false );
3020 myGrid->attach( this );
3022 setMouseTracking( false );
3023 canvas()->setMouseTracking( true );
3025 myPlotZoomer->setEnabled( true );
3026 myPlotZoomer->setZoomBase();
3028 setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
3031 Plot2d_Plot2d::~Plot2d_Plot2d()
3036 \set axis scale engine - linear or log10
3038 void Plot2d_Plot2d::setLogScale( int axisId, bool log10 )
3041 setAxisScaleEngine( axisId, new QwtLogScaleEngine() );
3043 setAxisScaleEngine( axisId, new QwtLinearScaleEngine() );
3047 Recalculates and redraws Plot 2d view
3049 void Plot2d_Plot2d::replot()
3051 // the following code is intended to enable only axes
3052 // that are really used by displayed objects
3053 bool enableXBottom = false, enableXTop = false;
3054 bool enableYLeft = false, enableYRight = false;
3055 const QwtPlotItemList& items = itemList();
3056 QwtPlotItemIterator it;
3057 for ( it = items.begin(); it != items.end(); it++ ) {
3058 QwtPlotItem* item = *it;
3060 enableXBottom |= item->xAxis() == QwtPlot::xBottom;
3061 enableXTop |= item->xAxis() == QwtPlot::xTop;
3062 enableYLeft |= item->yAxis() == QwtPlot::yLeft;
3063 enableYRight |= item->yAxis() == QwtPlot::yRight;
3066 enableAxis( QwtPlot::xBottom, enableXBottom );
3067 enableAxis( QwtPlot::xTop, enableXTop );
3068 enableAxis( QwtPlot::yLeft, enableYLeft );
3069 enableAxis( QwtPlot::yRight, enableYRight );
3071 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
3078 QwtAbstractLegend* Plot2d_Plot2d::getLegend()
3080 #if QWT_VERSION < 0x040200
3083 return legend(); /* mpv: porting to the Qwt 4.2.0 */
3088 \return the recommended size for the widget
3090 QSize Plot2d_Plot2d::sizeHint() const
3092 return QwtPlot::minimumSizeHint();
3096 return minimum size for qwt plot
3098 QSize Plot2d_Plot2d::minimumSizeHint() const
3100 return QSize( 0, 0 );
3101 // QSize aSize = QwtPlot::minimumSizeHint();
3102 // return QSize(aSize.width()*3/4, aSize.height());
3105 void Plot2d_Plot2d::defaultPicker()
3107 myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1,
3108 Qt::RightButton, Qt::ControlModifier ); // zooming button
3109 for ( int i = QwtEventPattern::MouseSelect2; i < QwtEventPattern::MouseSelect6; i++ )
3110 myPlotZoomer->setMousePattern( (QwtEventPattern::MousePatternCode)i, Qt::NoButton,
3114 void Plot2d_Plot2d::setPickerMousePattern( int button, int state )
3116 myPlotZoomer->setMousePattern( QwtEventPattern::MouseSelect1, (Qt::MouseButton)button,
3117 (Qt::KeyboardModifiers)state );
3121 * Set the point picker associated with a graphic view
3123 void Plot2d_Plot2d::setPicker( Plot2d_QwtPlotPicker *picker)
3129 * Create marker and tooltip associed with a point
3131 QwtPlotMarker* Plot2d_Plot2d::createMarkerAndTooltip( QwtSymbol* symbol,
3135 Plot2d_QwtPlotPicker *picker)
3137 QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
3139 aPlotMarker->setSymbol( symbol ); // symbol must have a color
3140 aPlotMarker->setLabelAlignment( Qt::AlignTop);
3141 aPlotMarker->setXValue(X);
3142 aPlotMarker->setYValue(Y);
3144 aPlotMarker->attach(this);
3146 // Associate a tooltip with the point's marker
3147 // PB: how to obtain a tooltip with a rectangular frame ?
3148 //QwtText tooltip ("X=" + QString::number(X) + " Y=" + QString::number(Y) );
3150 QwtText text (tooltip);
3151 //QColor tooltipColor( 245, 222, 179); // Wheat -RGB (0 a 255)
3152 QColor tooltipColor( 253, 245, 230); // OldLace
3153 text.setBackgroundBrush( QBrush(tooltipColor)); //, Qt::SolidPattern));
3156 picker->pMarkers.append( aPlotMarker);
3157 picker->pMarkersToolTip[ aPlotMarker] = text;
3162 QwtPlotGrid* Plot2d_Plot2d::grid() const
3167 QwtPlotZoomer* Plot2d_Plot2d::zoomer() const
3169 return myPlotZoomer;
3173 Updates identifiers of Y axis type in the legend.
3175 void Plot2d_Plot2d::updateYAxisIdentifiers()
3177 bool enableYLeft = false, enableYRight = false;
3178 const QwtPlotItemList& items = itemList();
3179 QwtPlotItemIterator it;
3180 for ( it = items.begin(); it != items.end(); it++ ) {
3181 QwtPlotItem* item = *it;
3183 enableYLeft |= item->yAxis() == QwtPlot::yLeft;
3184 enableYRight |= item->yAxis() == QwtPlot::yRight;
3188 // if several curves are attached to different axes
3189 // display corresponding identifiers in the legend,
3190 // otherwise hide them
3191 for ( it = items.begin(); it != items.end(); it++ ) {
3192 QwtPlotItem* item = *it;
3193 if ( Plot2d_QwtPlotCurve* aPCurve = dynamic_cast<Plot2d_QwtPlotCurve*>( item ) )
3194 aPCurve->setYAxisIdentifierEnabled( enableYLeft && enableYRight );
3195 if ( item && item->isVisible() && legend() )
3196 item->updateLegend( item, item->legendData() );
3200 // Methods to manage axis graduations
3202 /* Create definition and graduations of axes
3204 void Plot2d_Plot2d::createAxisScaleDraw()
3206 myScaleDraw = new Plot2d_AxisScaleDraw( this);
3210 /* Stock X axis's ticks in the drawing zone
3212 void Plot2d_Plot2d::applyTicks()
3214 myScaleDraw->applyTicks();
3218 /* Unactivate automatic ticks drawing (call to method Plot2d_AxisScaleDraw::draw() )
3220 * - number call to ticks drawing (for information) : numcall
3222 void Plot2d_Plot2d::unactivAxisScaleDraw( int numcall)
3224 // Memorize X axis (myScaleDraw already exists) in the drawing zone
3225 //setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
3227 myScaleDraw->unactivTicksDrawing( numcall);
3231 /* Draw ticks and labels on X axis of the drawing zone
3232 * Draw systems' names under the X axis of the drawing zone
3233 * Draw vertical segments between X axis's intervals of the systems
3235 * - left and right margins for ticks : XLeftMargin, XRightMargin
3236 * - for each named system :
3237 * positions and labels for ticks on X axis : devicesPosLabelTicks
3239 * The true drawings will be realized by the method Plot2d_AxisScaleDraw::draw()
3242 void Plot2d_Plot2d::displayXTicksAndLabels(
3243 double XLeftMargin, double XRightMargin,
3244 const QList< QPair< QString, QMap<double, QString> > > & devicesPosLabelTicks)
3245 // name position label
3248 //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
3250 int nbDevices = devicesPosLabelTicks.size();
3252 //std::cout << " Nombre de systemes = " << nbDevices << std::endl;
3253 if (nbDevices == 0) return;
3255 // For drawing systems' names, their positions must be in the allTicks list
3256 // (cf class Plot2d_AxisScaleDraw)
3258 // Liste of ticks' positions and systems' names
3259 QList<double> allTicks;
3261 double devXmin, devXmax; // X interval of a system
3262 double gapXmin, gapXmax; // X interval between two systems
3263 double devLabPos; // Label's position of a system
3264 double segmentPos; // Position of the vertical segment between current system and the next
3266 // 1)- Search for the system whose X interval is the most to the left
3269 double XminMin = 1.e+12;
3273 for (int idev=0; idev < nbDevices; idev++)
3275 QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
3277 QString deviceLabel = paire.first;
3279 // Ticks' map of the system
3280 QMap<double,QString> devPosLabelTicks = paire.second;
3282 QList<double> posTicks = devPosLabelTicks.keys();
3284 // List's items increasing sorting
3285 qSort( posTicks.begin(), posTicks.end() ); // iterators
3287 // X interval for the system
3288 devXmin = posTicks.first();
3289 devXmax = posTicks.last();
3291 if (devXmin < XminMin)
3299 // 2)- Ticks, systems' names, verticals segments
3301 for (int idev=0; idev < nbDevices; idev++)
3303 QPair< QString, QMap<double,QString> > paire = devicesPosLabelTicks.at(idev);
3305 QString deviceLabel = paire.first;
3307 std::string std_label = deviceLabel.toStdString();
3308 //const char *c_label = std_label.c_str();
3309 //std::cout << " deviceLabel: |" << c_label << "|" << std::endl;
3311 // Ticks' map of the system
3312 QMap<double,QString> devPosLabelTicks = paire.second;
3314 int nbTicks = devPosLabelTicks.size();
3316 QList<double> posTicks = devPosLabelTicks.keys();
3318 // List's items increasing sorting
3319 qSort( posTicks.begin(), posTicks.end() ); // iterators
3321 // X interval for the system
3322 devXmin = posTicks.first();
3323 devXmax = posTicks.last();
3325 // Stock ticks' positions and labels on X axis
3329 for (int itic=0; itic < nbTicks; itic++)
3331 pos = posTicks.at(itic);
3332 label = devPosLabelTicks[pos];
3334 myScaleDraw->setLabelTick( pos, label, false);
3336 std::string std_label = label.toStdString();
3337 //const char *c_label = std_label.c_str();
3338 //std::cout << " tick " << itic << " : pos= " << pos << ", label= |" << c_label << "|" << std::endl;
3340 allTicks.append( posTicks);
3342 // Compute the position of the system's label
3343 if (idev == ileftDev)
3345 devLabPos = devXmin + 0.25*(devXmax - devXmin);
3349 devLabPos = devXmin + 0.50*(devXmax - devXmin);
3351 allTicks.append( devLabPos);
3353 // Stock position and name of the system under X axis
3354 myScaleDraw->setLabelTick( devLabPos, deviceLabel, true);
3358 // Create the vertical segment between the current system and the next
3360 segmentPos = gapXmin + 0.5*(gapXmax - gapXmin);
3362 createSeparationLine( segmentPos);
3367 // List's items increasing sorting
3368 qSort( allTicks.begin(), allTicks.end() ); // iterators
3370 // Stock the interval of X's values
3371 double lowerBound = allTicks.first() - XLeftMargin;
3372 double upperBound = allTicks.last() + XRightMargin;
3373 myScaleDraw->setInterval( lowerBound, upperBound);
3375 // For each system, stock the position of the X's ticks and those of the name
3376 myScaleDraw->setTicks( allTicks); // do not draw the ticks
3378 // Memorize the X axis in the drawing zone
3379 setAxisScaleDraw( QwtPlot::xBottom, myScaleDraw); // heritage of QwtPlot
3381 //std::cout << "Plot2d_Plot2d::displayXTicksAndLabels() 1" << std::endl;
3385 /* Create vertical segment between two curves
3387 void Plot2d_Plot2d::createSeparationLine( double Xpos)
3389 QwtPlotMarker* aPlotMarker = new QwtPlotMarker();
3391 aPlotMarker->setLineStyle( QwtPlotMarker::VLine);
3392 aPlotMarker->setXValue( Xpos);
3393 aPlotMarker->setLinePen( QPen(Qt::black));
3394 aPlotMarker->attach(this); // Add to drawing zone
3395 // To deallocate in EraseAll()
3396 mySeparationLineList.append( aPlotMarker);
3399 void Plot2d_Plot2d::clearSeparationLineList()
3401 mySeparationLineList.clear();
3404 /* Set type of legend symbol
3406 void Plot2d_Plot2d::setLegendSymbolType( const int type )
3408 myLegendSymbolType = type;
3411 /* Get type of legend symbol
3413 int Plot2d_Plot2d::getLegendSymbolType()
3415 return myLegendSymbolType;
3419 Creates presentation of object
3420 Default implementation is empty
3422 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
3428 Copies preferences from other viewframe
3429 \param vf - other view frame
3431 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
3436 myCurveType = vf->myCurveType;
3437 myShowLegend = vf->myShowLegend;
3438 myLegendPos = vf->myLegendPos;
3439 myLegendSymbolType = vf->myLegendSymbolType;
3440 myLegendFont = vf->myLegendFont;
3441 mySelectedLegendFontColor = vf->mySelectedLegendFontColor;
3442 myMarkerSize = vf->myMarkerSize;
3443 myBackground = vf->myBackground;
3444 mySelectionColor = vf->mySelectionColor;
3445 myTitle = vf->myTitle;
3446 myXTitle = vf->myXTitle;
3447 myYTitle = vf->myYTitle;
3448 myY2Title = vf->myY2Title;
3449 myTitleEnabled = vf->myTitleEnabled;
3450 myXTitleEnabled = vf->myXTitleEnabled;
3451 myYTitleEnabled = vf->myYTitleEnabled;
3452 myY2TitleEnabled = vf->myY2TitleEnabled;
3453 myXGridMajorEnabled = vf->myXGridMajorEnabled;
3454 myYGridMajorEnabled = vf->myYGridMajorEnabled;
3455 myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
3456 myXGridMinorEnabled = vf->myXGridMinorEnabled;
3457 myYGridMinorEnabled = vf->myYGridMinorEnabled;
3458 myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
3459 myXGridMaxMajor = vf->myXGridMaxMajor;
3460 myYGridMaxMajor = vf->myYGridMaxMajor;
3461 myY2GridMaxMajor = vf->myY2GridMaxMajor;
3462 myXGridMaxMinor = vf->myXGridMaxMinor;
3463 myYGridMaxMinor = vf->myYGridMaxMinor;
3464 myY2GridMaxMinor = vf->myY2GridMaxMinor;
3465 myXMode = vf->myXMode;
3466 myYMode = vf->myYMode;
3467 mySecondY = vf->mySecondY;
3471 Updates titles according to curves
3473 #define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
3474 void Plot2d_ViewFrame::updateTitles( const bool update )
3476 ObjectDict::iterator it = myObjects.begin();
3477 QStringList aXTitles;
3478 QStringList aYTitles;
3479 QStringList aY2Titles;
3480 QStringList aXUnits;
3481 QStringList aYUnits;
3482 QStringList aY2Units;
3483 QStringList aTables;
3486 Plot2d_Object* anObject;
3487 for ( ; it != myObjects.end(); it++ ) {
3488 // collect titles and units from all curves...
3489 anObject = it.value();
3490 QString xTitle = anObject->getHorTitle().trimmed();
3491 QString yTitle = anObject->getVerTitle().trimmed();
3492 QString xUnits = anObject->getHorUnits().trimmed();
3493 QString yUnits = anObject->getVerUnits().trimmed();
3495 if ( anObject->getYAxis() == QwtPlot::yLeft ) {
3496 if ( !aYTitles.contains( yTitle ) )
3497 aYTitles.append( yTitle );
3498 if ( !aYUnits.contains( yUnits ) )
3499 aYUnits.append( yUnits );
3502 if ( !aY2Titles.contains( yTitle ) )
3503 aY2Titles.append( yTitle );
3504 if ( !aY2Units.contains( yUnits ) )
3505 aY2Units.append( yUnits );
3507 if ( !aXTitles.contains( xTitle ) )
3508 aXTitles.append( xTitle );
3509 if ( !aXUnits.contains( xUnits ) )
3510 aXUnits.append( xUnits );
3512 QString aName = anObject->getTableTitle();
3513 if( !aName.isEmpty() && !aTables.contains( aName ) )
3514 aTables.append( aName );
3517 // ... and update plot 2d view
3518 QString xUnits, yUnits, y2Units;
3519 if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() )
3520 xUnits = BRACKETIZE( aXUnits[0] );
3521 if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty())
3522 yUnits = BRACKETIZE( aYUnits[0] );
3523 if ( aY2Units.count() == 1 && !aY2Units[0].isEmpty())
3524 y2Units = BRACKETIZE( aY2Units[0] );
3525 QString xTitle, yTitle, y2Title;
3526 if ( aXTitles.count() == 1 && aXUnits.count() == 1 )
3527 xTitle = aXTitles[0];
3528 if ( aYTitles.count() == 1 )
3529 yTitle = aYTitles[0];
3530 if ( mySecondY && aY2Titles.count() == 1 )
3531 y2Title = aY2Titles[0];
3533 if ( !xTitle.isEmpty() && !xUnits.isEmpty() )
3535 if ( !yTitle.isEmpty() && !yUnits.isEmpty() )
3537 if ( !y2Title.isEmpty() && !y2Units.isEmpty() )
3540 setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, false );
3541 setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, false );
3543 setTitle( myY2TitleEnabled, y2Title + y2Units, Y2Title, false );
3545 setTitle( true, aTables.join("; "), MainTitle, false );
3547 // do update if necessary
3554 Outputs content of viewframe to file
3555 \param file - file name
3556 \param format - file format
3558 bool Plot2d_ViewFrame::print( const QString& file, const QString& format ) const
3567 QPaintDevice* pd = 0;
3568 if( format=="PS" || format=="EPS" || format == "PDF" )
3570 QPrinter* pr = new QPrinter( QPrinter::HighResolution );
3572 pr->setOutputFormat(QPrinter::PdfFormat);
3573 pr->setPageSize( QPrinter::A4 );
3574 pr->setOutputFileName( file );
3575 pr->setPrintProgram( "" );
3581 QwtPlotRenderer* pr = new QwtPlotRenderer();
3582 pr->renderTo( myPlot, *pd );
3593 * Print Plot2d window
3595 void Plot2d_ViewFrame::printPlot( QPainter* p, const QRectF& rect) const
3597 QwtPlotRenderer* pr = new QwtPlotRenderer();
3598 pr->render( myPlot, p, rect );
3602 \return string with all visual parameters
3604 QString Plot2d_ViewFrame::getVisualParameters()
3607 return getXmlVisualParameters();
3610 RNV: Old case, now visual parameters stored in the XML format.
3612 double xmin, xmax, ymin, ymax, y2min, y2max;
3613 getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
3615 //Store font in the visual parameters string as:
3617 // ...*FontFamily|FontSize|B|I|U|r:g:b*...
3619 retStr.sprintf( "%d*%d*%d*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%s|%i|%i|%i|%i|%i:%i:%i",
3620 myXMode, myYMode, mySecondY, xmin, xmax, ymin, ymax, y2min, y2max,
3621 qPrintable(myLegendFont.family()), myLegendFont.pointSize(),myLegendFont.bold(),
3622 myLegendFont.italic(), myLegendFont.underline(),myLegendColor.red(),
3623 myLegendColor.green(), myLegendColor.blue());
3625 //store all Analytical curves
3626 //store each curve in the following format
3627 // ...*Name|isActive|Expresion|NbInervals|isAutoAssign[|MarkerType|LineType|LineWidth|r:g:b]
3628 // parameters in the [ ] is optional in case if isAutoAssign == true
3629 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
3630 Plot2d_AnalyticalCurve* c = 0;
3632 for( ; it != myAnalyticalCurves.end(); it++) {
3635 QString curveString("");
3636 isAuto = c->isAutoAssign();
3637 curveString.sprintf("*%s|%i|%s|%i|%i",
3638 qPrintable(c->getName()),
3640 qPrintable(c->getExpression()),
3641 c->getNbIntervals(),
3644 retStr+=curveString;
3646 QString optCurveString("");
3647 optCurveString.sprintf("|%i|%i|%i|%i:%i:%i",
3648 (int)c->getMarker(),
3651 c->getColor().red(),
3652 c->getColor().green(),
3653 c->getColor().blue());
3654 retStr+=optCurveString;
3657 retStr += QString( "*%1" ).arg( Qtx::colorToString( backgroundColor() ) );
3663 Restores all visual parameters from string
3665 void Plot2d_ViewFrame::setVisualParameters( const QString& parameters )
3667 if(setXmlVisualParameters(parameters))
3671 QStringList paramsLst = parameters.split( '*' );
3672 if ( paramsLst.size() >= 9 ) {
3673 double ymin, ymax, y2min, y2max;
3674 myXMode = paramsLst[0].toInt();
3675 myYMode = paramsLst[1].toInt();
3676 mySecondY = (bool)paramsLst[2].toInt();
3677 xmin = paramsLst[3].toDouble();
3678 xmax = paramsLst[4].toDouble();
3679 ymin = paramsLst[5].toDouble();
3680 ymax = paramsLst[6].toDouble();
3681 y2min = paramsLst[7].toDouble();
3682 y2max = paramsLst[8].toDouble();
3685 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
3686 setHorScaleMode( myXMode, /*update=*/false );
3687 setVerScaleMode( myYMode, /*update=*/false );
3690 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
3691 myYDistance2 = yMap2.s2() - yMap2.s1();
3694 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3695 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3698 //Restore legend font
3699 if(paramsLst.size() >= 10) {
3700 QStringList fontList = paramsLst[9].split( '|' );
3701 if(fontList.size() == 6) {
3702 myLegendFont = QFont(fontList[0]);
3703 myLegendFont.setPointSize(fontList[1].toInt());
3704 myLegendFont.setBold(fontList[2].toInt());
3705 myLegendFont.setItalic(fontList[3].toInt());
3706 myLegendFont.setUnderline(fontList[4].toInt());
3707 QStringList colorList = fontList[5].split(":");
3708 setLegendFont( myLegendFont );
3710 if(colorList.size() == 3) {
3711 myLegendColor = QColor(colorList[0].toInt(),
3712 colorList[1].toInt(),
3713 colorList[2].toInt());
3714 setLegendFontColor( myLegendColor );
3719 #ifndef NO_ANALYTICAL_CURVES
3720 //Restore all Analytical curves
3721 int startCurveIndex = 10;
3722 if( paramsLst.size() >= startCurveIndex+1 ) {
3723 for( int i=startCurveIndex; i<paramsLst.size() ; i++ ) {
3724 QStringList curveLst = paramsLst[i].split("|");
3725 if( curveLst.size() == 5 || curveLst.size() == 9 ) {
3726 Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
3727 c->setName(curveLst[0]);
3728 c->setActive(curveLst[1].toInt());
3729 c->setExpression(curveLst[2]);
3730 c->setNbIntervals(curveLst[3].toLong());
3731 c->setAutoAssign(curveLst[4].toInt());
3732 if( !c->isAutoAssign() ) {
3733 c->setMarker((Plot2d::MarkerType)curveLst[5].toInt());
3734 c->setLine((Plot2d::LineType)curveLst[6].toInt());
3735 c->setLineWidth(curveLst[7].toInt());
3736 QStringList colorList = curveLst[8].split(":");
3737 if( colorList.size() == 3 ) {
3738 c->setColor(QColor(colorList[0].toInt(),
3739 colorList[1].toInt(),
3740 colorList[2].toInt()));
3743 c->autoFill( myPlot );
3745 addAnalyticalCurve(c);
3746 updateAnalyticalCurve(c);
3748 else if( curveLst.size() == 1 ) {
3749 // background color can be set here
3751 if ( Qtx::stringToColor( paramsLst[i], c ) )
3752 setBackgroundColor( c );
3761 Store visual parameters in xml format.
3763 QString Plot2d_ViewFrame::getXmlVisualParameters() {
3765 QXmlStreamWriter aWriter(&retStr);
3766 aWriter.setAutoFormatting(true);
3769 aWriter.writeStartDocument();
3770 aWriter.writeStartElement("ViewState");
3771 aWriter.writeStartElement("Range");
3772 double xmin, xmax, ymin, ymax, y2min, y2max;
3773 getFitRanges( xmin, xmax, ymin, ymax, y2min, y2max );
3774 aWriter.writeAttribute("Xmin", QString("").sprintf("%.12e",xmin));
3775 aWriter.writeAttribute("Xmax", QString("").sprintf("%.12e",xmax));
3776 aWriter.writeAttribute("Ymin", QString("").sprintf("%.12e",ymin));
3777 aWriter.writeAttribute("Ymax", QString("").sprintf("%.12e",ymax));
3778 aWriter.writeAttribute("Y2min", QString("").sprintf("%.12e",y2min));
3779 aWriter.writeAttribute("Y2max", QString("").sprintf("%.12e",y2max));
3780 aWriter.writeEndElement();
3783 aWriter.writeStartElement("DisplayMode");
3784 aWriter.writeAttribute("SecondAxis", QString("").sprintf("%d",mySecondY));
3785 aWriter.writeStartElement("ScaleMode");
3786 aWriter.writeAttribute("Xscale", QString("").sprintf("%d",myXMode));
3787 aWriter.writeAttribute("Yscale", QString("").sprintf("%d",myYMode));
3788 aWriter.writeEndElement();
3789 aWriter.writeStartElement("NormalizationMode");
3790 aWriter.writeAttribute("LeftMin", QString("").sprintf("%d",myNormLMin));
3791 aWriter.writeAttribute("LeftMax", QString("").sprintf("%d",myNormLMax));
3792 aWriter.writeAttribute("RightMin", QString("").sprintf("%d",myNormRMin));
3793 aWriter.writeAttribute("RightMax", QString("").sprintf("%d",myNormRMax));
3794 aWriter.writeEndElement();
3795 aWriter.writeEndElement();
3798 aWriter.writeStartElement("Legend");
3799 aWriter.writeAttribute("Visibility", QString("").sprintf("%d", myShowLegend));
3800 aWriter.writeStartElement("LegendFont");
3801 aWriter.writeAttribute("Family", myLegendFont.family());
3802 aWriter.writeAttribute("Size", QString("").sprintf("%d",myLegendFont.pointSize()));
3803 aWriter.writeAttribute("Bold", QString("").sprintf("%d",myLegendFont.bold()));
3804 aWriter.writeAttribute("Italic", QString("").sprintf("%d",myLegendFont.italic()));
3805 aWriter.writeAttribute("Underline", QString("").sprintf("%d",myLegendFont.underline()));
3806 aWriter.writeAttribute("R", QString("").sprintf("%d",myLegendColor.red()));
3807 aWriter.writeAttribute("G", QString("").sprintf("%d",myLegendColor.green()));
3808 aWriter.writeAttribute("B", QString("").sprintf("%d",myLegendColor.blue()));
3809 aWriter.writeEndElement();
3810 aWriter.writeEndElement();
3812 #ifndef NO_ANALYTICAL_CURVES
3814 aWriter.writeStartElement("AnalyticalCurves");
3815 AnalyticalCurveList::iterator it = myAnalyticalCurves.begin();
3816 Plot2d_AnalyticalCurve* c = 0;
3819 for( ; it != myAnalyticalCurves.end(); it++) {
3822 aWriter.writeStartElement(QString("AnalyticalCurve_%1").arg(id));
3823 isAuto = c->isAutoAssign();
3824 aWriter.writeAttribute("Name",c->getName());
3825 aWriter.writeAttribute("IsActive", QString("").sprintf("%d", c->isActive()));
3826 aWriter.writeAttribute("Expression", c->getExpression());
3827 aWriter.writeAttribute("NbIntervals", QString("").sprintf("%d", c->getNbIntervals()));
3828 aWriter.writeAttribute("isAuto", QString("").sprintf("%d",isAuto));
3830 aWriter.writeAttribute("Marker", QString("").sprintf("%d",(int)c->getMarker()));
3831 aWriter.writeAttribute("Line", QString("").sprintf("%d",(int)c->getLine()));
3832 aWriter.writeAttribute("LineWidth", QString("").sprintf("%d",c->getLineWidth()));
3833 aWriter.writeAttribute("R", QString("").sprintf("%d",c->getColor().red()));
3834 aWriter.writeAttribute("G", QString("").sprintf("%d",c->getColor().green()));
3835 aWriter.writeAttribute("B", QString("").sprintf("%d",c->getColor().blue()));
3837 aWriter.writeEndElement();
3840 aWriter.writeEndElement(); //AnalyticalCurve
3844 aWriter.writeStartElement(QString("Background"));
3845 aWriter.writeStartElement(QString("BackgroundColor"));
3846 aWriter.writeAttribute("R", QString("").sprintf("%d",backgroundColor().red()));
3847 aWriter.writeAttribute("G", QString("").sprintf("%d",backgroundColor().green()));
3848 aWriter.writeAttribute("B", QString("").sprintf("%d",backgroundColor().blue()));
3849 aWriter.writeEndElement();
3850 aWriter.writeEndElement();
3853 aWriter.writeEndDocument();
3857 Restore visual parameters from xml format.
3859 bool Plot2d_ViewFrame::setXmlVisualParameters(const QString& parameters) {
3860 QXmlStreamReader aReader(parameters);
3861 double xmin, xmax, ymin, ymax, y2min, y2max;
3862 bool leftMin,leftMax,rightMin,rightMax;
3863 leftMin = leftMax = rightMin = rightMax = false;
3864 while(!aReader.atEnd()) {
3866 if (aReader.isStartElement()) {
3867 QXmlStreamAttributes aAttr = aReader.attributes();
3868 if(aReader.name() == "Range") {
3869 xmin = aAttr.value("Xmin").toString().toDouble();
3870 xmax = aAttr.value("Xmax").toString().toDouble();
3871 ymin = aAttr.value("Ymin").toString().toDouble();
3872 ymax = aAttr.value("Ymax").toString().toDouble();
3873 y2min = aAttr.value("Y2min").toString().toDouble();
3874 y2max = aAttr.value("Y2max").toString().toDouble();
3875 } else if(aReader.name() == "DisplayMode") {
3876 mySecondY = aAttr.value("Y2max").toString().toDouble();
3877 } else if(aReader.name() == "ScaleMode") {
3878 myXMode = aAttr.value("Xscale").toString().toInt();
3879 myYMode = aAttr.value("Yscale").toString().toInt();
3880 } else if(aReader.name() == "NormalizationMode") {
3881 leftMin = (bool)aAttr.value("LeftMin").toString().toInt();
3882 leftMax = (bool)aAttr.value("LeftMax").toString().toInt();
3883 rightMin = (bool)aAttr.value("RightMin").toString().toInt();
3884 rightMax = (bool)aAttr.value("RightMax").toString().toInt();
3885 } else if(aReader.name() == "Legend") {
3886 myShowLegend = (bool)aAttr.value("Visibility").toString().toInt();
3887 } else if (aReader.name() == "LegendFont") {
3888 myLegendFont = QFont(aAttr.value("Family").toString());
3889 myLegendFont.setPointSize(aAttr.value("Size").toString().toInt());
3890 myLegendFont.setBold((bool)aAttr.value("Bold").toString().toInt());
3891 myLegendFont.setItalic((bool)aAttr.value("Italic").toString().toInt());
3892 myLegendFont.setUnderline((bool)aAttr.value("Underline").toString().toInt());
3893 myLegendColor = QColor(aAttr.value("R").toString().toInt(),
3894 aAttr.value("G").toString().toInt(),
3895 aAttr.value("B").toString().toInt());
3896 setLegendFontColor( myLegendColor );
3897 setLegendFont(myLegendFont);
3898 } else if(aReader.name().toString().indexOf("AnalyticalCurve_") >= 0) {
3899 #ifndef NO_ANALYTICAL_CURVES
3900 Plot2d_AnalyticalCurve* c = new Plot2d_AnalyticalCurve();
3901 c->setName(aAttr.value("Name").toString());
3902 c->setActive((bool)aAttr.value("IsActive").toString().toInt());
3903 c->setExpression(aAttr.value("Expression").toString());
3904 c->setNbIntervals(aAttr.value("NbIntervals").toString().toLong());
3905 c->setAutoAssign((bool)aAttr.value("isAuto").toString().toInt());
3906 if( !c->isAutoAssign() ) {
3907 c->setMarker((Plot2d::MarkerType)aAttr.value("Marker").toString().toInt());
3908 c->setLine((Plot2d::LineType)aAttr.value("Line").toString().toInt());
3909 c->setLineWidth(aAttr.value("LineWidth").toString().toInt());
3910 c->setColor(QColor(aAttr.value("R").toString().toInt(),
3911 aAttr.value("G").toString().toInt(),
3912 aAttr.value("B").toString().toInt()));
3914 c->autoFill( myPlot );
3916 addAnalyticalCurve(c);
3917 updateAnalyticalCurve(c);
3919 } else if(aReader.name().toString() == "BackgroundColor") {
3920 setBackgroundColor(QColor(aAttr.value("R").toString().toInt(),
3921 aAttr.value("G").toString().toInt(),
3922 aAttr.value("B").toString().toInt()));
3927 if(aReader.hasError())
3931 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
3932 setHorScaleMode( myXMode, /*update=*/false );
3933 setVerScaleMode( myYMode, /*update=*/false );
3935 QwtScaleMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
3936 myYDistance2 = yMap2.s2() - yMap2.s1();
3938 setNormLMinMode(leftMin);
3939 setNormLMaxMode(leftMax);
3940 setNormRMinMode(rightMin);
3941 setNormRMaxMode(rightMax);
3943 showLegend( myShowLegend, false );
3945 fitData( 0, xmin, xmax, ymin, ymax, y2min, y2max );
3950 Incremental zooming operation
3952 void Plot2d_ViewFrame::incrementalPan( const int incrX, const int incrY ) {
3953 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
3954 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
3956 myPlot->setAxisScale( QwtPlot::yLeft,
3957 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s1() )-incrY ),
3958 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() )-incrY ) );
3959 myPlot->setAxisScale( QwtPlot::xBottom,
3960 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s1() )-incrX ),
3961 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() )-incrX ) );
3963 QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
3964 myPlot->setAxisScale( QwtPlot::yRight,
3965 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s1() )-incrY ),
3966 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() )-incrY ) );
3972 Incremental panning operation
3974 void Plot2d_ViewFrame::incrementalZoom( const int incrX, const int incrY ) {
3975 QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
3976 QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
3978 myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(),
3979 myPlot->invTransform( QwtPlot::yLeft, yMap.transform( yMap.s2() ) + incrY ) );
3980 myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(),
3981 myPlot->invTransform( QwtPlot::xBottom, xMap.transform( xMap.s2() ) - incrX ) );
3983 QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
3984 myPlot->setAxisScale( QwtPlot::yRight, y2Map.s1(),
3985 myPlot->invTransform( QwtPlot::yRight, y2Map.transform( y2Map.s2() ) + incrY ) );
3993 void Plot2d_ViewFrame::updatePlotItem(Plot2d_Object* theObject, QwtPlotItem* theItem) {
3994 theObject->updatePlotItem( theItem );
3995 Plot2d_Curve* c = dynamic_cast<Plot2d_Curve*>(theObject);
3996 QwtPlotCurve* cu = dynamic_cast<QwtPlotCurve*>(theItem);
3997 Plot2d_NormalizeAlgorithm* aNormAlgo;
3999 if(c->getYAxis() == QwtPlot::yRight)
4000 aNormAlgo = myRNormAlgo;
4002 aNormAlgo = myLNormAlgo;
4003 if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
4004 AlgoPlot2dOutputData aResultData = aNormAlgo->getOutput();
4005 AlgoPlot2dOutputData::iterator itTmp = aResultData.find(theObject);
4007 int size = itTmp.value().size();
4008 xNew = new double[size];
4009 yNew = new double[size];
4011 for (; j < size; ++j) {
4012 xNew[j] = itTmp.value().at(j).first;
4013 yNew[j] = itTmp.value().at(j).second;
4015 cu->setSamples(xNew, yNew,j);
4018 if(aNormAlgo->getNormalizationMode() != Plot2d_NormalizeAlgorithm::NormalizeNone) {
4019 QString name = c->getName().isEmpty() ? c->getVerTitle() : c->getName();
4020 name = name + QString("(B=%1, K=%2)");
4021 name = name.arg(aNormAlgo->getBkoef(c)).arg(aNormAlgo->getKkoef(c));
4031 QwtPlotCanvas* Plot2d_ViewFrame::getPlotCanvas() const
4033 return myPlot ? (QwtPlotCanvas*)myPlot->canvas() : 0;
4037 return closest curve if it exist, else 0
4039 Plot2d_Curve* Plot2d_ViewFrame::getClosestCurve( QPoint p, double& distance, int& index ) const
4041 CurveDict aCurves = getCurves();
4042 CurveDict::iterator it = aCurves.begin();
4043 Plot2d_Curve* pCurve = 0;
4045 for ( ; it != aCurves.end(); it++ ) {
4046 QwtPlotCurve* aCurve = it.key();
4050 int i = aCurve->closestPoint( p, &d );
4051 if ( i > -1 && ( distance < 0 || d < distance ) ) {
4052 pCurve = it.value();
4060 #ifndef NO_ANALYTICAL_CURVES
4062 \brief Deselect all analytical curves.
4064 void Plot2d_ViewFrame::deselectAnalyticalCurves() {
4065 foreach(Plot2d_AnalyticalCurve* c, myAnalyticalCurves) {
4066 c->setSelected(false);
4072 \brief Deselect all objects, except analytical curves.
4074 void Plot2d_ViewFrame::deselectObjects() {
4075 ObjectDict::const_iterator it = myObjects.begin(), aLast = myObjects.end();
4076 for ( ; it != aLast; it++ ) {
4077 it.value()->setSelected(false);
4081 #define INCREMENT_FOR_OP 10
4084 Performs incremental panning to the left
4086 void Plot2d_ViewFrame::onPanLeft()
4088 this->incrementalPan( -INCREMENT_FOR_OP, 0 );
4089 #ifndef NO_ANALYTICAL_CURVES
4090 updateAnalyticalCurves();
4095 Performs incremental panning to the right
4097 void Plot2d_ViewFrame::onPanRight()
4099 this->incrementalPan( INCREMENT_FOR_OP, 0 );
4100 #ifndef NO_ANALYTICAL_CURVES
4101 updateAnalyticalCurves();
4106 Performs incremental panning to the top
4108 void Plot2d_ViewFrame::onPanUp()
4110 this->incrementalPan( 0, -INCREMENT_FOR_OP );
4111 #ifndef NO_ANALYTICAL_CURVES
4112 updateAnalyticalCurves();
4117 Performs incremental panning to the bottom
4119 void Plot2d_ViewFrame::onPanDown()
4121 this->incrementalPan( 0, INCREMENT_FOR_OP );
4122 #ifndef NO_ANALYTICAL_CURVES
4123 updateAnalyticalCurves();
4128 Performs incremental zooming in
4130 void Plot2d_ViewFrame::onZoomIn()
4132 this->incrementalZoom( INCREMENT_FOR_OP, INCREMENT_FOR_OP );
4133 #ifndef NO_ANALYTICAL_CURVES
4134 updateAnalyticalCurves();
4139 Performs incremental zooming out
4141 void Plot2d_ViewFrame::onZoomOut()
4143 this->incrementalZoom( -INCREMENT_FOR_OP, -INCREMENT_FOR_OP );
4144 #ifndef NO_ANALYTICAL_CURVES
4145 updateAnalyticalCurves();
4150 Schedules a FitAll operation by putting it to the application's
4151 event queue. This ensures that other important events (show, resize, etc.)
4152 are processed first.
4154 void Plot2d_ViewFrame::customEvent( QEvent* ce )
4156 if ( ce->type() == FITALL_EVENT )
4162 * Return Plot2d_Object by the QwtPlotItem
4165 Plot2d_Object* Plot2d_ViewFrame::getPlotObject( QwtPlotItem* plotItem ) const {
4167 ObjectDict::const_iterator it = myObjects.begin();
4168 for( ; it != myObjects.end(); ++it ) {
4169 if ( it.key() == plotItem ) {
4176 Plot2d_ScaleDraw::Plot2d_ScaleDraw( char f, int prec )
4184 QwtText Plot2d_ScaleDraw::label( double value ) const
4186 QwtScaleMap m = scaleMap();
4187 QString str1 = QwtScaleDraw::label( m.s1() ).text();
4188 QString str2 = QwtScaleDraw::label( m.s2() ).text();
4189 if ( str1 == str2 ) {
4190 double aDist = fabs(scaleMap().s2()-scaleMap().s1())/5;
4192 while (aDist < 1 ) {
4196 if ( precision > 0 && value > 0 )
4197 return QLocale::system().toString( value,'f', precision );
4200 return QwtScaleDraw::label( value );
4203 Plot2d_YScaleDraw::Plot2d_YScaleDraw()
4208 QwtText Plot2d_YScaleDraw::label( double value ) const
4210 // Axis labels format
4211 QString strD = QString( "%1").arg( value, 10, 'e', 3); // format 10.3e
4213 return QwtText( strD);
4216 /* Definition of X axis graduations
4218 const QString Plot2d_AxisScaleDraw::DEVICE_FONT = QString("Times");
4219 const int Plot2d_AxisScaleDraw::DEVICE_FONT_SIZE = 12;
4220 const int Plot2d_AxisScaleDraw::DEVICE_BY = 40;
4222 Plot2d_AxisScaleDraw::Plot2d_AxisScaleDraw( Plot2d_Plot2d* plot)
4227 setLabelAlignment(Qt::AlignRight);
4228 setLabelRotation(45.);
4232 myActivTicksDrawing = true;
4233 myNumTicksDrawingCall = 1;
4237 Plot2d_AxisScaleDraw::~Plot2d_AxisScaleDraw()
4242 /* Unactivate automatic ticks drawing
4244 void Plot2d_AxisScaleDraw::unactivTicksDrawing( int numcall)
4246 myActivTicksDrawing = false;
4247 myNumTicksDrawingCall = numcall;
4251 /* Draw X ticks and labels.
4252 * Draw systems names under X axis.
4253 * Overload the same name QwtScaleDraw method.
4254 * (PB: who call automaticaly this method)
4256 void Plot2d_AxisScaleDraw::draw( QPainter* painter, const QPalette & palette) const
4258 //std::cout << "Plot2d_AxisScaleDraw::draw() : activ= " << myActivTicksDrawing
4259 // << " numcall= " << myNumTicksDrawingCall << std::endl;
4261 if (!myActivTicksDrawing) return;
4263 //std::cout << "Plot2d_AxisScaleDraw::draw()" << std::endl;
4265 QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
4266 QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
4267 QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
4269 medium_ticks.clear();
4270 minor_ticks.clear();
4271 major_ticks.clear();
4273 major_ticks.append( myTicks);
4275 QwtScaleDiv aScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
4276 aScaleDiv.setTicks( QwtScaleDiv::MajorTick, major_ticks );
4277 aScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
4278 aScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
4279 myPlot->setAxisScaleDiv( QwtPlot::xBottom, aScaleDiv );
4281 QwtScaleDraw *scale = myPlot->axisScaleDraw(QwtPlot::xBottom);
4282 ((Plot2d_AxisScaleDraw*)(scale))->applyTicks();
4284 QwtScaleDraw::draw( painter, palette);
4286 for (int i = 0; i < myTicks.size(); i++)
4288 drawLabel( painter, myTicks[i]);
4291 //std::cout << "Ok for Plot2d_AxisScaleDraw::draw()" << std::endl;
4295 double Plot2d_AxisScaleDraw::extent( const QFont &font ) const
4297 QFontMetrics fm( font );
4298 return QwtScaleDraw::extent( font ) + fm.height() * 2;
4301 QwtText Plot2d_AxisScaleDraw::label( double value) const
4303 if (myLabelX.contains(value))
4304 return myLabelX[value];
4306 return QwtText(QString::number(value, 'f', 1));
4310 /* Stock position and label of a X tick
4312 void Plot2d_AxisScaleDraw::setLabelTick( double value, QString label, bool isDevice)
4314 //qDebug()<< "setLabelTick ( " << value << ","<< label <<" )";
4317 // For systems names under X axis
4318 myLabelDevice[value] = label;
4322 // For X axis graduations
4323 myLabelX[value] = label;
4328 /* Stock ticks positions of a system, and draw them
4330 void Plot2d_AxisScaleDraw::setTicks(const QList<double> aTicks)
4332 //std::cout << " Plot2d_AxisScaleDraw::setTicks()" << std::endl;
4339 void Plot2d_AxisScaleDraw::setInterval(double lowerBound, double upperBound)
4341 myLowerBound = lowerBound;
4342 myUpperBound = upperBound;
4343 myPlot->setAxisScale( QwtPlot::xBottom, myLowerBound, myUpperBound );
4347 /* Stock X ticks in drawing zone
4349 void Plot2d_AxisScaleDraw::applyTicks()
4351 //std::cout << " Plot2d_AxisScaleDraw::applyTicks()" << std::endl;
4353 QList<double> major_ticks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
4354 QList<double> medium_ticks = scaleDiv().ticks(QwtScaleDiv::MediumTick);
4355 QList<double> minor_ticks = scaleDiv().ticks(QwtScaleDiv::MinorTick);
4357 medium_ticks.clear();
4358 minor_ticks.clear();
4360 QwtScaleDiv aQwtScaleDiv = myPlot->axisScaleDiv( QwtPlot::xBottom );
4361 aQwtScaleDiv.setTicks( QwtScaleDiv::MajorTick, myTicks );
4362 aQwtScaleDiv.setTicks( QwtScaleDiv::MediumTick, medium_ticks );
4363 aQwtScaleDiv.setTicks( QwtScaleDiv::MinorTick, minor_ticks );
4364 myPlot->setAxisScaleDiv( QwtPlot::xBottom, aQwtScaleDiv );
4366 QwtScaleDiv* aScaleDiv = (QwtScaleDiv*) &scaleDiv();
4368 aScaleDiv->setTicks(QwtScaleDiv::MajorTick, myTicks);
4369 aScaleDiv->setTicks(QwtScaleDiv::MediumTick, medium_ticks);
4370 aScaleDiv->setTicks(QwtScaleDiv::MinorTick, minor_ticks);
4372 if (myLowerBound != -1 && myUpperBound != -1)
4373 aScaleDiv->setInterval(myLowerBound, myUpperBound);
4375 //for (int i = 0; i < myTicks.size(); i++){
4376 // QPoint p = labelPosition( i );
4377 // qDebug() << i<< ") applyTicks -> LABEL" <<p;
4382 void Plot2d_AxisScaleDraw::drawLabel( QPainter* painter, double value) const
4384 //std::cout << " Plot2d_AxisScaleDraw::drawLabel( " << value << " ) : "; //<< std::endl;
4386 //qDebug() << "drawLabel ( " <<value<<" )";
4387 if ( myLabelDevice.contains(value) )
4389 QString deviceLabel = myLabelDevice[value];
4391 std::string std_label = deviceLabel.toStdString();
4392 //const char *c_label = std_label.c_str();
4393 //std::cout << " deviceLabel= |" << c_label << "|" << std::endl;
4395 QPointF p = labelPosition( value );
4396 p += QPoint(0, DEVICE_BY);
4397 QFont prevf = painter->font();
4398 //QColor prevc = (painter->pen()).color();
4400 QFont devicef( DEVICE_FONT, DEVICE_FONT_SIZE, QFont::Bold);
4402 //painter->setPen( QColor("blue") );
4403 painter->setFont( devicef );
4404 painter->drawText( p, myLabelDevice[value] );
4405 //painter->setPen( prevc );
4406 painter->setFont( prevf );
4408 if ( myLabelX.contains(value) )
4410 QString xLabel = myLabelX[value];
4412 std::string std_label = xLabel.toStdString();
4413 //const char *c_label = std_label.c_str();
4414 //std::cout << " xLabel= |" << c_label << "|" << std::endl;
4416 QwtScaleDraw::drawLabel( painter, value );
4421 void Plot2d_AxisScaleDraw::drawTick( QPainter* painter, double value, int len) const
4423 //qDebug() << "drawTick ( " <<value<<" , "<<len<<" ) " ;
4424 //qDebug() << "myLabelX" << myLabelX;
4426 if ( myLabelX.contains(value) )
4428 QwtScaleDraw::drawTick( painter, value, len);
4433 /* Management of tooltips associated with markers for curves points or others points
4435 const double Plot2d_QwtPlotPicker::BOUND_HV_SIZE = 0.2;
4437 Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
4439 RubberBand rubberBand,
4440 DisplayMode trackerMode,
4441 QwtPlotCanvas *canvas)
4442 : QwtPlotPicker( xAxis,
4446 canvas) // of drawing zone QwtPlot
4450 Plot2d_QwtPlotPicker::Plot2d_QwtPlotPicker( int xAxis,
4452 QwtPlotCanvas *canvas)
4453 : QwtPlotPicker( xAxis,
4459 Plot2d_QwtPlotPicker::~Plot2d_QwtPlotPicker()
4462 // http://www.qtcentre.org/threads/22751-How-do-i-select-a-QwtPlotMarker-using-a-QPlotPicker
4464 /* Return the tooltip associated with a point when the mouse cursor pass near
4466 QwtText Plot2d_QwtPlotPicker::trackerText( const QPoint & pos ) const
4468 for (QList<QwtPlotMarker* >::const_iterator pMarkerIt = pMarkers.begin();pMarkerIt != pMarkers.end(); ++pMarkerIt )
4470 QwtPlotMarker* pMarker = *pMarkerIt;
4471 if ( pMarker != NULL )
4473 const QwtSymbol* symb=pMarker->symbol();
4474 const QSize& sz=symb->size();
4475 const QwtScaleMap yMapRef=plot()->canvasMap(QwtPlot::yLeft);
4476 const QwtScaleMap xMap=plot()->canvasMap(pMarker->xAxis());
4477 const QwtScaleMap yMap=plot()->canvasMap(pMarker->yAxis());
4478 QwtDoubleRect bound0=pMarker->boundingRect();
4479 int x1 = qRound(xMap.transform(bound0.left()));
4480 int x2 = qRound(xMap.transform(bound0.right()));
4481 int y1 = qRound(yMap.transform(bound0.top()));
4482 int y2 = qRound(yMap.transform(bound0.bottom()));
4489 QRect bound00=QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
4490 QPoint toto(xMap.transform(pos.x()),yMapRef.transform(pos.y()));
4491 bound00.setX(bound00.x()-sz.width());
4492 bound00.setY(bound00.y()-sz.height());
4493 bound00.setWidth(bound00.width()+sz.width());
4494 bound00.setHeight(bound00.height()+sz.height());
4495 if( bound00.contains(toto) )
4497 return pMarkersToolTip[pMarker];