1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // File : SMESHGUI_PropertiesDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "SMESHGUI_PropertiesDlg.h"
26 #include "SMESH_Actor.h"
31 #include <QHBoxLayout>
34 #include <QtxBiColorTool.h>
35 #include <QtxColorButton.h>
36 #include <QtxIntSpinBox.h>
37 #include <VTKViewer_MarkerWidget.h>
38 #include <SUIT_Session.h>
39 #include <LightApp_Application.h>
42 const int SPACING = 6;
45 \class SMESHGUI_PropertiesDlg
46 \brief Dialog box to set-up mesh presentation properties: colors,
47 sizes of elements, width of lines etc
52 \param customMarkers custom node markers
53 \param parent parent widget
55 SMESHGUI_PropertiesDlg::SMESHGUI_PropertiesDlg( const VTK::MarkerMap& customMarkers, QWidget* parent )
56 : SMESHGUI_Dialog( parent, true, true, Standard )
59 setWindowTitle( tr( "TITLE" ) );
64 int widthLab1 = 0, widthLab2 = 0;
67 myNodeGrp = new QGroupBox( tr( "NODES" ), mainFrame() );
68 QLabel* nodeColorLab = new QLabel( tr( "COLOR" ), myNodeGrp );
69 myNodeColor = new QtxColorButton( myNodeGrp );
70 myNodeMarker = new VTKViewer_MarkerWidget( myNodeGrp );
71 hl = new QHBoxLayout( myNodeGrp );
72 hl->setMargin( MARGIN );
73 hl->setSpacing( SPACING );
74 hl->addWidget( nodeColorLab );
75 hl->addWidget( myNodeColor );
76 hl->addWidget( myNodeMarker );
77 widthLab1 = qMax( widthLab1, nodeColorLab->minimumSizeHint().width() );
78 widthLab2 = qMax( widthLab2, myNodeMarker->typeLabel()->minimumSizeHint().width() );
81 myEdgeGrp = new QGroupBox( tr( "EDGES" ), mainFrame() );
82 QLabel* edgeColorLab = new QLabel( tr( "COLOR" ), myEdgeGrp );
83 myEdgeColor = new QtxColorButton( myEdgeGrp );
84 QLabel* edgeWidthLab = new QLabel( tr( "WIDTH" ), myEdgeGrp );
85 myEdgeWidth = new QtxIntSpinBox( myEdgeGrp );
86 hl = new QHBoxLayout( myEdgeGrp );
87 hl->setMargin( MARGIN );
88 hl->setSpacing( SPACING );
89 hl->addWidget( edgeColorLab );
90 hl->addWidget( myEdgeColor );
91 hl->addWidget( edgeWidthLab );
92 hl->addWidget( myEdgeWidth );
93 widthLab1 = qMax( widthLab1, edgeColorLab->minimumSizeHint().width() );
94 widthLab2 = qMax( widthLab2, edgeWidthLab->minimumSizeHint().width() );
97 myFaceGrp = new QGroupBox( tr( "FACES" ), mainFrame() );
98 QLabel* faceColorLab = new QLabel( tr( "FACE_FRONT" ), myFaceGrp );
99 myFaceColor = new QtxBiColorTool( myFaceGrp );
100 myFaceColor->label()->setText( tr( "FACE_BACK" ) );
101 hl = new QHBoxLayout( myFaceGrp );
102 hl->setMargin( MARGIN );
103 hl->setSpacing( SPACING );
104 hl->addWidget( faceColorLab );
105 hl->addWidget( myFaceColor );
106 widthLab1 = qMax( widthLab1, faceColorLab->minimumSizeHint().width() );
107 widthLab2 = qMax( widthLab2, myFaceColor->label()->minimumSizeHint().width() );
110 myVolumeGrp = new QGroupBox( tr( "VOLUMES" ), mainFrame() );
111 QLabel* volumeColorLab = new QLabel( tr( "VOLUME_NORMAL" ), myVolumeGrp );
112 myVolumeColor = new QtxBiColorTool( myVolumeGrp );
113 myVolumeColor->label()->setText( tr( "VOLUME_REVERSED" ) );
114 hl = new QHBoxLayout( myVolumeGrp );
115 hl->setMargin( MARGIN );
116 hl->setSpacing( SPACING );
117 hl->addWidget( volumeColorLab );
118 hl->addWidget( myVolumeColor );
119 widthLab1 = qMax( widthLab1, volumeColorLab->minimumSizeHint().width() );
120 widthLab2 = qMax( widthLab2, myVolumeColor->label()->minimumSizeHint().width() );
122 // -- outline controls
123 myOutlineGrp = new QGroupBox( tr( "OUTLINES" ), mainFrame() );
124 QLabel* outlineColorLab = new QLabel( tr( "COLOR" ), myOutlineGrp );
125 myOutlineColor = new QtxColorButton( myOutlineGrp );
126 QLabel* outlineWidthLab = new QLabel( tr( "WIDTH" ), myOutlineGrp );
127 myOutlineWidth = new QtxIntSpinBox( myOutlineGrp );
128 hl = new QHBoxLayout( myOutlineGrp );
129 hl->setMargin( MARGIN );
130 hl->setSpacing( SPACING );
131 hl->addWidget( outlineColorLab );
132 hl->addWidget( myOutlineColor );
133 hl->addWidget( outlineWidthLab );
134 hl->addWidget( myOutlineWidth );
135 widthLab1 = qMax( widthLab1, outlineColorLab->minimumSizeHint().width() );
136 widthLab2 = qMax( widthLab2, outlineWidthLab->minimumSizeHint().width() );
138 // -- 0d element controls
139 myElem0dGrp = new QGroupBox( tr( "0D_ELEMENTS" ), mainFrame() );
140 QLabel* elem0dColorLab = new QLabel( tr( "COLOR" ), myElem0dGrp );
141 myElem0dColor = new QtxColorButton( myElem0dGrp );
142 QLabel* elem0dSizeLab = new QLabel( tr( "SIZE" ), myElem0dGrp );
143 myElem0dSize = new QtxIntSpinBox( myElem0dGrp );
144 hl = new QHBoxLayout( myElem0dGrp );
145 hl->setMargin( MARGIN );
146 hl->setSpacing( SPACING );
147 hl->addWidget( elem0dColorLab );
148 hl->addWidget( myElem0dColor );
149 hl->addWidget( elem0dSizeLab );
150 hl->addWidget( myElem0dSize );
151 widthLab1 = qMax( widthLab1, elem0dColorLab->minimumSizeHint().width() );
152 widthLab2 = qMax( widthLab2, elem0dSizeLab->minimumSizeHint().width() );
155 myBallGrp = new QGroupBox( tr( "BALLS" ), mainFrame() );
156 QLabel* ballColorLab = new QLabel( tr( "COLOR" ), myBallGrp );
157 myBallColor = new QtxColorButton( myBallGrp );
158 QLabel* ballSizeLab = new QLabel( tr( "SIZE" ), myBallGrp );
159 myBallSize = new QtxIntSpinBox( myBallGrp );
160 hl = new QHBoxLayout( myBallGrp );
161 hl->setMargin( MARGIN );
162 hl->setSpacing( SPACING );
163 hl->addWidget( ballColorLab );
164 hl->addWidget( myBallColor );
165 hl->addWidget( ballSizeLab );
166 hl->addWidget( myBallSize );
167 widthLab1 = qMax( widthLab1, ballColorLab->minimumSizeHint().width() );
168 widthLab2 = qMax( widthLab2, ballSizeLab->minimumSizeHint().width() );
170 // -- orientation vector controls
171 myOrientationGrp = new QGroupBox( tr( "ORIENTATIONS" ), mainFrame() );
172 QLabel* orientationColorLab = new QLabel( tr( "COLOR" ), myOrientationGrp );
173 myOrientationColor = new QtxColorButton( myOrientationGrp );
174 QLabel* orientationScaleLab = new QLabel( tr( "ORIENTATION_SCALE" ), myOrientationGrp );
175 myOrientationSize = new QtxIntSpinBox( myOrientationGrp );
176 myOrientationSize->setSuffix( "% ");
177 myOrientation3d = new QCheckBox( tr("ORIENTATION_3D"), myOrientationGrp );
178 hl = new QHBoxLayout( myOrientationGrp );
179 hl->setMargin( MARGIN );
180 hl->setSpacing( SPACING );
181 hl->addWidget( orientationColorLab );
182 hl->addWidget( myOrientationColor );
183 hl->addWidget( orientationScaleLab );
184 hl->addWidget( myOrientationSize );
185 hl->addWidget( myOrientation3d );
186 widthLab1 = qMax( widthLab1, orientationColorLab->minimumSizeHint().width() );
187 widthLab2 = qMax( widthLab2, orientationScaleLab->minimumSizeHint().width() );
190 myExtraGrp = new QFrame( mainFrame() );
191 QLabel* shrinkSizeLab = new QLabel( tr( "SHRINK" ), myExtraGrp );
192 myShrinkSize = new QtxIntSpinBox( myExtraGrp );
193 myShrinkSize->setSuffix( "% ");
194 hl = new QHBoxLayout( myExtraGrp );
195 hl->setMargin( MARGIN );
196 hl->setSpacing( SPACING );
197 hl->addWidget( shrinkSizeLab );
198 hl->addWidget( myShrinkSize );
200 widthLab1 = qMax( widthLab1, shrinkSizeLab->minimumSizeHint().width() );
203 QVBoxLayout* vl = new QVBoxLayout( mainFrame() );
205 vl->setSpacing( SPACING );
206 vl->addWidget( myNodeGrp );
207 vl->addWidget( myEdgeGrp );
208 vl->addWidget( myFaceGrp );
209 vl->addWidget( myVolumeGrp );
210 vl->addWidget( myOutlineGrp );
211 vl->addWidget( myElem0dGrp );
212 vl->addWidget( myBallGrp );
213 vl->addWidget( myOrientationGrp );
214 vl->addWidget( myExtraGrp );
216 nodeColorLab->setMinimumWidth( widthLab1 );
217 edgeColorLab->setMinimumWidth( widthLab1 );
218 faceColorLab->setMinimumWidth( widthLab1 );
219 volumeColorLab->setMinimumWidth( widthLab1 );
220 outlineColorLab->setMinimumWidth( widthLab1 );
221 elem0dColorLab->setMinimumWidth( widthLab1 );
222 ballColorLab->setMinimumWidth( widthLab1 );
223 orientationColorLab->setMinimumWidth( widthLab1 );
224 shrinkSizeLab->setMinimumWidth( widthLab1 );
226 myNodeMarker->typeLabel()->setMinimumWidth( widthLab2 );
227 edgeWidthLab->setMinimumWidth( widthLab2 );
228 myFaceColor->label()->setMinimumWidth( widthLab2 );
229 myVolumeColor->label()->setMinimumWidth( widthLab2 );
230 outlineWidthLab->setMinimumWidth( widthLab2 );
231 elem0dSizeLab->setMinimumWidth( widthLab2 );
232 ballSizeLab->setMinimumWidth( widthLab2 );
233 orientationScaleLab->setMinimumWidth( widthLab2 );
235 myEdgeWidth->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
236 myOutlineWidth->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
237 myElem0dSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
238 myBallSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
239 myOrientationSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
240 myShrinkSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
242 // initialize widgets
243 myNodeMarker->setCustomMarkers( customMarkers );
244 myElem0dSize->setRange( 1, 10 );
245 myBallSize->setRange( 1, 10 );
246 myEdgeWidth->setRange( 1, 5 );
247 myOutlineWidth->setRange( 1, 5 );
248 myShrinkSize->setRange( 20, 100 );
249 myOrientationSize->setRange( 5, 100 );
251 button( OK )->setText( tr( "SMESH_BUT_OK" ) );
253 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
257 \brief Destructor: clean-up resources if necessary
259 SMESHGUI_PropertiesDlg::~SMESHGUI_PropertiesDlg()
264 \brief Set nodes color
265 \param color nodes color
267 void SMESHGUI_PropertiesDlg::setNodeColor( const QColor& color )
269 myNodeColor->setColor( color );
273 \brief Get nodes color
274 \return current nodes color
276 QColor SMESHGUI_PropertiesDlg::nodeColor() const
278 return myNodeColor->color();
282 \brief Set standard nodes marker
283 \param type standard nodes marker type
284 \param scale standard nodes marker scale
286 void SMESHGUI_PropertiesDlg::setNodeMarker( VTK::MarkerType type, VTK::MarkerScale scale )
288 myNodeMarker->setMarker( type, scale );
292 \brief Set custom nodes marker
293 \param id custom nodes marker id
295 void SMESHGUI_PropertiesDlg::setNodeCustomMarker( int id )
297 myNodeMarker->setCustomMarker( id );
301 \brief Get nodes marker type.
302 For custom marker, VTK::MT_USER is returned and markerId() function
303 then returns its identifier.
304 \return currently selected nodes marker type
306 VTK::MarkerType SMESHGUI_PropertiesDlg::nodeMarkerType() const
308 return myNodeMarker->markerType();
312 \brief Get nodes marker scale.
313 For custom marker return value is undefined.
314 \return currently selected nodes marker scale
316 VTK::MarkerScale SMESHGUI_PropertiesDlg::nodeMarkerScale() const
318 return myNodeMarker->markerScale();
322 \brief Get custom nodes marker.
323 For standard markers return value is VTK::MT_NONE.
324 \return custom nodes marker id
326 int SMESHGUI_PropertiesDlg::nodeMarkerId() const
328 return myNodeMarker->markerId();
332 \brief Set edges (wireframe) color
333 \param color edges color
335 void SMESHGUI_PropertiesDlg::setEdgeColor( const QColor& color )
337 myEdgeColor->setColor( color );
341 \brief Get edges (wireframe) color
342 \return current edges color
344 QColor SMESHGUI_PropertiesDlg::edgeColor() const
346 return myEdgeColor->color();
350 \brief Set edges width
351 \param width edges width
353 void SMESHGUI_PropertiesDlg::setEdgeWidth( int width )
355 myEdgeWidth->setValue( width );
359 \brief Get edges width
360 \return current edges width
362 int SMESHGUI_PropertiesDlg::edgeWidth() const
364 return myEdgeWidth->value();
368 \brief Set faces colors
369 \param color front faces color
370 \param delta back faces coloring delta
372 void SMESHGUI_PropertiesDlg::setFaceColor( const QColor& color, int delta )
374 myFaceColor->setMainColor( color );
375 myFaceColor->setDelta( delta );
379 \brief Get front faces color
380 \return current front faces color
382 QColor SMESHGUI_PropertiesDlg::faceColor() const
384 return myFaceColor->mainColor();
388 \brief Get back faces coloring delta
389 \return current back faces coloring delta
391 int SMESHGUI_PropertiesDlg::faceColorDelta() const
393 return myFaceColor->delta();
397 \brief Set volumes colors
398 \param color normal volumes color
399 \param delta reversed volumes coloring delta
401 void SMESHGUI_PropertiesDlg::setVolumeColor( const QColor& color, int delta )
403 myVolumeColor->setMainColor( color );
404 myVolumeColor->setDelta( delta );
408 \brief Get normal volumes color
409 \return current normal volumes color
411 QColor SMESHGUI_PropertiesDlg::volumeColor() const
413 return myVolumeColor->mainColor();
417 \brief Get reversed volumes coloring delta
418 \return current reversed volumes coloring delta
420 int SMESHGUI_PropertiesDlg::volumeColorDelta() const
422 return myVolumeColor->delta();
426 \brief Set outlines color
427 \param color outlines color
429 void SMESHGUI_PropertiesDlg::setOutlineColor( const QColor& color )
431 myOutlineColor->setColor( color );
435 \brief Get outlines color
436 \return current outlines color
438 QColor SMESHGUI_PropertiesDlg::outlineColor() const
440 return myOutlineColor->color();
444 \brief Set outlines width
445 \param width outlines width
447 void SMESHGUI_PropertiesDlg::setOutlineWidth( int width )
449 myOutlineWidth->setValue( width );
453 \brief Get outlines width
454 \return current outlines width
456 int SMESHGUI_PropertiesDlg::outlineWidth() const
458 return myOutlineWidth->value();
462 \brief Set 0D elements color
463 \param color 0D elements color
465 void SMESHGUI_PropertiesDlg::setElem0dColor( const QColor& color )
467 myElem0dColor->setColor( color );
471 \brief Get 0D elements color
472 \return current 0D elements color
474 QColor SMESHGUI_PropertiesDlg::elem0dColor() const
476 return myElem0dColor->color();
480 \brief Set 0D elements size
481 \param size 0D elements size
483 void SMESHGUI_PropertiesDlg::setElem0dSize( int size )
485 myElem0dSize->setValue( size );
489 \brief Get 0D elements size
490 \return current 0D elements size
492 int SMESHGUI_PropertiesDlg::elem0dSize() const
494 return myElem0dSize->value();
498 \brief Set discrete elements (balls) color
499 \param color discrete elements (balls) color
501 void SMESHGUI_PropertiesDlg::setBallColor( const QColor& color )
503 myBallColor->setColor( color );
507 \brief Get discrete elements (balls) color
508 \return current discrete elements (balls) color
510 QColor SMESHGUI_PropertiesDlg::ballColor() const
512 return myBallColor->color();
516 \brief Set discrete elements (balls) size
517 \param size discrete elements (balls) size
519 void SMESHGUI_PropertiesDlg::setBallSize( int size )
521 myBallSize->setValue( size );
525 \brief Get discrete elements (balls) size
526 \return current discrete elements (balls) size
528 int SMESHGUI_PropertiesDlg::ballSize() const
530 return myBallSize->value();
534 \brief Set orientation vectors color
535 \param color orientation vectors color
537 void SMESHGUI_PropertiesDlg::setOrientationColor( const QColor& color )
539 myOrientationColor->setColor( color );
543 \brief Get orientation vectors color
544 \return current orientation vectors color
546 QColor SMESHGUI_PropertiesDlg::orientationColor() const
548 return myOrientationColor->color();
552 \brief Set orientation vectors scale (percent)
553 \param scale orientation vectors scale
555 void SMESHGUI_PropertiesDlg::setOrientationSize( int scale )
557 myOrientationSize->setValue( scale );
561 \brief Get orientation vectors scale (percent)
562 \return current orientation vectors scale
564 int SMESHGUI_PropertiesDlg::orientationSize() const
566 return myOrientationSize->value();
570 \brief Set orientation vectors 3d flag
571 \param on orientation vectors 3d flag value
573 void SMESHGUI_PropertiesDlg::setOrientation3d( bool on )
575 myOrientation3d->setChecked( on );
579 \brief Get orientation vectors 3d flag
580 \return orientation vectors 3d flag value
582 bool SMESHGUI_PropertiesDlg::orientation3d() const
584 return myOrientation3d->isChecked();
588 \brief Set shrink coefficient (percent)
589 \param coef shrink coefficient
591 void SMESHGUI_PropertiesDlg::setShrinkCoef( int coef )
593 myShrinkSize->setValue( coef );
597 \brief Get shrink coefficient (percent)
598 \return current shrink coefficient
600 int SMESHGUI_PropertiesDlg::shrinkCoef() const
602 return myShrinkSize->value();
606 \brief Get custom markers
607 \return custom markers map
609 VTK::MarkerMap SMESHGUI_PropertiesDlg::customMarkers() const
611 return myNodeMarker->customMarkers();
615 \brief Show / hide controls for specified entity type
616 \param elements mesh element types (an or-ed combination of flags)
617 \param nodes mesh nodes presence flag
619 void SMESHGUI_PropertiesDlg::showControls( int elements, bool nodes )
621 // node controls are supposed to be shown if at least any element type is present
622 // or if there are only nodes
623 myNodeGrp->setVisible( nodes || elements & SMESH_Actor::eAllEntity );
624 // edge/wireframe controls are needed for edges, faces and volumes
625 myEdgeGrp->setVisible( elements & ( SMESH_Actor::eEdges | SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
626 // face controls are shown only if there are faces
627 myFaceGrp->setVisible( elements & SMESH_Actor::eFaces );
628 // volume controls are shown only if there are volumes
629 myVolumeGrp->setVisible( elements & SMESH_Actor::eVolumes );
630 // 0d elements controls are shown only if there are 0d elements
631 myElem0dGrp->setVisible( elements & SMESH_Actor::e0DElements );
632 // ball controls are shown only if there are balls
633 myBallGrp->setVisible( elements & SMESH_Actor::eBallElem );
634 // outline controls are needed for faces and volumes
635 myOutlineGrp->setVisible( elements & ( SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
636 // orientation controls are needed for faces and volumes
637 myOrientationGrp->setVisible( elements & ( SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
638 // shrink factor is shown if there are edges and/or faces and/or volumes
639 myExtraGrp->setVisible( elements & ( SMESH_Actor::eEdges | SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
643 \brief Show online help on dialog box
645 void SMESHGUI_PropertiesDlg::onHelp()
647 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
648 app->onHelpContextModule( "SMESH", "colors_size_page.html" );