]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
SMESHGUI_DeleteOp operation added
authorsln <sln@opencascade.com>
Thu, 14 Jul 2005 09:59:06 +0000 (09:59 +0000)
committersln <sln@opencascade.com>
Thu, 14 Jul 2005 09:59:06 +0000 (09:59 +0000)
src/SMESHGUI/Makefile.in
src/SMESHGUI/SMESHGUI.cxx
src/SMESHGUI/SMESHGUI_DeleteOp.cxx [new file with mode: 0755]
src/SMESHGUI/SMESHGUI_DeleteOp.h [new file with mode: 0755]
src/SMESHGUI/SMESH_msg_en.po

index 448420647823c1bdce19240f2af3ef1da1ca9fa7..1aa77135798bf6dc65424a7a2ee43cab78541718 100644 (file)
@@ -116,7 +116,8 @@ LIB_SRC =   SMESHGUI.cxx \
                SMESHGUI_CreatePolyhedralVolumeDlg.cxx \
                SMESHGUI_Dialog.cxx \
                SMESHGUI_Operation.cxx \
-               SMESHGUI_SelectionOp.cxx
+               SMESHGUI_SelectionOp.cxx \
+               SMESHGUI_DeleteOp.cxx
 
 LIB_MOC = \
                SMESHGUI.h \
@@ -169,6 +170,7 @@ LIB_MOC = \
                SMESHGUI_Dialog.h \
                SMESHGUI_CreatePolyhedralVolumeDlg.h \
                SMESHGUI_Operation.h \
+               SMESHGUI_DeleteOp.h \
                SMESHGUI_SelectionOp.h
     
 LIB_CLIENT_IDL = SALOME_Exception.idl \
index 2d215dc02303ac116f79a38908692f3aa147a720..6b2d1e1cd43b0e91d8411a2d3c0df6d7f77988de 100644 (file)
@@ -28,6 +28,7 @@
 #include "SMESHGUI_InitMeshOp.h"
 #include "SMESHGUI_AddSubMeshOp.h"
 #include "SMESHGUI_NodesOp.h"
+#include "SMESHGUI_DeleteOp.h"
 #include "SMESHGUI_TransparencyDlg.h"
 #include "SMESHGUI_ClippingDlg.h"
 #include "SMESHGUI_GroupDlg.h"
@@ -714,115 +715,6 @@ namespace{
 
     return RefType;
   }
