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_FileDlg.h"
11 #include "SUIT_Session.h"
12 #include "SUIT_MessageBox.h"
13 #include "SUIT_ResourceMgr.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 QGridLayout* aLayout = new QGridLayout( this );
146 myPlot = new Plot2d_Plot2d( this );
147 aLayout->addWidget( myPlot, 0, 0);
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 );
1125 Gets background color
1127 QColor Plot2d_ViewFrame::backgroundColor() const
1129 return myBackground;
1132 Sets hor.axis grid parameters
1134 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
1135 bool xMinorEnabled, const int xMinorMax,
1138 myXGridMajorEnabled = xMajorEnabled;
1139 myXGridMinorEnabled = xMinorEnabled;
1140 myXGridMaxMajor = xMajorMax;
1141 myXGridMaxMinor = xMinorMax;
1142 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1143 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1144 myPlot->setGridXAxis(QwtPlot::xBottom);
1145 myPlot->enableGridX( myXGridMajorEnabled );
1146 myPlot->enableGridXMin( myXGridMinorEnabled );
1151 Sets ver.axis grid parameters
1153 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
1154 bool yMinorEnabled, const int yMinorMax,
1155 bool y2MajorEnabled, const int y2MajorMax,
1156 bool y2MinorEnabled, const int y2MinorMax,
1159 myYGridMajorEnabled = yMajorEnabled;
1160 myYGridMinorEnabled = yMinorEnabled;
1161 myYGridMaxMajor = yMajorMax;
1162 myYGridMaxMinor = yMinorMax;
1165 myY2GridMajorEnabled = y2MajorEnabled;
1166 myY2GridMinorEnabled = y2MinorEnabled;
1167 myY2GridMaxMajor = y2MajorMax;
1168 myY2GridMaxMinor = y2MinorMax;
1170 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1171 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1174 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
1175 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
1178 myPlot->setGridYAxis(QwtPlot::yLeft);
1181 if (myYGridMajorEnabled) {
1182 myPlot->enableGridYMin(myYGridMinorEnabled);
1183 myPlot->enableGridY( myYGridMajorEnabled);
1185 else if (myY2GridMajorEnabled) {
1186 myPlot->setGridYAxis(QwtPlot::yRight);
1187 myPlot->enableGridYMin(myY2GridMinorEnabled);
1188 myPlot->enableGridY(myY2GridMajorEnabled);
1191 myPlot->enableGridYMin(false);
1192 myPlot->enableGridY(false);
1196 myPlot->enableGridY( myYGridMajorEnabled );
1197 myPlot->enableGridYMin( myYGridMinorEnabled );
1204 Sets title for some axis
1206 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
1207 ObjectType type, bool update )
1211 myTitleEnabled = enabled;
1213 myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1216 myXTitleEnabled = enabled;
1218 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1221 myYTitleEnabled = enabled;
1223 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1226 myY2TitleEnabled = enabled;
1228 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null );
1235 Sets title for some axis
1237 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
1242 title = myTitle; break;
1244 title = myXTitle; break;
1246 title = myYTitle; break;
1248 title = myY2Title; break;
1253 Sets font for Plot2d object : title or axis
1255 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
1259 myPlot->setTitleFont(font);
1262 myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break;
1264 myPlot->setAxisTitleFont(QwtPlot::yLeft, font); break;
1266 myPlot->setAxisTitleFont(QwtPlot::yRight, font); break;
1268 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
1270 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
1272 myPlot->setAxisFont(QwtPlot::yRight, font); break;
1278 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1280 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1283 if ( myXMode == 0 ) // linear
1284 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1286 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1290 emit vpModeHorChanged();
1293 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1295 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1298 if ( myYMode == 0 ) { // linear
1299 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1301 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1303 else { // logarithmic
1304 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1306 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true );
1310 emit vpModeVerChanged();
1314 Return, scale mode for horizontal axis
1316 bool Plot2d_ViewFrame::isModeHorLinear()
1318 return (myXMode == 0 ? true : false);
1322 Return, scale mode for vertical axis
1324 bool Plot2d_ViewFrame::isModeVerLinear()
1326 return (myYMode == 0 ? true : false);
1329 Slot, called when user presses mouse button
1331 void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me )
1333 if ( myOperation == NoOpId )
1334 myOperation = testOperation( me );
1335 if ( myOperation != NoOpId ) {
1337 if ( myOperation == FitAreaId ) {
1338 myPlot->setOutlineStyle( Qwt::Rect );
1340 else if ( myOperation == GlPanId ) {
1341 myPlot->setAxisScale( QwtPlot::yLeft,
1342 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2,
1343 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 );
1344 myPlot->setAxisScale( QwtPlot::xBottom,
1345 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
1346 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
1348 myPlot->setAxisScale( QwtPlot::yRight,
1349 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2,
1350 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 );
1355 int btn = me.button() | me.state();
1356 if (btn == RightButton) {
1357 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
1358 me.pos(), btn, me.state());
1359 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
1360 parent()->eventFilter(this, aEvent);
1365 Slot, called when user moves mouse
1367 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1369 int dx = me.pos().x() - myPnt.x();
1370 int dy = me.pos().y() - myPnt.y();
1372 if ( myOperation != NoOpId) {
1373 if ( myOperation == ZoomId ) {
1374 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1375 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1377 myPlot->setAxisScale( QwtPlot::yLeft,
1378 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1379 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1380 myPlot->setAxisScale( QwtPlot::xBottom,
1381 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1382 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1384 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1385 myPlot->setAxisScale( QwtPlot::yRight,
1386 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1387 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + dy ) );
1392 else if ( myOperation == PanId ) {
1393 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1394 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1396 myPlot->setAxisScale( QwtPlot::yLeft,
1397 myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
1398 myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1399 myPlot->setAxisScale( QwtPlot::xBottom,
1400 myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1401 myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
1403 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1404 myPlot->setAxisScale( QwtPlot::yRight,
1405 myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-dy ),
1406 myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-dy ) );
1413 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1417 Slot, called when user releases mouse
1419 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1421 if ( myOperation == NoOpId && me.button() == RightButton )
1423 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1424 me.pos(), me.globalPos(),
1426 emit contextMenuRequested( &aEvent );
1428 if ( myOperation == FitAreaId ) {
1429 QRect rect( myPnt, me.pos() );
1432 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1433 myPlot->setOutlineStyle( Qwt::Triangle );
1435 ((Plot2d_ViewWindow*)parent())->putInfo(tr("INF_READY"));
1436 myOperation = NoOpId;
1439 Slot, called when user wheeling mouse
1441 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
1443 double aDelta = event->delta();
1444 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
1446 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1447 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1449 myPlot->setAxisScale( QwtPlot::yLeft,
1450 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1451 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale );
1452 myPlot->setAxisScale( QwtPlot::xBottom,
1453 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1454 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale );
1456 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1457 myPlot->setAxisScale( QwtPlot::yRight,
1458 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1459 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale );
1462 myPnt = event->pos();
1465 View operations : Dump view
1467 void Plot2d_ViewFrame::onDump()
1469 QApplication::setOverrideCursor( Qt::waitCursor );
1470 QPixmap px = QPixmap::grabWindow(winId());
1471 QApplication::restoreOverrideCursor();
1473 QString fileName = SUIT_FileDlg::getFileName(this,
1475 tr("OCC_IMAGE_FILES"),
1476 tr("INF_APP_DUMP_VIEW"),
1478 if ( !fileName.isNull() )
1480 QApplication::setOverrideCursor( Qt::waitCursor );
1481 QString fmt = SUIT_Tools::extension( fileName ).upper();
1483 fmt = QString("BMP"); // default format
1486 bool bOk = px.save(fileName, fmt.latin1());
1487 QApplication::restoreOverrideCursor();
1489 SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK"));
1494 View operations : Pan view
1496 void Plot2d_ViewFrame::onViewPan()
1498 myPlot->canvas()->setCursor( panCursor );
1499 myOperation = PanId;
1500 qApp->installEventFilter( this );
1503 View operations : Zoom view
1505 void Plot2d_ViewFrame::onViewZoom()
1507 myPlot->canvas()->setCursor( zoomCursor );
1508 myOperation = ZoomId;
1509 qApp->installEventFilter( this );
1512 View operations : Fot All
1514 void Plot2d_ViewFrame::onViewFitAll()
1519 View operations : Fit Area
1521 void Plot2d_ViewFrame::onViewFitArea()
1523 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1524 myOperation = FitAreaId;
1525 qApp->installEventFilter( this );
1528 View operations : Global panning
1530 void Plot2d_ViewFrame::onViewGlobalPan()
1532 myPlot->canvas()->setCursor( glPanCursor );
1533 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1534 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1536 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1538 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1539 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1541 myXDistance = xMap.d2() - xMap.d1();
1542 myYDistance = yMap.d2() - yMap.d1();
1545 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
1546 myYDistance2 = yMap2.d2() - yMap2.d1();
1549 myOperation = GlPanId;
1550 qApp->installEventFilter( this );
1553 //=================================================================================
1554 // Plot2d_Plot2d implementation
1555 //=================================================================================
1559 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1563 enableOutline( true );
1564 setOutlineStyle( Qwt::Triangle );
1565 setOutlinePen( green );
1567 setAutoLegend( false );
1568 setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1569 enableLegend( false );
1571 enableGridX( false );
1572 enableGridXMin( false );
1573 enableGridY( false );
1574 enableGridYMin( false );
1575 // auto scaling by default
1576 setAxisAutoScale( QwtPlot::yLeft );
1577 setAxisAutoScale( QwtPlot::yRight );
1578 setAxisAutoScale( QwtPlot::xBottom );
1581 Recalculates and redraws Plot 2d view
1583 void Plot2d_Plot2d::replot()
1585 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
1590 Checks if two colors are close to each other [ static ]
1591 uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1593 const long COLOR_DISTANCE = 100;
1594 const int MAX_ATTEMPTS = 10;
1595 static bool closeColors( const QColor& color1, const QColor& color2 )
1597 long tol = abs( color2.red() - color1.red() ) +
1598 abs( color2.green() - color1.green() ) +
1599 abs( color2.blue() - color1.blue() );
1601 return ( tol <= COLOR_DISTANCE );
1604 Gets new unique marker for item if possible
1606 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
1611 int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
1612 int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
1613 int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
1614 int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty )
1615 int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty )
1617 typeMarker = ( QwtSymbol::Style )aMarker;
1618 color = QColor( aRed, aGreen, aBlue );
1619 typeLine = ( Qt::PenStyle )aLine;
1622 if ( cnt == MAX_ATTEMPTS )
1625 bOk = !existMarker( typeMarker, color, typeLine );
1628 static int aMarker = -1;
1629 static int aColor = -1;
1630 static int aLine = -1;
1632 if ( myColors.isEmpty() ) {
1633 // creating colors list
1634 myColors.append( Qt::white );
1635 myColors.append( Qt::blue );
1636 myColors.append( Qt::gray );
1637 myColors.append( Qt::darkGreen );
1638 myColors.append( Qt::magenta );
1639 myColors.append( Qt::darkGray );
1640 myColors.append( Qt::red );
1641 myColors.append( Qt::darkBlue );
1642 myColors.append( Qt::darkYellow );
1643 myColors.append( Qt::cyan );
1644 myColors.append( Qt::darkRed );
1645 myColors.append( Qt::darkCyan );
1646 myColors.append( Qt::yellow );
1647 myColors.append( Qt::darkMagenta );
1648 myColors.append( Qt::green );
1649 myColors.append( Qt::black );
1652 int nbMarkers = 11; // QwtSymbol supports 11 marker types
1653 int nbLines = 6; // Qt supports 6 line types
1654 int nbColors = myColors.count(); // number of default colors supported
1656 aMarker = ( aMarker + 1 ) % nbMarkers;
1657 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1658 aColor = ( aColor + 1 ) % nbColors;
1659 aLine = ( aLine + 1 ) % nbLines;
1660 if ( aLine == Qt::NoPen ) aLine++;
1662 typeMarker = ( QwtSymbol::Style )aMarker;
1663 color = myColors[ aColor ];
1664 typeLine = ( Qt::PenStyle )aLine;
1665 if ( !existMarker( typeMarker, color, typeLine ) )
1669 for ( i = 0; i < nbMarkers; i++ ) {
1670 aMarker = ( aMarker + 1 ) % nbMarkers;
1671 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1672 for ( j = 0; j < nbColors; j++ ) {
1673 aColor = ( aColor + 1 ) % nbColors;
1674 for ( k = 0; k < nbLines; k++ ) {
1675 aLine = ( aLine + 1 ) % nbLines;
1676 if ( aLine == Qt::NoPen ) aLine++;
1677 if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1678 typeMarker = ( QwtSymbol::Style )aMarker;
1679 color = myColors[ aColor ];
1680 typeLine = ( Qt::PenStyle )aLine;
1690 return minimum size for qwt plot
1692 QSize Plot2d_Plot2d::minimumSizeHint() const
1694 QSize aSize = QwtPlot::minimumSizeHint();
1695 return QSize(aSize.width()*3/4, aSize.height());
1698 Checks if marker belongs to any enitity
1700 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
1702 // getting all curves
1703 QArray<long> keys = curveKeys();
1706 if ( closeColors( color, backgroundColor() ) )
1708 for ( int i = 0; i < (int)keys.count(); i++ )
1710 QwtPlotCurve* crv = curve( keys[i] );
1712 QwtSymbol::Style aStyle = crv->symbol().style();
1713 QColor aColor = crv->pen().color();
1714 Qt::PenStyle aLine = crv->pen().style();
1715 // if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1716 if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )