Salome HOME
Issue 0019946: integrate fix for 0019855 to SALOME 3 maintainance branch V3_2_0_maintainance_FINAL V3_2_10_patch4
authorvsr <vsr@opencascade.com>
Mon, 25 Aug 2008 07:50:57 +0000 (07:50 +0000)
committervsr <vsr@opencascade.com>
Mon, 25 Aug 2008 07:50:57 +0000 (07:50 +0000)
src/GEOMGUI/GEOM_msg_en.po
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h
src/GEOMToolsGUI/GEOMToolsGUI_DeleteDlg.cxx [new file with mode: 0644]
src/GEOMToolsGUI/GEOMToolsGUI_DeleteDlg.h [new file with mode: 0644]
src/GEOMToolsGUI/Makefile.in

index 680043394a777cb3a33cea09fe89300bfc1adb1d..e097f1ee228c56830b0dd6f659f8812139f98a99 100644 (file)
@@ -237,9 +237,14 @@ msgstr "Radius is null"
 msgid "GEOM_WRN_WARNING"
 msgstr "Warning"
 
-#: GeometryGUI.cxx:3854
-msgid "GEOM_REALLY_DELETE"
-msgstr "Do you really want to delete this %1 object(s):"
+msgid "GEOMToolsGUI_DeleteDlg::GEOM_REALLY_DELETE"
+msgstr "Do you really want to delete %1 object(s)?"
+
+msgid "GEOMToolsGUI_DeleteDlg::GEOM_REALLY_DELETE_ALL"
+msgstr "Do you really want to delete all objects?"
+
+msgid "GEOMToolsGUI_DeleteDlg::GEOM_DELETE_OBJECTS"
+msgstr "Delete objects:"
 
 #
 #==============================================================================
index f2efec3a721bdf22c4c124793acf6a43e26325e4..751e2d0535aad67b46075e8be9cd630498a61d13 100644 (file)
 //  $Header$
 
 #include "GEOMToolsGUI.h"
+#include "GEOMToolsGUI_DeleteDlg.h"
 
 #include "GeometryGUI.h"
 #include "GEOM_Actor.h"
 #include "GEOMBase.h"
-#include "GEOMBase_aWarningDlg.h"
 
 #include "GEOM_Operation.h"
 #include "GEOM_Displayer.h"
@@ -116,6 +116,92 @@ static QString getFileName( QWidget*           parent,
   return filename;
 }
 
