From 2439f9a459c92ba5adbb7ff64f0ad8f04771c4d6 Mon Sep 17 00:00:00 2001 From: sln Date: Thu, 14 Jul 2005 09:59:06 +0000 Subject: [PATCH] SMESHGUI_DeleteOp operation added --- src/SMESHGUI/Makefile.in | 4 +- src/SMESHGUI/SMESHGUI.cxx | 121 ++--------------- src/SMESHGUI/SMESHGUI_DeleteOp.cxx | 206 +++++++++++++++++++++++++++++ src/SMESHGUI/SMESHGUI_DeleteOp.h | 44 ++++++ src/SMESHGUI/SMESH_msg_en.po | 1 + 5 files changed, 262 insertions(+), 114 deletions(-) create mode 100755 src/SMESHGUI/SMESHGUI_DeleteOp.cxx create mode 100755 src/SMESHGUI/SMESHGUI_DeleteOp.h diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index 448420647..1aa771357 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -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 \ diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 2d215dc02..6b2d1e1cd 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -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( 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 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 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 index 000000000..afcc895c9 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_DeleteOp.cxx @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*! + * \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 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 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 index 000000000..66b235722 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_DeleteOp.h @@ -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 +#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 + + + + + + diff --git a/src/SMESHGUI/SMESH_msg_en.po b/src/SMESHGUI/SMESH_msg_en.po index 4f1839fac..65c6edfa3 100644 --- a/src/SMESHGUI/SMESH_msg_en.po +++ b/src/SMESHGUI/SMESH_msg_en.po @@ -2813,3 +2813,4 @@ msgstr "Hypothesises" msgid "SMESHGUI_Dialog::DLG_ALGO" msgstr "Algorithms" + -- 2.39.2