00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_Preferences_ColorDlg.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_SpinBox.h"
00032 #include "SMESHGUI_Utils.h"
00033
00034
00035 #include <SUIT_Desktop.h>
00036 #include <SUIT_MessageBox.h>
00037 #include <SUIT_ResourceMgr.h>
00038 #include <SUIT_Session.h>
00039 #include <QtxColorButton.h>
00040 #include <VTKViewer_MarkerWidget.h>
00041 #include <LightApp_Application.h>
00042 #include <SalomeApp_IntSpinBox.h>
00043
00044
00045 #include <QGroupBox>
00046 #include <QLabel>
00047 #include <QPushButton>
00048 #include <QVBoxLayout>
00049 #include <QHBoxLayout>
00050 #include <QGridLayout>
00051 #include <QCheckBox>
00052 #include <QKeyEvent>
00053
00054 #define SPACING 6
00055 #define MARGIN 11
00056
00057
00058
00059
00060
00061
00062
00063
00064 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
00065 : QDialog( SMESH::GetDesktop( theModule ) ),
00066 mySMESHGUI( theModule )
00067 {
00068 setModal( true );
00069 setWindowTitle( tr( "Preferences - Set Color" ) );
00070 setSizeGripEnabled( true );
00071
00072
00073 QVBoxLayout* topLayout = new QVBoxLayout( this );
00074 topLayout->setSpacing( SPACING );
00075 topLayout->setMargin( MARGIN );
00076
00077
00078 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
00079 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
00080 ButtonGroup1Layout->setSpacing( SPACING );
00081 ButtonGroup1Layout->setMargin( MARGIN );
00082
00083 QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
00084 btnFillColor = new QtxColorButton( ButtonGroup1 );
00085
00086 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
00087 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
00088
00089 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
00090 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
00091
00092 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
00093 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
00094
00095 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
00096 SpinBox_0DElements_Size = new SalomeApp_IntSpinBox( ButtonGroup1 );
00097 SpinBox_0DElements_Size->setAcceptNames( false );
00098 SpinBox_0DElements_Size->setRange( 1, 10 );
00099 SpinBox_0DElements_Size->setSingleStep( 1 );
00100 SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00101 SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
00102
00103 QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
00104 SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
00105 SpinBox_Width->setAcceptNames( false );
00106 SpinBox_Width->setRange( 0, 5 );
00107 SpinBox_Width->setSingleStep( 1 );
00108 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00109 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
00110
00111 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
00112 SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
00113 SpinBox_Shrink->setAcceptNames( false );
00114 SpinBox_Shrink->setRange( 20, 100 );
00115 SpinBox_Shrink->setSingleStep( 1 );
00116 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00117 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
00118
00119 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
00120 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
00121 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 0, 2 );
00122 ButtonGroup1Layout->addWidget( btnBackFaceColor, 0, 3 );
00123 ButtonGroup1Layout->addWidget( TextLabel_Outine, 1, 0 );
00124 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
00125 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
00126 ButtonGroup1Layout->addWidget( btn0DElementsColor, 1, 3 );
00127 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 0 );
00128 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 1 );
00129 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
00130 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
00131 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
00132 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
00133
00134
00135 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
00136 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
00137 ButtonGroup2Layout->setSpacing( SPACING );
00138 ButtonGroup2Layout->setMargin( MARGIN );
00139
00140 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
00141 btnNodeColor = new QtxColorButton( ButtonGroup2 );
00142
00143 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
00144 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
00145 MarkerGroupLayout->setSpacing( 0 );
00146 MarkerGroupLayout->setMargin( 0 );
00147
00148 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
00149
00150 MarkerGroupLayout->addWidget( MarkerWidget );
00151
00152 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
00153 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
00154 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
00155 ButtonGroup2Layout->setColumnStretch( 2, 1 );
00156
00157
00158 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
00159 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
00160 ButtonGroup3Layout->setSpacing( SPACING );
00161 ButtonGroup3Layout->setMargin( MARGIN );
00162
00163 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
00164 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
00165
00166 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
00167 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
00168 SpinBox_Orientation_Scale->setAcceptNames( false );
00169 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
00170 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00171 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
00172
00173 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
00174
00175 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
00176 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
00177 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
00178 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
00179 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
00180
00181
00182 QGroupBox* GroupButtons = new QGroupBox( this );
00183 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00184 GroupButtonsLayout->setSpacing( SPACING );
00185 GroupButtonsLayout->setMargin( MARGIN );
00186
00187 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
00188 buttonOk->setAutoDefault( true );
00189 buttonOk->setDefault( true );
00190
00191 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
00192 buttonCancel->setAutoDefault( true );
00193
00194 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ), GroupButtons );
00195 buttonHelp->setAutoDefault( true );
00196
00197 GroupButtonsLayout->addWidget( buttonOk );
00198 GroupButtonsLayout->addSpacing( 10 );
00199 GroupButtonsLayout->addStretch();
00200 GroupButtonsLayout->addWidget( buttonCancel );
00201 GroupButtonsLayout->addWidget( buttonHelp );
00202
00203
00204 topLayout->addWidget( ButtonGroup1 );
00205 topLayout->addWidget( ButtonGroup2 );
00206 topLayout->addWidget( ButtonGroup3 );
00207 topLayout->addWidget( GroupButtons );
00208
00209
00210 mySMESHGUI->SetActiveDialogBox( this );
00211
00212 myHelpFileName = "colors_size_page.html";
00213
00214
00215 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00216 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
00217 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
00218
00219 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
00220 this, SLOT( DeactivateActiveDialog() ) );
00221
00222 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
00223 this, SLOT( ClickOnCancel() ) );
00224 }
00225
00226
00227
00228
00229
00230 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
00231 {
00232 }
00233
00234
00235
00236
00237
00238 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
00239 {
00240 mySMESHGUI->ResetState();
00241 accept();
00242 }
00243
00244
00245
00246
00247
00248 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
00249 {
00250 mySMESHGUI->ResetState();
00251 reject();
00252 }
00253
00254
00255
00256
00257
00258 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
00259 {
00260 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00261 if (app)
00262 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00263 else {
00264 QString platform;
00265 #ifdef WIN32
00266 platform = "winapplication";
00267 #else
00268 platform = "application";
00269 #endif
00270 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00271 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00272 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00273 platform)).
00274 arg(myHelpFileName));
00275 }
00276 }
00277
00278
00279
00280
00281
00282 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
00283 {
00284 }
00285
00286
00287
00288
00289
00290 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
00291 {
00292 ClickOnCancel();
00293 }
00294
00295
00296
00297
00298
00299 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
00300 {
00301
00302 mySMESHGUI->EmitSignalDeactivateDialog();
00303 }
00304
00305
00306
00307
00308
00309 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
00310 {
00311 switch ( type ) {
00312 case 1 : btnFillColor->setColor( color ); break;
00313 case 2 : btnOutlineColor->setColor( color ); break;
00314 case 3 : btnNodeColor->setColor( color ); break;
00315 case 4 : btnBackFaceColor->setColor( color ); break;
00316 case 5 : btn0DElementsColor->setColor( color ); break;
00317 case 6 : btnOrientationColor->setColor( color ); break;
00318 default: break;
00319 }
00320 }
00321
00322
00323
00324
00325
00326 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
00327 {
00328 QColor color;
00329 switch ( type ) {
00330 case 1 : color = btnFillColor->color(); break;
00331 case 2 : color = btnOutlineColor->color(); break;
00332 case 3 : color = btnNodeColor->color(); break;
00333 case 4 : color = btnBackFaceColor->color(); break;
00334 case 5 : color = btn0DElementsColor->color(); break;
00335 case 6 : color = btnOrientationColor->color(); break;
00336 default: break;
00337 }
00338 return color;
00339 }
00340
00341
00342
00343
00344
00345 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
00346 {
00347 switch ( type ) {
00348 case 1 : SpinBox_Width->setValue( value ); break;
00349 case 2 : SpinBox_Shrink->setValue( value ); break;
00350 case 3 : SpinBox_0DElements_Size->setValue( value ); break;
00351 default: break;
00352 }
00353 }
00354
00355
00356
00357
00358
00359 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
00360 {
00361 int res = 0;
00362 switch ( type ) {
00363 case 1 : res = SpinBox_Width->value(); break;
00364 case 2 : res = SpinBox_Shrink->value(); break;
00365 case 3 : res = SpinBox_0DElements_Size->value(); break;
00366 default: break;
00367 }
00368 return res;
00369 }
00370
00371
00372
00373
00374
00375 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
00376 {
00377 switch ( type ) {
00378 case 1 : SpinBox_Orientation_Scale->setValue( value ); break;
00379 default: break;
00380 }
00381 }
00382
00383
00384
00385
00386
00387 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
00388 {
00389 double res = 0;
00390 switch ( type ) {
00391 case 1 : res = SpinBox_Orientation_Scale->value(); break;
00392 default: break;
00393 }
00394 return res;
00395 }
00396
00397
00398
00399
00400
00401 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
00402 {
00403 switch ( type ) {
00404 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break;
00405 default: break;
00406 }
00407 }
00408
00409
00410
00411
00412
00413 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
00414 {
00415 bool res = false;
00416 switch ( type ) {
00417 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break;
00418 default: break;
00419 }
00420 return res;
00421 }
00422
00423
00424
00425
00426
00427 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
00428 {
00429 MarkerWidget->setCustomMarkerMap( theMarkerMap );
00430 }
00431
00432
00433
00434
00435
00436 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
00437 {
00438 return MarkerWidget->getCustomMarkerMap();
00439 }
00440
00441
00442
00443
00444
00445 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
00446 VTK::MarkerScale theMarkerScale )
00447 {
00448 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
00449 }
00450
00451
00452
00453
00454
00455 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
00456 {
00457 MarkerWidget->setCustomMarker( theId );
00458 }
00459
00460
00461
00462
00463
00464 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
00465 {
00466 return MarkerWidget->getMarkerType();
00467 }
00468
00469
00470
00471
00472
00473 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
00474 {
00475 return MarkerWidget->getStandardMarkerScale();
00476 }
00477
00478
00479
00480
00481
00482 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
00483 {
00484 return MarkerWidget->getCustomMarkerID();
00485 }
00486
00487
00488
00489
00490
00491 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
00492 {
00493 QDialog::keyPressEvent( e );
00494 if ( e->isAccepted() )
00495 return;
00496
00497 if ( e->key() == Qt::Key_F1 ) {
00498 e->accept();
00499 ClickOnHelp();
00500 }
00501 }