1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 <QtxDoubleSpinBox.h>
38 #include <VTKViewer_MarkerWidget.h>
39 #include <SUIT_Session.h>
40 #include <LightApp_Application.h>
43 const int SPACING = 6;
46 \class SMESHGUI_PropertiesDlg
47 \brief Dialog box to set-up mesh presentation properties: colors,
48 sizes of elements, width of lines etc
53 \param customMarkers custom node markers
54 \param parent parent widget
56 SMESHGUI_PropertiesDlg::SMESHGUI_PropertiesDlg( const VTK::MarkerMap& customMarkers, QWidget* parent )
57 : SMESHGUI_Dialog( parent, true, true, Standard )
60 setWindowTitle( tr( "TITLE" ) );
65 int widthLab1 = 0, widthLab2 = 0;
68 myNodeGrp = new QGroupBox( tr( "NODES" ), mainFrame() );
69 QLabel* nodeColorLab = new QLabel( tr( "COLOR" ), myNodeGrp );
70 myNodeColor = new QtxColorButton( myNodeGrp );
71 myNodeMarker = new VTKViewer_MarkerWidget( myNodeGrp );
72 hl = new QHBoxLayout( myNodeGrp );
73 hl->setMargin( MARGIN );
74 hl->setSpacing( SPACING );
75 hl->addWidget( nodeColorLab );
76 hl->addWidget( myNodeColor );
77 hl->addWidget( myNodeMarker );
78 widthLab1 = qMax( widthLab1, nodeColorLab->minimumSizeHint().width() );
79 widthLab2 = qMax( widthLab2, myNodeMarker->typeLabel()->minimumSizeHint().width() );
82 myEdgeGrp = new QGroupBox( tr( "EDGES" ), mainFrame() );
83 QLabel* edgeColorLab = new QLabel( tr( "COLOR" ), myEdgeGrp );
84 myEdgeColor = new QtxColorButton( myEdgeGrp );
85 QLabel* edgeWidthLab = new QLabel( tr( "WIDTH" ), myEdgeGrp );
86 myEdgeWidth = new QtxIntSpinBox( myEdgeGrp );
87 hl = new QHBoxLayout( myEdgeGrp );
88 hl->setMargin( MARGIN );
89 hl->setSpacing( SPACING );
90 hl->addWidget( edgeColorLab );
91 hl->addWidget( myEdgeColor );
92 hl->addWidget( edgeWidthLab );
93 hl->addWidget( myEdgeWidth );
94 widthLab1 = qMax( widthLab1, edgeColorLab->minimumSizeHint().width() );
95 widthLab2 = qMax( widthLab2, edgeWidthLab->minimumSizeHint().width() );
98 myFaceGrp = new QGroupBox( tr( "FACES" ), mainFrame() );
99 QLabel* faceColorLab = new QLabel( tr( "FACE_FRONT" ), myFaceGrp );
100 myFaceColor = new QtxBiColorTool( myFaceGrp );
101 myFaceColor->label()->setText( tr( "FACE_BACK" ) );
102 hl = new QHBoxLayout( myFaceGrp );
103 hl->setMargin( MARGIN );
104 hl->setSpacing( SPACING );
105 hl->addWidget( faceColorLab );
106 hl->addWidget( myFaceColor );
107 widthLab1 = qMax( widthLab1, faceColorLab->minimumSizeHint().width() );
108 widthLab2 = qMax( widthLab2, myFaceColor->label()->minimumSizeHint().width() );
111 myVolumeGrp = new QGroupBox( tr( "VOLUMES" ), mainFrame() );
112 QLabel* volumeColorLab = new QLabel( tr( "VOLUME_NORMAL" ), myVolumeGrp );
113 myVolumeColor = new QtxBiColorTool( myVolumeGrp );
114 myVolumeColor->label()->setText( tr( "VOLUME_REVERSED" ) );
115 hl = new QHBoxLayout( myVolumeGrp );
116 hl->setMargin( MARGIN );
117 hl->setSpacing( SPACING );
118 hl->addWidget( volumeColorLab );
119 hl->addWidget( myVolumeColor );
120 widthLab1 = qMax( widthLab1, volumeColorLab->minimumSizeHint().width() );
121 widthLab2 = qMax( widthLab2, myVolumeColor->label()->minimumSizeHint().width() );
123 // -- outline controls
124 myOutlineGrp = new QGroupBox( tr( "OUTLINES" ), mainFrame() );
125 QLabel* outlineColorLab = new QLabel( tr( "COLOR" ), myOutlineGrp );
126 myOutlineColor = new QtxColorButton( myOutlineGrp );
127 QLabel* outlineWidthLab = new QLabel( tr( "WIDTH" ), myOutlineGrp );
128 myOutlineWidth = new QtxIntSpinBox( myOutlineGrp );
129 hl = new QHBoxLayout( myOutlineGrp );
130 hl->setMargin( MARGIN );
131 hl->setSpacing( SPACING );
132 hl->addWidget( outlineColorLab );
133 hl->addWidget( myOutlineColor );
134 hl->addWidget( outlineWidthLab );
135 hl->addWidget( myOutlineWidth );
136 widthLab1 = qMax( widthLab1, outlineColorLab->minimumSizeHint().width() );
137 widthLab2 = qMax( widthLab2, outlineWidthLab->minimumSizeHint().width() );
139 // -- 0d element controls
140 myElem0dGrp = new QGroupBox( tr( "0D_ELEMENTS" ), mainFrame() );
141 QLabel* elem0dColorLab = new QLabel( tr( "COLOR" ), myElem0dGrp );
142 myElem0dColor = new QtxColorButton( myElem0dGrp );
143 QLabel* elem0dSizeLab = new QLabel( tr( "SIZE" ), myElem0dGrp );
144 myElem0dSize = new QtxIntSpinBox( myElem0dGrp );
145 hl = new QHBoxLayout( myElem0dGrp );
146 hl->setMargin( MARGIN );
147 hl->setSpacing( SPACING );
148 hl->addWidget( elem0dColorLab );
149 hl->addWidget( myElem0dColor );
150 hl->addWidget( elem0dSizeLab );
151 hl->addWidget( myElem0dSize );
152 widthLab1 = qMax( widthLab1, elem0dColorLab->minimumSizeHint().width() );
153 widthLab2 = qMax( widthLab2, elem0dSizeLab->minimumSizeHint().width() );
156 myBallGrp = new QGroupBox( tr( "BALLS" ), mainFrame() );
157 QLabel* ballColorLab = new QLabel( tr( "COLOR" ), myBallGrp );
158 myBallColor = new QtxColorButton( myBallGrp );
159 // QLabel* ballSizeLab = new QLabel( tr( "SIZE" ), myBallGrp );
160 // myBallSize = new QtxIntSpinBox( myBallGrp );
161 QLabel* ballScaleLab = new QLabel( tr( "SCALE_FACTOR" ), myBallGrp );
162 myBallScale = new QtxDoubleSpinBox( 1e-2, 1e7, 0.5, myBallGrp );
163 hl = new QHBoxLayout( myBallGrp );
164 hl->setMargin( MARGIN );
165 hl->setSpacing( SPACING );
166 hl->addWidget( ballColorLab );
167 hl->addWidget( myBallColor );
168 // hl->addWidget( ballSizeLab );
169 // hl->addWidget( myBallSize );
170 hl->addWidget( ballScaleLab );
171 hl->addWidget( myBallScale );
172 widthLab1 = qMax( widthLab1, ballColorLab->minimumSizeHint().width() );
173 // widthLab2 = qMax( widthLab2, ballSizeLab->minimumSizeHint().width() );
175 // -- orientation vector controls
176 myOrientationGrp = new QGroupBox( tr( "ORIENTATIONS" ), mainFrame() );
177 QLabel* orientationColorLab = new QLabel( tr( "COLOR" ), myOrientationGrp );
178 myOrientationColor = new QtxColorButton( myOrientationGrp );
179 QLabel* orientationScaleLab = new QLabel( tr( "SCALE_FACTOR" ), myOrientationGrp );
180 myOrientationSize = new QtxIntSpinBox( myOrientationGrp );
181 myOrientationSize->setSuffix( "% ");
182 myOrientation3d = new QCheckBox( tr("ORIENTATION_3D"), myOrientationGrp );
183 hl = new QHBoxLayout( myOrientationGrp );
184 hl->setMargin( MARGIN );
185 hl->setSpacing( SPACING );
186 hl->addWidget( orientationColorLab );
187 hl->addWidget( myOrientationColor );
188 hl->addWidget( orientationScaleLab );
189 hl->addWidget( myOrientationSize );
190 hl->addWidget( myOrientation3d );
191 widthLab1 = qMax( widthLab1, orientationColorLab->minimumSizeHint().width() );
192 widthLab2 = qMax( widthLab2, orientationScaleLab->minimumSizeHint().width() );
195 myExtraGrp = new QFrame( mainFrame() );
196 QLabel* shrinkSizeLab = new QLabel( tr( "SHRINK" ), myExtraGrp );
197 myShrinkSize = new QtxIntSpinBox( myExtraGrp );
198 myShrinkSize->setSuffix( "% ");
199 hl = new QHBoxLayout( myExtraGrp );
200 hl->setMargin( MARGIN );
201 hl->setSpacing( SPACING );
202 hl->addWidget( shrinkSizeLab );
203 hl->addWidget( myShrinkSize );
205 widthLab1 = qMax( widthLab1, shrinkSizeLab->minimumSizeHint().width() );
208 QVBoxLayout* vl = new QVBoxLayout( mainFrame() );
210 vl->setSpacing( SPACING );
211 vl->addWidget( myNodeGrp );
212 vl->addWidget( myEdgeGrp );
213 vl->addWidget( myFaceGrp );
214 vl->addWidget( myVolumeGrp );
215 vl->addWidget( myOutlineGrp );
216 vl->addWidget( myElem0dGrp );
217 vl->addWidget( myBallGrp );
218 vl->addWidget( myOrientationGrp );
219 vl->addWidget( myExtraGrp );
221 nodeColorLab->setMinimumWidth( widthLab1 );
222 edgeColorLab->setMinimumWidth( widthLab1 );
223 faceColorLab->setMinimumWidth( widthLab1 );
224 volumeColorLab->setMinimumWidth( widthLab1 );
225 outlineColorLab->setMinimumWidth( widthLab1 );
226 elem0dColorLab->setMinimumWidth( widthLab1 );
227 ballColorLab->setMinimumWidth( widthLab1 );
228 orientationColorLab->setMinimumWidth( widthLab1 );
229 shrinkSizeLab->setMinimumWidth( widthLab1 );
231 myNodeMarker->typeLabel()->setMinimumWidth( widthLab2 );
232 edgeWidthLab->setMinimumWidth( widthLab2 );
233 myFaceColor->label()->setMinimumWidth( widthLab2 );
234 myVolumeColor->label()->setMinimumWidth( widthLab2 );
235 outlineWidthLab->setMinimumWidth( widthLab2 );
236 elem0dSizeLab->setMinimumWidth( widthLab2 );
237 // ballSizeLab->setMinimumWidth( widthLab2 );
238 orientationScaleLab->setMinimumWidth( widthLab2 );
240 myEdgeWidth->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
241 myOutlineWidth->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
242 myElem0dSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
243 // myBallSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
244 myBallScale->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
245 myOrientationSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
246 myShrinkSize->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
248 // initialize widgets
249 myNodeMarker->setCustomMarkers( customMarkers );
250 myElem0dSize->setRange( 1, 10 );
251 // myBallSize->setRange( 1, 10 );
252 myEdgeWidth->setRange( 1, 5 );
253 myOutlineWidth->setRange( 1, 5 );
254 myShrinkSize->setRange( 20, 100 );
255 myOrientationSize->setRange( 5, 100 );
257 button( OK )->setText( tr( "SMESH_BUT_OK" ) );
259 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
263 \brief Destructor: clean-up resources if necessary
265 SMESHGUI_PropertiesDlg::~SMESHGUI_PropertiesDlg()
270 \brief Set nodes color
271 \param color nodes color
273 void SMESHGUI_PropertiesDlg::setNodeColor( const QColor& color )
275 myNodeColor->setColor( color );
279 \brief Get nodes color
280 \return current nodes color
282 QColor SMESHGUI_PropertiesDlg::nodeColor() const
284 return myNodeColor->color();
288 \brief Set standard nodes marker
289 \param type standard nodes marker type
290 \param scale standard nodes marker scale
292 void SMESHGUI_PropertiesDlg::setNodeMarker( VTK::MarkerType type, VTK::MarkerScale scale )
294 myNodeMarker->setMarker( type, scale );
298 \brief Set custom nodes marker
299 \param id custom nodes marker id
301 void SMESHGUI_PropertiesDlg::setNodeCustomMarker( int id )
303 myNodeMarker->setCustomMarker( id );
307 \brief Get nodes marker type.
308 For custom marker, VTK::MT_USER is returned and markerId() function
309 then returns its identifier.
310 \return currently selected nodes marker type
312 VTK::MarkerType SMESHGUI_PropertiesDlg::nodeMarkerType() const
314 return myNodeMarker->markerType();
318 \brief Get nodes marker scale.
319 For custom marker return value is undefined.
320 \return currently selected nodes marker scale
322 VTK::MarkerScale SMESHGUI_PropertiesDlg::nodeMarkerScale() const
324 return myNodeMarker->markerScale();
328 \brief Get custom nodes marker.
329 For standard markers return value is VTK::MT_NONE.
330 \return custom nodes marker id
332 int SMESHGUI_PropertiesDlg::nodeMarkerId() const
334 return myNodeMarker->markerId();
338 \brief Set edges (wireframe) color
339 \param color edges color
341 void SMESHGUI_PropertiesDlg::setEdgeColor( const QColor& color )
343 myEdgeColor->setColor( color );
347 \brief Get edges (wireframe) color
348 \return current edges color
350 QColor SMESHGUI_PropertiesDlg::edgeColor() const
352 return myEdgeColor->color();
356 \brief Set edges width
357 \param width edges width
359 void SMESHGUI_PropertiesDlg::setEdgeWidth( int width )
361 myEdgeWidth->setValue( width );
365 \brief Get edges width
366 \return current edges width
368 int SMESHGUI_PropertiesDlg::edgeWidth() const
370 return myEdgeWidth->value();
374 \brief Set faces colors
375 \param color front faces color
376 \param delta back faces coloring delta
378 void SMESHGUI_PropertiesDlg::setFaceColor( const QColor& color, int delta )
380 myFaceColor->setMainColor( color );
381 myFaceColor->setDelta( delta );
385 \brief Get front faces color
386 \return current front faces color
388 QColor SMESHGUI_PropertiesDlg::faceColor() const
390 return myFaceColor->mainColor();
394 \brief Get back faces coloring delta
395 \return current back faces coloring delta
397 int SMESHGUI_PropertiesDlg::faceColorDelta() const
399 return myFaceColor->delta();
403 \brief Set volumes colors
404 \param color normal volumes color
405 \param delta reversed volumes coloring delta
407 void SMESHGUI_PropertiesDlg::setVolumeColor( const QColor& color, int delta )
409 myVolumeColor->setMainColor( color );
410 myVolumeColor->setDelta( delta );
414 \brief Get normal volumes color
415 \return current normal volumes color
417 QColor SMESHGUI_PropertiesDlg::volumeColor() const
419 return myVolumeColor->mainColor();
423 \brief Get reversed volumes coloring delta
424 \return current reversed volumes coloring delta
426 int SMESHGUI_PropertiesDlg::volumeColorDelta() const
428 return myVolumeColor->delta();
432 \brief Set outlines color
433 \param color outlines color
435 void SMESHGUI_PropertiesDlg::setOutlineColor( const QColor& color )
437 myOutlineColor->setColor( color );
441 \brief Get outlines color
442 \return current outlines color
444 QColor SMESHGUI_PropertiesDlg::outlineColor() const
446 return myOutlineColor->color();
450 \brief Set outlines width
451 \param width outlines width
453 void SMESHGUI_PropertiesDlg::setOutlineWidth( int width )
455 myOutlineWidth->setValue( width );
459 \brief Get outlines width
460 \return current outlines width
462 int SMESHGUI_PropertiesDlg::outlineWidth() const
464 return myOutlineWidth->value();
468 \brief Set 0D elements color
469 \param color 0D elements color
471 void SMESHGUI_PropertiesDlg::setElem0dColor( const QColor& color )
473 myElem0dColor->setColor( color );
477 \brief Get 0D elements color
478 \return current 0D elements color
480 QColor SMESHGUI_PropertiesDlg::elem0dColor() const
482 return myElem0dColor->color();
486 \brief Set 0D elements size
487 \param size 0D elements size
489 void SMESHGUI_PropertiesDlg::setElem0dSize( int size )
491 myElem0dSize->setValue( size );
495 \brief Get 0D elements size
496 \return current 0D elements size
498 int SMESHGUI_PropertiesDlg::elem0dSize() const
500 return myElem0dSize->value();
504 \brief Set discrete elements (balls) color
505 \param color discrete elements (balls) color
507 void SMESHGUI_PropertiesDlg::setBallColor( const QColor& color )
509 myBallColor->setColor( color );
513 \brief Get discrete elements (balls) color
514 \return current discrete elements (balls) color
516 QColor SMESHGUI_PropertiesDlg::ballColor() const
518 return myBallColor->color();
522 \brief Set discrete elements (balls) size
523 \param size discrete elements (balls) size
525 /*void SMESHGUI_PropertiesDlg::setBallSize( int size )
527 myBallSize->setValue( size );
531 \brief Get discrete elements (balls) size
532 \return current discrete elements (balls) size
534 /*int SMESHGUI_PropertiesDlg::ballSize() const
536 return myBallSize->value();
540 \brief Set discrete elements (balls) scale factor
541 \param size discrete elements (balls) scale factor
543 void SMESHGUI_PropertiesDlg::setBallScale( double size )
545 myBallScale->setValue( size );
549 \brief Get discrete elements (balls) scale factor
550 \return current discrete elements (balls) scale factor
552 double SMESHGUI_PropertiesDlg::ballScale() const
554 return myBallScale->value();
558 \brief Set orientation vectors color
559 \param color orientation vectors color
561 void SMESHGUI_PropertiesDlg::setOrientationColor( const QColor& color )
563 myOrientationColor->setColor( color );
567 \brief Get orientation vectors color
568 \return current orientation vectors color
570 QColor SMESHGUI_PropertiesDlg::orientationColor() const
572 return myOrientationColor->color();
576 \brief Set orientation vectors scale (percent)
577 \param scale orientation vectors scale
579 void SMESHGUI_PropertiesDlg::setOrientationSize( int scale )
581 myOrientationSize->setValue( scale );
585 \brief Get orientation vectors scale (percent)
586 \return current orientation vectors scale
588 int SMESHGUI_PropertiesDlg::orientationSize() const
590 return myOrientationSize->value();
594 \brief Set orientation vectors 3d flag
595 \param on orientation vectors 3d flag value
597 void SMESHGUI_PropertiesDlg::setOrientation3d( bool on )
599 myOrientation3d->setChecked( on );
603 \brief Get orientation vectors 3d flag
604 \return orientation vectors 3d flag value
606 bool SMESHGUI_PropertiesDlg::orientation3d() const
608 return myOrientation3d->isChecked();
612 \brief Set shrink coefficient (percent)
613 \param coef shrink coefficient
615 void SMESHGUI_PropertiesDlg::setShrinkCoef( int coef )
617 myShrinkSize->setValue( coef );
621 \brief Get shrink coefficient (percent)
622 \return current shrink coefficient
624 int SMESHGUI_PropertiesDlg::shrinkCoef() const
626 return myShrinkSize->value();
630 \brief Get custom markers
631 \return custom markers map
633 VTK::MarkerMap SMESHGUI_PropertiesDlg::customMarkers() const
635 return myNodeMarker->customMarkers();
639 \brief Show / hide controls for specified entity type
640 \param elements mesh element types (an or-ed combination of flags)
641 \param nodes mesh nodes presence flag
643 void SMESHGUI_PropertiesDlg::showControls( int elements, bool nodes )
645 // node controls are supposed to be shown if at least any element type is present
646 // or if there are only nodes
647 myNodeGrp->setVisible( nodes || elements & SMESH_Actor::eAllEntity );
648 // edge/wireframe controls are needed for edges, faces and volumes
649 myEdgeGrp->setVisible( elements & ( SMESH_Actor::eEdges | SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
650 // face controls are shown only if there are faces
651 myFaceGrp->setVisible( elements & SMESH_Actor::eFaces );
652 // volume controls are shown only if there are volumes
653 myVolumeGrp->setVisible( elements & SMESH_Actor::eVolumes );
654 // 0d elements controls are shown only if there are 0d elements
655 myElem0dGrp->setVisible( elements & SMESH_Actor::e0DElements );
656 // ball controls are shown only if there are balls
657 myBallGrp->setVisible( elements & SMESH_Actor::eBallElem );
658 // outline controls are needed for faces and volumes
659 myOutlineGrp->setVisible( elements & ( SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
660 // orientation controls are needed for faces and volumes
661 myOrientationGrp->setVisible( elements & ( SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
662 // shrink factor is shown if there are edges and/or faces and/or volumes
663 myExtraGrp->setVisible( elements & ( SMESH_Actor::eEdges | SMESH_Actor::eFaces | SMESH_Actor::eVolumes ) );
667 \brief Show online help on dialog box
669 void SMESHGUI_PropertiesDlg::onHelp()
671 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
672 app->onHelpContextModule( "SMESH", "colors_size_page.html" );