]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_VectorsDlg.cxx
Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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
31 #include "VisuGUI.h"
32 //#include "VisuGUI_Selection.h"
33 #include "VisuGUI_Tools.h"
34
35 #include "VISU_Vectors_i.hh"
36 #include "LightApp_Application.h"
37 #include "SalomeApp_Module.h"
38
39 #include "SUIT_Desktop.h"
40 #include "SUIT_MessageBox.h"
41 #include "SUIT_ResourceMgr.h"
42 #include "SUIT_Session.h"
43
44 #include <qlayout.h>
45 #include <qcolordialog.h>
46 #include <qtabwidget.h>
47
48 using namespace std;
49
50 /*!
51   Constructor
52 */
53 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (SalomeApp_Module* theModule)
54     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_VectorsDlg", true,
55       WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
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   QTabWidget* aTabBox = 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   aTabBox->addTab(aBox, "Vectors");
175   myScalarPane = new VisuGUI_ScalarBarPane(this, false);
176   myScalarPane->setMargin( 5 );
177   aTabBox->addTab(myScalarPane, "Scalar Bar");  
178
179   TopLayout->addWidget( aTabBox );
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
201
202 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
203   myScalarPane->initFromPrsObject(thePrs);
204   setScaleFactor(thePrs->GetScale());
205   setLineWidth((int)thePrs->GetLineWidth());
206   setUseMagnColor(thePrs->IsColored());
207   SALOMEDS::Color anOldColor = thePrs->GetColor();
208   QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
209   setColor(aColor);
210   
211   if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
212     setUseGlyphs(true);
213     setGlyphType(thePrs->GetGlyphType());
214     setGlyphPos(thePrs->GetGlyphPos());
215   } else 
216     setUseGlyphs(false);
217
218   enableSetColor();
219 }
220
221
222 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
223   myScalarPane->storeToPrsObject(thePrs);
224   thePrs->SetScale(getScaleFactor());
225   thePrs->SetLineWidth(getLineWidth());
226   thePrs->ShowColored(getUseMagnColor());
227   if(!thePrs->IsColored()){
228     SALOMEDS::Color aColor;
229     aColor.R = myColor.red()/255.;
230     aColor.G = myColor.green()/255.;
231     aColor.B = myColor.blue()/255.;
232     thePrs->SetColor(aColor);
233   }
234   if (getUseGlyphs()) {
235     thePrs->SetGlyphPos(getGlyphPos());
236     thePrs->SetGlyphType(getGlyphType());
237   } else 
238     thePrs->SetGlyphType(VISU::Vectors::NONE);
239   return 1;
240 }
241
242
243
244 /*!
245   Called when "Use glyphs" check box clicked
246 */
247 void VisuGUI_VectorsDlg::enableGlyphType()
248 {
249   TypeGlyph->setEnabled( UseGlyph->isChecked() );
250   PosGlyph->setEnabled( UseGlyph->isChecked() );
251 }
252
253 /*!
254   Called when "Magnitude Coloring" check box clicked
255 */
256 void VisuGUI_VectorsDlg::enableSetColor()
257 {
258   SelColor->setEnabled(!UseMagn->isChecked() );
259   //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
260 }
261
262 /*!
263   Called when "Select Color" buttonx clicked
264 */
265 void VisuGUI_VectorsDlg::setVColor()
266 {
267   QColor cnew = QColorDialog::getColor( myColor, this );
268   if ( cnew.isValid() )
269     setColor( cnew );
270 }
271
272 /*!
273   Sets Scale factor
274 */
275 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
276 {
277   ScalFact->setValue( sf );
278 }
279
280 /*!
281   Gets Scale factor
282 */
283 double VisuGUI_VectorsDlg::getScaleFactor()
284 {
285   return ScalFact->value();
286 }
287
288 /*!
289   Sets Line width
290 */
291 void VisuGUI_VectorsDlg::setLineWidth( int lw )
292 {
293   LinWid->setValue( lw );
294 }
295
296 /*!
297   Gets Line width
298 */
299 int VisuGUI_VectorsDlg::getLineWidth() 
300 {
301   return LinWid->value();
302 }
303
304 /*!
305   Sets "Use Magnitude Coloring" flag
306 */
307 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
308 {
309   UseMagn->setChecked( on );
310   enableSetColor();
311 }
312
313 /*!
314   Gets "Use Magnitude Coloring" flag state
315 */
316 bool VisuGUI_VectorsDlg::getUseMagnColor()
317 {
318   return UseMagn->isChecked();
319 }
320
321 /*!
322   Sets "Use Glyphs" flag
323 */
324 void VisuGUI_VectorsDlg::setUseGlyphs( bool on ) 
325 {
326   UseGlyph->setChecked( on );
327   enableGlyphType();
328 }
329
330 /*!
331   Gets "Use Glyphs" flag state
332 */
333 bool VisuGUI_VectorsDlg::getUseGlyphs()
334 {
335   return UseGlyph->isChecked();
336 }
337
338 /*!
339   Sets color
340 */
341 void VisuGUI_VectorsDlg::setColor( QColor color )
342 {
343   myColor = color;
344   SelColor->setPaletteBackgroundColor(myColor);
345 /*  QPalette pal = ColorLab->palette();
346   QColorGroup ca = pal.active();
347   ca.setColor( QColorGroup::Background, myColor );
348   pal.setActive( ca );
349   ColorLab->setPalette( pal );*/
350 }
351
352 /*!
353   Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
354 */
355 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
356 {
357   if ( type ==  VISU::Vectors::CONE2) 
358     RBCones2->setChecked( true );
359   else if ( type == VISU::Vectors::CONE6)
360     RBCones6->setChecked( true );
361   else
362     RBArrows->setChecked( true );
363 }
364
365 /*!
366   Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
367 */
368 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
369 {
370   VISU::Vectors::GlyphType type;
371   if ( RBCones2->isChecked() )
372     type = VISU::Vectors::CONE2;
373   else if ( RBCones6->isChecked() )
374     type = VISU::Vectors::CONE6;
375   else
376     type = VISU::Vectors::ARROW;
377   return type;
378 }
379
380 /*!
381   Sets glyph position : -1 - tail, 0 - center, 1 - head
382 */
383 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
384 {
385   if ( pos == VISU::Vectors::TAIL) 
386     RBTail->setChecked(true);
387   else if ( pos == VISU::Vectors::HEAD)
388     RBHead->setChecked(true);
389   else
390     RBCent->setChecked(true);
391 }
392
393 /*!
394   Gets glyph position : -1 - tail, 0 - center, 1 - head
395 */
396 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
397 {
398   VISU::Vectors::GlyphPos pos;
399   if ( RBTail->isChecked() )
400     pos = VISU::Vectors::TAIL;
401   else if ( RBHead->isChecked() )
402     pos = VISU::Vectors::HEAD;
403   else
404     pos = VISU::Vectors::CENTER;
405   return pos;
406 }
407
408 /*!
409   Enbled/disables magnitude coloring
410 */
411 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
412 {
413   UseMagn->setEnabled( enable );
414   enableSetColor();
415 }
416
417
418 void VisuGUI_VectorsDlg::accept() {
419   if (myScalarPane->check()) 
420     {
421       myScalarPane->deletePreview();
422       QDialog::accept();
423     }
424 }
425
426 void VisuGUI_VectorsDlg::reject()
427 {
428   myScalarPane->deletePreview();
429   QDialog::reject();
430 }
431
432 void VisuGUI_VectorsDlg::onHelp()
433 {
434   QString aHelpFileName = "/files/vectors_presentation.htm";
435   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
436   if (app) {
437     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
438     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
439   }
440   else {
441     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
442                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
443                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
444                            QObject::tr("BUT_OK"));
445   }
446 }