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_Selection.h"
33 #include "VisuGUI_Tools.h"
35 #include "VISU_Vectors_i.hh"
36 #include "LightApp_Application.h"
37 #include "SalomeApp_Module.h"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_MessageBox.h"
41 #include "SUIT_ResourceMgr.h"
42 #include "SUIT_Session.h"
45 #include <qcolordialog.h>
46 #include <qtabwidget.h>
53 VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (SalomeApp_Module* theModule)
54 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_VectorsDlg", true,
55 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 setCaption(tr("DLG_TITLE"));
58 setSizeGripEnabled(TRUE);
60 QVBoxLayout* TopLayout = new QVBoxLayout( this );
61 TopLayout->setSpacing( 6 );
62 TopLayout->setMargin( 11 );
64 QTabWidget* aTabBox = 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 aTabBox->addTab(aBox, "Vectors");
175 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
176 myScalarPane->setMargin( 5 );
177 aTabBox->addTab(myScalarPane, "Scalar Bar");
179 TopLayout->addWidget( aTabBox );
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 ) );
202 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
203 myScalarPane->initFromPrsObject(thePrs);
204 setScaleFactor(thePrs->GetScale());
205 setLineWidth((int)thePrs->GetLineWidth());
206 setUseMagnColor(thePrs->IsColored());
207 SALOMEDS::Color anOldColor = thePrs->GetColor();
208 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
211 if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
213 setGlyphType(thePrs->GetGlyphType());
214 setGlyphPos(thePrs->GetGlyphPos());
222 int VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
223 myScalarPane->storeToPrsObject(thePrs);
224 thePrs->SetScale(getScaleFactor());
225 thePrs->SetLineWidth(getLineWidth());
226 thePrs->ShowColored(getUseMagnColor());
227 if(!thePrs->IsColored()){
228 SALOMEDS::Color aColor;
229 aColor.R = myColor.red()/255.;
230 aColor.G = myColor.green()/255.;
231 aColor.B = myColor.blue()/255.;
232 thePrs->SetColor(aColor);
234 if (getUseGlyphs()) {
235 thePrs->SetGlyphPos(getGlyphPos());
236 thePrs->SetGlyphType(getGlyphType());
238 thePrs->SetGlyphType(VISU::Vectors::NONE);
245 Called when "Use glyphs" check box clicked
247 void VisuGUI_VectorsDlg::enableGlyphType()
249 TypeGlyph->setEnabled( UseGlyph->isChecked() );
250 PosGlyph->setEnabled( UseGlyph->isChecked() );
254 Called when "Magnitude Coloring" check box clicked
256 void VisuGUI_VectorsDlg::enableSetColor()
258 SelColor->setEnabled(!UseMagn->isChecked() );
259 //ColorLab->setEnabled( UseMagn->isEnabled() && !UseMagn->isChecked() );
263 Called when "Select Color" buttonx clicked
265 void VisuGUI_VectorsDlg::setVColor()
267 QColor cnew = QColorDialog::getColor( myColor, this );
268 if ( cnew.isValid() )
275 void VisuGUI_VectorsDlg::setScaleFactor( double sf )
277 ScalFact->setValue( sf );
283 double VisuGUI_VectorsDlg::getScaleFactor()
285 return ScalFact->value();
291 void VisuGUI_VectorsDlg::setLineWidth( int lw )
293 LinWid->setValue( lw );
299 int VisuGUI_VectorsDlg::getLineWidth()
301 return LinWid->value();
305 Sets "Use Magnitude Coloring" flag
307 void VisuGUI_VectorsDlg::setUseMagnColor( bool on )
309 UseMagn->setChecked( on );
314 Gets "Use Magnitude Coloring" flag state
316 bool VisuGUI_VectorsDlg::getUseMagnColor()
318 return UseMagn->isChecked();
322 Sets "Use Glyphs" flag
324 void VisuGUI_VectorsDlg::setUseGlyphs( bool on )
326 UseGlyph->setChecked( on );
331 Gets "Use Glyphs" flag state
333 bool VisuGUI_VectorsDlg::getUseGlyphs()
335 return UseGlyph->isChecked();
341 void VisuGUI_VectorsDlg::setColor( QColor color )
344 SelColor->setPaletteBackgroundColor(myColor);
345 /* QPalette pal = ColorLab->palette();
346 QColorGroup ca = pal.active();
347 ca.setColor( QColorGroup::Background, myColor );
349 ColorLab->setPalette( pal );*/
353 Sets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
355 void VisuGUI_VectorsDlg::setGlyphType(VISU::Vectors::GlyphType type )
357 if ( type == VISU::Vectors::CONE2)
358 RBCones2->setChecked( true );
359 else if ( type == VISU::Vectors::CONE6)
360 RBCones6->setChecked( true );
362 RBArrows->setChecked( true );
366 Gets glyphs type : 0 - arrows, 1 - cones2, 2 - cones6
368 VISU::Vectors::GlyphType VisuGUI_VectorsDlg::getGlyphType()
370 VISU::Vectors::GlyphType type;
371 if ( RBCones2->isChecked() )
372 type = VISU::Vectors::CONE2;
373 else if ( RBCones6->isChecked() )
374 type = VISU::Vectors::CONE6;
376 type = VISU::Vectors::ARROW;
381 Sets glyph position : -1 - tail, 0 - center, 1 - head
383 void VisuGUI_VectorsDlg::setGlyphPos(VISU::Vectors::GlyphPos pos)
385 if ( pos == VISU::Vectors::TAIL)
386 RBTail->setChecked(true);
387 else if ( pos == VISU::Vectors::HEAD)
388 RBHead->setChecked(true);
390 RBCent->setChecked(true);
394 Gets glyph position : -1 - tail, 0 - center, 1 - head
396 VISU::Vectors::GlyphPos VisuGUI_VectorsDlg::getGlyphPos()
398 VISU::Vectors::GlyphPos pos;
399 if ( RBTail->isChecked() )
400 pos = VISU::Vectors::TAIL;
401 else if ( RBHead->isChecked() )
402 pos = VISU::Vectors::HEAD;
404 pos = VISU::Vectors::CENTER;
409 Enbled/disables magnitude coloring
411 void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
413 UseMagn->setEnabled( enable );
418 void VisuGUI_VectorsDlg::accept() {
419 if (myScalarPane->check())
421 myScalarPane->deletePreview();
426 void VisuGUI_VectorsDlg::reject()
428 myScalarPane->deletePreview();
432 void VisuGUI_VectorsDlg::onHelp()
434 QString aHelpFileName = "/files/vectors_presentation.htm";
435 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
437 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
438 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
441 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
442 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
443 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
444 QObject::tr("BUT_OK"));