1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : Plot2d_SetupPlot2dDlg.cxx
6 // Author : Vadim SANDLER
10 #include "SPlot2d_SetupPlot2dDlg.h"
11 #include "SPlot2d_Curve.h"
13 #include "SUIT_Tools.h"
14 #include "SUIT_MessageBox.h"
16 #include <SALOMEDSClient_AttributeTableOfInteger.hxx>
17 #include <SALOMEDSClient_AttributeTableOfReal.hxx>
20 #include <qpushbutton.h>
21 #include <qcheckbox.h>
22 #include <qtoolbutton.h>
23 #include <qcombobox.h>
24 #include <qscrollview.h>
26 #include <qcolordialog.h>
32 #include "utilities.h"
36 #define DLG_SIZE_WIDTH 500
37 #define DLG_SIZE_HEIGHT 400
38 #define MAX_LINE_WIDTH 100
39 #define MARGIN_SIZE 11
40 #define SPACING_SIZE 6
45 SPlot2d_SetupPlot2dDlg::SPlot2d_SetupPlot2dDlg( _PTR(SObject) object, QWidget* parent )
47 "SPlot2d_SetupPlot2dDlg",
49 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
51 setCaption( tr("TLT_SETUP_PLOT2D") );
52 setSizeGripEnabled( TRUE );
53 QGridLayout* topLayout = new QGridLayout( this );
54 topLayout->setSpacing( SPACING_SIZE );
55 topLayout->setMargin( MARGIN_SIZE );
57 myItems.setAutoDelete( false );
62 myView = new QScrollView( this );
63 QFrame* frame = new QFrame( myView );
64 frame->setFrameStyle( QFrame::Plain | QFrame::NoFrame );
65 QGridLayout* frameLayout = new QGridLayout( frame, 1, 12 );
66 frameLayout->setMargin( MARGIN_SIZE ); frameLayout->setSpacing( SPACING_SIZE );
70 QLabel* labAxis = new QLabel( tr( "AXIS_LBL" ), frame );
71 QLabel* labData = new QLabel( tr( "DATA_LBL" ), frame );
72 QLabel* labUnit = new QLabel( tr( "UNITS_LBL" ), frame );
73 QLabel* labAttr = new QLabel( tr( "ATTRIBUTES_LBL" ), frame );
74 labAxis->setAlignment( AlignCenter );
75 labData->setAlignment( AlignCenter );
76 labUnit->setAlignment( AlignCenter );
77 labAttr->setAlignment( AlignCenter );
78 QFont font = labAxis->font(); font.setBold( true );
79 labAxis->setFont( font );
80 labData->setFont( font );
81 labUnit->setFont( font );
82 labAttr->setFont( font );
84 frameLayout->addMultiCellWidget( labAxis, 0, 0, 0, 1 );
85 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
86 frameLayout->addWidget( lin, 0, 2 );
87 frameLayout->addWidget( labData, 0, 3 );
88 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
89 frameLayout->addWidget( lin, 0, 4 );
90 frameLayout->addWidget( labUnit, 0, 5 );
91 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
92 frameLayout->addWidget( lin, 0, 6 );
93 frameLayout->addMultiCellWidget( labAttr, 0, 0, 7, 11 );
94 frameLayout->setColStretch( 12, 5 );
95 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::HLine | QFrame::Sunken );
96 frameLayout->addMultiCellWidget( lin, 1, 1, 0, 12 );
99 _PTR(GenericAttribute) anAttr;
100 _PTR(AttributeTableOfInteger) tblIntAttr;
101 _PTR(AttributeTableOfReal) tblRealAttr;
103 /* Try table of integer */
104 if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
108 int nbRows = tblIntAttr->GetNbRows() ;
109 vector<string> rowTitles = tblIntAttr->GetRowTitles();
110 vector<string> rowUnits = tblIntAttr->GetRowUnits();
111 for ( int i = 0; i < nbRows; i++ ) {
112 SPlot2d_ItemContainer* item = new SPlot2d_ItemContainer( this );
113 item->createWidgets( frame );
114 frameLayout->addWidget( item->myHBtn, row, 0 );
115 frameLayout->addWidget( item->myVBtn, row, 1 );
116 frameLayout->addWidget( item->myTitleLab, row, 3 );
117 if ( rowTitles.size() > 0 )
118 item->myTitleLab->setText( QString( rowTitles[ i ] ) );
119 frameLayout->addWidget( item->myUnitLab, row, 5 );
120 if ( rowUnits.size() > 0 )
121 item->myUnitLab->setText( QString( rowUnits[ i ] ) );
122 frameLayout->addWidget( item->myAutoCheck, row, 7 );
123 frameLayout->addWidget( item->myLineCombo, row, 8 );
124 frameLayout->addWidget( item->myLineSpin, row, 9 );
125 frameLayout->addWidget( item->myMarkerCombo, row, 10 );
126 frameLayout->addWidget( item->myColorBtn, row, 11 );
127 connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
128 connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
129 myItems.append( item );
134 MESSAGE("SPlot2d_SetupPlot2dDlg::SPlot2d_SetupPlot2dDlg : Exception has been caught (int)!!!");
138 /* Try table of real */
139 else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
140 tblRealAttr = anAttr;
143 int nbRows = tblRealAttr->GetNbRows() ;
144 vector<string> rowTitles = tblRealAttr->GetRowTitles();
145 vector<string> rowUnits = tblRealAttr->GetRowUnits();
146 for ( int i = 0; i < nbRows; i++ ) {
147 SPlot2d_ItemContainer* item = new SPlot2d_ItemContainer( this );
148 item->createWidgets( frame );
149 frameLayout->addWidget( item->myHBtn, row, 0 );
150 frameLayout->addWidget( item->myVBtn, row, 1 );
151 frameLayout->addWidget( item->myTitleLab, row, 3 );
152 if ( rowTitles.size() > 0 )
153 item->myTitleLab->setText( QString( rowTitles[ i ] ) );
154 frameLayout->addWidget( item->myUnitLab, row, 5 );
155 if ( rowUnits.size() > 0 )
156 item->myUnitLab->setText( QString( rowUnits[ i ] ) );
157 frameLayout->addWidget( item->myAutoCheck, row, 7 );
158 frameLayout->addWidget( item->myLineCombo, row, 8 );
159 frameLayout->addWidget( item->myLineSpin, row, 9 );
160 frameLayout->addWidget( item->myMarkerCombo, row, 10 );
161 frameLayout->addWidget( item->myColorBtn, row, 11 );
162 connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
163 connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
164 myItems.append( item );
169 MESSAGE("SPlot2d_SetupPlot2dDlg::SPlot2d_SetupPlot2dDlg : Exception has been caught (real)!!!");
173 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
174 frameLayout->addMultiCellWidget( lin, 2, row+1, 2, 2 );
175 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
176 frameLayout->addMultiCellWidget( lin, 2, row+1, 4, 4 );
177 lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
178 frameLayout->addMultiCellWidget( lin, 2, row+1, 6, 6 );
179 frameLayout->setRowStretch( row+1, 5 );
181 myView->addChild( frame, 0, 0 );
182 myView->setResizePolicy( QScrollView::AutoOneFit );
184 myView->setMinimumWidth( frame->sizeHint().width() + MARGIN_SIZE * 2 );
186 /* OK/Cancel buttons */
187 myOkBtn = new QPushButton( tr( "BUT_OK" ), this, "buttonOk" );
188 myOkBtn->setAutoDefault( TRUE );
189 myOkBtn->setDefault( TRUE );
190 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this, "buttonCancel" );
191 myCancelBtn->setAutoDefault( TRUE );
193 topLayout->addMultiCellWidget( myView, 0, 0, 0, 2 );
194 topLayout->addWidget( myOkBtn, 1, 0 );
195 topLayout->setColStretch( 1, 5 );
196 topLayout->addWidget( myCancelBtn, 1, 2 );
198 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
199 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
203 /* Center widget inside it's parent widget */
204 resize( DLG_SIZE_WIDTH, DLG_SIZE_HEIGHT );
205 SUIT_Tools::centerWidget( this, parentWidget() );
210 SPlot2d_SetupPlot2dDlg::~SPlot2d_SetupPlot2dDlg()
214 Gets curves info ( indexes of row data in the table for horizontal and verical axes )
216 void SPlot2d_SetupPlot2dDlg::getCurvesSource( int& horIndex, QValueList<int>& verIndexes )
218 /* collecting horizontal and vertical axis items */
221 for ( i = 0; i < myItems.count(); i++ ) {
222 if ( myItems.at( i )->isHorizontalOn() ) {
225 else if ( myItems.at( i )->isVerticalOn() ) {
226 verIndexes.append( i );
231 Gets curve attributes
233 bool SPlot2d_SetupPlot2dDlg::getCurveAttributes( const int vIndex,
240 if ( vIndex >= 0 && vIndex < myItems.count() ) {
241 isAuto = myItems.at( vIndex )->isAutoAssign();
242 marker = myItems.at( vIndex )->getMarker();
243 line = myItems.at( vIndex )->getLine();
244 lineWidth = myItems.at( vIndex )->getLineWidth();
245 color = myItems.at( vIndex )->getColor();
251 Creates and returns curves presentations
253 void SPlot2d_SetupPlot2dDlg::getCurves( QPtrList<Plot2d_Curve>& container )
255 _PTR(GenericAttribute) anAttr;
256 _PTR(AttributeTableOfInteger) tblIntAttr;
257 _PTR(AttributeTableOfReal) tblRealAttr;
259 /* clearing container contents */
262 /* collecting horizontal and vertical axis items */
265 QValueList<int> verIndex;
266 getCurvesSource( horIndex, verIndex );
267 if ( horIndex < 0 || verIndex.isEmpty() ) /* no curves can be created */
270 /* Try table of integer */
271 if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
275 int nbCols = tblIntAttr->GetNbColumns() ;
276 vector<string> rowTitles = tblIntAttr->GetRowTitles();
277 vector<string> rowUnits = tblIntAttr->GetRowUnits();
279 for ( i = 0; i < verIndex.count(); i++ ) {
280 SPlot2d_Curve* curve = new SPlot2d_Curve();
282 if ( rowTitles.size() > 0 ) {
283 curve->setHorTitle( QString( rowTitles[ horIndex ] ) );
284 curve->setVerTitle( QString( rowTitles[ verIndex[i] ] ) );
287 if ( rowUnits.size() > 0 ) {
288 curve->setHorUnits( QString( rowUnits[ horIndex ] ) );
289 curve->setVerUnits( QString( rowUnits[ verIndex[i] ] ) );
293 for ( j = 1; j <= nbCols; j++ ) {
294 if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) )
297 if ( nbPoints > 0 ) {
298 double* xList = new double[ nbPoints ];
299 double* yList = new double[ nbPoints ];
300 for ( j = 1; j <= nbCols; j++ ) {
301 if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) ) {
302 xList[j-1] = tblIntAttr->GetValue( horIndex +1, j );
303 yList[j-1] = tblIntAttr->GetValue( verIndex[i]+1, j );
306 curve->setData( xList, yList, nbPoints );
309 curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
310 curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
311 curve->setColor( myItems.at( verIndex[i] )->getColor() );
312 curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
313 // add curve into container
314 container.append( curve );
318 MESSAGE("SPlot2d_SetupPlot2dDlg::getCurves : Exception has been caught (int)!!!");
322 /* Try table of real */
323 else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
324 tblRealAttr = anAttr;
327 int nbCols = tblRealAttr->GetNbColumns() ;
328 vector<string> rowTitles = tblRealAttr->GetRowTitles();
329 vector<string> rowUnits = tblRealAttr->GetRowUnits();
331 for ( i = 0; i < verIndex.count(); i++ ) {
332 SPlot2d_Curve* curve = new SPlot2d_Curve();
334 if ( rowTitles.size() > 0 ) {
335 curve->setHorTitle( QString( rowTitles[ horIndex ] ) );
336 curve->setVerTitle( QString( rowTitles[ verIndex[i] ] ) );
339 if ( rowUnits.size() > 0 ) {
340 curve->setHorUnits( QString( rowUnits[ horIndex ] ) );
341 curve->setVerUnits( QString( rowUnits[ verIndex[i] ] ) );
345 for ( j = 1; j <= nbCols; j++ ) {
346 if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) )
349 if ( nbPoints > 0 ) {
350 double* xList = new double[ nbPoints ];
351 double* yList = new double[ nbPoints ];
352 for ( j = 1; j <= nbCols; j++ ) {
353 if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) ) {
354 xList[j-1] = tblRealAttr->GetValue( horIndex +1, j );
355 yList[j-1] = tblRealAttr->GetValue( verIndex[i]+1, j );
358 curve->setData( xList, yList, nbPoints );
361 curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
362 curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
363 curve->setColor( myItems.at( verIndex[i] )->getColor() );
364 curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
365 // add curve into container
366 container.append( curve );
370 MESSAGE("SPlot2d_SetupPlot2dDlg::getCurves : Exception has been caught (real)!!!");
376 Slot, called when any <H> button is clicked
378 void SPlot2d_SetupPlot2dDlg::onHBtnToggled( bool on )
380 SPlot2d_ItemContainer* item = ( SPlot2d_ItemContainer* )sender();
382 for ( int i = 0; i < myItems.count(); i++ ) {
383 if ( myItems.at( i ) != item )
384 myItems.at( i )->setHorizontalOn( false );
390 Slot, called when any <V> button is clicked
392 void SPlot2d_SetupPlot2dDlg::onVBtnToggled( bool on )
394 SPlot2d_ItemContainer* item = ( SPlot2d_ItemContainer* )sender();
395 QPtrList<SPlot2d_ItemContainer> itemList;
396 itemList.setAutoDelete( false );
400 for ( i = 0; i < myItems.count(); i++ ) {
401 if ( myItems.at( i ) != item && !myItems.at( i )->isHorizontalOn() ) {
402 if ( myItems.at( i )->myUnitLab->text() == item->myUnitLab->text() ) {
403 if ( myItems.at( i )->isVerticalOn() )
406 itemList.append( myItems.at( i ) );
409 myItems.at( i )->setVerticalOn( false );
413 if ( totalOn == 0 && !itemList.isEmpty() &&
414 SUIT_MessageBox::info2( this,
416 tr( "QUE_WANT_SAME_UNITS" ),
420 for ( i = 0; i < itemList.count(); i++ ) {
421 itemList.at( i )->blockSignals( true );
422 itemList.at( i )->setVerticalOn( true );
423 itemList.at( i )->blockSignals( false );
430 Enables/disables buttons
432 void SPlot2d_SetupPlot2dDlg::enableControls()
436 for ( int i = 0; i < myItems.count(); i++ ) {
437 if ( myItems.at( i )->isHorizontalOn() ) {
442 for ( int i = 0; i < myItems.count(); i++ ) {
443 if ( myItems.at( i )->isVerticalOn() )
445 myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
447 myOkBtn->setEnabled( bHSet && bVSet );
450 // ====================================================================================
454 SPlot2d_ItemContainer::SPlot2d_ItemContainer( QObject* parent, const char* name )
455 : QObject( parent, name ),
462 void SPlot2d_ItemContainer::createWidgets( QWidget* parentWidget )
464 myHBtn = new QToolButton( parentWidget );
465 myHBtn->setText( tr( " H " ) );
466 myHBtn->setToggleButton( true );
467 myHBtn->setOn( false );
469 myVBtn = new QToolButton( parentWidget );
470 myVBtn->setText( tr( " V " ) );
471 myVBtn->setToggleButton( true );
472 myVBtn->setOn( false );
474 myTitleLab = new QLabel( parentWidget );
475 myUnitLab = new QLabel( parentWidget );
476 myUnitLab->setAlignment( AlignCenter);
478 myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
479 myAutoCheck->setChecked( true );
481 myLineCombo = new QComboBox( false, parentWidget );
482 myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
483 myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
484 myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
485 myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
486 myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
487 myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
488 myLineCombo->setCurrentItem( 1 ); // SOLID by default
490 myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, parentWidget );
491 myLineSpin->setValue( 0 ); // width = 0 by default
493 myMarkerCombo = new QComboBox( false, parentWidget );
494 myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
495 myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
496 myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
497 myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
498 myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
499 myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
500 myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
501 myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
502 myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
503 myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
504 myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
506 myColorBtn = new QToolButton( parentWidget );
508 connect( myAutoCheck, SIGNAL( clicked() ), this, SLOT( onAutoChanged() ) );
509 connect( myColorBtn, SIGNAL( clicked() ), this, SLOT( onColorChanged() ) );
510 connect( myHBtn, SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
511 connect( myVBtn, SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
512 setColor( QColor( 0, 0, 0 ) );
516 Enables attributes widgets
518 void SPlot2d_ItemContainer::enableWidgets( bool enable )
524 Sets horizontal button's state on
526 void SPlot2d_ItemContainer::setHorizontalOn( bool on )
531 Gets horizontal button's state
533 bool SPlot2d_ItemContainer::isHorizontalOn() const
535 return myHBtn->isOn();
538 Sets vertical button's state on
540 void SPlot2d_ItemContainer::setVerticalOn( bool on )
545 Gets vertical button's state
547 bool SPlot2d_ItemContainer::isVerticalOn() const
549 return myVBtn->isOn();
552 Sets item AutoAssign flag state
554 void SPlot2d_ItemContainer::setAutoAssign( bool on )
556 myAutoCheck->setChecked( on );
560 Gets item AutoAssign flag state
562 bool SPlot2d_ItemContainer::isAutoAssign() const
564 return myAutoCheck->isChecked();
567 Sets item line type and width
569 void SPlot2d_ItemContainer::setLine( const int line, const int width )
571 myLineCombo->setCurrentItem( line );
576 int SPlot2d_ItemContainer::getLine() const
578 return myLineCombo->currentItem();
583 int SPlot2d_ItemContainer::getLineWidth() const
585 return myLineSpin->value();
588 Sets item marker type
590 void SPlot2d_ItemContainer::setMarker( const int marker )
592 myMarkerCombo->setCurrentItem( marker );
595 Gets item marker type
597 int SPlot2d_ItemContainer::getMarker() const
599 return myMarkerCombo->currentItem();
604 void SPlot2d_ItemContainer::setColor( const QColor& color )
606 QPalette pal = myColorBtn->palette();
607 QColorGroup ca = pal.active();
608 ca.setColor( QColorGroup::Button, color );
609 QColorGroup ci = pal.inactive();
610 ci.setColor( QColorGroup::Button, color );
612 pal.setInactive( ci );
613 myColorBtn->setPalette( pal );
618 QColor SPlot2d_ItemContainer::getColor() const
620 return myColorBtn->palette().active().button();
623 Enables/disables widgets
625 void SPlot2d_ItemContainer::updateState()
627 myAutoCheck->setEnabled( myEnabled );
628 myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() );
629 myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() );
630 myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() );
631 myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() );
634 Slot, called when user clickes <Auto assign> check box
636 void SPlot2d_ItemContainer::onAutoChanged()
639 emit( autoClicked() );
642 <Color> button slot, invokes color selection dialog box
644 void SPlot2d_ItemContainer::onColorChanged()
646 QColor color = QColorDialog::getColor( getColor() );
647 if ( color.isValid() ) {
652 <H> and <V> buttons slot
654 void SPlot2d_ItemContainer::onHVToggled( bool on )
656 const QObject* snd = sender();
657 if ( snd == myHBtn ) {
659 if ( myVBtn->isOn() ) {
660 // blockSignals( true );
661 myVBtn->setOn( false );
662 // blockSignals( false );
665 emit horToggled( on );
669 if ( myHBtn->isOn() ) {
670 // blockSignals( true );
671 myHBtn->setOn( false );
672 // blockSignals( false );
675 emit verToggled( on );