]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Creating and importing 2 meshes from the same engine was not working. Mesh ID managem...
authorjrt <jrt>
Fri, 26 Mar 2004 14:53:44 +0000 (14:53 +0000)
committerjrt <jrt>
Fri, 26 Mar 2004 14:53:44 +0000 (14:53 +0000)
src/SMESH/SMESH_Gen.cxx
src/SMESH/SMESH_Gen.hxx
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_HypothesisFactory_i.hxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx

index 5be63b4a9ff765c419be4e622b352a438bb957d2..d120f41f1a4dbdc4d237ab0a147408d4470d4c2a 100644 (file)
@@ -97,8 +97,8 @@ SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
  */
 //=============================================================================
 
-SMESH_Mesh *SMESH_Gen::Init(int studyId, const TopoDS_Shape & aShape)
-throw(SALOME_Exception)
+SMESH_Mesh *SMESH_Gen::Init(int studyId, const TopoDS_Shape & aShape, int meshID)
+       throw(SALOME_Exception)
 {
        MESSAGE("SMESH_Gen::Init");
 //   if (aShape.ShapeType() == TopAbs_COMPOUND)
@@ -113,11 +113,16 @@ throw(SALOME_Exception)
 
        // create a new SMESH_mesh object 
 
-       SMESH_Mesh *mesh = new SMESH_Mesh(_localId++,
+       if(meshID == -1)
+               meshID=_localId++;
+       else if(_localId<=meshID)
+               _localId=meshID+1;
+
+       SMESH_Mesh *mesh = new SMESH_Mesh(meshID,
                studyId,
                this,
                myStudyContext->myDocument);
-       myStudyContext->mapMesh[_localId] = mesh;
+       myStudyContext->mapMesh[meshID] = mesh;
 
        // associate a TopoDS_Shape to the mesh
 
index 70f17f50605287ab1479e3a01d0bcbaf05692dec..27b4a8abc6f00c0d5c0b98d1322d3688d93c716c 100644 (file)
@@ -61,7 +61,7 @@ class SMESH_Gen
 
        SMESH_Hypothesis *CreateHypothesis(const char *anHyp, int studyId)
                throw(SALOME_Exception);
-       SMESH_Mesh *Init(int studyId, const TopoDS_Shape & aShape)
+       SMESH_Mesh *Init(int studyId, const TopoDS_Shape & aShape, int meshID = -1)
                throw(SALOME_Exception);
        bool Compute(::SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
                throw(SALOME_Exception);
index 511cddd735eb272cfc78fe786644654bf74466b2..0d77f87268b5910ba3dd1770557ce1005aa0427d 100644 (file)
@@ -26,7 +26,6 @@
 //  Module : SMESH
 //  $Header$
 
-using namespace std;
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
@@ -45,9 +44,6 @@ using namespace std;
 #include <BRep_Tool.hxx>
 #include <TCollection_AsciiString.hxx>
 
-#include <fstream>
-#include <stdio.h>
-
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_LocalLength_i.hxx"
@@ -71,6 +67,9 @@ using namespace std;
 #include "GEOM_Client.hxx"
 
 #include <map>
+#include <fstream>
+#include <stdio.h>
+using namespace std;
 
 #define NUM_TMP_FILES 4
 
@@ -118,7 +117,6 @@ SMESH_Gen_i::SMESH_Gen_i(CORBA::ORB_ptr orb,
        _id = _poa->activate_object(_thisObj);
 
        _ShapeReader = NULL;
-       _localId = 0;                           // number of created objects & local id 
 
 }
 
@@ -164,15 +162,23 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis(const char *anHyp,
        return SMESH::SMESH_Hypothesis::_duplicate(hypothesis_i);
 }
 
-//=============================================================================
-/*!
- *  
+/**
+ * CORBA implementation of SMESH_Gen::Init. See SMESH_Gen.idl.
  */
-//=============================================================================
-
 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
        CORBA::Long studyId,
        GEOM::GEOM_Shape_ptr aShape) throw(SALOME::SALOME_Exception)
+{
+       return Init(geomEngine, studyId, aShape, -1);
+}
+
+/**
+ * This is NOT a CORBA implementation. Differ from the Init CORBA method
+ * by allowing to specify the ID of the created mesh.
+ */
+SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
+       CORBA::Long studyId, GEOM::GEOM_Shape_ptr aShape, int meshID)
+       throw(SALOME::SALOME_Exception)
 {
        MESSAGE("Init");
        // _narrow() duplicates the reference and checks the type
@@ -204,16 +210,13 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Init(GEOM::GEOM_Gen_ptr geomEngine,
                }
                StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
 
-               // create a new mesh object servant, store it in a map in study context
-
-               meshServant = new SMESH_Mesh_i(this, geom, studyId, _localId);
-               myStudyContext->mapMesh_i[_localId] = meshServant;
-               _localId++;
-
                // create a new mesh object
-
                TopoDS_Shape myLocShape = _ShapeReader->GetShape(geom, myShape);
-               meshServant->SetImpl(_impl.Init(studyId, myLocShape));
+               SMESH_Mesh * meshImpl=_impl.Init(studyId, myLocShape, meshID);
+
+               // create a new mesh object servant, store it in a map in study context
+               meshServant = new SMESH_Mesh_i(this, geom, studyId, meshImpl);
+               myStudyContext->mapMesh_i[meshServant->GetId()] = meshServant;
        }
        catch(SALOME_Exception & S_ex)
        {
@@ -551,7 +554,7 @@ SALOMEDS::TMPFile * SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
                                                string_to_object(anIOR->Value()));
                                        SCRUTE(anIOR->Value());
                                        SCRUTE(myAlgo->_is_nil());
-                                       fprintf(destFile, "%i\n", myAlgo->GetId());
+                                       fprintf(destFile, "%li\n", myAlgo->GetId());
                                        fprintf(destFile, "%s\n", myAlgo->GetName());
                                }
                        }
