Salome HOME
Merge from V6_3_BR branch (Windows porting) 27/10/2011
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File      : SMESH_2smeshpy.cxx
25 // Created   : Fri Nov 18 13:20:10 2005
26 // Author    : Edward AGAPOV (eap)
27 //
28 #include "SMESH_2smeshpy.hxx"
29
30 #include "utilities.h"
31 #include "SMESH_PythonDump.hxx"
32 #include "SMESH_NoteBook.hxx"
33 #include "SMESH_Filter_i.hxx"
34
35 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
36
37 #include "SMESH_Gen_i.hxx"
38 /* SALOME headers that include CORBA headers that include windows.h 
39  * that defines GetObject symbol as GetObjectA should stand before SALOME headers
40  * that declare methods named GetObject - to apply the same rules of GetObject renaming
41  * and thus to avoid mess with GetObject symbol on Windows */
42
43 IMPLEMENT_STANDARD_HANDLE (_pyObject          ,Standard_Transient);
44 IMPLEMENT_STANDARD_HANDLE (_pyCommand         ,Standard_Transient);
45 IMPLEMENT_STANDARD_HANDLE (_pyGen             ,_pyObject);
46 IMPLEMENT_STANDARD_HANDLE (_pyMesh            ,_pyObject);
47 IMPLEMENT_STANDARD_HANDLE (_pySubMesh         ,_pyObject);
48 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor      ,_pyObject);
49 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis      ,_pyObject);
50 IMPLEMENT_STANDARD_HANDLE (_pySelfEraser      ,_pyObject);
51 IMPLEMENT_STANDARD_HANDLE (_pyGroup           ,_pyObject);
52 IMPLEMENT_STANDARD_HANDLE (_pyFilter          ,_pyObject);
53 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm       ,_pyHypothesis);
54 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
55 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis);
56
57 IMPLEMENT_STANDARD_RTTIEXT(_pyObject          ,Standard_Transient);
58 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand         ,Standard_Transient);
59 IMPLEMENT_STANDARD_RTTIEXT(_pyGen             ,_pyObject);
60 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh            ,_pyObject);
61 IMPLEMENT_STANDARD_RTTIEXT(_pySubMesh         ,_pyObject);
62 IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor      ,_pyObject);
63 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis      ,_pyObject);
64 IMPLEMENT_STANDARD_RTTIEXT(_pySelfEraser      ,_pyObject);
65 IMPLEMENT_STANDARD_RTTIEXT(_pyGroup           ,_pyObject);
66 IMPLEMENT_STANDARD_RTTIEXT(_pyFilter          ,_pyObject);
67 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm       ,_pyHypothesis);
68 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
69 IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis);
70 IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis);
71 IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis);
72
73 using namespace std;
74 using SMESH::TPythonDump;
75
76 /*!
77  * \brief Container of commands into which the initial script is split.
78  *        It also contains data coresponding to SMESH_Gen contents
79  */
80 static Handle(_pyGen) theGen;
81
82 static TCollection_AsciiString theEmptyString;
83
84 //#define DUMP_CONVERSION
85
86 #if !defined(_DEBUG_) && defined(DUMP_CONVERSION)
87 #undef DUMP_CONVERSION
88 #endif
89
90
91 namespace {
92
93   //================================================================================
94   /*!
95    * \brief Set of TCollection_AsciiString initialized by C array of C strings
96    */
97   //================================================================================
98
99   struct TStringSet: public set<TCollection_AsciiString>
100   {
101     /*!
102      * \brief Filling. The last string must be ""
103      */
104     void Insert(const char* names[]) {
105       for ( int i = 0; names[i][0] ; ++i )
106         insert( (char*) names[i] );
107     }
108     /*!
109      * \brief Check if a string is in
110      */
111     bool Contains(const TCollection_AsciiString& name ) {
112       return find( name ) != end();
113     }
114   };
115 }
116
117 //================================================================================
118 /*!
119  * \brief Convert python script using commands of smesh.py
120   * \param theScript - Input script
121   * \retval TCollection_AsciiString - Convertion result
122   *
123   * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
124  */
125 //================================================================================
126
127 TCollection_AsciiString
128 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
129                               Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
130                               Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
131 {
132   theGen = new _pyGen( theEntry2AccessorMethod, theObjectNames );
133
134   // split theScript into separate commands
135
136   SMESH_NoteBook * aNoteBook = new SMESH_NoteBook();
137   
138   int from = 1, end = theScript.Length(), to;
139   while ( from < end && ( to = theScript.Location( "\n", from, end )))
140   {
141     if ( to != from )
142         // cut out and store a command
143         aNoteBook->AddCommand( theScript.SubString( from, to - 1 ));
144       from = to + 1;
145   }
146   
147   aNoteBook->ReplaceVariables();
148
149   TCollection_AsciiString aNoteScript = aNoteBook->GetResultScript();
150   delete aNoteBook;
151   aNoteBook = 0;
152   
153   // split theScript into separate commands
154   from = 1, end = aNoteScript.Length();
155   while ( from < end && ( to = aNoteScript.Location( "\n", from, end )))
156   {
157     if ( to != from )
158       // cut out and store a command
159       theGen->AddCommand( aNoteScript.SubString( from, to - 1 ));
160     from = to + 1;
161   }
162
163   // finish conversion
164   theGen->Flush();
165 #ifdef DUMP_CONVERSION
166   MESSAGE_BEGIN ( std::endl << " ######## RESULT ######## " << std::endl<< std::endl );
167 #endif
168
169   // reorder commands after conversion
170   list< Handle(_pyCommand) >::iterator cmd;
171   bool orderChanges;
172   do {
173     orderChanges = false;
174     for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
175       if ( (*cmd)->SetDependentCmdsAfter() )
176         orderChanges = true;
177   } while ( orderChanges );
178   
179   // concat commands back into a script
180   TCollection_AsciiString aScript;
181   for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
182   {
183 #ifdef DUMP_CONVERSION
184     MESSAGE_ADD ( "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << std::endl );
185 #endif
186     if ( !(*cmd)->IsEmpty() ) {
187       aScript += "\n";
188       aScript += (*cmd)->GetString();
189     }
190   }
191   aScript += "\n";
192
193   theGen.Nullify();
194
195   return aScript;
196 }
197
198 //================================================================================
199 /*!
200  * \brief _pyGen constructor
201  */
202 //================================================================================
203
204 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
205                Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
206   : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
207     myNbCommands( 0 ),
208     myID2AccessorMethod( theEntry2AccessorMethod ),
209     myObjectNames( theObjectNames ),
210     myNbFilters( 0 )
211 {
212   // make that GetID() to return TPythonDump::SMESHGenName()
213   GetCreationCmd()->GetString() += "=";
214 }
215
216 //================================================================================
217 /*!
218  * \brief name of SMESH_Gen in smesh.py
219  */
220 //================================================================================
221
222 const char* _pyGen::AccessorMethod() const
223 {
224   return SMESH_2smeshpy::GenName();
225 }
226
227 //================================================================================
228 /*!
229  * \brief Convert a command using a specific converter
230   * \param theCommand - the command to convert
231  */
232 //================================================================================
233
234 Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
235 {
236   // store theCommand in the sequence
237   myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
238
239   Handle(_pyCommand) aCommand = myCommands.back();
240 #ifdef DUMP_CONVERSION
241   MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
242 #endif
243
244   _pyID objID = aCommand->GetObject();
245
246   if ( objID.IsEmpty() )
247     return aCommand;
248
249   // Find an object to process theCommand
250
251   // SMESH_Gen method?
252   if ( objID == this->GetID() || objID == SMESH_2smeshpy::GenName()) {
253     this->Process( aCommand );
254     return aCommand;
255   }
256
257   // SMESH_Mesh method?
258   map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
259   if ( id_mesh != myMeshes.end() )
260   {
261     // check for mesh editor object
262     if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
263       _pyID editorID = aCommand->GetResultValue();
264       Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
265       myMeshEditors.insert( make_pair( editorID, editor ));
266       return aCommand;
267     } 
268     // check for SubMesh objects
269     else if ( aCommand->GetMethod() == "GetSubMesh" ) { // SubMesh creation
270       _pyID subMeshID = aCommand->GetResultValue();
271       Handle(_pySubMesh) subMesh = new _pySubMesh( aCommand );
272       myObjects.insert( make_pair( subMeshID, subMesh ));
273     }
274     
275     id_mesh->second->Process( aCommand );
276     return aCommand;
277   }
278
279   // SMESH_MeshEditor method?
280   map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
281   if ( id_editor != myMeshEditors.end() )
282   {
283     id_editor->second->Process( aCommand );
284     TCollection_AsciiString processedCommand = aCommand->GetString();
285     // some commands of SMESH_MeshEditor create meshes
286     if ( aCommand->GetMethod().Search("MakeMesh") != -1 ) {
287       Handle(_pyMesh) mesh = new _pyMesh( aCommand, aCommand->GetResultValue() );
288       aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
289       myMeshes.insert( make_pair( mesh->GetID(), mesh ));
290     }
291     if ( aCommand->GetMethod() == "MakeBoundaryMesh") {
292       _pyID meshID = aCommand->GetResultValue(0);
293       if ( !myMeshes.count( meshID ) )
294       {
295         Handle(_pyMesh) mesh = new _pyMesh( aCommand, meshID );
296         aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
297         myMeshes.insert( make_pair( meshID, mesh ));
298       }
299     }
300     return aCommand;
301   }
302   // SMESH_Hypothesis method?
303   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
304   for ( ; hyp != myHypos.end(); ++hyp )
305     if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
306       (*hyp)->Process( aCommand );
307       return aCommand;
308     }
309
310   // aFilterManager.CreateFilter() ?
311   if ( aCommand->GetMethod() == "CreateFilter" )
312   {
313     // Set a more human readable name to a filter
314     // aFilter0x7fbf6c71cfb0 -> aFilter_nb
315     _pyID newID, filterID = aCommand->GetResultValue();
316     int pos = filterID.Search( "0x" );
317     if ( pos > 1 )
318       newID = (filterID.SubString(1,pos-1) + "_") + _pyID( ++myNbFilters );
319
320     Handle(_pyObject) filter( new _pyFilter( aCommand, newID ));
321     AddObject( filter );
322   }
323
324   // other object method?
325   map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.find( objID );
326   if ( id_obj != myObjects.end() ) {
327     id_obj->second->Process( aCommand );
328     return aCommand;
329   }
330
331   // Add access to a wrapped mesh
332   AddMeshAccessorMethod( aCommand );
333
334   // Add access to a wrapped algorithm
335   //  AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
336
337   // PAL12227. PythonDump was not updated at proper time; result is
338   //     aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
339   // TypeError: __init__() takes exactly 11 arguments (10 given)
340   const char wrongCommand[] = "SMESH.Filter.Criterion(";
341   if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
342   {
343     _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
344     // there must be 10 arguments, 5-th arg ThresholdID is missing,
345     const int wrongNbArgs = 9, missingArg = 5;
346     if ( tmpCmd.GetNbArgs() == wrongNbArgs )
347     {
348       for ( int i = wrongNbArgs; i > missingArg; --i )
349         tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
350       tmpCmd.SetArg(  missingArg, "''");
351       aCommand->GetString().Trunc( beg - 1 );
352       aCommand->GetString() += tmpCmd.GetString();
353     }
354     // IMP issue 0021014
355     // set GetCriterion(elementType,CritType,Compare,Treshold,UnaryOp,BinaryOp,Tolerance)
356     //                  1           2        3       4        5       6        7
357     // instead of "SMESH.Filter.Criterion(
358     // Type,Compare,Threshold,ThresholdStr,ThresholdID,UnaryOp,BinaryOp,Tolerance,TypeOfElement,Precision)
359     // 1    2       3         4            5           6       7        8         9             10
360     // in order to avoid the problem of type mismatch of long and FunctorType
361     const TCollection_AsciiString
362       SMESH("SMESH."), dfltFunctor = "SMESH.FT_Undefined", dftlTol = "1e-07", dftlPreci = "-1";
363     TCollection_AsciiString
364       Type          = aCommand->GetArg(1),  // long
365       Compare       = aCommand->GetArg(2),  // long
366       Threshold     = aCommand->GetArg(3),  // double
367       ThresholdStr  = aCommand->GetArg(4),  // string
368       ThresholdID   = aCommand->GetArg(5),  // string
369       UnaryOp       = aCommand->GetArg(6),  // long
370       BinaryOp      = aCommand->GetArg(7),  // long
371       Tolerance     = aCommand->GetArg(8),  // double
372       TypeOfElement = aCommand->GetArg(9),  // ElementType
373       Precision     = aCommand->GetArg(10); // long
374     Type     = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Type.IntegerValue() ));
375     Compare  = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Compare.IntegerValue() ));
376     UnaryOp  = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( UnaryOp.IntegerValue() ));
377     BinaryOp = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( BinaryOp.IntegerValue() ));
378
379     aCommand->RemoveArgs();
380     aCommand->SetObject( SMESH_2smeshpy::GenName() );
381     aCommand->SetMethod( "GetCriterion" );
382
383     aCommand->SetArg( 1, TypeOfElement );
384     aCommand->SetArg( 2, Type );
385     aCommand->SetArg( 3, Compare );
386
387     if ( ThresholdStr.Length() != 2 ) // not '' or ""
388       aCommand->SetArg( 4, ThresholdStr );
389     else if ( ThresholdID.Length() != 2 )
390       aCommand->SetArg( 4, ThresholdID );
391     else
392       aCommand->SetArg( 4, Threshold );
393     // find the last not default arg
394     int lastDefault = 8;
395     if ( Tolerance == dftlTol ) {
396       lastDefault = 7;
397       if ( BinaryOp == dfltFunctor ) {
398         lastDefault = 6;
399         if ( UnaryOp == dfltFunctor )
400           lastDefault = 5;
401       }
402     }
403     if ( 5 < lastDefault ) aCommand->SetArg( 5, UnaryOp );
404     if ( 6 < lastDefault ) aCommand->SetArg( 6, BinaryOp );
405     if ( 7 < lastDefault ) aCommand->SetArg( 7, Tolerance );
406     if ( Precision != dftlPreci )
407     {
408       TCollection_AsciiString crit = aCommand->GetResultValue();
409       aCommand->GetString() += "; ";
410       aCommand->GetString() += crit + ".Precision = " + Precision;
411     }
412   }
413   return aCommand;
414 }
415
416 //================================================================================
417 /*!
418  * \brief Convert the command or remember it for later conversion
419   * \param theCommand - The python command calling a method of SMESH_Gen
420  */
421 //================================================================================
422
423 void _pyGen::Process( const Handle(_pyCommand)& theCommand )
424 {
425   // there are methods to convert:
426   // CreateMesh( shape )
427   // Concatenate( [mesh1, ...], ... )
428   // CreateHypothesis( theHypType, theLibName )
429   // Compute( mesh, geom )
430   // Evaluate( mesh, geom )
431   // mesh creation
432   TCollection_AsciiString method = theCommand->GetMethod();
433
434   if ( method == "CreateMesh" || method == "CreateEmptyMesh")
435   {
436     Handle(_pyMesh) mesh = new _pyMesh( theCommand );
437     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
438     return;
439   }
440   if ( method == "CreateMeshesFromUNV" ||
441        method == "CreateMeshesFromSTL" ||
442        method == "CreateMeshesFromCGNS" ||
443        method == "CopyMesh" )
444   {
445     Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
446     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
447     return;
448   }
449   if( method == "CreateMeshesFromMED" || method == "CreateMeshesFromSAUV")
450   {
451     for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
452     {
453       Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
454       myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));
455     }
456   }
457
458   // CreateHypothesis()
459   if ( method == "CreateHypothesis" )
460   {
461     // issue 199929, remove standard library name (default parameter)
462     const TCollection_AsciiString & aLibName = theCommand->GetArg( 2 );
463     if ( aLibName.Search( "StdMeshersEngine" ) != -1 ) {
464       // keep first argument
465       TCollection_AsciiString arg = theCommand->GetArg( 1 );
466       theCommand->RemoveArgs();
467       theCommand->SetArg( 1, arg );
468     }
469
470     myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
471     return;
472   }
473
474   // smeshgen.Compute( mesh, geom ) --> mesh.Compute()
475   if ( method == "Compute" )
476   {
477     const _pyID& meshID = theCommand->GetArg( 1 );
478     map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
479     if ( id_mesh != myMeshes.end() ) {
480       theCommand->SetObject( meshID );
481       theCommand->RemoveArgs();
482       id_mesh->second->Flush();
483       return;
484     }
485   }
486
487   // smeshgen.Evaluate( mesh, geom ) --> mesh.Evaluate(geom)
488   if ( method == "Evaluate" )
489   {
490     const _pyID& meshID = theCommand->GetArg( 1 );
491     map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
492     if ( id_mesh != myMeshes.end() ) {
493       theCommand->SetObject( meshID );
494       _pyID geom = theCommand->GetArg( 2 );
495       theCommand->RemoveArgs();
496       theCommand->SetArg( 1, geom );
497       return;
498     }
499   }
500
501   // objects erasing creation command if no more it's commands invoked:
502   // SMESH_Pattern, FilterManager
503   if ( method == "GetPattern" ||
504        method == "CreateFilterManager" ||
505        method == "CreateMeasurements" ) {
506     Handle(_pyObject) obj = new _pySelfEraser( theCommand );
507     if ( !myObjects.insert( make_pair( obj->GetID(), obj )).second )
508       theCommand->Clear(); // already created
509   }
510
511   // Concatenate( [mesh1, ...], ... )
512   if ( method == "Concatenate" || method == "ConcatenateWithGroups")
513   {
514     if ( method == "ConcatenateWithGroups" ) {
515       theCommand->SetMethod( "Concatenate" );
516       theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
517     }
518     Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
519     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
520     AddMeshAccessorMethod( theCommand );
521   }
522
523   // Replace name of SMESH_Gen
524
525   // names of SMESH_Gen methods fully equal to methods defined in smesh.py
526   static TStringSet smeshpyMethods;
527   if ( smeshpyMethods.empty() ) {
528     const char * names[] =
529       { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
530         "GetPattern","GetSubShapesId",
531         "" }; // <- mark of array end
532     smeshpyMethods.Insert( names );
533   }
534   if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
535     // smeshgen.Method() --> smesh.Method()
536     theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
537   else
538     // smeshgen.Method() --> smesh.smesh.Method()
539     theCommand->SetObject( SMESH_2smeshpy::GenName() );
540 }
541
542 //================================================================================
543 /*!
544  * \brief Convert the remembered commands
545  */
546 //================================================================================
547
548 void _pyGen::Flush()
549 {
550   // create empty command
551   myLastCommand = new _pyCommand();
552
553   map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
554   for ( ; id_mesh != myMeshes.end(); ++id_mesh )
555     if ( ! id_mesh->second.IsNull() )
556       id_mesh->second->Flush();
557
558   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
559   for ( ; hyp != myHypos.end(); ++hyp )
560     if ( !hyp->IsNull() ) {
561       (*hyp)->Flush();
562       // smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
563       if ( !(*hyp)->IsWrapped() )
564         (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
565     }
566
567   map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.begin();
568   for ( ; id_obj != myObjects.end(); ++id_obj )
569     if ( ! id_obj->second.IsNull() )
570       id_obj->second->Flush();
571
572   myLastCommand->SetOrderNb( ++myNbCommands );
573   myCommands.push_back( myLastCommand );
574 }
575
576 //================================================================================
577 /*!
578  * \brief Add access method to mesh that is an argument
579   * \param theCmd - command to add access method
580   * \retval bool - true if added
581  */
582 //================================================================================
583
584 bool _pyGen::AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const
585 {
586   bool added = false;
587   map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
588   for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
589     if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
590       added = true;
591   }
592   return added;
593 }
594
595 //================================================================================
596 /*!
597  * \brief Add access method to algo that is an object or an argument
598   * \param theCmd - command to add access method
599   * \retval bool - true if added
600  */
601 //================================================================================
602
603 bool _pyGen::AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const
604 {
605   bool added = false;
606   list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
607   for ( ; hyp != myHypos.end(); ++hyp ) {
608     if ( (*hyp)->IsAlgo() && /*(*hyp)->IsWrapped() &&*/
609          theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
610       added = true;
611   }
612   return added;
613 }
614
615 //================================================================================
616 /*!
617  * \brief Find hypothesis by ID (entry)
618   * \param theHypID - The hypothesis ID
619   * \retval Handle(_pyHypothesis) - The found hypothesis
620  */
621 //================================================================================
622
623 Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
624 {
625   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
626   for ( ; hyp != myHypos.end(); ++hyp )
627     if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
628       return *hyp;
629   return Handle(_pyHypothesis)();
630 }
631
632 //================================================================================
633 /*!
634  * \brief Find algorithm the created algorithm
635   * \param theGeom - The shape ID the algorithm was created on
636   * \param theMesh - The mesh ID that created the algorithm
637   * \param dim - The algo dimension
638   * \retval Handle(_pyHypothesis) - The found algo
639  */
640 //================================================================================
641
642 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
643                                         const Handle(_pyHypothesis)& theHypothesis )
644 {
645   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
646   for ( ; hyp != myHypos.end(); ++hyp )
647     if ( !hyp->IsNull() &&
648          (*hyp)->IsAlgo() &&
649          theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
650          (*hyp)->GetGeom() == theGeom &&
651          (*hyp)->GetMesh() == theMesh )
652       return *hyp;
653   return 0;
654 }
655
656 //================================================================================
657 /*!
658  * \brief Find subMesh by ID (entry)
659   * \param theSubMeshID - The subMesh ID
660   * \retval Handle(_pySubMesh) - The found subMesh
661  */
662 //================================================================================
663
664 Handle(_pySubMesh) _pyGen::FindSubMesh( const _pyID& theSubMeshID )
665 {
666   map< _pyID, Handle(_pyObject) >::iterator id_subMesh = myObjects.find(theSubMeshID);
667   if ( id_subMesh != myObjects.end() )
668     return Handle(_pySubMesh)::DownCast( id_subMesh->second );
669   return Handle(_pySubMesh)();
670 }
671
672
673 //================================================================================
674 /*!
675  * \brief Change order of commands in the script
676   * \param theCmd1 - One command
677   * \param theCmd2 - Another command
678  */
679 //================================================================================
680
681 void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 )
682 {
683   list< Handle(_pyCommand) >::iterator pos1, pos2;
684   pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
685   pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
686   myCommands.insert( pos1, theCmd2 );
687   myCommands.insert( pos2, theCmd1 );
688   myCommands.erase( pos1 );
689   myCommands.erase( pos2 );
690
691   int nb1 = theCmd1->GetOrderNb();
692   theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
693   theCmd2->SetOrderNb( nb1 );
694 //   cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
695 //        << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
696 }
697
698 //================================================================================
699 /*!
700  * \brief Set one command after the other
701   * \param theCmd - Command to move
702   * \param theAfterCmd - Command ater which to insert the first one
703  */
704 //================================================================================
705
706 void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
707 {
708   setNeighbourCommand( theCmd, theAfterCmd, true );
709 }
710
711 //================================================================================
712 /*!
713  * \brief Set one command before the other
714   * \param theCmd - Command to move
715   * \param theBeforeCmd - Command before which to insert the first one
716  */
717 //================================================================================
718
719 void _pyGen::SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd )
720 {
721   setNeighbourCommand( theCmd, theBeforeCmd, false );
722 }
723
724 //================================================================================
725 /*!
726  * \brief Set one command before or after the other
727   * \param theCmd - Command to move
728   * \param theOtherCmd - Command ater or before which to insert the first one
729  */
730 //================================================================================
731
732 void _pyGen::setNeighbourCommand( Handle(_pyCommand)& theCmd,
733                                   Handle(_pyCommand)& theOtherCmd,
734                                   const bool theIsAfter )
735 {
736   list< Handle(_pyCommand) >::iterator pos;
737   pos = find( myCommands.begin(), myCommands.end(), theCmd );
738   myCommands.erase( pos );
739   pos = find( myCommands.begin(), myCommands.end(), theOtherCmd );
740   myCommands.insert( (theIsAfter ? ++pos : pos), theCmd );
741
742   int i = 1;
743   for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
744     (*pos)->SetOrderNb( i++ );
745 }
746
747 //================================================================================
748 /*!
749  * \brief Set command be last in list of commands
750   * \param theCmd - Command to be last
751  */
752 //================================================================================
753
754 Handle(_pyCommand)& _pyGen::GetLastCommand()
755 {
756   return myLastCommand;
757 }
758
759 //================================================================================
760 /*!
761  * \brief Set method to access to object wrapped with python class
762   * \param theID - The wrapped object entry
763   * \param theMethod - The accessor method
764  */
765 //================================================================================
766
767 void _pyGen::SetAccessorMethod(const _pyID& theID, const char* theMethod )
768 {
769   myID2AccessorMethod.Bind( theID, (char*) theMethod );
770 }
771
772 //================================================================================
773 /*!
774  * \brief Generated new ID for object and assign with existing name
775   * \param theID - ID of existing object
776  */
777 //================================================================================
778
779 _pyID _pyGen::GenerateNewID( const _pyID& theID )
780 {
781   int index = 1;
782   _pyID aNewID;
783   do {
784     aNewID = theID + _pyID( ":" ) + _pyID( index++ );
785   }
786   while ( myObjectNames.IsBound( aNewID ) );
787
788   myObjectNames.Bind( aNewID, myObjectNames.IsBound( theID )
789                       ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ))
790                       : _pyID( "A" ) + aNewID );
791   return aNewID;
792 }
793
794 //================================================================================
795 /*!
796  * \brief Stores theObj in myObjects
797  */
798 //================================================================================
799
800 void _pyGen::AddObject( Handle(_pyObject)& theObj )
801 {
802   myObjects.insert( make_pair( theObj->GetID(), theObj ));
803 }
804
805 //================================================================================
806 /*!
807  * \brief Finds a _pyObject by ID
808  */
809 //================================================================================
810
811 Handle(_pyObject) _pyGen::FindObject( const _pyID& theObjID )  const
812 {
813   std::map< _pyID, Handle(_pyObject) >::const_iterator id_obj = myObjects.find( theObjID );
814   return ( id_obj == myObjects.end() ) ? Handle(_pyObject)() : id_obj->second;
815 }
816   
817 //================================================================================
818 /*!
819  * \brief Find out type of geom group
820   * \param grpID - The geom group entry
821   * \retval int - The type
822  */
823 //================================================================================
824
825 // static bool sameGroupType( const _pyID&                   grpID,
826 //                            const TCollection_AsciiString& theType)
827 // {
828 //   // define group type as smesh.Mesh.Group() does
829 //   int type = -1;
830 //   SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
831 //   SALOMEDS::SObject_var aSObj = study->FindObjectID( grpID.ToCString() );
832 //   if ( !aSObj->_is_nil() ) {
833 //     GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
834 //     if ( !aGeomObj->_is_nil() ) {
835 //       switch ( aGeomObj->GetShapeType() ) {
836 //       case GEOM::VERTEX: type = SMESH::NODE; break;
837 //       case GEOM::EDGE:   type = SMESH::EDGE; break;
838 //       case GEOM::FACE:   type = SMESH::FACE; break;
839 //       case GEOM::SOLID:
840 //       case GEOM::SHELL:  type = SMESH::VOLUME; break;
841 //       case GEOM::COMPOUND: {
842 //         GEOM::GEOM_Gen_ptr aGeomGen = SMESH_Gen_i::GetSMESHGen()->GetGeomEngine();
843 //         if ( !aGeomGen->_is_nil() ) {
844 //           GEOM::GEOM_IGroupOperations_var aGrpOp =
845 //             aGeomGen->GetIGroupOperations( study->StudyId() );
846 //           if ( !aGrpOp->_is_nil() ) {
847 //             switch ( aGrpOp->GetType( aGeomObj )) {
848 //             case TopAbs_VERTEX: type = SMESH::NODE; break;
849 //             case TopAbs_EDGE:   type = SMESH::EDGE; break;
850 //             case TopAbs_FACE:   type = SMESH::FACE; break;
851 //             case TopAbs_SOLID:  type = SMESH::VOLUME; break;
852 //             default:;
853 //             }
854 //           }
855 //         }
856 //       }
857 //       default:;
858 //       }
859 //     }
860 //   }
861 //   if ( type < 0 ) {
862 //     MESSAGE("Type of the group " << grpID << " not found");
863 //     return false;
864 //   }
865 //   if ( theType.IsIntegerValue() )
866 //     return type == theType.IntegerValue();
867
868 //   switch ( type ) {
869 //   case SMESH::NODE:   return theType.Location( "NODE", 1, theType.Length() );
870 //   case SMESH::EDGE:   return theType.Location( "EDGE", 1, theType.Length() );
871 //   case SMESH::FACE:   return theType.Location( "FACE", 1, theType.Length() );
872 //   case SMESH::VOLUME: return theType.Location( "VOLUME", 1, theType.Length() );
873 //   default:;
874 //   }
875 //   return false;
876 // }
877
878 //================================================================================
879 /*!
880  * \brief
881   * \param theCreationCmd -
882  */
883 //================================================================================
884
885 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd)
886   : _pyObject(theCreationCmd), myHasEditor(false)
887 {
888   // convert my creation command
889   Handle(_pyCommand) creationCmd = GetCreationCmd();
890   //TCollection_AsciiString str = creationCmd->GetMethod();
891 //   if(str != "CreateMeshesFromUNV" &&
892 //      str != "CreateMeshesFromMED" &&
893 //      str != "CreateMeshesFromSTL")
894   creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
895   creationCmd->SetMethod( "Mesh" );
896
897   theGen->SetAccessorMethod( GetID(), "GetMesh()" );
898 }
899
900 //================================================================================
901 /*!
902  * \brief
903   * \param theCreationCmd -
904  */
905 //================================================================================
906 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString& id):
907   _pyObject(theCreationCmd), myHasEditor(false)
908 {
909   // convert my creation command
910   Handle(_pyCommand) creationCmd = GetCreationCmd();
911   creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
912   theGen->SetAccessorMethod( id, "GetMesh()" );
913 }
914
915 //================================================================================
916 /*!
917  * \brief Convert an IDL API command of SMESH::SMESH_Mesh to a method call of python Mesh
918   * \param theCommand - Engine method called for this mesh
919  */
920 //================================================================================
921
922 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
923 {
924   // some methods of SMESH_Mesh interface needs special conversion
925   // to methods of Mesh python class
926   //
927   // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
928   //     --> in Mesh_Algorithm.Create(mesh, geom, hypo, so)
929   // 2. AddHypothesis(geom, hyp)
930   //     --> in Mesh_Algorithm.Hypothesis(hyp, args, so)
931   // 3. CreateGroupFromGEOM(type, name, grp)
932   //     --> in Mesh.Group(grp, name="")
933   // 4. ExportToMED(f, auto_groups, version)
934   //     --> in Mesh.ExportMED( f, auto_groups, version )
935   // 5. etc
936
937   const TCollection_AsciiString method = theCommand->GetMethod();
938   // ----------------------------------------------------------------------
939   if ( method == "GetSubMesh" ) { // collect submeshes of the mesh
940     Handle(_pySubMesh) subMesh = theGen->FindSubMesh( theCommand->GetResultValue() );
941     if ( !subMesh.IsNull() ) {
942       subMesh->SetCreator( this );
943       mySubmeshes.push_back( subMesh );
944     }
945   }
946   // ----------------------------------------------------------------------
947   else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO )
948     myAddHypCmds.push_back( theCommand );
949     // set mesh to hypo
950     const _pyID& hypID = theCommand->GetArg( 2 );
951     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
952     if ( !hyp.IsNull() ) {
953       myHypos.push_back( hyp );
954       if ( hyp->GetMesh().IsEmpty() )
955         hyp->SetMesh( this->GetID() );
956     }
957   }
958   // ----------------------------------------------------------------------
959   else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
960     _pyID grp = theCommand->GetArg( 3 );
961     // VSR 24/12/2010. PAL21106: always use GroupOnGeom() function on dump
962     // next if(){...} section is commented
963     //if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
964     //  theCommand->SetMethod( "Group" );
965     //  theCommand->RemoveArgs();
966     //  theCommand->SetArg( 1, grp );
967     //}
968     //else {
969     // ------------------------->>>>> GroupOnGeom( grp, name, typ )
970       _pyID type = theCommand->GetArg( 1 );
971       _pyID name = theCommand->GetArg( 2 );
972       theCommand->SetMethod( "GroupOnGeom" );
973       theCommand->RemoveArgs();
974       theCommand->SetArg( 1, grp );
975       theCommand->SetArg( 2, name );
976       theCommand->SetArg( 3, type );
977     //}
978   }
979   // ----------------------------------------------------------------------
980   else if ( method == "CreateGroupFromFilter" ) // --> GroupOnFilter()
981   {
982     theCommand->SetMethod( "GroupOnFilter" );
983   }
984   // ----------------------------------------------------------------------
985   else if ( method == "GetIdsFromFilter" )
986   {
987     // GetIdsFromFilter( aFilter0x4743dc0) -> GetIdsFromFilter( aFilter_1)
988     _pyID filterID = theCommand->GetArg(1);
989     Handle(_pyObject) filter = theGen->FindObject( filterID );
990     if ( !filter.IsNull() && filter->IsKind(STANDARD_TYPE(_pyFilter)))
991       filter->Process( theCommand );
992   }
993   // ----------------------------------------------------------------------
994   else if ( method == "CreateGroup" ) // CreateGroup() --> CreateEmptyGroup()
995   {
996     theCommand->SetMethod( "CreateEmptyGroup" );
997     Handle(_pyGroup) group = new _pyGroup( theCommand );
998     theGen->AddObject( group );
999   }
1000   // ----------------------------------------------------------------------
1001   else if ( method == "ExportToMED" ||   // ExportToMED()  --> ExportMED()
1002             method == "ExportToMEDX" ) { // ExportToMEDX() --> ExportMED()
1003     theCommand->SetMethod( "ExportMED" );
1004   }
1005   // ----------------------------------------------------------------------
1006   else if ( method == "ExportCGNS" )
1007   { // ExportCGNS(part, ...) -> ExportCGNS(..., part)
1008     _pyID partID = theCommand->GetArg( 1 );
1009     int nbArgs = theCommand->GetNbArgs();
1010     for ( int i = 2; i <= nbArgs; ++i )
1011       theCommand->SetArg( i-1, theCommand->GetArg( i ));
1012     theCommand->SetArg( nbArgs, partID );
1013   }
1014   // ----------------------------------------------------------------------
1015   else if ( method.Location( "ExportPartTo", 1, method.Length() ) == 1 )
1016   { // ExportPartTo*(part, ...) -> Export*(..., part)
1017     //
1018     // remove "PartTo" from the method
1019     TCollection_AsciiString newMethod = method;
1020     newMethod.Remove( 7, 6 );
1021     theCommand->SetMethod( newMethod );
1022     // make the 1st arg be the last one
1023     _pyID partID = theCommand->GetArg( 1 );
1024     int nbArgs = theCommand->GetNbArgs();
1025     for ( int i = 2; i <= nbArgs; ++i )
1026       theCommand->SetArg( i-1, theCommand->GetArg( i ));
1027     theCommand->SetArg( nbArgs, partID );
1028   }
1029   // ----------------------------------------------------------------------
1030   else if ( method == "RemoveHypothesis" ) // (geom, hyp)
1031   {
1032     _pyID hypID = theCommand->GetArg( 2 );
1033
1034     // check if this mesh still has corresponding addition command
1035     bool hasAddCmd = false;
1036     list< Handle(_pyCommand) >::iterator cmd = myAddHypCmds.begin();
1037     while ( cmd != myAddHypCmds.end() )
1038     {
1039       // AddHypothesis(geom, hyp)
1040       if ( hypID == (*cmd)->GetArg( 2 )) { // erase both (add and remove) commands
1041         theCommand->Clear();
1042         (*cmd)->Clear();
1043         cmd = myAddHypCmds.erase( cmd );
1044         hasAddCmd = true;
1045       }
1046       else {
1047         ++cmd;
1048       }
1049     }
1050     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
1051     if ( ! hasAddCmd && hypID.Length() != 0 ) { // hypo addition already wrapped
1052       // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
1053       _pyID geom = theCommand->GetArg( 1 );
1054       theCommand->RemoveArgs();
1055       theCommand->SetArg( 1, hypID );
1056       if ( geom != GetGeom() )
1057         theCommand->SetArg( 2, geom );
1058     }
1059     // remove hyp from myHypos
1060     myHypos.remove( hyp );
1061   }
1062   // check for SubMesh order commands
1063   else if ( theCommand->GetMethod() == "GetMeshOrder" ||
1064             theCommand->GetMethod() == "SetMeshOrder" )
1065   {
1066     // make commands GetSubMesh() returning sub-meshes be before using sub-meshes
1067     // by GetMeshOrder() and SetMeshOrder(), since by defalut GetSubMesh()
1068     // commands are moved at the end of the script
1069     const bool isArg = theCommand->GetMethod() == "SetMeshOrder";
1070     const TCollection_AsciiString& cmdStr = theCommand->GetString();
1071     int begPos = (/*isArg ? cmdStr.Search( "(" ) :*/ cmdStr.Search( "[" )) + 1;
1072     int endPos = (isArg ? cmdStr.Search( ")" ) : cmdStr.Search( "=" )) - 1;
1073     if ( begPos != -1 && begPos < endPos && endPos <= cmdStr.Length() ) {
1074       TCollection_AsciiString aSubStr = cmdStr.SubString( begPos, endPos );
1075       Standard_Integer index = 1;
1076       TCollection_AsciiString anIDStr = aSubStr.Token("\t ,[]", index++);
1077       while ( !anIDStr.IsEmpty() ) {
1078         Handle(_pySubMesh) subMesh = theGen->FindSubMesh( anIDStr );
1079         if ( !subMesh.IsNull() )
1080           subMesh->Process( theCommand ); // it moves GetSubMesh() before theCommand
1081         anIDStr = aSubStr.Token("\t ,[]", index++);
1082       }
1083     }
1084   }
1085   // add accessor method if necessary
1086   else
1087   {
1088     if ( NeedMeshAccess( theCommand ))
1089       // apply theCommand to the mesh wrapped by smeshpy mesh
1090       AddMeshAccess( theCommand );
1091   }
1092 }
1093
1094 //================================================================================
1095 /*!
1096  * \brief Return True if addition of accesor method is needed
1097  */
1098 //================================================================================
1099
1100 bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
1101 {
1102   // names of SMESH_Mesh methods fully equal to methods of python class Mesh,
1103   // so no conversion is needed for them at all:
1104   static TStringSet sameMethods;
1105   if ( sameMethods.empty() ) {
1106     const char * names[] =
1107       { "ExportDAT","ExportUNV","ExportSTL","ExportSAUV", "RemoveGroup","RemoveGroupWithContents",
1108         "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
1109         "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
1110         "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
1111         "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
1112         "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
1113         "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
1114         "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
1115         "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
1116         "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
1117         "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
1118         "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
1119         "Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder"
1120         ,"" }; // <- mark of end
1121     sameMethods.Insert( names );
1122   }
1123
1124   return !sameMethods.Contains( theCommand->GetMethod() );
1125 }
1126
1127 //================================================================================
1128 /*!
1129  * \brief Convert creation and addition of all algos and hypos
1130  */
1131 //================================================================================
1132
1133 void _pyMesh::Flush()
1134 {
1135   list < Handle(_pyCommand) >::iterator cmd;
1136
1137   // try to convert algo addition like this:
1138   // mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
1139   for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
1140   {
1141     Handle(_pyCommand) addCmd = *cmd;
1142
1143     _pyID algoID = addCmd->GetArg( 2 );
1144     Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
1145     if ( algo.IsNull() || !algo->IsAlgo() )
1146       continue;
1147
1148     // check and create new algorithm instance if it is already wrapped
1149     if ( algo->IsWrapped() ) {
1150       _pyID localAlgoID = theGen->GenerateNewID( algoID );
1151       TCollection_AsciiString aNewCmdStr = localAlgoID +
1152         TCollection_AsciiString( " = " ) + theGen->GetID() +
1153         TCollection_AsciiString( ".CreateHypothesis( \"" ) + algo->GetAlgoType() +
1154         TCollection_AsciiString( "\" )" );
1155
1156       Handle(_pyCommand) newCmd = theGen->AddCommand( aNewCmdStr );
1157       Handle(_pyAlgorithm) newAlgo = Handle(_pyAlgorithm)::DownCast(theGen->FindHyp( localAlgoID ));
1158       if ( !newAlgo.IsNull() ) {
1159         newAlgo->Assign( algo, this->GetID() );
1160         newAlgo->SetCreationCmd( newCmd );
1161         algo = newAlgo;
1162         // set algorithm creation
1163         theGen->SetCommandBefore( newCmd, addCmd );
1164       }
1165       else
1166         newCmd->Clear();
1167     }
1168     _pyID geom = addCmd->GetArg( 1 );
1169     bool isLocalAlgo = ( geom != GetGeom() );
1170
1171     // try to convert
1172     if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
1173     {
1174       // wrapped algo is created atfer mesh creation
1175       GetCreationCmd()->AddDependantCmd( addCmd );
1176
1177       if ( isLocalAlgo ) {
1178         // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
1179         addCmd->SetArg( addCmd->GetNbArgs() + 1,
1180                         TCollection_AsciiString( "geom=" ) + geom );
1181         // sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
1182         list < Handle(_pySubMesh) >::iterator smIt;
1183         for ( smIt = mySubmeshes.begin(); smIt != mySubmeshes.end(); ++smIt ) {
1184           Handle(_pySubMesh) subMesh = *smIt;
1185           Handle(_pyCommand) subCmd = subMesh->GetCreationCmd();
1186           if ( geom == subCmd->GetArg( 1 )) {
1187             subCmd->SetObject( algo->GetID() );
1188             subCmd->RemoveArgs();
1189             subMesh->SetCreator( algo );
1190           }
1191         }
1192       }
1193     }
1194     else // KO - ALGO was already created
1195     {
1196       // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
1197       addCmd->RemoveArgs();
1198       addCmd->SetArg( 1, algoID );
1199       if ( isLocalAlgo )
1200         addCmd->SetArg( 2, geom );
1201     }
1202   }
1203
1204   // try to convert hypo addition like this:
1205   // mesh.AddHypothesis(geom, HYPO ) --> HYPO = algo.Hypo()
1206   for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
1207   {
1208     Handle(_pyCommand) addCmd = *cmd;
1209     _pyID hypID = addCmd->GetArg( 2 );
1210     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
1211     if ( hyp.IsNull() || hyp->IsAlgo() )
1212       continue;
1213     bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
1214     if ( !converted ) {
1215       // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
1216       _pyID geom = addCmd->GetArg( 1 );
1217       addCmd->RemoveArgs();
1218       addCmd->SetArg( 1, hypID );
1219       if ( geom != GetGeom() )
1220         addCmd->SetArg( 2, geom );
1221     }
1222   }
1223
1224   // sm = mesh.GetSubMesh(geom, name) --> sm = mesh.GetMesh().GetSubMesh(geom, name)
1225 //   for ( cmd = mySubmeshes.begin(); cmd != mySubmeshes.end(); ++cmd ) {
1226 //     Handle(_pyCommand) subCmd = *cmd;
1227 //     if ( subCmd->GetNbArgs() > 0 )
1228 //       AddMeshAccess( subCmd );
1229 //   }
1230   myAddHypCmds.clear();
1231   mySubmeshes.clear();
1232
1233   // flush hypotheses
1234   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1235   for ( ; hyp != myHypos.end(); ++hyp )
1236     (*hyp)->Flush();
1237 }
1238
1239 //================================================================================
1240 /*!
1241  * \brief MeshEditor convert its commands to ones of mesh
1242  */
1243 //================================================================================
1244
1245 _pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
1246   _pyObject( theCreationCmd )
1247 {
1248   myMesh = theCreationCmd->GetObject();
1249   myCreationCmdStr = theCreationCmd->GetString();
1250   theCreationCmd->Clear();
1251 }
1252
1253 //================================================================================
1254 /*!
1255  * \brief convert its commands to ones of mesh
1256  */
1257 //================================================================================
1258
1259 void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
1260 {
1261   // names of SMESH_MeshEditor methods fully equal to methods of python class Mesh, so
1262   // commands calling this methods are converted to calls of methods of Mesh
1263   static TStringSet sameMethods;
1264   if ( sameMethods.empty() ) {
1265     const char * names[] = {
1266       "RemoveElements","RemoveNodes","RemoveOrphanNodes","AddNode","Add0DElement","AddEdge","AddFace","AddPolygonalFace",
1267       "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode", "MoveClosestNodeToPoint",
1268       "InverseDiag","DeleteDiag","Reorient","ReorientObject","TriToQuad","SplitQuad","SplitQuadObject",
1269       "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
1270       "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
1271       "RotationSweep","RotationSweepObject","RotationSweepObject1D","RotationSweepObject2D",
1272       "ExtrusionSweep","AdvancedExtrusion","ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D",
1273       "ExtrusionAlongPath","ExtrusionAlongPathObject","ExtrusionAlongPathX",
1274       "ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D",
1275       "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
1276       "FindCoincidentNodes",/*"FindCoincidentNodesOnPart",*/"MergeNodes","FindEqualElements",
1277       "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
1278       "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
1279       "GetLastCreatedElems",
1280       "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
1281       "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh"
1282       ,"" }; // <- mark of the end
1283     sameMethods.Insert( names );
1284   }
1285
1286   // names of SMESH_MeshEditor methods which differ from methods of class Mesh
1287   // only by last two arguments
1288   static TStringSet diffLastTwoArgsMethods;
1289   if (diffLastTwoArgsMethods.empty() ) {
1290     const char * names[] = {
1291       "MirrorMakeGroups","MirrorObjectMakeGroups",
1292       "TranslateMakeGroups","TranslateObjectMakeGroups",
1293       "RotateMakeGroups","RotateObjectMakeGroups",
1294       ""};// <- mark of the end
1295     diffLastTwoArgsMethods.Insert( names );
1296   }
1297
1298   const TCollection_AsciiString & method = theCommand->GetMethod();
1299   bool isPyMeshMethod = sameMethods.Contains( method );
1300   if ( !isPyMeshMethod )
1301   {
1302     //Replace SMESH_MeshEditor "MakeGroups" functions by the Mesh
1303     //functions with the flag "theMakeGroups = True" like:
1304     //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
1305     int pos = method.Search("MakeGroups");
1306     if( pos != -1)
1307     {
1308       isPyMeshMethod = true;
1309
1310       // 1. Remove "MakeGroups" from the Command
1311       TCollection_AsciiString aMethod = theCommand->GetMethod();
1312       int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
1313       aMethod.Trunc(pos-1);
1314       theCommand->SetMethod(aMethod);
1315
1316       // 2. And add last "True" argument(s)
1317       while(nbArgsToAdd--)
1318         theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
1319     }
1320   }
1321
1322   // set "ExtrusionAlongPathX()" instead of "ExtrusionAlongPathObjX()"
1323   if ( !isPyMeshMethod && method == "ExtrusionAlongPathObjX")
1324   {
1325     isPyMeshMethod=true;
1326     theCommand->SetMethod("ExtrusionAlongPathX");
1327   }
1328
1329   // set "FindCoincidentNodesOnPart()" instead of "FindCoincidentNodesOnPartBut()"
1330   if ( !isPyMeshMethod && method == "FindCoincidentNodesOnPartBut")
1331   {
1332     isPyMeshMethod=true;
1333     theCommand->SetMethod("FindCoincidentNodesOnPart");
1334   }
1335   // DoubleNodeElemGroupNew() -> DoubleNodeElemGroup()
1336   // DoubleNodeGroupNew() -> DoubleNodeGroup()
1337   // DoubleNodeGroupsNew() -> DoubleNodeGroups()
1338   // DoubleNodeElemGroupsNew() -> DoubleNodeElemGroups()
1339   if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew"  ||
1340                             method == "DoubleNodeElemGroupsNew" ||
1341                             method == "DoubleNodeGroupNew"      ||
1342                             method == "DoubleNodeGroupsNew"))
1343   {
1344     isPyMeshMethod=true;
1345     theCommand->SetMethod( method.SubString( 1, method.Length()-3));
1346     theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
1347   }
1348   // ConvertToQuadraticObject(bool,obj) -> ConvertToQuadratic(bool,obj)
1349   // ConvertFromQuadraticObject(obj) -> ConvertFromQuadratic(obj)
1350   if ( !isPyMeshMethod && ( method == "ConvertToQuadraticObject" ||
1351                             method == "ConvertFromQuadraticObject" ))
1352   {
1353     isPyMeshMethod=true;
1354     theCommand->SetMethod( method.SubString( 1, method.Length()-6));
1355     // prevent moving creation of the converted sub-mesh to the end of the script
1356     bool isFromQua = ( method.Value( 8 ) == 'F' );
1357     Handle(_pySubMesh) sm = theGen->FindSubMesh( theCommand->GetArg( isFromQua ? 1 : 2 ));
1358     if ( !sm.IsNull() )
1359       sm->Process( theCommand );
1360   }
1361   // FindAmongElementsByPoint(meshPart, x, y, z, elementType) ->
1362   // FindElementsByPoint(x, y, z, elementType, meshPart)
1363   if ( !isPyMeshMethod && method == "FindAmongElementsByPoint" )
1364   {
1365     isPyMeshMethod=true;
1366     theCommand->SetMethod( "FindElementsByPoint" );
1367     // make the 1st arg be the last one
1368     _pyID partID = theCommand->GetArg( 1 );
1369     int nbArgs = theCommand->GetNbArgs();
1370     for ( int i = 2; i <= nbArgs; ++i )
1371       theCommand->SetArg( i-1, theCommand->GetArg( i ));
1372     theCommand->SetArg( nbArgs, partID );
1373   }
1374
1375   // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
1376   // so let _pyMesh care of it (TMP?)
1377   //     if ( theCommand->GetMethod().Search("MakeMesh") != -1 )
1378   //       _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod()
1379   if ( isPyMeshMethod )
1380   {
1381     theCommand->SetObject( myMesh );
1382   }
1383   else
1384   {
1385     // editor creation command is needed only if any editor function is called
1386     theGen->AddMeshAccessorMethod( theCommand ); // for *Object()
1387     if ( !myCreationCmdStr.IsEmpty() ) {
1388       GetCreationCmd()->GetString() = myCreationCmdStr;
1389       myCreationCmdStr.Clear();
1390     }
1391   }
1392 }
1393
1394 //================================================================================
1395 /*!
1396  * \brief _pyHypothesis constructor
1397   * \param theCreationCmd -
1398  */
1399 //================================================================================
1400
1401 _pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
1402   _pyObject( theCreationCmd )
1403 {
1404   myIsAlgo = myIsWrapped = /*myIsConverted = myIsLocal = myDim = */false;
1405 }
1406
1407 //================================================================================
1408 /*!
1409  * \brief Creates algorithm or hypothesis
1410   * \param theCreationCmd - The engine command creating a hypothesis
1411   * \retval Handle(_pyHypothesis) - Result _pyHypothesis
1412  */
1413 //================================================================================
1414
1415 Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& theCreationCmd)
1416 {
1417   // theCreationCmd: CreateHypothesis( "theHypType", "theLibName" )
1418   ASSERT (( theCreationCmd->GetMethod() == "CreateHypothesis"));
1419
1420   Handle(_pyHypothesis) hyp, algo;
1421
1422   // "theHypType"
1423   const TCollection_AsciiString & hypTypeQuoted = theCreationCmd->GetArg( 1 );
1424   if ( hypTypeQuoted.IsEmpty() )
1425     return hyp;
1426   // theHypType
1427   TCollection_AsciiString  hypType =
1428     hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
1429
1430   algo = new _pyAlgorithm( theCreationCmd );
1431   hyp  = new _pyHypothesis( theCreationCmd );
1432
1433   // 1D Regular_1D ----------
1434   if ( hypType == "Regular_1D" ) {
1435     // set mesh's method creating algo,
1436     // i.e. convertion result will be "regular1d = Mesh.Segment()",
1437     // and set hypType by which algo creating a hypothesis is searched for
1438     algo->SetConvMethodAndType("Segment", hypType.ToCString());
1439   }
1440   else if ( hypType == "CompositeSegment_1D" ) {
1441     algo->SetConvMethodAndType("Segment", "Regular_1D");
1442     algo->myArgs.Append( "algo=smesh.COMPOSITE");
1443   }
1444   else if ( hypType == "LocalLength" ) {
1445     // set algo's method creating hyp, and algo type
1446     hyp->SetConvMethodAndType( "LocalLength", "Regular_1D");
1447     // set method whose 1 arg will become the 1-st arg of hyp creation command
1448     // i.e. convertion result will be "locallength = regular1d.LocalLength(<arg of SetLength()>)"
1449     hyp->AddArgMethod( "SetLength" );
1450   }
1451   else if ( hypType == "MaxLength" ) {
1452     // set algo's method creating hyp, and algo type
1453     hyp->SetConvMethodAndType( "MaxSize", "Regular_1D");
1454     // set method whose 1 arg will become the 1-st arg of hyp creation command
1455     // i.e. convertion result will be "maxsize = regular1d.MaxSize(<arg of SetLength()>)"
1456     hyp->AddArgMethod( "SetLength" );
1457   }
1458   else if ( hypType == "NumberOfSegments" ) {
1459     hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
1460     hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
1461     // arg of SetNumberOfSegments() will become the 1-st arg of hyp creation command
1462     hyp->AddArgMethod( "SetNumberOfSegments" );
1463     // arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
1464     hyp->AddArgMethod( "SetScaleFactor" );
1465     hyp->AddArgMethod( "SetReversedEdges" );
1466   }
1467   else if ( hypType == "Arithmetic1D" ) {
1468     hyp = new _pyComplexParamHypo( theCreationCmd );
1469     hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
1470     hyp->AddArgMethod( "SetStartLength" );
1471     hyp->AddArgMethod( "SetEndLength" );
1472     hyp->AddArgMethod( "SetReversedEdges" );
1473   }
1474   else if ( hypType == "StartEndLength" ) {
1475     hyp = new _pyComplexParamHypo( theCreationCmd );
1476     hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
1477     hyp->AddArgMethod( "SetStartLength" );
1478     hyp->AddArgMethod( "SetEndLength" );
1479     hyp->AddArgMethod( "SetReversedEdges" );
1480   }
1481   else if ( hypType == "Deflection1D" ) {
1482     hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
1483     hyp->AddArgMethod( "SetDeflection" );
1484   }
1485   else if ( hypType == "Propagation" ) {
1486     hyp->SetConvMethodAndType( "Propagation", "Regular_1D");
1487   }
1488   else if ( hypType == "QuadraticMesh" ) {
1489     hyp->SetConvMethodAndType( "QuadraticMesh", "Regular_1D");
1490   }
1491   else if ( hypType == "AutomaticLength" ) {
1492     hyp->SetConvMethodAndType( "AutomaticLength", "Regular_1D");
1493     hyp->AddArgMethod( "SetFineness");
1494   }
1495   else if ( hypType == "SegmentLengthAroundVertex" ) {
1496     hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
1497     hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
1498     hyp->AddArgMethod( "SetLength" );
1499   }
1500   // 1D Python_1D ----------
1501   else if ( hypType == "Python_1D" ) {
1502     algo->SetConvMethodAndType( "Segment", hypType.ToCString());
1503     algo->myArgs.Append( "algo=smesh.PYTHON");
1504   }
1505   else if ( hypType == "PythonSplit1D" ) {
1506     hyp->SetConvMethodAndType( "PythonSplit1D", "Python_1D");
1507     hyp->AddArgMethod( "SetNumberOfSegments");
1508     hyp->AddArgMethod( "SetPythonLog10RatioFunction");
1509   }
1510   // MEFISTO_2D ----------
1511   else if ( hypType == "MEFISTO_2D" ) { // MEFISTO_2D
1512     algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
1513   }
1514   else if ( hypType == "MaxElementArea" ) {
1515     hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
1516     hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
1517     hyp->AddArgMethod( "SetMaxElementArea");
1518   }
1519   else if ( hypType == "LengthFromEdges" ) {
1520     hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
1521     hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
1522   }
1523   // Quadrangle_2D ----------
1524   else if ( hypType == "Quadrangle_2D" ) {
1525     algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
1526   }
1527   else if ( hypType == "QuadranglePreference" ) {
1528     hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
1529     hyp->SetConvMethodAndType( "SetQuadAllowed", "NETGEN_2D_ONLY");
1530   }
1531   else if ( hypType == "TrianglePreference" ) {
1532     hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
1533   }
1534   // RadialQuadrangle_1D2D ----------
1535   else if ( hypType == "RadialQuadrangle_1D2D" ) {
1536     algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
1537     algo->myArgs.Append( "algo=smesh.RADIAL_QUAD" );
1538   }
1539   else if ( hypType == "NumberOfLayers2D" ) {
1540     hyp->SetConvMethodAndType( "NumberOfLayers", "RadialQuadrangle_1D2D");
1541     hyp->AddArgMethod( "SetNumberOfLayers" );
1542   }
1543   else if ( hypType == "LayerDistribution2D" ) {
1544     hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get2DHypothesis" );
1545     hyp->SetConvMethodAndType( "LayerDistribution", "RadialQuadrangle_1D2D");
1546   }
1547   // BLSURF ----------
1548   else if ( hypType == "BLSURF" ) {
1549     algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
1550     algo->myArgs.Append( "algo=smesh.BLSURF" );
1551   }
1552   else if ( hypType == "BLSURF_Parameters") {
1553     hyp->SetConvMethodAndType( "Parameters", "BLSURF");
1554   }
1555   // NETGEN ----------
1556   else if ( hypType == "NETGEN_2D") { // 1D-2D
1557     algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1558     algo->myArgs.Append( "algo=smesh.NETGEN" );
1559   }
1560   else if ( hypType == "NETGEN_Parameters_2D") {
1561     hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D");
1562   }
1563   else if ( hypType == "NETGEN_SimpleParameters_2D") {
1564     hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D");
1565     hyp->myArgs.Append( "which=smesh.SIMPLE" );
1566   }
1567   else if ( hypType == "NETGEN_2D3D") { // 1D-2D-3D
1568     algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
1569     algo->myArgs.Append( "algo=smesh.FULL_NETGEN" );
1570   }
1571   else if ( hypType == "NETGEN_Parameters") {
1572     hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D3D");
1573   }
1574   else if ( hypType == "NETGEN_SimpleParameters_3D") {
1575     hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D3D");
1576     hyp->myArgs.Append( "which=smesh.SIMPLE" );
1577   }
1578   else if ( hypType == "NETGEN_2D_ONLY") { // 2D
1579     algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1580     algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
1581   }
1582   else if ( hypType == "NETGEN_3D") { // 3D
1583     algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
1584     algo->myArgs.Append( "algo=smesh.NETGEN" );
1585   }
1586   else if ( hypType == "MaxElementVolume") {
1587     hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
1588     hyp->AddArgMethod( "SetMaxElementVolume" );
1589   }
1590   // GHS3D_3D ----------
1591   else if ( hypType == "GHS3D_3D" ) {
1592     algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
1593     algo->myArgs.Append( "algo=smesh.GHS3D" );
1594   }
1595   else if ( hypType == "GHS3D_Parameters") {
1596     hyp->SetConvMethodAndType( "Parameters", "GHS3D_3D");
1597   }
1598   // Hexa_3D ---------
1599   else if ( hypType == "BLSURF" ) {
1600     algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
1601   }
1602   // Repetitive Projection_1D ---------
1603   else if ( hypType == "Projection_1D" ) {
1604     algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
1605   }
1606   else if ( hypType == "ProjectionSource1D" ) {
1607     hyp->SetConvMethodAndType( "SourceEdge", "Projection_1D");
1608     hyp->AddArgMethod( "SetSourceEdge");
1609     hyp->AddArgMethod( "SetSourceMesh");
1610     // 2 args of SetVertexAssociation() will become the 3-th and 4-th args of hyp creation command
1611     hyp->AddArgMethod( "SetVertexAssociation", 2 );
1612   }
1613   // Projection_2D ---------
1614   else if ( hypType == "Projection_2D" ) {
1615     algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
1616   }
1617   else if ( hypType == "Projection_1D2D" ) {
1618     algo->SetConvMethodAndType( "Projection1D2D", hypType.ToCString());
1619   }
1620   else if ( hypType == "ProjectionSource2D" ) {
1621     hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
1622     hyp->AddArgMethod( "SetSourceFace");
1623     hyp->AddArgMethod( "SetSourceMesh");
1624     hyp->AddArgMethod( "SetVertexAssociation", 4 );
1625   }
1626   // Projection_3D ---------
1627   else if ( hypType == "Projection_3D" ) {
1628     algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
1629   }
1630   else if ( hypType == "ProjectionSource3D" ) {
1631     hyp->SetConvMethodAndType( "SourceShape3D", "Projection_3D");
1632     hyp->AddArgMethod( "SetSource3DShape");
1633     hyp->AddArgMethod( "SetSourceMesh");
1634     hyp->AddArgMethod( "SetVertexAssociation", 4 );
1635   }
1636   // Prism_3D ---------
1637   else if ( hypType == "Prism_3D" ) {
1638     algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1639   }
1640   // RadialPrism_3D ---------
1641   else if ( hypType == "RadialPrism_3D" ) {
1642     algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1643   }
1644   else if ( hypType == "NumberOfLayers" ) {
1645     hyp->SetConvMethodAndType( "NumberOfLayers", "RadialPrism_3D");
1646     hyp->AddArgMethod( "SetNumberOfLayers" );
1647   }
1648   else if ( hypType == "LayerDistribution" ) {
1649     hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get3DHypothesis" );
1650     hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
1651   }
1652
1653   return algo->IsValid() ? algo : hyp;
1654 }
1655
1656 //================================================================================
1657 /*!
1658  * \brief Convert the command adding a hypothesis to mesh into a smesh command
1659   * \param theCmd - The command like mesh.AddHypothesis( geom, hypo )
1660   * \param theAlgo - The algo that can create this hypo
1661   * \retval bool - false if the command cant be converted
1662  */
1663 //================================================================================
1664
1665 bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
1666                                        const _pyID&              theMesh)
1667 {
1668   ASSERT(( theCmd->GetMethod() == "AddHypothesis" ));
1669
1670   if ( !IsWrappable( theMesh ))
1671     return false;
1672
1673   myGeom = theCmd->GetArg( 1 );
1674
1675   Handle(_pyHypothesis) algo;
1676   if ( !IsAlgo() ) {
1677     // find algo created on myGeom in theMesh
1678     algo = theGen->FindAlgo( myGeom, theMesh, this );
1679     if ( algo.IsNull() )
1680       return false;
1681     // attach hypothesis creation command to be after algo creation command
1682     // because it can be new created instance of algorithm
1683     algo->GetCreationCmd()->AddDependantCmd( theCmd );
1684   }
1685   myIsWrapped = true;
1686
1687   // mesh.AddHypothesis(geom,hyp) --> hyp = <theMesh or algo>.myCreationMethod(args)
1688   theCmd->SetResultValue( GetID() );
1689   theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
1690   theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
1691   // set args
1692   theCmd->RemoveArgs();
1693   for ( int i = 1; i <= myArgs.Length(); ++i ) {
1694     if ( !myArgs( i ).IsEmpty() )
1695       theCmd->SetArg( i, myArgs( i ));
1696     else
1697       theCmd->SetArg( i, "[]");
1698   }
1699   // set a new creation command
1700   GetCreationCmd()->Clear();
1701   // replace creation command by wrapped instance
1702   // please note, that hypothesis attaches to algo creation command (see upper)
1703   SetCreationCmd( theCmd );
1704
1705
1706   // clear commands setting arg values
1707   list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
1708   for ( ; argCmd != myArgCommands.end(); ++argCmd )
1709     (*argCmd)->Clear();
1710
1711   // set unknown arg commands after hypo creation
1712   Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
1713   list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
1714   for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1715     afterCmd->AddDependantCmd( *cmd );
1716   }
1717
1718   return myIsWrapped;
1719 }
1720
1721 //================================================================================
1722 /*!
1723  * \brief Remember hypothesis parameter values
1724  * \param theCommand - The called hypothesis method
1725  */
1726 //================================================================================
1727
1728 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
1729 {
1730   ASSERT( !myIsAlgo );
1731   // set args
1732   int nbArgs = 0;
1733   for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
1734     if ( myArgMethods( i ) == theCommand->GetMethod() ) {
1735       while ( myArgs.Length() < nbArgs + myNbArgsByMethod( i ))
1736         myArgs.Append( "[]" );
1737       for ( int iArg = 1; iArg <= myNbArgsByMethod( i ); ++iArg )
1738         myArgs( nbArgs + iArg ) = theCommand->GetArg( iArg ); // arg value
1739       myArgCommands.push_back( theCommand );
1740       return;
1741     }
1742     nbArgs += myNbArgsByMethod( i );
1743   }
1744   myUnknownCommands.push_back( theCommand );
1745 }
1746
1747 //================================================================================
1748 /*!
1749  * \brief Finish conversion
1750  */
1751 //================================================================================
1752
1753 void _pyHypothesis::Flush()
1754 {
1755   if ( IsWrapped() ) {
1756   }
1757   else {
1758     list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
1759     for ( ; cmd != myArgCommands.end(); ++cmd ) {
1760       // Add access to a wrapped mesh
1761       theGen->AddMeshAccessorMethod( *cmd );
1762       // Add access to a wrapped algorithm
1763       theGen->AddAlgoAccessorMethod( *cmd );
1764     }
1765     cmd = myUnknownCommands.begin();
1766     for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1767       // Add access to a wrapped mesh
1768       theGen->AddMeshAccessorMethod( *cmd );
1769       // Add access to a wrapped algorithm
1770       theGen->AddAlgoAccessorMethod( *cmd );
1771     }
1772   }
1773   // forget previous hypothesis modifications
1774   myArgCommands.clear();
1775   myUnknownCommands.clear();
1776 }
1777
1778 //================================================================================
1779 /*!
1780  * \brief clear creation, arg and unkown commands
1781  */
1782 //================================================================================
1783
1784 void _pyHypothesis::ClearAllCommands()
1785 {
1786   GetCreationCmd()->Clear();
1787   list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
1788   for ( ; cmd != myArgCommands.end(); ++cmd )
1789     ( *cmd )->Clear();
1790   cmd = myUnknownCommands.begin();
1791   for ( ; cmd != myUnknownCommands.end(); ++cmd )
1792     ( *cmd )->Clear();
1793 }
1794
1795
1796 //================================================================================
1797 /*!
1798  * \brief Assign fields of theOther to me except myIsWrapped
1799  */
1800 //================================================================================
1801
1802 void _pyHypothesis::Assign( const Handle(_pyHypothesis)& theOther,
1803                             const _pyID&                 theMesh )
1804 {
1805   myIsWrapped = false;
1806   myMesh = theMesh;
1807
1808   // myCreationCmd = theOther->myCreationCmd;
1809   myIsAlgo = theOther->myIsAlgo;
1810   myGeom = theOther->myGeom;
1811   myType2CreationMethod = theOther->myType2CreationMethod;
1812   myArgs = theOther->myArgs;
1813   myArgMethods = theOther->myArgMethods;
1814   myNbArgsByMethod = theOther->myNbArgsByMethod;
1815   myArgCommands = theOther->myArgCommands;
1816   myUnknownCommands = theOther->myUnknownCommands;
1817 }
1818
1819 //================================================================================
1820 /*!
1821  * \brief Remember hypothesis parameter values
1822   * \param theCommand - The called hypothesis method
1823  */
1824 //================================================================================
1825
1826 void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
1827 {
1828   if( theCommand->GetMethod() == "SetLength" )
1829   {
1830     // NOW it becomes OBSOLETE
1831     // ex: hyp.SetLength(start, 1)
1832     //     hyp.SetLength(end,   0)
1833     ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
1834     int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
1835     while ( myArgs.Length() < i )
1836       myArgs.Append( "[]" );
1837     myArgs( i ) = theCommand->GetArg( 1 ); // arg value
1838     myArgCommands.push_back( theCommand );
1839   }
1840   else
1841   {
1842     _pyHypothesis::Process( theCommand );
1843   }
1844 }
1845 //================================================================================
1846 /*!
1847  * \brief Clear SetObjectEntry() as it is called by methods of Mesh_Segment
1848  */
1849 //================================================================================
1850
1851 void _pyComplexParamHypo::Flush()
1852 {
1853   if ( IsWrapped() )
1854   {
1855     list < Handle(_pyCommand) >::iterator cmd = myUnknownCommands.begin();
1856     for ( ; cmd != myUnknownCommands.end(); ++cmd )
1857       if ((*cmd)->GetMethod() == "SetObjectEntry" )
1858         (*cmd)->Clear();
1859   }
1860 }
1861
1862 //================================================================================
1863 /*!
1864  * \brief Convert methods of 1D hypotheses to my own methods
1865   * \param theCommand - The called hypothesis method
1866  */
1867 //================================================================================
1868
1869 void _pyLayerDistributionHypo::Process( const Handle(_pyCommand)& theCommand)
1870 {
1871   if ( theCommand->GetMethod() != "SetLayerDistribution" )
1872     return;
1873
1874   _pyID newName; // name for 1D hyp = "HypType" + "_Distribution"
1875
1876   const _pyID& hyp1dID = theCommand->GetArg( 1 );
1877   Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
1878   if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
1879     hyp1d = my1dHyp;
1880   else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() ) {
1881     // 1D hypo is already set, so distribution changes and the old
1882     // 1D hypo is thrown away
1883     my1dHyp->ClearAllCommands();
1884   }
1885   my1dHyp = hyp1d;
1886
1887   if ( !myArgCommands.empty() )
1888     myArgCommands.front()->Clear();
1889   myArgCommands.push_back( theCommand );
1890 }
1891
1892 //================================================================================
1893 /*!
1894  * \brief
1895   * \param theAdditionCmd - command to be converted
1896   * \param theMesh - mesh instance
1897   * \retval bool - status
1898  */
1899 //================================================================================
1900
1901 bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
1902                                                   const _pyID&              theMesh)
1903 {
1904   myIsWrapped = false;
1905
1906   if ( my1dHyp.IsNull() )
1907     return false;
1908
1909   // set "SetLayerDistribution()" after addition cmd
1910   theAdditionCmd->AddDependantCmd( myArgCommands.front() );
1911
1912   _pyID geom = theAdditionCmd->GetArg( 1 );
1913
1914   Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
1915   if ( !algo.IsNull() )
1916   {
1917     my1dHyp->SetMesh( theMesh );
1918     my1dHyp->SetConvMethodAndType(my1dHyp->GetAlgoCreationMethod().ToCString(),
1919                                   algo->GetAlgoType().ToCString());
1920     if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
1921       return false;
1922
1923     // clear "SetLayerDistribution()" cmd
1924     myArgCommands.back()->Clear();
1925
1926     // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
1927
1928     // find RadialPrism algo created on <geom> for theMesh
1929     GetCreationCmd()->SetObject( algo->GetID() );
1930     GetCreationCmd()->SetMethod( myAlgoMethod );
1931     GetCreationCmd()->RemoveArgs();
1932     theAdditionCmd->AddDependantCmd( GetCreationCmd() );
1933     myIsWrapped = true;
1934   }
1935   return myIsWrapped;
1936 }
1937
1938 //================================================================================
1939 /*!
1940  * \brief
1941  */
1942 //================================================================================
1943
1944 void _pyLayerDistributionHypo::Flush()
1945 {
1946   // as creation of 1D hyp was written later then it's edition,
1947   // we need to find all it's edition calls and process them
1948   if ( !my1dHyp.IsNull() )
1949   {
1950     _pyID hyp1dID = my1dHyp->GetCreationCmd()->GetResultValue();
1951
1952     // make a new name for 1D hyp = "HypType" + "_Distribution"
1953     _pyID newName;
1954     if ( my1dHyp->IsWrapped() ) {
1955       newName = my1dHyp->GetCreationCmd()->GetMethod();
1956     }
1957     else {
1958       TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
1959       newName = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
1960     }
1961     newName += "_Distribution";
1962     my1dHyp->GetCreationCmd()->SetResultValue( newName );
1963
1964     list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
1965     list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
1966     for ( ; cmdIt != cmds.end(); ++cmdIt ) {
1967       const _pyID& objID = (*cmdIt)->GetObject();
1968       if ( objID == hyp1dID ) {
1969         my1dHyp->Process( *cmdIt );
1970         my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
1971         ( *cmdIt )->SetObject( newName );
1972       }
1973     }
1974     // Set new hyp name to SetLayerDistribution() cmd
1975     if ( !myArgCommands.empty() && !myArgCommands.back()->IsEmpty() )
1976       myArgCommands.back()->SetArg( 1, newName );
1977   }
1978 }
1979
1980 //================================================================================
1981 /*!
1982  * \brief additionally to Addition2Creation, clears SetDistrType() command
1983   * \param theCmd - AddHypothesis() command
1984   * \param theMesh - mesh to which a hypothesis is added
1985   * \retval bool - convertion result
1986  */
1987 //================================================================================
1988
1989 bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1990                                                 const _pyID&              theMesh)
1991 {
1992   if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
1993     // scale factor (2-nd arg) is provided: clear SetDistrType(1) command
1994     bool scaleDistrType = false;
1995     list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1996     for ( ; cmd != myUnknownCommands.rend(); ++cmd ) {
1997       if ( (*cmd)->GetMethod() == "SetDistrType" ) {
1998         if ( (*cmd)->GetArg( 1 ) == "1" ) {
1999           scaleDistrType = true;
2000           (*cmd)->Clear();
2001         }
2002         else if ( !scaleDistrType ) {
2003           // distribution type changed: remove scale factor from args
2004           myArgs.Remove( 2, myArgs.Length() );
2005           break;
2006         }
2007       }
2008     }
2009   }
2010   return _pyHypothesis::Addition2Creation( theCmd, theMesh );
2011 }
2012
2013 //================================================================================
2014 /*!
2015  * \brief remove repeated commands defining distribution
2016  */
2017 //================================================================================
2018
2019 void _pyNumberOfSegmentsHyp::Flush()
2020 {
2021   // find number of the last SetDistrType() command
2022   list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
2023   int distrTypeNb = 0;
2024   for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
2025     if ( (*cmd)->GetMethod() == "SetDistrType" )
2026       distrTypeNb = (*cmd)->GetOrderNb();
2027     else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" )
2028       (*cmd)->Clear();
2029
2030   // clear commands before the last SetDistrType()
2031   list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
2032   for ( int i = 0; i < 2; ++i ) {
2033     set<TCollection_AsciiString> uniqueMethods;
2034     list<Handle(_pyCommand)> & cmdList = *cmds[i];
2035     for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
2036     {
2037       bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
2038       const TCollection_AsciiString& method = (*cmd)->GetMethod();
2039       if ( !clear || method == "SetNumberOfSegments" ) {
2040         bool isNewInSet = uniqueMethods.insert( method ).second;
2041         clear = !isNewInSet;
2042       }
2043       if ( clear )
2044         (*cmd)->Clear();
2045     }
2046     cmdList.clear();
2047   }
2048 }
2049
2050 //================================================================================
2051 /*!
2052  * \brief Convert the command adding "SegmentLengthAroundVertex" to mesh
2053  * into regular1D.LengthNearVertex( length, vertex )
2054   * \param theCmd - The command like mesh.AddHypothesis( vertex, SegmentLengthAroundVertex )
2055   * \param theMesh - The mesh needing this hypo
2056   * \retval bool - false if the command cant be converted
2057  */
2058 //================================================================================
2059
2060 bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
2061                                                          const _pyID&              theMeshID)
2062 {
2063   if ( IsWrappable( theMeshID )) {
2064
2065     _pyID vertex = theCmd->GetArg( 1 );
2066
2067     // the problem here is that segment algo will not be found
2068     // by pyHypothesis::Addition2Creation() for <vertex>, so we try to find
2069     // geometry where segment algorithm is assigned
2070     Handle(_pyHypothesis) algo;
2071     _pyID geom = vertex;
2072     while ( algo.IsNull() && !geom.IsEmpty()) {
2073       // try to find geom as a father of <vertex>
2074       geom = FatherID( geom );
2075       algo = theGen->FindAlgo( geom, theMeshID, this );
2076     }
2077     if ( algo.IsNull() )
2078       return false; // also possible to find geom as brother of veretex...
2079     // set geom instead of vertex
2080     theCmd->SetArg( 1, geom );
2081
2082     // set vertex as a second arg
2083     if ( myArgs.Length() < 1) myArgs.Append( "1" ); // :(
2084     myArgs.Append( vertex );
2085
2086     // mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) -->
2087     // theMeshID.LengthNearVertex( length, vertex )
2088     return _pyHypothesis::Addition2Creation( theCmd, theMeshID );
2089   }
2090   return false;
2091 }
2092
2093 //================================================================================
2094 /*!
2095  * \brief _pyAlgorithm constructor
2096  * \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)"
2097  */
2098 //================================================================================
2099
2100 _pyAlgorithm::_pyAlgorithm(const Handle(_pyCommand)& theCreationCmd)
2101   : _pyHypothesis( theCreationCmd )
2102 {
2103   myIsAlgo = true;
2104 }
2105
2106 //================================================================================
2107 /*!
2108  * \brief Convert the command adding an algorithm to mesh
2109   * \param theCmd - The command like mesh.AddHypothesis( geom, algo )
2110   * \param theMesh - The mesh needing this algo
2111   * \retval bool - false if the command cant be converted
2112  */
2113 //================================================================================
2114
2115 bool _pyAlgorithm::Addition2Creation( const Handle(_pyCommand)& theCmd,
2116                                       const _pyID&              theMeshID)
2117 {
2118   // mesh.AddHypothesis(geom,algo) --> theMeshID.myCreationMethod()
2119   if ( _pyHypothesis::Addition2Creation( theCmd, theMeshID )) {
2120     theGen->SetAccessorMethod( GetID(), "GetAlgorithm()" );
2121     return true;
2122   }
2123   return false;
2124 }
2125
2126 //================================================================================
2127 /*!
2128  * \brief Return starting position of a part of python command
2129   * \param thePartIndex - The index of command part
2130   * \retval int - Part position
2131  */
2132 //================================================================================
2133
2134 int _pyCommand::GetBegPos( int thePartIndex )
2135 {
2136   if ( IsEmpty() )
2137     return EMPTY;
2138   if ( myBegPos.Length() < thePartIndex )
2139     return UNKNOWN;
2140   return myBegPos( thePartIndex );
2141 }
2142
2143 //================================================================================
2144 /*!
2145  * \brief Store starting position of a part of python command
2146   * \param thePartIndex - The index of command part
2147   * \param thePosition - Part position
2148  */
2149 //================================================================================
2150
2151 void _pyCommand::SetBegPos( int thePartIndex, int thePosition )
2152 {
2153   while ( myBegPos.Length() < thePartIndex )
2154     myBegPos.Append( UNKNOWN );
2155   myBegPos( thePartIndex ) = thePosition;
2156 }
2157
2158 //================================================================================
2159 /*!
2160  * \brief Returns whitespace symbols at the line beginning
2161   * \retval TCollection_AsciiString - result
2162  */
2163 //================================================================================
2164
2165 TCollection_AsciiString _pyCommand::GetIndentation()
2166 {
2167   int end = 1;
2168   if ( GetBegPos( RESULT_IND ) == UNKNOWN )
2169     GetWord( myString, end, true );
2170   else
2171     end = GetBegPos( RESULT_IND );
2172   return myString.SubString( 1, end - 1 );
2173 }
2174
2175 //================================================================================
2176 /*!
2177  * \brief Return substring of python command looking like ResultValue = Obj.Meth()
2178   * \retval const TCollection_AsciiString & - ResultValue substring
2179  */
2180 //================================================================================
2181
2182 const TCollection_AsciiString & _pyCommand::GetResultValue()
2183 {
2184   if ( GetBegPos( RESULT_IND ) == UNKNOWN )
2185   {
2186     int begPos = myString.Location( "=", 1, Length() );
2187     if ( begPos )
2188       myRes = GetWord( myString, begPos, false );
2189     else
2190       begPos = EMPTY;
2191     SetBegPos( RESULT_IND, begPos );
2192   }
2193   return myRes;
2194 }
2195
2196 //================================================================================
2197 /*!
2198  * \brief Return number of python command result value ResultValue = Obj.Meth()
2199   * \retval const int
2200  */
2201 //================================================================================
2202
2203 const int _pyCommand::GetNbResultValues()
2204 {
2205   int begPos = 1;
2206   int Nb=0;
2207   int endPos = myString.Location( "=", 1, Length() );
2208   TCollection_AsciiString str = "";
2209   while ( begPos < endPos) {
2210     str = GetWord( myString, begPos, true );
2211     begPos = begPos+ str.Length();
2212     Nb++;
2213   }
2214   return (Nb-1);
2215 }
2216
2217
2218 //================================================================================
2219 /*!
2220  * \brief Return substring of python command looking like
2221  *  ResultValue1 , ResultValue1,... = Obj.Meth() with res index
2222  * \retval const TCollection_AsciiString & - ResultValue with res index substring
2223  */
2224 //================================================================================
2225 const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
2226 {
2227   int begPos = 1;
2228   int Nb=0;
2229   int endPos = myString.Location( "=", 1, Length() );
2230   while ( begPos < endPos) {
2231     myRes = GetWord( myString, begPos, true );
2232     begPos = begPos + myRes.Length();
2233     Nb++;
2234     if(res == Nb){
2235       myRes.RemoveAll('[');myRes.RemoveAll(']');
2236       return myRes;
2237     }
2238     if(Nb>res)
2239       break;
2240   }
2241   return theEmptyString;
2242 }
2243
2244 //================================================================================
2245 /*!
2246  * \brief Return substring of python command looking like ResVal = Object.Meth()
2247   * \retval const TCollection_AsciiString & - Object substring
2248  */
2249 //================================================================================
2250
2251 const TCollection_AsciiString & _pyCommand::GetObject()
2252 {
2253   if ( GetBegPos( OBJECT_IND ) == UNKNOWN )
2254   {
2255     // beginning
2256     int begPos = GetBegPos( RESULT_IND ) + myRes.Length();
2257     if ( begPos < 1 ) {
2258       begPos = myString.Location( "=", 1, Length() ) + 1;
2259       // is '=' in the string argument (for example, name) or not
2260       int nb1 = 0; // number of ' character at the left of =
2261       int nb2 = 0; // number of " character at the left of =
2262       for ( int i = 1; i < begPos-1; i++ ) {
2263         if ( myString.Value( i )=='\'' )
2264           nb1 += 1;
2265         else if ( myString.Value( i )=='"' )
2266           nb2 += 1;
2267       }
2268       // if number of ' or " is not divisible by 2,
2269       // then get an object at the start of the command
2270       if ( nb1 % 2 != 0 || nb2 % 2 != 0 )
2271         begPos = 1;
2272     }
2273     myObj = GetWord( myString, begPos, true );
2274     // check if object is complex,
2275     // so far consider case like "smesh.smesh.Method()"
2276     if ( int bracketPos = myString.Location( "(", begPos, Length() )) {
2277       //if ( bracketPos==0 ) bracketPos = Length();
2278       int dotPos = begPos+myObj.Length();
2279       while ( dotPos+1 < bracketPos ) {
2280         if ( int pos = myString.Location( ".", dotPos+1, bracketPos ))
2281           dotPos = pos;
2282         else
2283           break;
2284       }
2285       if ( dotPos > begPos+myObj.Length() )
2286         myObj = myString.SubString( begPos, dotPos-1 );
2287     }
2288     // store
2289     SetBegPos( OBJECT_IND, begPos );
2290   }
2291   //SCRUTE(myObj);
2292   return myObj;
2293 }
2294
2295 //================================================================================
2296 /*!
2297  * \brief Return substring of python command looking like ResVal = Obj.Method()
2298   * \retval const TCollection_AsciiString & - Method substring
2299  */
2300 //================================================================================
2301
2302 const TCollection_AsciiString & _pyCommand::GetMethod()
2303 {
2304   if ( GetBegPos( METHOD_IND ) == UNKNOWN )
2305   {
2306     // beginning
2307     int begPos = GetBegPos( OBJECT_IND ) + myObj.Length();
2308     bool forward = true;
2309     if ( begPos < 1 ) {
2310       begPos = myString.Location( "(", 1, Length() ) - 1;
2311       forward = false;
2312     }
2313     // store
2314     myMeth = GetWord( myString, begPos, forward );
2315     SetBegPos( METHOD_IND, begPos );
2316   }
2317   //SCRUTE(myMeth);
2318   return myMeth;
2319 }
2320
2321 //================================================================================
2322 /*!
2323  * \brief Return substring of python command looking like ResVal = Obj.Meth(Arg1,...)
2324   * \retval const TCollection_AsciiString & - Arg<index> substring
2325  */
2326 //================================================================================
2327
2328 const TCollection_AsciiString & _pyCommand::GetArg( int index )
2329 {
2330   if ( GetBegPos( ARG1_IND ) == UNKNOWN )
2331   {
2332     // Find all args
2333
2334     int pos = GetBegPos( METHOD_IND ) + myMeth.Length();
2335     if ( pos < 1 )
2336       pos = myString.Location( "(", 1, Length() );
2337     else
2338       --pos;
2339
2340     // we are at or before '(', skip it if present
2341     if ( pos > 0 ) {
2342       while ( pos <= Length() && myString.Value( pos ) != '(' ) ++pos;
2343       if ( myString.Value( pos ) != '(' )
2344         pos = 0;
2345     }
2346     if ( pos < 1 ) {
2347       SetBegPos( ARG1_IND, 0 ); // even no '('
2348       return theEmptyString;
2349     }
2350     ++pos;
2351
2352     list< TCollection_AsciiString > separatorStack( 1, ",)");
2353     bool ignoreNesting = false;
2354     int prevPos = pos;
2355     while ( pos <= Length() )
2356     {
2357       const char chr = myString.Value( pos );
2358
2359       if ( separatorStack.back().Location( chr, 1, separatorStack.back().Length()))
2360       {
2361         if ( separatorStack.size() == 1 ) // ',' dividing args or a terminal ')' found
2362         {
2363           while ( pos-1 >= prevPos && isspace( myString.Value( prevPos )))
2364             ++prevPos;
2365           if ( pos-1 >= prevPos ) {
2366             TCollection_AsciiString arg = myString.SubString( prevPos, pos-1 );
2367             arg.RightAdjust(); // remove spaces
2368             arg.LeftAdjust();
2369             SetBegPos( ARG1_IND + myArgs.Length(), prevPos );
2370             myArgs.Append( arg );
2371           }
2372           if ( chr == ')' )
2373             break;
2374           prevPos = pos+1;
2375         }
2376         else // end of nesting args found
2377         {
2378           separatorStack.pop_back();
2379           ignoreNesting = false;
2380         }
2381       }
2382       else if ( !ignoreNesting )
2383       {
2384         switch ( chr ) {
2385         case '(' : separatorStack.push_back(")"); break;
2386         case '[' : separatorStack.push_back("]"); break;
2387         case '\'': separatorStack.push_back("'");  ignoreNesting=true; break;
2388         case '"' : separatorStack.push_back("\""); ignoreNesting=true; break;
2389         default:;
2390         }
2391       }
2392       ++pos;
2393     }
2394   }
2395   if ( myArgs.Length() < index )
2396     return theEmptyString;
2397   return myArgs( index );
2398 }
2399
2400 //================================================================================
2401 /*!
2402  * \brief Check if char is a word part
2403   * \param c - The character to check
2404   * \retval bool - The check result
2405  */
2406 //================================================================================
2407
2408 static inline bool isWord(const char c, const bool dotIsWord)
2409 {
2410   return
2411     !isspace(c) && c != ',' && c != '=' && c != ')' && c != '(' && ( dotIsWord || c != '.');
2412 }
2413
2414 //================================================================================
2415 /*!
2416  * \brief Looks for a word in the string and returns word's beginning
2417   * \param theString - The input string
2418   * \param theStartPos - The position to start the search, returning word's beginning
2419   * \param theForward - The search direction
2420   * \retval TCollection_AsciiString - The found word
2421  */
2422 //================================================================================
2423
2424 TCollection_AsciiString _pyCommand::GetWord( const TCollection_AsciiString & theString,
2425                                             int &      theStartPos,
2426                                             const bool theForward,
2427                                             const bool dotIsWord )
2428 {
2429   int beg = theStartPos, end = theStartPos;
2430   theStartPos = EMPTY;
2431   if ( beg < 1 || beg > theString.Length() )
2432     return theEmptyString;
2433
2434   if ( theForward ) { // search forward
2435     // beg
2436     while ( beg <= theString.Length() && !isWord( theString.Value( beg ), dotIsWord))
2437       ++beg;
2438     if ( beg > theString.Length() )
2439       return theEmptyString; // no word found
2440     // end
2441     end = beg + 1;
2442     char begChar = theString.Value( beg );
2443     if ( begChar == '"' || begChar == '\'' || begChar == '[') {
2444       char endChar = ( begChar == '[' ) ? ']' : begChar;
2445       // end is at the corresponding quoting mark or bracket
2446       while ( end < theString.Length() &&
2447               ( theString.Value( end ) != endChar || theString.Value( end-1 ) == '\\'))
2448         ++end;
2449     }
2450     else {
2451       while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
2452         ++end;
2453       --end;
2454     }
2455   }
2456   else {  // search backward
2457     // end
2458     while ( end > 0 && !isWord( theString.Value( end ), dotIsWord))
2459       --end;
2460     if ( end == 0 )
2461       return theEmptyString; // no word found
2462     beg = end - 1;
2463     char endChar = theString.Value( end );
2464     if ( endChar == '"' || endChar == '\'' ) {
2465       // beg is at the corresponding quoting mark
2466       while ( beg > 1 &&
2467               ( theString.Value( beg ) != endChar || theString.Value( beg-1 ) == '\\'))
2468         --beg;
2469     }
2470     else {
2471       while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
2472         --beg;
2473       ++beg;
2474     }
2475   }
2476   theStartPos = beg;
2477   //cout << theString << " ---- " << beg << " - " << end << endl;
2478   return theString.SubString( beg, end );
2479 }
2480
2481 //================================================================================
2482 /*!
2483  * \brief Look for position where not space char is
2484   * \param theString - The string
2485   * \param thePos - The position to search from and which returns result
2486   * \retval bool - false if there are only space after thePos in theString
2487  *
2488  *
2489  */
2490 //================================================================================
2491
2492 bool _pyCommand::SkipSpaces( const TCollection_AsciiString & theString, int & thePos )
2493 {
2494   if ( thePos < 1 || thePos > theString.Length() )
2495     return false;
2496
2497   while ( thePos <= theString.Length() && isspace( theString.Value( thePos )))
2498     ++thePos;
2499
2500   return thePos <= theString.Length();
2501 }
2502
2503 //================================================================================
2504 /*!
2505  * \brief Modify a part of the command
2506   * \param thePartIndex - The index of the part
2507   * \param thePart - The new part string
2508   * \param theOldPart - The old part
2509  */
2510 //================================================================================
2511
2512 void _pyCommand::SetPart(int thePartIndex, const TCollection_AsciiString& thePart,
2513                         TCollection_AsciiString& theOldPart)
2514 {
2515   int pos = GetBegPos( thePartIndex );
2516   if ( pos <= Length() && theOldPart != thePart)
2517   {
2518     TCollection_AsciiString seperator;
2519     if ( pos < 1 ) {
2520       pos = GetBegPos( thePartIndex + 1 );
2521       if ( pos < 1 ) return;
2522       switch ( thePartIndex ) {
2523       case RESULT_IND: seperator = " = "; break;
2524       case OBJECT_IND: seperator = "."; break;
2525       case METHOD_IND: seperator = "()"; break;
2526       default:;
2527       }
2528     }
2529     myString.Remove( pos, theOldPart.Length() );
2530     if ( !seperator.IsEmpty() )
2531       myString.Insert( pos , seperator );
2532     myString.Insert( pos, thePart );
2533     // update starting positions of the following parts
2534     int posDelta = thePart.Length() + seperator.Length() - theOldPart.Length();
2535     for ( int i = thePartIndex + 1; i <= myBegPos.Length(); ++i ) {
2536       if ( myBegPos( i ) > 0 )
2537         myBegPos( i ) += posDelta;
2538     }
2539     theOldPart = thePart;
2540   }
2541 }
2542
2543 //================================================================================
2544 /*!
2545  * \brief Set agrument
2546   * \param index - The argument index, it counts from 1
2547   * \param theArg - The argument string
2548  */
2549 //================================================================================
2550
2551 void _pyCommand::SetArg( int index, const TCollection_AsciiString& theArg)
2552 {
2553   FindAllArgs();
2554   int argInd = ARG1_IND + index - 1;
2555   int pos = GetBegPos( argInd );
2556   if ( pos < 1 ) // no index-th arg exist, append inexistent args
2557   {
2558     // find a closing parenthesis
2559     if ( GetNbArgs() != 0 && index <= GetNbArgs() ) {
2560       int lastArgInd = GetNbArgs();
2561       pos = GetBegPos( ARG1_IND + lastArgInd  - 1 ) + GetArg( lastArgInd ).Length();
2562       while ( pos > 0 && pos <= Length() && myString.Value( pos ) != ')' )
2563         ++pos;
2564     }
2565     else {
2566       pos = Length();
2567       while ( pos > 0 && myString.Value( pos ) != ')' )
2568         --pos;
2569     }
2570     if ( pos < 1 || myString.Value( pos ) != ')' ) { // no parentheses at all
2571       myString += "()";
2572       pos = Length();
2573     }
2574     while ( myArgs.Length() < index ) {
2575       if ( myArgs.Length() )
2576         myString.Insert( pos++, "," );
2577       myArgs.Append("None");
2578       myString.Insert( pos, myArgs.Last() );
2579       SetBegPos( ARG1_IND + myArgs.Length() - 1, pos );
2580       pos += myArgs.Last().Length();
2581     }
2582   }
2583   SetPart( argInd, theArg, myArgs( index ));
2584 }
2585
2586 //================================================================================
2587 /*!
2588  * \brief Empty arg list
2589  */
2590 //================================================================================
2591
2592 void _pyCommand::RemoveArgs()
2593 {
2594   if ( int pos = myString.Location( '(', 1, Length() ))
2595     myString.Trunc( pos );
2596   myString += ")";
2597   myArgs.Clear();
2598   if ( myBegPos.Length() >= ARG1_IND )
2599     myBegPos.Remove( ARG1_IND, myBegPos.Length() );
2600 }
2601
2602 //================================================================================
2603 /*!
2604  * \brief Set dependent commands after this one
2605  */
2606 //================================================================================
2607
2608 bool _pyCommand::SetDependentCmdsAfter() const
2609 {
2610   bool orderChanged = false;
2611   list< Handle(_pyCommand)>::const_reverse_iterator cmd = myDependentCmds.rbegin();
2612   for ( ; cmd != myDependentCmds.rend(); ++cmd ) {
2613     if ( (*cmd)->GetOrderNb() < GetOrderNb() ) {
2614       orderChanged = true;
2615       theGen->SetCommandAfter( *cmd, this );
2616       (*cmd)->SetDependentCmdsAfter();
2617     }
2618   }
2619   return orderChanged;
2620 }
2621 //================================================================================
2622 /*!
2623  * \brief Insert accessor method after theObjectID
2624   * \param theObjectID - id of the accessed object
2625   * \param theAcsMethod - name of the method giving access to the object
2626   * \retval bool - false if theObjectID is not found in the command string
2627  */
2628 //================================================================================
2629
2630 bool _pyCommand::AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod )
2631 {
2632   if ( !theAcsMethod )
2633     return false;
2634   // start object search from the object, i.e. ignore result
2635   GetObject();
2636   int beg = GetBegPos( OBJECT_IND );
2637   if ( beg < 1 || beg > Length() )
2638     return false;
2639   bool added = false;
2640   while (( beg = myString.Location( theObjectID, beg, Length() )))
2641   {
2642     // check that theObjectID is not just a part of a longer ID
2643     int afterEnd = beg + theObjectID.Length();
2644     Standard_Character c = myString.Value( afterEnd );
2645     if ( !isalnum( c ) && c != ':' ) {
2646       // check if accessor method already present
2647       if ( c != '.' ||
2648            myString.Location( (char*) theAcsMethod, afterEnd, Length() ) != afterEnd+1) {
2649         // insertion
2650         int oldLen = Length();
2651         myString.Insert( afterEnd, (char*) theAcsMethod );
2652         myString.Insert( afterEnd, "." );
2653         // update starting positions of the parts following the modified one
2654         int posDelta = Length() - oldLen;
2655         for ( int i = 1; i <= myBegPos.Length(); ++i ) {
2656           if ( myBegPos( i ) > afterEnd )
2657             myBegPos( i ) += posDelta;
2658         }
2659         added = true;
2660       }
2661     }
2662     beg = afterEnd; // is a part - next search
2663   }
2664   return added;
2665 }
2666
2667 //================================================================================
2668 /*!
2669  * \brief Return method name giving access to an interaface object wrapped by python class
2670   * \retval const char* - method name
2671  */
2672 //================================================================================
2673
2674 const char* _pyObject::AccessorMethod() const
2675 {
2676   return 0;
2677 }
2678 //================================================================================
2679 /*!
2680  * \brief Return ID of a father
2681  */
2682 //================================================================================
2683
2684 _pyID _pyObject::FatherID(const _pyID & childID)
2685 {
2686   int colPos = childID.SearchFromEnd(':');
2687   if ( colPos > 0 )
2688     return childID.SubString( 1, colPos-1 );
2689   return "";
2690 }
2691
2692 //================================================================================
2693 /*!
2694  * \brief SelfEraser erases creation command if no more it's commands invoked
2695  */
2696 //================================================================================
2697
2698 void _pySelfEraser::Flush()
2699 {
2700   if ( GetNbCalls() == 0 )
2701     GetCreationCmd()->Clear();
2702 }
2703
2704 //================================================================================
2705 /*!
2706  * \brief count invoked commands
2707  */
2708 //================================================================================
2709
2710 void _pySubMesh::Process( const Handle(_pyCommand)& theCommand )
2711 {
2712   _pyObject::Process(theCommand); // count calls of Process()
2713   GetCreationCmd()->AddDependantCmd( theCommand );
2714 }
2715
2716 //================================================================================
2717 /*!
2718  * \brief Clear creation command if no commands invoked
2719  */
2720 //================================================================================
2721
2722 void _pySubMesh::Flush()
2723 {
2724   if ( GetNbCalls() == 0 ) // move to the end of all commands
2725     theGen->GetLastCommand()->AddDependantCmd( GetCreationCmd() );
2726   else if ( !myCreator.IsNull() )
2727     // move to be just after creator
2728     myCreator->GetCreationCmd()->AddDependantCmd( GetCreationCmd() );
2729 }
2730
2731 //================================================================================
2732 /*!
2733  * \brief To convert creation of a group by filter
2734  */
2735 //================================================================================
2736
2737 void _pyGroup::Process( const Handle(_pyCommand)& theCommand)
2738 {
2739   // Convert the following set of commands into mesh.MakeGroupByFilter(groupName, theFilter)
2740   // group = mesh.CreateEmptyGroup( elemType, groupName )
2741   // aFilter.SetMesh(mesh)
2742   // nbAdd = group.AddFrom( aFilter )
2743   if ( theCommand->GetMethod() == "AddFrom" )
2744   {
2745     _pyID idSource = theCommand->GetArg(1);
2746     // check if idSource is a filter
2747     Handle(_pyObject) filter = theGen->FindObject( idSource );
2748     if ( filter.IsNull() || !filter->IsKind(STANDARD_TYPE(_pyFilter)))
2749       return;
2750     // find aFilter.SetMesh(mesh) to clear it, it should be just before theCommand
2751     list< Handle(_pyCommand) >::reverse_iterator cmdIt = theGen->GetCommands().rbegin();
2752     while ( *cmdIt != theCommand ) ++cmdIt;
2753     while ( (*cmdIt)->GetOrderNb() != 1 )
2754     {
2755       const Handle(_pyCommand)& setMeshCmd = *(++cmdIt);
2756       if ((setMeshCmd->GetObject() == idSource ||
2757            setMeshCmd->GetObject() == Handle(_pyFilter)::DownCast(filter)->GetNewID() )
2758           &&
2759           setMeshCmd->GetMethod() == "SetMesh")
2760       {
2761         setMeshCmd->Clear();
2762         break;
2763       }
2764     }
2765     // replace 3 commands by one
2766     theCommand->Clear();
2767     const Handle(_pyCommand)& makeGroupCmd = GetCreationCmd();
2768     TCollection_AsciiString name = makeGroupCmd->GetArg( 2 );
2769     makeGroupCmd->SetMethod( "MakeGroupByFilter" );
2770     makeGroupCmd->SetArg( 1, name );
2771     makeGroupCmd->SetArg( 2, idSource );
2772     // set new name of a filter
2773     filter->Process( makeGroupCmd );
2774   }
2775 }
2776
2777 //================================================================================
2778 /*!
2779  * \brief Constructor of _pyFilter
2780  */
2781 //================================================================================
2782
2783 _pyFilter::_pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID/*=""*/)
2784   :_pyObject(theCreationCmd), myNewID( newID )
2785 {
2786 }
2787
2788 //================================================================================
2789 /*!
2790  * \brief To convert creation of a filter by criteria and
2791  * to replace an old name by a new one
2792  */
2793 //================================================================================
2794
2795 void _pyFilter::Process( const Handle(_pyCommand)& theCommand)
2796 {
2797   if ( theCommand->GetObject() == GetID() )
2798     _pyObject::Process(theCommand); // count commands
2799
2800   if ( !myNewID.IsEmpty() )
2801   {
2802     if ( theCommand->GetObject() == GetID() )
2803       theCommand->SetObject( myNewID );
2804     else if ( theCommand->GetResultValue() == GetID() )
2805       theCommand->SetResultValue( myNewID );
2806     else
2807       for ( int i = 1, nb = theCommand->GetNbArgs(); i <= nb; ++i )
2808         if ( theCommand->GetArg( i ) == GetID() )
2809         {
2810           theCommand->SetArg( i, myNewID );
2811           break;
2812         }
2813   }
2814
2815   // Convert the following set of commands into smesh.GetFilterFromCriteria(criteria)
2816   // aFilter0x2aaab0487080 = aFilterManager.CreateFilter()
2817   // aFilter0x2aaab0487080.SetCriteria(aCriteria)
2818   if ( GetNbCalls() == 0 && // none method was called before SetCriteria()
2819        theCommand->GetMethod() == "SetCriteria")
2820   {
2821     // aFilter.SetCriteria(aCriteria) ->
2822     // aFilter = smesh.GetFilterFromCriteria(criteria)
2823     if ( myNewID.IsEmpty() )
2824       theCommand->SetResultValue( GetID() );
2825     else
2826       theCommand->SetResultValue( myNewID );
2827     theCommand->SetObject( SMESH_2smeshpy::GenName() );
2828     theCommand->SetMethod( "GetFilterFromCriteria" );
2829
2830     // Clear aFilterManager.CreateFilter()
2831     GetCreationCmd()->Clear();
2832   }
2833   else if ( theCommand->GetMethod() == "SetMesh")
2834   {
2835     theGen->AddMeshAccessorMethod( theCommand );
2836   }
2837 }
2838
2839 //================================================================================
2840 /*!
2841  * \brief Set new filter name to the creation command
2842  */
2843 //================================================================================
2844
2845 void _pyFilter::Flush()
2846 {
2847   if ( !myNewID.IsEmpty() && !GetCreationCmd()->IsEmpty() )
2848     GetCreationCmd()->SetResultValue( myNewID );
2849 }