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