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"
32 //#include "VisuGUI_Selection.h"
33 #include "VisuGUI_Tools.h"
35 #include "VISU_Vectors_i.hh"
37 #include "SalomeApp_Module.h"
38 #include "SUIT_Desktop.h"
41 #include <qcolordialog.h>
42 #include <qtabwidget.h>
49 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (SalomeApp_Module* theModule)
50 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_VectorsDlg", true,
51 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 setCaption(tr("DLG_TITLE"));
54 setSizeGripEnabled(TRUE);
56 QVBoxLayout* TopLayout = new QVBoxLayout( this );
57 TopLayout->setSpacing( 6 );
58 TopLayout->setMargin( 11 );
60 QTabWidget* aTabBox = new QTabWidget(this);
62 QVBox* aBox = new QVBox(this);
63 aBox->setMargin( 11 );
65 TopGroup = new QButtonGroup( aBox, "TopGroup" );
66 TopGroup->setColumnLayout(0, Qt::Vertical );
67 TopGroup->layout()->setSpacing( 0 );
68 TopGroup->layout()->setMargin( 5 );
69 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
70 TopGroupLayout->setAlignment( Qt::AlignTop );
71 TopGroupLayout->setSpacing( 6 );
72 TopGroupLayout->setMargin( 11 );
75 ScaleLabel = new QLabel (tr("LBL_SCALE_FACTOR"), TopGroup, "ScaleLabel");
77 ScalFact = new QtxDblSpinBox( 1e-20, 1.0E+38, 0.1, TopGroup );
78 ScalFact->setPrecision( 5 );
79 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80 ScalFact->setValue( 0.1 );
82 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
83 TopGroupLayout->addWidget( ScalFact, 0, 1 );
86 LineWidLabel = new QLabel (tr("LBL_LINE_WIDTH"), TopGroup, "LineWidLabel");
88 LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
89 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 LinWid->setValue( 1 );
92 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
93 TopGroupLayout->addWidget( LinWid, 1, 1 );
96 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), TopGroup, "UseMagn");
97 //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
98 SelColor = new QPushButton (tr("SEL_COLOR_BTN"), TopGroup, "SelColor");
100 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
101 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
102 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
104 TopGroupLayout->addWidget( UseMagn, 2, 0 );
105 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
106 TopGroupLayout->addWidget( SelColor, 2, 1 );
109 UseGlyph = new QCheckBox (tr("USE_GLYPHS_CHK"), TopGroup, "UseGlyph");
111 TypeGlyph = new QButtonGroup (tr("GLYPH_TYPE_GRP"), TopGroup, "TypeGlyph");
112 TypeGlyph->setColumnLayout(0, Qt::Vertical );
113 TypeGlyph->layout()->setSpacing( 0 );
114 TypeGlyph->layout()->setMargin( 0 );
115 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
116 TypeGlyphLayout->setAlignment( Qt::AlignTop );
117 TypeGlyphLayout->setSpacing( 6 );
118 TypeGlyphLayout->setMargin( 11 );
120 RBArrows = new QRadioButton (tr("ARROWS_BTN") , TypeGlyph, "RBArrows");
121 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
122 RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGlyph, "RBCones2");
123 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
124 RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGlyph, "RBCones6");
125 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
127 PosGlyph = new QButtonGroup (tr("GLYPH_POSITION_GRP"), TopGroup, "PosGlyph");
128 PosGlyph->setColumnLayout(0, Qt::Vertical );
129 PosGlyph->layout()->setSpacing( 0 );
130 PosGlyph->layout()->setMargin( 0 );
131 QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
132 PosGlyphLayout->setAlignment( Qt::AlignTop );
133 PosGlyphLayout->setSpacing( 6 );
134 PosGlyphLayout->setMargin( 11 );
136 RBTail = new QRadioButton (tr("TAIL_BTN" ), PosGlyph, "RBTail");
137 PosGlyphLayout->addWidget( RBTail, 0, 0 );
138 RBCent = new QRadioButton (tr("CENTER_BTN"), PosGlyph, "RBCent");
139 PosGlyphLayout->addWidget( RBCent, 1, 0 );
140 RBHead = new QRadioButton (tr("HEAD_BTN" ), PosGlyph, "RBHead");
141 PosGlyphLayout->addWidget( RBHead, 2, 0 );
143 TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
144 TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
145 TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
147 // Common buttons ===========================================================
148 GroupButtons = new QGroupBox( this, "GroupButtons" );
149 GroupButtons->setColumnLayout(0, Qt::Vertical );
150 GroupButtons->layout()->setSpacing( 0 );
151 GroupButtons->layout()->setMargin( 0 );
152 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
153 GroupButtonsLayout->setAlignment( Qt::AlignTop );
154 GroupButtonsLayout->setSpacing( 6 );
155 GroupButtonsLayout->setMargin( 11 );
157 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
158 buttonOk->setAutoDefault( TRUE );
159 buttonOk->setDefault( TRUE );
160 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
161 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
162 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
163 buttonCancel->setAutoDefault( TRUE );
164 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
167 aTabBox->addTab(aBox, "Vectors");
168 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
169 myScalarPane->setMargin( 5 );
170 aTabBox->addTab(myScalarPane, "Scalar Bar");
172 TopLayout->addWidget( aTabBox );
173 TopLayout->addWidget( GroupButtons );
175 // signals and slots connections
176 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
177 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
178 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
179 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
180 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
183 UseMagn->setChecked( TRUE );
184 UseGlyph->setChecked( TRUE );
185 RBArrows->setChecked( TRUE );
186 RBTail->setChecked( TRUE );
187 setColor( QColor( 255, 0, 0 ) );
194 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
195 myScalarPane->initFromPrsObject(thePrs);
196 setScaleFactor(thePrs->GetScale());
197 setLineWidth((int)thePrs->GetLineWidth());
198 setUseMagnColor(thePrs->IsColored());
199 SALOMEDS::Color anOldColor = thePrs->GetColor();
200 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
203 if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
205 setGlyphType(thePrs->GetGlyphType());
206 setGlyphPos(thePrs->GetGlyphPos());
214 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
215 myScalarPane->storeToPrsObject(thePrs);
216 thePrs->SetScale(getScaleFactor());
217 thePrs->SetLineWidth(getLineWidth());
218 thePrs->ShowColored(getUseMagnColor());
219 if(!thePrs->IsColored()){
220 SALOMEDS::Color aColor;
221 aColor.R = myColor.red()/255.;
222 aColor.G = myColor.green()/255.;
223 aColor.B = myColor.blue()/255.;
224 thePrs->SetColor(aColor);
226 if (getUseGlyphs()) {
227 thePrs->SetGlyphPos(getGlyphPos());
228 thePrs->SetGlyphType(getGlyphType());
230 thePrs->SetGlyphType(VISU::Vectors::NONE);
237 Called when "Use glyphs" check box clicked
239 void VisuGUI_VectorsDlg::enableGlyphType()
241 TypeGlyph->setEnabled( UseGlyph->isChecked() );
242 PosGlyph->setEnabled( UseGlyph->isChecked() );
246 Called when "Magnitude Coloring" check box clicked
248 void VisuGUI_VectorsDlg::enableSetColor()
250 SelColor->setEnabled(!UseMagn->isChecked() );
251 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
255 Called when "Select Color" buttonx clicked
257 void VisuGUI_VectorsDlg::setVColor()
259 QColor cnew = QColorDialog::getColor( myColor, this );
260 if ( cnew.isValid() )
267 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
269 ScalFact->setValue( sf );
275 double VisuGUI_VectorsDlg::getScaleFactor()
277 return ScalFact->value();
283 void VisuGUI_VectorsDlg::setLineWidth( int lw )
285 LinWid->setValue( lw );
291 int VisuGUI_VectorsDlg::getLineWidth()
293 return LinWid->value();
297 Sets "Use Magnitude Coloring" flag
299 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
301 UseMagn->setChecked( on );
306 Gets "Use Magnitude Coloring" flag state
308 bool VisuGUI_VectorsDlg::getUseMagnColor()
310 return UseMagn->isChecked();
314 Sets "Use Glyphs" flag
316 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
318 UseGlyph->setChecked( on );
323 Gets "Use Glyphs" flag state
325 bool VisuGUI_VectorsDlg::getUseGlyphs()
327 return UseGlyph->isChecked();
333 void VisuGUI_VectorsDlg::setColor( QColor color )
336 SelColor->setPaletteBackgroundColor(myColor);
337 /* QPalette pal = ColorLab->palette();
338 QColorGroup ca = pal.active();
339 ca.setColor( QColorGroup::Background, myColor );
341 ColorLab->setPalette( pal );*/
345 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
347 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
349 if ( type == VISU::Vectors::CONE2)
350 RBCones2->setChecked( true );
351 else if ( type == VISU::Vectors::CONE6)
352 RBCones6->setChecked( true );
354 RBArrows->setChecked( true );
358 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
360 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
362 VISU::Vectors::GlyphType type;
363 if ( RBCones2->isChecked() )
364 type = VISU::Vectors::CONE2;
365 else if ( RBCones6->isChecked() )
366 type = VISU::Vectors::CONE6;
368 type = VISU::Vectors::ARROW;
373 Sets glyph position : -1 - tail, 0 - center, 1 - head
375 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
377 if ( pos == VISU::Vectors::TAIL)
378 RBTail->setChecked(true);
379 else if ( pos == VISU::Vectors::HEAD)
380 RBHead->setChecked(true);
382 RBCent->setChecked(true);
386 Gets glyph position : -1 - tail, 0 - center, 1 - head
388 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
390 VISU::Vectors::GlyphPos pos;
391 if ( RBTail->isChecked() )
392 pos = VISU::Vectors::TAIL;
393 else if ( RBHead->isChecked() )
394 pos = VISU::Vectors::HEAD;
396 pos = VISU::Vectors::CENTER;
401 Enbled/disables magnitude coloring
403 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
405 UseMagn->setEnabled( enable );
410 void VisuGUI_VectorsDlg::accept() {
411 if (myScalarPane->check()) QDialog::accept();