+//=======================================================================
+// function : getParentComponent
+// purpose  : Get object's parent component entry
+//=======================================================================
+static QString getParentComponent( _PTR( SObject ) obj )
+{
+  if ( obj ) {
+    _PTR(SComponent) comp = obj->GetFatherComponent();
+    if ( comp )
+      return QString( comp->GetID().c_str() );
+  }
+  return QString();
+}
+
+//=====================================================================================
+// function : inUse
+// purpose  : check if the object(s) passed as the the second arguments are used
+//            by the other objects in the study
+//=====================================================================================
+static bool inUse( _PTR(Study) study, const QString& component, const QMap<QString,QString>& objects )
+{
+  _PTR(SObject) comp = study->FindObjectID( component.latin1() );
+  if ( !comp )
+    return false;
+
+  // collect all GEOM objects being deleted
+  QMap<QString, GEOM::GEOM_Object_var> gobjects;
+  QMap<QString, QString>::ConstIterator oit;
+  list<_PTR(SObject)> aSelectedSO;
+  for ( oit = objects.begin(); oit != objects.end(); ++oit ) {
+    _PTR(SObject) so = study->FindObjectID( oit.key().latin1() );
+    if ( !so )
+      continue;
+    aSelectedSO.push_back(so);
+    CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject( so );
+    GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
+    if( CORBA::is_nil( geomObj_rem ) ) 
+      continue;
+    gobjects.insert( oit.key(), geomObj_rem );
+  }
+
+  // Search References with other Modules
+  list< _PTR(SObject) >::iterator itSO = aSelectedSO.begin();
+  for ( ; itSO != aSelectedSO.end(); ++itSO ) {
+    std::vector<_PTR(SObject)> aReferences = study->FindDependances( *itSO  );    
+    int aRefLength = aReferences.size();
+    if (aRefLength) {
+      for (int i = 0; i < aRefLength; i++) {
+       _PTR(SObject) firstSO( aReferences[i] );
+       _PTR(SComponent) aComponent = firstSO->GetFatherComponent();
+       QString type = aComponent->ComponentDataType();
+       if ( type == "SMESH" )
+         return true;
+      }
+    }
+  }
+
+  // browse through all GEOM data tree
+  _PTR(ChildIterator) it ( study->NewChildIterator( comp ) );
+  for ( it->InitEx( true ); it->More(); it->Next() ) {
+    _PTR(SObject) child( it->Value() );
+    CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
+    GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
+    if( CORBA::is_nil( geomObj ) ) 
+      continue;
+
+    GEOM::ListOfGO_var list = geomObj->GetDependency();
+    if( list->length() == 0 ) 
+      continue;
+
+    for( int i = 0; i < list->length(); i++ ) {
+      bool depends = false;
+      bool deleted = false;
+      QMap<QString, GEOM::GEOM_Object_var>::Iterator git;
+      for ( git = gobjects.begin(); git != gobjects.end() && ( !depends || !deleted ); ++git ) {
+       depends = depends || list[i]->_is_equivalent( *git );
+       deleted = deleted || git.key() == child->GetID().c_str() ;//geomObj->_is_equivalent( *git );
+      }
+      if ( depends && !deleted )
+       return true;
+    }
+  }
+  return false;
+}
+
+
 //=======================================================================
 // function : GEOMToolsGUI()
 // purpose  : Constructor
