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