Salome HOME
Update copyrights 2014.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ConvToQuadOp.cxx
index a62d0b94993be4b23b7dcdf7e644cf7d431b31ec..70b7493cbcbe65f005424027f3a96c6157f0da58 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "SMESHGUI.h"
 #include "SMESHGUI_ConvToQuadDlg.h"
+#include "SMESHGUI_MeshEditPreview.h"
 #include "SMESHGUI_Utils.h"
-#include "SMDSAbs_ElementType.hxx"
-
+#include "SMESH_ActorUtils.h"
 #include "SMESH_TypeFilter.hxx"
+#include "SMDSAbs_ElementType.hxx"
 
 // SALOME GUI includes
 #include <LightApp_UpdateFlags.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_OverrideCursor.h>
 #include <SalomeApp_Tools.h>
+#include <SALOME_Actor.h>
 
 // IDL includes
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
 
+// VTK includes
+#include <vtkProperty.h>
+
 //================================================================================
 /*!
  * \brief Constructor
@@ -53,7 +58,8 @@
 //================================================================================
 SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
   : SMESHGUI_SelectionOp(), 
-    myDlg( 0 )
+    myDlg( 0 ),
+    myBadElemsPreview(0)
 {
 }
 
@@ -64,8 +70,8 @@ SMESHGUI_ConvToQuadOp::SMESHGUI_ConvToQuadOp()
 //================================================================================
 SMESHGUI_ConvToQuadOp::~SMESHGUI_ConvToQuadOp()
 {
-  if ( myDlg )
-    delete myDlg;
+  if ( myDlg ) delete myDlg;
+  if ( myBadElemsPreview ) delete myBadElemsPreview;
 }
 
 //================================================================================
@@ -136,19 +142,10 @@ void SMESHGUI_ConvToQuadOp::selectionDone()
       myDlg->setButtonEnabled( false, QtxDialog::OK | QtxDialog::Apply );
       return;
     }
-    MeshType meshType = ConsistMesh( idSource );
-    if( meshType == SMESHGUI_ConvToQuadOp::Quadratic )
-    {
-      myDlg->SetEnabledRB( 0, false );
-    }
-    else if( meshType == SMESHGUI_ConvToQuadOp::Linear )
-    {
-      myDlg->SetEnabledRB( 1, false );
-    }
-    else 
-    {
-      myDlg->SetEnabledControls( true );
-    }
+    SMESH::SMESH_Mesh_var      mesh = idSource->GetMesh();
+    bool                    hasGeom = mesh->HasShapeToMesh();
+    MeshDestinationType meshTgtType = DestinationMesh( idSource );
+    myDlg->SetEnabledRB( meshTgtType, hasGeom && ( meshTgtType & ( BiQuadratic | Quadratic )));
 
     // show warning on non-conformal result mesh
     if ( ! idSource->_is_nil() )
@@ -160,8 +157,9 @@ void SMESHGUI_ConvToQuadOp::selectionDone()
       {
         SMESH::SMESH_Mesh_var mesh = idSource->GetMesh();
         idSource = SMESH::SMESH_IDSource::_narrow( mesh );
-        MeshType fullMeshType = ConsistMesh( idSource );
-        toShow = ( fullMeshType != Comp );
+        bool isMixOrder;
+        DestinationMesh( idSource, &isMixOrder );
+        toShow = !isMixOrder;
       }
       myDlg->ShowWarning( toShow );
     }
@@ -187,7 +185,7 @@ void SMESHGUI_ConvToQuadOp::selectionDone()
 SUIT_SelectionFilter* SMESHGUI_ConvToQuadOp::createFilter( const int theId ) const
 {
   if ( theId == 0 )
-    return new SMESH_TypeFilter( MESHorSUBMESH );
+    return new SMESH_TypeFilter( SMESH::MESHorSUBMESH );
   else
     return 0;
 }
@@ -235,16 +233,52 @@ bool SMESHGUI_ConvToQuadOp::onApply()
     SMESH::SMESH_MeshEditor_var aEditor = mesh->GetMeshEditor();
     aResult = true; 
     SMESH::SMESH_Mesh_var sourceMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( pObj );  
-    if( !myDlg->CurrentRB() )
+    if( myDlg->CurrentRB()==1 || myDlg->CurrentRB()==2)
     {
-      bool aParam = true;
+      bool force3d = true;
       if( myDlg->IsEnabledCheck() )
-        aParam = myDlg->IsMediumNdsOnGeom();
-
-      if ( sourceMesh->_is_nil() )
-        aEditor->ConvertToQuadraticObject( aParam, idSource );
-      else
-        aEditor->ConvertToQuadratic( aParam );
+        force3d = myDlg->IsMediumNdsOnGeom();
+      bool theToBiQuad = myDlg->IsBiQuadratic();
+      if ( sourceMesh->_is_nil() ) {
+        if ( theToBiQuad ) aEditor->ConvertToBiQuadratic    ( force3d, idSource );
+        else               aEditor->ConvertToQuadraticObject( force3d, idSource );
+      }
+      else {
+        if ( theToBiQuad ) aEditor->ConvertToBiQuadratic( force3d, sourceMesh );
+        else               aEditor->ConvertToQuadratic  ( force3d );
+      }
+      if ( !force3d )
+      {
+        SMESH::ComputeError_var error = aEditor->GetLastError();
+        if ( error->hasBadMesh )
+        {
+          if ( myBadElemsPreview ) delete myBadElemsPreview; // viewWindow may change
+          myBadElemsPreview = new SMESHGUI_MeshEditPreview( viewWindow() );
+
+          double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
+          double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
+          vtkProperty* prop = vtkProperty::New();
+          prop->SetLineWidth( aLineWidth * 3 );
+          prop->SetPointSize( aPointSize * 3 );
+          prop->SetColor( 250, 0, 250 );
+          myBadElemsPreview->GetActor()->SetProperty( prop );
+          prop->Delete();
+
+          SMESH::MeshPreviewStruct_var previewData = aEditor->GetPreviewData();
+          myBadElemsPreview->SetData( & previewData.in() );
+          myBadElemsPreview->SetVisibility(true);
+
+          SUIT_MessageBox* mb = new SUIT_MessageBox(SUIT_MessageBox::Warning,
+                                                    tr( "SMESH_WRN_WARNING" ),
+                                                    tr("EDITERR_NO_MEDIUM_ON_GEOM"),
+                                                    SUIT_MessageBox::Ok, myDlg);
+          mb->setWindowModality( Qt::NonModal );
+          mb->setAttribute( Qt::WA_DeleteOnClose );
+          mb->show();
+          connect ( mb, SIGNAL( finished(int) ), this, SLOT( onWarningWinFinished() ));
+          //connect ( mb, SIGNAL( rejected() ), this, SLOT( onWarningWinFinished() ));
+        }
+      }
     }
     else
     {
@@ -272,14 +306,40 @@ bool SMESHGUI_ConvToQuadOp::onApply()
   return aResult;
 }
 
+//================================================================================
+/*!
+ * \brief SLOT called when a warning window is closed
+ */
+//================================================================================
+
+void SMESHGUI_ConvToQuadOp::onWarningWinFinished()
+{
+  if ( myBadElemsPreview )
+    myBadElemsPreview->SetVisibility(false);
+}
+
 //================================================================================
 /*! ConsistMesh
- *  Determines, what elements this mesh contains. 
+ *  Determines, what elements this mesh does not contain.
  */
 //================================================================================
-SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH::SMESH_IDSource_var& idSource) const
+
+SMESHGUI_ConvToQuadOp::MeshDestinationType
+SMESHGUI_ConvToQuadOp::DestinationMesh( const SMESH::SMESH_IDSource_var& idSource,
+                                        bool*                            isMixOrder) const
 {
   SMESH::long_array_var nbElemOfType = idSource->GetMeshInfo();
+
+  bool hasBiQuad     = ( nbElemOfType[SMDSEntity_BiQuad_Triangle   ] ||
+                         nbElemOfType[SMDSEntity_BiQuad_Quadrangle ] ||
+                         nbElemOfType[SMDSEntity_TriQuad_Hexa      ] );
+  bool hasLinBiQuad  = ( nbElemOfType[SMDSEntity_Triangle   ] ||
+                         nbElemOfType[SMDSEntity_Quadrangle ] ||
+                         nbElemOfType[SMDSEntity_Hexa       ] );
+  bool hasQuadBiQuad = ( nbElemOfType[SMDSEntity_Quad_Triangle   ] ||
+                         nbElemOfType[SMDSEntity_Quad_Quadrangle ] ||
+                         nbElemOfType[SMDSEntity_Quad_Hexa       ] );
+
   bool hasQuad = ( nbElemOfType[SMDSEntity_Quad_Edge      ] ||
                    nbElemOfType[SMDSEntity_Quad_Triangle  ] ||
                    nbElemOfType[SMDSEntity_Quad_Quadrangle] ||
@@ -296,9 +356,25 @@ SMESHGUI_ConvToQuadOp::MeshType SMESHGUI_ConvToQuadOp::ConsistMesh( const SMESH:
                    nbElemOfType[SMDSEntity_Pyramid   ] ||
                    nbElemOfType[SMDSEntity_Penta     ] );
 
-  if ( hasQuad && hasLin )
-    return Comp;
-  return hasQuad ? Quadratic : Linear;
+  int tgtType = 0;
+  if ( hasBiQuad )
+    tgtType |= ( Quadratic | Linear );
+  if ( hasLinBiQuad )
+    tgtType |= ( BiQuadratic | Quadratic );
+  if ( hasQuadBiQuad )
+    tgtType |= ( BiQuadratic | Linear );
+  if ( hasQuad )
+    tgtType |= Linear;
+  if ( hasLin )
+    tgtType |= Quadratic;
+
+  if ( tgtType == 0 )
+    tgtType = Quadratic;
+
+  if ( isMixOrder )
+    *isMixOrder = ( hasLin && ( hasQuad || hasBiQuad ));
+
+  return MeshDestinationType( tgtType );
 }
 
 void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
@@ -313,7 +389,7 @@ void SMESHGUI_ConvToQuadOp::ConnectRadioButtons( int id )
 
   bool hasGeom = mesh->HasShapeToMesh();
 
-  if( id || !hasGeom )
+  if( id==0 || !hasGeom )
     myDlg->SetEnabledCheck( false );
   else
     myDlg->SetEnabledCheck( true );