@@ -284,156 +370,148 @@ void GEOMToolsGUI::OnEditDelete()
   SALOME_ListIO selected;
   SalomeApp_Application* app =
     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( app ) {
-    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
-    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-    if ( aSelMgr && appStudy ) {
-      aSelMgr->selectedObjects( selected, QString::null, false );
-      if ( !selected.IsEmpty() ) {
-       _PTR(Study) aStudy = appStudy->studyDS();
-
-       bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
-       if ( aLocked ) {
-         SUIT_MessageBox::warn1 ( app->desktop(),
-                                  QObject::tr("WRN_WARNING"),
-                                  QObject::tr("WRN_STUDY_LOCKED"),
-                                  QObject::tr("BUT_OK") );
-         return;
-       }
-
-       // VSR 17/11/04: check if all objects selected belong to GEOM component --> start
-       // modifications of ASV 01.06.05
-       QString parentComp = getParentComponent( aStudy, selected );
-       const char* geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
-       QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR ) );
-
-       if ( parentComp != geomComp )  {
-         SUIT_MessageBox::warn1 ( app->desktop(),
-                                 QObject::tr("ERR_ERROR"),
-                                 QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ),
-                                 QObject::tr("BUT_OK") );
-         return;
-       }
-       // VSR 17/11/04: check if all objects selected belong to GEOM component <-- finish
-       QString aNameList;
-       int nbSel = 0;
-       //Get Main Objects Names
-       Handle(SALOME_InteractiveObject) anIObject;
-       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
-         {
-           QString aName = It.Value()->getName();
-           if ( aName != "" && aName.ref(0) != '*') {
-             aNameList.append("    - " + aName + "\n");
-             nbSel++;
-           }
-           anIObject = It.Value();
-         }
-       // Append Child Names of Last Selected Object
-       _PTR(SObject) obj ( aStudy->FindObjectID( anIObject->getEntry() ) );
-       for (_PTR(ChildIterator) iit (aStudy->NewChildIterator(obj)); iit->More(); iit->Next()) {
-         _PTR(SObject) child (iit->Value());
-         QString aName = child->GetName();
-         if (aName != "" && aName.ref(0) != '*') {
-           aNameList.append("    - " +  aName + "\n");
-           nbSel++;
-           //append childs child
-           for (_PTR(ChildIterator) iitt(aStudy->NewChildIterator(child)); iitt->More(); iitt->Next()) {
-             _PTR(SObject) childchild(iitt->Value());
-             QString aName = childchild->GetName();
-             if (aName != "" && aName.ref(0) != '*') {
-               aNameList.append("    - " +  aName + "\n");
-               nbSel++;
-               for (_PTR(ChildIterator) itt(aStudy->NewChildIterator(childchild)); itt->More(); itt->Next()) {
-                 _PTR(SObject) childs(itt->Value());
-                 QString aName = childs->GetName();
-                 if (aName != "" && aName.ref(0) != '*') {
-                   aNameList.append("    - " +  aName + "\n");
-                   nbSel++;
-                 }
-               }
-             }
-           }
-         }
-       } //end of child append
-
-       GEOMBase_aWarningDlg* Dialog = new GEOMBase_aWarningDlg( app->desktop(),  QObject::tr( "GEOM_WRN_WARNING" ), aNameList, nbSel);
-       int r = Dialog->exec();
-
-       if (!r)
-        return;
-
-       //      QAD_Operation* op = new SALOMEGUI_ImportOperation(.....);
-       //      op->start();
-
-       // prepare list of SALOME_Views
-       QPtrList<SALOME_View> views;
-       SALOME_View* view;
-       // fill the list
-       ViewManagerList vmans = app->viewManagers();
-       SUIT_ViewManager* vman;
-       for ( vman = vmans.first(); vman; vman = vmans.next() ) {
-         SUIT_ViewModel* vmod = vman->getViewModel();
-         view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
-         if ( view )
-           views.append( view );
-       }
-
-       _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
-       _PTR(GenericAttribute) anAttr;
-       GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
-
-        _PTR(SComponent) aGeom ( aStudy->FindComponent("GEOM") );
-          if ( !aGeom )
-            return;    
-
-       // MAIN LOOP OF SELECTED OBJECTS
-       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-
-         Handle(SALOME_InteractiveObject) io = It.Value();
-         if ( !io->hasEntry() )
-           continue;
-
-         _PTR(SObject) obj ( aStudy->FindObjectID( io->getEntry() ) );
-
-         // disable removal of "Geometry" component object
-         if ( !strcmp( obj->GetIOR().c_str(), geomIOR ) )
-           continue;
-
-          //If the object has been used to create another one,then it can't be deleted 
-          _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeom));
-          for ( it->InitEx( true ); it->More(); it->Next() ) {
-             _PTR(SObject) chobj (it->Value());
-            if(CheckSubObjectInUse(chobj, obj, aStudy)) return;
-            //check subobjects
-            for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
-              _PTR(SObject) child (it->Value());
-              if(CheckSubObjectInUse( chobj, child, aStudy)) return;
-            }
-          }
-
-          RemoveObjectWithChildren(obj, aStudy, views, disp);
-
-         // Remove objects from Study
-         aStudyBuilder->RemoveObject( obj );
-
-         //deleted = true;
-       } // MAIN LOOP of selected
-
-       selected.Clear();
-       aSelMgr->setSelectedObjects( selected );
-       getGeometryGUI()->updateObjBrowser();
-      } // if ( selected not empty )
-    } // if ( selMgr && appStudy )
-
-    app->updateActions(); //SRN: To update a Save button in the toolbar
-
-  } // if ( app )
-
+  if ( !app )
+    return;
+
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if ( !aSelMgr || !appStudy )
+    return;
+
+  // get selection
+  aSelMgr->selectedObjects( selected, "ObjectBrowser", false );
+  if ( selected.IsEmpty() )
+    return;
+
+  _PTR(Study) aStudy = appStudy->studyDS();
+  
+  // check if study is locked
+  if ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() )->IsLocked() ) {
+    SUIT_MessageBox::warn1( app->desktop(),
+                           tr("WRN_WARNING"),
+                           tr("WRN_STUDY_LOCKED"),
+                           tr("BUT_OK") );
+    return; // study is locked
+  }
+  
+  // get GEOM component
+  CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
+  QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) );
+
+  // check each selected object: if belongs to GEOM, if not reference...
+  QMap<QString,QString> toBeDeleted;
+  QMap<QString,QString> allDeleted;
+  bool isComponentSelected = false;
+  for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+    Handle(SALOME_InteractiveObject) anIObject = It.Value();
+    if ( !anIObject->hasEntry() )
+      continue; // invalid object
+    // ...
+    QString entry = anIObject->getEntry();
+    _PTR(SObject) obj = aStudy->FindObjectID( entry.latin1() );
+    // check parent component
+    QString parentComp = getParentComponent( obj );
+    if ( parentComp != geomComp )  {
+      SUIT_MessageBox::warn1( app->desktop(),
+                             QObject::tr("ERR_ERROR"),
+                             QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ),
+                             QObject::tr("BUT_OK") );
+      return; // not GEOM object selected
+    }
 
