Salome HOME
ClikOnClose() inexistant slot name corrected; onApply() return value corrected
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RemoveElementsDlg.cxx
index ae795cf64d5bbf84dcf977deb362d36255929069..18a63d2be0cc82b96630e099f24780cab4e8d6eb 100644 (file)
@@ -1,16 +1,41 @@
-using namespace std;
-//  File      : SMESHGUI_RemoveElementsDlg.cxx
-//  Created   : Fri Jun 07 11:18:31 2002
-//  Author    : Nicolas REJNERI
-
-//  Project   : SALOME
-//  Module    : SMESH
-//  Copyright : Open CASCADE 2002
+//  SMESH SMESHGUI : GUI for SMESH component
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SMESHGUI_RemoveElementsDlg.cxx
+//  Author : Nicolas REJNERI
+//  Module : SMESH
 //  $Header$
 
 #include "SMESHGUI_RemoveElementsDlg.h"
 
 #include "SMESHGUI.h"
+#include "SMESHGUI_Utils.h"
+#include "SMESHGUI_VTKUtils.h"
+#include "SMESHGUI_MeshUtils.h"
+#include "SMESHGUI_IdValidator.h"
+#include "SMESH_Actor.h"
+#include "SMDS_Mesh.hxx"
+
 #include "QAD_Application.h"
 #include "QAD_Desktop.h"
 #include "QAD_MessageBox.h"
@@ -30,6 +55,7 @@ using namespace std;
 #include <qimage.h>
 #include <qpixmap.h>
 
+using namespace std;
 
 //=================================================================================
 // class    : SMESHGUI_RemoveElementsDlg()
@@ -126,6 +152,7 @@ SMESHGUI_RemoveElementsDlg::SMESHGUI_RemoveElementsDlg( QWidget* parent, const c
     SelectButtonC1A1->setToggleButton( FALSE );
     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
+    LineEditC1A1->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
     SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupC1, 1, 0 );
 
@@ -153,10 +180,13 @@ void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
   myConstructorId = 0 ;
   Constructor1->setChecked( TRUE );
   myEditCurrentArgument = LineEditC1A1 ;       
+
   mySelection = Sel;  
-  this->myOkElements = false ;
+  myNbOkElements = false ;
   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
+  myActor = 0;
+  myBusy = false;
 
   /* signals and slots connections */
   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
@@ -169,6 +199,8 @@ void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
   /* to close dialog if study change */
   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
+  connect( myEditCurrentArgument, SIGNAL( textChanged( const QString& )),
+           SLOT( onTextChange( const QString& )));
 
   /* Move widget on the botton right corner of main widget */
   int x, y ;
@@ -176,7 +208,9 @@ void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
   this->move( x, y ) ;
   this->show() ; /* displays Dialog */
 
-  return ;
+  QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
+
+  SelectionIntoArgument();
 }
 
 
@@ -196,18 +230,33 @@ void SMESHGUI_RemoveElementsDlg::ConstructorsClicked(int constructorId)
 //=================================================================================
 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
 {
-  switch(myConstructorId)
-    { 
-    case 0 :
-      { 
-       if(myOkElements) {        
-         mySMESHGUI->RemoveElements( myMesh, myMapIndex ) ;
-         mySelection->ClearIObjects();
-       }
-       break ;
-      }
+  if (mySMESHGUI->ActiveStudyLocked())
+    return;
+  if ( myNbOkElements ) {
+    QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
+    SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
+    anArrayOfIdeces->length( aListId.count() );
+    for ( int i = 0; i < aListId.count(); i++ )
+      anArrayOfIdeces[i] = aListId[ i ].toInt();
+
+    bool aResult = false;
+    try
+    {
+      SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
+      aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.inout()) ;
     }
-  return ;
+    catch( ... )
+    {
+    }
+
+    if ( aResult )
+    {
+      Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
+      mySelection->ClearIObjects();
+      SMESH::UpdateView();
+      mySelection->AddIObject( anIO, false );
+    }
+  }
 }
 
 //=================================================================================
@@ -228,7 +277,8 @@ void SMESHGUI_RemoveElementsDlg::ClickOnOk()
 //=================================================================================
 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
 {
-  QAD_Application::getDesktop()->SetSelectionMode( 4 );
+  mySelection->ClearIObjects();
+  QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
   disconnect( mySelection, 0, this, 0 );
   mySMESHGUI->ResetState() ;
   reject() ;
@@ -236,39 +286,102 @@ void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
 }
 
 
