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