Back to index

salome-smesh  6.5.0
SMESHGUI_NodesDlg.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 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_NodesDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_NodesDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_SpinBox.h"
00032 #include "SMESHGUI_Utils.h"
00033 #include "SMESHGUI_VTKUtils.h"
00034 #include "SMESHGUI_MeshUtils.h"
00035 #include "SMESHGUI_GroupUtils.h"
00036 
00037 #include <SMESH_Actor.h>
00038 #include <SMESH_ActorUtils.h>
00039 #include <SMESH_ObjectDef.h>
00040 
00041 #include <SMDS_Mesh.hxx>
00042 #include <SMDS_MeshNode.hxx>
00043 
00044 // SALOME GUI includes
00045 #include <SUIT_Session.h>
00046 #include <SUIT_OverrideCursor.h>
00047 #include <SUIT_MessageBox.h>
00048 #include <SUIT_Desktop.h>
00049 #include <SUIT_ResourceMgr.h>
00050 
00051 #include <LightApp_Application.h>
00052 #include <LightApp_SelectionMgr.h>
00053 
00054 #include <SalomeApp_Application.h>
00055 
00056 #include <SVTK_ViewWindow.h>
00057 #include <VTKViewer_Algorithm.h>
00058 #include <VTKViewer_CellLocationsArray.h>
00059 
00060 // SALOME KERNEL includes
00061 #include <SALOMEDS_Study.hxx>
00062 #include <SALOMEDS_SObject.hxx>
00063 
00064 #include <utilities.h>
00065 
00066 // VTK includes
00067 #include <vtkIdList.h>
00068 #include <vtkCellArray.h>
00069 #include <vtkUnsignedCharArray.h>
00070 #include <vtkUnstructuredGrid.h>
00071 #include <vtkDataSetMapper.h>
00072 #include <vtkRenderer.h>
00073 #include <vtkProperty.h>
00074 #include <vtkPoints.h>
00075 
00076 // Qt includes
00077 #include <QComboBox>
00078 #include <QGroupBox>
00079 #include <QLabel>
00080 #include <QPushButton>
00081 #include <QRadioButton>
00082 #include <QHBoxLayout>
00083 #include <QVBoxLayout>
00084 #include <QKeyEvent>
00085 #include <QButtonGroup>
00086 
00087 // IDL includes
00088 #include <SALOMEconfig.h>
00089 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00090 
00091 #define SPACING 6
00092 #define MARGIN  11
00093 
00094 namespace SMESH
00095 {
00096   long AddNode( SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z, const QStringList& theParameters )
00097   {
00098     long aNodeId = -1;
00099     SUIT_OverrideCursor wc;
00100     try {
00101       _PTR(SObject) aSobj = SMESH::FindSObject( theMesh );
00102       SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
00103       theMesh->SetParameters( theParameters.join(":").toLatin1().constData() );
00104       aNodeId = aMeshEditor->AddNode( x, y, z );
00105       _PTR(Study) aStudy = GetActiveStudyDocument();
00106       CORBA::Long anId = aStudy->StudyId();
00107       if (TVisualObjPtr aVisualObj = SMESH::GetVisualObj( anId, aSobj->GetID().c_str() ) ) {
00108         aVisualObj->Update( true );
00109       }
00110     } 
00111     catch ( SALOME::SALOME_Exception& exc ) {
00112       INFOS( "Follow exception was cought:\n\t" << exc.details.text );
00113     }
00114     catch ( const std::exception& exc ) {
00115       INFOS( "Follow exception was cought:\n\t" << exc.what() );
00116     } 
00117     catch ( ... ) {
00118       INFOS( "Unknown exception was cought !!!" );
00119     }
00120     return aNodeId;
00121   }
00122 
00123   class TNodeSimulation 
00124   {
00125     SVTK_ViewWindow*  myViewWindow;
00126 
00127     SALOME_Actor*     myPreviewActor;
00128     vtkDataSetMapper* myMapper;
00129     vtkPoints*        myPoints;
00130 
00131   public:
00132     TNodeSimulation( SVTK_ViewWindow* theViewWindow ):
00133       myViewWindow( theViewWindow )
00134     {
00135       vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
00136 
00137       // Create points
00138       myPoints = vtkPoints::New();
00139       myPoints->SetNumberOfPoints( 1 );
00140       myPoints->SetPoint( 0, 0.0, 0.0, 0.0 );
00141 
00142       // Create cells
00143       vtkIdList *anIdList = vtkIdList::New();
00144       anIdList->SetNumberOfIds( 1 );
00145 
00146       vtkCellArray *aCells = vtkCellArray::New();
00147       aCells->Allocate( 2, 0 );
00148 
00149       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
00150       aCellTypesArray->SetNumberOfComponents( 1 );
00151       aCellTypesArray->Allocate( 1 );
00152 
00153       anIdList->SetId( 0, 0 );
00154       aCells->InsertNextCell( anIdList );
00155       aCellTypesArray->InsertNextValue( VTK_VERTEX );
00156 
00157       VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
00158       aCellLocationsArray->SetNumberOfComponents( 1 );
00159       aCellLocationsArray->SetNumberOfTuples( 1 );
00160 
00161       aCells->InitTraversal();
00162       vtkIdType npts = 0;
00163       aCellLocationsArray->SetValue( 0, aCells->GetTraversalLocation( npts ) );
00164 
00165       aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
00166 
00167       aGrid->SetPoints( myPoints );
00168       aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells );
00169       aCellLocationsArray->Delete();
00170       aCellTypesArray->Delete();
00171       aCells->Delete();
00172       anIdList->Delete();
00173 
00174       // Create and display actor
00175       myMapper = vtkDataSetMapper::New();
00176       myMapper->SetInput( aGrid );
00177       aGrid->Delete();
00178 
00179       myPreviewActor = SALOME_Actor::New();
00180       myPreviewActor->SetInfinitive( true );
00181       myPreviewActor->VisibilityOff();
00182       myPreviewActor->PickableOff();
00183       myPreviewActor->SetMapper( myMapper );
00184 
00185       vtkProperty* aProp = vtkProperty::New();
00186       aProp->SetRepresentationToPoints();
00187 
00188       vtkFloatingPointType anRGB[3];
00189       GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
00190       aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00191 
00192       vtkFloatingPointType aPointSize = GetFloat( "SMESH:node_size", 3 );
00193       aProp->SetPointSize( aPointSize );
00194 
00195       myPreviewActor->SetProperty( aProp );
00196       aProp->Delete();
00197 
00198       myViewWindow->AddActor( myPreviewActor );
00199     }
00200 
00201     void SetPosition( float x, float y, float z )
00202     {
00203       myPoints->SetPoint( 0, x, y, z );
00204       myPoints->Modified();
00205       SetVisibility( true );
00206     }
00207 
00208     void SetVisibility( bool theVisibility )
00209     {
00210       myPreviewActor->SetVisibility( theVisibility );
00211       RepaintCurrentView();
00212     }
00213 
00214     ~TNodeSimulation()
00215     {
00216       myViewWindow->RemoveActor( myPreviewActor );
00217       myPreviewActor->Delete();
00218 
00219       myMapper->RemoveAllInputs();
00220       myMapper->Delete();
00221 
00222       myPoints->Delete();
00223     }
00224   };
00225 }
00226 
00227 //=================================================================================
00228 // class    : SMESHGUI_NodesDlg()
00229 // purpose  :
00230 //=================================================================================
00231 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( SMESHGUI* theModule ): 
00232   QDialog( SMESH::GetDesktop( theModule ) ),
00233   mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
00234   mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00235   mySMESHGUI( theModule )
00236 {
00237   setModal( false );
00238   setAttribute( Qt::WA_DeleteOnClose, true );
00239   setWindowTitle( tr("MESH_NODE_TITLE") );
00240   setSizeGripEnabled( true );
00241   
00242   mySimulation = new SMESH::TNodeSimulation( SMESH::GetViewWindow( mySMESHGUI ) );
00243   
00244   QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", 
00245                                                                    tr( "ICON_DLG_NODE" ) ) );
00246   
00247   QVBoxLayout* SMESHGUI_NodesDlgLayout = new QVBoxLayout( this );
00248   SMESHGUI_NodesDlgLayout->setSpacing( SPACING );
00249   SMESHGUI_NodesDlgLayout->setMargin( MARGIN );
00250 
00251   /***************************************************************/
00252   GroupConstructors = new QGroupBox( tr( "MESH_NODE" ), this );
00253   QButtonGroup* ButtonGroup = new QButtonGroup(this);
00254   QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout( GroupConstructors );
00255   GroupConstructorsLayout->setSpacing( SPACING );
00256   GroupConstructorsLayout->setMargin( MARGIN );
00257 
00258   Constructor1 = new QRadioButton( GroupConstructors );
00259   Constructor1->setIcon( image0 );
00260   Constructor1->setChecked( true );
00261   
00262   GroupConstructorsLayout->addWidget( Constructor1 );
00263   ButtonGroup->addButton( Constructor1, 0 );
00264 
00265   /***************************************************************/
00266   GroupCoordinates = new QGroupBox( tr( "SMESH_COORDINATES" ), this );
00267   QHBoxLayout* GroupCoordinatesLayout = new QHBoxLayout(GroupCoordinates);
00268   GroupCoordinatesLayout->setSpacing(SPACING);
00269   GroupCoordinatesLayout->setMargin(MARGIN);
00270 
00271   TextLabel_X = new QLabel( tr( "SMESH_X" ), GroupCoordinates );
00272   SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates );
00273 
00274   TextLabel_Y = new QLabel( tr( "SMESH_Y" ), GroupCoordinates );
00275   SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates );
00276 
00277   TextLabel_Z = new QLabel( tr( "SMESH_Z" ), GroupCoordinates );
00278   SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates );
00279 
00280   GroupCoordinatesLayout->addWidget( TextLabel_X );
00281   GroupCoordinatesLayout->addWidget( SpinBox_X ); 
00282   GroupCoordinatesLayout->addWidget( TextLabel_Y);
00283   GroupCoordinatesLayout->addWidget( SpinBox_Y );
00284   GroupCoordinatesLayout->addWidget( TextLabel_Z );
00285   GroupCoordinatesLayout->addWidget( SpinBox_Z );
00286   GroupCoordinatesLayout->setStretch(1, 1);
00287   GroupCoordinatesLayout->setStretch(3, 1);
00288   GroupCoordinatesLayout->setStretch(5, 1);
00289 
00290   /***************************************************************/
00291   GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
00292   GroupGroups->setCheckable( true );
00293   QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
00294   GroupGroupsLayout->setSpacing(SPACING);
00295   GroupGroupsLayout->setMargin(MARGIN);
00296 
00297   TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
00298   ComboBox_GroupName = new QComboBox( GroupGroups );
00299   ComboBox_GroupName->setEditable( true );
00300   ComboBox_GroupName->setInsertPolicy( QComboBox::NoInsert );
00301 
00302   GroupGroupsLayout->addWidget( TextLabel_GroupName );
00303   GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
00304 
00305   /***************************************************************/
00306   GroupButtons = new QGroupBox( this );
00307   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00308   GroupButtonsLayout->setSpacing( SPACING );
00309   GroupButtonsLayout->setMargin( MARGIN );
00310   buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
00311   buttonOk->setAutoDefault( true );
00312   buttonOk->setDefault( true );
00313   buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
00314   buttonApply->setAutoDefault( true );
00315   buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
00316   buttonCancel->setAutoDefault( true );
00317   buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
00318   buttonHelp->setAutoDefault( true );
00319 
00320   GroupButtonsLayout->addWidget( buttonOk );
00321   GroupButtonsLayout->addSpacing( 10 );
00322   GroupButtonsLayout->addWidget( buttonApply );
00323   GroupButtonsLayout->addSpacing( 10 );
00324   GroupButtonsLayout->addStretch();
00325   GroupButtonsLayout->addWidget( buttonCancel );
00326   GroupButtonsLayout->addWidget( buttonHelp );
00327 
00328   /***************************************************************/
00329   SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors );
00330   SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates );
00331   SMESHGUI_NodesDlgLayout->addWidget( GroupGroups );
00332   SMESHGUI_NodesDlgLayout->addWidget( GroupButtons );
00333 
00334   myHelpFileName = "adding_nodes_and_elements_page.html#adding_nodes_anchor";
00335 
00336   /* Initialisation and display */
00337   Init();
00338 }
00339 
00340 //=======================================================================
00341 // function : ~SMESHGUI_NodesDlg()
00342 // purpose  : Destructor
00343 //=======================================================================
00344 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
00345 {
00346   delete mySimulation;
00347 }
00348 
00349 //=================================================================================
00350 // function : Init()
00351 // purpose  :
00352 //=================================================================================
00353 void SMESHGUI_NodesDlg::Init()
00354 {
00355   /* Get setting of step value from file configuration */
00356   double step = 25.0;
00357 
00358   /* min, max, step and decimals for spin boxes */
00359   SpinBox_X->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, "length_precision" );
00360   SpinBox_Y->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, "length_precision" );
00361   SpinBox_Z->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, "length_precision" );
00362   SpinBox_X->SetValue( 0.0 );
00363   SpinBox_Y->SetValue( 0.0 );
00364   SpinBox_Z->SetValue( 0.0 );
00365 
00366   /* reset "Add to group" control */
00367   GroupGroups->setChecked( false );
00368 
00369   mySMESHGUI->SetActiveDialogBox( this );
00370 
00371   /* signals and slots connections */
00372   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00373   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
00374   connect( buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00375   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
00376 
00377   connect( SpinBox_X, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
00378   connect( SpinBox_Y, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
00379   connect( SpinBox_Z, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
00380 
00381   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ),      SLOT( SelectionIntoArgument() ) );
00382   connect( mySMESHGUI,     SIGNAL( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog() ) );
00383   /* to close dialog if study frame change */
00384   connect( mySMESHGUI,     SIGNAL( SignalStudyFrameChanged() ),      SLOT( ClickOnCancel() ) );
00385   connect(mySMESHGUI,      SIGNAL(SignalCloseAllDialogs()),          SLOT(ClickOnCancel()));
00386 
00387   // set selection mode
00388   SMESH::SetPointRepresentation( true );
00389   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00390     aViewWindow->SetSelectionMode( NodeSelection );
00391 
00392   SelectionIntoArgument();
00393 }
00394 
00395 //=================================================================================
00396 // function : ValueChangedInSpinBox()
00397 // purpose  :
00398 //=================================================================================
00399 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
00400 {
00401   if ( !myMesh->_is_nil() ) {
00402     double vx = SpinBox_X->GetValue();
00403     double vy = SpinBox_Y->GetValue();
00404     double vz = SpinBox_Z->GetValue();
00405 
00406     mySimulation->SetPosition( vx, vy, vz );
00407   }
00408 }
00409 
00410 //=================================================================================
00411 // function : ClickOnOk()
00412 // purpose  :
00413 //=================================================================================
00414 void SMESHGUI_NodesDlg::ClickOnOk()
00415 {
00416   if ( ClickOnApply() )
00417     ClickOnCancel();
00418 }
00419 
00420 //=================================================================================
00421 // function : ClickOnApply()
00422 // purpose  :
00423 //=================================================================================
00424 bool SMESHGUI_NodesDlg::ClickOnApply()
00425 {
00426   if ( mySMESHGUI->isActiveStudyLocked() )
00427     return false;
00428 
00429   if ( myMesh->_is_nil() ) {
00430     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ),
00431                               tr( "MESH_IS_NOT_SELECTED" ) );
00432     return false;
00433   }
00434 
00435   if( !isValid() )
00436     return false;
00437 
00438   /* Recup args and call method */
00439   double x = SpinBox_X->GetValue();
00440   double y = SpinBox_Y->GetValue();
00441   double z = SpinBox_Z->GetValue();
00442 
00443   QStringList aParameters;
00444   aParameters << SpinBox_X->text();
00445   aParameters << SpinBox_Y->text();
00446   aParameters << SpinBox_Z->text();
00447 
00448   bool addToGroup = GroupGroups->isChecked();
00449   QString aGroupName;
00450 
00451   SMESH::SMESH_GroupBase_var aGroup;
00452   int idx = 0;
00453   if( addToGroup ) {
00454     aGroupName = ComboBox_GroupName->currentText();
00455     for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
00456       QString aName = ComboBox_GroupName->itemText( i );
00457       if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
00458         idx = i;
00459     }
00460     if ( idx > 0 && idx < myGroups.count() ) {
00461       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
00462       if ( !aGeomGroup->_is_nil() ) {
00463         int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
00464                                              tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
00465                                              tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
00466         if ( res == 1 ) return false;
00467       }
00468       aGroup = myGroups[idx-1];
00469     }
00470   }
00471       
00472   mySimulation->SetVisibility( false );
00473 
00474   long aNodeId = SMESH::AddNode( myMesh, x, y, z, aParameters );
00475 
00476   SMESH::SetPointRepresentation( true );
00477 
00478   if ( aNodeId != -1 && addToGroup && !aGroupName.isEmpty() ) {
00479     SMESH::SMESH_Group_var aGroupUsed;
00480     if ( aGroup->_is_nil() ){
00481       // create new group 
00482       aGroupUsed = SMESH::AddGroup( myMesh, SMESH::NODE, aGroupName );
00483       if ( !aGroupUsed->_is_nil() ) {
00484         myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
00485         ComboBox_GroupName->addItem( aGroupName );
00486       }
00487     }
00488     else {
00489       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
00490       if ( !aGeomGroup->_is_nil() ) {
00491         aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
00492         if ( !aGroupUsed->_is_nil() && idx > 0 ) {
00493           myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
00494           SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
00495         }
00496       }
00497       else
00498         aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
00499     }
00500 
00501     if ( !aGroupUsed->_is_nil() ) {
00502       SMESH::long_array_var anIdList = new SMESH::long_array;
00503       anIdList->length( 1 );
00504       anIdList[0] = aNodeId;
00505       aGroupUsed->Add( anIdList.inout() );
00506     }
00507   }
00508 
00509   // select myMesh
00510   SALOME_ListIO aList;
00511   mySelectionMgr->selectedObjects( aList );
00512   if ( aList.Extent() != 1 ) {
00513     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() ) {
00514       VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
00515       vtkActorCollection *aCollection = aCopy.GetActors();
00516       aCollection->InitTraversal();
00517       while ( vtkActor *anAct = aCollection->GetNextActor() ) {
00518         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) ) {
00519           if ( anActor->hasIO() ) {
00520             if ( SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>( anActor->GetObject().get() ) ) {
00521               if ( myMesh->_is_equivalent( aMeshObj->GetMeshServer() ) ) {
00522                 aList.Clear();
00523                 aList.Append( anActor->getIO() );
00524                 mySelectionMgr->setSelectedObjects( aList, false );
00525                 break;
00526               }
00527             }
00528           }
00529         }
00530       }
00531     }
00532   }
00533 
00534   SMESHGUI::Modified();
00535   SMESH::UpdateView();
00536   mySimulation->SetVisibility(false);
00537 
00538   return true;
00539 }
00540 
00541 //=================================================================================
00542 // function : ClickOnCancel()
00543 // purpose  :
00544 //=================================================================================
00545 void SMESHGUI_NodesDlg::ClickOnCancel()
00546 {
00547   disconnect( mySelectionMgr, 0, this, 0 );
00548   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00549     aViewWindow->SetSelectionMode( ActorSelection );
00550 
00551   mySimulation->SetVisibility( false );
00552   SMESH::SetPointRepresentation( false );
00553   mySMESHGUI->ResetState();
00554 
00555   reject();
00556 }
00557 
00558 //=================================================================================
00559 // function : ClickOnHelp()
00560 // purpose  :
00561 //=================================================================================
00562 void SMESHGUI_NodesDlg::ClickOnHelp()
00563 {
00564   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00565   if ( app ) 
00566     app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : 
00567                               QString( "" ), myHelpFileName );
00568   else {
00569     QString platform;
00570 #ifdef WIN32
00571     platform = "winapplication";
00572 #else
00573     platform = "application";
00574 #endif
00575     SUIT_MessageBox::warning( this, tr("WRN_WARNING"),
00576                               tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00577                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
00578                                                                     platform ) ).
00579                               arg( myHelpFileName ) );
00580   }
00581 }
00582 
00583 //=================================================================================
00584 // function : SelectionIntoArgument()
00585 // purpose  : Called when selection as changed or other case
00586 //=================================================================================
00587 void SMESHGUI_NodesDlg::SelectionIntoArgument()
00588 {
00589   if ( !GroupConstructors->isEnabled() )
00590     return;
00591 
00592   mySimulation->SetVisibility( false );
00593   SMESH::SetPointRepresentation( true );
00594 
00595   QString aCurrentEntry = myEntry;
00596 
00597   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00598   if ( aList.Extent() == 1 ) {
00599     Handle(SALOME_InteractiveObject) anIO = aList.First();
00600     if ( anIO->hasEntry() ) {
00601       myEntry = anIO->getEntry();
00602       myMesh = SMESH::GetMeshByIO( anIO );
00603       if ( myMesh->_is_nil() ) return;
00604       QString aText;
00605       if ( SMESH::GetNameOfSelectedNodes( mySelector, anIO, aText ) == 1 ) {
00606         if ( SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh.in() ) ) {
00607           if ( SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh() ) {
00608             if ( const SMDS_MeshNode* aNode = aMesh->FindNode( aText.toInt() ) ) {
00609               SpinBox_X->SetValue( aNode->X() );
00610               SpinBox_Y->SetValue( aNode->Y() );
00611               SpinBox_Z->SetValue( aNode->Z() );
00612             }
00613           }
00614         }
00615       }
00616       mySimulation->SetPosition( SpinBox_X->GetValue(),
00617                                  SpinBox_Y->GetValue(),
00618                                  SpinBox_Z->GetValue() );
00619     }
00620   }
00621 
00622   // process groups
00623   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
00624     myGroups.clear();
00625     ComboBox_GroupName->clear();
00626     ComboBox_GroupName->addItem( QString() );
00627     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
00628     for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
00629       SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
00630       if ( !aGroup->_is_nil() && aGroup->GetType() == SMESH::NODE ) {
00631         QString aGroupName( aGroup->GetName() );
00632         if ( !aGroupName.isEmpty() ) {
00633           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
00634           ComboBox_GroupName->addItem( aGroupName );
00635         }
00636       }
00637     }
00638   }
00639 }
00640 
00641 //=================================================================================
00642 // function : closeEvent()
00643 // purpose  :
00644 //=================================================================================
00645 void SMESHGUI_NodesDlg::closeEvent( QCloseEvent* )
00646 {
00647   this->ClickOnCancel(); /* same than click on cancel button */
00648 }
00649 
00650 //=================================================================================
00651 // function : hideEvent()
00652 // purpose  : caused by ESC key
00653 //=================================================================================
00654 void SMESHGUI_NodesDlg::hideEvent( QHideEvent* )
00655 {
00656   if ( !isMinimized() )
00657     ClickOnCancel();
00658 }
00659 
00660 //=================================================================================
00661 // function : enterEvent()
00662 // purpose  : to reactivate this dialog box when mouse enter onto the window
00663 //=================================================================================
00664 void SMESHGUI_NodesDlg::enterEvent( QEvent* )
00665 {
00666   if ( !GroupConstructors->isEnabled() )
00667     ActivateThisDialog();
00668 }
00669 
00670 //=================================================================================
00671 // function : DeactivateActiveDialog()
00672 // purpose  : public slot to deactivate if active
00673 //=================================================================================
00674 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
00675 {
00676   if ( GroupConstructors->isEnabled() ) {
00677     GroupConstructors->setEnabled( false );
00678     GroupCoordinates->setEnabled( false );
00679     GroupButtons->setEnabled( false );
00680     mySimulation->SetVisibility( false );
00681     mySMESHGUI->ResetState();
00682     mySMESHGUI->SetActiveDialogBox( 0 );
00683   }
00684 }
00685 
00686 //=================================================================================
00687 // function : ActivateThisDialog()
00688 // purpose  :
00689 //=================================================================================
00690 void SMESHGUI_NodesDlg::ActivateThisDialog()
00691 {
00692   mySMESHGUI->EmitSignalDeactivateDialog();
00693   GroupConstructors->setEnabled( true );
00694   GroupCoordinates->setEnabled( true );
00695   GroupButtons->setEnabled( true );
00696 
00697   SMESH::SetPointRepresentation( true );
00698   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00699     aViewWindow->SetSelectionMode( NodeSelection );
00700 
00701   SelectionIntoArgument();
00702 }
00703 
00704 //=================================================================================
00705 // function : keyPressEvent()
00706 // purpose  :
00707 //=================================================================================
00708 void SMESHGUI_NodesDlg::keyPressEvent( QKeyEvent* e )
00709 {
00710   QDialog::keyPressEvent( e );
00711   if ( e->isAccepted() )
00712     return;
00713 
00714   if ( e->key() == Qt::Key_F1 ) {
00715     e->accept();
00716     ClickOnHelp();
00717   }
00718 }
00719 
00720 //=================================================================================
00721 // function : isValid
00722 // purpose  :
00723 //=================================================================================
00724 bool SMESHGUI_NodesDlg::isValid()
00725 {
00726   QString msg;
00727   bool ok = true;
00728   ok = SpinBox_X->isValid( msg, true ) && ok;
00729   ok = SpinBox_Y->isValid( msg, true ) && ok;
00730   ok = SpinBox_Z->isValid( msg, true ) && ok;
00731 
00732   if( !ok ) {
00733     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00734     if ( !msg.isEmpty() )
00735       str += "\n" + msg;
00736     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00737     return false;
00738   }
00739 
00740   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
00741     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
00742     return false;
00743   }
00744   return true;
00745 }