+//=======================================================================
+//function : onTextChange
+//purpose  : 
+//=======================================================================
+
+void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
+{
+  if ( myBusy ) return;
+  myBusy = true;
+
+  myNbOkElements = 0;
+
+  buttonOk->setEnabled( false );
+  buttonApply->setEnabled( false );
+
+  // hilight entered elements
+  SMDS_Mesh* aMesh = 0;
+  if ( myActor )
+    aMesh = myActor->GetObject()->GetMesh();
+  if ( aMesh ) {
+
+    mySelection->ClearIObjects();
+    mySelection->AddIObject( myActor->getIO() );
+
+    QStringList aListId = QStringList::split( " ", theNewText, false);
+    for ( int i = 0; i < aListId.count(); i++ ) {
+      const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
+      if ( e ) {
+        if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
+          mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
+        myNbOkElements++;
+      }
+    }
+
+    if ( myNbOkElements ) {
+      buttonOk->setEnabled( true );
+      buttonApply->setEnabled( true );
+    }
+  }
+
+  myBusy = false;
+}
+
 //=================================================================================
 // function : SelectionIntoArgument()
 // purpose  : Called when selection as changed or other case
 //=================================================================================
 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
 {
-  myEditCurrentArgument->setText("") ;
-  myOkElements = false;
-  QString aString = "";
+  if ( myBusy ) return;
+
+  // clear
+
+  myNbOkElements = false;
+  myActor = 0;
+
+  myBusy = true;
+  myEditCurrentArgument->setText( "" );
+  myBusy = false;
+
+  if ( !GroupButtons->isEnabled() ) // inactive
+    return;
+
+  buttonOk->setEnabled( false );
+  buttonApply->setEnabled( false );
+
+  // get selected mesh
 
   int nbSel = mySelection->IObjectCount();
   if(nbSel != 1)
     return;
 
-  int nbElements = mySMESHGUI->GetNameOfSelectedElements(mySelection, aString) ;
-  if(nbElements < 1)
-    return ;
-  
-  if ( mySelection->SelectionMode() != 3 ) {
-    QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
-                           tr ("SMESH_WRN_SELECTIONMODE_ELEMENTS"), tr ("SMESH_BUT_YES") );
+  myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
+  if ( myMesh->_is_nil() )
     return;
-  }
 
-  myEditCurrentArgument->setText(aString) ;
-  Standard_Boolean res;
-  myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
-  if (!res)
+  myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
+  if ( !myActor )
+    return;
+
+  // get selected nodes
+
+  QString aString = "";
+  int nbElems = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
+  if(nbElems < 1)
     return ;
+  myBusy = true;
+  myEditCurrentArgument->setText( aString );
+  myBusy = false;
 
-  mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
-  myOkElements = true ;
-  return ;
+  // OK
+
+  myNbOkElements = nbElems;
+
+  buttonOk->setEnabled( true );
+  buttonApply->setEnabled( true );
 }
 
 
@@ -317,10 +430,12 @@ void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
 {
   /* Emit a signal to deactivate the active dialog */
   mySMESHGUI->EmitSignalDeactivateDialog() ;   
+
   GroupConstructors->setEnabled(true) ;
   GroupC1->setEnabled(true) ;
   GroupButtons->setEnabled(true) ;
-  return ;
+
+  QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
 }
 
 
@@ -330,10 +445,8 @@ void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
 //=================================================================================
 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent* e)
 {
-  if ( GroupConstructors->isEnabled() )
-    return ;  
-  ActivateThisDialog() ;
-  return ;
+  if ( !GroupConstructors->isEnabled() )
+    ActivateThisDialog() ;
 }
 
 
@@ -348,4 +461,13 @@ void SMESHGUI_RemoveElementsDlg::closeEvent( QCloseEvent* e )
   return ;
 }
 
+//=======================================================================
+//function : hideEvent
+//purpose  : caused by ESC key
+//=======================================================================
 
+void SMESHGUI_RemoveElementsDlg::hideEvent ( QHideEvent * e )
+{
+  if ( !isMinimized() )
+    ClickOnCancel();
+}