1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Partitioning/decimation module for the SALOME v3.2 platform
25 * \brief see MULTIPR_i.hxx
27 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
33 //*****************************************************************************
35 //*****************************************************************************
39 #include "MULTIPR_i.hxx"
40 #include "utilities.h"
45 #include "MULTIPR_API.hxx"
46 #include "MULTIPR_Exceptions.hxx"
47 #include "MULTIPR_Utils.hxx"
49 #include <SALOMEDS_Tool.hxx>
51 #include CORBA_CLIENT_HEADER(SALOMEDS)
52 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
55 static int MYDEBUG = 1;
57 static int MYDEBUG = 0;
60 // Dump Python utilities
65 std::ostringstream myStream;
66 static size_t myCounter;
67 //MULTIPR_ORB::MULTIPR_Gen_ptr myEngine;
68 MULTIPR_Gen_i* myEngine;
71 //TPythonDump (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine);
72 TPythonDump (MULTIPR_Gen_i* theEngine);
73 virtual ~TPythonDump();
75 TPythonDump& operator<< (long int theArg);
76 TPythonDump& operator<< (int theArg);
77 TPythonDump& operator<< (double theArg);
78 TPythonDump& operator<< (float theArg);
79 TPythonDump& operator<< (const void* theArg);
80 TPythonDump& operator<< (const char* theArg);
82 TPythonDump& operator<< (SALOMEDS::SObject_ptr theArg);
83 TPythonDump& operator<< (CORBA::Object_ptr theArg);
85 TPythonDump& operator<< (MULTIPR_ORB::MULTIPR_Gen_ptr theArg);
86 TPythonDump& operator<< (MULTIPR_ORB::MULTIPR_Obj_ptr theArg);
88 TPythonDump& operator<< (MULTIPR_Gen_i* theArg);
89 TPythonDump& operator<< (MULTIPR_Obj_i* theArg);
91 static char* MULTIPRGenName() { return "mpr_gen"; }
92 static char* MULTIPRObjName() { return "mpr_obj"; }
95 size_t TPythonDump::myCounter = 0;
97 //TPythonDump::TPythonDump (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine)
98 TPythonDump::TPythonDump (MULTIPR_Gen_i* theEngine)
101 //myEngine = MULTIPR_ORB::MULTIPR_Gen::_duplicate(theEngine);
102 myEngine = theEngine;
105 TPythonDump::~TPythonDump()
107 if (--myCounter == 0)
109 SALOMEDS::Study_ptr aStudy = myEngine->GetCurrentStudy();
111 if (!aStudy->_is_nil()) aStudyID = aStudy->StudyId();
113 std::string aString = myStream.str();
114 myEngine->AddToPythonScript(aStudyID, aString);
115 //if(MYDEBUG) MESSAGE(" *DP* " << aString.c_str());
119 TPythonDump& TPythonDump::operator<< (long int theArg)
125 TPythonDump& TPythonDump::operator<< (int theArg)
131 TPythonDump& TPythonDump::operator<< (double theArg)
137 TPythonDump& TPythonDump::operator<< (float theArg)
143 TPythonDump& TPythonDump::operator<< (const void* theArg)
149 TPythonDump& TPythonDump::operator<< (const char* theArg)
156 TPythonDump& TPythonDump::operator<< (SALOMEDS::SObject_ptr aSObject)
158 if (aSObject->_is_nil())
161 myStream << "theStudy.FindObjectID(\"" << aSObject->GetID() << "\")";
165 TPythonDump& TPythonDump::operator<< (CORBA::Object_ptr theArg)
167 if (CORBA::is_nil(theArg))
174 TPythonDump& TPythonDump::operator<< (MULTIPR_ORB::MULTIPR_Gen_ptr theArg)
176 myStream << MULTIPRGenName();
180 TPythonDump& TPythonDump::operator<< (MULTIPR_ORB::MULTIPR_Obj_ptr theArg)
182 myStream << MULTIPRObjName();
186 TPythonDump& TPythonDump::operator<< (MULTIPR_Gen_i* theArg)
188 myStream << MULTIPRGenName();
192 TPythonDump& TPythonDump::operator<< (MULTIPR_Obj_i* theArg)
194 myStream << MULTIPRObjName();
199 //*****************************************************************************
200 // Class MULTIPR_Gen_i implementation
201 //*****************************************************************************
203 MULTIPR_Gen_i::MULTIPR_Gen_i(
205 PortableServer::POA_ptr poa,
206 PortableServer::ObjectId* contId,
207 const char* instanceName,
208 const char* interfaceName) :
209 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
211 MESSAGE("activate object");
213 _id = _poa->activate_object(_thisObj);
217 MULTIPR_Gen_i::~MULTIPR_Gen_i()
222 //-----------------------------------------------------------------------------
224 //-----------------------------------------------------------------------------
226 char* MULTIPR_Gen_i::getVersion()
227 throw (SALOME::SALOME_Exception)
229 return CORBA::string_dup(multipr::getVersion());
233 void MULTIPR_Gen_i::partitionneDomaine(
234 const char* medFilename,
235 const char* meshName)
236 throw (SALOME::SALOME_Exception)
240 multipr::partitionneDomaine(medFilename, meshName);
242 catch (multipr::RuntimeException& e)
245 THROW_SALOME_CORBA_EXCEPTION("partitionneDomaine() failed", SALOME::INTERNAL_ERROR);
250 void MULTIPR_Gen_i::partitionneGroupe(
251 const char* medFilename,
252 const char* partName,
254 CORBA::Long partitionner)
255 throw (SALOME::SALOME_Exception)
259 multipr::partitionneGroupe(
265 catch (multipr::RuntimeException& e)
268 THROW_SALOME_CORBA_EXCEPTION("partitionneGroupe() failed", SALOME::INTERNAL_ERROR);
273 void MULTIPR_Gen_i::decimePartition(
274 const char* medFilename,
275 const char* partName,
276 const char* fieldName,
278 const char* filterName,
279 const char* filterParams)
280 throw (SALOME::SALOME_Exception)
285 cout << "File : " << medFilename << endl;
286 cout << "Part : " << partName << endl;
287 cout << "Field : " << fieldName << endl;
288 cout << "It : " << fieldIt << endl;
289 cout << "Filter: " << filterName << endl;
290 cout << "Med : " << tmed << endl;
291 cout << "Low : " << tlow << endl;
292 cout << "Rad : " << radius << endl;
293 cout << "Box : " << boxing << endl;
299 multipr::decimePartition(
307 catch (multipr::RuntimeException& e)
310 THROW_SALOME_CORBA_EXCEPTION("decimePartition() failed", SALOME::INTERNAL_ERROR);
315 //-----------------------------------------------------------------------------
317 //-----------------------------------------------------------------------------
319 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_Gen_i::getObject(const char* medFilename)
320 throw (SALOME::SALOME_Exception)
322 MULTIPR_Obj_i* obj = new MULTIPR_Obj_i(_poa, medFilename);
323 obj->setEngine(this);
326 MULTIPR::TPythonDump(this) << obj << " = " << this << ".getObject(\"" << medFilename << "\")";
328 return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this();
332 void MULTIPR_Gen_i::ObjModified (MULTIPR_ORB::MULTIPR_Obj_ptr theObj)
334 // Mark current study as modified, if theObj is published in it
335 if (!CORBA::is_nil(myCurrentStudy) && !CORBA::is_nil(theObj))
337 SALOMEDS::SObject_var aSO = myCurrentStudy->FindObjectIOR(_orb->object_to_string(theObj));
339 if (!CORBA::is_nil(aSO))
340 myCurrentStudy->Modified();
345 MULTIPR_Obj_i::MULTIPR_Obj_i(PortableServer::POA_ptr thePOA,
346 const char* medFilename,
349 throw (SALOME::SALOME_Exception)
350 : SALOME::GenericObj_i(thePOA),
353 mIsTmp(isPersistence && !isMultifile)
355 mObj = new multipr::Obj();
359 cout << "Load " << medFilename << endl;
361 mObj->restorePersistent(medFilename);
363 mObj->create(medFilename);
366 catch (multipr::RuntimeException& e)
371 THROW_SALOME_CORBA_EXCEPTION("Unable to create object", SALOME::INTERNAL_ERROR);
376 MULTIPR_Obj_i::~MULTIPR_Obj_i()
382 // Remove temporary files, created during study loading, together with directory
383 std::string strFile = mObj->getMEDFilename();
384 std::string strPath = multipr::getPath(strFile.c_str());
386 //std::string cmd_rm ("del /F \"");
388 std::string cmd_rm ("rm -rf \"");
390 cmd_rm += strPath + "\"";
391 system(cmd_rm.c_str());
394 if(MYDEBUG) MESSAGE("MULTIPR_Obj_i: Destructor: remove mObj");
400 void MULTIPR_Obj_i::reset()
401 throw (SALOME::SALOME_Exception)
406 CORBA::Boolean MULTIPR_Obj_i::isValidSequentialMEDFile()
407 throw (SALOME::SALOME_Exception)
409 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
411 return mObj->isValidSequentialMEDFile();
415 CORBA::Boolean MULTIPR_Obj_i::isValidDistributedMEDFile()
416 throw (SALOME::SALOME_Exception)
418 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
420 return mObj->isValidDistributedMEDFile();
424 char* MULTIPR_Obj_i::getFilename()
425 throw (SALOME::SALOME_Exception)
427 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
429 return CORBA::string_dup(mObj->getMEDFilename().c_str());
433 char* MULTIPR_Obj_i::getSeqFilename()
434 throw (SALOME::SALOME_Exception)
436 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
438 return CORBA::string_dup(mObj->getSequentialMEDFilename().c_str());
442 void MULTIPR_Obj_i::setMesh(const char* meshName)
443 throw (SALOME::SALOME_Exception)
445 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
449 mObj->setMesh(meshName);
452 MULTIPR::TPythonDump(_engine) << this << ".setMesh(\"" << meshName << "\")";
454 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::setMesh - OK");
456 catch (multipr::RuntimeException& e)
459 THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR);
462 // Mark current study as modified, if theObj is published in it
463 _engine->ObjModified(_this());
466 std::string MULTIPR_Obj_i::getMeshName() const
467 throw (SALOME::SALOME_Exception)
469 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
471 return mObj->getMeshName();
475 void MULTIPR_Obj_i::setBoxing(CORBA::Long pBoxing)
476 throw (SALOME::SALOME_Exception)
478 if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR);
479 if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR);
484 MULTIPR::TPythonDump(_engine) << this << ".setBoxing(" << pBoxing << ")";
486 // Mark current study as modified, if theObj is published in it
487 _engine->ObjModified(_this());
491 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getMeshes()
492 throw (SALOME::SALOME_Exception)
494 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
496 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
500 std::vector<std::string> listMeshes = mObj->getMeshes();
501 mySeq->length(listMeshes.size());
503 for (size_t i = 0 ; i < listMeshes.size() ; i++)
505 mySeq[i] = CORBA::string_dup(listMeshes[i].c_str());
508 catch (multipr::RuntimeException& e)
511 THROW_SALOME_CORBA_EXCEPTION("Unable to get meshes", SALOME::INTERNAL_ERROR);
514 return mySeq._retn();
518 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getFields(const char* pPartList)
519 throw (SALOME::SALOME_Exception)
521 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
523 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
527 std::vector<std::string> listFields = mObj->getFields(pPartList);
528 mySeq->length(listFields.size());
530 for (size_t i = 0 ; i < listFields.size() ; i++)
532 mySeq[i] = CORBA::string_dup(listFields[i].c_str());
535 catch (multipr::RuntimeException& e)
538 THROW_SALOME_CORBA_EXCEPTION("Unable to get fields", SALOME::INTERNAL_ERROR);
541 return mySeq._retn();
545 CORBA::Long MULTIPR_Obj_i::getTimeStamps(const char* pPartList, const char* fieldName)
546 throw (SALOME::SALOME_Exception)
548 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
552 return mObj->getTimeStamps(pPartList, fieldName);
554 catch (multipr::RuntimeException& e)
557 THROW_SALOME_CORBA_EXCEPTION("Unable to get time stamps", SALOME::INTERNAL_ERROR);
561 void MULTIPR_Obj_i::getFieldMinMax(const char* pPartName, const char* pFieldName,
562 CORBA::Float& pMin, CORBA::Float& pMax)
563 throw (SALOME::SALOME_Exception)
565 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
568 mObj->getFieldMinMax(pPartName, pFieldName, pMin, pMax);
570 catch (multipr::RuntimeException& e)
573 THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR);
577 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getParts()
578 throw (SALOME::SALOME_Exception)
580 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
582 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
586 std::vector<std::string> listParts = mObj->getParts();
587 mySeq->length(listParts.size());
589 for (size_t i = 0 ; i < listParts.size() ; i++)
591 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
594 catch (multipr::RuntimeException& e)
597 THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR);
600 return mySeq._retn();
604 char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
605 throw (SALOME::SALOME_Exception)
607 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
609 return CORBA::string_dup(mObj->getPartInfo(pPartName).c_str());
613 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine()
614 throw (SALOME::SALOME_Exception)
616 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
618 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
622 std::vector<std::string> listParts = mObj->partitionneDomaine();
623 mySeq->length(listParts.size());
625 for (size_t i = 0 ; i < listParts.size() ; i++)
627 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
631 MULTIPR::TPythonDump(_engine) << "parts = " << this << ".partitionneDomaine()";
633 catch (multipr::RuntimeException& e)
636 THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR);
639 // Mark current study as modified, if theObj is published in it
640 _engine->ObjModified(_this());
642 return mySeq._retn();
646 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneGroupe(
647 const char* pPartName,
648 CORBA::Long pNbParts,
649 CORBA::Long pPartitionner)
650 throw (SALOME::SALOME_Exception)
652 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
654 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
658 std::vector<std::string> listParts = mObj->partitionneGroupe(
663 mySeq->length(listParts.size());
665 for (size_t i = 0 ; i < listParts.size() ; i++)
667 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
671 MULTIPR::TPythonDump(_engine) << "new_parts = " << this << ".partitionneGroupe(\""
672 << pPartName << "\", " << pNbParts << ", " << pPartitionner << ")";
674 catch (std::exception& exc)
676 THROW_SALOME_CORBA_EXCEPTION(exc.what(), SALOME::INTERNAL_ERROR);
678 catch (multipr::RuntimeException& exc)
680 std::ostringstream aStream;
683 THROW_SALOME_CORBA_EXCEPTION(aStream.str().c_str(), SALOME::INTERNAL_ERROR);
686 // Mark current study as modified, if theObj is published in it
687 _engine->ObjModified(_this());
689 return mySeq._retn();
693 MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition(
694 const char* pPartName,
695 const char* pFieldName,
696 CORBA::Long pFieldIt,
697 const char* pFilterName,
698 const char* pFilterParams)
699 throw (SALOME::SALOME_Exception)
703 THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
705 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
709 std::vector<std::string> listParts = mObj->decimePartition(
715 mySeq->length(listParts.size());
716 for (size_t i = 0 ; i < listParts.size() ; i++)
718 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
722 MULTIPR::TPythonDump(_engine) << "parts = " << this << ".decimePartition(\""
723 << pPartName << "\", \"" << pFieldName << "\", "
724 << pFieldIt << ", \"" << pFilterName << "\", \""
725 << pFilterParams << "\")";
727 catch (multipr::RuntimeException& e)
730 THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR);
733 // Mark current study as modified, if theObj is published in it
734 _engine->ObjModified(_this());
736 return mySeq._retn();
740 MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimatePart(
741 const char* pPartName,
742 const char* pFieldName,
743 CORBA::Long pFieldIt,
744 const char* pFilterName,
745 const char* pFilterParams)
746 throw (SALOME::SALOME_Exception)
748 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
750 MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
754 std::list<std::string> emptyParts;
755 mObj->decimePartition(pPartName,
762 mySeq->length(emptyParts.size());
763 std::list<std::string>::const_iterator it = emptyParts.begin(), end = emptyParts.end();
764 for (size_t i = 0; it != end; it++, i++)
766 mySeq[i] = CORBA::string_dup((*it).c_str());
770 MULTIPR::TPythonDump(_engine) << "empty_parts = " << this << ".decimatePart(\""
771 << pPartName << "\", \"" << pFieldName << "\", "
772 << pFieldIt << ", \"" << pFilterName << "\", \""
773 << pFilterParams << "\")";
775 catch (multipr::RuntimeException& e)
778 THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR);
781 // Mark current study as modified, if theObj is published in it
782 _engine->ObjModified(_this());
784 return mySeq._retn();
788 char* MULTIPR_Obj_i::evalDecimationParams(
789 const char* pPartName,
790 const char* pFieldName,
791 CORBA::Long pFieldIt,
792 const char* pFilterName,
793 const char* pFilterParams)
794 throw (SALOME::SALOME_Exception)
796 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
800 string res = mObj->evalDecimationParams(
808 MULTIPR::TPythonDump(_engine) << "dec_params = " << this << ".evalDecimationParams(\""
809 << pPartName << "\", \"" << pFieldName << "\", " << pFieldIt
810 << ", \"" << pFilterName << "\", \"" << pFilterParams
811 << "\") # " << res.c_str();
812 return CORBA::string_dup(res.c_str());
814 catch (multipr::RuntimeException& e)
817 THROW_SALOME_CORBA_EXCEPTION("Unable to evaluate decimation parameters", SALOME::INTERNAL_ERROR);
822 void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName)
823 throw (SALOME::SALOME_Exception)
825 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
827 mObj->removeParts(pPrefixPartName);
830 MULTIPR::TPythonDump(_engine) << this << ".removeParts(\"" << pPrefixPartName << "\")";
832 // Mark current study as modified, if theObj is published in it
833 _engine->ObjModified(_this());
836 char* MULTIPR_Obj_i::getMEDInfo(const char* pPartName)
837 throw (SALOME::SALOME_Exception)
839 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
842 mObj->getMEDInfo(res, const_cast<char*>(pPartName));
843 return CORBA::string_dup(res);
846 void MULTIPR_Obj_i::save(const char* pPath)
847 throw (SALOME::SALOME_Exception)
849 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
853 std::string strFile = mObj->getMEDFilename();
858 // Remove temporary files, if needed
863 // Remove temporary files, created during study loading, together with directory
864 std::string strPath = multipr::getPath(strFile.c_str());
866 //std::string cmd_rm ("del /F \"");
868 std::string cmd_rm ("rm -rf \"");
870 cmd_rm += strPath + "\"";
871 system(cmd_rm.c_str());
874 catch (multipr::RuntimeException& e)
877 THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR);
881 MULTIPR::TPythonDump(_engine) << this << ".save(\"" << pPath << "\")";
884 CORBA::Long MULTIPR_Obj_i::getSaveProgress()
886 return mObj->getProgress();
889 void MULTIPR_Obj_i::resetSaveProgress()
891 mObj->resetProgress();
894 //-----------------------------------------------------------------------------
895 // savePersistent and setEngine (for Persistence & Dump Python)
896 //-----------------------------------------------------------------------------
898 void MULTIPR_Obj_i::savePersistent (const char* pPath)
899 throw (SALOME::SALOME_Exception)
901 if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
905 mObj->savePersistent(pPath);
907 catch (multipr::RuntimeException& e)
910 THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR);
914 void MULTIPR_Obj_i::setEngine (MULTIPR_Gen_i* theEngine)
920 //-----------------------------------------------------------------------------
921 // Set/Get current study (for Persistence & Dump Python)
922 //-----------------------------------------------------------------------------
924 /*! Set current study
926 void MULTIPR_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy)
928 //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::SetCurrentStudy");
930 // theStudy or myCurrentStudy may be nil
931 if (!CORBA::is_nil(theStudy))
933 if (CORBA::is_nil(myCurrentStudy))
935 // move python trace of unknown study to the real study
936 int studyId = theStudy->StudyId();
937 if (myPythonScripts.find(-1) != myPythonScripts.end())
939 myPythonScripts[studyId].insert(myPythonScripts[studyId].begin(), // at
940 myPythonScripts[-1].begin(), // from
941 myPythonScripts[-1].end()); // to
942 myPythonScripts[-1].clear();
947 myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
950 /*! Get current study
952 SALOMEDS::Study_ptr MULTIPR_Gen_i::GetCurrentStudy()
954 //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID());
955 return SALOMEDS::Study::_duplicate(myCurrentStudy);
958 //-----------------------------------------------------------------------------
959 // SALOMEDS::Driver methods (Persistence & Dump Python)
960 //-----------------------------------------------------------------------------
962 /*! Get component data type
964 char* MULTIPR_Gen_i::ComponentDataType()
966 if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::ComponentDataType" );
967 return CORBA::string_dup( "MULTIPR" );
970 /*! Clears study-connected data when it is closed
972 void MULTIPR_Gen_i::Close (SALOMEDS::SComponent_ptr theComponent)
974 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::Close");
977 /*! Save MULTIPR module's data
979 SALOMEDS::TMPFile* MULTIPR_Gen_i::Save (SALOMEDS::SComponent_ptr theComponent,
983 INFOS( "MULTIPR_Gen_i::Save" );
985 if (myCurrentStudy->_is_nil() ||
986 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId())
987 SetCurrentStudy(theComponent->GetStudy());
989 // Store study contents as a set of python commands
990 SavePython(myCurrentStudy);
992 // Study name (for tmp directory and tmp files naming)
993 std::string aStudyName;
995 aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL());
997 // Declare a byte stream
998 SALOMEDS::TMPFile_var aStreamFile;
1000 SALOMEDS::ChildIterator_ptr obj_it (myCurrentStudy->NewChildIterator(theComponent));
1002 // TODO: iterate on all objects under theComponent
1003 if (!obj_it->More())
1004 return aStreamFile._retn();
1006 SALOMEDS::SObject_ptr aSObj = obj_it->Value();
1007 CORBA::Object_var anObj = aSObj->GetObject();
1008 MULTIPR_ORB::MULTIPR_Obj_ptr obj = MULTIPR_ORB::MULTIPR_Obj::_narrow(anObj);
1009 if (CORBA::is_nil(obj))
1010 return aStreamFile._retn();
1012 // Obtain a temporary directory
1013 std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
1015 // Directory for MED data to be stored in a distributed MED file
1016 std::string subDir = aStudyName + "_MULTIPR_MED";
1017 std::string meshDir = tmpDir + subDir;
1019 // Create a new dir <meshDir> to save the sequential/distributed file in.
1020 // Remove all the files in <meshDir> if they exist.
1022 std::string dirSeparator = "\\";
1023 //std::string cmd_mk ("mkdir /F \"");
1024 //std::string cmd_rm ("del /F \"");
1026 std::string dirSeparator = "/";
1027 std::string cmd_mk ("mkdir \"");
1028 std::string cmd_rm ("rm -rf \"");
1030 cmd_mk += meshDir + "\"";
1031 cmd_rm += meshDir + dirSeparator + "\"*";
1032 system(cmd_mk.c_str());
1033 system(cmd_rm.c_str());
1035 // Create a sequence of files processed
1036 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1038 if (obj->isValidSequentialMEDFile())
1040 std::string aFile = obj->getFilename();
1041 std::string aFileName = multipr::getFilenameWithoutPath(aFile.c_str());
1043 // Copy initial sequential MED file to <meshDir>
1045 std::string dirSeparator = "\\";
1046 //std::string cmd_cp ("copy \"");
1048 std::string dirSeparator = "/";
1049 std::string cmd_cp ("cp \"");
1051 cmd_cp += aFile + "\" \"" + meshDir + dirSeparator + "\"";
1052 system(cmd_cp.c_str());
1054 // Set names of temporary files
1055 std::string aFileNameRel = subDir + dirSeparator + aFileName;
1056 aFileSeq->length(1);
1057 aFileSeq[0] = CORBA::string_dup(aFileNameRel.c_str()); // sequential MED file
1059 else if (obj->isValidDistributedMEDFile())
1061 // Save distributed MED file to the <meshDir>
1062 PortableServer::Servant aServant = _poa->reference_to_servant(obj);
1063 MULTIPR_Obj_i* objServant = dynamic_cast<MULTIPR_Obj_i*>(aServant);
1067 return aStreamFile._retn();
1069 objServant->savePersistent(meshDir.c_str());
1071 // ASCII master file name
1072 std::string aMaitreFile = obj->getFilename();
1073 std::string aMaitreFileName = multipr::getFilenameWithoutPath(aMaitreFile.c_str());
1074 // just after partitionneDomaine() the state is MULTIPR_OBJ_STATE_DIS_MEM,
1075 // and getFilename() returns name of sequential file
1076 // (because distributed file is not created on disk yet). So, build the name:
1077 if (aMaitreFile == obj->getSeqFilename())
1079 std::string strExtension (".med");
1080 std::string strNamePrefix =
1081 multipr::removeExtension(aMaitreFileName.c_str(), strExtension.c_str());
1082 aMaitreFileName = strNamePrefix + "_grains_maitre" + strExtension;
1084 //std::string aMaitreFileName = SALOMEDS_Tool::GetNameFromPath(aMaitreFile);
1085 std::string aMaitreFileNameRel = subDir + dirSeparator + aMaitreFileName;
1087 // Set names of temporary files
1088 MULTIPR_ORB::string_array* listParts = obj->getParts();
1089 unsigned int nbParts = listParts->length();
1090 aFileSeq->length(nbParts + 1);
1092 char lMeshName[256];
1094 char lPartName[256];
1096 char lMEDFileName[256];
1098 for (unsigned int i = 0; i < nbParts; i++) // each part MED files
1100 const char* strPartName = (*listParts)[i];
1101 char* strPartInfo = obj->getPartInfo(strPartName);
1104 int ret = sscanf(strPartInfo, "%s %d %s %s %s",
1105 lMeshName, &lId, lPartName, lPath, lMEDFileName);
1110 return aStreamFile._retn();
1113 std::string aPartFileName = multipr::getFilenameWithoutPath(lMEDFileName);
1114 std::string aPartFileNameRel = subDir + dirSeparator + aPartFileName;
1116 aFileSeq[i] = CORBA::string_dup(aPartFileNameRel.c_str()); // part MED file
1118 aFileSeq[nbParts] = CORBA::string_dup(aMaitreFileNameRel.c_str()); // ASCII master file
1123 return aStreamFile._retn();
1126 // Convert temporary files to stream
1127 aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir, aFileSeq.in(), isMultiFile);
1129 // Remove temporary files and directory
1132 //SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir, aFileSeq.in(), true);
1133 // remove with shell command, because SALOMEDS_Tool::RemoveTemporaryFiles does not remove sub-folders
1135 //std::string cmd_rm ("del /F \"");
1137 std::string cmd_rm ("rm -rf \"");
1139 cmd_rm += tmpDir + "\"";
1140 system(cmd_rm.c_str());
1143 INFOS("MULTIPR_Gen_i::Save() completed");
1144 return aStreamFile._retn();
1147 /*! Save MULTIPR module's data in ASCII format
1149 SALOMEDS::TMPFile* MULTIPR_Gen_i::SaveASCII (SALOMEDS::SComponent_ptr theComponent,
1153 if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::SaveASCII" );
1154 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
1155 return aStreamFile._retn();
1158 /*! Load MULTIPR module's data
1160 bool MULTIPR_Gen_i::Load (SALOMEDS::SComponent_ptr theComponent,
1161 const SALOMEDS::TMPFile& theStream,
1165 INFOS("MULTIPR_Gen_i::Load");
1167 if (myCurrentStudy->_is_nil() ||
1168 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId())
1169 SetCurrentStudy(theComponent->GetStudy());
1171 // Get temporary files location
1172 std::string tmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
1174 INFOS("THE URL++++++++++++++");
1176 INFOS("THE TMP PATH+++++++++");
1177 INFOS(tmpDir.c_str());
1179 // For LocalPersistentIDToIOR():
1182 // Create a new dir <meshDir> to restore the distributed/sequential
1183 // MED file in. It is needed only if not multifile, because in
1184 // multifile study all required files are already on disk.
1187 std::string subDir = "_MULTIPR_MED";
1188 std::string meshDir = tmpDir + subDir;
1190 //std::string cmd_mk ("mkdir /F \"");
1192 std::string cmd_mk ("mkdir \"");
1194 cmd_mk += meshDir + "\"";
1195 system(cmd_mk.c_str());
1198 // Convert the stream into sequence of files to process
1199 SALOMEDS::ListOfFileNames_var aFileSeq =
1200 SALOMEDS_Tool::PutStreamToFiles(theStream, tmpDir.c_str(), isMultiFile);
1202 //TCollection_AsciiString aStudyName;
1204 // aStudyName = ((char*)SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL()).c_str());
1206 // Set names of "temporary" files
1207 //TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_MULTIPR.hdf" );
1208 //TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_MULTIPR_Mesh.med" );
1210 // Remove temporary files created from the stream
1212 // SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
1214 INFOS("MULTIPR_Gen_i::Load completed");
1218 /*! Load MULTIPR module's data in ASCII format
1220 bool MULTIPR_Gen_i::LoadASCII (SALOMEDS::SComponent_ptr theComponent,
1221 const SALOMEDS::TMPFile& theStream,
1225 if(MYDEBUG) MESSAGE( "MULTIPR_Gen_i::LoadASCII" );
1226 return Load(theComponent, theStream, theURL, isMultiFile);
1229 /*! Transform data from transient form to persistent
1231 char* MULTIPR_Gen_i::IORToLocalPersistentID (SALOMEDS::SObject_ptr /*theSObject*/,
1232 const char* IORString,
1233 CORBA::Boolean isMultiFile,
1234 CORBA::Boolean /*isASCII*/ )
1236 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID");
1238 MULTIPR_ORB::MULTIPR_Obj_ptr obj =
1239 MULTIPR_ORB::MULTIPR_Obj::_narrow(_orb->string_to_object(IORString));
1241 if (!CORBA::is_nil(obj))
1243 std::string aStudyName;
1245 aStudyName = SALOMEDS_Tool::GetNameFromPath(myCurrentStudy->URL());
1247 std::string subDir = aStudyName + "_MULTIPR_MED";
1249 std::string aFile = obj->getFilename();
1250 std::string aFileName = multipr::getFilenameWithoutPath(aFile.c_str());
1252 // Get servant (to call methods, not present in IDL interface
1253 PortableServer::Servant aServant = _poa->reference_to_servant(obj);
1254 MULTIPR_Obj_i* objServant = dynamic_cast<MULTIPR_Obj_i*>(aServant);
1258 return CORBA::string_dup("");
1261 std::string strSeparator ("|");
1262 if (obj->isValidSequentialMEDFile())
1266 sprintf(strBoxing, "%d", objServant->getBoxing());
1267 aFileName += strSeparator + strBoxing;
1270 std::string aMeshName = objServant->getMeshName();
1271 if (!aMeshName.empty())
1273 aFileName += strSeparator + aMeshName;
1276 else if (obj->isValidDistributedMEDFile())
1278 // just after partitionneDomaine() the state is MULTIPR_OBJ_STATE_DIS_MEM,
1279 // and getFilename() returns name of sequential file
1280 // (because distributed file is not created on disk yet). So, build the name:
1281 if (aFile == obj->getSeqFilename())
1283 std::string strExtension (".med");
1284 std::string strNamePrefix =
1285 multipr::removeExtension(aFileName.c_str(), strExtension.c_str());
1286 aFileName = strNamePrefix + "_grains_maitre" + strExtension;
1291 sprintf(strBoxing, "%d", objServant->getBoxing());
1292 aFileName += strSeparator + strBoxing;
1297 return CORBA::string_dup("");
1300 // PersistentID will be a relative path to MED file (relatively tmp dir)
1301 // plus additianal parameters, separated by '|' (see above)
1303 std::string dirSeparator = "\\";
1305 std::string dirSeparator = "/";
1307 aFileName = subDir + dirSeparator + aFileName;
1309 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::IORToLocalPersistentID: id = " << aFileName.c_str());
1311 return CORBA::string_dup(aFileName.c_str());
1313 return CORBA::string_dup("");
1316 /*! Transform data from persistent form to transient
1318 char* MULTIPR_Gen_i::LocalPersistentIDToIOR (SALOMEDS::SObject_ptr /*theSObject*/,
1319 const char* aLocalPersistentID,
1320 CORBA::Boolean isMultiFile,
1321 CORBA::Boolean /*isASCII*/)
1323 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID);
1325 if (strlen(aLocalPersistentID) > 0)
1327 // Extract relative path
1328 std::string strLocalPersistentID (aLocalPersistentID);
1329 int nb = strLocalPersistentID.find("|");
1330 if (nb < 1) nb = strLocalPersistentID.size();
1334 return CORBA::string_dup("");
1336 std::string strRelativePath = strLocalPersistentID.substr(0, nb);
1337 strLocalPersistentID.erase(0, nb); // erase <strRelativePath>
1338 if (strLocalPersistentID.size() > 0) strLocalPersistentID.erase(0, 1); // erase "|"
1340 // the only kind of available objects is a MULTIPR_ORB::MULTIPR_Obj,
1341 // representing a sequential or a distributed MED file.
1342 std::string medFilename = myTmpDir + strRelativePath; // myTmpDir already contains dir separator
1344 // create MULTIPR_Obj from file
1345 //MULTIPR_ORB::MULTIPR_Obj_ptr obj = getObject(medFilename.c_str());
1346 MULTIPR_Obj_i* obj_i = new MULTIPR_Obj_i (_poa,
1347 medFilename.c_str(),
1348 /*isPersistence = */true,
1350 obj_i->setEngine(this);
1351 MULTIPR_ORB::MULTIPR_Obj_ptr obj = obj_i->POA_MULTIPR_ORB::MULTIPR_Obj::_this();
1353 // Set boxing and mesh name, if provided
1354 nb = strLocalPersistentID.find("|");
1355 if (nb < 1) nb = strLocalPersistentID.size();
1358 std::string strBoxing = strLocalPersistentID.substr(0, nb);
1359 strLocalPersistentID.erase(0, nb); // erase <strBoxing>
1360 if (strLocalPersistentID.size() > 0) strLocalPersistentID.erase(0, 1); // erase "|"
1361 int aBoxing = atoi(strBoxing.c_str());
1362 obj->setBoxing(aBoxing);
1365 if (obj->isValidSequentialMEDFile())
1367 nb = strLocalPersistentID.size();
1370 std::string strMeshName = strLocalPersistentID.substr(0, nb);
1371 obj->setMesh(strMeshName.c_str());
1372 // we do not cut <strLocalPersistentID> here,
1373 // because we do not expect to find in it anything
1378 CORBA::String_var anIORString = _orb->object_to_string(obj);
1379 return CORBA::string_dup(anIORString);
1381 return CORBA::string_dup("");
1384 /*! Transform data from persistent form to transient
1386 Engines::TMPFile* MULTIPR_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
1387 CORBA::Boolean isPublished,
1388 CORBA::Boolean& isValidScript)
1390 isValidScript = false;
1392 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1393 if (CORBA::is_nil(aStudy))
1394 return new Engines::TMPFile(0);
1397 SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
1398 if (CORBA::is_nil(aSO))
1399 return new Engines::TMPFile(0);
1401 // Map study entries to object names
1402 Resource_DataMapOfAsciiStringAsciiString aMap;
1403 Resource_DataMapOfAsciiStringAsciiString aMapNames;
1405 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
1406 for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
1407 SALOMEDS::SObject_var aValue = Itr->Value();
1408 CORBA::String_var anID = aValue->GetID();
1409 CORBA::String_var aName = aValue->GetName();
1410 TCollection_AsciiString aGUIName ( (char*) aName.in() );
1411 TCollection_AsciiString anEnrty ( (char*) anID.in() );
1412 if (aGUIName.Length() > 0) {
1413 aMapNames.Bind( anEnrty, aGUIName );
1414 aMap.Bind( anEnrty, aGUIName );
1419 // Get trace of restored study
1420 SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
1421 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1422 SALOMEDS::GenericAttribute_var anAttr =
1423 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
1425 char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
1426 std::string aSavedTrace (oldValue);
1428 // Add trace of API methods calls and replace study entries by names
1429 std::string aScript;
1430 aScript += DumpPython_impl(aStudy->StudyId(), isPublished, isValidScript, aSavedTrace);
1432 int aLen = aScript.length();
1433 unsigned char* aBuffer = new unsigned char[aLen+1];
1434 strcpy((char*)aBuffer, aScript.c_str());
1436 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
1437 Engines::TMPFile_var aStreamFile = new Engines::TMPFile (aLen+1, aLen+1, anOctetBuf, 1);
1439 //bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen);
1440 //isValidScript = isValidScript && !hasNotPublishedObjects;
1442 return aStreamFile._retn();
1447 std::string MULTIPR_Gen_i::DumpPython_impl (int theStudyID,
1450 std::string theSavedTrace)
1453 std::string aGen = MULTIPR::TPythonDump::MULTIPRGenName();
1455 // set initial part of a script
1456 std::string aScript ("import salome\n");
1457 aScript += "import MULTIPR_ORB\n\n";
1458 aScript += "def RebuildData(theStudy):\n";
1460 aScript += helper + "\tmpr_comp = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"" +
1461 ComponentDataType() + "\")\n";
1462 aScript += helper + "\t" + aGen + " = mpr_comp._narrow(MULTIPR_ORB.MULTIPR_Gen)\n";
1464 //if ( isPublished )
1465 // aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)";
1467 // aScript += helper + "\t" + aGen + ".SetCurrentStudy(None)";
1468 aScript += helper + "\t" + aGen + ".SetCurrentStudy(theStudy)\n";
1470 // Dump trace of restored study
1471 if (theSavedTrace.length() > 0)
1473 aScript += helper + "\n" + theSavedTrace;
1476 // Dump trace of API methods calls
1477 std::string aNewLines = GetNewPythonLines(theStudyID);
1478 if (aNewLines.length() > 0)
1480 aScript += helper + "\n" + aNewLines;
1483 // add final part of a script
1484 //aScript += helper + "\n\tisGUIMode = " + isPublished;
1485 //aScript += "\n\tif isGUIMode and salome.sg.hasDesktop():";
1486 //aScript += "\n\t\tsalome.sg.updateObjBrowser(0)";
1487 aScript += "\n\n\tpass\n";
1489 aValidScript = true;
1494 /*! GetNewPythonLines
1496 std::string MULTIPR_Gen_i::GetNewPythonLines (int theStudyID)
1498 std::string aScript;
1500 // Dump trace of API methods calls
1501 if (myPythonScripts.find(theStudyID) != myPythonScripts.end())
1503 std::vector <std::string> aPythonScript = myPythonScripts[theStudyID];
1504 int istr, aLen = aPythonScript.size();
1505 for (istr = 0; istr < aLen; istr++)
1508 aScript += aPythonScript[istr];
1516 /*! CleanPythonTrace
1518 void MULTIPR_Gen_i::CleanPythonTrace (int theStudyID)
1520 // Clean trace of API methods calls
1521 if (myPythonScripts.find(theStudyID) != myPythonScripts.end())
1523 myPythonScripts[theStudyID].clear();
1527 /*! AddToPythonScript
1529 void MULTIPR_Gen_i::AddToPythonScript (int theStudyID, std::string theString)
1531 //if (myPythonScripts.find(theStudyID) == myPythonScripts.end())
1533 // myPythonScripts[theStudyID] = std::vector<std::string>;
1535 myPythonScripts[theStudyID].push_back(theString);
1540 void MULTIPR_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
1542 // Dump trace of API methods calls
1543 std::string aScript = GetNewPythonLines(theStudy->StudyId());
1545 // Check contents of PythonObject attribute
1546 SALOMEDS::SObject_var aSO = theStudy->FindComponent(ComponentDataType());
1547 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1548 SALOMEDS::GenericAttribute_var anAttr =
1549 aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
1551 char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
1552 std::string oldScript (oldValue);
1554 if (oldScript.length() > 0) {
1556 oldScript += aScript;
1559 oldScript = aScript;
1562 // Store in PythonObject attribute
1563 SALOMEDS::AttributePythonObject::_narrow(anAttr)->SetObject(oldScript.c_str(), 1);
1565 // Clean trace of API methods calls
1566 CleanPythonTrace(theStudy->StudyId());
1570 /*! Returns true if object can be published in the study
1572 bool MULTIPR_Gen_i::CanPublishInStudy (CORBA::Object_ptr theIOR)
1574 //if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy - " << !CORBA::is_nil(myCurrentStudy));
1575 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy");
1577 //if (CORBA::is_nil(myCurrentStudy))
1580 MULTIPR_ORB::MULTIPR_Obj_var anObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(theIOR);
1581 if (!anObj->_is_nil())
1584 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::CanPublishInStudy - CANNOT");
1588 /*! Publish object in the study
1590 SALOMEDS::SObject_ptr MULTIPR_Gen_i::PublishInStudy (SALOMEDS::Study_ptr theStudy,
1591 SALOMEDS::SObject_ptr theSObject,
1592 CORBA::Object_ptr theIOR,
1593 const char* theName)
1594 throw (SALOME::SALOME_Exception)
1596 //Unexpect aCatch(SALOME_SalomeException);
1598 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy");
1600 //if (myCurrentStudy->_is_nil() || theStudy->StudyId() != myCurrentStudy->StudyId())
1601 if (myCurrentStudy->_is_nil())
1602 SetCurrentStudy(theStudy);
1604 SALOMEDS::SObject_var aSO;
1605 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theIOR))
1608 // Publishing a MULTIPR_Object
1609 MULTIPR_ORB::MULTIPR_Obj_var anObj = MULTIPR_ORB::MULTIPR_Obj::_narrow(theIOR);
1610 if (!anObj->_is_nil())
1612 aSO = theStudy->FindObjectIOR(_orb->object_to_string(anObj));
1615 SALOMEDS::GenericAttribute_var anAttr;
1616 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1618 SALOMEDS::SComponent_var aFather = theStudy->FindComponent(ComponentDataType());
1619 if (aFather->_is_nil())
1621 aFather = aStudyBuilder->NewComponent(ComponentDataType());
1622 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
1623 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1624 aName->SetValue("MULTI-PR");
1625 //anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
1626 //SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_MULTIPR");
1627 //aStudyBuilder->DefineComponentInstance(aFather, MULTIPR_ORB::MULTIPR_Gen::_this());
1628 aStudyBuilder->DefineComponentInstance(aFather, MULTIPR_Gen::_this());
1630 if (aFather->_is_nil()) return aSO._retn();
1632 if (CORBA::is_nil(theSObject))
1634 aSO = aStudyBuilder->NewObject(aFather);
1638 if (!theSObject->ReferencedObject(aSO))
1639 aSO = SALOMEDS::SObject::_duplicate(theSObject);
1642 anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1643 SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
1644 CORBA::String_var anIOR = _orb->object_to_string(anObj);
1645 anIORAttr->SetValue(anIOR);
1647 //anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap");
1648 //SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1649 //aPixmap->SetPixMap("ICON_OBJBROWSER_GROUP_PNT");
1651 anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1652 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1653 if (strlen(theName) == 0)
1654 aNameAttrib->SetValue(anObj->getFilename());
1656 aNameAttrib->SetValue(theName);
1659 MULTIPR::TPythonDump(this) << "sobj = " << this << ".PublishInStudy(theStudy, "
1660 << theSObject << ", " << anObj << ", \"" << theName
1661 << "\") # " << aSO->GetID();
1665 if(MYDEBUG) MESSAGE("MULTIPR_Gen_i::PublishInStudy - END");
1671 SALOMEDS::SComponent_ptr _Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
1673 if ( CORBA::is_nil( theStudy ))
1674 return SALOMEDS::SComponent::_nil();
1675 if(MYDEBUG) MESSAGE("PublishComponent");
1677 SALOMEDS::SComponent_var father =
1678 SALOMEDS::SComponent::_narrow( theStudy->FindComponent( ComponentDataType() ) );
1679 if ( !CORBA::is_nil( father ) )
1680 return father._retn();
1682 SALOME_ModuleCatalog::ModuleCatalog_var aCat =
1683 SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
1684 if ( CORBA::is_nil( aCat ) )
1685 return father._retn();
1687 SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( ComponentDataType() );
1688 if ( CORBA::is_nil( aComp ) )
1689 return father._retn();
1691 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1692 SALOMEDS::GenericAttribute_var anAttr;
1693 SALOMEDS::AttributePixMap_var aPixmap;
1695 father = aStudyBuilder->NewComponent( ComponentDataType() );
1696 aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
1697 anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
1698 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
1699 aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
1700 SetName( father, aComp->componentusername(), "MESH" );
1701 if(MYDEBUG) MESSAGE("PublishComponent--END");
1703 return father._retn();
1709 * MULTIPREngine_factory
1711 * C factory, accessible with dlsym, after dlopen
1715 PortableServer::ObjectId* MULTIPREngine_factory(
1717 PortableServer::POA_ptr poa,
1718 PortableServer::ObjectId * contId,
1719 const char* instanceName,
1720 const char* interfaceName)
1722 MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()");
1723 SCRUTE(interfaceName);
1724 MULTIPR_Gen_i* myMULTIPR = new MULTIPR_Gen_i(orb, poa, contId, instanceName, interfaceName);
1725 return myMULTIPR->getId();