Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_DumpPython.cc
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_DumpPython.cc
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #include "VISU_Gen_i.hh"
29 #include "VISU_Result_i.hh"
30 #include "VISU_PrsObject_i.hh"
31
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_ScalarMap_i.hh"
35 #include "VISU_IsoSurfaces_i.hh"
36 #include "VISU_DeformedShape_i.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_CutLines_i.hh"
39 #include "VISU_CutSegment_i.hh"
40 #include "VISU_Vectors_i.hh"
41 #include "VISU_StreamLines_i.hh"
42 #include "VISU_Plot3D_i.hh"
43 #include "VISU_Table_i.hh"
44 #include "VISU_PointMap3d_i.hh"
45 #include "VISU_GaussPoints_i.hh"
46 #include "VISU_DeformedShapeAndScalarMap_i.hh"
47 #include "VISU_ColoredPrs3dCache_i.hh"
48 #include "VISU_ColoredPrs3dHolder_i.hh"
49
50 #include "utilities.h"
51
52 #include <cctype>
53 #include <strstream>
54 #include <functional>
55
56 #include <QString>
57 #include <QFileInfo>
58
59 //#define COUT
60
61 using namespace std;
62
63 namespace VISU
64 {
65   //---------------------------------------------------------------------------
66   static std::string PREFIX("  ");
67
68   typedef std::map<std::string,std::string> TName2EntryMap;
69   typedef std::map<std::string,std::string> TEntry2NameMap;
70
71
72   //---------------------------------------------------------------------------
73   inline
74   std::string
75   GenerateName(std::string theName,
76                SALOMEDS::SObject_ptr theSObject,
77                TName2EntryMap& theName2EntryMap,
78                TEntry2NameMap& theEntry2NameMap,
79                char theSuffix)
80   {
81     if(theName2EntryMap.find(theName) != theName2EntryMap.end()){
82       theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix);
83     }else{
84       CORBA::String_var anID = theSObject->GetID();
85       theName2EntryMap[theName] = anID.in();
86       theEntry2NameMap[anID.in()] = theName;
87       //cout<<"GenerateName - "<<theName<<" => "<<anID.in()<<endl;
88     }
89
90     return theName;
91   }
92
93
94   //---------------------------------------------------------------------------
95   struct TReplacePredicate
96   {
97     bool operator()(char theChar) const
98     {
99       return !(isdigit(theChar) || isalpha(theChar) || theChar == '_');
100     }
101   };
102
103
104   //---------------------------------------------------------------------------
105   inline
106   std::string
107   GetName(SALOMEDS::SObject_ptr theSObject)
108   {
109     CORBA::String_var aString = theSObject->GetName();
110
111     std::string aName = QString(aString.in()).simplified().toLatin1().data();
112
113     //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_');
114     replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_');
115
116     if ( isdigit( aName[0] ))
117       aName.insert( 0, 1, 'a' );
118
119     return aName;
120   }
121
122
123   //---------------------------------------------------------------------------
124   inline
125   std::string
126   GenerateName(SALOMEDS::SObject_ptr theSObject,
127                TName2EntryMap& theName2EntryMap,
128                TEntry2NameMap& theEntry2NameMap)
129   {
130     std::string aName = GetName(theSObject);
131
132     return GenerateName(aName, theSObject, theName2EntryMap, theEntry2NameMap, 'X');
133   }
134
135
136   //---------------------------------------------------------------------------
137   inline
138   std::string
139   GetBoolean(bool theArgument)
140   {
141     if(theArgument)
142       return "True";
143
144     return "False";
145   }
146
147
148   //---------------------------------------------------------------------------
149   inline
150   std::string
151   GetColor(const SALOMEDS::Color& theColor)
152   {
153     std::ostringstream aStream;
154     aStream<<"SALOMEDS.Color("<<theColor.R<<", "<<theColor.G<<", "<<theColor.B<<")";
155     return aStream.str();
156   }
157
158
159   //---------------------------------------------------------------------------
160   typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy,
161                                 CORBA::Boolean theIsPublished,
162                                 CORBA::Boolean& theIsValidScript,
163                                 SALOMEDS::SObject_ptr theSObject,
164                                 std::ostream& theStr,
165                                 TName2EntryMap& theName2EntryMap,
166                                 TEntry2NameMap& theEntry2NameMap,
167                                 std::string theArgumentName,
168                                 std::string thePrefix);
169
170
171   void
172   DumpToPython(SALOMEDS::Study_ptr theStudy,
173                CORBA::Boolean theIsPublished,
174                CORBA::Boolean& theIsValidScript,
175                SALOMEDS::SObject_ptr theSObject,
176                std::ostream& theStr,
177                TName2EntryMap& theName2EntryMap,
178                TEntry2NameMap& theEntry2NameMap,
179                std::string theArgumentName,
180                std::string thePrefix);
181
182
183   //---------------------------------------------------------------------------
184   void SetClippingPlane(Prs3d_i* thePrs, string theName,
185                         std::ostream& theStr,
186                         std::string thePrefix) 
187   {
188     VISU_CutPlaneFunction* aPlane;
189     VISU_Gen_i* aGen = VISU_Gen_i::GetVisuGenImpl();
190     VISU_ClippingPlaneMgr& aMgr = aGen->GetClippingPlaneMgr();
191     int aId;
192     for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) {
193       aPlane = dynamic_cast<VISU_CutPlaneFunction*>(thePrs->GetClippingPlane(i));
194       if (aPlane) {
195         if (!aPlane->isAuto()) {
196           aId = aMgr.GetPlaneId(aPlane);
197           if (aId > -1) {
198             theStr<<thePrefix<<"aVisu.ApplyClippingPlane("<<theName<<", "<<aId<<")"<<endl;
199           }
200         }
201       }
202     }
203   }
204   
205
206   void
207   Prs3dToPython(VISU::Prs3d_i* theServant,
208                 std::ostream& theStr,
209                 const std::string& theName,
210                 std::string thePrefix)
211   {
212     float x, y, z;
213     theServant->GetOffset(x,y,z);
214     theStr<<thePrefix<<theName<<".SetOffset("<<x<<", "<<y<<", "<<z<<")"<<endl;
215     SetClippingPlane(theServant, theName, theStr, thePrefix);
216
217     VISU::MarkerType aMarkerType = theServant->GetMarkerType();
218     if( aMarkerType != VISU::MT_NONE ) {
219       if( aMarkerType != VISU::MT_USER ) {
220         VISU::MarkerScale aMarkerScale = theServant->GetMarkerScale();
221         std::string aParam1, aParam2;
222         switch( aMarkerType ) {
223         case MT_POINT:   aParam1 = "MT_POINT"; break;
224         case MT_PLUS:    aParam1 = "MT_PLUS"; break;
225         case MT_STAR:    aParam1 = "MT_STAR"; break;
226         case MT_O:       aParam1 = "MT_O"; break;
227         case MT_X:       aParam1 = "MT_X"; break;
228         case MT_O_POINT: aParam1 = "MT_O_POINT"; break;
229         case MT_O_PLUS:  aParam1 = "MT_O_PLUS"; break;
230         case MT_O_STAR:  aParam1 = "MT_O_STAR"; break;
231         case MT_O_X:     aParam1 = "MT_O_X"; break;
232         default:         aParam1 = "MT_NONE"; break;
233         }
234         switch( aMarkerScale ) {
235         case MS_10:      aParam2 = "MS_10"; break;
236         case MS_15:      aParam2 = "MS_15"; break;
237         case MS_20:      aParam2 = "MS_20"; break;
238         case MS_25:      aParam2 = "MS_25"; break;
239         case MS_30:      aParam2 = "MS_30"; break;
240         case MS_35:      aParam2 = "MS_35"; break;
241         case MS_40:      aParam2 = "MS_40"; break;
242         case MS_45:      aParam2 = "MS_45"; break;
243         case MS_50:      aParam2 = "MS_50"; break;
244         case MS_55:      aParam2 = "MS_55"; break;
245         case MS_60:      aParam2 = "MS_60"; break;
246         case MS_65:      aParam2 = "MS_65"; break;
247         case MS_70:      aParam2 = "MS_70"; break;
248         default:         aParam2 = "MT_NONE"; break;
249         }
250         theStr<<thePrefix<<theName<<".SetMarkerStd(VISU."<<aParam1<<", VISU."<<aParam2<<")"<<endl;
251       }
252       else {
253         int aMarkerTexture = theServant->GetMarkerTexture();
254         if( aMarkerTexture >= 0 )
255           theStr<<thePrefix<<theName<<".SetMarkerTexture(texture_map["<<aMarkerTexture<<"])"<<endl;
256       }
257     }
258   }
259
260   //---------------------------------------------------------------------------
261   struct TColoredPrs3dFactory
262   {
263     virtual
264     std::string
265     operator()(std::ostream& theStr,
266                std::string thePrefix)
267     {
268
269       return thePrefix;
270     }
271   };
272
273
274   struct TCreateFromResult: TColoredPrs3dFactory
275   {
276     VISU::ColoredPrs3d_i* myServant;
277     std::string myConstructorName;
278     std::string myArgumentName;
279
280     SALOMEDS::SObject_var mySObject;
281     std::string myName;
282
283     TCreateFromResult(const SALOMEDS::SObject_ptr theSObject,
284                       VISU::ColoredPrs3d_i* theServant,
285                       const std::string& theName,
286                       const std::string& theConstructorName,
287                       const std::string& theArgumentName):
288       myServant(theServant),
289       myConstructorName(theConstructorName),
290       myArgumentName(theArgumentName),
291       myName(theName)
292     {
293       mySObject = SALOMEDS::SObject::_duplicate(theSObject);
294     }
295
296     virtual
297     std::string
298     operator()(std::ostream& theStr,
299                std::string thePrefix)
300     {
301       std::string aParam;
302       switch(myServant->GetEntity()){
303       case NODE:
304         aParam = "VISU.NODE";
305         break;
306       case EDGE:
307         aParam = "VISU.EDGE";
308         break;
309       case FACE:
310         aParam = "VISU.FACE";
311         break;
312       case CELL:
313         aParam = "VISU.CELL";
314         break;
315       }
316
317       theStr<<thePrefix<<myName<<" = aVisu."<<myConstructorName<<"("<<myArgumentName<<
318         ", '"<<myServant->GetCMeshName()<<"'"<<
319         ", "<<aParam<<
320         ", '"<<myServant->GetCFieldName()<<"'"<<
321         ", "<<myServant->GetTimeStampNumber()<<
322         ")"<<endl;
323       
324       theStr<<thePrefix<<"if "<<myName<<" != None:"<<endl;
325       thePrefix += PREFIX;
326       
327       // Add to Name->Object map
328       theStr<<thePrefix<<"aName2ObjectMap['"<<myName<<"'] = "<<myName<<endl;
329
330       // Set name (as this object could be renamed by user)
331       CORBA::String_var aNameInStudy = mySObject->GetName();
332       theStr<<thePrefix<<"visu.SetName("<<myName<<", '"<<aNameInStudy.in()<<"')"<<endl;
333
334       return thePrefix;
335     }
336   };
337
338
339   //---------------------------------------------------------------------------
340   std::string
341   ColoredPrs3dToPython(SALOMEDS::SObject_ptr theSObject,
342                        VISU::ColoredPrs3d_i* theServant,
343                        std::ostream& theStr,
344                        const std::string& theName,
345                        TColoredPrs3dFactory& thePrsFactory,
346                        std::string thePrefix)
347   {
348     thePrefix = thePrsFactory(theStr, thePrefix);
349
350     // Set parameters common for all Prs3d objects (offset values)
351     Prs3dToPython(theServant, theStr, theName, thePrefix);
352
353     theStr<<thePrefix<<theName<<".SetPosition("<<theServant->GetPosX()<<", "<<theServant->GetPosY()<<")"<<endl;
354     theStr<<thePrefix<<theName<<".SetSize("<<theServant->GetWidth()<<", "<<theServant->GetHeight()<<")"<<endl;
355     theStr<<thePrefix<<theName<<".SetNbColors("<<theServant->GetNbColors()<<")"<<endl;
356     theStr<<thePrefix<<theName<<".SetLabels("<<theServant->GetLabels()<<")"<<endl;
357     theStr<<thePrefix<<theName<<".SetTitle('"<<theServant->GetTitle()<<"')"<<endl;
358
359     std::string aParam;
360     switch(theServant->GetBarOrientation()){
361     case ColoredPrs3dBase::HORIZONTAL:
362       aParam = "VISU.ColoredPrs3d.HORIZONTAL";
363       break;
364     case ColoredPrs3dBase::VERTICAL:
365       aParam = "VISU.ColoredPrs3d.VERTICAL";
366       break;
367     }
368     theStr<<thePrefix<<theName<<".SetBarOrientation("<<aParam<<")"<<endl;
369
370     theStr<<thePrefix<<theName<<".SetScalarMode("<<theServant->GetScalarMode()<<")"<<endl;
371
372     if(theServant->IsRangeFixed())
373       theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
374     else
375       theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
376
377     const VISU::ColoredPrs3d_i::TGroupNames aGroupNames = theServant->GetGroupNames();
378     VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
379     for(; anIter != aGroupNames.end(); anIter++){
380       const std::string& aGroupName = *anIter;
381       theStr<<thePrefix<<theName<<".AddMeshOnGroup('"<<aGroupName<<"')"<<endl;
382     }
383     
384     return thePrefix;
385   }
386
387
388   //---------------------------------------------------------------------------
389   std::string
390   GaussPointsToPython(SALOMEDS::SObject_ptr theSObject,
391                       VISU::GaussPoints_i* theServant,
392                       std::ostream& theStr,
393                       const std::string& theName,
394                       TColoredPrs3dFactory& thePrsFactory,
395                       std::string thePrefix)
396   {
397     thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
398     theStr<<thePrefix<<endl;
399
400     bool aBoolean = theServant->GetIsActiveLocalScalarBar();
401     theStr<<thePrefix<<theName<<".SetIsActiveLocalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
402
403     if(aBoolean){
404       aBoolean = theServant->GetIsDispGlobalScalarBar();
405       theStr<<thePrefix<<theName<<".SetIsDispGlobalScalarBar("<<GetBoolean(aBoolean)<<")"<<endl;
406     }
407
408     theStr<<thePrefix<<theName<<".SetSpacing("<<theServant->GetSpacing()<<")"<<endl;
409
410     aBoolean = theServant->GetBiColor();
411     theStr<<thePrefix<<theName<<".SetBiColor("<<GetBoolean(aBoolean)<<")"<<endl;
412
413     aBoolean = theServant->GetIsDeformed();
414     theStr<<thePrefix<<theName<<".SetIsDeformed("<<GetBoolean(aBoolean)<<")"<<endl;
415     theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
416
417     std::string aParam;
418     switch(theServant->GetPrimitiveType()){
419     case VISU::GaussPoints::SPRITE :
420       aParam = "VISU.GaussPoints.SPRITE";
421       break;
422     case VISU::GaussPoints::POINT :
423       aParam = "VISU.GaussPoints.POINT";
424       break;
425     case VISU::GaussPoints::SPHERE :
426       aParam = "VISU.GaussPoints.SPHERE";
427       break;
428     }
429     theStr<<thePrefix<<theName<<".SetPrimitiveType("<<aParam<<")"<<endl;
430
431     theStr<<thePrefix<<theName<<".SetClamp("<<theServant->GetClamp()<<")"<<endl;
432
433     QString aMainTexture = theServant->GetQMainTexture();
434     QString anAlphaTexture = theServant->GetQAlphaTexture();
435     theStr<<thePrefix<<theName<<".SetTextures('"<<aMainTexture.toLatin1().data()<<"', '"<<anAlphaTexture.toLatin1().data()<<"')"<<endl;
436
437     theStr<<thePrefix<<theName<<".SetAlphaThreshold("<<theServant->GetAlphaThreshold()<<")"<<endl;
438
439     theStr<<thePrefix<<theName<<".SetResolution("<<theServant->GetResolution()<<")"<<endl;
440
441     theStr<<thePrefix<<theName<<".SetFaceLimit("<<theServant->GetFaceLimit()<<")"<<endl;
442
443     aBoolean = theServant->GetIsColored();
444     theStr<<thePrefix<<theName<<".SetIsColored("<<GetBoolean(aBoolean)<<")"<<endl;
445
446     if(aBoolean){
447       theStr<<thePrefix<<theName<<".SetMinSize("<<theServant->GetMinSize()<<")"<<endl;
448       theStr<<thePrefix<<theName<<".SetMaxSize("<<theServant->GetMaxSize()<<")"<<endl;
449     }else{
450       theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
451       theStr<<thePrefix<<theName<<".SetGeomSize("<<theServant->GetGeomSize()<<")"<<endl;
452     }
453
454     theStr<<thePrefix<<theName<<".SetMagnification("<<theServant->GetMagnification()<<")"<<endl;
455     theStr<<thePrefix<<theName<<".SetMagnificationIncrement("<<theServant->GetMagnificationIncrement()<<")"<<endl;
456     
457     std::string aVisible = theServant->IsBarVisible()? "True" : "False";
458     theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
459
460     return thePrefix;
461   }
462
463
464   //---------------------------------------------------------------------------
465   std::string
466   ScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
467                     VISU::ScalarMap_i* theServant,
468                     std::ostream& theStr,
469                     const std::string& theName,
470                     TColoredPrs3dFactory& thePrsFactory,
471                     std::string thePrefix)
472   {
473     thePrefix = ColoredPrs3dToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
474     theStr<<thePrefix<<endl;
475
476     std::string aParam;
477     switch(theServant->GetScaling()){
478     case LINEAR:
479       aParam = "VISU.LINEAR";
480       break;
481     case LOGARITHMIC:
482       aParam = "VISU.LOGARITHMIC";
483       break;
484     }
485     std::string aVisible = theServant->IsBarVisible()? "True" : "False";
486     theStr<<thePrefix<<theName<<".SetScaling("<<aParam<<")"<<endl;
487     theStr<<thePrefix<<theName<<".SetBarVisible("<<aVisible<<")"<<endl;
488
489     switch(theServant->GetGaussMetric()){
490     case AVERAGE:
491       aParam = "VISU.AVERAGE";
492       break;
493     case MINIMUM:
494       aParam = "VISU.MINIMUM";
495       break;
496     case MAXIMUM:
497       aParam = "VISU.MAXIMUM";
498       break;
499     }
500     theStr<<thePrefix<<theName<<".SetGaussMetric("<<aParam<<")"<<endl;
501
502     SALOMEDS::Color aColor = theServant->GetLinkColor();
503     theStr<<thePrefix<<theName<<".SetLinkColor(SALOMEDS.Color("<<
504       aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
505
506     if(theServant->IsRangeFixed())
507       theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
508     else
509       theStr<<thePrefix<<theName<<".SetSourceRange()"<<endl;
510
511     return thePrefix;
512   }
513
514   //---------------------------------------------------------------------------
515   std::string
516   MonoColorPrsToPython(SALOMEDS::SObject_ptr theSObject,
517                        VISU::MonoColorPrs_i* theServant,
518                        std::ostream& theStr,
519                        const std::string& theName,
520                        TColoredPrs3dFactory& thePrsFactory,
521                        std::string thePrefix)
522   {
523     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
524     theStr<<thePrefix<<endl;
525     theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
526     theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
527     return thePrefix;
528   }
529
530   //---------------------------------------------------------------------------
531   std::string
532   DeformedShapeToPython(SALOMEDS::SObject_ptr theSObject,
533                         VISU::DeformedShape_i* theServant,
534                         std::ostream& theStr,
535                         const std::string& theName,
536                         TColoredPrs3dFactory& thePrsFactory,
537                         std::string thePrefix)
538   {
539     thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
540     theStr<<thePrefix<<endl;
541
542     theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
543 //     theStr<<thePrefix<<theName<<".ShowColored("<<GetBoolean(theServant->IsColored())<<")"<<endl;
544 //     theStr<<thePrefix<<theName<<".SetColor("<<GetColor(theServant->GetColor())<<")"<<endl;
545
546     return thePrefix;
547   }
548
549
550   //---------------------------------------------------------------------------
551   std::string
552   StreamLinesToPython(SALOMEDS::SObject_ptr theSObject,
553                       VISU::StreamLines_i* theServant,
554                       std::ostream& theStr,
555                       TEntry2NameMap& theEntry2NameMap,
556                       const std::string& theName,
557                       TColoredPrs3dFactory& thePrsFactory,
558                       std::string thePrefix)
559   {
560     thePrefix = MonoColorPrsToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
561     //    thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
562     theStr<<thePrefix<<endl;
563     
564     std::string aParam;
565     switch(theServant->GetDirection()){
566     case StreamLines::FORWARD:
567       aParam = "VISU.StreamLines.FORWARD";
568       break;
569     case StreamLines::BACKWARD:
570       aParam = "VISU.StreamLines.BACKWARD";
571       break;
572     case StreamLines::BOTH:
573       aParam = "VISU.StreamLines.BOTH";
574       break;
575     }
576     
577     theStr<<thePrefix<<"aPrs3d = None"<<endl;
578     VISU::Prs3d_var aPrs3d = theServant->GetSource();
579     if(!CORBA::is_nil(aPrs3d)){
580       if(Prs3d_i* aServant3d = dynamic_cast<Prs3d_i*>(GetServant(aPrs3d).in())){
581         SALOMEDS::SObject_var aSObject = aServant3d->GetSObject();
582         CORBA::String_var anID = aSObject->GetID();
583         std::string anArg = theEntry2NameMap[anID.in()];
584         theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
585         thePrefix += PREFIX;
586         theStr<<thePrefix<<"aPrs3d = aName2ObjectMap['"<<anArg<<"']"<<endl;
587       }
588     }
589     
590     theStr<<thePrefix<<theName<<".SetParams("<<
591       theServant->GetIntegrationStep()<<", "<<
592       theServant->GetPropagationTime()<<", "<<
593       theServant->GetStepLength()<<", "<<
594       "aPrs3d"<<", "<<
595       theServant->GetUsedPoints()<<", "<<
596       aParam<<
597       ")"<<endl;
598     
599     return thePrefix;
600   }
601
602
603   //---------------------------------------------------------------------------
604   std::string
605   DeformedShapeAndScalarMapToPython(SALOMEDS::SObject_ptr theSObject,
606                                     VISU::DeformedShapeAndScalarMap_i* theServant,
607                                     std::ostream& theStr,
608                                     const std::string& theName,
609                                     TColoredPrs3dFactory& thePrsFactory,
610                                     std::string thePrefix)
611   {
612     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
613     theStr<<thePrefix<<endl;
614
615     theStr<<thePrefix<<theName<<".SetRange("<<theServant->GetMin()<<", "<<theServant->GetMax()<<")"<<endl;
616     theStr<<thePrefix<<theName<<".SetScale("<<theServant->GetScale()<<")"<<endl;
617
618     std::string aParam;
619     VISU::Entity anEntity = theServant->GetScalarEntity();
620     switch(anEntity){
621     case NODE:
622       aParam = "VISU.NODE";
623       break;
624     case EDGE:
625       aParam = "VISU.EDGE";
626       break;
627     case FACE:
628       aParam = "VISU.FACE";
629       break;
630     case CELL:
631       aParam = "VISU.CELL";
632       break;
633     }
634     
635     CORBA::String_var aFieldName = theServant->GetScalarFieldName();
636     CORBA::Long aTimeStampNumber = theServant->GetScalarTimeStampNumber();
637     
638     theStr<<thePrefix<<theName<<".SetScalarField("<<
639       aParam<<", "<<
640       "'"<<aFieldName<<"', "<<
641       aTimeStampNumber<<
642       ")"<<endl;
643
644     return thePrefix;
645   }
646
647
648   //---------------------------------------------------------------------------
649   std::string
650   VectorsToPython(SALOMEDS::SObject_ptr theSObject,
651                   VISU::Vectors_i* theServant,
652                   std::ostream& theStr,
653                   const std::string& theName,
654                   TColoredPrs3dFactory& thePrsFactory,
655                   std::string thePrefix)
656   {
657     thePrefix = DeformedShapeToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
658     theStr<<thePrefix<<endl;
659
660     theStr<<thePrefix<<theName<<".SetLineWidth("<<theServant->GetLineWidth()<<")"<<endl;
661
662     std::string aParam;
663     switch(theServant->GetGlyphType()){
664     case Vectors::ARROW:
665       aParam = "VISU.Vectors.ARROW";
666       break;
667     case Vectors::CONE2:
668       aParam = "VISU.Vectors.CONE2";
669       break;
670     case Vectors::CONE6:
671       aParam = "VISU.Vectors.CONE6";
672       break;
673     case Vectors::NONE:
674       aParam = "VISU.Vectors.NONE";
675       break;
676     }
677     theStr<<thePrefix<<theName<<".SetGlyphType("<<aParam<<")"<<endl;
678     
679     switch(theServant->GetGlyphPos()){
680     case Vectors::CENTER:
681       aParam = "VISU.Vectors.CENTER";
682       break;
683     case Vectors::TAIL:
684       aParam = "VISU.Vectors.TAIL";
685       break;
686     case Vectors::HEAD:
687       aParam = "VISU.Vectors.HEAD";
688       break;
689     }
690     theStr<<thePrefix<<theName<<".SetGlyphPos("<<aParam<<")"<<endl;
691     
692     return thePrefix;
693   }
694
695
696   //---------------------------------------------------------------------------
697   std::string
698   IsoSurfacesToPython(SALOMEDS::SObject_ptr theSObject,
699                       VISU::IsoSurfaces_i* theServant,
700                       std::ostream& theStr,
701                       const std::string& theName,
702                       TColoredPrs3dFactory& thePrsFactory,
703                       std::string thePrefix)
704   {
705     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
706     theStr<<thePrefix<<endl;
707
708     theStr<<thePrefix<<theName<<".SetNbSurfaces("<<theServant->GetNbSurfaces()<<")"<<endl;
709     theStr<<thePrefix<<theName<<".ShowLabels("<<theServant->IsLabeled()<<","<<theServant->GetNbLabels()<<")"<<endl;
710
711     return thePrefix;
712   }
713
714
715   //---------------------------------------------------------------------------
716   std::string
717   CutPlanesToPython(SALOMEDS::SObject_ptr theSObject,
718                     VISU::CutPlanes_i* theServant,
719                     std::ostream& theStr,
720                     const std::string& theName,
721                     TColoredPrs3dFactory& thePrsFactory,
722                     std::string thePrefix)
723   {
724     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
725     theStr<<thePrefix<<endl;
726
727     std::string aParam;
728     switch(theServant->GetOrientationType()){
729     case CutPlanes::XY:
730       aParam = "VISU.CutPlanes.XY";
731       break;
732     case CutPlanes::YZ:
733       aParam = "VISU.CutPlanes.YZ";
734       break;
735     case CutPlanes::ZX:
736       aParam = "VISU.CutPlanes.ZX";
737       break;
738     }
739     theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
740     
741     theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
742     CORBA::Long aNbPlanes = theServant->GetNbPlanes();
743     theStr<<thePrefix<<theName<<".SetNbPlanes("<<aNbPlanes<<")"<<endl;
744     
745     for(CORBA::Long anId = 0; anId < aNbPlanes; anId++){
746       if(!theServant->IsDefault(anId))
747         theStr<<thePrefix<<theName<<".SetPlanePosition("<<anId<<", "<<theServant->GetPlanePosition(anId)<<")"<<endl;
748     }
749
750     theStr<<thePrefix<<theName<<".UseDeformation("<<GetBoolean(theServant->IsDeformed())<<")"<<endl;
751     if(theServant->IsDeformed()){
752       theStr<< thePrefix << theName << ".SetScale(" << theServant->GetScale()<<")"<<endl;
753       std::string aStringEntity;
754       VISU::Entity anEntity = theServant->GetVectorialFieldEntity();
755       switch(anEntity){
756       case NODE:
757         aStringEntity = "VISU.NODE";
758         break;
759       case EDGE:
760         aStringEntity = "VISU.EDGE";
761         break;
762       case FACE:
763         aStringEntity = "VISU.FACE";
764         break;
765       case CELL:
766         aStringEntity = "VISU.CELL";
767         break;
768       }
769       theStr<< thePrefix << theName << ".SetVectorialField("<<aStringEntity<<", '" << theServant->GetVectorialFieldName() <<"')"<<endl;
770     }
771     return thePrefix;
772   }
773
774
775   //---------------------------------------------------------------------------
776   std::string
777   CutLinesToPython(SALOMEDS::SObject_ptr theSObject,
778                    VISU::CutLines_i* theServant,
779                    std::ostream& theStr,
780                    const std::string& theName,
781                    TColoredPrs3dFactory& thePrsFactory,
782                    std::string thePrefix)
783   {
784     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
785     theStr<<thePrefix<<endl;
786
787     std::string aParam;
788     switch(theServant->GetOrientationType()){
789     case CutPlanes::XY:
790       aParam = "VISU.CutPlanes.XY";
791       break;
792     case CutPlanes::YZ:
793       aParam = "VISU.CutPlanes.YZ";
794       break;
795     case CutPlanes::ZX:
796       aParam = "VISU.CutPlanes.ZX";
797       break;
798     }
799     theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
800     
801     switch(theServant->GetOrientationType2()){
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<<theName<<".SetOrientation2("<<aParam<<", "<<theServant->GetRotateX2()<<", "<<theServant->GetRotateY2()<<")"<<endl;
813     
814     theStr<<thePrefix<<theName<<".SetDisplacement("<<theServant->GetDisplacement()<<")"<<endl;
815     theStr<<thePrefix<<theName<<".SetDisplacement2("<<theServant->GetDisplacement2()<<")"<<endl;
816     
817     if(!theServant->IsDefault())
818       theStr<<thePrefix<<theName<<".SetBasePlanePosition("<<theServant->GetBasePlanePosition()<<")"<<endl;
819     
820     CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
821     theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
822     
823     CORBA::Long aNbLines = theServant->GetNbLines();
824     theStr<<thePrefix<<theName<<".SetNbLines("<<aNbLines<<")"<<endl;
825     for(CORBA::Long anId = 0; anId < aNbLines; anId++){
826       if(!theServant->IsDefaultPosition(anId))
827         theStr<<thePrefix<<theName<<".SetLinePosition("<<anId<<", "<<theServant->GetLinePosition(anId)<<")"<<endl;
828     }
829     
830     return thePrefix;
831   }
832
833
834   //---------------------------------------------------------------------------
835   std::string
836   CutSegmentToPython(SALOMEDS::SObject_ptr theSObject,
837                      VISU::CutSegment_i* theServant,
838                      std::ostream& theStr,
839                      const std::string& theName,
840                      TColoredPrs3dFactory& thePrsFactory,
841                      std::string thePrefix)
842   {
843     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
844     theStr<<thePrefix<<endl;
845
846     double x1, y1, z1, x2, y2, z2;
847     theServant->GetPoint1(x1, y1, z1);
848     theServant->GetPoint2(x2, y2, z2);
849     theStr<<thePrefix<<theName<<".SetPoint1("<<x1<<", "<<y1<<", "<<z1<<")"<<endl;
850     theStr<<thePrefix<<theName<<".SetPoint2("<<x2<<", "<<y2<<", "<<z2<<")"<<endl;
851
852     CORBA::Boolean aUseAbsLength = theServant->IsUseAbsoluteLength();
853     theStr<<thePrefix<<theName<<".SetUseAbsoluteLength("<<aUseAbsLength<<")"<<endl;
854
855     return thePrefix;
856   }
857
858
859   //---------------------------------------------------------------------------
860   std::string
861   Plot3DToPython(SALOMEDS::SObject_ptr theSObject,
862                  VISU::Plot3D_i* theServant,
863                  std::ostream& theStr,
864                  const std::string& theName,
865                  TColoredPrs3dFactory& thePrsFactory,
866                  std::string thePrefix)
867   {
868     thePrefix = ScalarMapToPython(theSObject, theServant, theStr, theName, thePrsFactory, thePrefix);
869     theStr<<thePrefix<<endl;
870
871     std::string aParam;
872     switch(theServant->GetOrientationType()){
873     case CutPlanes::XY: 
874       aParam = "VISU.Plot3D.XY"; 
875       break;
876     case CutPlanes::YZ: 
877       aParam = "VISU.Plot3D.YZ"; 
878       break;
879     case CutPlanes::ZX: 
880       aParam = "VISU.Plot3D.ZX"; 
881       break;
882     }
883     theStr<<thePrefix<<theName<<".SetOrientation("<<aParam<<", "<<theServant->GetRotateX()<<", "<<theServant->GetRotateY()<<")"<<endl;
884
885     theStr<<thePrefix<<theName<<".SetPlanePosition("<<theServant->GetPlanePosition()<<", "<<theServant->IsPositionRelative()<<")"<<endl;
886     theStr<<thePrefix<<theName<<".SetScaleFactor("<<theServant->GetScaleFactor()<<")"<<endl;
887     theStr<<thePrefix<<theName<<".SetContourPrs("<<theServant->GetIsContourPrs()<<")"<<endl;
888     theStr<<thePrefix<<theName<<".SetNbOfContours("<<theServant->GetNbOfContours()<<")"<<endl;
889
890     return thePrefix;
891   }
892
893   //---------------------------------------------------------------------------
894   // declaration
895   void DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
896                             CORBA::Boolean theIsPublished,
897                             CORBA::Boolean& theIsValidScript,
898                             SALOMEDS::SObject_ptr theSObject,
899                             std::ostream& theStr,
900                             TName2EntryMap& theName2EntryMap,
901                             TEntry2NameMap& theEntry2NameMap,
902                             std::string theArgumentName,
903                             std::string thePrefix);
904
905   //---------------------------------------------------------------------------
906   template<class TTableAttr>
907   void
908   TableAttrToPython(SALOMEDS::Study_ptr theStudy,
909                     CORBA::Boolean theIsPublished,
910                     CORBA::Boolean& theIsValidScript,
911                     SALOMEDS::SObject_ptr theSObject,
912                     TTableAttr theTableAttr,
913                     const std::string& theAttrName,
914                     std::ostream& theStr,
915                     TName2EntryMap& theName2EntryMap,
916                     TEntry2NameMap& theEntry2NameMap,
917                     std::string theArgumentName,
918                     std::string thePrefix)
919   {
920     SALOMEDS::GenericAttribute_var anAttr;
921     SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather();
922     if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
923       SALOMEDS::AttributeString_var aComment =
924         SALOMEDS::AttributeString::_narrow(anAttr);
925       CORBA::String_var aValue = aComment->Value();
926       Storable::TRestoringMap aMap;
927       Storable::StringToMap(aValue.in(),aMap);
928       bool anIsExist;
929       QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
930       if(anIsExist){
931         if(strcmp(aMethodName.toLatin1().data(),"ImportTables") == 0){
932           return;
933         }
934       }
935     }
936
937     std::string aSObjectName = GetName(theSObject);
938     if(theArgumentName.empty())
939       theArgumentName = "aSComponent";
940     theStr<<thePrefix<<aSObjectName<<" = aBuilder.NewObject("<<theArgumentName<<")"<<endl;
941     theStr<<thePrefix<<"if "<<aSObjectName<<":"<<endl;
942     thePrefix += PREFIX;
943
944     theStr<<thePrefix<<"aBuilder.SetName("<<aSObjectName<<", \""<<theSObject->GetName()<<"\")"<<endl; // Fix for IPAL13165
945     std::string aName = "aTableAttr";
946     theStr<<thePrefix<<aName<<" = aBuilder.FindOrCreateAttribute("<<
947       aSObjectName<<", '"<<theAttrName<<"')"<<endl;
948
949     theStr<<thePrefix<<"if "<<aName<<":"<<endl;
950     std::string aPrefix = thePrefix;
951     thePrefix += PREFIX;
952
953     CORBA::String_var aString = theTableAttr->GetTitle();
954     theStr<<thePrefix<<aName<<".SetTitle('"<<aString.in()<<"')"<<endl;
955
956     CORBA::Long aNbColumns = theTableAttr->GetNbColumns();
957     theStr<<thePrefix<<aName<<".SetNbColumns("<<aNbColumns<<")"<<endl;
958
959     CORBA::Long aNbRows = theTableAttr->GetNbRows();
960
961     // push values and their indices into streams
962     strstream values, rows, columns;
963     string comma = "";
964     for(CORBA::Long i = 1; i <= aNbColumns; i++){
965       for(CORBA::Long j = aNbRows; j > 0; j--){
966         if(theTableAttr->HasValue(j,i)){
967           values  << comma << theTableAttr->GetValue(j,i);
968           rows    << comma << j;
969           columns << comma << i;
970           if ( comma.empty() )
971             comma = ",";
972         }
973       }
974     }
975     // push titles and units into streams
976     strstream rowUnits, rowTitles, colTitles;
977     SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits();
978     SALOMEDS::StringSeq_var aRowTitles = theTableAttr->GetRowTitles();
979     comma = "";
980     for(CORBA::Long j = 1; j <= aNbRows; j++){
981       rowUnits  << comma << "'" << aRowUnits [ j - 1 ] << "'";
982       rowTitles << comma << "'" << aRowTitles[ j - 1 ] << "'";
983       if ( comma.empty() )
984         comma = ",";
985     }
986     SALOMEDS::StringSeq_var aColumnTitles = theTableAttr->GetColumnTitles();
987     comma = "";
988     for(CORBA::Long j = 1; j <= aNbColumns; j++){
989       colTitles << comma << "'" << aColumnTitles[ j - 1 ] << "'";
990       if ( comma.empty() )
991         comma = ",";
992     }
993     values    << '\0';
994     rows      << '\0';
995     columns   << '\0';
996     rowUnits  << '\0';
997     rowTitles << '\0';
998     colTitles << '\0';
999     // write FillTable command
1000     theStr<< thePrefix << aName << "_values  = [" << values.str()  << "]" << endl;
1001     theStr<< thePrefix << aName << "_rows    = [" << rows.str()    << "]" << endl;
1002     theStr<< thePrefix << aName << "_columns = [" << columns.str() << "]" << endl;
1003     theStr<< thePrefix << aName << "_rUnits  = [" << rowUnits.str()  << "]" << endl;
1004     theStr<< thePrefix << aName << "_rTitles = [" << rowTitles.str() << "]" << endl;
1005     theStr<< thePrefix << aName << "_cTitles = [" << colTitles.str() << "]" << endl;
1006     theStr<< thePrefix << "visu.FillTable( "
1007       << aName << ", "
1008         << aName << "_values, "
1009           << aName << "_rows, "
1010             << aName << "_columns, "
1011               << aName << "_rTitles, "
1012                 << aName << "_rUnits, "
1013                   << aName << "_cTitles )" << endl;
1014
1015     if(theSObject->FindAttribute(anAttr,"AttributeIOR")){
1016       theStr<<thePrefix<<endl;
1017       std::string aName = "aTable";
1018       theStr<<thePrefix<<"anID = "<<aSObjectName<<".GetID()"<<endl;
1019       theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1020       theArgumentName = aName;
1021
1022       theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1023       std::string aPrefix2 = thePrefix + PREFIX;
1024
1025       // Set name (as this object could be renamed by user)
1026       CORBA::String_var aNameInStudy = theSObject->GetName();
1027       theStr<<aPrefix2<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 1"<<endl;
1028
1029       DumpChildrenToPython(theStudy,
1030                            theIsPublished,
1031                            theIsValidScript,
1032                            theSObject,
1033                            theStr,
1034                            theName2EntryMap,
1035                            theEntry2NameMap,
1036                            theArgumentName,
1037                            aPrefix2);
1038
1039       theStr<<aPrefix2<<"pass"<<endl<<endl;
1040     }
1041
1042     theStr<<thePrefix<<"pass"<<endl<<endl;
1043     theStr<<aPrefix<<"pass"<<endl<<endl;
1044   }
1045
1046
1047   //---------------------------------------------------------------------------
1048   void
1049   DumpChildrenToPython(SALOMEDS::Study_ptr theStudy,
1050                        CORBA::Boolean theIsPublished,
1051                        CORBA::Boolean& theIsValidScript,
1052                        SALOMEDS::SObject_ptr theSObject,
1053                        std::ostream& theStr,
1054                        TName2EntryMap& theName2EntryMap,
1055                        TEntry2NameMap& theEntry2NameMap,
1056                        std::string theArgumentName,
1057                        std::string thePrefix)
1058   {
1059     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1060     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1061       SALOMEDS::SObject_var aSObject = aChildItet->Value();
1062       DumpToPython(theStudy,
1063                    theIsPublished,
1064                    theIsValidScript,
1065                    aSObject,
1066                    theStr,
1067                    theName2EntryMap,
1068                    theEntry2NameMap,
1069                    theArgumentName,
1070                    thePrefix);
1071     }
1072   }
1073
1074
1075   //---------------------------------------------------------------------------
1076   void
1077   DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy,
1078                         CORBA::Boolean theIsPublished,
1079                         CORBA::Boolean& theIsValidScript,
1080                         SALOMEDS::SObject_ptr theSObject,
1081                         std::ostream& theStr,
1082                         TName2EntryMap& theName2EntryMap,
1083                         TEntry2NameMap& theEntry2NameMap,
1084                         std::string theArgumentName,
1085                         std::string thePrefix)
1086   {
1087     SALOMEDS::GenericAttribute_var anAttr;
1088     if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){
1089       SALOMEDS::AttributeTableOfInteger_var aTableAttr =
1090         SALOMEDS::AttributeTableOfInteger::_narrow(anAttr);
1091
1092       TableAttrToPython(theStudy,
1093                         theIsPublished,
1094                         theIsValidScript,
1095                         theSObject,
1096                         aTableAttr,
1097                         "AttributeTableOfInteger",
1098                         theStr,
1099                         theName2EntryMap,
1100                         theEntry2NameMap,
1101                         theArgumentName,
1102                         thePrefix);
1103
1104     }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){
1105       SALOMEDS::AttributeTableOfReal_var aTableAttr =
1106         SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1107
1108       TableAttrToPython(theStudy,
1109                         theIsPublished,
1110                         theIsValidScript,
1111                         theSObject,
1112                         aTableAttr,
1113                         "AttributeTableOfReal",
1114                         theStr,
1115                         theName2EntryMap,
1116                         theEntry2NameMap,
1117                         theArgumentName,
1118                         thePrefix);
1119     }
1120   }
1121
1122
1123
1124   //---------------------------------------------------------------------------
1125   void
1126   DumpToPython(SALOMEDS::Study_ptr theStudy,
1127                CORBA::Boolean theIsPublished,
1128                CORBA::Boolean& theIsValidScript,
1129                SALOMEDS::SObject_ptr theSObject,
1130                std::ostream& theStr,
1131                TName2EntryMap& theName2EntryMap,
1132                TEntry2NameMap& theEntry2NameMap,
1133                std::string theArgumentName,
1134                std::string thePrefix)
1135   {
1136     std::string aName = GetName(theSObject);
1137     if (aName == "")
1138       return;
1139
1140     CORBA::String_var anID = theSObject->GetID();
1141     CORBA::String_var aNameInStudy = theSObject->GetName();
1142
1143     CORBA::Object_var anObj = SObjectToObject(theSObject);
1144     if (!CORBA::is_nil(anObj)) {
1145       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1146       if(!CORBA::is_nil(aBase)){
1147         std::string aName = GenerateName(theSObject, theName2EntryMap, theEntry2NameMap);
1148
1149         VISU::VISUType aType = aBase->GetType();
1150         switch(aType){
1151         case VISU::TRESULT:
1152           if(Result_i* aServant = dynamic_cast<Result_i*>(GetServant(anObj).in())){
1153             std::string aFileName = aServant->GetInitFileName();
1154             Result_i::ECreationId anId = aServant->GetCreationId();
1155             if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){
1156               switch(anId){
1157               case Result_i::eImportFile:
1158                 theStr<<thePrefix<<aName<<" = aVisu.CreateResult('"<<aFileName<<"')"<<endl;
1159
1160                 theStr<<thePrefix<<aName<<".SetBuildGroups("<<
1161                   GetBoolean(aServant->IsGroupsDone())<<")"<<
1162                   endl;
1163
1164                 theStr<<thePrefix<<aName<<".SetBuildFields("<<
1165                   GetBoolean(aServant->IsFieldsDone())<<", "<<
1166                   GetBoolean(aServant->IsMinMaxDone())<<")"<<
1167                   endl;
1168
1169                 theStr<<thePrefix<<aName<<".Build(False, True)"<<endl;
1170
1171                 theStr<<thePrefix<<"if "<<aName<<".IsDone() :"<<endl;
1172                 break;
1173               case Result_i::eCopyAndImportFile:
1174                 theStr<<thePrefix<<aName<<" = aVisu.CopyAndImportFile('"<<aFileName<<"')"<<endl;
1175                 theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1176                 break;
1177               }
1178
1179               thePrefix += PREFIX;
1180               {
1181                 VISU::Result::EntityNames_var aMeshNames = aServant->GetMeshNames();
1182                 if (aMeshNames->length() > 0) {
1183                   for(size_t aMeshId = 0; aMeshId < aMeshNames->length(); aMeshId++){
1184                     CORBA::String_var aMeshName = aMeshNames[aMeshId];
1185                     VISU::Result::EntityNames_var aParts = aServant->GetPartNames(aMeshName);
1186                     if (aParts->length() > 0) {
1187                       for(size_t aPartId = 0; aPartId < aParts->length(); aPartId++){
1188                         CORBA::String_var aPart = aParts[aPartId];
1189                         VISU::Result::Resolution aResolution = aServant->GetResolution(aMeshName, aPart);
1190                         std::string aParam;
1191                         switch(aResolution){
1192                         case VISU::Result::FULL:
1193                           aParam = "VISU.Result.FULL";
1194                           break;
1195                         case VISU::Result::MEDIUM:
1196                           aParam = "VISU.Result.MEDIUM";
1197                           break;
1198                         case VISU::Result::LOW:
1199                           aParam = "VISU.Result.LOW";
1200                           break;
1201                         case VISU::Result::HIDDEN:
1202                           aParam = "VISU.Result.HIDDEN";
1203                           break;
1204                         }
1205                         theStr<<thePrefix<<aName<<".SetResolution('"<<aMeshName.in()<<"', '"<<aPart.in()<<"', "<<aParam<<")"<<endl;
1206                       }
1207                       theStr<<thePrefix<<endl;
1208                     }
1209                   }
1210                 }
1211               }
1212
1213               theArgumentName = aName;
1214               DumpChildrenToPython(theStudy,
1215                                    theIsPublished,
1216                                    theIsValidScript,
1217                                    theSObject,
1218                                    theStr,
1219                                    theName2EntryMap,
1220                                    theEntry2NameMap,
1221                                    theArgumentName,
1222                                    thePrefix);
1223
1224               theStr<<thePrefix<<"pass"<<endl<<endl;
1225             }else{
1226               SALOMEDS::SObject_var aRefSObj;
1227               if(theSObject->FindSubObject(1,aRefSObj)){
1228                 SALOMEDS::SObject_var aTargetRefSObj;
1229                 if(aRefSObj->ReferencedObject(aTargetRefSObj)){
1230                   CORBA::String_var aString = aTargetRefSObj->GetName();
1231                   theStr<<thePrefix<<"aSObject = theStudy.FindObject('"<<aString.in()<<"')"<<endl;
1232                   theStr<<thePrefix<<"if aSObject:"<<endl;
1233                   thePrefix += PREFIX;
1234                   theStr<<thePrefix<<"anObject = aSObject.GetObject()"<<endl;
1235                   theStr<<thePrefix<<"if anObject:"<<endl;
1236                   std::string aPrefix1 = thePrefix;
1237                   thePrefix += PREFIX;
1238
1239                   switch(anId){
1240                   case Result_i::eImportMed:
1241                     theStr<<thePrefix<<aName<<" = aVisu.ImportMed(aSObject)"<<endl;
1242                     break;
1243                   case Result_i::eImportMedField:
1244                     theStr<<thePrefix<<aName<<" = aVisu.ImportMedField(anObject)"<<endl;
1245                     break;
1246                   }
1247
1248                   theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1249                   std::string aPrefix2 = thePrefix;
1250                   thePrefix += PREFIX;
1251
1252                   theArgumentName = aName;
1253                   DumpChildrenToPython(theStudy,
1254                                        theIsPublished,
1255                                        theIsValidScript,
1256                                        theSObject,
1257                                        theStr,
1258                                        theName2EntryMap,
1259                                        theEntry2NameMap,
1260                                        theArgumentName,
1261                                        thePrefix);
1262
1263                   theStr<<thePrefix<<"pass"<<endl<<endl;
1264                   theStr<<aPrefix2<<"pass"<<endl<<endl;
1265                   theStr<<aPrefix1<<"pass"<<endl<<endl;
1266                 }
1267               }
1268             }
1269           }
1270           return;
1271         case VISU::TMESH:
1272           if(Mesh_i* aServant = dynamic_cast<Mesh_i*>(GetServant(anObj).in())){     
1273             VISU::Entity anEntity = aServant->GetEntity();
1274             const std::string& aSubMeshName = aServant->GetSubMeshName();
1275             if(anEntity >= 0){
1276               std::string aParam;
1277               switch(anEntity){
1278               case NODE:
1279                 aParam = "VISU.NODE";
1280                 break;
1281               case EDGE:
1282                 aParam = "VISU.EDGE";
1283                 break;
1284               case FACE:
1285                 aParam = "VISU.FACE";
1286                 break;
1287               case CELL:
1288                 aParam = "VISU.CELL";
1289                 break;
1290               }
1291
1292               if(aSubMeshName == "")
1293                 theStr<<thePrefix<<aName<<" = aVisu.MeshOnEntity("<<theArgumentName<<
1294                   ", '"<<aServant->GetCMeshName()<<"'"<<
1295                   ", "<<aParam<<
1296                   ")"<<endl;
1297               else
1298                 theStr<<thePrefix<<aName<<" = aVisu.FamilyMeshOnEntity("<<theArgumentName<<
1299                   ", '"<<aServant->GetCMeshName()<<"'"<<
1300                   ", "<<aParam<<
1301                   ", '"<<aSubMeshName<<"'"<<
1302                   ")"<<endl;
1303             }else
1304               theStr<<thePrefix<<aName<<" = aVisu.GroupMesh("<<theArgumentName<<
1305                 ", '"<<aServant->GetCMeshName()<<"'"<<
1306                 ", '"<<aSubMeshName<<"'"<<
1307                 ")"<<endl;
1308
1309             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1310             thePrefix += PREFIX;
1311
1312             // Add to Name->Object map
1313             theStr<<thePrefix<<"aName2ObjectMap['"<<aName<<"'] = "<<aName<<endl;
1314
1315             // Set name (as this object could be renamed by user)
1316             theStr<<thePrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1317
1318             // Set parameters common for all Prs3d objects (offset values)
1319             Prs3dToPython(aServant,theStr,aName,thePrefix);
1320
1321             // Set presentation parameters
1322             SALOMEDS::Color aColor;
1323             aColor = aServant->GetCellColor();
1324             theStr<<thePrefix<<aName<<".SetCellColor(SALOMEDS.Color("<<
1325               aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1326
1327             aColor = aServant->GetNodeColor();
1328             theStr<<thePrefix<<aName<<".SetNodeColor(SALOMEDS.Color("<<
1329               aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1330
1331             aColor = aServant->GetLinkColor();
1332             theStr<<thePrefix<<aName<<".SetLinkColor(SALOMEDS.Color("<<
1333               aColor.R<<", "<<aColor.G<<", "<<aColor.B<<"))"<<endl;
1334
1335             std::string aParam;
1336             switch(aServant->GetPresentationType()){
1337             case POINT:
1338               aParam = "VISU.POINT";
1339               break;
1340             case WIREFRAME:
1341               aParam = "VISU.WIREFRAME";
1342               break;
1343             case SHADED:
1344               aParam = "VISU.SHADED";
1345               break;
1346             case INSIDEFRAME:
1347               aParam = "VISU.INSIDEFRAME";
1348               break;
1349             case SURFACEFRAME:
1350               aParam = "VISU.SURFACEFRAME";
1351               break;
1352             case SHRINK:
1353               aParam = "VISU.SHRINK";
1354               break;
1355             }
1356             theStr<<thePrefix<<aName<<".SetPresentationType("<<aParam<<")"<<endl;
1357             theStr<<thePrefix<<aName<<".SetShrink("<<(aServant->IsShrank()? "True" : "False")<<")"<<endl;
1358             theStr<<thePrefix<<endl;
1359
1360             std::string aQuad2DPresent;
1361             switch(aServant->GetQuadratic2DPresentationType()){
1362             case LINES:
1363               aQuad2DPresent = "VISU.LINES";
1364               break;
1365             case ARCS:
1366               aQuad2DPresent = "VISU.ARCS";
1367               break;
1368             }
1369
1370             theStr<<thePrefix<<aName<<".SetQuadratic2DPresentationType("<<aQuad2DPresent<<")"<<endl;
1371             
1372             DumpChildrenToPython(theStudy,
1373                                  theIsPublished,
1374                                  theIsValidScript,
1375                                  theSObject,
1376                                  theStr,
1377                                  theName2EntryMap,
1378                                  theEntry2NameMap,
1379                                  theArgumentName,
1380                                  thePrefix);
1381
1382             theStr<<thePrefix<<"pass"<<endl<<endl;
1383             return;
1384           }
1385           break;
1386         case VISU::TSCALARMAP:
1387           if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(GetServant(anObj).in())){
1388             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "ScalarMapOnField", theArgumentName);
1389             thePrefix = ScalarMapToPython(theSObject, aServant, theStr,aName, aPrsFactory, thePrefix);
1390             theStr<<thePrefix<<"pass"<<endl<<endl;
1391           }
1392           return;
1393         case VISU::TDEFORMEDSHAPE:
1394           if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(GetServant(anObj).in())){
1395             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeOnField", theArgumentName);
1396             thePrefix = DeformedShapeToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1397             theStr<<thePrefix<<"pass"<<endl<<endl;
1398           }
1399           return;
1400         case VISU::TSTREAMLINES:
1401           if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(GetServant(anObj).in())){
1402             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "StreamLinesOnField", theArgumentName);
1403             thePrefix = StreamLinesToPython(theSObject, aServant, theStr, theEntry2NameMap, aName, aPrsFactory, thePrefix);
1404             theStr<<thePrefix<<"pass"<<endl<<endl;
1405           }
1406           return;
1407         case VISU::TSCALARMAPONDEFORMEDSHAPE:
1408         case VISU::TDEFORMEDSHAPEANDSCALARMAP:
1409           if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(GetServant(anObj).in())){
1410             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "DeformedShapeAndScalarMapOnField", theArgumentName);
1411             thePrefix = DeformedShapeAndScalarMapToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1412             theStr<<thePrefix<<"pass"<<endl<<endl;
1413           }
1414           return;
1415         case VISU::TVECTORS:
1416           if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(GetServant(anObj).in())){
1417             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "VectorsOnField", theArgumentName);
1418             thePrefix = VectorsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1419             theStr<<thePrefix<<"pass"<<endl<<endl;
1420           }
1421           return;
1422         case VISU::TISOSURFACES:
1423           if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(GetServant(anObj).in())){
1424             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "IsoSurfacesOnField", theArgumentName);
1425             thePrefix = IsoSurfacesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1426             theStr<<thePrefix<<"pass"<<endl<<endl;
1427           }
1428           return;
1429         case VISU::TCUTPLANES:
1430           if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(GetServant(anObj).in())){
1431             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutPlanesOnField", theArgumentName);
1432             thePrefix = CutPlanesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1433             theStr<<thePrefix<<"pass"<<endl<<endl;
1434           }
1435           return;
1436         case VISU::TCUTLINES:
1437           if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(GetServant(anObj).in())){
1438             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutLinesOnField", theArgumentName);
1439             thePrefix = CutLinesToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1440
1441             theArgumentName = aName;
1442             DumpChildrenToPython(theStudy,
1443                                  theIsPublished,
1444                                  theIsValidScript,
1445                                  theSObject,
1446                                  theStr,
1447                                  theName2EntryMap,
1448                                  theEntry2NameMap,
1449                                  theArgumentName,
1450                                  thePrefix);
1451
1452             theStr<<thePrefix<<"pass"<<endl<<endl;
1453           }
1454           return;
1455         case VISU::TCUTSEGMENT:
1456           if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(GetServant(anObj).in())){
1457             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "CutSegmentOnField", theArgumentName);
1458             thePrefix = CutSegmentToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1459
1460             theArgumentName = aName;
1461             DumpChildrenToPython(theStudy,
1462                                  theIsPublished,
1463                                  theIsValidScript,
1464                                  theSObject,
1465                                  theStr,
1466                                  theName2EntryMap,
1467                                  theEntry2NameMap,
1468                                  theArgumentName,
1469                                  thePrefix);
1470
1471             theStr<<thePrefix<<"pass"<<endl<<endl;
1472           }
1473           return;
1474         case VISU::TPLOT3D:
1475           if (Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(GetServant(anObj).in())) {
1476             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "Plot3DOnField", theArgumentName);
1477             thePrefix = Plot3DToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1478             theStr<<thePrefix<<"pass"<<endl<<endl;
1479           }
1480           return;
1481         case VISU::TPOINTMAP3D:
1482           if (PointMap3d_i* aServant = dynamic_cast<PointMap3d_i*>(GetServant(anObj).in())) {
1483             CORBA::Short aTag = theSObject->Tag();
1484             theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1485             theStr<<thePrefix<<"if anIsFound:"<<endl;
1486             thePrefix += PREFIX;
1487             
1488             theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1489             theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1490             
1491             // Set name (as this object could be renamed by user)
1492             theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1493
1494             // Set PointMap3D Properties
1495
1496             theStr<<thePrefix<<aName<<".SetScaleFactor("<<aServant->GetScaleFactor()<<")"<<endl;
1497             theStr<<thePrefix<<aName<<".SetContourPrs("<<aServant->GetIsContourPrs()<<")"<<endl;
1498             theStr<<thePrefix<<aName<<".SetNbOfContours("<<aServant->GetNbOfContours()<<")"<<endl;
1499
1500             std::string aParam;
1501             switch(aServant->GetScaling()){
1502             case LINEAR:
1503               aParam = "VISU.LINEAR";
1504               break;
1505             case LOGARITHMIC:
1506               aParam = "VISU.LOGARITHMIC";
1507               break;
1508             }
1509             theStr<<thePrefix<<aName<<".SetScaling("<<aParam<<")"<<endl;
1510
1511             theStr<<thePrefix<<aName<<".SetNbColors("<<aServant->GetNbColors()<<")"<<endl;
1512             theStr<<thePrefix<<aName<<".SetLabels("<<aServant->GetLabels()<<")"<<endl;
1513
1514             switch(aServant->GetBarOrientation()){
1515             case ColoredPrs3dBase::HORIZONTAL:
1516               aParam = "VISU.ColoredPrs3d.HORIZONTAL";
1517               break;
1518             case ColoredPrs3dBase::VERTICAL:
1519               aParam = "VISU.ColoredPrs3d.VERTICAL";
1520               break;
1521             }
1522             theStr<<thePrefix<<aName<<".SetBarOrientation("<<aParam<<")"<<endl;
1523
1524             if(aServant->IsRangeFixed())
1525               theStr<<thePrefix<<aName<<".SetRange("<<aServant->GetMin()<<", "<<aServant->GetMax()<<")"<<endl;
1526             else
1527               theStr<<thePrefix<<aName<<".SetSourceRange()"<<endl;
1528
1529             theStr<<thePrefix<<aName<<".SetPosition("<<aServant->GetPosX()<<", "<<aServant->GetPosY()<<")"<<endl;
1530             theStr<<thePrefix<<aName<<".SetSize("<<aServant->GetWidth()<<", "<<aServant->GetHeight()<<")"<<endl;
1531
1532             float dx, dy, dz;
1533             aServant->GetOffset(dx, dy, dz);
1534             theStr<<thePrefix<<aName<<".SetOffset("<<dx<<", "<<dy<<", "<<dz<<")"<<endl;
1535
1536             
1537             theStr<<thePrefix<<endl;
1538             
1539             theArgumentName = aName;
1540             DumpChildrenToPython(theStudy,
1541                                  theIsPublished,
1542                                  theIsValidScript,
1543                                  theSObject,
1544                                  theStr,
1545                                  theName2EntryMap,
1546                                  theEntry2NameMap,
1547                                  theArgumentName,
1548                                  thePrefix);
1549
1550             theStr<<thePrefix<<"pass"<<endl<<endl;
1551           }
1552           return;
1553         case VISU::TGAUSSPOINTS:
1554           if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(GetServant(anObj).in())){
1555             TCreateFromResult aPrsFactory(theSObject, aServant, aName, "GaussPointsOnField", theArgumentName);
1556             thePrefix = GaussPointsToPython(theSObject, aServant, theStr, aName, aPrsFactory, thePrefix);
1557             theStr<<thePrefix<<"pass"<<endl<<endl;
1558           }
1559           return;
1560         case VISU::TCURVE:
1561           if(Curve_i* aServant = dynamic_cast<Curve_i*>(GetServant(anObj).in()))
1562           {
1563             bool withZ = aServant->GetZRow()>0;
1564             bool isV2 = aServant->GetIsV2();
1565               
1566             theStr << thePrefix << "aName2ObjectMap['" << aName << "'] = visu.CreateCurve";
1567             if( isV2 )
1568               theStr << "WithZExt";
1569             else if( withZ )
1570               theStr << "WithZ";
1571             theStr << "(" <<
1572               theArgumentName<< // table
1573               ", "<<aServant->GetHRow()<< // H row
1574               ", "<<aServant->GetVRow(); // V row
1575             if( withZ || isV2 )
1576               theStr << ", " << aServant->GetZRow(); // Z row
1577             if( isV2 )
1578               theStr << ", " << aServant->GetIsV2(); // right axis
1579
1580             theStr << ", '"<<aServant->GetTitle()<<"'"; // title
1581             SALOMEDS::Color aColor = aServant->GetColor();
1582             theStr << ",SALOMEDS.Color("<<
1583               aColor.R<<", "<<aColor.G<<", "<<aColor.B<<")"; // color
1584
1585             std::string aParam;
1586             switch(aServant->GetMarker()){
1587             case Curve::NONE:      aParam = "VISU.Curve.NONE";      break;
1588             case Curve::CIRCLE:    aParam = "VISU.Curve.CIRCLE";    break;
1589             case Curve::RECTANGLE: aParam = "VISU.Curve.RECTANGLE"; break;
1590             case Curve::DIAMOND:   aParam = "VISU.Curve.DIAMOND";   break;
1591             case Curve::DTRIANGLE: aParam = "VISU.Curve.DTRIANGLE"; break;
1592             case Curve::UTRIANGLE: aParam = "VISU.Curve.UTRIANGLE"; break;
1593             case Curve::LTRIANGLE: aParam = "VISU.Curve.LTRIANGLE"; break;
1594             case Curve::RTRIANGLE: aParam = "VISU.Curve.RTRIANGLE"; break;
1595             case Curve::CROSS:     aParam = "VISU.Curve.CROSS";     break;
1596             case Curve::XCROSS:    aParam = "VISU.Curve.XCROSS";    break;
1597             }
1598             theStr<<", "<<aParam; // marker
1599
1600             switch(aServant->GetLine()){
1601             case Curve::VOIDLINE:       aParam = "VISU.Curve.VOIDLINE";       break;
1602             case Curve::SOLIDLINE:      aParam = "VISU.Curve.SOLIDLINE";      break;
1603             case Curve::DASHLINE:       aParam = "VISU.Curve.DASHLINE";       break;
1604             case Curve::DOTLINE:        aParam = "VISU.Curve.DOTLINE";        break;
1605             case Curve::DASHDOTLINE:    aParam = "VISU.Curve.DASHDOTLINE";    break;
1606             case Curve::DASHDOTDOTLINE: aParam = "VISU.Curve.DASHDOTDOTLINE"; break;
1607             }
1608             theStr<<", "<<aParam<<", "<<aServant->GetLineWidth()<<")"<<endl; // line type,width
1609           }
1610           return;
1611         case VISU::TTABLE:
1612           if(dynamic_cast<Table_i*>(GetServant(anObj).in())){
1613             SALOMEDS::GenericAttribute_var anAttr;
1614             if(theSObject->FindAttribute(anAttr,"AttributeString")){
1615               using namespace SALOMEDS;
1616               AttributeString_var aComment = AttributeString::_narrow(anAttr);
1617               CORBA::String_var aValue = aComment->Value();
1618               Storable::TRestoringMap aMap;
1619               Storable::StringToMap(aValue.in(),aMap);
1620               bool anIsExist;
1621               QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist);
1622               if(anIsExist){
1623                 if( aSourceId == "CutLines" ){
1624                   theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<theArgumentName<<"'):"<<endl;
1625                   thePrefix += PREFIX;
1626
1627                   theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<theArgumentName<<"']"<<endl;
1628                   theStr<<thePrefix<<"anIOR = anObject.GetID()"<<endl;
1629                   theStr<<thePrefix<<"aSObject = theStudy.FindObjectIOR(anIOR)"<<endl;
1630                   theStr<<thePrefix<<"if aSObject:"<<endl;
1631                   std::string aPrefix = thePrefix;
1632                   thePrefix += PREFIX;
1633
1634                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1635                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1636
1637                   // Set name (as this object could be renamed by user)
1638                   theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 2"<<endl;
1639
1640                   theStr<<thePrefix<<endl;
1641
1642                   theArgumentName = aName;
1643                   DumpChildrenToPython(theStudy,
1644                                        theIsPublished,
1645                                        theIsValidScript,
1646                                        theSObject,
1647                                        theStr,
1648                                        theName2EntryMap,
1649                                        theEntry2NameMap,
1650                                        theArgumentName,
1651                                        thePrefix);
1652
1653                   theStr<<thePrefix<<"pass"<<endl<<endl;
1654                   theStr<<aPrefix<<"pass"<<endl<<endl;
1655                 }else if( aSourceId == "TableFile" ){
1656                   CORBA::Short aTag = theSObject->Tag();
1657                   theStr<<thePrefix<<"anIsFound, aSObject = "<<theArgumentName<<".FindSubObject("<<aTag<<")"<<endl;
1658                   theStr<<thePrefix<<"if anIsFound:"<<endl;
1659                   thePrefix += PREFIX;
1660
1661                   theStr<<thePrefix<<"anID = aSObject.GetID()"<<endl;
1662                   theStr<<thePrefix<<aName<<" = aVisu.CreateTable(anID)"<<endl;
1663
1664                   // Set name (as this object could be renamed by user)
1665                   theStr<<thePrefix<<aName<<".SetTitle('"<<aNameInStudy.in()<<"') # 3"<<endl;
1666
1667                   theStr<<thePrefix<<endl;
1668
1669                   theArgumentName = aName;
1670                   DumpChildrenToPython(theStudy,
1671                                        theIsPublished,
1672                                        theIsValidScript,
1673                                        theSObject,
1674                                        theStr,
1675                                        theName2EntryMap,
1676                                        theEntry2NameMap,
1677                                        theArgumentName,
1678                                        thePrefix);
1679
1680                   theStr<<thePrefix<<"pass"<<endl<<endl;
1681                 }else if( aSourceId == "TableAttr" ){
1682                   theArgumentName = aName;
1683                   DumpTableAttrToPython(theStudy,
1684                                         theIsPublished,
1685                                         theIsValidScript,
1686                                         theSObject,
1687                                         theStr,
1688                                         theName2EntryMap,
1689                                         theEntry2NameMap,
1690                                         theArgumentName,
1691                                         thePrefix);
1692                 }
1693               }
1694             }
1695           }
1696           return;
1697         }
1698       }
1699     } else { /*if(!CORBA::is_nil(anObj))*/
1700       SALOMEDS::GenericAttribute_var anAttr;
1701       if (theSObject->FindAttribute(anAttr,"AttributeString")) {
1702         SALOMEDS::AttributeString_var aComment =
1703           SALOMEDS::AttributeString::_narrow(anAttr);
1704         CORBA::String_var aValue = aComment->Value();
1705         Storable::TRestoringMap aMap;
1706         Storable::StringToMap(aValue.in(),aMap);
1707         bool anIsExist;
1708         QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
1709         if (anIsExist) {
1710           if (aTypeName == "ImportTables") {
1711             QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist);
1712             if(anIsExist){
1713               std::string aName =
1714                 GenerateName(theSObject,theName2EntryMap,theEntry2NameMap);
1715               QString aFirstStrAsTitle =
1716                 VISU::Storable::FindValue(aMap,"myFirstStrAsTitle",&anIsExist);
1717               theStr<<thePrefix<<aName<<" = aVisu.ImportTables('"
1718                     <<aFileName.toLatin1().data()<<"',"
1719                     <<aFirstStrAsTitle.toLatin1().data()<<")"<<endl;
1720               theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1721               thePrefix += PREFIX;
1722
1723               theArgumentName = aName;
1724               DumpChildrenToPython(theStudy,
1725                                    theIsPublished,
1726                                    theIsValidScript,
1727                                    theSObject,
1728                                    theStr,
1729                                    theName2EntryMap,
1730                                    theEntry2NameMap,
1731                                    theArgumentName,
1732                                    thePrefix);
1733
1734               theStr<<thePrefix<<"pass"<<endl<<endl;
1735               return;
1736             }
1737           } else if (aTypeName == "VIEW3D") {
1738             std::string aName = GetName(theSObject);
1739             theStr<<thePrefix<<aName<<" = aBuilder.NewObject(aSComponent)"<<endl;
1740
1741             theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1742             thePrefix += PREFIX;
1743
1744             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeName')"<<endl;
1745             theStr<<thePrefix<<"anAttr.SetValue('"<<aName<<"')"<<endl;
1746
1747             theStr<<thePrefix<<"anAttr = aBuilder.FindOrCreateAttribute("<<aName<<",'AttributeString')"<<endl;
1748             theStr<<thePrefix<<"anAttr.SetValue('"<<aValue.in()<<"')"<<endl;
1749
1750             theStr<<thePrefix<<"pass"<<endl<<endl;
1751             return;
1752           } else if (aTypeName == "ENTITY" || aTypeName == "FAMILY" || aTypeName == "GROUP") {
1753             // Set name (as this object could be renamed by user)
1754             string aMeshName = VISU::Storable::FindValue(aMap,"myMeshName").toLatin1().data();
1755             string aSubMeshName = VISU::Storable::FindValue(aMap,"myName").toLatin1().data();
1756             string anEntityTypeKey = "myEntityId";
1757             if (aTypeName == "ENTITY") anEntityTypeKey = "myId";
1758             int anEntity = VISU::Storable::FindValue(aMap,anEntityTypeKey,"0").toInt();
1759             std::string anEntityType;
1760             switch ((TEntity)anEntity) {
1761             case NODE_ENTITY: anEntityType = "VISU.NODE"; break;
1762             case EDGE_ENTITY: anEntityType = "VISU.EDGE"; break;
1763             case FACE_ENTITY: anEntityType = "VISU.FACE"; break;
1764             case CELL_ENTITY: anEntityType = "VISU.CELL"; break;
1765             }
1766
1767             if (aTypeName == "ENTITY" ) {
1768               theStr<<thePrefix<<"aVisu.RenameEntityInStudy("<<theArgumentName<<", '"<<aMeshName
1769                     <<"', "<<anEntityType<<", '"<<aNameInStudy.in()<<"')"<<endl;
1770             }
1771             else if (aTypeName == "FAMILY") {
1772               if (aSubMeshName != aNameInStudy.in()) {
1773                 theStr<<thePrefix<<"aVisu.RenameFamilyInStudy("<<theArgumentName<<", '"<<aMeshName
1774                       <<"', "<<anEntityType<<", '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1775               }
1776             }
1777             else { // "GROUP"
1778               if (aSubMeshName != aNameInStudy.in()) {
1779                 theStr<<thePrefix<<"aVisu.RenameGroupInStudy("<<theArgumentName<<", '"<<aMeshName
1780                       <<"', '"<<aSubMeshName<<"', '"<<aNameInStudy.in()<<"')"<<endl;
1781               }
1782             }
1783           }
1784         }
1785       } else {
1786         DumpTableAttrToPython(theStudy,
1787                               theIsPublished,
1788                               theIsValidScript,
1789                               theSObject,
1790                               theStr,
1791                               theName2EntryMap,
1792                               theEntry2NameMap,
1793                               theArgumentName,
1794                               thePrefix);
1795       }
1796     }
1797
1798     DumpChildrenToPython(theStudy,
1799                          theIsPublished,
1800                          theIsValidScript,
1801                          theSObject,
1802                          theStr,
1803                          theName2EntryMap,
1804                          theEntry2NameMap,
1805                          theArgumentName,
1806                          thePrefix);
1807   }
1808
1809
1810   //---------------------------------------------------------------------------
1811   void
1812   DumpCurveToPython(SALOMEDS::Study_ptr theStudy,
1813                     CORBA::Boolean theIsPublished,
1814                     CORBA::Boolean& theIsValidScript,
1815                     SALOMEDS::SObject_ptr theSObject,
1816                     std::ostream& theStr,
1817                     TName2EntryMap& theName2EntryMap,
1818                     TEntry2NameMap& theEntry2NameMap,
1819                     std::string theArgumentName,
1820                     std::string thePrefix)
1821   {
1822     SALOMEDS::SObject_var aTargetRefSObj;
1823     if(theSObject->ReferencedObject(aTargetRefSObj)){
1824       CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj);
1825       if(CORBA::is_nil(anObj))
1826         return;
1827
1828       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1829       if(CORBA::is_nil(aBase))
1830         return;
1831
1832       if(aBase->GetType() == VISU::TCURVE){
1833         CORBA::String_var anID = aTargetRefSObj->GetID();
1834         std::string anArg = theEntry2NameMap[anID.in()];
1835         theStr<<thePrefix<<"if aName2ObjectMap.has_key('"<<anArg<<"'):"<<endl;
1836         thePrefix += PREFIX;
1837         theStr<<thePrefix<<"anObject = aName2ObjectMap['"<<anArg<<"']"<<endl;
1838         theStr<<thePrefix<<"if anObject: " <<theArgumentName<<".AddCurve(anObject)"<<endl;
1839         theStr<<thePrefix<<"pass"<<endl<<endl;
1840       }
1841     }
1842   }
1843
1844
1845   //---------------------------------------------------------------------------
1846   void
1847   DumpContainersToPython(SALOMEDS::Study_ptr theStudy,
1848                          CORBA::Boolean theIsPublished,
1849                          CORBA::Boolean& theIsValidScript,
1850                          SALOMEDS::SObject_ptr theSObject,
1851                          std::ostream& theStr,
1852                          TName2EntryMap& theName2EntryMap,
1853                          TEntry2NameMap& theEntry2NameMap,
1854                          std::string theArgumentName,
1855                          std::string thePrefix)
1856   {
1857     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
1858     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
1859       SALOMEDS::SObject_var aSObject = aChildItet->Value();
1860       CORBA::Object_var anObj = SObjectToObject(aSObject);
1861       if(CORBA::is_nil(anObj))
1862         continue;
1863
1864       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1865       if(CORBA::is_nil(aBase))
1866         continue;
1867
1868       if(aBase->GetType() == VISU::TCONTAINER){
1869         theStr<<thePrefix<<endl;
1870         std::string aName = GenerateName(aSObject,theName2EntryMap,theEntry2NameMap);
1871         theStr<<thePrefix<<aName<<" = aVisu.CreateContainer()"<<endl;
1872         theStr<<thePrefix<<"if "<<aName<<":"<<endl;
1873         std::string aPrefix = thePrefix + PREFIX;
1874         theArgumentName = aName;
1875
1876         // Set name (as this object could be renamed by user)
1877         CORBA::String_var aNameInStudy = aSObject->GetName();
1878         theStr<<aPrefix<<"visu.SetName("<<aName<<", '"<<aNameInStudy.in()<<"')"<<endl;
1879
1880         SALOMEDS::ChildIterator_var aCurveIter = theStudy->NewChildIterator(aSObject);
1881         for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){
1882           SALOMEDS::SObject_var aRefSObj = aCurveIter->Value();
1883           DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix);
1884         }
1885
1886         theStr<<aPrefix<<"pass"<<endl<<endl;
1887       }
1888     }
1889   }
1890
1891
1892   //---------------------------------------------------------------------------
1893   void
1894   DumpPrs3dCacheToPython(SALOMEDS::Study_ptr theStudy,
1895                          CORBA::Boolean theIsPublished,
1896                          CORBA::Boolean& theIsValidScript,
1897                          SALOMEDS::SObject_ptr theSObject,
1898                          std::ostream& theStr,
1899                          TName2EntryMap& theName2EntryMap,
1900                          TEntry2NameMap& theEntry2NameMap,
1901                          std::string theArgumentName,
1902                          std::string thePrefix)
1903   {
1904
1905     SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theSObject);
1906     for(anIter->InitEx(false); anIter->More(); anIter->Next()){
1907       SALOMEDS::SObject_var aSObject = anIter->Value();
1908       CORBA::Object_var anObj = SObjectToObject(aSObject);
1909       if(CORBA::is_nil(anObj))
1910         continue;
1911
1912       VISU::Base_var aBase = VISU::Base::_narrow(anObj);
1913       if(CORBA::is_nil(aBase))
1914         continue;
1915
1916       if(aBase->GetType() == VISU::TCOLOREDPRS3DCACHE){
1917         ColoredPrs3dCache_i* aCache = dynamic_cast<ColoredPrs3dCache_i*>(GetServant(aBase).in());
1918         theStr<<thePrefix<<"aCache = aVisu.GetColoredPrs3dCache(aVisu.GetCurrentStudy())"<<endl;
1919         theStr<<thePrefix<<"if aCache != None:"<<endl;
1920         {
1921           std::string aPrefix = thePrefix + PREFIX;
1922           std::string anArgument;
1923           VISU::ColoredPrs3dCache::MemoryMode aMode = aCache->GetMemoryMode();
1924           switch(aMode){
1925           case VISU::ColoredPrs3dCache::MINIMAL : anArgument = "VISU.ColoredPrs3dCache.MINIMAL"; break;
1926           case VISU::ColoredPrs3dCache::LIMITED : anArgument = "VISU.ColoredPrs3dCache.LIMITED"; break;
1927           }
1928           theStr<<aPrefix<<"aCache.SetMemoryMode("<<anArgument<<")"<<endl;
1929
1930           if(aMode == VISU::ColoredPrs3dCache::LIMITED)
1931             theStr<<aPrefix<<"aCache.SetLimitedMemory("<<aCache->GetLimitedMemory()<<") # (Mb)"<<endl;
1932
1933           SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(aSObject);
1934           for(aChildIter->InitEx(false); aChildIter->More(); aChildIter->Next()){
1935             SALOMEDS::SObject_var aSObject = aChildIter->Value();
1936             CORBA::Object_var anObject = SObjectToObject(aSObject);
1937             if (CORBA::is_nil(anObject))
1938               continue;
1939             
1940             ColoredPrs3dHolder_i* aServant = dynamic_cast<ColoredPrs3dHolder_i*>(GetServant(anObject).in());
1941             if(!aServant)
1942               continue;
1943           
1944             ColoredPrs3d_i* aDevice = aServant->GetPrs3dDevice();
1945             if(!aDevice)
1946               continue;
1947             
1948             Result_i* aResult = aDevice->GetCResult();
1949             std::string aResultEntry = aResult->GetEntry();
1950             std::string aResultName = theEntry2NameMap[aResultEntry];
1951             
1952             ColoredPrs3dHolder::BasicInput_var anInput = aServant->GetBasicInput();
1953             std::string anEntity;
1954             switch(anInput->myEntity){
1955             case VISU::NODE : anEntity = "VISU.NODE"; break;
1956             case VISU::EDGE : anEntity = "VISU.EDGE"; break;
1957             case VISU::FACE : anEntity = "VISU.FACE"; break;
1958             case VISU::CELL : anEntity = "VISU.CELL"; break;
1959             }
1960             
1961             
1962             theStr<<aPrefix<<"anInput = VISU.ColoredPrs3dHolder.BasicInput("<<
1963               aResultName<<", '"<<
1964               anInput->myMeshName<<"', "<<
1965               anEntity<<", '"<<
1966               anInput->myFieldName<<"', "<<
1967               anInput->myTimeStampNumber<<")"<<
1968               endl;
1969           
1970             std::string aComment = aDevice->GetComment();
1971             theStr<<aPrefix<<"aHolder = aCache.CreateHolder(VISU.T"<<aComment<<", anInput)"<<endl;
1972             theStr<<aPrefix<<"if aHolder != None:"<<endl;
1973             {
1974               std::string aPrefix2 = aPrefix + PREFIX;
1975               CORBA::String_var aNameInStudy = aSObject->GetName();
1976               theStr<<aPrefix2<<"visu.SetName(aHolder, '"<<aNameInStudy.in()<<"')"<<endl;
1977               theStr<<aPrefix2<<"aDevice = aHolder.GetDevice()"<<endl;
1978               theStr<<aPrefix2<<"if aDevice != None:"<<endl;
1979               {
1980                 std::string aPrefix3 = aPrefix2 + PREFIX;
1981                 TColoredPrs3dFactory aPrsFactory;
1982                 switch(aDevice->GetType()){
1983                 case VISU::TSCALARMAP:
1984                   if(ScalarMap_i* aServant = dynamic_cast<ScalarMap_i*>(aDevice)){
1985                     ScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1986                     break;
1987                   }
1988                 case VISU::TDEFORMEDSHAPE:
1989                   if(DeformedShape_i* aServant = dynamic_cast<DeformedShape_i*>(aDevice)){
1990                     DeformedShapeToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
1991                     break;
1992                   }
1993                 case VISU::TSTREAMLINES:
1994                   if(StreamLines_i* aServant = dynamic_cast<StreamLines_i*>(aDevice)){
1995                     StreamLinesToPython(aSObject, aServant, theStr, theEntry2NameMap, "aDevice", aPrsFactory, aPrefix3);
1996                     break;
1997                   }
1998                 case VISU::TSCALARMAPONDEFORMEDSHAPE:
1999                 case VISU::TDEFORMEDSHAPEANDSCALARMAP:
2000                   if(DeformedShapeAndScalarMap_i* aServant = dynamic_cast<DeformedShapeAndScalarMap_i*>(aDevice)){
2001                     DeformedShapeAndScalarMapToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2002                     break;
2003                   }
2004                 case VISU::TVECTORS:
2005                   if(Vectors_i* aServant = dynamic_cast<Vectors_i*>(aDevice)){
2006                     VectorsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2007                     break;
2008                   }
2009                 case VISU::TISOSURFACES:
2010                   if(IsoSurfaces_i* aServant = dynamic_cast<IsoSurfaces_i*>(aDevice)){
2011                     IsoSurfacesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2012                     break;
2013                   }
2014                 case VISU::TCUTPLANES:
2015                   if(CutPlanes_i* aServant = dynamic_cast<CutPlanes_i*>(aDevice)){
2016                     CutPlanesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2017                     break;
2018                   }
2019                 case VISU::TCUTLINES:
2020                   if(CutLines_i* aServant = dynamic_cast<CutLines_i*>(aDevice)){
2021                     CutLinesToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2022                     break;
2023                   }
2024                 case VISU::TCUTSEGMENT:
2025                   if(CutSegment_i* aServant = dynamic_cast<CutSegment_i*>(aDevice)){
2026                     CutSegmentToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2027                     break;
2028                   }
2029                 case VISU::TPLOT3D:
2030                   if(Plot3D_i* aServant = dynamic_cast<Plot3D_i*>(aDevice)){
2031                     Plot3DToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2032                     break;
2033                   }
2034                 case VISU::TGAUSSPOINTS:
2035                   if(GaussPoints_i* aServant = dynamic_cast<GaussPoints_i*>(aDevice)){
2036                     GaussPointsToPython(aSObject, aServant, theStr, "aDevice", aPrsFactory, aPrefix3);
2037                     break;
2038                   }
2039                 }
2040                 theStr<<aPrefix3<<"pass"<<endl;
2041               }
2042               theStr<<aPrefix2<<"pass"<<endl<<endl;
2043             }
2044           }
2045           theStr<<aPrefix<<"pass"<<endl;
2046         }
2047       }
2048     }
2049   }
2050
2051     
2052   //---------------------------------------------------------------------------
2053   void
2054   DumpEvolutionsToPython(SALOMEDS::Study_ptr theStudy,
2055                          CORBA::Boolean theIsPublished,
2056                          CORBA::Boolean& theIsValidScript,
2057                          SALOMEDS::SObject_ptr theSObject,
2058                          std::ostream& theStr,
2059                          TName2EntryMap& theName2EntryMap,
2060                          TEntry2NameMap& theEntry2NameMap,
2061                          std::string thePrefix)
2062   {
2063     if(!theIsPublished) return;
2064
2065     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2066     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2067       SALOMEDS::SObject_var aSObject = aChildItet->Value();
2068           
2069       SALOMEDS::GenericAttribute_var anAttr;
2070       if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2071       
2072       SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2073       QString value (aStringAttr->Value());
2074       if(value.isEmpty()) continue;
2075
2076       VISU::Storable::TRestoringMap aMap;
2077       VISU::Storable::StringToMap(value, aMap);
2078       bool isExist;
2079       
2080       QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2081       if(!isExist || aTypeName != "EVOLUTION") continue;
2082
2083       //EVOLUTION
2084       theStr<<thePrefix<<endl;
2085       QString evolutionName = aSObject->GetName();
2086       theStr<<thePrefix<<"#Evolution: "<<evolutionName.toLatin1().data()<<endl;
2087       theStr<<thePrefix<<endl;
2088       theStr<<thePrefix<<"evolutionSO = aBuilder.NewObject(aSComponent)"<<endl;
2089       theStr<<thePrefix<<"aBuilder.SetName(evolutionSO, '"<<evolutionName.toLatin1().data()<<"')"<< endl;
2090       theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(evolutionSO, 'AttributeString')"<< endl;
2091       theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2092
2093       SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2094       for (anIter->Init(); anIter->More(); anIter->Next()) {
2095         SALOMEDS::SObject_var anObj = anIter->Value();
2096
2097         //FIELD
2098         theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(evolutionSO)"<<endl;
2099         if (anObj->FindAttribute(anAttr, "AttributeString")) {
2100           aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2101           theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2102           theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2103         }
2104         
2105         SALOMEDS::SObject_var refObj;
2106         if(anObj->ReferencedObject(refObj)) {
2107           SALOMEDS::SObject_var father = refObj->GetFather();
2108           value = refObj->GetName();
2109           QString path(theStudy->GetObjectPath(father));
2110           //The following code requierd as a field name can contain '/' character
2111           theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2112         }
2113         value = anObj->GetName();
2114         if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2115
2116         //TABLE
2117         SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(anObj);
2118         for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2119           SALOMEDS::SObject_var aSObject = aChildItet->Value();
2120
2121           std::string anArgumentName = "fieldSO";
2122           DumpTableAttrToPython(theStudy,
2123                                 theIsPublished,
2124                                 theIsValidScript,
2125                                 aSObject,
2126                                 theStr,
2127                                 theName2EntryMap,
2128                                 theEntry2NameMap,
2129                                 anArgumentName,
2130                                 thePrefix);
2131         }
2132       }
2133       
2134     }
2135
2136     theStr<<thePrefix<<endl;
2137   }
2138
2139
2140   //---------------------------------------------------------------------------
2141   void
2142   DumpAnimationsToPython(SALOMEDS::Study_ptr theStudy,
2143                          CORBA::Boolean theIsPublished,
2144                          CORBA::Boolean& theIsValidScript,
2145                          SALOMEDS::SObject_ptr theSObject,
2146                          std::ostream& theStr,
2147                          std::string thePrefix)
2148   {
2149
2150     if(!theIsPublished) return;
2151
2152     SALOMEDS::ChildIterator_var aChildItet = theStudy->NewChildIterator(theSObject);
2153     for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){
2154       SALOMEDS::SObject_var aSObject = aChildItet->Value();
2155           
2156       SALOMEDS::GenericAttribute_var anAttr;
2157       if (!aSObject->FindAttribute(anAttr, "AttributeString")) continue;
2158       
2159       SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2160       QString value (aStringAttr->Value());
2161       if(value.isEmpty()) continue;
2162
2163       VISU::Storable::TRestoringMap aMap;
2164       VISU::Storable::StringToMap(value, aMap);
2165       bool isExist;
2166       
2167       QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&isExist);
2168       if(!isExist || aTypeName != "ANIMATION") continue;
2169
2170       //ANIMATION
2171       theStr<<thePrefix<<endl;
2172       QString animName = aSObject->GetName();
2173       theStr<<thePrefix<<"#Animation: "<<animName.toLatin1().data()<<endl;
2174       theStr<<thePrefix<<endl;
2175       theStr<<thePrefix<<"animSO = aBuilder.NewObject(aSComponent)"<<endl;
2176       theStr<<thePrefix<<"aBuilder.SetName(animSO, '"<<animName.toLatin1().data()<<"')"<< endl;
2177       theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(animSO, 'AttributeString')"<< endl;
2178       theStr<<thePrefix<<"strAttr.SetValue('"<<value.toLatin1().data()<<"')"<< endl;
2179
2180
2181     
2182       SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(aSObject);
2183       for (anIter->Init(); anIter->More(); anIter->Next()) {
2184         SALOMEDS::SObject_var anObj = anIter->Value();
2185
2186         //FIELD
2187         theStr<<thePrefix<<"fieldSO = aBuilder.NewObject(animSO)"<<endl;
2188         if (anObj->FindAttribute(anAttr, "AttributeString")) {
2189           aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2190           theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(fieldSO, 'AttributeString')"<< endl;
2191           theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2192         }
2193         
2194         SALOMEDS::SObject_var refObj;
2195         if(anObj->ReferencedObject(refObj)) {
2196           SALOMEDS::SObject_var father = refObj->GetFather();
2197           value = refObj->GetName();
2198           QString path(theStudy->GetObjectPath(father));
2199           //The following code requierd as a field name can contain '/' character
2200           theStr<<thePrefix<<"aBuilder.Addreference(fieldSO,getSObjectByFatherPathAndName(theStudy, '"<<path.toLatin1().data()<<"', '"<<value.toLatin1().data()<<"'))"<<endl;
2201         }
2202         value = anObj->GetName();
2203         if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(fieldSO, '"<<value.toLatin1().data()<<"')"<< endl;
2204
2205         //SCALARMAP,...
2206         SALOMEDS::ChildIterator_var aSubIter = theStudy->NewChildIterator(anObj);
2207         for (aSubIter->Init(); aSubIter->More(); aSubIter->Next()) {
2208           SALOMEDS::SObject_var aSubObj = aSubIter->Value();
2209           
2210           theStr<<thePrefix<<"subSO = aBuilder.NewObject(fieldSO)"<<endl;
2211           value = aSubObj->GetName();
2212           if(!value.isEmpty()) theStr<<thePrefix<<"aBuilder.SetName(subSO, '"<<value.toLatin1().data()<<"')"<< endl;
2213           if (aSubObj->FindAttribute(anAttr, "AttributeString")) {
2214             aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr);
2215             theStr<<thePrefix<<"strAttr = aBuilder.FindOrCreateAttribute(subSO, 'AttributeString')"<< endl;
2216             theStr<<thePrefix<<"strAttr.SetValue('"<<aStringAttr->Value()<<"')"<< endl;
2217           }
2218         }
2219
2220       }
2221       
2222     }
2223
2224     theStr<<thePrefix<<endl;
2225   }
2226
2227
2228   void
2229   DumpClippingPlanesToPython(SALOMEDS::Study_ptr theStudy,
2230                              CORBA::Boolean theIsPublished,
2231                              CORBA::Boolean& theIsValidScript,
2232                              SALOMEDS::SObject_ptr theSObject,
2233                              std::ostream& theStr,
2234                              std::string thePrefix,
2235                              VISU_ClippingPlaneMgr& thePlaneMgr)
2236   {
2237
2238     if(!theIsPublished) return;
2239
2240     VISU_CutPlaneFunction* aPlane;
2241     double aOrigin[3], aDir[3];
2242     for (int i = 0; i < thePlaneMgr.GetClippingPlanesNb(); i++) {
2243       aPlane = thePlaneMgr.GetClippingPlane(i);
2244       aPlane->GetOrigin(aOrigin);
2245       aPlane->GetNormal(aDir);
2246
2247       theStr<<thePrefix<<"aVisu.CreateClippingPlane("<<
2248         aOrigin[0]<<","<<aOrigin[1]<<","<<aOrigin[2]<<","<<
2249         aDir[0]<<","<<aDir[1]<<","<<aDir[2]<<","<<
2250         aPlane->isAuto()<<",\""<<aPlane->getName()<<"\")"<<endl;      
2251     }
2252     theStr<<endl;
2253   }  
2254
2255
2256   void
2257   DumpTextureMapToPython(SALOMEDS::Study_ptr theStudy,
2258                          CORBA::Boolean theIsPublished,
2259                          CORBA::Boolean& theIsValidScript,
2260                          SALOMEDS::SObject_ptr theSObject,
2261                          std::ostream& theStr,
2262                          std::string thePrefix,
2263                          const StudyId2MarkerMap& theMarkerMap)
2264   {
2265     if(!theIsPublished)
2266       return;
2267
2268     if(CORBA::is_nil(theStudy))
2269       return;
2270
2271     StudyId2MarkerMap::const_iterator anIter = theMarkerMap.find(theStudy->StudyId());
2272     if(anIter == theMarkerMap.end())
2273       return;
2274
2275     theStr<<thePrefix<<"texture_map = {}"<<endl<<endl;
2276
2277     const VTK::MarkerMap& aMarkerMap = anIter->second;
2278     VTK::MarkerMap::const_iterator aMarkerIter = aMarkerMap.begin();
2279     for(; aMarkerIter != aMarkerMap.end(); aMarkerIter++) {
2280       int aMarkerId = aMarkerIter->first;
2281       std::string aMarkerTexture = aMarkerIter->second.first;
2282       theStr<<thePrefix<<"texture_map["<<aMarkerId<<"] = aVisu.LoadTexture(\""<<aMarkerTexture<<"\")"<<endl;
2283     }
2284     theStr<<endl;
2285   }  
2286
2287
2288   //---------------------------------------------------------------------------
2289   Engines::TMPFile*
2290   VISU_Gen_i::
2291   DumpPython(CORBA::Object_ptr theStudy,
2292              CORBA::Boolean theIsPublished,
2293              CORBA::Boolean& theIsValidScript)
2294   {
2295     theIsValidScript = false;
2296
2297     SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2298     if(CORBA::is_nil(aStudy))
2299       return new Engines::TMPFile(0);
2300
2301     TName2EntryMap aName2EntryMap;
2302     TEntry2NameMap aEntry2NameMap;
2303
2304 #ifndef COUT
2305     ostringstream aStr;
2306 #else
2307 #define aStr cout
2308 #endif
2309
2310     std::string aPrefix(PREFIX);
2311     aStr<<"def RebuildData(theStudy):"<<endl;
2312     aStr<<aPrefix<<"from batchmode_salome import orb, naming_service, lcc, myStudyManager"<<endl;
2313     aStr<<aPrefix<<"import SALOME_MED"<<endl;
2314     aStr<<aPrefix<<"import SALOMEDS"<<endl;
2315     aStr<<aPrefix<<"import VISU"<<endl;
2316     aStr<<aPrefix<<"import visu"<<endl;
2317     aStr<<endl;
2318     aStr<<aPrefix<<"aVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,theStudy,0)"<<endl;
2319     aStr<<aPrefix<<"aSComponent = visu.PublishComponent(theStudy)"<<endl;
2320     aStr<<aPrefix<<"aMed = lcc.FindOrLoadComponent('FactoryServer','MED')"<<endl;
2321     aStr<<aPrefix<<"aBuilder = theStudy.NewBuilder()"<<endl;
2322     aStr<<aPrefix<<"aName2ObjectMap = {}"<<endl;
2323     aStr<<endl;
2324
2325     SALOMEDS::SComponent_var aComponent = FindOrCreateVisuComponent(aStudy);
2326
2327     VISU::DumpClippingPlanesToPython(aStudy,
2328                                      theIsPublished,
2329                                      theIsValidScript,
2330                                      aComponent.in(),
2331                                      aStr,
2332                                      aPrefix, 
2333                                      myClippingPlaneMgr);
2334
2335     VISU::DumpTextureMapToPython(aStudy,
2336                                  theIsPublished,
2337                                  theIsValidScript,
2338                                  aComponent.in(),
2339                                  aStr,
2340                                  aPrefix,
2341                                  myMarkerMap);
2342
2343     VISU::DumpChildrenToPython(aStudy,
2344                                theIsPublished,
2345                                theIsValidScript,
2346                                aComponent.in(),
2347                                aStr,
2348                                aName2EntryMap,
2349                                aEntry2NameMap,
2350                                "",
2351                                aPrefix);
2352
2353     VISU::DumpEvolutionsToPython(aStudy,
2354                                  theIsPublished,
2355                                  theIsValidScript,
2356                                  aComponent.in(),
2357                                  aStr,
2358                                  aName2EntryMap,
2359                                  aEntry2NameMap,
2360                                  aPrefix);
2361
2362     VISU::DumpContainersToPython(aStudy,
2363                                  theIsPublished,
2364                                  theIsValidScript,
2365                                  aComponent.in(),
2366                                  aStr,
2367                                  aName2EntryMap,
2368                                  aEntry2NameMap,
2369                                  "",
2370                                  aPrefix);
2371
2372     VISU::DumpPrs3dCacheToPython(aStudy,
2373                                  theIsPublished,
2374                                  theIsValidScript,
2375                                  aComponent.in(),
2376                                  aStr,
2377                                  aName2EntryMap,
2378                                  aEntry2NameMap,
2379                                  "",
2380                                  aPrefix);
2381
2382     VISU::DumpAnimationsToPython(aStudy,
2383                                  theIsPublished,
2384                                  theIsValidScript,
2385                                  aComponent.in(),
2386                                  aStr,
2387                                  aPrefix);
2388
2389
2390     //Output the script that sets up the visul parameters.
2391     if(theIsPublished) {
2392       char* script = aStudy->GetDefaultScript("Post-Pro", aPrefix.c_str());
2393       if(script && strlen(script) > 0) {
2394         aStr << script;
2395         CORBA::string_free(script);
2396       }
2397     }
2398
2399     aStr<<aPrefix<<"pass"<<endl;
2400
2401     if(theIsPublished) { //SRN: define function for Animation
2402
2403       //Define a function that find a SObject by its father's path and its name
2404       aStr<<endl;
2405       aStr<<endl;
2406
2407       aStr<<"def getSObjectByFatherPathAndName(theStudy, thePath, theName):"<<endl;
2408       aStr<<aPrefix<<"father = theStudy.FindObjectByPath(thePath)"<<endl;
2409       aStr<<aPrefix<<"itr = theStudy.NewChildIterator(father)"<<endl;
2410       aStr<<aPrefix<<"while itr.More():"<<endl;
2411       aStr<<aPrefix<<aPrefix<<"so = itr.Value()"<<endl;
2412       aStr<<aPrefix<<aPrefix<<"if so.GetName()==theName: return so"<<endl;
2413       aStr<<aPrefix<<aPrefix<<"itr.Next()"<<endl;
2414       aStr<<aPrefix<<aPrefix<<"pass"<<endl;
2415       aStr<<aPrefix<<"return None"<<endl;
2416
2417       aStr<<endl;
2418     }
2419
2420     // theIsValidScript currently is not used by internal dump methods (DumpChildrenToPython(), etc.)
2421     // If the situation changes, then the following line should be removed, and theIsValidScript
2422     // should be set properly by those internal methods
2423     theIsValidScript = true;
2424
2425 #ifndef COUT
2426     std::string aResult = aStr.str();
2427     //ofstream anFStream("/tmp/dump.py");
2428     //anFStream<<aResult<<endl;
2429
2430     CORBA::ULong aSize = aResult.size() + 1;
2431     char* aBuffer = new char[aSize];
2432     strcpy(aBuffer,&aResult[0]);
2433     return new Engines::TMPFile(aSize,aSize,(CORBA::Octet*)aBuffer,1);
2434 #else
2435 #undef aStr
2436     return new Engines::TMPFile(0);
2437 #endif
2438   }
2439 }