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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : VisuGUI_VectorsDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_VectorsDlg.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_InputPane.h"
35 #include "VISU_ColoredPrs3dFactory.hh"
36 #include "VISU_Vectors_i.hh"
37 #include "LightApp_Application.h"
38 #include "SalomeApp_Module.h"
40 #include "SUIT_Desktop.h"
41 #include "SUIT_MessageBox.h"
42 #include "SUIT_ResourceMgr.h"
43 #include "SUIT_Session.h"
46 #include <qcolordialog.h>
47 #include <qtabwidget.h>
54 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (SalomeApp_Module* theModule)
55 : VisuGUI_ScalarBarBaseDlg(theModule)
57 setCaption(tr("DLG_TITLE"));
58 setSizeGripEnabled(TRUE);
60 QVBoxLayout* TopLayout = new QVBoxLayout( this );
61 TopLayout->setSpacing( 6 );
62 TopLayout->setMargin( 11 );
64 myTabBox = new QTabWidget(this);
66 QVBox* aBox = new QVBox(this);
67 aBox->setMargin( 11 );
69 TopGroup = new QButtonGroup( aBox, "TopGroup" );
70 TopGroup->setColumnLayout(0, Qt::Vertical );
71 TopGroup->layout()->setSpacing( 0 );
72 TopGroup->layout()->setMargin( 5 );
73 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
74 TopGroupLayout->setAlignment( Qt::AlignTop );
75 TopGroupLayout->setSpacing( 6 );
76 TopGroupLayout->setMargin( 11 );
79 ScaleLabel = new QLabel (tr("LBL_SCALE_FACTOR"), TopGroup, "ScaleLabel");
81 ScalFact = new QtxDblSpinBox( 1e-20, 1.0E+38, 0.1, TopGroup );
82 ScalFact->setPrecision( 5 );
83 ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
84 ScalFact->setValue( 0.1 );
86 TopGroupLayout->addWidget( ScaleLabel, 0, 0 );
87 TopGroupLayout->addWidget( ScalFact, 0, 1 );
90 LineWidLabel = new QLabel (tr("LBL_LINE_WIDTH"), TopGroup, "LineWidLabel");
92 LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
93 LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 LinWid->setValue( 1 );
96 TopGroupLayout->addWidget( LineWidLabel, 1, 0 );
97 TopGroupLayout->addWidget( LinWid, 1, 1 );
100 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), TopGroup, "UseMagn");
101 //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
102 SelColor = new QPushButton (tr("SEL_COLOR_BTN"), TopGroup, "SelColor");
104 /* ColorLab = new QLabel( TopGroup, "ColorLab" );
105 ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
106 ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
108 TopGroupLayout->addWidget( UseMagn, 2, 0 );
109 //TopGroupLayout->addWidget( ColorLab, 2, 1 );
110 TopGroupLayout->addWidget( SelColor, 2, 1 );
113 UseGlyph = new QCheckBox (tr("USE_GLYPHS_CHK"), TopGroup, "UseGlyph");
115 TypeGlyph = new QButtonGroup (tr("GLYPH_TYPE_GRP"), TopGroup, "TypeGlyph");
116 TypeGlyph->setColumnLayout(0, Qt::Vertical );
117 TypeGlyph->layout()->setSpacing( 0 );
118 TypeGlyph->layout()->setMargin( 0 );
119 QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
120 TypeGlyphLayout->setAlignment( Qt::AlignTop );
121 TypeGlyphLayout->setSpacing( 6 );
122 TypeGlyphLayout->setMargin( 11 );
124 RBArrows = new QRadioButton (tr("ARROWS_BTN") , TypeGlyph, "RBArrows");
125 TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
126 RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGlyph, "RBCones2");
127 TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
128 RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGlyph, "RBCones6");
129 TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
131 PosGlyph = new QButtonGroup (tr("GLYPH_POSITION_GRP"), TopGroup, "PosGlyph");
132 PosGlyph->setColumnLayout(0, Qt::Vertical );
133 PosGlyph->layout()->setSpacing( 0 );
134 PosGlyph->layout()->setMargin( 0 );
135 QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
136 PosGlyphLayout->setAlignment( Qt::AlignTop );
137 PosGlyphLayout->setSpacing( 6 );
138 PosGlyphLayout->setMargin( 11 );
140 RBTail = new QRadioButton (tr("TAIL_BTN" ), PosGlyph, "RBTail");
141 PosGlyphLayout->addWidget( RBTail, 0, 0 );
142 RBCent = new QRadioButton (tr("CENTER_BTN"), PosGlyph, "RBCent");
143 PosGlyphLayout->addWidget( RBCent, 1, 0 );
144 RBHead = new QRadioButton (tr("HEAD_BTN" ), PosGlyph, "RBHead");
145 PosGlyphLayout->addWidget( RBHead, 2, 0 );
147 TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
148 TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
149 TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
151 // Common buttons ===========================================================
152 GroupButtons = new QGroupBox( this, "GroupButtons" );
153 GroupButtons->setColumnLayout(0, Qt::Vertical );
154 GroupButtons->layout()->setSpacing( 0 );
155 GroupButtons->layout()->setMargin( 0 );
156 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
157 GroupButtonsLayout->setAlignment( Qt::AlignTop );
158 GroupButtonsLayout->setSpacing( 6 );
159 GroupButtonsLayout->setMargin( 11 );
161 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
162 buttonOk->setAutoDefault( TRUE );
163 buttonOk->setDefault( TRUE );
164 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
165 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
166 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
167 buttonCancel->setAutoDefault( TRUE );
168 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
169 buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
170 buttonHelp->setAutoDefault( TRUE );
171 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
174 myTabBox->addTab(aBox, "Vectors");
175 myInputPane = new VisuGUI_InputPane(VISU::TVECTORS, theModule, this);
176 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
177 myTabBox->addTab(myInputPane, "Input");
179 TopLayout->addWidget( myTabBox );
180 TopLayout->addWidget( GroupButtons );
182 // signals and slots connections
183 connect( UseGlyph, SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
184 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
185 connect( UseMagn, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
186 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
187 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
188 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
191 UseMagn->setChecked( TRUE );
192 UseGlyph->setChecked( TRUE );
193 RBArrows->setChecked( TRUE );
194 RBTail->setChecked( TRUE );
195 setColor( QColor( 255, 0, 0 ) );
200 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
203 void VisuGUI_VectorsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
207 myPrsCopy = VISU::TSameAsFactory<VISU::TVECTORS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
209 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
211 setScaleFactor(myPrsCopy->GetScale());
212 setLineWidth((int)myPrsCopy->GetLineWidth());
213 setUseMagnColor(myPrsCopy->IsColored());
214 SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
215 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
218 if (myPrsCopy->GetGlyphType() != VISU::Vectors::NONE) {
220 setGlyphType(myPrsCopy->GetGlyphType());
221 setGlyphPos(myPrsCopy->GetGlyphPos());
230 myInputPane->initFromPrsObject( myPrsCopy );
231 myTabBox->setCurrentPage( 0 );
235 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
237 if(!myInputPane->check() || !GetScalarPane()->check())
240 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
241 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
243 myPrsCopy->SetScale(getScaleFactor());
244 myPrsCopy->SetLineWidth(getLineWidth());
245 myPrsCopy->ShowColored(getUseMagnColor());
246 if(!myPrsCopy->IsColored()){
247 SALOMEDS::Color aColor;
248 aColor.R = myColor.red()/255.;
249 aColor.G = myColor.green()/255.;
250 aColor.B = myColor.blue()/255.;
251 myPrsCopy->SetColor(aColor);
253 if (getUseGlyphs()) {
254 myPrsCopy->SetGlyphPos(getGlyphPos());
255 myPrsCopy->SetGlyphType(getGlyphType());
257 myPrsCopy->SetGlyphType(VISU::Vectors::NONE);
259 VISU::TSameAsFactory<VISU::TVECTORS>().Copy(myPrsCopy, thePrs);
267 Called when "Use glyphs" check box clicked
269 void VisuGUI_VectorsDlg::enableGlyphType()
271 TypeGlyph->setEnabled( UseGlyph->isChecked() );
272 PosGlyph->setEnabled( UseGlyph->isChecked() );
276 Called when "Magnitude Coloring" check box clicked
278 void VisuGUI_VectorsDlg::enableSetColor()
280 SelColor->setEnabled(!UseMagn->isChecked() );
281 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
285 Called when "Select Color" buttonx clicked
287 void VisuGUI_VectorsDlg::setVColor()
289 QColor cnew = QColorDialog::getColor( myColor, this );
290 if ( cnew.isValid() )
297 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
299 ScalFact->setValue( sf );
305 double VisuGUI_VectorsDlg::getScaleFactor()
307 return ScalFact->value();
313 void VisuGUI_VectorsDlg::setLineWidth( int lw )
315 LinWid->setValue( lw );
321 int VisuGUI_VectorsDlg::getLineWidth()
323 return LinWid->value();
327 Sets "Use Magnitude Coloring" flag
329 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
331 UseMagn->setChecked( on );
336 Gets "Use Magnitude Coloring" flag state
338 bool VisuGUI_VectorsDlg::getUseMagnColor()
340 return UseMagn->isChecked();
344 Sets "Use Glyphs" flag
346 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
348 UseGlyph->setChecked( on );
353 Gets "Use Glyphs" flag state
355 bool VisuGUI_VectorsDlg::getUseGlyphs()
357 return UseGlyph->isChecked();
363 void VisuGUI_VectorsDlg::setColor( QColor color )
366 SelColor->setPaletteBackgroundColor(myColor);
367 /* QPalette pal = ColorLab->palette();
368 QColorGroup ca = pal.active();
369 ca.setColor( QColorGroup::Background, myColor );
371 ColorLab->setPalette( pal );*/
375 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
377 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
379 if ( type == VISU::Vectors::CONE2)
380 RBCones2->setChecked( true );
381 else if ( type == VISU::Vectors::CONE6)
382 RBCones6->setChecked( true );
384 RBArrows->setChecked( true );
388 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
390 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
392 VISU::Vectors::GlyphType type;
393 if ( RBCones2->isChecked() )
394 type = VISU::Vectors::CONE2;
395 else if ( RBCones6->isChecked() )
396 type = VISU::Vectors::CONE6;
398 type = VISU::Vectors::ARROW;
403 Sets glyph position : -1 - tail, 0 - center, 1 - head
405 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
407 if ( pos == VISU::Vectors::TAIL)
408 RBTail->setChecked(true);
409 else if ( pos == VISU::Vectors::HEAD)
410 RBHead->setChecked(true);
412 RBCent->setChecked(true);
416 Gets glyph position : -1 - tail, 0 - center, 1 - head
418 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
420 VISU::Vectors::GlyphPos pos;
421 if ( RBTail->isChecked() )
422 pos = VISU::Vectors::TAIL;
423 else if ( RBHead->isChecked() )
424 pos = VISU::Vectors::HEAD;
426 pos = VISU::Vectors::CENTER;
431 Enbled/disables magnitude coloring
433 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
435 UseMagn->setEnabled( enable );
440 QString VisuGUI_VectorsDlg::GetContextHelpFilePath()
442 return "vectors_page.html";