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 "utilities.h"
33 #define DEFAULT_LINE_WIDTH 0 // (default) line width
34 #define DEFAULT_MARKER_SIZE 9 // default marker size
35 #define MIN_RECT_SIZE 11 // min sensibility area size
37 const char* imageZoomCursor[] = {
42 "................................",
43 "................................",
44 ".#######........................",
45 "..aaaaaaa.......................",
46 "................................",
47 ".............#####..............",
48 "...........##.aaaa##............",
49 "..........#.aa.....a#...........",
50 ".........#.a.........#..........",
51 ".........#a..........#a.........",
52 "........#.a...........#.........",
53 "........#a............#a........",
54 "........#a............#a........",
55 "........#a............#a........",
56 "........#a............#a........",
57 ".........#...........#.a........",
58 ".........#a..........#a.........",
59 ".........##.........#.a.........",
60 "........#####.....##.a..........",
61 ".......###aaa#####.aa...........",
62 "......###aa...aaaaa.......#.....",
63 ".....###aa................#a....",
64 "....###aa.................#a....",
65 "...###aa...............#######..",
66 "....#aa.................aa#aaaa.",
67 ".....a....................#a....",
68 "..........................#a....",
69 "...........................a....",
70 "................................",
71 "................................",
72 "................................",
73 "................................"};
75 const char* imageCrossCursor[] = {
80 "................................",
81 "................................",
82 "................................",
83 "................................",
84 "................................",
85 "................................",
86 "................................",
87 "...............#................",
88 "...............#a...............",
89 "...............#a...............",
90 "...............#a...............",
91 "...............#a...............",
92 "...............#a...............",
93 "...............#a...............",
94 "...............#a...............",
95 ".......#################........",
96 "........aaaaaaa#aaaaaaaaa.......",
97 "...............#a...............",
98 "...............#a...............",
99 "...............#a...............",
100 "...............#a...............",
101 "...............#a...............",
102 "...............#a...............",
103 "...............#a...............",
104 "................a...............",
105 "................................",
106 "................................",
107 "................................",
108 "................................",
109 "................................",
110 "................................",
111 "................................"};
114 QPixmap zoomPixmap(imageZoomCursor);
115 QPixmap globalPanPixmap(imageCrossCursor);
117 QCursor panCursor(Qt::SizeAllCursor);
118 QCursor zoomCursor(zoomPixmap);
119 QCursor glPanCursor(globalPanPixmap);
121 //=================================================================================
122 // Plot2d_ViewFrame implementation
123 //=================================================================================
128 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
129 : QWidget (parent, title, 0),
130 myOperation( NoOpId ),
132 myShowLegend( true ), myLegendPos( 1 ),
133 myMarkerSize( DEFAULT_MARKER_SIZE ),
134 myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
135 myBackground( white ),
136 myTitleEnabled( true ), myXTitleEnabled( true ),
137 myYTitleEnabled( true ), myY2TitleEnabled (true),
138 myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
139 myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
140 myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
141 myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
142 myXMode( 0 ), myYMode( 0 ), mySecondY( false )
145 QVBoxLayout* aLayout = new QVBoxLayout( this );
146 myPlot = new Plot2d_Plot2d( this );
147 aLayout->addWidget( myPlot );
151 connect( myPlot, SIGNAL( plotMouseMoved( const QMouseEvent& ) ),
152 this, SLOT( plotMouseMoved( const QMouseEvent& ) ) );
153 connect( myPlot, SIGNAL( plotMousePressed( const QMouseEvent& ) ),
154 this, SLOT( plotMousePressed( const QMouseEvent& ) ) );
155 connect( myPlot, SIGNAL( plotMouseReleased( const QMouseEvent& ) ),
156 this, SLOT( plotMouseReleased( const QMouseEvent& ) ) );
157 //connect( myPlot, SIGNAL( legendClicked( long ) ),
158 // this, SLOT( onLegendClicked( long ) ) );
160 /* Initial Setup - get from the preferences */
163 myPlot->setMargin( 5 );
164 setCurveType( myCurveType, false );
165 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
166 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
167 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
169 setTitle( myTitleEnabled, myTitle, MainTitle, false );
170 setTitle( myXTitleEnabled, myXTitle, XTitle, false );
171 setTitle( myYTitleEnabled, myYTitle, YTitle, false );
174 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
175 setHorScaleMode( myXMode, false );
176 setVerScaleMode( myYMode, false );
177 setBackgroundColor( myBackground );
178 setLegendPos( myLegendPos );
179 showLegend( myShowLegend, false );
183 resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) );
185 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
186 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
187 myXDistance = xMap.d2() - xMap.d1();
188 myYDistance = yMap.d2() - yMap.d1();
191 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
192 myYDistance2 = yMap2.d2() - yMap2.d1();
198 Plot2d_ViewFrame::~Plot2d_ViewFrame()
202 Gets window's central widget
204 QWidget* Plot2d_ViewFrame::getViewWidget()
206 return (QWidget*)myPlot;
209 Actually this method just re-displays all curves which are presented in the viewer
211 void Plot2d_ViewFrame::DisplayAll()
213 QList<Plot2d_Curve> clist;
215 for ( int i = 0; i < (int)clist.count(); i++ ) {
216 updateCurve( clist.at( i ), false );
221 Removes all curves from the view
223 void Plot2d_ViewFrame::EraseAll()
230 Redraws viewframe contents
232 void Plot2d_ViewFrame::Repaint()
239 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
241 if ( !prs || prs->IsNull() )
244 if (prs->isSecondY()) {
245 myPlot->enableAxis(QwtPlot::yRight, true);
249 myPlot->enableAxis(QwtPlot::yRight, false);
253 // display all curves from presentation
254 curveList aCurves = prs->getCurves();
255 displayCurves( aCurves );
256 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
257 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
258 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
264 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
266 if ( !prs || prs->IsNull() )
269 // erase all curves from presentation
270 curveList aCurves = prs->getCurves();
271 eraseCurves( aCurves );
277 void Plot2d_ViewFrame::setTitle( const QString& title )
279 setTitle( myTitleEnabled, title, MainTitle, true );
283 Reads Plot2d view settings from the preferences
285 void Plot2d_ViewFrame::readPreferences()
287 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
289 myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
290 if ( myCurveType < 1 || myCurveType > 2 )
292 myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
293 myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
294 myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
295 myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
297 myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
298 myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
299 myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
300 myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
302 myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
303 myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
304 myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
306 myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
307 myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
308 myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
310 myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
311 myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
313 myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
315 myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
316 myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
318 myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
320 myXMode = resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode );
321 myXMode = QMAX( 0, QMIN( 1, myXMode ) );
323 myYMode = resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode );
324 myYMode = QMAX( 0, QMIN( 1, myYMode ) );
328 Writes Plot2d view settings to the preferences
330 void Plot2d_ViewFrame::writePreferences()
332 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
334 resMgr->setValue( "Plot2d", "CurveType", myCurveType );
335 resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
336 resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
337 resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
338 resMgr->setValue( "Plot2d", "Background", myBackground );
339 resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
340 resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
341 resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
343 resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
345 resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
346 resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
347 resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
348 resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
350 resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
351 resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
353 resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
354 resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
356 resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
360 resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
361 resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
362 resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
363 resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
366 resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
370 Prints mouse cursor coordinates into string
372 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
375 bool xFound = false, yFound = false;
376 double xCoord, yCoord;
377 const QwtScaleDiv* aXscale = myPlot->axisScale( QwtPlot::xBottom );
378 for ( i = 0; i < aXscale->majCnt(); i++ ) {
379 double majXmark = aXscale->majMark( i );
380 int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
381 if ( xmark-2 == pnt.x() ) {
384 // MESSAGE("Plot2d_ViewFrame::getInfo : close maj X mark("<<i<<") = "<<majXmark<<" "<<xmark<<" "<<pnt.x());
389 for ( i = 0; i < aXscale->minCnt(); i++ ) {
390 double minXmark = aXscale->minMark( i );
391 int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
392 if ( xmark-2 == pnt.x() ) {
395 // MESSAGE("Plot2d_ViewFrame::getInfo : close min X mark("<<i<<") = "<<minXmark<<" "<<xmark<<" "<<pnt.x());
400 const QwtScaleDiv* aYscale = myPlot->axisScale( QwtPlot::yLeft );
401 for ( i = 0; i < aYscale->majCnt(); i++ ) {
402 double majYmark = aYscale->majMark( i );
403 int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
404 if ( ymark-2 == pnt.y() ) {
411 for ( i = 0; i < aYscale->minCnt(); i++ ) {
412 double minYmark = aYscale->minMark( i );
413 int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
414 if ( ymark-2 == pnt.y() ) {
422 QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).stripWhiteSpace();
425 QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).stripWhiteSpace();
431 bool yFound2 = false;
434 const QwtScaleDiv* aYscale2 = myPlot->axisScale( QwtPlot::yRight );
435 for ( i = 0; i < aYscale2->majCnt(); i++ ) {
436 double majYmark = aYscale2->majMark( i );
437 int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
438 if ( ymark-2 == pnt.y() ) {
445 for ( i = 0; i < aYscale2->minCnt(); i++ ) {
446 double minYmark = aYscale2->minMark( i );
447 int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
448 if ( ymark-2 == pnt.y() ) {
455 QString strY2 = QString::number( yFound2 ? yCoord2 :
456 myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).stripWhiteSpace();
459 info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
462 info = tr("INF_COORDINATES").arg( strX ).arg( strY );
468 Converts Plot2d_Curve's marker style to Qwt marker style [ static ]
470 static QwtSymbol::Style plot2qwtMarker( Plot2d_Curve::MarkerType m )
472 QwtSymbol::Style ms = QwtSymbol::None;
474 case Plot2d_Curve::Circle:
475 ms = QwtSymbol::Ellipse; break;
476 case Plot2d_Curve::Rectangle:
477 ms = QwtSymbol::Rect; break;
478 case Plot2d_Curve::Diamond:
479 ms = QwtSymbol::Diamond; break;
480 case Plot2d_Curve::DTriangle:
481 ms = QwtSymbol::DTriangle; break;
482 case Plot2d_Curve::UTriangle:
483 ms = QwtSymbol::UTriangle; break;
484 case Plot2d_Curve::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
485 ms = QwtSymbol::RTriangle; break;
486 case Plot2d_Curve::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
487 ms = QwtSymbol::LTriangle; break;
488 case Plot2d_Curve::Cross:
489 ms = QwtSymbol::Cross; break;
490 case Plot2d_Curve::XCross:
491 ms = QwtSymbol::XCross; break;
492 case Plot2d_Curve::None:
494 ms = QwtSymbol::None; break;
500 Converts Qwt marker style to Plot2d_Curve's marker style [ static ]
502 static Plot2d_Curve::MarkerType qwt2plotMarker( QwtSymbol::Style m )
504 Plot2d_Curve::MarkerType ms = Plot2d_Curve::None;
506 case QwtSymbol::Ellipse:
507 ms = Plot2d_Curve::Circle; break;
508 case QwtSymbol::Rect:
509 ms = Plot2d_Curve::Rectangle; break;
510 case QwtSymbol::Diamond:
511 ms = Plot2d_Curve::Diamond; break;
512 case QwtSymbol::DTriangle:
513 ms = Plot2d_Curve::DTriangle; break;
514 case QwtSymbol::UTriangle:
515 ms = Plot2d_Curve::UTriangle; break;
516 case QwtSymbol::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
517 ms = Plot2d_Curve::LTriangle; break;
518 case QwtSymbol::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
519 ms = Plot2d_Curve::RTriangle; break;
520 case QwtSymbol::Cross:
521 ms = Plot2d_Curve::Cross; break;
522 case QwtSymbol::XCross:
523 ms = Plot2d_Curve::XCross; break;
524 case QwtSymbol::None:
526 ms = Plot2d_Curve::None; break;
532 Converts Plot2d_Curve's line style to Qwt line style [ static ]
534 static Qt::PenStyle plot2qwtLine( Plot2d_Curve::LineType p )
536 Qt::PenStyle ps = Qt::NoPen;
538 case Plot2d_Curve::Solid:
539 ps = Qt::SolidLine; break;
540 case Plot2d_Curve::Dash:
541 ps = Qt::DashLine; break;
542 case Plot2d_Curve::Dot:
543 ps = Qt::DotLine; break;
544 case Plot2d_Curve::DashDot:
545 ps = Qt::DashDotLine; break;
546 case Plot2d_Curve::DashDotDot:
547 ps = Qt::DashDotDotLine; break;
548 case Plot2d_Curve::NoPen:
550 ps = Qt::NoPen; break;
556 Converts Qwt line style to Plot2d_Curve's line style [ static ]
558 static Plot2d_Curve::LineType qwt2plotLine( Qt::PenStyle p )
560 Plot2d_Curve::LineType ps = Plot2d_Curve::NoPen;
563 ps = Plot2d_Curve::Solid; break;
565 ps = Plot2d_Curve::Dash; break;
567 ps = Plot2d_Curve::Dot; break;
568 case Qt::DashDotLine:
569 ps = Plot2d_Curve::DashDot; break;
570 case Qt::DashDotDotLine:
571 ps = Plot2d_Curve::DashDotDot; break;
574 ps = Plot2d_Curve::NoPen; break;
582 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
586 if ( hasCurve( curve ) ) {
587 updateCurve( curve, update );
590 long curveKey = myPlot->insertCurve( curve->getVerTitle() );
591 myPlot->setCurveYAxis(curveKey, curve->getYAxis());
593 myCurves.insert( curveKey, curve );
594 if ( curve->isAutoAssign() ) {
595 QwtSymbol::Style typeMarker;
597 Qt::PenStyle typeLine;
598 myPlot->getNextMarker( typeMarker, color, typeLine );
599 myPlot->setCurvePen( curveKey, QPen( color, DEFAULT_LINE_WIDTH, typeLine ) );
600 myPlot->setCurveSymbol( curveKey, QwtSymbol( typeMarker,
603 QSize( myMarkerSize, myMarkerSize ) ) );
604 curve->setColor( color );
605 curve->setLine( qwt2plotLine( typeLine ) );
606 curve->setMarker( qwt2plotMarker( typeMarker ) );
609 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
610 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
611 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
612 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
613 QBrush( curve->getColor() ),
614 QPen( curve->getColor() ),
615 QSize( myMarkerSize, myMarkerSize ) ) );
617 if ( myCurveType == 0 )
618 myPlot->setCurveStyle( curveKey, QwtCurve::NoCurve );
619 else if ( myCurveType == 1 )
620 myPlot->setCurveStyle( curveKey, QwtCurve::Lines );
621 else if ( myCurveType == 2 )
622 myPlot->setCurveStyle( curveKey, QwtCurve::Spline );
623 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
630 Adds curves into view
632 void Plot2d_ViewFrame::displayCurves( curveList curves, bool update )
634 myPlot->setUpdatesEnabled( false );
635 QPtrListIterator<Plot2d_Curve> it(curves);
636 Plot2d_Curve* aCurve;
637 while( (aCurve = it.current()) ) {
638 displayCurve( aCurve, false );
643 myPlot->setUpdatesEnabled( true );
651 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
655 int curveKey = hasCurve( curve );
657 myPlot->removeCurve( curveKey );
658 myCurves.remove( curveKey );
667 void Plot2d_ViewFrame::eraseCurves( curveList& curves, bool update )
669 QPtrListIterator<Plot2d_Curve> it(curves);
670 Plot2d_Curve* aCurve;
671 while( (aCurve = it.current()) ) {
672 eraseCurve( aCurve, false );
681 Updates curves attributes
683 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
687 int curveKey = hasCurve( curve );
689 if ( !curve->isAutoAssign() ) {
690 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
691 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
692 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
693 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
694 QBrush( curve->getColor() ),
695 QPen( curve->getColor() ),
696 QSize( myMarkerSize, myMarkerSize ) ) );
697 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
699 myPlot->setCurveTitle( curveKey, curve->getVerTitle() );
700 myPlot->curve( curveKey )->setEnabled( true );
707 Returns curve key if is is displayed in the viewer and 0 otherwise
709 int Plot2d_ViewFrame::hasCurve( Plot2d_Curve* curve )
711 QIntDictIterator<Plot2d_Curve> it( myCurves );
712 for ( ; it.current(); ++it ) {
713 if ( it.current() == curve )
714 return it.currentKey();
720 Gets lsit of displayed curves
722 int Plot2d_ViewFrame::getCurves( QList<Plot2d_Curve>& clist )
725 clist.setAutoDelete( false );
726 QIntDictIterator<Plot2d_Curve> it( myCurves );
727 for ( ; it.current(); ++it ) {
728 clist.append( it.current() );
730 return clist.count();
734 Returns true if the curve is visible
736 bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve )
739 int key = hasCurve( curve );
741 return myPlot->curve( key )->enabled();
749 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
751 if ( !prs || prs->IsNull() )
753 curveList aCurves = prs->getCurves();
755 QPtrListIterator<Plot2d_Curve> it(aCurves);
756 Plot2d_Curve* aCurve;
757 while( (aCurve = it.current()) ) {
758 int curveKey = hasCurve( aCurve );
760 myPlot->setCurveTitle( curveKey, aCurve->getVerTitle() );
766 Fits the view to see all data
768 void Plot2d_ViewFrame::fitAll()
770 QwtDiMap xMap1 = myPlot->canvasMap( QwtPlot::xBottom );
772 myPlot->setAxisAutoScale( QwtPlot::yLeft );
773 myPlot->setAxisAutoScale( QwtPlot::xBottom );
777 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
778 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
780 myPlot->setAxisScale( QwtPlot::xBottom,
781 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
782 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) );
783 myPlot->setAxisScale( QwtPlot::yLeft,
784 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
785 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) );
788 myPlot->setAxisAutoScale( QwtPlot::yRight );
790 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
791 myPlot->setAxisScale( QwtPlot::yRight,
792 myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ),
793 myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) );
799 Fits the view to rectangle area (pixels)
801 void Plot2d_ViewFrame::fitArea( const QRect& area )
803 QRect rect = area.normalize();
804 if ( rect.width() < MIN_RECT_SIZE ) {
805 rect.setWidth( MIN_RECT_SIZE );
806 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
808 if ( rect.height() < MIN_RECT_SIZE ) {
809 rect.setHeight( MIN_RECT_SIZE );
810 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
812 myPlot->setAxisScale( QwtPlot::yLeft,
813 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
814 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
816 myPlot->setAxisScale( QwtPlot::yRight,
817 myPlot->invTransform( QwtPlot::yRight, rect.top() ),
818 myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
819 myPlot->setAxisScale( QwtPlot::xBottom,
820 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
821 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
826 Tests if it is necessary to start operation on mouse action
828 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
830 int btn = me.button() | me.state();
831 const int zoomBtn = ControlButton | LeftButton;
832 const int panBtn = ControlButton | MidButton;
833 const int fitBtn = ControlButton | RightButton;
838 myPlot->canvas()->setCursor( zoomCursor );
841 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
844 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
852 "Settings" toolbar action slot
854 void Plot2d_ViewFrame::onSettings()
856 #ifdef TEST_AUTOASSIGN
857 typedef QMap<int,int> IList;
858 typedef QMap<QString,int> SList;
861 cols[ "red-min" ] = 1000;
862 cols[ "red-max" ] = -1;
863 cols[ "green-min" ] = 1000;
864 cols[ "green-max" ] = -1;
865 cols[ "blue-min" ] = 1000;
866 cols[ "blue-max" ] = -1;
867 for ( unsigned i = 0; i < 10000; i++ ) {
868 QwtSymbol::Style typeMarker;
870 Qt::PenStyle typeLine;
871 myPlot->getNextMarker( typeMarker, color, typeLine );
872 if ( mars.contains(typeMarker) )
873 mars[ typeMarker ] = mars[ typeMarker ]+1;
875 mars[ typeMarker ] = 0;
876 if ( lins.contains(typeLine) )
877 lins[ typeLine ] = lins[ typeLine ]+1;
879 lins[ typeLine ] = 0;
880 if ( cols[ "red-max" ] < color.red() )
881 cols[ "red-max" ] = color.red();
882 if ( cols[ "red-min" ] > color.red() )
883 cols[ "red-min" ] = color.red();
884 if ( cols[ "green-max" ] < color.green() )
885 cols[ "green-max" ] = color.green();
886 if ( cols[ "green-min" ] > color.green() )
887 cols[ "green-min" ] = color.green();
888 if ( cols[ "blue-max" ] < color.blue() )
889 cols[ "blue-max" ] = color.blue();
890 if ( cols[ "blue-min" ] > color.blue() )
891 cols[ "blue-min" ] = color.blue();
893 for (IList::Iterator it = mars.begin(); it != mars.end(); ++it)
894 MESSAGE("markers( " << it.key() << ") = " << it.data() );
895 for (IList::Iterator it = lins.begin(); it != lins.end(); ++it)
896 MESSAGE("lines( " << it.key() << ") = " << it.data() );
897 for (SList::Iterator it = cols.begin(); it != cols.end(); ++it)
898 MESSAGE("colors( " << it.key() << ") = " << it.data() );
901 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
902 dlg->setMainTitle( myTitleEnabled, myTitle );
903 dlg->setXTitle( myXTitleEnabled, myXTitle );
904 dlg->setYTitle( myYTitleEnabled, myYTitle );
906 dlg->setY2Title( myY2TitleEnabled, myY2Title );
907 dlg->setCurveType( myCurveType );
908 dlg->setLegend( myShowLegend, myLegendPos );
909 dlg->setMarkerSize( myMarkerSize );
910 dlg->setBackgroundColor( myBackground );
911 dlg->setScaleMode(myXMode, myYMode);
913 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
914 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
915 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
916 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
917 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
918 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
919 if ( dlg->exec() == QDialog::Accepted ) {
920 // horizontal axis title
921 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
922 // vertical left axis title
923 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
924 if (mySecondY) // vertical right axis title
925 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
928 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
930 if ( myCurveType != dlg->getCurveType() ) {
931 setCurveType( dlg->getCurveType(), false );
934 if ( myShowLegend != dlg->isLegendEnabled() ) {
935 showLegend( dlg->isLegendEnabled(), false );
937 if ( myLegendPos != dlg->getLegendPos() ) {
938 setLegendPos( dlg->getLegendPos() );
941 if ( myMarkerSize != dlg->getMarkerSize() ) {
942 setMarkerSize( dlg->getMarkerSize(), false );
945 if ( myBackground != dlg->getBackgroundColor() ) {
946 setBackgroundColor( dlg->getBackgroundColor() );
949 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
950 aY2GridMajorEnabled, aY2GridMinorEnabled;
951 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
952 aY2GridMaxMajor, aY2GridMaxMinor;
953 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
954 aY2GridMajorEnabled, aY2GridMaxMajor);
955 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
956 aY2GridMinorEnabled, aY2GridMaxMinor);
957 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
958 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
959 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
960 if ( myXMode != dlg->getXScaleMode() ) {
961 setHorScaleMode( dlg->getXScaleMode() );
963 if ( myYMode != dlg->getYScaleMode() ) {
964 setVerScaleMode( dlg->getYScaleMode() );
968 // update preferences
969 if ( dlg->isSetAsDefault() )
976 "Fit Data" command slot
978 void Plot2d_ViewFrame::onFitData()
980 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
981 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1();
982 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2();
983 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1();
984 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2();
985 double xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
986 double xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
987 double yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
988 double yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
992 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1();
993 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2();
994 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
995 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
998 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
999 if ( dlg->exec() == QDialog::Accepted ) {
1000 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1001 if ( mode == 0 || mode == 2 ) {
1002 myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin );
1004 myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min );
1006 if ( mode == 0 || mode == 1 )
1007 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
1014 Change background color
1016 void Plot2d_ViewFrame::onChangeBackground()
1018 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1019 if ( selColor.isValid() ) {
1020 setBackgroundColor( selColor );
1027 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1029 myCurveType = curveType;
1030 QArray<long> keys = myPlot->curveKeys();
1031 for ( int i = 0; i < (int)keys.count(); i++ ) {
1032 if ( myCurveType == 0 )
1033 myPlot->setCurveStyle( keys[i], QwtCurve::Dots );//QwtCurve::NoCurve
1034 else if ( myCurveType == 1 )
1035 myPlot->setCurveStyle( keys[i], QwtCurve::Lines );
1036 else if ( myCurveType == 2 )
1037 myPlot->setCurveStyle( keys[i], QwtCurve::Spline );
1041 emit vpCurveChanged();
1044 void Plot2d_ViewFrame::setCurveTitle( int curveKey, const QString& title )
1046 if(myPlot) myPlot->setCurveTitle(curveKey, title);
1052 void Plot2d_ViewFrame::showLegend( bool show, bool update )
1054 myShowLegend = show;
1055 myPlot->setAutoLegend( myShowLegend );
1056 myPlot->enableLegend( myShowLegend );
1062 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
1064 void Plot2d_ViewFrame::setLegendPos( int pos )
1069 myPlot->setLegendPos( Qwt::Left );
1072 myPlot->setLegendPos( Qwt::Right );
1075 myPlot->setLegendPos( Qwt::Top );
1078 myPlot->setLegendPos( Qwt::Bottom );
1084 Sets new marker size
1086 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
1088 if ( myMarkerSize != size )
1090 myMarkerSize = size;
1091 QArray<long> keys = myPlot->curveKeys();
1092 for ( int i = 0; i < (int)keys.count(); i++ )
1094 QwtPlotCurve* crv = myPlot->curve( keys[i] );
1097 QwtSymbol aSymbol = crv->symbol();
1098 aSymbol.setSize( myMarkerSize, myMarkerSize );
1099 myPlot->setCurveSymbol( keys[i], aSymbol );
1108 Sets background color
1110 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
1112 myBackground = color;
1113 //myPlot->setCanvasBackground( myBackground );
1114 myPlot->canvas()->setPalette( myBackground );
1115 myPlot->setPalette( myBackground );
1116 QPalette aPal = myPlot->getLegend()->palette();
1117 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
1118 QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
1119 aPal.setColor( cg, QColorGroup::Base, myBackground );
1120 aPal.setColor( cg, QColorGroup::Background, myBackground );
1122 myPlot->getLegend()->setPalette( aPal );
1126 Gets background color
1128 QColor Plot2d_ViewFrame::backgroundColor() const
1130 return myBackground;
1133 Sets hor.axis grid parameters
1135 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
1136 bool xMinorEnabled, const int xMinorMax,
1139 myXGridMajorEnabled = xMajorEnabled;
1140 myXGridMinorEnabled = xMinorEnabled;
1141 myXGridMaxMajor = xMajorMax;
1142 myXGridMaxMinor = xMinorMax;
1143 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1144 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1145 myPlot->setGridXAxis(QwtPlot::xBottom);
1146 myPlot->enableGridX( myXGridMajorEnabled );
1147 myPlot->enableGridXMin( myXGridMinorEnabled );
1152 Sets ver.axis grid parameters
1154 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
1155 bool yMinorEnabled, const int yMinorMax,
1156 bool y2MajorEnabled, const int y2MajorMax,
1157 bool y2MinorEnabled, const int y2MinorMax,
1160 myYGridMajorEnabled = yMajorEnabled;
1161 myYGridMinorEnabled = yMinorEnabled;
1162 myYGridMaxMajor = yMajorMax;
1163 myYGridMaxMinor = yMinorMax;
1166 myY2GridMajorEnabled = y2MajorEnabled;
1167 myY2GridMinorEnabled = y2MinorEnabled;
1168 myY2GridMaxMajor = y2MajorMax;
1169 myY2GridMaxMinor = y2MinorMax;
1171 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1172 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1175 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
1176 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
1179 myPlot->setGridYAxis(QwtPlot::yLeft);
1182 if (myYGridMajorEnabled) {
1183 myPlot->enableGridYMin(myYGridMinorEnabled);
1184 myPlot->enableGridY( myYGridMajorEnabled);
1186 else if (myY2GridMajorEnabled) {
1187 myPlot->setGridYAxis(QwtPlot::yRight);
1188 myPlot->enableGridYMin(myY2GridMinorEnabled);
1189 myPlot->enableGridY(myY2GridMajorEnabled);
1192 myPlot->enableGridYMin(false);
1193 myPlot->enableGridY(false);
1197 myPlot->enableGridY( myYGridMajorEnabled );
1198 myPlot->enableGridYMin( myYGridMinorEnabled );
1205 Sets title for some axis
1207 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
1208 ObjectType type, bool update )
1212 myTitleEnabled = enabled;
1214 myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1217 myXTitleEnabled = enabled;
1219 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1222 myYTitleEnabled = enabled;
1224 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1227 myY2TitleEnabled = enabled;
1229 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null );
1236 Sets title for some axis
1238 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
1243 title = myTitle; break;
1245 title = myXTitle; break;
1247 title = myYTitle; break;
1249 title = myY2Title; break;
1254 Sets font for Plot2d object : title or axis
1256 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
1260 myPlot->setTitleFont(font);
1263 myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break;
1265 myPlot->setAxisTitleFont(QwtPlot::yLeft, font); break;
1267 myPlot->setAxisTitleFont(QwtPlot::yRight, font); break;
1269 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
1271 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
1273 myPlot->setAxisFont(QwtPlot::yRight, font); break;
1279 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1281 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1284 if ( myXMode == 0 ) // linear
1285 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1287 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1291 emit vpModeHorChanged();
1294 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1296 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1299 if ( myYMode == 0 ) { // linear
1300 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1302 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1304 else { // logarithmic
1305 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1307 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true );
1311 emit vpModeVerChanged();
1315 Return, scale mode for horizontal axis
1317 bool Plot2d_ViewFrame::isModeHorLinear()
1319 return (myXMode == 0 ? true : false);
1323 Return, scale mode for vertical axis
1325 bool Plot2d_ViewFrame::isModeVerLinear()
1327 return (myYMode == 0 ? true : false);
1330 Slot, called when user presses mouse button
1332 void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me )
1334 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1335 if ( myOperation == NoOpId )
1336 myOperation = testOperation( me );
1337 if ( myOperation != NoOpId ) {
1339 if ( myOperation == FitAreaId ) {
1340 myPlot->setOutlineStyle( Qwt::Rect );
1342 else if ( myOperation == GlPanId ) {
1343 myPlot->setAxisScale( QwtPlot::yLeft,
1344 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2,
1345 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 );
1346 myPlot->setAxisScale( QwtPlot::xBottom,
1347 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
1348 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
1350 myPlot->setAxisScale( QwtPlot::yRight,
1351 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2,
1352 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 );
1357 int btn = me.button() | me.state();
1358 if (btn == RightButton) {
1359 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
1360 me.pos(), btn, me.state());
1361 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
1362 parent()->eventFilter(this, aEvent);
1367 Slot, called when user moves mouse
1369 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1371 int dx = me.pos().x() - myPnt.x();
1372 int dy = me.pos().y() - myPnt.y();
1374 if ( myOperation != NoOpId) {
1375 if ( myOperation == ZoomId ) {
1376 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1377 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1379 myPlot->setAxisScale( QwtPlot::yLeft,
1380 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1381 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1382 myPlot->setAxisScale( QwtPlot::xBottom,
1383 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1384 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1386 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1387 myPlot->setAxisScale( QwtPlot::yRight,
1388 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1389 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + dy ) );
1394 else if ( myOperation == PanId ) {
1395 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1396 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1398 myPlot->setAxisScale( QwtPlot::yLeft,
1399 myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
1400 myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1401 myPlot->setAxisScale( QwtPlot::xBottom,
1402 myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1403 myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
1405 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1406 myPlot->setAxisScale( QwtPlot::yRight,
1407 myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-dy ),
1408 myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-dy ) );
1415 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1419 Slot, called when user releases mouse
1421 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1423 if ( myOperation == NoOpId && me.button() == RightButton )
1425 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1426 me.pos(), me.globalPos(),
1428 emit contextMenuRequested( &aEvent );
1430 if ( myOperation == FitAreaId ) {
1431 QRect rect( myPnt, me.pos() );
1434 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1435 myPlot->setOutlineStyle( Qwt::Triangle );
1437 ((Plot2d_ViewWindow*)parent())->putInfo(tr("INF_READY"));
1438 myOperation = NoOpId;
1441 Slot, called when user wheeling mouse
1443 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
1445 double aDelta = event->delta();
1446 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
1448 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1449 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1451 myPlot->setAxisScale( QwtPlot::yLeft,
1452 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1453 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale );
1454 myPlot->setAxisScale( QwtPlot::xBottom,
1455 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1456 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale );
1458 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1459 myPlot->setAxisScale( QwtPlot::yRight,
1460 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1461 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale );
1464 myPnt = event->pos();
1467 View operations : Pan view
1469 void Plot2d_ViewFrame::onViewPan()
1471 myPlot->canvas()->setCursor( panCursor );
1472 myOperation = PanId;
1473 qApp->installEventFilter( this );
1476 View operations : Zoom view
1478 void Plot2d_ViewFrame::onViewZoom()
1480 myPlot->canvas()->setCursor( zoomCursor );
1481 myOperation = ZoomId;
1482 qApp->installEventFilter( this );
1485 View operations : Fot All
1487 void Plot2d_ViewFrame::onViewFitAll()
1492 View operations : Fit Area
1494 void Plot2d_ViewFrame::onViewFitArea()
1496 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1497 myOperation = FitAreaId;
1498 qApp->installEventFilter( this );
1501 View operations : Global panning
1503 void Plot2d_ViewFrame::onViewGlobalPan()
1505 myPlot->canvas()->setCursor( glPanCursor );
1506 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1507 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1509 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1511 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1512 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1514 myXDistance = xMap.d2() - xMap.d1();
1515 myYDistance = yMap.d2() - yMap.d1();
1518 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
1519 myYDistance2 = yMap2.d2() - yMap2.d1();
1522 myOperation = GlPanId;
1523 qApp->installEventFilter( this );
1526 //=================================================================================
1527 // Plot2d_Plot2d implementation
1528 //=================================================================================
1532 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1536 enableOutline( true );
1537 setOutlineStyle( Qwt::Triangle );
1538 setOutlinePen( green );
1540 setAutoLegend( false );
1541 setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1542 enableLegend( false );
1544 enableGridX( false );
1545 enableGridXMin( false );
1546 enableGridY( false );
1547 enableGridYMin( false );
1548 // auto scaling by default
1549 setAxisAutoScale( QwtPlot::yLeft );
1550 setAxisAutoScale( QwtPlot::yRight );
1551 setAxisAutoScale( QwtPlot::xBottom );
1554 Recalculates and redraws Plot 2d view
1556 void Plot2d_Plot2d::replot()
1558 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
1563 Checks if two colors are close to each other [ static ]
1564 uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1566 const long COLOR_DISTANCE = 100;
1567 const int MAX_ATTEMPTS = 10;
1568 static bool closeColors( const QColor& color1, const QColor& color2 )
1570 long tol = abs( color2.red() - color1.red() ) +
1571 abs( color2.green() - color1.green() ) +
1572 abs( color2.blue() - color1.blue() );
1574 return ( tol <= COLOR_DISTANCE );
1577 Gets new unique marker for item if possible
1579 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
1584 int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
1585 int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
1586 int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
1587 int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty )
1588 int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty )
1590 typeMarker = ( QwtSymbol::Style )aMarker;
1591 color = QColor( aRed, aGreen, aBlue );
1592 typeLine = ( Qt::PenStyle )aLine;
1595 if ( cnt == MAX_ATTEMPTS )
1598 bOk = !existMarker( typeMarker, color, typeLine );
1601 static int aMarker = -1;
1602 static int aColor = -1;
1603 static int aLine = -1;
1605 if ( myColors.isEmpty() ) {
1606 // creating colors list
1607 myColors.append( Qt::white );
1608 myColors.append( Qt::blue );
1609 myColors.append( Qt::gray );
1610 myColors.append( Qt::darkGreen );
1611 myColors.append( Qt::magenta );
1612 myColors.append( Qt::darkGray );
1613 myColors.append( Qt::red );
1614 myColors.append( Qt::darkBlue );
1615 myColors.append( Qt::darkYellow );
1616 myColors.append( Qt::cyan );
1617 myColors.append( Qt::darkRed );
1618 myColors.append( Qt::darkCyan );
1619 myColors.append( Qt::yellow );
1620 myColors.append( Qt::darkMagenta );
1621 myColors.append( Qt::green );
1622 myColors.append( Qt::black );
1625 int nbMarkers = 11; // QwtSymbol supports 11 marker types
1626 int nbLines = 6; // Qt supports 6 line types
1627 int nbColors = myColors.count(); // number of default colors supported
1629 aMarker = ( aMarker + 1 ) % nbMarkers;
1630 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1631 aColor = ( aColor + 1 ) % nbColors;
1632 aLine = ( aLine + 1 ) % nbLines;
1633 if ( aLine == Qt::NoPen ) aLine++;
1635 typeMarker = ( QwtSymbol::Style )aMarker;
1636 color = myColors[ aColor ];
1637 typeLine = ( Qt::PenStyle )aLine;
1638 if ( !existMarker( typeMarker, color, typeLine ) )
1642 for ( i = 0; i < nbMarkers; i++ ) {
1643 aMarker = ( aMarker + 1 ) % nbMarkers;
1644 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1645 for ( j = 0; j < nbColors; j++ ) {
1646 aColor = ( aColor + 1 ) % nbColors;
1647 for ( k = 0; k < nbLines; k++ ) {
1648 aLine = ( aLine + 1 ) % nbLines;
1649 if ( aLine == Qt::NoPen ) aLine++;
1650 if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1651 typeMarker = ( QwtSymbol::Style )aMarker;
1652 color = myColors[ aColor ];
1653 typeLine = ( Qt::PenStyle )aLine;
1662 QSizePolicy Plot2d_Plot2d::sizePolicy() const
1664 return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
1667 QSize Plot2d_Plot2d::sizeHint() const
1669 return QwtPlot::minimumSizeHint();
1673 return minimum size for qwt plot
1675 QSize Plot2d_Plot2d::minimumSizeHint() const
1677 return QSize( 0, 0 );
1678 // QSize aSize = QwtPlot::minimumSizeHint();
1679 // return QSize(aSize.width()*3/4, aSize.height());
1682 Checks if marker belongs to any enitity
1684 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
1686 // getting all curves
1687 QArray<long> keys = curveKeys();
1690 if ( closeColors( color, backgroundColor() ) )
1692 for ( int i = 0; i < (int)keys.count(); i++ )
1694 QwtPlotCurve* crv = curve( keys[i] );
1696 QwtSymbol::Style aStyle = crv->symbol().style();
1697 QColor aColor = crv->pen().color();
1698 Qt::PenStyle aLine = crv->pen().style();
1699 // if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1700 if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
1707 // TEMPORARY SOLUTION!!! TO BE IMPLEMENTED!!!
1708 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )