1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_VectorsDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_VectorsDlg.h"
30 #include "VISU_Vectors_i.hh"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
36 #include <qcolordialog.h>
37 #include <qtabwidget.h>
44 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
45 : QDialog( QAD_Application::getDesktop(), "VisuGUI_VectorsDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 setCaption( tr( "Vector Field Representation" ) );
48 setSizeGripEnabled( TRUE );
50 QVBoxLayout* TopLayout = new QVBoxLayout( this );
51 TopLayout->setSpacing( 6 );
52 TopLayout->setMargin( 11 );
54 QTabWidget* aTabBox = new QTabWidget(this);
56 QVBox* aBox = new QVBox(this);
57 aBox->setMargin( 11 );
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 );
69 ScaleLabel = new QLabel( tr( "Scale factor:" ), TopGroup, "ScaleLabel" );
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 );
75 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
76 TopGroupLayout->addWidget( ScalFact, 0, 1 );
79 LineWidLabel = new QLabel( tr( "Line width:" ), TopGroup, "LineWidLabel" );
81 LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
82 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
83 LinWid->setValue( 1 );
85 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
86 TopGroupLayout->addWidget( LinWid, 1, 1 );
89 UseMagn = new QCheckBox( tr( "Magnitude coloring" ), TopGroup, "UseMagn" );
90 UseMagn->setText( tr( "Magnitude coloring" ) );
91 SelColor = new QPushButton( tr( "Select Color" ), TopGroup, "SelColor" );
93 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
94 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
95 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
97 TopGroupLayout->addWidget( UseMagn, 2, 0 );
98 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
99 TopGroupLayout->addWidget( SelColor, 2, 1 );
102 UseGlyph = new QCheckBox( tr( "Use glyphs" ), TopGroup, "UseGlyph" );
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 );
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 );
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 );
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 );
136 TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
137 TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
138 TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
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 );
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 );
160 aTabBox->addTab(aBox, "Vectors");
161 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
162 myScalarPane->setMargin( 5 );
163 aTabBox->addTab(myScalarPane, "Scalar Bar");
165 TopLayout->addWidget( aTabBox );
166 TopLayout->addWidget( GroupButtons );
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() ) );
176 UseMagn->setChecked( TRUE );
177 UseGlyph->setChecked( TRUE );
178 RBArrows->setChecked( TRUE );
179 RBTail->setChecked( TRUE );
180 setColor( QColor( 255, 0, 0 ) );
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));
196 if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
198 setGlyphType(thePrs->GetGlyphType());
199 setGlyphPos(thePrs->GetGlyphPos());
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);
219 if (getUseGlyphs()) {
220 thePrs->SetGlyphPos(getGlyphPos());
221 thePrs->SetGlyphType(getGlyphType());
223 thePrs->SetGlyphType(VISU::Vectors::NONE);
230 Called when "Use glyphs" check box clicked
232 void VisuGUI_VectorsDlg::enableGlyphType()
234 TypeGlyph->setEnabled( UseGlyph->isChecked() );
235 PosGlyph->setEnabled( UseGlyph->isChecked() );
239 Called when "Magnitude Coloring" check box clicked
241 void VisuGUI_VectorsDlg::enableSetColor()
243 SelColor->setEnabled(!UseMagn->isChecked() );
244 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
248 Called when "Select Color" buttonx clicked
250 void VisuGUI_VectorsDlg::setVColor()
252 QColor cnew = QColorDialog::getColor( myColor, this );
253 if ( cnew.isValid() )
260 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
262 ScalFact->setValue( sf );
268 double VisuGUI_VectorsDlg::getScaleFactor()
270 return ScalFact->value();
276 void VisuGUI_VectorsDlg::setLineWidth( int lw )
278 LinWid->setValue( lw );
284 int VisuGUI_VectorsDlg::getLineWidth()
286 return LinWid->value();
290 Sets "Use Magnitude Coloring" flag
292 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
294 UseMagn->setChecked( on );
299 Gets "Use Magnitude Coloring" flag state
301 bool VisuGUI_VectorsDlg::getUseMagnColor()
303 return UseMagn->isChecked();
307 Sets "Use Glyphs" flag
309 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
311 UseGlyph->setChecked( on );
316 Gets "Use Glyphs" flag state
318 bool VisuGUI_VectorsDlg::getUseGlyphs()
320 return UseGlyph->isChecked();
326 void VisuGUI_VectorsDlg::setColor( QColor color )
329 SelColor->setPaletteBackgroundColor(myColor);
330 /* QPalette pal = ColorLab->palette();
331 QColorGroup ca = pal.active();
332 ca.setColor( QColorGroup::Background, myColor );
334 ColorLab->setPalette( pal );*/
338 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
340 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
342 if ( type == VISU::Vectors::CONE2)
343 RBCones2->setChecked( true );
344 else if ( type == VISU::Vectors::CONE6)
345 RBCones6->setChecked( true );
347 RBArrows->setChecked( true );
351 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
353 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
355 VISU::Vectors::GlyphType type;
356 if ( RBCones2->isChecked() )
357 type = VISU::Vectors::CONE2;
358 else if ( RBCones6->isChecked() )
359 type = VISU::Vectors::CONE6;
361 type = VISU::Vectors::ARROW;
366 Sets glyph position : -1 - tail, 0 - center, 1 - head
368 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
370 if ( pos == VISU::Vectors::TAIL)
371 RBTail->setChecked(true);
372 else if ( pos == VISU::Vectors::HEAD)
373 RBHead->setChecked(true);
375 RBCent->setChecked(true);
379 Gets glyph position : -1 - tail, 0 - center, 1 - head
381 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
383 VISU::Vectors::GlyphPos pos;
384 if ( RBTail->isChecked() )
385 pos = VISU::Vectors::TAIL;
386 else if ( RBHead->isChecked() )
387 pos = VISU::Vectors::HEAD;
389 pos = VISU::Vectors::CENTER;
394 Enbled/disables magnitude coloring
396 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
398 UseMagn->setEnabled( enable );
403 void VisuGUI_VectorsDlg::accept() {
404 if (myScalarPane->check()) QDialog::accept();