]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_SetupPlot2dDlg.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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* labData = new QLabel( tr( "DATA_LBL" ),       frame );
92   QLabel* labUnit = new QLabel( tr( "UNITS_LBL" ),      frame );
93   QLabel* labAttr = new QLabel( tr( "ATTRIBUTES_LBL" ), frame );
94   labAxis->setAlignment( AlignCenter );
95   labData->setAlignment( AlignCenter );
96   labUnit->setAlignment( AlignCenter );
97   labAttr->setAlignment( AlignCenter );
98   QFont font = labAxis->font(); font.setBold( true );
99   labAxis->setFont( font );
100   labData->setFont( font );
101   labUnit->setFont( font );
102   labAttr->setFont( font );
103
104   frameLayout->addMultiCellWidget( labAxis, 0,  0, 0, 1 );
105       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
106       frameLayout->addWidget( lin,          0,     2 );
107   frameLayout->addWidget( labData,          0,     3 );
108       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
109       frameLayout->addWidget( lin,          0,     4 );
110   frameLayout->addWidget( labUnit,          0,     5 );
111       lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
112       frameLayout->addWidget( lin,          0,     6 );
113   frameLayout->addMultiCellWidget( labAttr, 0,  0, 7, 11 );
114   frameLayout->setColStretch(               12, 5 );
115   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::HLine | QFrame::Sunken );
116   frameLayout->addMultiCellWidget( lin, 1, 1, 0, 12 );
117
118   int row = 2;
119   _PTR(GenericAttribute)        anAttr;
120   _PTR(AttributeTableOfInteger) tblIntAttr;
121   _PTR(AttributeTableOfReal)    tblRealAttr;
122   
123   /* Try table of integer */
124   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
125     tblIntAttr = anAttr;
126     if ( tblIntAttr ) {
127       try {
128         int nbRows = tblIntAttr->GetNbRows() ; 
129         vector<string> rowTitles = tblIntAttr->GetRowTitles();
130         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
131         for ( int i = 0; i < nbRows; i++ ) {
132           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
133           item->createWidgets( frame );
134           frameLayout->addWidget( item->myHBtn,        row, 0 );
135           frameLayout->addWidget( item->myVBtn,        row, 1 );
136           frameLayout->addWidget( item->myTitleLab,    row, 3 );
137           if ( rowTitles.size() > 0 )
138             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
139           frameLayout->addWidget( item->myUnitLab,     row, 5 );
140           if ( rowUnits.size() > 0 )
141             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
142           frameLayout->addWidget( item->myAutoCheck,   row, 7 );
143           frameLayout->addWidget( item->myLineCombo,   row, 8 );
144           frameLayout->addWidget( item->myLineSpin,    row, 9 );
145           frameLayout->addWidget( item->myMarkerCombo, row, 10 );
146           frameLayout->addWidget( item->myColorBtn,    row, 11 );
147           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
148           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
149           myItems.append( item );
150           row++;
151         }
152       }
153       catch( ... ) {
154         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (int)!!!");
155       }
156     }
157   }
158   /* Try table of real */
159   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
160     tblRealAttr = anAttr;
161     if ( tblRealAttr ) {
162       try {
163         int nbRows = tblRealAttr->GetNbRows() ; 
164         vector<string> rowTitles = tblRealAttr->GetRowTitles();
165         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
166         for ( int i = 0; i < nbRows; i++ ) {
167           VisuGUI_ItemContainer* item = new VisuGUI_ItemContainer( this );
168           item->createWidgets( frame );
169           frameLayout->addWidget( item->myHBtn,        row, 0 );
170           frameLayout->addWidget( item->myVBtn,        row, 1 );
171           frameLayout->addWidget( item->myTitleLab,    row, 3 );
172           if ( rowTitles.size() > 0 )
173             item->myTitleLab->setText( QString( rowTitles[ i ].c_str() ) );
174           frameLayout->addWidget( item->myUnitLab,     row, 5 );
175           if ( rowUnits.size() > 0 )
176             item->myUnitLab->setText( QString( rowUnits[ i ].c_str() ) );
177           frameLayout->addWidget( item->myAutoCheck,   row, 7 );
178           frameLayout->addWidget( item->myLineCombo,   row, 8 );
179           frameLayout->addWidget( item->myLineSpin,    row, 9 );
180           frameLayout->addWidget( item->myMarkerCombo, row, 10 );
181           frameLayout->addWidget( item->myColorBtn,    row, 11 );
182           connect( item, SIGNAL( horToggled( bool ) ), this, SLOT( onHBtnToggled( bool ) ) );
183           connect( item, SIGNAL( verToggled( bool ) ), this, SLOT( onVBtnToggled( bool ) ) );
184           myItems.append( item );
185           row++;
186         }
187       }
188       catch( ... ) {
189         MESSAGE("VisuGUI_SetupPlot2dDlg::VisuGUI_SetupPlot2dDlg : Exception has been caught (real)!!!");
190       }
191     }
192   }
193   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
194   frameLayout->addMultiCellWidget( lin, 2, row+1, 2, 2 );
195   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
196   frameLayout->addMultiCellWidget( lin, 2, row+1, 4, 4 );
197   lin = new QFrame( frame ); lin->setFrameStyle( QFrame::VLine | QFrame::Sunken );
198   frameLayout->addMultiCellWidget( lin, 2, row+1, 6, 6 );
199   frameLayout->setRowStretch( row+1, 5 );
200
201   myView->addChild( frame, 0, 0 );
202   myView->setResizePolicy( QScrollView::AutoOneFit );
203   
204   myView->setMinimumWidth( frame->sizeHint().width() + MARGIN_SIZE * 2 );
205
206   /* OK/Cancel/Help buttons */
207   myOkBtn = new QPushButton( tr( "BUT_OK" ), this, "buttonOk" );
208   myOkBtn->setAutoDefault( TRUE );
209   myOkBtn->setDefault( TRUE );
210   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this, "buttonCancel" );
211   myCancelBtn->setAutoDefault( TRUE );
212   myHelpBtn = new QPushButton( tr( "BUT_HELP" ), this, "buttonHelp" );
213   myHelpBtn->setAutoDefault( TRUE );
214
215   topLayout->addMultiCellWidget( myView, 0, 0, 0, 3 );
216   topLayout->addWidget( myOkBtn, 1, 0 );
217   topLayout->setColStretch( 1, 5 );
218   topLayout->addWidget( myCancelBtn, 1, 2 );
219   topLayout->addWidget( myHelpBtn, 1, 3 );
220
221   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
222   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
223   connect( myHelpBtn,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
224
225   enableControls();
226
227   /* Center widget inside it's parent widget */
228   resize( DLG_SIZE_WIDTH, DLG_SIZE_HEIGHT  );
229   SUIT_Tools::centerWidget( this, parentWidget() );
230 }
231 /*!
232   Destructor
233 */
234 VisuGUI_SetupPlot2dDlg::~VisuGUI_SetupPlot2dDlg()
235 {
236 }
237 /*!
238   Gets curves info ( indexes of row data in the table for horizontal and verical axes )
239 */
240 void VisuGUI_SetupPlot2dDlg::getCurvesSource( int& horIndex, QValueList<int>& verIndexes )
241 {
242   /* collecting horizontal and vertical axis items */
243   horIndex = -1;
244   int i;
245   for ( i = 0; i < myItems.count(); i++ ) {
246     if ( myItems.at( i )->isHorizontalOn() ) {
247       horIndex = i;
248     }
249     else if ( myItems.at( i )->isVerticalOn() ) {
250       verIndexes.append( i );
251     }
252   }
253 }
254 /*!
255   Gets curve attributes
256 */
257 bool VisuGUI_SetupPlot2dDlg::getCurveAttributes( const int vIndex, 
258                                                    bool&     isAuto, 
259                                                    int&      marker, 
260                                                    int&      line, 
261                                                    int&      lineWidth, 
262                                                    QColor&   color)
263 {
264   if ( vIndex >= 0 && vIndex < myItems.count() ) {
265     isAuto    = myItems.at( vIndex )->isAutoAssign();
266     marker    = myItems.at( vIndex )->getMarker();
267     line      = myItems.at( vIndex )->getLine();
268     lineWidth = myItems.at( vIndex )->getLineWidth();
269     color     = myItems.at( vIndex )->getColor();
270     return true;
271   }
272   return false;
273 }
274 /*!
275   Creates and returns curves presentations
276 */
277 void VisuGUI_SetupPlot2dDlg::getCurves( QPtrList<Plot2d_Curve>& container )
278 {
279   _PTR(GenericAttribute)        anAttr;
280   _PTR(AttributeTableOfInteger) tblIntAttr;
281   _PTR(AttributeTableOfReal)    tblRealAttr;
282   
283   /* clearing container contents */
284   container.clear();
285
286   /* collecting horizontal and vertical axis items */
287   int horIndex;
288   int i, j;
289   QValueList<int> verIndex;
290   getCurvesSource( horIndex, verIndex );
291   if ( horIndex < 0 || verIndex.isEmpty() ) /* no curves can be created */
292     return;
293     
294   /* Try table of integer */
295   if ( myObject->FindAttribute( anAttr, "AttributeTableOfInteger" ) ) {
296     tblIntAttr = anAttr;
297     if ( tblIntAttr ) {
298       try {
299         int nbCols = tblIntAttr->GetNbColumns() ; 
300         vector<string> rowTitles = tblIntAttr->GetRowTitles();
301         vector<string> rowUnits  = tblIntAttr->GetRowUnits();
302
303         for ( i = 0; i < verIndex.count(); i++ ) {
304           SPlot2d_Curve* curve = new SPlot2d_Curve();
305           // curve titles
306           if ( rowTitles.size() > 0 ) {
307             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
308             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
309           }
310           // curve units
311           if ( rowUnits.size() > 0 ) {
312             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
313             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
314           }
315           // curve data
316           int nbPoints = 0;
317           for ( j = 1; j <= nbCols; j++ ) {
318             if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) )
319               nbPoints++;
320           }
321           if ( nbPoints > 0 ) {
322             double* xList = new double[ nbPoints ];
323             double* yList = new double[ nbPoints ];
324             for ( j = 1; j <= nbCols; j++ ) {
325               if ( tblIntAttr->HasValue( horIndex+1, j ) && tblIntAttr->HasValue( verIndex[i]+1, j ) ) {
326                 xList[j-1] = tblIntAttr->GetValue( horIndex   +1, j );
327                 yList[j-1] = tblIntAttr->GetValue( verIndex[i]+1, j );
328               }
329             }
330             curve->setData( xList, yList, nbPoints );
331           }
332           // curve attributes
333           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
334           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
335           curve->setColor( myItems.at( verIndex[i] )->getColor() );
336           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
337           // add curve into container
338           container.append( curve );
339         }
340       }
341       catch( ... ) {
342         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (int)!!!");
343       }
344     }
345   }
346   /* Try table of real */
347   else if ( myObject->FindAttribute( anAttr, "AttributeTableOfReal" ) ) {
348     tblRealAttr = anAttr;
349     if ( tblRealAttr ) {
350       try {
351         int nbCols = tblRealAttr->GetNbColumns() ; 
352         vector<string> rowTitles = tblRealAttr->GetRowTitles();
353         vector<string> rowUnits  = tblRealAttr->GetRowUnits();
354
355         for ( i = 0; i < verIndex.count(); i++ ) {
356           SPlot2d_Curve* curve = new SPlot2d_Curve();
357           // curve titles
358           if ( rowTitles.size() > 0 ) {
359             curve->setHorTitle( QString( rowTitles[ horIndex ].c_str() ) );
360             curve->setVerTitle( QString( rowTitles[ verIndex[i] ].c_str() ) );
361           }
362           // curve units
363           if ( rowUnits.size() > 0 ) {
364             curve->setHorUnits( QString( rowUnits[ horIndex ].c_str() ) );
365             curve->setVerUnits( QString( rowUnits[ verIndex[i] ].c_str() ) );
366           }
367           // curve data
368           int nbPoints = 0;
369           for ( j = 1; j <= nbCols; j++ ) {
370             if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) )
371               nbPoints++;
372           }
373           if ( nbPoints > 0 ) {
374             double* xList = new double[ nbPoints ];
375             double* yList = new double[ nbPoints ];
376             for ( j = 1; j <= nbCols; j++ ) {
377               if ( tblRealAttr->HasValue( horIndex+1, j ) && tblRealAttr->HasValue( verIndex[i]+1, j ) ) {
378                 xList[j-1] = tblRealAttr->GetValue( horIndex   +1, j );
379                 yList[j-1] = tblRealAttr->GetValue( verIndex[i]+1, j );
380               }
381             }
382             curve->setData( xList, yList, nbPoints );
383           }
384           // curve attributes
385           curve->setLine( (Plot2d_Curve::LineType)myItems.at( verIndex[i] )->getLine(), myItems.at( verIndex[i] )->getLineWidth() );
386           curve->setMarker( (Plot2d_Curve::MarkerType)myItems.at( verIndex[i] )->getMarker() );
387           curve->setColor( myItems.at( verIndex[i] )->getColor() );
388           curve->setAutoAssign( myItems.at( verIndex[i] )->isAutoAssign() );
389           // add curve into container
390           container.append( curve );
391         }
392       }
393       catch( ... ) {
394         MESSAGE("VisuGUI_SetupPlot2dDlg::getCurves : Exception has been caught (real)!!!");
395       }
396     }
397   }
398 }
399 /*!
400   Slot, called when any <H> button is clicked
401 */
402 void VisuGUI_SetupPlot2dDlg::onHBtnToggled( bool on )
403 {
404   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
405   if ( on ) {
406     for ( int i = 0; i < myItems.count(); i++ ) {
407       if ( myItems.at( i ) != item )
408         myItems.at( i )->setHorizontalOn( false );
409     }
410   }
411   enableControls();
412 }
413 /*!
414   Slot, called when any <V> button is clicked
415 */
416 void VisuGUI_SetupPlot2dDlg::onVBtnToggled( bool on )
417 {
418   VisuGUI_ItemContainer* item = ( VisuGUI_ItemContainer* )sender();
419   QPtrList<VisuGUI_ItemContainer> itemList;
420   itemList.setAutoDelete( false );
421   int i;
422   if ( on ) {
423     int totalOn = 0;
424     for ( i = 0; i < myItems.count(); i++ ) {
425       if ( myItems.at( i ) != item && !myItems.at( i )->isHorizontalOn() ) {
426         if ( myItems.at( i )->myUnitLab->text() == item->myUnitLab->text() ) {
427           if ( myItems.at( i )->isVerticalOn() )
428             totalOn++;
429           else
430             itemList.append( myItems.at( i ) );
431         }
432         else {
433           myItems.at( i )->setVerticalOn( false );
434         }
435       }
436     }
437     if ( totalOn == 0 && !itemList.isEmpty() && 
438          SUIT_MessageBox::info2( this, 
439                                 this->caption(), 
440                                 tr( "QUE_WANT_SAME_UNITS" ),
441                                 tr( "BUT_YES" ), 
442                                 tr( "BUT_NO" ), 
443                                 0, 1, 1 ) == 0 ) {
444       for ( i = 0; i < itemList.count(); i++ ) {
445         itemList.at( i )->blockSignals( true );
446         itemList.at( i )->setVerticalOn( true );
447         itemList.at( i )->blockSignals( false );
448       }
449     }
450   }
451   enableControls();
452 }
453 /*!
454   Slot, called when <Help> button is clicked
455 */
456 void VisuGUI_SetupPlot2dDlg::onHelp()
457 {
458   QString aHelpFileName = "/files/creating_curves.htm";
459   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
460   if (app) {
461     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
462     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
463   }
464   else {
465     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
466                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
467                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
468                            QObject::tr("BUT_OK"));
469   }
470 }
471 /*!
472   Enables/disables buttons 
473 */
474 void VisuGUI_SetupPlot2dDlg::enableControls()
475 {
476   bool bHSet = false;
477   bool bVSet = false;
478   for ( int i = 0; i < myItems.count(); i++ ) {
479     if ( myItems.at( i )->isHorizontalOn() ) {
480       bHSet = true;
481       break;
482     }
483   }
484 #ifndef WNT
485   for ( int i = 0; i < myItems.count(); i++ ) {
486 #else
487   for ( i = 0; i < myItems.count(); i++ ) {
488 #endif
489     if ( myItems.at( i )->isVerticalOn() )
490       bVSet = true;
491     myItems.at( i )->enableWidgets( bHSet && myItems.at( i )->isVerticalOn() );
492   }
493   myOkBtn->setEnabled( bHSet && bVSet );
494 }
495
496 // ====================================================================================
497 /*!
498   Constructor
499 */
500 VisuGUI_ItemContainer::VisuGUI_ItemContainer( QObject* parent, const char* name )
501      : QObject( parent, name ), 
502        myEnabled( true )
503 {
504 }
505 /*!
506   Creates widgets
507 */
508 void VisuGUI_ItemContainer::createWidgets( QWidget* parentWidget )
509 {
510   myHBtn = new QToolButton( parentWidget );
511   myHBtn->setText( tr( "H" ) );
512   myHBtn->setToggleButton( true );
513   myHBtn->setOn( false );
514
515   myVBtn = new QToolButton( parentWidget );
516   myVBtn->setText( tr( "V" ) );
517   myVBtn->setToggleButton( true );
518   myVBtn->setOn( false );
519   
520   myTitleLab = new QLabel( parentWidget );
521   myUnitLab  = new QLabel( parentWidget );
522   myUnitLab->setAlignment( AlignCenter);
523   
524   myAutoCheck = new QCheckBox( tr( "AUTO_CHECK_LBL" ), parentWidget );
525   myAutoCheck->setChecked( true );
526
527   myLineCombo = new QComboBox( false, parentWidget );
528   myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
529   myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
530   myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
531   myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
532   myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
533   myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
534   myLineCombo->setCurrentItem( 1 ); // SOLID by default
535
536   myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, parentWidget );
537   myLineSpin->setValue( 0 );        // width = 0 by default
538
539   myMarkerCombo = new QComboBox( false, parentWidget );
540   myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
541   myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
542   myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
543   myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
544   myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
545   myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
546   myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
547   myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
548   myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
549   myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
550   myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
551
552   myColorBtn = new QToolButton( parentWidget );
553   myColorBtn->setMinimumWidth( 20 );
554  
555   connect( myAutoCheck, SIGNAL( clicked() ),       this, SLOT( onAutoChanged() ) );
556   connect( myColorBtn,  SIGNAL( clicked() ),       this, SLOT( onColorChanged() ) );
557   connect( myHBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
558   connect( myVBtn,      SIGNAL( toggled( bool ) ), this, SLOT( onHVToggled( bool ) ) );
559   setColor( QColor( 0, 0, 0 ) );
560   updateState();
561 }
562 /*!
563   Enables attributes widgets
564 */
565 void VisuGUI_ItemContainer::enableWidgets( bool enable )
566 {
567   myEnabled = enable;
568   updateState();
569 }
570 /*!
571   Sets horizontal button's state on
572 */
573 void VisuGUI_ItemContainer::setHorizontalOn( bool on )
574 {
575   myHBtn->setOn( on );
576 }
577 /*!
578   Gets horizontal button's state
579 */
580 bool VisuGUI_ItemContainer::isHorizontalOn() const
581 {
582   return myHBtn->isOn();
583 }
584 /*!
585   Sets vertical button's state on
586 */
587 void VisuGUI_ItemContainer::setVerticalOn( bool on )
588 {
589   myVBtn->setOn( on );
590 }
591 /*!
592   Gets vertical button's state
593 */
594 bool VisuGUI_ItemContainer::isVerticalOn() const
595 {
596   return myVBtn->isOn();
597 }
598 /*!
599   Sets item AutoAssign flag state
600 */
601 void VisuGUI_ItemContainer::setAutoAssign( bool on )
602 {
603   myAutoCheck->setChecked( on );
604   updateState();
605 }
606 /*!
607   Gets item AutoAssign flag state
608 */
609 bool VisuGUI_ItemContainer::isAutoAssign() const
610 {
611   return myAutoCheck->isChecked();
612 }
613 /*!
614   Sets item line type and width
615 */
616 void VisuGUI_ItemContainer::setLine( const int line, const int width )
617 {
618   myLineCombo->setCurrentItem( line );
619 }
620 /*!
621   Gets item line type
622 */
623 int VisuGUI_ItemContainer::getLine() const
624 {
625   return myLineCombo->currentItem();
626 }
627 /*!
628   Gets item line width
629 */
630 int VisuGUI_ItemContainer::getLineWidth() const
631 {
632   return myLineSpin->value();
633 }
634 /*!
635   Sets item marker type
636 */
637 void VisuGUI_ItemContainer::setMarker( const int marker )
638 {
639   myMarkerCombo->setCurrentItem( marker );
640 }
641 /*!
642   Gets item marker type
643 */
644 int VisuGUI_ItemContainer::getMarker() const
645 {
646   return myMarkerCombo->currentItem();
647 }
648 /*!
649   Sets item color
650 */
651 void VisuGUI_ItemContainer::setColor( const QColor& color )
652 {
653   QPalette pal = myColorBtn->palette();
654   QColorGroup ca = pal.active();
655   ca.setColor( QColorGroup::Button, color );
656   QColorGroup ci = pal.inactive();
657   ci.setColor( QColorGroup::Button, color );
658   pal.setActive( ca );
659   pal.setInactive( ci );
660   myColorBtn->setPalette( pal );
661 }
662 /*!
663   Gets item color
664 */
665 QColor VisuGUI_ItemContainer::getColor() const
666 {
667   return myColorBtn->palette().active().button();
668 }
669 /*!
670   Enables/disables widgets
671 */
672 void VisuGUI_ItemContainer::updateState()
673 {
674   myAutoCheck->setEnabled( myEnabled );
675   myLineCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
676   myLineSpin->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
677   myMarkerCombo->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
678   myColorBtn->setEnabled( myEnabled && !myAutoCheck->isChecked() ); 
679 }
680 /*!
681   Slot, called when user clickes <Auto assign> check box
682 */
683 void VisuGUI_ItemContainer::onAutoChanged()
684 {
685   updateState();
686   emit( autoClicked() );
687 }
688 /*!
689   <Color> button slot, invokes color selection dialog box
690 */
691 void VisuGUI_ItemContainer::onColorChanged()
692 {
693   QColor color = QColorDialog::getColor( getColor() );
694   if ( color.isValid() ) {
695     setColor( color );
696   }
697 }
698 /*!
699   <H> and <V> buttons slot
700 */
701 void VisuGUI_ItemContainer::onHVToggled( bool on )
702 {
703   const QObject* snd = sender();
704   if ( snd == myHBtn ) {
705     if ( on ) {
706       if ( myVBtn->isOn() ) {
707 //      blockSignals( true );
708         myVBtn->setOn( false );
709 //      blockSignals( false );
710       }
711     }
712     emit horToggled( on );
713   }
714   else {
715     if ( on ) {
716       if ( myHBtn->isOn() ) {
717 //      blockSignals( true );
718         myHBtn->setOn( false );
719 //      blockSignals( false );
720       }
721     }
722     emit verToggled( on );
723   }
724 }
725
726
727
728
729