Version: 6.3.1

src/SMESHGUI/SMESHGUI_NodesDlg.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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       aNodeId = aMeshEditor->AddNode( x, y, z );
00104       theMesh->SetParameters( theParameters.join(":").toLatin1().constData() );
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 
00301   GroupGroupsLayout->addWidget( TextLabel_GroupName );
00302   GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
00303 
00304   /***************************************************************/
00305   GroupButtons = new QGroupBox( this );
00306   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00307   GroupButtonsLayout->setSpacing( SPACING );
00308   GroupButtonsLayout->setMargin( MARGIN );
00309   buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
00310   buttonOk->setAutoDefault( true );
00311   buttonOk->setDefault( true );
00312   buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
00313   buttonApply->setAutoDefault( true );
00314   buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
00315   buttonCancel->setAutoDefault( true );
00316   buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
00317   buttonHelp->setAutoDefault( true );
00318 
00319   GroupButtonsLayout->addWidget( buttonOk );
00320   GroupButtonsLayout->addSpacing( 10 );
00321   GroupButtonsLayout->addWidget( buttonApply );
00322   GroupButtonsLayout->addSpacing( 10 );
00323   GroupButtonsLayout->addStretch();
00324   GroupButtonsLayout->addWidget( buttonCancel );
00325   GroupButtonsLayout->addWidget( buttonHelp );
00326 
00327   /***************************************************************/
00328   SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors );
00329   SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates );
00330   SMESHGUI_NodesDlgLayout->addWidget( GroupGroups );
00331   SMESHGUI_NodesDlgLayout->addWidget( GroupButtons );
00332 
00333   myHelpFileName = "adding_nodes_and_elements_page.html#adding_nodes_anchor";
00334 
00335   /* Initialisation and display */
00336   Init();
00337 }
00338 
00339 //=======================================================================
00340 // function : ~SMESHGUI_NodesDlg()
00341 // purpose  : Destructor
00342 //=======================================================================
00343 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
00344 {
00345   delete mySimulation;
00346 }
00347 
00348 //=================================================================================
00349 // function : Init()
00350 // purpose  :
00351 //=================================================================================
00352 void SMESHGUI_NodesDlg::Init()
00353 {
00354   /* Get setting of step value from file configuration */
00355   double step = 25.0;
00356 
00357   /* min, max, step and decimals for spin boxes */
00358   SpinBox_X->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, "length_precision" );
00359   SpinBox_Y->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, "length_precision" );
00360   SpinBox_Z->RangeStepAndValidator( COORD_MIN, COORD_MAX, step, "length_precision" );
00361   SpinBox_X->SetValue( 0.0 );
00362   SpinBox_Y->SetValue( 0.0 );
00363   SpinBox_Z->SetValue( 0.0 );
00364 
00365   /* reset "Add to group" control */
00366   GroupGroups->setChecked( false );
00367 
00368   mySMESHGUI->SetActiveDialogBox( this );
00369 
00370   /* signals and slots connections */
00371   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00372   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
00373   connect( buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00374   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
00375 
00376   connect( SpinBox_X, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
00377   connect( SpinBox_Y, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
00378   connect( SpinBox_Z, SIGNAL( valueChanged( double ) ), SLOT( ValueChangedInSpinBox( double ) ) );
00379 
00380   connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ),      SLOT( SelectionIntoArgument() ) );
00381   connect( mySMESHGUI,     SIGNAL( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog() ) );
00382   /* to close dialog if study frame change */
00383   connect( mySMESHGUI,     SIGNAL( SignalStudyFrameChanged() ),      SLOT( ClickOnCancel() ) );
00384   connect(mySMESHGUI,      SIGNAL(SignalCloseAllDialogs()),          SLOT(ClickOnCancel()));
00385 
00386   // set selection mode
00387   SMESH::SetPointRepresentation( true );
00388   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00389     aViewWindow->SetSelectionMode( NodeSelection );
00390 
00391   SelectionIntoArgument();
00392 }
00393 
00394 //=================================================================================
00395 // function : ValueChangedInSpinBox()
00396 // purpose  :
00397 //=================================================================================
00398 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
00399 {
00400   if ( !myMesh->_is_nil() ) {
00401     double vx = SpinBox_X->GetValue();
00402     double vy = SpinBox_Y->GetValue();
00403     double vz = SpinBox_Z->GetValue();
00404 
00405     mySimulation->SetPosition( vx, vy, vz );
00406   }
00407 }
00408 
00409 //=================================================================================
00410 // function : ClickOnOk()
00411 // purpose  :
00412 //=================================================================================
00413 void SMESHGUI_NodesDlg::ClickOnOk()
00414 {
00415   if ( ClickOnApply() )
00416     ClickOnCancel();
00417 }
00418 
00419 //=================================================================================
00420 // function : ClickOnApply()
00421 // purpose  :
00422 //=================================================================================
00423 bool SMESHGUI_NodesDlg::ClickOnApply()
00424 {
00425   if ( mySMESHGUI->isActiveStudyLocked() )
00426     return false;
00427 
00428   if ( myMesh->_is_nil() ) {
00429     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ),
00430                               tr( "MESH_IS_NOT_SELECTED" ) );
00431     return false;
00432   }
00433 
00434   if( !isValid() )
00435     return false;
00436 
00437   /* Recup args and call method */
00438   double x = SpinBox_X->GetValue();
00439   double y = SpinBox_Y->GetValue();
00440   double z = SpinBox_Z->GetValue();
00441 
00442   QStringList aParameters;
00443   aParameters << SpinBox_X->text();
00444   aParameters << SpinBox_Y->text();
00445   aParameters << SpinBox_Z->text();
00446 
00447   bool addToGroup = GroupGroups->isChecked();
00448   QString aGroupName;
00449 
00450   SMESH::SMESH_GroupBase_var aGroup;
00451   int idx = 0;
00452   if( addToGroup ) {
00453     aGroupName = ComboBox_GroupName->currentText();
00454     for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
00455       QString aName = ComboBox_GroupName->itemText( i );
00456       if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
00457         idx = i;
00458     }
00459     if ( idx > 0 ) {
00460       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
00461       if ( !aGeomGroup->_is_nil() ) {
00462         int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
00463                                              tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
00464                                              tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
00465         if ( res == 1 ) return false;
00466       }
00467       aGroup = myGroups[idx-1];
00468     }
00469   }
00470       
00471   mySimulation->SetVisibility( false );
00472 
00473   long aNodeId = SMESH::AddNode( myMesh, x, y, z, aParameters );
00474 
00475   SMESH::SetPointRepresentation( true );
00476 
00477   if ( aNodeId != -1 && addToGroup && !aGroupName.isEmpty() ) {
00478     SMESH::SMESH_Group_var aGroupUsed;
00479     if ( aGroup->_is_nil() ){
00480       // create new group 
00481       aGroupUsed = SMESH::AddGroup( myMesh, SMESH::NODE, aGroupName );
00482       if ( !aGroupUsed->_is_nil() ) {
00483         myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
00484         ComboBox_GroupName->addItem( aGroupName );
00485       }
00486     }
00487     else {
00488       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
00489       if ( !aGeomGroup->_is_nil() ) {
00490         aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
00491         if ( !aGroupUsed->_is_nil() && idx > 0 ) {
00492           myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
00493           SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
00494         }
00495       }
00496       else
00497         aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
00498     }
00499 
00500     if ( !aGroupUsed->_is_nil() ) {
00501       SMESH::long_array_var anIdList = new SMESH::long_array;
00502       anIdList->length( 1 );
00503       anIdList[0] = aNodeId;
00504       aGroupUsed->Add( anIdList.inout() );
00505     }
00506   }
00507 
00508   // select myMesh
00509   SALOME_ListIO aList;
00510   mySelectionMgr->selectedObjects( aList );
00511   if ( aList.Extent() != 1 ) {
00512     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() ) {
00513       VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
00514       vtkActorCollection *aCollection = aCopy.GetActors();
00515       aCollection->InitTraversal();
00516       while ( vtkActor *anAct = aCollection->GetNextActor() ) {
00517         if ( SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>( anAct ) ) {
00518           if ( anActor->hasIO() ) {
00519             if ( SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>( anActor->GetObject().get() ) ) {
00520               if ( myMesh->_is_equivalent( aMeshObj->GetMeshServer() ) ) {
00521                 aList.Clear();
00522                 aList.Append( anActor->getIO() );
00523                 mySelectionMgr->setSelectedObjects( aList, false );
00524                 break;
00525               }
00526             }
00527           }
00528         }
00529       }
00530     }
00531   }
00532 
00533   SMESHGUI::Modified();
00534   SMESH::UpdateView();
00535   mySimulation->SetVisibility(false);
00536 
00537   return true;
00538 }
00539 
00540 //=================================================================================
00541 // function : ClickOnCancel()
00542 // purpose  :
00543 //=================================================================================
00544 void SMESHGUI_NodesDlg::ClickOnCancel()
00545 {
00546   disconnect( mySelectionMgr, 0, this, 0 );
00547   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00548     aViewWindow->SetSelectionMode( ActorSelection );
00549 
00550   mySimulation->SetVisibility( false );
00551   SMESH::SetPointRepresentation( false );
00552   mySMESHGUI->ResetState();
00553 
00554   reject();
00555 }
00556 
00557 //=================================================================================
00558 // function : ClickOnHelp()
00559 // purpose  :
00560 //=================================================================================
00561 void SMESHGUI_NodesDlg::ClickOnHelp()
00562 {
00563   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00564   if ( app ) 
00565     app->onHelpContextModule( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : 
00566                               QString( "" ), myHelpFileName );
00567   else {
00568     QString platform;
00569 #ifdef WIN32
00570     platform = "winapplication";
00571 #else
00572     platform = "application";
00573 #endif
00574     SUIT_MessageBox::warning( this, tr("WRN_WARNING"),
00575                               tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00576                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
00577                                                                     platform ) ).
00578                               arg( myHelpFileName ) );
00579   }
00580 }
00581 
00582 //=================================================================================
00583 // function : SelectionIntoArgument()
00584 // purpose  : Called when selection as changed or other case
00585 //=================================================================================
00586 void SMESHGUI_NodesDlg::SelectionIntoArgument()
00587 {
00588   if ( !GroupConstructors->isEnabled() )
00589     return;
00590 
00591   mySimulation->SetVisibility( false );
00592   SMESH::SetPointRepresentation( true );
00593 
00594   QString aCurrentEntry = myEntry;
00595 
00596   const SALOME_ListIO& aList = mySelector->StoredIObjects();
00597   if ( aList.Extent() == 1 ) {
00598     Handle(SALOME_InteractiveObject) anIO = aList.First();
00599     if ( anIO->hasEntry() ) {
00600       myEntry = anIO->getEntry();
00601       myMesh = SMESH::GetMeshByIO( anIO );
00602       if ( myMesh->_is_nil() ) return;
00603       QString aText;
00604       if ( SMESH::GetNameOfSelectedNodes( mySelector, anIO, aText ) == 1 ) {
00605         if ( SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh.in() ) ) {
00606           if ( SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh() ) {
00607             if ( const SMDS_MeshNode* aNode = aMesh->FindNode( aText.toInt() ) ) {
00608               SpinBox_X->SetValue( aNode->X() );
00609               SpinBox_Y->SetValue( aNode->Y() );
00610               SpinBox_Z->SetValue( aNode->Z() );
00611             }
00612           }
00613         }
00614       }
00615       mySimulation->SetPosition( SpinBox_X->GetValue(),
00616                                  SpinBox_Y->GetValue(),
00617                                  SpinBox_Z->GetValue() );
00618     }
00619   }
00620 
00621   // process groups
00622   if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
00623     myGroups.clear();
00624     ComboBox_GroupName->clear();
00625     ComboBox_GroupName->addItem( QString() );
00626     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
00627     for( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
00628       SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
00629       if ( !aGroup->_is_nil() && aGroup->GetType() == SMESH::NODE ) {
00630         QString aGroupName( aGroup->GetName() );
00631         if ( !aGroupName.isEmpty() ) {
00632           myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
00633           ComboBox_GroupName->addItem( aGroupName );
00634         }
00635       }
00636     }
00637   }
00638 }
00639 
00640 //=================================================================================
00641 // function : closeEvent()
00642 // purpose  :
00643 //=================================================================================
00644 void SMESHGUI_NodesDlg::closeEvent( QCloseEvent* )
00645 {
00646   this->ClickOnCancel(); /* same than click on cancel button */
00647 }
00648 
00649 //=================================================================================
00650 // function : hideEvent()
00651 // purpose  : caused by ESC key
00652 //=================================================================================
00653 void SMESHGUI_NodesDlg::hideEvent( QHideEvent* )
00654 {
00655   if ( !isMinimized() )
00656     ClickOnCancel();
00657 }
00658 
00659 //=================================================================================
00660 // function : enterEvent()
00661 // purpose  : to reactivate this dialog box when mouse enter onto the window
00662 //=================================================================================
00663 void SMESHGUI_NodesDlg::enterEvent( QEvent* )
00664 {
00665   if ( !GroupConstructors->isEnabled() )
00666     ActivateThisDialog();
00667 }
00668 
00669 //=================================================================================
00670 // function : DeactivateActiveDialog()
00671 // purpose  : public slot to deactivate if active
00672 //=================================================================================
00673 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
00674 {
00675   if ( GroupConstructors->isEnabled() ) {
00676     GroupConstructors->setEnabled( false );
00677     GroupCoordinates->setEnabled( false );
00678     GroupButtons->setEnabled( false );
00679     mySimulation->SetVisibility( false );
00680     mySMESHGUI->ResetState();
00681     mySMESHGUI->SetActiveDialogBox( 0 );
00682   }
00683 }
00684 
00685 //=================================================================================
00686 // function : ActivateThisDialog()
00687 // purpose  :
00688 //=================================================================================
00689 void SMESHGUI_NodesDlg::ActivateThisDialog()
00690 {
00691   mySMESHGUI->EmitSignalDeactivateDialog();
00692   GroupConstructors->setEnabled( true );
00693   GroupCoordinates->setEnabled( true );
00694   GroupButtons->setEnabled( true );
00695 
00696   SMESH::SetPointRepresentation( true );
00697   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ) )
00698     aViewWindow->SetSelectionMode( NodeSelection );
00699 
00700   SelectionIntoArgument();
00701 }
00702 
00703 //=================================================================================
00704 // function : keyPressEvent()
00705 // purpose  :
00706 //=================================================================================
00707 void SMESHGUI_NodesDlg::keyPressEvent( QKeyEvent* e )
00708 {
00709   QDialog::keyPressEvent( e );
00710   if ( e->isAccepted() )
00711     return;
00712 
00713   if ( e->key() == Qt::Key_F1 ) {
00714     e->accept();
00715     ClickOnHelp();
00716   }
00717 }
00718 
00719 //=================================================================================
00720 // function : isValid
00721 // purpose  :
00722 //=================================================================================
00723 bool SMESHGUI_NodesDlg::isValid()
00724 {
00725   QString msg;
00726   bool ok = true;
00727   ok = SpinBox_X->isValid( msg, true ) && ok;
00728   ok = SpinBox_Y->isValid( msg, true ) && ok;
00729   ok = SpinBox_Z->isValid( msg, true ) && ok;
00730 
00731   if( !ok ) {
00732     QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00733     if ( !msg.isEmpty() )
00734       str += "\n" + msg;
00735     SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00736     return false;
00737   }
00738 
00739   if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
00740     SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
00741     return false;
00742   }
00743   return true;
00744 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS