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