Back to index

salome-smesh  6.5.0
SMESHGUI_Measurements.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : SMESHGUI_Measurements.cxx
00023 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00024 
00025 #include "SMESHGUI_Measurements.h"
00026 
00027 #include "SMESH_Actor.h"
00028 #include "SMESHGUI.h"
00029 #include "SMESHGUI_IdValidator.h"
00030 #include "SMESHGUI_Utils.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032 #include <SMESH_TypeFilter.hxx>
00033 #include <SMESH_LogicalFilter.hxx>
00034 
00035 #include <LightApp_SelectionMgr.h>
00036 #include <SUIT_OverrideCursor.h>
00037 #include <SUIT_ResourceMgr.h>
00038 #include <SVTK_ViewWindow.h>
00039 #include <SALOME_ListIteratorOfListIO.hxx>
00040 
00041 #include <QButtonGroup>
00042 #include <QGridLayout>
00043 #include <QGroupBox>
00044 #include <QHBoxLayout>
00045 #include <QKeyEvent>
00046 #include <QLabel>
00047 #include <QLineEdit>
00048 #include <QPushButton>
00049 #include <QRadioButton>
00050 #include <QTabWidget>
00051 #include <QVBoxLayout>
00052 
00053 #include <vtkPoints.h>
00054 #include <vtkUnstructuredGrid.h>
00055 #include <vtkIdList.h>
00056 #include <vtkCellArray.h>
00057 #include <vtkUnsignedCharArray.h>
00058 #include <vtkDataSetMapper.h>
00059 #include <VTKViewer_CellLocationsArray.h>
00060 #include <vtkProperty.h>
00061 
00062 #include <SALOMEconfig.h>
00063 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00064 #include CORBA_SERVER_HEADER(SMESH_Measurements)
00065 
00066 const int SPACING = 6;            // layout spacing
00067 const int MARGIN  = 9;            // layout margin
00068 const int MAX_NB_FOR_EDITOR = 40; // max nb of items in the ID list editor field
00069 
00070 // Uncomment as soon as elements are supported by Min Distance operation
00071 //#define MINDIST_ENABLE_ELEMENT
00072 
00073 // Uncomment as soon as objects are supported by Min Distance operation
00074 //#define MINDIST_ENABLE_OBJECT
00075 
00087 SMESHGUI_MinDistance::SMESHGUI_MinDistance( QWidget* parent )
00088 : QWidget( parent ), myCurrentTgt( FirstTgt ), myFirstActor( 0 ), mySecondActor( 0 ), myPreview( 0 )
00089 {
00090   QGroupBox*    aFirstTgtGrp = new QGroupBox( tr( "FIRST_TARGET" ), this );
00091   QRadioButton* aFNode       = new QRadioButton( tr( "NODE" ),    aFirstTgtGrp );
00092   QRadioButton* aFElem       = new QRadioButton( tr( "ELEMENT" ), aFirstTgtGrp );
00093   QRadioButton* aFObject     = new QRadioButton( tr( "OBJECT" ),  aFirstTgtGrp );
00094   myFirstTgt                 = new QLineEdit( aFirstTgtGrp );
00095 
00096   QGridLayout* fl = new QGridLayout( aFirstTgtGrp );
00097   fl->setMargin( MARGIN );
00098   fl->setSpacing( SPACING );
00099   fl->addWidget( aFNode,     0, 0 );
00100   fl->addWidget( aFElem,     0, 1 );
00101   fl->addWidget( aFObject,   0, 2 );
00102   fl->addWidget( myFirstTgt, 1, 0, 1, 3 );
00103 
00104   myFirst = new QButtonGroup( this );
00105   myFirst->addButton( aFNode,   NodeTgt );
00106   myFirst->addButton( aFElem,   ElementTgt );
00107   myFirst->addButton( aFObject, ObjectTgt );
00108 
00109   QGroupBox*    aSecondTgtGrp = new QGroupBox( tr( "SECOND_TARGET" ), this );
00110   QRadioButton* aSOrigin      = new QRadioButton( tr( "ORIGIN" ),  aSecondTgtGrp );
00111   QRadioButton* aSNode        = new QRadioButton( tr( "NODE" ),    aSecondTgtGrp );
00112   QRadioButton* aSElem        = new QRadioButton( tr( "ELEMENT" ), aSecondTgtGrp );
00113   QRadioButton* aSObject      = new QRadioButton( tr( "OBJECT" ),  aSecondTgtGrp );
00114   mySecondTgt                 = new QLineEdit( aSecondTgtGrp );
00115 
00116   QGridLayout* sl = new QGridLayout( aSecondTgtGrp );
00117   sl->setMargin( MARGIN );
00118   sl->setSpacing( SPACING );
00119   sl->addWidget( aSOrigin,   0, 0 );
00120   sl->addWidget( aSNode,     0, 1 );
00121   sl->addWidget( aSElem,     0, 2 );
00122   sl->addWidget( aSObject,   0, 3 );
00123   sl->addWidget( mySecondTgt, 1, 0, 1, 4 );
00124 
00125   mySecond = new QButtonGroup( this );
00126   mySecond->addButton( aSOrigin, OriginTgt );
00127   mySecond->addButton( aSNode,   NodeTgt );
00128   mySecond->addButton( aSElem,   ElementTgt );
00129   mySecond->addButton( aSObject, ObjectTgt );
00130 
00131   QPushButton* aCompute = new QPushButton( tr( "COMPUTE" ), this );
00132   
00133   QGroupBox* aResults = new QGroupBox( tr( "RESULT" ), this );
00134   QLabel* aDxLab   = new QLabel( "dX", aResults );
00135   myDX             = new QLineEdit( aResults );
00136   QLabel* aDyLab   = new QLabel( "dY", aResults );
00137   myDY             = new QLineEdit( aResults );
00138   QLabel* aDzLab   = new QLabel( "dZ", aResults );
00139   myDZ             = new QLineEdit( aResults );
00140   QLabel* aDistLab = new QLabel( tr( "DISTANCE" ), aResults );
00141   myDistance       = new QLineEdit( aResults );
00142 
00143   QGridLayout* rl = new QGridLayout( aResults );
00144   rl->setMargin( MARGIN );
00145   rl->setSpacing( SPACING );
00146   rl->addWidget( aDxLab,     0, 0 );
00147   rl->addWidget( myDX,       0, 1 );
00148   rl->addWidget( aDyLab,     1, 0 );
00149   rl->addWidget( myDY,       1, 1 );
00150   rl->addWidget( aDzLab,     2, 0 );
00151   rl->addWidget( myDZ,       2, 1 );
00152   rl->addWidget( aDistLab,   0, 2 );
00153   rl->addWidget( myDistance, 0, 3 );
00154 
00155   QGridLayout* l = new QGridLayout( this );
00156   l->setMargin( MARGIN );
00157   l->setSpacing( SPACING );
00158 
00159   l->addWidget( aFirstTgtGrp,  0, 0, 1, 2 );
00160   l->addWidget( aSecondTgtGrp, 1, 0, 1, 2 );
00161   l->addWidget( aCompute,      2, 0 );
00162   l->addWidget( aResults,      3, 0, 1, 2 );
00163   l->setColumnStretch( 1, 5 );
00164   l->setRowStretch( 4, 5 );
00165 
00166   aFNode->setChecked( true );
00167   aSOrigin->setChecked( true );
00168 #ifndef MINDIST_ENABLE_ELEMENT
00169   aFElem->setEnabled( false );   // NOT AVAILABLE YET
00170   aSElem->setEnabled( false );   // NOT AVAILABLE YET
00171 #endif
00172 #ifndef MINDIST_ENABLE_OBJECT
00173   aFObject->setEnabled( false ); // NOT AVAILABLE YET
00174   aSObject->setEnabled( false ); // NOT AVAILABLE YET
00175 #endif
00176   myDX->setReadOnly( true );
00177   myDY->setReadOnly( true );
00178   myDZ->setReadOnly( true );
00179   myDistance->setReadOnly( true );
00180 
00181   myValidator = new SMESHGUI_IdValidator( this, 1 );
00182 
00183   myFirstTgt->installEventFilter( this );
00184   mySecondTgt->installEventFilter( this );
00185 
00186   connect( myFirst,     SIGNAL( buttonClicked( int ) ),  this, SLOT( firstChanged() ) );
00187   connect( mySecond,    SIGNAL( buttonClicked( int ) ),  this, SLOT( secondChanged() ) );
00188   connect( aCompute,    SIGNAL( clicked() ),             this, SLOT( compute() ) );
00189   connect( myFirstTgt,  SIGNAL( textEdited( QString ) ), this, SLOT( firstEdited() ) );
00190   connect( mySecondTgt, SIGNAL( textEdited( QString ) ), this, SLOT( secondEdited() ) );
00191 
00192   QList<SUIT_SelectionFilter*> filters;
00193   filters.append( new SMESH_TypeFilter( MESHorSUBMESH ) );
00194   filters.append( new SMESH_TypeFilter( GROUP ) );
00195   myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
00196 
00197   mySecondTgt->setEnabled( mySecond->checkedId() != OriginTgt );
00198   clear();
00199 
00200   //setTarget( FirstTgt );
00201 }
00202 
00206 SMESHGUI_MinDistance::~SMESHGUI_MinDistance()
00207 {
00208   erasePreview();
00209   if ( myPreview )
00210     myPreview->Delete();
00211 }
00212 
00219 bool SMESHGUI_MinDistance::eventFilter( QObject* o, QEvent* e )
00220 {
00221   if ( e->type() == QEvent::FocusIn ) {
00222     if ( o == myFirstTgt )
00223       setTarget( FirstTgt );
00224     else if ( o == mySecondTgt )
00225       setTarget( SecondTgt );
00226   }
00227   return QWidget::eventFilter( o, e );
00228 }
00229 
00233 void SMESHGUI_MinDistance::updateSelection()
00234 {
00235   LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
00236 
00237   disconnect( selMgr, 0, this, 0 );
00238   selMgr->clearFilters();
00239   
00240   bool nodeMode = ( myCurrentTgt == FirstTgt  && myFirst->checkedId() == NodeTgt ) ||
00241                   ( myCurrentTgt == SecondTgt && mySecond->checkedId() == NodeTgt );
00242   bool elemMode = ( myCurrentTgt == FirstTgt  && myFirst->checkedId() == ElementTgt ) ||
00243                   ( myCurrentTgt == SecondTgt && mySecond->checkedId() == ElementTgt );
00244   bool objMode  = ( myCurrentTgt == FirstTgt  && myFirst->checkedId() == ObjectTgt ) ||
00245                   ( myCurrentTgt == SecondTgt && mySecond->checkedId() == ObjectTgt ) ||
00246                   ( myCurrentTgt == NoTgt );
00247 
00248   if ( nodeMode ) {
00249     SMESH::SetPointRepresentation( true );
00250     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00251       aViewWindow->SetSelectionMode( NodeSelection );
00252   }
00253   else if ( elemMode ) {
00254     SMESH::SetPointRepresentation( false );
00255     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00256       aViewWindow->SetSelectionMode( CellSelection );
00257   }
00258   else if ( objMode ) {
00259     SMESH::SetPointRepresentation( false );
00260     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00261       aViewWindow->SetSelectionMode( ActorSelection );
00262     selMgr->installFilter( myFilter );
00263   }
00264 
00265   connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
00266 
00267   if ( myCurrentTgt == FirstTgt )
00268     firstEdited();
00269   else if ( myCurrentTgt == SecondTgt )
00270     secondEdited();
00271 
00272   //selectionChanged();
00273 }
00274 
00278 void SMESHGUI_MinDistance::deactivate()
00279 {
00280   disconnect( SMESHGUI::selectionMgr(), 0, this, 0 );
00281 }
00282 
00287 void SMESHGUI_MinDistance::setTarget( int target )
00288 {
00289   if ( myCurrentTgt != target ) {
00290     myCurrentTgt = target;
00291     updateSelection();
00292   }
00293 }
00294 
00298 void SMESHGUI_MinDistance::erasePreview()
00299 {
00300   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
00301   if ( aViewWindow && myPreview ) {
00302     aViewWindow->RemoveActor( myPreview );
00303     aViewWindow->Repaint();
00304   }
00305 }
00306 
00310 void SMESHGUI_MinDistance::displayPreview()
00311 {
00312   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
00313   if ( aViewWindow && myPreview ) {
00314     aViewWindow->AddActor( myPreview );
00315     aViewWindow->Repaint();
00316   }
00317 }
00318 
00328 void SMESHGUI_MinDistance::createPreview( double x1, double y1, double z1, double x2, double y2, double z2 )
00329 {
00330   if ( myPreview )
00331     myPreview->Delete();
00332 
00333   vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
00334   // create points
00335   vtkPoints* aPoints = vtkPoints::New();
00336   aPoints->SetNumberOfPoints( 2 );
00337   aPoints->SetPoint( 0, x1, y1, z1 );
00338   aPoints->SetPoint( 1, x2, y2, z2 );
00339   aGrid->SetPoints( aPoints );
00340   aPoints->Delete();
00341   // create cells
00342   vtkIdList* anIdList = vtkIdList::New();
00343   anIdList->SetNumberOfIds( 2 );
00344   vtkCellArray* aCells = vtkCellArray::New();
00345   aCells->Allocate( 2, 0);
00346   vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00347   aCellTypesArray->SetNumberOfComponents( 1 );
00348   aCellTypesArray->Allocate( 1 );
00349   anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 1 );
00350   aCells->InsertNextCell( anIdList );
00351   aCellTypesArray->InsertNextValue( VTK_LINE );
00352   anIdList->Delete();
00353   VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00354   aCellLocationsArray->SetNumberOfComponents( 1 );
00355   aCellLocationsArray->SetNumberOfTuples( 1 );
00356   aCells->InitTraversal();
00357   for( vtkIdType idType = 0, *pts, npts; aCells->GetNextCell( npts, pts ); idType++ )
00358     aCellLocationsArray->SetValue( idType, aCells->GetTraversalLocation( npts ) );
00359   aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
00360   aCellLocationsArray->Delete();
00361   aCellTypesArray->Delete();
00362   aCells->Delete();
00363   // create actor
00364   vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
00365   aMapper->SetInput( aGrid );
00366   aGrid->Delete();
00367   myPreview = SALOME_Actor::New();
00368   myPreview->PickableOff();
00369   myPreview->SetMapper( aMapper );
00370   aMapper->Delete();
00371   vtkProperty* aProp = vtkProperty::New();
00372   aProp->SetRepresentationToWireframe();
00373   aProp->SetColor( 250, 0, 250 );
00374   aProp->SetPointSize( 5 );
00375   aProp->SetLineWidth( 3 );
00376   myPreview->SetProperty( aProp );
00377   aProp->Delete();
00378 }
00379 
00383 void SMESHGUI_MinDistance::selectionChanged()
00384 {
00385   SUIT_OverrideCursor wc;
00386 
00387   SALOME_ListIO selected;
00388   SMESHGUI::selectionMgr()->selectedObjects( selected );
00389 
00390   if ( selected.Extent() == 1 ) {
00391     Handle(SALOME_InteractiveObject) IO = selected.First();
00392     SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
00393     if ( !CORBA::is_nil( obj ) ) {
00394       if ( myCurrentTgt == FirstTgt ) {
00395         myFirstSrc = obj;
00396         myFirstActor = SMESH::FindActorByEntry( IO->getEntry() );
00397         if ( myFirst->checkedId() == ObjectTgt ) {
00398           QString aName;
00399           SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
00400           myFirstTgt->setText( aName );
00401         }
00402         else {
00403           SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
00404           QString ID;
00405           int nb = 0;
00406           if ( myFirstActor && selector ) {
00407             nb = myFirst->checkedId() == NodeTgt ? 
00408               SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
00409               SMESH::GetNameOfSelectedNodes( selector, IO, ID );
00410           }
00411           if ( nb == 1 )
00412             myFirstTgt->setText( ID.trimmed() );
00413           else
00414             myFirstTgt->clear();
00415         }
00416       }
00417       else if ( myCurrentTgt == SecondTgt ) {
00418         mySecondSrc = obj;
00419         mySecondActor = SMESH::FindActorByEntry( IO->getEntry() );
00420         if ( mySecond->checkedId() == ObjectTgt ) {
00421           QString aName;
00422           SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
00423           mySecondTgt->setText( aName );
00424         }
00425         else {
00426           SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
00427           QString ID;
00428           int nb = 0;
00429           if ( mySecondActor && selector ) {
00430             nb = mySecond->checkedId() == NodeTgt ? 
00431               SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
00432               SMESH::GetNameOfSelectedNodes( selector, IO, ID );
00433           }
00434           if ( nb == 1 )
00435             mySecondTgt->setText( ID.trimmed() );
00436           else
00437             mySecondTgt->clear();
00438         }
00439       }
00440     }
00441   }
00442   clear();
00443 }
00444 
00448 void SMESHGUI_MinDistance::firstChanged()
00449 {
00450   myFirstSrc = SMESH::SMESH_IDSource::_nil();
00451   myFirstTgt->clear();
00452   myFirstTgt->setReadOnly( myFirst->checkedId() == ObjectTgt );
00453   myFirstTgt->setValidator( myFirst->checkedId() == ObjectTgt ? 0 : myValidator );
00454   setTarget( FirstTgt );
00455   updateSelection();
00456   clear();
00457 }
00458 
00462 void SMESHGUI_MinDistance::secondChanged()
00463 {
00464   mySecondSrc = SMESH::SMESH_IDSource::_nil();
00465   mySecondTgt->setEnabled( mySecond->checkedId() != OriginTgt );
00466   mySecondTgt->setReadOnly( mySecond->checkedId() == ObjectTgt );
00467   mySecondTgt->setValidator( mySecond->checkedId() == ObjectTgt ? 0 : myValidator );
00468   mySecondTgt->clear();
00469   setTarget( mySecond->checkedId() != OriginTgt ? SecondTgt : NoTgt );
00470   updateSelection();
00471   clear();
00472 }
00473 
00477 void SMESHGUI_MinDistance::firstEdited()
00478 {
00479   setTarget( FirstTgt );
00480   if ( sender() == myFirstTgt )
00481     clear();
00482   SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
00483   if ( myFirstActor && selector ) {
00484     Handle(SALOME_InteractiveObject) IO = myFirstActor->getIO();
00485     if ( myFirst->checkedId() == NodeTgt || myFirst->checkedId() == ElementTgt ) {
00486       TColStd_MapOfInteger ID;
00487       ID.Add( myFirstTgt->text().toLong() );
00488       selector->AddOrRemoveIndex( IO, ID, false );
00489     }
00490     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00491       aViewWindow->highlight( IO, true, true );
00492   }
00493 }
00494 
00498 void SMESHGUI_MinDistance::secondEdited()
00499 {
00500   setTarget( SecondTgt );
00501   if ( sender() == mySecondTgt )
00502     clear();
00503   SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
00504   if ( mySecondActor && selector ) {
00505     Handle(SALOME_InteractiveObject) IO = mySecondActor->getIO();
00506     if ( mySecond->checkedId() == NodeTgt || mySecond->checkedId() == ElementTgt ) {
00507       TColStd_MapOfInteger ID;
00508       ID.Add( mySecondTgt->text().toLong() );
00509       selector->AddOrRemoveIndex( IO, ID, false );
00510     }
00511     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00512       aViewWindow->highlight( IO, true, true );
00513   }
00514 }
00515 
00519 void SMESHGUI_MinDistance::compute()
00520 {
00521   SUIT_OverrideCursor wc;
00522   SMESH::SMESH_IDSource_var s1;
00523   SMESH::SMESH_IDSource_var s2;
00524   bool isOrigin = mySecond->checkedId() == OriginTgt;
00525 
00526   // process first target
00527   if ( !CORBA::is_nil( myFirstSrc ) ) {
00528     if ( myFirst->checkedId() == NodeTgt || myFirst->checkedId() == ElementTgt ) {
00529       SMESH::SMESH_Mesh_var m = myFirstSrc->GetMesh();
00530       long id = myFirstTgt->text().toLong();
00531       if ( !CORBA::is_nil( m ) && id ) {
00532         SMESH::long_array_var ids = new SMESH::long_array();
00533         ids->length( 1 );
00534         ids[0] = id;
00535         SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor();
00536         s1 = me->MakeIDSource( ids.in(), myFirst->checkedId() == NodeTgt ? SMESH::NODE : SMESH::FACE );
00537       }
00538     }
00539     else {
00540       s1 = myFirstSrc;
00541     }
00542   }
00543 
00544   // process second target
00545   if ( !CORBA::is_nil( mySecondSrc ) ) {
00546     if ( mySecond->checkedId() == NodeTgt || mySecond->checkedId() == ElementTgt ) {
00547       SMESH::SMESH_Mesh_var m = mySecondSrc->GetMesh();
00548       long id = mySecondTgt->text().toLong();
00549       if ( !CORBA::is_nil( m ) && id ) {
00550         SMESH::long_array_var ids = new SMESH::long_array();
00551         ids->length( 1 );
00552         ids[0] = id;
00553         SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor();
00554         s2 = me->MakeIDSource( ids.in(), mySecond->checkedId() == NodeTgt ? SMESH::NODE : SMESH::FACE );
00555       }
00556     }
00557     else {
00558       s2 = mySecondSrc;
00559     }
00560   }
00561 
00562   if ( !CORBA::is_nil( s1 ) && ( !CORBA::is_nil( s2 ) || isOrigin ) ) {
00563     // compute min distance
00564     int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
00565     SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements();
00566     SMESH::Measure result = measure->MinDistance( s1.in(), s2.in() );
00567     measure->UnRegister();
00568     myDX->setText( QString::number( result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
00569     myDY->setText( QString::number( result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
00570     myDZ->setText( QString::number( result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
00571     myDistance->setText( QString::number( result.value, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
00572     // update preview actor
00573     erasePreview();
00574     double x1, y1, z1, x2, y2, z2;
00575     SMESH::double_array_var coord = s1->GetMesh()->GetNodeXYZ( result.node1 );
00576     x1 = coord[0]; y1 = coord[1]; z1 = coord[2];
00577     if ( isOrigin ) {
00578       x2 = y2 = z2 = 0.;
00579     }
00580     else {
00581       coord = s2->GetMesh()->GetNodeXYZ( result.node2 );
00582       x2 = coord[0]; y2 = coord[1]; z2 = coord[2];
00583     }
00584     createPreview( x1, y1, z1, x2, y2, z2 );
00585     displayPreview();
00586   }
00587   else {
00588     clear();
00589   }
00590 }
00591 
00595 void SMESHGUI_MinDistance::clear()
00596 {
00597   myDX->clear();
00598   myDY->clear();
00599   myDZ->clear();
00600   myDistance->clear();
00601   erasePreview();
00602 }
00603 
00615 SMESHGUI_BoundingBox::SMESHGUI_BoundingBox( QWidget* parent )
00616 : QWidget( parent ), myActor( 0 ), myPreview( 0 )
00617 {
00618   QGroupBox* aSourceGrp = new QGroupBox( tr( "SOURCE" ), this );
00619   QRadioButton* aObjects  = new QRadioButton( tr( "OBJECTS" ),  aSourceGrp );
00620   QRadioButton* aNodes    = new QRadioButton( tr( "NODES" ),    aSourceGrp );
00621   QRadioButton* aElements = new QRadioButton( tr( "ELEMENTS" ), aSourceGrp );
00622   mySource = new QLineEdit( aSourceGrp );
00623   
00624   QGridLayout* fl = new QGridLayout( aSourceGrp );
00625   fl->setMargin( MARGIN );
00626   fl->setSpacing( SPACING );
00627   fl->addWidget( aObjects,   0, 0 );
00628   fl->addWidget( aNodes,     0, 1 );
00629   fl->addWidget( aElements,  0, 2 );
00630   fl->addWidget( mySource,   1, 0, 1, 3 );
00631   
00632   mySourceMode = new QButtonGroup( this );
00633   mySourceMode->addButton( aObjects,  ObjectsSrc );
00634   mySourceMode->addButton( aNodes,    NodesSrc );
00635   mySourceMode->addButton( aElements, ElementsSrc );
00636 
00637   QPushButton* aCompute = new QPushButton( tr( "COMPUTE" ), this );
00638 
00639   QGroupBox* aResults = new QGroupBox( tr( "RESULT" ), this );
00640   QLabel* aXminLab = new QLabel( "Xmin", aResults );
00641   myXmin           = new QLineEdit( aResults );
00642   QLabel* aXmaxLab = new QLabel( "Xmax", aResults );
00643   myXmax           = new QLineEdit( aResults );
00644   QLabel* aDxLab   = new QLabel( "dX", aResults );
00645   myDX             = new QLineEdit( aResults );
00646   QLabel* aYminLab = new QLabel( "Ymin", aResults );
00647   myYmin           = new QLineEdit( aResults );
00648   QLabel* aYmaxLab = new QLabel( "Ymax", aResults );
00649   myYmax           = new QLineEdit( aResults );
00650   QLabel* aDyLab   = new QLabel( "dY", aResults );
00651   myDY             = new QLineEdit( aResults );
00652   QLabel* aZminLab = new QLabel( "Zmin", aResults );
00653   myZmin           = new QLineEdit( aResults );
00654   QLabel* aZmaxLab = new QLabel( "Zmax", aResults );
00655   myZmax           = new QLineEdit( aResults );
00656   QLabel* aDzLab   = new QLabel( "dZ", aResults );
00657   myDZ             = new QLineEdit( aResults );
00658 
00659   QGridLayout* rl  = new QGridLayout( aResults );
00660   rl->setMargin( MARGIN );
00661   rl->setSpacing( SPACING );
00662   rl->addWidget( aXminLab,   0, 0 );
00663   rl->addWidget( myXmin,     0, 1 );
00664   rl->addWidget( aXmaxLab,   0, 2 );
00665   rl->addWidget( myXmax,     0, 3 );
00666   rl->addWidget( aDxLab,     0, 4 );
00667   rl->addWidget( myDX,       0, 5 );
00668   rl->addWidget( aYminLab,   1, 0 );
00669   rl->addWidget( myYmin,     1, 1 );
00670   rl->addWidget( aYmaxLab,   1, 2 );
00671   rl->addWidget( myYmax,     1, 3 );
00672   rl->addWidget( aDyLab,     1, 4 );
00673   rl->addWidget( myDY,       1, 5 );
00674   rl->addWidget( aZminLab,   2, 0 );
00675   rl->addWidget( myZmin,     2, 1 );
00676   rl->addWidget( aZmaxLab,   2, 2 );
00677   rl->addWidget( myZmax,     2, 3 );
00678   rl->addWidget( aDzLab,     2, 4 );
00679   rl->addWidget( myDZ,       2, 5 );
00680 
00681   QGridLayout* l = new QGridLayout( this );
00682   l->setMargin( MARGIN );
00683   l->setSpacing( SPACING );
00684 
00685   l->addWidget( aSourceGrp, 0, 0, 1, 2 );
00686   l->addWidget( aCompute,   1, 0 );
00687   l->addWidget( aResults,   2, 0, 1, 2 );
00688   l->setColumnStretch( 1, 5 );
00689   l->setRowStretch( 3, 5 );
00690 
00691   aObjects->setChecked( true );
00692   myXmin->setReadOnly( true );
00693   myXmax->setReadOnly( true );
00694   myDX->setReadOnly( true );
00695   myYmin->setReadOnly( true );
00696   myYmax->setReadOnly( true );
00697   myDY->setReadOnly( true );
00698   myZmin->setReadOnly( true );
00699   myZmax->setReadOnly( true );
00700   myDZ->setReadOnly( true );
00701 
00702   myValidator = new SMESHGUI_IdValidator( this );
00703 
00704   connect( mySourceMode, SIGNAL( buttonClicked( int ) ),  this, SLOT( sourceChanged() ) );
00705   connect( aCompute,     SIGNAL( clicked() ),             this, SLOT( compute() ) );
00706   connect( mySource,     SIGNAL( textEdited( QString ) ), this, SLOT( sourceEdited() ) );
00707 
00708   QList<SUIT_SelectionFilter*> filters;
00709   filters.append( new SMESH_TypeFilter( MESHorSUBMESH ) );
00710   filters.append( new SMESH_TypeFilter( GROUP ) );
00711   myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
00712 
00713   clear();
00714 }
00715 
00719 SMESHGUI_BoundingBox::~SMESHGUI_BoundingBox()
00720 {
00721   erasePreview();
00722   if ( myPreview )
00723     myPreview->Delete();
00724 }
00725 
00729 void SMESHGUI_BoundingBox::updateSelection()
00730 {
00731   LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
00732 
00733   disconnect( selMgr, 0, this, 0 );
00734   selMgr->clearFilters();
00735   
00736   bool nodeMode = mySourceMode->checkedId() == NodesSrc;
00737   bool elemMode = mySourceMode->checkedId() == ElementsSrc;
00738   bool objMode  = mySourceMode->checkedId() == ObjectsSrc;
00739 
00740   if ( nodeMode ) {
00741     SMESH::SetPointRepresentation( true );
00742     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00743       aViewWindow->SetSelectionMode( NodeSelection );
00744   }
00745   else if ( elemMode ) {
00746     SMESH::SetPointRepresentation( false );
00747     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00748       aViewWindow->SetSelectionMode( CellSelection );
00749   }
00750   else if ( objMode ) {
00751     SMESH::SetPointRepresentation( false );
00752     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
00753       aViewWindow->SetSelectionMode( ActorSelection );
00754     selMgr->installFilter( myFilter );
00755   }
00756 
00757   connect( selMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
00758 
00759   sourceEdited();
00760 
00761   //selectionChanged();
00762 }
00763 
00767 void SMESHGUI_BoundingBox::deactivate()
00768 {
00769   disconnect( SMESHGUI::selectionMgr(), 0, this, 0 );
00770 }
00771 
00775 void SMESHGUI_BoundingBox::erasePreview()
00776 {
00777   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
00778   if ( aViewWindow && myPreview ) {
00779     aViewWindow->RemoveActor( myPreview );
00780     aViewWindow->Repaint();
00781   }
00782 }
00783 
00787 void SMESHGUI_BoundingBox::displayPreview()
00788 {
00789   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
00790   if ( aViewWindow && myPreview ) {
00791     aViewWindow->AddActor( myPreview );
00792     aViewWindow->Repaint();
00793   }
00794 }
00795 
00805 void SMESHGUI_BoundingBox::createPreview( double minX, double maxX, double minY, double maxY, double minZ, double maxZ )
00806 {
00807   if ( myPreview )
00808     myPreview->Delete();
00809 
00810   vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
00811   // create points
00812   vtkPoints* aPoints = vtkPoints::New();
00813   aPoints->SetNumberOfPoints( 8 );
00814   aPoints->SetPoint( 0, minX, minY, minZ );
00815   aPoints->SetPoint( 1, maxX, minY, minZ );
00816   aPoints->SetPoint( 2, minX, maxY, minZ );
00817   aPoints->SetPoint( 3, maxX, maxY, minZ );
00818   aPoints->SetPoint( 4, minX, minY, maxZ );
00819   aPoints->SetPoint( 5, maxX, minY, maxZ );
00820   aPoints->SetPoint( 6, minX, maxY, maxZ );
00821   aPoints->SetPoint( 7, maxX, maxY, maxZ );
00822   aGrid->SetPoints( aPoints );
00823   aPoints->Delete();
00824   // create cells
00825   // 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
00826   vtkIdList* anIdList = vtkIdList::New();
00827   anIdList->SetNumberOfIds( 2 );
00828   vtkCellArray* aCells = vtkCellArray::New();
00829   aCells->Allocate( 2*12, 0);
00830   vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00831   aCellTypesArray->SetNumberOfComponents( 1 );
00832   aCellTypesArray->Allocate( 12 );
00833   anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 1 );
00834   aCells->InsertNextCell( anIdList );
00835   aCellTypesArray->InsertNextValue( VTK_LINE );
00836   anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 4 );
00837   aCells->InsertNextCell( anIdList );
00838   aCellTypesArray->InsertNextValue( VTK_LINE );
00839   anIdList->SetId( 0, 0 ); anIdList->SetId( 1, 2 );
00840   aCells->InsertNextCell( anIdList );
00841   aCellTypesArray->InsertNextValue( VTK_LINE );
00842   anIdList->SetId( 0, 1 ); anIdList->SetId( 1, 5 );
00843   aCells->InsertNextCell( anIdList );
00844   aCellTypesArray->InsertNextValue( VTK_LINE );
00845   anIdList->SetId( 0, 1 ); anIdList->SetId( 1, 3 );
00846   aCells->InsertNextCell( anIdList );
00847   aCellTypesArray->InsertNextValue( VTK_LINE );
00848   anIdList->SetId( 0, 2 ); anIdList->SetId( 1, 6 );
00849   aCells->InsertNextCell( anIdList );
00850   aCellTypesArray->InsertNextValue( VTK_LINE );
00851   anIdList->SetId( 0, 2 ); anIdList->SetId( 1, 3 );
00852   aCells->InsertNextCell( anIdList );
00853   aCellTypesArray->InsertNextValue( VTK_LINE );
00854   anIdList->SetId( 0, 3 ); anIdList->SetId( 1, 7 );
00855   aCells->InsertNextCell( anIdList );
00856   aCellTypesArray->InsertNextValue( VTK_LINE );
00857   anIdList->SetId( 0, 4 ); anIdList->SetId( 1, 6 );
00858   aCells->InsertNextCell( anIdList );
00859   aCellTypesArray->InsertNextValue( VTK_LINE );
00860   anIdList->SetId( 0, 4 ); anIdList->SetId( 1, 5 );
00861   aCells->InsertNextCell( anIdList );
00862   aCellTypesArray->InsertNextValue( VTK_LINE );
00863   anIdList->SetId( 0, 5 ); anIdList->SetId( 1, 7 );
00864   aCells->InsertNextCell( anIdList );
00865   aCellTypesArray->InsertNextValue( VTK_LINE );
00866   anIdList->SetId( 0, 6 ); anIdList->SetId( 1, 7 );
00867   aCells->InsertNextCell( anIdList );
00868   aCellTypesArray->InsertNextValue( VTK_LINE );
00869   anIdList->Delete();
00870   VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00871   aCellLocationsArray->SetNumberOfComponents( 1 );
00872   aCellLocationsArray->SetNumberOfTuples( 12 );
00873   aCells->InitTraversal();
00874   for( vtkIdType idType = 0, *pts, npts; aCells->GetNextCell( npts, pts ); idType++ )
00875     aCellLocationsArray->SetValue( idType, aCells->GetTraversalLocation( npts ) );
00876   aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
00877   aCellLocationsArray->Delete();
00878   aCellTypesArray->Delete();
00879   aCells->Delete();
00880   // create actor
00881   vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
00882   aMapper->SetInput( aGrid );
00883   aGrid->Delete();
00884   myPreview = SALOME_Actor::New();
00885   myPreview->PickableOff();
00886   myPreview->SetMapper( aMapper );
00887   aMapper->Delete();
00888   vtkProperty* aProp = vtkProperty::New();
00889   aProp->SetRepresentationToWireframe();
00890   aProp->SetColor( 250, 0, 250 );
00891   aProp->SetPointSize( 5 );
00892   aProp->SetLineWidth( 3 );
00893   myPreview->SetProperty( aProp );
00894   aProp->Delete();
00895 }
00896 
00900 void SMESHGUI_BoundingBox::selectionChanged()
00901 {
00902   SUIT_OverrideCursor wc;
00903 
00904   SALOME_ListIO selected;
00905   SMESHGUI::selectionMgr()->selectedObjects( selected );
00906 
00907   if ( selected.Extent() == 1 ) {
00908     Handle(SALOME_InteractiveObject) IO = selected.First();
00909     SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
00910     if ( !CORBA::is_nil( obj ) ) {
00911       mySrc.clear();
00912       mySrc.append( obj );
00913       myActor = SMESH::FindActorByEntry( IO->getEntry() );
00914       if ( mySourceMode->checkedId() == ObjectsSrc ) {
00915         QString aName;
00916         SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
00917         mySource->setText( aName );
00918       }
00919       else {
00920         SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
00921         QString ID;
00922         int nb = 0;
00923         if ( myActor && selector ) {
00924           nb = mySourceMode->checkedId() == NodesSrc ? 
00925             SMESH::GetNameOfSelectedElements( selector, IO, ID ) :
00926             SMESH::GetNameOfSelectedNodes( selector, IO, ID );
00927         }
00928         if ( nb > 0 ) {
00929           myIDs = ID.trimmed();
00930           if ( nb < MAX_NB_FOR_EDITOR ) {
00931             mySource->setReadOnly( false );
00932             if ( mySource->validator() != myValidator )
00933               mySource->setValidator( myValidator );
00934             mySource->setText( ID.trimmed() );
00935           }
00936           else {
00937             mySource->setReadOnly( true );
00938             mySource->setValidator( 0 );
00939             mySource->setText( tr( "SELECTED_NB_OBJ" ).arg( nb )
00940                                .arg( mySourceMode->checkedId() == NodesSrc ? tr( "NB_NODES" ) : tr( "NB_ELEMENTS") ) );
00941           }
00942         }
00943         else {
00944           myIDs = "";
00945           mySource->clear();
00946           mySource->setReadOnly( false );
00947           mySource->setValidator( myValidator );
00948         }
00949       }
00950     }
00951   }
00952   else if ( selected.Extent() > 1 ) {
00953     myIDs = "";
00954     SALOME_ListIteratorOfListIO It( selected );
00955     mySrc.clear();
00956     myActor = 0;
00957     if ( mySourceMode->checkedId() == ObjectsSrc ) {
00958       for( ; It.More(); It.Next()){
00959         Handle(SALOME_InteractiveObject) IO = It.Value();
00960         SMESH::SMESH_IDSource_var obj = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
00961         if ( !CORBA::is_nil( obj ) ) {
00962           mySrc.append( obj );
00963         }
00964       }
00965       QString aName;
00966       SMESH::GetNameOfSelectedIObjects( SMESHGUI::selectionMgr(), aName );
00967       mySource->setText( aName );
00968     }
00969     else {
00970       mySource->clear();
00971     }
00972   }
00973   clear();
00974 }
00975 
00979 void SMESHGUI_BoundingBox::sourceChanged()
00980 {
00981   myIDs = "";
00982   mySource->clear();
00983   mySource->setReadOnly( mySourceMode->checkedId() == ObjectsSrc );
00984   mySource->setValidator( mySourceMode->checkedId() == ObjectsSrc ? 0 : myValidator );
00985   updateSelection();
00986   clear();
00987 }
00988 
00992 void SMESHGUI_BoundingBox::sourceEdited()
00993 {
00994   if ( sender() == mySource )
00995     clear();
00996   SVTK_Selector* selector = SMESH::GetViewWindow()->GetSelector();
00997   if ( myActor && selector ) {
00998     Handle(SALOME_InteractiveObject) IO = myActor->getIO();
00999     if ( mySourceMode->checkedId() == NodesSrc || mySourceMode->checkedId() == ElementsSrc ) {
01000       TColStd_MapOfInteger ID;
01001       if ( !mySource->isReadOnly() )
01002         myIDs = mySource->text();
01003       QStringList ids = myIDs.split( " ", QString::SkipEmptyParts );
01004       foreach ( QString id, ids )
01005         ID.Add( id.trimmed().toLong() );
01006       selector->AddOrRemoveIndex( IO, ID, false );
01007     }
01008     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
01009       aViewWindow->highlight( IO, true, true );
01010   }
01011 }
01012 
01016 void SMESHGUI_BoundingBox::compute()
01017 {
01018   SUIT_OverrideCursor wc;
01019   SMESH::ListOfIDSources_var srcList = new SMESH::ListOfIDSources();
01020   if ( mySourceMode->checkedId() == NodesSrc || mySourceMode->checkedId() == ElementsSrc ) {
01021     if ( mySrc.count() > 0 && !CORBA::is_nil( mySrc[0] ) ) {
01022       SMESH::SMESH_Mesh_var m = mySrc[0]->GetMesh();
01023       QStringList ids = myIDs.split( " ", QString::SkipEmptyParts );
01024       if ( !CORBA::is_nil( m ) && ids.count() > 0 ) {
01025         SMESH::long_array_var ids_in = new SMESH::long_array();
01026         ids_in->length( ids.count() );
01027         for( int i = 0; i < ids.count(); i++ )
01028           ids_in[i] = ids[i].trimmed().toLong();
01029         SMESH::SMESH_MeshEditor_var me = m->GetMeshEditor();
01030         SMESH::SMESH_IDSource_var s = me->MakeIDSource( ids_in.in(), mySourceMode->checkedId() == NodesSrc ? SMESH::NODE : SMESH::FACE ); 
01031         srcList->length( 1 );
01032         srcList[0] = s;
01033       }
01034     }
01035   }
01036   else {
01037     srcList->length( mySrc.count() );
01038     for( int i = 0; i < mySrc.count(); i++ )
01039       srcList[i] = mySrc[i];
01040   }
01041   if ( srcList->length() > 0 ) {
01042     // compute bounding box
01043     int precision = SMESHGUI::resourceMgr()->integerValue( "SMESH", "length_precision", 6 );
01044     SMESH::Measurements_var measure = SMESHGUI::GetSMESHGen()->CreateMeasurements();
01045     SMESH::Measure result = measure->BoundingBox( srcList.in() );
01046     measure->UnRegister();
01047     myXmin->setText( QString::number( result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01048     myXmax->setText( QString::number( result.maxX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01049     myDX->setText( QString::number( result.maxX-result.minX, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01050     myYmin->setText( QString::number( result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01051     myYmax->setText( QString::number( result.maxY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01052     myDY->setText( QString::number( result.maxY-result.minY, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01053     myZmin->setText( QString::number( result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01054     myZmax->setText( QString::number( result.maxZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01055     myDZ->setText( QString::number( result.maxZ-result.minZ, precision > 0 ? 'f' : 'g', qAbs( precision ) ) );
01056     // update preview actor
01057     erasePreview();
01058     createPreview( result.minX, result.maxX, result.minY, result.maxY, result.minZ, result.maxZ );
01059     displayPreview();
01060   }
01061   else {
01062     clear();
01063   }
01064 }
01065 
01069 void SMESHGUI_BoundingBox::clear()
01070 {
01071   myXmin->clear();
01072   myXmax->clear();
01073   myDX->clear();
01074   myYmin->clear();
01075   myYmax->clear();
01076   myDY->clear();
01077   myZmin->clear();
01078   myZmax->clear();
01079   myDZ->clear();
01080   erasePreview();
01081 }
01082 
01093 SMESHGUI_MeasureDlg::SMESHGUI_MeasureDlg( QWidget* parent, int page )
01094 : QDialog( parent )
01095 {
01096   setModal( false );
01097   setAttribute( Qt::WA_DeleteOnClose, true );
01098   setWindowTitle( tr( "MEASUREMENTS" ) );
01099   setSizeGripEnabled( true );
01100 
01101   SUIT_ResourceMgr* resMgr = SMESHGUI::resourceMgr();
01102 
01103   myTabWidget = new QTabWidget( this );
01104 
01105   // min distance
01106 
01107   myMinDist = new SMESHGUI_MinDistance( myTabWidget );
01108   myTabWidget->addTab( myMinDist, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_MIN_DIST" ) ), tr( "MIN_DIST" ) );
01109 
01110   // bounding box
01111   
01112   myBndBox = new SMESHGUI_BoundingBox( myTabWidget );
01113   myTabWidget->addTab( myBndBox, resMgr->loadPixmap( "SMESH", tr( "ICON_MEASURE_BND_BOX" ) ), tr( "BND_BOX" ) );
01114 
01115   // buttons
01116   QPushButton* okBtn = new QPushButton( tr( "SMESH_BUT_OK" ), this );
01117   okBtn->setAutoDefault( true );
01118   okBtn->setDefault( true );
01119   okBtn->setFocus();
01120   QPushButton* helpBtn = new QPushButton( tr( "SMESH_BUT_HELP" ), this );
01121   helpBtn->setAutoDefault( true );
01122 
01123   QHBoxLayout* btnLayout = new QHBoxLayout;
01124   btnLayout->setSpacing( SPACING );
01125   btnLayout->setMargin( 0 );
01126   btnLayout->addWidget( okBtn );
01127   btnLayout->addStretch( 10 );
01128   btnLayout->addWidget( helpBtn );
01129 
01130   QVBoxLayout* l = new QVBoxLayout ( this );
01131   l->setMargin( MARGIN );
01132   l->setSpacing( SPACING );
01133   l->addWidget( myTabWidget );
01134   l->addStretch();
01135   l->addLayout( btnLayout );
01136 
01137   myTabWidget->setCurrentIndex( qMax( (int)MinDistance, qMin( (int)BoundingBox, page ) ) );
01138 
01139   connect( okBtn,       SIGNAL( clicked() ),              this, SLOT( reject() ) );
01140   connect( helpBtn,     SIGNAL( clicked() ),              this, SLOT( help() ) );
01141   connect( myTabWidget, SIGNAL( currentChanged( int  ) ), this, SLOT( updateSelection() ) );
01142   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( deactivate() ) );
01143   connect( SMESHGUI::GetSMESHGUI(),  SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( reject() ) );
01144 
01145   updateSelection();
01146 }
01147 
01151 SMESHGUI_MeasureDlg::~SMESHGUI_MeasureDlg()
01152 {
01153 }
01154 
01158 void SMESHGUI_MeasureDlg::reject()
01159 {
01160   LightApp_SelectionMgr* selMgr = SMESHGUI::selectionMgr();
01161   selMgr->clearFilters();
01162   SMESH::SetPointRepresentation( false );
01163   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow() )
01164     aViewWindow->SetSelectionMode( ActorSelection );
01165   QDialog::reject();
01166 }
01167 
01172 void SMESHGUI_MeasureDlg::keyPressEvent( QKeyEvent* e )
01173 {
01174   QDialog::keyPressEvent( e );
01175   if ( !e->isAccepted() && e->key() == Qt::Key_F1 ) {
01176     e->accept();
01177     help();
01178   }
01179 }
01180 
01184 void SMESHGUI_MeasureDlg::enterEvent( QEvent* )
01185 {
01186   activate();
01187 }
01188 
01192 void SMESHGUI_MeasureDlg::updateSelection()
01193 {
01194   if ( myTabWidget->currentIndex() == MinDistance )
01195     myMinDist->updateSelection();
01196   else if ( myTabWidget->currentIndex() == BoundingBox )
01197     myBndBox->updateSelection();
01198     
01199 }
01200 
01204 void SMESHGUI_MeasureDlg::help()
01205 {
01206   SMESH::ShowHelpFile( myTabWidget->currentIndex() == MinDistance ?
01207                        "measurements_page.html#min_distance_anchor" : 
01208                        "measurements_page.html#bounding_box_anchor" );
01209 }
01210 
01214 void SMESHGUI_MeasureDlg::activate()
01215 {
01216   SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
01217   SMESHGUI::GetSMESHGUI()->SetActiveDialogBox( this );
01218   myTabWidget->setEnabled( true );
01219   updateSelection();
01220 }
01221 
01225 void SMESHGUI_MeasureDlg::deactivate()
01226 {
01227   myMinDist->deactivate();
01228   myBndBox->deactivate();
01229   myTabWidget->setEnabled( false );
01230   disconnect( SMESHGUI::selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( updateInfo() ) );
01231 }