1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_VectorsDlg.cxx
24 // Author : Laurent CORNABE & Hubert ROLLAND
28 #include "VisuGUI_VectorsDlg.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_InputPane.h"
34 #include "VISU_ColoredPrs3dFactory.hh"
35 #include "VISU_Vectors_i.hh"
36 #include "LightApp_Application.h"
37 #include "SalomeApp_Module.h"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_MessageBox.h"
41 #include "SUIT_ResourceMgr.h"
42 #include "SUIT_Session.h"
44 #include <QtxColorButton.h>
47 #include <QColorDialog>
49 #include <QButtonGroup>
51 #include <QRadioButton>
55 #include <QPushButton>
65 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (SalomeApp_Module* theModule)
66 : VisuGUI_ScalarBarBaseDlg(theModule)
68 setWindowTitle(tr("DLG_TITLE"));
69 setSizeGripEnabled(TRUE);
71 QVBoxLayout* TopLayout = new QVBoxLayout( this );
72 TopLayout->setSpacing( 6 );
73 TopLayout->setMargin( 11 );
75 myTabBox = new QTabWidget(this);
77 QWidget* aBox = new QWidget(this);
78 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
79 aVBLay->setMargin( 11 );
81 TopGroup = new QGroupBox( aBox );
82 aVBLay->addWidget( TopGroup );
83 //TopGroup->setColumnLayout(0, Qt::Vertical );
84 //TopGroup->layout()->setSpacing( 0 );
85 //TopGroup->layout()->setMargin( 5 );
86 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup );
87 TopGroupLayout->setAlignment( Qt::AlignTop );
88 TopGroupLayout->setSpacing( 6 );
89 TopGroupLayout->setMargin( 11 );
92 ScaleLabel = new QLabel (tr("LBL_SCALE_FACTOR"), TopGroup );
94 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
95 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
97 ScalFact = new QtxDoubleSpinBox( 0, 1.0E+38, 0.1, aPrecision*(-1), 32, TopGroup );
98 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
99 ScalFact->setValue( 0.1 );
101 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
102 TopGroupLayout->addWidget( ScalFact, 0, 1 );
105 LineWidLabel = new QLabel (tr("LBL_LINE_WIDTH"), TopGroup );
107 LinWid = new QSpinBox( TopGroup );
108 LinWid->setMinimum( 1 );
109 LinWid->setMaximum( 10 );
110 LinWid->setSingleStep( 1 );
112 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
113 LinWid->setValue( 1 );
115 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
116 TopGroupLayout->addWidget( LinWid, 1, 1 );
119 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), TopGroup);
120 //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
121 SelColor = new QtxColorButton (TopGroup);
122 SelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123 SelColor->setText( tr("SEL_COLOR_BTN") );
125 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
126 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
127 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
129 TopGroupLayout->addWidget( UseMagn, 2, 0 );
130 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
131 TopGroupLayout->addWidget( SelColor, 2, 1 );
134 UseGlyph = new QCheckBox (tr("USE_GLYPHS_CHK"), TopGroup);
136 TypeGlyph = new QButtonGroup ( TopGroup);
137 TypeGB = new QGroupBox( tr("GLYPH_TYPE_GRP"), TopGroup );
138 //TypeGlyph->setColumnLayout(0, Qt::Vertical );
139 //TypeGlyph->layout()->setSpacing( 0 );
140 //TypeGlyph->layout()->setMargin( 0 );
141 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGB );
142 TypeGlyphLayout->setAlignment( Qt::AlignTop );
143 TypeGlyphLayout->setSpacing( 6 );
144 TypeGlyphLayout->setMargin( 11 );
146 RBArrows = new QRadioButton (tr("ARROWS_BTN"), TypeGB );
147 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
148 RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGB );
149 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
150 RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGB );
151 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
153 TypeGlyph->addButton( RBArrows );
154 TypeGlyph->addButton( RBCones2 );
155 TypeGlyph->addButton( RBCones6 );
157 PosGlyph = new QButtonGroup ( TopGroup );
158 PosGB = new QGroupBox( tr("GLYPH_POSITION_GRP"), TopGroup );
159 //PosGlyph->setColumnLayout(0, Qt::Vertical );
160 //PosGlyph->layout()->setSpacing( 0 );
161 //PosGlyph->layout()->setMargin( 0 );
162 QGridLayout* PosGlyphLayout = new QGridLayout( PosGB );
163 PosGlyphLayout->setAlignment( Qt::AlignTop );
164 PosGlyphLayout->setSpacing( 6 );
165 PosGlyphLayout->setMargin( 11 );
167 RBTail = new QRadioButton (tr("TAIL_BTN" ), PosGB );
168 PosGlyphLayout->addWidget( RBTail, 0, 0 );
169 RBCent = new QRadioButton (tr("CENTER_BTN"), PosGB );
170 PosGlyphLayout->addWidget( RBCent, 1, 0 );
171 RBHead = new QRadioButton (tr("HEAD_BTN" ), PosGB );
172 PosGlyphLayout->addWidget( RBHead, 2, 0 );
174 PosGlyph->addButton( RBTail );
175 PosGlyph->addButton( RBCent );
176 PosGlyph->addButton( RBHead );
178 TopGroupLayout->addWidget( UseGlyph, 3, 0, 1, 3 );
179 TopGroupLayout->addWidget( TypeGB, 4, 0 );
180 TopGroupLayout->addWidget( PosGB, 4, 1, 1, 2 );
182 // Common buttons ===========================================================
183 GroupButtons = new QGroupBox( this );
184 //GroupButtons->setColumnLayout(0, Qt::Vertical );
185 //GroupButtons->layout()->setSpacing( 0 );
186 //GroupButtons->layout()->setMargin( 0 );
187 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
188 GroupButtonsLayout->setAlignment( Qt::AlignTop );
189 GroupButtonsLayout->setSpacing( 6 );
190 GroupButtonsLayout->setMargin( 11 );
192 buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
193 buttonOk->setAutoDefault( TRUE );
194 buttonOk->setDefault( TRUE );
195 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
196 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
197 buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
198 buttonCancel->setAutoDefault( TRUE );
199 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
200 buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
201 buttonHelp->setAutoDefault( TRUE );
202 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
205 myTabBox->addTab(aBox, "Vectors");
206 myInputPane = new VisuGUI_InputPane(VISU::TVECTORS, theModule, this);
207 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
208 myTabBox->addTab(myInputPane, "Input");
210 TopLayout->addWidget( myTabBox );
211 TopLayout->addWidget( GroupButtons );
213 // signals and slots connections
214 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
215 //connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
216 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
217 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
218 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
219 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
222 UseMagn->setChecked( TRUE );
223 UseGlyph->setChecked( TRUE );
224 RBArrows->setChecked( TRUE );
225 RBTail->setChecked( TRUE );
226 setColor( QColor( 255, 0, 0 ) );
231 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
234 void VisuGUI_VectorsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
238 myPrsCopy = VISU::TSameAsFactory<VISU::TVECTORS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
240 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
242 setScaleFactor(myPrsCopy->GetScale());
243 setLineWidth((int)myPrsCopy->GetLineWidth());
244 setUseMagnColor(myPrsCopy->IsColored());
245 SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
246 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
249 if (myPrsCopy->GetGlyphType() != VISU::Vectors::NONE) {
251 setGlyphType(myPrsCopy->GetGlyphType());
252 setGlyphPos(myPrsCopy->GetGlyphPos());
261 myInputPane->initFromPrsObject( myPrsCopy );
262 myTabBox->setCurrentIndex( 0 );
266 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
268 if(!myInputPane->check() || !GetScalarPane()->check())
271 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
272 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
274 myPrsCopy->SetScale(getScaleFactor());
275 myPrsCopy->SetLineWidth(getLineWidth());
276 myPrsCopy->ShowColored(getUseMagnColor());
277 if(!myPrsCopy->IsColored()){
278 QColor aSelectedColor = SelColor->color();
279 SALOMEDS::Color aColor;
280 aColor.R = aSelectedColor.red()/255.;
281 aColor.G = aSelectedColor.green()/255.;
282 aColor.B = aSelectedColor.blue()/255.;
283 myPrsCopy->SetColor(aColor);
285 if (getUseGlyphs()) {
286 myPrsCopy->SetGlyphPos(getGlyphPos());
287 myPrsCopy->SetGlyphType(getGlyphType());
289 myPrsCopy->SetGlyphType(VISU::Vectors::NONE);
291 VISU::TSameAsFactory<VISU::TVECTORS>().Copy(myPrsCopy, thePrs);
299 Called when "Use glyphs" check box clicked
301 void VisuGUI_VectorsDlg::enableGlyphType()
303 TypeGB->setEnabled( UseGlyph->isChecked() );
304 PosGB->setEnabled( UseGlyph->isChecked() );
308 Called when "Magnitude Coloring" check box clicked
310 void VisuGUI_VectorsDlg::enableSetColor()
312 SelColor->setEnabled(!UseMagn->isChecked() );
313 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
317 Called when "Select Color" buttonx clicked
319 /*void VisuGUI_VectorsDlg::setVColor()
321 QColor cnew = QColorDialog::getColor( myColor, this );
322 if ( cnew.isValid() )
329 void VisuGUI_VectorsDlg::setScaleFactor(double theFactor)
332 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
333 int degree = int(log10(fabs(theFactor))) - 1;
334 if (fabs(theFactor) < 1) {
335 // as logarithm value is negative in this case
336 // and it is truncated to the bigger integer
339 step = pow(10., double(degree));
342 ScalFact->setSingleStep(step);
343 ScalFact->setValue(theFactor);
349 double VisuGUI_VectorsDlg::getScaleFactor()
351 return ScalFact->value();
357 void VisuGUI_VectorsDlg::setLineWidth( int lw )
359 LinWid->setValue( lw );
365 int VisuGUI_VectorsDlg::getLineWidth()
367 return LinWid->value();
371 Sets "Use Magnitude Coloring" flag
373 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
375 UseMagn->setChecked( on );
380 Gets "Use Magnitude Coloring" flag state
382 bool VisuGUI_VectorsDlg::getUseMagnColor()
384 return UseMagn->isChecked();
388 Sets "Use Glyphs" flag
390 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
392 UseGlyph->setChecked( on );
397 Gets "Use Glyphs" flag state
399 bool VisuGUI_VectorsDlg::getUseGlyphs()
401 return UseGlyph->isChecked();
407 void VisuGUI_VectorsDlg::setColor( QColor color )
410 //QPalette aPal = SelColor->palette();
411 //aPal.setColor( SelColor->backgroundRole(), myColor );
412 //SelColor->setPalette( aPal );
413 SelColor->setColor( color );
417 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
419 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
421 if ( type == VISU::Vectors::CONE2)
422 RBCones2->setChecked( true );
423 else if ( type == VISU::Vectors::CONE6)
424 RBCones6->setChecked( true );
426 RBArrows->setChecked( true );
430 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
432 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
434 VISU::Vectors::GlyphType type;
435 if ( RBCones2->isChecked() )
436 type = VISU::Vectors::CONE2;
437 else if ( RBCones6->isChecked() )
438 type = VISU::Vectors::CONE6;
440 type = VISU::Vectors::ARROW;
445 Sets glyph position : -1 - tail, 0 - center, 1 - head
447 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
449 if ( pos == VISU::Vectors::TAIL)
450 RBTail->setChecked(true);
451 else if ( pos == VISU::Vectors::HEAD)
452 RBHead->setChecked(true);
454 RBCent->setChecked(true);
458 Gets glyph position : -1 - tail, 0 - center, 1 - head
460 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
462 VISU::Vectors::GlyphPos pos;
463 if ( RBTail->isChecked() )
464 pos = VISU::Vectors::TAIL;
465 else if ( RBHead->isChecked() )
466 pos = VISU::Vectors::HEAD;
468 pos = VISU::Vectors::CENTER;
473 Enbled/disables magnitude coloring
475 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
477 UseMagn->setEnabled( enable );
481 QString VisuGUI_VectorsDlg::GetContextHelpFilePath()
483 return "vectors_page.html";