{
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());
}
}
}
+//-----------------------------------------------------------------------------
+// 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)
//-----------------------------------------------------------------------------
{
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 <tmpDir> 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();
{
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 =
// 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)
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();
//*****************************************************************************
// 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<SalomeApp_Study*>(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
// 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