1 // Copyright (C) 2007-2015 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_Measurements.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "SMESHGUI_Measurements.h"
27 #include "SMESH_Actor.h"
29 #include "SMESHGUI_IdValidator.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include <SMESH_TypeFilter.hxx>
33 #include <SMESH_LogicalFilter.hxx>
35 #include <LightApp_SelectionMgr.h>
36 #include <SUIT_OverrideCursor.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SVTK_ViewWindow.h>
39 #include <SALOME_ListIO.hxx>
41 #include <QButtonGroup>
42 #include <QGridLayout>
44 #include <QHBoxLayout>
48 #include <QPushButton>
49 #include <QRadioButton>
51 #include <QVBoxLayout>
53 #include <vtkPoints.h>
54 #include <vtkUnstructuredGrid.h>
55 #include <vtkIdList.h>
56 #include <vtkCellArray.h>
57 #include <vtkUnsignedCharArray.h>
58 #include <vtkDataSetMapper.h>
59 #include <VTKViewer_CellLocationsArray.h>
60 #include <vtkProperty.h>
62 #include <SALOMEconfig.h>
63 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
64 #include CORBA_SERVER_HEADER(SMESH_Measurements)
66 const int SPACING = 6; // layout spacing
67 const int MARGIN = 9; // layout margin
68 const int MAX_NB_FOR_EDITOR = 40; // max nb of items in the ID list editor field
70 // Uncomment as soon as elements are supported by Min Distance operation
71 //#define MINDIST_ENABLE_ELEMENT
73 // Uncomment as soon as objects are supported by Min Distance operation
74 //#define MINDIST_ENABLE_OBJECT
77 \class SMESHGUI_MinDistance
78 \brief Minimum distance measurement widget.
80 Widget to calculate minimum distance between two objects.
85 \param parent parent widget
87 SMESHGUI_MinDistance::SMESHGUI_MinDistance( QWidget* parent )
88 : QWidget( parent ), myCurrentTgt( FirstTgt ), myFirstActor( 0 ), mySecondActor( 0 ), myPreview( 0 )
90 QGroupBox* aFirstTgtGrp = new QGroupBox( tr( "FIRST_TARGET" ), this );
91 QRadioButton* aFNode = new QRadioButton( tr( "NODE" ), aFirstTgtGrp );
92 QRadioButton* aFElem = new QRadioButton( tr( "ELEMENT" ), aFirstTgtGrp );
93 QRadioButton* aFObject = new QRadioButton( tr( "OBJECT" ), aFirstTgtGrp );
94 myFirstTgt = new QLineEdit( aFirstTgtGrp );
96 QGridLayout* fl = new QGridLayout( aFirstTgtGrp );
97 fl->setMargin( MARGIN );
98 fl->setSpacing( SPACING );
99 fl->addWidget( aFNode, 0, 0 );
100 fl->addWidget( aFElem, 0, 1 );
101 fl->addWidget( aFObject, 0, 2 );
102 fl->addWidget( myFirstTgt, 1, 0, 1, 3 );
104 myFirst = new QButtonGroup( this );
105 myFirst->addButton( aFNode, NodeTgt );
106 myFirst->addButton( aFElem, ElementTgt );
107 myFirst->addButton( aFObject, ObjectTgt );
109 QGroupBox* aSecondTgtGrp = new QGroupBox( tr( "SECOND_TARGET" ), this );
110 QRadioButton* aSOrigin = new QRadioButton( tr( "ORIGIN" ), aSecondTgtGrp );
111 QRadioButton* aSNode = new QRadioButton( tr( "NODE" ), aSecondTgtGrp );
112 QRadioButton* aSElem = new QRadioButton( tr( "ELEMENT" ), aSecondTgtGrp );
113 QRadioButton* aSObject = new QRadioButton( tr( "OBJECT" ), aSecondTgtGrp );
114 mySecondTgt = new QLineEdit( aSecondTgtGrp );
116 QGridLayout* sl = new QGridLayout( aSecondTgtGrp );
117 sl->setMargin( MARGIN );
118 sl->setSpacing( SPACING );
119 sl->addWidget( aSOrigin, 0, 0 );
120 sl->addWidget( aSNode, 0, 1 );
121 sl->addWidget( aSElem, 0, 2 );
122 sl->addWidget( aSObject, 0, 3 );
123 sl->addWidget( mySecondTgt, 1, 0, 1, 4 );
125 mySecond = new QButtonGroup( this );
126 mySecond->addButton( aSOrigin, OriginTgt );
127 mySecond->addButton( aSNode, NodeTgt );
128 mySecond->addButton( aSElem, ElementTgt );
129 mySecond->addButton( aSObject, ObjectTgt );
131 QPushButton* aCompute = new QPushButton( tr( "COMPUTE" ), this );
133 QGroupBox* aResults = new QGroupBox( tr( "RESULT" ), this );
134 QLabel* aDxLab = new QLabel( "dX", aResults );
135 myDX = new QLineEdit( aResults );
136 QLabel* aDyLab = new QLabel( "dY", aResults );
137 myDY = new QLineEdit( aResults );
138 QLabel* aDzLab = new QLabel( "dZ", aResults );
139 myDZ = new QLineEdit( aResults );
140 QLabel* aDistLab = new QLabel( tr( "DISTANCE" ), aResults );
141 myDistance = new QLineEdit( aResults );
143 QGridLayout* rl = new QGridLayout( aResults );
144 rl->setMargin( MARGIN );
145 rl->setSpacing( SPACING );
146 rl->addWidget( aDxLab, 0, 0 );
147 rl->addWidget( myDX, 0, 1 );
148 rl->addWidget( aDyLab, 1, 0 );
149 rl->addWidget( myDY, 1, 1 );
150 rl->addWidget( aDzLab, 2, 0 );
151 rl->addWidget( myDZ, 2, 1 );
152 rl->addWidget( aDistLab, 0, 2 );
153 rl->addWidget( myDistance, 0, 3 );
155 QGridLayout* l = new QGridLayout( this );
156 l->setMargin( MARGIN );
157 l->setSpacing( SPACING );
159 l->addWidget( aFirstTgtGrp, 0, 0, 1, 2 );
160 l->addWidget( aSecondTgtGrp, 1, 0, 1, 2 );
161 l->addWidget( aCompute, 2, 0 );
162 l->addWidget( aResults, 3, 0, 1, 2 );
163 l->setColumnStretch( 1, 5 );
164 l->setRowStretch( 4, 5 );
166 aFNode->setChecked( true );
167 aSOrigin->setChecked( true );
168 #ifndef MINDIST_ENABLE_ELEMENT
169 aFElem->setEnabled( false ); // NOT AVAILABLE YET
170 aSElem->setEnabled( false ); // NOT AVAILABLE YET
172 #ifndef MINDIST_ENABLE_OBJECT
173 aFObject->setEnabled( false ); // NOT AVAILABLE YET
174 aSObject->setEnabled( false ); // NOT AVAILABLE YET
176 myDX->setReadOnly( true );
177 myDY->setReadOnly( true );
178 myDZ->setReadOnly( true );
179 myDistance->setReadOnly( true );
181 myValidator = new SMESHGUI_IdValidator( this, 1 );
183 myFirstTgt->installEventFilter( this );
184 mySecondTgt->installEventFilter( this );
186 connect( myFirst, SIGNAL( buttonClicked( int ) ), this, SLOT( firstChanged() ) );
187 connect( mySecond, SIGNAL( buttonClicked( int ) ), this, SLOT( secondChanged() ) );
188 connect( aCompute, SIGNAL( clicked() ), this, SLOT( compute() ) );
189 connect( myFirstTgt, SIGNAL( textEdited( QString ) ), this, SLOT( firstEdited() ) );
190 connect( mySecondTgt, SIGNAL( textEdited( QString ) ), this, SLOT( secondEdited() ) );
192 QList<SUIT_SelectionFilter*> filters;
193 filters.append( new SMESH_TypeFilter( SMESH::MESHorSUBMESH ) );
194 filters.append( new SMESH_TypeFilter( SMESH::GROUP ) );
195 myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
197 mySecondTgt->setEnabled( mySecond->checkedId() != OriginTgt );
200 //setTarget( FirstTgt );
207 SMESHGUI_MinDistance::~SMESHGUI_MinDistance()
218 \return \c true if event is filtered or \c false otherwise
220 bool SMESHGUI_MinDistance::eventFilter( QObject* o, QEvent* e )
222 if ( e->type() == QEvent::FocusIn ) {
223 if ( o == myFirstTgt )
224 setTarget( FirstTgt );
225 else if ( o == mySecondTgt )
226 setTarget( SecondTgt );
228 return QWidget::eventFilter( o, e );
232 \brief Setup selection mode depending on the current widget state
234 void SMESHGUI_MinDistance::updateSelection()
236 LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
238 disconnect( selMgr, 0, this, 0 );
239 selMgr->clearFilters();
241 bool nodeMode = ( myCurrentTgt == FirstTgt && myFirst->checkedId() == NodeTgt ) ||
242 ( myCurrentTgt == SecondTgt && mySecond->checkedId() == NodeTgt );
243 bool elemMode = ( myCurrentTgt == FirstTgt && myFirst->checkedId() == ElementTgt ) ||
244 ( myCurrentTgt == SecondTgt && mySecond->checkedId() == ElementTgt );
245 bool objMode = ( myCurrentTgt == FirstTgt && myFirst->checkedId() == ObjectTgt ) ||
246 ( myCurrentTgt == SecondTgt && mySecond->checkedId() == ObjectTgt ) ||
247 ( myCurrentTgt == NoTgt );
250 SMESH::SetPointRepresentation( true );
251 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
252 aViewWindow->SetSelectionMode( NodeSelection );
254 else if ( elemMode ) {
255 SMESH::SetPointRepresentation( false );
256 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
257 aViewWindow->SetSelectionMode( CellSelection );
259 else if ( objMode ) {
260 SMESH::SetPointRepresentation( false );
261 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
262 aViewWindow->SetSelectionMode( ActorSelection );
263 selMgr->installFilter( myFilter );
266 connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
268 if ( myCurrentTgt == FirstTgt )
270 else if ( myCurrentTgt == SecondTgt )
273 //selectionChanged();
277 \brief Deactivate widget
279 void SMESHGUI_MinDistance::deactivate()
281 disconnect( SMESHGUI::selectionMgr(), 0, this, 0 );
285 \brief Set current target for selection
286 \param target new target ID
288 void SMESHGUI_MinDistance::setTarget( int target )
290 if ( myCurrentTgt != target ) {
291 myCurrentTgt = target;
297 \brief Erase preview actor
299 void SMESHGUI_MinDistance::erasePreview()
301 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
302 if ( aViewWindow && myPreview ) {
303 aViewWindow->RemoveActor( myPreview );
304 aViewWindow->Repaint();
309 \brief Display preview actor
311 void SMESHGUI_MinDistance::displayPreview()
313 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
314 if ( aViewWindow && myPreview ) {
315 aViewWindow->AddActor( myPreview );
316 aViewWindow->Repaint();
321 \brief Create preview actor
322 \param x1 X coordinate of first point
323 \param y1 X coordinate of first point
324 \param z1 Y coordinate of first point
325 \param x2 Y coordinate of second point
326 \param y2 Z coordinate of second point
327 \param z2 Z coordinate of second point
329 void SMESHGUI_MinDistance::createPreview( double x1, double y1, double z1, double x2, double y2, double z2 )
334 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
336 vtkPoints* aPoints = vtkPoints::New();
337 aPoints->SetNumberOfPoints( 2 );
338 aPoints->SetPoint( 0, x1, y1, z1 );
339 aPoints->SetPoint( 1, x2, y2, z2 );
340 aGrid->SetPoints( aPoints );
343 vtkIdList* anIdList = vtkIdList::New();
344 anIdList->SetNumberOfIds( 2 );
345 vtkCellArray* aCells = vtkCellArray::New();
346 aCells->Allocate( 2, 0);
347 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
348 aCellTypesArray->SetNumberOfComponents( 1 );
349 aCellTypesArray->Allocate( 1 );
350 anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 1 );
351 aCells->InsertNextCell( anIdList );
352 aCellTypesArray->InsertNextValue( VTK_LINE );
354 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
355 aCellLocationsArray->SetNumberOfComponents( 1 );
356 aCellLocationsArray->SetNumberOfTuples( 1 );
357 aCells->InitTraversal();
358 for( vtkIdType idType = 0, *pts, npts; aCells->GetNextCell( npts, pts ); idType++ )
359 aCellLocationsArray->SetValue( idType, aCells->GetTraversalLocation( npts ) );
360 aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
361 aCellLocationsArray->Delete();
362 aCellTypesArray->Delete();
365 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
366 aMapper->SetInputData( aGrid );
368 myPreview = SALOME_Actor::New();
369 myPreview->PickableOff();
370 myPreview->SetMapper( aMapper );
372 vtkProperty* aProp = vtkProperty::New();
373 aProp->SetRepresentationToWireframe();
374 aProp->SetColor( 250, 0, 250 );
375 aProp->SetPointSize( 5 );
376 aProp->SetLineWidth( 3 );
377 myPreview->SetProperty( aProp );
382 \brief Called when selection is changed
384 void SMESHGUI_MinDistance::selectionChanged()
386 SUIT_OverrideCursor wc;
388 SALOME_ListIO selected;
389 SMESHGUI::selectionMgr()->selectedObjects( selected );
391 if ( selected.Extent() == 1 ) {
392 Handle(SALOME_InteractiveObject) IO = selected.First();
393 SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
394 if ( !CORBA::is_nil( obj ) ) {
395 if ( myCurrentTgt == FirstTgt ) {
397 myFirstActor = SMESH::FindActorByEntry( IO->getEntry() );
398 if ( myFirst->checkedId() == ObjectTgt ) {
400 SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
401 myFirstTgt->setText( aName );
404 SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
407 if ( myFirstActor && selector ) {
408 nb = myFirst->checkedId() == NodeTgt ?
409 SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
410 SMESH::GetNameOfSelectedNodes( selector, IO, ID );
413 myFirstTgt->setText( ID.trimmed() );
418 else if ( myCurrentTgt == SecondTgt ) {
420 mySecondActor = SMESH::FindActorByEntry( IO->getEntry() );
421 if ( mySecond->checkedId() == ObjectTgt ) {
423 SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
424 mySecondTgt->setText( aName );
427 SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
430 if ( mySecondActor && selector ) {
431 nb = mySecond->checkedId() == NodeTgt ?
432 SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
433 SMESH::GetNameOfSelectedNodes( selector, IO, ID );
436 mySecondTgt->setText( ID.trimmed() );
438 mySecondTgt->clear();
447 \brief Called when first target mode is changed by the user
449 void SMESHGUI_MinDistance::firstChanged()
451 myFirstSrc = SMESH::SMESH_IDSource::_nil();
453 myFirstTgt->setReadOnly( myFirst->checkedId() == ObjectTgt );
454 myFirstTgt->setValidator( myFirst->checkedId() == ObjectTgt ? 0 : myValidator );
455 setTarget( FirstTgt );
461 \brief Called when second target mode is changed by the user
463 void SMESHGUI_MinDistance::secondChanged()
465 mySecondSrc = SMESH::SMESH_IDSource::_nil();
466 mySecondTgt->setEnabled( mySecond->checkedId() != OriginTgt );
467 mySecondTgt->setReadOnly( mySecond->checkedId() == ObjectTgt );
468 mySecondTgt->setValidator( mySecond->checkedId() == ObjectTgt ? 0 : myValidator );
469 mySecondTgt->clear();
470 setTarget( mySecond->checkedId() != OriginTgt ? SecondTgt : NoTgt );
476 \brief Called when first target is edited by the user
478 void SMESHGUI_MinDistance::firstEdited()
480 setTarget( FirstTgt );
481 if ( sender() == myFirstTgt )
483 SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
484 if ( myFirstActor && selector ) {
485 Handle(SALOME_InteractiveObject) IO = myFirstActor->getIO();
486 if ( myFirst->checkedId() == NodeTgt || myFirst->checkedId() == ElementTgt ) {
487 TColStd_MapOfInteger ID;
488 ID.Add( myFirstTgt->text().toLong() );
489 selector->AddOrRemoveIndex( IO, ID, false );
491 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
492 aViewWindow->highlight( IO, true, true );
497 \brief Called when second target is edited by the user
499 void SMESHGUI_MinDistance::secondEdited()
501 setTarget( SecondTgt );
502 if ( sender() == mySecondTgt )
504 QString text = mySecondTgt->text();
505 if ( !mySecondActor )
508 mySecondTgt->setText( text );
510 SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
511 if ( mySecondActor && selector ) {
512 Handle(SALOME_InteractiveObject) IO = mySecondActor->getIO();
513 if ( mySecond->checkedId() == NodeTgt || mySecond->checkedId() == ElementTgt ) {
514 if ( !text.isEmpty() ) {
515 TColStd_MapOfInteger ID;
516 ID.Add( text.toLong() );
517 selector->AddOrRemoveIndex( IO, ID, false );
520 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
521 aViewWindow->highlight( IO, true, true );
526 \brief Compute the minimum distance between targets
528 void SMESHGUI_MinDistance::compute()
530 SUIT_OverrideCursor wc;
531 SMESH::IDSource_wrap s1;
532 SMESH::IDSource_wrap s2;
533 bool isOrigin = mySecond->checkedId() == OriginTgt;
535 // process first target
536 if ( !CORBA::is_nil( myFirstSrc ) ) {
537 if ( myFirst->checkedId() == NodeTgt || myFirst->checkedId() == ElementTgt ) {
538 SMESH::SMESH_Mesh_var m = myFirstSrc->GetMesh();
539 long id = myFirstTgt->text().toLong();
540 if ( !CORBA::is_nil( m ) && id ) {
541 SMESH::long_array_var ids = new SMESH::long_array();
544 SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor();
545 s1 = me->MakeIDSource( ids.in(), myFirst->checkedId() == NodeTgt ? SMESH::NODE : SMESH::FACE );
554 // process second target
555 if ( !CORBA::is_nil( mySecondSrc ) ) {
556 if ( mySecond->checkedId() == NodeTgt || mySecond->checkedId() == ElementTgt ) {
557 SMESH::SMESH_Mesh_var m = mySecondSrc->GetMesh();
558 long id = mySecondTgt->text().toLong();
559 if ( !CORBA::is_nil( m ) && id ) {
560 SMESH::long_array_var ids = new SMESH::long_array();
563 SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor();
564 s2 = me->MakeIDSource( ids.in(), mySecond->checkedId() == NodeTgt ? SMESH::NODE : SMESH::FACE );
573 if ( !CORBA::is_nil( s1 ) && ( !CORBA::is_nil( s2 ) || isOrigin ) ) {
574 // compute min distance
575 int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
576 SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements();
577 SMESH::Measure result = measure->MinDistance( s1.in(), s2.in() );
578 measure->UnRegister();
579 myDX->setText( QString::number( result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
580 myDY->setText( QString::number( result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
581 myDZ->setText( QString::number( result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
582 myDistance->setText( QString::number( result.value, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
583 // update preview actor
585 double x1, y1, z1, x2, y2, z2;
586 SMESH::double_array_var coord = s1->GetMesh()->GetNodeXYZ( result.node1 );
587 x1 = coord[0]; y1 = coord[1]; z1 = coord[2];
592 coord = s2->GetMesh()->GetNodeXYZ( result.node2 );
593 x2 = coord[0]; y2 = coord[1]; z2 = coord[2];
595 createPreview( x1, y1, z1, x2, y2, z2 );
604 \brief Reset the widget to the initial state (nullify result fields)
606 void SMESHGUI_MinDistance::clear()
616 \class SMESHGUI_BoundingBox
617 \brief Bounding box measurement widget.
619 Widget to calculate bounding box of the selected object(s).
624 \param parent parent widget
626 SMESHGUI_BoundingBox::SMESHGUI_BoundingBox( QWidget* parent )
627 : QWidget( parent ), myActor( 0 ), myPreview( 0 )
629 QGroupBox* aSourceGrp = new QGroupBox( tr( "SOURCE" ), this );
630 QRadioButton* aObjects = new QRadioButton( tr( "OBJECTS" ), aSourceGrp );
631 QRadioButton* aNodes = new QRadioButton( tr( "NODES" ), aSourceGrp );
632 QRadioButton* aElements = new QRadioButton( tr( "ELEMENTS" ), aSourceGrp );
633 mySource = new QLineEdit( aSourceGrp );
635 QGridLayout* fl = new QGridLayout( aSourceGrp );
636 fl->setMargin( MARGIN );
637 fl->setSpacing( SPACING );
638 fl->addWidget( aObjects, 0, 0 );
639 fl->addWidget( aNodes, 0, 1 );
640 fl->addWidget( aElements, 0, 2 );
641 fl->addWidget( mySource, 1, 0, 1, 3 );
643 mySourceMode = new QButtonGroup( this );
644 mySourceMode->addButton( aObjects, ObjectsSrc );
645 mySourceMode->addButton( aNodes, NodesSrc );
646 mySourceMode->addButton( aElements, ElementsSrc );
648 QPushButton* aCompute = new QPushButton( tr( "COMPUTE" ), this );
650 QGroupBox* aResults = new QGroupBox( tr( "RESULT" ), this );
651 QLabel* aXminLab = new QLabel( "Xmin", aResults );
652 myXmin = new QLineEdit( aResults );
653 QLabel* aXmaxLab = new QLabel( "Xmax", aResults );
654 myXmax = new QLineEdit( aResults );
655 QLabel* aDxLab = new QLabel( "dX", aResults );
656 myDX = new QLineEdit( aResults );
657 QLabel* aYminLab = new QLabel( "Ymin", aResults );
658 myYmin = new QLineEdit( aResults );
659 QLabel* aYmaxLab = new QLabel( "Ymax", aResults );
660 myYmax = new QLineEdit( aResults );
661 QLabel* aDyLab = new QLabel( "dY", aResults );
662 myDY = new QLineEdit( aResults );
663 QLabel* aZminLab = new QLabel( "Zmin", aResults );
664 myZmin = new QLineEdit( aResults );
665 QLabel* aZmaxLab = new QLabel( "Zmax", aResults );
666 myZmax = new QLineEdit( aResults );
667 QLabel* aDzLab = new QLabel( "dZ", aResults );
668 myDZ = new QLineEdit( aResults );
670 QGridLayout* rl = new QGridLayout( aResults );
671 rl->setMargin( MARGIN );
672 rl->setSpacing( SPACING );
673 rl->addWidget( aXminLab, 0, 0 );
674 rl->addWidget( myXmin, 0, 1 );
675 rl->addWidget( aXmaxLab, 0, 2 );
676 rl->addWidget( myXmax, 0, 3 );
677 rl->addWidget( aDxLab, 0, 4 );
678 rl->addWidget( myDX, 0, 5 );
679 rl->addWidget( aYminLab, 1, 0 );
680 rl->addWidget( myYmin, 1, 1 );
681 rl->addWidget( aYmaxLab, 1, 2 );
682 rl->addWidget( myYmax, 1, 3 );
683 rl->addWidget( aDyLab, 1, 4 );
684 rl->addWidget( myDY, 1, 5 );
685 rl->addWidget( aZminLab, 2, 0 );
686 rl->addWidget( myZmin, 2, 1 );
687 rl->addWidget( aZmaxLab, 2, 2 );
688 rl->addWidget( myZmax, 2, 3 );
689 rl->addWidget( aDzLab, 2, 4 );
690 rl->addWidget( myDZ, 2, 5 );
692 QGridLayout* l = new QGridLayout( this );
693 l->setMargin( MARGIN );
694 l->setSpacing( SPACING );
696 l->addWidget( aSourceGrp, 0, 0, 1, 2 );
697 l->addWidget( aCompute, 1, 0 );
698 l->addWidget( aResults, 2, 0, 1, 2 );
699 l->setColumnStretch( 1, 5 );
700 l->setRowStretch( 3, 5 );
702 aObjects->setChecked( true );
703 myXmin->setReadOnly( true );
704 myXmax->setReadOnly( true );
705 myDX->setReadOnly( true );
706 myYmin->setReadOnly( true );
707 myYmax->setReadOnly( true );
708 myDY->setReadOnly( true );
709 myZmin->setReadOnly( true );
710 myZmax->setReadOnly( true );
711 myDZ->setReadOnly( true );
713 myValidator = new SMESHGUI_IdValidator( this );
715 connect( mySourceMode, SIGNAL( buttonClicked( int ) ), this, SLOT( sourceChanged() ) );
716 connect( aCompute, SIGNAL( clicked() ), this, SLOT( compute() ) );
717 connect( mySource, SIGNAL( textEdited( QString ) ), this, SLOT( sourceEdited() ) );
719 QList<SUIT_SelectionFilter*> filters;
720 filters.append( new SMESH_TypeFilter( SMESH::MESHorSUBMESH ) );
721 filters.append( new SMESH_TypeFilter( SMESH::GROUP ) );
722 myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
730 SMESHGUI_BoundingBox::~SMESHGUI_BoundingBox()
738 \brief Setup selection mode depending on the current widget state
740 void SMESHGUI_BoundingBox::updateSelection()
742 LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
744 disconnect( selMgr, 0, this, 0 );
745 selMgr->clearFilters();
747 bool nodeMode = mySourceMode->checkedId() == NodesSrc;
748 bool elemMode = mySourceMode->checkedId() == ElementsSrc;
749 bool objMode = mySourceMode->checkedId() == ObjectsSrc;
752 SMESH::SetPointRepresentation( true );
753 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
754 aViewWindow->SetSelectionMode( NodeSelection );
756 else if ( elemMode ) {
757 SMESH::SetPointRepresentation( false );
758 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
759 aViewWindow->SetSelectionMode( CellSelection );
761 else if ( objMode ) {
762 SMESH::SetPointRepresentation( false );
763 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
764 aViewWindow->SetSelectionMode( ActorSelection );
765 selMgr->installFilter( myFilter );
768 connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
772 if ( mySource->text().isEmpty() )
777 \brief Deactivate widget
779 void SMESHGUI_BoundingBox::deactivate()
781 disconnect( SMESHGUI::selectionMgr(), 0, this, 0 );
785 \brief Erase preview actor
787 void SMESHGUI_BoundingBox::erasePreview()
789 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
790 if ( aViewWindow && myPreview ) {
791 aViewWindow->RemoveActor( myPreview );
792 aViewWindow->Repaint();
797 \brief Display preview actor
799 void SMESHGUI_BoundingBox::displayPreview()
801 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
802 if ( aViewWindow && myPreview ) {
803 aViewWindow->AddActor( myPreview );
804 aViewWindow->Repaint();
809 \brief Create preview actor
810 \param minX min X coordinate of bounding box
811 \param maxX max X coordinate of bounding box
812 \param minY min Y coordinate of bounding box
813 \param maxY max Y coordinate of bounding box
814 \param minZ min Z coordinate of bounding box
815 \param maxZ max Z coordinate of bounding box
817 void SMESHGUI_BoundingBox::createPreview( double minX, double maxX, double minY, double maxY, double minZ, double maxZ )
822 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
824 vtkPoints* aPoints = vtkPoints::New();
825 aPoints->SetNumberOfPoints( 8 );
826 aPoints->SetPoint( 0, minX, minY, minZ );
827 aPoints->SetPoint( 1, maxX, minY, minZ );
828 aPoints->SetPoint( 2, minX, maxY, minZ );
829 aPoints->SetPoint( 3, maxX, maxY, minZ );
830 aPoints->SetPoint( 4, minX, minY, maxZ );
831 aPoints->SetPoint( 5, maxX, minY, maxZ );
832 aPoints->SetPoint( 6, minX, maxY, maxZ );
833 aPoints->SetPoint( 7, maxX, maxY, maxZ );
834 aGrid->SetPoints( aPoints );
837 // connectivity: 0-1 0-4 0-2 1-5 1-3 2-6 2-3 3-7 4-6 4-5 5-7 6-7
838 vtkIdList* anIdList = vtkIdList::New();
839 anIdList->SetNumberOfIds( 2 );
840 vtkCellArray* aCells = vtkCellArray::New();
841 aCells->Allocate( 2*12, 0);
842 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
843 aCellTypesArray->SetNumberOfComponents( 1 );
844 aCellTypesArray->Allocate( 12 );
845 anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 1 );
846 aCells->InsertNextCell( anIdList );
847 aCellTypesArray->InsertNextValue( VTK_LINE );
848 anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 4 );
849 aCells->InsertNextCell( anIdList );
850 aCellTypesArray->InsertNextValue( VTK_LINE );
851 anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 2 );
852 aCells->InsertNextCell( anIdList );
853 aCellTypesArray->InsertNextValue( VTK_LINE );
854 anIdList->SetId( 0, 1 ); anIdList->SetId( 1, 5 );
855 aCells->InsertNextCell( anIdList );
856 aCellTypesArray->InsertNextValue( VTK_LINE );
857 anIdList->SetId( 0, 1 ); anIdList->SetId( 1, 3 );
858 aCells->InsertNextCell( anIdList );
859 aCellTypesArray->InsertNextValue( VTK_LINE );
860 anIdList->SetId( 0, 2 ); anIdList->SetId( 1, 6 );
861 aCells->InsertNextCell( anIdList );
862 aCellTypesArray->InsertNextValue( VTK_LINE );
863 anIdList->SetId( 0, 2 ); anIdList->SetId( 1, 3 );
864 aCells->InsertNextCell( anIdList );
865 aCellTypesArray->InsertNextValue( VTK_LINE );
866 anIdList->SetId( 0, 3 ); anIdList->SetId( 1, 7 );
867 aCells->InsertNextCell( anIdList );
868 aCellTypesArray->InsertNextValue( VTK_LINE );
869 anIdList->SetId( 0, 4 ); anIdList->SetId( 1, 6 );
870 aCells->InsertNextCell( anIdList );
871 aCellTypesArray->InsertNextValue( VTK_LINE );
872 anIdList->SetId( 0, 4 ); anIdList->SetId( 1, 5 );
873 aCells->InsertNextCell( anIdList );
874 aCellTypesArray->InsertNextValue( VTK_LINE );
875 anIdList->SetId( 0, 5 ); anIdList->SetId( 1, 7 );
876 aCells->InsertNextCell( anIdList );
877 aCellTypesArray->InsertNextValue( VTK_LINE );
878 anIdList->SetId( 0, 6 ); anIdList->SetId( 1, 7 );
879 aCells->InsertNextCell( anIdList );
880 aCellTypesArray->InsertNextValue( VTK_LINE );
882 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
883 aCellLocationsArray->SetNumberOfComponents( 1 );
884 aCellLocationsArray->SetNumberOfTuples( 12 );
885 aCells->InitTraversal();
886 for( vtkIdType idType = 0, *pts, npts; aCells->GetNextCell( npts, pts ); idType++ )
887 aCellLocationsArray->SetValue( idType, aCells->GetTraversalLocation( npts ) );
888 aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
889 aCellLocationsArray->Delete();
890 aCellTypesArray->Delete();
893 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
894 aMapper->SetInputData( aGrid );
896 myPreview = SALOME_Actor::New();
897 myPreview->PickableOff();
898 myPreview->SetMapper( aMapper );
900 vtkProperty* aProp = vtkProperty::New();
901 aProp->SetRepresentationToWireframe();
902 aProp->SetColor( 250, 0, 250 );
903 aProp->SetPointSize( 5 );
904 aProp->SetLineWidth( 3 );
905 myPreview->SetProperty( aProp );
910 \brief Called when selection is changed
912 void SMESHGUI_BoundingBox::selectionChanged()
914 SUIT_OverrideCursor wc;
916 SALOME_ListIO selected;
917 SMESHGUI::selectionMgr()->selectedObjects( selected );
919 if ( selected.Extent() == 1 ) {
920 Handle(SALOME_InteractiveObject) IO = selected.First();
921 SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
922 if ( !CORBA::is_nil( obj ) ) {
925 myActor = SMESH::FindActorByEntry( IO->getEntry() );
926 if ( mySourceMode->checkedId() == ObjectsSrc ) {
928 SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
929 mySource->setText( aName );
932 SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
935 if ( myActor && selector ) {
936 nb = mySourceMode->checkedId() == NodesSrc ?
937 SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
938 SMESH::GetNameOfSelectedNodes( selector, IO, ID );
941 myIDs = ID.trimmed();
942 if ( nb < MAX_NB_FOR_EDITOR ) {
943 mySource->setReadOnly( false );
944 if ( mySource->validator() != myValidator )
945 mySource->setValidator( myValidator );
946 mySource->setText( ID.trimmed() );
949 mySource->setReadOnly( true );
950 mySource->setValidator( 0 );
951 mySource->setText( tr( "SELECTED_NB_OBJ" ).arg( nb )
952 .arg( mySourceMode->checkedId() == NodesSrc ? tr( "NB_NODES" ) : tr( "NB_ELEMENTS") ) );
958 mySource->setReadOnly( false );
959 mySource->setValidator( myValidator );
964 else if ( selected.Extent() > 1 ) {
966 SALOME_ListIteratorOfListIO It( selected );
969 if ( mySourceMode->checkedId() == ObjectsSrc ) {
970 for( ; It.More(); It.Next()){
971 Handle(SALOME_InteractiveObject) IO = It.Value();
972 SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
973 if ( !CORBA::is_nil( obj ) ) {
978 SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
979 mySource->setText( aName );
989 \brief Called when source mode is changed by the user
991 void SMESHGUI_BoundingBox::sourceChanged()
995 mySource->setReadOnly( mySourceMode->checkedId() == ObjectsSrc );
996 mySource->setValidator( mySourceMode->checkedId() == ObjectsSrc ? 0 : myValidator );
1002 \brief Called when source mode is edited by the user
1004 void SMESHGUI_BoundingBox::sourceEdited()
1006 if ( sender() == mySource )
1008 SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
1009 if ( myActor && selector ) {
1010 Handle(SALOME_InteractiveObject) IO = myActor->getIO();
1011 if ( mySourceMode->checkedId() == NodesSrc || mySourceMode->checkedId() == ElementsSrc ) {
1012 TColStd_MapOfInteger ID;
1013 if ( !mySource->isReadOnly() )
1014 myIDs = mySource->text();
1015 QStringList ids = myIDs.split( " ", QString::SkipEmptyParts );
1016 foreach ( QString id, ids )
1017 ID.Add( id.trimmed().toLong() );
1018 selector->AddOrRemoveIndex( IO, ID, false );
1020 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1021 aViewWindow->highlight( IO, true, true );
1026 \brief Calculate bounding box of the selected object(s)
1028 void SMESHGUI_BoundingBox::compute()
1030 SUIT_OverrideCursor wc;
1031 SMESH::ListOfIDSources_var srcList = new SMESH::ListOfIDSources();
1032 if ( mySourceMode->checkedId() == NodesSrc || mySourceMode->checkedId() == ElementsSrc ) {
1033 if ( mySrc.count() > 0 && !CORBA::is_nil( mySrc[0] ) ) {
1034 SMESH::SMESH_Mesh_var m = mySrc[0]->GetMesh();
1035 QStringList ids = myIDs.split( " ", QString::SkipEmptyParts );
1036 if ( !CORBA::is_nil( m ) && ids.count() > 0 ) {
1037 SMESH::long_array_var ids_in = new SMESH::long_array();
1038 ids_in->length( ids.count() );
1039 for( int i = 0; i < ids.count(); i++ )
1040 ids_in[i] = ids[i].trimmed().toLong();
1041 SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor();
1042 SMESH::SMESH_IDSource_var s = me->MakeIDSource( ids_in.in(), mySourceMode->checkedId() == NodesSrc ? SMESH::NODE : SMESH::FACE );
1043 srcList->length( 1 );
1049 srcList->length( mySrc.count() );
1050 for( int i = 0; i < mySrc.count(); i++ ) {
1051 srcList[i] = mySrc[i];
1052 mySrc[i]->Register();
1055 if ( srcList->length() > 0 ) {
1056 // compute bounding box
1057 int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
1058 SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements();
1059 SMESH::Measure result = measure->BoundingBox( srcList.in() );
1060 SALOME::UnRegister( srcList );
1061 measure->UnRegister();
1062 myXmin->setText( QString::number( result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1063 myXmax->setText( QString::number( result.maxX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1064 myDX->setText( QString::number( result.maxX-result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1065 myYmin->setText( QString::number( result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1066 myYmax->setText( QString::number( result.maxY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1067 myDY->setText( QString::number( result.maxY-result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1068 myZmin->setText( QString::number( result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1069 myZmax->setText( QString::number( result.maxZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1070 myDZ->setText( QString::number( result.maxZ-result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1071 // update preview actor
1073 createPreview( result.minX, result.maxX, result.minY, result.maxY, result.minZ, result.maxZ );
1082 \brief Reset the widget to the initial state (nullify result fields)
1084 void SMESHGUI_BoundingBox::clear()
1099 \class SMESHGUI_BasicProperties
1100 \brief basic properties measurement widget.
1102 Widget to calculate length, area or volume for the selected object(s).
1107 \param parent parent widget
1109 SMESHGUI_BasicProperties::SMESHGUI_BasicProperties( QWidget* parent )
1112 // Property (length, area or volume)
1113 QGroupBox* aPropertyGrp = new QGroupBox( tr( "PROPERTY" ), this );
1115 QRadioButton* aLength = new QRadioButton( tr( "LENGTH" ), aPropertyGrp );
1116 QRadioButton* anArea = new QRadioButton( tr( "AREA" ), aPropertyGrp );
1117 QRadioButton* aVolume = new QRadioButton( tr( "VOLUME" ), aPropertyGrp );
1119 myMode = new QButtonGroup( this );
1120 myMode->addButton( aLength, Length );
1121 myMode->addButton( anArea, Area );
1122 myMode->addButton( aVolume, Volume );
1124 QHBoxLayout* aPropertyLayout = new QHBoxLayout;
1125 aPropertyLayout->addWidget( aLength );
1126 aPropertyLayout->addWidget( anArea );
1127 aPropertyLayout->addWidget( aVolume );
1129 aPropertyGrp->setLayout( aPropertyLayout );
1132 QGroupBox* aSourceGrp = new QGroupBox( tr( "SOURCE_MESH_SUBMESH_GROUP" ), this );
1134 mySource = new QLineEdit( aSourceGrp );
1135 mySource->setReadOnly( true );
1137 QHBoxLayout* aSourceLayout = new QHBoxLayout;
1138 aSourceLayout->addWidget( mySource );
1140 aSourceGrp->setLayout( aSourceLayout );
1143 QPushButton* aCompute = new QPushButton( tr( "COMPUTE" ), this );
1145 // Result of computation (length, area or volume)
1146 myResultGrp = new QGroupBox( this );
1148 myResult = new QLineEdit;
1149 myResult->setReadOnly( true );
1151 QHBoxLayout* aResultLayout = new QHBoxLayout;
1152 aResultLayout->addWidget( myResult );
1154 myResultGrp->setLayout( aResultLayout );
1157 QGridLayout* aMainLayout = new QGridLayout( this );
1158 aMainLayout->setMargin( MARGIN );
1159 aMainLayout->setSpacing( SPACING );
1161 aMainLayout->addWidget( aPropertyGrp, 0, 0, 1, 2 );
1162 aMainLayout->addWidget( aSourceGrp, 1, 0, 1, 2 );
1163 aMainLayout->addWidget( aCompute, 2, 0 );
1164 aMainLayout->addWidget( myResultGrp, 3, 0, 1, 2 );
1165 aMainLayout->setColumnStretch( 1, 5 );
1166 aMainLayout->setRowStretch( 4, 5 );
1172 connect( myMode, SIGNAL( buttonClicked( int ) ), this, SLOT( modeChanged( int ) ) );
1173 connect( aCompute, SIGNAL( clicked() ), this, SLOT( compute() ) );
1176 QList<SUIT_SelectionFilter*> filters;
1177 filters.append( new SMESH_TypeFilter( SMESH::MESHorSUBMESH ) );
1178 filters.append( new SMESH_TypeFilter( SMESH::GROUP ) );
1179 myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
1185 SMESHGUI_BasicProperties::~SMESHGUI_BasicProperties()
1190 \brief Sets the measurement mode.
1191 \param theMode the mode to set (length, area or volume meausurement)
1193 void SMESHGUI_BasicProperties::setMode( const Mode theMode )
1195 QRadioButton* aButton = qobject_cast<QRadioButton*>( myMode->button( theMode ) );
1197 aButton->setChecked( true );
1198 modeChanged( theMode );
1203 \brief Setup the selection mode.
1205 void SMESHGUI_BasicProperties::updateSelection()
1207 LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
1209 disconnect( selMgr, 0, this, 0 );
1210 selMgr->clearFilters();
1212 SMESH::SetPointRepresentation( false );
1213 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() ) {
1214 aViewWindow->SetSelectionMode( ActorSelection );
1216 selMgr->installFilter( myFilter );
1218 connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
1220 if ( mySource->text().isEmpty() )
1225 \brief Deactivate widget
1227 void SMESHGUI_BasicProperties::deactivate()
1229 disconnect( SMESHGUI::selectionMgr(), 0, this, 0 );
1233 \brief Called when selection is changed
1235 void SMESHGUI_BasicProperties::selectionChanged()
1237 SUIT_OverrideCursor wc;
1239 SALOME_ListIO selected;
1240 SMESHGUI::selectionMgr()->selectedObjects( selected );
1242 if ( selected.Extent() == 1 ) {
1243 Handle(SALOME_InteractiveObject) IO = selected.First();
1244 SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
1245 if ( !CORBA::is_nil( obj ) ) {
1249 SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
1250 mySource->setText( aName );
1258 \brief Called when the measurement mode selection is changed.
1259 \param theMode the selected mode
1261 void SMESHGUI_BasicProperties::modeChanged( int theMode )
1265 if ( theMode == Length ) {
1266 myResultGrp->setTitle( tr("LENGTH") );
1267 } else if ( theMode == Area ) {
1268 myResultGrp->setTitle( tr("AREA") );
1269 } else if ( theMode == Volume ) {
1270 myResultGrp->setTitle( tr("VOLUME") );
1275 \brief Calculate length, area or volume for the selected object(s)
1277 void SMESHGUI_BasicProperties::compute()
1279 SUIT_OverrideCursor wc;
1281 SMESH::SMESH_IDSource_var source;
1283 if ( !CORBA::is_nil( mySrc ) ) {
1285 int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
1286 SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements();
1290 if ( myMode->checkedId() == Length ) {
1291 result = measure->Length( mySrc.in() );
1292 } else if ( myMode->checkedId() == Area ) {
1293 result = measure->Area( mySrc.in() );
1294 } else if ( myMode->checkedId() == Volume ) {
1295 result = measure->Volume( mySrc.in() );
1298 measure->UnRegister();
1300 myResult->setText( QString::number( result, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
1307 \brief Reset the widget to the initial state (nullify the result field)
1309 void SMESHGUI_BasicProperties::clear()
1315 \class SMESHGUI_MeshInfoDlg
1316 \brief Centralized dialog box for the measurements
1321 \param parent parent widget
1322 \param page specifies the dialog page to be shown at the start-up
1324 SMESHGUI_MeasureDlg::SMESHGUI_MeasureDlg( QWidget* parent, int page )
1328 setAttribute( Qt::WA_DeleteOnClose, true );
1329 setWindowTitle( tr( "MEASUREMENTS" ) );
1330 setSizeGripEnabled( true );
1332 SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
1334 myTabWidget = new QTabWidget( this );
1338 myMinDist = new SMESHGUI_MinDistance( myTabWidget );
1339 int aMinDistInd = myTabWidget->addTab( myMinDist, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_MIN_DIST" ) ), tr( "MIN_DIST" ) );
1343 myBndBox = new SMESHGUI_BoundingBox( myTabWidget );
1344 int aBndBoxInd = myTabWidget->addTab( myBndBox, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_BND_BOX" ) ), tr( "BND_BOX" ) );
1348 myBasicProps = new SMESHGUI_BasicProperties( myTabWidget );
1349 int aBasicPropInd = myTabWidget->addTab( myBasicProps, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_BASIC_PROPS" ) ), tr( "BASIC_PROPERTIES" ) );
1352 QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
1353 okBtn->setAutoDefault( true );
1354 okBtn->setDefault( true );
1356 QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
1357 helpBtn->setAutoDefault( true );
1359 QHBoxLayout* btnLayout = new QHBoxLayout;
1360 btnLayout->setSpacing( SPACING );
1361 btnLayout->setMargin( 0 );
1362 btnLayout->addWidget( okBtn );
1363 btnLayout->addStretch( 10 );
1364 btnLayout->addWidget( helpBtn );
1366 QVBoxLayout* l = new QVBoxLayout ( this );
1367 l->setMargin( MARGIN );
1368 l->setSpacing( SPACING );
1369 l->addWidget( myTabWidget );
1371 l->addLayout( btnLayout );
1374 if ( page == MinDistance ) {
1375 anInd = aMinDistInd;
1376 } else if ( page == BoundingBox ) {
1378 } else if ( page == Length || page == Area || page == Volume ) {
1379 myBasicProps->setMode( (SMESHGUI_BasicProperties::Mode)(page - Length) );
1380 anInd = aBasicPropInd;
1384 myTabWidget->setCurrentIndex( anInd );
1387 connect( okBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
1388 connect( helpBtn, SIGNAL( clicked() ), this, SLOT( help() ) );
1389 connect( myTabWidget, SIGNAL( currentChanged( int ) ), this, SLOT( updateSelection() ) );
1390 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( deactivate() ) );
1391 connect( SMESHGUI::GetSMESHGUI(), SIGNAL( SignalCloseAllDialogs() ), this, SLOT( reject() ) );
1399 SMESHGUI_MeasureDlg::~SMESHGUI_MeasureDlg()
1404 \brief Perform clean-up actions on the dialog box closing.
1406 void SMESHGUI_MeasureDlg::reject()
1408 LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
1409 selMgr->clearFilters();
1410 SMESH::SetPointRepresentation( false );
1411 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
1412 aViewWindow->SetSelectionMode( ActorSelection );
1417 \brief Process keyboard event
1418 \param e key press event
1420 void SMESHGUI_MeasureDlg::keyPressEvent( QKeyEvent* e )
1422 QDialog::keyPressEvent( e );
1423 if ( !e->isAccepted() && e->key() == Qt::Key_F1 ) {
1430 \brief Reactivate dialog box, when mouse pointer goes into it.
1432 void SMESHGUI_MeasureDlg::enterEvent( QEvent* )
1438 \brief Setup selection mode depending on the current dialog box state.
1440 void SMESHGUI_MeasureDlg::updateSelection()
1442 if ( myTabWidget->currentIndex() == MinDistance )
1443 myMinDist->updateSelection();
1444 else if ( myTabWidget->currentIndex() == BoundingBox )
1445 myBndBox->updateSelection();
1447 myBndBox->erasePreview();
1448 myBasicProps->updateSelection();
1453 \brief Show help page
1455 void SMESHGUI_MeasureDlg::help()
1458 if ( myTabWidget->currentIndex() == MinDistance ) {
1459 aHelpFile = "measurements_page.html#min_distance_anchor";
1460 } else if ( myTabWidget->currentIndex() == BoundingBox ) {
1461 aHelpFile = "measurements_page.html#bounding_box_anchor";
1463 aHelpFile = "measurements_page.html#basic_properties_anchor";
1466 SMESH::ShowHelpFile( aHelpFile );
1470 \brief Activate dialog box
1472 void SMESHGUI_MeasureDlg::activate()
1474 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1475 SMESHGUI::GetSMESHGUI()->SetActiveDialogBox( this );
1476 myTabWidget->setEnabled( true );
1481 \brief Deactivate dialog box
1483 void SMESHGUI_MeasureDlg::deactivate()
1485 myBasicProps->deactivate();
1486 myMinDist->deactivate();
1487 myBndBox->deactivate();
1488 myTabWidget->setEnabled( false );
1489 disconnect( SMESHGUI::selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( updateInfo() ) );