Salome HOME
Merge from V7_3_BR branch 18/12/2013
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MultiEditDlg.cxx
index ee4e206b2eda23c6b4153fcc0a37023fd787c59a..d48e740f5903e8ef301126e4589cd7a20f32b9ce 100755 (executable)
@@ -34,6 +34,7 @@
 #include "SMESHGUI_MeshUtils.h"
 #include "SMESHGUI_FilterUtils.h"
 #include "SMESHGUI_SpinBox.h"
+#include "SMESHGUI_MeshEditPreview.h"
 
 #include <SMESH_Actor.h>
 #include <SMESH_TypeFilter.hxx>
@@ -105,7 +106,7 @@ SMESHGUI_MultiEditDlg
 ::SMESHGUI_MultiEditDlg(SMESHGUI* theModule,
                         const int theMode,
                         const bool the3d2d):
-  QDialog(SMESH::GetDesktop(theModule)),
+  SMESHGUI_PreviewDlg(theModule),
   mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
   mySMESHGUI(theModule)
@@ -988,6 +989,7 @@ bool SMESHGUI_MultiEditDlg::onApply()
 
     updateButtons();
   }
+  obj._retn(); // else myMesh is deleted by ~obj
 
   myBusy = false;
   return aResult;
@@ -1080,6 +1082,11 @@ SMESHGUI_UnionOfTrianglesDlg
 {
   setWindowTitle(tr("CAPTION"));
 
+  //Preview check box
+  myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), mySelGrp);
+  QGridLayout* aLay = (QGridLayout*)(mySelGrp->layout());
+  aLay->addWidget(myPreviewCheckBox, aLay->rowCount(), 0, 1, aLay->columnCount());
+
   myComboBoxFunctor->setEnabled(true);  
   myComboBoxFunctor->addItem(tr("AREA_ELEMENTS"));
   myComboBoxFunctor->addItem(tr("WARP_ELEMENTS")); // for quadrangles only
@@ -1102,6 +1109,14 @@ SMESHGUI_UnionOfTrianglesDlg
   ((QVBoxLayout*)(myCriterionGrp->layout()))->addWidget(aMaxAngleGrp);
   myCriterionGrp->show();
 
+  connect(myComboBoxFunctor, SIGNAL(activated(int)),       this, SLOT(toDisplaySimulation()));
+  connect(myMaxAngleSpin,    SIGNAL(valueChanged(int)),    this, SLOT(toDisplaySimulation()));
+  connect(this,              SIGNAL(ListContensChanged()), this, SLOT(toDisplaySimulation()));
+  connectPreviewControl(); //To Connect preview check box
+
+  myPreviewCheckBox->setChecked(false);
+  onDisplaySimulation(false);
+
   myHelpFileName = "uniting_set_of_triangles_page.html";
 }
 
@@ -1148,7 +1163,47 @@ bool SMESHGUI_UnionOfTrianglesDlg::process (SMESH::SMESH_MeshEditor_ptr theEdito
     ok = theEditor->TriToQuadObject(obj, aCriterion, aMaxAngle);
   return ok;
 }
-
+  
+void SMESHGUI_UnionOfTrianglesDlg::onDisplaySimulation( bool toDisplayPreview )
+{
+  if ( myPreviewCheckBox->isChecked() && toDisplayPreview ) {
+    if ( isValid( true ) ) {
+      try{
+       SUIT_OverrideCursor aWaitCursor;
+       // get Ids of elements
+       SMESH::SMESH_IDSource_var obj;
+       SMESH::long_array_var anElemIds = getIds( obj );
+
+       SMESH::NumericalFunctor_var aCriterion  = getNumericalFunctor();
+       SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
+
+       double aMaxAngle = myMaxAngleSpin->GetValue() * M_PI / 180.0;
+      
+       if ( CORBA::is_nil( obj ) )
+         aMeshEditor->TriToQuad( anElemIds.inout(), aCriterion, aMaxAngle );
+       else
+         aMeshEditor->TriToQuadObject( obj, aCriterion, aMaxAngle );
+      
+       SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
+
+       vtkProperty* aProp = vtkProperty::New();
+       aProp->SetRepresentationToWireframe();
+       aProp->SetColor( 250, 0, 250 );
+       aProp->SetLineWidth( SMESH::GetFloat( "SMESH:element_width", 1 ) + 3 );
+       mySimulation->GetActor()->SetProperty( aProp );
+       aProp->Delete();
+
+       mySimulation->SetData( aMeshPreviewStruct._retn() );
+      } catch ( ... ) {
+       hidePreview();
+      }
+    } else {
+      hidePreview();
+    }
+  } else {
+    hidePreview();
+  }
+}
 
 /*!
  *  Class       : SMESHGUI_CuttingOfQuadsDlg
@@ -1212,7 +1267,7 @@ bool SMESHGUI_CuttingOfQuadsDlg::process (SMESH::SMESH_MeshEditor_ptr theEditor,
     {
       if ( hasObj )
         return theEditor->QuadTo4Tri( obj ), true;
-      SMESH::SMESH_IDSource_var elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
+      SMESH::SMESH_IDSource_wrap elems = theEditor->MakeIDSource( theIds, SMESH::FACE );
       theEditor->QuadTo4Tri( elems );
       return true;
     }
@@ -1270,6 +1325,7 @@ void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
   if (myPreviewActor != 0)
     erasePreview();
 
+  SUIT_OverrideCursor aWaitCursor;
   // get Ids of elements
   SMESH::SMESH_IDSource_var obj;
   SMESH::long_array_var anElemIds = getIds(obj);
@@ -1291,6 +1347,10 @@ void SMESHGUI_CuttingOfQuadsDlg::displayPreview()
       return;
   }
 
+  if ( anElemIds->length() == 0 ) {
+    anElemIds = obj->GetIDs();
+  }
+
   //Create grid
   vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
 
@@ -1466,9 +1526,11 @@ bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEdito
                                             const SMESH::long_array&    theIds,
                                             SMESH::SMESH_IDSource_ptr   theObj)
 {
-  SMESH::SMESH_IDSource_var obj = theObj;
+  SMESH::SMESH_IDSource_wrap obj = theObj;
   if ( CORBA::is_nil( obj ))
     obj = theEditor->MakeIDSource( theIds, myEntityType ? SMESH::VOLUME : SMESH::FACE );
+  else
+    obj->Register();
   try {
     theEditor->SplitVolumesIntoTetra( obj, myGroupChoice->checkedId()+1 );
   }
@@ -1476,5 +1538,8 @@ bool SMESHGUI_CuttingIntoTetraDlg::process (SMESH::SMESH_MeshEditor_ptr theEdito
     SalomeApp_Tools::QtCatchCorbaException( S_ex );
     return false;
   }
+  catch(...) {
+    return false;
+  }
   return true;
 }