1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
7 * \brief see MULTIPR_i.hxx
9 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
15 //*****************************************************************************
17 //*****************************************************************************
21 #include "MULTIPR_i.hxx"
22 #include "utilities.h"
27 #include "MULTIPR_API.hxx"
28 #include "MULTIPR_Exceptions.hxx"
29 #include "MULTIPR_Utils.hxx"
31 #include <SALOMEDS_Tool.hxx>
33 #include CORBA_CLIENT_HEADER(SALOMEDS)
34 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
37 static int MYDEBUG = 1;
39 static int MYDEBUG = 0;
42 // Dump Python utilities
47 std::ostringstream myStream;
48 static size_t myCounter;
49 //MULTIPR_ORB::MULTIPR_Gen_ptr myEngine;
50 MULTIPR_Gen_i* myEngine;
53 //TPythonDump (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine);
54 TPythonDump (MULTIPR_Gen_i* theEngine);
55 virtual ~TPythonDump();
57 TPythonDump& operator<< (long int theArg);
58 TPythonDump& operator<< (int theArg);
59 TPythonDump& operator<< (double theArg);
60 TPythonDump& operator<< (float theArg);
61 TPythonDump& operator<< (const void* theArg);
62 TPythonDump& operator<< (const char* theArg);
64 TPythonDump& operator<< (SALOMEDS::SObject_ptr theArg);
65 TPythonDump& operator<< (CORBA::Object_ptr theArg);
67 TPythonDump& operator<< (MULTIPR_ORB::MULTIPR_Gen_ptr theArg);
68 TPythonDump& operator<< (MULTIPR_ORB::MULTIPR_Obj_ptr theArg);
70 TPythonDump& operator<< (MULTIPR_Gen_i* theArg);
71 TPythonDump& operator<< (MULTIPR_Obj_i* theArg);
73 static char* MULTIPRGenName() { return "mpr_gen"; }
74 static char* MULTIPRObjName() { return "mpr_obj"; }
77 size_t TPythonDump::myCounter = 0;
79 //TPythonDump::TPythonDump (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine)
80 TPythonDump::TPythonDump (MULTIPR_Gen_i* theEngine)
83 //myEngine = MULTIPR_ORB::MULTIPR_Gen::_duplicate(theEngine);
87 TPythonDump::~TPythonDump()
91 SALOMEDS::Study_ptr aStudy = myEngine->GetCurrentStudy();
93 if (!aStudy->_is_nil()) aStudyID = aStudy->StudyId();
95 std::string aString = myStream.str();
96 myEngine->AddToPythonScript(aStudyID, aString);
97 //if(MYDEBUG) MESSAGE(" *DP* " << aString.c_str());
101 TPythonDump& TPythonDump::operator<< (long int theArg)
107 TPythonDump& TPythonDump::operator<< (int theArg)
113 TPythonDump& TPythonDump::operator<< (double theArg)
119 TPythonDump& TPythonDump::operator<< (float theArg)
125 TPythonDump& TPythonDump::operator<< (const void* theArg)
131 TPythonDump& TPythonDump::operator<< (const char* theArg)
138 TPythonDump& TPythonDump::operator<< (SALOMEDS::SObject_ptr aSObject)
140 if (aSObject->_is_nil())
143 myStream << "theStudy.FindObjectID(\"" << aSObject->GetID() << "\")";
147 TPythonDump& TPythonDump::operator<< (CORBA::Object_ptr theArg)
149 if (CORBA::is_nil(theArg))
156 TPythonDump& TPythonDump::operator<< (MULTIPR_ORB::MULTIPR_Gen_ptr theArg)
158 myStream << MULTIPRGenName();
162 TPythonDump& TPythonDump::operator<< (MULTIPR_ORB::MULTIPR_Obj_ptr theArg)
164 myStream << MULTIPRObjName();
168 TPythonDump& TPythonDump::operator<< (MULTIPR_Gen_i* theArg)
170 myStream << MULTIPRGenName();
174 TPythonDump& TPythonDump::operator<< (MULTIPR_Obj_i* theArg)
176 myStream << MULTIPRObjName();
181 //*****************************************************************************
182 // Class MULTIPR_Gen_i implementation
183 //*****************************************************************************
185 MULTIPR_Gen_i::MULTIPR_Gen_i(
187 PortableServer::POA_ptr poa,
188 PortableServer::ObjectId* contId,
189 const char* instanceName,
190 const char* interfaceName) :
191 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
193 MESSAGE("activate object");
195 _id = _poa->activate_object(_thisObj);
199 MULTIPR_Gen_i::~MULTIPR_Gen_i()
204 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
208 char* MULTIPR_Gen_i::getVersion()
209 throw (SALOME::SALOME_Exception)
211 return CORBA::string_dup(multipr::getVersion());
215 void MULTIPR_Gen_i::partitionneDomaine(
216 const char* medFilename,
217 const char* meshName)
218 throw (SALOME::SALOME_Exception)
222 multipr::partitionneDomaine(medFilename, meshName);
224 catch (multipr::RuntimeException& e)
227 THROW_SALOME_CORBA_EXCEPTION("partitionneDomaine() failed", SALOME::INTERNAL_ERROR);
232 void MULTIPR_Gen_i::partitionneGroupe(
233 const char* medFilename,
234 const char* partName,
236 CORBA::Long partitionner)
237 throw (SALOME::SALOME_Exception)
241 multipr::partitionneGroupe(
247 catch (multipr::RuntimeException& e)
250 THROW_SALOME_CORBA_EXCEPTION("partitionneGroupe() failed", SALOME::INTERNAL_ERROR);
255 void MULTIPR_Gen_i::decimePartition(
256 const char* medFilename,
257 const char* partName,
258 const char* fieldName,
260 const char* filterName,
261 const char* filterParams)
262 throw (SALOME::SALOME_Exception)
267 cout << "File : " << medFilename << endl;
268 cout << "Part : " << partName << endl;
269 cout << "Field : " << fieldName << endl;
270 cout << "It : " << fieldIt << endl;
271 cout << "Filter: " << filterName << endl;
272 cout << "Med : " << tmed << endl;
273 cout << "Low : " << tlow << endl;
274 cout << "Rad : " << radius << endl;
275 cout << "Box : " << boxing << endl;
281 multipr::decimePartition(
289 catch (multipr::RuntimeException& e)
292 THROW_SALOME_CORBA_EXCEPTION("decimePartition() failed", SALOME::INTERNAL_ERROR);
297 //-----------------------------------------------------------------------------
299 //-----------------------------------------------------------------------------
301 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_Gen_i::getObject(const char* medFilename)
302 throw (SALOME::SALOME_Exception)
304 MULTIPR_Obj_i* obj = new MULTIPR_Obj_i(_poa, medFilename);
305 obj->setEngine(this);
308 MULTIPR::TPythonDump(this) << obj << " = " << this << ".getObject(\"" << medFilename << "\")";
310 return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this();
314 void MULTIPR_Gen_i::ObjModified (MULTIPR_ORB::MULTIPR_Obj_ptr theObj)
316 // Mark current study as modified, if theObj is published in it
317 if (!CORBA::is_nil(myCurrentStudy) && !CORBA::is_nil(theObj))
319 SALOMEDS::SObject_var aSO = myCurrentStudy->FindObjectIOR(_orb->object_to_string(theObj));
321 if (!CORBA::is_nil(aSO))
322 myCurrentStudy->Modified();
327 MULTIPR_Obj_i::MULTIPR_Obj_i(PortableServer::POA_ptr thePOA,
328 const char* medFilename,
331 throw (SALOME::SALOME_Exception)
332 : SALOME::GenericObj_i(thePOA),
335 mIsTmp(isPersistence && !isMultifile)
337 mObj = new multipr::Obj();
341 cout << "Load " << medFilename << endl;
343 mObj->restorePersistent(medFilename);
345 mObj->create(medFilename);
348 catch (multipr::RuntimeException& e)
353 THROW_SALOME_CORBA_EXCEPTION("Unable to create object", SALOME::INTERNAL_ERROR);
358 MULTIPR_Obj_i::~MULTIPR_Obj_i()
364 // Remove temporary files, created during study loading, together with directory
365 std::string strFile = mObj->getMEDFilename();
366 std::string strPath = multipr::getPath(strFile.c_str());
368 //std::string cmd_rm ("del /F \"");
370 std::string cmd_rm ("rm -rf \"");
372 cmd_rm += strPath + "\"";
373 system(cmd_rm.c_str());
376 if(MYDEBUG) MESSAGE("MULTIPR_Obj_i: Destructor: remove mObj");
382 void MULTIPR_Obj_i::reset()
383 throw (SALOME::SALOME_Exception)
388 CORBA::Boolean MULTIPR_Obj_i::isValidSequentialMEDFile()
389 throw (SALOME::SALOME_Exception)
391 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
393 return mObj->isValidSequentialMEDFile();
397 CORBA::Boolean MULTIPR_Obj_i::isValidDistributedMEDFile()
398 throw (SALOME::SALOME_Exception)
400 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
402 return mObj->isValidDistributedMEDFile();
406 char* MULTIPR_Obj_i::getFilename()
407 throw (SALOME::SALOME_Exception)
409 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
411 return CORBA::string_dup(mObj->getMEDFilename().c_str());
415 char* MULTIPR_Obj_i::getSeqFilename()
416 throw (SALOME::SALOME_Exception)
418 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
420 return CORBA::string_dup(mObj->getSequentialMEDFilename().c_str());
424 void MULTIPR_Obj_i::setMesh(const char* meshName)
425 throw (SALOME::SALOME_Exception)
427 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
431 mObj->setMesh(meshName);
434 MULTIPR::TPythonDump(_engine) << this << ".setMesh(\"" << meshName << "\")";
436 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::setMesh - OK");
438 catch (multipr::RuntimeException& e)
441 THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR);
444 // Mark current study as modified, if theObj is published in it
445 _engine->ObjModified(_this());
448 std::string MULTIPR_Obj_i::getMeshName() const
449 throw (SALOME::SALOME_Exception)
451 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
453 return mObj->getMeshName();
457 void MULTIPR_Obj_i::setBoxing(CORBA::Long pBoxing)
458 throw (SALOME::SALOME_Exception)
460 if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR);
461 if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR);
466 MULTIPR::TPythonDump(_engine) << this << ".setBoxing(" << pBoxing << ")";
468 // Mark current study as modified, if theObj is published in it
469 _engine->ObjModified(_this());
473 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getMeshes()
474 throw (SALOME::SALOME_Exception)
476 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
478 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
482 std::vector<std::string> listMeshes = mObj->getMeshes();
483 mySeq->length(listMeshes.size());
485 for (size_t i = 0 ; i < listMeshes.size() ; i++)
487 mySeq[i] = CORBA::string_dup(listMeshes[i].c_str());
490 catch (multipr::RuntimeException& e)
493 THROW_SALOME_CORBA_EXCEPTION("Unable to get meshes", SALOME::INTERNAL_ERROR);
496 return mySeq._retn();
500 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getFields(const char* pPartList)
501 throw (SALOME::SALOME_Exception)
503 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
505 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
509 std::vector<std::string> listFields = mObj->getFields(pPartList);
510 mySeq->length(listFields.size());
512 for (size_t i = 0 ; i < listFields.size() ; i++)
514 mySeq[i] = CORBA::string_dup(listFields[i].c_str());
517 catch (multipr::RuntimeException& e)
520 THROW_SALOME_CORBA_EXCEPTION("Unable to get fields", SALOME::INTERNAL_ERROR);
523 return mySeq._retn();
527 CORBA::Long MULTIPR_Obj_i::getTimeStamps(const char* pPartList, const char* fieldName)
528 throw (SALOME::SALOME_Exception)
530 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
534 return mObj->getTimeStamps(pPartList, fieldName);
536 catch (multipr::RuntimeException& e)
539 THROW_SALOME_CORBA_EXCEPTION("Unable to get time stamps", SALOME::INTERNAL_ERROR);
543 void MULTIPR_Obj_i::getFieldMinMax(const char* pPartName, const char* pFieldName,
544 CORBA::Float& pMin, CORBA::Float& pMax)
545 throw (SALOME::SALOME_Exception)
547 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
550 mObj->getFieldMinMax(pPartName, pFieldName, pMin, pMax);
552 catch (multipr::RuntimeException& e)
555 THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR);
559 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getParts()
560 throw (SALOME::SALOME_Exception)
562 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
564 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
568 std::vector<std::string> listParts = mObj->getParts();
569 mySeq->length(listParts.size());
571 for (size_t i = 0 ; i < listParts.size() ; i++)
573 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
576 catch (multipr::RuntimeException& e)
579 THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR);
582 return mySeq._retn();
586 char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
587 throw (SALOME::SALOME_Exception)
589 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
591 return CORBA::string_dup(mObj->getPartInfo(pPartName).c_str());
595 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine()
596 throw (SALOME::SALOME_Exception)
598 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
600 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
604 std::vector<std::string> listParts = mObj->partitionneDomaine();
605 mySeq->length(listParts.size());
607 for (size_t i = 0 ; i < listParts.size() ; i++)
609 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
613 MULTIPR::TPythonDump(_engine) << "parts = " << this << ".partitionneDomaine()";
615 catch (multipr::RuntimeException& e)
618 THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR);
621 // Mark current study as modified, if theObj is published in it
622 _engine->ObjModified(_this());
624 return mySeq._retn();
628 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneGroupe(
629 const char* pPartName,
630 CORBA::Long pNbParts,
631 CORBA::Long pPartitionner)
632 throw (SALOME::SALOME_Exception)
634 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
636 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
640 std::vector<std::string> listParts = mObj->partitionneGroupe(
645 mySeq->length(listParts.size());
647 for (size_t i = 0 ; i < listParts.size() ; i++)
649 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
653 MULTIPR::TPythonDump(_engine) << "new_parts = " << this << ".partitionneGroupe(\""
654 << pPartName << "\", " << pNbParts << ", " << pPartitionner << ")";
656 catch (std::exception& exc)
658 THROW_SALOME_CORBA_EXCEPTION(exc.what(), SALOME::INTERNAL_ERROR);
660 catch (multipr::RuntimeException& exc)
662 std::ostringstream aStream;
665 THROW_SALOME_CORBA_EXCEPTION(aStream.str().c_str(), SALOME::INTERNAL_ERROR);
668 // Mark current study as modified, if theObj is published in it
669 _engine->ObjModified(_this());
671 return mySeq._retn();
675 MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition(
676 const char* pPartName,
677 const char* pFieldName,
678 CORBA::Long pFieldIt,
679 const char* pFilterName,
680 const char* pFilterParams)
681 throw (SALOME::SALOME_Exception)
685 THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
687 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
691 std::vector<std::string> listParts = mObj->decimePartition(
697 mySeq->length(listParts.size());
698 for (size_t i = 0 ; i < listParts.size() ; i++)
700 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
704 MULTIPR::TPythonDump(_engine) << "parts = " << this << ".decimePartition(\""
705 << pPartName << "\", \"" << pFieldName << "\", "
706 << pFieldIt << ", \"" << pFilterName << "\", \""
707 << pFilterParams << "\")";
709 catch (multipr::RuntimeException& e)
712 THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR);
715 // Mark current study as modified, if theObj is published in it
716 _engine->ObjModified(_this());
718 return mySeq._retn();
722 MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimatePart(
723 const char* pPartName,
724 const char* pFieldName,
725 CORBA::Long pFieldIt,
726 const char* pFilterName,
727 const char* pFilterParams)
728 throw (SALOME::SALOME_Exception)
730 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
732 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
736 std::list<std::string> emptyParts;
737 mObj->decimePartition(pPartName,
744 mySeq->length(emptyParts.size());
745 std::list<std::string>::const_iterator it = emptyParts.begin(), end = emptyParts.end();
746 for (size_t i = 0; it != end; it++, i++)
748 mySeq[i] = CORBA::string_dup((*it).c_str());
752 MULTIPR::TPythonDump(_engine) << "empty_parts = " << this << ".decimatePart(\""
753 << pPartName << "\", \"" << pFieldName << "\", "
754 << pFieldIt << ", \"" << pFilterName << "\", \""
755 << pFilterParams << "\")";
757 catch (multipr::RuntimeException& e)
760 THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR);
763 // Mark current study as modified, if theObj is published in it
764 _engine->ObjModified(_this());
766 return mySeq._retn();
770 char* MULTIPR_Obj_i::evalDecimationParams(
771 const char* pPartName,
772 const char* pFieldName,
773 CORBA::Long pFieldIt,
774 const char* pFilterName,
775 const char* pFilterParams)
776 throw (SALOME::SALOME_Exception)
778 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
782 string res = mObj->evalDecimationParams(
790 MULTIPR::TPythonDump(_engine) << "dec_params = " << this << ".evalDecimationParams(\""
791 << pPartName << "\", \"" << pFieldName << "\", " << pFieldIt
792 << ", \"" << pFilterName << "\", \"" << pFilterParams
793 << "\") # " << res.c_str();
794 return CORBA::string_dup(res.c_str());
796 catch (multipr::RuntimeException& e)
799 THROW_SALOME_CORBA_EXCEPTION("Unable to evaluate decimation parameters", SALOME::INTERNAL_ERROR);
804 void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName)
805 throw (SALOME::SALOME_Exception)
807 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
809 mObj->removeParts(pPrefixPartName);
812 MULTIPR::TPythonDump(_engine) << this << ".removeParts(\"" << pPrefixPartName << "\")";
814 // Mark current study as modified, if theObj is published in it
815 _engine->ObjModified(_this());
818 char* MULTIPR_Obj_i::getMEDInfo(const char* pPartName)
819 throw (SALOME::SALOME_Exception)
821 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
824 mObj->getMEDInfo(res, const_cast<char*>(pPartName));
825 return CORBA::string_dup(res);
828 void MULTIPR_Obj_i::save(const char* pPath)
829 throw (SALOME::SALOME_Exception)
831 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
835 std::string strFile = mObj->getMEDFilename();
840 // Remove temporary files, if needed
845 // Remove temporary files, created during study loading, together with directory
846 std::string strPath = multipr::getPath(strFile.c_str());
848 //std::string cmd_rm ("del /F \"");
850 std::string cmd_rm ("rm -rf \"");
852 cmd_rm += strPath + "\"";
853 system(cmd_rm.c_str());
856 catch (multipr::RuntimeException& e)
859 THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR);
863 MULTIPR::TPythonDump(_engine) << this << ".save(\"" << pPath << "\")";
866 CORBA::Long MULTIPR_Obj_i::getSaveProgress()
868 return mObj->getProgress();
871 void MULTIPR_Obj_i::resetSaveProgress()
873 mObj->resetProgress();
876 //-----------------------------------------------------------------------------
877 // savePersistent and setEngine (for Persistence & Dump Python)
878 //-----------------------------------------------------------------------------
880 void MULTIPR_Obj_i::savePersistent (const char* pPath)
881 throw (SALOME::SALOME_Exception)
883 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
887 mObj->savePersistent(pPath);
889 catch (multipr::RuntimeException& e)
892 THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR);
896 void MULTIPR_Obj_i::setEngine (MULTIPR_Gen_i* theEngine)
902 //-----------------------------------------------------------------------------
903 // Set/Get current study (for Persistence & Dump Python)
904 //-----------------------------------------------------------------------------
906 /*! Set current study
908 void MULTIPR_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
910 //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::SetCurrentStudy");
912 // theStudy or myCurrentStudy may be nil
913 if (!CORBA::is_nil(theStudy))
915 if (CORBA::is_nil(myCurrentStudy))
917 // move python trace of unknown study to the real study
918 int studyId = theStudy->StudyId();
919 if (myPythonScripts.find(-1) != myPythonScripts.end())
921 myPythonScripts[studyId].insert(myPythonScripts[studyId].begin(), // at
922 myPythonScripts[-1].begin(), // from
923 myPythonScripts[-1].end()); // to
924 myPythonScripts[-1].clear();
929 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
932 /*! Get current study
934 SALOMEDS::Study_ptr MULTIPR_Gen_i::GetCurrentStudy()
936 //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID());
937 return SALOMEDS::Study::_duplicate(myCurrentStudy);
940 //-----------------------------------------------------------------------------
941 // SALOMEDS::Driver methods (Persistence & Dump Python)
942 //-----------------------------------------------------------------------------
944 /*! Get component data type
946 char* MULTIPR_Gen_i::ComponentDataType()
948 if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::ComponentDataType" );
949 return CORBA::string_dup( "MULTIPR" );
952 /*! Clears study-connected data when it is closed
954 void MULTIPR_Gen_i::Close (SALOMEDS::SComponent_ptr theComponent)
956 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::Close");
959 /*! Save MULTIPR module's data
961 SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent,
965 INFOS( "MULTIPR_Gen_i::Save" );
967 if (myCurrentStudy->_is_nil() ||
968 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId())
969 SetCurrentStudy(theComponent->GetStudy());
971 // Store study contents as a set of python commands
972 SavePython(myCurrentStudy);
974 // Study name (for tmp directory and tmp files naming)
975 std::string aStudyName;
977 aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL());
979 // Declare a byte stream
980 SALOMEDS::TMPFile_var aStreamFile;
982 SALOMEDS::ChildIterator_ptr obj_it (myCurrentStudy->NewChildIterator(theComponent));
984 // TODO: iterate on all objects under theComponent
986 return aStreamFile._retn();
988 SALOMEDS::SObject_ptr aSObj = obj_it->Value();
989 CORBA::Object_var anObj = aSObj->GetObject();
990 MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
991 if (CORBA::is_nil(obj))
992 return aStreamFile._retn();
994 // Obtain a temporary directory
995 std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
997 // Directory for MED data to be stored in a distributed MED file
998 std::string subDir = aStudyName + "_MULTIPR_MED";
999 std::string meshDir = tmpDir + subDir;
1001 // Create a new dir <meshDir> to save the sequential/distributed file in.
1002 // Remove all the files in <meshDir> if they exist.
1004 std::string dirSeparator = "\\";
1005 //std::string cmd_mk ("mkdir /F \"");
1006 //std::string cmd_rm ("del /F \"");
1008 std::string dirSeparator = "/";
1009 std::string cmd_mk ("mkdir \"");
1010 std::string cmd_rm ("rm -rf \"");
1012 cmd_mk += meshDir + "\"";
1013 cmd_rm += meshDir + dirSeparator + "\"*";
1014 system(cmd_mk.c_str());
1015 system(cmd_rm.c_str());
1017 // Create a sequence of files processed
1018 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1020 if (obj->isValidSequentialMEDFile())
1022 std::string aFile = obj->getFilename();
1023 std::string aFileName = multipr::getFilenameWithoutPath(aFile.c_str());
1025 // Copy initial sequential MED file to <meshDir>
1027 std::string dirSeparator = "\\";
1028 //std::string cmd_cp ("copy \"");
1030 std::string dirSeparator = "/";
1031 std::string cmd_cp ("cp \"");
1033 cmd_cp += aFile + "\" \"" + meshDir + dirSeparator + "\"";
1034 system(cmd_cp.c_str());
1036 // Set names of temporary files
1037 std::string aFileNameRel = subDir + dirSeparator + aFileName;
1038 aFileSeq->length(1);
1039 aFileSeq[0] = CORBA::string_dup(aFileNameRel.c_str()); // sequential MED file
1041 else if (obj->isValidDistributedMEDFile())
1043 // Save distributed MED file to the <meshDir>
1044 PortableServer::Servant aServant = _poa->reference_to_servant(obj);
1045 MULTIPR_Obj_i* objServant = dynamic_cast<MULTIPR_Obj_i*>(aServant);
1049 return aStreamFile._retn();
1051 objServant->savePersistent(meshDir.c_str());
1053 // ASCII master file name
1054 std::string aMaitreFile = obj->getFilename();
1055 std::string aMaitreFileName = multipr::getFilenameWithoutPath(aMaitreFile.c_str());
1056 // just after partitionneDomaine() the state is MULTIPR_OBJ_STATE_DIS_MEM,
1057 // and getFilename() returns name of sequential file
1058 // (because distributed file is not created on disk yet). So, build the name:
1059 if (aMaitreFile == obj->getSeqFilename())
1061 std::string strExtension (".med");
1062 std::string strNamePrefix =
1063 multipr::removeExtension(aMaitreFileName.c_str(), strExtension.c_str());
1064 aMaitreFileName = strNamePrefix + "_grains_maitre" + strExtension;
1066 //std::string aMaitreFileName = SALOMEDS_Tool::GetNameFromPath(aMaitreFile);
1067 std::string aMaitreFileNameRel = subDir + dirSeparator + aMaitreFileName;
1069 // Set names of temporary files
1070 MULTIPR_ORB::string_array* listParts = obj->getParts();
1071 unsigned int nbParts = listParts->length();
1072 aFileSeq->length(nbParts + 1);
1074 char lMeshName[256];
1076 char lPartName[256];
1078 char lMEDFileName[256];
1080 for (unsigned int i = 0; i < nbParts; i++) // each part MED files
1082 const char* strPartName = (*listParts)[i];
1083 char* strPartInfo = obj->getPartInfo(strPartName);
1086 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
1087 lMeshName, &lId, lPartName, lPath, lMEDFileName);
1092 return aStreamFile._retn();
1095 std::string aPartFileName = multipr::getFilenameWithoutPath(lMEDFileName);
1096 std::string aPartFileNameRel = subDir + dirSeparator + aPartFileName;
1098 aFileSeq[i] = CORBA::string_dup(aPartFileNameRel.c_str()); // part MED file
1100 aFileSeq[nbParts] = CORBA::string_dup(aMaitreFileNameRel.c_str()); // ASCII master file
1105 return aStreamFile._retn();
1108 // Convert temporary files to stream
1109 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir, aFileSeq.in(), isMultiFile);
1111 // Remove temporary files and directory
1114 //SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir, aFileSeq.in(), true);
1115 // remove with shell command, because SALOMEDS_Tool::RemoveTemporaryFiles does not remove sub-folders
1117 //std::string cmd_rm ("del /F \"");
1119 std::string cmd_rm ("rm -rf \"");
1121 cmd_rm += tmpDir + "\"";
1122 system(cmd_rm.c_str());
1125 INFOS("MULTIPR_Gen_i::Save() completed");
1126 return aStreamFile._retn();
1129 /*! Save MULTIPR module's data in ASCII format
1131 SALOMEDS::TMPFile* MULTIPR_Gen_i::SaveASCII (SALOMEDS::SComponent_ptr theComponent,
1135 if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::SaveASCII" );
1136 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
1137 return aStreamFile._retn();
1140 /*! Load MULTIPR module's data
1142 bool MULTIPR_Gen_i::Load (SALOMEDS::SComponent_ptr theComponent,
1143 const SALOMEDS::TMPFile& theStream,
1147 INFOS("MULTIPR_Gen_i::Load");
1149 if (myCurrentStudy->_is_nil() ||
1150 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId())
1151 SetCurrentStudy(theComponent->GetStudy());
1153 // Get temporary files location
1154 std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
1156 INFOS("THE URL++++++++++++++");
1158 INFOS("THE TMP PATH+++++++++");
1159 INFOS(tmpDir.c_str());
1161 // For LocalPersistentIDToIOR():
1164 // Create a new dir <meshDir> to restore the distributed/sequential
1165 // MED file in. It is needed only if not multifile, because in
1166 // multifile study all required files are already on disk.
1169 std::string subDir = "_MULTIPR_MED";
1170 std::string meshDir = tmpDir + subDir;
1172 //std::string cmd_mk ("mkdir /F \"");
1174 std::string cmd_mk ("mkdir \"");
1176 cmd_mk += meshDir + "\"";
1177 system(cmd_mk.c_str());
1180 // Convert the stream into sequence of files to process
1181 SALOMEDS::ListOfFileNames_var aFileSeq =
1182 SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.c_str(), isMultiFile);
1184 //TCollection_AsciiString aStudyName;
1186 // aStudyName = ((char*)SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()).c_str());
1188 // Set names of "temporary" files
1189 //TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_MULTIPR.hdf" );
1190 //TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_MULTIPR_Mesh.med" );
1192 // Remove temporary files created from the stream
1194 // SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
1196 INFOS("MULTIPR_Gen_i::Load completed");
1200 /*! Load MULTIPR module's data in ASCII format
1202 bool MULTIPR_Gen_i::LoadASCII (SALOMEDS::SComponent_ptr theComponent,
1203 const SALOMEDS::TMPFile& theStream,
1207 if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::LoadASCII" );
1208 return Load(theComponent, theStream, theURL, isMultiFile);
1211 /*! Transform data from transient form to persistent
1213 char* MULTIPR_Gen_i::IORToLocalPersistentID (SALOMEDS::SObject_ptr /*theSObject*/,
1214 const char* IORString,
1215 CORBA::Boolean isMultiFile,
1216 CORBA::Boolean /*isASCII*/ )
1218 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID");
1220 MULTIPR_ORB::MULTIPR_Obj_ptr obj =
1221 MULTIPR_ORB::MULTIPR_Obj::_narrow(_orb->string_to_object(IORString));
1223 if (!CORBA::is_nil(obj))
1225 std::string aStudyName;
1227 aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL());
1229 std::string subDir = aStudyName + "_MULTIPR_MED";
1231 std::string aFile = obj->getFilename();
1232 std::string aFileName = multipr::getFilenameWithoutPath(aFile.c_str());
1234 // Get servant (to call methods, not present in IDL interface
1235 PortableServer::Servant aServant = _poa->reference_to_servant(obj);
1236 MULTIPR_Obj_i* objServant = dynamic_cast<MULTIPR_Obj_i*>(aServant);
1240 return CORBA::string_dup("");
1243 std::string strSeparator ("|");
1244 if (obj->isValidSequentialMEDFile())
1248 sprintf(strBoxing, "%d", objServant->getBoxing());
1249 aFileName += strSeparator + strBoxing;
1252 std::string aMeshName = objServant->getMeshName();
1253 if (!aMeshName.empty())
1255 aFileName += strSeparator + aMeshName;
1258 else if (obj->isValidDistributedMEDFile())
1260 // just after partitionneDomaine() the state is MULTIPR_OBJ_STATE_DIS_MEM,
1261 // and getFilename() returns name of sequential file
1262 // (because distributed file is not created on disk yet). So, build the name:
1263 if (aFile == obj->getSeqFilename())
1265 std::string strExtension (".med");
1266 std::string strNamePrefix =
1267 multipr::removeExtension(aFileName.c_str(), strExtension.c_str());
1268 aFileName = strNamePrefix + "_grains_maitre" + strExtension;
1273 sprintf(strBoxing, "%d", objServant->getBoxing());
1274 aFileName += strSeparator + strBoxing;
1279 return CORBA::string_dup("");
1282 // PersistentID will be a relative path to MED file (relatively tmp dir)
1283 // plus additianal parameters, separated by '|' (see above)
1285 std::string dirSeparator = "\\";
1287 std::string dirSeparator = "/";
1289 aFileName = subDir + dirSeparator + aFileName;
1291 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID: id = " << aFileName.c_str());
1293 return CORBA::string_dup(aFileName.c_str());
1295 return CORBA::string_dup("");
1298 /*! Transform data from persistent form to transient
1300 char* MULTIPR_Gen_i::LocalPersistentIDToIOR (SALOMEDS::SObject_ptr /*theSObject*/,
1301 const char* aLocalPersistentID,
1302 CORBA::Boolean isMultiFile,
1303 CORBA::Boolean /*isASCII*/)
1305 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID);
1307 if (strlen(aLocalPersistentID) > 0)
1309 // Extract relative path
1310 std::string strLocalPersistentID (aLocalPersistentID);
1311 int nb = strLocalPersistentID.find("|");
1312 if (nb < 1) nb = strLocalPersistentID.size();
1316 return CORBA::string_dup("");
1318 std::string strRelativePath = strLocalPersistentID.substr(0, nb);
1319 strLocalPersistentID.erase(0, nb); // erase <strRelativePath>
1320 if (strLocalPersistentID.size() > 0) strLocalPersistentID.erase(0, 1); // erase "|"
1322 // the only kind of available objects is a MULTIPR_ORB::MULTIPR_Obj,
1323 // representing a sequential or a distributed MED file.
1324 std::string medFilename = myTmpDir + strRelativePath; // myTmpDir already contains dir separator
1326 // create MULTIPR_Obj from file
1327 //MULTIPR_ORB::MULTIPR_Obj_ptr obj = getObject(medFilename.c_str());
1328 MULTIPR_Obj_i* obj_i = new MULTIPR_Obj_i (_poa,
1329 medFilename.c_str(),
1330 /*isPersistence = */true,
1332 obj_i->setEngine(this);
1333 MULTIPR_ORB::MULTIPR_Obj_ptr obj = obj_i->POA_MULTIPR_ORB::MULTIPR_Obj::_this();
1335 // Set boxing and mesh name, if provided
1336 nb = strLocalPersistentID.find("|");
1337 if (nb < 1) nb = strLocalPersistentID.size();
1340 std::string strBoxing = strLocalPersistentID.substr(0, nb);
1341 strLocalPersistentID.erase(0, nb); // erase <strBoxing>
1342 if (strLocalPersistentID.size() > 0) strLocalPersistentID.erase(0, 1); // erase "|"
1343 int aBoxing = atoi(strBoxing.c_str());
1344 obj->setBoxing(aBoxing);
1347 if (obj->isValidSequentialMEDFile())
1349 nb = strLocalPersistentID.size();
1352 std::string strMeshName = strLocalPersistentID.substr(0, nb);
1353 obj->setMesh(strMeshName.c_str());
1354 // we do not cut <strLocalPersistentID> here,
1355 // because we do not expect to find in it anything
1360 CORBA::String_var anIORString = _orb->object_to_string(obj);
1361 return CORBA::string_dup(anIORString);
1363 return CORBA::string_dup("");
1366 /*! Transform data from persistent form to transient
1368 Engines::TMPFile* MULTIPR_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
1369 CORBA::Boolean isPublished,
1370 CORBA::Boolean& isValidScript)
1372 isValidScript = false;
1374 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1375 if (CORBA::is_nil(aStudy))
1376 return new Engines::TMPFile(0);
1379 SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
1380 if (CORBA::is_nil(aSO))
1381 return new Engines::TMPFile(0);
1383 // Map study entries to object names
1384 Resource_DataMapOfAsciiStringAsciiString aMap;
1385 Resource_DataMapOfAsciiStringAsciiString aMapNames;
1387 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
1388 for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
1389 SALOMEDS::SObject_var aValue = Itr->Value();
1390 CORBA::String_var anID = aValue->GetID();
1391 CORBA::String_var aName = aValue->GetName();
1392 TCollection_AsciiString aGUIName ( (char*) aName.in() );
1393 TCollection_AsciiString anEnrty ( (char*) anID.in() );
1394 if (aGUIName.Length() > 0) {
1395 aMapNames.Bind( anEnrty, aGUIName );
1396 aMap.Bind( anEnrty, aGUIName );
1401 // Get trace of restored study
1402 SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
1403 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1404 SALOMEDS::GenericAttribute_var anAttr =
1405 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
1407 char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
1408 std::string aSavedTrace (oldValue);
1410 // Add trace of API methods calls and replace study entries by names
1411 std::string aScript =
1412 "### This file is generated by SALOME automatically "
1413 "by dump python functionality of MULTIPR component\n\n";
1414 aScript += DumpPython_impl(aStudy->StudyId(), isPublished, isValidScript, aSavedTrace);
1416 int aLen = aScript.length();
1417 unsigned char* aBuffer = new unsigned char[aLen+1];
1418 strcpy((char*)aBuffer, aScript.c_str());
1420 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
1421 Engines::TMPFile_var aStreamFile = new Engines::TMPFile (aLen+1, aLen+1, anOctetBuf, 1);
1423 //bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen);
1424 //isValidScript = isValidScript && !hasNotPublishedObjects;
1426 return aStreamFile._retn();
1431 std::string MULTIPR_Gen_i::DumpPython_impl (int theStudyID,
1434 std::string theSavedTrace)
1437 std::string aGen = MULTIPR::TPythonDump::MULTIPRGenName();
1439 // set initial part of a script
1440 std::string aScript ("import salome\n");
1441 aScript += "import MULTIPR_ORB\n\n";
1442 aScript += "def RebuildData(theStudy):\n";
1444 aScript += helper + "\tmpr_comp = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"" +
1445 ComponentDataType() + "\")\n";
1446 aScript += helper + "\t" + aGen + " = mpr_comp._narrow(MULTIPR_ORB.MULTIPR_Gen)\n";
1448 //if ( isPublished )
1449 // aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)";
1451 // aScript += helper + "\t" + aGen + ".SetCurrentStudy(None)";
1452 aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)\n";
1454 // Dump trace of restored study
1455 if (theSavedTrace.length() > 0)
1457 aScript += helper + "\n" + theSavedTrace;
1460 // Dump trace of API methods calls
1461 std::string aNewLines = GetNewPythonLines(theStudyID);
1462 if (aNewLines.length() > 0)
1464 aScript += helper + "\n" + aNewLines;
1467 // add final part of a script
1468 //aScript += helper + "\n\tisGUIMode = " + isPublished;
1469 //aScript += "\n\tif isGUIMode and salome.sg.hasDesktop():";
1470 //aScript += "\n\t\tsalome.sg.updateObjBrowser(0)";
1471 aScript += "\n\n\tpass\n";
1473 aValidScript = true;
1478 /*! GetNewPythonLines
1480 std::string MULTIPR_Gen_i::GetNewPythonLines (int theStudyID)
1482 std::string aScript;
1484 // Dump trace of API methods calls
1485 if (myPythonScripts.find(theStudyID) != myPythonScripts.end())
1487 std::vector <std::string> aPythonScript = myPythonScripts[theStudyID];
1488 int istr, aLen = aPythonScript.size();
1489 for (istr = 0; istr < aLen; istr++)
1492 aScript += aPythonScript[istr];
1500 /*! CleanPythonTrace
1502 void MULTIPR_Gen_i::CleanPythonTrace (int theStudyID)
1504 // Clean trace of API methods calls
1505 if (myPythonScripts.find(theStudyID) != myPythonScripts.end())
1507 myPythonScripts[theStudyID].clear();
1511 /*! AddToPythonScript
1513 void MULTIPR_Gen_i::AddToPythonScript (int theStudyID, std::string theString)
1515 //if (myPythonScripts.find(theStudyID) == myPythonScripts.end())
1517 // myPythonScripts[theStudyID] = std::vector<std::string>;
1519 myPythonScripts[theStudyID].push_back(theString);
1524 void MULTIPR_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
1526 // Dump trace of API methods calls
1527 std::string aScript = GetNewPythonLines(theStudy->StudyId());
1529 // Check contents of PythonObject attribute
1530 SALOMEDS::SObject_var aSO = theStudy->FindComponent(ComponentDataType());
1531 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1532 SALOMEDS::GenericAttribute_var anAttr =
1533 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
1535 char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
1536 std::string oldScript (oldValue);
1538 if (oldScript.length() > 0) {
1540 oldScript += aScript;
1543 oldScript = aScript;
1546 // Store in PythonObject attribute
1547 SALOMEDS::AttributePythonObject::_narrow(anAttr)->SetObject(oldScript.c_str(), 1);
1549 // Clean trace of API methods calls
1550 CleanPythonTrace(theStudy->StudyId());
1554 /*! Returns true if object can be published in the study
1556 bool MULTIPR_Gen_i::CanPublishInStudy (CORBA::Object_ptr theIOR)
1558 //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy - " << !CORBA::is_nil(myCurrentStudy));
1559 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy");
1561 //if (CORBA::is_nil(myCurrentStudy))
1564 MULTIPR_ORB::MULTIPR_Obj_var anObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(theIOR);
1565 if (!anObj->_is_nil())
1568 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy - CANNOT");
1572 /*! Publish object in the study
1574 SALOMEDS::SObject_ptr MULTIPR_Gen_i::PublishInStudy (SALOMEDS::Study_ptr theStudy,
1575 SALOMEDS::SObject_ptr theSObject,
1576 CORBA::Object_ptr theIOR,
1577 const char* theName)
1578 throw (SALOME::SALOME_Exception)
1580 //Unexpect aCatch(SALOME_SalomeException);
1582 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy");
1584 //if (myCurrentStudy->_is_nil() || theStudy->StudyId() != myCurrentStudy->StudyId())
1585 if (myCurrentStudy->_is_nil())
1586 SetCurrentStudy(theStudy);
1588 SALOMEDS::SObject_var aSO;
1589 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theIOR))
1592 // Publishing a MULTIPR_Object
1593 MULTIPR_ORB::MULTIPR_Obj_var anObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(theIOR);
1594 if (!anObj->_is_nil())
1596 aSO = theStudy->FindObjectIOR(_orb->object_to_string(anObj));
1599 SALOMEDS::GenericAttribute_var anAttr;
1600 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1602 SALOMEDS::SComponent_var aFather = theStudy->FindComponent(ComponentDataType());
1603 if (aFather->_is_nil())
1605 aFather = aStudyBuilder->NewComponent(ComponentDataType());
1606 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
1607 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1608 aName->SetValue("MULTI-PR");
1609 //anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
1610 //SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_MULTIPR");
1611 //aStudyBuilder->DefineComponentInstance(aFather, MULTIPR_ORB::MULTIPR_Gen::_this());
1612 aStudyBuilder->DefineComponentInstance(aFather, MULTIPR_Gen::_this());
1614 if (aFather->_is_nil()) return aSO._retn();
1616 if (CORBA::is_nil(theSObject))
1618 aSO = aStudyBuilder->NewObject(aFather);
1622 if (!theSObject->ReferencedObject(aSO))
1623 aSO = SALOMEDS::SObject::_duplicate(theSObject);
1626 anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1627 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
1628 CORBA::String_var anIOR = _orb->object_to_string(anObj);
1629 anIORAttr->SetValue(anIOR);
1631 //anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap");
1632 //SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1633 //aPixmap->SetPixMap("ICON_OBJBROWSER_GROUP_PNT");
1635 anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1636 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1637 if (strlen(theName) == 0)
1638 aNameAttrib->SetValue(anObj->getFilename());
1640 aNameAttrib->SetValue(theName);
1643 MULTIPR::TPythonDump(this) << "sobj = " << this << ".PublishInStudy(theStudy, "
1644 << theSObject << ", " << anObj << ", \"" << theName
1645 << "\") # " << aSO->GetID();
1649 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy - END");
1655 SALOMEDS::SComponent_ptr _Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
1657 if ( CORBA::is_nil( theStudy ))
1658 return SALOMEDS::SComponent::_nil();
1659 if(MYDEBUG) MESSAGE("PublishComponent");
1661 SALOMEDS::SComponent_var father =
1662 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
1663 if ( !CORBA::is_nil( father ) )
1664 return father._retn();
1666 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
1667 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
1668 if ( CORBA::is_nil( aCat ) )
1669 return father._retn();
1671 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
1672 if ( CORBA::is_nil( aComp ) )
1673 return father._retn();
1675 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1676 SALOMEDS::GenericAttribute_var anAttr;
1677 SALOMEDS::AttributePixMap_var aPixmap;
1679 father = aStudyBuilder->NewComponent( ComponentDataType() );
1680 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
1681 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
1682 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
1683 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
1684 SetName( father, aComp->componentusername(), "MESH" );
1685 if(MYDEBUG) MESSAGE("PublishComponent--END");
1687 return father._retn();
1693 * MULTIPREngine_factory
1695 * C factory, accessible with dlsym, after dlopen
1699 PortableServer::ObjectId* MULTIPREngine_factory(
1701 PortableServer::POA_ptr poa,
1702 PortableServer::ObjectId * contId,
1703 const char* instanceName,
1704 const char* interfaceName)
1706 MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()");
1707 SCRUTE(interfaceName);
1708 MULTIPR_Gen_i* myMULTIPR = new MULTIPR_Gen_i(orb, poa, contId, instanceName, interfaceName);
1709 return myMULTIPR->getId();