Salome HOME
regression SALOME_TESTS/Grids/smesh/bugs_05/F1
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index 0a935efbed51278c103f22b813f9c0f8fb23915b..6b962a028b003449a14ee77f41dc4c2aa5b7b537 100644 (file)
@@ -93,7 +93,7 @@
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_PreMeshInfo.hxx"
 #include "SMESH_PythonDump.hxx"
-//#include "memoire.h"
+#include "SMESH_TryCatch.hxx" // to include after OCC headers!
 
 #include CORBA_SERVER_HEADER(SMESH_Group)
 #include CORBA_SERVER_HEADER(SMESH_Filter)
@@ -355,20 +355,20 @@ SMESH_Gen_i::~SMESH_Gen_i()
   if ( myShapeReader )
     delete myShapeReader;
 }
-
 //=============================================================================
 /*!
- *  SMESH_Gen_i::createHypothesis
+ *  SMESH_Gen_i::getHypothesisCreator
  *
- *  Create hypothesis of given type
+ *  Get hypothesis creator
  */
 //=============================================================================
-SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
-                                                          const char* theLibName)
+GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHypName,
+                                                              const char* theLibName,
+                                                              std::string& thePlatformLibName)
   throw (SALOME::SALOME_Exception)
 {
-  /* It's Need to tranlate lib name for WIN32 or X platform */
   std::string aPlatformLibName;
+  /* It's Need to tranlate lib name for WIN32 or X platform */
   if ( theLibName && theLibName[0] != '\0'  )
   {
     int libNameLen = strlen(theLibName);
@@ -395,14 +395,13 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName
 #endif
     }
   }
+  thePlatformLibName = aPlatformLibName;
 
   Unexpect aCatch(SALOME_SalomeException);
   if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName);
 
-  // create a new hypothesis object servant
-  SMESH_Hypothesis_i* myHypothesis_i = 0;
-  SMESH::SMESH_Hypothesis_var hypothesis_i;
-
+  typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* );
+  GenericHypothesisCreator_i* aCreator;
   try
   {
     // check, if creator for this hypothesis type already exists
@@ -424,7 +423,6 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName
 
       // get method, returning hypothesis creator
       if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
-      typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
       GetHypothesisCreator procHandle =
         (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
       if (!procHandle)
@@ -435,26 +433,47 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName
 
       // get hypothesis creator
       if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
-      GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
+      aCreator = procHandle(theHypName);
       if (!aCreator)
       {
         throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
       }
-
       // map hypothesis creator to a hypothesis name
       myHypCreatorMap[string(theHypName)] = aCreator;
+      return aCreator;
+    }
+    else
+    {
+      return myHypCreatorMap[string(theHypName)];
     }
-
-    // create a new hypothesis object, store its ref. in studyContext
-    if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
-    myHypothesis_i =
-      myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
-    myHypothesis_i->SetLibName(aPlatformLibName.c_str()); // for persistency assurance
   }
   catch (SALOME_Exception& S_ex)
   {
     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
   }
+  return aCreator;
+}
+
+//=============================================================================
+/*!
+ *  SMESH_Gen_i::createHypothesis
+ *
+ *  Create hypothesis of given type
+ */
+//=============================================================================
+SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
+                                                          const char* theLibName)
+{
+  SMESH_Hypothesis_i* myHypothesis_i = 0;
+  SMESH::SMESH_Hypothesis_var hypothesis_i;
+  std::string aPlatformLibName;
+  typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* );
+  GenericHypothesisCreator_i* aCreator = getHypothesisCreator(theHypName, theLibName, aPlatformLibName);
+  // create a new hypothesis object, store its ref. in studyContext
+  if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
+  myHypothesis_i =
+      myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
+  myHypothesis_i->SetLibName(aPlatformLibName.c_str()); // for persistency assurance
 
   if (!myHypothesis_i)
     return hypothesis_i._retn();
@@ -621,7 +640,7 @@ void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy,
           SALOMEDS::SObject_wrap so = anIter->Value();
           CORBA::Object_var     ior = SObjectToObject( so );
           if ( SMESH_Mesh_i*   mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
-            mesh->CheckGeomGroupModif();
+            mesh->CheckGeomModif();
         }
       }
     }
