Salome HOME
Copyrights update
[modules/smesh.git] / src / SMESH_I / SMESH_DumpPython.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 // File    : SMESH_Gen_i_DumpPython.cxx
21 // Created : Thu Mar 24 17:17:59 2005
22 // Author  : Julia DOROVSKIKH
23 // Module  : SMESH
24 // $Header : $
25
26 #include "SMESH_PythonDump.hxx"
27 #include "SMESH_Gen_i.hxx"
28 #include "SMESH_Filter_i.hxx"
29
30 #include <TColStd_HSequenceOfInteger.hxx>
31 #include <TCollection_AsciiString.hxx>
32
33
34 #ifdef _DEBUG_
35 static int MYDEBUG = 0;
36 #else
37 static int MYDEBUG = 0;
38 #endif
39
40 static TCollection_AsciiString NotPublishedObjectName()
41 {
42   return "__NOT__Published__Object__";
43 }
44
45 namespace SMESH
46 {
47
48   size_t TPythonDump::myCounter = 0;
49
50   TPythonDump::
51   TPythonDump()
52   {
53     ++myCounter;
54   }
55   TPythonDump::
56   ~TPythonDump()
57   {
58     if(--myCounter == 0){
59       SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
60       SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
61       if(!aStudy->_is_nil()){
62         std::string aString = myStream.str();
63         TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
64         aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
65         if(MYDEBUG) MESSAGE(aString);
66       }
67     }
68   }
69
70   TPythonDump& 
71   TPythonDump::
72   operator<<(long int theArg){
73     myStream<<theArg;
74     return *this;
75   }
76
77   TPythonDump& 
78   TPythonDump::
79   operator<<(int theArg){
80     myStream<<theArg;
81     return *this;
82   }
83
84   TPythonDump& 
85   TPythonDump::
86   operator<<(double theArg){
87     myStream<<theArg;
88     return *this;
89   }
90
91   TPythonDump& 
92   TPythonDump::
93   operator<<(float theArg){
94     myStream<<theArg;
95     return *this;
96   }
97
98   TPythonDump& 
99   TPythonDump::
100   operator<<(const void* theArg){
101     myStream<<theArg;
102     return *this;
103   }
104
105   TPythonDump& 
106   TPythonDump::
107   operator<<(const char* theArg){
108     myStream<<theArg;
109     return *this;
110   }
111
112   TPythonDump& 
113   TPythonDump::
114   operator<<(const SMESH::ElementType& theArg)
115   {
116     myStream<<"SMESH.";
117     switch(theArg){
118     case ALL: 
119       myStream<<"ALL"; 
120       break;
121     case NODE: 
122       myStream<<"NODE"; 
123       break;
124     case EDGE: 
125       myStream<<"EDGE"; 
126       break;
127     case FACE: 
128       myStream<<"FACE"; 
129       break;
130     case VOLUME: 
131       myStream<<"VOLUME"; 
132       break;
133     }
134     return *this;
135   }
136
137
138   TPythonDump& 
139   TPythonDump::
140   operator<<(const SMESH::long_array& theArg)
141   {
142     myStream<<"[ ";
143     CORBA::Long i = 1, iEnd = theArg.length();
144     for(; i <= iEnd; i++) {
145       myStream<<theArg[i-1];
146       if(i < iEnd)
147         myStream<< ", ";
148     }
149     myStream<<" ]";
150     return *this;
151   }
152
153
154   TPythonDump& 
155   TPythonDump::
156   operator<<(CORBA::Object_ptr theArg)
157   {
158     TCollection_AsciiString aString("None");
159     SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
160     SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
161     SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
162     if(!aSObject->_is_nil()){
163       aString = aSObject->GetID();
164     }else if(!CORBA::is_nil(theArg)){
165       aString = "smeshObj_";
166       if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
167         aString += (int) theArg;
168       else
169         aString = NotPublishedObjectName();
170     }
171     myStream<<aString.ToCString();
172     return *this;
173   }
174
175   TPythonDump& 
176   TPythonDump::
177   operator<<(SMESH::FilterLibrary_i* theArg)
178   {
179     myStream<<"aFilterLibrary"<<theArg;
180     return *this;
181   }
182
183   TPythonDump& 
184   TPythonDump::
185   operator<<(SMESH::FilterManager_i* theArg)
186   {
187     myStream<<"aFilterManager";
188     return *this;
189   }
190
191   TPythonDump& 
192   TPythonDump::
193   operator<<(SMESH::Filter_i* theArg)
194   {
195     myStream<<"aFilter"<<theArg;
196     return *this;
197   }
198
199   TPythonDump& 
200   TPythonDump::
201   operator<<(SMESH::Functor_i* theArg)
202   {
203     FunctorType aFunctorType = theArg->GetFunctorType();
204     switch(aFunctorType){
205     case FT_AspectRatio:
206       myStream<<"anAspectRatio";
207       break;
208     case FT_AspectRatio3D:
209       myStream<<"anAspectRatio3D";
210       break;
211     case FT_Warping:
212       myStream<<"aWarping";
213       break;
214     case FT_MinimumAngle:
215       myStream<<"aMinimumAngle";
216       break;
217     case FT_Taper:
218       myStream<<"aTaper";
219       break;
220     case FT_Skew:
221       myStream<<"aSkew";
222       break;
223     case FT_Area:
224       myStream<<"aArea";
225       break;
226     case FT_FreeBorders:
227       myStream<<"aFreeBorders";
228       break;
229     case FT_FreeEdges:
230       myStream<<"aFreeEdges";
231       break;
232     case FT_MultiConnection:
233       myStream<<"aMultiConnection";
234       break;
235     case FT_MultiConnection2D:
236       myStream<<"aMultiConnection2D";
237       break;
238     case FT_Length:
239       myStream<<"aLength";
240       break;
241     case FT_Length2D:
242       myStream<<"aLength";
243       break;
244     case FT_BelongToGeom:
245       myStream<<"aBelongToGeom";
246       break;
247     case FT_BelongToPlane:
248       myStream<<"aBelongToPlane";
249       break;
250     case FT_BelongToCylinder:
251       myStream<<"aBelongToCylinder";
252       break;
253     case FT_LyingOnGeom:
254       myStream<<"aLyingOnGeom";
255       break;
256     case FT_RangeOfIds:
257       myStream<<"aRangeOfIds";
258       break;
259     case FT_BadOrientedVolume:
260       myStream<<"aBadOrientedVolume";
261       break;
262     case FT_LessThan:
263       myStream<<"aLessThan";
264       break;
265     case FT_MoreThan:
266       myStream<<"aMoreThan";
267       break;
268     case FT_EqualTo:
269       myStream<<"anEqualTo";
270       break;
271     case FT_LogicalNOT:
272       myStream<<"aLogicalNOT";
273       break;
274     case FT_LogicalAND:
275       myStream<<"aLogicalAND";
276       break;
277     case FT_LogicalOR:
278       myStream<<"aLogicalOR";
279       break;
280     case FT_Undefined:
281       myStream<<"anUndefined";
282       break;
283     }
284     myStream<<theArg;
285     return *this;
286   }
287 }
288
289 //=======================================================================
290 //function : DumpPython
291 //purpose  : 
292 //=======================================================================
293 Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
294                                            CORBA::Boolean isPublished,
295                                            CORBA::Boolean& isValidScript)
296 {
297   SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
298   if (CORBA::is_nil(aStudy))
299     return new Engines::TMPFile(0);
300
301   SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
302   if (CORBA::is_nil(aSO))
303     return new Engines::TMPFile(0);
304
305   // Map study entries to object names
306   Resource_DataMapOfAsciiStringAsciiString aMap;
307   Resource_DataMapOfAsciiStringAsciiString aMapNames;
308   TCollection_AsciiString s ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
309
310   SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
311   for (Itr->InitEx(true); Itr->More(); Itr->Next()) {
312     SALOMEDS::SObject_var aValue = Itr->Value();
313     CORBA::String_var anID = aValue->GetID();
314     CORBA::String_var aName = aValue->GetName();
315     TCollection_AsciiString aGUIName ( (char*) aName.in() );
316     TCollection_AsciiString anEnrty ( (char*) anID.in() );
317     if (aGUIName.Length() > 0) {
318       aMapNames.Bind( anEnrty, aGUIName );
319       aMap.Bind( anEnrty, aGUIName );
320     }
321   }
322
323   // Get trace of restored study
324   //SALOMEDS::SObject_var aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
325   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
326   SALOMEDS::GenericAttribute_var anAttr =
327     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
328
329   char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
330   TCollection_AsciiString aSavedTrace (oldValue);
331
332   // Add trace of API methods calls and replace study entries by names
333   //TCollection_AsciiString aScript =
334   //  SALOMEDSImpl_Study::GetDumpStudyComment("SMESH") + "\n\n" +
335   //    DumpPython_impl(aStudy->StudyId(), aMap, aMapNames, isPublished, isValidScript, aSavedTrace);
336   TCollection_AsciiString aScript =
337     "### This file is generated by SALOME automatically by dump python functionality of SMESH component\n\n";
338   aScript += DumpPython_impl(aStudy->StudyId(), aMap, aMapNames,
339                              isPublished, isValidScript, aSavedTrace);
340
341   int aLen = aScript.Length(); 
342   unsigned char* aBuffer = new unsigned char[aLen+1];
343   strcpy((char*)aBuffer, aScript.ToCString());
344
345   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
346   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1); 
347
348   bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen);
349   isValidScript = isValidScript && !hasNotPublishedObjects;
350
351   return aStreamFile._retn(); 
352 }
353
354 //=============================================================================
355 /*!
356  *  AddToPythonScript
357  */
358 //=============================================================================
359 void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString)
360 {
361   if (myPythonScripts.find(theStudyID) == myPythonScripts.end()) {
362     myPythonScripts[theStudyID] = new TColStd_HSequenceOfAsciiString;
363   }
364   myPythonScripts[theStudyID]->Append(theString);
365 }
366
367 //=============================================================================
368 /*!
369  *  RemoveLastFromPythonScript
370  */
371 //=============================================================================
372 void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID)
373 {
374   if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
375     int aLen = myPythonScripts[theStudyID]->Length();
376     myPythonScripts[theStudyID]->Remove(aLen);
377   }
378 }
379
380 //=======================================================================
381 //function : AddToCurrentPyScript
382 //purpose  : 
383 //=======================================================================
384
385 void SMESH_Gen_i::AddToCurrentPyScript (const TCollection_AsciiString& theString)
386 {
387   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
388   SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
389   if (aStudy->_is_nil()) return;
390   aSMESHGen->AddToPythonScript(aStudy->StudyId(), theString);
391 }
392
393
394 //=======================================================================
395 //function : AddObject
396 //purpose  : add object to script string
397 //=======================================================================
398
399 TCollection_AsciiString& SMESH_Gen_i::AddObject(TCollection_AsciiString& theStr,
400                                                 CORBA::Object_ptr        theObject)
401 {
402   TCollection_AsciiString aString("None");
403   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
404   SALOMEDS::SObject_var aSObject =
405     aSMESHGen->ObjectToSObject(aSMESHGen->GetCurrentStudy(), theObject);
406   if ( !aSObject->_is_nil() ) {
407     aString = aSObject->GetID();
408   } else if ( !CORBA::is_nil( theObject )) {
409     aString = "smeshObj_";
410     if ( aSMESHGen->CanPublishInStudy( theObject )) // not published SMESH object
411       aString += (int) theObject;
412     else
413       aString = NotPublishedObjectName();
414   }
415   theStr += aString;
416   return theStr;
417 }
418
419 //=======================================================================
420 //function : SavePython
421 //purpose  : 
422 //=======================================================================
423 void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
424 {
425   // Dump trace of API methods calls
426   TCollection_AsciiString aScript = GetNewPythonLines(theStudy->StudyId());
427
428   // Check contents of PythonObject attribute
429   SALOMEDS::SObject_var aSO = theStudy->FindComponent(ComponentDataType());
430   //SALOMEDS::SObject_var aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
431   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
432   SALOMEDS::GenericAttribute_var anAttr =
433     aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");
434
435   char* oldValue = SALOMEDS::AttributePythonObject::_narrow(anAttr)->GetObject();
436   TCollection_AsciiString oldScript (oldValue);
437
438   if (oldScript.Length() > 0) {
439     oldScript += "\n";
440     oldScript += aScript;
441   } else {
442     oldScript = aScript;
443   }
444
445   // Store in PythonObject attribute
446   SALOMEDS::AttributePythonObject::_narrow(anAttr)->SetObject(oldScript.ToCString(), 1);
447
448   // Clean trace of API methods calls
449   CleanPythonTrace(theStudy->StudyId());
450 }
451
452
453 // impl
454
455
456 //=============================================================================
457 /*!
458  *  FindEntries: Returns a sequence of start/end positions of entries in the string
459  */
460 //=============================================================================
461 Handle(TColStd_HSequenceOfInteger) FindEntries (TCollection_AsciiString& theString)
462 {
463   Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
464   Standard_Integer aLen = theString.Length();
465   Standard_Boolean isFound = Standard_False;
466
467   char* arr = theString.ToCString();
468   Standard_Integer i = 0, j;
469
470   while(i < aLen) {
471     int c = (int)arr[i];
472     j = i+1;
473     if(c >= 48 && c <= 57) { //Is digit?
474  
475       isFound = Standard_False;
476       while((j < aLen) && ((c >= 48 && c <= 57) || c == 58) ) { //Check if it is an entry
477         c = (int)arr[j++];  
478         if(c == 58) isFound = Standard_True;
479       }
480
481       if (isFound) {
482         int prev = (i < 1) ? 0 : (int)arr[i - 1];
483         // last char should be a diggit,
484         // previous char should not be '"'.
485         if (arr[j-2] != 58 && prev != 34) {
486           aSeq->Append(i+1); // +1 because AsciiString starts from 1
487           aSeq->Append(j-1);
488         }
489       }
490     }
491
492     i = j;
493   }
494
495   return aSeq;
496 }
497
498 //=============================================================================
499 /*!
500  *  DumpPython
501  */
502 //=============================================================================
503 TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
504                         (int theStudyID, 
505                          Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
506                          Resource_DataMapOfAsciiStringAsciiString& theNames,
507                          bool isPublished, 
508                          bool& aValidScript,
509                          const TCollection_AsciiString& theSavedTrace)
510 {
511   TCollection_AsciiString aScript;
512   aScript = "def RebuildData(theStudy):";
513   aScript += "\n\tsmesh = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"SMESH\")";
514   aScript += "\n\taFilterManager = smesh.CreateFilterManager()";
515   if ( isPublished )
516     aScript += "\n\tsmesh.SetCurrentStudy(theStudy)";
517   else
518     aScript += "\n\tsmesh.SetCurrentStudy(None)";
519
520   // Dump trace of restored study
521   if (theSavedTrace.Length() > 0) {
522     aScript += "\n";
523     aScript += theSavedTrace;
524   }
525
526   // Dump trace of API methods calls
527   TCollection_AsciiString aNewLines = GetNewPythonLines(theStudyID);
528   if (aNewLines.Length() > 0) {
529     aScript += "\n";
530     aScript += aNewLines;
531   }
532
533   // Find entries to be replaced by names
534   Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript);
535   Standard_Integer aLen = aSeq->Length();
536
537   if (aLen == 0)
538     return aScript;
539
540   // Replace entries by the names
541   GEOM::GEOM_Gen_ptr geom = GetGeomEngine();
542   TColStd_SequenceOfAsciiString seqRemoved;
543   Resource_DataMapOfAsciiStringAsciiString mapRemoved;
544   Standard_Integer objectCounter = 0, aStart = 1, aScriptLength = aScript.Length();
545   TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("smeshObj_"),
546     allowedChars ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
547
548   // Collect names of GEOM objects to exclude same names for SMESH objects
549   GEOM::string_array_var aGeomNames = geom->GetAllDumpNames();
550   int ign = 0, nbgn = aGeomNames->length();
551   for (; ign < nbgn; ign++) {
552     aName = aGeomNames[ign];
553     theObjectNames.Bind(aName, "1");
554   }
555
556   bool importGeom = false;
557   for (Standard_Integer i = 1; i <= aLen; i += 2) {
558     anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1);
559     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
560     // is a GEOM object?
561     aName = geom->GetDumpName( anEntry.ToCString() );
562     if (aName.IsEmpty()) {
563       // is a SMESH object
564       if (theObjectNames.IsBound(anEntry)) {
565         // The Object is in Study
566         aName = theObjectNames.Find(anEntry);
567         // check validity of aName
568         bool isValidName = true;
569         if ( aName.IsIntegerValue() ) { // aName must not start with a digit
570           aName.Insert( 1, 'a' );
571           isValidName = false;
572         }
573         int p, p2=1; // replace not allowed chars
574         while ((p = aName.FirstLocationNotInSet(allowedChars, p2, aName.Length()))) {
575           aName.SetValue(p, '_');
576           p2=p;
577           isValidName = false;
578         }
579         if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
580           // diff objects have same name - make a new name by appending a digit
581           TCollection_AsciiString aName2;
582           Standard_Integer i = 0;
583           do {
584             aName2 = aName + "_" + ++i;
585           } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2));
586           aName = aName2;
587           isValidName = false;
588         }
589         if ( !isValidName )
590           theObjectNames(anEntry) = aName;
591
592       } else {
593         // Removed Object
594         do {
595           aName = aBaseName + TCollection_AsciiString(++objectCounter);
596         } while (theObjectNames.IsBound(aName));
597         seqRemoved.Append(aName);
598         mapRemoved.Bind(anEntry, "1");
599         theObjectNames.Bind(anEntry, aName);
600       }
601       theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
602     }
603     else
604     {
605       importGeom = true;
606     }
607     anUpdatedScript += aName;
608     aStart = aSeq->Value(i + 1) + 1;
609   }
610
611   // set initial part of aSript
612   TCollection_AsciiString initPart = "import salome, SMESH, StdMeshers\n\n";
613   if ( importGeom )
614   {
615     initPart += ("import string, os, sys, re\n"
616                  "sys.path.insert( 0, os.path.dirname(__file__) )\n"
617                  "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n\n");
618   }
619   anUpdatedScript.Insert ( 1, initPart );
620
621   // add final part of aScript
622   if (aSeq->Value(aLen) < aScriptLength)
623     anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength);
624
625   // Remove removed objects
626   anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
627   for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
628     anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
629     anUpdatedScript += seqRemoved.Value(ir);
630     anUpdatedScript += "))\n\tif SO is not None: aStudyBuilder.RemoveObjectWithChildren(SO)";
631   }
632
633   // Set object names
634   anUpdatedScript += "\n\n\tisGUIMode = ";
635   anUpdatedScript += isPublished;
636   anUpdatedScript += "\n\tif isGUIMode:";
637   anUpdatedScript += "\n\t\tsmeshgui = salome.ImportComponentGUI(\"SMESH\")";
638   anUpdatedScript += "\n\t\tsmeshgui.Init(theStudy._get_StudyId())";
639   anUpdatedScript += "\n";
640
641   TCollection_AsciiString aGUIName;
642   Resource_DataMapOfAsciiStringAsciiString mapEntries;
643   for (Standard_Integer i = 1; i <= aLen; i += 2) {
644     anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
645     aName = geom->GetDumpName( anEntry.ToCString() );
646     if (aName.IsEmpty() && // Not a GEOM object
647         theNames.IsBound(anEntry) &&
648         !mapEntries.IsBound(anEntry) && // Not yet processed
649         !mapRemoved.IsBound(anEntry)) { // Was not removed
650       aName = theObjectNames.Find(anEntry);
651       aGUIName = theNames.Find(anEntry);
652       mapEntries.Bind(anEntry, aName);
653       anUpdatedScript += "\n\t\tsmeshgui.SetName(salome.ObjectToID(";
654       anUpdatedScript += aName + "), \"" + aGUIName + "\")";
655     }
656   }
657   anUpdatedScript += "\n\n\t\tsalome.sg.updateObjBrowser(0)";
658
659   anUpdatedScript += "\n\n\tpass\n";
660
661   aValidScript = true;
662
663   return anUpdatedScript;
664 }
665
666 //=============================================================================
667 /*!
668  *  GetNewPythonLines
669  */
670 //=============================================================================
671 TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines (int theStudyID)
672 {
673   TCollection_AsciiString aScript;
674
675   // Dump trace of API methods calls
676   if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
677     Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[theStudyID];
678     Standard_Integer istr, aLen = aPythonScript->Length();
679     for (istr = 1; istr <= aLen; istr++) {
680       aScript += "\n\t";
681       aScript += aPythonScript->Value(istr);
682     }
683     aScript += "\n";
684   }
685
686   return aScript;
687 }
688
689 //=============================================================================
690 /*!
691  *  CleanPythonTrace
692  */
693 //=============================================================================
694 void SMESH_Gen_i::CleanPythonTrace (int theStudyID)
695 {
696   TCollection_AsciiString aScript;
697
698   // Clean trace of API methods calls
699   if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) {
700     myPythonScripts[theStudyID]->Clear();
701   }
702 }