]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_SetupPlot2dDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_SetupPlot2dDlg.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : VisuGUI_SetupPlot2dDlg.cxx
21 //  Author : Vadim SANDLER
22 //  Module : SALOME
23 //  $Header$
24
25 #include "VisuGUI_SetupPlot2dDlg.h"
26 #include "VisuGUI.h"
27 #include "SPlot2d_Curve.h"
28
29 #include "SUIT_Tools.h"
30 #include "SUIT_MessageBox.h"
31 #include "SUIT_ResourceMgr.h"
32 #include "SUIT_Session.h"
33
34 #include "LightApp_Application.h"
35
36 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
37 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
38
39 #include <qlabel.h>
40 #include <qpushbutton.h>
41 #include <qcheckbox.h>
42 #include <qtoolbutton.h>
43 #include <qcombobox.h>
44 #include <qscrollview.h>
45 #include <qlayout.h>
46 #include <qcolordialog.h>
47 #include <qspinbox.h>
48
49 #include <vector>
50 #include <string>
51
52 #include "utilities.h"
53
54 using namespace std;
55
56 #define DLG_SIZE_WIDTH    500
57 #define DLG_SIZE_HEIGHT   400
58 #define MAX_LINE_WIDTH    100
59 #define MARGIN_SIZE       11
60 #define SPACING_SIZE      6
61
62 /*!
63   Constructor
64 */
65 VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg( _PTR(SObject) object, QWidget* parent )
66     : QDialog( parent,
67                "VisuGUI_SetupPlot2dDlg",
68                true,
69                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
70 {
71   setCaption( tr("TLT_SETUP_PLOT2D") );
72   setSizeGripEnabled( TRUE );
73   QGridLayout* topLayout = new QGridLayout( this );
74   topLayout->setSpacing( SPACING_SIZE );
75   topLayout->setMargin( MARGIN_SIZE );
76
77   myItems.setAutoDelete( false );
78
79   myObject = object;
80
81   /* Top scroll view */
82   myView = new QScrollView( this );
83   QFrame* frame  = new QFrame( myView );
84   frame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
85   QGridLayout* frameLayout = new QGridLayout( frame, 1, 12 );
86   frameLayout->setMargin( MARGIN_SIZE ); frameLayout->setSpacing( SPACING_SIZE );
87
88   QFrame* lin;
89
90   QLabel* labAxis = new QLabel( tr( "AXIS_LBL" ),       frame );
91   QLabel* labAssigned = new QLabel( tr( "ASSIGNED" ),   frame );
92   QLabel* labData = new QLabel( tr( "DATA_LBL" ),       frame );
93   QLabel* labUnit = new QLabel( tr( "UNITS_LBL" ),      frame );
94   QLabel* labAttr = new QLabel( tr( "ATTRIBUTES_LBL" ), frame );
95   labAxis->setAlignment( AlignCenter );
96   labAssigned->setAlignment( AlignCenter );
97   labData->setAlignment( AlignCenter );
98   labUnit->setAlignment( AlignCenter );
99   labAttr->setAlignment( AlignCenter );
100   QFont font = labAxis->font(); font.setBold( true );
101   labAxis->setFont( font );
102   labAssigned->setFont( font );
103   labData->setFont( font );
104   labUnit->setFont( font );
105   labAttr->setFont( font );
106
107   frameLayout->addMultiCellWidget( labAxis, 0,  0, 0, 1 );
108       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
109       frameLayout->addWidget( lin,          0,     2 );
110
111   frameLayout->addWidget( labAssigned,      0,     3 );
112       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
113       frameLayout->addWidget( lin,          0,     4 );
114
115   frameLayout->addWidget( labData,          0,     5 );
116       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
117       frameLayout->addWidget( lin,          0,     6 );
118   frameLayout->addWidget( labUnit,          0,     7 );
119       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
120       frameLayout->addWidget( lin,          0,     8 );
121   frameLayout->addMultiCellWidget( labAttr, 0,  0, 9, 13 );
122   frameLayout->setColStretch(               14, 5 );
123   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::HLine | QFrame::Sunken );
124   frameLayout->addMultiCellWidget( lin, 1, 1, 0, 14 );
125
126   int row = 2;
127   _PTR(GenericAttribute)        anAttr;
128   _PTR(AttributeTableOfInteger) tblIntAttr;
129   _PTR(AttributeTableOfReal)    tblRealAttr;
130
131   /* Try table of integer */
132   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
133     tblIntAttr = anAttr;
134     if ( tblIntAttr ) {
135       try {
136         int nbRows = tblIntAttr->GetNbRows() ;
137         vector<string> rowTitles = tblIntAttr->GetRowTitles();
138         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
139         QStringList rows;
140         for ( int i = 0; i < nbRows; i++ )
141           rows.append( rowTitles[i] );
142
143         for ( int i = 0; i < nbRows; i++ ) {
144           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
145           item->createWidgets( frame, rows );
146           frameLayout->addWidget( item->myHBtn,        row, 0 );
147           frameLayout->addWidget( item->myVBtn,        row, 1 );
148           frameLayout->addWidget( item->myAssigned,    row, 3 );
149
150           frameLayout->addWidget( item->myTitleLab,    row, 5 );
151           if ( rowTitles.size() > 0 )
152             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
153           frameLayout->addWidget( item->myUnitLab,     row, 7 );
154           if ( rowUnits.size() > 0 )
155             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
156           frameLayout->addWidget( item->myAutoCheck,   row, 9 );
157           frameLayout->addWidget( item->myLineCombo,   row, 10 );
158           frameLayout->addWidget( item->myLineSpin,    row, 11 );
159           frameLayout->addWidget( item->myMarkerCombo, row, 12 );
160           frameLayout->addWidget( item->myColorBtn,    row, 13 );
161           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
162           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
163           myItems.append( item );
164           row++;
165         }
166       }
167       catch( ... ) {
168         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (int)!!!");
169       }
170     }
171   }
172   /* Try table of real */
173   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
174     tblRealAttr = anAttr;
175     if ( tblRealAttr ) {
176       try {
177         int nbRows = tblRealAttr->GetNbRows();
178         vector<string> rowTitles = tblRealAttr->GetRowTitles();
179         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
180         QStringList rows;
181         for ( int i = 0; i < nbRows; i++ )
182           rows.append( rowTitles[i] );
183
184         for ( int i = 0; i < nbRows; i++ ) {
185           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
186           item->createWidgets( frame, rows );
187           frameLayout->addWidget( item->myHBtn,        row, 0 );
188           frameLayout->addWidget( item->myVBtn,        row, 1 );
189           frameLayout->addWidget( item->myAssigned,    row, 3 );
190
191           frameLayout->addWidget( item->myTitleLab,    row, 5 );
192           if ( rowTitles.size() > 0 )
193             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
194           frameLayout->addWidget( item->myUnitLab,     row, 7 );
195           if ( rowUnits.size() > 0 )
196             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
197           frameLayout->addWidget( item->myAutoCheck,   row, 9 );
198           frameLayout->addWidget( item->myLineCombo,   row, 10 );
199           frameLayout->addWidget( item->myLineSpin,    row, 11 );
200           frameLayout->addWidget( item->myMarkerCombo, row, 12 );
201           frameLayout->addWidget( item->myColorBtn,    row, 13 );
202           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
203           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
204           myItems.append( item );
205           row++;
206         }
207       }
208       catch( ... ) {
209         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (real)!!!");
210       }
211     }
212   }
213   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
214   frameLayout->addMultiCellWidget( lin, 2, row+1, 2, 2 );
215   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
216   frameLayout->addMultiCellWidget( lin, 2, row+1, 4, 4 );
217   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
218   frameLayout->addMultiCellWidget( lin, 2, row+1, 6, 6 );
219   frameLayout->setRowStretch( row+1, 5 );
220
221   myView->addChild( frame, 0, 0 );
222   myView->setResizePolicy( QScrollView::AutoOneFit );
223
224   myView->setMinimumWidth( frame->sizeHint().width() + MARGIN_SIZE * 2 );
225
226   /* OK/Cancel/Help buttons */
227   myOkBtn = new QPushButton( tr( "BUT_OK" ), this, "buttonOk" );
228   myOkBtn->setAutoDefault( TRUE );
229   myOkBtn->setDefault( TRUE );
230   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this, "buttonCancel" );
231   myCancelBtn->setAutoDefault( TRUE );
232   myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this, "buttonHelp" );
233   myHelpBtn->setAutoDefault( TRUE );
234
235   topLayout->addMultiCellWidget( myView, 0, 0, 0, 3 );
236   topLayout->addWidget( myOkBtn, 1, 0 );
237   topLayout->setColStretch( 1, 5 );
238   topLayout->addWidget( myCancelBtn, 1, 2 );
239   topLayout->addWidget( myHelpBtn, 1, 3 );
240
241   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
242   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
243   connect( myHelpBtn,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
244
245   enableControls();
246
247   /* Center widget inside it's parent widget */
248   resize( DLG_SIZE_WIDTH, DLG_SIZE_HEIGHT  );
249   SUIT_Tools::centerWidget( this, parentWidget() );
250 }
251 /*!
252   Destructor
253 */
254 VisuGUI_SetupPlot2dDlg::~VisuGUI_SetupPlot2dDlg()
255 {
256 }
257 /*!
258   Gets curves info ( indexes of row data in the table for horizontal and verical axes )
259 */
260 void VisuGUI_SetupPlot2dDlg::getCurvesSource( int& horIndex, QValueList<int>& verIndexes,
261                                               QValueList<int>& zIndices )
262 {
263   /* collecting horizontal and vertical axis items */
264   horIndex = -1;
265   int i;
266   for ( i = 0; i < myItems.count(); i++ ) {
267     if ( myItems.at( i )->isHorizontalOn() ) {
268       horIndex = i;
269     }
270     else if ( myItems.at( i )->isVerticalOn() ) {
271       verIndexes.append( i );
272       zIndices.append( myItems.at( i )->assigned() );
273     }
274
275   }
276 }
277 /*!
278   Gets curve attributes
279 */
280 bool VisuGUI_SetupPlot2dDlg::getCurveAttributes (const int vIndex,
281                                                  bool&     isAuto,
282                                                  int&      marker,
283                                                  int&      line,
284                                                  int&      lineWidth,
285                                                  QColor&   color)
286 {
287   if ( vIndex >= 0 && vIndex < myItems.count() ) {
288     isAuto    = myItems.at( vIndex )->isAutoAssign();
289     marker    = myItems.at( vIndex )->getMarker();
290     line      = myItems.at( vIndex )->getLine();
291     lineWidth = myItems.at( vIndex )->getLineWidth();
292     color     = myItems.at( vIndex )->getColor();
293     return true;
294   }
295   return false;
296 }
297 /*!
298   Creates and returns curves presentations
299 */
300 void VisuGUI_SetupPlot2dDlg::getCurves( QPtrList<Plot2d_Curve>& container )
301 {
302   _PTR(GenericAttribute)        anAttr;
303   _PTR(AttributeTableOfInteger) tblIntAttr;
304   _PTR(AttributeTableOfReal)    tblRealAttr;
305
306   /* clearing container contents */
307   container.clear();
308
309   /* collecting horizontal and vertical axis items */
310   int horIndex;
311   int i, j;
312   QValueList<int> verIndex, zIndices;
313   getCurvesSource( horIndex, verIndex, zIndices );
314   if ( horIndex < 0 || verIndex.isEmpty() ) /* no curves can be created */
315     return;
316
317   /* Try table of integer */
318   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
319     tblIntAttr = anAttr;
320     if ( tblIntAttr ) {
321       try {
322         int nbCols = tblIntAttr->GetNbColumns();
323         vector<string> rowTitles = tblIntAttr->GetRowTitles();
324         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
325
326         for ( i = 0; i < verIndex.count(); i++ ) {
327           SPlot2d_Curve* curve = new SPlot2d_Curve();
328           // curve titles
329           if ( rowTitles.size() > 0 ) {
330             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
331             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
332           }
333           // curve units
334           if ( rowUnits.size() > 0 ) {
335             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
336             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
337           }
338           // curve data
339           int nbPoints = 0;
340           for ( j = 1; j <= nbCols; j++ ) {
341             if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) )
342               nbPoints++;
343           }
344           if ( nbPoints > 0 ) {
345             double* xList = new double[ nbPoints ];
346             double* yList = new double[ nbPoints ];
347             QStringList zList;
348             for ( j = 1; j <= nbCols; j++ ) {
349               if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) ) {
350                 xList[j-1] = tblIntAttr->GetValue( horIndex   +1, j );
351                 yList[j-1] = tblIntAttr->GetValue( verIndex[i]+1, j );
352                 zList.append( QString( "%1" ).arg( tblIntAttr->GetValue( zIndices[i]+1, j ) ) );
353               }
354             }
355             curve->setData( xList, yList, nbPoints, zList );
356           }
357           // curve attributes
358           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
359           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
360           curve->setColor( myItems.at( verIndex[i] )->getColor() );
361           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
362           // add curve into container
363           container.append( curve );
364         }
365       }
366       catch( ... ) {
367         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (int)!!!");
368       }
369     }
370   }
371   /* Try table of real */
372   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
373     tblRealAttr = anAttr;
374     if ( tblRealAttr ) {
375       try {
376         int nbCols = tblRealAttr->GetNbColumns();
377         vector<string> rowTitles = tblRealAttr->GetRowTitles();
378         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
379
380         for ( i = 0; i < verIndex.count(); i++ ) {
381           SPlot2d_Curve* curve = new SPlot2d_Curve();
382           // curve titles
383           if ( rowTitles.size() > 0 ) {
384             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
385             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
386           }
387           // curve units
388           if ( rowUnits.size() > 0 ) {
389             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
390             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
391           }
392           // curve data
393           int nbPoints = 0;
394           for ( j = 1; j <= nbCols; j++ ) {
395             if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) )
396               nbPoints++;
397           }
398           if ( nbPoints > 0 ) {
399             double* xList = new double[ nbPoints ];
400             double* yList = new double[ nbPoints ];
401             QStringList zList;
402             for ( j = 1; j <= nbCols; j++ ) {
403               if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) ) {
404                 xList[j-1] = tblRealAttr->GetValue( horIndex   +1, j );
405                 yList[j-1] = tblRealAttr->GetValue( verIndex[i]+1, j );
406                 zList.append( QString( "%1" ).arg( tblIntAttr->GetValue( zIndices[i]+1, j ) ) );
407               }
408             }
409             curve->setData( xList, yList, nbPoints, zList );
410           }
411           // curve attributes
412           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
413           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
414           curve->setColor( myItems.at( verIndex[i] )->getColor() );
415           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
416           // add curve into container
417           container.append( curve );
418         }
419       }
420       catch( ... ) {
421         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (real)!!!");
422       }
423     }
424   }
425 }
426 /*!
427   Slot, called when any <H> button is clicked
428 */
429 void VisuGUI_SetupPlot2dDlg::onHBtnToggled( bool on )
430 {
431   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
432   if ( on ) {
433     for ( int i = 0; i < myItems.count(); i++ ) {
434       if ( myItems.at( i ) != item )
435         myItems.at( i )->setHorizontalOn( false );
436     }
437   }
438   enableControls();
439 }
440 /*!
441   Slot, called when any <V> button is clicked
442 */
443 void VisuGUI_SetupPlot2dDlg::onVBtnToggled( bool on )
444 {
445   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
446   QPtrList<VisuGUI_ItemContainer> itemList;
447   itemList.setAutoDelete( false );
448   item->myAssigned->setEnabled( on );
449   int i;
450   if ( on ) {
451     int totalOn = 0;
452     for ( i = 0; i < myItems.count(); i++ ) {
453       if ( myItems.at( i ) != item && !myItems.at( i )->isHorizontalOn() ) {
454         if ( myItems.at( i )->myUnitLab->text() == item->myUnitLab->text() ) {
455           if ( myItems.at( i )->isVerticalOn() )
456             totalOn++;
457           else
458             itemList.append( myItems.at( i ) );
459         }
460         else {
461           myItems.at( i )->setVerticalOn( false );
462         }
463       }
464     }
465     if ( totalOn == 0 && !itemList.isEmpty() &&
466          SUIT_MessageBox::info2( this,
467                                 this->caption(),
468                                 tr( "QUE_WANT_SAME_UNITS" ),
469                                 tr( "BUT_YES" ),
470                                 tr( "BUT_NO" ),
471                                 0, 1, 1 ) == 0 ) {
472       for ( i = 0; i < itemList.count(); i++ ) {
473         itemList.at( i )->blockSignals( true );
474         itemList.at( i )->setVerticalOn( true );
475         itemList.at( i )->blockSignals( false );
476       }
477     }
478   }
479   enableControls();
480 }
481 /*!
482   Slot, called when <Help> button is clicked
483 */
484 void VisuGUI_SetupPlot2dDlg::onHelp()
485 {
486   QString aHelpFileName = "plot2d_viewer_page.html";
487   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
488   if (app) {
489     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
490     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
491   }
492   else {
493     QString platform;
494 #ifdef WIN32
495     platform = "winapplication";
496 #else
497     platform = "application";
498 #endif
499     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
500                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
501                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
502                            QObject::tr("BUT_OK"));
503   }
504 }
505 /*!
506   Enables/disables buttons
507 */
508 void VisuGUI_SetupPlot2dDlg::enableControls()
509 {
510   bool bHSet = false;
511   bool bVSet = false;
512   for ( int i = 0; i < myItems.count(); i++ ) {
513     if ( myItems.at( i )->isHorizontalOn() ) {
514       bHSet = true;
515       break;
516     }
517   }
518 #ifndef WNT
519   for ( int i = 0; i < myItems.count(); i++ ) {
520 #else
521   for ( i = 0; i < myItems.count(); i++ ) {
522 #endif
523     if ( myItems.at( i )->isVerticalOn() )
524       bVSet = true;
525     myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
526   }
527   myOkBtn->setEnabled( bHSet && bVSet );
528 }
529
530 /*!
531   Provides help on F1 button click
532 */
533 void VisuGUI_SetupPlot2dDlg::keyPressEvent( QKeyEvent* e )
534 {
535   QDialog::keyPressEvent( e );
536   if ( e->isAccepted() )
537     return;
538
539   if ( e->key() == Key_F1 )
540     {
541       e->accept();
542       onHelp();
543     }
544 }
545
546 // ====================================================================================
547 /*!
548   Constructor
549 */
550 VisuGUI_ItemContainer::VisuGUI_ItemContainer( QObject* parent, const char* name )
551      : QObject( parent, name ),
552        myEnabled( true )
553 {
554 }
555 /*!
556   Creates widgets
557 */
558 void VisuGUI_ItemContainer::createWidgets( QWidget* parentWidget, const QStringList& lst )
559 {
560   myHBtn = new QToolButton( parentWidget );
561   myHBtn->setText( tr( "H" ) );
562   myHBtn->setToggleButton( true );
563   myHBtn->setOn( false );
564
565   myVBtn = new QToolButton( parentWidget );
566   myVBtn->setText( tr( "V" ) );
567   myVBtn->setToggleButton( true );
568   myVBtn->setOn( false );
569
570   myTitleLab = new QLabel( parentWidget );
571   myUnitLab  = new QLabel( parentWidget );
572   myUnitLab->setAlignment( AlignCenter);
573
574   myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
575   myAutoCheck->setChecked( true );
576
577   myLineCombo = new QComboBox( false, parentWidget );
578   myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
579   myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
580   myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
581   myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
582   myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
583   myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
584   myLineCombo->setCurrentItem( 1 ); // SOLID by default
585
586   myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, parentWidget );
587   myLineSpin->setValue( 0 );        // width = 0 by default
588
589   myMarkerCombo = new QComboBox( false, parentWidget );
590   myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
591   myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
592   myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
593   myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
594   myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
595   myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
596   myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
597   myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
598   myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
599   myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
600   myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
601
602   myColorBtn = new QToolButton( parentWidget );
603   myColorBtn->setMinimumWidth( 20 );
604
605   myAssigned = new QComboBox( false, parentWidget );
606   myAssigned->insertItem( "" );
607   QStringList::const_iterator anIt = lst.begin(), aLast = lst.end();
608   for( ; anIt!=aLast; anIt++ )
609     myAssigned->insertItem( *anIt );
610   myAssigned->setEnabled( false );
611
612   connect( myAutoCheck, SIGNAL( clicked() ),       this, SLOT( onAutoChanged() ) );
613   connect( myColorBtn,  SIGNAL( clicked() ),       this, SLOT( onColorChanged() ) );
614   connect( myHBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
615   connect( myVBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
616   setColor( QColor( 0, 0, 0 ) );
617   updateState();
618 }
619 /*!
620   Enables attributes widgets
621 */
622 void VisuGUI_ItemContainer::enableWidgets( bool enable )
623 {
624   myEnabled = enable;
625   updateState();
626 }
627 /*!
628   Sets horizontal button's state on
629 */
630 void VisuGUI_ItemContainer::setHorizontalOn( bool on )
631 {
632   myHBtn->setOn( on );
633 }
634 /*!
635   Gets horizontal button's state
636 */
637 bool VisuGUI_ItemContainer::isHorizontalOn() const
638 {
639   return myHBtn->isOn();
640 }
641 /*!
642   Sets vertical button's state on
643 */
644 void VisuGUI_ItemContainer::setVerticalOn( bool on )
645 {
646   myVBtn->setOn( on );
647 }
648 /*!
649   Gets vertical button's state
650 */
651 bool VisuGUI_ItemContainer::isVerticalOn() const
652 {
653   return myVBtn->isOn();
654 }
655 /*!
656   Sets item AutoAssign flag state
657 */
658 void VisuGUI_ItemContainer::setAutoAssign( bool on )
659 {
660   myAutoCheck->setChecked( on );
661   updateState();
662 }
663 /*!
664   Gets item AutoAssign flag state
665 */
666 bool VisuGUI_ItemContainer::isAutoAssign() const
667 {
668   return myAutoCheck->isChecked();
669 }
670 /*!
671   Sets item line type and width
672 */
673 void VisuGUI_ItemContainer::setLine( const int line, const int width )
674 {
675   myLineCombo->setCurrentItem( line );
676 }
677 /*!
678   Gets item line type
679 */
680 int VisuGUI_ItemContainer::getLine() const
681 {
682   return myLineCombo->currentItem();
683 }
684 /*!
685   Gets item line width
686 */
687 int VisuGUI_ItemContainer::getLineWidth() const
688 {
689   return myLineSpin->value();
690 }
691 /*!
692   Sets item marker type
693 */
694 void VisuGUI_ItemContainer::setMarker( const int marker )
695 {
696   myMarkerCombo->setCurrentItem( marker );
697 }
698 /*!
699   Gets item marker type
700 */
701 int VisuGUI_ItemContainer::getMarker() const
702 {
703   return myMarkerCombo->currentItem();
704 }
705 /*!
706   Sets item color
707 */
708 void VisuGUI_ItemContainer::setColor( const QColor& color )
709 {
710   QPalette pal = myColorBtn->palette();
711   QColorGroup ca = pal.active();
712   ca.setColor( QColorGroup::Button, color );
713   QColorGroup ci = pal.inactive();
714   ci.setColor( QColorGroup::Button, color );
715   pal.setActive( ca );
716   pal.setInactive( ci );
717   myColorBtn->setPalette( pal );
718 }
719 /*!
720   Gets item color
721 */
722 QColor VisuGUI_ItemContainer::getColor() const
723 {
724   return myColorBtn->palette().active().button();
725 }
726 /*!
727   Enables/disables widgets
728 */
729 void VisuGUI_ItemContainer::updateState()
730 {
731   myAutoCheck->setEnabled( myEnabled );
732   myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() );
733   myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() );
734   myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() );
735   myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() );
736 }
737 /*!
738   Slot, called when user clickes <Auto assign> check box
739 */
740 void VisuGUI_ItemContainer::onAutoChanged()
741 {
742   updateState();
743   emit( autoClicked() );
744 }
745 /*!
746   <Color> button slot, invokes color selection dialog box
747 */
748 void VisuGUI_ItemContainer::onColorChanged()
749 {
750   QColor color = QColorDialog::getColor( getColor() );
751   if ( color.isValid() ) {
752     setColor( color );
753   }
754 }
755 /*!
756   <H> and <V> buttons slot
757 */
758 void VisuGUI_ItemContainer::onHVToggled( bool on )
759 {
760   const QObject* snd = sender();
761   if ( snd == myHBtn ) {
762     if ( on ) {
763       if ( myVBtn->isOn() ) {
764 //      blockSignals( true );
765         myVBtn->setOn( false );
766 //      blockSignals( false );
767       }
768     }
769     emit horToggled( on );
770   }
771   else {
772     if ( on ) {
773       if ( myHBtn->isOn() ) {
774 //      blockSignals( true );
775         myHBtn->setOn( false );
776 //      blockSignals( false );
777       }
778     }
779     emit verToggled( on );
780   }
781 }
782
783 /*!
784   \return index of assigned row (0, if there is no assigned row)
785 */
786 int VisuGUI_ItemContainer::assigned() const
787 {
788   if ( isVerticalOn() )
789     return myAssigned->currentItem()-1;
790   else
791     return -1;
792 }