1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 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
24 // File : SMESH_2D_Algo_i.hxx
25 // Author : Paul RASCLE, EDF
29 // File : SMESH_2smeshpy.cxx
30 // Created : Fri Nov 18 13:20:10 2005
31 // Author : Edward AGAPOV (eap)
33 #include "SMESH_2smeshpy.hxx"
35 #include "utilities.h"
36 #include "SMESH_PythonDump.hxx"
37 #include "SMESH_NoteBook.hxx"
38 #include "Resource_DataMapOfAsciiStringAsciiString.hxx"
40 #include "SMESH_Gen_i.hxx"
41 /* SALOME headers that include CORBA headers that include windows.h
42 * that defines GetObject symbol as GetObjectA should stand before SALOME headers
43 * that declare methods named GetObject - to apply the same rules of GetObject renaming
44 * and thus to avoid mess with GetObject symbol on Windows */
46 IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient);
47 IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
48 IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject);
49 IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject);
50 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor ,_pyObject);
51 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis ,_pyObject);
52 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
53 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
54 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis);
56 IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient);
57 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient);
58 IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject);
59 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject);
60 IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject);
61 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject);
62 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis);
63 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
64 IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis);
65 IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis);
66 IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis);
69 using SMESH::TPythonDump;
72 * \brief Container of commands into which the initial script is split.
73 * It also contains data coresponding to SMESH_Gen contents
75 static Handle(_pyGen) theGen;
77 static TCollection_AsciiString theEmptyString;
79 //#define DUMP_CONVERSION
81 #if !defined(_DEBUG_) && defined(DUMP_CONVERSION)
82 #undef DUMP_CONVERSION
88 //================================================================================
90 * \brief Set of TCollection_AsciiString initialized by C array of C strings
92 //================================================================================
94 struct TStringSet: public set<TCollection_AsciiString>
97 * \brief Filling. The last string must be ""
99 void Insert(const char* names[]) {
100 for ( int i = 0; names[i][0] ; ++i )
101 insert( (char*) names[i] );
104 * \brief Check if a string is in
106 bool Contains(const TCollection_AsciiString& name ) {
107 return find( name ) != end();
112 //================================================================================
114 * \brief Convert python script using commands of smesh.py
115 * \param theScript - Input script
116 * \retval TCollection_AsciiString - Convertion result
118 * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
120 //================================================================================
122 TCollection_AsciiString
123 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
124 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
126 theGen = new _pyGen( theEntry2AccessorMethod );
128 SMESH_NoteBook * aNoteBook = new SMESH_NoteBook();
130 int from = 1, end = theScript.Length(), to;
131 while ( from < end && ( to = theScript.Location( "\n", from, end )))
134 // cut out and store a command
135 aNoteBook->AddCommand( theScript.SubString( from, to - 1 ));
139 aNoteBook->ReplaceVariables();
141 TCollection_AsciiString aNoteScript = aNoteBook->GetResultScript();
145 // split theScript into separate commands
146 from = 1, end = aNoteScript.Length();
147 while ( from < end && ( to = aNoteScript.Location( "\n", from, end )))
150 // cut out and store a command
151 theGen->AddCommand( aNoteScript.SubString( from, to - 1 ));
156 #ifdef DUMP_CONVERSION
157 MESSAGE_BEGIN ( std::endl << " ######## RESULT ######## " << std::endl<< std::endl );
159 // reorder commands after conversion
160 list< Handle(_pyCommand) >::iterator cmd;
163 orderChanges = false;
164 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
165 if ( (*cmd)->SetDependentCmdsAfter() )
167 } while ( orderChanges );
169 // concat commands back into a script
170 TCollection_AsciiString aScript;
171 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
173 #ifdef DUMP_CONVERSION
174 MESSAGE_ADD ( "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << std::endl );
176 if ( !(*cmd)->IsEmpty() ) {
178 aScript += (*cmd)->GetString();
188 //================================================================================
190 * \brief _pyGen constructor
192 //================================================================================
194 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
195 : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
196 myID2AccessorMethod( theEntry2AccessorMethod )
199 myHasPattern = false;
200 // make that GetID() to return TPythonDump::SMESHGenName()
201 GetCreationCmd()->GetString() += "=";
204 //================================================================================
206 * \brief name of SMESH_Gen in smesh.py
208 //================================================================================
210 const char* _pyGen::AccessorMethod() const
212 return SMESH_2smeshpy::GenName();
215 //================================================================================
217 * \brief Convert a command using a specific converter
218 * \param theCommand - the command to convert
220 //================================================================================
222 Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
224 // store theCommand in the sequence
225 myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
227 Handle(_pyCommand) aCommand = myCommands.back();
228 #ifdef DUMP_CONVERSION
229 MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
232 _pyID objID = aCommand->GetObject();
234 if ( objID.IsEmpty() )
238 if ( objID == this->GetID() ) {
239 this->Process( aCommand );
242 // SMESH_Mesh method?
243 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
244 if ( id_mesh != myMeshes.end() ) {
245 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
246 _pyID editorID = aCommand->GetResultValue();
247 Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
248 myMeshEditors.insert( make_pair( editorID, editor ));
251 id_mesh->second->Process( aCommand );
254 // SMESH_MeshEditor method?
255 map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
256 if ( id_editor != myMeshEditors.end() ) {
257 id_editor->second->Process( aCommand );
260 // SMESH_Hypothesis method?
261 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
262 for ( ; hyp != myHypos.end(); ++hyp )
263 if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
264 (*hyp)->Process( aCommand );
268 // Add access to a wrapped mesh
269 AddMeshAccessorMethod( aCommand );
271 // Add access to a wrapped algorithm
272 // AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
274 // PAL12227. PythonDump was not updated at proper time; result is
275 // aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
276 // TypeError: __init__() takes exactly 11 arguments (10 given)
277 char wrongCommand[] = "SMESH.Filter.Criterion(";
278 if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
280 _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
281 // there must be 10 arguments, 5-th arg ThresholdID is missing,
282 const int wrongNbArgs = 9, missingArg = 5;
283 if ( tmpCmd.GetNbArgs() == wrongNbArgs )
285 for ( int i = wrongNbArgs; i > missingArg; --i )
286 tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
287 tmpCmd.SetArg( missingArg, "''");
288 aCommand->GetString().Trunc( beg - 1 );
289 aCommand->GetString() += tmpCmd.GetString();
295 //================================================================================
297 * \brief Convert the command or remember it for later conversion
298 * \param theCommand - The python command calling a method of SMESH_Gen
300 //================================================================================
302 void _pyGen::Process( const Handle(_pyCommand)& theCommand )
304 // there are methods to convert:
305 // CreateMesh( shape )
306 // Concatenate( [mesh1, ...], ... )
307 // CreateHypothesis( theHypType, theLibName )
308 // Compute( mesh, geom )
310 if ( theCommand->GetMethod() == "CreateMesh" ||
311 theCommand->GetMethod() == "CreateEmptyMesh" ||
312 theCommand->GetMethod() == "CreateMeshesFromUNV" ||
313 theCommand->GetMethod() == "CreateMeshesFromSTL")
315 Handle(_pyMesh) mesh = new _pyMesh( theCommand );
316 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
320 if(theCommand->GetMethod() == "CreateMeshesFromMED")
322 for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
324 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
325 myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));
329 // CreateHypothesis()
330 if ( theCommand->GetMethod() == "CreateHypothesis" )
332 myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
336 // smeshgen.Compute( mesh, geom ) --> mesh.Compute()
337 if ( theCommand->GetMethod() == "Compute" )
339 const _pyID& meshID = theCommand->GetArg( 1 );
340 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
341 if ( id_mesh != myMeshes.end() ) {
342 theCommand->SetObject( meshID );
343 theCommand->RemoveArgs();
344 id_mesh->second->Flush();
349 // leave only one smeshgen.GetPattern() in the script
350 if ( theCommand->GetMethod() == "GetPattern" ) {
351 if ( myHasPattern ) {
358 // Concatenate( [mesh1, ...], ... )
359 if ( theCommand->GetMethod() == "Concatenate" ||
360 theCommand->GetMethod() == "ConcatenateWithGroups")
362 AddMeshAccessorMethod( theCommand );
365 // Replace name of SMESH_Gen
367 // names of SMESH_Gen methods fully equal to methods defined in smesh.py
368 static TStringSet smeshpyMethods;
369 if ( smeshpyMethods.empty() ) {
370 const char * names[] =
371 { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
372 "GetPattern","GetSubShapesId",
373 "" }; // <- mark of array end
374 smeshpyMethods.Insert( names );
376 if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
377 // smeshgen.Method() --> smesh.Method()
378 theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
380 // smeshgen.Method() --> smesh.smesh.Method()
381 theCommand->SetObject( SMESH_2smeshpy::GenName() );
384 //================================================================================
386 * \brief Convert the remembered commands
388 //================================================================================
392 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
393 for ( ; id_mesh != myMeshes.end(); ++id_mesh )
394 if ( ! id_mesh->second.IsNull() )
395 id_mesh->second->Flush();
397 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
398 for ( ; hyp != myHypos.end(); ++hyp )
399 if ( !hyp->IsNull() ) {
401 // smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
402 if ( !(*hyp)->IsWrapped() )
403 (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
407 //================================================================================
409 * \brief Add access method to mesh that is an argument
410 * \param theCmd - command to add access method
411 * \retval bool - true if added
413 //================================================================================
415 bool _pyGen::AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const
418 map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
419 for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
420 if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
426 //================================================================================
428 * \brief Add access method to algo that is an object or an argument
429 * \param theCmd - command to add access method
430 * \retval bool - true if added
432 //================================================================================
434 bool _pyGen::AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const
437 list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
438 for ( ; hyp != myHypos.end(); ++hyp ) {
439 if ( (*hyp)->IsAlgo() && /*(*hyp)->IsWrapped() &&*/
440 theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
446 //================================================================================
448 * \brief Find hypothesis by ID (entry)
449 * \param theHypID - The hypothesis ID
450 * \retval Handle(_pyHypothesis) - The found hypothesis
452 //================================================================================
454 Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
456 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
457 for ( ; hyp != myHypos.end(); ++hyp )
458 if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
460 return Handle(_pyHypothesis)();
463 //================================================================================
465 * \brief Find algorithm the created algorithm
466 * \param theGeom - The shape ID the algorithm was created on
467 * \param theMesh - The mesh ID that created the algorithm
468 * \param dim - The algo dimension
469 * \retval Handle(_pyHypothesis) - The found algo
471 //================================================================================
473 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
474 const Handle(_pyHypothesis)& theHypothesis )
476 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
477 for ( ; hyp != myHypos.end(); ++hyp )
478 if ( !hyp->IsNull() &&
480 theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
481 (*hyp)->GetGeom() == theGeom &&
482 (*hyp)->GetMesh() == theMesh )
487 //================================================================================
489 * \brief Change order of commands in the script
490 * \param theCmd1 - One command
491 * \param theCmd2 - Another command
493 //================================================================================
495 void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 )
497 list< Handle(_pyCommand) >::iterator pos1, pos2;
498 pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
499 pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
500 myCommands.insert( pos1, theCmd2 );
501 myCommands.insert( pos2, theCmd1 );
502 myCommands.erase( pos1 );
503 myCommands.erase( pos2 );
505 int nb1 = theCmd1->GetOrderNb();
506 theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
507 theCmd2->SetOrderNb( nb1 );
508 // cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
509 // << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
512 //================================================================================
514 * \brief Set one command after the other
515 * \param theCmd - Command to move
516 * \param theAfterCmd - Command ater which to insert the first one
518 //================================================================================
520 void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
523 //cout << "SET\t" << theAfterCmd->GetString() << endl << "BEFORE\t" << theCmd->GetString() << endl<<endl;
525 list< Handle(_pyCommand) >::iterator pos;
526 pos = find( myCommands.begin(), myCommands.end(), theCmd );
527 myCommands.erase( pos );
528 pos = find( myCommands.begin(), myCommands.end(), theAfterCmd );
529 myCommands.insert( ++pos, theCmd );
532 for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
533 (*pos)->SetOrderNb( i++ );
536 //================================================================================
538 * \brief Set method to access to object wrapped with python class
539 * \param theID - The wrapped object entry
540 * \param theMethod - The accessor method
542 //================================================================================
544 void _pyGen::SetAccessorMethod(const _pyID& theID, const char* theMethod )
546 myID2AccessorMethod.Bind( theID, (char*) theMethod );
549 //================================================================================
551 * \brief Find out type of geom group
552 * \param grpID - The geom group entry
553 * \retval int - The type
555 //================================================================================
557 static bool sameGroupType( const _pyID& grpID,
558 const TCollection_AsciiString& theType)
560 // define group type as smesh.Mesh.Group() does
562 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
563 SALOMEDS::SObject_var aSObj = study->FindObjectID( grpID.ToCString() );
564 if ( !aSObj->_is_nil() ) {
565 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
566 if ( !aGeomObj->_is_nil() ) {
567 switch ( aGeomObj->GetShapeType() ) {
568 case GEOM::VERTEX: type = SMESH::NODE; break;
569 case GEOM::EDGE: type = SMESH::EDGE; break;
570 case GEOM::FACE: type = SMESH::FACE; break;
572 case GEOM::SHELL: type = SMESH::VOLUME; break;
573 case GEOM::COMPOUND: {
574 GEOM::GEOM_Gen_ptr aGeomGen = SMESH_Gen_i::GetSMESHGen()->GetGeomEngine();
575 if ( !aGeomGen->_is_nil() ) {
576 GEOM::GEOM_IGroupOperations_var aGrpOp =
577 aGeomGen->GetIGroupOperations( study->StudyId() );
578 if ( !aGrpOp->_is_nil() ) {
579 switch ( aGrpOp->GetType( aGeomObj )) {
580 case TopAbs_VERTEX: type = SMESH::NODE; break;
581 case TopAbs_EDGE: type = SMESH::EDGE; break;
582 case TopAbs_FACE: type = SMESH::FACE; break;
583 case TopAbs_SOLID: type = SMESH::VOLUME; break;
594 MESSAGE("Type of the group " << grpID << " not found");
597 if ( theType.IsIntegerValue() )
598 return type == theType.IntegerValue();
601 case SMESH::NODE: return theType.Location( "NODE", 1, theType.Length() );
602 case SMESH::EDGE: return theType.Location( "EDGE", 1, theType.Length() );
603 case SMESH::FACE: return theType.Location( "FACE", 1, theType.Length() );
604 case SMESH::VOLUME: return theType.Location( "VOLUME", 1, theType.Length() );
610 //================================================================================
613 * \param theCreationCmd -
615 //================================================================================
617 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd):
618 _pyObject(theCreationCmd), myHasEditor(false)
620 // convert my creation command
621 Handle(_pyCommand) creationCmd = GetCreationCmd();
622 TCollection_AsciiString str = creationCmd->GetMethod();
624 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
625 if(str != "CreateMeshesFromUNV" &&
626 str != "CreateMeshesFromMED" &&
627 str != "CreateMeshesFromSTL")
628 creationCmd->SetMethod( "Mesh" );
630 theGen->SetAccessorMethod( GetID(), "GetMesh()" );
633 //================================================================================
636 * \param theCreationCmd -
638 //================================================================================
639 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString& id):
640 _pyObject(theCreationCmd), myHasEditor(false)
642 // convert my creation command
643 Handle(_pyCommand) creationCmd = GetCreationCmd();
644 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
645 theGen->SetAccessorMethod( id, "GetMesh()" );
648 //================================================================================
650 * \brief Convert a IDL API command of SMESH::Mesh to a method call of python Mesh
651 * \param theCommand - Engine method called for this mesh
653 //================================================================================
655 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
657 // some methods of SMESH_Mesh interface needs special conversion
658 // to methods of Mesh python class
660 // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
661 // --> in Mesh_Algorithm.Create(mesh, geom, hypo, so)
662 // 2. AddHypothesis(geom, hyp)
663 // --> in Mesh_Algorithm.Hypothesis(hyp, args, so)
664 // 3. CreateGroupFromGEOM(type, name, grp)
665 // --> in Mesh.Group(grp, name="")
666 // 4. ExportToMED(f, auto_groups, version)
667 // --> in Mesh.ExportMED( f, auto_groups, version )
670 const TCollection_AsciiString method = theCommand->GetMethod();
671 // ----------------------------------------------------------------------
672 if ( method == "GetSubMesh" ) {
673 mySubmeshes.push_back( theCommand );
675 // ----------------------------------------------------------------------
676 else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO )
677 myAddHypCmds.push_back( theCommand );
679 const _pyID& hypID = theCommand->GetArg( 2 );
680 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
681 if ( !hyp.IsNull() ) {
682 myHypos.push_back( hyp );
683 if ( hyp->GetMesh().IsEmpty() )
684 hyp->SetMesh( this->GetID() );
687 // ----------------------------------------------------------------------
688 else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
689 _pyID grp = theCommand->GetArg( 3 );
690 if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
691 theCommand->SetMethod( "Group" );
692 theCommand->RemoveArgs();
693 theCommand->SetArg( 1, grp );
696 AddMeshAccess( theCommand );
699 // ----------------------------------------------------------------------
700 else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
701 theCommand->SetMethod( "ExportMED" );
703 // ----------------------------------------------------------------------
704 else if ( method == "CreateGroup" ) { // CreateGroup() --> CreateEmptyGroup()
705 theCommand->SetMethod( "CreateEmptyGroup" );
707 // ----------------------------------------------------------------------
708 else if ( method == "RemoveHypothesis" ) // (geom, hyp)
710 _pyID hypID = theCommand->GetArg( 2 );
712 // check if this mesh still has corresponding addition command
713 bool hasAddCmd = false;
714 list< Handle(_pyCommand) >::iterator cmd = myAddHypCmds.begin();
715 while ( cmd != myAddHypCmds.end() )
717 // AddHypothesis(geom, hyp)
718 if ( hypID == (*cmd)->GetArg( 2 )) { // erase both (add and remove) commands
721 cmd = myAddHypCmds.erase( cmd );
728 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
729 if ( ! hasAddCmd && hypID.Length() != 0 ) { // hypo addition already wrapped
730 // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
731 _pyID geom = theCommand->GetArg( 1 );
732 theCommand->RemoveArgs();
733 theCommand->SetArg( 1, hypID );
734 if ( geom != GetGeom() )
735 theCommand->SetArg( 2, geom );
737 // remove hyp from myHypos
738 myHypos.remove( hyp );
740 // add accessor method if necessary
743 if ( NeedMeshAccess( theCommand ))
744 // apply theCommand to the mesh wrapped by smeshpy mesh
745 AddMeshAccess( theCommand );
749 //================================================================================
751 * \brief Return True if addition of accesor method is needed
753 //================================================================================
755 bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
757 // names of SMESH_Mesh methods fully equal to methods of class Mesh, so
758 // no conversion is needed for them at all:
759 static TStringSet sameMethods;
760 if ( sameMethods.empty() ) {
761 const char * names[] =
762 { "ExportDAT","ExportUNV","ExportSTL", "RemoveGroup","RemoveGroupWithContents",
763 "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
764 "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
765 "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
766 "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
767 "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
768 "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
769 "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
770 "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
771 "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
772 "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
773 "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
775 ,"" }; // <- mark of end
776 sameMethods.Insert( names );
779 return !sameMethods.Contains( theCommand->GetMethod() );
782 //================================================================================
784 * \brief Convert creation and addition of all algos and hypos
786 //================================================================================
788 void _pyMesh::Flush()
790 list < Handle(_pyCommand) >::iterator cmd, cmd2;
792 // try to convert algo addition like this:
793 // mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
794 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
796 Handle(_pyCommand) addCmd = *cmd;
797 _pyID algoID = addCmd->GetArg( 2 );
798 Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
799 if ( algo.IsNull() || !algo->IsAlgo() )
802 _pyID geom = addCmd->GetArg( 1 );
803 bool isLocalAlgo = ( geom != GetGeom() );
804 if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
806 // wrapped algo is created atfer mesh creation
807 GetCreationCmd()->AddDependantCmd( addCmd );
810 // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
811 addCmd->SetArg( addCmd->GetNbArgs() + 1,
812 TCollection_AsciiString( "geom=" ) + geom );
813 // sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
814 for ( cmd2 = mySubmeshes.begin(); cmd2 != mySubmeshes.end(); ++cmd2 ) {
815 Handle(_pyCommand) subCmd = *cmd2;
816 if ( geom == subCmd->GetArg( 1 )) {
817 subCmd->SetObject( algo->GetID() );
818 subCmd->RemoveArgs();
819 addCmd->AddDependantCmd( subCmd );
824 else // KO - ALGO was already created
826 // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
827 addCmd->RemoveArgs();
828 addCmd->SetArg( 1, algoID );
830 addCmd->SetArg( 2, geom );
834 // try to convert hypo addition like this:
835 // mesh.AddHypothesis(geom, HYPO ) --> HYPO = algo.Hypo()
836 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
838 Handle(_pyCommand) addCmd = *cmd;
839 _pyID hypID = addCmd->GetArg( 2 );
840 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
841 if ( hyp.IsNull() || hyp->IsAlgo() )
843 bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
845 // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
846 _pyID geom = addCmd->GetArg( 1 );
847 addCmd->RemoveArgs();
848 addCmd->SetArg( 1, hypID );
849 if ( geom != GetGeom() )
850 addCmd->SetArg( 2, geom );
854 // sm = mesh.GetSubMesh(geom, name) --> sm = mesh.GetMesh().GetSubMesh(geom, name)
855 // for ( cmd = mySubmeshes.begin(); cmd != mySubmeshes.end(); ++cmd ) {
856 // Handle(_pyCommand) subCmd = *cmd;
857 // if ( subCmd->GetNbArgs() > 0 )
858 // AddMeshAccess( subCmd );
860 myAddHypCmds.clear();
864 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
865 for ( ; hyp != myHypos.end(); ++hyp )
869 //================================================================================
871 * \brief MeshEditor convert its commands to ones of mesh
873 //================================================================================
875 _pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
876 _pyObject( theCreationCmd )
878 myMesh = theCreationCmd->GetObject();
879 myCreationCmdStr = theCreationCmd->GetString();
880 theCreationCmd->Clear();
883 //================================================================================
885 * \brief convert its commands to ones of mesh
887 //================================================================================
889 void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
891 // names of SMESH_MeshEditor methods fully equal to methods of class Mesh, so
892 // commands calling this methods are converted to calls of methods of Mesh
893 static TStringSet sameMethods;
894 if ( sameMethods.empty() ) {
895 const char * names[] = {
896 "RemoveElements","RemoveNodes","AddNode","AddEdge","AddFace","AddPolygonalFace",
897 "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode", "MoveClosestNodeToPoint",
898 "InverseDiag","DeleteDiag","Reorient","ReorientObject","TriToQuad","SplitQuad","SplitQuadObject",
899 "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
900 "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
901 "RotationSweep","RotationSweepObject","ExtrusionSweep","AdvancedExtrusion",
902 "ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D","ExtrusionAlongPath",
903 "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
904 "FindCoincidentNodes","FindCoincidentNodesOnPart","MergeNodes","FindEqualElements",
905 "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
906 "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
907 "GetLastCreatedElems",
908 "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
909 "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh"
910 ,"" }; // <- mark of the end
911 sameMethods.Insert( names );
914 // names of SMESH_MeshEditor methods which differ from methods of class Mesh
915 // only last two arguments
916 static TStringSet diffLastTwoArgsMethods;
917 if (diffLastTwoArgsMethods.empty() ){
918 const char * names[] = {
919 "MirrorMakeGroups","MirrorObjectMakeGroups",
920 "TranslateMakeGroups","TranslateObjectMakeGroups",
921 "RotateMakeGroups","RotateObjectMakeGroups",
922 ""};// <- mark of the end
923 diffLastTwoArgsMethods.Insert( names );
926 if ( sameMethods.Contains( theCommand->GetMethod() )) {
927 theCommand->SetObject( myMesh );
929 // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
930 // so let _pyMesh care of it (TMP?)
931 if ( theCommand->GetMethod().Search("MakeMesh") != -1 )
932 _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod()
936 //Replace SMESH_MeshEditor "MakeGroups" functions on the Mesh
937 //functions with the flag "theMakeGroups = True" like:
938 //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
939 int pos = theCommand->GetMethod().Search("MakeGroups");
941 // 1. Remove "MakeGroups" from the Command
942 TCollection_AsciiString aMethod = theCommand->GetMethod();
943 int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
944 aMethod.Trunc(pos-1);
945 theCommand->SetMethod(aMethod);
947 // 2. Set Mesh object instead SMESH_MeshEditor
948 theCommand->SetObject( myMesh );
950 // 3. And add last "True" argument
952 theCommand->SetArg(theCommand->GetNbArgs()+1,"True ");
955 // editor creation command is needed only if any editor function is called
956 theGen->AddMeshAccessorMethod( theCommand ); // for *Object()
957 if ( !myCreationCmdStr.IsEmpty() ) {
958 GetCreationCmd()->GetString() = myCreationCmdStr;
959 myCreationCmdStr.Clear();
965 //================================================================================
967 * \brief _pyHypothesis constructor
968 * \param theCreationCmd -
970 //================================================================================
972 _pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
973 _pyObject( theCreationCmd )
975 myIsAlgo = myIsWrapped = /*myIsConverted = myIsLocal = myDim = */false;
978 //================================================================================
980 * \brief Creates algorithm or hypothesis
981 * \param theCreationCmd - The engine command creating a hypothesis
982 * \retval Handle(_pyHypothesis) - Result _pyHypothesis
984 //================================================================================
986 Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& theCreationCmd)
988 // theCreationCmd: CreateHypothesis( "theHypType", "theLibName" )
989 ASSERT (( theCreationCmd->GetMethod() == "CreateHypothesis"));
991 Handle(_pyHypothesis) hyp, algo;
994 const TCollection_AsciiString & hypTypeQuoted = theCreationCmd->GetArg( 1 );
995 if ( hypTypeQuoted.IsEmpty() )
998 TCollection_AsciiString hypType =
999 hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
1001 algo = new _pyAlgorithm( theCreationCmd );
1002 hyp = new _pyHypothesis( theCreationCmd );
1004 // 1D Regular_1D ----------
1005 if ( hypType == "Regular_1D" ) {
1006 // set mesh's method creating algo,
1007 // i.e. convertion result will be "regular1d = Mesh.Segment()",
1008 // and set hypType by which algo creating a hypothesis is searched for
1009 algo->SetConvMethodAndType("Segment", hypType.ToCString());
1011 else if ( hypType == "CompositeSegment_1D" ) {
1012 algo->SetConvMethodAndType("Segment", "Regular_1D");
1013 algo->myArgs.Append( "algo=smesh.COMPOSITE");
1015 else if ( hypType == "LocalLength" ) {
1016 // set algo's method creating hyp, and algo type
1017 hyp->SetConvMethodAndType( "LocalLength", "Regular_1D");
1018 // set method whose 1 arg will become the 1-st arg of hyp creation command
1019 // i.e. convertion result will be "locallength = regular1d.LocalLength(<arg of SetLength()>)"
1020 hyp->AddArgMethod( "SetLength" );
1022 else if ( hypType == "NumberOfSegments" ) {
1023 hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
1024 hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
1025 // arg of SetNumberOfSegments() will become the 1-st arg of hyp creation command
1026 hyp->AddArgMethod( "SetNumberOfSegments" );
1027 // arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
1028 hyp->AddArgMethod( "SetScaleFactor" );
1030 else if ( hypType == "Arithmetic1D" ) {
1031 hyp = new _pyComplexParamHypo( theCreationCmd );
1032 hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
1034 else if ( hypType == "StartEndLength" ) {
1035 hyp = new _pyComplexParamHypo( theCreationCmd );
1036 hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
1038 else if ( hypType == "Deflection1D" ) {
1039 hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
1040 hyp->AddArgMethod( "SetDeflection" );
1042 else if ( hypType == "Propagation" ) {
1043 hyp->SetConvMethodAndType( "Propagation", "Regular_1D");
1045 else if ( hypType == "QuadraticMesh" ) {
1046 hyp->SetConvMethodAndType( "QuadraticMesh", "Regular_1D");
1048 else if ( hypType == "AutomaticLength" ) {
1049 hyp->SetConvMethodAndType( "AutomaticLength", "Regular_1D");
1050 hyp->AddArgMethod( "SetFineness");
1052 else if ( hypType == "SegmentLengthAroundVertex" ) {
1053 hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
1054 hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
1055 hyp->AddArgMethod( "SetLength" );
1057 // 1D Python_1D ----------
1058 else if ( hypType == "Python_1D" ) {
1059 algo->SetConvMethodAndType( "Segment", hypType.ToCString());
1060 algo->myArgs.Append( "algo=smesh.PYTHON");
1062 else if ( hypType == "PythonSplit1D" ) {
1063 hyp->SetConvMethodAndType( "PythonSplit1D", "Python_1D");
1064 hyp->AddArgMethod( "SetNumberOfSegments");
1065 hyp->AddArgMethod( "SetPythonLog10RatioFunction");
1067 // MEFISTO_2D ----------
1068 else if ( hypType == "MEFISTO_2D" ) { // MEFISTO_2D
1069 algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
1071 else if ( hypType == "MaxElementArea" ) {
1072 hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
1073 hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
1074 hyp->AddArgMethod( "SetMaxElementArea");
1076 else if ( hypType == "LengthFromEdges" ) {
1077 hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
1078 hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
1080 // Quadrangle_2D ----------
1081 else if ( hypType == "Quadrangle_2D" ) {
1082 algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
1084 else if ( hypType == "QuadranglePreference" ) {
1085 hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
1086 hyp->SetConvMethodAndType( "QuadranglePreference", "NETGEN_2D_ONLY");
1088 else if ( hypType == "TrianglePreference" ) {
1089 hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
1091 // NETGEN ----------
1092 // else if ( hypType == "NETGEN_2D") { // 1D-2D
1093 // algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1094 // algo->myArgs.Append( "algo=smesh.NETGEN" );
1096 else if ( hypType == "NETGEN_2D_ONLY") { // 2D
1097 algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1098 algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
1100 else if ( hypType == "NETGEN_3D") { // 3D
1101 algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
1102 algo->myArgs.Append( "algo=smesh.NETGEN" );
1104 else if ( hypType == "MaxElementVolume") {
1105 hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
1106 hyp->AddArgMethod( "SetMaxElementVolume" );
1108 // GHS3D_3D ----------
1109 else if ( hypType == "GHS3D_3D" ) {
1110 algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
1111 algo->myArgs.Append( "algo=smesh.GHS3D" );
1113 // Hexa_3D ---------
1114 else if ( hypType == "Hexa_3D" ) {
1115 algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
1117 // Repetitive Projection_1D ---------
1118 else if ( hypType == "Projection_1D" ) {
1119 algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
1121 else if ( hypType == "ProjectionSource1D" ) {
1122 hyp->SetConvMethodAndType( "SourceEdge", "Projection_1D");
1123 hyp->AddArgMethod( "SetSourceEdge");
1124 hyp->AddArgMethod( "SetSourceMesh");
1125 // 2 args of SetVertexAssociation() will become the 3-th and 4-th args of hyp creation command
1126 hyp->AddArgMethod( "SetVertexAssociation", 2 );
1128 // Projection_2D ---------
1129 else if ( hypType == "Projection_2D" ) {
1130 algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
1132 else if ( hypType == "ProjectionSource2D" ) {
1133 hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
1134 hyp->AddArgMethod( "SetSourceFace");
1135 hyp->AddArgMethod( "SetSourceMesh");
1136 hyp->AddArgMethod( "SetVertexAssociation", 4 );
1138 // Projection_3D ---------
1139 else if ( hypType == "Projection_3D" ) {
1140 algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
1142 else if ( hypType == "ProjectionSource3D" ) {
1143 hyp->SetConvMethodAndType( "SourceShape3D", "Projection_3D");
1144 hyp->AddArgMethod( "SetSource3DShape");
1145 hyp->AddArgMethod( "SetSourceMesh");
1146 hyp->AddArgMethod( "SetVertexAssociation", 4 );
1148 // Prism_3D ---------
1149 else if ( hypType == "Prism_3D" ) {
1150 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1152 // RadialPrism_3D ---------
1153 else if ( hypType == "RadialPrism_3D" ) {
1154 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1156 else if ( hypType == "NumberOfLayers" ) {
1157 hyp->SetConvMethodAndType( "NumberOfLayers", "RadialPrism_3D");
1158 hyp->AddArgMethod( "SetNumberOfLayers" );
1160 else if ( hypType == "LayerDistribution" ) {
1161 hyp = new _pyLayerDistributionHypo( theCreationCmd );
1162 hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
1165 if ( algo->IsValid() ) {
1171 //================================================================================
1173 * \brief Convert the command adding a hypothesis to mesh into a smesh command
1174 * \param theCmd - The command like mesh.AddHypothesis( geom, hypo )
1175 * \param theAlgo - The algo that can create this hypo
1176 * \retval bool - false if the command cant be converted
1178 //================================================================================
1180 bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
1181 const _pyID& theMesh)
1183 ASSERT(( theCmd->GetMethod() == "AddHypothesis" ));
1185 if ( !IsWrappable( theMesh ))
1188 myGeom = theCmd->GetArg( 1 );
1190 Handle(_pyHypothesis) algo;
1192 // find algo created on myGeom in theMesh
1193 algo = theGen->FindAlgo( myGeom, theMesh, this );
1194 if ( algo.IsNull() )
1196 algo->GetCreationCmd()->AddDependantCmd( theCmd );
1200 // mesh.AddHypothesis(geom,hyp) --> hyp = <theMesh or algo>.myCreationMethod(args)
1201 theCmd->SetResultValue( GetID() );
1202 theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
1203 theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
1205 theCmd->RemoveArgs();
1206 for ( int i = 1; i <= myArgs.Length(); ++i ) {
1207 if ( !myArgs( i ).IsEmpty() )
1208 theCmd->SetArg( i, myArgs( i ));
1210 theCmd->SetArg( i, "[]");
1212 // set a new creation command
1213 GetCreationCmd()->Clear();
1214 SetCreationCmd( theCmd );
1216 // clear commands setting arg values
1217 list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
1218 for ( ; argCmd != myArgCommands.end(); ++argCmd )
1221 // set unknown arg commands after hypo creation
1222 Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
1223 list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
1224 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1225 afterCmd->AddDependantCmd( *cmd );
1231 //================================================================================
1233 * \brief Remember hypothesis parameter values
1234 * \param theCommand - The called hypothesis method
1236 //================================================================================
1238 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
1240 ASSERT( !myIsAlgo );
1243 for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
1244 if ( myArgMethods( i ) == theCommand->GetMethod() ) {
1245 while ( myArgs.Length() < nbArgs + myNbArgsByMethod( i ))
1246 myArgs.Append( "[]" );
1247 for ( int iArg = 1; iArg <= myNbArgsByMethod( i ); ++iArg )
1248 myArgs( nbArgs + iArg ) = theCommand->GetArg( iArg ); // arg value
1249 myArgCommands.push_back( theCommand );
1252 nbArgs += myNbArgsByMethod( i );
1254 myUnknownCommands.push_back( theCommand );
1257 //================================================================================
1259 * \brief Finish conversion
1261 //================================================================================
1263 void _pyHypothesis::Flush()
1265 if ( IsWrapped() ) {
1268 list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
1269 for ( ; cmd != myArgCommands.end(); ++cmd ) {
1270 // Add access to a wrapped mesh
1271 theGen->AddMeshAccessorMethod( *cmd );
1272 // Add access to a wrapped algorithm
1273 theGen->AddAlgoAccessorMethod( *cmd );
1275 cmd = myUnknownCommands.begin();
1276 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1277 // Add access to a wrapped mesh
1278 theGen->AddMeshAccessorMethod( *cmd );
1279 // Add access to a wrapped algorithm
1280 theGen->AddAlgoAccessorMethod( *cmd );
1283 // forget previous hypothesis modifications
1284 myArgCommands.clear();
1285 myUnknownCommands.clear();
1288 //================================================================================
1290 * \brief clear creation, arg and unkown commands
1292 //================================================================================
1294 void _pyHypothesis::ClearAllCommands()
1296 GetCreationCmd()->Clear();
1297 list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
1298 for ( ; cmd != myArgCommands.end(); ++cmd )
1300 cmd = myUnknownCommands.begin();
1301 for ( ; cmd != myUnknownCommands.end(); ++cmd )
1305 //================================================================================
1307 * \brief Remember hypothesis parameter values
1308 * \param theCommand - The called hypothesis method
1310 //================================================================================
1312 void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
1314 // ex: hyp.SetLength(start, 1)
1315 // hyp.SetLength(end, 0)
1316 ASSERT(( theCommand->GetMethod() == "SetLength" ));
1317 ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
1318 int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
1319 while ( myArgs.Length() < i )
1320 myArgs.Append( "[]" );
1321 myArgs( i ) = theCommand->GetArg( 1 ); // arg value
1322 myArgCommands.push_back( theCommand );
1325 //================================================================================
1327 * \brief Convert methods of 1D hypotheses to my own methods
1328 * \param theCommand - The called hypothesis method
1330 //================================================================================
1332 void _pyLayerDistributionHypo::Process( const Handle(_pyCommand)& theCommand)
1334 if ( theCommand->GetMethod() != "SetLayerDistribution" )
1337 _pyID newName; // name for 1D hyp = "HypType" + "_Distribution"
1339 const _pyID& hyp1dID = theCommand->GetArg( 1 );
1340 Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
1341 if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
1343 else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() ) {
1344 // 1D hypo is already set, so distribution changes and the old
1345 // 1D hypo is thrown away
1346 my1dHyp->ClearAllCommands();
1349 if ( my1dHyp.IsNull() )
1350 return; // something wrong :(
1352 // make a new name for 1D hyp = "HypType" + "_Distribution"
1353 if ( my1dHyp->GetCreationCmd()->GetMethod() == "CreateHypothesis" ) {
1354 // not yet converted creation cmd
1355 TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
1356 TCollection_AsciiString hypType = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
1357 newName = hypType + "_Distribution";
1358 my1dHyp->GetCreationCmd()->SetResultValue( newName );
1361 // already converted creation cmd
1362 newName = my1dHyp->GetCreationCmd()->GetResultValue();
1365 // as creation of 1D hyp was written later then it's edition,
1366 // we need to find all it's edition calls and process them
1367 list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
1368 list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
1369 for ( ; cmdIt != cmds.end(); ++cmdIt ) {
1370 const _pyID& objID = (*cmdIt)->GetObject();
1371 if ( objID == hyp1dID ) {
1372 my1dHyp->Process( *cmdIt );
1373 my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
1374 ( *cmdIt )->SetObject( newName );
1377 if ( !myArgCommands.empty() )
1378 myArgCommands.front()->Clear();
1379 theCommand->SetArg( 1, newName );
1380 myArgCommands.push_back( theCommand );
1381 // copy hyp1d's creation method and args
1382 // myCreationMethod = hyp1d->GetCreationMethod();
1383 // myArgs = hyp1d->GetArgs();
1384 // // make them cleared at conversion
1385 // myArgCommands = hyp1d->GetArgCommands();
1387 // // to be cleared at convertion only
1388 // myArgCommands.push_back( theCommand );
1391 //================================================================================
1394 * \param theAdditionCmd -
1398 //================================================================================
1400 bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
1401 const _pyID& theMesh)
1403 myIsWrapped = false;
1405 if ( my1dHyp.IsNull() )
1408 // set "SetLayerDistribution()" after addition cmd
1409 theAdditionCmd->AddDependantCmd( myArgCommands.front() );
1411 _pyID geom = theAdditionCmd->GetArg( 1 );
1413 my1dHyp->SetMesh( theMesh );
1414 if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
1417 // clear "SetLayerDistribution()" cmd
1418 myArgCommands.front()->Clear();
1420 // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
1422 // find RadialPrism algo created on <geom> for theMesh
1423 Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
1424 if ( !algo.IsNull() ) {
1425 GetCreationCmd()->SetObject( algo->GetID() );
1426 GetCreationCmd()->SetMethod( "Get3DHypothesis" );
1427 GetCreationCmd()->RemoveArgs();
1428 theAdditionCmd->AddDependantCmd( GetCreationCmd() );
1434 //================================================================================
1438 //================================================================================
1440 void _pyLayerDistributionHypo::Flush()
1442 //my1dHyp.Nullify();
1443 //_pyHypothesis::Flush();
1446 //================================================================================
1448 * \brief additionally to Addition2Creation, clears SetDistrType() command
1449 * \param theCmd - AddHypothesis() command
1450 * \param theMesh - mesh to which a hypothesis is added
1451 * \retval bool - convertion result
1453 //================================================================================
1455 bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1456 const _pyID& theMesh)
1458 if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
1459 // scale factor (2-nd arg) is provided: clear SetDistrType(1) command
1460 bool scaleDistrType = false;
1461 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1462 for ( ; cmd != myUnknownCommands.rend(); ++cmd ) {
1463 if ( (*cmd)->GetMethod() == "SetDistrType" ) {
1464 if ( (*cmd)->GetArg( 1 ) == "1" ) {
1465 scaleDistrType = true;
1468 else if ( !scaleDistrType ) {
1469 // distribution type changed: remove scale factor from args
1470 myArgs.Remove( 2, myArgs.Length() );
1476 return _pyHypothesis::Addition2Creation( theCmd, theMesh );
1479 //================================================================================
1481 * \brief remove repeated commands defining distribution
1483 //================================================================================
1485 void _pyNumberOfSegmentsHyp::Flush()
1487 // find number of the last SetDistrType() command
1488 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1489 int distrTypeNb = 0;
1490 for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
1491 if ( (*cmd)->GetMethod() == "SetDistrType" )
1492 distrTypeNb = (*cmd)->GetOrderNb();
1494 // clear commands before the last SetDistrType()
1495 list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
1496 for ( int i = 0; i < 2; ++i ) {
1497 set<TCollection_AsciiString> uniqueMethods;
1498 list<Handle(_pyCommand)> & cmdList = *cmds[i];
1499 for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
1501 bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
1502 const TCollection_AsciiString& method = (*cmd)->GetMethod();
1503 if ( !clear || method == "SetNumberOfSegments" ) {
1504 bool isNewInSet = uniqueMethods.insert( method ).second;
1505 clear = !isNewInSet;
1514 //================================================================================
1516 * \brief Convert the command adding "SegmentLengthAroundVertex" to mesh
1517 * into regular1D.LengthNearVertex( length, vertex )
1518 * \param theCmd - The command like mesh.AddHypothesis( vertex, SegmentLengthAroundVertex )
1519 * \param theMesh - The mesh needing this hypo
1520 * \retval bool - false if the command cant be converted
1522 //================================================================================
1524 bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1525 const _pyID& theMeshID)
1527 if ( IsWrappable( theMeshID )) {
1529 _pyID vertex = theCmd->GetArg( 1 );
1531 // the problem here is that segment algo will not be found
1532 // by pyHypothesis::Addition2Creation() for <vertex>, so we try to find
1533 // geometry where segment algorithm is assigned
1534 Handle(_pyHypothesis) algo;
1535 _pyID geom = vertex;
1536 while ( algo.IsNull() && !geom.IsEmpty()) {
1537 // try to find geom as a father of <vertex>
1538 geom = FatherID( geom );
1539 algo = theGen->FindAlgo( geom, theMeshID, this );
1541 if ( algo.IsNull() )
1542 return false; // also possible to find geom as brother of veretex...
1543 // set geom instead of vertex
1544 theCmd->SetArg( 1, geom );
1546 // set vertex as a second arg
1547 if ( myArgs.Length() < 1) myArgs.Append( "1" ); // :(
1548 myArgs.Append( vertex );
1550 // mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) -->
1551 // theMeshID.LengthNearVertex( length, vertex )
1552 return _pyHypothesis::Addition2Creation( theCmd, theMeshID );
1557 //================================================================================
1559 * \brief _pyAlgorithm constructor
1560 * \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)"
1562 //================================================================================
1564 _pyAlgorithm::_pyAlgorithm(const Handle(_pyCommand)& theCreationCmd)
1565 : _pyHypothesis( theCreationCmd )
1570 //================================================================================
1572 * \brief Convert the command adding an algorithm to mesh
1573 * \param theCmd - The command like mesh.AddHypothesis( geom, algo )
1574 * \param theMesh - The mesh needing this algo
1575 * \retval bool - false if the command cant be converted
1577 //================================================================================
1579 bool _pyAlgorithm::Addition2Creation( const Handle(_pyCommand)& theCmd,
1580 const _pyID& theMeshID)
1582 // mesh.AddHypothesis(geom,algo) --> theMeshID.myCreationMethod()
1583 if ( _pyHypothesis::Addition2Creation( theCmd, theMeshID )) {
1584 theGen->SetAccessorMethod( GetID(), "GetAlgorithm()" );
1590 //================================================================================
1592 * \brief Return starting position of a part of python command
1593 * \param thePartIndex - The index of command part
1594 * \retval int - Part position
1596 //================================================================================
1598 int _pyCommand::GetBegPos( int thePartIndex )
1602 if ( myBegPos.Length() < thePartIndex )
1604 return myBegPos( thePartIndex );
1607 //================================================================================
1609 * \brief Store starting position of a part of python command
1610 * \param thePartIndex - The index of command part
1611 * \param thePosition - Part position
1613 //================================================================================
1615 void _pyCommand::SetBegPos( int thePartIndex, int thePosition )
1617 while ( myBegPos.Length() < thePartIndex )
1618 myBegPos.Append( UNKNOWN );
1619 myBegPos( thePartIndex ) = thePosition;
1622 //================================================================================
1624 * \brief Returns whitespace symbols at the line beginning
1625 * \retval TCollection_AsciiString - result
1627 //================================================================================
1629 TCollection_AsciiString _pyCommand::GetIndentation()
1632 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
1633 GetWord( myString, end, true );
1635 end = GetBegPos( RESULT_IND );
1636 return myString.SubString( 1, end - 1 );
1639 //================================================================================
1641 * \brief Return substring of python command looking like ResultValue = Obj.Meth()
1642 * \retval const TCollection_AsciiString & - ResultValue substring
1644 //================================================================================
1646 const TCollection_AsciiString & _pyCommand::GetResultValue()
1648 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
1650 int begPos = myString.Location( "=", 1, Length() );
1652 myRes = GetWord( myString, begPos, false );
1655 SetBegPos( RESULT_IND, begPos );
1660 //================================================================================
1662 * \brief Return number of python command result value ResultValue = Obj.Meth()
1665 //================================================================================
1667 const int _pyCommand::GetNbResultValues()
1671 int endPos = myString.Location( "=", 1, Length() );
1672 TCollection_AsciiString str = "";
1673 while ( begPos < endPos) {
1674 str = GetWord( myString, begPos, true );
1675 begPos = begPos+ str.Length();
1682 //================================================================================
1684 * \brief Return substring of python command looking like
1685 * ResultValue1 , ResultValue1,... = Obj.Meth() with res index
1686 * \retval const TCollection_AsciiString & - ResultValue with res index substring
1688 //================================================================================
1689 const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
1693 int endPos = myString.Location( "=", 1, Length() );
1694 while ( begPos < endPos) {
1695 myRes = GetWord( myString, begPos, true );
1696 begPos = begPos + myRes.Length();
1699 myRes.RemoveAll('[');myRes.RemoveAll(']');
1705 return theEmptyString;
1708 //================================================================================
1710 * \brief Return substring of python command looking like ResVal = Object.Meth()
1711 * \retval const TCollection_AsciiString & - Object substring
1713 //================================================================================
1715 const TCollection_AsciiString & _pyCommand::GetObject()
1717 if ( GetBegPos( OBJECT_IND ) == UNKNOWN )
1720 int begPos = GetBegPos( RESULT_IND ) + myRes.Length();
1722 begPos = myString.Location( "=", 1, Length() ) + 1;
1724 myObj = GetWord( myString, begPos, true );
1725 SetBegPos( OBJECT_IND, begPos );
1731 //================================================================================
1733 * \brief Return substring of python command looking like ResVal = Obj.Method()
1734 * \retval const TCollection_AsciiString & - Method substring
1736 //================================================================================
1738 const TCollection_AsciiString & _pyCommand::GetMethod()
1740 if ( GetBegPos( METHOD_IND ) == UNKNOWN )
1743 int begPos = GetBegPos( OBJECT_IND ) + myObj.Length();
1744 bool forward = true;
1746 begPos = myString.Location( "(", 1, Length() ) - 1;
1750 myMeth = GetWord( myString, begPos, forward );
1751 SetBegPos( METHOD_IND, begPos );
1757 //================================================================================
1759 * \brief Return substring of python command looking like ResVal = Obj.Meth(Arg1,...)
1760 * \retval const TCollection_AsciiString & - Arg<index> substring
1762 //================================================================================
1764 const TCollection_AsciiString & _pyCommand::GetArg( int index )
1766 if ( GetBegPos( ARG1_IND ) == UNKNOWN )
1769 int begPos = GetBegPos( METHOD_IND ) + myMeth.Length();
1771 begPos = myString.Location( "(", 1, Length() ) + 1;
1773 int i = 0, prevLen = 0, nbNestings = 0;
1774 while ( begPos != EMPTY ) {
1776 if( myString.Value( begPos ) == '(' )
1778 // check if we are looking at the closing parenthesis
1779 while ( begPos <= Length() && isspace( myString.Value( begPos )))
1781 if ( begPos > Length() )
1783 if ( myString.Value( begPos ) == ')' ) {
1785 if( nbNestings == 0 )
1788 myArgs.Append( GetWord( myString, begPos, true, true ));
1789 SetBegPos( ARG1_IND + i, begPos );
1790 prevLen = myArgs.Last().Length();
1792 myArgs.Remove( myArgs.Length() ); // no more args
1796 if ( myArgs.Length() < index )
1797 return theEmptyString;
1798 return myArgs( index );
1801 //================================================================================
1803 * \brief Check if char is a word part
1804 * \param c - The character to check
1805 * \retval bool - The check result
1807 //================================================================================
1809 static inline bool isWord(const char c, const bool dotIsWord)
1812 !isspace(c) && c != ',' && c != '=' && c != ')' && c != '(' && ( dotIsWord || c != '.');
1815 //================================================================================
1817 * \brief Looks for a word in the string and returns word's beginning
1818 * \param theString - The input string
1819 * \param theStartPos - The position to start the search, returning word's beginning
1820 * \param theForward - The search direction
1821 * \retval TCollection_AsciiString - The found word
1823 //================================================================================
1825 TCollection_AsciiString _pyCommand::GetWord( const TCollection_AsciiString & theString,
1827 const bool theForward,
1828 const bool dotIsWord )
1830 int beg = theStartPos, end = theStartPos;
1831 theStartPos = EMPTY;
1832 if ( beg < 1 || beg > theString.Length() )
1833 return theEmptyString;
1835 if ( theForward ) { // search forward
1837 while ( beg <= theString.Length() && !isWord( theString.Value( beg ), dotIsWord))
1839 if ( beg > theString.Length() )
1840 return theEmptyString; // no word found
1843 while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
1847 else { // search backward
1849 while ( end > 0 && !isWord( theString.Value( end ), dotIsWord))
1852 return theEmptyString; // no word found
1854 while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
1859 //cout << theString << " ---- " << beg << " - " << end << endl;
1860 return theString.SubString( beg, end );
1863 //================================================================================
1865 * \brief Look for position where not space char is
1866 * \param theString - The string
1867 * \param thePos - The position to search from and which returns result
1868 * \retval bool - false if there are only space after thePos in theString
1872 //================================================================================
1874 bool _pyCommand::SkipSpaces( const TCollection_AsciiString & theString, int & thePos )
1876 if ( thePos < 1 || thePos > theString.Length() )
1879 while ( thePos <= theString.Length() && isspace( theString.Value( thePos )))
1882 return thePos <= theString.Length();
1885 //================================================================================
1887 * \brief Modify a part of the command
1888 * \param thePartIndex - The index of the part
1889 * \param thePart - The new part string
1890 * \param theOldPart - The old part
1892 //================================================================================
1894 void _pyCommand::SetPart(int thePartIndex, const TCollection_AsciiString& thePart,
1895 TCollection_AsciiString& theOldPart)
1897 int pos = GetBegPos( thePartIndex );
1898 if ( pos <= Length() && theOldPart != thePart)
1900 TCollection_AsciiString seperator;
1902 pos = GetBegPos( thePartIndex + 1 );
1903 if ( pos < 1 ) return;
1904 switch ( thePartIndex ) {
1905 case RESULT_IND: seperator = " = "; break;
1906 case OBJECT_IND: seperator = "."; break;
1907 case METHOD_IND: seperator = "()"; break;
1911 myString.Remove( pos, theOldPart.Length() );
1912 if ( !seperator.IsEmpty() )
1913 myString.Insert( pos , seperator );
1914 myString.Insert( pos, thePart );
1915 // update starting positions of the following parts
1916 int posDelta = thePart.Length() + seperator.Length() - theOldPart.Length();
1917 for ( int i = thePartIndex + 1; i <= myBegPos.Length(); ++i ) {
1918 if ( myBegPos( i ) > 0 )
1919 myBegPos( i ) += posDelta;
1921 theOldPart = thePart;
1925 //================================================================================
1927 * \brief Set agrument
1928 * \param index - The argument index, it counts from 1
1929 * \param theArg - The argument string
1931 //================================================================================
1933 void _pyCommand::SetArg( int index, const TCollection_AsciiString& theArg)
1936 int argInd = ARG1_IND + index - 1;
1937 int pos = GetBegPos( argInd );
1938 if ( pos < 1 ) // no index-th arg exist, append inexistent args
1940 // find a closing parenthesis
1941 if ( GetNbArgs() != 0 && index <= GetNbArgs() ) {
1942 int lastArgInd = GetNbArgs();
1943 pos = GetBegPos( ARG1_IND + lastArgInd - 1 ) + GetArg( lastArgInd ).Length();
1944 while ( pos > 0 && pos <= Length() && myString.Value( pos ) != ')' )
1949 while ( pos > 0 && myString.Value( pos ) != ')' )
1952 if ( pos < 1 || myString.Value( pos ) != ')' ) { // no parentheses at all
1956 while ( myArgs.Length() < index ) {
1957 if ( myArgs.Length() )
1958 myString.Insert( pos++, "," );
1959 myArgs.Append("None");
1960 myString.Insert( pos, myArgs.Last() );
1961 SetBegPos( ARG1_IND + myArgs.Length() - 1, pos );
1962 pos += myArgs.Last().Length();
1965 SetPart( argInd, theArg, myArgs( index ));
1968 //================================================================================
1970 * \brief Empty arg list
1972 //================================================================================
1974 void _pyCommand::RemoveArgs()
1976 if ( int pos = myString.Location( '(', 1, Length() ))
1977 myString.Trunc( pos );
1980 if ( myBegPos.Length() >= ARG1_IND )
1981 myBegPos.Remove( ARG1_IND, myBegPos.Length() );
1984 //================================================================================
1986 * \brief Set dependent commands after this one
1988 //================================================================================
1990 bool _pyCommand::SetDependentCmdsAfter() const
1992 bool orderChanged = false;
1993 list< Handle(_pyCommand)>::const_reverse_iterator cmd = myDependentCmds.rbegin();
1994 for ( ; cmd != myDependentCmds.rend(); ++cmd ) {
1995 if ( (*cmd)->GetOrderNb() < GetOrderNb() ) {
1996 orderChanged = true;
1997 theGen->SetCommandAfter( *cmd, this );
1998 (*cmd)->SetDependentCmdsAfter();
2001 return orderChanged;
2003 //================================================================================
2005 * \brief Insert accessor method after theObjectID
2006 * \param theObjectID - id of the accessed object
2007 * \param theAcsMethod - name of the method giving access to the object
2008 * \retval bool - false if theObjectID is not found in the command string
2010 //================================================================================
2012 bool _pyCommand::AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod )
2014 if ( !theAcsMethod )
2016 // start object search from the object, i.e. ignore result
2018 int beg = GetBegPos( OBJECT_IND );
2019 if ( beg < 1 || beg > Length() )
2022 while (( beg = myString.Location( theObjectID, beg, Length() )))
2024 // check that theObjectID is not just a part of a longer ID
2025 int afterEnd = beg + theObjectID.Length();
2026 Standard_Character c = myString.Value( afterEnd );
2027 if ( !isalnum( c ) && c != ':' ) {
2028 // check if accessor method already present
2030 myString.Location( (char*) theAcsMethod, afterEnd, Length() ) != afterEnd+1) {
2032 int oldLen = Length();
2033 myString.Insert( afterEnd, (char*) theAcsMethod );
2034 myString.Insert( afterEnd, "." );
2035 // update starting positions of the parts following the modified one
2036 int posDelta = Length() - oldLen;
2037 for ( int i = 1; i <= myBegPos.Length(); ++i ) {
2038 if ( myBegPos( i ) > afterEnd )
2039 myBegPos( i ) += posDelta;
2044 beg = afterEnd; // is a part - next search
2049 //================================================================================
2051 * \brief Return method name giving access to an interaface object wrapped by python class
2052 * \retval const char* - method name
2054 //================================================================================
2056 const char* _pyObject::AccessorMethod() const
2060 //================================================================================
2062 * \brief Return ID of a father
2064 //================================================================================
2066 _pyID _pyObject::FatherID(const _pyID & childID)
2068 int colPos = childID.SearchFromEnd(':');
2070 return childID.SubString( 1, colPos-1 );