From 61c36a7e0c3f43b3aedd77ef20793ff15620defe Mon Sep 17 00:00:00 2001 From: jrt Date: Fri, 26 Mar 2004 14:53:44 +0000 Subject: [PATCH] Creating and importing 2 meshes from the same engine was not working. Mesh ID management was change to fix this problem. --- src/SMESH/SMESH_Gen.cxx | 13 +++-- src/SMESH/SMESH_Gen.hxx | 2 +- src/SMESH_I/SMESH_Gen_i.cxx | 68 +++++++++++------------ src/SMESH_I/SMESH_Gen_i.hxx | 7 ++- src/SMESH_I/SMESH_HypothesisFactory_i.hxx | 1 + src/SMESH_I/SMESH_Mesh_i.cxx | 37 ++---------- src/SMESH_I/SMESH_Mesh_i.hxx | 7 +-- 7 files changed, 58 insertions(+), 77 deletions(-) diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index 5be63b4a9..d120f41f1 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -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 diff --git a/src/SMESH/SMESH_Gen.hxx b/src/SMESH/SMESH_Gen.hxx index 70f17f506..27b4a8abc 100644 --- a/src/SMESH/SMESH_Gen.hxx +++ b/src/SMESH/SMESH_Gen.hxx @@ -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); diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 511cddd73..0d77f8726 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -26,7 +26,6 @@ // Module : SMESH // $Header$ -using namespace std; #include #include #include @@ -45,9 +44,6 @@ using namespace std; #include #include -#include -#include - #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 +#include +#include +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("<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 "<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) { diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 15cf0b990..7a22deae3 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -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 _mapStudyContext_i; map _SMESHCorbaObj; diff --git a/src/SMESH_I/SMESH_HypothesisFactory_i.hxx b/src/SMESH_I/SMESH_HypothesisFactory_i.hxx index a561a3c00..52fafa587 100644 --- a/src/SMESH_I/SMESH_HypothesisFactory_i.hxx +++ b/src/SMESH_I/SMESH_HypothesisFactory_i.hxx @@ -32,6 +32,7 @@ #include "SMESH_Hypothesis_i.hxx" #include #include +using namespace std; class GenericHypothesisCreator_i { diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 9f1f90099..2c051c72b 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -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 #include - -//**** 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()"); diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 796421478..4942e7983 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -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 _mapSubMeshIor; SMESH::SMESH_Mesh_var _myIor; }; -- 2.30.2