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