Salome HOME
For IMP 16155: use BRep_Tool::IsClosed() instead of TopoDS_Shape::Closed().
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index 4d27d31aed8ae5c2fbcedc828f461b4db9deb33a..fbe5bae2707399a02c498bf6d83c0c34896f253e 100644 (file)
@@ -65,6 +65,7 @@
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Shell.hxx>
 #include <TopExp_Explorer.hxx>
+#include <BRep_Tool.hxx>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -334,10 +335,57 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const
   return false;
 }
 
+//================================================================================
+/*!
+ * \brief Return name of the algorithm that does not support submeshes and makes
+ * submesh creation useless 
+ *  \retval char* - string is to be deleted!!!
+ */
+//================================================================================
+
+char* SMESHGUI_MeshOp::isSubmeshIgnored() const
+{
+  if ( myToCreate && !myIsMesh ) {
+
+    QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+    QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+    _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
+    if ( pMesh ) {
+
+      QStringList algoNames;
+      THypList    algoList;
+      existingHyps(3, Algo, pMesh, algoNames, algoList);
+      if (!algoList.empty()) {
+        HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
+        if ( algo &&
+             algo->InputTypes.empty() && // builds all dimensions it-self
+             !algo->IsSupportSubmeshes )
+          return CORBA::string_dup( algoNames[0].toLatin1().data() );
+      }
+
+//       GEOM::GEOM_Object_var geom;
+//       if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() ))
+//         geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( pGeom );
+
+//       if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
+        existingHyps(2, Algo, pMesh, algoNames, algoList);
+        if (!algoList.empty()) {
+          HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
+          if ( algo &&
+               algo->InputTypes.empty() && // builds all dimensions it-self
+               !algo->IsSupportSubmeshes )
+            return CORBA::string_dup( algoNames[0].toLatin1().data() );
+        }
+//       }
+    }
+  }
+  return 0;
+}
+
 //================================================================================
 /*!
  * \brief find an existing submesh by the selected shape
 * \retval _PTR(SObject) - the found submesh SObject
+ * \retval _PTR(SObject) - the found submesh SObject
  */
 //================================================================================
 
@@ -462,7 +510,7 @@ void SMESHGUI_MeshOp::selectionDone()
               shapeDim = (shapeDim < 2) ? 2 : shapeDim;
               TopoDS_Shape aShape;
               if (GEOMBase::GetShape(aGeomVar, aShape)) {
-                if (aShape.Closed())
+                if (/*aShape.Closed()*/BRep_Tool::IsClosed(aShape))
                   shapeDim = 3;
               }
             }
@@ -480,7 +528,7 @@ void SMESHGUI_MeshOp::selectionDone()
                   //shapeDim = 3; // Bug 0016155: EDF PAL 447: If the shape is a Shell, disable 3D tab
                   shapeDim = (shapeDim < 2) ? 2 : shapeDim;
                   for (; exp.More() && shapeDim == 2; exp.Next()) {
-                    if (exp.Current().Closed())
+                    if (/*exp.Current().Closed()*/BRep_Tool::IsClosed(exp.Current()))
                       shapeDim = 3;
                   }
                 }
@@ -540,8 +588,20 @@ void SMESHGUI_MeshOp::selectionDone()
             myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" );
             selectObject( _PTR(SObject)() );
             selectionDone();
+            return;
           }
         }
+        // discard selected mesh if submesh creation not allowed because of
+        // a global algorithm that does not support submeshes
+        if ( char* algoName = isSubmeshIgnored() ) {
+          SUIT_MessageBox::warning( myDlg, tr( "SMESH_ERROR" ),
+                                    tr("SUBMESH_NOT_ALLOWED").arg(algoName));
+          CORBA::string_free( algoName );
+          myDlg->selectObject( "", SMESHGUI_MeshDlg::Mesh, "" );
+          selectObject( _PTR(SObject)() );
+          selectionDone();
+          return;
+        }
 
         // enable/disable popup for choice of geom selection way
         bool enable = false;