Salome HOME
Improve english localization
[modules/visu.git] / src / VISUGUI / VisuGUI_VectorsDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VisuGUI_VectorsDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND 
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_VectorsDlg.h"
30 #include "VISU_Vectors_i.hh"
31 #include "VisuGUI.h"
32 #include "VisuGUI_Selection.h"
33
34 #include <qlayout.h>
35 #include <qcolordialog.h>
36 #include <qtabwidget.h>
37
38 using namespace std;
39
40 /*!
41   Constructor
42 */
43 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (QWidget* parent)
44     : QDialog(parent, "VisuGUI_VectorsDlg", true,
45       WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 {
47   setCaption(tr("DLG_TITLE"));
48   setSizeGripEnabled(TRUE);
49
50   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
51   TopLayout->setSpacing( 6 );
52   TopLayout->setMargin( 11 );
53
54   QTabWidget* aTabBox = new QTabWidget(this);
55
56   QVBox* aBox = new QVBox(this);
57   aBox->setMargin( 11 );
58
59   TopGroup = new QButtonGroup( aBox, "TopGroup" );
60   TopGroup->setColumnLayout(0, Qt::Vertical );
61   TopGroup->layout()->setSpacing( 0 );
62   TopGroup->layout()->setMargin( 5 );
63   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
64   TopGroupLayout->setAlignment( Qt::AlignTop );
65   TopGroupLayout->setSpacing( 6 );
66   TopGroupLayout->setMargin( 11 );
67
68   // Scale factor
69   ScaleLabel = new QLabel (tr("LBL_SCALE_FACTOR"), TopGroup, "ScaleLabel");
70
71   ScalFact = new QtxDblSpinBox( 1e-20, 1.0E+38, 0.1, TopGroup );
72   ScalFact->setPrecision( 5 );
73   ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
74   ScalFact->setValue( 0.1 );
75
76   TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
77   TopGroupLayout->addWidget( ScalFact, 0, 1 );
78
79   // Line width
80   LineWidLabel = new QLabel (tr("LBL_LINE_WIDTH"), TopGroup, "LineWidLabel");
81
82   LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
83   LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
84   LinWid->setValue( 1 );
85
86   TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
87   TopGroupLayout->addWidget( LinWid, 1, 1 );
88
89   // Color
90   UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), TopGroup, "UseMagn");
91   //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
92   SelColor = new QPushButton (tr("SEL_COLOR_BTN"), TopGroup, "SelColor");
93
94   /*  ColorLab = new QLabel( TopGroup, "ColorLab" );
95   ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
96   ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
97   */
98   TopGroupLayout->addWidget( UseMagn,  2, 0 );
99   //TopGroupLayout->addWidget( ColorLab, 2, 1 );
100   TopGroupLayout->addWidget( SelColor, 2, 1 );
101
102   // Gliphs
103   UseGlyph = new QCheckBox (tr("USE_GLYPHS_CHK"), TopGroup, "UseGlyph");
104   
105   TypeGlyph = new QButtonGroup (tr("GLYPH_TYPE_GRP"), TopGroup, "TypeGlyph");
106   TypeGlyph->setColumnLayout(0, Qt::Vertical );
107   TypeGlyph->layout()->setSpacing( 0 );
108   TypeGlyph->layout()->setMargin( 0 );
109   QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
110   TypeGlyphLayout->setAlignment( Qt::AlignTop );
111   TypeGlyphLayout->setSpacing( 6 );
112   TypeGlyphLayout->setMargin( 11 );
113
114   RBArrows = new QRadioButton (tr("ARROWS_BTN") , TypeGlyph, "RBArrows");
115   TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
116   RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGlyph, "RBCones2");
117   TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
118   RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGlyph, "RBCones6");
119   TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
120
121   PosGlyph = new QButtonGroup (tr("GLYPH_POSITION_GRP"), TopGroup, "PosGlyph");
122   PosGlyph->setColumnLayout(0, Qt::Vertical );
123   PosGlyph->layout()->setSpacing( 0 );
124   PosGlyph->layout()->setMargin( 0 );
125   QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
126   PosGlyphLayout->setAlignment( Qt::AlignTop );
127   PosGlyphLayout->setSpacing( 6 );
128   PosGlyphLayout->setMargin( 11 );
129   
130   RBTail = new QRadioButton (tr("TAIL_BTN"  ), PosGlyph, "RBTail");
131   PosGlyphLayout->addWidget( RBTail, 0, 0 );
132   RBCent = new QRadioButton (tr("CENTER_BTN"), PosGlyph, "RBCent");
133   PosGlyphLayout->addWidget( RBCent, 1, 0 );
134   RBHead = new QRadioButton (tr("HEAD_BTN"  ), PosGlyph, "RBHead");
135   PosGlyphLayout->addWidget( RBHead, 2, 0 );
136
137   TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
138   TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
139   TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
140
141   // Common buttons ===========================================================
142   GroupButtons = new QGroupBox( this, "GroupButtons" );
143   GroupButtons->setColumnLayout(0, Qt::Vertical );
144   GroupButtons->layout()->setSpacing( 0 );
145   GroupButtons->layout()->setMargin( 0 );
146   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
147   GroupButtonsLayout->setAlignment( Qt::AlignTop );
148   GroupButtonsLayout->setSpacing( 6 );
149   GroupButtonsLayout->setMargin( 11 );
150
151   buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
152   buttonOk->setAutoDefault( TRUE );
153   buttonOk->setDefault( TRUE );
154   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
155   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
156   buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
157   buttonCancel->setAutoDefault( TRUE );
158   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
159
160   // top layout
161   aTabBox->addTab(aBox, "Vectors");
162   myScalarPane = new VisuGUI_ScalarBarPane(this, false);
163   myScalarPane->setMargin( 5 );
164   aTabBox->addTab(myScalarPane, "Scalar Bar");  
165
166   TopLayout->addWidget( aTabBox );
167   TopLayout->addWidget( GroupButtons );
168   
169   // signals and slots connections
170   connect( UseGlyph,     SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
171   connect( SelColor,     SIGNAL( clicked() ), this, SLOT( setVColor() ) );
172   connect( UseMagn,      SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
173   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
174   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
175   
176   // default values
177   UseMagn->setChecked( TRUE );
178   UseGlyph->setChecked( TRUE );
179   RBArrows->setChecked( TRUE );
180   RBTail->setChecked( TRUE );
181   setColor( QColor( 255, 0, 0 ) );
182   enableGlyphType();
183   enableSetColor();
184 }
185
186
187
188 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
189   myScalarPane->initFromPrsObject(thePrs);
190   setScaleFactor(thePrs->GetScale());
191   setLineWidth((int)thePrs->GetLineWidth());
192   setUseMagnColor(thePrs->IsColored());
193   SALOMEDS::Color anOldColor = thePrs->GetColor();
194   QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
195   setColor(aColor);
196   
197   if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
198     setUseGlyphs(true);
199     setGlyphType(thePrs->GetGlyphType());
200     setGlyphPos(thePrs->GetGlyphPos());
201   } else 
202     setUseGlyphs(false);
203
204   enableSetColor();
205 }
206
207
208 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
209   myScalarPane->storeToPrsObject(thePrs);
210   thePrs->SetScale(getScaleFactor());
211   thePrs->SetLineWidth(getLineWidth());
212   thePrs->ShowColored(getUseMagnColor());
213   if(!thePrs->IsColored()){
214     SALOMEDS::Color aColor;
215     aColor.R = myColor.red()/255.;
216     aColor.G = myColor.green()/255.;
217     aColor.B = myColor.blue()/255.;
218     thePrs->SetColor(aColor);
219   }
220   if (getUseGlyphs()) {
221     thePrs->SetGlyphPos(getGlyphPos());
222     thePrs->SetGlyphType(getGlyphType());
223   } else 
224     thePrs->SetGlyphType(VISU::Vectors::NONE);
225   return 1;
226 }
227
228
229
230 /*!
231   Called when "Use glyphs" check box clicked
232 */
233 void VisuGUI_VectorsDlg::enableGlyphType()
234 {
235   TypeGlyph->setEnabled( UseGlyph->isChecked() );
236   PosGlyph->setEnabled( UseGlyph->isChecked() );
237 }
238
239 /*!
240   Called when "Magnitude Coloring" check box clicked
241 */
242 void VisuGUI_VectorsDlg::enableSetColor()
243 {
244   SelColor->setEnabled(!UseMagn->isChecked() );
245   //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
246 }
247
248 /*!
249   Called when "Select Color" buttonx clicked
250 */
251 void VisuGUI_VectorsDlg::setVColor()
252 {
253   QColor cnew = QColorDialog::getColor( myColor, this );
254   if ( cnew.isValid() )
255     setColor( cnew );
256 }
257
258 /*!
259   Sets Scale factor
260 */
261 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
262 {
263   ScalFact->setValue( sf );
264 }
265
266 /*!
267   Gets Scale factor
268 */
269 double VisuGUI_VectorsDlg::getScaleFactor()
270 {
271   return ScalFact->value();
272 }
273
274 /*!
275   Sets Line width
276 */
277 void VisuGUI_VectorsDlg::setLineWidth( int lw )
278 {
279   LinWid->setValue( lw );
280 }
281
282 /*!
283   Gets Line width
284 */
285 int VisuGUI_VectorsDlg::getLineWidth() 
286 {
287   return LinWid->value();
288 }
289
290 /*!
291   Sets "Use Magnitude Coloring" flag
292 */
293 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
294 {
295   UseMagn->setChecked( on );
296   enableSetColor();
297 }
298
299 /*!
300   Gets "Use Magnitude Coloring" flag state
301 */
302 bool VisuGUI_VectorsDlg::getUseMagnColor()
303 {
304   return UseMagn->isChecked();
305 }
306
307 /*!
308   Sets "Use Glyphs" flag
309 */
310 void VisuGUI_VectorsDlg::setUseGlyphs( bool on ) 
311 {
312   UseGlyph->setChecked( on );
313   enableGlyphType();
314 }
315
316 /*!
317   Gets "Use Glyphs" flag state
318 */
319 bool VisuGUI_VectorsDlg::getUseGlyphs()
320 {
321   return UseGlyph->isChecked();
322 }
323
324 /*!
325   Sets color
326 */
327 void VisuGUI_VectorsDlg::setColor( QColor color )
328 {
329   myColor = color;
330   SelColor->setPaletteBackgroundColor(myColor);
331 /*  QPalette pal = ColorLab->palette();
332   QColorGroup ca = pal.active();
333   ca.setColor( QColorGroup::Background, myColor );
334   pal.setActive( ca );
335   ColorLab->setPalette( pal );*/
336 }
337
338 /*!
339   Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
340 */
341 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
342 {
343   if ( type ==  VISU::Vectors::CONE2) 
344     RBCones2->setChecked( true );
345   else if ( type == VISU::Vectors::CONE6)
346     RBCones6->setChecked( true );
347   else
348     RBArrows->setChecked( true );
349 }
350
351 /*!
352   Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
353 */
354 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
355 {
356   VISU::Vectors::GlyphType type;
357   if ( RBCones2->isChecked() )
358     type = VISU::Vectors::CONE2;
359   else if ( RBCones6->isChecked() )
360     type = VISU::Vectors::CONE6;
361   else
362     type = VISU::Vectors::ARROW;
363   return type;
364 }
365
366 /*!
367   Sets glyph position : -1 - tail, 0 - center, 1 - head
368 */
369 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
370 {
371   if ( pos == VISU::Vectors::TAIL) 
372     RBTail->setChecked(true);
373   else if ( pos == VISU::Vectors::HEAD)
374     RBHead->setChecked(true);
375   else
376     RBCent->setChecked(true);
377 }
378
379 /*!
380   Gets glyph position : -1 - tail, 0 - center, 1 - head
381 */
382 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
383 {
384   VISU::Vectors::GlyphPos pos;
385   if ( RBTail->isChecked() )
386     pos = VISU::Vectors::TAIL;
387   else if ( RBHead->isChecked() )
388     pos = VISU::Vectors::HEAD;
389   else
390     pos = VISU::Vectors::CENTER;
391   return pos;
392 }
393
394 /*!
395   Enbled/disables magnitude coloring
396 */
397 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
398 {
399   UseMagn->setEnabled( enable );
400   enableSetColor();
401 }
402
403
404 void VisuGUI_VectorsDlg::accept() {
405   if (myScalarPane->check())  QDialog::accept();
406 }
407