From 4a6593b42e0624ebb8d85178cc9a678d534c2b8c Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 4 Jul 2007 13:11:35 +0000 Subject: [PATCH] Persistence for MULTIPR: first version. --- src/MULTIPR/MULTIPR_i.cxx | 500 ++++++++++++++++++++++++++------- src/MULTIPR/MULTIPR_i.hxx | 41 ++- src/MULTIPRGUI/MULTIPR_GUI.cxx | 9 +- src/MULTIPRGUI/MULTIPR_GUI.h | 6 +- 4 files changed, 437 insertions(+), 119 deletions(-) diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index 05318b7..ce51c25 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -27,6 +27,7 @@ using namespace std; #include "MULTIPR_API.hxx" #include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Utils.hxx" #include @@ -183,8 +184,8 @@ namespace MULTIPR // Class MULTIPR_Gen_i implementation //***************************************************************************** -MULTIPR_Gen_i::MULTIPR_Gen_i( - CORBA::ORB_ptr orb, +MULTIPR_Gen_i::MULTIPR_Gen_i + (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId* contId, const char* instanceName, @@ -308,28 +309,30 @@ MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_Gen_i::getObject (const char* medFilename) throw (SALOME::SALOME_Exception) { MULTIPR_Obj_i* obj = new MULTIPR_Obj_i(medFilename); - //MULTIPR_ORB::MULTIPR_Gen_ptr engine = _this(); - //obj->setEngine(engine); obj->setEngine(this); // Dump Python - //MULTIPR::TPythonDump(engine) << obj << " = " << this << ".getObject(\"" << medFilename << "\")"; MULTIPR::TPythonDump(this) << obj << " = " << this << ".getObject(\"" << medFilename << "\")"; return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this(); } -MULTIPR_Obj_i::MULTIPR_Obj_i (const char* medFilename) - throw (SALOME::SALOME_Exception) +MULTIPR_Obj_i::MULTIPR_Obj_i (const char* medFilename, bool isPersistence, bool isMultifile) + throw (SALOME::SALOME_Exception) + : mBoxing(100), + _engine(NULL), + mIsTmp(isPersistence && !isMultifile) { - mObj = new multipr::Obj(); - mBoxing = 100; - + mObj = new multipr::Obj(); + try { cout << "Load " << medFilename << endl; - mObj->create(medFilename); + if (isPersistence) + mObj->restorePersistent(medFilename); + else + mObj->create(medFilename); cout << endl; } catch (multipr::RuntimeException& e) @@ -344,12 +347,26 @@ MULTIPR_Obj_i::MULTIPR_Obj_i (const char* medFilename) MULTIPR_Obj_i::~MULTIPR_Obj_i() { - if (mObj != NULL) + if (mObj != NULL) + { + if (mIsTmp) { - cout << "MULTIPR: Destructor: remove mObj" << endl; - delete mObj; - mObj = NULL; + // Remove temporary files, created during study loading, together with directory + std::string strFile = mObj->getMEDFilename(); + std::string strPath = multipr::getPath(strFile.c_str()); +#ifdef WNT + //std::string cmd_rm ("del /F \""); +#else + std::string cmd_rm ("rm -rf \""); +#endif + cmd_rm += strPath + "\""; + system(cmd_rm.c_str()); } + + cout << "MULTIPR: Destructor: remove mObj" << endl; + delete mObj; + mObj = NULL; + } } @@ -410,6 +427,14 @@ void MULTIPR_Obj_i::setMesh (const char* meshName) } } +std::string MULTIPR_Obj_i::getMeshName() const + throw (SALOME::SALOME_Exception) +{ + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + return mObj->getMeshName(); +} + void MULTIPR_Obj_i::setBoxing (CORBA::Long pBoxing) throw (SALOME::SALOME_Exception) @@ -697,27 +722,64 @@ void MULTIPR_Obj_i::removeParts (const char* pPrefixPartName) void MULTIPR_Obj_i::save(const char* pPath) throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - try - { - mObj->save(pPath); - } - catch (multipr::RuntimeException& e) + try + { + std::string strFile = mObj->getMEDFilename(); + + // Do Save + mObj->save(pPath); + + // Remove temporary files, if needed + if (mIsTmp) { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR); + mIsTmp = false; + + // Remove temporary files, created during study loading, together with directory + std::string strPath = multipr::getPath(strFile.c_str()); +#ifdef WNT + //std::string cmd_rm ("del /F \""); +#else + std::string cmd_rm ("rm -rf \""); +#endif + cmd_rm += strPath + "\""; + system(cmd_rm.c_str()); } + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR); + } - // Dump Python - MULTIPR::TPythonDump(_engine) << this << ".save(\"" << pPath << "\")"; + // Dump Python + MULTIPR::TPythonDump(_engine) << this << ".save(\"" << pPath << "\")"; } -//void MULTIPR_Obj_i::setEngine (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine) +//----------------------------------------------------------------------------- +// savePersistent and setEngine (for Persistence & Dump Python) +//----------------------------------------------------------------------------- + +void MULTIPR_Obj_i::savePersistent (const char* pPath) + throw (SALOME::SALOME_Exception) +{ + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + mObj->savePersistent(pPath); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR); + } +} + void MULTIPR_Obj_i::setEngine (MULTIPR_Gen_i* theEngine) { - //_engine = MULTIPR_ORB::MULTIPR_Gen::_duplicate(theEngine); _engine = theEngine; } @@ -764,6 +826,39 @@ SALOMEDS::Study_ptr MULTIPR_Gen_i::GetCurrentStudy() // SALOMEDS::Driver methods (Persistence & Dump Python) //----------------------------------------------------------------------------- +/*! Get component data type + */ +char* MULTIPR_Gen_i::ComponentDataType() +{ + if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::ComponentDataType" ); + return CORBA::string_dup( "MULTIPR" ); +} + +/*! Clears study-connected data when it is closed + */ +void MULTIPR_Gen_i::Close (SALOMEDS::SComponent_ptr theComponent) +{ + if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::Close" ); + + // Clear study contexts data + //_impl->Close(theComponent->GetStudy()->StudyId()); + + // Destroy all objects + SALOMEDS::Study_ptr aStudy = theComponent->GetStudy(); + SALOMEDS::ChildIterator_ptr obj_it (aStudy->NewChildIterator(theComponent)); + for (; obj_it->More(); obj_it->Next()) + { + SALOMEDS::SObject_ptr aSObj = obj_it->Value(); + CORBA::Object_var anObj = aSObj->GetObject(); + MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj); + if (!CORBA::is_nil(obj)) + { + //obj->Destroy(); + CORBA::Object_Helper::release(obj); + } + } +} + /*! Save MULTIPR module's data */ SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent, @@ -779,6 +874,11 @@ SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent, // Store study contents as a set of python commands SavePython(myCurrentStudy); + // Study name (for tmp directory and tmp files naming) + std::string aStudyName; + if (isMultiFile) + aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()); + // Declare a byte stream SALOMEDS::TMPFile_var aStreamFile; @@ -794,64 +894,135 @@ SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent, if (CORBA::is_nil(obj)) return aStreamFile._retn(); + // Obtain a temporary directory + std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); + + // Directory for MED data to be stored in a distributed MED file + std::string subDir = aStudyName + "_MULTIPR_MED"; + std::string meshDir = tmpDir + subDir; + + // Create a new dir to save the sequential/distributed file in. + // Remove all the files in if they exist. +#ifdef WNT + std::string dirSeparator = "\\"; + //std::string cmd_mk ("mkdir /F \""); + //std::string cmd_rm ("del /F \""); +#else + std::string dirSeparator = "/"; + std::string cmd_mk ("mkdir \""); + std::string cmd_rm ("rm -rf \""); +#endif + cmd_mk += meshDir + "\""; + cmd_rm += meshDir + dirSeparator + "\"*"; + system(cmd_mk.c_str()); + system(cmd_rm.c_str()); + + // Create a sequence of files processed + SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames; + if (obj->isValidSequentialMEDFile()) { - // TODO + std::string aFile = obj->getFilename(); + std::string aFileName = multipr::getFilenameWithoutPath(aFile.c_str()); + + // Copy initial sequential MED file to +#ifdef WNT + std::string dirSeparator = "\\"; + //std::string cmd_cp ("copy \""); +#else + std::string dirSeparator = "/"; + std::string cmd_cp ("cp \""); +#endif + cmd_cp += aFile + "\" \"" + meshDir + dirSeparator + "\""; + system(cmd_cp.c_str()); + + // Set names of temporary files + std::string aFileNameRel = subDir + dirSeparator + aFileName; + aFileSeq->length(1); + aFileSeq[0] = CORBA::string_dup(aFileNameRel.c_str()); // sequential MED file } else if (obj->isValidDistributedMEDFile()) { - /* - // Obtain a temporary dir - std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); + // Save distributed MED file to the + PortableServer::Servant aServant = _poa->reference_to_servant(obj); + MULTIPR_Obj_i* objServant = dynamic_cast(aServant); + if (!objServant) + { + // TODO: exception + return aStreamFile._retn(); + } + objServant->savePersistent(meshDir.c_str()); + + // ASCII master file name + std::string aMaitreFile = obj->getFilename(); + std::string aMaitreFileName = multipr::getFilenameWithoutPath(aMaitreFile.c_str()); + // just after partitionneDomaine() the state is MULTIPR_OBJ_STATE_DIS_MEM, + // and getFilename() returns name of sequential file + // (because distributed file is not created on disk yet). So, build the name: + if (aMaitreFile == obj->getSeqFilename()) + { + std::string strExtension (".med"); + std::string strNamePrefix = + multipr::removeExtension(aMaitreFileName.c_str(), strExtension.c_str()); + aMaitreFileName = strNamePrefix + "_grains_maitre" + strExtension; + } + //std::string aMaitreFileName = SALOMEDS_Tool::GetNameFromPath(aMaitreFile); + std::string aMaitreFileNameRel = subDir + dirSeparator + aMaitreFileName; - // Create a sequence of files processed - SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames; + // Set names of temporary files + MULTIPR_ORB::string_array* listParts = obj->getParts(); + unsigned int nbParts = listParts->length(); + aFileSeq->length(nbParts + 1); - std::string aStudyName; - if (isMultiFile) - aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()); + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; - // ?? create a new dir in for all parts of distributed file - // or it will be created automatically ?? - obj->save(tmpDir.c_str()); + for (unsigned int i = 0; i < nbParts; i++) // each part MED files + { + const char* strPartName = (*listParts)[i]; + char* strPartInfo = obj->getPartInfo(strPartName); - // TODO: set real length - aFileSeq->length(1); // nb.distributed files + 1 (_maitre.med) + // parse infos + int ret = sscanf(strPartInfo, "%s %d %s %s %s", + lMeshName, &lId, lPartName, lPath, lMEDFileName); - // Set names of temporary files - std::string meshdir = - aStudyName + "_MULTIPR_Mesh"; // for MED data to be stored in distributed MED file - //std::string filename = aStudyName + "_MULTIPR.hdf"; // for MULTIPR data itself - - aFileSeq[0] = CORBA::string_dup(meshdir.c_str()); - //aFileSeq[1] = CORBA::string_dup(meshfile.ToCString()); - meshdir = tmpDir + meshfile; - //filename = tmpDir + filename; - //*/ - - //Remove the files if they exist - //#ifndef WNT - // TCollection_AsciiString cmd ("rm -f \""); - //#else - // TCollection_AsciiString cmd ("del /F \""); - //#endif - - //cmd+=filename; - //cmd+="\" \""; - //cmd+=meshfile; - //cmd+="\""; - //system(cmd.ToCString()); - - // Convert temporary files to stream - //aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile); - - // Remove temporary files and directory - //if (!isMultiFile) - // SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true); + if (ret != 5) + { + // TODO: exception + return aStreamFile._retn(); + } + + std::string aPartFileName = multipr::getFilenameWithoutPath(lMEDFileName); + std::string aPartFileNameRel = subDir + dirSeparator + aPartFileName; + + aFileSeq[i] = CORBA::string_dup(aPartFileNameRel.c_str()); // part MED file + } + aFileSeq[nbParts] = CORBA::string_dup(aMaitreFileNameRel.c_str()); // ASCII master file } else { - // ?? + // TODO: exception + return aStreamFile._retn(); + } + + // Convert temporary files to stream + aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir, aFileSeq.in(), isMultiFile); + + // Remove temporary files and directory + if (!isMultiFile) + { + //SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir, aFileSeq.in(), true); + // remove with shell command, because SALOMEDS_Tool::RemoveTemporaryFiles does not remove sub-folders +#ifdef WNT + //std::string cmd_rm ("del /F \""); +#else + std::string cmd_rm ("rm -rf \""); +#endif + cmd_rm += tmpDir + "\""; + system(cmd_rm.c_str()); } INFOS("MULTIPR_Gen_i::Save() completed"); @@ -883,17 +1054,35 @@ bool MULTIPR_Gen_i::Load (SALOMEDS::SComponent_ptr theComponent, SetCurrentStudy(theComponent->GetStudy()); // Get temporary files location - //TCollection_AsciiString tmpDir = - // isMultiFile ? TCollection_AsciiString((char*)theURL) : (char*)SALOMEDS_Tool::GetTmpDir().c_str(); + std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); INFOS("THE URL++++++++++++++"); INFOS(theURL); - //INFOS("THE TMP PATH+++++++++"); - //INFOS(tmpDir); + INFOS("THE TMP PATH+++++++++"); + INFOS(tmpDir.c_str()); + + // For LocalPersistentIDToIOR(): + myTmpDir = tmpDir; + + // Create a new dir to restore the distributed/sequential + // MED file in. It is needed only if not multifile, because in + // multifile study all required files are already on disk. + if (!isMultiFile) + { + std::string subDir = "_MULTIPR_MED"; + std::string meshDir = tmpDir + subDir; +#ifdef WNT + //std::string cmd_mk ("mkdir /F \""); +#else + std::string cmd_mk ("mkdir \""); +#endif + cmd_mk += meshDir + "\""; + system(cmd_mk.c_str()); + } // Convert the stream into sequence of files to process - //SALOMEDS::ListOfFileNames_var aFileSeq = - // SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.ToCString(), isMultiFile); + SALOMEDS::ListOfFileNames_var aFileSeq = + SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.c_str(), isMultiFile); //TCollection_AsciiString aStudyName; //if (isMultiFile) @@ -922,40 +1111,89 @@ bool MULTIPR_Gen_i::LoadASCII (SALOMEDS::SComponent_ptr theComponent, return Load(theComponent, theStream, theURL, isMultiFile); } -/*! Clears study-connected data when it is closed - */ -void MULTIPR_Gen_i::Close (SALOMEDS::SComponent_ptr theComponent) -{ - if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::Close" ); - - // Clear study contexts data - //_impl->Close(theComponent->GetStudy()->StudyId()); -} - -/*! Get component data type - */ -char* MULTIPR_Gen_i::ComponentDataType() -{ - if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::ComponentDataType" ); - return CORBA::string_dup( "MULTIPR" ); -} - /*! Transform data from transient form to persistent */ char* MULTIPR_Gen_i::IORToLocalPersistentID (SALOMEDS::SObject_ptr /*theSObject*/, const char* IORString, - CORBA::Boolean /*isMultiFile*/, + CORBA::Boolean isMultiFile, CORBA::Boolean /*isASCII*/ ) { if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID"); - MULTIPR_ORB::MULTIPR_Obj_ptr anObject = + MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(_orb->string_to_object(IORString)); - if (!CORBA::is_nil(anObject)) + if (!CORBA::is_nil(obj)) { - if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID: id = " << anObject->getFilename()); - return CORBA::string_dup(anObject->getFilename()); + std::string aStudyName; + if (isMultiFile) + aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()); + + std::string subDir = aStudyName + "_MULTIPR_MED"; + + std::string aFile = obj->getFilename(); + std::string aFileName = multipr::getFilenameWithoutPath(aFile.c_str()); + + // Get servant (to call methods, not present in IDL interface + PortableServer::Servant aServant = _poa->reference_to_servant(obj); + MULTIPR_Obj_i* objServant = dynamic_cast(aServant); + if (!objServant) + { + // TODO: exception + return CORBA::string_dup(""); + } + + std::string strSeparator ("|"); + if (obj->isValidSequentialMEDFile()) + { + // Save Boxing + char strBoxing[32]; + sprintf(strBoxing, "%d", objServant->getBoxing()); + aFileName += strSeparator + strBoxing; + + // Save Mesh Name + std::string aMeshName = objServant->getMeshName(); + if (!aMeshName.empty()) + { + aFileName += strSeparator + aMeshName; + } + } + else if (obj->isValidDistributedMEDFile()) + { + // just after partitionneDomaine() the state is MULTIPR_OBJ_STATE_DIS_MEM, + // and getFilename() returns name of sequential file + // (because distributed file is not created on disk yet). So, build the name: + if (aFile == obj->getSeqFilename()) + { + std::string strExtension (".med"); + std::string strNamePrefix = + multipr::removeExtension(aFileName.c_str(), strExtension.c_str()); + aFileName = strNamePrefix + "_grains_maitre" + strExtension; + } + + // Save Boxing + char strBoxing[32]; + sprintf(strBoxing, "%d", objServant->getBoxing()); + aFileName += strSeparator + strBoxing; + } + else + { + // TODO: exception + return CORBA::string_dup(""); + } + + // PersistentID will be a relative path to MED file (relatively tmp dir) + // plus additianal parameters, separated by '|' (see above) +#ifdef WNT + std::string dirSeparator = "\\"; +#else + std::string dirSeparator = "/"; +#endif + aFileName = subDir + dirSeparator + aFileName; + + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID: id = " << aFileName.c_str()); + + return CORBA::string_dup(aFileName.c_str()); } return CORBA::string_dup(""); } @@ -964,23 +1202,67 @@ char* MULTIPR_Gen_i::IORToLocalPersistentID (SALOMEDS::SObject_ptr /*theSObject* */ char* MULTIPR_Gen_i::LocalPersistentIDToIOR (SALOMEDS::SObject_ptr /*theSObject*/, const char* aLocalPersistentID, - CORBA::Boolean /*isMultiFile*/, + CORBA::Boolean isMultiFile, CORBA::Boolean /*isASCII*/) { if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID); if (strlen(aLocalPersistentID) > 0) { - //string medFilename (myTmpDir); - //medFilename += "/"; - string medFilename ("/tmp/"); - medFilename += aLocalPersistentID; - MULTIPR_ORB::MULTIPR_Obj_ptr anObj = getObject(medFilename.c_str()); + // Extract relative path + std::string strLocalPersistentID (aLocalPersistentID); + int nb = strLocalPersistentID.find("|"); + if (nb < 1) nb = strLocalPersistentID.size(); + if (nb < 1) + { + // TODO: exception + return CORBA::string_dup(""); + } + std::string strRelativePath = strLocalPersistentID.substr(0, nb); + strLocalPersistentID.erase(0, nb); // erase + if (strLocalPersistentID.size() > 0) strLocalPersistentID.erase(0, 1); // erase "|" + + // the only kind of available objects is a MULTIPR_ORB::MULTIPR_Obj, + // representing a sequential or a distributed MED file. + std::string medFilename = myTmpDir + strRelativePath; // myTmpDir already contains dir separator + + // create MULTIPR_Obj from file + //MULTIPR_ORB::MULTIPR_Obj_ptr obj = getObject(medFilename.c_str()); + MULTIPR_Obj_i* obj_i = new MULTIPR_Obj_i (medFilename.c_str(), + /*isPersistence = */true, + isMultiFile); + obj_i->setEngine(this); + MULTIPR_ORB::MULTIPR_Obj_ptr obj = obj_i->POA_MULTIPR_ORB::MULTIPR_Obj::_this(); + + // Set boxing and mesh name, if provided + nb = strLocalPersistentID.find("|"); + if (nb < 1) nb = strLocalPersistentID.size(); + if (nb > 0) + { + std::string strBoxing = strLocalPersistentID.substr(0, nb); + strLocalPersistentID.erase(0, nb); // erase + if (strLocalPersistentID.size() > 0) strLocalPersistentID.erase(0, 1); // erase "|" + int aBoxing = atoi(strBoxing.c_str()); + obj->setBoxing(aBoxing); + } + + if (obj->isValidSequentialMEDFile()) + { + nb = strLocalPersistentID.size(); + if (nb > 0) + { + std::string strMeshName = strLocalPersistentID.substr(0, nb); + obj->setMesh(strMeshName.c_str()); + // we do not cut here, + // because we do not expect to find in it anything + } + } - CORBA::String_var anIORString = _orb->object_to_string(anObj); + // get IOR string + CORBA::String_var anIORString = _orb->object_to_string(obj); return CORBA::string_dup(anIORString); } - return CORBA::string_dup( "" ); + return CORBA::string_dup(""); } /*! Transform data from persistent form to transient diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index 9a18cd3..cb47bef 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -49,7 +49,9 @@ public: * Associate a MED file (sequential or distributed) with this object. * \param pMEDFilename MED file to be associated with this object. */ - MULTIPR_Obj_i(const char* pMEDFilename) + MULTIPR_Obj_i (const char* pMEDFilename, + bool isPersistence = false, + bool isMultifile = false) throw (SALOME::SALOME_Exception); /** @@ -88,20 +90,35 @@ public: */ char* getSeqFilename() throw (SALOME::SALOME_Exception); + /** * Defines the mesh to be processed. * \param pMeshName name of the mesh to be partitionned. */ void setMesh(const char* pMeshName) throw (SALOME::SALOME_Exception); - + + /** + * Returns a name of the mesh to be processed. + * \return a name of the mesh to be processed. + */ + std::string getMeshName() const + throw (SALOME::SALOME_Exception); + /** * Sets boxing parameters for decimation (100 by default). - * \param pBoxing number of cells along each axis of the grid (= acceleration structure) ; should be in [1..200]. + * \param pBoxing number of cells along each axis of the grid + * (= acceleration structure) ; should be in [1..200]. */ void setBoxing(CORBA::Long pBoxing) throw (SALOME::SALOME_Exception); + /** + * Returns currently set boxing parameter for decimation. + * \return currently set boxing parameter for decimation. + */ + int getBoxing() const { return mBoxing; } + /** * Returns the list of meshes contained in the sequential MED file. * Assumes this object encapsulates a sequential MED file. @@ -237,11 +254,19 @@ public: */ void save(const char* pPath) throw (SALOME::SALOME_Exception); - + //--------------------------------------------------------------------- // Persistence and Dump Python //--------------------------------------------------------------------- + /** + * Saves the associated MED file to the given location. + * \note To be used only for persistence. + * \param pPath path where to save the file. + */ + void savePersistent (const char* pPath) + throw (SALOME::SALOME_Exception); + /** * Set Engine. */ @@ -265,8 +290,12 @@ private: /** * Engine. */ - //MULTIPR_ORB::MULTIPR_Gen_ptr _engine; MULTIPR_Gen_i* _engine; + + /** + * Is restored MED file (Used by Persistence to remove temporary files). + */ + bool mIsTmp; }; @@ -419,6 +448,8 @@ private: SALOMEDS::Study_var myCurrentStudy; // Dump Python: trace of API methods calls std::map < int, std::vector > myPythonScripts; + // Tmp directory. Used by Persistence. + std::string myTmpDir; }; diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index 43e3ea7..b5bb286 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -935,7 +935,8 @@ QString MULTIPR_GUI_DataObject_Resolution::toolTip() const //***************************************************************************** MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) - : LightApp_DataModel(module) + //: LightApp_DataModel(module) + : SalomeApp_DataModel(module) { mMULTIPR_GUI = dynamic_cast(module); } @@ -1058,9 +1059,11 @@ void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy) if (!CORBA::is_nil(obj)) { // MED file object - const char* lMEDFile = obj->getFilename(); + std::string lMEDFile = obj->getFilename(); + std::string lMEDFileName = multipr::getFilenameWithoutPath(lMEDFile.c_str()); //MULTIPR_GUI_DataObject_MED* dataObjectMED = new MULTIPR_GUI_DataObject_MED(modelRoot, lMEDFile); - MULTIPR_GUI_DataObject_Mesh* dataObjectMED = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFile); + MULTIPR_GUI_DataObject_Mesh* dataObjectMED = + new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFileName.c_str()); // MESH object MULTIPR_ORB::string_array* listParts = obj->getParts(); diff --git a/src/MULTIPRGUI/MULTIPR_GUI.h b/src/MULTIPRGUI/MULTIPR_GUI.h index d87e8a7..e3ff9b6 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.h +++ b/src/MULTIPRGUI/MULTIPR_GUI.h @@ -21,7 +21,8 @@ #include #include -#include +//#include +#include #include #include CORBA_CLIENT_HEADER(MULTIPR) @@ -224,7 +225,8 @@ public: // Class MULTIPR_GUI_DataModel //***************************************************************************** -class MULTIPR_GUI_DataModel : public LightApp_DataModel +//class MULTIPR_GUI_DataModel : public LightApp_DataModel +class MULTIPR_GUI_DataModel : public SalomeApp_DataModel { public: -- 2.39.2