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 Tests if it is necessary to start operation on mouse action
830 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
832 int btn = me.button() | me.state();
833 const int zoomBtn = ControlButton | LeftButton;
834 const int panBtn = ControlButton | MidButton;
835 const int fitBtn = ControlButton | RightButton;
840 myPlot->canvas()->setCursor( zoomCursor );
843 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
846 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
854 "Settings" toolbar action slot
856 void Plot2d_ViewFrame::onSettings()
858 #ifdef TEST_AUTOASSIGN
859 typedef QMap<int,int> IList;
860 typedef QMap<QString,int> SList;
863 cols[ "red-min" ] = 1000;
864 cols[ "red-max" ] = -1;
865 cols[ "green-min" ] = 1000;
866 cols[ "green-max" ] = -1;
867 cols[ "blue-min" ] = 1000;
868 cols[ "blue-max" ] = -1;
869 for ( unsigned i = 0; i < 10000; i++ ) {
870 QwtSymbol::Style typeMarker;
872 Qt::PenStyle typeLine;
873 myPlot->getNextMarker( typeMarker, color, typeLine );
874 if ( mars.contains(typeMarker) )
875 mars[ typeMarker ] = mars[ typeMarker ]+1;
877 mars[ typeMarker ] = 0;
878 if ( lins.contains(typeLine) )
879 lins[ typeLine ] = lins[ typeLine ]+1;
881 lins[ typeLine ] = 0;
882 if ( cols[ "red-max" ] < color.red() )
883 cols[ "red-max" ] = color.red();
884 if ( cols[ "red-min" ] > color.red() )
885 cols[ "red-min" ] = color.red();
886 if ( cols[ "green-max" ] < color.green() )
887 cols[ "green-max" ] = color.green();
888 if ( cols[ "green-min" ] > color.green() )
889 cols[ "green-min" ] = color.green();
890 if ( cols[ "blue-max" ] < color.blue() )
891 cols[ "blue-max" ] = color.blue();
892 if ( cols[ "blue-min" ] > color.blue() )
893 cols[ "blue-min" ] = color.blue();
895 for (IList::Iterator it = mars.begin(); it != mars.end(); ++it)
896 MESSAGE("markers( " << it.key() << ") = " << it.data() );
897 for (IList::Iterator it = lins.begin(); it != lins.end(); ++it)
898 MESSAGE("lines( " << it.key() << ") = " << it.data() );
899 for (SList::Iterator it = cols.begin(); it != cols.end(); ++it)
900 MESSAGE("colors( " << it.key() << ") = " << it.data() );
903 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
904 dlg->setMainTitle( myTitleEnabled, myTitle );
905 dlg->setXTitle( myXTitleEnabled, myXTitle );
906 dlg->setYTitle( myYTitleEnabled, myYTitle );
908 dlg->setY2Title( myY2TitleEnabled, myY2Title );
909 dlg->setCurveType( myCurveType );
910 dlg->setLegend( myShowLegend, myLegendPos );
911 dlg->setMarkerSize( myMarkerSize );
912 dlg->setBackgroundColor( myBackground );
913 dlg->setScaleMode(myXMode, myYMode);
915 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
916 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
917 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
918 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
919 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
920 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
921 if ( dlg->exec() == QDialog::Accepted ) {
922 // horizontal axis title
923 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
924 // vertical left axis title
925 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
926 if (mySecondY) // vertical right axis title
927 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
930 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
932 if ( myCurveType != dlg->getCurveType() ) {
933 setCurveType( dlg->getCurveType(), false );
936 if ( myShowLegend != dlg->isLegendEnabled() ) {
937 showLegend( dlg->isLegendEnabled(), false );
939 if ( myLegendPos != dlg->getLegendPos() ) {
940 setLegendPos( dlg->getLegendPos() );
943 if ( myMarkerSize != dlg->getMarkerSize() ) {
944 setMarkerSize( dlg->getMarkerSize(), false );
947 if ( myBackground != dlg->getBackgroundColor() ) {
948 setBackgroundColor( dlg->getBackgroundColor() );
951 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
952 aY2GridMajorEnabled, aY2GridMinorEnabled;
953 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
954 aY2GridMaxMajor, aY2GridMaxMinor;
955 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
956 aY2GridMajorEnabled, aY2GridMaxMajor);
957 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
958 aY2GridMinorEnabled, aY2GridMaxMinor);
959 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
960 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
961 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
962 if ( myXMode != dlg->getXScaleMode() ) {
963 setHorScaleMode( dlg->getXScaleMode() );
965 if ( myYMode != dlg->getYScaleMode() ) {
966 setVerScaleMode( dlg->getYScaleMode() );
970 // update preferences
971 if ( dlg->isSetAsDefault() )
978 "Fit Data" command slot
980 void Plot2d_ViewFrame::onFitData()
982 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
983 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1();
984 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2();
985 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1();
986 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2();
987 double xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
988 double xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
989 double yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
990 double yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
994 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1();
995 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2();
996 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
997 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
1000 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1001 if ( dlg->exec() == QDialog::Accepted ) {
1002 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1003 if ( mode == 0 || mode == 2 ) {
1004 myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin );
1006 myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min );
1008 if ( mode == 0 || mode == 1 )
1009 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
1016 Change background color
1018 void Plot2d_ViewFrame::onChangeBackground()
1020 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1021 if ( selColor.isValid() ) {
1022 setBackgroundColor( selColor );
1029 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1031 myCurveType = curveType;
1032 QArray<long> keys = myPlot->curveKeys();
1033 for ( int i = 0; i < (int)keys.count(); i++ ) {
1034 if ( myCurveType == 0 )
1035 myPlot->setCurveStyle( keys[i], QwtCurve::Dots );//QwtCurve::NoCurve
1036 else if ( myCurveType == 1 )
1037 myPlot->setCurveStyle( keys[i], QwtCurve::Lines );
1038 else if ( myCurveType == 2 )
1039 myPlot->setCurveStyle( keys[i], QwtCurve::Spline );
1043 emit vpCurveChanged();
1046 void Plot2d_ViewFrame::setCurveTitle( int curveKey, const QString& title )
1048 if(myPlot) myPlot->setCurveTitle(curveKey, title);
1054 void Plot2d_ViewFrame::showLegend( bool show, bool update )
1056 myShowLegend = show;
1057 myPlot->setAutoLegend( myShowLegend );
1058 myPlot->enableLegend( myShowLegend );
1064 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
1066 void Plot2d_ViewFrame::setLegendPos( int pos )
1071 myPlot->setLegendPos( Qwt::Left );
1074 myPlot->setLegendPos( Qwt::Right );
1077 myPlot->setLegendPos( Qwt::Top );
1080 myPlot->setLegendPos( Qwt::Bottom );
1086 Sets new marker size
1088 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
1090 if ( myMarkerSize != size )
1092 myMarkerSize = size;
1093 QArray<long> keys = myPlot->curveKeys();
1094 for ( int i = 0; i < (int)keys.count(); i++ )
1096 QwtPlotCurve* crv = myPlot->curve( keys[i] );
1099 QwtSymbol aSymbol = crv->symbol();
1100 aSymbol.setSize( myMarkerSize, myMarkerSize );
1101 myPlot->setCurveSymbol( keys[i], aSymbol );
1110 Sets background color
1112 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
1114 myBackground = color;
1115 //myPlot->setCanvasBackground( myBackground );
1116 myPlot->canvas()->setPalette( myBackground );
1117 myPlot->setPalette( myBackground );
1118 QPalette aPal = myPlot->getLegend()->palette();
1119 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
1120 QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
1121 aPal.setColor( cg, QColorGroup::Base, myBackground );
1122 aPal.setColor( cg, QColorGroup::Background, myBackground );
1124 myPlot->getLegend()->setPalette( aPal );
1128 Gets background color
1130 QColor Plot2d_ViewFrame::backgroundColor() const
1132 return myBackground;
1135 Sets hor.axis grid parameters
1137 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
1138 bool xMinorEnabled, const int xMinorMax,
1141 myXGridMajorEnabled = xMajorEnabled;
1142 myXGridMinorEnabled = xMinorEnabled;
1143 myXGridMaxMajor = xMajorMax;
1144 myXGridMaxMinor = xMinorMax;
1145 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1146 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1147 myPlot->setGridXAxis(QwtPlot::xBottom);
1148 myPlot->enableGridX( myXGridMajorEnabled );
1149 myPlot->enableGridXMin( myXGridMinorEnabled );
1154 Sets ver.axis grid parameters
1156 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
1157 bool yMinorEnabled, const int yMinorMax,
1158 bool y2MajorEnabled, const int y2MajorMax,
1159 bool y2MinorEnabled, const int y2MinorMax,
1162 myYGridMajorEnabled = yMajorEnabled;
1163 myYGridMinorEnabled = yMinorEnabled;
1164 myYGridMaxMajor = yMajorMax;
1165 myYGridMaxMinor = yMinorMax;
1168 myY2GridMajorEnabled = y2MajorEnabled;
1169 myY2GridMinorEnabled = y2MinorEnabled;
1170 myY2GridMaxMajor = y2MajorMax;
1171 myY2GridMaxMinor = y2MinorMax;
1173 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1174 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1177 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
1178 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
1181 myPlot->setGridYAxis(QwtPlot::yLeft);
1184 if (myYGridMajorEnabled) {
1185 myPlot->enableGridYMin(myYGridMinorEnabled);
1186 myPlot->enableGridY( myYGridMajorEnabled);
1188 else if (myY2GridMajorEnabled) {
1189 myPlot->setGridYAxis(QwtPlot::yRight);
1190 myPlot->enableGridYMin(myY2GridMinorEnabled);
1191 myPlot->enableGridY(myY2GridMajorEnabled);
1194 myPlot->enableGridYMin(false);
1195 myPlot->enableGridY(false);
1199 myPlot->enableGridY( myYGridMajorEnabled );
1200 myPlot->enableGridYMin( myYGridMinorEnabled );
1207 Sets title for some axis
1209 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
1210 ObjectType type, bool update )
1214 myTitleEnabled = enabled;
1216 myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1219 myXTitleEnabled = enabled;
1221 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1224 myYTitleEnabled = enabled;
1226 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1229 myY2TitleEnabled = enabled;
1231 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null );
1238 Sets title for some axis
1240 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
1245 title = myTitle; break;
1247 title = myXTitle; break;
1249 title = myYTitle; break;
1251 title = myY2Title; break;
1256 Sets font for Plot2d object : title or axis
1258 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
1262 myPlot->setTitleFont(font);
1265 myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break;
1267 myPlot->setAxisTitleFont(QwtPlot::yLeft, font); break;
1269 myPlot->setAxisTitleFont(QwtPlot::yRight, font); break;
1271 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
1273 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
1275 myPlot->setAxisFont(QwtPlot::yRight, font); break;
1281 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1283 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1286 if ( myXMode == 0 ) // linear
1287 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1289 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1293 emit vpModeHorChanged();
1296 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1298 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1301 if ( myYMode == 0 ) { // linear
1302 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1304 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1306 else { // logarithmic
1307 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1309 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true );
1313 emit vpModeVerChanged();
1317 Return, scale mode for horizontal axis
1319 bool Plot2d_ViewFrame::isModeHorLinear()
1321 return (myXMode == 0 ? true : false);
1325 Return, scale mode for vertical axis
1327 bool Plot2d_ViewFrame::isModeVerLinear()
1329 return (myYMode == 0 ? true : false);
1332 Slot, called when user presses mouse button
1334 void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me )
1336 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1337 if ( myOperation == NoOpId )
1338 myOperation = testOperation( me );
1339 if ( myOperation != NoOpId ) {
1341 if ( myOperation == FitAreaId ) {
1342 myPlot->setOutlineStyle( Qwt::Rect );
1344 else if ( myOperation == GlPanId ) {
1345 myPlot->setAxisScale( QwtPlot::yLeft,
1346 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2,
1347 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 );
1348 myPlot->setAxisScale( QwtPlot::xBottom,
1349 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
1350 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
1352 myPlot->setAxisScale( QwtPlot::yRight,
1353 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2,
1354 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 );
1359 int btn = me.button() | me.state();
1360 if (btn == RightButton) {
1361 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
1362 me.pos(), btn, me.state());
1363 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
1364 parent()->eventFilter(this, aEvent);
1369 Slot, called when user moves mouse
1371 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1373 int dx = me.pos().x() - myPnt.x();
1374 int dy = me.pos().y() - myPnt.y();
1376 if ( myOperation != NoOpId) {
1377 if ( myOperation == ZoomId ) {
1378 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1379 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1381 myPlot->setAxisScale( QwtPlot::yLeft,
1382 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1383 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1384 myPlot->setAxisScale( QwtPlot::xBottom,
1385 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1386 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1388 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1389 myPlot->setAxisScale( QwtPlot::yRight,
1390 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1391 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + dy ) );
1396 else if ( myOperation == PanId ) {
1397 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1398 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1400 myPlot->setAxisScale( QwtPlot::yLeft,
1401 myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
1402 myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1403 myPlot->setAxisScale( QwtPlot::xBottom,
1404 myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1405 myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
1407 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1408 myPlot->setAxisScale( QwtPlot::yRight,
1409 myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-dy ),
1410 myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-dy ) );
1417 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1421 Slot, called when user releases mouse
1423 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1425 if ( myOperation == NoOpId && me.button() == RightButton )
1427 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1428 me.pos(), me.globalPos(),
1430 emit contextMenuRequested( &aEvent );
1432 if ( myOperation == FitAreaId ) {
1433 QRect rect( myPnt, me.pos() );
1436 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1437 myPlot->setOutlineStyle( Qwt::Triangle );
1439 ((Plot2d_ViewWindow*)parent())->putInfo(tr("INF_READY"));
1440 myOperation = NoOpId;
1443 Slot, called when user wheeling mouse
1445 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
1447 double aDelta = event->delta();
1448 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
1450 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1451 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1453 myPlot->setAxisScale( QwtPlot::yLeft,
1454 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1455 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale );
1456 myPlot->setAxisScale( QwtPlot::xBottom,
1457 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1458 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale );
1460 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1461 myPlot->setAxisScale( QwtPlot::yRight,
1462 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1463 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale );
1466 myPnt = event->pos();
1469 View operations : Pan view
1471 void Plot2d_ViewFrame::onViewPan()
1473 myPlot->canvas()->setCursor( panCursor );
1474 myOperation = PanId;
1475 qApp->installEventFilter( this );
1478 View operations : Zoom view
1480 void Plot2d_ViewFrame::onViewZoom()
1482 myPlot->canvas()->setCursor( zoomCursor );
1483 myOperation = ZoomId;
1484 qApp->installEventFilter( this );
1487 View operations : Fot All
1489 void Plot2d_ViewFrame::onViewFitAll()
1494 View operations : Fit Area
1496 void Plot2d_ViewFrame::onViewFitArea()
1498 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1499 myOperation = FitAreaId;
1500 qApp->installEventFilter( this );
1503 View operations : Global panning
1505 void Plot2d_ViewFrame::onViewGlobalPan()
1507 myPlot->canvas()->setCursor( glPanCursor );
1508 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1509 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1511 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1513 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1514 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1516 myXDistance = xMap.d2() - xMap.d1();
1517 myYDistance = yMap.d2() - yMap.d1();
1520 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
1521 myYDistance2 = yMap2.d2() - yMap2.d1();
1524 myOperation = GlPanId;
1525 qApp->installEventFilter( this );
1528 //=================================================================================
1529 // Plot2d_Plot2d implementation
1530 //=================================================================================
1534 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1538 enableOutline( true );
1539 setOutlineStyle( Qwt::Triangle );
1540 setOutlinePen( green );
1542 setAutoLegend( false );
1543 setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1544 enableLegend( false );
1546 enableGridX( false );
1547 enableGridXMin( false );
1548 enableGridY( false );
1549 enableGridYMin( false );
1550 // auto scaling by default
1551 setAxisAutoScale( QwtPlot::yLeft );
1552 setAxisAutoScale( QwtPlot::yRight );
1553 setAxisAutoScale( QwtPlot::xBottom );
1556 Recalculates and redraws Plot 2d view
1558 void Plot2d_Plot2d::replot()
1560 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
1565 Checks if two colors are close to each other [ static ]
1566 uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1568 const long COLOR_DISTANCE = 100;
1569 const int MAX_ATTEMPTS = 10;
1570 static bool closeColors( const QColor& color1, const QColor& color2 )
1572 long tol = abs( color2.red() - color1.red() ) +
1573 abs( color2.green() - color1.green() ) +
1574 abs( color2.blue() - color1.blue() );
1576 return ( tol <= COLOR_DISTANCE );
1579 Gets new unique marker for item if possible
1581 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
1586 int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
1587 int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
1588 int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
1589 int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty )
1590 int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty )
1592 typeMarker = ( QwtSymbol::Style )aMarker;
1593 color = QColor( aRed, aGreen, aBlue );
1594 typeLine = ( Qt::PenStyle )aLine;
1597 if ( cnt == MAX_ATTEMPTS )
1600 bOk = !existMarker( typeMarker, color, typeLine );
1603 static int aMarker = -1;
1604 static int aColor = -1;
1605 static int aLine = -1;
1607 if ( myColors.isEmpty() ) {
1608 // creating colors list
1609 myColors.append( Qt::white );
1610 myColors.append( Qt::blue );
1611 myColors.append( Qt::gray );
1612 myColors.append( Qt::darkGreen );
1613 myColors.append( Qt::magenta );
1614 myColors.append( Qt::darkGray );
1615 myColors.append( Qt::red );
1616 myColors.append( Qt::darkBlue );
1617 myColors.append( Qt::darkYellow );
1618 myColors.append( Qt::cyan );
1619 myColors.append( Qt::darkRed );
1620 myColors.append( Qt::darkCyan );
1621 myColors.append( Qt::yellow );
1622 myColors.append( Qt::darkMagenta );
1623 myColors.append( Qt::green );
1624 myColors.append( Qt::black );
1627 int nbMarkers = 11; // QwtSymbol supports 11 marker types
1628 int nbLines = 6; // Qt supports 6 line types
1629 int nbColors = myColors.count(); // number of default colors supported
1631 aMarker = ( aMarker + 1 ) % nbMarkers;
1632 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1633 aColor = ( aColor + 1 ) % nbColors;
1634 aLine = ( aLine + 1 ) % nbLines;
1635 if ( aLine == Qt::NoPen ) aLine++;
1637 typeMarker = ( QwtSymbol::Style )aMarker;
1638 color = myColors[ aColor ];
1639 typeLine = ( Qt::PenStyle )aLine;
1640 if ( !existMarker( typeMarker, color, typeLine ) )
1644 for ( i = 0; i < nbMarkers; i++ ) {
1645 aMarker = ( aMarker + 1 ) % nbMarkers;
1646 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1647 for ( j = 0; j < nbColors; j++ ) {
1648 aColor = ( aColor + 1 ) % nbColors;
1649 for ( k = 0; k < nbLines; k++ ) {
1650 aLine = ( aLine + 1 ) % nbLines;
1651 if ( aLine == Qt::NoPen ) aLine++;
1652 if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1653 typeMarker = ( QwtSymbol::Style )aMarker;
1654 color = myColors[ aColor ];
1655 typeLine = ( Qt::PenStyle )aLine;
1664 QSizePolicy Plot2d_Plot2d::sizePolicy() const
1666 return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
1669 QSize Plot2d_Plot2d::sizeHint() const
1671 return QwtPlot::minimumSizeHint();
1675 return minimum size for qwt plot
1677 QSize Plot2d_Plot2d::minimumSizeHint() const
1679 return QSize( 0, 0 );
1680 // QSize aSize = QwtPlot::minimumSizeHint();
1681 // return QSize(aSize.width()*3/4, aSize.height());
1684 Checks if marker belongs to any enitity
1686 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
1688 // getting all curves
1689 QArray<long> keys = curveKeys();
1692 if ( closeColors( color, backgroundColor() ) )
1694 for ( int i = 0; i < (int)keys.count(); i++ )
1696 QwtPlotCurve* crv = curve( keys[i] );
1698 QwtSymbol::Style aStyle = crv->symbol().style();
1699 QColor aColor = crv->pen().color();
1700 Qt::PenStyle aLine = crv->pen().style();
1701 // if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1702 if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
1709 // TEMPORARY SOLUTION!!! TO BE IMPLEMENTED!!!
1710 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
1715 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
1720 myCurveType = vf->myCurveType;
1721 myShowLegend = vf->myShowLegend;
1722 myLegendPos = vf->myLegendPos;
1723 myMarkerSize = vf->myMarkerSize;
1724 myBackground = vf->myBackground;
1725 myTitle = vf->myTitle;
1726 myXTitle = vf->myXTitle;
1727 myYTitle = vf->myYTitle;
1728 myY2Title = vf->myY2Title;
1729 myTitleEnabled = vf->myTitleEnabled;
1730 myXTitleEnabled = vf->myXTitleEnabled;
1731 myYTitleEnabled = vf->myYTitleEnabled;
1732 myY2TitleEnabled = vf->myY2TitleEnabled;
1733 myXGridMajorEnabled = vf->myXGridMajorEnabled;
1734 myYGridMajorEnabled = vf->myYGridMajorEnabled;
1735 myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
1736 myXGridMinorEnabled = vf->myXGridMinorEnabled;
1737 myYGridMinorEnabled = vf->myYGridMinorEnabled;
1738 myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
1739 myXGridMaxMajor = vf->myXGridMaxMajor;
1740 myYGridMaxMajor = vf->myYGridMaxMajor;
1741 myY2GridMaxMajor = vf->myY2GridMaxMajor;
1742 myXGridMaxMinor = vf->myXGridMaxMinor;
1743 myYGridMaxMinor = vf->myYGridMaxMinor;
1744 myY2GridMaxMinor = vf->myY2GridMaxMinor;
1745 myXMode = vf->myXMode;
1746 myYMode = vf->myYMode;
1747 mySecondY = vf->mySecondY;