From: jfa Date: Mon, 2 Jul 2007 13:15:35 +0000 (+0000) Subject: Dump python task implemented. X-Git-Tag: T_MULTIPR_INDUS_Dump_python X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b9ac953eec7bd7d69a8ac339e22c643f87ea17a9;p=modules%2Fmultipr.git Dump python task implemented. --- diff --git a/idl/MULTIPR.idl b/idl/MULTIPR.idl index 94c1d78..d571fd8 100644 --- a/idl/MULTIPR.idl +++ b/idl/MULTIPR.idl @@ -255,6 +255,21 @@ interface MULTIPR_Gen : Engines::Component, SALOMEDS::Driver MULTIPR_Obj getObject(in string medFilename) raises (SALOME::SALOME_Exception); + //------------------------------------------------------------------------ + // Engine API + // Methods to correctly serve Persistence and Dump Python. + //------------------------------------------------------------------------ + + /*! + * Set the current study + */ + void SetCurrentStudy (in SALOMEDS::Study theStudy); + + /*! + * Get the current study + */ + SALOMEDS::Study GetCurrentStudy(); + }; // interface MULTIPR_Gen diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index bdb3540..05318b7 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -88,14 +88,13 @@ namespace MULTIPR { if (--myCounter == 0) { - //SALOMEDS::Study_ptr aStudy = aMULTIPRGen->GetCurrentStudy(); - //if (!aStudy->_is_nil()) - { - std::string aString = myStream.str(); - //myEngine->AddToPythonScript(aStudy->StudyId(), aCollection); - myEngine->AddToPythonScript(1, aString); - if(MYDEBUG) MESSAGE(" *DP* " << aString.c_str()); - } + SALOMEDS::Study_ptr aStudy = myEngine->GetCurrentStudy(); + int aStudyID = -1; + if (!aStudy->_is_nil()) aStudyID = aStudy->StudyId(); + + std::string aString = myStream.str(); + myEngine->AddToPythonScript(aStudyID, aString); + //if(MYDEBUG) MESSAGE(" *DP* " << aString.c_str()); } } @@ -723,6 +722,44 @@ void MULTIPR_Obj_i::setEngine (MULTIPR_Gen_i* theEngine) } +//----------------------------------------------------------------------------- +// Set/Get current study (for Persistence & Dump Python) +//----------------------------------------------------------------------------- + +/*! Set current study + */ +void MULTIPR_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy) +{ + //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::SetCurrentStudy"); + + // theStudy or myCurrentStudy may be nil + if (!CORBA::is_nil(theStudy)) + { + if (CORBA::is_nil(myCurrentStudy)) + { + // move python trace of unknown study to the real study + int studyId = theStudy->StudyId(); + if (myPythonScripts.find(-1) != myPythonScripts.end()) + { + myPythonScripts[studyId].insert(myPythonScripts[studyId].begin(), // at + myPythonScripts[-1].begin(), // from + myPythonScripts[-1].end()); // to + myPythonScripts[-1].clear(); + } + } + } + + myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy); +} + +/*! Get current study + */ +SALOMEDS::Study_ptr MULTIPR_Gen_i::GetCurrentStudy() +{ + //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID()); + return SALOMEDS::Study::_duplicate(myCurrentStudy); +} + //----------------------------------------------------------------------------- // SALOMEDS::Driver methods (Persistence & Dump Python) //----------------------------------------------------------------------------- @@ -735,58 +772,87 @@ SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent, { INFOS( "MULTIPR_Gen_i::Save" ); - //if (myCurrentStudy->_is_nil() || - // theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId()) - // SetCurrentStudy(theComponent->GetStudy()); + if (myCurrentStudy->_is_nil() || + theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId()) + SetCurrentStudy(theComponent->GetStudy()); // Store study contents as a set of python commands - //SavePython(myCurrentStudy); + SavePython(myCurrentStudy); // Declare a byte stream SALOMEDS::TMPFile_var aStreamFile; - // Obtain a temporary dir - //TCollection_AsciiString tmpDir = - // isMultiFile ? TCollection_AsciiString((char*)theURL) : (char*)SALOMEDS_Tool::GetTmpDir().c_str(); + SALOMEDS::ChildIterator_ptr obj_it (myCurrentStudy->NewChildIterator(theComponent)); - // Create a sequence of files processed - SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames; - aFileSeq->length(2); + // TODO: iterate on all objects under theComponent + if (!obj_it->More()) + return aStreamFile._retn(); - //TCollection_AsciiString aStudyName; - //if (isMultiFile) - // aStudyName = ((char*)SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()).c_str()); + 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)) + return aStreamFile._retn(); - // Set names of temporary files - //TCollection_AsciiString filename = - // aStudyName + TCollection_AsciiString( "_MULTIPR.hdf" ); // for MULTIPR data itself - //TCollection_AsciiString meshfile = - // aStudyName + TCollection_AsciiString( "_MULTIPR_Mesh.med" ); // for MED data to be stored in MED file - - //aFileSeq[0] = CORBA::string_dup(filename.ToCString()); - //aFileSeq[1] = CORBA::string_dup(meshfile.ToCString()); - //filename = tmpDir + filename; - //meshfile = tmpDir + meshfile; - - //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 (obj->isValidSequentialMEDFile()) + { + // TODO + } + else if (obj->isValidDistributedMEDFile()) + { + /* + // Obtain a temporary dir + std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); + + // Create a sequence of files processed + SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames; + + std::string aStudyName; + if (isMultiFile) + aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()); + + // ?? create a new dir in for all parts of distributed file + // or it will be created automatically ?? + obj->save(tmpDir.c_str()); + + // TODO: set real length + aFileSeq->length(1); // nb.distributed files + 1 (_maitre.med) + + // 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); + } + else + { + // ?? + } INFOS("MULTIPR_Gen_i::Save() completed"); return aStreamFile._retn(); @@ -812,9 +878,9 @@ bool MULTIPR_Gen_i::Load (SALOMEDS::SComponent_ptr theComponent, { INFOS("MULTIPR_Gen_i::Load"); - //if (myCurrentStudy->_is_nil() || - // theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId()) - // SetCurrentStudy(theComponent->GetStudy()); + if (myCurrentStudy->_is_nil() || + theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId()) + SetCurrentStudy(theComponent->GetStudy()); // Get temporary files location //TCollection_AsciiString tmpDir = @@ -1003,6 +1069,7 @@ std::string MULTIPR_Gen_i::DumpPython_impl (int theStudyID, // aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)"; //else // aScript += helper + "\t" + aGen + ".SetCurrentStudy(None)"; + aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)\n"; // Dump trace of restored study if (theSavedTrace.length() > 0) @@ -1134,6 +1201,10 @@ SALOMEDS::SObject_ptr MULTIPR_Gen_i::PublishInStudy (SALOMEDS::Study_ptr theSt if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy"); + //if (myCurrentStudy->_is_nil() || theStudy->StudyId() != myCurrentStudy->StudyId()) + if (myCurrentStudy->_is_nil()) + SetCurrentStudy(theStudy); + SALOMEDS::SObject_var aSO; if (CORBA::is_nil(theStudy) || CORBA::is_nil(theIOR)) return aSO._retn(); diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index f97592f..9a18cd3 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -320,6 +320,14 @@ public: MULTIPR_ORB::MULTIPR_Obj_ptr getObject(const char* medFilename) throw (SALOME::SALOME_Exception); + // **************************************************** + // Set/Get current study for Persistence and Dump Python + // **************************************************** + + // Set current study + void SetCurrentStudy (SALOMEDS::Study_ptr theStudy); + // Get current study + SALOMEDS::Study_ptr GetCurrentStudy(); // **************************************************** // Interface inherited methods (from SALOMEDS::Driver) @@ -407,6 +415,8 @@ private: void SavePython (SALOMEDS::Study_ptr theStudy); private: + // Current study + SALOMEDS::Study_var myCurrentStudy; // Dump Python: trace of API methods calls std::map < int, std::vector > myPythonScripts; }; diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index 1c1e2c8..43e3ea7 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -86,27 +86,34 @@ namespace multipr //***************************************************************************** // singleton -MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen(const CAM_Module* theModule) +MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen (const CAM_Module* theModule) { static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL; - + if (!aGen) { - SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService()); + SALOME_LifeCycleCORBA aLCC (SalomeApp_Application::namingService()); Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer", "MULTIPR"); aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(aComponent); if (!CORBA::is_nil(aGen)) { - //aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule)))); + // Set current study + SalomeApp_Study* aSAStudy = + dynamic_cast(theModule->application()->activeStudy()); + _PTR(Study) aStudy = aSAStudy->studyDS(); + SALOMEDS::Study_ptr aStudyDS; + if (aStudy) + aStudyDS = _CAST(Study,aStudy)->GetStudy(); + aGen->SetCurrentStudy(aStudyDS); } } - + if (CORBA::is_nil(aGen)) throw std::runtime_error("Can't find MULTIPR component"); - + return aGen; } - + //***************************************************************************** // Class MULTIPR_GUI implementation @@ -1009,6 +1016,13 @@ void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy) // set Object to MULTIPR_GUI mMULTIPR_GUI->setMULTIPRObj(obj); } + //CORBA::Object_var anObj = aSObj->GetObject(); + //obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj); + //if (!CORBA::is_nil(obj)) + //{ + // // set Object to MULTIPR_GUI + // mMULTIPR_GUI->setMULTIPRObj(obj); + //} } // remove Data Objects, automatically built for not loaded MULTIPR module