1 #include "Plot2d_ViewFrame.h"
3 #include "Plot2d_Prs.h"
4 #include "Plot2d_Curve.h"
5 #include "Plot2d_FitDataDlg.h"
6 #include "Plot2d_ViewWindow.h"
7 #include "Plot2d_SetupViewDlg.h"
9 #include "SUIT_Tools.h"
10 #include "SUIT_Session.h"
11 #include "SUIT_MessageBox.h"
12 #include "SUIT_ResourceMgr.h"
13 #include "SUIT_Application.h"
15 //#include "utilities.h"
17 #include "qapplication.h"
19 #include <qtoolbutton.h>
21 #include <qcolordialog.h>
27 #include <qwt_plot_canvas.h>
31 #include <qwt_legend.h>
33 //#include "utilities.h"
35 #define DEFAULT_LINE_WIDTH 0 // (default) line width
36 #define DEFAULT_MARKER_SIZE 9 // default marker size
37 #define MIN_RECT_SIZE 11 // min sensibility area size
39 const char* imageZoomCursor[] = {
44 "................................",
45 "................................",
46 ".#######........................",
47 "..aaaaaaa.......................",
48 "................................",
49 ".............#####..............",
50 "...........##.aaaa##............",
51 "..........#.aa.....a#...........",
52 ".........#.a.........#..........",
53 ".........#a..........#a.........",
54 "........#.a...........#.........",
55 "........#a............#a........",
56 "........#a............#a........",
57 "........#a............#a........",
58 "........#a............#a........",
59 ".........#...........#.a........",
60 ".........#a..........#a.........",
61 ".........##.........#.a.........",
62 "........#####.....##.a..........",
63 ".......###aaa#####.aa...........",
64 "......###aa...aaaaa.......#.....",
65 ".....###aa................#a....",
66 "....###aa.................#a....",
67 "...###aa...............#######..",
68 "....#aa.................aa#aaaa.",
69 ".....a....................#a....",
70 "..........................#a....",
71 "...........................a....",
72 "................................",
73 "................................",
74 "................................",
75 "................................"};
77 const char* imageCrossCursor[] = {
82 "................................",
83 "................................",
84 "................................",
85 "................................",
86 "................................",
87 "................................",
88 "................................",
89 "...............#................",
90 "...............#a...............",
91 "...............#a...............",
92 "...............#a...............",
93 "...............#a...............",
94 "...............#a...............",
95 "...............#a...............",
96 "...............#a...............",
97 ".......#################........",
98 "........aaaaaaa#aaaaaaaaa.......",
99 "...............#a...............",
100 "...............#a...............",
101 "...............#a...............",
102 "...............#a...............",
103 "...............#a...............",
104 "...............#a...............",
105 "...............#a...............",
106 "................a...............",
107 "................................",
108 "................................",
109 "................................",
110 "................................",
111 "................................",
112 "................................",
113 "................................"};
116 QPixmap zoomPixmap(imageZoomCursor);
117 QPixmap globalPanPixmap(imageCrossCursor);
119 QCursor panCursor(Qt::SizeAllCursor);
120 QCursor zoomCursor(zoomPixmap);
121 QCursor glPanCursor(globalPanPixmap);
123 //=================================================================================
124 // Plot2d_ViewFrame implementation
125 //=================================================================================
130 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
131 : QWidget (parent, title, 0),
132 myOperation( NoOpId ),
134 myShowLegend( true ), myLegendPos( 1 ),
135 myMarkerSize( DEFAULT_MARKER_SIZE ),
136 myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
137 myBackground( white ),
138 myTitleEnabled( true ), myXTitleEnabled( true ),
139 myYTitleEnabled( true ), myY2TitleEnabled (true),
140 myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
141 myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
142 myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
143 myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
144 myXMode( 0 ), myYMode( 0 ), mySecondY( false )
147 QVBoxLayout* aLayout = new QVBoxLayout( this );
148 myPlot = new Plot2d_Plot2d( this );
149 aLayout->addWidget( myPlot );
153 connect( myPlot, SIGNAL( plotMouseMoved( const QMouseEvent& ) ),
154 this, SLOT( plotMouseMoved( const QMouseEvent& ) ) );
155 connect( myPlot, SIGNAL( plotMousePressed( const QMouseEvent& ) ),
156 this, SLOT( plotMousePressed( const QMouseEvent& ) ) );
157 connect( myPlot, SIGNAL( plotMouseReleased( const QMouseEvent& ) ),
158 this, SLOT( plotMouseReleased( const QMouseEvent& ) ) );
159 //connect( myPlot, SIGNAL( legendClicked( long ) ),
160 // this, SLOT( onLegendClicked( long ) ) );
162 /* Initial Setup - get from the preferences */
165 myPlot->setMargin( 5 );
166 setCurveType( myCurveType, false );
167 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
168 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
169 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
171 setTitle( myTitleEnabled, myTitle, MainTitle, false );
172 setTitle( myXTitleEnabled, myXTitle, XTitle, false );
173 setTitle( myYTitleEnabled, myYTitle, YTitle, false );
176 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
177 setHorScaleMode( myXMode, false );
178 setVerScaleMode( myYMode, false );
179 setBackgroundColor( myBackground );
180 setLegendPos( myLegendPos );
181 showLegend( myShowLegend, false );
185 resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) );
187 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
188 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
189 myXDistance = xMap.d2() - xMap.d1();
190 myYDistance = yMap.d2() - yMap.d1();
193 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
194 myYDistance2 = yMap2.d2() - yMap2.d1();
200 Plot2d_ViewFrame::~Plot2d_ViewFrame()
204 Gets window's central widget
206 QWidget* Plot2d_ViewFrame::getViewWidget()
208 return (QWidget*)myPlot;
211 Actually this method just re-displays all curves which are presented in the viewer
213 void Plot2d_ViewFrame::DisplayAll()
215 QList<Plot2d_Curve> clist;
217 for ( int i = 0; i < (int)clist.count(); i++ ) {
218 updateCurve( clist.at( i ), false );
223 Removes all curves from the view
225 void Plot2d_ViewFrame::EraseAll()
232 Redraws viewframe contents
234 void Plot2d_ViewFrame::Repaint()
241 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
243 if ( !prs || prs->IsNull() )
246 if (prs->isSecondY()) {
247 myPlot->enableAxis(QwtPlot::yRight, true);
251 myPlot->enableAxis(QwtPlot::yRight, false);
255 // display all curves from presentation
256 curveList aCurves = prs->getCurves();
257 displayCurves( aCurves );
258 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
259 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
260 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
266 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
268 if ( !prs || prs->IsNull() )
271 // erase all curves from presentation
272 curveList aCurves = prs->getCurves();
273 eraseCurves( aCurves );
279 void Plot2d_ViewFrame::setTitle( const QString& title )
281 setTitle( myTitleEnabled, title, MainTitle, true );
285 Reads Plot2d view settings from the preferences
287 void Plot2d_ViewFrame::readPreferences()
289 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
291 myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
292 if ( myCurveType < 1 || myCurveType > 2 )
294 myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
295 myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
296 myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
297 myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
299 myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
300 myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
301 myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
302 myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
304 myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
305 myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
306 myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
308 myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
309 myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
310 myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
312 myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
313 myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
315 myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
317 myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
318 myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
320 myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
322 myXMode = resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode );
323 myXMode = QMAX( 0, QMIN( 1, myXMode ) );
325 myYMode = resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode );
326 myYMode = QMAX( 0, QMIN( 1, myYMode ) );
330 Writes Plot2d view settings to the preferences
332 void Plot2d_ViewFrame::writePreferences()
334 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
336 resMgr->setValue( "Plot2d", "CurveType", myCurveType );
337 resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
338 resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
339 resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
340 resMgr->setValue( "Plot2d", "Background", myBackground );
341 resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
342 resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
343 resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
345 resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
347 resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
348 resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
349 resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
350 resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
352 resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
353 resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
355 resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
356 resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
358 resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
362 resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
363 resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
364 resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
365 resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
368 resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
372 Prints mouse cursor coordinates into string
374 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
377 bool xFound = false, yFound = false;
378 double xCoord, yCoord;
379 const QwtScaleDiv* aXscale = myPlot->axisScale( QwtPlot::xBottom );
380 for ( i = 0; i < aXscale->majCnt(); i++ ) {
381 double majXmark = aXscale->majMark( i );
382 int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
383 if ( xmark-2 == pnt.x() ) {
386 // MESSAGE("Plot2d_ViewFrame::getInfo : close maj X mark("<<i<<") = "<<majXmark<<" "<<xmark<<" "<<pnt.x());
391 for ( i = 0; i < aXscale->minCnt(); i++ ) {
392 double minXmark = aXscale->minMark( i );
393 int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
394 if ( xmark-2 == pnt.x() ) {
397 // MESSAGE("Plot2d_ViewFrame::getInfo : close min X mark("<<i<<") = "<<minXmark<<" "<<xmark<<" "<<pnt.x());
402 const QwtScaleDiv* aYscale = myPlot->axisScale( QwtPlot::yLeft );
403 for ( i = 0; i < aYscale->majCnt(); i++ ) {
404 double majYmark = aYscale->majMark( i );
405 int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
406 if ( ymark-2 == pnt.y() ) {
413 for ( i = 0; i < aYscale->minCnt(); i++ ) {
414 double minYmark = aYscale->minMark( i );
415 int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
416 if ( ymark-2 == pnt.y() ) {
424 QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).stripWhiteSpace();
427 QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).stripWhiteSpace();
433 bool yFound2 = false;
436 const QwtScaleDiv* aYscale2 = myPlot->axisScale( QwtPlot::yRight );
437 for ( i = 0; i < aYscale2->majCnt(); i++ ) {
438 double majYmark = aYscale2->majMark( i );
439 int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
440 if ( ymark-2 == pnt.y() ) {
447 for ( i = 0; i < aYscale2->minCnt(); i++ ) {
448 double minYmark = aYscale2->minMark( i );
449 int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
450 if ( ymark-2 == pnt.y() ) {
457 QString strY2 = QString::number( yFound2 ? yCoord2 :
458 myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).stripWhiteSpace();
461 info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
464 info = tr("INF_COORDINATES").arg( strX ).arg( strY );
470 Converts Plot2d_Curve's marker style to Qwt marker style [ static ]
472 static QwtSymbol::Style plot2qwtMarker( Plot2d_Curve::MarkerType m )
474 QwtSymbol::Style ms = QwtSymbol::None;
476 case Plot2d_Curve::Circle:
477 ms = QwtSymbol::Ellipse; break;
478 case Plot2d_Curve::Rectangle:
479 ms = QwtSymbol::Rect; break;
480 case Plot2d_Curve::Diamond:
481 ms = QwtSymbol::Diamond; break;
482 case Plot2d_Curve::DTriangle:
483 ms = QwtSymbol::DTriangle; break;
484 case Plot2d_Curve::UTriangle:
485 ms = QwtSymbol::UTriangle; break;
486 case Plot2d_Curve::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
487 ms = QwtSymbol::RTriangle; break;
488 case Plot2d_Curve::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
489 ms = QwtSymbol::LTriangle; break;
490 case Plot2d_Curve::Cross:
491 ms = QwtSymbol::Cross; break;
492 case Plot2d_Curve::XCross:
493 ms = QwtSymbol::XCross; break;
494 case Plot2d_Curve::None:
496 ms = QwtSymbol::None; break;
502 Converts Qwt marker style to Plot2d_Curve's marker style [ static ]
504 static Plot2d_Curve::MarkerType qwt2plotMarker( QwtSymbol::Style m )
506 Plot2d_Curve::MarkerType ms = Plot2d_Curve::None;
508 case QwtSymbol::Ellipse:
509 ms = Plot2d_Curve::Circle; break;
510 case QwtSymbol::Rect:
511 ms = Plot2d_Curve::Rectangle; break;
512 case QwtSymbol::Diamond:
513 ms = Plot2d_Curve::Diamond; break;
514 case QwtSymbol::DTriangle:
515 ms = Plot2d_Curve::DTriangle; break;
516 case QwtSymbol::UTriangle:
517 ms = Plot2d_Curve::UTriangle; break;
518 case QwtSymbol::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
519 ms = Plot2d_Curve::LTriangle; break;
520 case QwtSymbol::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
521 ms = Plot2d_Curve::RTriangle; break;
522 case QwtSymbol::Cross:
523 ms = Plot2d_Curve::Cross; break;
524 case QwtSymbol::XCross:
525 ms = Plot2d_Curve::XCross; break;
526 case QwtSymbol::None:
528 ms = Plot2d_Curve::None; break;
534 Converts Plot2d_Curve's line style to Qwt line style [ static ]
536 static Qt::PenStyle plot2qwtLine( Plot2d_Curve::LineType p )
538 Qt::PenStyle ps = Qt::NoPen;
540 case Plot2d_Curve::Solid:
541 ps = Qt::SolidLine; break;
542 case Plot2d_Curve::Dash:
543 ps = Qt::DashLine; break;
544 case Plot2d_Curve::Dot:
545 ps = Qt::DotLine; break;
546 case Plot2d_Curve::DashDot:
547 ps = Qt::DashDotLine; break;
548 case Plot2d_Curve::DashDotDot:
549 ps = Qt::DashDotDotLine; break;
550 case Plot2d_Curve::NoPen:
552 ps = Qt::NoPen; break;
558 Converts Qwt line style to Plot2d_Curve's line style [ static ]
560 static Plot2d_Curve::LineType qwt2plotLine( Qt::PenStyle p )
562 Plot2d_Curve::LineType ps = Plot2d_Curve::NoPen;
565 ps = Plot2d_Curve::Solid; break;
567 ps = Plot2d_Curve::Dash; break;
569 ps = Plot2d_Curve::Dot; break;
570 case Qt::DashDotLine:
571 ps = Plot2d_Curve::DashDot; break;
572 case Qt::DashDotDotLine:
573 ps = Plot2d_Curve::DashDotDot; break;
576 ps = Plot2d_Curve::NoPen; break;
584 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
588 if ( hasCurve( curve ) ) {
589 updateCurve( curve, update );
592 long curveKey = myPlot->insertCurve( curve->getVerTitle() );
593 myPlot->setCurveYAxis(curveKey, curve->getYAxis());
595 myCurves.insert( curveKey, curve );
596 if ( curve->isAutoAssign() ) {
597 QwtSymbol::Style typeMarker;
599 Qt::PenStyle typeLine;
600 myPlot->getNextMarker( typeMarker, color, typeLine );
601 myPlot->setCurvePen( curveKey, QPen( color, DEFAULT_LINE_WIDTH, typeLine ) );
602 myPlot->setCurveSymbol( curveKey, QwtSymbol( typeMarker,
605 QSize( myMarkerSize, myMarkerSize ) ) );
606 curve->setColor( color );
607 curve->setLine( qwt2plotLine( typeLine ) );
608 curve->setMarker( qwt2plotMarker( typeMarker ) );
611 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
612 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
613 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
614 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
615 QBrush( curve->getColor() ),
616 QPen( curve->getColor() ),
617 QSize( myMarkerSize, myMarkerSize ) ) );
619 if ( myCurveType == 0 )
620 myPlot->setCurveStyle( curveKey, QwtCurve::NoCurve );
621 else if ( myCurveType == 1 )
622 myPlot->setCurveStyle( curveKey, QwtCurve::Lines );
623 else if ( myCurveType == 2 )
624 myPlot->setCurveStyle( curveKey, QwtCurve::Spline );
625 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
632 Adds curves into view
634 void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
636 myPlot->setUpdatesEnabled( false );
637 QPtrListIterator<Plot2d_Curve> it(curves);
638 Plot2d_Curve* aCurve;
639 while( (aCurve = it.current()) ) {
640 displayCurve( aCurve, false );
645 myPlot->setUpdatesEnabled( true );
653 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
657 int curveKey = hasCurve( curve );
659 myPlot->removeCurve( curveKey );
660 myCurves.remove( curveKey );
669 void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
671 QPtrListIterator<Plot2d_Curve> it(curves);
672 Plot2d_Curve* aCurve;
673 while( (aCurve = it.current()) ) {
674 eraseCurve( aCurve, false );
683 Updates curves attributes
685 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
689 int curveKey = hasCurve( curve );
691 if ( !curve->isAutoAssign() ) {
692 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
693 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
694 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
695 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
696 QBrush( curve->getColor() ),
697 QPen( curve->getColor() ),
698 QSize( myMarkerSize, myMarkerSize ) ) );
699 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
701 myPlot->setCurveTitle( curveKey, curve->getVerTitle() );
702 myPlot->curve( curveKey )->setEnabled( true );
709 Returns curve key if is is displayed in the viewer and 0 otherwise
711 int Plot2d_ViewFrame::hasCurve( Plot2d_Curve* curve )
713 QIntDictIterator<Plot2d_Curve> it( myCurves );
714 for ( ; it.current(); ++it ) {
715 if ( it.current() == curve )
716 return it.currentKey();
722 Gets lsit of displayed curves
724 int Plot2d_ViewFrame::getCurves( QList<Plot2d_Curve>& clist )
727 clist.setAutoDelete( false );
728 QIntDictIterator<Plot2d_Curve> it( myCurves );
729 for ( ; it.current(); ++it ) {
730 clist.append( it.current() );
732 return clist.count();
736 Returns true if the curve is visible
738 bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve )
741 int key = hasCurve( curve );
743 return myPlot->curve( key )->enabled();
751 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
753 if ( !prs || prs->IsNull() )
755 curveList aCurves = prs->getCurves();
757 QPtrListIterator<Plot2d_Curve> it(aCurves);
758 Plot2d_Curve* aCurve;
759 while( (aCurve = it.current()) ) {
760 int curveKey = hasCurve( aCurve );
762 myPlot->setCurveTitle( curveKey, aCurve->getVerTitle() );
768 Fits the view to see all data
770 void Plot2d_ViewFrame::fitAll()
772 QwtDiMap xMap1 = myPlot->canvasMap( QwtPlot::xBottom );
774 myPlot->setAxisAutoScale( QwtPlot::yLeft );
775 myPlot->setAxisAutoScale( QwtPlot::xBottom );
779 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
780 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
782 myPlot->setAxisScale( QwtPlot::xBottom,
783 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
784 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) );
785 myPlot->setAxisScale( QwtPlot::yLeft,
786 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
787 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) );
790 myPlot->setAxisAutoScale( QwtPlot::yRight );
792 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
793 myPlot->setAxisScale( QwtPlot::yRight,
794 myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ),
795 myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) );
801 Fits the view to rectangle area (pixels)
803 void Plot2d_ViewFrame::fitArea( const QRect& area )
805 QRect rect = area.normalize();
806 if ( rect.width() < MIN_RECT_SIZE ) {
807 rect.setWidth( MIN_RECT_SIZE );
808 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
810 if ( rect.height() < MIN_RECT_SIZE ) {
811 rect.setHeight( MIN_RECT_SIZE );
812 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
814 myPlot->setAxisScale( QwtPlot::yLeft,
815 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
816 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
818 myPlot->setAxisScale( QwtPlot::yRight,
819 myPlot->invTransform( QwtPlot::yRight, rect.top() ),
820 myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
821 myPlot->setAxisScale( QwtPlot::xBottom,
822 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
823 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
828 "Fit Data" command for TUI interface
830 void Plot2d_ViewFrame::fitData(const int mode,
831 const double xMin, const double xMax,
832 const double yMin, const double yMax,
833 double y2Min, double y2Max)
835 if ( mode == 0 || mode == 2 ) {
836 myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin );
838 myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min );
840 if ( mode == 0 || mode == 1 )
841 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
846 Gets current fit ranges for view frame
848 void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax,
849 double& yMin, double& yMax,
850 double& y2Min, double& y2Max)
852 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1();
853 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2();
854 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1();
855 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2();
856 xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
857 xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
858 yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
859 yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
863 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1();
864 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2();
865 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
866 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
871 Tests if it is necessary to start operation on mouse action
873 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
875 int btn = me.button() | me.state();
876 const int zoomBtn = ControlButton | LeftButton;
877 const int panBtn = ControlButton | MidButton;
878 const int fitBtn = ControlButton | RightButton;
883 myPlot->canvas()->setCursor( zoomCursor );
886 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
889 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
897 "Settings" toolbar action slot
899 void Plot2d_ViewFrame::onSettings()
901 #ifdef TEST_AUTOASSIGN
902 typedef QMap<int,int> IList;
903 typedef QMap<QString,int> SList;
906 cols[ "red-min" ] = 1000;
907 cols[ "red-max" ] = -1;
908 cols[ "green-min" ] = 1000;
909 cols[ "green-max" ] = -1;
910 cols[ "blue-min" ] = 1000;
911 cols[ "blue-max" ] = -1;
912 for ( unsigned i = 0; i < 10000; i++ ) {
913 QwtSymbol::Style typeMarker;
915 Qt::PenStyle typeLine;
916 myPlot->getNextMarker( typeMarker, color, typeLine );
917 if ( mars.contains(typeMarker) )
918 mars[ typeMarker ] = mars[ typeMarker ]+1;
920 mars[ typeMarker ] = 0;
921 if ( lins.contains(typeLine) )
922 lins[ typeLine ] = lins[ typeLine ]+1;
924 lins[ typeLine ] = 0;
925 if ( cols[ "red-max" ] < color.red() )
926 cols[ "red-max" ] = color.red();
927 if ( cols[ "red-min" ] > color.red() )
928 cols[ "red-min" ] = color.red();
929 if ( cols[ "green-max" ] < color.green() )
930 cols[ "green-max" ] = color.green();
931 if ( cols[ "green-min" ] > color.green() )
932 cols[ "green-min" ] = color.green();
933 if ( cols[ "blue-max" ] < color.blue() )
934 cols[ "blue-max" ] = color.blue();
935 if ( cols[ "blue-min" ] > color.blue() )
936 cols[ "blue-min" ] = color.blue();
938 for (IList::Iterator it = mars.begin(); it != mars.end(); ++it)
939 MESSAGE("markers( " << it.key() << ") = " << it.data() );
940 for (IList::Iterator it = lins.begin(); it != lins.end(); ++it)
941 MESSAGE("lines( " << it.key() << ") = " << it.data() );
942 for (SList::Iterator it = cols.begin(); it != cols.end(); ++it)
943 MESSAGE("colors( " << it.key() << ") = " << it.data() );
946 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
947 dlg->setMainTitle( myTitleEnabled, myTitle );
948 dlg->setXTitle( myXTitleEnabled, myXTitle );
949 dlg->setYTitle( myYTitleEnabled, myYTitle );
951 dlg->setY2Title( myY2TitleEnabled, myY2Title );
952 dlg->setCurveType( myCurveType );
953 dlg->setLegend( myShowLegend, myLegendPos );
954 dlg->setMarkerSize( myMarkerSize );
955 dlg->setBackgroundColor( myBackground );
956 dlg->setScaleMode(myXMode, myYMode);
958 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
959 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
960 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
961 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
962 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
963 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
964 if ( dlg->exec() == QDialog::Accepted ) {
965 // horizontal axis title
966 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
967 // vertical left axis title
968 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
969 if (mySecondY) // vertical right axis title
970 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
973 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
975 if ( myCurveType != dlg->getCurveType() ) {
976 setCurveType( dlg->getCurveType(), false );
979 if ( myShowLegend != dlg->isLegendEnabled() ) {
980 showLegend( dlg->isLegendEnabled(), false );
982 if ( myLegendPos != dlg->getLegendPos() ) {
983 setLegendPos( dlg->getLegendPos() );
986 if ( myMarkerSize != dlg->getMarkerSize() ) {
987 setMarkerSize( dlg->getMarkerSize(), false );
990 if ( myBackground != dlg->getBackgroundColor() ) {
991 setBackgroundColor( dlg->getBackgroundColor() );
994 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
995 aY2GridMajorEnabled, aY2GridMinorEnabled;
996 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
997 aY2GridMaxMajor, aY2GridMaxMinor;
998 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
999 aY2GridMajorEnabled, aY2GridMaxMajor);
1000 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
1001 aY2GridMinorEnabled, aY2GridMaxMinor);
1002 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
1003 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
1004 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
1005 if ( myXMode != dlg->getXScaleMode() ) {
1006 setHorScaleMode( dlg->getXScaleMode() );
1008 if ( myYMode != dlg->getYScaleMode() ) {
1009 setVerScaleMode( dlg->getYScaleMode() );
1013 // update preferences
1014 if ( dlg->isSetAsDefault() )
1021 "Fit Data" command slot
1023 void Plot2d_ViewFrame::onFitData()
1025 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
1026 double xMin,xMax,yMin,yMax,y2Min,y2Max;
1027 getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
1029 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1030 if ( dlg->exec() == QDialog::Accepted ) {
1031 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1032 fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max);
1038 Change background color
1040 void Plot2d_ViewFrame::onChangeBackground()
1042 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1043 if ( selColor.isValid() ) {
1044 setBackgroundColor( selColor );
1051 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1053 myCurveType = curveType;
1054 QArray<long> keys = myPlot->curveKeys();
1055 for ( int i = 0; i < (int)keys.count(); i++ ) {
1056 if ( myCurveType == 0 )
1057 myPlot->setCurveStyle( keys[i], QwtCurve::Dots );//QwtCurve::NoCurve
1058 else if ( myCurveType == 1 )
1059 myPlot->setCurveStyle( keys[i], QwtCurve::Lines );
1060 else if ( myCurveType == 2 )
1061 myPlot->setCurveStyle( keys[i], QwtCurve::Spline );
1065 emit vpCurveChanged();
1068 void Plot2d_ViewFrame::setCurveTitle( int curveKey, const QString& title )
1070 if(myPlot) myPlot->setCurveTitle(curveKey, title);
1076 void Plot2d_ViewFrame::showLegend( bool show, bool update )
1078 myShowLegend = show;
1079 myPlot->setAutoLegend( myShowLegend );
1080 myPlot->enableLegend( myShowLegend );
1086 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
1088 void Plot2d_ViewFrame::setLegendPos( int pos )
1093 myPlot->setLegendPos( Qwt::Left );
1096 myPlot->setLegendPos( Qwt::Right );
1099 myPlot->setLegendPos( Qwt::Top );
1102 myPlot->setLegendPos( Qwt::Bottom );
1108 Sets new marker size
1110 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
1112 if ( myMarkerSize != size )
1114 myMarkerSize = size;
1115 QArray<long> keys = myPlot->curveKeys();
1116 for ( int i = 0; i < (int)keys.count(); i++ )
1118 QwtPlotCurve* crv = myPlot->curve( keys[i] );
1121 QwtSymbol aSymbol = crv->symbol();
1122 aSymbol.setSize( myMarkerSize, myMarkerSize );
1123 myPlot->setCurveSymbol( keys[i], aSymbol );
1132 Sets background color
1134 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
1136 myBackground = color;
1137 //myPlot->setCanvasBackground( myBackground );
1138 myPlot->canvas()->setPalette( myBackground );
1139 myPlot->setPalette( myBackground );
1140 QPalette aPal = myPlot->getLegend()->palette();
1141 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
1142 QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
1143 aPal.setColor( cg, QColorGroup::Base, myBackground );
1144 aPal.setColor( cg, QColorGroup::Background, myBackground );
1146 myPlot->getLegend()->setPalette( aPal );
1150 Gets background color
1152 QColor Plot2d_ViewFrame::backgroundColor() const
1154 return myBackground;
1157 Sets hor.axis grid parameters
1159 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
1160 bool xMinorEnabled, const int xMinorMax,
1163 if( xMinorMax>=xMajorMax )
1166 myXGridMajorEnabled = xMajorEnabled;
1167 myXGridMinorEnabled = xMinorEnabled;
1168 myXGridMaxMajor = xMajorMax;
1169 myXGridMaxMinor = xMinorMax;
1170 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1171 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1172 myPlot->setGridXAxis(QwtPlot::xBottom);
1173 myPlot->enableGridX( myXGridMajorEnabled );
1174 myPlot->enableGridXMin( myXGridMinorEnabled );
1179 Sets ver.axis grid parameters
1181 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
1182 bool yMinorEnabled, const int yMinorMax,
1183 bool y2MajorEnabled, const int y2MajorMax,
1184 bool y2MinorEnabled, const int y2MinorMax,
1187 myYGridMajorEnabled = yMajorEnabled;
1188 myYGridMinorEnabled = yMinorEnabled;
1189 myYGridMaxMajor = yMajorMax;
1190 myYGridMaxMinor = yMinorMax;
1193 myY2GridMajorEnabled = y2MajorEnabled;
1194 myY2GridMinorEnabled = y2MinorEnabled;
1195 myY2GridMaxMajor = y2MajorMax;
1196 myY2GridMaxMinor = y2MinorMax;
1198 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1199 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1202 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
1203 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
1206 myPlot->setGridYAxis(QwtPlot::yLeft);
1209 if (myYGridMajorEnabled) {
1210 myPlot->enableGridYMin(myYGridMinorEnabled);
1211 myPlot->enableGridY( myYGridMajorEnabled);
1213 else if (myY2GridMajorEnabled) {
1214 myPlot->setGridYAxis(QwtPlot::yRight);
1215 myPlot->enableGridYMin(myY2GridMinorEnabled);
1216 myPlot->enableGridY(myY2GridMajorEnabled);
1219 myPlot->enableGridYMin(false);
1220 myPlot->enableGridY(false);
1224 myPlot->enableGridY( myYGridMajorEnabled );
1225 myPlot->enableGridYMin( myYGridMinorEnabled );
1232 Sets title for some axis
1234 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
1235 ObjectType type, bool update )
1239 myTitleEnabled = enabled;
1241 myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1244 myXTitleEnabled = enabled;
1246 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1249 myYTitleEnabled = enabled;
1251 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1254 myY2TitleEnabled = enabled;
1256 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null );
1263 Sets title for some axis
1265 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
1270 title = myTitle; break;
1272 title = myXTitle; break;
1274 title = myYTitle; break;
1276 title = myY2Title; break;
1281 Sets font for Plot2d object : title or axis
1283 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
1287 myPlot->setTitleFont(font);
1290 myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break;
1292 myPlot->setAxisTitleFont(QwtPlot::yLeft, font); break;
1294 myPlot->setAxisTitleFont(QwtPlot::yRight, font); break;
1296 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
1298 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
1300 myPlot->setAxisFont(QwtPlot::yRight, font); break;
1306 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1308 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1311 if ( myXMode == 0 ) // linear
1312 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1314 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1318 emit vpModeHorChanged();
1321 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1323 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1326 if ( myYMode == 0 ) { // linear
1327 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1329 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1331 else { // logarithmic
1332 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1334 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true );
1338 emit vpModeVerChanged();
1342 Return, scale mode for horizontal axis
1344 bool Plot2d_ViewFrame::isModeHorLinear()
1346 return (myXMode == 0 ? true : false);
1350 Return, scale mode for vertical axis
1352 bool Plot2d_ViewFrame::isModeVerLinear()
1354 return (myYMode == 0 ? true : false);
1357 Slot, called when user presses mouse button
1359 void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me )
1361 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1362 if ( myOperation == NoOpId )
1363 myOperation = testOperation( me );
1364 if ( myOperation != NoOpId ) {
1366 if ( myOperation == FitAreaId ) {
1367 myPlot->setOutlineStyle( Qwt::Rect );
1369 else if ( myOperation == GlPanId ) {
1370 myPlot->setAxisScale( QwtPlot::yLeft,
1371 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2,
1372 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 );
1373 myPlot->setAxisScale( QwtPlot::xBottom,
1374 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
1375 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
1377 myPlot->setAxisScale( QwtPlot::yRight,
1378 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2,
1379 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 );
1384 int btn = me.button() | me.state();
1385 if (btn == RightButton) {
1386 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
1387 me.pos(), btn, me.state());
1388 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
1389 parent()->eventFilter(this, aEvent);
1394 Slot, called when user moves mouse
1396 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1398 int dx = me.pos().x() - myPnt.x();
1399 int dy = me.pos().y() - myPnt.y();
1401 if ( myOperation != NoOpId) {
1402 if ( myOperation == ZoomId ) {
1403 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1404 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1406 myPlot->setAxisScale( QwtPlot::yLeft,
1407 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1408 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1409 myPlot->setAxisScale( QwtPlot::xBottom,
1410 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1411 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1413 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1414 myPlot->setAxisScale( QwtPlot::yRight,
1415 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1416 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + dy ) );
1421 else if ( myOperation == PanId ) {
1422 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1423 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1425 myPlot->setAxisScale( QwtPlot::yLeft,
1426 myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
1427 myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1428 myPlot->setAxisScale( QwtPlot::xBottom,
1429 myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1430 myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
1432 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1433 myPlot->setAxisScale( QwtPlot::yRight,
1434 myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-dy ),
1435 myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-dy ) );
1442 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1446 Slot, called when user releases mouse
1448 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1450 if ( myOperation == NoOpId && me.button() == RightButton )
1452 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1453 me.pos(), me.globalPos(),
1455 emit contextMenuRequested( &aEvent );
1457 if ( myOperation == FitAreaId ) {
1458 QRect rect( myPnt, me.pos() );
1461 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1462 myPlot->setOutlineStyle( Qwt::Triangle );
1464 ((Plot2d_ViewWindow*)parent())->putInfo(tr("INF_READY"));
1465 myOperation = NoOpId;
1468 Slot, called when user wheeling mouse
1470 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
1472 double aDelta = event->delta();
1473 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
1475 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1476 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1478 myPlot->setAxisScale( QwtPlot::yLeft,
1479 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1480 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale );
1481 myPlot->setAxisScale( QwtPlot::xBottom,
1482 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1483 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale );
1485 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1486 myPlot->setAxisScale( QwtPlot::yRight,
1487 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1488 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale );
1491 myPnt = event->pos();
1494 View operations : Pan view
1496 void Plot2d_ViewFrame::onViewPan()
1498 myPlot->canvas()->setCursor( panCursor );
1499 myOperation = PanId;
1500 qApp->installEventFilter( this );
1503 View operations : Zoom view
1505 void Plot2d_ViewFrame::onViewZoom()
1507 myPlot->canvas()->setCursor( zoomCursor );
1508 myOperation = ZoomId;
1509 qApp->installEventFilter( this );
1512 View operations : Fot All
1514 void Plot2d_ViewFrame::onViewFitAll()
1519 View operations : Fit Area
1521 void Plot2d_ViewFrame::onViewFitArea()
1523 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1524 myOperation = FitAreaId;
1525 qApp->installEventFilter( this );
1528 View operations : Global panning
1530 void Plot2d_ViewFrame::onViewGlobalPan()
1532 myPlot->canvas()->setCursor( glPanCursor );
1533 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1534 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1536 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1538 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1539 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1541 myXDistance = xMap.d2() - xMap.d1();
1542 myYDistance = yMap.d2() - yMap.d1();
1545 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
1546 myYDistance2 = yMap2.d2() - yMap2.d1();
1549 myOperation = GlPanId;
1550 qApp->installEventFilter( this );
1553 //=================================================================================
1554 // Plot2d_Plot2d implementation
1555 //=================================================================================
1559 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1563 enableOutline( true );
1564 setOutlineStyle( Qwt::Triangle );
1565 setOutlinePen( green );
1567 setAutoLegend( false );
1568 setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1569 enableLegend( false );
1571 enableGridX( false );
1572 enableGridXMin( false );
1573 enableGridY( false );
1574 enableGridYMin( false );
1575 // auto scaling by default
1576 setAxisAutoScale( QwtPlot::yLeft );
1577 setAxisAutoScale( QwtPlot::yRight );
1578 setAxisAutoScale( QwtPlot::xBottom );
1581 Recalculates and redraws Plot 2d view
1583 void Plot2d_Plot2d::replot()
1585 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
1590 Checks if two colors are close to each other [ static ]
1591 uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1593 const long COLOR_DISTANCE = 100;
1594 const int MAX_ATTEMPTS = 10;
1595 static bool closeColors( const QColor& color1, const QColor& color2 )
1597 long tol = abs( color2.red() - color1.red() ) +
1598 abs( color2.green() - color1.green() ) +
1599 abs( color2.blue() - color1.blue() );
1601 return ( tol <= COLOR_DISTANCE );
1604 Gets new unique marker for item if possible
1606 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
1611 int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
1612 int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
1613 int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
1614 int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty )
1615 int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty )
1617 typeMarker = ( QwtSymbol::Style )aMarker;
1618 color = QColor( aRed, aGreen, aBlue );
1619 typeLine = ( Qt::PenStyle )aLine;
1622 if ( cnt == MAX_ATTEMPTS )
1625 bOk = !existMarker( typeMarker, color, typeLine );
1628 static int aMarker = -1;
1629 static int aColor = -1;
1630 static int aLine = -1;
1632 if ( myColors.isEmpty() ) {
1633 // creating colors list
1634 myColors.append( Qt::white );
1635 myColors.append( Qt::blue );
1636 myColors.append( Qt::gray );
1637 myColors.append( Qt::darkGreen );
1638 myColors.append( Qt::magenta );
1639 myColors.append( Qt::darkGray );
1640 myColors.append( Qt::red );
1641 myColors.append( Qt::darkBlue );
1642 myColors.append( Qt::darkYellow );
1643 myColors.append( Qt::cyan );
1644 myColors.append( Qt::darkRed );
1645 myColors.append( Qt::darkCyan );
1646 myColors.append( Qt::yellow );
1647 myColors.append( Qt::darkMagenta );
1648 myColors.append( Qt::green );
1649 myColors.append( Qt::black );
1652 int nbMarkers = 11; // QwtSymbol supports 11 marker types
1653 int nbLines = 6; // Qt supports 6 line types
1654 int nbColors = myColors.count(); // number of default colors supported
1656 aMarker = ( aMarker + 1 ) % nbMarkers;
1657 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1658 aColor = ( aColor + 1 ) % nbColors;
1659 aLine = ( aLine + 1 ) % nbLines;
1660 if ( aLine == Qt::NoPen ) aLine++;
1662 typeMarker = ( QwtSymbol::Style )aMarker;
1663 color = myColors[ aColor ];
1664 typeLine = ( Qt::PenStyle )aLine;
1665 if ( !existMarker( typeMarker, color, typeLine ) )
1669 for ( i = 0; i < nbMarkers; i++ ) {
1670 aMarker = ( aMarker + 1 ) % nbMarkers;
1671 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1672 for ( j = 0; j < nbColors; j++ ) {
1673 aColor = ( aColor + 1 ) % nbColors;
1674 for ( k = 0; k < nbLines; k++ ) {
1675 aLine = ( aLine + 1 ) % nbLines;
1676 if ( aLine == Qt::NoPen ) aLine++;
1677 if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1678 typeMarker = ( QwtSymbol::Style )aMarker;
1679 color = myColors[ aColor ];
1680 typeLine = ( Qt::PenStyle )aLine;
1689 QSizePolicy Plot2d_Plot2d::sizePolicy() const
1691 return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
1694 QSize Plot2d_Plot2d::sizeHint() const
1696 return QwtPlot::minimumSizeHint();
1700 return minimum size for qwt plot
1702 QSize Plot2d_Plot2d::minimumSizeHint() const
1704 return QSize( 0, 0 );
1705 // QSize aSize = QwtPlot::minimumSizeHint();
1706 // return QSize(aSize.width()*3/4, aSize.height());
1709 Checks if marker belongs to any enitity
1711 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
1713 // getting all curves
1714 QArray<long> keys = curveKeys();
1717 if ( closeColors( color, backgroundColor() ) )
1719 for ( int i = 0; i < (int)keys.count(); i++ )
1721 QwtPlotCurve* crv = curve( keys[i] );
1723 QwtSymbol::Style aStyle = crv->symbol().style();
1724 QColor aColor = crv->pen().color();
1725 Qt::PenStyle aLine = crv->pen().style();
1726 // if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1727 if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
1734 // TEMPORARY SOLUTION!!! TO BE IMPLEMENTED!!!
1735 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
1740 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
1745 myCurveType = vf->myCurveType;
1746 myShowLegend = vf->myShowLegend;
1747 myLegendPos = vf->myLegendPos;
1748 myMarkerSize = vf->myMarkerSize;
1749 myBackground = vf->myBackground;
1750 myTitle = vf->myTitle;
1751 myXTitle = vf->myXTitle;
1752 myYTitle = vf->myYTitle;
1753 myY2Title = vf->myY2Title;
1754 myTitleEnabled = vf->myTitleEnabled;
1755 myXTitleEnabled = vf->myXTitleEnabled;
1756 myYTitleEnabled = vf->myYTitleEnabled;
1757 myY2TitleEnabled = vf->myY2TitleEnabled;
1758 myXGridMajorEnabled = vf->myXGridMajorEnabled;
1759 myYGridMajorEnabled = vf->myYGridMajorEnabled;
1760 myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
1761 myXGridMinorEnabled = vf->myXGridMinorEnabled;
1762 myYGridMinorEnabled = vf->myYGridMinorEnabled;
1763 myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
1764 myXGridMaxMajor = vf->myXGridMaxMajor;
1765 myYGridMaxMajor = vf->myYGridMaxMajor;
1766 myY2GridMaxMajor = vf->myY2GridMaxMajor;
1767 myXGridMaxMinor = vf->myXGridMaxMinor;
1768 myYGridMaxMinor = vf->myYGridMaxMinor;
1769 myY2GridMaxMinor = vf->myY2GridMaxMinor;
1770 myXMode = vf->myXMode;
1771 myYMode = vf->myYMode;
1772 mySecondY = vf->mySecondY;