@@ -1723,7 +1742,7 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
     ASSERT( meshServant );
     if ( meshServant ) {
       // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
-      meshServant->CheckGeomGroupModif();
+      meshServant->CheckGeomModif();
       // get local TopoDS_Shape
       TopoDS_Shape myLocShape;
       if(theMesh->HasShapeToMesh())
@@ -1805,7 +1824,7 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh
     ASSERT( meshServant );
     if ( meshServant ) {
       // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
-      meshServant->CheckGeomGroupModif();
+      meshServant->CheckGeomModif();
       // get local TopoDS_Shape
       TopoDS_Shape myLocShape;
       if(theMesh->HasShapeToMesh())
@@ -2001,7 +2020,7 @@ SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
     ASSERT( meshServant );
     if ( meshServant ) {
       // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
-      meshServant->CheckGeomGroupModif();
+      meshServant->CheckGeomModif();
       // get local TopoDS_Shape
       TopoDS_Shape myLocShape;
       if(theMesh->HasShapeToMesh())
@@ -2635,6 +2654,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
   SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes();
   if ( SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
   {
+    srcMesh_i->Load();
     srcElemIt = srcMeshDS->elementsIterator();
     srcNodeIt = srcMeshDS->nodesIterator();
   }
@@ -2701,10 +2721,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
       const SMDS_MeshElement * newElem;
       switch ( elem->GetEntityType() ) {
       case SMDSEntity_Polyhedra:
-        newElem = editor.GetMeshDS()->
-          AddPolyhedralVolumeWithID( nodes,
-                                     static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
-                                     ID);
+        if ( toKeepIDs )
+          newElem = editor.GetMeshDS()->
+            AddPolyhedralVolumeWithID( nodes,
+                                       static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
+                                       ID);
+        else
+          newElem = editor.GetMeshDS()->
+            AddPolyhedralVolume( nodes,
+                                 static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities());
         break;
       case SMDSEntity_Ball:
         newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID,
@@ -2880,8 +2905,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
   //  ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
   // san -- in case <myCurrentStudy> differs from theComponent's study,
   // use that of the component
-  if ( myCurrentStudy->_is_nil() ||
-    theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
+  if ( theComponent->GetStudy()->StudyId() != GetCurrentStudyID() )
     SetCurrentStudy( theComponent->GetStudy() );
 
   // Store study contents as a set of python commands
@@ -3930,8 +3954,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
 {
   INFOS( "SMESH_Gen_i::Load" );
 
-  if ( myCurrentStudy->_is_nil() ||
-       theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
+  if ( theComponent->GetStudy()->StudyId() != GetCurrentStudyID() )
     SetCurrentStudy( theComponent->GetStudy() );
 
   /*  if( !theComponent->_is_nil() )
@@ -5042,13 +5065,42 @@ void SMESH_Gen_i::Move( const SMESH::sobject_list& what,
       useCaseBuilder->AppendTo( where, sobj );        // append to the end of list
   }
 }
+//=================================================================================
+// function : IsApplicable
+// purpose  : Return true if algorithm can be applied
+//=================================================================================
+CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char*           theAlgoType,
+                                           const char*           theLibName,
+                                           GEOM::GEOM_Object_ptr theGeomObject,
+                                           CORBA::Boolean        toCheckAll)
+{
+  SMESH_TRY;
+
+  std::string aPlatformLibName;
+  typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char*);
+  GenericHypothesisCreator_i* aCreator = getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName);
+  if (aCreator)
+  {
+    TopoDS_Shape shape = GeomObjectToShape( theGeomObject );
+    if ( !shape.IsNull() )
+      return aCreator->IsApplicable( shape, toCheckAll );
+  }
+  else
+  {
+    return false;
+  }
+
+  SMESH_CATCH( SMESH::doNothing );
+  return true;
+}
 
 //=================================================================================
 // function : importData
 // purpose  : imports mesh data file (the med one) into the SMESH internal data structure
 //=================================================================================
-Engines::ListOfIdentifiers* SMESH_Gen_i::importData(
-  CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options)
+Engines::ListOfIdentifiers* SMESH_Gen_i::importData(CORBA::Long                   studyId,
+                                                    Engines::DataContainer_ptr    data,
+                                                    const Engines::ListOfOptions& options)
 {
   Engines::ListOfIdentifiers_var aResultIds = new Engines::ListOfIdentifiers;
   list<string> aResultList;