using namespace std;
#include "MULTIPR_i.hxx"
+
#include "utilities.h"
#include <string>
+#include <sstream>
#include "MULTIPR_API.hxx"
#include "MULTIPR_Exceptions.hxx"
+#include <SALOMEDS_Tool.hxx>
+
+#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
// 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();
}
-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 << ")";
}
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<std::string> 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<std::string> 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();
}
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<std::string> 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<std::string> 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();
}
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<std::string> 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<std::string> 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();
}
throw (SALOME::SALOME_Exception)
{
if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
-
+
try
{
string res = mObj->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)
{
}
-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 << "\")";
}
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 <std::string> 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<std::string>;
+ //}
+ 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()");
* \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__
#include "MULTIPR_Obj.hxx"
+#include <map>
+#include <vector>
+#include <string>
+
+class MULTIPR_Gen_i;
//*****************************************************************************
// Class MULTIPR_Obj_i
/**
* 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);
/**
* 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);
/**
* 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);
/**
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()
* \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);
* \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);
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:
/**
*/
int mBoxing;
+ /**
+ * Engine.
+ */
+ //MULTIPR_ORB::MULTIPR_Gen_ptr _engine;
+ MULTIPR_Gen_i* _engine;
};
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();
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,
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 <std::string> > myPythonScripts;
};
#endif // __MULTIPR_IMPLEMENTATION_CORBA__
// EOF
-
#include "MULTIPR_Utils.hxx"
// Salome Includes
-#include <SUIT_MessageBox.h>
-#include <SUIT_ResourceMgr.h>
-#include <SUIT_Session.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_DataModel.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_CheckFileDlg.h>
+
#include <LightApp_Study.h>
#include <LightApp_DataModel.h>
#include <LightApp_DataOwner.h>
#include <LightApp_SelectionMgr.h>
+
#include <CAM_DataModel.h>
#include <CAM_Module.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+
#include <SALOME_LifeCycleCORBA.hxx>
+#include <SALOMEDS_Study.hxx>
#include <QtxPopupMgr.h>
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
{
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<SalomeApp_Study*>(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())
{
mSelectedParts.clear();
- QStringList userSelection;
+ QStringList userSelection;
selected(userSelection, true);
for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++)
{
// 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<MULTIPR_GUI*>(module);
}
-
MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
{
// do nothing!
}
+void MULTIPR_GUI_DataModel::update (LightApp_DataObject*, LightApp_Study* theStudy)
+{
+ LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
+ DataObjectList ch;
+ QMap<SUIT_DataObject*,int> aMap;
+ if( modelRoot )
+ {
+ ch = modelRoot->children();
+ for ( DataObjectListIterator it( ch ); it.current(); ++it )
+ it.current()->setParent( 0 );
+ }
+
+ buildAll(theStudy);
+
+ modelRoot = dynamic_cast<LightApp_ModuleObject*>( 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<SalomeApp_Study*>(theStudy);
+ if (!aSAStudy)
+ aSAStudy = dynamic_cast<SalomeApp_Study*>(getModule()->getApp()->activeStudy());
+
+ if (!aSAStudy) return;
+
+ MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(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<MULTIPR_GUI_DataObject_Module*>(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<LightApp_DataObject*>(*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 (...)
+ {
+ }
}