Salome HOME
Merge from V5_1_4_BR 07/05/2010
[modules/geom.git] / src / OperationGUI / OperationGUI_PartitionDlg.cxx
index e52df271c4f2bf71e5cdbf5ff4c4ad22a1506ef1..0b08ae59fcdf065eff571fb32c7d137609c8192a 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : OperationGUI_PartitionDlg.cxx
 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
 #include <SUIT_Desktop.h>
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_MessageBox.h>
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
+#include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
+
 //=================================================================================
 // class    : OperationGUI_PartitionDlg()
 // purpose  : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the 
@@ -65,7 +70,7 @@ OperationGUI_PartitionDlg::OperationGUI_PartitionDlg( GeometryGUI* theGeometryGU
   GroupPoints = new DlgRef_2Sel1List1Check( centralWidget() );
   GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
   GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
-  GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECT" ) );
+  GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
   GroupPoints->TextLabel3->setText( tr( "GEOM_RECONSTRUCTION_LIMIT" ) );
   GroupPoints->PushButton1->setIcon( image2 );
   GroupPoints->PushButton2->setIcon( image2 );
@@ -138,7 +143,7 @@ void OperationGUI_PartitionDlg::Init()
   connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
 
   connect( myGeomGUI->getApp()->selectionMgr(),
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
   
   initName( tr( "GEOM_PARTITION" ) );
 
@@ -165,7 +170,7 @@ void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
   switch ( constructorId ) {
   case 0: /*Full partition */
     GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
-    GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECT" ) );
+    GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
     GroupPoints->TextLabel3->show();
     GroupPoints->ComboBox1->show();
     GroupPoints->ComboBox1->setCurrentIndex( 0 );
@@ -196,7 +201,7 @@ void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
 
   myEditCurrentArgument->setFocus();
   connect( myGeomGUI->getApp()->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 }
 
 
@@ -220,8 +225,10 @@ bool OperationGUI_PartitionDlg::ClickOnApply()
   if ( !onAccept() )
     return false;
   
+
   initName();
-  ConstructorsClicked( getConstructorId() );
+  //  0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window 
+  //  ConstructorsClicked( getConstructorId() );
   return true;
 }
 
@@ -331,7 +338,7 @@ void OperationGUI_PartitionDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 
   ConstructorsClicked( getConstructorId() ); 
 }
@@ -365,7 +372,7 @@ GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
 bool OperationGUI_PartitionDlg::isValid( QString& )
 {
   return ( myListShapes.length()     || myListTools.length() ||
-          myListKeepInside.length() || myListRemoveInside.length() );
+           myListKeepInside.length() || myListRemoveInside.length() );
 }
 
 
@@ -397,15 +404,28 @@ bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
   }
 
   if ( isValid( msg ) ) {
-    anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->
-      MakePartition( myListShapes, myListTools,
-                    myListKeepInside, myListRemoveInside,
-                    aLimit, false, myListMaterials, aKeepNonlimitShapes );
+    GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
+    anObj = anOper->MakePartition( myListShapes, myListTools,
+                                   myListKeepInside, myListRemoveInside,
+                                   aLimit, false, myListMaterials, aKeepNonlimitShapes );
     res = true;
   }
 
-  if ( !anObj->_is_nil() )
-    objects.push_back( anObj._retn() );
+  if ( !anObj->_is_nil() ) {
+    TopoDS_Shape aShape;
+    GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE);
+    TopoDS_Iterator It (aShape, Standard_True, Standard_True);
+    int nbSubshapes=0;
+    for (; It.More(); It.Next())
+      nbSubshapes++;
+
+    if (nbSubshapes)
+      objects.push_back( anObj._retn() );
+    else
+      SUIT_MessageBox::warning(this,
+                               QObject::tr("GEOM_ERROR"),
+                               QObject::tr("GEOM_WRN_PARTITION_RESULT_EMPTY"));
+  }
 
   return res;
 }
@@ -420,8 +440,9 @@ void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy
   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
     // empty list of arguments means that all arguments should be restored
     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
-                                        /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
-                                        /*theInheritFirstArg=*/myListShapes.length() == 1 ); // ? false
+                                         /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
+                                         /*theInheritFirstArg=*/myListShapes.length() == 1,
+                                         mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
   }
 }