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