Salome HOME
0020145: EDF 666 SMESH: Modifications of GEOM groups are not taken into account
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index 11d298a6db9ad87391b8a15f3f3075a7a8d470ca..8e8394dfb3e8c79a5089002d03243c9ecd6c686f 100644 (file)
@@ -1,21 +1,23 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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.
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// Lesser General Public License for more details.
+//  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.
 //
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 /**
 *  SMESH SMESHGUI
@@ -74,6 +76,8 @@
 #include <TopoDS_Shape.hxx>
 #include <TopExp_Explorer.hxx>
 
+using namespace std;
+
 //================================================================================
 /*!
  * \brief Constructor
@@ -340,6 +344,53 @@ 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.latin1() );
+    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].latin1() );
+      }
+
+//       GEOM::GEOM_Object_var geom;
+//       if (_PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ))
+//         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].latin1() );
+        }
+//       }
+    }
+  }
+  return 0;
+}
+
 //================================================================================
 /*!
  * \brief find an existing submesh by the selected shape
@@ -483,6 +534,10 @@ void SMESHGUI_MeshOp::selectionDone()
           }
         }
       }
+      for (int i = SMESH::DIM_3D; i > shapeDim; i--) {
+        // reset algos before disabling tabs (0020138)
+        onAlgoSelected(-1, i);
+      }
       myDlg->setMaxHypoDim( shapeDim );
 
 
@@ -526,8 +581,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::warn1( myDlg, tr( "SMESH_ERROR" ),
+                                  tr("SUBMESH_NOT_ALLOWED").arg(algoName), tr( "SMESH_BUT_OK" ));
+          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;
@@ -900,14 +967,6 @@ void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex )
   createHypothesis(aDim, theHypType, aHypTypeName);
 }
 
-//================================================================================
-/*!
- *  Create hypothesis and update dialog.
- *  \param theDim - dimension of hypothesis to be created
- *  \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
- *  \param theTypeName - specifies hypothesis to be created
- */
-//================================================================================
 namespace
 {
   QString GetUniqueName (const QStringList& theHypNames,
@@ -921,14 +980,19 @@ namespace
   }
 }
 
+//================================================================================
+/*!
+ *  Create hypothesis and update dialog.
+ *  \param theDim - dimension of hypothesis to be created
+ *  \param theType - hypothesis category (algorithm, hypothesis, additional hypothesis)
+ *  \param theTypeName - specifies hypothesis to be created
+ */
+//================================================================================
+
 void SMESHGUI_MeshOp::createHypothesis (const int theDim,
                                         const int theType,
                                         const QString& theTypeName)
 {
-  // During a hypothesis creation we might need to select some objects.
-  // Main dialog must not update it's own selected objects in this case.
-  dlg()->deactivateAll();
-
   HypothesisData* aData = SMESH::GetHypothesisData(theTypeName.latin1());
   if (!aData)
     return;
@@ -963,12 +1027,15 @@ void SMESHGUI_MeshOp::createHypothesis (const int theDim,
 
     // Create hypothesis
     if (aCreator) {
-      // When create or edit a submesh, try to initialize a new hypothesis
-      // with values used to mesh a subshape
+      // Get parameters appropriate to initialize a new hypothesis
       SMESH::SMESH_Hypothesis_var initParamHyp =
         getInitParamsHypothesis(theTypeName, aData->ServerLibName);
+
+      int obj = myDlg->getActiveObject();
+      removeCustomFilters(); // Issue 0020170
       myDlg->setEnabled( false );
       aCreator->create(initParamHyp, aHypName, myDlg);
+      onActivateObject( obj ); // Issue 0020170. Restore filters
       myDlg->setEnabled( true );
     } else {
       SMESH::CreateHypothesis(theTypeName, aHypName, false);
@@ -1014,8 +1081,11 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
   CORBA::String_var aTypeName = aHyp->GetName();
   SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName );
   if ( aCreator ) {
+    int obj = myDlg->getActiveObject();
+    removeCustomFilters(); // Issue 0020170
     myDlg->setEnabled( false );
     aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
+    onActivateObject( obj ); // Issue 0020170. Restore filters
     myDlg->setEnabled( true );
   }
 }