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