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