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