From: jfa Date: Fri, 29 Jun 2007 11:56:47 +0000 (+0000) Subject: Start Persistence and DumpPython for MULTIPR. X-Git-Tag: T_MULTIPR_INDUS_Dump_python~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3570cdd7e297bb0a8301187de84957518ebf8131;p=modules%2Fmultipr.git Start Persistence and DumpPython for MULTIPR. --- diff --git a/idl/MULTIPR.idl b/idl/MULTIPR.idl index 6c54f48..94c1d78 100644 --- a/idl/MULTIPR.idl +++ b/idl/MULTIPR.idl @@ -57,13 +57,13 @@ interface MULTIPR_Obj */ string getFilename() raises (SALOME::SALOME_Exception); - - /*! - * Return the name of the associated sequential MED file (for a distributed MED file). - */ - string getSeqFilename() - raises (SALOME::SALOME_Exception); - + + /*! + * Return the name of the associated sequential MED file (for a distributed MED file). + */ + string getSeqFilename() + raises (SALOME::SALOME_Exception); + /*! * Set the mesh to be partitionned/decimated. * Assume sequential MED file. @@ -114,7 +114,8 @@ interface MULTIPR_Obj //-------------------------------------------------------------------- /*! - * Create a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file. + * Create a distributed MED file (v2.3) by extracting all the groups + * from the current mesh of the current MED sequential MED file. * Assume: * - the file is in MED format and can be read using MED file v2.3. * - the file is sequential (not a distributed MED). @@ -126,7 +127,8 @@ interface MULTIPR_Obj raises (SALOME::SALOME_Exception); /*! - * Create a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. + * Create a distributed MED file (V2.3) by splitting a group + * of a MED file previously created by partitionneDomaine. * Assume: * - the file is a distributed MED file, previously created by partitionneDomaine() * (=> each part only contain 1 mesh, TETRA10 elements only) @@ -193,14 +195,14 @@ interface MULTIPR_Obj // Interface of the %MULTIPR component; used to create MULTIPR_Obj object // and to define high level API. //************************************************************************* -interface MULTIPR_Gen : Engines::Component +interface MULTIPR_Gen : Engines::Component, SALOMEDS::Driver { /*! * Return the version of the MULTIPR library. */ string getVersion() raises (SALOME::SALOME_Exception); - + //------------------------------------------------------------------------ // High level API // Directly apply one of the 3 main operations of the MULTIPR module on a MED file diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index 126f14a..bdb3540 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -19,13 +19,166 @@ using namespace std; #include "MULTIPR_i.hxx" + #include "utilities.h" #include +#include #include "MULTIPR_API.hxx" #include "MULTIPR_Exceptions.hxx" +#include + +#include CORBA_CLIENT_HEADER(SALOMEDS) +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +// Dump Python utilities +namespace MULTIPR +{ + class TPythonDump + { + std::ostringstream myStream; + static size_t myCounter; + //MULTIPR_ORB::MULTIPR_Gen_ptr myEngine; + MULTIPR_Gen_i* myEngine; + + public: + //TPythonDump (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine); + TPythonDump (MULTIPR_Gen_i* theEngine); + virtual ~TPythonDump(); + + TPythonDump& operator<< (long int theArg); + TPythonDump& operator<< (int theArg); + TPythonDump& operator<< (double theArg); + TPythonDump& operator<< (float theArg); + TPythonDump& operator<< (const void* theArg); + TPythonDump& operator<< (const char* theArg); + + TPythonDump& operator<< (SALOMEDS::SObject_ptr theArg); + TPythonDump& operator<< (CORBA::Object_ptr theArg); + + TPythonDump& operator<< (MULTIPR_ORB::MULTIPR_Gen_ptr theArg); + TPythonDump& operator<< (MULTIPR_ORB::MULTIPR_Obj_ptr theArg); + + TPythonDump& operator<< (MULTIPR_Gen_i* theArg); + TPythonDump& operator<< (MULTIPR_Obj_i* theArg); + + static char* MULTIPRGenName() { return "mpr_gen"; } + static char* MULTIPRObjName() { return "mpr_obj"; } + }; + + size_t TPythonDump::myCounter = 0; + + //TPythonDump::TPythonDump (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine) + TPythonDump::TPythonDump (MULTIPR_Gen_i* theEngine) + { + ++myCounter; + //myEngine = MULTIPR_ORB::MULTIPR_Gen::_duplicate(theEngine); + myEngine = theEngine; + } + + TPythonDump::~TPythonDump() + { + 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()); + } + } + } + + TPythonDump& TPythonDump::operator<< (long int theArg) + { + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (int theArg) + { + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (double theArg) + { + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (float theArg) + { + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (const void* theArg) + { + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (const char* theArg) + { + if (theArg) + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (SALOMEDS::SObject_ptr aSObject) + { + if (aSObject->_is_nil()) + myStream << "None"; + else + myStream << "theStudy.FindObjectID(\"" << aSObject->GetID() << "\")"; + return *this; + } + + TPythonDump& TPythonDump::operator<< (CORBA::Object_ptr theArg) + { + if (CORBA::is_nil(theArg)) + myStream << "None"; + else + myStream << theArg; + return *this; + } + + TPythonDump& TPythonDump::operator<< (MULTIPR_ORB::MULTIPR_Gen_ptr theArg) + { + myStream << MULTIPRGenName(); + return *this; + } + + TPythonDump& TPythonDump::operator<< (MULTIPR_ORB::MULTIPR_Obj_ptr theArg) + { + myStream << MULTIPRObjName(); + return *this; + } + + TPythonDump& TPythonDump::operator<< (MULTIPR_Gen_i* theArg) + { + myStream << MULTIPRGenName(); + return *this; + } + + TPythonDump& TPythonDump::operator<< (MULTIPR_Obj_i* theArg) + { + myStream << MULTIPRObjName(); + return *this; + } +} + //***************************************************************************** // Class MULTIPR_Gen_i implementation @@ -152,15 +305,23 @@ void MULTIPR_Gen_i::decimePartition( // Low level API //----------------------------------------------------------------------------- -MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_Gen_i::getObject(const char* medFilename) +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); - return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this(); + 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) +MULTIPR_Obj_i::MULTIPR_Obj_i (const char* medFilename) throw (SALOME::SALOME_Exception) { mObj = new multipr::Obj(); @@ -229,32 +390,40 @@ char* MULTIPR_Obj_i::getSeqFilename() } -void MULTIPR_Obj_i::setMesh(const char* meshName) +void MULTIPR_Obj_i::setMesh (const char* meshName) throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - try - { - mObj->setMesh(meshName); - - cout << "Set mesh OK" << endl << endl; - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR); - } + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + mObj->setMesh(meshName); + + // Dump Python + MULTIPR::TPythonDump(_engine) << this << ".setMesh(\"" << meshName << "\")"; + + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::setMesh - OK"); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR); + } } -void MULTIPR_Obj_i::setBoxing(CORBA::Long pBoxing) +void MULTIPR_Obj_i::setBoxing (CORBA::Long pBoxing) throw (SALOME::SALOME_Exception) { - if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR); - if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR); - - mBoxing = pBoxing; + if (mBoxing < 0) + THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR); + if (mBoxing > 200) + THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR); + + mBoxing = pBoxing; + + // Dump Python + MULTIPR::TPythonDump(_engine) << this << ".setBoxing(" << pBoxing << ")"; } @@ -368,27 +537,30 @@ char* MULTIPR_Obj_i::getPartInfo(const char* pPartName) MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine() throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->partitionneDomaine(); - mySeq->length(listParts.size()); - - for (size_t i = 0 ; i < listParts.size() ; i++) - { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); - } - } - catch (multipr::RuntimeException& e) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->partitionneDomaine(); + mySeq->length(listParts.size()); + + for (size_t i = 0 ; i < listParts.size() ; i++) { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - - return mySeq._retn(); + + // Dump Python + MULTIPR::TPythonDump(_engine) << "parts = " << this << ".partitionneDomaine()"; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR); + } + + return mySeq._retn(); } @@ -398,31 +570,34 @@ MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneGrain( CORBA::Long pPartitionner) throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->partitionneGrain( - pPartName, - pNbParts, - pPartitionner); - - mySeq->length(listParts.size()); - - for (size_t i = 0 ; i < listParts.size() ; i++) - { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); - } - } - catch (multipr::RuntimeException& e) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->partitionneGrain(pPartName, + pNbParts, + pPartitionner); + + mySeq->length(listParts.size()); + + for (size_t i = 0 ; i < listParts.size() ; i++) { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to partition group", SALOME::INTERNAL_ERROR); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - - return mySeq._retn(); + + // Dump Python + MULTIPR::TPythonDump(_engine) << "new_parts = " << this << ".partitionneGrain(\"" + << pPartName << "\", " << pNbParts << ", " << pPartitionner << ")"; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to partition group", SALOME::INTERNAL_ERROR); + } + + return mySeq._retn(); } @@ -436,36 +611,41 @@ MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition( CORBA::Double pRadius) throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->decimePartition( - pPartName, - pFieldName, - pFieldIt, - pFilterName, - pTmed, - pTlow, - pRadius, - mBoxing); - - mySeq->length(listParts.size()); - - for (size_t i = 0 ; i < listParts.size() ; i++) - { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); - } - } - catch (multipr::RuntimeException& e) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->decimePartition(pPartName, + pFieldName, + pFieldIt, + pFilterName, + pTmed, + pTlow, + pRadius, + mBoxing); + + mySeq->length(listParts.size()); + + for (size_t i = 0 ; i < listParts.size() ; i++) { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - - return mySeq._retn(); + + // Dump Python + MULTIPR::TPythonDump(_engine) << "parts = " << this << ".decimePartition(\"" + << pPartName << "\", \"" << pFieldName << "\", " + << pFieldIt << ", \"" << pFilterName << "\", " + << pTmed << ", " << pTlow << ", " << pRadius << ")"; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR); + } + + return mySeq._retn(); } @@ -478,7 +658,7 @@ char* MULTIPR_Obj_i::evalDecimationParams( throw (SALOME::SALOME_Exception) { if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - + try { string res = mObj->evalDecimationParams( @@ -487,9 +667,13 @@ char* MULTIPR_Obj_i::evalDecimationParams( pFieldIt, pFilterName, pFilterParams); - + + // Dump Python + MULTIPR::TPythonDump(_engine) << "dec_params = " << this << ".evalDecimationParams(\"" + << pPartName << "\", \"" << pFieldName << "\", " << pFieldIt << ", \"" + << pFilterName << "\", \"" << pFilterParams << "\") # " << res.c_str(); + return CORBA::string_dup(res.c_str()); - } catch (multipr::RuntimeException& e) { @@ -499,12 +683,15 @@ char* MULTIPR_Obj_i::evalDecimationParams( } -void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName) +void MULTIPR_Obj_i::removeParts (const char* pPrefixPartName) throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - mObj->removeParts(pPrefixPartName); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + mObj->removeParts(pPrefixPartName); + + // Dump Python + MULTIPR::TPythonDump(_engine) << this << ".removeParts(\"" << pPrefixPartName << "\")"; } @@ -512,27 +699,557 @@ 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); - + try { mObj->save(pPath); - } 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 << "\")"; +} + + +//void MULTIPR_Obj_i::setEngine (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine) +void MULTIPR_Obj_i::setEngine (MULTIPR_Gen_i* theEngine) +{ + //_engine = MULTIPR_ORB::MULTIPR_Gen::_duplicate(theEngine); + _engine = theEngine; } +//----------------------------------------------------------------------------- +// SALOMEDS::Driver methods (Persistence & Dump Python) +//----------------------------------------------------------------------------- + +/*! Save MULTIPR module's data + */ +SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) +{ + INFOS( "MULTIPR_Gen_i::Save" ); + + //if (myCurrentStudy->_is_nil() || + // theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId()) + // SetCurrentStudy(theComponent->GetStudy()); + + // Store study contents as a set of python commands + //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(); + + // Create a sequence of files processed + SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames; + aFileSeq->length(2); + + //TCollection_AsciiString aStudyName; + //if (isMultiFile) + // aStudyName = ((char*)SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()).c_str()); + + // 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); + + INFOS("MULTIPR_Gen_i::Save() completed"); + return aStreamFile._retn(); +} + +/*! Save MULTIPR module's data in ASCII format + */ +SALOMEDS::TMPFile* MULTIPR_Gen_i::SaveASCII (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) +{ + if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::SaveASCII" ); + SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile); + return aStreamFile._retn(); +} + +/*! Load MULTIPR module's data + */ +bool MULTIPR_Gen_i::Load (SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) +{ + INFOS("MULTIPR_Gen_i::Load"); + + //if (myCurrentStudy->_is_nil() || + // theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId()) + // SetCurrentStudy(theComponent->GetStudy()); + + // Get temporary files location + //TCollection_AsciiString tmpDir = + // isMultiFile ? TCollection_AsciiString((char*)theURL) : (char*)SALOMEDS_Tool::GetTmpDir().c_str(); + + INFOS("THE URL++++++++++++++"); + INFOS(theURL); + //INFOS("THE TMP PATH+++++++++"); + //INFOS(tmpDir); + + // Convert the stream into sequence of files to process + //SALOMEDS::ListOfFileNames_var aFileSeq = + // SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.ToCString(), isMultiFile); + + //TCollection_AsciiString aStudyName; + //if (isMultiFile) + // aStudyName = ((char*)SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()).c_str()); + + // Set names of "temporary" files + //TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_MULTIPR.hdf" ); + //TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_MULTIPR_Mesh.med" ); + + // Remove temporary files created from the stream + //if (!isMultiFile) + // SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true ); + + INFOS("MULTIPR_Gen_i::Load completed"); + return true; +} + +/*! Load MULTIPR module's data in ASCII format + */ +bool MULTIPR_Gen_i::LoadASCII (SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) +{ + if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::LoadASCII" ); + 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 /*isASCII*/ ) +{ + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID"); + + MULTIPR_ORB::MULTIPR_Obj_ptr anObject = + MULTIPR_ORB::MULTIPR_Obj::_narrow(_orb->string_to_object(IORString)); + + if (!CORBA::is_nil(anObject)) + { + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID: id = " << anObject->getFilename()); + return CORBA::string_dup(anObject->getFilename()); + } + return CORBA::string_dup(""); +} + +/*! Transform data from persistent form to transient + */ +char* MULTIPR_Gen_i::LocalPersistentIDToIOR (SALOMEDS::SObject_ptr /*theSObject*/, + const char* aLocalPersistentID, + 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()); + + CORBA::String_var anIORString = _orb->object_to_string(anObj); + return CORBA::string_dup(anIORString); + } + return CORBA::string_dup( "" ); +} + +/*! Transform data from persistent form to transient + */ +Engines::TMPFile* MULTIPR_Gen_i::DumpPython (CORBA::Object_ptr theStudy, + CORBA::Boolean isPublished, + CORBA::Boolean& isValidScript) +{ + isValidScript = false; + + SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy); + if (CORBA::is_nil(aStudy)) + return new Engines::TMPFile(0); + + /* + SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType()); + if (CORBA::is_nil(aSO)) + return new Engines::TMPFile(0); + + // Map study entries to object names + Resource_DataMapOfAsciiStringAsciiString aMap; + Resource_DataMapOfAsciiStringAsciiString aMapNames; + + SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO); + for (Itr->InitEx(true); Itr->More(); Itr->Next()) { + SALOMEDS::SObject_var aValue = Itr->Value(); + CORBA::String_var anID = aValue->GetID(); + CORBA::String_var aName = aValue->GetName(); + TCollection_AsciiString aGUIName ( (char*) aName.in() ); + TCollection_AsciiString anEnrty ( (char*) anID.in() ); + if (aGUIName.Length() > 0) { + aMapNames.Bind( anEnrty, aGUIName ); + aMap.Bind( anEnrty, aGUIName ); + } + } + //*/ + + // Get trace of restored study + SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType()); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr = + aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject"); + + char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject(); + std::string aSavedTrace (oldValue); + + // Add trace of API methods calls and replace study entries by names + std::string aScript = + "### This file is generated by SALOME automatically " + "by dump python functionality of MULTIPR component\n\n"; + aScript += DumpPython_impl(aStudy->StudyId(), isPublished, isValidScript, aSavedTrace); + + int aLen = aScript.length(); + unsigned char* aBuffer = new unsigned char[aLen+1]; + strcpy((char*)aBuffer, aScript.c_str()); + + CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; + Engines::TMPFile_var aStreamFile = new Engines::TMPFile (aLen+1, aLen+1, anOctetBuf, 1); + + //bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen); + //isValidScript = isValidScript && !hasNotPublishedObjects; + + return aStreamFile._retn(); +} + +/*! DumpPython_impl + */ +std::string MULTIPR_Gen_i::DumpPython_impl (int theStudyID, + bool isPublished, + bool& aValidScript, + std::string theSavedTrace) +{ + std::string helper; + std::string aGen = MULTIPR::TPythonDump::MULTIPRGenName(); + + // set initial part of a script + std::string aScript ("import salome, SMESH\n"); + aScript += "import MULTIPR_ORB\n\n"; + aScript += "def RebuildData(theStudy):\n"; + + aScript += helper + "\tmpr_comp = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"" + + ComponentDataType() + "\")\n"; + aScript += helper + "\t" + aGen + " = mpr_comp._narrow(MULTIPR_ORB.MULTIPR_Gen)\n"; + + //if ( isPublished ) + // aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)"; + //else + // aScript += helper + "\t" + aGen + ".SetCurrentStudy(None)"; + + // Dump trace of restored study + if (theSavedTrace.length() > 0) + { + aScript += helper + "\n" + theSavedTrace; + } + + // Dump trace of API methods calls + std::string aNewLines = GetNewPythonLines(theStudyID); + if (aNewLines.length() > 0) + { + aScript += helper + "\n" + aNewLines; + } + + // add final part of a script + //aScript += helper + "\n\tisGUIMode = " + isPublished; + //aScript += "\n\tif isGUIMode and salome.sg.hasDesktop():"; + //aScript += "\n\t\tsalome.sg.updateObjBrowser(0)"; + aScript += "\n\n\tpass\n"; + + aValidScript = true; + + return aScript; +} + +/*! GetNewPythonLines + */ +std::string MULTIPR_Gen_i::GetNewPythonLines (int theStudyID) +{ + std::string aScript; + + // Dump trace of API methods calls + if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) + { + std::vector aPythonScript = myPythonScripts[theStudyID]; + int istr, aLen = aPythonScript.size(); + for (istr = 0; istr < aLen; istr++) + { + aScript += "\n\t"; + aScript += aPythonScript[istr]; + } + aScript += "\n"; + } + + return aScript; +} + +/*! CleanPythonTrace + */ +void MULTIPR_Gen_i::CleanPythonTrace (int theStudyID) +{ + // Clean trace of API methods calls + if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) + { + myPythonScripts[theStudyID].clear(); + } +} + +/*! AddToPythonScript + */ +void MULTIPR_Gen_i::AddToPythonScript (int theStudyID, std::string theString) +{ + //if (myPythonScripts.find(theStudyID) == myPythonScripts.end()) + //{ + // myPythonScripts[theStudyID] = std::vector; + //} + myPythonScripts[theStudyID].push_back(theString); +} + +/*! SavePython + */ +void MULTIPR_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy) +{ + // Dump trace of API methods calls + std::string aScript = GetNewPythonLines(theStudy->StudyId()); + + // Check contents of PythonObject attribute + SALOMEDS::SObject_var aSO = theStudy->FindComponent(ComponentDataType()); + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr = + aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject"); + + char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject(); + std::string oldScript (oldValue); + + if (oldScript.length() > 0) { + oldScript += "\n"; + oldScript += aScript; + } + else { + oldScript = aScript; + } + + // Store in PythonObject attribute + SALOMEDS::AttributePythonObject::_narrow(anAttr)->SetObject(oldScript.c_str(), 1); + + // Clean trace of API methods calls + CleanPythonTrace(theStudy->StudyId()); +} + + +/*! Returns true if object can be published in the study + */ +bool MULTIPR_Gen_i::CanPublishInStudy (CORBA::Object_ptr theIOR) +{ + //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy - " << !CORBA::is_nil(myCurrentStudy)); + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy"); + + //if (CORBA::is_nil(myCurrentStudy)) + // return false; + + MULTIPR_ORB::MULTIPR_Obj_var anObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(theIOR); + if (!anObj->_is_nil()) + return true; + + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy - CANNOT"); + return false; +} + +/*! Publish object in the study + */ +SALOMEDS::SObject_ptr MULTIPR_Gen_i::PublishInStudy (SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theIOR, + const char* theName) + throw (SALOME::SALOME_Exception) +{ + //Unexpect aCatch(SALOME_SalomeException); + + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy"); + + SALOMEDS::SObject_var aSO; + if (CORBA::is_nil(theStudy) || CORBA::is_nil(theIOR)) + return aSO._retn(); + + // Publishing a MULTIPR_Object + MULTIPR_ORB::MULTIPR_Obj_var anObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(theIOR); + if (!anObj->_is_nil()) + { + //aSO = ObjectToSObject(theStudy, anObj); + if (aSO->_is_nil()) + { + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + + SALOMEDS::SComponent_var aFather = theStudy->FindComponent(ComponentDataType()); + if (aFather->_is_nil()) + { + aFather = aStudyBuilder->NewComponent(ComponentDataType()); + anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue("MULTI-PR"); + //anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap"); + //SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_MULTIPR"); + //aStudyBuilder->DefineComponentInstance(aFather, MULTIPR_ORB::MULTIPR_Gen::_this()); + aStudyBuilder->DefineComponentInstance(aFather, MULTIPR_Gen::_this()); + } + if (aFather->_is_nil()) return aSO._retn(); + + if (CORBA::is_nil(theSObject)) + { + aSO = aStudyBuilder->NewObject(aFather); + } + else + { + if (!theSObject->ReferencedObject(aSO)) + aSO = SALOMEDS::SObject::_duplicate(theSObject); + } + + anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeIOR"); + SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var anIOR = _orb->object_to_string(anObj); + anIORAttr->SetValue(anIOR); + + //anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap"); + //SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); + //aPixmap->SetPixMap("ICON_OBJBROWSER_GROUP_PNT"); + + anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeName"); + SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr); + if (strlen(theName) == 0) + aNameAttrib->SetValue(anObj->getFilename()); + else + aNameAttrib->SetValue(theName); + + // Dump Python + MULTIPR::TPythonDump(this) << "sobj = " << this << ".PublishInStudy(theStudy, " + << theSObject << ", " << anObj << ", \"" << theName + << "\") # " << aSO->GetID(); + } + } + + if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy - END"); + + return aSO._retn(); +} + +/* +SALOMEDS::SComponent_ptr _Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy) +{ + if ( CORBA::is_nil( theStudy )) + return SALOMEDS::SComponent::_nil(); + if(MYDEBUG) MESSAGE("PublishComponent"); + + SALOMEDS::SComponent_var father = + SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) ); + if ( !CORBA::is_nil( father ) ) + return father._retn(); + + SALOME_ModuleCatalog::ModuleCatalog_var aCat = + SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") ); + if ( CORBA::is_nil( aCat ) ) + return father._retn(); + + SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() ); + if ( CORBA::is_nil( aComp ) ) + return father._retn(); + + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributePixMap_var aPixmap; + + father = aStudyBuilder->NewComponent( ComponentDataType() ); + aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() ); + anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" ); + aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); + aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" ); + SetName( father, aComp->componentusername(), "MESH" ); + if(MYDEBUG) MESSAGE("PublishComponent--END"); + + return father._retn(); +} +//*/ + + +/*! + * MULTIPREngine_factory + * + * C factory, accessible with dlsym, after dlopen + */ extern "C" { PortableServer::ObjectId* MULTIPREngine_factory( CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, + PortableServer::POA_ptr poa, PortableServer::ObjectId * contId, - const char* instanceName, + const char* instanceName, const char* interfaceName) { MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()"); diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index 23f567a..f97592f 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -7,15 +7,15 @@ * \brief C++ implementation of the CORBA interface of the MULTIPR module. * * \author Olivier LE ROUX - CS, Virtual Reality Dpt - * + * * \date 01/2007 */ - + //***************************************************************************** // Includes section //***************************************************************************** - + #ifndef __MULTIPR_IMPLEMENTATION_CORBA__ #define __MULTIPR_IMPLEMENTATION_CORBA__ @@ -26,6 +26,11 @@ #include "MULTIPR_Obj.hxx" +#include +#include +#include + +class MULTIPR_Gen_i; //***************************************************************************** // Class MULTIPR_Obj_i @@ -80,7 +85,7 @@ public: /** * Returns the name of the associated sequential MED file (for a distributed MED file). * \return the name of the associated sequential MED file (for a distributed MED file). - */ + */ char* getSeqFilename() throw (SALOME::SALOME_Exception); /** @@ -102,7 +107,7 @@ public: * Assumes this object encapsulates a sequential MED file. * \return the list of meshes contained in the sequential MED file. */ - MULTIPR_ORB::string_array* getMeshes() + MULTIPR_ORB::string_array* getMeshes() throw (SALOME::SALOME_Exception); /** @@ -110,7 +115,7 @@ public: * Assumes this object encapsulates a sequential MED file. * \return the list of fields contained in the sequential MED file. */ - MULTIPR_ORB::string_array* getFields() + MULTIPR_ORB::string_array* getFields() throw (SALOME::SALOME_Exception); /** @@ -155,7 +160,7 @@ public: MULTIPR_ORB::string_array* partitionneDomaine() throw (SALOME::SALOME_Exception); - /** + /** * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. * Assumes: * - the file is a distributed MED file, previously created by partitionneDomaine() @@ -167,8 +172,8 @@ public: * \return the name of each part. */ MULTIPR_ORB::string_array* partitionneGrain( - const char* pPartName, - CORBA::Long pNbParts, + const char* pPartName, + CORBA::Long pNbParts, CORBA::Long pPartitionner) throw (SALOME::SALOME_Exception); @@ -206,9 +211,9 @@ public: * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). */ char* evalDecimationParams( - const char* pPartName, - const char* pFieldName, - CORBA::Long pFieldIt, + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, const char* pFilterName, const char* pFilterParams) throw (SALOME::SALOME_Exception); @@ -233,6 +238,16 @@ public: void save(const char* pPath) throw (SALOME::SALOME_Exception); + //--------------------------------------------------------------------- + // Persistence and Dump Python + //--------------------------------------------------------------------- + + /** + * Set Engine. + */ + //void setEngine (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine); + void setEngine (MULTIPR_Gen_i* theEngine); + private: /** @@ -247,6 +262,11 @@ private: */ int mBoxing; + /** + * Engine. + */ + //MULTIPR_ORB::MULTIPR_Gen_ptr _engine; + MULTIPR_Gen_i* _engine; }; @@ -257,16 +277,15 @@ private: class MULTIPR_Gen_i : public POA_MULTIPR_ORB::MULTIPR_Gen, - public Engines_Component_i + public Engines_Component_i { - public: MULTIPR_Gen_i( CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - PortableServer::ObjectId* contId, - const char* instanceName, + PortableServer::ObjectId* contId, + const char* instanceName, const char* interfaceName); virtual ~MULTIPR_Gen_i(); @@ -275,20 +294,20 @@ public: throw (SALOME::SALOME_Exception); void partitionneDomaine( - const char* medFilename, + const char* medFilename, const char* meshName) throw (SALOME::SALOME_Exception); void partitionneGrain( - const char* medFilename, - const char* partName, - CORBA::Long nbParts, + const char* medFilename, + const char* partName, + CORBA::Long nbParts, CORBA::Long partitionner) throw (SALOME::SALOME_Exception); void decimePartition( - const char* medFilename, - const char* partName, + const char* medFilename, + const char* partName, const char* fieldName, CORBA::Long fieldIt, const char* filterName, @@ -300,6 +319,96 @@ public: MULTIPR_ORB::MULTIPR_Obj_ptr getObject(const char* medFilename) throw (SALOME::SALOME_Exception); + + + // **************************************************** + // Interface inherited methods (from SALOMEDS::Driver) + // **************************************************** + + // Save SMESH data + SALOMEDS::TMPFile* Save (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + // Load SMESH data + bool Load (SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile); + + // Save SMESH data in ASCII format + SALOMEDS::TMPFile* SaveASCII (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + // Load SMESH data in ASCII format + bool LoadASCII (SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile); + + // Clears study-connected data when it is closed + void Close (SALOMEDS::SComponent_ptr theComponent); + + // Get component data type + char* ComponentDataType(); + + // Transform data from transient form to persistent + char* IORToLocalPersistentID (SALOMEDS::SObject_ptr theSObject, + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + // Transform data from persistent form to transient + char* LocalPersistentIDToIOR (SALOMEDS::SObject_ptr theSObject, + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + + // Returns true if object can be published in the study + bool CanPublishInStudy (CORBA::Object_ptr theIOR); + // Publish object in the study + SALOMEDS::SObject_ptr PublishInStudy (SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) + throw (SALOME::SALOME_Exception); + + // Copy-paste methods - returns true if object can be copied to the clipboard + CORBA::Boolean CanCopy (SALOMEDS::SObject_ptr theObject) { return false; } + // Copy-paste methods - copy object to the clipboard + SALOMEDS::TMPFile* CopyFrom (SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) { return false; } + // Copy-paste methods - returns true if object can be pasted from the clipboard + CORBA::Boolean CanPaste (const char* theComponentName, CORBA::Long theObjectID) { return false; } + // Copy-paste methods - paste object from the clipboard + SALOMEDS::SObject_ptr PasteInto (const SALOMEDS::TMPFile& theStream, + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject) + { + SALOMEDS::SObject_var aResultSO; + return aResultSO._retn(); + } + + // ============ + // Dump python + // ============ + + virtual Engines::TMPFile* DumpPython (CORBA::Object_ptr theStudy, + CORBA::Boolean isPublished, + CORBA::Boolean& isValidScript); + + void AddToPythonScript (int theStudyID, std::string theString); + +private: + std::string DumpPython_impl (int theStudyID, + bool isPublished, + bool& aValidScript, + std::string theSavedTrace); + + std::string GetNewPythonLines (int theStudyID); + void CleanPythonTrace (int theStudyID); + void SavePython (SALOMEDS::Study_ptr theStudy); + +private: + // Dump Python: trace of API methods calls + std::map < int, std::vector > myPythonScripts; }; @@ -313,4 +422,3 @@ extern "C" PortableServer::ObjectId* MULTIPREngine_factory( #endif // __MULTIPR_IMPLEMENTATION_CORBA__ // EOF - diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index d74519e..1c1e2c8 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -21,21 +21,25 @@ #include "MULTIPR_Utils.hxx" // Salome Includes -#include -#include -#include #include #include #include #include + #include #include #include #include + #include #include +#include +#include +#include + #include +#include #include @@ -129,6 +133,11 @@ MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj() return mMULTIPRObj; } +void MULTIPR_GUI::setMULTIPRObj (MULTIPR_ORB::MULTIPR_Obj_ptr theObj) +{ + mMULTIPRObj = MULTIPR_ORB::MULTIPR_Obj::_duplicate(theObj); +} + SalomeApp_Application* MULTIPR_GUI::getAppli() const { @@ -362,23 +371,30 @@ void MULTIPR_GUI::OnImportFromMEDFile() QApplication::setOverrideCursor(Qt::waitCursor); + MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this); + try { - MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this); - mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1()); + mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1()); } catch(...) { - SUIT_MessageBox::error1( - getApp()->desktop(), - "Import MED file error", - "Invalid MED file (not recognized by MULTIPR)", - tr("MULTIPR_BUT_OK") ); + SUIT_MessageBox::error1( + getApp()->desktop(), + "Import MED file error", + "Invalid MED file (not recognized by MULTIPR)", + tr("MULTIPR_BUT_OK") ); } QApplication::restoreOverrideCursor(); if (mMULTIPRObj != NULL) { + SALOMEDS::SObject_ptr aSObject = SALOMEDS::SObject::_nil(); + SalomeApp_Study* aSAStudy = dynamic_cast(getApp()->activeStudy()); + _PTR(Study) aStudyDSClient = aSAStudy->studyDS(); + SALOMEDS::Study_ptr aStudyDS = _CAST(Study,aStudyDSClient)->GetStudy(); + multiprgen->PublishInStudy(aStudyDS, aSObject, mMULTIPRObj, "Mesh"); + try { if (mMULTIPRObj->isValidSequentialMEDFile()) @@ -582,7 +598,7 @@ void MULTIPR_GUI::retrieveSelectedParts() { mSelectedParts.clear(); - QStringList userSelection; + QStringList userSelection; selected(userSelection, true); for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++) { @@ -911,98 +927,192 @@ QString MULTIPR_GUI_DataObject_Resolution::toolTip() const // Data Model //***************************************************************************** -MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) : - LightApp_DataModel(module) +MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) + : LightApp_DataModel(module) { mMULTIPR_GUI = dynamic_cast(module); } - MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel() { // do nothing! } +void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStudy) +{ + LightApp_ModuleObject* modelRoot = dynamic_cast( root() ); + DataObjectList ch; + QMap aMap; + if( modelRoot ) + { + ch = modelRoot->children(); + for ( DataObjectListIterator it( ch ); it.current(); ++it ) + it.current()->setParent( 0 ); + } + + buildAll(theStudy); + + modelRoot = dynamic_cast( root() ); + if( modelRoot ) + { + DataObjectList new_ch = modelRoot->children(); + for ( DataObjectListIterator it1( new_ch ); it1.current(); ++it1 ) + aMap.insert( it1.current(), 0 ); + } + + updateWidgets(); + + for( DataObjectListIterator it( ch ); it.current(); ++it ) + if( !aMap.contains( it.current() ) ) + delete it.current(); +} void MULTIPR_GUI_DataModel::build() { - try + cout << endl << " *** !!! MULTIPR_GUI_DataModel::build()" << endl << endl; +} + +void MULTIPR_GUI_DataModel::buildAll (LightApp_Study* theStudy) +{ + try + { + SalomeApp_Study* aSAStudy = dynamic_cast(theStudy); + if (!aSAStudy) + aSAStudy = dynamic_cast(getModule()->getApp()->activeStudy()); + + if (!aSAStudy) return; + + MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast(root()); + if (!modelRoot) + { + // root is not set yet + modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR"); + setRoot(modelRoot); + } + + // find SObject in Study + MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_nil(); + + _PTR(SComponent) aSComp = aSAStudy->studyDS()->FindComponent(module()->name()); + if (aSComp) { - MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast(root()); - - if (!modelRoot) - { - // root is not set yet - modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR"); - setRoot(modelRoot); + _PTR(ChildIterator) it (aSAStudy->studyDS()->NewChildIterator(aSComp)); + if (it->More()) + { + _PTR(SObject) aSObj = it->Value(); + string anIOR = aSObj->GetIOR(); + if (!anIOR.empty()) + { + CORBA::Object_var anObj = mMULTIPR_GUI->getApp()->orb()->string_to_object(anIOR.c_str()); + obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj); + + // set Object to MULTIPR_GUI + mMULTIPR_GUI->setMULTIPRObj(obj); } - - MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj(); - - if (obj != NULL) + } + + // remove Data Objects, automatically built for not loaded MULTIPR module + // by SalomeApp_Application::updateObjectBrowser + if (aSAStudy->root()) + { + DataObjectList ch_comp; + aSAStudy->root()->children(ch_comp); + DataObjectList::const_iterator anIt_comp = ch_comp.begin(), aLast_comp = ch_comp.end(); + for (; anIt_comp != aLast_comp; anIt_comp++) { - MULTIPR_ORB::string_array* listParts = obj->getParts(); - - if (listParts->length() >= 1) - { - const char* strPartName0 = (*listParts)[0]; - char* strPartInfo0 = obj->getPartInfo(strPartName0); - - char lMeshName[256]; - int lId; - char lPartName[256]; - char lPath[256]; - char lMEDFileName[256]; - - // parse infos - int ret = sscanf(strPartInfo0, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) - { - cout << "MULTIPR: build() tree; error while parsing part info" << endl; - std::runtime_error("MULTIPR: build() tree; error while parsing part info"); - return; - } - - MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName); - - MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL; - - for (int i = 0 ; i < listParts->length() ; i++) - { - const char* strItem = (*listParts)[i]; - char* strPartInfo = obj->getPartInfo(strItem); - - // parse infos - int ret = sscanf(strPartInfo, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) return; - - if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL)) - { - new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo); - } - else - { - dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo); - } - } - } + LightApp_DataObject* dobj = dynamic_cast(*anIt_comp); + if (dobj && dobj->name() == aSComp->GetName().c_str()) + { + //SalomeApp_DataModelSync sync (aSAStudy->studyDS(), aSAStudy->root()); + //sync.deleteItemWithChildren(dobj); + DataObjectList ch_obj; + dobj->children(ch_obj); + DataObjectList::const_iterator anIt_obj = ch_obj.begin(), aLast_obj = ch_obj.end(); + for (; anIt_obj != aLast_obj; anIt_obj++) + // delete data object of each SObject + delete (*anIt_obj); + + // delete data object of SComponent itself + delete dobj; + break; + } } + } } - catch (...) + + // build data tree + if (!CORBA::is_nil(obj)) { + // MED file object + const char* lMEDFile = obj->getFilename(); + //MULTIPR_GUI_DataObject_MED* dataObjectMED = new MULTIPR_GUI_DataObject_MED(modelRoot, lMEDFile); + MULTIPR_GUI_DataObject_Mesh* dataObjectMED = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMEDFile); + + // MESH object + MULTIPR_ORB::string_array* listParts = obj->getParts(); + + if (listParts->length() >= 1) + { + const char* strPartName0 = (*listParts)[0]; + char* strPartInfo0 = obj->getPartInfo(strPartName0); + + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; + + // parse infos + int ret = sscanf(strPartInfo0, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) + { + cout << "MULTIPR: build() tree; error while parsing part info" << endl; + std::runtime_error("MULTIPR: build() tree; error while parsing part info"); + return; + } + + MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = + new MULTIPR_GUI_DataObject_Mesh(dataObjectMED, lMeshName); + + // PART and RESOLUTION objects + MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL; + + for (int i = 0 ; i < listParts->length() ; i++) + { + const char* strItem = (*listParts)[i]; + char* strPartInfo = obj->getPartInfo(strItem); + + // parse infos + int ret = sscanf(strPartInfo, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) return; + + if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL)) + { + new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo); + } + else + { + dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo); + } + } + } } + } + catch (...) + { + } } diff --git a/src/MULTIPRGUI/MULTIPR_GUI.h b/src/MULTIPRGUI/MULTIPR_GUI.h index bab9f4a..d87e8a7 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.h +++ b/src/MULTIPRGUI/MULTIPR_GUI.h @@ -70,6 +70,7 @@ public: void windows(QMap&) const; MULTIPR_ORB::MULTIPR_Obj_ptr getMULTIPRObj(); + void setMULTIPRObj (MULTIPR_ORB::MULTIPR_Obj_ptr theObj); SalomeApp_Application* getAppli() const; @@ -230,10 +231,13 @@ public: MULTIPR_GUI_DataModel(CAM_Module*); virtual ~MULTIPR_GUI_DataModel(); + virtual void update (LightApp_DataObject* = 0, LightApp_Study* = 0); + protected: virtual void build(); - + void buildAll (LightApp_Study* = 0); + private: MULTIPR_GUI* mMULTIPR_GUI; diff --git a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx index 0e2667b..9dd4187 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx @@ -7,7 +7,7 @@ * \brief see MULTIPR_GUI_Dlg.h * * \author Olivier LE ROUX - CS, Virtual Reality Dpt -* +* * \date 01/2007 */ @@ -50,21 +50,20 @@ using namespace std; -MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) : - QDialog( - theModule->application()->desktop(), - 0, - false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) + : QDialog(theModule->application()->desktop(), + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { - mModule = theModule; - + mModule = theModule; + buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" ); buttonGroupProcess->setGeometry( QRect( 10, 110, 450, 60 ) ); pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" ); pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) ); - + pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" ); pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) ); @@ -83,17 +82,17 @@ MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) : textLabelSelectMesh = new QLabel( buttonGroupSelectMesh, "textLabelSelectMesh" ); textLabelSelectMesh->setGeometry( QRect( 20, 30, 110, 40 ) ); - + setCaption( tr( "Extract groups from sequential MED file" ) ); buttonGroupProcess->setTitle( QString::null ); pushButtonCancel->setText( tr( "Cancel" ) ); pushButtonOK->setText( tr("OK") ); buttonGroupSelectMesh->setTitle( tr( "Select mesh" ) ); textLabelSelectMesh->setText( tr( "Mesh name" ) ); - + resize( QSize(471, 185).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); - + connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); } @@ -111,7 +110,7 @@ MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg() void MULTIPR_GUI_Partition1Dlg::accept() { const char* meshName = comboBoxSelectMesh->currentText().latin1(); - + try { mModule->getMULTIPRObj()->setMesh(meshName); @@ -206,42 +205,40 @@ MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg() void MULTIPR_GUI_Partition2Dlg::accept() { - const char* strSplitter = comboBoxSelectSplitter->currentText().latin1(); - int nbParts = spinBoxNbParts->value(); - int partitionner = -1; - if (strcmp(strSplitter, "METIS") == 0) - { - partitionner = 0; - } - else if (strcmp(strSplitter, "SCOTCH") == 0) - { - partitionner = 1; - } - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - const QStringList& partsList = mModule->getSelectedParts(); - for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++) - { - const QString& partName = (*it); - //cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl; - mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner); - } - - } - catch(...) + const char* strSplitter = comboBoxSelectSplitter->currentText().latin1(); + int nbParts = spinBoxNbParts->value(); + int partitionner = -1; + if (strcmp(strSplitter, "METIS") == 0) + { + partitionner = 0; + } + else if (strcmp(strSplitter, "SCOTCH") == 0) + { + partitionner = 1; + } + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + const QStringList& partsList = mModule->getSelectedParts(); + for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++) { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Split error", - "Error while splitting selected part(s)", - tr("OK") ); + const QString& partName = (*it); + //cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl; + mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner); } - - QApplication::restoreOverrideCursor(); - QDialog::accept(); + } + catch(...) + { + SUIT_MessageBox::error1(mModule->getAppli()->desktop(), + "Split error", + "Error while splitting selected part(s)", + tr("OK")); + } + + QApplication::restoreOverrideCursor(); + QDialog::accept(); }