-  //  if ( deleted )
-  //    op->finish();
-  //  else
-  //    op->abort();
+    ///////////////////////////////////////////////////////
+    // if GEOM component is selected, so skip other checks
+    if ( isComponentSelected ) continue; 
+    ///////////////////////////////////////////////////////
+       
+    // check if object is reference
+    _PTR(SObject) refobj;
+    if ( obj && obj->ReferencedObject( refobj ) )
+      continue; // skip references
+    // ...
+    QString aName = obj->GetName().c_str();
+    if ( entry == geomComp ) {
+      // GEOM component is selected, skip other checks
+      isComponentSelected = true;
+      continue;
+    }
+    toBeDeleted.insert( entry, aName );
+    allDeleted.insert( entry, aName ); // skip GEOM component
+    // browse through all children recursively
+    _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) );
+    for ( it->InitEx( true ); it->More(); it->Next() ) {
+      _PTR(SObject) child( it->Value() );
+      if ( child && child->ReferencedObject( refobj ) )
+       continue; // skip references
+      aName = child->GetName().c_str();
+      if ( !aName.isEmpty() )
+       allDeleted.insert( child->GetID().c_str(), aName );
+    }
+  }
+  
+  // is there is anything to delete?
+  if ( !isComponentSelected && allDeleted.count() <= 0 )
+    return; // nothing to delete
+
+  // show confirmation dialog box
+  GEOMToolsGUI_DeleteDlg dlg( app->desktop(), allDeleted, isComponentSelected );
+  if ( !dlg.exec() )
+    return; // operation is cancelled by user
+  
+  // get currently opened views
+  QPtrList<SALOME_View> views;
+  SALOME_View* view;
+  ViewManagerList vmans = app->viewManagers();
+  SUIT_ViewManager* vman;
+  for ( vman = vmans.first(); vman; vman = vmans.next() ) {
+    SUIT_ViewModel* vmod = vman->getViewModel();
+    view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
+    if ( view )
+      views.append( view );
+  }
+  
+  _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
+  GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
+  
+  if ( isComponentSelected ) {
+    // GEOM component is selected: delete all objects recursively
+    _PTR(SObject) comp = aStudy->FindObjectID( geomComp.latin1() );
+    if ( !comp )
+      return;
+    _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
+    // remove top-level objects only
+    for ( it->InitEx( false ); it->More(); it->Next() ) {
+      _PTR(SObject) child( it->Value() );
+      // remove object from GEOM engine
+      removeObjectWithChildren( child, aStudy, views, disp );
+      // remove object from study
+      aStudyBuilder->RemoveObjectWithChildren( child );
+    }
+  }
+  else {
+    // GEOM component is not selected: check if selected objects are in use
+    if ( inUse( aStudy, geomComp, allDeleted ) ) {
+      SUIT_MessageBox::warn1( app->desktop(),
+                             QObject::tr("WRN_WARNING"),
+                             QObject::tr("DEP_OBJECT"),
+                             QObject::tr("BUT_OK") );
+      return; // object(s) in use
+    }
+    // ... and then delete all objects
+    QMap<QString, QString>::Iterator it;
+    for ( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
+      _PTR(SObject) obj ( aStudy->FindObjectID( it.key().latin1() ) );
+      // remove object from GEOM engine
+      removeObjectWithChildren( obj, aStudy, views, disp );
+      // remove objects from study
+      aStudyBuilder->RemoveObjectWithChildren( obj );
+    }
+  }
+  
+  selected.Clear();
+  aSelMgr->setSelectedObjects( selected );
+  getGeometryGUI()->updateObjBrowser();
+  app->updateActions(); //SRN: To update a Save button in the toolbar
 }
 
 
