1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "Plot2d_ViewFrame.h"
21 #include "Plot2d_Prs.h"
22 #include "Plot2d_Curve.h"
23 #include "Plot2d_FitDataDlg.h"
24 #include "Plot2d_ViewWindow.h"
25 #include "Plot2d_SetupViewDlg.h"
27 #include "SUIT_Tools.h"
28 #include "SUIT_Session.h"
29 #include "SUIT_MessageBox.h"
30 #include "SUIT_ResourceMgr.h"
31 #include "SUIT_Application.h"
33 #include "qapplication.h"
35 #include <qtoolbutton.h>
37 #include <qcolordialog.h>
43 #include <qwt_plot_canvas.h>
47 #include <qwt_legend.h>
49 #define DEFAULT_LINE_WIDTH 0 // (default) line width
50 #define DEFAULT_MARKER_SIZE 9 // default marker size
51 #define MIN_RECT_SIZE 11 // min sensibility area size
53 const char* imageZoomCursor[] = {
58 "................................",
59 "................................",
60 ".#######........................",
61 "..aaaaaaa.......................",
62 "................................",
63 ".............#####..............",
64 "...........##.aaaa##............",
65 "..........#.aa.....a#...........",
66 ".........#.a.........#..........",
67 ".........#a..........#a.........",
68 "........#.a...........#.........",
69 "........#a............#a........",
70 "........#a............#a........",
71 "........#a............#a........",
72 "........#a............#a........",
73 ".........#...........#.a........",
74 ".........#a..........#a.........",
75 ".........##.........#.a.........",
76 "........#####.....##.a..........",
77 ".......###aaa#####.aa...........",
78 "......###aa...aaaaa.......#.....",
79 ".....###aa................#a....",
80 "....###aa.................#a....",
81 "...###aa...............#######..",
82 "....#aa.................aa#aaaa.",
83 ".....a....................#a....",
84 "..........................#a....",
85 "...........................a....",
86 "................................",
87 "................................",
88 "................................",
89 "................................"};
91 const char* imageCrossCursor[] = {
96 "................................",
97 "................................",
98 "................................",
99 "................................",
100 "................................",
101 "................................",
102 "................................",
103 "...............#................",
104 "...............#a...............",
105 "...............#a...............",
106 "...............#a...............",
107 "...............#a...............",
108 "...............#a...............",
109 "...............#a...............",
110 "...............#a...............",
111 ".......#################........",
112 "........aaaaaaa#aaaaaaaaa.......",
113 "...............#a...............",
114 "...............#a...............",
115 "...............#a...............",
116 "...............#a...............",
117 "...............#a...............",
118 "...............#a...............",
119 "...............#a...............",
120 "................a...............",
121 "................................",
122 "................................",
123 "................................",
124 "................................",
125 "................................",
126 "................................",
127 "................................"};
130 QPixmap zoomPixmap(imageZoomCursor);
131 QPixmap globalPanPixmap(imageCrossCursor);
133 QCursor panCursor(Qt::SizeAllCursor);
134 QCursor zoomCursor(zoomPixmap);
135 QCursor glPanCursor(globalPanPixmap);
137 //=================================================================================
138 // Plot2d_ViewFrame implementation
139 //=================================================================================
144 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
145 : QWidget (parent, title, 0),
146 myOperation( NoOpId ),
148 myShowLegend( true ), myLegendPos( 1 ),
149 myMarkerSize( DEFAULT_MARKER_SIZE ),
150 myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
151 myBackground( white ),
152 myTitleEnabled( true ), myXTitleEnabled( true ),
153 myYTitleEnabled( true ), myY2TitleEnabled (true),
154 myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ),
155 myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
156 myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
157 myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
158 myXMode( 0 ), myYMode( 0 ), mySecondY( false )
161 QVBoxLayout* aLayout = new QVBoxLayout( this );
162 myPlot = new Plot2d_Plot2d( this );
163 aLayout->addWidget( myPlot );
167 connect( myPlot, SIGNAL( plotMouseMoved( const QMouseEvent& ) ),
168 this, SLOT( plotMouseMoved( const QMouseEvent& ) ) );
169 connect( myPlot, SIGNAL( plotMousePressed( const QMouseEvent& ) ),
170 this, SLOT( plotMousePressed( const QMouseEvent& ) ) );
171 connect( myPlot, SIGNAL( plotMouseReleased( const QMouseEvent& ) ),
172 this, SLOT( plotMouseReleased( const QMouseEvent& ) ) );
173 //connect( myPlot, SIGNAL( legendClicked( long ) ),
174 // this, SLOT( onLegendClicked( long ) ) );
176 /* Initial Setup - get from the preferences */
179 myPlot->setMargin( 5 );
180 setCurveType( myCurveType, false );
181 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
182 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
183 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
185 setTitle( myTitleEnabled, myTitle, MainTitle, false );
186 setTitle( myXTitleEnabled, myXTitle, XTitle, false );
187 setTitle( myYTitleEnabled, myYTitle, YTitle, false );
190 setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
191 setHorScaleMode( myXMode, false );
192 setVerScaleMode( myYMode, false );
193 setBackgroundColor( myBackground );
194 setLegendPos( myLegendPos );
195 showLegend( myShowLegend, false );
199 resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) );
201 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
202 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
203 myXDistance = xMap.d2() - xMap.d1();
204 myYDistance = yMap.d2() - yMap.d1();
207 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
208 myYDistance2 = yMap2.d2() - yMap2.d1();
214 Plot2d_ViewFrame::~Plot2d_ViewFrame()
218 Gets window's central widget
220 QWidget* Plot2d_ViewFrame::getViewWidget()
222 return (QWidget*)myPlot;
225 Actually this method just re-displays all curves which are presented in the viewer
227 void Plot2d_ViewFrame::DisplayAll()
229 QList<Plot2d_Curve> clist;
231 for ( int i = 0; i < (int)clist.count(); i++ ) {
232 updateCurve( clist.at( i ), false );
237 Removes all curves from the view
239 void Plot2d_ViewFrame::EraseAll()
246 Redraws viewframe contents
248 void Plot2d_ViewFrame::Repaint()
255 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
257 if ( !prs || prs->IsNull() )
260 if (prs->isSecondY()) {
261 myPlot->enableAxis(QwtPlot::yRight, true);
265 myPlot->enableAxis(QwtPlot::yRight, false);
269 // display all curves from presentation
270 curveList aCurves = prs->getCurves();
271 displayCurves( aCurves );
272 setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
273 setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
274 myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
280 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
282 if ( !prs || prs->IsNull() )
285 // erase all curves from presentation
286 curveList aCurves = prs->getCurves();
287 eraseCurves( aCurves );
293 void Plot2d_ViewFrame::setTitle( const QString& title )
295 setTitle( myTitleEnabled, title, MainTitle, true );
299 Reads Plot2d view settings from the preferences
301 void Plot2d_ViewFrame::readPreferences()
303 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
305 myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
306 if ( myCurveType < 1 || myCurveType > 2 )
308 myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
309 myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
310 myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
311 myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
313 myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
314 myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
315 myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
316 myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
318 myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
319 myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
320 myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
322 myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
323 myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
324 myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
326 myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
327 myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
329 myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
331 myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
332 myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
334 myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
336 myXMode = resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode );
337 myXMode = QMAX( 0, QMIN( 1, myXMode ) );
339 myYMode = resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode );
340 myYMode = QMAX( 0, QMIN( 1, myYMode ) );
344 Writes Plot2d view settings to the preferences
346 void Plot2d_ViewFrame::writePreferences()
348 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
350 resMgr->setValue( "Plot2d", "CurveType", myCurveType );
351 resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
352 resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
353 resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
354 resMgr->setValue( "Plot2d", "Background", myBackground );
355 resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
356 resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
357 resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
359 resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
361 resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
362 resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
363 resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
364 resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
366 resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
367 resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
369 resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
370 resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
372 resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
376 resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
377 resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
378 resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
379 resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
382 resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
386 Prints mouse cursor coordinates into string
388 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt )
391 bool xFound = false, yFound = false;
392 double xCoord, yCoord;
393 const QwtScaleDiv* aXscale = myPlot->axisScale( QwtPlot::xBottom );
394 for ( i = 0; i < aXscale->majCnt(); i++ ) {
395 double majXmark = aXscale->majMark( i );
396 int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
397 if ( xmark-2 == pnt.x() ) {
404 for ( i = 0; i < aXscale->minCnt(); i++ ) {
405 double minXmark = aXscale->minMark( i );
406 int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
407 if ( xmark-2 == pnt.x() ) {
414 const QwtScaleDiv* aYscale = myPlot->axisScale( QwtPlot::yLeft );
415 for ( i = 0; i < aYscale->majCnt(); i++ ) {
416 double majYmark = aYscale->majMark( i );
417 int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
418 if ( ymark-2 == pnt.y() ) {
425 for ( i = 0; i < aYscale->minCnt(); i++ ) {
426 double minYmark = aYscale->minMark( i );
427 int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
428 if ( ymark-2 == pnt.y() ) {
436 QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).stripWhiteSpace();
439 QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).stripWhiteSpace();
445 bool yFound2 = false;
448 const QwtScaleDiv* aYscale2 = myPlot->axisScale( QwtPlot::yRight );
449 for ( i = 0; i < aYscale2->majCnt(); i++ ) {
450 double majYmark = aYscale2->majMark( i );
451 int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
452 if ( ymark-2 == pnt.y() ) {
459 for ( i = 0; i < aYscale2->minCnt(); i++ ) {
460 double minYmark = aYscale2->minMark( i );
461 int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
462 if ( ymark-2 == pnt.y() ) {
469 QString strY2 = QString::number( yFound2 ? yCoord2 :
470 myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).stripWhiteSpace();
473 info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
476 info = tr("INF_COORDINATES").arg( strX ).arg( strY );
482 Converts Plot2d_Curve's marker style to Qwt marker style [ static ]
484 static QwtSymbol::Style plot2qwtMarker( Plot2d_Curve::MarkerType m )
486 QwtSymbol::Style ms = QwtSymbol::None;
488 case Plot2d_Curve::Circle:
489 ms = QwtSymbol::Ellipse; break;
490 case Plot2d_Curve::Rectangle:
491 ms = QwtSymbol::Rect; break;
492 case Plot2d_Curve::Diamond:
493 ms = QwtSymbol::Diamond; break;
494 case Plot2d_Curve::DTriangle:
495 ms = QwtSymbol::DTriangle; break;
496 case Plot2d_Curve::UTriangle:
497 ms = QwtSymbol::UTriangle; break;
498 case Plot2d_Curve::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
499 ms = QwtSymbol::RTriangle; break;
500 case Plot2d_Curve::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
501 ms = QwtSymbol::LTriangle; break;
502 case Plot2d_Curve::Cross:
503 ms = QwtSymbol::Cross; break;
504 case Plot2d_Curve::XCross:
505 ms = QwtSymbol::XCross; break;
506 case Plot2d_Curve::None:
508 ms = QwtSymbol::None; break;
514 Converts Qwt marker style to Plot2d_Curve's marker style [ static ]
516 static Plot2d_Curve::MarkerType qwt2plotMarker( QwtSymbol::Style m )
518 Plot2d_Curve::MarkerType ms = Plot2d_Curve::None;
520 case QwtSymbol::Ellipse:
521 ms = Plot2d_Curve::Circle; break;
522 case QwtSymbol::Rect:
523 ms = Plot2d_Curve::Rectangle; break;
524 case QwtSymbol::Diamond:
525 ms = Plot2d_Curve::Diamond; break;
526 case QwtSymbol::DTriangle:
527 ms = Plot2d_Curve::DTriangle; break;
528 case QwtSymbol::UTriangle:
529 ms = Plot2d_Curve::UTriangle; break;
530 case QwtSymbol::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
531 ms = Plot2d_Curve::LTriangle; break;
532 case QwtSymbol::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
533 ms = Plot2d_Curve::RTriangle; break;
534 case QwtSymbol::Cross:
535 ms = Plot2d_Curve::Cross; break;
536 case QwtSymbol::XCross:
537 ms = Plot2d_Curve::XCross; break;
538 case QwtSymbol::None:
540 ms = Plot2d_Curve::None; break;
546 Converts Plot2d_Curve's line style to Qwt line style [ static ]
548 static Qt::PenStyle plot2qwtLine( Plot2d_Curve::LineType p )
550 Qt::PenStyle ps = Qt::NoPen;
552 case Plot2d_Curve::Solid:
553 ps = Qt::SolidLine; break;
554 case Plot2d_Curve::Dash:
555 ps = Qt::DashLine; break;
556 case Plot2d_Curve::Dot:
557 ps = Qt::DotLine; break;
558 case Plot2d_Curve::DashDot:
559 ps = Qt::DashDotLine; break;
560 case Plot2d_Curve::DashDotDot:
561 ps = Qt::DashDotDotLine; break;
562 case Plot2d_Curve::NoPen:
564 ps = Qt::NoPen; break;
570 Converts Qwt line style to Plot2d_Curve's line style [ static ]
572 static Plot2d_Curve::LineType qwt2plotLine( Qt::PenStyle p )
574 Plot2d_Curve::LineType ps = Plot2d_Curve::NoPen;
577 ps = Plot2d_Curve::Solid; break;
579 ps = Plot2d_Curve::Dash; break;
581 ps = Plot2d_Curve::Dot; break;
582 case Qt::DashDotLine:
583 ps = Plot2d_Curve::DashDot; break;
584 case Qt::DashDotDotLine:
585 ps = Plot2d_Curve::DashDotDot; break;
588 ps = Plot2d_Curve::NoPen; break;
596 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
600 if ( hasCurve( curve ) ) {
601 updateCurve( curve, update );
604 long curveKey = myPlot->insertCurve( curve->getVerTitle() );
605 myPlot->setCurveYAxis(curveKey, curve->getYAxis());
607 myCurves.insert( curveKey, curve );
608 if ( curve->isAutoAssign() ) {
609 QwtSymbol::Style typeMarker;
611 Qt::PenStyle typeLine;
612 myPlot->getNextMarker( typeMarker, color, typeLine );
613 myPlot->setCurvePen( curveKey, QPen( color, DEFAULT_LINE_WIDTH, typeLine ) );
614 myPlot->setCurveSymbol( curveKey, QwtSymbol( typeMarker,
617 QSize( myMarkerSize, myMarkerSize ) ) );
618 curve->setColor( color );
619 curve->setLine( qwt2plotLine( typeLine ) );
620 curve->setMarker( qwt2plotMarker( typeMarker ) );
623 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
624 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
625 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
626 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
627 QBrush( curve->getColor() ),
628 QPen( curve->getColor() ),
629 QSize( myMarkerSize, myMarkerSize ) ) );
631 if ( myCurveType == 0 )
632 myPlot->setCurveStyle( curveKey, QwtCurve::NoCurve );
633 else if ( myCurveType == 1 )
634 myPlot->setCurveStyle( curveKey, QwtCurve::Lines );
635 else if ( myCurveType == 2 )
636 myPlot->setCurveStyle( curveKey, QwtCurve::Spline );
637 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
645 Adds curves into view
647 void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
649 myPlot->setUpdatesEnabled( false );
650 QPtrListIterator<Plot2d_Curve> it(curves);
651 Plot2d_Curve* aCurve;
652 while( (aCurve = it.current()) ) {
653 displayCurve( aCurve, false );
658 myPlot->setUpdatesEnabled( true );
666 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
670 int curveKey = hasCurve( curve );
672 myPlot->removeCurve( curveKey );
673 myCurves.remove( curveKey );
682 void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
684 QPtrListIterator<Plot2d_Curve> it(curves);
685 Plot2d_Curve* aCurve;
686 while( (aCurve = it.current()) ) {
687 eraseCurve( aCurve, false );
696 Updates curves attributes
698 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
702 int curveKey = hasCurve( curve );
704 if ( !curve->isAutoAssign() ) {
705 Qt::PenStyle ps = plot2qwtLine( curve->getLine() );
706 QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
707 myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
708 myPlot->setCurveSymbol( curveKey, QwtSymbol( ms,
709 QBrush( curve->getColor() ),
710 QPen( curve->getColor() ),
711 QSize( myMarkerSize, myMarkerSize ) ) );
712 myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
714 myPlot->setCurveTitle( curveKey, curve->getVerTitle() );
715 myPlot->curve( curveKey )->setEnabled( true );
722 Returns curve key if is is displayed in the viewer and 0 otherwise
724 int Plot2d_ViewFrame::hasCurve( Plot2d_Curve* curve )
726 QIntDictIterator<Plot2d_Curve> it( myCurves );
727 for ( ; it.current(); ++it ) {
728 if ( it.current() == curve )
729 return it.currentKey();
735 Gets lsit of displayed curves
737 int Plot2d_ViewFrame::getCurves( QList<Plot2d_Curve>& clist )
740 clist.setAutoDelete( false );
741 QIntDictIterator<Plot2d_Curve> it( myCurves );
742 for ( ; it.current(); ++it ) {
743 clist.append( it.current() );
745 return clist.count();
749 Returns true if the curve is visible
751 bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve )
754 int key = hasCurve( curve );
756 return myPlot->curve( key )->enabled();
764 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
766 if ( !prs || prs->IsNull() )
768 curveList aCurves = prs->getCurves();
770 QPtrListIterator<Plot2d_Curve> it(aCurves);
771 Plot2d_Curve* aCurve;
772 while( (aCurve = it.current()) ) {
773 int curveKey = hasCurve( aCurve );
775 myPlot->setCurveTitle( curveKey, aCurve->getVerTitle() );
781 Fits the view to see all data
783 void Plot2d_ViewFrame::fitAll()
785 QwtDiMap xMap1 = myPlot->canvasMap( QwtPlot::xBottom );
787 myPlot->setAxisAutoScale( QwtPlot::yLeft );
788 myPlot->setAxisAutoScale( QwtPlot::xBottom );
792 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
793 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
795 myPlot->setAxisScale( QwtPlot::xBottom,
796 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
797 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) );
798 myPlot->setAxisScale( QwtPlot::yLeft,
799 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
800 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) );
803 myPlot->setAxisAutoScale( QwtPlot::yRight );
805 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
806 myPlot->setAxisScale( QwtPlot::yRight,
807 myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ),
808 myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) );
814 Fits the view to rectangle area (pixels)
816 void Plot2d_ViewFrame::fitArea( const QRect& area )
818 QRect rect = area.normalize();
819 if ( rect.width() < MIN_RECT_SIZE ) {
820 rect.setWidth( MIN_RECT_SIZE );
821 rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
823 if ( rect.height() < MIN_RECT_SIZE ) {
824 rect.setHeight( MIN_RECT_SIZE );
825 rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
827 myPlot->setAxisScale( QwtPlot::yLeft,
828 myPlot->invTransform( QwtPlot::yLeft, rect.top() ),
829 myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
831 myPlot->setAxisScale( QwtPlot::yRight,
832 myPlot->invTransform( QwtPlot::yRight, rect.top() ),
833 myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
834 myPlot->setAxisScale( QwtPlot::xBottom,
835 myPlot->invTransform( QwtPlot::xBottom, rect.left() ),
836 myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
841 "Fit Data" command for TUI interface
843 void Plot2d_ViewFrame::fitData(const int mode,
844 const double xMin, const double xMax,
845 const double yMin, const double yMax,
846 double y2Min, double y2Max)
848 if ( mode == 0 || mode == 2 ) {
849 myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin );
851 myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min );
853 if ( mode == 0 || mode == 1 )
854 myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax );
859 Gets current fit ranges for view frame
861 void Plot2d_ViewFrame::getFitRanges(double& xMin,double& xMax,
862 double& yMin, double& yMax,
863 double& y2Min, double& y2Max)
865 int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1();
866 int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2();
867 int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1();
868 int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2();
869 xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
870 xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
871 yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
872 yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
876 int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1();
877 int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2();
878 y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
879 y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
884 Tests if it is necessary to start operation on mouse action
886 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
888 int btn = me.button() | me.state();
889 const int zoomBtn = ControlButton | LeftButton;
890 const int panBtn = ControlButton | MidButton;
891 const int fitBtn = ControlButton | RightButton;
896 myPlot->canvas()->setCursor( zoomCursor );
899 myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
902 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
910 "Settings" toolbar action slot
912 void Plot2d_ViewFrame::onSettings()
914 #ifdef TEST_AUTOASSIGN
915 typedef QMap<int,int> IList;
916 typedef QMap<QString,int> SList;
919 cols[ "red-min" ] = 1000;
920 cols[ "red-max" ] = -1;
921 cols[ "green-min" ] = 1000;
922 cols[ "green-max" ] = -1;
923 cols[ "blue-min" ] = 1000;
924 cols[ "blue-max" ] = -1;
925 for ( unsigned i = 0; i < 10000; i++ ) {
926 QwtSymbol::Style typeMarker;
928 Qt::PenStyle typeLine;
929 myPlot->getNextMarker( typeMarker, color, typeLine );
930 if ( mars.contains(typeMarker) )
931 mars[ typeMarker ] = mars[ typeMarker ]+1;
933 mars[ typeMarker ] = 0;
934 if ( lins.contains(typeLine) )
935 lins[ typeLine ] = lins[ typeLine ]+1;
937 lins[ typeLine ] = 0;
938 if ( cols[ "red-max" ] < color.red() )
939 cols[ "red-max" ] = color.red();
940 if ( cols[ "red-min" ] > color.red() )
941 cols[ "red-min" ] = color.red();
942 if ( cols[ "green-max" ] < color.green() )
943 cols[ "green-max" ] = color.green();
944 if ( cols[ "green-min" ] > color.green() )
945 cols[ "green-min" ] = color.green();
946 if ( cols[ "blue-max" ] < color.blue() )
947 cols[ "blue-max" ] = color.blue();
948 if ( cols[ "blue-min" ] > color.blue() )
949 cols[ "blue-min" ] = color.blue();
953 Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
954 dlg->setMainTitle( myTitleEnabled, myTitle );
955 dlg->setXTitle( myXTitleEnabled, myXTitle );
956 dlg->setYTitle( myYTitleEnabled, myYTitle );
958 dlg->setY2Title( myY2TitleEnabled, myY2Title );
959 dlg->setCurveType( myCurveType );
960 dlg->setLegend( myShowLegend, myLegendPos );
961 dlg->setMarkerSize( myMarkerSize );
962 dlg->setBackgroundColor( myBackground );
963 dlg->setScaleMode(myXMode, myYMode);
965 dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
966 myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
967 myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
968 dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
969 myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
970 myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
971 if ( dlg->exec() == QDialog::Accepted ) {
972 // horizontal axis title
973 setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
974 // vertical left axis title
975 setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
976 if (mySecondY) // vertical right axis title
977 setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
980 setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
982 if ( myCurveType != dlg->getCurveType() ) {
983 setCurveType( dlg->getCurveType(), false );
986 if ( myShowLegend != dlg->isLegendEnabled() ) {
987 showLegend( dlg->isLegendEnabled(), false );
989 if ( myLegendPos != dlg->getLegendPos() ) {
990 setLegendPos( dlg->getLegendPos() );
993 if ( myMarkerSize != dlg->getMarkerSize() ) {
994 setMarkerSize( dlg->getMarkerSize(), false );
997 if ( myBackground != dlg->getBackgroundColor() ) {
998 setBackgroundColor( dlg->getBackgroundColor() );
1001 bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
1002 aY2GridMajorEnabled, aY2GridMinorEnabled;
1003 int aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
1004 aY2GridMaxMajor, aY2GridMaxMinor;
1005 dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
1006 aY2GridMajorEnabled, aY2GridMaxMajor);
1007 dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
1008 aY2GridMinorEnabled, aY2GridMaxMinor);
1009 setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
1010 setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
1011 aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
1012 if ( myXMode != dlg->getXScaleMode() ) {
1013 setHorScaleMode( dlg->getXScaleMode() );
1015 if ( myYMode != dlg->getYScaleMode() ) {
1016 setVerScaleMode( dlg->getYScaleMode() );
1020 // update preferences
1021 if ( dlg->isSetAsDefault() )
1028 "Fit Data" command slot
1030 void Plot2d_ViewFrame::onFitData()
1032 Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
1033 double xMin,xMax,yMin,yMax,y2Min,y2Max;
1034 getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
1036 dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1037 if ( dlg->exec() == QDialog::Accepted ) {
1038 int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1039 fitData(mode,xMin,xMax,yMin,yMax,y2Min,y2Max);
1045 Change background color
1047 void Plot2d_ViewFrame::onChangeBackground()
1049 QColor selColor = QColorDialog::getColor ( backgroundColor(), this );
1050 if ( selColor.isValid() ) {
1051 setBackgroundColor( selColor );
1058 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1060 myCurveType = curveType;
1061 QArray<long> keys = myPlot->curveKeys();
1062 for ( int i = 0; i < (int)keys.count(); i++ ) {
1063 if ( myCurveType == 0 )
1064 myPlot->setCurveStyle( keys[i], QwtCurve::Dots );//QwtCurve::NoCurve
1065 else if ( myCurveType == 1 )
1066 myPlot->setCurveStyle( keys[i], QwtCurve::Lines );
1067 else if ( myCurveType == 2 )
1068 myPlot->setCurveStyle( keys[i], QwtCurve::Spline );
1072 emit vpCurveChanged();
1075 void Plot2d_ViewFrame::setCurveTitle( int curveKey, const QString& title )
1077 if(myPlot) myPlot->setCurveTitle(curveKey, title);
1083 void Plot2d_ViewFrame::showLegend( bool show, bool update )
1085 myShowLegend = show;
1086 myPlot->setAutoLegend( myShowLegend );
1087 myPlot->enableLegend( myShowLegend );
1093 Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
1095 void Plot2d_ViewFrame::setLegendPos( int pos )
1100 myPlot->setLegendPos( Qwt::Left );
1103 myPlot->setLegendPos( Qwt::Right );
1106 myPlot->setLegendPos( Qwt::Top );
1109 myPlot->setLegendPos( Qwt::Bottom );
1115 Sets new marker size
1117 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
1119 if ( myMarkerSize != size )
1121 myMarkerSize = size;
1122 QArray<long> keys = myPlot->curveKeys();
1123 for ( int i = 0; i < (int)keys.count(); i++ )
1125 QwtPlotCurve* crv = myPlot->curve( keys[i] );
1128 QwtSymbol aSymbol = crv->symbol();
1129 aSymbol.setSize( myMarkerSize, myMarkerSize );
1130 myPlot->setCurveSymbol( keys[i], aSymbol );
1139 Sets background color
1141 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
1143 myBackground = color;
1144 //myPlot->setCanvasBackground( myBackground );
1145 myPlot->canvas()->setPalette( myBackground );
1146 myPlot->setPalette( myBackground );
1147 QPalette aPal = myPlot->getLegend()->palette();
1148 for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
1149 QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
1150 aPal.setColor( cg, QColorGroup::Base, myBackground );
1151 aPal.setColor( cg, QColorGroup::Background, myBackground );
1153 myPlot->getLegend()->setPalette( aPal );
1157 Gets background color
1159 QColor Plot2d_ViewFrame::backgroundColor() const
1161 return myBackground;
1164 Sets hor.axis grid parameters
1166 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax,
1167 bool xMinorEnabled, const int xMinorMax,
1170 if( xMinorMax>=xMajorMax )
1173 myXGridMajorEnabled = xMajorEnabled;
1174 myXGridMinorEnabled = xMinorEnabled;
1175 myXGridMaxMajor = xMajorMax;
1176 myXGridMaxMinor = xMinorMax;
1177 myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1178 myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1179 myPlot->setGridXAxis(QwtPlot::xBottom);
1180 myPlot->enableGridX( myXGridMajorEnabled );
1181 myPlot->enableGridXMin( myXGridMinorEnabled );
1186 Sets ver.axis grid parameters
1188 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax,
1189 bool yMinorEnabled, const int yMinorMax,
1190 bool y2MajorEnabled, const int y2MajorMax,
1191 bool y2MinorEnabled, const int y2MinorMax,
1194 myYGridMajorEnabled = yMajorEnabled;
1195 myYGridMinorEnabled = yMinorEnabled;
1196 myYGridMaxMajor = yMajorMax;
1197 myYGridMaxMinor = yMinorMax;
1200 myY2GridMajorEnabled = y2MajorEnabled;
1201 myY2GridMinorEnabled = y2MinorEnabled;
1202 myY2GridMaxMajor = y2MajorMax;
1203 myY2GridMaxMinor = y2MinorMax;
1205 myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1206 myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1209 myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
1210 myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
1213 myPlot->setGridYAxis(QwtPlot::yLeft);
1216 if (myYGridMajorEnabled) {
1217 myPlot->enableGridYMin(myYGridMinorEnabled);
1218 myPlot->enableGridY( myYGridMajorEnabled);
1220 else if (myY2GridMajorEnabled) {
1221 myPlot->setGridYAxis(QwtPlot::yRight);
1222 myPlot->enableGridYMin(myY2GridMinorEnabled);
1223 myPlot->enableGridY(myY2GridMajorEnabled);
1226 myPlot->enableGridYMin(false);
1227 myPlot->enableGridY(false);
1231 myPlot->enableGridY( myYGridMajorEnabled );
1232 myPlot->enableGridYMin( myYGridMinorEnabled );
1239 Sets title for some axis
1241 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
1242 ObjectType type, bool update )
1246 myTitleEnabled = enabled;
1248 myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1251 myXTitleEnabled = enabled;
1253 myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1256 myYTitleEnabled = enabled;
1258 myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1261 myY2TitleEnabled = enabled;
1263 myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null );
1270 Sets title for some axis
1272 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
1277 title = myTitle; break;
1279 title = myXTitle; break;
1281 title = myYTitle; break;
1283 title = myY2Title; break;
1288 Sets font for Plot2d object : title or axis
1290 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
1294 myPlot->setTitleFont(font);
1297 myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break;
1299 myPlot->setAxisTitleFont(QwtPlot::yLeft, font); break;
1301 myPlot->setAxisTitleFont(QwtPlot::yRight, font); break;
1303 myPlot->setAxisFont(QwtPlot::xBottom, font); break;
1305 myPlot->setAxisFont(QwtPlot::yLeft, font); break;
1307 myPlot->setAxisFont(QwtPlot::yRight, font); break;
1313 Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1315 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1318 if ( myXMode == 0 ) // linear
1319 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1321 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1325 emit vpModeHorChanged();
1328 Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1330 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1333 if ( myYMode == 0 ) { // linear
1334 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1336 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1338 else { // logarithmic
1339 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1341 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true );
1345 emit vpModeVerChanged();
1349 Return, scale mode for horizontal axis
1351 bool Plot2d_ViewFrame::isModeHorLinear()
1353 return (myXMode == 0 ? true : false);
1357 Return, scale mode for vertical axis
1359 bool Plot2d_ViewFrame::isModeVerLinear()
1361 return (myYMode == 0 ? true : false);
1364 Slot, called when user presses mouse button
1366 void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me )
1368 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1369 if ( myOperation == NoOpId )
1370 myOperation = testOperation( me );
1371 if ( myOperation != NoOpId ) {
1373 if ( myOperation == FitAreaId ) {
1374 myPlot->setOutlineStyle( Qwt::Rect );
1376 else if ( myOperation == GlPanId ) {
1377 myPlot->setAxisScale( QwtPlot::yLeft,
1378 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2,
1379 myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 );
1380 myPlot->setAxisScale( QwtPlot::xBottom,
1381 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2,
1382 myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
1384 myPlot->setAxisScale( QwtPlot::yRight,
1385 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2,
1386 myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 );
1391 int btn = me.button() | me.state();
1392 if (btn == RightButton) {
1393 QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
1394 me.pos(), btn, me.state());
1395 // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
1396 parent()->eventFilter(this, aEvent);
1401 Slot, called when user moves mouse
1403 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1405 int dx = me.pos().x() - myPnt.x();
1406 int dy = me.pos().y() - myPnt.y();
1408 if ( myOperation != NoOpId) {
1409 if ( myOperation == ZoomId ) {
1410 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1411 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1413 myPlot->setAxisScale( QwtPlot::yLeft,
1414 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1415 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1416 myPlot->setAxisScale( QwtPlot::xBottom,
1417 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1418 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1420 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1421 myPlot->setAxisScale( QwtPlot::yRight,
1422 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1423 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + dy ) );
1428 else if ( myOperation == PanId ) {
1429 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1430 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1432 myPlot->setAxisScale( QwtPlot::yLeft,
1433 myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ),
1434 myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1435 myPlot->setAxisScale( QwtPlot::xBottom,
1436 myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1437 myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) );
1439 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1440 myPlot->setAxisScale( QwtPlot::yRight,
1441 myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-dy ),
1442 myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-dy ) );
1449 ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1453 Slot, called when user releases mouse
1455 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1457 if ( myOperation == NoOpId && me.button() == RightButton )
1459 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1460 me.pos(), me.globalPos(),
1462 emit contextMenuRequested( &aEvent );
1464 if ( myOperation == FitAreaId ) {
1465 QRect rect( myPnt, me.pos() );
1468 myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1469 myPlot->setOutlineStyle( Qwt::Triangle );
1471 ((Plot2d_ViewWindow*)parent())->putInfo(tr("INF_READY"));
1472 myOperation = NoOpId;
1475 Slot, called when user wheeling mouse
1477 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
1479 double aDelta = event->delta();
1480 double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.;
1482 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1483 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1485 myPlot->setAxisScale( QwtPlot::yLeft,
1486 myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ),
1487 myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale );
1488 myPlot->setAxisScale( QwtPlot::xBottom,
1489 myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1490 myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale );
1492 QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1493 myPlot->setAxisScale( QwtPlot::yRight,
1494 myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ),
1495 myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale );
1498 myPnt = event->pos();
1501 View operations : Pan view
1503 void Plot2d_ViewFrame::onViewPan()
1505 myPlot->canvas()->setCursor( panCursor );
1506 myOperation = PanId;
1507 qApp->installEventFilter( this );
1510 View operations : Zoom view
1512 void Plot2d_ViewFrame::onViewZoom()
1514 myPlot->canvas()->setCursor( zoomCursor );
1515 myOperation = ZoomId;
1516 qApp->installEventFilter( this );
1519 View operations : Fot All
1521 void Plot2d_ViewFrame::onViewFitAll()
1526 View operations : Fit Area
1528 void Plot2d_ViewFrame::onViewFitArea()
1530 myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1531 myOperation = FitAreaId;
1532 qApp->installEventFilter( this );
1535 View operations : Global panning
1537 void Plot2d_ViewFrame::onViewGlobalPan()
1539 myPlot->canvas()->setCursor( glPanCursor );
1540 myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1541 myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1543 myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1545 QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1546 QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1548 myXDistance = xMap.d2() - xMap.d1();
1549 myYDistance = yMap.d2() - yMap.d1();
1552 QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
1553 myYDistance2 = yMap2.d2() - yMap2.d1();
1556 myOperation = GlPanId;
1557 qApp->installEventFilter( this );
1560 //=================================================================================
1561 // Plot2d_Plot2d implementation
1562 //=================================================================================
1566 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1570 enableOutline( true );
1571 setOutlineStyle( Qwt::Triangle );
1572 setOutlinePen( green );
1574 setAutoLegend( false );
1575 setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1576 enableLegend( false );
1578 enableGridX( false );
1579 enableGridXMin( false );
1580 enableGridY( false );
1581 enableGridYMin( false );
1582 // auto scaling by default
1583 setAxisAutoScale( QwtPlot::yLeft );
1584 setAxisAutoScale( QwtPlot::yRight );
1585 setAxisAutoScale( QwtPlot::xBottom );
1588 Recalculates and redraws Plot 2d view
1590 void Plot2d_Plot2d::replot()
1592 updateLayout(); // to fix bug(?) of Qwt - view is not updated when title is changed
1597 Checks if two colors are close to each other [ static ]
1598 uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1600 const long COLOR_DISTANCE = 100;
1601 const int MAX_ATTEMPTS = 10;
1602 static bool closeColors( const QColor& color1, const QColor& color2 )
1604 long tol = abs( color2.red() - color1.red() ) +
1605 abs( color2.green() - color1.green() ) +
1606 abs( color2.blue() - color1.blue() );
1608 return ( tol <= COLOR_DISTANCE );
1611 Gets new unique marker for item if possible
1613 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine )
1618 int aRed = (int)( 256.0 * rand() / RAND_MAX); // generate random color
1619 int aGreen = (int)( 256.0 * rand() / RAND_MAX); // ...
1620 int aBlue = (int)( 256.0 * rand() / RAND_MAX); // ...
1621 int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1; // 9 markers types ( not including empty )
1622 int aLine = (int)( 5.0 * rand() / RAND_MAX) + 1; // 5 line types ( not including empty )
1624 typeMarker = ( QwtSymbol::Style )aMarker;
1625 color = QColor( aRed, aGreen, aBlue );
1626 typeLine = ( Qt::PenStyle )aLine;
1629 if ( cnt == MAX_ATTEMPTS )
1632 bOk = !existMarker( typeMarker, color, typeLine );
1635 static int aMarker = -1;
1636 static int aColor = -1;
1637 static int aLine = -1;
1639 if ( myColors.isEmpty() ) {
1640 // creating colors list
1641 myColors.append( Qt::white );
1642 myColors.append( Qt::blue );
1643 myColors.append( Qt::gray );
1644 myColors.append( Qt::darkGreen );
1645 myColors.append( Qt::magenta );
1646 myColors.append( Qt::darkGray );
1647 myColors.append( Qt::red );
1648 myColors.append( Qt::darkBlue );
1649 myColors.append( Qt::darkYellow );
1650 myColors.append( Qt::cyan );
1651 myColors.append( Qt::darkRed );
1652 myColors.append( Qt::darkCyan );
1653 myColors.append( Qt::yellow );
1654 myColors.append( Qt::darkMagenta );
1655 myColors.append( Qt::green );
1656 myColors.append( Qt::black );
1659 int nbMarkers = 11; // QwtSymbol supports 11 marker types
1660 int nbLines = 6; // Qt supports 6 line types
1661 int nbColors = myColors.count(); // number of default colors supported
1663 aMarker = ( aMarker + 1 ) % nbMarkers;
1664 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1665 aColor = ( aColor + 1 ) % nbColors;
1666 aLine = ( aLine + 1 ) % nbLines;
1667 if ( aLine == Qt::NoPen ) aLine++;
1669 typeMarker = ( QwtSymbol::Style )aMarker;
1670 color = myColors[ aColor ];
1671 typeLine = ( Qt::PenStyle )aLine;
1672 if ( !existMarker( typeMarker, color, typeLine ) )
1676 for ( i = 0; i < nbMarkers; i++ ) {
1677 aMarker = ( aMarker + 1 ) % nbMarkers;
1678 if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1679 for ( j = 0; j < nbColors; j++ ) {
1680 aColor = ( aColor + 1 ) % nbColors;
1681 for ( k = 0; k < nbLines; k++ ) {
1682 aLine = ( aLine + 1 ) % nbLines;
1683 if ( aLine == Qt::NoPen ) aLine++;
1684 if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1685 typeMarker = ( QwtSymbol::Style )aMarker;
1686 color = myColors[ aColor ];
1687 typeLine = ( Qt::PenStyle )aLine;
1696 QSizePolicy Plot2d_Plot2d::sizePolicy() const
1698 return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
1701 QSize Plot2d_Plot2d::sizeHint() const
1703 return QwtPlot::minimumSizeHint();
1707 return minimum size for qwt plot
1709 QSize Plot2d_Plot2d::minimumSizeHint() const
1711 return QSize( 0, 0 );
1712 // QSize aSize = QwtPlot::minimumSizeHint();
1713 // return QSize(aSize.width()*3/4, aSize.height());
1716 Checks if marker belongs to any enitity
1718 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine )
1720 // getting all curves
1721 QArray<long> keys = curveKeys();
1724 if ( closeColors( color, backgroundColor() ) )
1726 for ( int i = 0; i < (int)keys.count(); i++ )
1728 QwtPlotCurve* crv = curve( keys[i] );
1730 QwtSymbol::Style aStyle = crv->symbol().style();
1731 QColor aColor = crv->pen().color();
1732 Qt::PenStyle aLine = crv->pen().style();
1733 // if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1734 if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
1741 // TEMPORARY SOLUTION!!! TO BE IMPLEMENTED!!!
1742 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
1747 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
1752 myCurveType = vf->myCurveType;
1753 myShowLegend = vf->myShowLegend;
1754 myLegendPos = vf->myLegendPos;
1755 myMarkerSize = vf->myMarkerSize;
1756 myBackground = vf->myBackground;
1757 myTitle = vf->myTitle;
1758 myXTitle = vf->myXTitle;
1759 myYTitle = vf->myYTitle;
1760 myY2Title = vf->myY2Title;
1761 myTitleEnabled = vf->myTitleEnabled;
1762 myXTitleEnabled = vf->myXTitleEnabled;
1763 myYTitleEnabled = vf->myYTitleEnabled;
1764 myY2TitleEnabled = vf->myY2TitleEnabled;
1765 myXGridMajorEnabled = vf->myXGridMajorEnabled;
1766 myYGridMajorEnabled = vf->myYGridMajorEnabled;
1767 myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
1768 myXGridMinorEnabled = vf->myXGridMinorEnabled;
1769 myYGridMinorEnabled = vf->myYGridMinorEnabled;
1770 myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
1771 myXGridMaxMajor = vf->myXGridMaxMajor;
1772 myYGridMaxMajor = vf->myYGridMaxMajor;
1773 myY2GridMaxMajor = vf->myY2GridMaxMajor;
1774 myXGridMaxMinor = vf->myXGridMaxMinor;
1775 myYGridMaxMinor = vf->myYGridMaxMinor;
1776 myY2GridMaxMinor = vf->myY2GridMaxMinor;
1777 myXMode = vf->myXMode;
1778 myYMode = vf->myYMode;
1779 mySecondY = vf->mySecondY;
1783 Updates titles according to curves
1785 #define BRACKETIZE(x) QString( "[ " ) + x + QString( " ]" )
1786 void Plot2d_ViewFrame::updateTitles()
1788 QIntDictIterator<Plot2d_Curve> it( myCurves );
1789 QStringList aXTitles;
1790 QStringList aYTitles;
1791 QStringList aXUnits;
1792 QStringList aYUnits;
1793 QStringList aTables;
1795 while ( it.current() ) {
1796 // collect titles and units from all curves...
1797 QString xTitle = it.current()->getHorTitle().stripWhiteSpace();
1798 QString yTitle = it.current()->getVerTitle().stripWhiteSpace();
1799 QString xUnits = it.current()->getHorUnits().stripWhiteSpace();
1800 QString yUnits = it.current()->getVerUnits().stripWhiteSpace();
1802 aYTitles.append( yTitle );
1803 if ( aXTitles.find( xTitle ) == aXTitles.end() )
1804 aXTitles.append( xTitle );
1805 if ( aXUnits.find( xUnits ) == aXUnits.end() )
1806 aXUnits.append( xUnits );
1807 if ( aYUnits.find( yUnits ) == aYUnits.end() )
1808 aYUnits.append( yUnits );
1810 QString aName = it.current()->getTableTitle();
1811 if( !aName.isEmpty() && aTables.find( aName ) == aTables.end() )
1812 aTables.append( aName );
1817 // ... and update plot 2d view
1818 QString xUnits, yUnits;
1819 if ( aXUnits.count() == 1 && !aXUnits[0].isEmpty() )
1820 xUnits = BRACKETIZE( aXUnits[0] );
1821 if ( aYUnits.count() == 1 && !aYUnits[0].isEmpty())
1822 yUnits = BRACKETIZE( aYUnits[0] );
1823 QString xTitle, yTitle;
1824 if ( aXTitles.count() == 1 && aXUnits.count() == 1 )
1825 xTitle = aXTitles[0];
1826 if ( aYTitles.count() == 1 )
1827 yTitle = aYTitles[0];
1829 if ( !xTitle.isEmpty() && !xUnits.isEmpty() )
1831 if ( !yTitle.isEmpty() && !yUnits.isEmpty() )
1834 setTitle( myXTitleEnabled, xTitle + xUnits, XTitle, true );
1835 setTitle( myYTitleEnabled, yTitle + yUnits, YTitle, true );
1836 setTitle( true, aTables.join("; "), MainTitle, true );