Salome HOME
PAL10190 - clone of plot2d
[modules/gui.git] / src / Plot2d / Plot2d_ViewFrame.cxx
1 #include "Plot2d_ViewFrame.h"
2
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"
8
9 #include "SUIT_Tools.h"
10 #include "SUIT_Session.h"
11 #include "SUIT_MessageBox.h"
12 #include "SUIT_ResourceMgr.h"
13 #include "SUIT_Application.h"
14
15 //#include "utilities.h"
16
17 #include "qapplication.h"
18 #include <qtoolbar.h>
19 #include <qtoolbutton.h>
20 #include <qcursor.h>
21 #include <qcolordialog.h>
22 #include <qptrlist.h>
23 #include <qlayout.h>
24 #include <qmap.h>
25
26 #include <qwt_math.h>
27 #include <qwt_plot_canvas.h>
28 #include <iostream>
29 #include <stdlib.h>
30
31 #include <qwt_legend.h>
32
33 //#include "utilities.h"
34
35 #define DEFAULT_LINE_WIDTH     0     // (default) line width
36 #define DEFAULT_MARKER_SIZE    9     // default marker size
37 #define MIN_RECT_SIZE          11    // min sensibility area size
38
39 const char* imageZoomCursor[] = { 
40 "32 32 3 1",
41 ". c None",
42 "a c #000000",
43 "# c #ffffff",
44 "................................",
45 "................................",
46 ".#######........................",
47 "..aaaaaaa.......................",
48 "................................",
49 ".............#####..............",
50 "...........##.aaaa##............",
51 "..........#.aa.....a#...........",
52 ".........#.a.........#..........",
53 ".........#a..........#a.........",
54 "........#.a...........#.........",
55 "........#a............#a........",
56 "........#a............#a........",
57 "........#a............#a........",
58 "........#a............#a........",
59 ".........#...........#.a........",
60 ".........#a..........#a.........",
61 ".........##.........#.a.........",
62 "........#####.....##.a..........",
63 ".......###aaa#####.aa...........",
64 "......###aa...aaaaa.......#.....",
65 ".....###aa................#a....",
66 "....###aa.................#a....",
67 "...###aa...............#######..",
68 "....#aa.................aa#aaaa.",
69 ".....a....................#a....",
70 "..........................#a....",
71 "...........................a....",
72 "................................",
73 "................................",
74 "................................",
75 "................................"};
76
77 const char* imageCrossCursor[] = { 
78   "32 32 3 1",
79   ". c None",
80   "a c #000000",
81   "# c #ffffff",
82   "................................",
83   "................................",
84   "................................",
85   "................................",
86   "................................",
87   "................................",
88   "................................",
89   "...............#................",
90   "...............#a...............",
91   "...............#a...............",
92   "...............#a...............",
93   "...............#a...............",
94   "...............#a...............",
95   "...............#a...............",
96   "...............#a...............",
97   ".......#################........",
98   "........aaaaaaa#aaaaaaaaa.......",
99   "...............#a...............",
100   "...............#a...............",
101   "...............#a...............",
102   "...............#a...............",
103   "...............#a...............",
104   "...............#a...............",
105   "...............#a...............",
106   "................a...............",
107   "................................",
108   "................................",
109   "................................",
110   "................................",
111   "................................",
112   "................................",
113   "................................"};
114   
115
116 QPixmap zoomPixmap(imageZoomCursor);
117 QPixmap globalPanPixmap(imageCrossCursor);
118
119 QCursor panCursor(Qt::SizeAllCursor);
120 QCursor zoomCursor(zoomPixmap);
121 QCursor glPanCursor(globalPanPixmap);
122
123 //=================================================================================
124 // Plot2d_ViewFrame implementation
125 //=================================================================================
126
127 /*!
128   Constructor
129 */
130 Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title )
131      : QWidget (parent, title, 0),
132        myOperation( NoOpId ), 
133        myCurveType( 1 ), 
134        myShowLegend( true ), myLegendPos( 1 ),
135        myMarkerSize( DEFAULT_MARKER_SIZE ),
136        myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ),
137        myBackground( white ),
138        myTitleEnabled( true ), myXTitleEnabled( true ),
139        myYTitleEnabled( true ), myY2TitleEnabled (true),
140        myXGridMajorEnabled( true ), myYGridMajorEnabled( true ), myY2GridMajorEnabled( true ), 
141        myXGridMinorEnabled( false ), myYGridMinorEnabled( false ), myY2GridMinorEnabled( false ),
142        myXGridMaxMajor( 8 ), myYGridMaxMajor( 8 ), myY2GridMaxMajor( 8 ),
143        myXGridMaxMinor( 5 ), myYGridMaxMinor( 5 ), myY2GridMaxMinor( 5 ),
144        myXMode( 0 ), myYMode( 0 ), mySecondY( false )
145 {
146   /* Plot 2d View */
147   QVBoxLayout* aLayout = new QVBoxLayout( this ); 
148   myPlot = new Plot2d_Plot2d( this );
149   aLayout->addWidget( myPlot );
150
151 //  createActions();
152
153   connect( myPlot, SIGNAL( plotMouseMoved( const QMouseEvent& ) ),
154      this,   SLOT( plotMouseMoved( const QMouseEvent& ) ) );
155   connect( myPlot, SIGNAL( plotMousePressed( const QMouseEvent& ) ),
156      this,   SLOT( plotMousePressed( const QMouseEvent& ) ) );
157   connect( myPlot, SIGNAL( plotMouseReleased( const QMouseEvent& ) ),
158      this,   SLOT( plotMouseReleased( const QMouseEvent& ) ) );
159   //connect( myPlot, SIGNAL( legendClicked( long ) ),
160   //   this,   SLOT( onLegendClicked( long ) ) );
161
162   /* Initial Setup - get from the preferences */
163   readPreferences();
164
165   myPlot->setMargin( 5 );
166   setCurveType( myCurveType, false );
167   setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, false );
168   setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
169             myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, false );
170
171   setTitle( myTitleEnabled,  myTitle,  MainTitle, false );
172   setTitle( myXTitleEnabled, myXTitle, XTitle, false );
173   setTitle( myYTitleEnabled, myYTitle, YTitle, false );
174
175   if (mySecondY)
176     setTitle( myY2TitleEnabled, myY2Title, Y2Title, false );
177   setHorScaleMode( myXMode, false );
178   setVerScaleMode( myYMode, false );
179   setBackgroundColor( myBackground );
180   setLegendPos( myLegendPos );
181   showLegend( myShowLegend, false );
182   myPlot->replot();
183
184   if ( parent ) {
185     resize( (int)(0.8 * parent->width()), (int)(0.8 * parent->height()) );
186   }
187   QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
188   QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
189   myXDistance = xMap.d2() - xMap.d1();
190   myYDistance = yMap.d2() - yMap.d1();
191   myYDistance2 = 0;
192   if (mySecondY) {
193     QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
194     myYDistance2 = yMap2.d2() - yMap2.d1();
195   }
196 }
197 /*!
198   Destructor
199 */
200 Plot2d_ViewFrame::~Plot2d_ViewFrame()
201 {
202 }
203 /*!
204   Gets window's central widget
205 */
206 QWidget* Plot2d_ViewFrame::getViewWidget()
207 {
208   return (QWidget*)myPlot;
209 }
210 /*!
211   Actually this method just re-displays all curves which are presented in the viewer
212 */
213 void Plot2d_ViewFrame::DisplayAll()
214 {
215   QList<Plot2d_Curve> clist;
216   getCurves( clist );
217   for ( int i = 0; i < (int)clist.count(); i++ ) {
218     updateCurve( clist.at( i ), false );
219   }
220   myPlot->replot();
221 }
222 /*!
223    Removes all curves from the view
224 */
225 void Plot2d_ViewFrame::EraseAll() 
226 {
227   myPlot->clear();
228   myCurves.clear();
229   myPlot->replot();
230 }
231 /*!
232   Redraws viewframe contents
233 */
234 void Plot2d_ViewFrame::Repaint()
235 {
236   myPlot->replot();
237 }
238 /*!
239   Display presentation
240 */
241 void Plot2d_ViewFrame::Display( const Plot2d_Prs* prs )
242 {
243   if ( !prs || prs->IsNull() )
244     return;
245
246   if (prs->isSecondY()) {
247     myPlot->enableAxis(QwtPlot::yRight, true);
248     mySecondY = true;
249   }
250   else {
251     myPlot->enableAxis(QwtPlot::yRight, false);
252     mySecondY = false;
253   }
254
255   // display all curves from presentation
256   curveList aCurves = prs->getCurves();
257   displayCurves( aCurves );
258   setXGrid( myXGridMajorEnabled, myXGridMaxMajor, myXGridMinorEnabled, myXGridMaxMinor, true );
259   setYGrid( myYGridMajorEnabled, myYGridMaxMajor, myYGridMinorEnabled, myYGridMaxMinor,
260             myY2GridMajorEnabled, myY2GridMaxMajor, myY2GridMinorEnabled, myY2GridMaxMinor, true );
261 }
262
263 /*!
264   Erase presentation
265 */
266 void Plot2d_ViewFrame::Erase( const Plot2d_Prs* prs, const bool )
267 {
268   if ( !prs || prs->IsNull() )
269     return;
270
271   // erase all curves from presentation
272   curveList aCurves = prs->getCurves();
273   eraseCurves( aCurves );
274 }
275
276 /*!
277   Sets title
278 */
279 void Plot2d_ViewFrame::setTitle( const QString& title )
280 {
281   setTitle( myTitleEnabled, title, MainTitle, true );
282 }
283
284 /*!
285   Reads Plot2d view settings from the preferences
286 */
287 void Plot2d_ViewFrame::readPreferences()
288 {
289   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
290
291   myCurveType = resMgr->integerValue( "Plot2d", "CurveType", myCurveType );
292   if ( myCurveType < 1 || myCurveType > 2 )
293     myCurveType = 1;
294   myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend );
295   myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos );
296   myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize );
297   myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground );
298
299   myTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowTitle", myTitleEnabled );
300   myXTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
301   myYTitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
302   myY2TitleEnabled = resMgr->booleanValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
303
304   myXGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
305   myYGridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
306   myY2GridMajorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
307
308   myXGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
309   myYGridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
310   myY2GridMinorEnabled = resMgr->booleanValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
311
312   myXGridMaxMajor = resMgr->integerValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
313   myYGridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
314   if ( mySecondY )
315     myY2GridMaxMajor = resMgr->integerValue( "Plot2d", "VerMajorRightGridMax", myY2GridMaxMajor );
316
317   myXGridMaxMinor = resMgr->integerValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
318   myYGridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
319   if ( mySecondY )
320     myY2GridMaxMinor = resMgr->integerValue( "Plot2d", "VerMinorGridMax", myY2GridMaxMinor );
321
322   myXMode = resMgr->integerValue( "Plot2d", "HorScaleMode", myXMode );
323   myXMode = QMAX( 0, QMIN( 1, myXMode ) );
324
325   myYMode = resMgr->integerValue( "Plot2d", "VerScaleMode", myYMode );
326   myYMode = QMAX( 0, QMIN( 1, myYMode ) );
327 }
328
329 /*!
330   Writes Plot2d view settings to the preferences
331 */
332 void Plot2d_ViewFrame::writePreferences()
333 {
334   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
335
336   resMgr->setValue( "Plot2d", "CurveType", myCurveType );
337   resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend );
338   resMgr->setValue( "Plot2d", "LegendPos", myLegendPos );
339   resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize );
340   resMgr->setValue( "Plot2d", "Background", myBackground );
341   resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled );
342   resMgr->setValue( "Plot2d", "ShowHorTitle", myXTitleEnabled );
343   resMgr->setValue( "Plot2d", "ShowVerLeftTitle", myYTitleEnabled );
344   if ( mySecondY )
345     resMgr->setValue( "Plot2d", "ShowVerRightTitle", myY2TitleEnabled );
346
347   resMgr->setValue( "Plot2d", "EnableHorMajorGrid", myXGridMajorEnabled );
348   resMgr->setValue( "Plot2d", "EnableVerMajorGrid", myYGridMajorEnabled );
349   resMgr->setValue( "Plot2d", "EnableHorMinorGrid", myXGridMinorEnabled );
350   resMgr->setValue( "Plot2d", "EnableVerMinorGrid", myYGridMinorEnabled );
351
352   resMgr->setValue( "Plot2d", "HorMajorGridMax", myXGridMaxMajor );
353   resMgr->setValue( "Plot2d", "VerMajorGridMax", myYGridMaxMajor );
354
355   resMgr->setValue( "Plot2d", "HorMinorGridMax", myXGridMaxMinor );
356   resMgr->setValue( "Plot2d", "VerMinorGridMax", myYGridMaxMinor );
357
358   resMgr->setValue( "Plot2d", "HorScaleMode", myXMode );
359
360   if ( mySecondY )
361   {
362     resMgr->setValue( "Plot2d", "EnableRightVerMajorGrid", myY2GridMajorEnabled );
363     resMgr->setValue( "Plot2d", "EnableRightVerMinorGrid", myY2GridMinorEnabled );
364     resMgr->setValue( "Plot2d", "VerRightMajorGridMax", myY2GridMaxMajor );
365     resMgr->setValue( "Plot2d", "VerRightMinorGridMax", myY2GridMaxMinor );
366   }
367
368   resMgr->setValue( "Plot2d", "VerScaleMode", myYMode );
369 }
370
371 /*!
372   Prints mouse cursor coordinates into string
373 */
374 QString Plot2d_ViewFrame::getInfo( const QPoint& pnt ) 
375 {
376   int i;
377   bool xFound = false, yFound = false;
378   double xCoord, yCoord;
379   const QwtScaleDiv* aXscale = myPlot->axisScale( QwtPlot::xBottom );
380   for ( i = 0; i < aXscale->majCnt(); i++ ) {
381     double majXmark = aXscale->majMark( i );
382     int xmark = myPlot->transform( QwtPlot::xBottom, majXmark );
383     if ( xmark-2 == pnt.x() ) {
384       xCoord = majXmark; 
385       xFound = true;
386 //      MESSAGE("Plot2d_ViewFrame::getInfo : close maj X mark("<<i<<") = "<<majXmark<<" "<<xmark<<" "<<pnt.x());
387       break;
388     }
389   }
390   if ( !xFound ) {
391     for ( i = 0; i < aXscale->minCnt(); i++ ) {
392       double minXmark = aXscale->minMark( i );
393       int xmark = myPlot->transform( QwtPlot::xBottom, minXmark );
394       if ( xmark-2 == pnt.x() ) {
395         xCoord = minXmark; 
396         xFound = true;
397 //        MESSAGE("Plot2d_ViewFrame::getInfo : close min X mark("<<i<<") = "<<minXmark<<" "<<xmark<<" "<<pnt.x());
398         break;
399       }
400     }
401   }  
402   const QwtScaleDiv* aYscale = myPlot->axisScale( QwtPlot::yLeft );
403   for ( i = 0; i < aYscale->majCnt(); i++ ) {
404     double majYmark = aYscale->majMark( i );
405     int ymark = myPlot->transform( QwtPlot::yLeft, majYmark );
406     if ( ymark-2 == pnt.y() ) {
407       yCoord = majYmark; 
408       yFound = true;
409       break;
410     }
411   }
412   if ( !yFound ) {
413     for ( i = 0; i < aYscale->minCnt(); i++ ) {
414       double minYmark = aYscale->minMark( i );
415       int ymark = myPlot->transform( QwtPlot::yLeft, minYmark );
416       if ( ymark-2 == pnt.y() ) {
417         yCoord = minYmark; 
418         yFound = true;
419         break;
420       }
421     }
422   }  
423
424   QString strX = QString::number( xFound ? xCoord : myPlot->invTransform( QwtPlot::xBottom, pnt.x() ) ).stripWhiteSpace();
425   if ( strX == "-0" )
426     strX = "0";
427   QString strY = QString::number( yFound ? yCoord : myPlot->invTransform( QwtPlot::yLeft, pnt.y() ) ).stripWhiteSpace();
428   if ( strY == "-0" )
429     strY = "0";
430   QString info = "";
431
432   if (mySecondY) {
433     bool yFound2 = false;
434     double yCoord2;
435
436     const QwtScaleDiv* aYscale2 = myPlot->axisScale( QwtPlot::yRight );
437     for ( i = 0; i < aYscale2->majCnt(); i++ ) {
438       double majYmark = aYscale2->majMark( i );
439       int ymark = myPlot->transform( QwtPlot::yRight, majYmark );
440       if ( ymark-2 == pnt.y() ) {
441         yCoord2 = majYmark; 
442         yFound2 = true;
443         break;
444       }
445     }
446     if ( !yFound2 ) {
447       for ( i = 0; i < aYscale2->minCnt(); i++ ) {
448         double minYmark = aYscale2->minMark( i );
449         int ymark = myPlot->transform( QwtPlot::yRight, minYmark );
450         if ( ymark-2 == pnt.y() ) {
451           yCoord2 = minYmark; 
452           yFound2 = true;
453           break;
454         }
455       }
456     }
457     QString strY2 = QString::number( yFound2 ? yCoord2 : 
458                       myPlot->invTransform( QwtPlot::yRight, pnt.y() ) ).stripWhiteSpace();
459     if ( strY2 == "-0" )
460     strY2 = "0";
461     info = tr("INF_COORDINATES_SOME_Y").arg( strX ).arg( strY ).arg( strY2 );
462   }
463   else
464     info = tr("INF_COORDINATES").arg( strX ).arg( strY );
465
466   return info;
467 }
468
469 /*!
470   Converts Plot2d_Curve's marker style to Qwt marker style [ static ]
471 */
472 static QwtSymbol::Style plot2qwtMarker( Plot2d_Curve::MarkerType m )
473 {
474   QwtSymbol::Style ms = QwtSymbol::None;  
475   switch ( m ) {
476   case Plot2d_Curve::Circle:
477     ms = QwtSymbol::Ellipse;   break;
478   case Plot2d_Curve::Rectangle:
479     ms = QwtSymbol::Rect;      break;
480   case Plot2d_Curve::Diamond:
481     ms = QwtSymbol::Diamond;   break;
482   case Plot2d_Curve::DTriangle:
483     ms = QwtSymbol::DTriangle; break;
484   case Plot2d_Curve::UTriangle:
485     ms = QwtSymbol::UTriangle; break;
486   case Plot2d_Curve::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
487     ms = QwtSymbol::RTriangle; break;
488   case Plot2d_Curve::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
489     ms = QwtSymbol::LTriangle; break;
490   case Plot2d_Curve::Cross:
491     ms = QwtSymbol::Cross;     break;
492   case Plot2d_Curve::XCross:
493     ms = QwtSymbol::XCross;    break;
494   case Plot2d_Curve::None:
495   default:
496     ms = QwtSymbol::None;      break;
497   }
498   return ms;
499 }
500
501 /*!
502   Converts Qwt marker style to Plot2d_Curve's marker style [ static ]
503 */
504 static Plot2d_Curve::MarkerType qwt2plotMarker( QwtSymbol::Style m )
505 {
506   Plot2d_Curve::MarkerType ms = Plot2d_Curve::None;  
507   switch ( m ) {
508   case QwtSymbol::Ellipse:
509     ms = Plot2d_Curve::Circle;    break;
510   case QwtSymbol::Rect:
511     ms = Plot2d_Curve::Rectangle; break;
512   case QwtSymbol::Diamond:
513     ms = Plot2d_Curve::Diamond;   break;
514   case QwtSymbol::DTriangle:
515     ms = Plot2d_Curve::DTriangle; break;
516   case QwtSymbol::UTriangle:
517     ms = Plot2d_Curve::UTriangle; break;
518   case QwtSymbol::RTriangle: // Qwt confuses LTriangle and RTriangle :(((
519     ms = Plot2d_Curve::LTriangle; break;
520   case QwtSymbol::LTriangle: // Qwt confuses LTriangle and RTriangle :(((
521     ms = Plot2d_Curve::RTriangle; break;
522   case QwtSymbol::Cross:
523     ms = Plot2d_Curve::Cross;     break;
524   case QwtSymbol::XCross:
525     ms = Plot2d_Curve::XCross;    break;
526   case QwtSymbol::None:
527   default:
528     ms = Plot2d_Curve::None;      break;
529   }
530   return ms;
531 }
532
533 /*!
534   Converts Plot2d_Curve's line style to Qwt line style [ static ]
535 */
536 static Qt::PenStyle plot2qwtLine( Plot2d_Curve::LineType p )
537 {
538   Qt::PenStyle ps = Qt::NoPen;
539   switch ( p ) {
540   case Plot2d_Curve::Solid:
541     ps = Qt::SolidLine;      break;
542   case Plot2d_Curve::Dash:
543     ps = Qt::DashLine;       break;
544   case Plot2d_Curve::Dot:
545     ps = Qt::DotLine;        break;
546   case Plot2d_Curve::DashDot:
547     ps = Qt::DashDotLine;    break;
548   case Plot2d_Curve::DashDotDot:
549     ps = Qt::DashDotDotLine; break;
550   case Plot2d_Curve::NoPen:
551   default:
552     ps = Qt::NoPen;          break;
553   }
554   return ps;
555 }
556
557 /*!
558   Converts Qwt line style to Plot2d_Curve's line style [ static ]
559 */
560 static Plot2d_Curve::LineType qwt2plotLine( Qt::PenStyle p )
561 {
562   Plot2d_Curve::LineType ps = Plot2d_Curve::NoPen;
563   switch ( p ) {
564   case Qt::SolidLine:
565     ps = Plot2d_Curve::Solid;      break;
566   case Qt::DashLine:
567     ps = Plot2d_Curve::Dash;       break;
568   case Qt::DotLine:
569     ps = Plot2d_Curve::Dot;        break;
570   case Qt::DashDotLine:
571     ps = Plot2d_Curve::DashDot;    break;
572   case Qt::DashDotDotLine:
573     ps = Plot2d_Curve::DashDotDot; break;
574   case Qt::NoPen:
575   default:
576     ps = Plot2d_Curve::NoPen;      break;
577   }
578   return ps;
579 }
580
581 /*!
582   Adds curve into view
583 */
584 void Plot2d_ViewFrame::displayCurve( Plot2d_Curve* curve, bool update )
585 {
586   if ( !curve )
587     return;
588   if ( hasCurve( curve ) ) {
589     updateCurve( curve, update );
590   }
591   else {
592     long curveKey = myPlot->insertCurve( curve->getVerTitle() );
593     myPlot->setCurveYAxis(curveKey, curve->getYAxis());
594
595     myCurves.insert( curveKey, curve );
596     if ( curve->isAutoAssign() ) {
597       QwtSymbol::Style typeMarker;
598       QColor           color;
599       Qt::PenStyle     typeLine;
600       myPlot->getNextMarker( typeMarker, color, typeLine );
601       myPlot->setCurvePen( curveKey, QPen( color, DEFAULT_LINE_WIDTH, typeLine ) );
602       myPlot->setCurveSymbol( curveKey, QwtSymbol( typeMarker, 
603                QBrush( color ), 
604                QPen( color ), 
605                QSize( myMarkerSize, myMarkerSize ) ) );
606       curve->setColor( color );
607       curve->setLine( qwt2plotLine( typeLine ) );
608       curve->setMarker( qwt2plotMarker( typeMarker ) );
609     }
610     else {
611       Qt::PenStyle     ps = plot2qwtLine( curve->getLine() );
612       QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
613       myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
614       myPlot->setCurveSymbol( curveKey, QwtSymbol( ms, 
615                QBrush( curve->getColor() ), 
616                QPen( curve->getColor() ), 
617                QSize( myMarkerSize, myMarkerSize ) ) );
618     }
619     if ( myCurveType == 0 )
620       myPlot->setCurveStyle( curveKey, QwtCurve::NoCurve );
621     else if ( myCurveType == 1 )
622       myPlot->setCurveStyle( curveKey, QwtCurve::Lines );
623     else if ( myCurveType == 2 )
624       myPlot->setCurveStyle( curveKey, QwtCurve::Spline );
625     myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
626   }
627   if ( update )
628     myPlot->replot();
629 }
630
631 /*!
632   Adds curves into view
633 */
634 void Plot2d_ViewFrame::displayCurves( const curveList& curves, bool update )
635 {
636   myPlot->setUpdatesEnabled( false );
637   QPtrListIterator<Plot2d_Curve> it(curves);
638   Plot2d_Curve* aCurve;
639   while( (aCurve = it.current()) ) {
640     displayCurve( aCurve, false );
641     ++it;
642   }
643
644   fitAll();
645   myPlot->setUpdatesEnabled( true );
646   if ( update )
647     myPlot->replot();
648 }
649
650 /*!
651   Erases curve
652 */
653 void Plot2d_ViewFrame::eraseCurve( Plot2d_Curve* curve, bool update )
654 {
655   if ( !curve )
656     return;
657   int curveKey = hasCurve( curve );
658   if ( curveKey ) {
659     myPlot->removeCurve( curveKey );
660     myCurves.remove( curveKey );
661     if ( update )
662       myPlot->replot();
663   }
664 }
665
666 /*!
667   Erases curves
668 */
669 void Plot2d_ViewFrame::eraseCurves( const curveList& curves, bool update )
670 {
671   QPtrListIterator<Plot2d_Curve> it(curves);
672   Plot2d_Curve* aCurve;
673   while( (aCurve = it.current()) ) {
674     eraseCurve( aCurve, false );
675     ++it;
676   }
677 //  fitAll();
678   if ( update )
679     myPlot->replot();
680 }
681
682 /*!
683   Updates curves attributes
684 */
685 void Plot2d_ViewFrame::updateCurve( Plot2d_Curve* curve, bool update )
686 {
687   if ( !curve )
688     return;
689   int curveKey = hasCurve( curve );
690   if ( curveKey ) {
691     if ( !curve->isAutoAssign() ) {
692       Qt::PenStyle     ps = plot2qwtLine( curve->getLine() );
693       QwtSymbol::Style ms = plot2qwtMarker( curve->getMarker() );
694       myPlot->setCurvePen( curveKey, QPen( curve->getColor(), curve->getLineWidth(), ps ) );
695       myPlot->setCurveSymbol( curveKey, QwtSymbol( ms, 
696                QBrush( curve->getColor() ), 
697                QPen( curve->getColor() ), 
698                QSize( myMarkerSize, myMarkerSize ) ) );
699       myPlot->setCurveData( curveKey, curve->horData(), curve->verData(), curve->nbPoints() );
700     }
701     myPlot->setCurveTitle( curveKey, curve->getVerTitle() );
702     myPlot->curve( curveKey )->setEnabled( true );
703     if ( update )
704       myPlot->replot();
705   }
706 }
707
708 /*!
709   Returns curve key if is is displayed in the viewer and 0 otherwise
710 */
711 int Plot2d_ViewFrame::hasCurve( Plot2d_Curve* curve )
712 {
713   QIntDictIterator<Plot2d_Curve> it( myCurves );
714   for ( ; it.current(); ++it ) {
715     if ( it.current() == curve )
716       return it.currentKey();
717   }
718   return 0;
719 }
720
721 /*!
722   Gets lsit of displayed curves
723 */
724 int Plot2d_ViewFrame::getCurves( QList<Plot2d_Curve>& clist )
725 {
726   clist.clear();
727   clist.setAutoDelete( false );
728   QIntDictIterator<Plot2d_Curve> it( myCurves );
729   for ( ; it.current(); ++it ) {
730     clist.append( it.current() );
731   }
732   return clist.count();
733 }
734
735 /*!
736   Returns true if the curve is visible
737 */
738 bool Plot2d_ViewFrame::isVisible( Plot2d_Curve* curve )
739 {
740   if(curve) {
741     int key = hasCurve( curve );
742     if ( key )
743       return myPlot->curve( key )->enabled();
744   }
745   return false;
746
747
748 /*!
749   update legend
750 */
751 void Plot2d_ViewFrame::updateLegend( const Plot2d_Prs* prs )
752 {
753   if ( !prs || prs->IsNull() )
754     return;
755   curveList aCurves = prs->getCurves();
756
757   QPtrListIterator<Plot2d_Curve> it(aCurves);
758   Plot2d_Curve* aCurve;
759   while( (aCurve = it.current()) ) {
760     int curveKey = hasCurve( aCurve );
761     if ( curveKey )
762       myPlot->setCurveTitle( curveKey, aCurve->getVerTitle() );
763     ++it;
764   }
765 }
766
767 /*!
768   Fits the view to see all data
769 */
770 void Plot2d_ViewFrame::fitAll()
771 {
772   QwtDiMap xMap1 = myPlot->canvasMap( QwtPlot::xBottom );
773
774   myPlot->setAxisAutoScale( QwtPlot::yLeft );
775   myPlot->setAxisAutoScale( QwtPlot::xBottom );
776   myPlot->replot();
777
778   // for existing grid
779   QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
780   QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
781
782   myPlot->setAxisScale( QwtPlot::xBottom, 
783       myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), 
784       myPlot->invTransform( QwtPlot::xBottom, xMap.i2() ) );
785   myPlot->setAxisScale( QwtPlot::yLeft, 
786       myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), 
787       myPlot->invTransform( QwtPlot::yLeft, yMap.i2() ) );
788
789   if (mySecondY) {
790     myPlot->setAxisAutoScale( QwtPlot::yRight );
791     myPlot->replot();
792     QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
793     myPlot->setAxisScale( QwtPlot::yRight, 
794         myPlot->invTransform( QwtPlot::yRight, yMap2.i1() ), 
795         myPlot->invTransform( QwtPlot::yRight, yMap2.i2() ) );
796   }
797   myPlot->replot();
798 }
799
800 /*!
801   Fits the view to rectangle area (pixels)
802 */
803 void Plot2d_ViewFrame::fitArea( const QRect& area )
804 {
805   QRect rect = area.normalize();
806   if ( rect.width() < MIN_RECT_SIZE ) {
807     rect.setWidth( MIN_RECT_SIZE );
808     rect.setLeft( rect.left() - MIN_RECT_SIZE/2 );
809   }
810   if ( rect.height() < MIN_RECT_SIZE ) {
811     rect.setHeight( MIN_RECT_SIZE );
812     rect.setTop( rect.top() - MIN_RECT_SIZE/2 );
813   }
814   myPlot->setAxisScale( QwtPlot::yLeft, 
815             myPlot->invTransform( QwtPlot::yLeft, rect.top() ), 
816             myPlot->invTransform( QwtPlot::yLeft, rect.bottom() ) );
817   if (mySecondY)
818     myPlot->setAxisScale( QwtPlot::yRight, 
819             myPlot->invTransform( QwtPlot::yRight, rect.top() ), 
820             myPlot->invTransform( QwtPlot::yRight, rect.bottom() ) );
821   myPlot->setAxisScale( QwtPlot::xBottom, 
822             myPlot->invTransform( QwtPlot::xBottom, rect.left() ), 
823             myPlot->invTransform( QwtPlot::xBottom, rect.right() ) );
824   myPlot->replot();
825 }
826
827 /*!
828   Tests if it is necessary to start operation on mouse action
829 */
830 int Plot2d_ViewFrame::testOperation( const QMouseEvent& me )
831 {
832   int btn = me.button() | me.state();
833   const int zoomBtn = ControlButton | LeftButton;
834   const int panBtn  = ControlButton | MidButton;
835   const int fitBtn  = ControlButton | RightButton;
836
837   switch (btn)
838   {
839   case zoomBtn:
840     myPlot->canvas()->setCursor( zoomCursor );
841     return ZoomId;
842   case panBtn:
843     myPlot->canvas()->setCursor( QCursor( Qt::SizeAllCursor ) );
844     return PanId;
845   case fitBtn:
846     myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
847     return FitAreaId;
848   default :
849     return NoOpId;
850   }
851 }
852
853 /*!
854   "Settings" toolbar action slot
855 */
856 void Plot2d_ViewFrame::onSettings()
857 {
858 #ifdef TEST_AUTOASSIGN
859   typedef QMap<int,int> IList;
860   typedef QMap<QString,int> SList;
861   IList mars, lins;
862   SList cols;
863   cols[ "red-min" ]   = 1000;
864   cols[ "red-max" ]   = -1;
865   cols[ "green-min" ] = 1000;
866   cols[ "green-max" ] = -1;
867   cols[ "blue-min" ]  = 1000;
868   cols[ "blue-max" ]  = -1;
869   for ( unsigned i = 0; i < 10000; i++ ) {
870     QwtSymbol::Style typeMarker;
871     QColor           color;
872     Qt::PenStyle     typeLine;
873     myPlot->getNextMarker( typeMarker, color, typeLine );
874     if ( mars.contains(typeMarker) )
875       mars[ typeMarker ] = mars[ typeMarker ]+1;
876     else
877       mars[ typeMarker ] = 0;
878     if ( lins.contains(typeLine) )
879       lins[ typeLine ] = lins[ typeLine ]+1;
880     else
881       lins[ typeLine ] = 0;
882     if ( cols[ "red-max" ] < color.red() )
883       cols[ "red-max" ] = color.red();
884     if ( cols[ "red-min" ] > color.red() )
885       cols[ "red-min" ] = color.red();
886     if ( cols[ "green-max" ] < color.green() )
887       cols[ "green-max" ] = color.green();
888     if ( cols[ "green-min" ] > color.green() )
889       cols[ "green-min" ] = color.green();
890     if ( cols[ "blue-max" ] < color.blue() )
891       cols[ "blue-max" ] = color.blue();
892     if ( cols[ "blue-min" ] > color.blue() )
893       cols[ "blue-min" ] = color.blue();
894   }
895   for (IList::Iterator it = mars.begin();  it != mars.end(); ++it)
896     MESSAGE("markers( " << it.key() << ") = " << it.data() );
897   for (IList::Iterator it = lins.begin();  it != lins.end(); ++it)
898     MESSAGE("lines( " << it.key() << ") = " << it.data() );
899   for (SList::Iterator it = cols.begin();  it != cols.end(); ++it)
900     MESSAGE("colors( " << it.key() << ") = " << it.data() );
901 #endif
902   
903   Plot2d_SetupViewDlg* dlg = new Plot2d_SetupViewDlg( this, true, mySecondY );
904   dlg->setMainTitle( myTitleEnabled, myTitle );
905   dlg->setXTitle( myXTitleEnabled, myXTitle );
906   dlg->setYTitle( myYTitleEnabled, myYTitle );
907   if (mySecondY)
908     dlg->setY2Title( myY2TitleEnabled, myY2Title );
909   dlg->setCurveType( myCurveType );
910   dlg->setLegend( myShowLegend, myLegendPos );
911   dlg->setMarkerSize( myMarkerSize );
912   dlg->setBackgroundColor( myBackground );
913   dlg->setScaleMode(myXMode, myYMode);
914   //
915   dlg->setMajorGrid( myXGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::xBottom ),
916          myYGridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yLeft ),
917          myY2GridMajorEnabled, myPlot->axisMaxMajor( QwtPlot::yRight ) );
918   dlg->setMinorGrid( myXGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::xBottom ),
919          myYGridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yLeft ),
920          myY2GridMinorEnabled, myPlot->axisMaxMinor( QwtPlot::yRight ) );
921   if ( dlg->exec() == QDialog::Accepted ) {
922     // horizontal axis title
923     setTitle( dlg->isXTitleEnabled(), dlg->getXTitle(), XTitle, false );
924     // vertical left axis title
925     setTitle( dlg->isYTitleEnabled(), dlg->getYTitle(), YTitle, false );
926     if (mySecondY) // vertical right axis title
927       setTitle( dlg->isY2TitleEnabled(), dlg->getY2Title(), Y2Title, false );
928
929     // main title
930     setTitle( dlg->isMainTitleEnabled(), dlg->getMainTitle(), MainTitle, true );
931     // curve type
932     if ( myCurveType != dlg->getCurveType() ) {
933       setCurveType( dlg->getCurveType(), false );
934     }
935     // legend
936     if ( myShowLegend != dlg->isLegendEnabled() ) {
937       showLegend( dlg->isLegendEnabled(), false );
938     }
939     if ( myLegendPos != dlg->getLegendPos() ) {
940       setLegendPos( dlg->getLegendPos() );
941     }
942     // marker size
943     if ( myMarkerSize != dlg->getMarkerSize() ) {
944       setMarkerSize( dlg->getMarkerSize(), false );
945     }
946     // background color
947     if ( myBackground != dlg->getBackgroundColor() ) {
948       setBackgroundColor( dlg->getBackgroundColor() );
949     }
950     // grid
951     bool aXGridMajorEnabled, aXGridMinorEnabled, aYGridMajorEnabled, aYGridMinorEnabled,
952          aY2GridMajorEnabled, aY2GridMinorEnabled;
953     int  aXGridMaxMajor, aXGridMaxMinor, aYGridMaxMajor, aYGridMaxMinor,
954          aY2GridMaxMajor, aY2GridMaxMinor;
955     dlg->getMajorGrid( aXGridMajorEnabled, aXGridMaxMajor, aYGridMajorEnabled, aYGridMaxMajor,
956                        aY2GridMajorEnabled, aY2GridMaxMajor);
957     dlg->getMinorGrid( aXGridMinorEnabled, aXGridMaxMinor, aYGridMinorEnabled, aYGridMaxMinor,
958                        aY2GridMinorEnabled, aY2GridMaxMinor);
959     setXGrid( aXGridMajorEnabled, aXGridMaxMajor, aXGridMinorEnabled, aXGridMaxMinor, false );
960     setYGrid( aYGridMajorEnabled, aYGridMaxMajor, aYGridMinorEnabled, aYGridMaxMinor,
961               aY2GridMajorEnabled, aY2GridMaxMajor, aY2GridMinorEnabled, aY2GridMaxMinor, false );
962     if ( myXMode != dlg->getXScaleMode() ) {
963       setHorScaleMode( dlg->getXScaleMode() );
964     }
965     if ( myYMode != dlg->getYScaleMode() ) {
966       setVerScaleMode( dlg->getYScaleMode() );
967     }
968     // update view
969     myPlot->replot();
970     // update preferences
971     if ( dlg->isSetAsDefault() ) 
972       writePreferences();
973   }
974   delete dlg;
975 }
976
977 /*!
978   "Fit Data" command slot
979 */
980 void Plot2d_ViewFrame::onFitData()
981 {
982   Plot2d_FitDataDlg* dlg = new Plot2d_FitDataDlg( this, mySecondY );
983   int ixMin = myPlot->canvasMap( QwtPlot::xBottom ).i1();
984   int ixMax = myPlot->canvasMap( QwtPlot::xBottom ).i2();
985   int iyMin = myPlot->canvasMap( QwtPlot::yLeft ).i1();
986   int iyMax = myPlot->canvasMap( QwtPlot::yLeft ).i2();
987   double xMin = myPlot->invTransform(QwtPlot::xBottom, ixMin);
988   double xMax = myPlot->invTransform(QwtPlot::xBottom, ixMax);
989   double yMin = myPlot->invTransform(QwtPlot::yLeft, iyMin);
990   double yMax = myPlot->invTransform(QwtPlot::yLeft, iyMax);
991   double y2Min = 0;
992   double y2Max = 0;
993   if (mySecondY) {
994     int iyMin = myPlot->canvasMap( QwtPlot::yRight ).i1();
995     int iyMax = myPlot->canvasMap( QwtPlot::yRight ).i2();
996     y2Min = myPlot->invTransform(QwtPlot::yRight, iyMin);
997     y2Max = myPlot->invTransform(QwtPlot::yRight, iyMax);
998   }
999   
1000   dlg->setRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1001   if ( dlg->exec() == QDialog::Accepted ) {
1002     int mode = dlg->getRange( xMin, xMax, yMin, yMax, y2Min, y2Max );
1003     if ( mode == 0 || mode == 2 ) {
1004       myPlot->setAxisScale( QwtPlot::yLeft, yMax, yMin );
1005       if (mySecondY)
1006         myPlot->setAxisScale( QwtPlot::yRight, y2Max, y2Min );
1007     }
1008     if ( mode == 0 || mode == 1 ) 
1009       myPlot->setAxisScale( QwtPlot::xBottom, xMin, xMax ); 
1010     myPlot->replot();
1011   }
1012   delete dlg;
1013 }
1014
1015 /*!
1016   Change background color
1017 */
1018 void Plot2d_ViewFrame::onChangeBackground()
1019 {
1020   QColor selColor = QColorDialog::getColor ( backgroundColor(), this ); 
1021   if ( selColor.isValid() ) {
1022     setBackgroundColor( selColor );
1023   }
1024 }
1025
1026 /*!
1027   Sets curve type
1028 */
1029 void Plot2d_ViewFrame::setCurveType( int curveType, bool update )
1030 {
1031   myCurveType = curveType;
1032   QArray<long> keys = myPlot->curveKeys();
1033   for ( int i = 0; i < (int)keys.count(); i++ ) {
1034     if ( myCurveType == 0 )
1035       myPlot->setCurveStyle( keys[i], QwtCurve::Dots );//QwtCurve::NoCurve
1036     else if ( myCurveType == 1 )
1037       myPlot->setCurveStyle( keys[i], QwtCurve::Lines );
1038     else if ( myCurveType == 2 )
1039       myPlot->setCurveStyle( keys[i], QwtCurve::Spline );
1040   }
1041   if ( update )
1042     myPlot->replot();
1043   emit vpCurveChanged();
1044 }
1045
1046 void Plot2d_ViewFrame::setCurveTitle( int curveKey, const QString& title ) 
1047
1048   if(myPlot) myPlot->setCurveTitle(curveKey, title); 
1049 }   
1050
1051 /*!
1052   Shows/hides legend
1053 */
1054 void Plot2d_ViewFrame::showLegend( bool show, bool update )
1055 {
1056   myShowLegend = show;
1057   myPlot->setAutoLegend( myShowLegend );
1058   myPlot->enableLegend( myShowLegend );
1059   if ( update )
1060     myPlot->replot();
1061 }
1062
1063 /*!
1064   Sets legend position : 0 - left, 1 - right, 2 - top, 3 - bottom
1065 */
1066 void Plot2d_ViewFrame::setLegendPos( int pos )
1067 {
1068   myLegendPos = pos;
1069   switch( pos ) {
1070   case 0:
1071     myPlot->setLegendPos( Qwt::Left );
1072     break;
1073   case 1:
1074     myPlot->setLegendPos( Qwt::Right );
1075     break;
1076   case 2:
1077     myPlot->setLegendPos( Qwt::Top );
1078     break;
1079   case 3:
1080     myPlot->setLegendPos( Qwt::Bottom );
1081     break;
1082   }
1083 }
1084
1085 /*!
1086   Sets new marker size
1087 */
1088 void Plot2d_ViewFrame::setMarkerSize( const int size, bool update )
1089 {
1090   if ( myMarkerSize != size )
1091   {
1092     myMarkerSize = size;
1093     QArray<long> keys = myPlot->curveKeys();
1094     for ( int i = 0; i < (int)keys.count(); i++ )
1095     {
1096       QwtPlotCurve* crv = myPlot->curve( keys[i] );
1097       if ( crv )
1098       {
1099         QwtSymbol aSymbol = crv->symbol();
1100         aSymbol.setSize( myMarkerSize, myMarkerSize );
1101         myPlot->setCurveSymbol( keys[i], aSymbol );
1102       }
1103     }
1104     if ( update )
1105       myPlot->replot();
1106   }
1107 }
1108
1109 /*!
1110   Sets background color
1111 */
1112 void Plot2d_ViewFrame::setBackgroundColor( const QColor& color )
1113 {
1114   myBackground = color;
1115   //myPlot->setCanvasBackground( myBackground );
1116   myPlot->canvas()->setPalette( myBackground );
1117   myPlot->setPalette( myBackground );
1118   QPalette aPal = myPlot->getLegend()->palette();
1119   for ( int i = 0; i < QPalette::NColorGroups; i++ ) {
1120     QPalette::ColorGroup cg = (QPalette::ColorGroup)i;
1121     aPal.setColor( cg, QColorGroup::Base, myBackground );
1122     aPal.setColor( cg, QColorGroup::Background, myBackground );
1123   }
1124   myPlot->getLegend()->setPalette( aPal );
1125   Repaint();
1126 }
1127 /*!
1128   Gets background color
1129 */
1130 QColor Plot2d_ViewFrame::backgroundColor() const
1131 {
1132   return myBackground;
1133 }
1134 /*!
1135   Sets hor.axis grid parameters
1136 */
1137 void Plot2d_ViewFrame::setXGrid( bool xMajorEnabled, const int xMajorMax, 
1138          bool xMinorEnabled, const int xMinorMax, 
1139          bool update )
1140 {
1141   myXGridMajorEnabled = xMajorEnabled;
1142   myXGridMinorEnabled = xMinorEnabled;
1143   myXGridMaxMajor = xMajorMax;
1144   myXGridMaxMinor = xMinorMax;
1145   myPlot->setAxisMaxMajor( QwtPlot::xBottom, myXGridMaxMajor );
1146   myPlot->setAxisMaxMinor( QwtPlot::xBottom, myXGridMaxMinor );
1147   myPlot->setGridXAxis(QwtPlot::xBottom);
1148   myPlot->enableGridX( myXGridMajorEnabled );
1149   myPlot->enableGridXMin( myXGridMinorEnabled );
1150   if ( update )
1151     myPlot->replot();
1152 }
1153 /*!
1154   Sets ver.axis grid parameters
1155 */
1156 void Plot2d_ViewFrame::setYGrid( bool yMajorEnabled, const int yMajorMax, 
1157                                  bool yMinorEnabled, const int yMinorMax,
1158                                  bool y2MajorEnabled, const int y2MajorMax, 
1159                                  bool y2MinorEnabled, const int y2MinorMax, 
1160                                  bool update )
1161 {
1162   myYGridMajorEnabled = yMajorEnabled;
1163   myYGridMinorEnabled = yMinorEnabled;
1164   myYGridMaxMajor = yMajorMax;
1165   myYGridMaxMinor = yMinorMax;
1166
1167   if (mySecondY) {
1168     myY2GridMajorEnabled = y2MajorEnabled;
1169     myY2GridMinorEnabled = y2MinorEnabled;
1170     myY2GridMaxMajor = y2MajorMax;
1171     myY2GridMaxMinor = y2MinorMax;
1172   }
1173   myPlot->setAxisMaxMajor( QwtPlot::yLeft, myYGridMaxMajor );
1174   myPlot->setAxisMaxMinor( QwtPlot::yLeft, myYGridMaxMinor );
1175
1176   if (mySecondY) {
1177     myPlot->setAxisMaxMajor( QwtPlot::yRight, myY2GridMaxMajor );
1178     myPlot->setAxisMaxMinor( QwtPlot::yRight, myY2GridMaxMinor );
1179   }
1180
1181   myPlot->setGridYAxis(QwtPlot::yLeft);
1182
1183   if (mySecondY) {
1184     if (myYGridMajorEnabled) {
1185       myPlot->enableGridYMin(myYGridMinorEnabled);
1186       myPlot->enableGridY( myYGridMajorEnabled);
1187     }
1188     else if (myY2GridMajorEnabled) {
1189       myPlot->setGridYAxis(QwtPlot::yRight);
1190       myPlot->enableGridYMin(myY2GridMinorEnabled);
1191       myPlot->enableGridY(myY2GridMajorEnabled);
1192     }
1193     else {
1194       myPlot->enableGridYMin(false);
1195       myPlot->enableGridY(false);
1196     }
1197   }
1198   else {
1199     myPlot->enableGridY( myYGridMajorEnabled );
1200     myPlot->enableGridYMin( myYGridMinorEnabled );
1201   }
1202   if ( update )
1203     myPlot->replot();
1204 }
1205
1206 /*!
1207   Sets title for some axis
1208 */
1209 void Plot2d_ViewFrame::setTitle( bool enabled, const QString& title,
1210                                  ObjectType type, bool update )
1211 {
1212   switch (type) {
1213     case MainTitle:
1214       myTitleEnabled = enabled;
1215       myTitle = title;
1216       myPlot->setTitle( myTitleEnabled ? myTitle : QString::null );
1217       break;
1218     case XTitle:
1219       myXTitleEnabled = enabled;
1220       myXTitle = title;
1221       myPlot->setAxisTitle( QwtPlot::xBottom, myXTitleEnabled ? myXTitle : QString::null );
1222       break;
1223     case YTitle:
1224       myYTitleEnabled = enabled;
1225       myYTitle = title;
1226       myPlot->setAxisTitle( QwtPlot::yLeft, myYTitleEnabled ? myYTitle : QString::null );
1227       break;
1228     case Y2Title:
1229       myY2TitleEnabled = enabled;
1230       myY2Title = title;
1231       myPlot->setAxisTitle( QwtPlot::yRight, myY2TitleEnabled ? myY2Title : QString::null );
1232       break;
1233   }
1234   if ( update )
1235     myPlot->replot();
1236 }
1237 /*!
1238   Sets title for some axis
1239 */
1240 QString Plot2d_ViewFrame::getTitle( ObjectType type ) const
1241 {
1242   QString title = "";
1243   switch (type) {
1244     case MainTitle:
1245       title = myTitle;   break;
1246     case XTitle:
1247       title = myXTitle;  break;
1248     case YTitle:
1249       title = myYTitle;  break;
1250     case Y2Title:
1251       title = myY2Title; break;
1252   }
1253   return title;
1254 }
1255 /*!
1256   Sets font for Plot2d object : title or axis
1257 */
1258 void Plot2d_ViewFrame::setFont( const QFont& font, ObjectType type, bool update)
1259 {
1260   switch (type) {
1261     case MainTitle:
1262       myPlot->setTitleFont(font);
1263       break;
1264     case XTitle:
1265       myPlot->setAxisTitleFont(QwtPlot::xBottom, font); break;
1266     case YTitle:
1267       myPlot->setAxisTitleFont(QwtPlot::yLeft, font);   break;
1268     case Y2Title:
1269       myPlot->setAxisTitleFont(QwtPlot::yRight, font);  break;
1270     case XAxis:
1271       myPlot->setAxisFont(QwtPlot::xBottom, font);      break;
1272     case YAxis:
1273       myPlot->setAxisFont(QwtPlot::yLeft, font);        break;
1274     case Y2Axis:
1275       myPlot->setAxisFont(QwtPlot::yRight, font);       break;
1276   }
1277   if ( update )
1278     myPlot->replot();
1279 }
1280 /*!
1281   Sets scale mode for horizontal axis: 0 - linear, 1 - logarithmic
1282 */
1283 void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update )
1284 {
1285   myXMode = mode;
1286   if ( myXMode == 0 ) // linear
1287     myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1288   else                // logarithmic
1289     myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, true );
1290
1291   if ( update )
1292     fitAll();
1293   emit vpModeHorChanged();
1294 }
1295 /*!
1296   Sets scale mode for vertical axis: 0 - linear, 1 - logarithmic
1297 */
1298 void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update )
1299 {
1300   myYMode = mode;
1301   if ( myYMode == 0 ) { // linear
1302     myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1303     if (mySecondY)
1304       myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1305   }
1306   else {               // logarithmic
1307     myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, true );
1308     if (mySecondY)
1309       myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, true );
1310   }
1311   if ( update )
1312     fitAll();
1313   emit vpModeVerChanged();
1314 }
1315
1316 /*!
1317   Return, scale mode for horizontal axis
1318 */
1319 bool Plot2d_ViewFrame::isModeHorLinear()
1320 {
1321   return (myXMode == 0 ? true : false);
1322 }
1323
1324 /*!
1325   Return, scale mode for vertical axis
1326 */
1327 bool Plot2d_ViewFrame::isModeVerLinear()
1328 {
1329   return (myYMode == 0 ? true : false);
1330 }
1331 /*!
1332   Slot, called when user presses mouse button
1333 */
1334 void Plot2d_ViewFrame::plotMousePressed(const QMouseEvent& me )
1335 {
1336   ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1337   if ( myOperation == NoOpId )
1338     myOperation = testOperation( me );
1339   if ( myOperation != NoOpId ) {
1340     myPnt = me.pos();
1341     if ( myOperation == FitAreaId ) {
1342       myPlot->setOutlineStyle( Qwt::Rect );
1343     }
1344     else if ( myOperation == GlPanId ) {
1345       myPlot->setAxisScale( QwtPlot::yLeft,
1346           myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) + myYDistance/2, 
1347           myPlot->invTransform( QwtPlot::yLeft, myPnt.y() ) - myYDistance/2 );
1348       myPlot->setAxisScale( QwtPlot::xBottom, 
1349           myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) - myXDistance/2, 
1350           myPlot->invTransform( QwtPlot::xBottom, myPnt.x() ) + myXDistance/2 );
1351       if (mySecondY)
1352         myPlot->setAxisScale( QwtPlot::yRight,
1353           myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) + myYDistance2/2, 
1354           myPlot->invTransform( QwtPlot::yRight, myPnt.y() ) - myYDistance2/2 );
1355       myPlot->replot();
1356     }
1357   }
1358   else {
1359     int btn = me.button() | me.state();
1360     if (btn == RightButton) {
1361       QMouseEvent* aEvent = new QMouseEvent(QEvent::MouseButtonPress,
1362                                             me.pos(), btn, me.state());
1363       // QMouseEvent 'me' has the 'MouseButtonDblClick' type. In this case we create new event 'aEvent'.
1364       parent()->eventFilter(this, aEvent);
1365     }
1366   }
1367 }
1368 /*!
1369   Slot, called when user moves mouse
1370 */
1371 void Plot2d_ViewFrame::plotMouseMoved( const QMouseEvent& me )
1372 {
1373   int    dx = me.pos().x() - myPnt.x();
1374   int    dy = me.pos().y() - myPnt.y();
1375
1376   if ( myOperation != NoOpId) {
1377     if ( myOperation == ZoomId ) {
1378       QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1379       QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1380
1381       myPlot->setAxisScale( QwtPlot::yLeft, 
1382           myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), 
1383           myPlot->invTransform( QwtPlot::yLeft, yMap.i2() + dy ) );
1384       myPlot->setAxisScale( QwtPlot::xBottom, 
1385           myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ), 
1386           myPlot->invTransform( QwtPlot::xBottom, xMap.i2() - dx ) );
1387       if (mySecondY) {
1388         QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1389         myPlot->setAxisScale( QwtPlot::yRight, 
1390           myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ), 
1391           myPlot->invTransform( QwtPlot::yRight, y2Map.i2() + dy ) );
1392       }
1393       myPlot->replot();
1394       myPnt = me.pos();
1395     }
1396     else if ( myOperation == PanId ) {
1397       QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1398       QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1399
1400       myPlot->setAxisScale( QwtPlot::yLeft, 
1401           myPlot->invTransform( QwtPlot::yLeft, yMap.i1()-dy ), 
1402           myPlot->invTransform( QwtPlot::yLeft, yMap.i2()-dy ) );
1403       myPlot->setAxisScale( QwtPlot::xBottom, 
1404           myPlot->invTransform( QwtPlot::xBottom, xMap.i1()-dx ),
1405           myPlot->invTransform( QwtPlot::xBottom, xMap.i2()-dx ) ); 
1406       if (mySecondY) {
1407         QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1408         myPlot->setAxisScale( QwtPlot::yRight,
1409           myPlot->invTransform( QwtPlot::yRight, y2Map.i1()-dy ), 
1410           myPlot->invTransform( QwtPlot::yRight, y2Map.i2()-dy ) );
1411       }
1412       myPlot->replot();
1413       myPnt = me.pos();
1414     }
1415   }
1416   else {
1417     ((Plot2d_ViewWindow*)parent())->putInfo(getInfo(me.pos()));
1418   }
1419 }
1420 /*!
1421   Slot, called when user releases mouse
1422 */
1423 void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me )
1424 {
1425   if ( myOperation == NoOpId && me.button() == RightButton )
1426   {
1427     QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
1428                               me.pos(), me.globalPos(),
1429                               me.state() );
1430     emit contextMenuRequested( &aEvent );
1431   }
1432   if ( myOperation == FitAreaId ) {
1433     QRect rect( myPnt, me.pos() );
1434     fitArea( rect );
1435   }
1436   myPlot->canvas()->setCursor( QCursor( Qt::CrossCursor ) );
1437   myPlot->setOutlineStyle( Qwt::Triangle );
1438
1439   ((Plot2d_ViewWindow*)parent())->putInfo(tr("INF_READY"));
1440   myOperation = NoOpId;
1441 }
1442 /*!
1443   Slot, called when user wheeling mouse
1444 */
1445 void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event)
1446
1447   double aDelta = event->delta();
1448   double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.; 
1449
1450   QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1451   QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1452
1453   myPlot->setAxisScale( QwtPlot::yLeft,
1454     myPlot->invTransform( QwtPlot::yLeft, yMap.i1() ), 
1455     myPlot->invTransform( QwtPlot::yLeft, yMap.i2() )*aScale );
1456   myPlot->setAxisScale( QwtPlot::xBottom, 
1457     myPlot->invTransform( QwtPlot::xBottom, xMap.i1() ),
1458     myPlot->invTransform( QwtPlot::xBottom, xMap.i2() )*aScale );
1459   if (mySecondY) {
1460     QwtDiMap y2Map = myPlot->canvasMap( QwtPlot::yRight );
1461     myPlot->setAxisScale( QwtPlot::yRight,
1462       myPlot->invTransform( QwtPlot::yRight, y2Map.i1() ), 
1463       myPlot->invTransform( QwtPlot::yRight, y2Map.i2() )*aScale );
1464   }
1465   myPlot->replot();
1466   myPnt = event->pos();
1467 }
1468 /*!
1469   View operations : Pan view
1470 */
1471 void Plot2d_ViewFrame::onViewPan()
1472
1473   myPlot->canvas()->setCursor( panCursor );
1474   myOperation = PanId;
1475   qApp->installEventFilter( this );
1476 }
1477 /*!
1478   View operations : Zoom view
1479 */
1480 void Plot2d_ViewFrame::onViewZoom() 
1481 {
1482   myPlot->canvas()->setCursor( zoomCursor );
1483   myOperation = ZoomId;
1484   qApp->installEventFilter( this );
1485 }
1486 /*!
1487   View operations : Fot All
1488 */
1489 void Plot2d_ViewFrame::onViewFitAll() 
1490
1491   fitAll();
1492 }
1493 /*!
1494   View operations : Fit Area
1495 */
1496 void Plot2d_ViewFrame::onViewFitArea() 
1497 {
1498   myPlot->canvas()->setCursor( QCursor( Qt::PointingHandCursor ) );
1499   myOperation = FitAreaId;
1500   qApp->installEventFilter( this );
1501 }
1502 /*!
1503   View operations : Global panning
1504 */
1505 void Plot2d_ViewFrame::onViewGlobalPan() 
1506 {
1507   myPlot->canvas()->setCursor( glPanCursor );
1508   myPlot->changeAxisOptions( QwtPlot::xBottom, QwtAutoScale::Logarithmic, false );
1509   myPlot->changeAxisOptions( QwtPlot::yLeft, QwtAutoScale::Logarithmic, false );
1510   if (mySecondY)
1511     myPlot->changeAxisOptions( QwtPlot::yRight, QwtAutoScale::Logarithmic, false );
1512   myPlot->replot();
1513   QwtDiMap xMap = myPlot->canvasMap( QwtPlot::xBottom );
1514   QwtDiMap yMap = myPlot->canvasMap( QwtPlot::yLeft );
1515
1516   myXDistance = xMap.d2() - xMap.d1();
1517   myYDistance = yMap.d2() - yMap.d1();
1518
1519   if (mySecondY) {
1520     QwtDiMap yMap2 = myPlot->canvasMap( QwtPlot::yRight );
1521     myYDistance2 = yMap2.d2() - yMap2.d1();
1522   }
1523   fitAll();
1524   myOperation = GlPanId;
1525   qApp->installEventFilter( this );
1526 }
1527
1528 //=================================================================================
1529 // Plot2d_Plot2d implementation
1530 //=================================================================================
1531 /*!
1532   Constructor
1533 */
1534 Plot2d_Plot2d::Plot2d_Plot2d( QWidget* parent )
1535      : QwtPlot( parent )
1536 {
1537   // outline
1538   enableOutline( true );
1539   setOutlineStyle( Qwt::Triangle );
1540   setOutlinePen( green );
1541   // legend
1542   setAutoLegend( false );
1543   setLegendFrameStyle( QFrame::Box | QFrame::Sunken );
1544   enableLegend( false );
1545   // grid
1546   enableGridX( false );
1547   enableGridXMin( false );
1548   enableGridY( false );
1549   enableGridYMin( false );
1550   // auto scaling by default
1551   setAxisAutoScale( QwtPlot::yLeft );
1552   setAxisAutoScale( QwtPlot::yRight );
1553   setAxisAutoScale( QwtPlot::xBottom );
1554 }
1555 /*!
1556   Recalculates and redraws Plot 2d view 
1557 */
1558 void Plot2d_Plot2d::replot()
1559 {
1560   updateLayout();  // to fix bug(?) of Qwt - view is not updated when title is changed
1561   QwtPlot::replot(); 
1562 }
1563
1564 /*!
1565   Checks if two colors are close to each other [ static ]
1566   uses COLOR_DISTANCE variable as max tolerance for comparing of colors
1567 */
1568 const long COLOR_DISTANCE = 100;
1569 const int  MAX_ATTEMPTS   = 10;
1570 static bool closeColors( const QColor& color1, const QColor& color2 )
1571 {
1572   long tol = abs( color2.red()   - color1.red() ) + 
1573              abs( color2.green() - color1.green() ) +
1574        abs( color2.blue()  - color1.blue() );
1575
1576   return ( tol <= COLOR_DISTANCE );
1577 }
1578 /*!
1579   Gets new unique marker for item if possible
1580 */
1581 void Plot2d_Plot2d::getNextMarker( QwtSymbol::Style& typeMarker, QColor& color, Qt::PenStyle& typeLine ) 
1582 {
1583   bool bOk = false;
1584   int cnt = 1;
1585   while ( !bOk ) {
1586     int aRed    = (int)( 256.0 * rand() / RAND_MAX);    // generate random color
1587     int aGreen  = (int)( 256.0 * rand() / RAND_MAX);    // ...
1588     int aBlue   = (int)( 256.0 * rand() / RAND_MAX);    // ...
1589     int aMarker = (int)( 9.0 * rand() / RAND_MAX) + 1;  // 9 markers types ( not including empty )
1590     int aLine   = (int)( 5.0 * rand() / RAND_MAX) + 1;  // 5 line types ( not including empty )
1591
1592     typeMarker = ( QwtSymbol::Style )aMarker;
1593     color      = QColor( aRed, aGreen, aBlue );
1594     typeLine   = ( Qt::PenStyle )aLine;
1595
1596     cnt++;
1597     if ( cnt == MAX_ATTEMPTS )
1598       bOk = true;
1599     else
1600       bOk = !existMarker( typeMarker, color, typeLine );
1601   }
1602 /*
1603   static int aMarker = -1;
1604   static int aColor  = -1;
1605   static int aLine   = -1;
1606
1607   if ( myColors.isEmpty() ) {
1608     // creating colors list
1609     myColors.append( Qt::white );
1610     myColors.append( Qt::blue );
1611     myColors.append( Qt::gray );
1612     myColors.append( Qt::darkGreen );
1613     myColors.append( Qt::magenta );
1614     myColors.append( Qt::darkGray );
1615     myColors.append( Qt::red );
1616     myColors.append( Qt::darkBlue );
1617     myColors.append( Qt::darkYellow );
1618     myColors.append( Qt::cyan );
1619     myColors.append( Qt::darkRed );
1620     myColors.append( Qt::darkCyan );
1621     myColors.append( Qt::yellow );
1622     myColors.append( Qt::darkMagenta );
1623     myColors.append( Qt::green );
1624     myColors.append( Qt::black );
1625   }
1626
1627   int nbMarkers = 11;                   // QwtSymbol supports 11 marker types
1628   int nbLines   = 6;                    // Qt supports 6 line types
1629   int nbColors  = myColors.count();     // number of default colors supported
1630
1631   aMarker = ( aMarker + 1 ) % nbMarkers;  
1632   if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1633   aColor  = ( aColor  + 1 ) % nbColors;
1634   aLine   = ( aLine   + 1 ) % nbLines;    
1635   if ( aLine == Qt::NoPen ) aLine++;             
1636
1637   typeMarker = ( QwtSymbol::Style )aMarker;
1638   color      = myColors[ aColor ];
1639   typeLine   = ( Qt::PenStyle )aLine;
1640   if ( !existMarker( typeMarker, color, typeLine ) )
1641     return;
1642
1643   int i, j, k;
1644   for ( i = 0; i < nbMarkers; i++ ) {
1645     aMarker = ( aMarker + 1 ) % nbMarkers;
1646     if ( aMarker == QwtSymbol::None || aMarker == QwtSymbol::Triangle ) aMarker++;
1647     for ( j = 0; j < nbColors; j++ ) {
1648       aColor  = ( aColor  + 1 ) % nbColors;
1649       for ( k = 0; k < nbLines; k++ ) {
1650         aLine = ( aLine + 1 ) % nbLines;
1651   if ( aLine == Qt::NoPen ) aLine++;             
1652         if ( !existMarker( ( QwtSymbol::Style )aMarker, aColor, ( Qt::PenStyle )aLine ) ) {
1653           typeMarker = ( QwtSymbol::Style )aMarker;
1654           color      = myColors[ aColor ];
1655           typeLine   = ( Qt::PenStyle )aLine;
1656           return;
1657         }
1658       }
1659     }
1660   }
1661 */
1662 }
1663
1664 QSizePolicy Plot2d_Plot2d::sizePolicy() const
1665 {
1666   return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
1667 }
1668
1669 QSize Plot2d_Plot2d::sizeHint() const
1670 {
1671   return QwtPlot::minimumSizeHint();
1672 }
1673
1674 /*!
1675   return minimum size for qwt plot
1676 */
1677 QSize Plot2d_Plot2d::minimumSizeHint() const
1678 {
1679   return QSize( 0, 0 );
1680 //  QSize aSize = QwtPlot::minimumSizeHint();
1681 //  return QSize(aSize.width()*3/4, aSize.height());
1682 }
1683 /*!
1684   Checks if marker belongs to any enitity
1685 */
1686 bool Plot2d_Plot2d::existMarker( const QwtSymbol::Style typeMarker, const QColor& color, const Qt::PenStyle typeLine ) 
1687 {
1688   // getting all curves
1689   QArray<long> keys = curveKeys();
1690   //QColor aRgbColor;
1691
1692   if ( closeColors( color, backgroundColor() ) )
1693       return true;
1694   for ( int i = 0; i < (int)keys.count(); i++ )
1695   {
1696     QwtPlotCurve* crv = curve( keys[i] );
1697     if ( crv ) {
1698       QwtSymbol::Style aStyle = crv->symbol().style();
1699       QColor           aColor = crv->pen().color();
1700       Qt::PenStyle     aLine  = crv->pen().style();
1701 //      if ( aStyle == typeMarker && aColor == color && aLine == typeLine )
1702       if ( aStyle == typeMarker && closeColors( aColor,color ) && aLine == typeLine )
1703   return true;
1704     }
1705   }
1706   return false;
1707 }
1708
1709 // TEMPORARY SOLUTION!!!  TO BE IMPLEMENTED!!!
1710 Plot2d_Prs* Plot2d_ViewFrame::CreatePrs( const char* /*entry*/ )
1711 {
1712   return 0;
1713 }
1714
1715 void Plot2d_ViewFrame::copyPreferences( Plot2d_ViewFrame* vf )
1716 {
1717   if( !vf )
1718     return;
1719
1720   myCurveType = vf->myCurveType;
1721   myShowLegend = vf->myShowLegend;
1722   myLegendPos = vf->myLegendPos;
1723   myMarkerSize = vf->myMarkerSize;
1724   myBackground = vf->myBackground;
1725   myTitle = vf->myTitle; 
1726   myXTitle = vf->myXTitle;
1727   myYTitle = vf->myYTitle;
1728   myY2Title = vf->myY2Title;
1729   myTitleEnabled = vf->myTitleEnabled;
1730   myXTitleEnabled = vf->myXTitleEnabled;
1731   myYTitleEnabled = vf->myYTitleEnabled;
1732   myY2TitleEnabled = vf->myY2TitleEnabled;
1733   myXGridMajorEnabled = vf->myXGridMajorEnabled;
1734   myYGridMajorEnabled = vf->myYGridMajorEnabled;
1735   myY2GridMajorEnabled = vf->myY2GridMajorEnabled;
1736   myXGridMinorEnabled = vf->myXGridMinorEnabled;
1737   myYGridMinorEnabled = vf->myYGridMinorEnabled;
1738   myY2GridMinorEnabled = vf->myY2GridMinorEnabled;
1739   myXGridMaxMajor = vf->myXGridMaxMajor;
1740   myYGridMaxMajor = vf->myYGridMaxMajor;
1741   myY2GridMaxMajor = vf->myY2GridMaxMajor;
1742   myXGridMaxMinor = vf->myXGridMaxMinor;
1743   myYGridMaxMinor = vf->myYGridMaxMinor;
1744   myY2GridMaxMinor = vf->myY2GridMaxMinor;
1745   myXMode = vf->myXMode;
1746   myYMode = vf->myYMode;
1747   mySecondY = vf->mySecondY;
1748 }