Salome HOME
1474d24ef9caf7fe34f523497b88eb5829107e03
[modules/visu.git] / src / VISU_I / VISU_DumpPython.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //  File   : VISU_DumpPython.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_Gen_i.hh"
28 #include "VISU_Result_i.hh"
29 #include "VISU_PrsObject_i.hh"
30
31 #include "VISU_Prs3d_i.hh"
32 #include "VISU_Mesh_i.hh"
33 #include "VISU_ScalarMap_i.hh"
34 #include "VISU_IsoSurfaces_i.hh"
35 #include "VISU_DeformedShape_i.hh"
36 #include "VISU_CutPlanes_i.hh"
37 #include "VISU_CutLines_i.hh"
38 #include "VISU_Vectors_i.hh"
39 #include "VISU_StreamLines_i.hh"
40 #include "VISU_Table_i.hh"
41
42 #include "utilities.h"
43
44 #include <cctype>       
45 #include <strstream>    
46 #include <functional>   
47
48 #include <qstring.h>
49 #include <qfileinfo.h>
50
51 //#define COUT
52
53 using namespace std;
54
55 namespace VISU{
56   static std::string PREFIX("  ");
57
58   typedef std::map<std::string,std::string> TName2EntryMap;
59   typedef std::map<std::string,std::string> TEntry2NameMap;
60
61   inline
62   std::string 
63   GenerateName(std::string theName, 
64                SALOMEDS::SObject_ptr theSObject,
65                TName2EntryMap& theName2EntryMap,
66                TEntry2NameMap& theEntry2NameMap,
67                char theSuffix)
68   {
69     if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
70       theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
71     }else{
72       CORBA::String_var anID = theSObject->GetID();
73       theName2EntryMap[theName] = anID.in();
74       theEntry2NameMap[anID.in()] = theName;
75       //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
76     }
77
78     return theName;
79   }
80
81   struct TReplacePredicate{
82     bool operator()(char theChar) const
83     {
84       return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
85     }
86   };
87
88   inline
89   std::string 
90   GetName(SALOMEDS::SObject_ptr theSObject)
91   {
92     CORBA::String_var aString = theSObject->GetName();
93
94     std::string aName = QString(aString.in()).simplifyWhiteSpace().latin1();
95
96     //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
97     replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
98
99     if ( isdigit( aName[0] ))
100       aName.insert( 0, 1, 'a' );
101
102     return aName;
103   }
104
105   inline
106   std::string 
107   GenerateName(SALOMEDS::SObject_ptr theSObject,
108                TName2EntryMap& theName2EntryMap,
109                TEntry2NameMap& theEntry2NameMap)
110   {
111     std::string aName = GetName(theSObject);
112
113     return GenerateName(aName,theSObject,theName2EntryMap,theEntry2NameMap,'X');
114   }
115
116
117   //===========================================================================
118   typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
119                                 CORBA::Boolean theIsPublished,
120                                 CORBA::Boolean& theIsValidScript,
121                                 SALOMEDS::SObject_ptr theSObject,
122                                 std::ostream& theStr,
123                                 TName2EntryMap& theName2EntryMap,
124                                 TEntry2NameMap& theEntry2NameMap,
125                                 std::string theArgumentName,
126                                 std::string thePrefix);
127
128
129   void
130   DumpToPython(SALOMEDS::Study_ptr theStudy,
131                CORBA::Boolean theIsPublished,
132                CORBA::Boolean& theIsValidScript,
133                SALOMEDS::SObject_ptr theSObject,
134                std::ostream& theStr,
135                TName2EntryMap& theName2EntryMap,
136                TEntry2NameMap& theEntry2NameMap,
137                std::string theArgumentName,
138                std::string thePrefix);
139
140
141   //===========================================================================
142   std::string
143   ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
144                     VISU::ScalarMap_i* theServant, 
145                     std::ostream& theStr,
146                     std::string& theName,
147                     const std::string& theConstructorName,
148                     const std::string& theArgumentName,
149                     std::string thePrefix)
150   {
151     std::string aParam;
152     switch(theServant->GetEntity()){
153     case NODE:
154       aParam = "VISU.NODE";
155       break;
156     case EDGE:
157       aParam = "VISU.EDGE";
158       break;
159     case FACE:
160       aParam = "VISU.FACE";
161       break;
162     case CELL:
163       aParam = "VISU.CELL";
164       break;
165     }
166
167     theStr<<thePrefix<<theName<<" = aVisu."<<theConstructorName<<"("<<theArgumentName<<
168       ",'"<<theServant->GetMeshName()<<"'"<<
169       ","<<aParam<<
170       ",'"<<theServant->GetFieldName()<<"'"<<
171       ","<<theServant->GetIteration()<<
172       ")"<<endl;
173
174     theStr<<thePrefix<<"if "<<theName<<":"<<endl;
175     thePrefix += PREFIX;
176
177     theStr<<thePrefix<<"aName2ObjectMap['"<<theName<<"'] = "<<theName<<endl;
178
179     theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
180     
181     switch(theServant->GetScaling()){
182     case LINEAR:
183       aParam = "VISU.LINEAR";
184       break;
185     case LOGARITHMIC:
186       aParam = "VISU.LOGARITHMIC";
187       break;
188     }
189     theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
190     theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<","<<theServant->GetMax()<<")"<<endl;
191     
192     switch(theServant->GetBarOrientation()){
193     case ScalarMap::HORIZONTAL:
194       aParam = "VISU.ScalarMap.HORIZONTAL";
195       break;
196     case ScalarMap::VERTICAL:
197       aParam = "VISU.ScalarMap.VERTICAL";
198       break;
199     }
200     theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
201     
202     theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<","<<theServant->GetPosY()<<")"<<endl;
203     theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<","<<theServant->GetHeight()<<")"<<endl;
204     theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
205     theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
206     theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
207
208     return thePrefix;
209   }
210
211
212   //===========================================================================
213   std::string
214   DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
215                         VISU::DeformedShape_i* theServant, 
216                         std::ostream& theStr,
217                         std::string& theName,
218                         const std::string& theConstructorName,
219                         const std::string& theArgumentName,
220                         std::string thePrefix)
221   {
222     thePrefix = ScalarMapToPython(theSObject,theServant,theStr,theName,theConstructorName,theArgumentName,thePrefix);
223     theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
224     theStr<<thePrefix<<theName<<".ShowColored("<<theServant->IsColored()<<")"<<endl;
225     SALOMEDS::Color aColor = theServant->GetColor();
226     theStr<<thePrefix<<theName<<".SetColor(SALOMEDS.Color("<<
227       aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
228
229     return thePrefix;
230   }
231
232   
233   //===========================================================================
234   template<class TTableAttr>
235   void
236   TableAttrToPython(SALOMEDS::Study_ptr theStudy,
237                     CORBA::Boolean theIsPublished,
238                     CORBA::Boolean& theIsValidScript,
239                     SALOMEDS::SObject_ptr theSObject,
240                     TTableAttr theTableAttr,
241                     const std::string& theAttrName,
242                     std::ostream& theStr,
243                     TName2EntryMap& theName2EntryMap,
244                     TEntry2NameMap& theEntry2NameMap,
245                     std::string theArgumentName,
246                     std::string thePrefix)
247   {
248     SALOMEDS::GenericAttribute_var anAttr; 
249     SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
250     if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){
251       SALOMEDS::AttributeComment_var aComment = 
252         SALOMEDS::AttributeComment::_narrow(anAttr);
253       CORBA::String_var aValue = aComment->Value();
254       Storable::TRestoringMap aMap;       
255       Storable::StrToMap(aValue.in(),aMap);
256       bool anIsExist;
257       QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
258       if(anIsExist){
259         if(strcmp(aMethodName.latin1(),"ImportTables") == 0){
260           return;
261         }
262       }
263     }
264
265     std::string aSObjectName = GetName(theSObject);
266     theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
267     theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
268     thePrefix += PREFIX;
269
270     std::string aName = "aTableAttr";
271     theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
272       aSObjectName<<",'"<<theAttrName<<"')"<<endl;
273
274     theStr<<thePrefix<<"if "<<aName<<":"<<endl;
275     std::string aPrefix = thePrefix;
276     thePrefix += PREFIX;
277
278     CORBA::String_var aString = theTableAttr->GetTitle();
279     theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
280
281     CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
282     theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
283
284     CORBA::Long aNbRows = theTableAttr->GetNbRows();
285
286     // push values and their indices into streams
287     strstream values, rows, columns;
288     string comma = "";
289     for(CORBA::Long i = 1; i <= aNbColumns; i++){
290       for(CORBA::Long j = aNbRows; j > 0; j--){
291         if(theTableAttr->HasValue(j,i)){
292           values  << comma << theTableAttr->GetValue(j,i);
293           rows    << comma << j;
294           columns << comma << i;
295           if ( comma.empty() )
296             comma = ",";
297         }
298       }
299     }
300     // push titles and units into streams
301     strstream rowUnits, rowTitles, colTitles;
302     SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
303     SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
304     comma = "";
305     for(CORBA::Long j = 1; j <= aNbRows; j++){
306       rowUnits  << comma << "'" << aRowUnits [ j - 1 ] << "'";
307       rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
308       if ( comma.empty() )
309         comma = ",";
310     }
311     SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
312     comma = "";
313     for(CORBA::Long j = 1; j <= aNbColumns; j++){
314       colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
315       if ( comma.empty() )
316         comma = ",";
317     }
318     values    << '\0';
319     rows      << '\0';
320     columns   << '\0';
321     rowUnits  << '\0';
322     rowTitles << '\0';
323     colTitles << '\0';
324     // write FillTable command
325     theStr<< thePrefix << aName << "_values  = [" << values.str()  << "]" << endl;
326     theStr<< thePrefix << aName << "_rows    = [" << rows.str()    << "]" << endl;
327     theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
328     theStr<< thePrefix << aName << "_rUnits  = [" << rowUnits.str()  << "]" << endl;
329     theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
330     theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
331     theStr<< thePrefix << "visu.FillTable( "
332       << aName << ", "
333         << aName << "_values, "
334           << aName << "_rows, "
335             << aName << "_columns, "
336               << aName << "_rTitles, "
337                 << aName << "_rUnits, "
338                   << aName << "_cTitles )" << endl;
339
340     if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
341       theStr<<endl;
342       std::string aName = "aTable";
343       theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
344       theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
345       theArgumentName = aName;
346       
347       theStr<<thePrefix<<"if "<<aName<<":"<<endl;
348       std::string aPrefix2 = thePrefix + PREFIX;
349
350       DumpChildrenToPython(theStudy,
351                            theIsPublished,
352                            theIsValidScript,
353                            theSObject,
354                            theStr,
355                            theName2EntryMap,
356                            theEntry2NameMap,
357                            theArgumentName,
358                            aPrefix2);
359
360       theStr<<aPrefix2<<"pass"<<endl<<endl;
361     }
362
363     theStr<<thePrefix<<"pass"<<endl<<endl;
364     theStr<<aPrefix<<"pass"<<endl<<endl;
365   }
366
367
368   //===========================================================================
369   void
370   DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
371                        CORBA::Boolean theIsPublished,
372                        CORBA::Boolean& theIsValidScript,
373                        SALOMEDS::SObject_ptr theSObject,
374                        std::ostream& theStr,
375                        TName2EntryMap& theName2EntryMap,
376                        TEntry2NameMap& theEntry2NameMap,
377                        std::string theArgumentName,
378                        std::string thePrefix)
379   {
380     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
381     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
382       SALOMEDS::SObject_var aSObject = aChildItet->Value();
383       DumpToPython(theStudy,
384                    theIsPublished,
385                    theIsValidScript,
386                    aSObject,
387                    theStr,
388                    theName2EntryMap,
389                    theEntry2NameMap,
390                    theArgumentName,
391                    thePrefix);
392     }
393   }
394
395
396   //===========================================================================
397   void
398   DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
399                         CORBA::Boolean theIsPublished,
400                         CORBA::Boolean& theIsValidScript,
401                         SALOMEDS::SObject_ptr theSObject,
402                         std::ostream& theStr,
403                         TName2EntryMap& theName2EntryMap,
404                         TEntry2NameMap& theEntry2NameMap,
405                         std::string theArgumentName,
406                         std::string thePrefix)
407   {
408     SALOMEDS::GenericAttribute_var anAttr;
409     if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
410       SALOMEDS::AttributeTableOfInteger_var aTableAttr =  
411         SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
412       
413       TableAttrToPython(theStudy,
414                         theIsPublished,
415                         theIsValidScript,
416                         theSObject,
417                         aTableAttr,
418                         "AttributeTableOfInteger",
419                         theStr,
420                         theName2EntryMap,
421                         theEntry2NameMap,
422                         theArgumentName,
423                         thePrefix);
424       
425     }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
426       SALOMEDS::AttributeTableOfReal_var aTableAttr =  
427         SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
428       
429       TableAttrToPython(theStudy,
430                         theIsPublished,
431                         theIsValidScript,
432                         theSObject,
433                         aTableAttr,
434                         "AttributeTableOfReal",
435                         theStr,
436                         theName2EntryMap,
437                         theEntry2NameMap,
438                         theArgumentName,
439                         thePrefix);
440     }
441   }
442
443
444   //===========================================================================
445   void
446   DumpToPython(SALOMEDS::Study_ptr theStudy,
447                CORBA::Boolean theIsPublished,
448                CORBA::Boolean& theIsValidScript,
449                SALOMEDS::SObject_ptr theSObject,
450                std::ostream& theStr,
451                TName2EntryMap& theName2EntryMap,
452                TEntry2NameMap& theEntry2NameMap,
453                std::string theArgumentName,
454                std::string thePrefix)
455   {
456     std::string aName = GetName(theSObject);
457     if(aName == "")
458       return;
459
460     CORBA::Object_var anObj = SObjectToObject(theSObject);
461     if(!CORBA::is_nil(anObj)){
462       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
463       if(!CORBA::is_nil(aBase)){
464         std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
465         CORBA::String_var anID = theSObject->GetID();
466
467         VISU::VISUType aType = aBase->GetType();
468         switch(aType){
469         case VISU::TRESULT:
470           if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
471             std::string aFileName = aServant->GetFileName();
472             Result_i::ECreationId anId = aServant->GetCreationId();
473             if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
474               switch(anId){
475               case Result_i::eImportFile:
476                 theStr<<thePrefix<<aName<<" = aVisu.ImportFile('"<<aFileName<<"')"<<endl;
477                 break;
478               case Result_i::eCopyAndImportFile: 
479                 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
480                 break;
481               }
482
483               theStr<<thePrefix<<"if "<<aName<<":"<<endl;
484               thePrefix += PREFIX;
485               
486               theArgumentName = aName;
487               DumpChildrenToPython(theStudy,
488                                    theIsPublished,
489                                    theIsValidScript,
490                                    theSObject,
491                                    theStr,
492                                    theName2EntryMap,
493                                    theEntry2NameMap,
494                                    theArgumentName,
495                                    thePrefix);
496               
497               theStr<<thePrefix<<"pass"<<endl<<endl;
498             }else{
499               SALOMEDS::SObject_var aRefSObj;
500               if(theSObject->FindSubObject(1,aRefSObj)){
501                 SALOMEDS::SObject_var aTargetRefSObj;
502                 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
503                   CORBA::String_var aString = aTargetRefSObj->GetName();
504                   theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
505                   theStr<<thePrefix<<"if aSObject:"<<endl;
506                   thePrefix += PREFIX;
507                   theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
508                   theStr<<thePrefix<<"if anObject:"<<endl;
509                   std::string aPrefix1 = thePrefix;
510                   thePrefix += PREFIX;
511
512                   switch(anId){
513                   case Result_i::eImportMed: 
514                     theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
515                     break;
516                   case Result_i::eImportMedField:
517                     theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
518                     break;
519                   }
520
521                   theStr<<thePrefix<<"if "<<aName<<":"<<endl;
522                   std::string aPrefix2 = thePrefix;
523                   thePrefix += PREFIX;
524                   
525                   theArgumentName = aName;
526                   DumpChildrenToPython(theStudy,
527                                        theIsPublished,
528                                        theIsValidScript,
529                                        theSObject,
530                                        theStr,
531                                        theName2EntryMap,
532                                        theEntry2NameMap,
533                                        theArgumentName,
534                                        thePrefix);
535               
536                   theStr<<thePrefix<<"pass"<<endl<<endl;
537                   theStr<<aPrefix2<<"pass"<<endl<<endl;
538                   theStr<<aPrefix1<<"pass"<<endl<<endl;
539                 }
540               }
541             }
542           }
543           return;
544         case VISU::TMESH:
545           if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
546             VISU::Entity anEntity = aServant->GetEntity();
547             const std::string& aSubMeshName = aServant->GetSubMeshName();
548             if(anEntity >= 0){
549               std::string aParam;
550               switch(anEntity){
551               case NODE:
552                 aParam = "VISU.NODE";
553                 break;
554               case EDGE:
555                 aParam = "VISU.EDGE";
556                 break;
557               case FACE:
558                 aParam = "VISU.FACE";
559                 break;
560               case CELL:
561                 aParam = "VISU.CELL";
562                 break;
563               }
564               
565               if(aSubMeshName == "")
566                 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
567                   ",'"<<aServant->GetMeshName()<<"'"<<
568                   ","<<aParam<<
569                   ")"<<endl;
570               else
571                 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
572                   ",'"<<aServant->GetMeshName()<<"'"<<
573                   ","<<aParam<<
574                   ",'"<<aSubMeshName<<"'"<<
575                   ")"<<endl;
576             }else
577               theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
578                 ",'"<<aServant->GetMeshName()<<"'"<<
579                 ",'"<<aSubMeshName<<"'"<<
580                 ")"<<endl;
581             
582             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
583             thePrefix += PREFIX;
584
585             theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
586
587             SALOMEDS::Color aColor;
588             aColor = aServant->GetCellColor();
589             theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
590               aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
591             
592             aColor = aServant->GetNodeColor();
593             theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
594               aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
595             
596             aColor = aServant->GetLinkColor();
597             theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
598               aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
599             
600             std::string aParam;
601             switch(aServant->GetPresentationType()){
602             case POINT:
603               aParam = "VISU.POINT";
604               break;
605             case WIREFRAME:
606               aParam = "VISU.WIREFRAME";
607               break;
608             case SHADED:
609               aParam = "VISU.SHADED";
610               break;
611             case INSIDEFRAME:
612               aParam = "VISU.INSIDEFRAME";
613               break;
614             case SURFACEFRAME:
615               aParam = "VISU.SURFACEFRAME";
616               break;
617             case SHRINK:
618               aParam = "VISU.SHRINK";
619               break;
620             }
621             theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
622             theStr<<endl;
623
624             DumpChildrenToPython(theStudy,
625                                  theIsPublished,
626                                  theIsValidScript,
627                                  theSObject,
628                                  theStr,
629                                  theName2EntryMap,
630                                  theEntry2NameMap,
631                                  theArgumentName,
632                                  thePrefix);
633               
634             theStr<<thePrefix<<"pass"<<endl<<endl;
635             return;
636           }
637           break;
638         case VISU::TSCALARMAP:
639           if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
640             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"ScalarMapOnField",theArgumentName,thePrefix);
641             theStr<<thePrefix<<"pass"<<endl<<endl;
642           }
643           return;
644         case VISU::TDEFORMEDSHAPE:
645           if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
646             thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"DeformedShapeOnField",theArgumentName,thePrefix);
647             theStr<<thePrefix<<"pass"<<endl<<endl;
648           }
649           return;
650         case VISU::TSTREAMLINES:
651           if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
652             thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"StreamLinesOnField",theArgumentName,thePrefix);
653             
654             std::string aParam;
655             switch(aServant->GetDirection()){
656             case StreamLines::FORWARD:
657               aParam = "VISU.StreamLines.FORWARD";
658               break;
659             case StreamLines::BACKWARD:
660               aParam = "VISU.StreamLines.BACKWARD";
661               break;
662             case StreamLines::BOTH:
663               aParam = "VISU.StreamLines.BOTH";
664               break;
665             }
666
667             theStr<<thePrefix<<"aPrs3d = None"<<endl;
668             VISU::Prs3d_var aPrs3d = aServant->GetSource();
669             if(!CORBA::is_nil(aPrs3d)){
670               if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
671                 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
672                 CORBA::String_var anID = aSObject->GetID();
673                 std::string anArg = theEntry2NameMap[anID.in()];
674                 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
675                 thePrefix += PREFIX;
676                 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
677               }
678             }
679             
680             theStr<<thePrefix<<aName<<".SetParams("<<
681               aServant->GetIntegrationStep()<<","<<
682               aServant->GetPropagationTime()<<","<<
683               aServant->GetStepLength()<<","<<
684               "aPrs3d"<<","<<
685               aServant->GetUsedPoints()<<","<<
686               aParam<<
687               ")"<<endl;
688
689             theStr<<thePrefix<<"pass"<<endl<<endl;
690           }
691           return;
692         case VISU::TVECTORS:
693           if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
694             thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"VectorsOnField",theArgumentName,thePrefix);
695             
696             theStr<<thePrefix<<aName<<".SetLineWidth("<<aServant->GetLineWidth()<<")"<<endl;
697             
698             std::string aParam;
699             switch(aServant->GetGlyphType()){
700             case Vectors::ARROW:
701               aParam = "VISU.Vectors.ARROW";
702               break;
703             case Vectors::CONE2:
704               aParam = "VISU.Vectors.CONE2";
705               break;
706             case Vectors::CONE6:
707               aParam = "VISU.Vectors.CONE6";
708               break;
709             case Vectors::NONE:
710               aParam = "VISU.Vectors.NONE";
711               break;
712             }
713             theStr<<thePrefix<<aName<<".SetGlyphType("<<aParam<<")"<<endl;
714             
715             switch(aServant->GetGlyphPos()){
716             case Vectors::CENTER:
717               aParam = "VISU.Vectors.CENTER";
718               break;
719             case Vectors::TAIL:
720               aParam = "VISU.Vectors.TAIL";
721               break;
722             case Vectors::HEAD:
723               aParam = "VISU.Vectors.HEAD";
724               break;
725             }
726             theStr<<thePrefix<<aName<<".SetGlyphPos("<<aParam<<")"<<endl;
727
728             theStr<<thePrefix<<"pass"<<endl<<endl;
729           }
730           return;
731         case VISU::TISOSURFACE:
732           if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
733             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"IsoSurfacesOnField",theArgumentName,thePrefix);
734             theStr<<thePrefix<<aName<<".SetNbSurfaces("<<aServant->GetNbSurfaces()<<")"<<endl;
735             theStr<<thePrefix<<"pass"<<endl<<endl;
736           }
737           return;
738         case VISU::TCUTPLANES:
739           if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
740             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutPlanesOnField",theArgumentName,thePrefix);
741             
742             std::string aParam;
743             switch(aServant->GetOrientationType()){
744             case CutPlanes::XY:
745               aParam = "VISU.CutPlanes.XY";
746               break;
747             case CutPlanes::YZ:
748               aParam = "VISU.CutPlanes.YZ";
749               break;
750             case CutPlanes::ZX:
751               aParam = "VISU.CutPlanes.ZX";
752               break;
753             }
754             theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
755             
756             theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
757             CORBA::Long aNbPlanes = aServant->GetNbPlanes();
758             theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
759             
760             for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
761               if(!aServant->IsDefault(anId))
762                 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
763             }
764
765             theStr<<thePrefix<<"pass"<<endl<<endl;
766           }
767           return;
768         case VISU::TCUTLINES:
769           if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
770             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutLinesOnField",theArgumentName,thePrefix);
771             
772             std::string aParam;
773             switch(aServant->GetOrientationType()){
774             case CutPlanes::XY:
775               aParam = "VISU.CutPlanes.XY";
776               break;
777             case CutPlanes::YZ:
778               aParam = "VISU.CutPlanes.YZ";
779               break;
780             case CutPlanes::ZX:
781               aParam = "VISU.CutPlanes.ZX";
782               break;
783             }
784             theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
785             
786             switch(aServant->GetOrientationType2()){
787             case CutPlanes::XY:
788               aParam = "VISU.CutPlanes.XY";
789               break;
790             case CutPlanes::YZ:
791               aParam = "VISU.CutPlanes.YZ";
792               break;
793             case CutPlanes::ZX:
794               aParam = "VISU.CutPlanes.ZX";
795               break;
796             }
797             theStr<<thePrefix<<aName<<".SetOrientation2("<<aParam<<","<<aServant->GetRotateX2()<<","<<aServant->GetRotateY2()<<")"<<endl;
798             
799             theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
800             theStr<<thePrefix<<aName<<".SetDisplacement2("<<aServant->GetDisplacement2()<<")"<<endl;
801             
802             if(!aServant->IsDefault())
803               theStr<<thePrefix<<aName<<".SetBasePlanePosition("<<aServant->GetBasePlanePosition()<<")"<<endl;
804             
805             CORBA::Long aNbLines = aServant->GetNbLines();
806             theStr<<thePrefix<<aName<<".SetNbLines("<<aNbLines<<")"<<endl;
807             for(CORBA::Long anId = 0; anId < aNbLines; anId++){
808               if(!aServant->IsDefaultPosition(anId))
809                 theStr<<thePrefix<<aName<<".SetLinePosition("<<anId<<","<<aServant->GetLinePosition(anId)<<")"<<endl;
810             }
811
812             theStr<<endl;
813
814             theArgumentName = aName;
815             DumpChildrenToPython(theStudy,
816                                  theIsPublished,
817                                  theIsValidScript,
818                                  theSObject,
819                                  theStr,
820                                  theName2EntryMap,
821                                  theEntry2NameMap,
822                                  theArgumentName,
823                                  thePrefix);
824
825             theStr<<thePrefix<<"pass"<<endl<<endl;
826           }
827           return;
828         case VISU::TCURVE:
829           if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
830           {
831             theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve(" <<
832               theArgumentName<< // table
833                 ","<<aServant->GetHRow()<< // H row
834                   ","<<aServant->GetVRow()<< // V row
835                     ",'"<<aServant->GetTitle()<<"'"; // title
836             SALOMEDS::Color aColor = aServant->GetColor();
837             theStr << ",SALOMEDS.Color("<<
838               aColor.R<<","<<aColor.G<<","<<aColor.B<<")"; // color
839             
840             std::string aParam;
841             switch(aServant->GetMarker()){
842             case Curve::NONE:      aParam = "VISU.Curve.NONE";      break;
843             case Curve::CIRCLE:    aParam = "VISU.Curve.CIRCLE";    break;
844             case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
845             case Curve::DIAMOND:   aParam = "VISU.Curve.DIAMOND";   break;
846             case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
847             case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
848             case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
849             case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
850             case Curve::CROSS:     aParam = "VISU.Curve.CROSS";     break;
851             case Curve::XCROSS:    aParam = "VISU.Curve.XCROSS";    break;
852             }
853             theStr<<","<<aParam; // marker
854
855             switch(aServant->GetLine()){
856             case Curve::VOIDLINE:       aParam = "VISU.Curve.VOIDLINE";       break;
857             case Curve::SOLIDLINE:      aParam = "VISU.Curve.SOLIDLINE";      break;
858             case Curve::DASHLINE:       aParam = "VISU.Curve.DASHLINE";       break;
859             case Curve::DOTLINE:        aParam = "VISU.Curve.DOTLINE";        break;
860             case Curve::DASHDOTLINE:    aParam = "VISU.Curve.DASHDOTLINE";    break;
861             case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
862             }
863             theStr<<","<<aParam<<","<<aServant->GetLineWidth()<<")"<<endl; // line type,width
864           }
865           return;
866         case VISU::TTABLE:
867           if(Table_i* aServant = dynamic_cast<Table_i*>(GetServant(anObj).in())){
868             SALOMEDS::SObject_var aSObject = aServant->GetSObject();
869             SALOMEDS::GenericAttribute_var anAttr;
870             if(theSObject->FindAttribute(anAttr,"AttributeComment")){
871               using namespace SALOMEDS;
872               AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
873               CORBA::String_var aValue = aComment->Value();
874               Storable::TRestoringMap aMap;       
875               Storable::StrToMap(aValue.in(),aMap);
876               bool anIsExist;
877               QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
878               if(anIsExist){
879                 if(strcmp(aSourceId.latin1(),"CutLines") == 0){
880                   theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
881                   thePrefix += PREFIX;
882
883                   theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
884                   theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
885                   theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
886                   theStr<<thePrefix<<"if aSObject:"<<endl;
887                   std::string aPrefix = thePrefix;
888                   thePrefix += PREFIX;
889
890                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
891                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
892                   theStr<<endl;
893                   
894                   theArgumentName = aName;
895                   DumpChildrenToPython(theStudy,
896                                        theIsPublished,
897                                        theIsValidScript,
898                                        theSObject,
899                                        theStr,
900                                        theName2EntryMap,
901                                        theEntry2NameMap,
902                                        theArgumentName,
903                                        thePrefix);
904                   
905                   theStr<<thePrefix<<"pass"<<endl<<endl;
906                   theStr<<aPrefix<<"pass"<<endl<<endl;
907                 }else if(strcmp(aSourceId.latin1(),"TableFile") == 0){
908                   CORBA::Short aTag = theSObject->Tag();
909                   theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
910                   theStr<<thePrefix<<"if anIsFound:"<<endl;
911                   thePrefix += PREFIX;
912                   
913                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
914                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
915                   theStr<<endl;
916
917                   theArgumentName = aName;
918                   DumpChildrenToPython(theStudy,
919                                        theIsPublished,
920                                        theIsValidScript,
921                                        theSObject,
922                                        theStr,
923                                        theName2EntryMap,
924                                        theEntry2NameMap,
925                                        theArgumentName,
926                                        thePrefix);
927                   
928                   theStr<<thePrefix<<"pass"<<endl<<endl;
929                 }else if(strcmp(aSourceId.latin1(),"TableAttr") == 0){
930                   theArgumentName = aName;
931                   DumpTableAttrToPython(theStudy,
932                                         theIsPublished,
933                                         theIsValidScript,
934                                         theSObject,
935                                         theStr,
936                                         theName2EntryMap,
937                                         theEntry2NameMap,
938                                         theArgumentName,
939                                         thePrefix);
940                 }
941               }
942             }
943           }
944           return;
945         }
946       }
947     }else{
948       SALOMEDS::GenericAttribute_var anAttr;
949       if(theSObject->FindAttribute(anAttr,"AttributeComment")){
950         SALOMEDS::AttributeComment_var aComment = 
951           SALOMEDS::AttributeComment::_narrow(anAttr);
952         CORBA::String_var aValue = aComment->Value();
953         Storable::TRestoringMap aMap;     
954         Storable::StrToMap(aValue.in(),aMap);
955         bool anIsExist;
956         QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
957         if(anIsExist){
958           if(strcmp(aTypeName.latin1(),"ImportTables") == 0){
959             QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
960             if(anIsExist){
961               std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
962               theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.latin1()<<"')"<<endl;
963               theStr<<thePrefix<<"if "<<aName<<":"<<endl;
964               thePrefix += PREFIX;
965
966               theArgumentName = aName;
967               DumpChildrenToPython(theStudy,
968                                    theIsPublished,
969                                    theIsValidScript,
970                                    theSObject,
971                                    theStr,
972                                    theName2EntryMap,
973                                    theEntry2NameMap,
974                                    theArgumentName,
975                                    thePrefix);
976                   
977               theStr<<thePrefix<<"pass"<<endl<<endl;
978               return;
979             }
980           }else if(strcmp(aTypeName.latin1(),"VIEW3D") == 0){
981             std::string aName = GetName(theSObject);
982             theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
983
984             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
985             thePrefix += PREFIX;
986
987             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
988             theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
989
990             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeComment')"<<endl;
991             theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
992
993             theStr<<thePrefix<<"pass"<<endl<<endl;
994             return;
995           }
996         }
997       }else{
998         DumpTableAttrToPython(theStudy,
999                               theIsPublished,
1000                               theIsValidScript,
1001                               theSObject,
1002                               theStr,
1003                               theName2EntryMap,
1004                               theEntry2NameMap,
1005                               theArgumentName,
1006                               thePrefix);
1007       }
1008     }
1009
1010     DumpChildrenToPython(theStudy,
1011                          theIsPublished,
1012                          theIsValidScript,
1013                          theSObject,
1014                          theStr,
1015                          theName2EntryMap,
1016                          theEntry2NameMap,
1017                          theArgumentName,
1018                          thePrefix);
1019   }
1020
1021
1022   //===========================================================================
1023   void
1024   DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1025                     CORBA::Boolean theIsPublished,
1026                     CORBA::Boolean& theIsValidScript,
1027                     SALOMEDS::SObject_ptr theSObject,
1028                     std::ostream& theStr,
1029                     TName2EntryMap& theName2EntryMap,
1030                     TEntry2NameMap& theEntry2NameMap,
1031                     std::string theArgumentName,
1032                     std::string thePrefix)
1033   {
1034     SALOMEDS::SObject_var aTargetRefSObj;
1035     if(theSObject->ReferencedObject(aTargetRefSObj)){
1036       CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1037       if(CORBA::is_nil(anObj)) 
1038         return;
1039       
1040       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1041       if(CORBA::is_nil(aBase)) 
1042         return;
1043       
1044       if(aBase->GetType() == VISU::TCURVE){
1045         CORBA::String_var anID = aTargetRefSObj->GetID();
1046         std::string anArg = theEntry2NameMap[anID.in()];
1047         theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1048         thePrefix += PREFIX;
1049         theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1050         theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1051         theStr<<thePrefix<<"pass"<<endl<<endl;
1052       }
1053     }
1054   }
1055
1056
1057   //===========================================================================
1058   void
1059   DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1060                          CORBA::Boolean theIsPublished,
1061                          CORBA::Boolean& theIsValidScript,
1062                          SALOMEDS::SObject_ptr theSObject,
1063                          std::ostream& theStr,
1064                          TName2EntryMap& theName2EntryMap,
1065                          TEntry2NameMap& theEntry2NameMap,
1066                          std::string theArgumentName,
1067                          std::string thePrefix)
1068   {
1069     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1070     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1071       SALOMEDS::SObject_var aSObject = aChildItet->Value();
1072       CORBA::Object_var anObj = SObjectToObject(aSObject);
1073       if(CORBA::is_nil(anObj)) 
1074         continue;
1075
1076       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1077       if(CORBA::is_nil(aBase)) 
1078         continue;
1079
1080       if(aBase->GetType() == VISU::TCONTAINER){
1081         theStr<<endl;
1082         std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1083         theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1084         theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1085         std::string aPrefix = thePrefix + PREFIX;
1086         theArgumentName = aName;
1087
1088         SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1089         for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1090           SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1091           DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1092         }
1093
1094         theStr<<aPrefix<<"pass"<<endl<<endl;
1095       }
1096     }
1097   }
1098
1099
1100   //===========================================================================
1101   Engines::TMPFile* 
1102   VISU_Gen_i::
1103   DumpPython(CORBA::Object_ptr theStudy,
1104              CORBA::Boolean theIsPublished,
1105              CORBA::Boolean& theIsValidScript)
1106   {
1107     SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1108     if(CORBA::is_nil(aStudy)) 
1109       return new Engines::TMPFile(0);
1110
1111     TName2EntryMap aName2EntryMap;
1112     TEntry2NameMap aEntry2NameMap;
1113
1114 #ifndef COUT
1115     ostringstream aStr;
1116 #else
1117 #define aStr cout    
1118 #endif
1119
1120     std::string aPrefix(PREFIX);
1121     aStr<<"### This file is generated by SALOME automatically by dump python funcitonality"
1122       " of VISU component"<<endl<<endl;
1123     aStr<<"def RebuildData(theStudy):"<<endl;
1124     aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
1125     aStr<<aPrefix<<"import SALOME_MED"<<endl;
1126     aStr<<aPrefix<<"import SALOMEDS"<<endl;
1127     aStr<<aPrefix<<"import VISU"<<endl;
1128     aStr<<aPrefix<<"import visu"<<endl;
1129     aStr<<endl;
1130     aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
1131     aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
1132     aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
1133     aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
1134     aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
1135     aStr<<endl;
1136
1137     SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
1138     VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1139     VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1140
1141     aStr<<aPrefix<<"pass"<<endl;
1142
1143 #ifndef COUT
1144     std::string aResult = aStr.str();
1145     //ofstream anFStream("/tmp/dump.py");
1146     //anFStream<<aResult<<endl;
1147
1148     CORBA::ULong aSize = aResult.size() + 1;
1149     char* aBuffer = new char[aSize];
1150     strcpy(aBuffer,&aResult[0]);
1151     return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1); 
1152 #else
1153 #undef aStr
1154     return new Engines::TMPFile(0);
1155 #endif
1156   }
1157
1158 }