1 // Copyright (C) 2007-2012 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
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_VectorsDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_VectorsDlg.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_InputPane.h"
35 #include "VISU_ColoredPrs3dFactory.hh"
36 #include "VISU_Vectors_i.hh"
37 #include "LightApp_Application.h"
38 #include "SalomeApp_Module.h"
39 #include <SalomeApp_IntSpinBox.h>
40 #include <SalomeApp_DoubleSpinBox.h>
42 #include "SUIT_Desktop.h"
43 #include "SUIT_MessageBox.h"
45 #include <QtxColorButton.h>
48 #include <QColorDialog>
50 #include <QButtonGroup>
52 #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 ScalFact = new SalomeApp_DoubleSpinBox( TopGroup );
95 VISU::initSpinBox( ScalFact, 0., 1.0E+38, .1, "visual_data_precision" );
96 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
97 ScalFact->setValue( 0.1 );
99 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
100 TopGroupLayout->addWidget( ScalFact, 0, 1 );
103 LineWidLabel = new QLabel (tr("LBL_LINE_WIDTH"), TopGroup );
105 LinWid = new SalomeApp_IntSpinBox( TopGroup );
106 LinWid->setAcceptNames( false );
107 LinWid->setMinimum( 1 );
108 LinWid->setMaximum( 10 );
109 LinWid->setSingleStep( 1 );
111 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112 LinWid->setValue( 1 );
114 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
115 TopGroupLayout->addWidget( LinWid, 1, 1 );
118 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), TopGroup);
119 //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
120 SelColor = new QtxColorButton (TopGroup);
121 SelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
122 SelColor->setText( tr("SEL_COLOR_BTN") );
124 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
125 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
126 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
128 TopGroupLayout->addWidget( UseMagn, 2, 0 );
129 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
130 TopGroupLayout->addWidget( SelColor, 2, 1 );
133 UseGlyph = new QCheckBox (tr("USE_GLYPHS_CHK"), TopGroup);
135 TypeGlyph = new QButtonGroup ( TopGroup);
136 TypeGB = new QGroupBox( tr("GLYPH_TYPE_GRP"), TopGroup );
137 //TypeGlyph->setColumnLayout(0, Qt::Vertical );
138 //TypeGlyph->layout()->setSpacing( 0 );
139 //TypeGlyph->layout()->setMargin( 0 );
140 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGB );
141 TypeGlyphLayout->setAlignment( Qt::AlignTop );
142 TypeGlyphLayout->setSpacing( 6 );
143 TypeGlyphLayout->setMargin( 11 );
145 RBArrows = new QRadioButton (tr("ARROWS_BTN"), TypeGB );
146 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
147 RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGB );
148 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
149 RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGB );
150 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
152 TypeGlyph->addButton( RBArrows );
153 TypeGlyph->addButton( RBCones2 );
154 TypeGlyph->addButton( RBCones6 );
156 PosGlyph = new QButtonGroup ( TopGroup );
157 PosGB = new QGroupBox( tr("GLYPH_POSITION_GRP"), TopGroup );
158 //PosGlyph->setColumnLayout(0, Qt::Vertical );
159 //PosGlyph->layout()->setSpacing( 0 );
160 //PosGlyph->layout()->setMargin( 0 );
161 QGridLayout* PosGlyphLayout = new QGridLayout( PosGB );
162 PosGlyphLayout->setAlignment( Qt::AlignTop );
163 PosGlyphLayout->setSpacing( 6 );
164 PosGlyphLayout->setMargin( 11 );
166 RBTail = new QRadioButton (tr("TAIL_BTN" ), PosGB );
167 PosGlyphLayout->addWidget( RBTail, 0, 0 );
168 RBCent = new QRadioButton (tr("CENTER_BTN"), PosGB );
169 PosGlyphLayout->addWidget( RBCent, 1, 0 );
170 RBHead = new QRadioButton (tr("HEAD_BTN" ), PosGB );
171 PosGlyphLayout->addWidget( RBHead, 2, 0 );
173 PosGlyph->addButton( RBTail );
174 PosGlyph->addButton( RBCent );
175 PosGlyph->addButton( RBHead );
177 TopGroupLayout->addWidget( UseGlyph, 3, 0, 1, 3 );
178 TopGroupLayout->addWidget( TypeGB, 4, 0 );
179 TopGroupLayout->addWidget( PosGB, 4, 1, 1, 2 );
181 // Common buttons ===========================================================
182 GroupButtons = new QGroupBox( this );
183 //GroupButtons->setColumnLayout(0, Qt::Vertical );
184 //GroupButtons->layout()->setSpacing( 0 );
185 //GroupButtons->layout()->setMargin( 0 );
186 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
187 GroupButtonsLayout->setAlignment( Qt::AlignTop );
188 GroupButtonsLayout->setSpacing( 6 );
189 GroupButtonsLayout->setMargin( 11 );
191 buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
192 buttonOk->setAutoDefault( TRUE );
193 buttonOk->setDefault( TRUE );
194 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
195 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
196 buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
197 buttonCancel->setAutoDefault( TRUE );
198 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
199 buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
200 buttonHelp->setAutoDefault( TRUE );
201 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
204 myTabBox->addTab(aBox, tr("VISU_VECTORS"));
205 myInputPane = new VisuGUI_InputPane(VISU::TVECTORS, theModule, this);
206 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
207 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
209 TopLayout->addWidget( myTabBox );
210 TopLayout->addWidget( GroupButtons );
212 // signals and slots connections
213 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
214 //connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
215 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
216 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
217 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
218 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
221 UseMagn->setChecked( TRUE );
222 UseGlyph->setChecked( TRUE );
223 RBArrows->setChecked( TRUE );
224 RBTail->setChecked( TRUE );
225 setColor( QColor( 255, 0, 0 ) );
230 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
233 void VisuGUI_VectorsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
237 myPrsCopy = VISU::TSameAsFactory<VISU::TVECTORS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
239 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
241 setScaleFactor(myPrsCopy->GetScale());
242 setLineWidth((int)myPrsCopy->GetLineWidth());
243 setUseMagnColor(myPrsCopy->IsColored());
244 SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
245 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
248 if (myPrsCopy->GetGlyphType() != VISU::Vectors::NONE) {
250 setGlyphType(myPrsCopy->GetGlyphType());
251 setGlyphPos(myPrsCopy->GetGlyphPos());
260 myInputPane->initFromPrsObject( myPrsCopy );
261 myTabBox->setCurrentIndex( 0 );
265 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
267 if(!myInputPane->check() || !GetScalarPane()->check())
270 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
271 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
273 myPrsCopy->SetScale(getScaleFactor());
274 myPrsCopy->SetLineWidth(getLineWidth());
275 myPrsCopy->ShowColored(getUseMagnColor());
276 if(!myPrsCopy->IsColored()){
277 QColor aSelectedColor = SelColor->color();
278 SALOMEDS::Color aColor;
279 aColor.R = aSelectedColor.red()/255.;
280 aColor.G = aSelectedColor.green()/255.;
281 aColor.B = aSelectedColor.blue()/255.;
282 myPrsCopy->SetColor(aColor);
284 if (getUseGlyphs()) {
285 myPrsCopy->SetGlyphPos(getGlyphPos());
286 myPrsCopy->SetGlyphType(getGlyphType());
288 myPrsCopy->SetGlyphType(VISU::Vectors::NONE);
290 VISU::TSameAsFactory<VISU::TVECTORS>().Copy(myPrsCopy, thePrs);
298 Called when "Use glyphs" check box clicked
300 void VisuGUI_VectorsDlg::enableGlyphType()
302 TypeGB->setEnabled( UseGlyph->isChecked() );
303 PosGB->setEnabled( UseGlyph->isChecked() );
307 Called when "Magnitude Coloring" check box clicked
309 void VisuGUI_VectorsDlg::enableSetColor()
311 SelColor->setEnabled(!UseMagn->isChecked() );
312 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
316 Called when "Select Color" buttonx clicked
318 /*void VisuGUI_VectorsDlg::setVColor()
320 QColor cnew = QColorDialog::getColor( myColor, this );
321 if ( cnew.isValid() )
328 void VisuGUI_VectorsDlg::setScaleFactor(double theFactor)
331 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
332 int degree = int(log10(fabs(theFactor))) - 1;
333 if (fabs(theFactor) < 1) {
334 // as logarithm value is negative in this case
335 // and it is truncated to the bigger integer
338 step = pow(10., double(degree));
341 ScalFact->setSingleStep(step);
342 ScalFact->setValue(theFactor);
348 double VisuGUI_VectorsDlg::getScaleFactor()
350 return ScalFact->value();
356 void VisuGUI_VectorsDlg::setLineWidth( int lw )
358 LinWid->setValue( lw );
364 int VisuGUI_VectorsDlg::getLineWidth()
366 return LinWid->value();
370 Sets "Use Magnitude Coloring" flag
372 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
374 UseMagn->setChecked( on );
379 Gets "Use Magnitude Coloring" flag state
381 bool VisuGUI_VectorsDlg::getUseMagnColor()
383 return UseMagn->isChecked();
387 Sets "Use Glyphs" flag
389 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
391 UseGlyph->setChecked( on );
396 Gets "Use Glyphs" flag state
398 bool VisuGUI_VectorsDlg::getUseGlyphs()
400 return UseGlyph->isChecked();
406 void VisuGUI_VectorsDlg::setColor( QColor color )
409 //QPalette aPal = SelColor->palette();
410 //aPal.setColor( SelColor->backgroundRole(), myColor );
411 //SelColor->setPalette( aPal );
412 SelColor->setColor( color );
416 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
418 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
420 if ( type == VISU::Vectors::CONE2)
421 RBCones2->setChecked( true );
422 else if ( type == VISU::Vectors::CONE6)
423 RBCones6->setChecked( true );
425 RBArrows->setChecked( true );
429 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
431 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
433 VISU::Vectors::GlyphType type;
434 if ( RBCones2->isChecked() )
435 type = VISU::Vectors::CONE2;
436 else if ( RBCones6->isChecked() )
437 type = VISU::Vectors::CONE6;
439 type = VISU::Vectors::ARROW;
444 Sets glyph position : -1 - tail, 0 - center, 1 - head
446 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
448 if ( pos == VISU::Vectors::TAIL)
449 RBTail->setChecked(true);
450 else if ( pos == VISU::Vectors::HEAD)
451 RBHead->setChecked(true);
453 RBCent->setChecked(true);
457 Gets glyph position : -1 - tail, 0 - center, 1 - head
459 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
461 VISU::Vectors::GlyphPos pos;
462 if ( RBTail->isChecked() )
463 pos = VISU::Vectors::TAIL;
464 else if ( RBHead->isChecked() )
465 pos = VISU::Vectors::HEAD;
467 pos = VISU::Vectors::CENTER;
472 Enbled/disables magnitude coloring
474 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
476 UseMagn->setEnabled( enable );
480 QString VisuGUI_VectorsDlg::GetContextHelpFilePath()
482 return "vectors_page.html";