Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MultiEditDlg.cxx
index 907f8a65b86b43439488e7d909061f8a03a20c72..98b047400a782cf2e4dce932b08004e5558aeba7 100755 (executable)
@@ -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
 //
+
 // File   : SMESHGUI_MultiEditDlg.cxx
 // Author : Sergey LITONIN, Open CASCADE S.A.S.
 // SMESH includes
 #include <SMDS_Mesh.hxx>
 
 // SALOME GUI includes
-#include <SUIT_ResourceMgr.h>
 #include <SUIT_Desktop.h>
-#include <SUIT_Session.h>
 #include <SUIT_MessageBox.h>
+#include <SUIT_OverrideCursor.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
 
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_Application.h>
 #include <SALOME_ListIO.hxx>
 #include <SALOME_ListIteratorOfListIO.hxx>
+#include <SalomeApp_Tools.h>
 
 #include <SVTK_Selector.h>
 #include <SVTK_ViewWindow.h>
@@ -301,7 +304,7 @@ QWidget* SMESHGUI_MultiEditDlg::createButtonFrame (QWidget* theParent)
 bool SMESHGUI_MultiEditDlg::isValid (const bool /*theMess*/)
 {
   return (!myMesh->_is_nil() &&
-          (myListBox->count() > 0 || (myToAllChk->isChecked() && myActor)));
+          (myListBox->count() > 0 || (myToAllChk->isChecked()/* && myActor*/)));
 }
 
 //=======================================================================
@@ -423,49 +426,51 @@ void SMESHGUI_MultiEditDlg::onOk()
 
 //=======================================================================
 // name    : SMESHGUI_MultiEditDlg::getIds
-// Purpose : Retrive identifiers from list box
+// Purpose : Retrive identifiers from list box or the whole object
 //=======================================================================
-SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds()
+
+SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds(SMESH::SMESH_IDSource_var& obj)
 {
   SMESH::long_array_var anIds = new SMESH::long_array;
 
   if (myToAllChk->isChecked())
   {
     myIds.Clear();
-    SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
-    if (!anActor)
-      anActor = myActor;
-    if (anActor != 0)
-    {
-      // skl 07.02.2006
-      SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
-      if( myFilterType == SMESH::TriaFilter || 
-          myFilterType == SMESH::QuadFilter ||
-          myFilterType == SMESH::FaceFilter ) {
-        SMDS_FaceIteratorPtr it = aMesh->facesIterator();
-        while(it->more()) {
-          const SMDS_MeshFace* f = it->next();
-          if(myFilterType == SMESH::FaceFilter) {
-            myIds.Add(f->GetID());
-          }
-          else if( myFilterType==SMESH::TriaFilter &&
-                   ( f->NbNodes()==3 || f->NbNodes()==6 ) ) {
-            myIds.Add(f->GetID());
-          }
-          else if( myFilterType==SMESH::QuadFilter &&
-                   ( f->NbNodes()==4 || f->NbNodes()==8 ) ) {
-            myIds.Add(f->GetID());
-          }
-        }
-      }
-      else if(myFilterType == SMESH::VolumeFilter) {
-        SMDS_VolumeIteratorPtr it = aMesh->volumesIterator();
-        while(it->more()) {
-          const SMDS_MeshVolume* f = it->next();
-          myIds.Add(f->GetID());
-        }
-      }
-      /* commented by skl 07.02.2006
+    obj = SMESH::SMESH_IDSource::_narrow( myMesh );
+//     SMESH_Actor * anActor = SMESH::FindActorByObject(myMesh);
+//     if (!anActor)
+//       anActor = myActor;
+//     if (anActor != 0)
+//     {
+//       // skl 07.02.2006
+//       SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
+//       if( myFilterType == SMESH::TriaFilter || 
+//           myFilterType == SMESH::QuadFilter ||
+//           myFilterType == SMESH::FaceFilter ) {
+//         SMDS_FaceIteratorPtr it = aMesh->facesIterator();
+//         while(it->more()) {
+//           const SMDS_MeshFace* f = it->next();
+//           if(myFilterType == SMESH::FaceFilter) {
+//             myIds.Add(f->GetID());
+//           }
+//           else if( myFilterType==SMESH::TriaFilter &&
+//                    ( f->NbNodes()==3 || f->NbNodes()==6 ) ) {
+//             myIds.Add(f->GetID());
+//           }
+//           else if( myFilterType==SMESH::QuadFilter &&
+//                    ( f->NbNodes()==4 || f->NbNodes()==8 ) ) {
+//             myIds.Add(f->GetID());
+//           }
+//         }
+//       }
+//       else if(myFilterType == SMESH::VolumeFilter) {
+//         SMDS_VolumeIteratorPtr it = aMesh->volumesIterator();
+//         while(it->more()) {
+//           const SMDS_MeshVolume* f = it->next();
+//           myIds.Add(f->GetID());
+//         }
+//       }
+      /* commented by skl 07.02.2006 - to work with quadratic elements
       TVisualObjPtr aVisualObj = anActor->GetObject();
       vtkUnstructuredGrid* aGrid = aVisualObj->GetUnstructuredGrid();
       if (aGrid != 0) {
@@ -490,7 +495,7 @@ SMESH::long_array_var SMESHGUI_MultiEditDlg::getIds()
         }
       }
       */
-    }
+    //}
   }
 
   anIds->length(myIds.Extent());
@@ -1034,9 +1039,12 @@ bool SMESHGUI_MultiEditDlg::onApply()
 
   myBusy = true;
 
-  SMESH::long_array_var anIds = getIds();
+  SUIT_OverrideCursor aWaitCursor;
+
+  SMESH::SMESH_IDSource_var obj;
+  SMESH::long_array_var anIds = getIds(obj);
 
-  bool aResult = process(aMeshEditor, anIds.inout());
+  bool aResult = process(aMeshEditor, anIds.inout(), obj);
   if (aResult) {
     if (myActor) {
       SALOME_ListIO sel;
@@ -1124,9 +1132,13 @@ SMESHGUI_ChangeOrientationDlg::~SMESHGUI_ChangeOrientationDlg()
 }
 
 bool SMESHGUI_ChangeOrientationDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
-                                             const SMESH::long_array&    theIds)
+                                             const SMESH::long_array&    theIds,
+                                             SMESH::SMESH_IDSource_ptr   obj)
 {
-  return theEditor->Reorient(theIds);
+  if ( CORBA::is_nil( obj ))
+    return theEditor->Reorient(theIds);
+  else
+    return theEditor->ReorientObject( obj );
 }
 
 /*!
@@ -1152,7 +1164,7 @@ SMESHGUI_UnionOfTrianglesDlg
 
   QLabel* aLab = new QLabel (tr("MAXIMUM_ANGLE"), aMaxAngleGrp);
   myMaxAngleSpin = new SMESHGUI_SpinBox (aMaxAngleGrp);
-  myMaxAngleSpin->RangeStepAndValidator(0, 180.0, 1.0, 3);
+  myMaxAngleSpin->RangeStepAndValidator(0, 180.0, 1.0, "angle_precision");
   myMaxAngleSpin->SetValue(30.0);
 
   aMaxAngleGrpLayout->addWidget(aLab);
@@ -1190,11 +1202,16 @@ bool SMESHGUI_UnionOfTrianglesDlg::isValid (const bool theMess)
 }
 
 bool SMESHGUI_UnionOfTrianglesDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
-                                            const SMESH::long_array&    theIds)
+                                            const SMESH::long_array&    theIds,
+                                            SMESH::SMESH_IDSource_ptr   obj)
 {
   SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
   double aMaxAngle = myMaxAngleSpin->GetValue() * PI / 180.0;
-  bool ok = theEditor->TriToQuad(theIds, aCriterion, aMaxAngle);
+  bool ok;
+  if ( CORBA::is_nil( obj ))
+    ok = theEditor->TriToQuad(theIds, aCriterion, aMaxAngle);
+  else
+    ok = theEditor->TriToQuadObject(obj, aCriterion, aMaxAngle);
   if( ok ) {
     QStringList aParameters;
     aParameters << myMaxAngleSpin->text();
@@ -1243,19 +1260,21 @@ void SMESHGUI_CuttingOfQuadsDlg::onClose()
 }
 
 bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
-                                          const SMESH::long_array&    theIds)
+                                          const SMESH::long_array&    theIds,
+                                          SMESH::SMESH_IDSource_ptr   obj)
 {
+  bool hasObj = (! CORBA::is_nil( obj ));
   switch (myGroupChoice->checkedId()) {
   case 0: // use diagonal 1-3
-    return theEditor->SplitQuad(theIds, true);
+    return hasObj ? theEditor->SplitQuadObject(obj, true) : theEditor->SplitQuad(theIds, true);
   case 1: // use diagonal 2-4
-    return theEditor->SplitQuad(theIds, false);
+    return hasObj ? theEditor->SplitQuadObject(obj, false) : theEditor->SplitQuad(theIds, false);
   default: // use numeric functor
     break;
   }
 
-  SMESH::NumericalFunctor_var aCriterion = getNumericalFunctor();
-  return theEditor->QuadToTri(theIds, aCriterion);
+  SMESH::NumericalFunctor_var aCrit = getNumericalFunctor();
+  return hasObj ? theEditor->QuadToTriObject(obj, aCrit) : theEditor->QuadToTri(theIds, aCrit);
 }
 
 void SMESHGUI_CuttingOfQuadsDlg::onCriterionRB()
@@ -1295,8 +1314,9 @@ void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
     erasePreview();
 
   // get Ids of elements
-  SMESH::long_array_var anElemIds = getIds();
-  if (getIds()->length() == 0)
+  SMESH::SMESH_IDSource_var obj;
+  SMESH::long_array_var anElemIds = getIds(obj);
+  if (anElemIds->length() == 0 && obj->_is_nil() )
     return;
 
   SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
@@ -1449,3 +1469,55 @@ void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
   aCellTypesArray->Delete();
   aCellLocationsArray->Delete();
 }
+
+/*!
+ *  Class       : SMESHGUI_CuttingIntoTetraDlg
+ *  Description : Modification of orientation of faces
+ */
+
+SMESHGUI_CuttingIntoTetraDlg::SMESHGUI_CuttingIntoTetraDlg(SMESHGUI* theModule)
+  : SMESHGUI_MultiEditDlg(theModule, SMESH::VolumeFilter, false)
+{
+  setWindowTitle(tr("CAPTION"));
+  myHelpFileName = "split_to_tetra_page.html";
+  myEntityType = SMESH::VolumeFilter;
+
+  myToAllChk->setChecked( true ); //aplly to the whole mesh by default
+
+  bool hasHexa = true;//myMesh->_is_nil() ? false : myMesh->NbHexas();
+
+  if ( hasHexa )
+  {
+    myGroupChoice->button(2)->hide();
+    myGroupChoice->button(0)->setText( tr("SPLIT_HEX_TO_5_TETRA"));
+    myGroupChoice->button(1)->setText( tr("SPLIT_HEX_TO_6_TETRA"));
+
+    myCriterionGrp->setTitle( tr("SPLIT_METHOD"));
+    myCriterionGrp->show();
+    myComboBoxFunctor->hide();
+    myChoiceWidget->show();
+  }
+  setSelectionMode();
+  updateButtons();
+}
+
+SMESHGUI_CuttingIntoTetraDlg::~SMESHGUI_CuttingIntoTetraDlg()
+{
+}
+
+bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
+                                            const SMESH::long_array&    theIds,
+                                            SMESH::SMESH_IDSource_ptr   theObj)
+{
+  SMESH::SMESH_IDSource_var obj = theObj;
+  if ( CORBA::is_nil( obj ))
+    obj = theEditor->MakeIDSource( theIds );
+  try {
+    theEditor->SplitVolumesIntoTetra( obj, myGroupChoice->checkedId()+1 );
+  }
+  catch ( const SALOME::SALOME_Exception& S_ex ) {
+    SalomeApp_Tools::QtCatchCorbaException( S_ex );
+    return false;
+  }
+  return true;
+}