1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_2smeshpy.cxx
24 // Created : Fri Nov 18 13:20:10 2005
25 // Author : Edward AGAPOV (eap)
27 #include "SMESH_2smeshpy.hxx"
29 #include "SMESH_PythonDump.hxx"
30 #include "SMESH_NoteBook.hxx"
31 #include "SMESH_Filter_i.hxx"
33 #include <SALOMEDS_wrap.hxx>
34 #include <utilities.h>
36 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
37 #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
39 #include "SMESH_Gen_i.hxx"
40 /* SALOME headers that include CORBA headers that include windows.h
41 * that defines GetObject symbol as GetObjectA should stand before SALOME headers
42 * that declare methods named GetObject - to apply the same rules of GetObject renaming
43 * and thus to avoid mess with GetObject symbol on Windows */
45 #include <LDOMParser.hxx>
54 IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient);
55 IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
56 IMPLEMENT_STANDARD_HANDLE (_pyHypothesisReader,Standard_Transient);
57 IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject);
58 IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject);
59 IMPLEMENT_STANDARD_HANDLE (_pySubMesh ,_pyObject);
60 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor ,_pyObject);
61 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis ,_pyObject);
62 IMPLEMENT_STANDARD_HANDLE (_pySelfEraser ,_pyObject);
63 IMPLEMENT_STANDARD_HANDLE (_pyGroup ,_pyObject);
64 IMPLEMENT_STANDARD_HANDLE (_pyFilter ,_pyObject);
65 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
66 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
67 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis);
69 IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient);
70 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient);
71 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesisReader,Standard_Transient);
72 IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject);
73 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject);
74 IMPLEMENT_STANDARD_RTTIEXT(_pySubMesh ,_pyObject);
75 IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject);
76 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject);
77 IMPLEMENT_STANDARD_RTTIEXT(_pySelfEraser ,_pyObject);
78 IMPLEMENT_STANDARD_RTTIEXT(_pyGroup ,_pyObject);
79 IMPLEMENT_STANDARD_RTTIEXT(_pyFilter ,_pyObject);
80 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis);
81 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
82 IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis);
83 IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis);
84 IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis);
87 using SMESH::TPythonDump;
90 * \brief Container of commands into which the initial script is split.
91 * It also contains data coresponding to SMESH_Gen contents
93 static Handle(_pyGen) theGen;
95 static TCollection_AsciiString theEmptyString;
97 //#define DUMP_CONVERSION
99 #if !defined(_DEBUG_) && defined(DUMP_CONVERSION)
100 #undef DUMP_CONVERSION
106 //================================================================================
108 * \brief Set of TCollection_AsciiString initialized by C array of C strings
110 //================================================================================
112 struct TStringSet: public set<TCollection_AsciiString>
115 * \brief Filling. The last string must be ""
117 void Insert(const char* names[]) {
118 for ( int i = 0; names[i][0] ; ++i )
119 insert( (char*) names[i] );
122 * \brief Check if a string is in
124 bool Contains(const TCollection_AsciiString& name ) {
125 return find( name ) != end();
129 //================================================================================
131 * \brief Map of TCollection_AsciiString initialized by C array of C strings.
132 * Odd items of the C array are map keys, and even items are values
134 //================================================================================
136 struct TStringMap: public map<TCollection_AsciiString,TCollection_AsciiString>
139 * \brief Filling. The last string must be ""
141 void Insert(const char* names_values[]) {
142 for ( int i = 0; names_values[i][0] ; i += 2 )
143 insert( make_pair( (char*) names_values[i], names_values[i+1] ));
146 * \brief Check if a string is in
148 TCollection_AsciiString Value(const TCollection_AsciiString& name ) {
149 map< _AString, _AString >::iterator it = find( name );
150 return it == end() ? "" : it->second;
154 //================================================================================
156 * \brief Returns a mesh by object
158 //================================================================================
160 Handle(_pyMesh) ObjectToMesh( const Handle( _pyObject )& obj )
164 if ( obj->IsKind( STANDARD_TYPE( _pyMesh )))
165 return Handle(_pyMesh)::DownCast( obj );
166 else if ( obj->IsKind( STANDARD_TYPE( _pySubMesh )))
167 return Handle(_pySubMesh)::DownCast( obj )->GetMesh();
168 else if ( obj->IsKind( STANDARD_TYPE( _pyGroup )))
169 return Handle(_pyGroup)::DownCast( obj )->GetMesh();
171 return Handle(_pyMesh)();
174 //================================================================================
176 * \brief Check if objects used as args have been created by previous commands
178 //================================================================================
180 void CheckObjectPresence( const Handle(_pyCommand)& cmd, set<_pyID> & presentObjects)
182 // either comment or erase a command including NotPublishedObjectName()
183 if ( cmd->GetString().Location( TPythonDump::NotPublishedObjectName(), 1, cmd->Length() ))
185 bool isResultPublished = false;
186 for ( int i = 0; i < cmd->GetNbResultValues(); i++ )
188 _pyID objID = cmd->GetResultValue( i+1 );
189 if ( cmd->IsStudyEntry( objID ))
190 isResultPublished = (! theGen->IsNotPublished( objID ));
191 theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
193 if ( isResultPublished )
199 // comment a command having not created args
200 for ( int iArg = cmd->GetNbArgs(); iArg; --iArg )
202 const _pyID& arg = cmd->GetArg( iArg );
203 if ( arg.IsEmpty() || arg.Value( 1 ) == '"' || arg.Value( 1 ) == '\'' )
205 list< _pyID > idList = cmd->GetStudyEntries( arg );
206 list< _pyID >::iterator id = idList.begin();
207 for ( ; id != idList.end(); ++id )
208 if ( !theGen->IsGeomObject( *id ) && !presentObjects.count( *id ))
211 cmd->GetString() += " ### " ;
212 cmd->GetString() += *id + " has not been yet created";
213 for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {
214 _pyID objID = cmd->GetResultValue( i+1 );
215 theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
220 // comment a command having not created Object
221 const _pyID& obj = cmd->GetObject();
222 if ( !obj.IsEmpty() && cmd->IsStudyEntry( obj ) && !presentObjects.count( obj ))
225 cmd->GetString() += " ### not created object" ;
226 for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {
227 _pyID objID = cmd->GetResultValue( i+1 );
228 theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
231 const _pyID& result = cmd->GetResultValue();
232 if ( result.IsEmpty() || result.Value( 1 ) == '"' || result.Value( 1 ) == '\'' )
234 list< _pyID > idList = cmd->GetStudyEntries( result );
235 list< _pyID >::iterator id = idList.begin();
236 for ( ; id != idList.end(); ++id )
237 presentObjects.insert( *id );
240 //================================================================================
242 * \brief Fix SMESH::FunctorType arguments of SMESH::Filter::Criterion()
244 //================================================================================
246 void fixFunctorType( TCollection_AsciiString& Type,
247 TCollection_AsciiString& Compare,
248 TCollection_AsciiString& UnaryOp,
249 TCollection_AsciiString& BinaryOp )
251 // The problem is that dumps of old studies created using filters becomes invalid
252 // when new items are inserted in the enum SMESH::FunctorType since values
253 // of this enum are dumped as integer values.
254 // This function corrects enum values of old studies given as args (Type,Compare,...)
255 // We can find out how to correct them by value of BinaryOp which can have only two
256 // values: FT_Undefined or FT_LogicalNOT.
257 // Hereafter is the history of the enum SMESH::FunctorType since v3.0.0
258 // where PythonDump appeared
259 // v 3.0.0: FT_Undefined == 25
260 // v 3.1.0: FT_Undefined == 26, new items:
262 // v 4.1.2: FT_Undefined == 27, new items:
263 // - FT_BelongToGenSurface = 17
264 // v 5.1.1: FT_Undefined == 32, new items:
265 // - FT_FreeNodes = 10
266 // - FT_FreeFaces = 11
267 // - FT_LinearOrQuadratic = 23
268 // - FT_GroupColor = 24
269 // - FT_ElemGeomType = 25
270 // v 5.1.5: FT_Undefined == 33, new items:
271 // - FT_CoplanarFaces = 26
272 // v 6.2.0: FT_Undefined == 39, new items:
273 // - FT_MaxElementLength2D = 8
274 // - FT_MaxElementLength3D = 9
275 // - FT_BareBorderVolume = 25
276 // - FT_BareBorderFace = 26
277 // - FT_OverConstrainedVolume = 27
278 // - FT_OverConstrainedFace = 28
279 // v 6.5.0: FT_Undefined == 43, new items:
280 // - FT_EqualNodes = 14
281 // - FT_EqualEdges = 15
282 // - FT_EqualFaces = 16
283 // - FT_EqualVolumes = 17
284 // v 6.6.0: FT_Undefined == 44, new items:
285 // - FT_BallDiameter = 37
286 // v 6.7.1: FT_Undefined == 45, new items:
287 // - FT_EntityType = 36
289 // It's necessary to continue recording this history and to fill
290 // undef2newItems (see below) accordingly.
292 typedef map< int, vector< int > > TUndef2newItems;
293 static TUndef2newItems undef2newItems;
294 if ( undef2newItems.empty() )
296 undef2newItems[ 26 ].push_back( 7 );
297 undef2newItems[ 27 ].push_back( 17 );
298 { int items[] = { 10, 11, 23, 24, 25 };
299 undef2newItems[ 32 ].assign( items, items+5 ); }
300 undef2newItems[ 33 ].push_back( 26 );
301 { int items[] = { 8, 9, 25, 26, 27, 28 };
302 undef2newItems[ 39 ].assign( items, items+6 ); }
303 { int items[] = { 14, 15, 16, 17 };
304 undef2newItems[ 43 ].assign( items, items+4 ); }
305 { int items[] = { 37 };
306 undef2newItems[ 44 ].assign( items, items+1 ); }
307 { int items[] = { 36 };
308 undef2newItems[ 45 ].assign( items, items+1 ); }
311 int iType = Type.IntegerValue();
312 int iCompare = Compare.IntegerValue();
313 int iUnaryOp = UnaryOp.IntegerValue();
314 int iBinaryOp = BinaryOp.IntegerValue();
316 // find out integer value of FT_Undefined at the moment of dump
317 int oldUndefined = iBinaryOp;
318 if ( iBinaryOp < iUnaryOp ) // BinaryOp was FT_LogicalNOT
321 // apply history to args
322 TUndef2newItems::const_iterator undef_items =
323 undef2newItems.upper_bound( oldUndefined );
324 if ( undef_items != undef2newItems.end() )
326 int* pArg[4] = { &iType, &iCompare, &iUnaryOp, &iBinaryOp };
327 for ( ; undef_items != undef2newItems.end(); ++undef_items )
329 const vector< int > & addedItems = undef_items->second;
330 for ( size_t i = 0; i < addedItems.size(); ++i )
331 for ( int iArg = 0; iArg < 4; ++iArg )
333 int& arg = *pArg[iArg];
334 if ( arg >= addedItems[i] )
338 Type = TCollection_AsciiString( iType );
339 Compare = TCollection_AsciiString( iCompare );
340 UnaryOp = TCollection_AsciiString( iUnaryOp );
341 BinaryOp = TCollection_AsciiString( iBinaryOp );
346 //================================================================================
348 * \brief Convert a python script using commands of smeshBuilder.py
349 * \param theScript - Input script
350 * \param theEntry2AccessorMethod - returns method names to access to
351 * objects wrapped with python class
352 * \param theObjectNames - names of objects
353 * \param theRemovedObjIDs - entries of objects whose created commands were removed
354 * \param theHistoricalDump - true means to keep all commands, false means
355 * to exclude commands relating to objects removed from study
356 * \retval TCollection_AsciiString - Convertion result
358 //================================================================================
360 TCollection_AsciiString
361 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
362 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
363 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
364 std::set< TCollection_AsciiString >& theRemovedObjIDs,
365 SALOMEDS::Study_ptr& theStudy,
366 const bool theToKeepAllCommands)
368 theGen = new _pyGen( theEntry2AccessorMethod,
372 theToKeepAllCommands );
374 // split theScript into separate commands
376 SMESH_NoteBook * aNoteBook = new SMESH_NoteBook();
378 int from = 1, end = theScript.Length(), to;
379 while ( from < end && ( to = theScript.Location( "\n", from, end )))
382 // cut out and store a command
383 aNoteBook->AddCommand( theScript.SubString( from, to - 1 ));
387 aNoteBook->ReplaceVariables();
389 TCollection_AsciiString aNoteScript = aNoteBook->GetResultScript();
393 // split theScript into separate commands
394 from = 1, end = aNoteScript.Length();
395 while ( from < end && ( to = aNoteScript.Location( "\n", from, end )))
398 // cut out and store a command
399 theGen->AddCommand( aNoteScript.SubString( from, to - 1 ));
405 #ifdef DUMP_CONVERSION
406 MESSAGE_BEGIN ( std::endl << " ######## RESULT ######## " << std::endl<< std::endl );
409 // clean commmands of removed objects depending on myIsPublished flag
410 theGen->ClearCommands();
412 // reorder commands after conversion
413 list< Handle(_pyCommand) >::iterator cmd;
416 orderChanges = false;
417 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
418 if ( (*cmd)->SetDependentCmdsAfter() )
420 } while ( orderChanges );
422 // concat commands back into a script
423 TCollection_AsciiString aScript, aPrevCmd;
424 set<_pyID> createdObjects;
425 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
427 #ifdef DUMP_CONVERSION
428 MESSAGE_ADD ( "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << std::endl );
430 if ( !(*cmd)->IsEmpty() && aPrevCmd != (*cmd)->GetString()) {
431 CheckObjectPresence( *cmd, createdObjects );
432 aPrevCmd = (*cmd)->GetString();
445 //================================================================================
447 * \brief _pyGen constructor
449 //================================================================================
451 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
452 Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
453 std::set< TCollection_AsciiString >& theRemovedObjIDs,
454 SALOMEDS::Study_ptr& theStudy,
455 const bool theToKeepAllCommands)
456 : _pyObject( new _pyCommand( "", 0 )),
458 myID2AccessorMethod( theEntry2AccessorMethod ),
459 myObjectNames( theObjectNames ),
460 myRemovedObjIDs( theRemovedObjIDs ),
462 myToKeepAllCommands( theToKeepAllCommands ),
463 myStudy( SALOMEDS::Study::_duplicate( theStudy )),
464 myGeomIDNb(0), myGeomIDIndex(-1)
466 // make that GetID() to return TPythonDump::SMESHGenName()
467 GetCreationCmd()->Clear();
468 GetCreationCmd()->GetString() = TPythonDump::SMESHGenName();
469 GetCreationCmd()->GetString() += "=";
471 // Find 1st digit of study entry by which a GEOM object differs from a SMESH object
472 if ( !theObjectNames.IsEmpty() && !CORBA::is_nil( theStudy ))
476 SALOMEDS::SComponent_wrap geomComp = theStudy->FindComponent("GEOM");
477 if ( geomComp->_is_nil() ) return;
478 CORBA::String_var entry = geomComp->GetID();
481 // find a SMESH entry
483 Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString e2n( theObjectNames );
484 for ( ; e2n.More() && smeshID.IsEmpty(); e2n.Next() )
485 if ( _pyCommand::IsStudyEntry( e2n.Key() ))
488 // find 1st difference between smeshID and geomID
489 if ( !geomID.IsEmpty() && !smeshID.IsEmpty() )
490 for ( int i = 1; i <= geomID.Length() && i <= smeshID.Length(); ++i )
491 if ( geomID.Value( i ) != smeshID.Value( i ))
493 myGeomIDNb = geomID.Value( i );
499 //================================================================================
501 * \brief name of SMESH_Gen in smeshBuilder.py
503 //================================================================================
505 const char* _pyGen::AccessorMethod() const
507 return SMESH_2smeshpy::GenName();
510 //================================================================================
512 * \brief Convert a command using a specific converter
513 * \param theCommand - the command to convert
515 //================================================================================
517 Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
519 // store theCommand in the sequence
520 myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
522 Handle(_pyCommand) aCommand = myCommands.back();
523 #ifdef DUMP_CONVERSION
524 MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
527 const _pyID& objID = aCommand->GetObject();
529 if ( objID.IsEmpty() )
532 // Prevent moving a command creating a sub-mesh to the end of the script
533 // if the sub-mesh is used in theCommand as argument
534 if ( _pySubMesh::CanBeArgOfMethod( aCommand->GetMethod() ))
536 PlaceSubmeshAfterItsCreation( aCommand );
539 // Find an object to process theCommand
542 if ( objID == this->GetID() || objID == SMESH_2smeshpy::GenName())
544 this->Process( aCommand );
548 // SMESH_Mesh method?
549 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
550 if ( id_mesh != myMeshes.end() )
552 //id_mesh->second->AddProcessedCmd( aCommand );
554 // check for mesh editor object
555 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
556 _pyID editorID = aCommand->GetResultValue();
557 Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
558 myMeshEditors.insert( make_pair( editorID, editor ));
561 // check for SubMesh objects
562 else if ( aCommand->GetMethod() == "GetSubMesh" ) { // SubMesh creation
563 _pyID subMeshID = aCommand->GetResultValue();
564 Handle(_pySubMesh) subMesh = new _pySubMesh( aCommand );
565 myObjects.insert( make_pair( subMeshID, subMesh ));
568 id_mesh->second->Process( aCommand );
569 id_mesh->second->AddProcessedCmd( aCommand );
573 // SMESH_MeshEditor method?
574 map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
575 if ( id_editor != myMeshEditors.end() )
577 const TCollection_AsciiString& method = aCommand->GetMethod();
579 // some commands of SMESH_MeshEditor create meshes and groups
580 _pyID meshID, groups;
581 if ( method.Search("MakeMesh") != -1 )
582 meshID = aCommand->GetResultValue();
583 else if ( method == "MakeBoundaryMesh")
584 meshID = aCommand->GetResultValue(1);
585 else if ( method == "MakeBoundaryElements")
586 meshID = aCommand->GetResultValue(2);
588 if ( method.Search("MakeGroups") != -1 ||
589 method == "ExtrusionAlongPathX" ||
590 method == "ExtrusionAlongPathObjX" ||
591 method == "DoubleNodeGroupNew" ||
592 method == "DoubleNodeGroupsNew" ||
593 method == "DoubleNodeElemGroupNew" ||
594 method == "DoubleNodeElemGroupsNew"||
595 method == "DoubleNodeElemGroup2New"||
596 method == "DoubleNodeElemGroups2New"
598 groups = aCommand->GetResultValue();
599 else if ( method == "MakeBoundaryMesh" )
600 groups = aCommand->GetResultValue(2);
601 else if ( method == "MakeBoundaryElements")
602 groups = aCommand->GetResultValue(3);
603 else if ( method == "Create0DElementsOnAllNodes" &&
604 aCommand->GetArg(2).Length() > 2 ) // group name != ''
605 groups = aCommand->GetResultValue();
607 id_editor->second->Process( aCommand );
608 id_editor->second->AddProcessedCmd( aCommand );
611 if ( !meshID.IsEmpty() &&
612 !myMeshes.count( meshID ) &&
613 aCommand->IsStudyEntry( meshID ))
615 TCollection_AsciiString processedCommand = aCommand->GetString();
616 Handle(_pyMesh) mesh = new _pyMesh( aCommand, meshID );
617 myMeshes.insert( make_pair( meshID, mesh ));
619 aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
622 if ( !groups.IsEmpty() )
624 if ( !aCommand->IsStudyEntry( meshID ))
625 meshID = id_editor->second->GetMesh();
626 Handle(_pyMesh) mesh = myMeshes[ meshID ];
628 list< _pyID > idList = aCommand->GetStudyEntries( groups );
629 list< _pyID >::iterator grID = idList.begin();
630 for ( ; grID != idList.end(); ++grID )
631 if ( !myObjects.count( *grID ))
633 Handle(_pyGroup) group = new _pyGroup( aCommand, *grID );
635 if ( !mesh.IsNull() ) mesh->AddGroup( group );
639 } // SMESH_MeshEditor methods
641 // SMESH_Hypothesis method?
642 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
643 for ( ; hyp != myHypos.end(); ++hyp )
644 if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
645 (*hyp)->Process( aCommand );
646 (*hyp)->AddProcessedCmd( aCommand );
650 // aFilterManager.CreateFilter() ?
651 if ( aCommand->GetMethod() == "CreateFilter" )
653 // Set a more human readable name to a filter
654 // aFilter0x7fbf6c71cfb0 -> aFilter_nb
655 _pyID newID, filterID = aCommand->GetResultValue();
656 int pos = filterID.Search( "0x" );
658 newID = (filterID.SubString(1,pos-1) + "_") + _pyID( ++myNbFilters );
660 Handle(_pyObject) filter( new _pyFilter( aCommand, newID ));
664 // other object method?
665 map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.find( objID );
666 if ( id_obj != myObjects.end() ) {
667 id_obj->second->Process( aCommand );
668 id_obj->second->AddProcessedCmd( aCommand );
672 // Add access to a wrapped mesh
673 AddMeshAccessorMethod( aCommand );
675 // Add access to a wrapped algorithm
676 // AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
678 // PAL12227. PythonDump was not updated at proper time; result is
679 // aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
680 // TypeError: __init__() takes exactly 11 arguments (10 given)
681 const char wrongCommand[] = "SMESH.Filter.Criterion(";
682 if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
684 _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
685 // there must be 10 arguments, 5-th arg ThresholdID is missing,
686 const int wrongNbArgs = 9, missingArg = 5;
687 if ( tmpCmd.GetNbArgs() == wrongNbArgs )
689 for ( int i = wrongNbArgs; i > missingArg; --i )
690 tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
691 tmpCmd.SetArg( missingArg, "''");
692 aCommand->GetString().Trunc( beg - 1 );
693 aCommand->GetString() += tmpCmd.GetString();
696 // set GetCriterion(elementType,CritType,Compare,Treshold,UnaryOp,BinaryOp,Tolerance)
698 // instead of "SMESH.Filter.Criterion(
699 // Type,Compare,Threshold,ThresholdStr,ThresholdID,UnaryOp,BinaryOp,Tolerance,TypeOfElement,Precision)
700 // 1 2 3 4 5 6 7 8 9 10
701 // in order to avoid the problem of type mismatch of long and FunctorType
702 const TCollection_AsciiString
703 SMESH("SMESH."), dfltFunctor("SMESH.FT_Undefined"), dftlTol("1e-07"), dftlPreci("-1");
704 TCollection_AsciiString
705 Type = aCommand->GetArg(1), // long
706 Compare = aCommand->GetArg(2), // long
707 Threshold = aCommand->GetArg(3), // double
708 ThresholdStr = aCommand->GetArg(4), // string
709 ThresholdID = aCommand->GetArg(5), // string
710 UnaryOp = aCommand->GetArg(6), // long
711 BinaryOp = aCommand->GetArg(7), // long
712 Tolerance = aCommand->GetArg(8), // double
713 TypeOfElement = aCommand->GetArg(9), // ElementType
714 Precision = aCommand->GetArg(10); // long
715 fixFunctorType( Type, Compare, UnaryOp, BinaryOp );
716 Type = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Type.IntegerValue() ));
717 Compare = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Compare.IntegerValue() ));
718 UnaryOp = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( UnaryOp.IntegerValue() ));
719 BinaryOp = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( BinaryOp.IntegerValue() ));
721 aCommand->RemoveArgs();
722 aCommand->SetObject( SMESH_2smeshpy::GenName() );
723 aCommand->SetMethod( "GetCriterion" );
725 aCommand->SetArg( 1, TypeOfElement );
726 aCommand->SetArg( 2, Type );
727 aCommand->SetArg( 3, Compare );
729 if ( Threshold.IsIntegerValue() )
731 int iGeom = Threshold.IntegerValue();
732 if ( Type == "SMESH.FT_ElemGeomType" )
734 // set SMESH.GeometryType instead of a numerical Threshold
735 const char* types[SMESH::Geom_BALL+1] = {
736 "Geom_POINT", "Geom_EDGE", "Geom_TRIANGLE", "Geom_QUADRANGLE", "Geom_POLYGON",
737 "Geom_TETRA", "Geom_PYRAMID", "Geom_HEXA", "Geom_PENTA", "Geom_HEXAGONAL_PRISM",
738 "Geom_POLYHEDRA", "Geom_BALL" };
739 if ( -1 < iGeom && iGeom < SMESH::Geom_POLYHEDRA+1 )
740 Threshold = SMESH + types[ iGeom ];
742 if (Type == "SMESH.FT_EntityType")
744 // set SMESH.EntityType instead of a numerical Threshold
745 const char* types[SMESH::Entity_Ball+1] = {
746 "Entity_Node", "Entity_0D", "Entity_Edge", "Entity_Quad_Edge",
747 "Entity_Triangle", "Entity_Quad_Triangle",
748 "Entity_Quadrangle", "Entity_Quad_Quadrangle", "Entity_BiQuad_Quadrangle",
749 "Entity_Polygon", "Entity_Quad_Polygon", "Entity_Tetra", "Entity_Quad_Tetra",
750 "Entity_Pyramid", "Entity_Quad_Pyramid",
751 "Entity_Hexa", "Entity_Quad_Hexa", "Entity_TriQuad_Hexa",
752 "Entity_Penta", "Entity_Quad_Penta", "Entity_Hexagonal_Prism",
753 "Entity_Polyhedra", "Entity_Quad_Polyhedra", "Entity_Ball" };
754 if ( -1 < iGeom && iGeom < SMESH::Entity_Quad_Polyhedra+1 )
755 Threshold = SMESH + types[ iGeom ];
758 if ( ThresholdID.Length() != 2 && ThresholdStr.Length() != 2) // not '' or ""
759 aCommand->SetArg( 4, ThresholdID.SubString( 2, ThresholdID.Length()-1 )); // shape entry
760 else if ( ThresholdStr.Length() != 2 )
761 aCommand->SetArg( 4, ThresholdStr );
762 else if ( ThresholdID.Length() != 2 )
763 aCommand->SetArg( 4, ThresholdID );
765 aCommand->SetArg( 4, Threshold );
766 // find the last not default arg
768 if ( Tolerance == dftlTol ) {
770 if ( BinaryOp == dfltFunctor ) {
772 if ( UnaryOp == dfltFunctor )
776 if ( 5 < lastDefault ) aCommand->SetArg( 5, UnaryOp );
777 if ( 6 < lastDefault ) aCommand->SetArg( 6, BinaryOp );
778 if ( 7 < lastDefault ) aCommand->SetArg( 7, Tolerance );
779 if ( Precision != dftlPreci )
781 TCollection_AsciiString crit = aCommand->GetResultValue();
782 aCommand->GetString() += "; ";
783 aCommand->GetString() += crit + ".Precision = " + Precision;
789 //================================================================================
791 * \brief Convert the command or remember it for later conversion
792 * \param theCommand - The python command calling a method of SMESH_Gen
794 //================================================================================
796 void _pyGen::Process( const Handle(_pyCommand)& theCommand )
798 // there are methods to convert:
799 // CreateMesh( shape )
800 // Concatenate( [mesh1, ...], ... )
801 // CreateHypothesis( theHypType, theLibName )
802 // Compute( mesh, geom )
803 // Evaluate( mesh, geom )
805 TCollection_AsciiString method = theCommand->GetMethod();
807 if ( method == "CreateMesh" || method == "CreateEmptyMesh")
809 Handle(_pyMesh) mesh = new _pyMesh( theCommand );
810 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
813 if ( method == "CreateMeshesFromUNV" ||
814 method == "CreateMeshesFromSTL" ||
815 method == "CreateMeshesFromCGNS" ||
816 method == "CopyMesh" )
818 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
819 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
822 if( method == "CreateMeshesFromMED" ||
823 method == "CreateMeshesFromSAUV"||
824 method == "CreateMeshesFromGMF" )
826 for ( int ind = 0; ind < theCommand->GetNbResultValues(); ind++ )
828 _pyID meshID = theCommand->GetResultValue(ind+1);
829 if ( !theCommand->IsStudyEntry( meshID ) ) continue;
830 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind+1));
831 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
833 if ( method == "CreateMeshesFromGMF" )
835 // CreateMeshesFromGMF( theFileName, theMakeRequiredGroups ) ->
836 // CreateMeshesFromGMF( theFileName )
837 _AString file = theCommand->GetArg(1);
838 theCommand->RemoveArgs();
839 theCommand->SetArg( 1, file );
843 // CreateHypothesis()
844 if ( method == "CreateHypothesis" )
846 // issue 199929, remove standard library name (default parameter)
847 const TCollection_AsciiString & aLibName = theCommand->GetArg( 2 );
848 if ( aLibName.Search( "StdMeshersEngine" ) != -1 ) {
849 // keep first argument
850 TCollection_AsciiString arg = theCommand->GetArg( 1 );
851 theCommand->RemoveArgs();
852 theCommand->SetArg( 1, arg );
855 myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
859 // smeshgen.Compute( mesh, geom ) --> mesh.Compute()
860 if ( method == "Compute" )
862 const _pyID& meshID = theCommand->GetArg( 1 );
863 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
864 if ( id_mesh != myMeshes.end() ) {
865 theCommand->SetObject( meshID );
866 theCommand->RemoveArgs();
867 id_mesh->second->Process( theCommand );
868 id_mesh->second->AddProcessedCmd( theCommand );
873 // smeshgen.Evaluate( mesh, geom ) --> mesh.Evaluate(geom)
874 if ( method == "Evaluate" )
876 const _pyID& meshID = theCommand->GetArg( 1 );
877 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
878 if ( id_mesh != myMeshes.end() ) {
879 theCommand->SetObject( meshID );
880 _pyID geom = theCommand->GetArg( 2 );
881 theCommand->RemoveArgs();
882 theCommand->SetArg( 1, geom );
883 id_mesh->second->AddProcessedCmd( theCommand );
888 // objects erasing creation command if no more its commands invoked:
889 // SMESH_Pattern, FilterManager
890 if ( method == "GetPattern" ||
891 method == "CreateFilterManager" ||
892 method == "CreateMeasurements" ) {
893 Handle(_pyObject) obj = new _pySelfEraser( theCommand );
894 if ( !myObjects.insert( make_pair( obj->GetID(), obj )).second )
895 theCommand->Clear(); // already created
897 // Concatenate( [mesh1, ...], ... )
898 else if ( method == "Concatenate" || method == "ConcatenateWithGroups")
900 if ( method == "ConcatenateWithGroups" ) {
901 theCommand->SetMethod( "Concatenate" );
902 theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
904 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
905 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
906 AddMeshAccessorMethod( theCommand );
908 else if ( method == "SetName" ) // SetName(obj,name)
910 // store theCommand as one of object commands to erase it along with the object
911 const _pyID& objID = theCommand->GetArg( 1 );
912 Handle(_pyObject) obj = FindObject( objID );
914 obj->AddProcessedCmd( theCommand );
917 // Replace name of SMESH_Gen
919 // names of SMESH_Gen methods fully equal to methods defined in smeshBuilder.py
920 static TStringSet smeshpyMethods;
921 if ( smeshpyMethods.empty() ) {
922 const char * names[] =
923 { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
924 "GetPattern","GetSubShapesId",
925 "" }; // <- mark of array end
926 smeshpyMethods.Insert( names );
928 if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
929 // smeshgen.Method() --> smesh.Method()
930 theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
932 // smeshgen.Method() --> smesh.Method()
933 theCommand->SetObject( SMESH_2smeshpy::GenName() );
936 //================================================================================
938 * \brief Convert the remembered commands
940 //================================================================================
944 // create an empty command
945 myLastCommand = new _pyCommand();
947 map< _pyID, Handle(_pyMesh) >::iterator id_mesh;
948 map< _pyID, Handle(_pyObject) >::iterator id_obj;
949 list< Handle(_pyHypothesis) >::iterator hyp;
951 if ( IsToKeepAllCommands() ) // historical dump
953 // set myIsPublished = true to all objects
954 for ( id_mesh = myMeshes.begin(); id_mesh != myMeshes.end(); ++id_mesh )
955 id_mesh->second->SetRemovedFromStudy( false );
956 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
957 (*hyp)->SetRemovedFromStudy( false );
958 for ( id_obj = myObjects.begin(); id_obj != myObjects.end(); ++id_obj )
959 id_obj->second->SetRemovedFromStudy( false );
963 // let hypotheses find referred objects in order to prevent clearing
964 // not published referred hyps (it's needed for hyps like "LayerDistribution")
965 list< Handle(_pyMesh) > fatherMeshes;
966 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
967 if ( !hyp->IsNull() )
968 (*hyp)->GetReferredMeshesAndGeom( fatherMeshes );
970 // set myIsPublished = false to all objects depending on
971 // meshes built on a removed geometry
972 for ( id_mesh = myMeshes.begin(); id_mesh != myMeshes.end(); ++id_mesh )
973 if ( id_mesh->second->IsNotGeomPublished() )
974 id_mesh->second->SetRemovedFromStudy( true );
977 for ( id_mesh = myMeshes.begin(); id_mesh != myMeshes.end(); ++id_mesh )
978 if ( ! id_mesh->second.IsNull() )
979 id_mesh->second->Flush();
982 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
983 if ( !hyp->IsNull() ) {
985 // smeshgen.CreateHypothesis() --> smesh.CreateHypothesis()
986 if ( !(*hyp)->IsWrapped() )
987 (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
990 // Flush other objects
991 for ( id_obj = myObjects.begin(); id_obj != myObjects.end(); ++id_obj )
992 if ( ! id_obj->second.IsNull() )
993 id_obj->second->Flush();
995 myLastCommand->SetOrderNb( ++myNbCommands );
996 myCommands.push_back( myLastCommand );
999 //================================================================================
1001 * \brief Prevent moving a command creating a sub-mesh to the end of the script
1002 * if the sub-mesh is used in theCmdUsingSubmesh as argument
1004 //================================================================================
1006 void _pyGen::PlaceSubmeshAfterItsCreation( Handle(_pyCommand) theCmdUsingSubmesh ) const
1008 map< _pyID, Handle(_pyObject) >::const_iterator id_obj = myObjects.begin();
1009 for ( ; id_obj != myObjects.end(); ++id_obj )
1011 if ( !id_obj->second->IsKind( STANDARD_TYPE( _pySubMesh ))) continue;
1012 for ( int iArg = theCmdUsingSubmesh->GetNbArgs(); iArg; --iArg )
1014 const _pyID& arg = theCmdUsingSubmesh->GetArg( iArg );
1015 if ( arg.IsEmpty() || arg.Value( 1 ) == '"' || arg.Value( 1 ) == '\'' )
1017 list< _pyID > idList = theCmdUsingSubmesh->GetStudyEntries( arg );
1018 list< _pyID >::iterator id = idList.begin();
1019 for ( ; id != idList.end(); ++id )
1020 if ( id_obj->first == *id )
1021 // _pySubMesh::Process() does what we need
1022 Handle(_pySubMesh)::DownCast( id_obj->second )->Process( theCmdUsingSubmesh );
1027 //================================================================================
1029 * \brief Clean commmands of removed objects depending on myIsPublished flag
1031 //================================================================================
1033 void _pyGen::ClearCommands()
1035 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
1036 for ( ; id_mesh != myMeshes.end(); ++id_mesh )
1037 id_mesh->second->ClearCommands();
1039 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1040 for ( ; hyp != myHypos.end(); ++hyp )
1041 if ( !hyp->IsNull() )
1042 (*hyp)->ClearCommands();
1044 map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.begin();
1045 for ( ; id_obj != myObjects.end(); ++id_obj )
1046 id_obj->second->ClearCommands();
1049 //================================================================================
1051 * \brief Release mutual handles of objects
1053 //================================================================================
1057 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
1058 for ( ; id_mesh != myMeshes.end(); ++id_mesh )
1059 id_mesh->second->Free();
1062 map< _pyID, Handle(_pyMeshEditor) >::iterator id_ed = myMeshEditors.begin();
1063 for ( ; id_ed != myMeshEditors.end(); ++id_ed )
1064 id_ed->second->Free();
1065 myMeshEditors.clear();
1067 map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.begin();
1068 for ( ; id_obj != myObjects.end(); ++id_obj )
1069 id_obj->second->Free();
1072 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1073 for ( ; hyp != myHypos.end(); ++hyp )
1074 if ( !hyp->IsNull() )
1078 myFile2ExportedMesh.clear();
1081 //================================================================================
1083 * \brief Add access method to mesh that is an argument
1084 * \param theCmd - command to add access method
1085 * \retval bool - true if added
1087 //================================================================================
1089 bool _pyGen::AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const
1092 map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
1093 for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
1094 if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
1100 //================================================================================
1102 * \brief Add access method to algo that is an object or an argument
1103 * \param theCmd - command to add access method
1104 * \retval bool - true if added
1106 //================================================================================
1108 bool _pyGen::AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const
1111 list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
1112 for ( ; hyp != myHypos.end(); ++hyp ) {
1113 if ( (*hyp)->IsAlgo() && /*(*hyp)->IsWrapped() &&*/
1114 theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
1120 //================================================================================
1122 * \brief Find hypothesis by ID (entry)
1123 * \param theHypID - The hypothesis ID
1124 * \retval Handle(_pyHypothesis) - The found hypothesis
1126 //================================================================================
1128 Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
1130 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1131 for ( ; hyp != myHypos.end(); ++hyp )
1132 if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
1134 return Handle(_pyHypothesis)();
1137 //================================================================================
1139 * \brief Find algorithm the created algorithm
1140 * \param theGeom - The shape ID the algorithm was created on
1141 * \param theMesh - The mesh ID that created the algorithm
1142 * \param dim - The algo dimension
1143 * \retval Handle(_pyHypothesis) - The found algo
1145 //================================================================================
1147 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
1148 const Handle(_pyHypothesis)& theHypothesis )
1150 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1151 for ( ; hyp != myHypos.end(); ++hyp )
1152 if ( !hyp->IsNull() &&
1154 theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
1155 (*hyp)->GetGeom() == theGeom &&
1156 (*hyp)->GetMesh() == theMesh )
1161 //================================================================================
1163 * \brief Find subMesh by ID (entry)
1164 * \param theSubMeshID - The subMesh ID
1165 * \retval Handle(_pySubMesh) - The found subMesh
1167 //================================================================================
1169 Handle(_pySubMesh) _pyGen::FindSubMesh( const _pyID& theSubMeshID )
1171 map< _pyID, Handle(_pyObject) >::iterator id_subMesh = myObjects.find(theSubMeshID);
1172 if ( id_subMesh != myObjects.end() )
1173 return Handle(_pySubMesh)::DownCast( id_subMesh->second );
1174 return Handle(_pySubMesh)();
1178 //================================================================================
1180 * \brief Change order of commands in the script
1181 * \param theCmd1 - One command
1182 * \param theCmd2 - Another command
1184 //================================================================================
1186 void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 )
1188 list< Handle(_pyCommand) >::iterator pos1, pos2;
1189 pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
1190 pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
1191 myCommands.insert( pos1, theCmd2 );
1192 myCommands.insert( pos2, theCmd1 );
1193 myCommands.erase( pos1 );
1194 myCommands.erase( pos2 );
1196 int nb1 = theCmd1->GetOrderNb();
1197 theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
1198 theCmd2->SetOrderNb( nb1 );
1199 // cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
1200 // << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
1203 //================================================================================
1205 * \brief Set one command after the other
1206 * \param theCmd - Command to move
1207 * \param theAfterCmd - Command ater which to insert the first one
1209 //================================================================================
1211 void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
1213 setNeighbourCommand( theCmd, theAfterCmd, true );
1216 //================================================================================
1218 * \brief Set one command before the other
1219 * \param theCmd - Command to move
1220 * \param theBeforeCmd - Command before which to insert the first one
1222 //================================================================================
1224 void _pyGen::SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd )
1226 setNeighbourCommand( theCmd, theBeforeCmd, false );
1229 //================================================================================
1231 * \brief Set one command before or after the other
1232 * \param theCmd - Command to move
1233 * \param theOtherCmd - Command ater or before which to insert the first one
1235 //================================================================================
1237 void _pyGen::setNeighbourCommand( Handle(_pyCommand)& theCmd,
1238 Handle(_pyCommand)& theOtherCmd,
1239 const bool theIsAfter )
1241 list< Handle(_pyCommand) >::iterator pos;
1242 pos = find( myCommands.begin(), myCommands.end(), theCmd );
1243 myCommands.erase( pos );
1244 pos = find( myCommands.begin(), myCommands.end(), theOtherCmd );
1245 myCommands.insert( (theIsAfter ? ++pos : pos), theCmd );
1248 for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
1249 (*pos)->SetOrderNb( i++ );
1252 //================================================================================
1254 * \brief Set command be last in list of commands
1255 * \param theCmd - Command to be last
1257 //================================================================================
1259 Handle(_pyCommand)& _pyGen::GetLastCommand()
1261 return myLastCommand;
1264 //================================================================================
1266 * \brief Set method to access to object wrapped with python class
1267 * \param theID - The wrapped object entry
1268 * \param theMethod - The accessor method
1270 //================================================================================
1272 void _pyGen::SetAccessorMethod(const _pyID& theID, const char* theMethod )
1274 myID2AccessorMethod.Bind( theID, (char*) theMethod );
1277 //================================================================================
1279 * \brief Generated new ID for object and assign with existing name
1280 * \param theID - ID of existing object
1282 //================================================================================
1284 _pyID _pyGen::GenerateNewID( const _pyID& theID )
1289 aNewID = theID + _pyID( ":" ) + _pyID( index++ );
1291 while ( myObjectNames.IsBound( aNewID ) );
1293 myObjectNames.Bind( aNewID, myObjectNames.IsBound( theID )
1294 ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ))
1295 : _pyID( "A" ) + aNewID );
1299 //================================================================================
1301 * \brief Stores theObj in myObjects
1303 //================================================================================
1305 void _pyGen::AddObject( Handle(_pyObject)& theObj )
1307 if ( theObj.IsNull() ) return;
1309 if ( theObj->IsKind( STANDARD_TYPE( _pyMesh )))
1310 myMeshes.insert( make_pair( theObj->GetID(), Handle(_pyMesh)::DownCast( theObj )));
1312 else if ( theObj->IsKind( STANDARD_TYPE( _pyMeshEditor )))
1313 myMeshEditors.insert( make_pair( theObj->GetID(), Handle(_pyMeshEditor)::DownCast( theObj )));
1316 myObjects.insert( make_pair( theObj->GetID(), theObj ));
1319 //================================================================================
1321 * \brief Re-register an object with other ID to make it Process() commands of
1322 * other object having this ID
1324 //================================================================================
1326 void _pyGen::SetProxyObject( const _pyID& theID, Handle(_pyObject)& theObj )
1328 if ( theObj.IsNull() ) return;
1330 if ( theObj->IsKind( STANDARD_TYPE( _pyMesh )))
1331 myMeshes.insert( make_pair( theID, Handle(_pyMesh)::DownCast( theObj )));
1333 else if ( theObj->IsKind( STANDARD_TYPE( _pyMeshEditor )))
1334 myMeshEditors.insert( make_pair( theID, Handle(_pyMeshEditor)::DownCast( theObj )));
1337 myObjects.insert( make_pair( theID, theObj ));
1340 //================================================================================
1342 * \brief Finds a _pyObject by ID
1344 //================================================================================
1346 Handle(_pyObject) _pyGen::FindObject( const _pyID& theObjID ) const
1349 map< _pyID, Handle(_pyObject) >::const_iterator id_obj = myObjects.find( theObjID );
1350 if ( id_obj != myObjects.end() )
1351 return id_obj->second;
1354 map< _pyID, Handle(_pyMesh) >::const_iterator id_obj = myMeshes.find( theObjID );
1355 if ( id_obj != myMeshes.end() )
1356 return id_obj->second;
1359 // map< _pyID, Handle(_pyMeshEditor) >::const_iterator id_obj = myMeshEditors.find( theObjID );
1360 // if ( id_obj != myMeshEditors.end() )
1361 // return id_obj->second;
1363 return Handle(_pyObject)();
1366 //================================================================================
1368 * \brief Check if a study entry is under GEOM component
1370 //================================================================================
1372 bool _pyGen::IsGeomObject(const _pyID& theObjID) const
1376 return ( myGeomIDIndex <= theObjID.Length() &&
1377 int( theObjID.Value( myGeomIDIndex )) == myGeomIDNb &&
1378 _pyCommand::IsStudyEntry( theObjID ));
1383 //================================================================================
1385 * \brief Returns true if an object is not present in a study
1387 //================================================================================
1389 bool _pyGen::IsNotPublished(const _pyID& theObjID) const
1391 if ( theObjID.IsEmpty() ) return false;
1393 if ( myObjectNames.IsBound( theObjID ))
1394 return false; // SMESH object is in study
1396 // either the SMESH object is not in study or it is a GEOM object
1397 if ( IsGeomObject( theObjID ))
1399 SALOMEDS::SObject_wrap so = myStudy->FindObjectID( theObjID.ToCString() );
1400 if ( so->_is_nil() ) return true;
1401 CORBA::Object_var obj = so->GetObject();
1402 return CORBA::is_nil( obj );
1404 return true; // SMESH object not in study
1407 //================================================================================
1409 * \brief Remove object name from myObjectNames that leads to that SetName() for
1410 * this object is not dumped
1411 * \param [in] theObjID - entry of the object whose creation command was eliminated
1413 //================================================================================
1415 void _pyGen::ObjectCreationRemoved(const _pyID& theObjID)
1417 myRemovedObjIDs.insert( theObjID );
1420 //================================================================================
1422 * \brief Return reader of hypotheses of plugins
1424 //================================================================================
1426 Handle( _pyHypothesisReader ) _pyGen::GetHypothesisReader() const
1428 if (myHypReader.IsNull() )
1429 ((_pyGen*) this)->myHypReader = new _pyHypothesisReader;
1435 //================================================================================
1437 * \brief Mesh created by SMESH_Gen
1439 //================================================================================
1441 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd)
1442 : _pyObject( theCreationCmd ), myGeomNotInStudy( false )
1444 if ( theCreationCmd->GetMethod() == "CreateMesh" && theGen->IsNotPublished( GetGeom() ))
1445 myGeomNotInStudy = true;
1447 // convert my creation command --> smeshpy.Mesh(...)
1448 Handle(_pyCommand) creationCmd = GetCreationCmd();
1449 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
1450 creationCmd->SetMethod( "Mesh" );
1451 theGen->SetAccessorMethod( GetID(), _pyMesh::AccessorMethod() );
1454 //================================================================================
1456 * \brief Mesh created by SMESH_MeshEditor
1458 //================================================================================
1460 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const _pyID& meshId):
1461 _pyObject(theCreationCmd,meshId), myGeomNotInStudy(false )
1463 if ( theCreationCmd->MethodStartsFrom( "CreateMeshesFrom" ))
1465 // this mesh depends on the exported mesh
1466 const TCollection_AsciiString& file = theCreationCmd->GetArg( 1 );
1467 if ( !file.IsEmpty() )
1469 ExportedMeshData& exportData = theGen->FindExportedMesh( file );
1470 addFatherMesh( exportData.myMesh );
1471 if ( !exportData.myLastComputeCmd.IsNull() )
1473 // restore cleared Compute() by which the exported mesh was generated
1474 exportData.myLastComputeCmd->GetString() = exportData.myLastComputeCmdString;
1475 // protect that Compute() cmd from clearing
1476 if ( exportData.myMesh->myLastComputeCmd == exportData.myLastComputeCmd )
1477 exportData.myMesh->myLastComputeCmd.Nullify();
1481 else if ( theCreationCmd->MethodStartsFrom( "Concatenate" ))
1483 // this mesh depends on concatenated meshes
1484 const TCollection_AsciiString& meshIDs = theCreationCmd->GetArg( 1 );
1485 list< _pyID > idList = theCreationCmd->GetStudyEntries( meshIDs );
1486 list< _pyID >::iterator meshID = idList.begin();
1487 for ( ; meshID != idList.end(); ++meshID )
1488 addFatherMesh( *meshID );
1490 else if ( theCreationCmd->GetMethod() == "CopyMesh" )
1492 // this mesh depends on a copied IdSource
1493 const _pyID& objID = theCreationCmd->GetArg( 1 );
1494 addFatherMesh( objID );
1496 else if ( theCreationCmd->GetMethod().Search("MakeMesh") != -1 ||
1497 theCreationCmd->GetMethod() == "MakeBoundaryMesh" ||
1498 theCreationCmd->GetMethod() == "MakeBoundaryElements" )
1500 // this mesh depends on a source mesh
1501 // (theCreationCmd is already Process()ed by _pyMeshEditor)
1502 const _pyID& meshID = theCreationCmd->GetObject();
1503 addFatherMesh( meshID );
1506 // convert my creation command
1507 Handle(_pyCommand) creationCmd = GetCreationCmd();
1508 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
1509 theGen->SetAccessorMethod( meshId, _pyMesh::AccessorMethod() );
1512 //================================================================================
1514 * \brief Convert an IDL API command of SMESH::SMESH_Mesh to a method call of python Mesh
1515 * \param theCommand - Engine method called for this mesh
1517 //================================================================================
1519 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
1521 // some methods of SMESH_Mesh interface needs special conversion
1522 // to methods of Mesh python class
1524 // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
1525 // --> in Mesh_Algorithm.Create(mesh, geom, hypo, so)
1526 // 2. AddHypothesis(geom, hyp)
1527 // --> in Mesh_Algorithm.Hypothesis(hyp, args, so)
1528 // 3. CreateGroupFromGEOM(type, name, grp)
1529 // --> in Mesh.Group(grp, name="")
1530 // 4. ExportToMED(f, auto_groups, version)
1531 // --> in Mesh.ExportMED( f, auto_groups, version )
1534 const TCollection_AsciiString& method = theCommand->GetMethod();
1535 // ----------------------------------------------------------------------
1536 if ( method == "Compute" ) // in snapshot mode, clear the previous Compute()
1538 if ( !theGen->IsToKeepAllCommands() ) // !historical
1540 list< Handle(_pyHypothesis) >::iterator hyp;
1541 if ( !myLastComputeCmd.IsNull() )
1543 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
1544 (*hyp)->ComputeDiscarded( myLastComputeCmd );
1546 myLastComputeCmd->Clear();
1548 myLastComputeCmd = theCommand;
1550 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
1551 (*hyp)->MeshComputed( myLastComputeCmd );
1555 // ----------------------------------------------------------------------
1556 else if ( method == "Clear" ) // in snapshot mode, clear all previous commands
1558 if ( !theGen->IsToKeepAllCommands() ) // !historical
1561 myChildMeshes.empty() ? 0 : myChildMeshes.back()->GetCreationCmd()->GetOrderNb();
1562 // list< Handle(_pyCommand) >::reverse_iterator cmd = myProcessedCmds.rbegin();
1563 // for ( ; cmd != myProcessedCmds.rend() && (*cmd)->GetOrderNb() > untilCmdNb; ++cmd )
1565 if ( !myLastComputeCmd.IsNull() )
1567 list< Handle(_pyHypothesis) >::iterator hyp;
1568 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
1569 (*hyp)->ComputeDiscarded( myLastComputeCmd );
1571 myLastComputeCmd->Clear();
1574 list< Handle(_pyMeshEditor)>::iterator e = myEditors.begin();
1575 for ( ; e != myEditors.end(); ++e )
1577 list< Handle(_pyCommand)>& cmds = (*e)->GetProcessedCmds();
1578 list< Handle(_pyCommand) >::reverse_iterator cmd = cmds.rbegin();
1579 for ( ; cmd != cmds.rend() && (*cmd)->GetOrderNb() > untilCmdNb; ++cmd )
1580 if ( !(*cmd)->IsEmpty() )
1582 if ( (*cmd)->GetStudyEntries( (*cmd)->GetResultValue() ).empty() ) // no object created
1586 myLastComputeCmd = theCommand; // to clear Clear() the same way as Compute()
1589 // ----------------------------------------------------------------------
1590 else if ( method == "GetSubMesh" ) { // collect submeshes of the mesh
1591 Handle(_pySubMesh) subMesh = theGen->FindSubMesh( theCommand->GetResultValue() );
1592 if ( !subMesh.IsNull() ) {
1593 subMesh->SetCreator( this );
1594 mySubmeshes.push_back( subMesh );
1597 // ----------------------------------------------------------------------
1598 else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO )
1599 myAddHypCmds.push_back( theCommand );
1601 const _pyID& hypID = theCommand->GetArg( 2 );
1602 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
1603 if ( !hyp.IsNull() ) {
1604 myHypos.push_back( hyp );
1605 if ( hyp->GetMesh().IsEmpty() )
1606 hyp->SetMesh( this->GetID() );
1609 // ----------------------------------------------------------------------
1610 else if ( method == "CreateGroup" ||
1611 method == "CreateGroupFromGEOM" ||
1612 method == "CreateGroupFromFilter" )
1614 Handle(_pyGroup) group = new _pyGroup( theCommand );
1615 myGroups.push_back( group );
1616 theGen->AddObject( group );
1618 // update list of groups
1619 else if ( method == "GetGroups" )
1621 TCollection_AsciiString grIDs = theCommand->GetResultValue();
1622 list< _pyID > idList = theCommand->GetStudyEntries( grIDs );
1623 list< _pyID >::iterator grID = idList.begin();
1624 for ( ; grID != idList.end(); ++grID )
1626 Handle(_pyObject) obj = theGen->FindObject( *grID );
1629 Handle(_pyGroup) group = new _pyGroup( theCommand, *grID );
1630 theGen->AddObject( group );
1631 myGroups.push_back( group );
1635 // notify a group about full removal
1636 else if ( method == "RemoveGroupWithContents" )
1638 if ( !theGen->IsToKeepAllCommands() ) { // snapshot mode
1639 const _pyID groupID = theCommand->GetArg( 1 );
1640 Handle(_pyGroup) grp = Handle(_pyGroup)::DownCast( theGen->FindObject( groupID ));
1641 if ( !grp.IsNull() )
1642 grp->RemovedWithContents();
1645 // ----------------------------------------------------------------------
1646 else if ( theCommand->MethodStartsFrom( "Export" ))
1648 if ( method == "ExportToMED" || // ExportToMED() --> ExportMED()
1649 method == "ExportToMEDX" ) { // ExportToMEDX() --> ExportMED()
1650 theCommand->SetMethod( "ExportMED" );
1652 else if ( method == "ExportCGNS" )
1653 { // ExportCGNS(part, ...) -> ExportCGNS(..., part)
1654 _pyID partID = theCommand->GetArg( 1 );
1655 int nbArgs = theCommand->GetNbArgs();
1656 for ( int i = 2; i <= nbArgs; ++i )
1657 theCommand->SetArg( i-1, theCommand->GetArg( i ));
1658 theCommand->SetArg( nbArgs, partID );
1660 else if ( method == "ExportGMF" )
1661 { // ExportGMF(part,file,bool) -> ExportCGNS(file, part)
1662 _pyID partID = theCommand->GetArg( 1 );
1663 _AString file = theCommand->GetArg( 2 );
1664 theCommand->RemoveArgs();
1665 theCommand->SetArg( 1, file );
1666 theCommand->SetArg( 2, partID );
1668 else if ( theCommand->MethodStartsFrom( "ExportPartTo" ))
1669 { // ExportPartTo*(part, ...) -> Export*(..., part)
1671 // remove "PartTo" from the method
1672 TCollection_AsciiString newMethod = method;
1673 newMethod.Remove( 7, 6 );
1674 theCommand->SetMethod( newMethod );
1675 // make the 1st arg be the last one
1676 _pyID partID = theCommand->GetArg( 1 );
1677 int nbArgs = theCommand->GetNbArgs();
1678 for ( int i = 2; i <= nbArgs; ++i )
1679 theCommand->SetArg( i-1, theCommand->GetArg( i ));
1680 theCommand->SetArg( nbArgs, partID );
1682 // remember file name
1683 theGen->AddExportedMesh( theCommand->GetArg( 1 ),
1684 ExportedMeshData( this, myLastComputeCmd ));
1686 // ----------------------------------------------------------------------
1687 else if ( method == "RemoveHypothesis" ) // (geom, hyp)
1689 _pyID hypID = theCommand->GetArg( 2 );
1690 _pyID geomID = theCommand->GetArg( 1 );
1691 bool isLocal = ( geomID != GetGeom() );
1693 // check if this mesh still has corresponding addition command
1694 Handle(_pyCommand) addCmd;
1695 list< Handle(_pyCommand) >::iterator cmd;
1696 list< Handle(_pyCommand) >* addCmds[2] = { &myAddHypCmds, &myNotConvertedAddHypCmds };
1697 for ( int i = 0; i < 2; ++i )
1699 list< Handle(_pyCommand )> & addHypCmds = *(addCmds[i]);
1700 for ( cmd = addHypCmds.begin(); cmd != addHypCmds.end(); )
1702 bool sameHyp = true;
1703 if ( hypID != (*cmd)->GetArg( 1 ) && hypID != (*cmd)->GetArg( 2 ))
1704 sameHyp = false; // other hyp
1705 if ( (*cmd)->GetNbArgs() == 2 &&
1706 geomID != (*cmd)->GetArg( 1 ) && geomID != (*cmd)->GetArg( 2 ))
1707 sameHyp = false; // other geom
1708 if ( (*cmd)->GetNbArgs() == 1 && isLocal )
1709 sameHyp = false; // other geom
1713 cmd = addHypCmds.erase( cmd );
1714 if ( !theGen->IsToKeepAllCommands() ) {
1716 theCommand->Clear();
1725 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
1726 if ( !theCommand->IsEmpty() && !hypID.IsEmpty() ) {
1727 // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
1728 _pyID geom = theCommand->GetArg( 1 );
1729 theCommand->RemoveArgs();
1730 theCommand->SetArg( 1, hypID );
1731 if ( geom != GetGeom() )
1732 theCommand->SetArg( 2, geom );
1734 // remove hyp from myHypos
1735 myHypos.remove( hyp );
1737 // check for SubMesh order commands
1738 else if ( method == "GetMeshOrder" || method == "SetMeshOrder" )
1740 // make commands GetSubMesh() returning sub-meshes be before using sub-meshes
1741 // by GetMeshOrder() and SetMeshOrder(), since by defalut GetSubMesh()
1742 // commands are moved at the end of the script
1743 TCollection_AsciiString subIDs =
1744 ( method == "SetMeshOrder" ) ? theCommand->GetArg(1) : theCommand->GetResultValue();
1745 list< _pyID > idList = theCommand->GetStudyEntries( subIDs );
1746 list< _pyID >::iterator subID = idList.begin();
1747 for ( ; subID != idList.end(); ++subID )
1749 Handle(_pySubMesh) subMesh = theGen->FindSubMesh( *subID );
1750 if ( !subMesh.IsNull() )
1751 subMesh->Process( theCommand ); // it moves GetSubMesh() before theCommand
1754 // add accessor method if necessary
1757 if ( NeedMeshAccess( theCommand ))
1758 // apply theCommand to the mesh wrapped by smeshpy mesh
1759 AddMeshAccess( theCommand );
1763 //================================================================================
1765 * \brief Return True if addition of accesor method is needed
1767 //================================================================================
1769 bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
1771 // names of SMESH_Mesh methods fully equal to methods of python class Mesh,
1772 // so no conversion is needed for them at all:
1773 static TStringSet sameMethods;
1774 if ( sameMethods.empty() ) {
1775 const char * names[] =
1776 { "ExportDAT","ExportUNV","ExportSTL","ExportSAUV", "RemoveGroup","RemoveGroupWithContents",
1777 "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
1778 "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
1779 "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
1780 "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
1781 "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
1782 "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
1783 "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
1784 "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
1785 "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
1786 "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
1787 "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
1788 "Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder"
1789 ,"" }; // <- mark of end
1790 sameMethods.Insert( names );
1793 return !sameMethods.Contains( theCommand->GetMethod() );
1796 //================================================================================
1798 * \brief Convert creation and addition of all algos and hypos
1800 //================================================================================
1802 void _pyMesh::Flush()
1805 // get the meshes this mesh depends on via hypotheses
1806 list< Handle(_pyMesh) > fatherMeshes;
1807 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1808 for ( ; hyp != myHypos.end(); ++hyp )
1809 if ( ! (*hyp)->GetReferredMeshesAndGeom( fatherMeshes ))
1810 myGeomNotInStudy = true;
1812 list< Handle(_pyMesh) >::iterator m = fatherMeshes.begin();
1813 for ( ; m != fatherMeshes.end(); ++m )
1814 addFatherMesh( *m );
1815 // if ( removedGeom )
1816 // SetRemovedFromStudy(); // as reffered geometry not in study
1818 if ( myGeomNotInStudy )
1821 list < Handle(_pyCommand) >::iterator cmd;
1823 // try to convert algo addition like this:
1824 // mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
1825 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
1827 Handle(_pyCommand) addCmd = *cmd;
1829 _pyID algoID = addCmd->GetArg( 2 );
1830 Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
1831 if ( algo.IsNull() || !algo->IsAlgo() )
1834 // check and create new algorithm instance if it is already wrapped
1835 if ( algo->IsWrapped() ) {
1836 _pyID localAlgoID = theGen->GenerateNewID( algoID );
1837 TCollection_AsciiString aNewCmdStr = addCmd->GetIndentation() + localAlgoID +
1838 TCollection_AsciiString( " = " ) + theGen->GetID() +
1839 TCollection_AsciiString( ".CreateHypothesis( \"" ) + algo->GetAlgoType() +
1840 TCollection_AsciiString( "\" )" );
1842 Handle(_pyCommand) newCmd = theGen->AddCommand( aNewCmdStr );
1843 Handle(_pyAlgorithm) newAlgo = Handle(_pyAlgorithm)::DownCast(theGen->FindHyp( localAlgoID ));
1844 if ( !newAlgo.IsNull() ) {
1845 newAlgo->Assign( algo, this->GetID() );
1846 newAlgo->SetCreationCmd( newCmd );
1848 // set algorithm creation
1849 theGen->SetCommandBefore( newCmd, addCmd );
1850 myHypos.push_back( newAlgo );
1851 if ( !myLastComputeCmd.IsNull() &&
1852 newCmd->GetOrderNb() == myLastComputeCmd->GetOrderNb() + 1)
1853 newAlgo->MeshComputed( myLastComputeCmd );
1858 _pyID geom = addCmd->GetArg( 1 );
1859 bool isLocalAlgo = ( geom != GetGeom() );
1862 if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
1864 // wrapped algo is created after mesh creation
1865 GetCreationCmd()->AddDependantCmd( addCmd );
1867 if ( isLocalAlgo ) {
1868 // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
1869 addCmd->SetArg( addCmd->GetNbArgs() + 1,
1870 TCollection_AsciiString( "geom=" ) + geom );
1871 // sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
1872 list < Handle(_pySubMesh) >::iterator smIt;
1873 for ( smIt = mySubmeshes.begin(); smIt != mySubmeshes.end(); ++smIt ) {
1874 Handle(_pySubMesh) subMesh = *smIt;
1875 Handle(_pyCommand) subCmd = subMesh->GetCreationCmd();
1876 if ( geom == subCmd->GetArg( 1 )) {
1877 subCmd->SetObject( algo->GetID() );
1878 subCmd->RemoveArgs();
1879 subMesh->SetCreator( algo );
1884 else // KO - ALGO was already created
1886 // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
1887 addCmd->RemoveArgs();
1888 addCmd->SetArg( 1, algoID );
1890 addCmd->SetArg( 2, geom );
1891 myNotConvertedAddHypCmds.push_back( addCmd );
1895 // try to convert hypo addition like this:
1896 // mesh.AddHypothesis(geom, HYPO ) --> HYPO = algo.Hypo()
1897 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
1899 Handle(_pyCommand) addCmd = *cmd;
1900 _pyID hypID = addCmd->GetArg( 2 );
1901 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
1902 if ( hyp.IsNull() || hyp->IsAlgo() )
1904 bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
1906 // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
1907 _pyID geom = addCmd->GetArg( 1 );
1908 addCmd->RemoveArgs();
1909 addCmd->SetArg( 1, hypID );
1910 if ( geom != GetGeom() )
1911 addCmd->SetArg( 2, geom );
1912 myNotConvertedAddHypCmds.push_back( addCmd );
1916 myAddHypCmds.clear();
1917 mySubmeshes.clear();
1920 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
1921 for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
1925 //================================================================================
1927 * \brief Sets myIsPublished of me and of all objects depending on me.
1929 //================================================================================
1931 void _pyMesh::SetRemovedFromStudy(const bool isRemoved)
1933 _pyObject::SetRemovedFromStudy(isRemoved);
1935 list< Handle(_pySubMesh) >::iterator sm = mySubmeshes.begin();
1936 for ( ; sm != mySubmeshes.end(); ++sm )
1937 (*sm)->SetRemovedFromStudy(isRemoved);
1939 list< Handle(_pyGroup) >::iterator gr = myGroups.begin();
1940 for ( ; gr != myGroups.end(); ++gr )
1941 (*gr)->SetRemovedFromStudy(isRemoved);
1943 list< Handle(_pyMesh) >::iterator m = myChildMeshes.begin();
1944 for ( ; m != myChildMeshes.end(); ++m )
1945 (*m)->SetRemovedFromStudy(isRemoved);
1947 list< Handle(_pyMeshEditor)>::iterator e = myEditors.begin();
1948 for ( ; e != myEditors.end(); ++e )
1949 (*e)->SetRemovedFromStudy(isRemoved);
1952 //================================================================================
1954 * \brief Return true if none of myChildMeshes is in study
1956 //================================================================================
1958 bool _pyMesh::CanClear()
1963 list< Handle(_pyMesh) >::iterator m = myChildMeshes.begin();
1964 for ( ; m != myChildMeshes.end(); ++m )
1965 if ( !(*m)->CanClear() )
1971 //================================================================================
1973 * \brief Clear my commands and commands of mesh editor
1975 //================================================================================
1977 void _pyMesh::ClearCommands()
1983 // mark all sub-objects as not removed, except child meshes
1984 list< Handle(_pyMesh) > children;
1985 children.swap( myChildMeshes );
1986 SetRemovedFromStudy( false );
1987 children.swap( myChildMeshes );
1991 _pyObject::ClearCommands();
1993 list< Handle(_pySubMesh) >::iterator sm = mySubmeshes.begin();
1994 for ( ; sm != mySubmeshes.end(); ++sm )
1995 (*sm)->ClearCommands();
1997 list< Handle(_pyGroup) >::iterator gr = myGroups.begin();
1998 for ( ; gr != myGroups.end(); ++gr )
1999 (*gr)->ClearCommands();
2001 list< Handle(_pyMeshEditor)>::iterator e = myEditors.begin();
2002 for ( ; e != myEditors.end(); ++e )
2003 (*e)->ClearCommands();
2006 //================================================================================
2008 * \brief Add a father mesh by ID
2010 //================================================================================
2012 void _pyMesh::addFatherMesh( const _pyID& meshID )
2014 if ( !meshID.IsEmpty() )
2015 addFatherMesh( Handle(_pyMesh)::DownCast( theGen->FindObject( meshID )));
2018 //================================================================================
2020 * \brief Add a father mesh
2022 //================================================================================
2024 void _pyMesh::addFatherMesh( const Handle(_pyMesh)& mesh )
2026 if ( !mesh.IsNull() )
2028 //myFatherMeshes.push_back( mesh );
2029 mesh->myChildMeshes.push_back( this );
2031 // protect last Compute() from clearing by the next Compute()
2032 mesh->myLastComputeCmd.Nullify();
2036 //================================================================================
2038 * \brief MeshEditor convert its commands to ones of mesh
2040 //================================================================================
2042 _pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
2043 _pyObject( theCreationCmd )
2045 myMesh = theCreationCmd->GetObject();
2046 myCreationCmdStr = theCreationCmd->GetString();
2047 theCreationCmd->Clear();
2049 Handle(_pyMesh) mesh = ObjectToMesh( theGen->FindObject( myMesh ));
2050 if ( !mesh.IsNull() )
2051 mesh->AddEditor( this );
2054 //================================================================================
2056 * \brief convert its commands to ones of mesh
2058 //================================================================================
2060 void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
2062 // names of SMESH_MeshEditor methods fully equal to methods of the python class Mesh, so
2063 // commands calling this methods are converted to calls of Mesh methods
2064 static TStringSet sameMethods;
2065 if ( sameMethods.empty() ) {
2066 const char * names[] = {
2067 "RemoveElements","RemoveNodes","RemoveOrphanNodes","AddNode","Add0DElement","AddEdge","AddFace","AddPolygonalFace","AddBall",
2068 "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode", "MoveClosestNodeToPoint",
2069 "InverseDiag","DeleteDiag","Reorient","ReorientObject",
2070 "TriToQuad","TriToQuadObject", "SplitQuad","SplitQuadObject",
2071 "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
2072 "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
2073 "RotationSweep","RotationSweepObject","RotationSweepObject1D","RotationSweepObject2D",
2074 "ExtrusionSweep","AdvancedExtrusion","ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D",
2075 "ExtrusionAlongPath","ExtrusionAlongPathObject","ExtrusionAlongPathX",
2076 "ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D",
2077 "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
2078 "FindCoincidentNodes",/*"FindCoincidentNodesOnPart",*/"MergeNodes","FindEqualElements",
2079 "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
2080 "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
2081 "GetLastCreatedElems",
2082 "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
2083 "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh",
2084 "MakeBoundaryElements", "SplitVolumesIntoTetra"
2085 ,"" }; // <- mark of the end
2086 sameMethods.Insert( names );
2089 // names of SMESH_MeshEditor commands in which only a method name must be replaced
2090 TStringMap diffMethods;
2091 if ( diffMethods.empty() ) {
2092 const char * orig2newName[] = {
2093 // original name --------------> new name
2094 "ExtrusionAlongPathObjX" , "ExtrusionAlongPathX",
2095 "FindCoincidentNodesOnPartBut", "FindCoincidentNodesOnPart",
2096 "ConvertToQuadraticObject" , "ConvertToQuadratic",
2097 "ConvertFromQuadraticObject" , "ConvertFromQuadratic",
2098 "Create0DElementsOnAllNodes" , "Add0DElementsToAllNodes",
2099 ""};// <- mark of the end
2100 diffMethods.Insert( orig2newName );
2103 // names of SMESH_MeshEditor methods which differ from methods of Mesh class
2104 // only by last two arguments
2105 static TStringSet diffLastTwoArgsMethods;
2106 if (diffLastTwoArgsMethods.empty() ) {
2107 const char * names[] = {
2108 "MirrorMakeGroups","MirrorObjectMakeGroups",
2109 "TranslateMakeGroups","TranslateObjectMakeGroups",
2110 "RotateMakeGroups","RotateObjectMakeGroups",
2111 ""};// <- mark of the end
2112 diffLastTwoArgsMethods.Insert( names );
2115 // only a method name is to change?
2116 const TCollection_AsciiString & method = theCommand->GetMethod();
2117 bool isPyMeshMethod = sameMethods.Contains( method );
2118 if ( !isPyMeshMethod )
2120 TCollection_AsciiString newMethod = diffMethods.Value( method );
2121 if (( isPyMeshMethod = ( newMethod.Length() > 0 )))
2122 theCommand->SetMethod( newMethod );
2124 // ConvertToBiQuadratic(...) -> ConvertToQuadratic(...,True)
2125 if ( !isPyMeshMethod && (method == "ConvertToBiQuadratic" || method == "ConvertToBiQuadraticObject") )
2127 isPyMeshMethod = true;
2128 theCommand->SetMethod( method.SubString( 1, 9) + method.SubString( 12, method.Length()));
2129 theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
2132 if ( !isPyMeshMethod )
2134 // Replace SMESH_MeshEditor "*MakeGroups" functions by the Mesh
2135 // functions with the flag "theMakeGroups = True" like:
2136 // SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
2137 int pos = method.Search("MakeGroups");
2140 isPyMeshMethod = true;
2141 bool is0DmethId = ( method == "ExtrusionSweepMakeGroups0D" );
2142 bool is0DmethObj = ( method == "ExtrusionSweepObject0DMakeGroups");
2144 // 1. Remove "MakeGroups" from the Command
2145 TCollection_AsciiString aMethod = theCommand->GetMethod();
2146 int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
2149 pos = pos-2; //Remove "0D" from the Command too
2150 aMethod.Trunc(pos-1);
2151 theCommand->SetMethod(aMethod);
2153 // 2. And add last "True" argument(s)
2154 while(nbArgsToAdd--)
2155 theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
2156 if( is0DmethId || is0DmethObj )
2157 theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
2161 // ExtrusionSweep0D() -> ExtrusionSweep()
2162 // ExtrusionSweepObject0D() -> ExtrusionSweepObject()
2163 if ( !isPyMeshMethod && ( method == "ExtrusionSweep0D" ||
2164 method == "ExtrusionSweepObject0D" ))
2166 isPyMeshMethod = true;
2167 theCommand->SetMethod( method.SubString( 1, method.Length()-2));
2168 theCommand->SetArg(theCommand->GetNbArgs()+1,"False"); //sets flag "MakeGroups = False"
2169 theCommand->SetArg(theCommand->GetNbArgs()+1,"True"); //sets flag "IsNode = True"
2172 // DoubleNode...New(...) -> DoubleNode...(...,True)
2173 if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" ||
2174 method == "DoubleNodeElemGroupsNew" ||
2175 method == "DoubleNodeGroupNew" ||
2176 method == "DoubleNodeGroupsNew" ||
2177 method == "DoubleNodeElemGroup2New" ||
2178 method == "DoubleNodeElemGroups2New"))
2180 isPyMeshMethod = true;
2181 const int excessLen = 3 + int( method.Value( method.Length()-3 ) == '2' );
2182 theCommand->SetMethod( method.SubString( 1, method.Length()-excessLen));
2183 if ( excessLen == 3 )
2185 theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
2187 else if ( theCommand->GetArg(4) == "0" ||
2188 theCommand->GetArg(5) == "0" )
2190 // [ nothing, Group ] = DoubleNodeGroup2New(,,,False, True) ->
2191 // Group = DoubleNodeGroup2New(,,,False, True)
2192 _pyID groupID = theCommand->GetResultValue( 1 + int( theCommand->GetArg(4) == "0"));
2193 theCommand->SetResultValue( groupID );
2196 // FindAmongElementsByPoint(meshPart, x, y, z, elementType) ->
2197 // FindElementsByPoint(x, y, z, elementType, meshPart)
2198 if ( !isPyMeshMethod && method == "FindAmongElementsByPoint" )
2200 isPyMeshMethod = true;
2201 theCommand->SetMethod( "FindElementsByPoint" );
2202 // make the 1st arg be the last one
2203 _pyID partID = theCommand->GetArg( 1 );
2204 int nbArgs = theCommand->GetNbArgs();
2205 for ( int i = 2; i <= nbArgs; ++i )
2206 theCommand->SetArg( i-1, theCommand->GetArg( i ));
2207 theCommand->SetArg( nbArgs, partID );
2209 // Reorient2D( mesh, dir, face, point ) -> Reorient2D( mesh, dir, faceORpoint )
2210 if ( !isPyMeshMethod && method == "Reorient2D" )
2212 isPyMeshMethod = true;
2213 _AString mesh = theCommand->GetArg( 1 );
2214 _AString dir = theCommand->GetArg( 2 );
2215 _AString face = theCommand->GetArg( 3 );
2216 _AString point = theCommand->GetArg( 4 );
2217 theCommand->RemoveArgs();
2218 theCommand->SetArg( 1, mesh );
2219 theCommand->SetArg( 2, dir );
2220 if ( face.Value(1) == '-' || face.Value(1) == '0' ) // invalid: face <= 0
2221 theCommand->SetArg( 3, point );
2223 theCommand->SetArg( 3, face );
2226 if ( method == "QuadToTri" || method == "QuadToTriObject" )
2228 isPyMeshMethod = true;
2229 int crit_arg = theCommand->GetNbArgs();
2230 const _AString& crit = theCommand->GetArg(crit_arg);
2231 if (crit.Search("MaxElementLength2D") != -1)
2232 theCommand->SetArg(crit_arg, "");
2235 if ( isPyMeshMethod )
2237 theCommand->SetObject( myMesh );
2241 // editor creation command is needed only if any editor function is called
2242 theGen->AddMeshAccessorMethod( theCommand ); // for *Object() methods
2243 if ( !myCreationCmdStr.IsEmpty() ) {
2244 GetCreationCmd()->GetString() = myCreationCmdStr;
2245 myCreationCmdStr.Clear();
2250 //================================================================================
2252 * \brief Return true if my mesh can be removed
2254 //================================================================================
2256 bool _pyMeshEditor::CanClear()
2258 Handle(_pyMesh) mesh = ObjectToMesh( theGen->FindObject( myMesh ));
2259 return mesh.IsNull() ? true : mesh->CanClear();
2262 //================================================================================
2264 * \brief _pyHypothesis constructor
2265 * \param theCreationCmd -
2267 //================================================================================
2269 _pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
2270 _pyObject( theCreationCmd ), myCurCrMethod(0)
2272 myIsAlgo = myIsWrapped = /*myIsConverted = myIsLocal = myDim = */false;
2275 //================================================================================
2277 * \brief Creates algorithm or hypothesis
2278 * \param theCreationCmd - The engine command creating a hypothesis
2279 * \retval Handle(_pyHypothesis) - Result _pyHypothesis
2281 //================================================================================
2283 Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& theCreationCmd)
2285 // theCreationCmd: CreateHypothesis( "theHypType", "theLibName" )
2286 ASSERT (( theCreationCmd->GetMethod() == "CreateHypothesis"));
2288 Handle(_pyHypothesis) hyp, algo;
2291 const TCollection_AsciiString & hypTypeQuoted = theCreationCmd->GetArg( 1 );
2292 if ( hypTypeQuoted.IsEmpty() )
2295 TCollection_AsciiString hypType =
2296 hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
2298 algo = new _pyAlgorithm( theCreationCmd );
2299 hyp = new _pyHypothesis( theCreationCmd );
2301 if ( hypType == "NumberOfSegments" ) {
2302 hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
2303 hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
2304 // arg of SetNumberOfSegments() will become the 1-st arg of hyp creation command
2305 hyp->AddArgMethod( "SetNumberOfSegments" );
2306 // arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
2307 hyp->AddArgMethod( "SetScaleFactor" );
2308 hyp->AddArgMethod( "SetReversedEdges" );
2309 // same for ""CompositeSegment_1D:
2310 hyp->SetConvMethodAndType( "NumberOfSegments", "CompositeSegment_1D");
2311 hyp->AddArgMethod( "SetNumberOfSegments" );
2312 hyp->AddArgMethod( "SetScaleFactor" );
2313 hyp->AddArgMethod( "SetReversedEdges" );
2315 else if ( hypType == "SegmentLengthAroundVertex" ) {
2316 hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
2317 hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
2318 hyp->AddArgMethod( "SetLength" );
2319 // same for ""CompositeSegment_1D:
2320 hyp->SetConvMethodAndType( "LengthNearVertex", "CompositeSegment_1D");
2321 hyp->AddArgMethod( "SetLength" );
2323 else if ( hypType == "LayerDistribution2D" ) {
2324 hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get2DHypothesis" );
2325 hyp->SetConvMethodAndType( "LayerDistribution", "RadialQuadrangle_1D2D");
2327 else if ( hypType == "LayerDistribution" ) {
2328 hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get3DHypothesis" );
2329 hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
2331 else if ( hypType == "CartesianParameters3D" ) {
2332 hyp = new _pyComplexParamHypo( theCreationCmd );
2333 hyp->SetConvMethodAndType( "SetGrid", "Cartesian_3D");
2334 for ( int iArg = 0; iArg < 4; ++iArg )
2335 hyp->setCreationArg( iArg+1, "[]");
2339 hyp = theGen->GetHypothesisReader()->GetHypothesis( hypType, theCreationCmd );
2342 return algo->IsValid() ? algo : hyp;
2345 //================================================================================
2347 * \brief Returns true if addition of this hypothesis to a given mesh can be
2348 * wrapped into hypothesis creation
2350 //================================================================================
2352 bool _pyHypothesis::IsWrappable(const _pyID& theMesh) const
2354 if ( !myIsWrapped && myMesh == theMesh && IsInStudy() )
2356 Handle(_pyObject) pyMesh = theGen->FindObject( myMesh );
2357 if ( !pyMesh.IsNull() && pyMesh->IsInStudy() )
2363 //================================================================================
2365 * \brief Convert the command adding a hypothesis to mesh into a smesh command
2366 * \param theCmd - The command like mesh.AddHypothesis( geom, hypo )
2367 * \param theAlgo - The algo that can create this hypo
2368 * \retval bool - false if the command cant be converted
2370 //================================================================================
2372 bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
2373 const _pyID& theMesh)
2375 ASSERT(( theCmd->GetMethod() == "AddHypothesis" ));
2377 if ( !IsWrappable( theMesh ))
2380 myGeom = theCmd->GetArg( 1 );
2382 Handle(_pyHypothesis) algo;
2384 // find algo created on myGeom in theMesh
2385 algo = theGen->FindAlgo( myGeom, theMesh, this );
2386 if ( algo.IsNull() )
2388 // attach hypothesis creation command to be after algo creation command
2389 // because it can be new created instance of algorithm
2390 algo->GetCreationCmd()->AddDependantCmd( theCmd );
2394 // mesh.AddHypothesis(geom,hyp) --> hyp = <theMesh or algo>.myCreationMethod(args)
2395 theCmd->SetResultValue( GetID() );
2396 theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
2397 theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
2398 // set args (geom will be set by _pyMesh calling this method)
2399 theCmd->RemoveArgs();
2400 for ( size_t i = 0; i < myCurCrMethod->myArgs.size(); ++i ) {
2401 if ( !myCurCrMethod->myArgs[ i ].IsEmpty() )
2402 theCmd->SetArg( i+1, myCurCrMethod->myArgs[ i ]);
2404 theCmd->SetArg( i+1, "[]");
2406 // set a new creation command
2407 GetCreationCmd()->Clear();
2408 // replace creation command by wrapped instance
2409 // please note, that hypothesis attaches to algo creation command (see upper)
2410 SetCreationCmd( theCmd );
2413 // clear commands setting arg values
2414 list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
2415 for ( ; argCmd != myArgCommands.end(); ++argCmd )
2418 // set unknown arg commands after hypo creation
2419 Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
2420 list<Handle(_pyCommand)>::iterator cmd = myUnusedCommands.begin();
2421 for ( ; cmd != myUnusedCommands.end(); ++cmd ) {
2422 afterCmd->AddDependantCmd( *cmd );
2428 //================================================================================
2430 * \brief Remember hypothesis parameter values
2431 * \param theCommand - The called hypothesis method
2433 //================================================================================
2435 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
2437 ASSERT( !myIsAlgo );
2438 if ( !theGen->IsToKeepAllCommands() )
2439 rememberCmdOfParameter( theCommand );
2441 bool usedCommand = false;
2442 TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
2443 for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
2445 CreationMethod& crMethod = type2meth->second;
2446 for ( size_t i = 0; i < crMethod.myArgMethods.size(); ++i ) {
2447 if ( crMethod.myArgMethods[ i ] == theCommand->GetMethod() ) {
2449 myArgCommands.push_back( theCommand );
2451 while ( crMethod.myArgs.size() < i+1 )
2452 crMethod.myArgs.push_back( "[]" );
2453 crMethod.myArgs[ i ] = theCommand->GetArg( crMethod.myArgNb[i] );
2458 myUnusedCommands.push_back( theCommand );
2461 //================================================================================
2463 * \brief Finish conversion
2465 //================================================================================
2467 void _pyHypothesis::Flush()
2471 list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
2472 for ( ; cmd != myArgCommands.end(); ++cmd ) {
2473 // Add access to a wrapped mesh
2474 theGen->AddMeshAccessorMethod( *cmd );
2475 // Add access to a wrapped algorithm
2476 theGen->AddAlgoAccessorMethod( *cmd );
2478 cmd = myUnusedCommands.begin();
2479 for ( ; cmd != myUnusedCommands.end(); ++cmd ) {
2480 // Add access to a wrapped mesh
2481 theGen->AddMeshAccessorMethod( *cmd );
2482 // Add access to a wrapped algorithm
2483 theGen->AddAlgoAccessorMethod( *cmd );
2486 // forget previous hypothesis modifications
2487 myArgCommands.clear();
2488 myUnusedCommands.clear();
2491 //================================================================================
2493 * \brief clear creation, arg and unkown commands
2495 //================================================================================
2497 void _pyHypothesis::ClearAllCommands()
2499 GetCreationCmd()->Clear();
2500 list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
2501 for ( ; cmd != myArgCommands.end(); ++cmd )
2503 cmd = myUnusedCommands.begin();
2504 for ( ; cmd != myUnusedCommands.end(); ++cmd )
2509 //================================================================================
2511 * \brief Assign fields of theOther to me except myIsWrapped
2513 //================================================================================
2515 void _pyHypothesis::Assign( const Handle(_pyHypothesis)& theOther,
2516 const _pyID& theMesh )
2518 // myCreationCmd = theOther->myCreationCmd;
2519 myIsAlgo = theOther->myIsAlgo;
2520 myIsWrapped = false;
2521 myGeom = theOther->myGeom;
2523 myAlgoType2CreationMethod = theOther->myAlgoType2CreationMethod;
2524 myAccumulativeMethods = theOther->myAccumulativeMethods;
2525 //myUnusedCommands = theOther->myUnusedCommands;
2526 // init myCurCrMethod
2527 GetCreationMethod( theOther->GetAlgoType() );
2530 //================================================================================
2532 * \brief Analyze my erasability depending on myReferredObjs
2534 //================================================================================
2536 bool _pyHypothesis::CanClear()
2540 list< Handle(_pyObject) >::iterator obj = myReferredObjs.begin();
2541 for ( ; obj != myReferredObjs.end(); ++obj )
2542 if ( (*obj)->CanClear() )
2549 //================================================================================
2551 * \brief Clear my commands depending on usage by meshes
2553 //================================================================================
2555 void _pyHypothesis::ClearCommands()
2557 // if ( !theGen->IsToKeepAllCommands() )
2559 // bool isUsed = false;
2560 // int lastComputeOrder = 0;
2561 // list<Handle(_pyCommand) >::iterator cmd = myComputeCmds.begin();
2562 // for ( ; cmd != myComputeCmds.end(); ++cmd )
2563 // if ( ! (*cmd)->IsEmpty() )
2566 // if ( (*cmd)->GetOrderNb() > lastComputeOrder )
2567 // lastComputeOrder = (*cmd)->GetOrderNb();
2571 // SetRemovedFromStudy( true );
2575 // // clear my commands invoked after lastComputeOrder
2576 // // map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
2577 // // for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
2579 // // list< Handle(_pyCommand)> & cmds = m2c->second;
2580 // // if ( !cmds.empty() && cmds.back()->GetOrderNb() > lastComputeOrder )
2581 // // cmds.back()->Clear();
2585 _pyObject::ClearCommands();
2588 //================================================================================
2590 * \brief Find arguments that are objects like mesh, group, geometry
2591 * \param meshes - referred meshes (directly or indirrectly)
2592 * \retval bool - false if a referred geometry is not in the study
2594 //================================================================================
2596 bool _pyHypothesis::GetReferredMeshesAndGeom( list< Handle(_pyMesh) >& meshes )
2598 if ( IsAlgo() ) return true;
2600 bool geomPublished = true;
2601 vector< _AString > args;
2602 TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
2603 for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
2605 CreationMethod& crMethod = type2meth->second;
2606 args.insert( args.end(), crMethod.myArgs.begin(), crMethod.myArgs.end());
2608 list<Handle(_pyCommand)>::iterator cmd = myUnusedCommands.begin();
2609 for ( ; cmd != myUnusedCommands.end(); ++cmd ) {
2610 for ( int nb = (*cmd)->GetNbArgs(); nb; --nb )
2611 args.push_back( (*cmd)->GetArg( nb ));
2614 for ( size_t i = 0; i < args.size(); ++i )
2616 list< _pyID > idList = _pyCommand::GetStudyEntries( args[ i ]);
2617 if ( idList.empty() && !args[ i ].IsEmpty() )
2618 idList.push_back( args[ i ]);
2619 list< _pyID >::iterator id = idList.begin();
2620 for ( ; id != idList.end(); ++id )
2622 Handle(_pyObject) obj = theGen->FindObject( *id );
2623 if ( obj.IsNull() ) obj = theGen->FindHyp( *id );
2626 if ( theGen->IsGeomObject( *id ) && theGen->IsNotPublished( *id ))
2627 geomPublished = false;
2631 myReferredObjs.push_back( obj );
2632 Handle(_pyMesh) mesh = ObjectToMesh( obj );
2633 if ( !mesh.IsNull() )
2634 meshes.push_back( mesh );
2635 // prevent clearing not published hyps referred e.g. by "LayerDistribution"
2636 else if ( obj->IsKind( STANDARD_TYPE( _pyHypothesis )) && this->IsInStudy() )
2637 obj->SetRemovedFromStudy( false );
2641 return geomPublished;
2644 //================================================================================
2646 * \brief Remember theCommand setting a parameter
2648 //================================================================================
2650 void _pyHypothesis::rememberCmdOfParameter( const Handle(_pyCommand) & theCommand )
2652 // parameters are discriminated by method name
2653 _AString method = theCommand->GetMethod();
2654 if ( myAccumulativeMethods.count( method ))
2655 return; // this method adds values and not override the previus value
2657 // discriminate commands setting different parameters via one method
2658 // by passing parameter names like e.g. SetOption("size", "0.2")
2659 if ( theCommand->GetString().FirstLocationInSet( "'\"", 1, theCommand->Length() ) &&
2660 theCommand->GetNbArgs() > 1 )
2662 // mangle method by appending a 1st textual arg
2663 for ( int iArg = 1; iArg <= theCommand->GetNbArgs(); ++iArg )
2665 const TCollection_AsciiString& arg = theCommand->GetArg( iArg );
2666 if ( arg.Value(1) != '\"' && arg.Value(1) != '\'' ) continue;
2667 if ( !isalpha( arg.Value(2))) continue;
2672 // parameters are discriminated by method name
2673 list< Handle(_pyCommand)>& cmds = myMeth2Commands[ method /*theCommand->GetMethod()*/ ];
2674 if ( !cmds.empty() && !isCmdUsedForCompute( cmds.back() ))
2676 cmds.back()->Clear(); // previous parameter value has not been used
2677 cmds.back() = theCommand;
2681 cmds.push_back( theCommand );
2685 //================================================================================
2687 * \brief Return true if a setting parameter command ha been used to compute mesh
2689 //================================================================================
2691 bool _pyHypothesis::isCmdUsedForCompute( const Handle(_pyCommand) & cmd,
2692 _pyCommand::TAddr avoidComputeAddr ) const
2694 bool isUsed = false;
2695 map< _pyCommand::TAddr, list<Handle(_pyCommand) > >::const_iterator addr2cmds =
2696 myComputeAddr2Cmds.begin();
2697 for ( ; addr2cmds != myComputeAddr2Cmds.end() && !isUsed; ++addr2cmds )
2699 if ( addr2cmds->first == avoidComputeAddr ) continue;
2700 const list<Handle(_pyCommand)> & cmds = addr2cmds->second;
2701 isUsed = ( std::find( cmds.begin(), cmds.end(), cmd ) != cmds.end() );
2706 //================================================================================
2708 * \brief Save commands setting parameters as they are used for a mesh computation
2710 //================================================================================
2712 void _pyHypothesis::MeshComputed( const Handle(_pyCommand)& theComputeCmd )
2714 myComputeCmds.push_back( theComputeCmd );
2715 list<Handle(_pyCommand)>& savedCmds = myComputeAddr2Cmds[ theComputeCmd->GetAddress() ];
2717 map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
2718 for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
2719 savedCmds.push_back( m2c->second.back() );
2722 //================================================================================
2724 * \brief Clear commands setting parameters as a mesh computed using them is cleared
2726 //================================================================================
2728 void _pyHypothesis::ComputeDiscarded( const Handle(_pyCommand)& theComputeCmd )
2730 list<Handle(_pyCommand)>& savedCmds = myComputeAddr2Cmds[ theComputeCmd->GetAddress() ];
2732 list<Handle(_pyCommand)>::iterator cmd = savedCmds.begin();
2733 for ( ; cmd != savedCmds.end(); ++cmd )
2735 // check if a cmd has been used to compute another mesh
2736 if ( isCmdUsedForCompute( *cmd, theComputeCmd->GetAddress() ))
2738 // check if a cmd is a sole command setting its parameter;
2739 // don't use method name for search as it can change
2740 map<TCollection_AsciiString, list<Handle(_pyCommand)> >::iterator
2741 m2cmds = myMeth2Commands.begin();
2742 for ( ; m2cmds != myMeth2Commands.end(); ++m2cmds )
2744 list< Handle(_pyCommand)>& cmds = m2cmds->second;
2745 list< Handle(_pyCommand)>::iterator cmdIt = std::find( cmds.begin(), cmds.end(), *cmd );
2746 if ( cmdIt != cmds.end() )
2748 if ( cmds.back() != *cmd )
2750 cmds.erase( cmdIt );
2757 myComputeAddr2Cmds.erase( theComputeCmd->GetAddress() );
2760 //================================================================================
2762 * \brief Sets an argNb-th argument of current creation command
2763 * \param argNb - argument index countered from 1
2765 //================================================================================
2767 void _pyHypothesis::setCreationArg( const int argNb, const _AString& arg )
2769 if ( myCurCrMethod )
2771 while ( myCurCrMethod->myArgs.size() < argNb )
2772 myCurCrMethod->myArgs.push_back( "None" );
2773 if ( arg.IsEmpty() )
2774 myCurCrMethod->myArgs[ argNb-1 ] = "None";
2776 myCurCrMethod->myArgs[ argNb-1 ] = arg;
2781 //================================================================================
2783 * \brief Remember hypothesis parameter values
2784 * \param theCommand - The called hypothesis method
2786 //================================================================================
2788 void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
2790 if ( GetAlgoType() == "Cartesian_3D" )
2792 // CartesianParameters3D hyp
2794 if ( theCommand->GetMethod() == "SetSizeThreshold" )
2796 setCreationArg( 4, theCommand->GetArg( 1 ));
2797 myArgCommands.push_back( theCommand );
2800 if ( theCommand->GetMethod() == "SetGrid" ||
2801 theCommand->GetMethod() == "SetGridSpacing" )
2803 TCollection_AsciiString axis = theCommand->GetArg( theCommand->GetNbArgs() );
2804 int iArg = axis.Value(1) - '0';
2805 if ( theCommand->GetMethod() == "SetGrid" )
2807 setCreationArg( 1+iArg, theCommand->GetArg( 1 ));
2811 myCurCrMethod->myArgs[ iArg ] = "[ ";
2812 myCurCrMethod->myArgs[ iArg ] += theCommand->GetArg( 1 );
2813 myCurCrMethod->myArgs[ iArg ] += ", ";
2814 myCurCrMethod->myArgs[ iArg ] += theCommand->GetArg( 2 );
2815 myCurCrMethod->myArgs[ iArg ] += "]";
2817 myArgCommands.push_back( theCommand );
2818 rememberCmdOfParameter( theCommand );
2823 if( theCommand->GetMethod() == "SetLength" )
2825 // NOW it is OBSOLETE
2826 // ex: hyp.SetLength(start, 1)
2827 // hyp.SetLength(end, 0)
2828 ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
2829 int i = 1 - theCommand->GetArg( 2 ).IntegerValue();
2830 TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
2831 for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
2833 CreationMethod& crMethod = type2meth->second;
2834 while ( crMethod.myArgs.size() < i+1 )
2835 crMethod.myArgs.push_back( "[]" );
2836 crMethod.myArgs[ i ] = theCommand->GetArg( 1 ); // arg value
2838 myArgCommands.push_back( theCommand );
2842 _pyHypothesis::Process( theCommand );
2845 //================================================================================
2847 * \brief Clear SetObjectEntry() as it is called by methods of Mesh_Segment
2849 //================================================================================
2851 void _pyComplexParamHypo::Flush()
2855 list < Handle(_pyCommand) >::iterator cmd = myUnusedCommands.begin();
2856 for ( ; cmd != myUnusedCommands.end(); ++cmd )
2857 if ((*cmd)->GetMethod() == "SetObjectEntry" )
2862 //================================================================================
2864 * \brief Convert methods of 1D hypotheses to my own methods
2865 * \param theCommand - The called hypothesis method
2867 //================================================================================
2869 void _pyLayerDistributionHypo::Process( const Handle(_pyCommand)& theCommand)
2871 if ( theCommand->GetMethod() != "SetLayerDistribution" )
2874 const _pyID& hyp1dID = theCommand->GetArg( 1 );
2875 // Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
2876 // if ( hyp1d.IsNull() && ! my1dHyp.IsNull()) // apparently hypId changed at study restoration
2878 // TCollection_AsciiString cmd =
2879 // my1dHyp->GetCreationCmd()->GetIndentation() + hyp1dID + " = " + my1dHyp->GetID();
2880 // Handle(_pyCommand) newCmd = theGen->AddCommand( cmd );
2881 // theGen->SetCommandAfter( newCmd, my1dHyp->GetCreationCmd() );
2884 // else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() )
2886 // // 1D hypo is already set, so distribution changes and the old
2887 // // 1D hypo is thrown away
2888 // my1dHyp->ClearAllCommands();
2891 // //my1dHyp->SetRemovedFromStudy( false );
2893 // if ( !myArgCommands.empty() )
2894 // myArgCommands.back()->Clear();
2895 myCurCrMethod->myArgs.push_back( hyp1dID );
2896 myArgCommands.push_back( theCommand );
2899 //================================================================================
2902 * \param theAdditionCmd - command to be converted
2903 * \param theMesh - mesh instance
2904 * \retval bool - status
2906 //================================================================================
2908 bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
2909 const _pyID& theMesh)
2911 myIsWrapped = false;
2913 if ( my1dHyp.IsNull() )
2916 // set "SetLayerDistribution()" after addition cmd
2917 theAdditionCmd->AddDependantCmd( myArgCommands.front() );
2919 _pyID geom = theAdditionCmd->GetArg( 1 );
2921 Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
2922 if ( !algo.IsNull() )
2924 my1dHyp->SetMesh( theMesh );
2925 my1dHyp->SetConvMethodAndType(my1dHyp->GetAlgoCreationMethod().ToCString(),
2926 algo->GetAlgoType().ToCString());
2927 if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
2930 // clear "SetLayerDistribution()" cmd
2931 myArgCommands.back()->Clear();
2933 // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
2935 // find RadialPrism algo created on <geom> for theMesh
2936 GetCreationCmd()->SetObject( algo->GetID() );
2937 GetCreationCmd()->SetMethod( myAlgoMethod );
2938 GetCreationCmd()->RemoveArgs();
2939 theAdditionCmd->AddDependantCmd( GetCreationCmd() );
2945 //================================================================================
2949 //================================================================================
2951 void _pyLayerDistributionHypo::Flush()
2953 // as creation of 1D hyp was written later then it's edition,
2954 // we need to find all it's edition calls and process them
2955 list< Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
2957 for ( cmd = myArgCommands.begin(); cmd != myArgCommands.end(); ++cmd )
2959 const _pyID& hyp1dID = (*cmd)->GetArg( 1 );
2960 if ( hyp1dID.IsEmpty() ) continue;
2962 Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
2964 // make a new name for 1D hyp = "HypType" + "_Distribution"
2966 if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
2968 if ( prevNewName.IsEmpty() ) continue;
2969 newName = prevNewName;
2973 if ( hyp1d->IsWrapped() ) {
2974 newName = hyp1d->GetCreationCmd()->GetMethod();
2977 TCollection_AsciiString hypTypeQuoted = hyp1d->GetCreationCmd()->GetArg(1);
2978 newName = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
2980 newName += "_Distribution";
2981 prevNewName = newName;
2983 hyp1d->GetCreationCmd()->SetResultValue( newName );
2985 list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
2986 list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
2987 for ( ; cmdIt != cmds.end(); ++cmdIt ) {
2988 const _pyID& objID = (*cmdIt)->GetObject();
2989 if ( objID == hyp1dID ) {
2990 if ( !hyp1d.IsNull() )
2992 hyp1d->Process( *cmdIt );
2993 hyp1d->GetCreationCmd()->AddDependantCmd( *cmdIt );
2995 ( *cmdIt )->SetObject( newName );
2998 // Set new hyp name to SetLayerDistribution(hyp1dID) cmd
2999 (*cmd)->SetArg( 1, newName );
3003 //================================================================================
3005 * \brief additionally to Addition2Creation, clears SetDistrType() command
3006 * \param theCmd - AddHypothesis() command
3007 * \param theMesh - mesh to which a hypothesis is added
3008 * \retval bool - convertion result
3010 //================================================================================
3012 bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
3013 const _pyID& theMesh)
3015 if ( IsWrappable( theMesh ) && myCurCrMethod->myArgs.size() > 1 ) {
3016 // scale factor (2-nd arg) is provided: clear SetDistrType(1) command
3017 bool scaleDistrType = false;
3018 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnusedCommands.rbegin();
3019 for ( ; cmd != myUnusedCommands.rend(); ++cmd ) {
3020 if ( (*cmd)->GetMethod() == "SetDistrType" ) {
3021 if ( (*cmd)->GetArg( 1 ) == "1" ) {
3022 scaleDistrType = true;
3025 else if ( !scaleDistrType ) {
3026 // distribution type changed: remove scale factor from args
3027 TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
3028 for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
3030 CreationMethod& crMethod = type2meth->second;
3031 if ( crMethod.myArgs.size() == 2 )
3032 crMethod.myArgs.pop_back();
3039 return _pyHypothesis::Addition2Creation( theCmd, theMesh );
3042 //================================================================================
3044 * \brief remove repeated commands defining distribution
3046 //================================================================================
3048 void _pyNumberOfSegmentsHyp::Flush()
3050 // find number of the last SetDistrType() command
3051 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnusedCommands.rbegin();
3052 int distrTypeNb = 0;
3053 for ( ; !distrTypeNb && cmd != myUnusedCommands.rend(); ++cmd )
3054 if ( (*cmd)->GetMethod() == "SetDistrType" ) {
3055 if ( cmd != myUnusedCommands.rbegin() )
3056 distrTypeNb = (*cmd)->GetOrderNb();
3058 else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" ) {
3061 // clear commands before the last SetDistrType()
3062 list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnusedCommands };
3063 set< int > treatedCmdNbs; // avoid treating same cmd twice
3064 for ( int i = 0; i < 2; ++i ) {
3065 set<TCollection_AsciiString> uniqueMethods;
3066 list<Handle(_pyCommand)> & cmdList = *cmds[i];
3067 for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
3069 if ( !treatedCmdNbs.insert( (*cmd)->GetOrderNb() ).second )
3070 continue;// avoid treating same cmd twice
3071 bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
3072 const TCollection_AsciiString& method = (*cmd)->GetMethod();
3073 if ( !clear || method == "SetNumberOfSegments" ) {
3074 bool isNewInSet = uniqueMethods.insert( method ).second;
3075 clear = !isNewInSet;
3084 //================================================================================
3086 * \brief Convert the command adding "SegmentLengthAroundVertex" to mesh
3087 * into regular1D.LengthNearVertex( length, vertex )
3088 * \param theCmd - The command like mesh.AddHypothesis( vertex, SegmentLengthAroundVertex )
3089 * \param theMesh - The mesh needing this hypo
3090 * \retval bool - false if the command cant be converted
3092 //================================================================================
3094 bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
3095 const _pyID& theMeshID)
3097 if ( IsWrappable( theMeshID )) {
3099 _pyID vertex = theCmd->GetArg( 1 );
3101 // the problem here is that segment algo will not be found
3102 // by pyHypothesis::Addition2Creation() for <vertex>, so we try to find
3103 // geometry where segment algorithm is assigned
3104 Handle(_pyHypothesis) algo;
3105 _pyID geom = vertex;
3106 while ( algo.IsNull() && !geom.IsEmpty()) {
3107 // try to find geom as a father of <vertex>
3108 geom = FatherID( geom );
3109 algo = theGen->FindAlgo( geom, theMeshID, this );
3111 if ( algo.IsNull() )
3112 return false; // also possible to find geom as brother of veretex...
3113 // set geom instead of vertex
3114 theCmd->SetArg( 1, geom );
3116 // set vertex as a second arg
3117 if ( myCurCrMethod->myArgs.size() < 1) setCreationArg( 1, "1" ); // :(
3118 setCreationArg( 2, vertex );
3120 // mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) -->
3121 // theMeshID.LengthNearVertex( length, vertex )
3122 return _pyHypothesis::Addition2Creation( theCmd, theMeshID );
3127 //================================================================================
3129 * \brief _pyAlgorithm constructor
3130 * \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)"
3132 //========================