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