@@ -691,50 +769,11 @@ bool GEOMToolsGUI::Export()
   return true;
 }
 
-
-QString GEOMToolsGUI::getParentComponent( _PTR( Study ) study, const SALOME_ListIO& iobjs )
-{
-  QString parentComp;
-
-  for ( SALOME_ListIteratorOfListIO it( iobjs ); it.More(); it.Next() ) {
-
-    Handle(SALOME_InteractiveObject) io = it.Value();
-    if ( !io->hasEntry() )
-      continue;
-
-    QString compName = getParentComponent( study->FindObjectID( io->getEntry() ) );
-
-    if ( parentComp.isNull() )
-      parentComp = compName;
-    else if ( parentComp.compare( compName) != 0 ) { // objects belonging to different components are selected
-      parentComp = QString::null;
-      break;
-    }
-  }
-
-  return parentComp;
-}
-
-QString GEOMToolsGUI::getParentComponent( _PTR( SObject ) obj )
-{
-  if ( obj ) {
-    _PTR(SComponent) comp = obj->GetFatherComponent();
-    if ( comp ) {
-      _PTR(GenericAttribute) anAttr;
-      if ( comp->FindAttribute( anAttr, "AttributeName") ) {
-       _PTR(AttributeName) aName( anAttr );
-       return QString( aName->Value().c_str() );
-      }
-    }
-  }
-  return QString();
-}
-
 //=====================================================================================
 // function : RemoveObjectWithChildren
 // purpose  : to be used by OnEditDelete() method
 //=====================================================================================
-void GEOMToolsGUI::RemoveObjectWithChildren(_PTR(SObject) obj,
+void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj,
                                             _PTR(Study) aStudy,
                                             QPtrList<SALOME_View> views,
                                             GEOM_Displayer* disp)
@@ -742,7 +781,7 @@ void GEOMToolsGUI::RemoveObjectWithChildren(_PTR(SObject) obj,
   // iterate through all children of obj
   for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
     _PTR(SObject) child (it->Value());
-    RemoveObjectWithChildren(child, aStudy, views, disp);
+    removeObjectWithChildren(child, aStudy, views, disp);
   }
 
   // erase object and remove it from engine
@@ -769,39 +808,6 @@ void GEOMToolsGUI::RemoveObjectWithChildren(_PTR(SObject) obj,
   }
 }
 
-//=====================================================================================
-// function : CheckSubObjectInUse
-// purpose  : to be used by OnEditDelete() method
-//=====================================================================================
-bool GEOMToolsGUI::CheckSubObjectInUse(_PTR(SObject) checkobj,
-                                      _PTR(SObject) remobj,
-                                       _PTR(Study) aStudy)
-{
-  CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(checkobj);
-  GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
-  if( CORBA::is_nil(geomObj) ) 
-    return false;
-
-  GEOM::ListOfGO_var list = geomObj->GetDependency();
-  if( list->length() > 1 )
-    for(int i = 0; i < list->length(); i++ ){
-      CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject(remobj);
-      GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
-      if( list[i]->_is_equivalent( geomObj_rem ) ){
-       SalomeApp_Application* app =
-         dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-
-       SUIT_MessageBox::warn1 ( app->desktop(),
-                                QObject::tr("WRN_WARNING"),
-                                QObject::tr("DEP_OBJECT"),
-                                QObject::tr("BUT_OK") );
-       return true;
-      }
-    }
-
-  return false;
-}
-
 //=================================================================================
 // function : deactivate()
 // purpose  : Called when GEOM component is deactivated
