]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_DumpPython.cc
Salome HOME
02ae8b78ef138d5e226390c3c5407d4cac6c0638
[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             // jfa: TODO
843             /*thePrefix = ScalarMapToPython(theSObject, aServant, theStr, aName,
844                                           "Plot3DOnField", theArgumentName, thePrefix);
845
846             std::string aParam;
847             switch(aServant->GetOrientationType()){
848             case CutPlanes::XY:
849               aParam = "VISU.CutPlanes.XY";
850               break;
851             case CutPlanes::YZ:
852               aParam = "VISU.CutPlanes.YZ";
853               break;
854             case CutPlanes::ZX:
855               aParam = "VISU.CutPlanes.ZX";
856               break;
857             }
858             theStr<<thePrefix<<aName<<".SetOrientation("<<aParam<<","<<aServant->GetRotateX()<<","<<aServant->GetRotateY()<<")"<<endl;
859
860             theStr<<thePrefix<<aName<<".SetDisplacement("<<aServant->GetDisplacement()<<")"<<endl;
861             CORBA::Long aNbPlanes = aServant->GetNbPlanes();
862             theStr<<thePrefix<<aName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
863
864             for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
865               if(!aServant->IsDefault(anId))
866                 theStr<<thePrefix<<aName<<".SetPlanePosition("<<anId<<","<<aServant->GetPlanePosition(anId)<<")"<<endl;
867             }
868
869             theStr<<thePrefix<<"pass"<<endl<<endl;*/
870           }
871           return;
872         case VISU::TCURVE:
873           if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
874           {
875             theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve(" <<
876               theArgumentName<< // table
877                 ","<<aServant->GetHRow()<< // H row
878                   ","<<aServant->GetVRow()<< // V row
879                     ",'"<<aServant->GetTitle()<<"'"; // title
880             SALOMEDS::Color aColor = aServant->GetColor();
881             theStr << ",SALOMEDS.Color("<<
882               aColor.R<<","<<aColor.G<<","<<aColor.B<<")"; // color
883
884             std::string aParam;
885             switch(aServant->GetMarker()){
886             case Curve::NONE:      aParam = "VISU.Curve.NONE";      break;
887             case Curve::CIRCLE:    aParam = "VISU.Curve.CIRCLE";    break;
888             case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
889             case Curve::DIAMOND:   aParam = "VISU.Curve.DIAMOND";   break;
890             case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
891             case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
892             case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
893             case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
894             case Curve::CROSS:     aParam = "VISU.Curve.CROSS";     break;
895             case Curve::XCROSS:    aParam = "VISU.Curve.XCROSS";    break;
896             }
897             theStr<<","<<aParam; // marker
898
899             switch(aServant->GetLine()){
900             case Curve::VOIDLINE:       aParam = "VISU.Curve.VOIDLINE";       break;
901             case Curve::SOLIDLINE:      aParam = "VISU.Curve.SOLIDLINE";      break;
902             case Curve::DASHLINE:       aParam = "VISU.Curve.DASHLINE";       break;
903             case Curve::DOTLINE:        aParam = "VISU.Curve.DOTLINE";        break;
904             case Curve::DASHDOTLINE:    aParam = "VISU.Curve.DASHDOTLINE";    break;
905             case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
906             }
907             theStr<<","<<aParam<<","<<aServant->GetLineWidth()<<")"<<endl; // line type,width
908           }
909           return;
910         case VISU::TTABLE:
911           if(Table_i* aServant = dynamic_cast<Table_i*>(GetServant(anObj).in())){
912             SALOMEDS::SObject_var aSObject = aServant->GetSObject();
913             SALOMEDS::GenericAttribute_var anAttr;
914             if(theSObject->FindAttribute(anAttr,"AttributeComment")){
915               using namespace SALOMEDS;
916               AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
917               CORBA::String_var aValue = aComment->Value();
918               Storable::TRestoringMap aMap;
919               Storable::StrToMap(aValue.in(),aMap);
920               bool anIsExist;
921               QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
922               if(anIsExist){
923                 if(strcmp(aSourceId.latin1(),"CutLines") == 0){
924                   theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
925                   thePrefix += PREFIX;
926
927                   theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
928                   theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
929                   theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
930                   theStr<<thePrefix<<"if aSObject:"<<endl;
931                   std::string aPrefix = thePrefix;
932                   thePrefix += PREFIX;
933
934                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
935                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
936                   theStr<<endl;
937
938                   theArgumentName = aName;
939                   DumpChildrenToPython(theStudy,
940                                        theIsPublished,
941                                        theIsValidScript,
942                                        theSObject,
943                                        theStr,
944                                        theName2EntryMap,
945                                        theEntry2NameMap,
946                                        theArgumentName,
947                                        thePrefix);
948
949                   theStr<<thePrefix<<"pass"<<endl<<endl;
950                   theStr<<aPrefix<<"pass"<<endl<<endl;
951                 }else if(strcmp(aSourceId.latin1(),"TableFile") == 0){
952                   CORBA::Short aTag = theSObject->Tag();
953                   theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
954                   theStr<<thePrefix<<"if anIsFound:"<<endl;
955                   thePrefix += PREFIX;
956
957                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
958                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
959                   theStr<<endl;
960
961                   theArgumentName = aName;
962                   DumpChildrenToPython(theStudy,
963                                        theIsPublished,
964                                        theIsValidScript,
965                                        theSObject,
966                                        theStr,
967                                        theName2EntryMap,
968                                        theEntry2NameMap,
969                                        theArgumentName,
970                                        thePrefix);
971
972                   theStr<<thePrefix<<"pass"<<endl<<endl;
973                 }else if(strcmp(aSourceId.latin1(),"TableAttr") == 0){
974                   theArgumentName = aName;
975                   DumpTableAttrToPython(theStudy,
976                                         theIsPublished,
977                                         theIsValidScript,
978                                         theSObject,
979                                         theStr,
980                                         theName2EntryMap,
981                                         theEntry2NameMap,
982                                         theArgumentName,
983                                         thePrefix);
984                 }
985               }
986             }
987           }
988           return;
989         }
990       }
991     }else{
992       SALOMEDS::GenericAttribute_var anAttr;
993       if(theSObject->FindAttribute(anAttr,"AttributeComment")){
994         SALOMEDS::AttributeComment_var aComment =
995           SALOMEDS::AttributeComment::_narrow(anAttr);
996         CORBA::String_var aValue = aComment->Value();
997         Storable::TRestoringMap aMap;
998         Storable::StrToMap(aValue.in(),aMap);
999         bool anIsExist;
1000         QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1001         if(anIsExist){
1002           if(strcmp(aTypeName.latin1(),"ImportTables") == 0){
1003             QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1004             if(anIsExist){
1005               std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1006               theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"<<aFileName.latin1()<<"')"<<endl;
1007               theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1008               thePrefix += PREFIX;
1009
1010               theArgumentName = aName;
1011               DumpChildrenToPython(theStudy,
1012                                    theIsPublished,
1013                                    theIsValidScript,
1014                                    theSObject,
1015                                    theStr,
1016                                    theName2EntryMap,
1017                                    theEntry2NameMap,
1018                                    theArgumentName,
1019                                    thePrefix);
1020
1021               theStr<<thePrefix<<"pass"<<endl<<endl;
1022               return;
1023             }
1024           }else if(strcmp(aTypeName.latin1(),"VIEW3D") == 0){
1025             std::string aName = GetName(theSObject);
1026             theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1027
1028             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1029             thePrefix += PREFIX;
1030
1031             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1032             theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1033
1034             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeComment')"<<endl;
1035             theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1036
1037             theStr<<thePrefix<<"pass"<<endl<<endl;
1038             return;
1039           }
1040         }
1041       }else{
1042         DumpTableAttrToPython(theStudy,
1043                               theIsPublished,
1044                               theIsValidScript,
1045                               theSObject,
1046                               theStr,
1047                               theName2EntryMap,
1048                               theEntry2NameMap,
1049                               theArgumentName,
1050                               thePrefix);
1051       }
1052     }
1053
1054     DumpChildrenToPython(theStudy,
1055                          theIsPublished,
1056                          theIsValidScript,
1057                          theSObject,
1058                          theStr,
1059                          theName2EntryMap,
1060                          theEntry2NameMap,
1061                          theArgumentName,
1062                          thePrefix);
1063   }
1064
1065
1066   //===========================================================================
1067   void
1068   DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1069                     CORBA::Boolean theIsPublished,
1070                     CORBA::Boolean& theIsValidScript,
1071                     SALOMEDS::SObject_ptr theSObject,
1072                     std::ostream& theStr,
1073                     TName2EntryMap& theName2EntryMap,
1074                     TEntry2NameMap& theEntry2NameMap,
1075                     std::string theArgumentName,
1076                     std::string thePrefix)
1077   {
1078     SALOMEDS::SObject_var aTargetRefSObj;
1079     if(theSObject->ReferencedObject(aTargetRefSObj)){
1080       CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1081       if(CORBA::is_nil(anObj))
1082         return;
1083
1084       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1085       if(CORBA::is_nil(aBase))
1086         return;
1087
1088       if(aBase->GetType() == VISU::TCURVE){
1089         CORBA::String_var anID = aTargetRefSObj->GetID();
1090         std::string anArg = theEntry2NameMap[anID.in()];
1091         theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1092         thePrefix += PREFIX;
1093         theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1094         theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1095         theStr<<thePrefix<<"pass"<<endl<<endl;
1096       }
1097     }
1098   }
1099
1100
1101   //===========================================================================
1102   void
1103   DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1104                          CORBA::Boolean theIsPublished,
1105                          CORBA::Boolean& theIsValidScript,
1106                          SALOMEDS::SObject_ptr theSObject,
1107                          std::ostream& theStr,
1108                          TName2EntryMap& theName2EntryMap,
1109                          TEntry2NameMap& theEntry2NameMap,
1110                          std::string theArgumentName,
1111                          std::string thePrefix)
1112   {
1113     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1114     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1115       SALOMEDS::SObject_var aSObject = aChildItet->Value();
1116       CORBA::Object_var anObj = SObjectToObject(aSObject);
1117       if(CORBA::is_nil(anObj))
1118         continue;
1119
1120       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1121       if(CORBA::is_nil(aBase))
1122         continue;
1123
1124       if(aBase->GetType() == VISU::TCONTAINER){
1125         theStr<<endl;
1126         std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1127         theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1128         theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1129         std::string aPrefix = thePrefix + PREFIX;
1130         theArgumentName = aName;
1131
1132         SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1133         for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1134           SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1135           DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1136         }
1137
1138         theStr<<aPrefix<<"pass"<<endl<<endl;
1139       }
1140     }
1141   }
1142
1143
1144   //===========================================================================
1145   Engines::TMPFile*
1146   VISU_Gen_i::
1147   DumpPython(CORBA::Object_ptr theStudy,
1148              CORBA::Boolean theIsPublished,
1149              CORBA::Boolean& theIsValidScript)
1150   {
1151     SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
1152     if(CORBA::is_nil(aStudy))
1153       return new Engines::TMPFile(0);
1154
1155     TName2EntryMap aName2EntryMap;
1156     TEntry2NameMap aEntry2NameMap;
1157
1158 #ifndef COUT
1159     ostringstream aStr;
1160 #else
1161 #define aStr cout
1162 #endif
1163
1164     std::string aPrefix(PREFIX);
1165     aStr<<"### This file is generated by SALOME automatically by dump python funcitonality"
1166       " of VISU component"<<endl<<endl;
1167     aStr<<"def RebuildData(theStudy):"<<endl;
1168     aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
1169     aStr<<aPrefix<<"import SALOME_MED"<<endl;
1170     aStr<<aPrefix<<"import SALOMEDS"<<endl;
1171     aStr<<aPrefix<<"import VISU"<<endl;
1172     aStr<<aPrefix<<"import visu"<<endl;
1173     aStr<<endl;
1174     aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
1175     aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
1176     aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
1177     aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
1178     aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
1179     aStr<<endl;
1180
1181     SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
1182     VISU::DumpChildrenToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1183     VISU::DumpContainersToPython(aStudy,theIsPublished,theIsValidScript,aComponent.in(),aStr,aName2EntryMap,aEntry2NameMap,"",aPrefix);
1184
1185     aStr<<aPrefix<<"pass"<<endl;
1186
1187 #ifndef COUT
1188     std::string aResult = aStr.str();
1189     //ofstream anFStream("/tmp/dump.py");
1190     //anFStream<<aResult<<endl;
1191
1192     CORBA::ULong aSize = aResult.size() + 1;
1193     char* aBuffer = new char[aSize];
1194     strcpy(aBuffer,&aResult[0]);
1195     return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
1196 #else
1197 #undef aStr
1198     return new Engines::TMPFile(0);
1199 #endif
1200   }
1201 }