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
30 #include "VisuGUI_VectorsDlg.h"
32 #include <qcolordialog.h>
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
39 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
40 : QDialog( QAD_Application::getDesktop(), "VisuGUI_VectorsDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
42 setCaption( tr( "Vector Field Representation" ) );
43 setSizeGripEnabled( TRUE );
45 QVBoxLayout* TopLayout = new QVBoxLayout( this );
46 TopLayout->setSpacing( 6 );
47 TopLayout->setMargin( 11 );
49 TopGroup = new QButtonGroup( this, "TopGroup" );
50 TopGroup->setColumnLayout(0, Qt::Vertical );
51 TopGroup->layout()->setSpacing( 0 );
52 TopGroup->layout()->setMargin( 0 );
53 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
54 TopGroupLayout->setAlignment( Qt::AlignTop );
55 TopGroupLayout->setSpacing( 6 );
56 TopGroupLayout->setMargin( 11 );
59 ScaleLabel = new QLabel( tr( "Scale factor:" ), TopGroup, "ScaleLabel" );
61 ScalFact = new QAD_SpinBoxDbl( TopGroup, 1e-20, 1.0E+38, 0.1, 5);
62 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
63 ScalFact->setValue( 0.1 );
65 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
66 TopGroupLayout->addWidget( ScalFact, 0, 1 );
69 LineWidLabel = new QLabel( tr( "Line width:" ), TopGroup, "LineWidLabel" );
71 LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
72 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
73 LinWid->setValue( 1 );
75 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
76 TopGroupLayout->addWidget( LinWid, 1, 1 );
79 UseMagn = new QCheckBox( tr( "Magnitude coloring" ), TopGroup, "UseMagn" );
80 UseMagn->setText( tr( "Magnitude coloring" ) );
81 SelColor = new QPushButton( tr( "Select Color" ), TopGroup, "SelColor" );
83 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
84 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
85 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
87 TopGroupLayout->addWidget( UseMagn, 2, 0 );
88 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
89 TopGroupLayout->addWidget( SelColor, 2, 1 );
92 UseGlyph = new QCheckBox( tr( "Use glyphs" ), TopGroup, "UseGlyph" );
94 TypeGlyph = new QButtonGroup( tr( "Glyph type" ), TopGroup, "TypeGlyph" );
95 TypeGlyph->setColumnLayout(0, Qt::Vertical );
96 TypeGlyph->layout()->setSpacing( 0 );
97 TypeGlyph->layout()->setMargin( 0 );
98 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
99 TypeGlyphLayout->setAlignment( Qt::AlignTop );
100 TypeGlyphLayout->setSpacing( 6 );
101 TypeGlyphLayout->setMargin( 11 );
103 RBArrows = new QRadioButton( tr( "Arrows" ), TypeGlyph, "RBArrows" );
104 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
105 RBCones2 = new QRadioButton( tr( "Cones (2)" ), TypeGlyph, "RBCones2" );
106 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
107 RBCones6 = new QRadioButton( tr( "Cones (6)" ), TypeGlyph, "RBCones6" );
108 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
110 PosGlyph = new QButtonGroup( tr( "Glyph position" ), TopGroup, "PosGlyph" );
111 PosGlyph->setColumnLayout(0, Qt::Vertical );
112 PosGlyph->layout()->setSpacing( 0 );
113 PosGlyph->layout()->setMargin( 0 );
114 QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
115 PosGlyphLayout->setAlignment( Qt::AlignTop );
116 PosGlyphLayout->setSpacing( 6 );
117 PosGlyphLayout->setMargin( 11 );
119 RBTail = new QRadioButton( tr( "Tail" ), PosGlyph, "RBTail" );
120 PosGlyphLayout->addWidget( RBTail, 0, 0 );
121 RBCent = new QRadioButton( tr( "Center" ), PosGlyph, "RBCent" );
122 PosGlyphLayout->addWidget( RBCent, 1, 0 );
123 RBHead = new QRadioButton( tr( "Head" ), PosGlyph, "RBHead" );
124 PosGlyphLayout->addWidget( RBHead, 2, 0 );
126 TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
127 TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
128 TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
130 // Common buttons ===========================================================
131 GroupButtons = new QGroupBox( this, "GroupButtons" );
132 GroupButtons->setColumnLayout(0, Qt::Vertical );
133 GroupButtons->layout()->setSpacing( 0 );
134 GroupButtons->layout()->setMargin( 0 );
135 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
136 GroupButtonsLayout->setAlignment( Qt::AlignTop );
137 GroupButtonsLayout->setSpacing( 6 );
138 GroupButtonsLayout->setMargin( 11 );
140 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
141 buttonOk->setAutoDefault( TRUE );
142 buttonOk->setDefault( TRUE );
143 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
144 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
145 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
146 buttonCancel->setAutoDefault( TRUE );
147 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
150 TopLayout->addWidget( TopGroup );
151 TopLayout->addWidget( GroupButtons );
153 // signals and slots connections
154 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
155 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
156 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
157 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
158 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
161 UseMagn->setChecked( TRUE );
162 UseGlyph->setChecked( TRUE );
163 RBArrows->setChecked( TRUE );
164 RBTail->setChecked( TRUE );
165 setColor( QColor( 255, 0, 0 ) );
173 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
178 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
179 setScaleFactor(thePrs->GetScale());
180 setLineWidth((int)thePrs->GetLineWidth());
181 setUseMagnColor(thePrs->isColored());
182 SALOMEDS::Color anOldColor = thePrs->GetColor();
183 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
186 if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
188 setGlyphType(thePrs->GetGlyphType());
189 setGlyphPos(thePrs->GetGlyphPos());
197 void VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
198 thePrs->SetScale(getScaleFactor());
199 thePrs->SetLineWidth(getLineWidth());
200 thePrs->setColored(getUseMagnColor());
201 if(!thePrs->isColored()){
202 SALOMEDS::Color aColor;
203 aColor.R = myColor.red()/255.;
204 aColor.G = myColor.green()/255.;
205 aColor.B = myColor.blue()/255.;
206 thePrs->SetColor(aColor);
208 if (getUseGlyphs()) {
209 thePrs->SetGlyphPos(getGlyphPos());
210 thePrs->SetGlyphType(getGlyphType());
212 thePrs->SetGlyphType(VISU::Vectors::NONE);
218 Called when "Use glyphs" check box clicked
220 void VisuGUI_VectorsDlg::enableGlyphType()
222 TypeGlyph->setEnabled( UseGlyph->isChecked() );
223 PosGlyph->setEnabled( UseGlyph->isChecked() );
227 Called when "Magnitude Coloring" check box clicked
229 void VisuGUI_VectorsDlg::enableSetColor()
231 SelColor->setEnabled(!UseMagn->isChecked() );
232 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
236 Called when "Select Color" buttonx clicked
238 void VisuGUI_VectorsDlg::setVColor()
240 QColor cnew = QColorDialog::getColor( myColor, this );
241 if ( cnew.isValid() )
248 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
250 ScalFact->setValue( sf );
256 double VisuGUI_VectorsDlg::getScaleFactor()
258 return ScalFact->value();
264 void VisuGUI_VectorsDlg::setLineWidth( int lw )
266 LinWid->setValue( lw );
272 int VisuGUI_VectorsDlg::getLineWidth()
274 return LinWid->value();
278 Sets "Use Magnitude Coloring" flag
280 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
282 UseMagn->setChecked( on );
287 Gets "Use Magnitude Coloring" flag state
289 bool VisuGUI_VectorsDlg::getUseMagnColor()
291 return UseMagn->isChecked();
295 Sets "Use Glyphs" flag
297 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
299 UseGlyph->setChecked( on );
304 Gets "Use Glyphs" flag state
306 bool VisuGUI_VectorsDlg::getUseGlyphs()
308 return UseGlyph->isChecked();
314 void VisuGUI_VectorsDlg::setColor( QColor color )
317 SelColor->setPaletteBackgroundColor(myColor);
318 /* QPalette pal = ColorLab->palette();
319 QColorGroup ca = pal.active();
320 ca.setColor( QColorGroup::Background, myColor );
322 ColorLab->setPalette( pal );*/
326 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
328 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
330 if ( type == VISU::Vectors::CONE2)
331 RBCones2->setChecked( true );
332 else if ( type == VISU::Vectors::CONE6)
333 RBCones6->setChecked( true );
335 RBArrows->setChecked( true );
339 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
341 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
343 VISU::Vectors::GlyphType type;
344 if ( RBCones2->isChecked() )
345 type = VISU::Vectors::CONE2;
346 else if ( RBCones6->isChecked() )
347 type = VISU::Vectors::CONE6;
349 type = VISU::Vectors::ARROW;
354 Sets glyph position : -1 - tail, 0 - center, 1 - head
356 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
358 if ( pos == VISU::Vectors::TAIL)
359 RBTail->setChecked(true);
360 else if ( pos == VISU::Vectors::HEAD)
361 RBHead->setChecked(true);
363 RBCent->setChecked(true);
367 Gets glyph position : -1 - tail, 0 - center, 1 - head
369 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
371 VISU::Vectors::GlyphPos pos;
372 if ( RBTail->isChecked() )
373 pos = VISU::Vectors::TAIL;
374 else if ( RBHead->isChecked() )
375 pos = VISU::Vectors::HEAD;
377 pos = VISU::Vectors::CENTER;
382 Enbled/disables magnitude coloring
384 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
386 UseMagn->setEnabled( enable );