Salome HOME
0022238: Study dump produced by SMESH refers to undefined variable names
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
1 // Copyright (C) 2007-2013  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 //  File    : SMESH_DumpPython.cxx
23 //  Created : Thu Mar 24 17:17:59 2005
24 //  Author  : Julia DOROVSKIKH
25 //  Module  : SMESH
26
27 #include "SMESH_PythonDump.hxx"
28
29 #include "SMESH_2smeshpy.hxx"
30 #include "SMESH_Comment.hxx"
31 #include "SMESH_Filter_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_MeshEditor_i.hxx"
34
35 #include <SALOMEDS_wrap.hxx>
36
37 #include <TColStd_HSequenceOfInteger.hxx>
38 #include <TCollection_AsciiString.hxx>
39
40 #ifdef _DEBUG_
41 static int MYDEBUG = 0;
42 #else
43 static int MYDEBUG = 0;
44 #endif
45
46 namespace SMESH
47 {
48
49   size_t TPythonDump::myCounter = 0;
50   const char theNotPublishedObjectName[] = "__NOT__Published__Object__";
51
52   TVar::TVar(CORBA::Double value):myVals(1) { myVals[0] = SMESH_Comment(value); }
53   TVar::TVar(CORBA::Long   value):myVals(1) { myVals[0] = SMESH_Comment(value); }
54   TVar::TVar(CORBA::Short  value):myVals(1) { myVals[0] = SMESH_Comment(value); }
55   TVar::TVar(const SMESH::double_array& value):myVals(value.length())
56   {
57     for ( size_t i = 0; i < value.length(); i++)
58       myVals[i] = SMESH_Comment(value[i]);
59   }
60
61   TPythonDump::
62   TPythonDump():myVarsCounter(0)
63   {
64     ++myCounter;
65   }
66   TPythonDump::
67   ~TPythonDump()
68   {
69     if(--myCounter == 0){
70       SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
71       std::string aString = myStream.str();
72       TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
73       SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
74       if(!aStudy->_is_nil() && !aCollection.IsEmpty())
75       {
76         const std::string & objEntry = SMESH_Gen_i::GetSMESHGen()->GetLastObjEntry();
77         if ( !objEntry.empty() )
78           aCollection += (TVar::ObjPrefix() + objEntry ).c_str();
79         aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
80         if(MYDEBUG) MESSAGE(aString);
81         // prevent misuse of already treated variables
82         aSMESHGen->UpdateParameters(CORBA::Object_var().in(),"");
83       }
84     }
85   }
86
87   TPythonDump& //!< store a variable value. Write either a value or '$varID$'
88   TPythonDump::
89   operator<<(const TVar& theVarValue)
90   {
91     const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices();
92     if ( theVarValue.myVals.size() != 1 )
93     {
94       myStream << "[ ";
95       for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
96       {
97         if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
98           myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
99         else
100           myStream << theVarValue.myVals[i-1];
101         if ( i < theVarValue.myVals.size() )
102           myStream << ", ";
103         ++myVarsCounter;
104       }
105       myStream << " ]";
106     }
107     else
108     {
109       if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
110         myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
111       else
112         myStream << theVarValue.myVals[0];
113       ++myVarsCounter;
114     }
115     return *this;
116   }
117
118   TPythonDump&
119   TPythonDump::
120   operator<<(long int theArg){
121     myStream<<theArg;
122     return *this;
123   }
124
125   TPythonDump&
126   TPythonDump::
127   operator<<(int theArg){
128     myStream<<theArg;
129     return *this;
130   }
131
132   TPythonDump&
133   TPythonDump::
134   operator<<(double theArg){
135     myStream<<theArg;
136     return *this;
137   }
138
139   TPythonDump&
140   TPythonDump::
141   operator<<(float theArg){
142     myStream<<theArg;
143     return *this;
144   }
145
146   TPythonDump&
147   TPythonDump::
148   operator<<(const void* theArg){
149     myStream<<theArg;
150     return *this;
151   }
152
153   TPythonDump&
154   TPythonDump::
155   operator<<(const char* theArg){
156     if ( theArg )
157       myStream<<theArg;
158     return *this;
159   }
160
161   TPythonDump&
162   TPythonDump::
163   operator<<(const SMESH::ElementType& theArg)
164   {
165     myStream<<"SMESH.";
166     switch(theArg){
167     case ALL:    myStream<<"ALL";    break;
168     case NODE:   myStream<<"NODE";   break;
169     case EDGE:   myStream<<"EDGE";   break;
170     case FACE:   myStream<<"FACE";   break;
171     case VOLUME: myStream<<"VOLUME"; break;
172     case ELEM0D: myStream<<"ELEM0D"; break;
173     case BALL:   myStream<<"BALL";   break;
174     default:     myStream<<"__UNKNOWN__ElementType: " << theArg;
175     }
176     return *this;
177   }
178
179   TPythonDump&
180   TPythonDump::
181   operator<<(const SMESH::GeometryType& theArg)
182   {
183     myStream<<"SMESH.";
184     switch(theArg){
185     case Geom_POINT:      myStream<<"Geom_POINT";      break;
186     case Geom_EDGE:       myStream<<"Geom_EDGE";       break;
187     case Geom_TRIANGLE:   myStream<<"Geom_TRIANGLE";   break;
188     case Geom_QUADRANGLE: myStream<<"Geom_QUADRANGLE"; break;
189     case Geom_POLYGON:    myStream<<"Geom_POLYGON";    break;
190     case Geom_TETRA:      myStream<<"Geom_TETRA";      break;
191     case Geom_PYRAMID:    myStream<<"Geom_PYRAMID";    break;
192     case Geom_HEXA:       myStream<<"Geom_HEXA";       break;
193     case Geom_PENTA:      myStream<<"Geom_PENTA";      break;
194     case Geom_POLYHEDRA:  myStream<<"Geom_POLYHEDRA";  break;
195     case Geom_BALL:       myStream<<"Geom_BALL";       break;
196     default:    myStream<<"__UNKNOWN__GeometryType: " << theArg;
197     }
198     return *this;
199   }
200   TPythonDump&
201   TPythonDump::
202   operator<<(const SMESH::EntityType& theArg)
203   {
204     myStream<<"SMESH.";
205     switch(theArg){
206     case Entity_0D:                myStream<<"Entity_0D";                break;
207     case Entity_Edge:              myStream<<"Entity_Edge";              break;
208     case Entity_Quad_Edge:         myStream<<"Entity_Quad_Edge";         break;
209     case Entity_Triangle:          myStream<<"Entity_Triangle";          break;
210     case Entity_Quad_Triangle:     myStream<<"Entity_Quad_Triangle";     break;
211     case Entity_BiQuad_Triangle:   myStream<<"Entity_BiQuad_Triangle";   break;
212     case Entity_Quadrangle:        myStream<<"Entity_Quadrangle";        break;
213     case Entity_Quad_Quadrangle:   myStream<<"Entity_Quad_Quadrangle";   break;
214     case Entity_BiQuad_Quadrangle: myStream<<"Entity_BiQuad_Quadrangle"; break;
215     case Entity_Polygon:           myStream<<"Entity_Polygon";           break;
216     case Entity_Quad_Polygon:      myStream<<"Entity_Quad_Polygon";      break;
217     case Entity_Tetra:             myStream<<"Entity_Tetra";             break;
218     case Entity_Quad_Tetra:        myStream<<"Entity_Quad_Tetra";        break;
219     case Entity_Pyramid:           myStream<<"Entity_Pyramid";           break;
220     case Entity_Quad_Pyramid:      myStream<<"Entity_Quad_Pyramid";      break;
221     case Entity_Hexa:              myStream<<"Entity_Hexa";              break;
222     case Entity_Quad_Hexa:         myStream<<"Entity_Quad_Hexa";         break;
223     case Entity_TriQuad_Hexa:      myStream<<"Entity_TriQuad_Hexa";      break;
224     case Entity_Penta:             myStream<<"Entity_Penta";             break;
225     case Entity_Quad_Penta:        myStream<<"Entity_Quad_Penta";        break;
226     case Entity_Hexagonal_Prism:   myStream<<"Entity_Hexagonal_Prism";   break;
227     case Entity_Polyhedra:         myStream<<"Entity_Polyhedra";         break;
228     case Entity_Quad_Polyhedra:    myStream<<"Entity_Quad_Polyhedra";    break;
229     case Entity_Ball:              myStream<<"Entity_Ball";              break;
230     case Entity_Last:              myStream<<"Entity_Last";              break;
231     default:    myStream<<"__UNKNOWN__EntityType: " << theArg;
232     }
233     return *this;
234   }
235
236   template<class TArray>
237   void DumpArray(const TArray& theArray, TPythonDump & theStream)
238   {
239     theStream << "[ ";
240     for (int i = 1; i <= theArray.length(); i++) {
241       theStream << theArray[i-1];
242       if ( i < theArray.length() )
243         theStream << ", ";
244     }
245     theStream << " ]";
246   }
247
248   TPythonDump&
249   TPythonDump::operator<<(const SMESH::long_array& theArg)
250   {
251     DumpArray( theArg, *this );
252     return *this;
253   }
254
255   TPythonDump&
256   TPythonDump::operator<<(const SMESH::double_array& theArg)
257   {
258     DumpArray( theArg, *this );
259     return *this;
260   }
261
262   TPythonDump&
263   TPythonDump::operator<<(const SMESH::string_array& theArray)
264   {
265     myStream << "[ ";
266     for (int i = 1; i <= theArray.length(); i++) {
267       myStream << "'" << theArray[i-1] << "'";
268       if ( i < theArray.length() )
269         myStream << ", ";
270     }
271     myStream << " ]";
272     return *this;
273   }
274
275   TPythonDump&
276   TPythonDump::
277   operator<<(SALOMEDS::SObject_ptr aSObject)
278   {
279     if ( !aSObject->_is_nil() ) {
280       CORBA::String_var entry = aSObject->GetID();
281       myStream << entry.in();
282     }
283     else {
284       myStream << theNotPublishedObjectName;
285     }
286     return *this;
287   }
288
289   TPythonDump&
290   TPythonDump::
291   operator<<(CORBA::Object_ptr theArg)
292   {
293     SMESH_Gen_i*          aSMESHGen = SMESH_Gen_i::GetSMESHGen();
294     SALOMEDS::Study_var      aStudy = aSMESHGen->GetCurrentStudy();
295     SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
296     if(!aSObject->_is_nil()) {
297       CORBA::String_var id = aSObject->GetID();
298       myStream << id;
299     } else if ( !CORBA::is_nil(theArg)) {
300       if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
301         myStream << "smeshObj_" << size_t(theArg);
302       else
303         myStream << theNotPublishedObjectName;
304     }
305     else
306       myStream << "None";
307     return *this;
308   }
309
310   TPythonDump&
311   TPythonDump::
312   operator<<(SMESH::SMESH_Hypothesis_ptr theArg)
313   {
314     SALOMEDS::Study_var     aStudy = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
315     SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
316     if(aSObject->_is_nil() && !CORBA::is_nil(theArg))
317       myStream << "hyp_" << theArg->GetId();
318     else
319       *this << aSObject;
320     return *this;
321   }
322
323   TPythonDump&
324   TPythonDump::
325   operator<<(SMESH::SMESH_IDSource_ptr theArg)
326   {
327     if ( CORBA::is_nil( theArg ) )
328       return *this << "None";
329     SMESH_Gen_i*          aSMESHGen = SMESH_Gen_i::GetSMESHGen();
330     SALOMEDS::Study_var      aStudy = aSMESHGen->GetCurrentStudy();
331     SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
332     if(!aSObject->_is_nil())
333     {
334       return *this << aSObject;
335     }
336     if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theArg ))
337     {
338       return *this << filter;
339     }
340     if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theArg ))
341     {
342       SMESH::SMESH_Mesh_var            mesh = theArg->GetMesh();
343       SMESH::long_array_var    anElementsId = theArg->GetIDs();
344       SMESH::array_of_ElementType_var types = theArg->GetTypes();
345       SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
346       return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
347     }
348     return *this << theNotPublishedObjectName;
349   }
350
351   TPythonDump&
352   TPythonDump::
353   operator<<(SMESH::FilterLibrary_i* theArg)
354   {
355     myStream<<"aFilterLibrary"<<theArg;
356     return *this;
357   }
358
359   TPythonDump&
360   TPythonDump::
361   operator<<(SMESH::FilterManager_i* theArg)
362   {
363     myStream<<"aFilterManager";
364     return *this;
365   }
366
367   TPythonDump&
368   TPythonDump::
369   operator<<(SMESH::Filter_i* theArg)
370   {
371     myStream<<"aFilter"<<theArg;
372     return *this;
373   }
374
375   TPythonDump&
376   TPythonDump::
377   operator<<(SMESH::Functor_i* theArg)
378   {
379     if ( theArg ) {
380       FunctorType aFunctorType = theArg->GetFunctorType();
381       switch(aFunctorType) {
382       case FT_AspectRatio:           myStream<< "aAspectRatio";           break;
383       case FT_AspectRatio3D:         myStream<< "aAspectRatio3D";         break;
384       case FT_Warping:               myStream<< "aWarping";               break;
385       case FT_MinimumAngle:          myStream<< "aMinimumAngle";          break;
386       case FT_Taper:                 myStream<< "aTaper";                 break;
387       case FT_Skew:                  myStream<< "aSkew";                  break;
388       case FT_Area:                  myStream<< "aArea";                  break;
389       case FT_Volume3D:              myStream<< "aVolume3D";              break;
390       case FT_MaxElementLength2D:    myStream<< "aMaxElementLength2D";    break;
391       case FT_MaxElementLength3D:    myStream<< "aMaxElementLength3D";    break;
392       case FT_FreeBorders:           myStream<< "aFreeBorders";           break;
393       case FT_FreeEdges:             myStream<< "aFreeEdges";             break;
394       case FT_FreeNodes:             myStream<< "aFreeNodes";             break;
395       case FT_FreeFaces:             myStream<< "aFreeFaces";             break;
396       case FT_EqualNodes:            myStream<< "aEqualNodes";            break;
397       case FT_EqualEdges:            myStream<< "aEqualEdges";            break;
398       case FT_EqualFaces:            myStream<< "aEqualFaces";            break;
399       case FT_EqualVolumes:          myStream<< "aEqualVolumes";          break;
400       case FT_MultiConnection:       myStream<< "aMultiConnection";       break;
401       case FT_MultiConnection2D:     myStream<< "aMultiConnection2D";     break;
402       case FT_Length:                myStream<< "aLength";                break;
403       case FT_Length2D:              myStream<< "aLength2D";              break;
404       case FT_BelongToGeom:          myStream<< "aBelongToGeom";          break;
405       case FT_BelongToPlane:         myStream<< "aBelongToPlane";         break;
406       case FT_BelongToCylinder:      myStream<< "aBelongToCylinder";      break;
407       case FT_BelongToGenSurface:    myStream<< "aBelongToGenSurface";    break;
408       case FT_LyingOnGeom:           myStream<< "aLyingOnGeom";           break;
409       case FT_RangeOfIds:            myStream<< "aRangeOfIds";            break;
410       case FT_BadOrientedVolume:     myStream<< "aBadOrientedVolume";     break;
411       case FT_BareBorderVolume:      myStream<< "aBareBorderVolume";      break;
412       case FT_BareBorderFace:        myStream<< "aBareBorderFace";        break;
413       case FT_OverConstrainedVolume: myStream<< "aOverConstrainedVolume"; break;
414       case FT_OverConstrainedFace:   myStream<< "aOverConstrainedFace";   break;
415       case FT_LinearOrQuadratic:     myStream<< "aLinearOrQuadratic";     break;
416       case FT_GroupColor:            myStream<< "aGroupColor";            break;
417       case FT_ElemGeomType:          myStream<< "aElemGeomType";          break;
418       case FT_EntityType:            myStream<< "aEntityType";            break;
419       case FT_CoplanarFaces:         myStream<< "aCoplanarFaces";         break;
420       case FT_BallDiameter:          myStream<< "aBallDiameter";          break;
421       case FT_ConnectedElements:     myStream<< "aConnectedElements";     break;
422       case FT_LessThan:              myStream<< "aLessThan";              break;
423       case FT_MoreThan:              myStream<< "aMoreThan";              break;
424       case FT_EqualTo:               myStream<< "aEqualTo";               break;
425       case FT_LogicalNOT:            myStream<< "aLogicalNOT";            break;
426       case FT_LogicalAND:            myStream<< "aLogicalAND";            break;
427       case FT_LogicalOR:             myStream<< "aLogicalOR";             break;
428       case FT_Undefined:
429       default:                       myStream<< "anUndefined";            break;
430       }
431       myStream<<theArg;
432     }
433     return *this;
434   }
435
436   TPythonDump&
437   TPythonDump::
438   operator<<(SMESH::Measurements_i* theArg)
439   {
440     myStream<<"aMeasurements";
441     return *this;
442   }
443
444
445   TPythonDump& TPythonDump:: operator<<(SMESH_Gen_i* theArg)
446   {
447     myStream << SMESHGenName(); return *this;
448   }
449
450   TPythonDump& TPythonDump::operator<<(SMESH_MeshEditor_i* theArg)
451   {
452     myStream << MeshEditorName() << "_" << ( theArg ? theArg->GetMeshId() : -1 ); return *this;
453   }
454
455   TPythonDump& TPythonDump::operator<<(const TCollection_AsciiString & theStr)
456   {
457     myStream << theStr; return *this;
458   }
459
460
461   TPythonDump& TPythonDump::operator<<(SMESH::MED_VERSION theVersion)
462   {
463     switch (theVersion) {
464     case SMESH::MED_V2_1: myStream << "SMESH.MED_V2_1"; break;
465     case SMESH::MED_V2_2: myStream << "SMESH.MED_V2_2"; break;
466     default: myStream << theVersion;
467     }
468     return *this;
469   }
470
471   TPythonDump& TPythonDump::operator<<(const SMESH::AxisStruct & theAxis)
472   {
473     *this << "SMESH.AxisStruct( "
474           << TVar( theAxis.x  ) << ", "
475           << TVar( theAxis.y  ) << ", "
476           << TVar( theAxis.z  ) << ", "
477           << TVar( theAxis.vx ) << ", "
478           << TVar( theAxis.vy ) << ", "
479           << TVar( theAxis.vz ) << " )";
480     return *this;
481   }
482
483   TPythonDump& TPythonDump::operator<<(const SMESH::DirStruct & theDir)
484   {
485     const SMESH::PointStruct & P = theDir.PS;
486     *this << "SMESH.DirStruct( SMESH.PointStruct ( "
487           << TVar( P.x ) << ", "
488           << TVar( P.y ) << ", "
489           << TVar( P.z ) << " ))";
490     return *this;
491   }
492
493   TPythonDump& TPythonDump::operator<<(const SMESH::PointStruct & P)
494   {
495     *this << "SMESH.PointStruct ( "
496           << TVar( P.x ) << ", "
497           << TVar( P.y ) << ", "
498           << TVar( P.z ) << " )";
499     return *this;
500   }
501
502   TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups& theList)
503   {
504     DumpArray( theList, *this );
505     return *this;
506   }
507   TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups * theList)
508   {
509     DumpArray( *theList, *this );
510     return *this;
511   }
512   TPythonDump& TPythonDump::operator<<(const SMESH::ListOfIDSources& theList)
513   {
514     DumpArray( theList, *this );
515     return *this;
516   }
517   const char* TPythonDump::NotPublishedObjectName()
518   {
519     return theNotPublishedObjectName;
520   }
521
522   TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
523   TCollection_AsciiString myLongStringEnd  ( "TPythonDump::LongStringEnd" );
524
525   //================================================================================
526   /*!
527    * \brief Return marker of long string literal beginning
528    * \param type - a name of functionality producing the string literal
529    * \retval TCollection_AsciiString - the marker string to be written into
530    * a raw python script
531    */
532   //================================================================================
533
534   TCollection_AsciiString TPythonDump::LongStringStart(const char* type)
535   {
536     return
537       myLongStringStart +
538       (Standard_Integer) strlen(type) +
539       " " +
540       (char*) type;
541   }
542
543   //================================================================================
544   /*!
545      * \brief Return marker of long string literal end
546       * \retval TCollection_AsciiString - the marker string to be written into
547       * a raw python script
548    */
549   //================================================================================
550
551   TCollection_AsciiString TPythonDump::LongStringEnd()
552   {
553     return myLongStringEnd;
554   }
555
556   //================================================================================
557   /*!
558      * \brief Cut out a long string literal from a string
559       * \param theText - text possibly containing string literals
560       * \param theFrom - position in the text to search from
561       * \param theLongString - the retrieved literal
562       * \param theStringType - a name of functionality produced the literal
563       * \retval bool - true if a string literal found
564      *
565      * The literal is removed from theText; theFrom points position right after
566      * the removed literal
567    */
568   //================================================================================
569
570   bool  TPythonDump::CutoutLongString( TCollection_AsciiString & theText,
571                                        int                     & theFrom,
572                                        TCollection_AsciiString & theLongString,
573                                        TCollection_AsciiString & theStringType)
574   {
575     if ( theFrom < 1 || theFrom > theText.Length() )
576       return false;
577
578     // ...script \  beg marker    \ \ type \       literal              \  end marker  \ script...
579     //  "theText myLongStringStart7 Pattern!!! SALOME Mesh Pattern file myLongStringEndtextEnd"
580     //  012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
581     //  0         1         2         3         4         5         6         7         8
582
583     theFrom = theText.Location( myLongStringStart, theFrom, theText.Length() ); // = 09
584     if ( !theFrom )
585       return false;
586
587     // find where literal begins
588     int literalBeg = theFrom + myLongStringStart.Length(); // = 26
589     char* typeLenStr = (char*) theText.ToCString() + literalBeg - 1; // = "7 Pattern!!! SALO...."
590     int typeLen = atoi ( typeLenStr ); // = 7
591     while ( *typeLenStr != ' ' ) { // look for ' ' after typeLen
592       literalBeg++; // 26 -> 27
593       typeLenStr++;
594     }
595     literalBeg += typeLen + 1; // = 35
596     if ( literalBeg > theText.Length() )
597       return false;
598
599     // where literal ends (i.e. end marker begins)
600     int literalEnd = theText.Location( myLongStringEnd, literalBeg, theText.Length() ); // = 64
601     if ( !literalEnd )
602       literalEnd = theText.Length();
603
604     // literal
605     theLongString = theText.SubString( literalBeg, literalEnd - 1); // "!!! SALOME Mesh Pattern file "
606     // type
607     theStringType = theText.SubString( literalBeg - typeLen, literalBeg - 1 ); // "Pattern"
608     // cut off literal
609     literalEnd += myLongStringEnd.Length(); // = 79
610     TCollection_AsciiString textEnd = theText.SubString( literalEnd, theText.Length() ); // "textE..."
611     theText = theText.SubString( 1, theFrom - 1 ) + textEnd;
612
613     return true;
614   }
615 }
616
617 //=======================================================================
618 //function : RemoveTabulation
619 //purpose  : 
620 //=======================================================================
621 void RemoveTabulation( TCollection_AsciiString& theScript )
622 {
623   std::string aString( theScript.ToCString() );
624   std::string::size_type aPos = 0;
625   while( aPos < aString.length() )
626   {
627     aPos = aString.find( "\n\t", aPos );
628     if( aPos == std::string::npos )
629       break;
630     aString.replace( aPos, 2, "\n" );
631     aPos++;
632   }
633   theScript = aString.c_str();
634 }
635
636 //=======================================================================
637 //function : DumpPython
638 //purpose  :
639 //=======================================================================
640 Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
641                                            CORBA::Boolean isPublished,
642                                            CORBA::Boolean isMultiFile,
643                                            CORBA::Boolean& isValidScript)
644 {
645   SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
646   if (CORBA::is_nil(aStudy))
647     return new Engines::TMPFile(0);
648
649   CORBA::String_var compDataType = ComponentDataType();
650   SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
651   if (CORBA::is_nil(aSO))
652     return new Engines::TMPFile(0);
653
654   // Map study entries to object names
655   Resource_DataMapOfAsciiStringAsciiString aMap;
656   Resource_DataMapOfAsciiStringAsciiString aMapNames;
657   //TCollection_AsciiString s ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
658
659   SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
660   for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
661     SALOMEDS::SObject_wrap aValue = Itr->Value();
662     CORBA::String_var anID = aValue->GetID();
663     CORBA::String_var aName = aValue->GetName();
664     TCollection_AsciiString aGUIName ( (char*) aName.in() );
665     TCollection_AsciiString anEnrty ( (char*) anID.in() );
666     if (aGUIName.Length() > 0) {
667       aMapNames.Bind( anEnrty, aGUIName );
668       aMap.Bind( anEnrty, aGUIName );
669     }
670   }
671
672   // Get trace of restored study
673   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
674   SALOMEDS::GenericAttribute_wrap anAttr =
675     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
676
677   SALOMEDS::AttributePythonObject_var pyAttr =
678     SALOMEDS::AttributePythonObject::_narrow(anAttr);
679   CORBA::String_var oldValue = pyAttr->GetObject();
680   TCollection_AsciiString aSavedTrace (oldValue.in());
681
682   // Add trace of API methods calls and replace study entries by names
683   TCollection_AsciiString aScript;
684   aScript += DumpPython_impl(aStudy, aMap, aMapNames, isPublished, isMultiFile,
685                              myIsHistoricalPythonDump, isValidScript, aSavedTrace);
686
687   int aLen = aScript.Length();
688   unsigned char* aBuffer = new unsigned char[aLen+1];
689   strcpy((char*)aBuffer, aScript.ToCString());
690
691   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
692   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
693
694   bool hasNotPublishedObjects = aScript.Location( SMESH::theNotPublishedObjectName, 1, aLen);
695   isValidScript = isValidScript && !hasNotPublishedObjects;
696
697   return aStreamFile._retn();
698 }
699
700 //=============================================================================
701 /*!
702  *  AddToPythonScript
703  */
704 //=============================================================================
705 void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString)
706 {
707   if (myPythonScripts.find(theStudyID) == myPythonScripts.end()) {
708     myPythonScripts[theStudyID] = new TColStd_HSequenceOfAsciiString;
709   }
710   myPythonScripts[theStudyID]->Append(theString);
711 }
712
713 //=============================================================================
714 /*!
715  *  RemoveLastFromPythonScript
716  */
717 //=============================================================================
718 void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID)
719 {
720   if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
721     int aLen = myPythonScripts[theStudyID]->Length();
722     myPythonScripts[theStudyID]->Remove(aLen);
723   }
724 }
725
726 //=======================================================================
727 //function : SavePython
728 //purpose  :
729 //=======================================================================
730 void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
731 {
732   // Dump trace of API methods calls
733   TCollection_AsciiString aScript = GetNewPythonLines(theStudy->StudyId());
734
735   // Check contents of PythonObject attribute
736   CORBA::String_var compDataType = ComponentDataType();
737   SALOMEDS::SObject_wrap aSO = theStudy->FindComponent( compDataType.in() );
738   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
739   SALOMEDS::GenericAttribute_wrap anAttr =
740     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
741
742   SALOMEDS::AttributePythonObject_var pyAttr =
743     SALOMEDS::AttributePythonObject::_narrow(anAttr);
744   CORBA::String_var oldValue = pyAttr->GetObject();
745   TCollection_AsciiString oldScript (oldValue.in());
746
747   if (oldScript.Length() > 0) {
748     oldScript += "\n";
749     oldScript += aScript;
750   } else {
751     oldScript = aScript;
752   }
753
754   // Store in PythonObject attribute
755   pyAttr->SetObject(oldScript.ToCString(), 1);
756
757   // Clean trace of API methods calls
758   CleanPythonTrace(theStudy->StudyId());
759 }
760
761
762 // impl
763
764
765 //=============================================================================
766 /*!
767  *  FindEntries: Returns a sequence of start/end positions of entries in the string
768  */
769 //=============================================================================
770 Handle(TColStd_HSequenceOfInteger) FindEntries (TCollection_AsciiString& theString)
771 {
772   Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
773   Standard_Integer aLen = theString.Length();
774   Standard_Boolean isFound = Standard_False;
775
776   char* arr = (char*) theString.ToCString();
777   Standard_Integer i = 0, j;
778
779   while(i < aLen) {
780     int c = (int)arr[i];
781     j = i+1;
782     if ( isdigit( c )) { //Is digit?
783
784       isFound = Standard_False;
785       while((j < aLen) && ( isdigit(c) || c == ':' )) { //Check if it is an entry
786         c = (int)arr[j++];
787         if(c == ':') isFound = Standard_True;
788       }
789
790       if (isFound) {
791         int prev = (i < 1) ? 0 : (int)arr[i - 1];
792         // to distinguish from a sketcher command:
793         // last char should be a digit, not ":",
794         // previous char should not be '"'.
795         if (arr[j-2] != ':' && prev != '"') {
796           aSeq->Append(i+1); // +1 because AsciiString starts from 1
797           aSeq->Append(j-1);
798         }
799       }
800     }
801
802     i = j;
803   }
804
805   return aSeq;
806 }
807
808 namespace {
809
810   //================================================================================
811   /*!
812    * \brief Make a string be a valid python name
813     * \param aName - a string to fix
814     * \retval bool - true if aName was not modified
815    */
816   //================================================================================
817
818   bool fixPythonName(TCollection_AsciiString & aName )
819   {
820     const TCollection_AsciiString allowedChars =
821       "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_";
822     bool isValidName = true;
823     int nbUnderscore = 0;
824     int p=1; // replace not allowed chars by underscore
825     while (p <= aName.Length() &&
826            (p = aName.FirstLocationNotInSet(allowedChars, p, aName.Length())))
827     {
828       if ( p == 1 || p == aName.Length() || aName.Value(p-1) == '_')
829         aName.Remove( p, 1 ); // remove double _ from the start and the end
830       else
831         aName.SetValue(p, '_'), nbUnderscore++;
832       isValidName = false;
833     }
834     if ( aName.IsIntegerValue() ) { // aName must not start with a digit
835       aName.Insert( 1, 'a' );
836       isValidName = false;
837     }
838     // shorten names like CartesianParameters3D_400_400_400_1000000_1
839     const int nbAllowedUnderscore = 3; /* changed from 2 to 3 by an user request
840                                           posted to SALOME Forum */
841     if ( aName.Length() > 20 && nbUnderscore > nbAllowedUnderscore )
842     {
843       p = aName.Location( "_", 20, aName.Length());
844       if ( p > 1 )
845         aName.Trunc( p-1 );
846     }
847     return isValidName;
848   }
849 }
850
851 //=============================================================================
852 /*!
853  *  DumpPython
854  */
855 //=============================================================================
856 TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
857                         (SALOMEDS::Study_ptr                       theStudy,
858                          Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
859                          Resource_DataMapOfAsciiStringAsciiString& theNames,
860                          bool                                      isPublished,
861                          bool                                      isMultiFile,
862                          bool                                      isHistoricalDump,
863                          bool&                                     aValidScript,
864                          const TCollection_AsciiString&            theSavedTrace)
865 {
866   int aStudyID = theStudy->StudyId();
867
868   TCollection_AsciiString helper; // to comfortably concatenate C strings
869   TCollection_AsciiString aSmeshpy( SMESH_2smeshpy::SmeshpyName() );
870   TCollection_AsciiString aSMESHGen( SMESH_2smeshpy::GenName() );
871   TCollection_AsciiString anOldGen( SMESH::TPythonDump::SMESHGenName() );
872
873   TCollection_AsciiString aScript;
874   if( isMultiFile )
875     aScript += "def RebuildData(theStudy):";
876   aScript += "\n\t";
877   if ( isPublished )
878     aScript += aSMESHGen + " = smeshBuilder.New(theStudy)\n\t";
879   else
880     aScript += aSMESHGen + " = smeshBuilder.New(None)\n\t";
881   aScript += helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()\n\t";
882   aScript += helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()\n\t";
883
884   // This is not needed since entering a plug-in system to smesh.py
885   // import python files corresponding to plugins
886   // set<string> moduleNameSet;
887   // map<string, GenericHypothesisCreator_i*>::iterator hyp_creator = myHypCreatorMap.begin();
888   // for ( ; hyp_creator != myHypCreatorMap.end(); ++hyp_creator ) {
889   //   string moduleName = hyp_creator->second->GetModuleName();
890   //   bool newModule = moduleNameSet.insert( moduleName ).second;
891   //   if ( newModule )
892   //     aScript += helper + "\n\t" + "from salome." + (char*) moduleName.c_str() + " import " + (char*) moduleName.c_str() +"Builder";
893   // }
894
895   // Dump trace of restored study
896   if (theSavedTrace.Length() > 0) {
897     // For the convertion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen
898     // was replaces with "smeshgen" (==TPythonDump::SMESHGenName()).
899     // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API
900     bool isNewVersion =
901       theSavedTrace.Location( anOldGen + ".", 1, theSavedTrace.Length() );
902     if ( !isNewVersion ) {
903       TCollection_AsciiString aSavedTrace( theSavedTrace );
904       TCollection_AsciiString aSmeshCall ( "smesh." ), gen( "gen" );
905       int beg, end = aSavedTrace.Length(), from = 1;
906       while ( from < end && ( beg = aSavedTrace.Location( aSmeshCall, from, end ))) {
907         char charBefore = ( beg == 1 ) ? ' ' : aSavedTrace.Value( beg - 1 );
908         if ( isspace( charBefore ) || charBefore == '=' ) { // "smesh." is not a part of a long word
909           aSavedTrace.Insert( beg + aSmeshCall.Length() - 1, gen );// "smesh" -> "smeshgen"
910           end += gen.Length();
911         }
912         from = beg + aSmeshCall.Length();
913       }
914       aScript += helper + "\n" + aSavedTrace;
915     }
916     else
917       // append a saved trace to the script
918       aScript += helper + "\n" + theSavedTrace;
919   }
920
921   // Dump trace of API methods calls
922   TCollection_AsciiString aNewLines = GetNewPythonLines(aStudyID);
923   if (aNewLines.Length() > 0) {
924     aScript += helper + "\n" + aNewLines;
925   }
926
927   // Convert IDL API calls into smeshBuilder.py API.
928   // Some objects are wrapped with python classes and
929   // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
930   Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
931   std::set< TCollection_AsciiString >      aRemovedObjIDs;
932   if ( !getenv("NO_2smeshpy_conversion"))
933     aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
934                                              theObjectNames, aRemovedObjIDs,
935                                              theStudy, isHistoricalDump );
936
937   // Replace characters used instead of quote marks to quote notebook variables
938   {
939     int pos = 1;
940     while (( pos = aScript.Location( 1, SMESH::TVar::Quote(), pos, aScript.Length() )))
941       aScript.SetValue( pos, '"' );
942   }
943
944   // Find entries to be replaced by names
945   Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript);
946   Standard_Integer aLen = aSeq->Length();
947
948   if (aLen == 0 && isMultiFile)
949     return aScript;
950
951   // Replace entries by the names
952   GEOM::GEOM_Gen_ptr geom = GetGeomEngine();
953   TColStd_SequenceOfAsciiString seqRemoved;
954   Resource_DataMapOfAsciiStringAsciiString mapRemoved;
955   Standard_Integer objectCounter = 0, aStart = 1, aScriptLength = aScript.Length();
956   TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("smeshObj_");
957
958   // Collect names of GEOM objects to exclude same names of SMESH objects
959   GEOM::string_array_var aGeomNames = geom->GetAllDumpNames();
960   int ign = 0, nbgn = aGeomNames->length();
961   for (; ign < nbgn; ign++) {
962     aName = aGeomNames[ign];
963     theObjectNames.Bind(aName, "1");
964   }
965
966   bool importGeom = false;
967   for (Standard_Integer i = 1; i <= aLen; i += 2) {
968     anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1);
969     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
970     // is a GEOM object?
971     aName = geom->GetDumpName( anEntry.ToCString() );
972     if (aName.IsEmpty()) {
973       // is a SMESH object
974       if (theObjectNames.IsBound(anEntry)) {
975         // The Object is in Study
976         aName = theObjectNames.Find(anEntry);
977         // check validity of aName
978         bool isValidName = fixPythonName( aName );
979         if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
980           // diff objects have same name - make a new name by appending a digit
981           TCollection_AsciiString aName2;
982           Standard_Integer i = 0;
983           do {
984             aName2 = aName + "_" + ++i;
985           } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2));
986           aName = aName2;
987           isValidName = false;
988         }
989         if ( !isValidName )
990           theObjectNames(anEntry) = aName;
991
992       } else {
993         // Removed Object
994         do {
995           aName = aBaseName + (++objectCounter);
996         } while (theObjectNames.IsBound(aName));
997         if ( !aRemovedObjIDs.count( anEntry ))
998           seqRemoved.Append(aName);
999         mapRemoved.Bind(anEntry, "1");
1000         theObjectNames.Bind(anEntry, aName);
1001       }
1002       theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
1003     }
1004     else
1005     {
1006       importGeom = true;
1007     }
1008     anUpdatedScript += aName;
1009     aStart = aSeq->Value(i + 1) + 1;
1010   }
1011
1012   // set initial part of aSript
1013   TCollection_AsciiString initPart = "import ";
1014   if ( isMultiFile )
1015     initPart += helper + "salome, ";
1016   initPart += " SMESH, SALOMEDS\n";
1017   initPart += "from salome.smesh import smeshBuilder\n";
1018   if ( importGeom && isMultiFile )
1019   {
1020     initPart += ("\n## import GEOM dump file ## \n"
1021                  "import string, os, sys, re\n"
1022                  "sys.path.insert( 0, os.path.dirname(__file__) )\n"
1023                  "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n");
1024   }
1025   anUpdatedScript.Insert ( 1, initPart );
1026
1027   // add final part of aScript
1028   if (aLen && aSeq->Value(aLen) < aScriptLength)
1029     anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength);
1030
1031   // Remove removed objects
1032   if ( seqRemoved.Length() > 0 ) {
1033     anUpdatedScript += "\n\t## some objects were removed";
1034     anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
1035   }
1036   for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
1037     anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
1038     anUpdatedScript += seqRemoved.Value(ir);
1039     // for object wrapped by class of smeshBuilder.py
1040     anEntry = theObjectNames( seqRemoved.Value(ir) );
1041     if ( anEntry2AccessorMethod.IsBound( anEntry ) )
1042       anUpdatedScript += helper + "." + anEntry2AccessorMethod( anEntry );
1043     anUpdatedScript += "))\n\tif SO is not None: aStudyBuilder.RemoveObjectWithChildren(SO)";
1044   }
1045
1046   // Set object names
1047
1048   TCollection_AsciiString aGUIName, aSetNameScriptPart;
1049   Resource_DataMapOfAsciiStringAsciiString mapEntries;
1050   for (Standard_Integer i = 1; i <= aLen; i += 2)
1051   {
1052     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
1053     aName   = geom->GetDumpName( anEntry.ToCString() );
1054     if (aName.IsEmpty() && // Not a GEOM object
1055         theNames.IsBound(anEntry) &&
1056         !aRemovedObjIDs.count(anEntry) && // A command creating anEntry was erased
1057         !mapEntries.IsBound(anEntry) && // Not yet processed
1058         !mapRemoved.IsBound(anEntry)) // Was not removed
1059     {
1060       aName    = theObjectNames.Find(anEntry);
1061       aGUIName = theNames.Find(anEntry);
1062       mapEntries.Bind(anEntry, aName);
1063       aSetNameScriptPart += helper + "\n\t" + aSMESHGen + ".SetName(" + aName;
1064       if ( anEntry2AccessorMethod.IsBound( anEntry ) )
1065         aSetNameScriptPart += helper + "." + anEntry2AccessorMethod( anEntry );
1066       aSetNameScriptPart += helper + ", '" + aGUIName + "')";
1067     }
1068   }
1069   if ( !aSetNameScriptPart.IsEmpty() )
1070   {
1071     anUpdatedScript += "\n\t## set object names";
1072     anUpdatedScript += aSetNameScriptPart;
1073   }
1074
1075   // -----------------------------------------------------------------
1076   // store visual properties of displayed objects
1077   // -----------------------------------------------------------------
1078
1079   if (isPublished)
1080   {
1081     //Output the script that sets up the visual parameters.
1082     CORBA::String_var compDataType = ComponentDataType();
1083     char* script = theStudy->GetDefaultScript( compDataType.in(), "\t");
1084     if (script && strlen(script) > 0) {
1085       anUpdatedScript += "\n\n\t### Store presentation parameters of displayed objects\n";
1086       anUpdatedScript += script;
1087       CORBA::string_free(script);
1088     }
1089   }
1090
1091   if( isMultiFile )
1092     anUpdatedScript += "\n\tpass";
1093   anUpdatedScript += "\n";
1094
1095   if( !isMultiFile ) // remove unnecessary tabulation
1096     RemoveTabulation( anUpdatedScript );
1097
1098   // -----------------------------------------------------------------
1099   // put string literals describing patterns into separate functions
1100   // -----------------------------------------------------------------
1101
1102   TCollection_AsciiString aLongString, aFunctionType;
1103   int where = 1;
1104   set< string > functionNameSet;
1105   while ( SMESH::TPythonDump::CutoutLongString( anUpdatedScript, where, aLongString, aFunctionType ))
1106   {
1107     // make a python string literal
1108     aLongString.Prepend(":\n\treturn '''\n");
1109     aLongString += "\n\t'''\n\tpass\n";
1110
1111     TCollection_AsciiString functionName;
1112
1113     // check if the function returning this literal is already defined
1114     int posAlready = anUpdatedScript.Location( aLongString, where, anUpdatedScript.Length() );
1115     if ( posAlready ) // already defined
1116     {
1117       // find the function name
1118       int functBeg = posAlready;
1119       char* script = (char*) anUpdatedScript.ToCString() + posAlready - 1; // look at ":" after "def fuction()"
1120       while ( *script != ' ' ) {
1121         script--;
1122         functBeg--;
1123       }
1124       functBeg++; // do not take ' '
1125       posAlready--; // do not take ':'
1126       functionName = anUpdatedScript.SubString( functBeg, posAlready );
1127     }
1128     else // not defined yet
1129     {
1130       // find a unique function name
1131       fixPythonName( aFunctionType );
1132       Standard_Integer nb = 0;
1133       do functionName = aFunctionType + "_" + ( nb++ ) + "()";
1134       while ( !functionNameSet.insert( functionName.ToCString() ).second );
1135
1136       // define function
1137       TCollection_AsciiString funDef = helper + "def " + functionName + aLongString;
1138       if ( isMultiFile )
1139       {
1140         anUpdatedScript += helper + "\n\n" + funDef;
1141       }
1142       else
1143       {
1144         funDef += "\n\n";
1145         anUpdatedScript.Insert( 1, funDef);
1146         where += funDef.Length();
1147       }
1148     }
1149     anUpdatedScript.InsertBefore( where, functionName ); // call function
1150   }
1151
1152   aValidScript = true;
1153
1154   return anUpdatedScript;
1155 }
1156
1157 //=============================================================================
1158 /*!
1159  *  GetNewPythonLines
1160  */
1161 //=============================================================================
1162 TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines (int theStudyID)
1163 {
1164   TCollection_AsciiString aScript;
1165
1166   // Dump trace of API methods calls
1167   if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
1168     Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[theStudyID];
1169     Standard_Integer istr, aLen = aPythonScript->Length();
1170     for (istr = 1; istr <= aLen; istr++) {
1171       aScript += "\n\t";
1172       aScript += aPythonScript->Value(istr);
1173     }
1174     aScript += "\n";
1175   }
1176
1177   return aScript;
1178 }
1179
1180 //=============================================================================
1181 /*!
1182  *  CleanPythonTrace
1183  */
1184 //=============================================================================
1185 void SMESH_Gen_i::CleanPythonTrace (int theStudyID)
1186 {
1187   TCollection_AsciiString aScript;
1188
1189   // Clean trace of API methods calls
1190   if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
1191     myPythonScripts[theStudyID]->Clear();
1192   }
1193 }