@@ -615,7 +618,7 @@ SALOMEDS::TMPFile * SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
                                        meshfile = "No data";
 
                                //********** opening of the HDF group
-                               sprintf(name_meshgroup, "Mesh %d", gotBranch->Tag());
+                               sprintf(name_meshgroup, "Mesh %d", meshId);
                                SCRUTE(name_meshgroup);
                                hdf_group[gotBranch->Tag()] =
                                        new HDFgroup(name_meshgroup, hdf_file);
@@ -973,8 +976,6 @@ void SMESH_Gen_i::loadHypothesis(char * name, HDFfile * hdf_file,
 {
        char name_of_group[HDF_NAME_MAX_LEN + 1];
        char objectId[10];
-       double length, maxElementsArea, maxElementsVolume;
-       int numberOfSegments;
 
        HDFgroup * hdfGroup = new HDFgroup(name, hdf_file);
        hdfGroup->OpenOnDisk();
@@ -1421,7 +1422,8 @@ GEOM::GEOM_Shape_var SMESH_Gen_i::getShape(SALOMEDS::Study_var Study, char * ref
 void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
        char* meshfile, SALOMEDS::Study_var Study)
 {
-       MESSAGE("in mesh load");
+       MESSAGE("SMESH_Gen_i::loadMesh("<<name<<","<<meshfile<<")");
+
        char msgname[HDF_NAME_MAX_LEN + 1];     
        char objectId[10];
        char name_of_group[HDF_NAME_MAX_LEN + 1];
@@ -1437,7 +1439,6 @@ void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
        SCRUTE(nb_meshsubgroup);
 
        //********** Loading of the file name where the data are stored
-       MESSAGE("Mesh data file");
        strcpy(name_of_group, "Mesh data");
        HDFdataset * dataset =
                new HDFdataset(name_of_group, hdfGroupMeshId);
@@ -1451,7 +1452,6 @@ void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
 
        //********** Loading of the reference on the shape
        //********** and mesh initialization
-       MESSAGE("Ref on shape");
        strcpy(name_of_group, "Ref on shape");
        dataset =
                new HDFdataset(name_of_group, hdfGroupMeshId);
@@ -1469,10 +1469,12 @@ void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
        if (!CORBA::is_nil(aShape))
        {
                _found = true;
-               myNewMesh = this->Init(getGeomEngine(), Study->StudyId(), aShape);
+               myNewMesh = Init(getGeomEngine(), Study->StudyId(), aShape, myMeshId);
                string iorString = _orb->object_to_string(myNewMesh);
                sprintf(objectId, "%ld", myNewMesh->GetId());
-               _SMESHCorbaObj[string("Mesh_") + string(objectId)] = iorString;
+               string key=string("Mesh_")+string(objectId);
+               MESSAGE("IOR of "<<key<<" is "<< iorString)
+               _SMESHCorbaObj[key] = iorString;
 
                
                //********** 
@@ -1526,7 +1528,6 @@ void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
                }
        }
        hdfGroupMeshId->CloseOnDisk();
-       MESSAGE("End of Meshes Load");
 }
 
 /**
@@ -1943,13 +1944,12 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Import(CORBA::Long studyId,
                }
                StudyContext_iStruct *myStudyContext = _mapStudyContext_i[studyId];
 
-               // create a new mesh object servant, store it in a map in study context
-               meshServant = new SMESH_Mesh_i(this, NULL, studyId, _localId);
-               myStudyContext->mapMesh_i[_localId] = meshServant;
-               _localId++;
-
                // create a new mesh object
-               meshServant->SetImpl(_impl.Import(studyId, fileName, fileType));
+               SMESH_Mesh * meshImpl=_impl.Import(studyId, fileName, fileType);
+               
+               // create a new mesh object servant, store it in a map in study context
+               meshServant = new SMESH_Mesh_i(this, NULL, studyId, meshImpl);
+               myStudyContext->mapMesh_i[meshImpl->GetId()] = meshServant;
        }
        catch(SALOME_Exception & S_ex)
        {
index 15cf0b9900cbf6e237d6ade246e4325217d18480..7a22deae399c388ee99a251af161aca80076a0a0 100644 (file)
@@ -82,6 +82,12 @@ public:
                              GEOM::GEOM_Shape_ptr aShape)
     throw (SALOME::SALOME_Exception);
 
+  SMESH::SMESH_Mesh_ptr Init(GEOM::GEOM_Gen_ptr geomEngine,
+                             CORBA::Long studyId,
+                             GEOM::GEOM_Shape_ptr aShape,
+                                                        int meshID)
+    throw (SALOME::SALOME_Exception);
+
   CORBA::Boolean Compute(SMESH::SMESH_Mesh_ptr aMesh,
                          GEOM::GEOM_Shape_ptr aShape)
     throw (SALOME::SALOME_Exception);
@@ -175,7 +181,6 @@ void loadSubMeshes(HDFgroup * hdfGroupMeshId, char * msgname,
                        
   SMESH_HypothesisFactory_i _hypothesisFactory_i;
   ::SMESH_Gen _impl;  // no namespace here
-  int _localId; // unique Id of created objects, within SMESH_Gen_i entity
 
   map<int, StudyContext_iStruct*> _mapStudyContext_i;
   map <string, string> _SMESHCorbaObj;
index a561a3c00aa3931a16c53c716d901e0de8fb7b62..52fafa5875bdf831171121ac28a3f8b5dc413002 100644 (file)
@@ -32,6 +32,7 @@
 #include "SMESH_Hypothesis_i.hxx"
 #include <map>
 #include <string>
+using namespace std;
 
 class GenericHypothesisCreator_i
 {
index 9f1f9009968941fb7c867d8bc30c456300f16fbe..2c051c72b72f2fc8b3c26c119d2e4efb906ab6ba 100644 (file)
@@ -26,7 +26,6 @@
 //  Module : SMESH
 //  $Header$
 
-using namespace std;
 #include "SMESH_Mesh_i.hxx"
 #include "SMESH_subMesh_i.hxx"
 #include "SMESH_MEDMesh_i.hxx"
@@ -45,20 +44,7 @@ using namespace std;
 
 #include <string>
 #include <iostream>
-
-//**** SMESHDS en champ
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-
-SMESH_Mesh_i::SMESH_Mesh_i()
-{
-       MESSAGE("SMESH_Mesh_i: default constructor, not for use");
-       ASSERT(0);
-};
+using namespace std;
 
 //=============================================================================
 /*!
@@ -67,13 +53,13 @@ SMESH_Mesh_i::SMESH_Mesh_i()
 //=============================================================================
 
 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i * gen_i,
-       GEOM::GEOM_Gen_ptr geomEngine, CORBA::Long studyId, int localId)
+       GEOM::GEOM_Gen_ptr geomEngine, CORBA::Long studyId, ::SMESH_Mesh * impl)
 {
        MESSAGE("SMESH_Mesh_i");
        _gen_i = gen_i;
-       _id = localId;
        _geom = GEOM::GEOM_Gen::_narrow(geomEngine);
-       _studyId = studyId;
+       _impl=impl;
+       _studyId=studyId;
 }
 
 //=============================================================================
@@ -512,8 +498,7 @@ void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
 
 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
 {
-       MESSAGE("SMESH_Mesh_i::GetId");
-       return _id;
+       return _impl->GetId();
 }
 
 //=============================================================================
@@ -533,18 +518,6 @@ CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
  */
 //=============================================================================
 
-void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
-{
-       MESSAGE("SMESH_Mesh_i::SetImpl");
-       _impl = impl;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-
 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
 {
        MESSAGE("SMESH_Mesh_i::GetImpl()");
index 796421478fe7b5b02f99a041ce2239500307516e..4942e798350a0e5e9ef4e7f4baffe6e22019dcab 100644 (file)
@@ -50,11 +50,10 @@ class SMESH_Mesh_i:
   public POA_SMESH::SMESH_Mesh
 {
 public:
-  SMESH_Mesh_i();
   SMESH_Mesh_i(SMESH_Gen_i* myGen_i,
               GEOM::GEOM_Gen_ptr geomEngine,
               CORBA::Long studyId,
-              int localId);
+              ::SMESH_Mesh * impl);
 
   virtual ~SMESH_Mesh_i();
 
@@ -143,10 +142,8 @@ private:
   SMESH_Gen_i* _gen_i;
   //   CORBA::ORB_ptr _orb;
 //   SMESH_topo* _topo;   // all local TopoDS_Shape of subShapes
-  int _id;          // id given by creator (unique within the creator instance)
   GEOM::GEOM_Gen_var _geom;
-  int _studyId;
-  //  int _localId; // id attributed to all objects created by Mesh_i
+  CORBA::Long _studyId;
   map<int, SMESH::SMESH_subMesh_ptr> _mapSubMeshIor;
   SMESH::SMESH_Mesh_var _myIor;
 };