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>
43 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
44 : QDialog( QAD_Application::getDesktop(), "VisuGUI_VectorsDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
46 setCaption( tr( "Vector Field Representation" ) );
47 setSizeGripEnabled( TRUE );
49 QVBoxLayout* TopLayout = new QVBoxLayout( this );
50 TopLayout->setSpacing( 6 );
51 TopLayout->setMargin( 11 );
53 TopGroup = new QButtonGroup( this, "TopGroup" );
54 TopGroup->setColumnLayout(0, Qt::Vertical );
55 TopGroup->layout()->setSpacing( 0 );
56 TopGroup->layout()->setMargin( 0 );
57 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
58 TopGroupLayout->setAlignment( Qt::AlignTop );
59 TopGroupLayout->setSpacing( 6 );
60 TopGroupLayout->setMargin( 11 );
63 ScaleLabel = new QLabel( tr( "Scale factor:" ), TopGroup, "ScaleLabel" );
65 ScalFact = new QAD_SpinBoxDbl( TopGroup, 1e-20, 1.0E+38, 0.1, 5);
66 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
67 ScalFact->setValue( 0.1 );
69 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
70 TopGroupLayout->addWidget( ScalFact, 0, 1 );
73 LineWidLabel = new QLabel( tr( "Line width:" ), TopGroup, "LineWidLabel" );
75 LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
76 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
77 LinWid->setValue( 1 );
79 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
80 TopGroupLayout->addWidget( LinWid, 1, 1 );
83 UseMagn = new QCheckBox( tr( "Magnitude coloring" ), TopGroup, "UseMagn" );
84 UseMagn->setText( tr( "Magnitude coloring" ) );
85 SelColor = new QPushButton( tr( "Select Color" ), TopGroup, "SelColor" );
87 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
88 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
89 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
91 TopGroupLayout->addWidget( UseMagn, 2, 0 );
92 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
93 TopGroupLayout->addWidget( SelColor, 2, 1 );
96 UseGlyph = new QCheckBox( tr( "Use glyphs" ), TopGroup, "UseGlyph" );
98 TypeGlyph = new QButtonGroup( tr( "Glyph type" ), TopGroup, "TypeGlyph" );
99 TypeGlyph->setColumnLayout(0, Qt::Vertical );
100 TypeGlyph->layout()->setSpacing( 0 );
101 TypeGlyph->layout()->setMargin( 0 );
102 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
103 TypeGlyphLayout->setAlignment( Qt::AlignTop );
104 TypeGlyphLayout->setSpacing( 6 );
105 TypeGlyphLayout->setMargin( 11 );
107 RBArrows = new QRadioButton( tr( "Arrows" ), TypeGlyph, "RBArrows" );
108 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
109 RBCones2 = new QRadioButton( tr( "Cones (2)" ), TypeGlyph, "RBCones2" );
110 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
111 RBCones6 = new QRadioButton( tr( "Cones (6)" ), TypeGlyph, "RBCones6" );
112 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
114 PosGlyph = new QButtonGroup( tr( "Glyph position" ), TopGroup, "PosGlyph" );
115 PosGlyph->setColumnLayout(0, Qt::Vertical );
116 PosGlyph->layout()->setSpacing( 0 );
117 PosGlyph->layout()->setMargin( 0 );
118 QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
119 PosGlyphLayout->setAlignment( Qt::AlignTop );
120 PosGlyphLayout->setSpacing( 6 );
121 PosGlyphLayout->setMargin( 11 );
123 RBTail = new QRadioButton( tr( "Tail" ), PosGlyph, "RBTail" );
124 PosGlyphLayout->addWidget( RBTail, 0, 0 );
125 RBCent = new QRadioButton( tr( "Center" ), PosGlyph, "RBCent" );
126 PosGlyphLayout->addWidget( RBCent, 1, 0 );
127 RBHead = new QRadioButton( tr( "Head" ), PosGlyph, "RBHead" );
128 PosGlyphLayout->addWidget( RBHead, 2, 0 );
130 TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
131 TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
132 TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
134 // Common buttons ===========================================================
135 GroupButtons = new QGroupBox( this, "GroupButtons" );
136 GroupButtons->setColumnLayout(0, Qt::Vertical );
137 GroupButtons->layout()->setSpacing( 0 );
138 GroupButtons->layout()->setMargin( 0 );
139 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
140 GroupButtonsLayout->setAlignment( Qt::AlignTop );
141 GroupButtonsLayout->setSpacing( 6 );
142 GroupButtonsLayout->setMargin( 11 );
144 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
145 buttonOk->setAutoDefault( TRUE );
146 buttonOk->setDefault( TRUE );
147 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
148 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
149 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
150 buttonCancel->setAutoDefault( TRUE );
151 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
154 TopLayout->addWidget( TopGroup );
155 TopLayout->addWidget( GroupButtons );
157 // signals and slots connections
158 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
159 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
160 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
161 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
162 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
165 UseMagn->setChecked( TRUE );
166 UseGlyph->setChecked( TRUE );
167 RBArrows->setChecked( TRUE );
168 RBTail->setChecked( TRUE );
169 setColor( QColor( 255, 0, 0 ) );
177 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
182 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
183 setScaleFactor(thePrs->GetScale());
184 setLineWidth((int)thePrs->GetLineWidth());
185 setUseMagnColor(thePrs->IsColored());
186 SALOMEDS::Color anOldColor = thePrs->GetColor();
187 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
190 if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
192 setGlyphType(thePrs->GetGlyphType());
193 setGlyphPos(thePrs->GetGlyphPos());
201 void VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
202 thePrs->SetScale(getScaleFactor());
203 thePrs->SetLineWidth(getLineWidth());
204 thePrs->ShowColored(getUseMagnColor());
205 if(!thePrs->IsColored()){
206 SALOMEDS::Color aColor;
207 aColor.R = myColor.red()/255.;
208 aColor.G = myColor.green()/255.;
209 aColor.B = myColor.blue()/255.;
210 thePrs->SetColor(aColor);
212 if (getUseGlyphs()) {
213 thePrs->SetGlyphPos(getGlyphPos());
214 thePrs->SetGlyphType(getGlyphType());
216 thePrs->SetGlyphType(VISU::Vectors::NONE);
222 Called when "Use glyphs" check box clicked
224 void VisuGUI_VectorsDlg::enableGlyphType()
226 TypeGlyph->setEnabled( UseGlyph->isChecked() );
227 PosGlyph->setEnabled( UseGlyph->isChecked() );
231 Called when "Magnitude Coloring" check box clicked
233 void VisuGUI_VectorsDlg::enableSetColor()
235 SelColor->setEnabled(!UseMagn->isChecked() );
236 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
240 Called when "Select Color" buttonx clicked
242 void VisuGUI_VectorsDlg::setVColor()
244 QColor cnew = QColorDialog::getColor( myColor, this );
245 if ( cnew.isValid() )
252 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
254 ScalFact->setValue( sf );
260 double VisuGUI_VectorsDlg::getScaleFactor()
262 return ScalFact->value();
268 void VisuGUI_VectorsDlg::setLineWidth( int lw )
270 LinWid->setValue( lw );
276 int VisuGUI_VectorsDlg::getLineWidth()
278 return LinWid->value();
282 Sets "Use Magnitude Coloring" flag
284 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
286 UseMagn->setChecked( on );
291 Gets "Use Magnitude Coloring" flag state
293 bool VisuGUI_VectorsDlg::getUseMagnColor()
295 return UseMagn->isChecked();
299 Sets "Use Glyphs" flag
301 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
303 UseGlyph->setChecked( on );
308 Gets "Use Glyphs" flag state
310 bool VisuGUI_VectorsDlg::getUseGlyphs()
312 return UseGlyph->isChecked();
318 void VisuGUI_VectorsDlg::setColor( QColor color )
321 SelColor->setPaletteBackgroundColor(myColor);
322 /* QPalette pal = ColorLab->palette();
323 QColorGroup ca = pal.active();
324 ca.setColor( QColorGroup::Background, myColor );
326 ColorLab->setPalette( pal );*/
330 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
332 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
334 if ( type == VISU::Vectors::CONE2)
335 RBCones2->setChecked( true );
336 else if ( type == VISU::Vectors::CONE6)
337 RBCones6->setChecked( true );
339 RBArrows->setChecked( true );
343 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
345 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
347 VISU::Vectors::GlyphType type;
348 if ( RBCones2->isChecked() )
349 type = VISU::Vectors::CONE2;
350 else if ( RBCones6->isChecked() )
351 type = VISU::Vectors::CONE6;
353 type = VISU::Vectors::ARROW;
358 Sets glyph position : -1 - tail, 0 - center, 1 - head
360 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
362 if ( pos == VISU::Vectors::TAIL)
363 RBTail->setChecked(true);
364 else if ( pos == VISU::Vectors::HEAD)
365 RBHead->setChecked(true);
367 RBCent->setChecked(true);
371 Gets glyph position : -1 - tail, 0 - center, 1 - head
373 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
375 VISU::Vectors::GlyphPos pos;
376 if ( RBTail->isChecked() )
377 pos = VISU::Vectors::TAIL;
378 else if ( RBHead->isChecked() )
379 pos = VISU::Vectors::HEAD;
381 pos = VISU::Vectors::CENTER;
386 Enbled/disables magnitude coloring
388 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
390 UseMagn->setEnabled( enable );