index e2751c3deee0c292f64b142212c925815e28fe61..7c19e05d9b72fa5cbeac62d58f1eb148c205f652 100644 (file)
@@ -81,22 +81,11 @@ private:
   void OnOpen();
   void OnSelectOnly(int mode);
   
-  // returns name of Module (Component) of given objects (usually selected objects)
-  // if objects belong to different Components, a NULL string is returned.
-  QString getParentComponent( _PTR( Study ), const SALOME_ListIO& );
-  QString getParentComponent( _PTR(SObject) );
-
   // Recursive deletion of object with children
-  void RemoveObjectWithChildren(_PTR(SObject) obj,
+  void removeObjectWithChildren(_PTR(SObject) obj,
                                _PTR(Study) aStudy,
                                QPtrList<SALOME_View> views,
                                GEOM_Displayer* disp);
-
-  //checks if the object passed as the first argument depends on the second arguments
-  bool CheckSubObjectInUse(_PTR(SObject) checkobj,
-                          _PTR(SObject) remobj,
-                          _PTR(Study) aStudy);
-    
 };
 
 #endif
diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_DeleteDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_DeleteDlg.cxx
new file mode 100644 (file)
index 0000000..e0f7f93
--- /dev/null
@@ -0,0 +1,131 @@
+// GEOM GEOMGUI : GUI for Geometry 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File   : GEOMToolsGUI_DeleteDlg.cxx
+// Author : Dmitry Matveitchev, Open CASCADE S.A.S.
+//
+
+#include "GEOMToolsGUI_DeleteDlg.h"
+
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qtextbrowser.h>
+#include <qstringlist.h>
+#include <qlayout.h>
+#include <qmessagebox.h>
+#include <SUIT_MessageBox.h>
+static bool isEntryLess( const QString& e1, const QString& e2 )
+{
+  QStringList el1 = QStringList::split(":", e1);
+  QStringList el2 = QStringList::split(":", e2);
+  int e1c = el1.count(), e2c = el2.count();
+  for ( int i = 0; i < e1c && i < e2c; i++ ) {
+    int id1 = el1[i].toInt();
+    int id2 = el2[i].toInt();
+    if ( id1 < id2 ) return true;
+    else if ( id2 < id1 ) return false;
+  }
+  return el1.count() < el2.count();
+}
+
+static QStringList objectsToNames( const QMap<QString, QString>& objects )
+{
+  QStringList entries;
+  for ( QMap<QString, QString>::ConstIterator it = objects.begin(); it != objects.end(); ++it ) {
+    QString entry = it.key();
+    QStringList::Iterator it;
+    bool added = false;
+    for ( it = entries.begin(); it != entries.end() && !added; ++it ) {
+      if ( isEntryLess( entry, *it ) ) {
+       entries.insert( it, entry );
+       added = true;
+      }
+    }
+    if ( !added ) 
+      entries.append( entry );
+  }
+  QStringList names;
+  for ( int i = 0; i < entries.count(); i++ ) {
+    int level = entries[i].contains(":")-3;
+    QString prefix; prefix.fill( ' ', level*2 );
+    names.append( prefix + objects[ entries[i] ] );
+  }
+  return names;
+}
+
+/*!
+  \brief Constructor.
+  \param parent parent widget
+*/
+GEOMToolsGUI_DeleteDlg::GEOMToolsGUI_DeleteDlg( QWidget* parent, 
+                                               const QMap<QString, QString>& objects, 
+                                               bool deleteAll )
+: QDialog( parent, "GEOMToolsGUI_DeleteDlg", true )
+{
+  setCaption( tr( "GEOM_DELETE_OBJECTS" ) );
+  setSizeGripEnabled( true );
+
+  QGridLayout* topLayout = new QGridLayout( this );
+
+  topLayout->setSpacing( 6 );
+  topLayout->setMargin( 11 );
+
+  QLabel* pix = new QLabel( this );
+  pix->setPixmap( QMessageBox::standardIcon( QMessageBox::Question ) );
+  pix->setScaledContents( false );
+  pix->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
+  topLayout->addWidget( pix, 0, 0 );
+
+  QLabel* lab = new QLabel( this );
+  lab->setAlignment( Qt::AlignCenter );
+  topLayout->addWidget( lab, 0, 1 );
+
+  if ( !deleteAll ) {
+    lab->setText( tr( "GEOM_REALLY_DELETE" ).arg( objects.count() ) );
+    QTextBrowser* viewer = new QTextBrowser( this );
+    viewer->setText( QString( " - %1" ).arg( objectsToNames( objects ).join( "\n - " ) ) );
+    topLayout->addMultiCellWidget( viewer,    1, 1, 0, 1 );
+  }
+  else {
+    lab->setText( tr( "GEOM_REALLY_DELETE_ALL" ) );
+  }
+
+  QPushButton* buttonYes = new QPushButton( tr( "GEOM_BUT_YES" ), this );
+  QPushButton* buttonNo  = new QPushButton( tr( "GEOM_BUT_NO" ),  this );
+  QHBoxLayout* btnLayout = new QHBoxLayout;
+  btnLayout->setMargin( 0 );
+  btnLayout->setSpacing( 6 );
+  btnLayout->addWidget( buttonYes );
+  btnLayout->addSpacing( 10 );
+  btnLayout->addStretch();
+  btnLayout->addWidget( buttonNo );
+  int rc = topLayout->numRows();
+  topLayout->addMultiCellLayout( btnLayout, rc, rc, 0, 1 );
+
+  /* signals and slots connections */
+  connect( buttonYes, SIGNAL( clicked() ), this, SLOT( accept() ) );
+  connect( buttonNo,  SIGNAL( clicked() ), this, SLOT( reject() ) );
+}
+
+GEOMToolsGUI_DeleteDlg::~GEOMToolsGUI_DeleteDlg()
+{
+}
diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_DeleteDlg.h b/src/GEOMToolsGUI/GEOMToolsGUI_DeleteDlg.h
new file mode 100644 (file)
index 0000000..d178dac
--- /dev/null
@@ -0,0 +1,41 @@
+// GEOM GEOMGUI : GUI for Geometry 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File   : GEOMToolsGUI_DeleteDlg.h
+// Author : Dmitry Matveitchev, Open CASCADE S.A.S.
+//
+
+#ifndef GEOMTOOLSGUI_DELETEDLG_H
+#define GEOMTOOLSGUI_DELETEDLG_H
+
+#include <qdialog.h>
+#include <qmap.h>
+
+class GEOMToolsGUI_DeleteDlg : public QDialog
+{ 
+  Q_OBJECT
+
+public:
+  GEOMToolsGUI_DeleteDlg( QWidget*, const QMap<QString, QString>&, bool = false );
+  ~GEOMToolsGUI_DeleteDlg();
+};
+
+#endif // GEOMTOOLSGUI_DELETEDLG_H
index f5fcab3e96307528616379ccceb7ee643a425882..3d38544042a3adfd12831f2aa406b65280aff379 100644 (file)
@@ -43,10 +43,12 @@ EXPORT_HEADERS =
 LIB_SRC =      GEOMToolsGUI.cxx \
                GEOMToolsGUI_1.cxx \
                GEOMToolsGUI_TransparencyDlg.cxx \
-               GEOMToolsGUI_NbIsosDlg.cxx
+               GEOMToolsGUI_NbIsosDlg.cxx \
+               GEOMToolsGUI_DeleteDlg.cxx
 
 LIB_MOC =      GEOMToolsGUI_TransparencyDlg.h \
-               GEOMToolsGUI_NbIsosDlg.h
+               GEOMToolsGUI_NbIsosDlg.h \
+               GEOMToolsGUI_DeleteDlg.h
 
 LIB_CLIENT_IDL = SALOMEDS_Attributes.idl \
                 SALOME_GenericObj.idl \