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