-
-  void OnEditDelete()
-  {
-    // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
-    SalomeApp_SelectionMgr* aSel = SMESHGUI::selectionMgr();
-    SALOME_ListIO selected; aSel->selectedObjects( selected );
-
-    QString aParentComponent = QString::null;
-    for( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
-    {
-      QString cur = anIt.Value()->getComponentDataType();
-      if( aParentComponent.isNull() )
-        aParentComponent = cur;
-      else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
-        aParentComponent = "";
-    }
-
-    if ( aParentComponent != SMESHGUI::GetSMESHGUI()->name() )  {
-      SUIT_MessageBox::warn1 ( SMESHGUI::desktop(),
-                             QObject::tr("ERR_ERROR"),
-                             QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg( SMESHGUI::GetSMESHGUI()->moduleName() ),
-                             QObject::tr("BUT_OK") );
-      return;
-    }
-    // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
-    if (SUIT_MessageBox::warn2
-       (SMESHGUI::desktop(),
-        QObject::tr("SMESH_WRN_WARNING"),
-        QObject::tr("SMESH_REALLY_DELETE"),
-        QObject::tr("SMESH_BUT_YES"), QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
-      return;
-
-    SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
-    SUIT_ViewManager* vm = anApp->activeViewManager();
-    int nbSf = vm->getViewsCount();
-
-    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-    _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
-    _PTR(GenericAttribute) anAttr;
-    _PTR(AttributeIOR) anIOR;
-
-    SALOME_ListIteratorOfListIO It(selected);
-
-    aStudyBuilder->NewCommand();  // There is a transaction
-    for(; It.More(); It.Next()){
-      Handle(SALOME_InteractiveObject) IObject = It.Value();
-      if(IObject->hasEntry()){
-       _PTR(SObject) SO = aStudy->FindObjectID(IObject->getEntry());
-
-       /* Erase child graphical objects */
-       _PTR(ChildIterator) it = aStudy->NewChildIterator(SO);
-       for(it->InitEx(true); it->More(); it->Next()){
-         _PTR(SObject) CSO = it->Value();
-         if(CSO->FindAttribute(anAttr, "AttributeIOR")){
-           anIOR = anAttr;
-
-           QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
-           for(int i = 0; i < nbSf; i++){
-             SUIT_ViewWindow *sf = aViews[i];
-             CORBA::String_var anEntry = CSO->GetID().c_str();
-             if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
-               SMESH::RemoveActor(sf,anActor);
-             }
-           }
-         }
-       }
-
-       /* Erase main graphical object */
-       QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
-       for(int i = 0; i < nbSf; i++){
-         SUIT_ViewWindow *sf = aViews[i];
-         if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
-           SMESH::RemoveActor(sf,anActor);
-         }
-       }
-
-       // Remove object(s) from data structures
-       _PTR(SObject) obj = aStudy->FindObjectID(IObject->getEntry());
-       if(obj){
-         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( obj ) );
-         SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( obj ) );
-
-         if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
-           SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
-           aMesh->RemoveGroup( aGroup );
-         }
-         else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
-           SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
-           aMesh->RemoveSubMesh( aSubMesh );
-         }
-         else {// default action: remove SObject from the study
-           // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
-           //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
-           //op->start();
-           aStudyBuilder->RemoveObjectWithChildren( obj );
-           //op->finish();
-         }
-       }
-
-      } /* IObject->hasEntry() */
-    } /* more/next */
-    aStudyBuilder->CommitCommand();
-
-    /* Clear any previous selection */
-    SALOME_ListIO l1;
-    aSel->setSelectedObjects( l1 );
-
-    SMESHGUI::GetSMESHGUI()->updateObjBrowser();
-  }
 }
 
 extern "C" {
@@ -1115,9 +1007,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   QAction* act = action( theCommandID );
 
   switch (theCommandID)        {
-  case 33:                                     // DELETE
-    if(checkLock(aStudy)) break;
-    ::OnEditDelete();
+  case 33:  // DELETE
+      startOperation( 33 );
     break;
 
   case 113:                                    // IMPORT
@@ -3292,7 +3183,11 @@ SalomeApp_Operation* SMESHGUI::createOperation( const int id ) const
 {
   SalomeApp_Operation* op = 0;
   switch( id )
-  {     
+  {
+    case 33:
+      op = new SMESHGUI_DeleteOp();
+      break;
+    
     case 400:
       op = new SMESHGUI_NodesOp();
       break;
diff --git a/src/SMESHGUI/SMESHGUI_DeleteOp.cxx b/src/SMESHGUI/SMESHGUI_DeleteOp.cxx
new file mode 100755 (executable)
index 0000000..afcc895
--- /dev/null
@@ -0,0 +1,206 @@
+//  SALOME SMESHGUI
+//
+//  Copyright (C) 2005  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : SMESHGUI_DeleteOp.cxx
+//  Author : Sergey LITONIN
+//  Module : SALOME
+
+
+#include "SMESHGUI_DeleteOp.h"
+#include "SMESHGUI_Utils.h"
+#include "SMESHGUI.h"
+#include "SMESHGUI_VTKUtils.h"
+#include <SMESH_Actor.h>
+#include <SalomeApp_UpdateFlags.h>
+#include <SalomeApp_Tools.h>
+#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
+#include <SalomeApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ViewManager.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_Desktop.h>
+#include <qapplication.h>
+
+/*!
+ * \brief Constructor
+*/
+SMESHGUI_DeleteOp::SMESHGUI_DeleteOp()
+: SMESHGUI_Operation()
+{
+}
+
+/*!
+ * \brief Destructor
+*/
+SMESHGUI_DeleteOp::~SMESHGUI_DeleteOp()
+{
+}
+
+/*!
+ * \brief Verifies whether operation is ready to start
+  * \return TRUE if operation is ready to start, FALSE otherwise
+*
+* Virtual method redefined from the base class verifies whether operation is ready to start
+*/
+bool SMESHGUI_DeleteOp::isReadyToStart() const
+{
+  if ( !SMESHGUI_Operation::isReadyToStart() )
+    return false;
+    
+  // VSR 17/11/04: check if all objects selected belong to SMESH component --> start
+  SALOME_ListIO selected;
+  selectionMgr()->selectedObjects( selected );
+
+  QString aParentComponent = QString::null;
+  for ( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() )
+  {
+    QString cur = anIt.Value()->getComponentDataType();
+    if ( aParentComponent.isNull() )
+      aParentComponent = cur;
+    else if( !aParentComponent.isEmpty() && aParentComponent!=cur )
+      aParentComponent = "";
+  }
+
+  if ( aParentComponent != getSMESHGUI()->name() )
+  {
+    QString aMess = QObject::tr("NON_SMESH_OBJECTS_SELECTED").arg(
+      getSMESHGUI()->moduleName() );
+    SUIT_MessageBox::warn1 ( desktop(), QObject::tr( "ERR_ERROR" ), aMess, tr( "BUT_OK" ) );
+    return false;
+  }
+  
+  // VSR 17/11/04: check if all objects selected belong to SMESH component <-- finish
+  if ( SUIT_MessageBox::warn2 ( desktop(), QObject::tr( "SMESH_WRN_WARNING" ),
+         QObject::tr( "SMESH_REALLY_DELETE" ), tr( "SMESH_BUT_YES"),
+         QObject::tr("SMESH_BUT_NO"), 1, 0, 0) != 1 )
+    return false;
+
+  if ( isStudyLocked() )
+    return false;
+
+  return true;
+}
+
+/*!
+ * \brief Deletes selected objects
+  * \return TRUE if operation is ready to start, FALSE otherwise
+*
+* Virtual method redefined from the base deletes selected objects
+*/
+void SMESHGUI_DeleteOp::startOperation()
+{
+  QApplication::setOverrideCursor( Qt::waitCursor );
+  
+  try
+  {
+    SUIT_ViewManager* vm =
+      ( (SalomeApp_Application*) application() )->activeViewManager();
+    int nbSf = vm->getViewsCount();
+
+    _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+    _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
+    _PTR(GenericAttribute) anAttr;
+    _PTR(AttributeIOR) anIOR;
+
+    SALOME_ListIO selected;
+    selectionMgr()->selectedObjects( selected );
+    SALOME_ListIteratorOfListIO It( selected );
+
+    aStudyBuilder->NewCommand();  // There is a transaction
+    for ( ; It.More(); It.Next() )
+    {
+      Handle(SALOME_InteractiveObject) IObject = It.Value();
+      if ( IObject->hasEntry())
+      {
+        _PTR(SObject) SO = aStudy->FindObjectID(IObject->getEntry());
+
+        /* Erase child graphical objects */
+        _PTR(ChildIterator) it = aStudy->NewChildIterator(SO);
+        for ( it->InitEx(true); it->More(); it->Next())
+        {
+          _PTR(SObject) CSO = it->Value();
+          if ( CSO->FindAttribute( anAttr, "AttributeIOR" ) )
+          {
+            anIOR = anAttr;
+            QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
+            for ( int i = 0; i < nbSf; i++ )
+            {
+              SUIT_ViewWindow *sf = aViews[ i ];
+              CORBA::String_var anEntry = CSO->GetID().c_str();
+              if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( sf,anEntry.in() ) )
+                SMESH::RemoveActor(sf,anActor);
+            }
+          }
+        }
+
+        /* Erase main graphical object */
+        QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
+        for ( int i = 0; i < nbSf; i++ )
+        {
+          SUIT_ViewWindow *sf = aViews[ i ];
+          if ( SMESH_Actor* anActor = SMESH::FindActorByEntry( sf,IObject->getEntry() ) )
+            SMESH::RemoveActor(sf,anActor);
+        }
+
+        // Remove object(s) from data structures
+        _PTR(SObject) obj = aStudy->FindObjectID(IObject->getEntry());
+        if ( obj )
+        {
+          SMESH::SMESH_GroupBase_var aGroup =
+            SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( obj ) );
+          SMESH::SMESH_subMesh_var   aSubMesh =
+            SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( obj ) );
+
+          if ( !aGroup->_is_nil() )  // DELETE GROUP
+          {
+            SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
+            aMesh->RemoveGroup( aGroup );
+          }
+          else if ( !aSubMesh->_is_nil() ) // DELETE SUBMESH
+          {
+            SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
+            aMesh->RemoveSubMesh( aSubMesh );
+          }
+          else
+          {
+            // default action: remove SObject from the study
+            // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
+            //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
+            //op->start();
+            aStudyBuilder->RemoveObjectWithChildren( obj );
+            //op->finish();
+          }
+        }
+      } /* IObject->hasEntry() */
+    } /* more/next */
+
+    aStudyBuilder->CommitCommand();
+
+    /* Clear any previous selection */
+    SALOME_ListIO l1;
+    selectionMgr()->setSelectedObjects( l1 );
+
+    update( UF_Model | UF_ObjBrowser );
+  }
+  catch ( const SALOME::SALOME_Exception& S_ex )
+  {
+    SalomeApp_Tools::QtCatchCorbaException(S_ex);
+  }
+  catch (...)
+  {
+  }
+
+  QApplication::restoreOverrideCursor();
+  commit();
+}
+
+
+
+
+
+
diff --git a/src/SMESHGUI/SMESHGUI_DeleteOp.h b/src/SMESHGUI/SMESHGUI_DeleteOp.h
new file mode 100755 (executable)
index 0000000..66b2357
--- /dev/null
@@ -0,0 +1,44 @@
+//  SALOME SMESHGUI
+//
+//  Copyright (C) 2005  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : SMESHGUI_DeleteOp.h
+//  Author : Sergey LITONIN
+//  Module : SALOME
+
+
+#ifndef SMESHGUI_DeleteOp_H
+#define SMESHGUI_DeleteOp_H
+
+#include "SMESHGUI_Operation.h"
+
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SMESH_Group)
+
+/*!
+ * \brief Operation for deleting objects
+*/
+
+class SMESHGUI_DeleteOp : public SMESHGUI_Operation
+{
+  Q_OBJECT
+
+public:
+  SMESHGUI_DeleteOp();
+  virtual ~SMESHGUI_DeleteOp();
+
+protected:
+
+  virtual bool isReadyToStart() const;
+  virtual void startOperation();
+};
+
+#endif
+
+
+
+
+
+
index 4f1839fac77da987f3ee1985b33e82c4d35d7089..65c6edfa3f57c6ec513d7196d577140a74114954 100644 (file)
@@ -2813,3 +2813,4 @@ msgstr "Hypothesises"
 
 msgid "SMESHGUI_Dialog::DLG_ALGO"
 msgstr "Algorithms"
+