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