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