Salome HOME
Start implementation of methods, manipulating view parameters (position, size, splitt...
[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   // declaration
234   void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
235                             CORBA::Boolean theIsPublished,
236                             CORBA::Boolean& theIsValidScript,
237                             SALOMEDS::SObject_ptr theSObject,
238                             std::ostream& theStr,
239                             TName2EntryMap& theName2EntryMap,
240                             TEntry2NameMap& theEntry2NameMap,
241                             std::string theArgumentName,
242                             std::string thePrefix);
243   
244   //===========================================================================
245   template<class TTableAttr>
246   void
247   TableAttrToPython(SALOMEDS::Study_ptr theStudy,
248                     CORBA::Boolean theIsPublished,
249                     CORBA::Boolean& theIsValidScript,
250                     SALOMEDS::SObject_ptr theSObject,
251                     TTableAttr theTableAttr,
252                     const std::string& theAttrName,
253                     std::ostream& theStr,
254                     TName2EntryMap& theName2EntryMap,
255                     TEntry2NameMap& theEntry2NameMap,
256                     std::string theArgumentName,
257                     std::string thePrefix)
258   {
259     SALOMEDS::GenericAttribute_var anAttr; 
260     SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
261     if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){
262       SALOMEDS::AttributeComment_var aComment = 
263         SALOMEDS::AttributeComment::_narrow(anAttr);
264       CORBA::String_var aValue = aComment->Value();
265       Storable::TRestoringMap aMap;       
266       Storable::StrToMap(aValue.in(),aMap);
267       bool anIsExist;
268       QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
269       if(anIsExist){
270         if(strcmp(aMethodName.latin1(),"ImportTables") == 0){
271           return;
272         }
273       }
274     }
275
276     std::string aSObjectName = GetName(theSObject);
277     theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject(aSComponent)"<<endl;
278     theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
279     thePrefix += PREFIX;
280
281     std::string aName = "aTableAttr";
282     theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
283       aSObjectName<<",'"<<theAttrName<<"')"<<endl;
284
285     theStr<<thePrefix<<"if "<<aName<<":"<<endl;
286     std::string aPrefix = thePrefix;
287     thePrefix += PREFIX;
288
289     CORBA::String_var aString = theTableAttr->GetTitle();
290     theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
291
292     CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
293     theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
294
295     CORBA::Long aNbRows = theTableAttr->GetNbRows();
296
297     // push values and their indices into streams
298     strstream values, rows, columns;
299     string comma = "";
300     for(CORBA::Long i = 1; i <= aNbColumns; i++){
301       for(CORBA::Long j = aNbRows; j > 0; j--){
302         if(theTableAttr->HasValue(j,i)){
303           values  << comma << theTableAttr->GetValue(j,i);
304           rows    << comma << j;
305           columns << comma << i;
306           if ( comma.empty() )
307             comma = ",";
308         }
309       }
310     }
311     // push titles and units into streams
312     strstream rowUnits, rowTitles, colTitles;
313     SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
314     SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
315     comma = "";
316     for(CORBA::Long j = 1; j <= aNbRows; j++){
317       rowUnits  << comma << "'" << aRowUnits [ j - 1 ] << "'";
318       rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
319       if ( comma.empty() )
320         comma = ",";
321     }
322     SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
323     comma = "";
324     for(CORBA::Long j = 1; j <= aNbColumns; j++){
325       colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
326       if ( comma.empty() )
327         comma = ",";
328     }
329     values    << '\0';
330     rows      << '\0';
331     columns   << '\0';
332     rowUnits  << '\0';
333     rowTitles << '\0';
334     colTitles << '\0';
335     // write FillTable command
336     theStr<< thePrefix << aName << "_values  = [" << values.str()  << "]" << endl;
337     theStr<< thePrefix << aName << "_rows    = [" << rows.str()    << "]" << endl;
338     theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
339     theStr<< thePrefix << aName << "_rUnits  = [" << rowUnits.str()  << "]" << endl;
340     theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
341     theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
342     theStr<< thePrefix << "visu.FillTable( "
343       << aName << ", "
344         << aName << "_values, "
345           << aName << "_rows, "
346             << aName << "_columns, "
347               << aName << "_rTitles, "
348                 << aName << "_rUnits, "
349                   << aName << "_cTitles )" << endl;
350
351     if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
352       theStr<<endl;
353       std::string aName = "aTable";
354       theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
355       theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
356       theArgumentName = aName;
357       
358       theStr<<thePrefix<<"if "<<aName<<":"<<endl;
359       std::string aPrefix2 = thePrefix + PREFIX;
360
361       DumpChildrenToPython(theStudy,
362                            theIsPublished,
363                            theIsValidScript,
364                            theSObject,
365                            theStr,
366                            theName2EntryMap,
367                            theEntry2NameMap,
368                            theArgumentName,
369                            aPrefix2);
370
371       theStr<<aPrefix2<<"pass"<<endl<<endl;
372     }
373
374     theStr<<thePrefix<<"pass"<<endl<<endl;
375     theStr<<aPrefix<<"pass"<<endl<<endl;
376   }
377
378
379   //===========================================================================
380   void
381   DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
382                        CORBA::Boolean theIsPublished,
383                        CORBA::Boolean& theIsValidScript,
384                        SALOMEDS::SObject_ptr theSObject,
385                        std::ostream& theStr,
386                        TName2EntryMap& theName2EntryMap,
387                        TEntry2NameMap& theEntry2NameMap,
388                        std::string theArgumentName,
389                        std::string thePrefix)
390   {
391     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
392     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
393       SALOMEDS::SObject_var aSObject = aChildItet->Value();
394       DumpToPython(theStudy,
395                    theIsPublished,
396                    theIsValidScript,
397                    aSObject,
398                    theStr,
399                    theName2EntryMap,
400                    theEntry2NameMap,
401                    theArgumentName,
402                    thePrefix);
403     }
404   }
405
406
407   //===========================================================================
408   void
409   DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
410                         CORBA::Boolean theIsPublished,
411                         CORBA::Boolean& theIsValidScript,
412                         SALOMEDS::SObject_ptr theSObject,
413                         std::ostream& theStr,
414                         TName2EntryMap& theName2EntryMap,
415                         TEntry2NameMap& theEntry2NameMap,
416                         std::string theArgumentName,
417                         std::string thePrefix)
418   {
419     SALOMEDS::GenericAttribute_var anAttr;
420     if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
421       SALOMEDS::AttributeTableOfInteger_var aTableAttr =  
422         SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
423       
424       TableAttrToPython(theStudy,
425                         theIsPublished,
426                         theIsValidScript,
427                         theSObject,
428                         aTableAttr,
429                         "AttributeTableOfInteger",
430                         theStr,
431                         theName2EntryMap,
432                         theEntry2NameMap,
433                         theArgumentName,
434                         thePrefix);
435       
436     }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
437       SALOMEDS::AttributeTableOfReal_var aTableAttr =  
438         SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
439       
440       TableAttrToPython(theStudy,
441                         theIsPublished,
442                         theIsValidScript,
443                         theSObject,
444                         aTableAttr,
445                         "AttributeTableOfReal",
446                         theStr,
447                         theName2EntryMap,
448                         theEntry2NameMap,
449                         theArgumentName,
450                         thePrefix);
451     }
452   }
453
454
455   //===========================================================================
456   void
457   DumpToPython(SALOMEDS::Study_ptr theStudy,
458                CORBA::Boolean theIsPublished,
459                CORBA::Boolean& theIsValidScript,
460                SALOMEDS::SObject_ptr theSObject,
461                std::ostream& theStr,
462                TName2EntryMap& theName2EntryMap,
463                TEntry2NameMap& theEntry2NameMap,
464                std::string theArgumentName,
465                std::string thePrefix)
466   {
467     std::string aName = GetName(theSObject);
468     if(aName == "")
469       return;
470
471     CORBA::Object_var anObj = SObjectToObject(theSObject);
472     if(!CORBA::is_nil(anObj)){
473       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
474       if(!CORBA::is_nil(aBase)){
475         std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
476         CORBA::String_var anID = theSObject->GetID();
477
478         VISU::VISUType aType = aBase->GetType();
479         switch(aType){
480         case VISU::TRESULT:
481           if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
482             std::string aFileName = aServant->GetFileName();
483             Result_i::ECreationId anId = aServant->GetCreationId();
484             if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
485               switch(anId){
486               case Result_i::eImportFile:
487                 theStr<<thePrefix<<aName<<" = aVisu.ImportFile('"<<aFileName<<"')"<<endl;
488                 break;
489               case Result_i::eCopyAndImportFile: 
490                 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
491                 break;
492               }
493
494               theStr<<thePrefix<<"if "<<aName<<":"<<endl;
495               thePrefix += PREFIX;
496               
497               theArgumentName = aName;
498               DumpChildrenToPython(theStudy,
499                                    theIsPublished,
500                                    theIsValidScript,
501                                    theSObject,
502                                    theStr,
503                                    theName2EntryMap,
504                                    theEntry2NameMap,
505                                    theArgumentName,
506                                    thePrefix);
507               
508               theStr<<thePrefix<<"pass"<<endl<<endl;
509             }else{
510               SALOMEDS::SObject_var aRefSObj;
511               if(theSObject->FindSubObject(1,aRefSObj)){
512                 SALOMEDS::SObject_var aTargetRefSObj;
513                 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
514                   CORBA::String_var aString = aTargetRefSObj->GetName();
515                   theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
516                   theStr<<thePrefix<<"if aSObject:"<<endl;
517                   thePrefix += PREFIX;
518                   theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
519                   theStr<<thePrefix<<"if anObject:"<<endl;
520                   std::string aPrefix1 = thePrefix;
521                   thePrefix += PREFIX;
522
523                   switch(anId){
524                   case Result_i::eImportMed: 
525                     theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
526                     break;
527                   case Result_i::eImportMedField:
528                     theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
529                     break;
530                   }
531
532                   theStr<<thePrefix<<"if "<<aName<<":"<<endl;
533                   std::string aPrefix2 = thePrefix;
534                   thePrefix += PREFIX;
535                   
536                   theArgumentName = aName;
537                   DumpChildrenToPython(theStudy,
538                                        theIsPublished,
539                                        theIsValidScript,
540                                        theSObject,
541                                        theStr,
542                                        theName2EntryMap,
543                                        theEntry2NameMap,
544                                        theArgumentName,
545                                        thePrefix);
546               
547                   theStr<<thePrefix<<"pass"<<endl<<endl;
548                   theStr<<aPrefix2<<"pass"<<endl<<endl;
549                   theStr<<aPrefix1<<"pass"<<endl<<endl;
550                 }
551               }
552             }
553           }
554           return;
555         case VISU::TMESH:
556           if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){
557             VISU::Entity anEntity = aServant->GetEntity();
558             const std::string& aSubMeshName = aServant->GetSubMeshName();
559             if(anEntity >= 0){
560               std::string aParam;
561               switch(anEntity){
562               case NODE:
563                 aParam = "VISU.NODE";
564                 break;
565               case EDGE:
566                 aParam = "VISU.EDGE";
567                 break;
568               case FACE:
569                 aParam = "VISU.FACE";
570                 break;
571               case CELL:
572                 aParam = "VISU.CELL";
573                 break;
574               }
575               
576               if(aSubMeshName == "")
577                 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
578                   ",'"<<aServant->GetMeshName()<<"'"<<
579                   ","<<aParam<<
580                   ")"<<endl;
581               else
582                 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
583                   ",'"<<aServant->GetMeshName()<<"'"<<
584                   ","<<aParam<<
585                   ",'"<<aSubMeshName<<"'"<<
586                   ")"<<endl;
587             }else
588               theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
589                 ",'"<<aServant->GetMeshName()<<"'"<<
590                 ",'"<<aSubMeshName<<"'"<<
591                 ")"<<endl;
592             
593             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
594             thePrefix += PREFIX;
595
596             theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
597
598             SALOMEDS::Color aColor;
599             aColor = aServant->GetCellColor();
600             theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
601               aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
602             
603             aColor = aServant->GetNodeColor();
604             theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
605               aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
606             
607             aColor = aServant->GetLinkColor();
608             theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
609               aColor.R<<","<<aColor.G<<","<<aColor.B<<"))"<<endl;
610             
611             std::string aParam;
612             switch(aServant->GetPresentationType()){
613             case POINT:
614               aParam = "VISU.POINT";
615               break;
616             case WIREFRAME:
617               aParam = "VISU.WIREFRAME";
618               break;
619             case SHADED:
620               aParam = "VISU.SHADED";
621               break;
622             case INSIDEFRAME:
623               aParam = "VISU.INSIDEFRAME";
624               break;
625             case SURFACEFRAME:
626               aParam = "VISU.SURFACEFRAME";
627               break;
628             case SHRINK:
629               aParam = "VISU.SHRINK";
630               break;
631             }
632             theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
633             theStr<<endl;
634
635             DumpChildrenToPython(theStudy,
636                                  theIsPublished,
637                                  theIsValidScript,
638                                  theSObject,
639                                  theStr,
640                                  theName2EntryMap,
641                                  theEntry2NameMap,
642                                  theArgumentName,
643                                  thePrefix);
644               
645             theStr<<thePrefix<<"pass"<<endl<<endl;
646             return;
647           }
648           break;
649         case VISU::TSCALARMAP:
650           if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
651             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"ScalarMapOnField",theArgumentName,thePrefix);
652             theStr<<thePrefix<<"pass"<<endl<<endl;
653           }
654           return;
655         case VISU::TDEFORMEDSHAPE:
656           if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
657             thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"DeformedShapeOnField",theArgumentName,thePrefix);
658             theStr<<thePrefix<<"pass"<<endl<<endl;
659           }
660           return;
661         case VISU::TSTREAMLINES:
662           if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
663             thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"StreamLinesOnField",theArgumentName,thePrefix);
664             
665             std::string aParam;
666             switch(aServant->GetDirection()){
667             case StreamLines::FORWARD:
668               aParam = "VISU.StreamLines.FORWARD";
669               break;
670             case StreamLines::BACKWARD:
671               aParam = "VISU.StreamLines.BACKWARD";
672               break;
673             case StreamLines::BOTH:
674               aParam = "VISU.StreamLines.BOTH";
675               break;
676             }
677
678             theStr<<thePrefix<<"aPrs3d = None"<<endl;
679             VISU::Prs3d_var aPrs3d = aServant->GetSource();
680             if(!CORBA::is_nil(aPrs3d)){
681               if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
682                 SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
683                 CORBA::String_var anID = aSObject->GetID();
684                 std::string anArg = theEntry2NameMap[anID.in()];
685                 theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
686                 thePrefix += PREFIX;
687                 theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
688               }
689             }
690             
691             theStr<<thePrefix<<aName<<".SetParams("<<
692               aServant->GetIntegrationStep()<<","<<
693               aServant->GetPropagationTime()<<","<<
694               aServant->GetStepLength()<<","<<
695               "aPrs3d"<<","<<
696               aServant->GetUsedPoints()<<","<<
697               aParam<<
698               ")"<<endl;
699
700             theStr<<thePrefix<<"pass"<<endl<<endl;
701           }
702           return;
703         case VISU::TVECTORS:
704           if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
705             thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"VectorsOnField",theArgumentName,thePrefix);
706             
707             theStr<<thePrefix<<aName<<".SetLineWidth("<<aServant->GetLineWidth()<<")"<<endl;
708             
709             std::string aParam;
710             switch(aServant->GetGlyphType()){
711             case Vectors::ARROW:
712               aParam = "VISU.Vectors.ARROW";
713               break;
714             case Vectors::CONE2:
715               aParam = "VISU.Vectors.CONE2";
716               break;
717             case Vectors::CONE6:
718               aParam = "VISU.Vectors.CONE6";
719               break;
720             case Vectors::NONE:
721               aParam = "VISU.Vectors.NONE";
722               break;
723             }
724             theStr<<thePrefix<<aName<<".SetGlyphType("<<aParam<<")"<<endl;
725             
726             switch(aServant->GetGlyphPos()){
727             case Vectors::CENTER:
728               aParam = "VISU.Vectors.CENTER";
729               break;
730             case Vectors::TAIL:
731               aParam = "VISU.Vectors.TAIL";
732               break;
733             case Vectors::HEAD:
734               aParam = "VISU.Vectors.HEAD";
735               break;
736             }
737             theStr<<thePrefix<<aName<<".SetGlyphPos("<<aParam<<")"<<endl;
738
739             theStr<<thePrefix<<"pass"<<endl<<endl;
740           }
741           return;
742         case VISU::TISOSURFACE:
743           if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
744             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"IsoSurfacesOnField",theArgumentName,thePrefix);
745             theStr<<thePrefix<<aName<<".SetNbSurfaces("<<aServant->GetNbSurfaces()<<")"<<endl;
746             theStr<<thePrefix<<"pass"<<endl<<endl;
747           }
748           return;
749         case VISU::TCUTPLANES:
750           if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
751             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutPlanesOnField",theArgumentName,thePrefix);
752             
753             std::string aParam;
754             switch(aServant->GetOrientationType()){
755             case CutPlanes::XY:
756               aParam = "VISU.CutPlanes.XY";
757               break;
758             case CutPlanes::YZ:
759               aParam = "VISU.CutPlanes.YZ";
760               break;
761             case CutPlanes::ZX:
762               aParam = "VISU.CutPlanes.ZX";
763               break;
764             }
765             theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
766             
767             theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
768             CORBA::Long aNbPlanes = aServant->GetNbPlanes();
769             theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
770             
771             for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
772               if(!aServant->IsDefault(anId))
773                 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
774             }
775
776             theStr<<thePrefix<<"pass"<<endl<<endl;
777           }
778           return;
779         case VISU::TCUTLINES:
780           if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
781             thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutLinesOnField",theArgumentName,thePrefix);
782             
783             std::string aParam;
784             switch(aServant->GetOrientationType()){
785             case CutPlanes::XY:
786               aParam = "VISU.CutPlanes.XY";
787               break;
788             case CutPlanes::YZ:
789               aParam = "VISU.CutPlanes.YZ";
790               break;
791             case CutPlanes::ZX:
792               aParam = "VISU.CutPlanes.ZX";
793               break;
794             }
795             theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
796             
797             switch(aServant->GetOrientationType2()){
798             case CutPlanes::XY:
799               aParam = "VISU.CutPlanes.XY";
800               break;
801             case CutPlanes::YZ:
802               aParam = "VISU.CutPlanes.YZ";
803               break;
804             case CutPlanes::ZX:
805               aParam = "VISU.CutPlanes.ZX";
806               break;
807             }
808             theStr<<thePrefix<<aName<<".SetOrientation2("<<aParam<<","<<aServant->GetRotateX2()<<","<<aServant->GetRotateY2()<<")"<<endl;
809             
810             theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
811             theStr<<thePrefix<<aName<<".SetDisplacement2("<<aServant->GetDisplacement2()<<")"<<endl;
812             
813             if(!aServant->IsDefault())
814               theStr<<thePrefix<<aName<<".SetBasePlanePosition("<<aServant->GetBasePlanePosition()<<")"<<endl;
815             
816             CORBA::Long aNbLines = aServant->GetNbLines();
817             theStr<<thePrefix<<aName<<".SetNbLines("<<aNbLines<<")"<<endl;
818             for(CORBA::Long anId = 0; anId < aNbLines; anId++){
819               if(!aServant->IsDefaultPosition(anId))
820                 theStr<<thePrefix<<aName<<".SetLinePosition("<<anId<<","<<aServant->GetLinePosition(anId)<<")"<<endl;
821             }
822
823             theStr<<endl;
824
825             theArgumentName = aName;
826             DumpChildrenToPython(theStudy,
827                                  theIsPublished,
828                                  theIsValidScript,
829                                  theSObject,
830                                  theStr,
831                                  theName2EntryMap,
832                                  theEntry2NameMap,
833                                  theArgumentName,
834                                  thePrefix);
835
836             theStr<<thePrefix<<"pass"<<endl<<endl;
837           }
838           return;
839         case VISU::TCURVE:
840           if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
841           {
842             theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve(" <<
843               theArgumentName<< // table
844                 ","<<aServant->GetHRow()<< // H row
845                   ","<<aServant->GetVRow()<< // V row
846                     ",'"<<aServant->GetTitle()<<"'"; // title
847             SALOMEDS::Color aColor = aServant->GetColor();
848             theStr << ",SALOMEDS.Color("<<
849               aColor.R<<","<<aColor.G<<","<<aColor.B<<")"; // color
850             
851             std::string aParam;
852             switch(aServant->GetMarker()){
853             case Curve::NONE:      aParam = "VISU.Curve.NONE";      break;
854             case Curve::CIRCLE:    aParam = "VISU.Curve.CIRCLE";    break;
855             case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
856             case Curve::DIAMOND:   aParam = "VISU.Curve.DIAMOND";   break;
857             case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
858             case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
859             case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
860             case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
861             case Curve::CROSS:     aParam = "VISU.Curve.CROSS";     break;
862             case Curve::XCROSS:    aParam = "VISU.Curve.XCROSS";    break;
863             }
864             theStr<<","<<aParam; // marker
865
866             switch(aServant->GetLine()){
867             case Curve::VOIDLINE:       aParam = "VISU.Curve.VOIDLINE";       break;
868             case Curve::SOLIDLINE:      aParam = "VISU.Curve.SOLIDLINE";      break;
869             case Curve::DASHLINE:       aParam = "VISU.Curve.DASHLINE";       break;
870             case Curve::DOTLINE:        aParam = "VISU.Curve.DOTLINE";        break;
871             case Curve::DASHDOTLINE:    aParam = "VISU.Curve.DASHDOTLINE";    break;
872             case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
873             }
874             theStr<<","<<aParam<<","<<aServant->GetLineWidth()<<")"<<endl; // line type,width
875           }
876           return;
877         case VISU::TTABLE:
878           if(Table_i* aServant = dynamic_cast<Table_i*>(GetServant(anObj).in())){
879             SALOMEDS::SObject_var aSObject = aServant->GetSObject();
880             SALOMEDS::GenericAttribute_var anAttr;
881             if(theSObject->FindAttribute(anAttr,"AttributeComment")){
882               using namespace SALOMEDS;
883               AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
884               CORBA::String_var aValue = aComment->Value();
885               Storable::TRestoringMap aMap;       
886               Storable::StrToMap(aValue.in(),aMap);
887               bool anIsExist;
888               QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
889               if(anIsExist){
890                 if(strcmp(aSourceId.latin1(),"CutLines") == 0){
891                   theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
892                   thePrefix += PREFIX;
893
894                   theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
895                   theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
896                   theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
897                   theStr<<thePrefix<<"if aSObject:"<<endl;
898                   std::string aPrefix = thePrefix;
899                   thePrefix += PREFIX;
900
901                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
902                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
903                   theStr<<endl;
904                   
905                   theArgumentName = aName;
906                   DumpChildrenToPython(theStudy,
907                                        theIsPublished,
908                                        theIsValidScript,
909                                        theSObject,
910                                        theStr,
911                                        theName2EntryMap,
912                                        theEntry2NameMap,
913                                        theArgumentName,
914                                        thePrefix);
915                   
916                   theStr<<thePrefix<<"pass"<<endl<<endl;
917                   theStr<<aPrefix<<"pass"<<endl<<endl;
918                 }else if(strcmp(aSourceId.latin1(),"TableFile") == 0){
919                   CORBA::Short aTag = theSObject->Tag();
920                   theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
921                   theStr<<thePrefix<<"if anIsFound:"<<endl;
922                   thePrefix += PREFIX;
923                   
924                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
925                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
926                   theStr<<endl;
927
928                   theArgumentName = aName;
929                   DumpChildrenToPython(theStudy,
930                                        theIsPublished,
931                                        theIsValidScript,
932                                        theSObject,
933                                        theStr,
934                                        theName2EntryMap,
935                                        theEntry2NameMap,
936                                        theArgumentName,
937                                        thePrefix);
938                   
939                   theStr<<thePrefix<<"pass"<<endl<<endl;
940                 }else if(strcmp(aSourceId.latin1(),"TableAttr") == 0){
941                   theArgumentName = aName;
942                   DumpTableAttrToPython(theStudy,
943                                         theIsPublished,
944                                         theIsValidScript,
945                                         theSObject,
946                                         theStr,
947                                         theName2EntryMap,
948                                         theEntry2NameMap,
949                                         theArgumentName,
950                                         thePrefix);
951                 }
952               }
953             }
954           }
955           return;
956         }
957       }
958     }else{
959       SALOMEDS::GenericAttribute_var anAttr;
960       if(theSObject->FindAttribute(anAttr,"AttributeComment")){
961         SALOMEDS::AttributeComment_var aComment = 
962           SALOMEDS::AttributeComment::_narrow(anAttr);
963         CORBA::String_var aValue = aComment->Value();
964         Storable::TRestoringMap aMap;     
965         Storable::StrToMap(aValue.in(),aMap);
966         bool anIsExist;
967         QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
968         if(anIsExist){
969           if(strcmp(aTypeName.latin1(),"ImportTables") == 0){
970             QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
971             if(anIsExist){
972               std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
973               theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.latin1()<<"')"<<endl;
974               theStr<<thePrefix<<"if "<<aName<<":"<<endl;
975               thePrefix += PREFIX;
976
977               theArgumentName = aName;
978               DumpChildrenToPython(theStudy,
979                                    theIsPublished,
980                                    theIsValidScript,
981                                    theSObject,
982                                    theStr,
983                                    theName2EntryMap,
984                                    theEntry2NameMap,
985                                    theArgumentName,
986                                    thePrefix);
987                   
988               theStr<<thePrefix<<"pass"<<endl<<endl;
989               return;
990             }
991           }else if(strcmp(aTypeName.latin1(),"VIEW3D") == 0){
992             std::string aName = GetName(theSObject);
993             theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
994
995             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
996             thePrefix += PREFIX;
997
998             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
999             theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1000
1001             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeComment')"<<endl;
1002             theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1003
1004             theStr<<thePrefix<<"pass"<<endl<<endl;
1005             return;
1006           }
1007         }
1008       }else{
1009         DumpTableAttrToPython(theStudy,
1010                               theIsPublished,
1011                               theIsValidScript,
1012                               theSObject,
1013                               theStr,
1014                               theName2EntryMap,
1015                               theEntry2NameMap,
1016                               theArgumentName,
1017                               thePrefix);
1018       }
1019     }
1020
1021     DumpChildrenToPython(theStudy,
1022                          theIsPublished,
1023                          theIsValidScript,
1024                          theSObject,
1025                          theStr,
1026                          theName2EntryMap,
1027                          theEntry2NameMap,
1028                          theArgumentName,
1029                          thePrefix);
1030   }
1031
1032
1033   //===========================================================================
1034   void
1035   DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1036                     CORBA::Boolean theIsPublished,
1037                     CORBA::Boolean& theIsValidScript,
1038                     SALOMEDS::SObject_ptr theSObject,
1039                     std::ostream& theStr,
1040                     TName2EntryMap& theName2EntryMap,
1041                     TEntry2NameMap& theEntry2NameMap,
1042                     std::string theArgumentName,
1043                     std::string thePrefix)
1044   {
1045     SALOMEDS::SObject_var aTargetRefSObj;
1046     if(theSObject->ReferencedObject(aTargetRefSObj)){
1047       CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1048       if(CORBA::is_nil(anObj)) 
1049         return;
1050       
1051       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1052       if(CORBA::is_nil(aBase)) 
1053         return;
1054       
1055       if(aBase->GetType() == VISU::TCURVE){
1056         CORBA::String_var anID = aTargetRefSObj->GetID();
1057         std::string anArg = theEntry2NameMap[anID.in()];
1058         theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1059         thePrefix += PREFIX;
1060         theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1061         theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1062         theStr<<thePrefix<<"pass"<<endl<<endl;
1063       }
1064     }
1065   }
1066
1067
1068   //===========================================================================
1069   void
1070   DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1071                          CORBA::Boolean theIsPublished,
1072                          CORBA::Boolean& theIsValidScript,
1073                          SALOMEDS::SObject_ptr theSObject,
1074                          std::ostream& theStr,
1075                          TName2EntryMap& theName2EntryMap,
1076                          TEntry2NameMap& theEntry2NameMap,
1077                          std::string theArgumentName,
1078                          std::string thePrefix)
1079   {
1080     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1081     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1082       SALOMEDS::SObject_var aSObject = aChildItet->Value();
1083       CORBA::Object_var anObj = SObjectToObject(aSObject);
1084       if(CORBA::is_nil(anObj)) 
1085         continue;
1086
1087       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1088       if(CORBA::is_nil(aBase)) 
1089         continue;
1090
1091       if(aBase->GetType() == VISU::TCONTAINER){
1092         theStr<<endl;
1093         std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1094         theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1095         theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1096         std::string aPrefix = thePrefix + PREFIX;
1097         theArgumentName = aName;
1098
1099         SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1100         for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1101           SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1102           DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1103         }
1104
1105         theStr<<aPrefix<<"pass"<<endl<<endl;
1106       }
1107     }
1108   }
1109
1110
1111   //===========================================================================
1112   Engines::TMPFile* 
1113   VISU_Gen_i::
1114   DumpPython(CORBA::Object_ptr theStudy,
1115              CORBA::Boolean theIsPublished,
1116              CORBA::Boolean& theIsValidScript)
1117   {
1118     SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1119     if(CORBA::is_nil(aStudy)) 
1120       return new Engines::TMPFile(0);
1121
1122     TName2EntryMap aName2EntryMap;
1123     TEntry2NameMap aEntry2NameMap;
1124
1125 #ifndef COUT
1126     ostringstream aStr;
1127 #else
1128 #define aStr cout    
1129 #endif
1130
1131     std::string aPrefix(PREFIX);
1132     aStr<<"### This file is generated by SALOME automatically by dump python funcitonality"
1133       " of VISU component"<<endl<<endl;
1134     aStr<<"def RebuildData(theStudy):"<<endl;
1135     aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
1136     aStr<<aPrefix<<"import SALOME_MED"<<endl;
1137     aStr<<aPrefix<<"import SALOMEDS"<<endl;
1138     aStr<<aPrefix<<"import VISU"<<endl;
1139     aStr<<aPrefix<<"import visu"<<endl;
1140     aStr<<endl;
1141     aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
1142     aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
1143     aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
1144     aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
1145     aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
1146     aStr<<endl;
1147
1148     SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
1149     VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1150     VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1151
1152     aStr<<aPrefix<<"pass"<<endl;
1153
1154 #ifndef COUT
1155     std::string aResult = aStr.str();
1156     //ofstream anFStream("/tmp/dump.py");
1157     //anFStream<<aResult<<endl;
1158
1159     CORBA::ULong aSize = aResult.size() + 1;
1160     char* aBuffer = new char[aSize];
1161     strcpy(aBuffer,&aResult[0]);
1162     return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1); 
1163 #else
1164 #undef aStr
1165     return new Engines::TMPFile(0);
1166 #endif
1167   }
1168
1169 }