2 // File : VisuGUI_VectorsDlg.cxx
3 // Created : Wed Aug 01 10:23:06 2001
4 // Author : Laurent CORNABE & Hubert ROLLAND
7 // Copyright : PRINCIPIA
10 #include "VisuGUI_VectorsDlg.h"
12 #include <qcolordialog.h>
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
19 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
20 : QDialog( QAD_Application::getDesktop(), "VisuGUI_VectorsDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
22 setCaption( tr( "Vector Field Representation" ) );
23 setSizeGripEnabled( TRUE );
25 QVBoxLayout* TopLayout = new QVBoxLayout( this );
26 TopLayout->setSpacing( 6 );
27 TopLayout->setMargin( 11 );
29 TopGroup = new QButtonGroup( this, "TopGroup" );
30 TopGroup->setColumnLayout(0, Qt::Vertical );
31 TopGroup->layout()->setSpacing( 0 );
32 TopGroup->layout()->setMargin( 0 );
33 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
34 TopGroupLayout->setAlignment( Qt::AlignTop );
35 TopGroupLayout->setSpacing( 6 );
36 TopGroupLayout->setMargin( 11 );
39 ScaleLabel = new QLabel( tr( "Scale factor:" ), TopGroup, "ScaleLabel" );
41 ScalFact = new QAD_SpinBoxDbl( TopGroup, 1e-20, 1.0E+38, 0.1, 5);
42 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
43 ScalFact->setValue( 0.1 );
45 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
46 TopGroupLayout->addWidget( ScalFact, 0, 1 );
49 LineWidLabel = new QLabel( tr( "Line width:" ), TopGroup, "LineWidLabel" );
51 LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
52 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
53 LinWid->setValue( 1 );
55 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
56 TopGroupLayout->addWidget( LinWid, 1, 1 );
59 UseMagn = new QCheckBox( tr( "Magnitude coloring" ), TopGroup, "UseMagn" );
60 UseMagn->setText( tr( "Magnitude coloring" ) );
61 SelColor = new QPushButton( tr( "Select Color" ), TopGroup, "SelColor" );
63 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
64 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
65 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
67 TopGroupLayout->addWidget( UseMagn, 2, 0 );
68 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
69 TopGroupLayout->addWidget( SelColor, 2, 1 );
72 UseGlyph = new QCheckBox( tr( "Use glyphs" ), TopGroup, "UseGlyph" );
74 TypeGlyph = new QButtonGroup( tr( "Glyph type" ), TopGroup, "TypeGlyph" );
75 TypeGlyph->setColumnLayout(0, Qt::Vertical );
76 TypeGlyph->layout()->setSpacing( 0 );
77 TypeGlyph->layout()->setMargin( 0 );
78 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
79 TypeGlyphLayout->setAlignment( Qt::AlignTop );
80 TypeGlyphLayout->setSpacing( 6 );
81 TypeGlyphLayout->setMargin( 11 );
83 RBArrows = new QRadioButton( tr( "Arrows" ), TypeGlyph, "RBArrows" );
84 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
85 RBCones2 = new QRadioButton( tr( "Cones (2)" ), TypeGlyph, "RBCones2" );
86 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
87 RBCones6 = new QRadioButton( tr( "Cones (6)" ), TypeGlyph, "RBCones6" );
88 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
90 PosGlyph = new QButtonGroup( tr( "Glyph position" ), TopGroup, "PosGlyph" );
91 PosGlyph->setColumnLayout(0, Qt::Vertical );
92 PosGlyph->layout()->setSpacing( 0 );
93 PosGlyph->layout()->setMargin( 0 );
94 QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
95 PosGlyphLayout->setAlignment( Qt::AlignTop );
96 PosGlyphLayout->setSpacing( 6 );
97 PosGlyphLayout->setMargin( 11 );
99 RBTail = new QRadioButton( tr( "Tail" ), PosGlyph, "RBTail" );
100 PosGlyphLayout->addWidget( RBTail, 0, 0 );
101 RBCent = new QRadioButton( tr( "Center" ), PosGlyph, "RBCent" );
102 PosGlyphLayout->addWidget( RBCent, 1, 0 );
103 RBHead = new QRadioButton( tr( "Head" ), PosGlyph, "RBHead" );
104 PosGlyphLayout->addWidget( RBHead, 2, 0 );
106 TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
107 TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
108 TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
110 // Common buttons ===========================================================
111 GroupButtons = new QGroupBox( this, "GroupButtons" );
112 GroupButtons->setColumnLayout(0, Qt::Vertical );
113 GroupButtons->layout()->setSpacing( 0 );
114 GroupButtons->layout()->setMargin( 0 );
115 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
116 GroupButtonsLayout->setAlignment( Qt::AlignTop );
117 GroupButtonsLayout->setSpacing( 6 );
118 GroupButtonsLayout->setMargin( 11 );
120 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
121 buttonOk->setAutoDefault( TRUE );
122 buttonOk->setDefault( TRUE );
123 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
124 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
125 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
126 buttonCancel->setAutoDefault( TRUE );
127 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
130 TopLayout->addWidget( TopGroup );
131 TopLayout->addWidget( GroupButtons );
133 // signals and slots connections
134 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
135 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
136 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
137 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
138 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
141 UseMagn->setChecked( TRUE );
142 UseGlyph->setChecked( TRUE );
143 RBArrows->setChecked( TRUE );
144 RBTail->setChecked( TRUE );
145 setColor( QColor( 255, 0, 0 ) );
153 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
158 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
159 setScaleFactor(thePrs->GetScale());
160 setLineWidth(thePrs->GetLineWidth());
161 setUseMagnColor(thePrs->isColored());
162 setColor(QColor(thePrs->GetColor()[0]*255,
163 thePrs->GetColor()[1]*255,
164 thePrs->GetColor()[2]*255));
166 if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
168 setGlyphType(thePrs->GetGlyphType());
169 setGlyphPos(thePrs->GetGlyphPos());
177 void VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
178 thePrs->SetScale(getScaleFactor());
179 thePrs->SetLineWidth(getLineWidth());
180 thePrs->setColored(getUseMagnColor());
183 aColor[0] = myColor.red()/255.;
184 aColor[1] = myColor.green()/255.;
185 aColor[2] = myColor.blue()/255.;
187 thePrs->SetColor(aColor);
189 if (getUseGlyphs()) {
190 thePrs->SetGlyphPos(getGlyphPos());
191 thePrs->SetGlyphType(getGlyphType());
193 thePrs->SetGlyphType(VISU::Vectors::NONE);
199 Called when "Use glyphs" check box clicked
201 void VisuGUI_VectorsDlg::enableGlyphType()
203 TypeGlyph->setEnabled( UseGlyph->isChecked() );
204 PosGlyph->setEnabled( UseGlyph->isChecked() );
208 Called when "Magnitude Coloring" check box clicked
210 void VisuGUI_VectorsDlg::enableSetColor()
212 SelColor->setEnabled(!UseMagn->isChecked() );
213 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
217 Called when "Select Color" buttonx clicked
219 void VisuGUI_VectorsDlg::setVColor()
221 QColor cnew = QColorDialog::getColor( myColor, this );
222 if ( cnew.isValid() )
229 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
231 ScalFact->setValue( sf );
237 double VisuGUI_VectorsDlg::getScaleFactor()
239 return ScalFact->value();
245 void VisuGUI_VectorsDlg::setLineWidth( int lw )
247 LinWid->setValue( lw );
253 int VisuGUI_VectorsDlg::getLineWidth()
255 return LinWid->value();
259 Sets "Use Magnitude Coloring" flag
261 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
263 UseMagn->setChecked( on );
268 Gets "Use Magnitude Coloring" flag state
270 bool VisuGUI_VectorsDlg::getUseMagnColor()
272 return UseMagn->isChecked();
276 Sets "Use Glyphs" flag
278 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
280 UseGlyph->setChecked( on );
285 Gets "Use Glyphs" flag state
287 bool VisuGUI_VectorsDlg::getUseGlyphs()
289 return UseGlyph->isChecked();
295 void VisuGUI_VectorsDlg::setColor( QColor color )
298 SelColor->setPaletteBackgroundColor(myColor);
299 /* QPalette pal = ColorLab->palette();
300 QColorGroup ca = pal.active();
301 ca.setColor( QColorGroup::Background, myColor );
303 ColorLab->setPalette( pal );*/
307 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
309 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
311 if ( type == VISU::Vectors::CONE2)
312 RBCones2->setChecked( true );
313 else if ( type == VISU::Vectors::CONE6)
314 RBCones6->setChecked( true );
316 RBArrows->setChecked( true );
320 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
322 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
324 VISU::Vectors::GlyphType type;
325 if ( RBCones2->isChecked() )
326 type = VISU::Vectors::CONE2;
327 else if ( RBCones6->isChecked() )
328 type = VISU::Vectors::CONE6;
330 type = VISU::Vectors::ARROW;
335 Sets glyph position : -1 - tail, 0 - center, 1 - head
337 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
339 if ( pos == VISU::Vectors::TAIL)
340 RBTail->setChecked(true);
341 else if ( pos == VISU::Vectors::HEAD)
342 RBHead->setChecked(true);
344 RBCent->setChecked(true);
348 Gets glyph position : -1 - tail, 0 - center, 1 - head
350 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
352 VISU::Vectors::GlyphPos pos;
353 if ( RBTail->isChecked() )
354 pos = VISU::Vectors::TAIL;
355 else if ( RBHead->isChecked() )
356 pos = VISU::Vectors::HEAD;
358 pos = VISU::Vectors::CENTER;
363 Enbled/disables magnitude coloring
365 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
367 UseMagn->setEnabled( enable );