Salome HOME
NRI : Correction 1.1a version.
[modules/visu.git] / src / VISUGUI / VisuGUI_StreamLinesDlg.cxx
1 //  File      : VisuGUI_StreamLinesDlg.cxx
2 //  Created   : 06 / 03 / 2003
3 //  Author    : Vitaly SMETANNIKOV
4 //  Project   : SALOME 
5 //  Module    : VISUGUI
6 //  Copyright : Open CASCADE 
7
8
9 #include "VisuGUI_StreamLinesDlg.h"
10 #include <qlayout.h>
11 #include <qgroupbox.h>
12 #include <qcolordialog.h>
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_Config.h"
16
17
18 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg()
19     : QDialog( QAD_Application::getDesktop(), "VisuGUI_StreamLinesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
20 {
21   setCaption("Stream lines Preferences");
22   setSizeGripEnabled( TRUE );
23
24   QGridLayout* TopLayout = new QGridLayout( this ); 
25   TopLayout->setSpacing( 6 );
26   TopLayout->setMargin( 11 );
27
28   QLabel* aStepLenLbl = new QLabel( tr( "Step Length" ), this);
29   TopLayout->addWidget(aStepLenLbl, 0, 0);
30   myStepLen = new QAD_SpinBoxDbl( this);
31   myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
32   TopLayout->addWidget(myStepLen, 0, 1);
33
34   QLabel* aIntegStepLenLbl = new QLabel( tr( "Integration Step" ), this);
35   TopLayout->addWidget(aIntegStepLenLbl, 1, 0);
36   myIntegStepLen = new QAD_SpinBoxDbl( this);
37   myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
38   TopLayout->addWidget(myIntegStepLen, 1, 1);
39   
40   QLabel* aPropagationLbl = new QLabel( tr( "Propagation Time" ), this);
41   TopLayout->addWidget(aPropagationLbl, 2, 0);
42   myPropTime = new QAD_SpinBoxDbl( this, 0, 1000, 10);
43   myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
44   TopLayout->addWidget(myPropTime, 2, 1);
45   
46   QLabel* aDirLbl = new QLabel( tr( "Direction" ), this);
47   TopLayout->addWidget(aDirLbl, 3, 0);
48   myDirCombo = new QComboBox(this);
49   myDirCombo->insertItem("Forward");
50   myDirCombo->insertItem("Backward");
51   myDirCombo->insertItem("Both");
52   TopLayout->addWidget(myDirCombo, 3, 1);
53
54   myUseScalar = new QCheckBox( tr( "Magnitude coloring" ), this, "UseMagn" );
55   //  TopLayout->addMultiCellWidget(myUseScalar, 4, 4, 0, 1);
56   connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
57   TopLayout->addWidget(myUseScalar, 4, 0);
58
59   SelColor = new QPushButton( tr( "Use Color" ), this, "SelColor" );
60   connect( SelColor,     SIGNAL( clicked() ), this, SLOT( setVColor() ) );
61   TopLayout->addWidget( SelColor, 4, 1);
62  
63   QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
64   aGroupButtons->setColumnLayout(0, Qt::Vertical );
65   aGroupButtons->layout()->setSpacing( 0 );
66   aGroupButtons->layout()->setMargin( 0 );
67   
68   QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
69   aGroupButtonsLayout->setAlignment( Qt::AlignTop );
70   aGroupButtonsLayout->setSpacing( 6 );
71   aGroupButtonsLayout->setMargin( 11 );
72
73   QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
74   aOkBtn->setAutoDefault( TRUE );
75   aOkBtn->setDefault( TRUE );
76   aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
77   aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
78
79   QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
80   aCancelBtn->setAutoDefault( TRUE );
81   aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
82   connect( aOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
83   connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
84   TopLayout->addMultiCellWidget( aGroupButtons, 5, 5, 0, 1 );
85   enableSetColor();
86 }
87
88
89
90 void VisuGUI_StreamLinesDlg::initFromPrsObject(VISU::StreamLines_i* thePrs) {
91   myStepLen->setValue(thePrs->GetStepLength());
92   myIntegStepLen->setValue(thePrs->GetIntegrationStep());
93   myPropTime->setValue(thePrs->GetPropagationTime());
94   switch (thePrs->GetDirection()) {
95   case VISU::StreamLines::FORWARD:
96     myDirCombo->setCurrentItem(0);
97     break;
98   case VISU::StreamLines::BACKWARD:
99     myDirCombo->setCurrentItem(1);
100     break;
101   case VISU::StreamLines::BOTH:
102     myDirCombo->setCurrentItem(2);
103   }
104   myUseScalar->setChecked(thePrs->isColored());
105
106   setColor(QColor(thePrs->GetColor()[0]*255,
107                   thePrs->GetColor()[1]*255,
108                   thePrs->GetColor()[2]*255));
109   enableSetColor();
110 }
111
112
113
114 void VisuGUI_StreamLinesDlg::storeToPrsObject(VISU::StreamLines_i* thePrs) {
115   thePrs->SetStepLength(myStepLen->value());
116   thePrs->SetIntegrationStep(myIntegStepLen->value());
117   thePrs->SetPropagationTime(myPropTime->value());
118   switch (myDirCombo->currentItem()) {
119   case 0:
120     thePrs->SetDirection(VISU::StreamLines::FORWARD);
121     break;
122   case 1:
123     thePrs->SetDirection(VISU::StreamLines::BACKWARD);
124     break;
125   case 2:
126     thePrs->SetDirection(VISU::StreamLines::BOTH);
127   }
128   thePrs->setColored(myUseScalar->isChecked());
129
130   float aColor[3];
131   aColor[0] = myColor.red()/255.;
132   aColor[1] = myColor.green()/255.;
133   aColor[2] = myColor.blue()/255.;
134
135   thePrs->SetColor(aColor);
136 }
137
138 /*!
139   Sets color
140 */
141 void VisuGUI_StreamLinesDlg::setColor( QColor color )
142 {
143   myColor = color;
144   SelColor->setPaletteBackgroundColor(myColor);
145 }
146
147
148 /*!
149   Called when "Select Color" buttonx clicked
150 */
151 void VisuGUI_StreamLinesDlg::setVColor()
152 {
153   QColor cnew = QColorDialog::getColor( myColor, this );
154   if ( cnew.isValid() )
155     setColor( cnew );
156 }
157
158
159 /*!
160   Enbled/disables magnitude coloring
161 */
162 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
163 {
164   myUseScalar->setEnabled( enable );
165   enableSetColor();
166 }
167
168 /*!
169   Called when "Magnitude Coloring" check box clicked
170 */
171 void VisuGUI_StreamLinesDlg::enableSetColor()
172 {
173   SelColor->setEnabled(!myUseScalar->isChecked() );
174 }
175