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 "Resource_DataMapOfAsciiStringAsciiString.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 IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient);
46 IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
47 IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject);
48 IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject);
49 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor ,_pyObject);
50 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis ,_pyObject);
51 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
52 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
53 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis);
55 IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient);
56 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient);
57 IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject);
58 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject);
59 IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject);
60 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject);
61 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis);
62 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
63 IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis);
64 IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis);
65 IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis);
68 using SMESH::TPythonDump;
71 * \brief Container of commands into which the initial script is split.
72 * It also contains data coresponding to SMESH_Gen contents
74 static Handle(_pyGen) theGen;
76 static TCollection_AsciiString theEmptyString;
78 //#define DUMP_CONVERSION
80 #if !defined(_DEBUG_) && defined(DUMP_CONVERSION)
81 #undef DUMP_CONVERSION
87 //================================================================================
89 * \brief Set of TCollection_AsciiString initialized by C array of C strings
91 //================================================================================
93 struct TStringSet: public set<TCollection_AsciiString>
96 * \brief Filling. The last string must be ""
98 void Insert(const char* names[]) {
99 for ( int i = 0; names[i][0] ; ++i )
100 insert( (char*) names[i] );
103 * \brief Check if a string is in
105 bool Contains(const TCollection_AsciiString& name ) {
106 return find( name ) != end();
111 //================================================================================
113 * \brief Convert python script using commands of smesh.py
114 * \param theScript - Input script
115 * \retval TCollection_AsciiString - Convertion result
117 * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
119 //================================================================================
121 TCollection_AsciiString
122 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
123 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
125 theGen = new _pyGen( theEntry2AccessorMethod );
127 // split theScript into separate commands
128 int from = 1, end = theScript.Length(), to;
129 while ( from < end && ( to = theScript.Location( "\n", from, end )))
132 // cut out and store a command
133 theGen->AddCommand( theScript.SubString( from, to - 1 ));
138 #ifdef DUMP_CONVERSION
139 MESSAGE_BEGIN ( std::endl << " ######## RESULT ######## " << std::endl<< std::endl );
141 // reorder commands after conversion
142 list< Handle(_pyCommand) >::iterator cmd;
145 orderChanges = false;
146 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
147 if ( (*cmd)->SetDependentCmdsAfter() )
149 } while ( orderChanges );
151 // concat commands back into a script
152 TCollection_AsciiString aScript;
153 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
155 #ifdef DUMP_CONVERSION
156 MESSAGE_ADD ( "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << std::endl );
158 if ( !(*cmd)->IsEmpty() ) {
160 aScript += (*cmd)->GetString();
170 //================================================================================
172 * \brief _pyGen constructor
174 //================================================================================
176 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
177 : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
178 myID2AccessorMethod( theEntry2AccessorMethod )
181 myHasPattern = false;
182 // make that GetID() to return TPythonDump::SMESHGenName()
183 GetCreationCmd()->GetString() += "=";
186 //================================================================================
188 * \brief name of SMESH_Gen in smesh.py
190 //================================================================================
192 const char* _pyGen::AccessorMethod() const
194 return SMESH_2smeshpy::GenName();
197 //================================================================================
199 * \brief Convert a command using a specific converter
200 * \param theCommand - the command to convert
202 //================================================================================
204 Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
206 // store theCommand in the sequence
207 myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
209 Handle(_pyCommand) aCommand = myCommands.back();
210 #ifdef DUMP_CONVERSION
211 MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
214 _pyID objID = aCommand->GetObject();
216 if ( objID.IsEmpty() )
220 if ( objID == this->GetID() ) {
221 this->Process( aCommand );
224 // SMESH_Mesh method?
225 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
226 if ( id_mesh != myMeshes.end() ) {
227 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
228 _pyID editorID = aCommand->GetResultValue();
229 Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
230 myMeshEditors.insert( make_pair( editorID, editor ));
233 id_mesh->second->Process( aCommand );
236 // SMESH_MeshEditor method?
237 map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
238 if ( id_editor != myMeshEditors.end() ) {
239 id_editor->second->Process( aCommand );
240 TCollection_AsciiString processedCommand = aCommand->GetString();
241 // some commands of SMESH_MeshEditor create meshes
242 if ( aCommand->GetMethod().Search("MakeMesh") != -1 ) {
243 Handle(_pyMesh) mesh = new _pyMesh( aCommand, aCommand->GetResultValue() );
244 aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
245 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
249 // SMESH_Hypothesis method?
250 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
251 for ( ; hyp != myHypos.end(); ++hyp )
252 if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
253 (*hyp)->Process( aCommand );
257 // Add access to a wrapped mesh
258 AddMeshAccessorMethod( aCommand );
260 // Add access to a wrapped algorithm
261 // AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
263 // PAL12227. PythonDump was not updated at proper time; result is
264 // aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
265 // TypeError: __init__() takes exactly 11 arguments (10 given)
266 char wrongCommand[] = "SMESH.Filter.Criterion(";
267 if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
269 _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
270 // there must be 10 arguments, 5-th arg ThresholdID is missing,
271 const int wrongNbArgs = 9, missingArg = 5;
272 if ( tmpCmd.GetNbArgs() == wrongNbArgs )
274 for ( int i = wrongNbArgs; i > missingArg; --i )
275 tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
276 tmpCmd.SetArg( missingArg, "''");
277 aCommand->GetString().Trunc( beg - 1 );
278 aCommand->GetString() += tmpCmd.GetString();
284 //================================================================================
286 * \brief Convert the command or remember it for later conversion
287 * \param theCommand - The python command calling a method of SMESH_Gen
289 //================================================================================
291 void _pyGen::Process( const Handle(_pyCommand)& theCommand )
293 // there are methods to convert:
294 // CreateMesh( shape )
295 // Concatenate( [mesh1, ...], ... )
296 // CreateHypothesis( theHypType, theLibName )
297 // Compute( mesh, geom )
299 TCollection_AsciiString method = theCommand->GetMethod();
300 if ( method == "CreateMesh" || method == "CreateEmptyMesh")
302 Handle(_pyMesh) mesh = new _pyMesh( theCommand );
303 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
306 if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL")
308 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
309 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
312 if( method == "CreateMeshesFromMED")
314 for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
316 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
317 myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));
321 // CreateHypothesis()
322 if ( method == "CreateHypothesis" )
324 myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
328 // smeshgen.Compute( mesh, geom ) --> mesh.Compute()
329 if ( method == "Compute" )
331 const _pyID& meshID = theCommand->GetArg( 1 );
332 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
333 if ( id_mesh != myMeshes.end() ) {
334 theCommand->SetObject( meshID );
335 theCommand->RemoveArgs();
336 id_mesh->second->Flush();
341 // leave only one smeshgen.GetPattern() in the script
342 if ( method == "GetPattern" ) {
343 if ( myHasPattern ) {
350 // Concatenate( [mesh1, ...], ... )
351 if ( method == "Concatenate" || method == "ConcatenateWithGroups")
353 if ( method == "ConcatenateWithGroups" ) {
354 theCommand->SetMethod( "Concatenate" );
355 theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
357 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
358 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
359 AddMeshAccessorMethod( theCommand );
362 // Replace name of SMESH_Gen
364 // names of SMESH_Gen methods fully equal to methods defined in smesh.py
365 static TStringSet smeshpyMethods;
366 if ( smeshpyMethods.empty() ) {
367 const char * names[] =
368 { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
369 "GetPattern","GetSubShapesId",
370 "" }; // <- mark of array end
371 smeshpyMethods.Insert( names );
373 if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
374 // smeshgen.Method() --> smesh.Method()
375 theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
377 // smeshgen.Method() --> smesh.smesh.Method()
378 theCommand->SetObject( SMESH_2smeshpy::GenName() );
381 //================================================================================
383 * \brief Convert the remembered commands
385 //================================================================================
389 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
390 for ( ; id_mesh != myMeshes.end(); ++id_mesh )
391 if ( ! id_mesh->second.IsNull() )
392 id_mesh->second->Flush();
394 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
395 for ( ; hyp != myHypos.end(); ++hyp )
396 if ( !hyp->IsNull() ) {
398 // smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
399 if ( !(*hyp)->IsWrapped() )
400 (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
404 //================================================================================
406 * \brief Add access method to mesh that is an argument
407 * \param theCmd - command to add access method
408 * \retval bool - true if added
410 //================================================================================
412 bool _pyGen::AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const
415 map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
416 for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
417 if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
423 //================================================================================
425 * \brief Add access method to algo that is an object or an argument
426 * \param theCmd - command to add access method
427 * \retval bool - true if added
429 //================================================================================
431 bool _pyGen::AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const
434 list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
435 for ( ; hyp != myHypos.end(); ++hyp ) {
436 if ( (*hyp)->IsAlgo() && /*(*hyp)->IsWrapped() &&*/
437 theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
443 //================================================================================
445 * \brief Find hypothesis by ID (entry)
446 * \param theHypID - The hypothesis ID
447 * \retval Handle(_pyHypothesis) - The found hypothesis
449 //================================================================================
451 Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
453 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
454 for ( ; hyp != myHypos.end(); ++hyp )
455 if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
457 return Handle(_pyHypothesis)();
460 //================================================================================
462 * \brief Find algorithm the created algorithm
463 * \param theGeom - The shape ID the algorithm was created on
464 * \param theMesh - The mesh ID that created the algorithm
465 * \param dim - The algo dimension
466 * \retval Handle(_pyHypothesis) - The found algo
468 //================================================================================
470 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
471 const Handle(_pyHypothesis)& theHypothesis )
473 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
474 for ( ; hyp != myHypos.end(); ++hyp )
475 if ( !hyp->IsNull() &&
477 theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
478 (*hyp)->GetGeom() == theGeom &&
479 (*hyp)->GetMesh() == theMesh )
484 //================================================================================
486 * \brief Change order of commands in the script
487 * \param theCmd1 - One command
488 * \param theCmd2 - Another command
490 //================================================================================
492 void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 )
494 list< Handle(_pyCommand) >::iterator pos1, pos2;
495 pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
496 pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
497 myCommands.insert( pos1, theCmd2 );
498 myCommands.insert( pos2, theCmd1 );
499 myCommands.erase( pos1 );
500 myCommands.erase( pos2 );
502 int nb1 = theCmd1->GetOrderNb();
503 theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
504 theCmd2->SetOrderNb( nb1 );
505 // cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
506 // << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
509 //================================================================================
511 * \brief Set one command after the other
512 * \param theCmd - Command to move
513 * \param theAfterCmd - Command ater which to insert the first one
515 //================================================================================
517 void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
520 //cout << "SET\t" << theAfterCmd->GetString() << endl << "BEFORE\t" << theCmd->GetString() << endl<<endl;
522 list< Handle(_pyCommand) >::iterator pos;
523 pos = find( myCommands.begin(), myCommands.end(), theCmd );
524 myCommands.erase( pos );
525 pos = find( myCommands.begin(), myCommands.end(), theAfterCmd );
526 myCommands.insert( ++pos, theCmd );
529 for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
530 (*pos)->SetOrderNb( i++ );
533 //================================================================================
535 * \brief Set method to access to object wrapped with python class
536 * \param theID - The wrapped object entry
537 * \param theMethod - The accessor method
539 //================================================================================
541 void _pyGen::SetAccessorMethod(const _pyID& theID, const char* theMethod )
543 myID2AccessorMethod.Bind( theID, (char*) theMethod );
546 //================================================================================
548 * \brief Find out type of geom group
549 * \param grpID - The geom group entry
550 * \retval int - The type
552 //================================================================================
554 static bool sameGroupType( const _pyID& grpID,
555 const TCollection_AsciiString& theType)
557 // define group type as smesh.Mesh.Group() does
559 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
560 SALOMEDS::SObject_var aSObj = study->FindObjectID( grpID.ToCString() );
561 if ( !aSObj->_is_nil() ) {
562 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
563 if ( !aGeomObj->_is_nil() ) {
564 switch ( aGeomObj->GetShapeType() ) {
565 case GEOM::VERTEX: type = SMESH::NODE; break;
566 case GEOM::EDGE: type = SMESH::EDGE; break;
567 case GEOM::FACE: type = SMESH::FACE; break;
569 case GEOM::SHELL: type = SMESH::VOLUME; break;
570 case GEOM::COMPOUND: {
571 GEOM::GEOM_Gen_ptr aGeomGen = SMESH_Gen_i::GetSMESHGen()->GetGeomEngine();
572 if ( !aGeomGen->_is_nil() ) {
573 GEOM::GEOM_IGroupOperations_var aGrpOp =
574 aGeomGen->GetIGroupOperations( study->StudyId() );
575 if ( !aGrpOp->_is_nil() ) {
576 switch ( aGrpOp->GetType( aGeomObj )) {
577 case TopAbs_VERTEX: type = SMESH::NODE; break;
578 case TopAbs_EDGE: type = SMESH::EDGE; break;
579 case TopAbs_FACE: type = SMESH::FACE; break;
580 case TopAbs_SOLID: type = SMESH::VOLUME; break;
591 MESSAGE("Type of the group " << grpID << " not found");
594 if ( theType.IsIntegerValue() )
595 return type == theType.IntegerValue();
598 case SMESH::NODE: return theType.Location( "NODE", 1, theType.Length() );
599 case SMESH::EDGE: return theType.Location( "EDGE", 1, theType.Length() );
600 case SMESH::FACE: return theType.Location( "FACE", 1, theType.Length() );
601 case SMESH::VOLUME: return theType.Location( "VOLUME", 1, theType.Length() );
607 //================================================================================
610 * \param theCreationCmd -
612 //================================================================================
614 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd)
615 : _pyObject(theCreationCmd), myHasEditor(false)
617 // convert my creation command
618 Handle(_pyCommand) creationCmd = GetCreationCmd();
619 //TCollection_AsciiString str = creationCmd->GetMethod();
620 // if(str != "CreateMeshesFromUNV" &&
621 // str != "CreateMeshesFromMED" &&
622 // str != "CreateMeshesFromSTL")
623 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
624 creationCmd->SetMethod( "Mesh" );
626 theGen->SetAccessorMethod( GetID(), "GetMesh()" );
629 //================================================================================
632 * \param theCreationCmd -
634 //================================================================================
635 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString& id):
636 _pyObject(theCreationCmd), myHasEditor(false)
638 // convert my creation command
639 Handle(_pyCommand) creationCmd = GetCreationCmd();
640 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
641 theGen->SetAccessorMethod( id, "GetMesh()" );
644 //================================================================================
646 * \brief Convert a IDL API command of SMESH::Mesh to a method call of python Mesh
647 * \param theCommand - Engine method called for this mesh
649 //================================================================================
651 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
653 // some methods of SMESH_Mesh interface needs special conversion
654 // to methods of Mesh python class
656 // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
657 // --> in Mesh_Algorithm.Create(mesh, geom, hypo, so)
658 // 2. AddHypothesis(geom, hyp)
659 // --> in Mesh_Algorithm.Hypothesis(hyp, args, so)
660 // 3. CreateGroupFromGEOM(type, name, grp)
661 // --> in Mesh.Group(grp, name="")
662 // 4. ExportToMED(f, auto_groups, version)
663 // --> in Mesh.ExportMED( f, auto_groups, version )
666 const TCollection_AsciiString method = theCommand->GetMethod();
667 // ----------------------------------------------------------------------
668 if ( method == "GetSubMesh" ) {
669 mySubmeshes.push_back( theCommand );
671 // ----------------------------------------------------------------------
672 else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO )
673 myAddHypCmds.push_back( theCommand );
675 const _pyID& hypID = theCommand->GetArg( 2 );
676 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
677 if ( !hyp.IsNull() ) {
678 myHypos.push_back( hyp );
679 if ( hyp->GetMesh().IsEmpty() )
680 hyp->SetMesh( this->GetID() );
683 // ----------------------------------------------------------------------
684 else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
685 _pyID grp = theCommand->GetArg( 3 );
686 if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
687 theCommand->SetMethod( "Group" );
688 theCommand->RemoveArgs();
689 theCommand->SetArg( 1, grp );
692 AddMeshAccess( theCommand );
695 // ----------------------------------------------------------------------
696 else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
697 theCommand->SetMethod( "ExportMED" );
699 // ----------------------------------------------------------------------
700 else if ( method == "CreateGroup" ) { // CreateGroup() --> CreateEmptyGroup()
701 theCommand->SetMethod( "CreateEmptyGroup" );
703 // ----------------------------------------------------------------------
704 else if ( method == "RemoveHypothesis" ) // (geom, hyp)
706 _pyID hypID = theCommand->GetArg( 2 );
708 // check if this mesh still has corresponding addition command
709 bool hasAddCmd = false;
710 list< Handle(_pyCommand) >::iterator cmd = myAddHypCmds.begin();
711 while ( cmd != myAddHypCmds.end() )
713 // AddHypothesis(geom, hyp)
714 if ( hypID == (*cmd)->GetArg( 2 )) { // erase both (add and remove) commands
717 cmd = myAddHypCmds.erase( cmd );
724 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
725 if ( ! hasAddCmd && hypID.Length() != 0 ) { // hypo addition already wrapped
726 // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
727 _pyID geom = theCommand->GetArg( 1 );
728 theCommand->RemoveArgs();
729 theCommand->SetArg( 1, hypID );
730 if ( geom != GetGeom() )
731 theCommand->SetArg( 2, geom );
733 // remove hyp from myHypos
734 myHypos.remove( hyp );
736 // add accessor method if necessary
739 if ( NeedMeshAccess( theCommand ))
740 // apply theCommand to the mesh wrapped by smeshpy mesh
741 AddMeshAccess( theCommand );
745 //================================================================================
747 * \brief Return True if addition of accesor method is needed
749 //================================================================================
751 bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
753 // names of SMESH_Mesh methods fully equal to methods of class Mesh, so
754 // no conversion is needed for them at all:
755 static TStringSet sameMethods;
756 if ( sameMethods.empty() ) {
757 const char * names[] =
758 { "ExportDAT","ExportUNV","ExportSTL", "RemoveGroup","RemoveGroupWithContents",
759 "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
760 "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
761 "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
762 "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
763 "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
764 "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
765 "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
766 "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
767 "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
768 "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
769 "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
771 ,"" }; // <- mark of end
772 sameMethods.Insert( names );
775 return !sameMethods.Contains( theCommand->GetMethod() );
778 //================================================================================
780 * \brief Convert creation and addition of all algos and hypos
782 //================================================================================
784 void _pyMesh::Flush()
786 list < Handle(_pyCommand) >::iterator cmd, cmd2;
788 // try to convert algo addition like this:
789 // mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
790 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
792 Handle(_pyCommand) addCmd = *cmd;
793 _pyID algoID = addCmd->GetArg( 2 );
794 Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
795 if ( algo.IsNull() || !algo->IsAlgo() )
798 _pyID geom = addCmd->GetArg( 1 );
799 bool isLocalAlgo = ( geom != GetGeom() );
800 if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
802 // wrapped algo is created atfer mesh creation
803 GetCreationCmd()->AddDependantCmd( addCmd );
806 // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
807 addCmd->SetArg( addCmd->GetNbArgs() + 1,
808 TCollection_AsciiString( "geom=" ) + geom );
809 // sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
810 for ( cmd2 = mySubmeshes.begin(); cmd2 != mySubmeshes.end(); ++cmd2 ) {
811 Handle(_pyCommand) subCmd = *cmd2;
812 if ( geom == subCmd->GetArg( 1 )) {
813 subCmd->SetObject( algo->GetID() );
814 subCmd->RemoveArgs();
815 addCmd->AddDependantCmd( subCmd );
820 else // KO - ALGO was already created
822 // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
823 addCmd->RemoveArgs();
824 addCmd->SetArg( 1, algoID );
826 addCmd->SetArg( 2, geom );
830 // try to convert hypo addition like this:
831 // mesh.AddHypothesis(geom, HYPO ) --> HYPO = algo.Hypo()
832 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
834 Handle(_pyCommand) addCmd = *cmd;
835 _pyID hypID = addCmd->GetArg( 2 );
836 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
837 if ( hyp.IsNull() || hyp->IsAlgo() )
839 bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
841 // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
842 _pyID geom = addCmd->GetArg( 1 );
843 addCmd->RemoveArgs();
844 addCmd->SetArg( 1, hypID );
845 if ( geom != GetGeom() )
846 addCmd->SetArg( 2, geom );
850 // sm = mesh.GetSubMesh(geom, name) --> sm = mesh.GetMesh().GetSubMesh(geom, name)
851 // for ( cmd = mySubmeshes.begin(); cmd != mySubmeshes.end(); ++cmd ) {
852 // Handle(_pyCommand) subCmd = *cmd;
853 // if ( subCmd->GetNbArgs() > 0 )
854 // AddMeshAccess( subCmd );
856 myAddHypCmds.clear();
860 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
861 for ( ; hyp != myHypos.end(); ++hyp )
865 //================================================================================
867 * \brief MeshEditor convert its commands to ones of mesh
869 //================================================================================
871 _pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
872 _pyObject( theCreationCmd )
874 myMesh = theCreationCmd->GetObject();
875 myCreationCmdStr = theCreationCmd->GetString();
876 theCreationCmd->Clear();
879 //================================================================================
881 * \brief convert its commands to ones of mesh
883 //================================================================================
885 void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
887 // names of SMESH_MeshEditor methods fully equal to methods of class Mesh, so
888 // commands calling this methods are converted to calls of methods of Mesh
889 static TStringSet sameMethods;
890 if ( sameMethods.empty() ) {
891 const char * names[] = {
892 "RemoveElements","RemoveNodes","AddNode","AddEdge","AddFace","AddPolygonalFace",
893 "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode",
894 "InverseDiag","DeleteDiag","Reorient","ReorientObject","SplitQuad","SplitQuadObject",
895 "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
896 "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
897 "RotationSweep","RotationSweepObject","ExtrusionSweep","AdvancedExtrusion",
898 "ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D","Mirror",
899 "MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
900 "FindCoincidentNodes","FindCoincidentNodesOnPart","MergeNodes","FindEqualElements",
901 "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
902 "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
903 "GetLastCreatedElems",
904 "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
905 "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh"
906 ,"" }; // <- mark of the end
907 sameMethods.Insert( names );
910 // names of SMESH_MeshEditor methods which differ from methods of class Mesh
911 // only last two arguments
912 static TStringSet diffLastTwoArgsMethods;
913 if (diffLastTwoArgsMethods.empty() ){
914 const char * names[] = {
915 "MirrorMakeGroups","MirrorObjectMakeGroups",
916 "TranslateMakeGroups","TranslateObjectMakeGroups",
917 "RotateMakeGroups","RotateObjectMakeGroups",
918 ""};// <- mark of the end
919 diffLastTwoArgsMethods.Insert( names );
922 if ( sameMethods.Contains( theCommand->GetMethod() )) {
923 theCommand->SetObject( myMesh );
925 // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
926 // so let _pyMesh care of it (TMP?)
927 // if ( theCommand->GetMethod().Search("MakeMesh") != -1 )
928 // _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod()
932 //Replace SMESH_MeshEditor "MakeGroups" functions on the Mesh
933 //functions with the flag "theMakeGroups = True" like:
934 //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
935 int pos = theCommand->GetMethod().Search("MakeGroups");
937 // 1. Remove "MakeGroups" from the Command
938 TCollection_AsciiString aMethod = theCommand->GetMethod();
939 int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
940 aMethod.Trunc(pos-1);
941 theCommand->SetMethod(aMethod);
943 // 2. Set Mesh object instead of SMESH_MeshEditor
944 theCommand->SetObject( myMesh );
946 // 3. And add last "True" argument
948 theCommand->SetArg(theCommand->GetNbArgs()+1,"True ");
951 // editor creation command is needed only if any editor function is called
952 theGen->AddMeshAccessorMethod( theCommand ); // for *Object()
953 if ( !myCreationCmdStr.IsEmpty() ) {
954 GetCreationCmd()->GetString() = myCreationCmdStr;
955 myCreationCmdStr.Clear();
961 //================================================================================
963 * \brief _pyHypothesis constructor
964 * \param theCreationCmd -
966 //================================================================================
968 _pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
969 _pyObject( theCreationCmd )
971 myIsAlgo = myIsWrapped = /*myIsConverted = myIsLocal = myDim = */false;
974 //================================================================================
976 * \brief Creates algorithm or hypothesis
977 * \param theCreationCmd - The engine command creating a hypothesis
978 * \retval Handle(_pyHypothesis) - Result _pyHypothesis
980 //================================================================================
982 Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& theCreationCmd)
984 // theCreationCmd: CreateHypothesis( "theHypType", "theLibName" )
985 ASSERT (( theCreationCmd->GetMethod() == "CreateHypothesis"));
987 Handle(_pyHypothesis) hyp, algo;
990 const TCollection_AsciiString & hypTypeQuoted = theCreationCmd->GetArg( 1 );
991 if ( hypTypeQuoted.IsEmpty() )
994 TCollection_AsciiString hypType =
995 hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
997 algo = new _pyAlgorithm( theCreationCmd );
998 hyp = new _pyHypothesis( theCreationCmd );
1000 // 1D Regular_1D ----------
1001 if ( hypType == "Regular_1D" ) {
1002 // set mesh's method creating algo,
1003 // i.e. convertion result will be "regular1d = Mesh.Segment()",
1004 // and set hypType by which algo creating a hypothesis is searched for
1005 algo->SetConvMethodAndType("Segment", hypType.ToCString());
1007 else if ( hypType == "CompositeSegment_1D" ) {
1008 algo->SetConvMethodAndType("Segment", "Regular_1D");
1009 algo->myArgs.Append( "algo=smesh.COMPOSITE");
1011 else if ( hypType == "LocalLength" ) {
1012 // set algo's method creating hyp, and algo type
1013 hyp->SetConvMethodAndType( "LocalLength", "Regular_1D");
1014 // set method whose 1 arg will become the 1-st arg of hyp creation command
1015 // i.e. convertion result will be "locallength = regular1d.LocalLength(<arg of SetLength()>)"
1016 hyp->AddArgMethod( "SetLength" );
1018 else if ( hypType == "NumberOfSegments" ) {
1019 hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
1020 hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
1021 // arg of SetNumberOfSegments() will become the 1-st arg of hyp creation command
1022 hyp->AddArgMethod( "SetNumberOfSegments" );
1023 // arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
1024 hyp->AddArgMethod( "SetScaleFactor" );
1026 else if ( hypType == "Arithmetic1D" ) {
1027 hyp = new _pyComplexParamHypo( theCreationCmd );
1028 hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
1030 else if ( hypType == "StartEndLength" ) {
1031 hyp = new _pyComplexParamHypo( theCreationCmd );
1032 hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
1034 else if ( hypType == "Deflection1D" ) {
1035 hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
1036 hyp->AddArgMethod( "SetDeflection" );
1038 else if ( hypType == "Propagation" ) {
1039 hyp->SetConvMethodAndType( "Propagation", "Regular_1D");
1041 else if ( hypType == "QuadraticMesh" ) {
1042 hyp->SetConvMethodAndType( "QuadraticMesh", "Regular_1D");
1044 else if ( hypType == "AutomaticLength" ) {
1045 hyp->SetConvMethodAndType( "AutomaticLength", "Regular_1D");
1046 hyp->AddArgMethod( "SetFineness");
1048 else if ( hypType == "SegmentLengthAroundVertex" ) {
1049 hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
1050 hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
1051 hyp->AddArgMethod( "SetLength" );
1053 // 1D Python_1D ----------
1054 else if ( hypType == "Python_1D" ) {
1055 algo->SetConvMethodAndType( "Segment", hypType.ToCString());
1056 algo->myArgs.Append( "algo=smesh.PYTHON");
1058 else if ( hypType == "PythonSplit1D" ) {
1059 hyp->SetConvMethodAndType( "PythonSplit1D", "Python_1D");
1060 hyp->AddArgMethod( "SetNumberOfSegments");
1061 hyp->AddArgMethod( "SetPythonLog10RatioFunction");
1063 // MEFISTO_2D ----------
1064 else if ( hypType == "MEFISTO_2D" ) { // MEFISTO_2D
1065 algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
1067 else if ( hypType == "MaxElementArea" ) {
1068 hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
1069 hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
1070 hyp->AddArgMethod( "SetMaxElementArea");
1072 else if ( hypType == "LengthFromEdges" ) {
1073 hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
1074 hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
1076 // Quadrangle_2D ----------
1077 else if ( hypType == "Quadrangle_2D" ) {
1078 algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
1080 else if ( hypType == "QuadranglePreference" ) {
1081 hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
1082 hyp->SetConvMethodAndType( "QuadranglePreference", "NETGEN_2D_ONLY");
1084 else if ( hypType == "TrianglePreference" ) {
1085 hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
1087 // NETGEN ----------
1088 // else if ( hypType == "NETGEN_2D") { // 1D-2D
1089 // algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1090 // algo->myArgs.Append( "algo=smesh.NETGEN" );
1092 else if ( hypType == "NETGEN_2D_ONLY") { // 2D
1093 algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1094 algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
1096 else if ( hypType == "NETGEN_3D") { // 3D
1097 algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
1098 algo->myArgs.Append( "algo=smesh.NETGEN" );
1100 else if ( hypType == "MaxElementVolume") {
1101 hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
1102 hyp->AddArgMethod( "SetMaxElementVolume" );
1104 // GHS3D_3D ----------
1105 else if ( hypType == "GHS3D_3D" ) {
1106 algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
1107 algo->myArgs.Append( "algo=smesh.GHS3D" );
1109 // Hexa_3D ---------
1110 else if ( hypType == "Hexa_3D" ) {
1111 algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
1113 // Repetitive Projection_1D ---------
1114 else if ( hypType == "Projection_1D" ) {
1115 algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
1117 else if ( hypType == "ProjectionSource1D" ) {
1118 hyp->SetConvMethodAndType( "SourceEdge", "Projection_1D");
1119 hyp->AddArgMethod( "SetSourceEdge");
1120 hyp->AddArgMethod( "SetSourceMesh");
1121 // 2 args of SetVertexAssociation() will become the 3-th and 4-th args of hyp creation command
1122 hyp->AddArgMethod( "SetVertexAssociation", 2 );
1124 // Projection_2D ---------
1125 else if ( hypType == "Projection_2D" ) {
1126 algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
1128 else if ( hypType == "ProjectionSource2D" ) {
1129 hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
1130 hyp->AddArgMethod( "SetSourceFace");
1131 hyp->AddArgMethod( "SetSourceMesh");
1132 hyp->AddArgMethod( "SetVertexAssociation", 4 );
1134 // Projection_3D ---------
1135 else if ( hypType == "Projection_3D" ) {
1136 algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
1138 else if ( hypType == "ProjectionSource3D" ) {
1139 hyp->SetConvMethodAndType( "SourceShape3D", "Projection_3D");
1140 hyp->AddArgMethod( "SetSource3DShape");
1141 hyp->AddArgMethod( "SetSourceMesh");
1142 hyp->AddArgMethod( "SetVertexAssociation", 4 );
1144 // Prism_3D ---------
1145 else if ( hypType == "Prism_3D" ) {
1146 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1148 // RadialPrism_3D ---------
1149 else if ( hypType == "RadialPrism_3D" ) {
1150 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1152 else if ( hypType == "NumberOfLayers" ) {
1153 hyp->SetConvMethodAndType( "NumberOfLayers", "RadialPrism_3D");
1154 hyp->AddArgMethod( "SetNumberOfLayers" );
1156 else if ( hypType == "LayerDistribution" ) {
1157 hyp = new _pyLayerDistributionHypo( theCreationCmd );
1158 hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
1161 if ( algo->IsValid() ) {
1167 //================================================================================
1169 * \brief Convert the command adding a hypothesis to mesh into a smesh command
1170 * \param theCmd - The command like mesh.AddHypothesis( geom, hypo )
1171 * \param theAlgo - The algo that can create this hypo
1172 * \retval bool - false if the command cant be converted
1174 //================================================================================
1176 bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
1177 const _pyID& theMesh)
1179 ASSERT(( theCmd->GetMethod() == "AddHypothesis" ));
1181 if ( !IsWrappable( theMesh ))
1184 myGeom = theCmd->GetArg( 1 );
1186 Handle(_pyHypothesis) algo;
1188 // find algo created on myGeom in theMesh
1189 algo = theGen->FindAlgo( myGeom, theMesh, this );
1190 if ( algo.IsNull() )
1192 algo->GetCreationCmd()->AddDependantCmd( theCmd );
1196 // mesh.AddHypothesis(geom,hyp) --> hyp = <theMesh or algo>.myCreationMethod(args)
1197 theCmd->SetResultValue( GetID() );
1198 theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
1199 theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
1201 theCmd->RemoveArgs();
1202 for ( int i = 1; i <= myArgs.Length(); ++i ) {
1203 if ( !myArgs( i ).IsEmpty() )
1204 theCmd->SetArg( i, myArgs( i ));
1206 theCmd->SetArg( i, "[]");
1208 // set a new creation command
1209 GetCreationCmd()->Clear();
1210 SetCreationCmd( theCmd );
1212 // clear commands setting arg values
1213 list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
1214 for ( ; argCmd != myArgCommands.end(); ++argCmd )
1217 // set unknown arg commands after hypo creation
1218 Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
1219 list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
1220 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1221 afterCmd->AddDependantCmd( *cmd );
1227 //================================================================================
1229 * \brief Remember hypothesis parameter values
1230 * \param theCommand - The called hypothesis method
1232 //================================================================================
1234 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
1236 ASSERT( !myIsAlgo );
1239 for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
1240 if ( myArgMethods( i ) == theCommand->GetMethod() ) {
1241 while ( myArgs.Length() < nbArgs + myNbArgsByMethod( i ))
1242 myArgs.Append( "[]" );
1243 for ( int iArg = 1; iArg <= myNbArgsByMethod( i ); ++iArg )
1244 myArgs( nbArgs + iArg ) = theCommand->GetArg( iArg ); // arg value
1245 myArgCommands.push_back( theCommand );
1248 nbArgs += myNbArgsByMethod( i );
1250 myUnknownCommands.push_back( theCommand );
1253 //================================================================================
1255 * \brief Finish conversion
1257 //================================================================================
1259 void _pyHypothesis::Flush()
1261 if ( IsWrapped() ) {
1264 list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
1265 for ( ; cmd != myArgCommands.end(); ++cmd ) {
1266 // Add access to a wrapped mesh
1267 theGen->AddMeshAccessorMethod( *cmd );
1268 // Add access to a wrapped algorithm
1269 theGen->AddAlgoAccessorMethod( *cmd );
1271 cmd = myUnknownCommands.begin();
1272 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1273 // Add access to a wrapped mesh
1274 theGen->AddMeshAccessorMethod( *cmd );
1275 // Add access to a wrapped algorithm
1276 theGen->AddAlgoAccessorMethod( *cmd );
1279 // forget previous hypothesis modifications
1280 myArgCommands.clear();
1281 myUnknownCommands.clear();
1284 //================================================================================
1286 * \brief clear creation, arg and unkown commands
1288 //================================================================================
1290 void _pyHypothesis::ClearAllCommands()
1292 GetCreationCmd()->Clear();
1293 list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
1294 for ( ; cmd != myArgCommands.end(); ++cmd )
1296 cmd = myUnknownCommands.begin();
1297 for ( ; cmd != myUnknownCommands.end(); ++cmd )
1301 //================================================================================
1303 * \brief Remember hypothesis parameter values
1304 * \param theCommand - The called hypothesis method
1306 //================================================================================
1308 void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
1310 // ex: hyp.SetLength(start, 1)
1311 // hyp.SetLength(end, 0)
1312 ASSERT(( theCommand->GetMethod() == "SetLength" ));
1313 ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
1314 int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
1315 while ( myArgs.Length() < i )
1316 myArgs.Append( "[]" );
1317 myArgs( i ) = theCommand->GetArg( 1 ); // arg value
1318 myArgCommands.push_back( theCommand );
1321 //================================================================================
1323 * \brief Convert methods of 1D hypotheses to my own methods
1324 * \param theCommand - The called hypothesis method
1326 //================================================================================
1328 void _pyLayerDistributionHypo::Process( const Handle(_pyCommand)& theCommand)
1330 if ( theCommand->GetMethod() != "SetLayerDistribution" )
1333 _pyID newName; // name for 1D hyp = "HypType" + "_Distribution"
1335 const _pyID& hyp1dID = theCommand->GetArg( 1 );
1336 Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
1337 if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
1339 else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() ) {
1340 // 1D hypo is already set, so distribution changes and the old
1341 // 1D hypo is thrown away
1342 my1dHyp->ClearAllCommands();
1345 if ( my1dHyp.IsNull() )
1346 return; // something wrong :(
1348 // make a new name for 1D hyp = "HypType" + "_Distribution"
1349 if ( my1dHyp->GetCreationCmd()->GetMethod() == "CreateHypothesis" ) {
1350 // not yet converted creation cmd
1351 TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
1352 TCollection_AsciiString hypType = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
1353 newName = hypType + "_Distribution";
1354 my1dHyp->GetCreationCmd()->SetResultValue( newName );
1357 // already converted creation cmd
1358 newName = my1dHyp->GetCreationCmd()->GetResultValue();
1361 // as creation of 1D hyp was written later then it's edition,
1362 // we need to find all it's edition calls and process them
1363 list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
1364 list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
1365 for ( ; cmdIt != cmds.end(); ++cmdIt ) {
1366 const _pyID& objID = (*cmdIt)->GetObject();
1367 if ( objID == hyp1dID ) {
1368 my1dHyp->Process( *cmdIt );
1369 my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
1370 ( *cmdIt )->SetObject( newName );
1373 if ( !myArgCommands.empty() )
1374 myArgCommands.front()->Clear();
1375 theCommand->SetArg( 1, newName );
1376 myArgCommands.push_back( theCommand );
1377 // copy hyp1d's creation method and args
1378 // myCreationMethod = hyp1d->GetCreationMethod();
1379 // myArgs = hyp1d->GetArgs();
1380 // // make them cleared at conversion
1381 // myArgCommands = hyp1d->GetArgCommands();
1383 // // to be cleared at convertion only
1384 // myArgCommands.push_back( theCommand );
1387 //================================================================================
1390 * \param theAdditionCmd -
1394 //================================================================================
1396 bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
1397 const _pyID& theMesh)
1399 myIsWrapped = false;
1401 if ( my1dHyp.IsNull() )
1404 // set "SetLayerDistribution()" after addition cmd
1405 theAdditionCmd->AddDependantCmd( myArgCommands.front() );
1407 _pyID geom = theAdditionCmd->GetArg( 1 );
1409 my1dHyp->SetMesh( theMesh );
1410 if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
1413 // clear "SetLayerDistribution()" cmd
1414 myArgCommands.front()->Clear();
1416 // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
1418 // find RadialPrism algo created on <geom> for theMesh
1419 Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
1420 if ( !algo.IsNull() ) {
1421 GetCreationCmd()->SetObject( algo->GetID() );
1422 GetCreationCmd()->SetMethod( "Get3DHypothesis" );
1423 GetCreationCmd()->RemoveArgs();
1424 theAdditionCmd->AddDependantCmd( GetCreationCmd() );
1430 //================================================================================
1434 //================================================================================
1436 void _pyLayerDistributionHypo::Flush()
1438 //my1dHyp.Nullify();
1439 //_pyHypothesis::Flush();
1442 //================================================================================
1444 * \brief additionally to Addition2Creation, clears SetDistrType() command
1445 * \param theCmd - AddHypothesis() command
1446 * \param theMesh - mesh to which a hypothesis is added
1447 * \retval bool - convertion result
1449 //================================================================================
1451 bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1452 const _pyID& theMesh)
1454 if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
1455 // scale factor (2-nd arg) is provided: clear SetDistrType(1) command
1456 bool scaleDistrType = false;
1457 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1458 for ( ; cmd != myUnknownCommands.rend(); ++cmd ) {
1459 if ( (*cmd)->GetMethod() == "SetDistrType" ) {
1460 if ( (*cmd)->GetArg( 1 ) == "1" ) {
1461 scaleDistrType = true;
1464 else if ( !scaleDistrType ) {
1465 // distribution type changed: remove scale factor from args
1466 myArgs.Remove( 2, myArgs.Length() );
1472 return _pyHypothesis::Addition2Creation( theCmd, theMesh );
1475 //================================================================================
1477 * \brief remove repeated commands defining distribution
1479 //================================================================================
1481 void _pyNumberOfSegmentsHyp::Flush()
1483 // find number of the last SetDistrType() command
1484 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1485 int distrTypeNb = 0;
1486 for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
1487 if ( (*cmd)->GetMethod() == "SetDistrType" )
1488 distrTypeNb = (*cmd)->GetOrderNb();
1490 // clear commands before the last SetDistrType()
1491 list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
1492 for ( int i = 0; i < 2; ++i ) {
1493 set<TCollection_AsciiString> uniqueMethods;
1494 list<Handle(_pyCommand)> & cmdList = *cmds[i];
1495 for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
1497 bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
1498 const TCollection_AsciiString& method = (*cmd)->GetMethod();
1499 if ( !clear || method == "SetNumberOfSegments" ) {
1500 bool isNewInSet = uniqueMethods.insert( method ).second;
1501 clear = !isNewInSet;
1510 //================================================================================
1512 * \brief Convert the command adding "SegmentLengthAroundVertex" to mesh
1513 * into regular1D.LengthNearVertex( length, vertex )
1514 * \param theCmd - The command like mesh.AddHypothesis( vertex, SegmentLengthAroundVertex )
1515 * \param theMesh - The mesh needing this hypo
1516 * \retval bool - false if the command cant be converted
1518 //================================================================================
1520 bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1521 const _pyID& theMeshID)
1523 if ( IsWrappable( theMeshID )) {
1525 _pyID vertex = theCmd->GetArg( 1 );
1527 // the problem here is that segment algo will not be found
1528 // by pyHypothesis::Addition2Creation() for <vertex>, so we try to find
1529 // geometry where segment algorithm is assigned
1530 Handle(_pyHypothesis) algo;
1531 _pyID geom = vertex;
1532 while ( algo.IsNull() && !geom.IsEmpty()) {
1533 // try to find geom as a father of <vertex>
1534 geom = FatherID( geom );
1535 algo = theGen->FindAlgo( geom, theMeshID, this );
1537 if ( algo.IsNull() )
1538 return false; // also possible to find geom as brother of veretex...
1539 // set geom instead of vertex
1540 theCmd->SetArg( 1, geom );
1542 // set vertex as a second arg
1543 if ( myArgs.Length() < 1) myArgs.Append( "1" ); // :(
1544 myArgs.Append( vertex );
1546 // mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) -->
1547 // theMeshID.LengthNearVertex( length, vertex )
1548 return _pyHypothesis::Addition2Creation( theCmd, theMeshID );
1553 //================================================================================
1555 * \brief _pyAlgorithm constructor
1556 * \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)"
1558 //================================================================================
1560 _pyAlgorithm::_pyAlgorithm(const Handle(_pyCommand)& theCreationCmd)
1561 : _pyHypothesis( theCreationCmd )
1566 //================================================================================
1568 * \brief Convert the command adding an algorithm to mesh
1569 * \param theCmd - The command like mesh.AddHypothesis( geom, algo )
1570 * \param theMesh - The mesh needing this algo
1571 * \retval bool - false if the command cant be converted
1573 //================================================================================
1575 bool _pyAlgorithm::Addition2Creation( const Handle(_pyCommand)& theCmd,
1576 const _pyID& theMeshID)
1578 // mesh.AddHypothesis(geom,algo) --> theMeshID.myCreationMethod()
1579 if ( _pyHypothesis::Addition2Creation( theCmd, theMeshID )) {
1580 theGen->SetAccessorMethod( GetID(), "GetAlgorithm()" );
1586 //================================================================================
1588 * \brief Return starting position of a part of python command
1589 * \param thePartIndex - The index of command part
1590 * \retval int - Part position
1592 //================================================================================
1594 int _pyCommand::GetBegPos( int thePartIndex )
1598 if ( myBegPos.Length() < thePartIndex )
1600 return myBegPos( thePartIndex );
1603 //================================================================================
1605 * \brief Store starting position of a part of python command
1606 * \param thePartIndex - The index of command part
1607 * \param thePosition - Part position
1609 //================================================================================
1611 void _pyCommand::SetBegPos( int thePartIndex, int thePosition )
1613 while ( myBegPos.Length() < thePartIndex )
1614 myBegPos.Append( UNKNOWN );
1615 myBegPos( thePartIndex ) = thePosition;
1618 //================================================================================
1620 * \brief Returns whitespace symbols at the line beginning
1621 * \retval TCollection_AsciiString - result
1623 //================================================================================
1625 TCollection_AsciiString _pyCommand::GetIndentation()
1628 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
1629 GetWord( myString, end, true );
1631 end = GetBegPos( RESULT_IND );
1632 return myString.SubString( 1, end - 1 );
1635 //================================================================================
1637 * \brief Return substring of python command looking like ResultValue = Obj.Meth()
1638 * \retval const TCollection_AsciiString & - ResultValue substring
1640 //================================================================================
1642 const TCollection_AsciiString & _pyCommand::GetResultValue()
1644 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
1646 int begPos = myString.Location( "=", 1, Length() );
1648 myRes = GetWord( myString, begPos, false );
1651 SetBegPos( RESULT_IND, begPos );
1656 //================================================================================
1658 * \brief Return number of python command result value ResultValue = Obj.Meth()
1661 //================================================================================
1663 const int _pyCommand::GetNbResultValues()
1667 int endPos = myString.Location( "=", 1, Length() );
1668 TCollection_AsciiString str = "";
1669 while ( begPos < endPos) {
1670 str = GetWord( myString, begPos, true );
1671 begPos = begPos+ str.Length();
1678 //================================================================================
1680 * \brief Return substring of python command looking like
1681 * ResultValue1 , ResultValue1,... = Obj.Meth() with res index
1682 * \retval const TCollection_AsciiString & - ResultValue with res index substring
1684 //================================================================================
1685 const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
1689 int endPos = myString.Location( "=", 1, Length() );
1690 while ( begPos < endPos) {
1691 myRes = GetWord( myString, begPos, true );
1692 begPos = begPos + myRes.Length();
1695 myRes.RemoveAll('[');myRes.RemoveAll(']');
1701 return theEmptyString;
1704 //================================================================================
1706 * \brief Return substring of python command looking like ResVal = Object.Meth()
1707 * \retval const TCollection_AsciiString & - Object substring
1709 //================================================================================
1711 const TCollection_AsciiString & _pyCommand::GetObject()
1713 if ( GetBegPos( OBJECT_IND ) == UNKNOWN )
1716 int begPos = GetBegPos( RESULT_IND ) + myRes.Length();
1718 begPos = myString.Location( "=", 1, Length() ) + 1;
1720 myObj = GetWord( myString, begPos, true );
1721 SetBegPos( OBJECT_IND, begPos );
1727 //================================================================================
1729 * \brief Return substring of python command looking like ResVal = Obj.Method()
1730 * \retval const TCollection_AsciiString & - Method substring
1732 //================================================================================
1734 const TCollection_AsciiString & _pyCommand::GetMethod()
1736 if ( GetBegPos( METHOD_IND ) == UNKNOWN )
1739 int begPos = GetBegPos( OBJECT_IND ) + myObj.Length();
1740 bool forward = true;
1742 begPos = myString.Location( "(", 1, Length() ) - 1;
1746 myMeth = GetWord( myString, begPos, forward );
1747 SetBegPos( METHOD_IND, begPos );
1753 //================================================================================
1755 * \brief Return substring of python command looking like ResVal = Obj.Meth(Arg1,...)
1756 * \retval const TCollection_AsciiString & - Arg<index> substring
1758 //================================================================================
1760 const TCollection_AsciiString & _pyCommand::GetArg( int index )
1762 if ( GetBegPos( ARG1_IND ) == UNKNOWN )
1765 int begPos = GetBegPos( METHOD_IND ) + myMeth.Length();
1767 begPos = myString.Location( "(", 1, Length() ) + 1;
1769 int i = 0, prevLen = 0;
1770 while ( begPos != EMPTY ) {
1772 // check if we are looking at the closing parenthesis
1773 while ( begPos <= Length() && isspace( myString.Value( begPos )))
1775 if ( begPos > Length() || myString.Value( begPos ) == ')' )
1777 myArgs.Append( GetWord( myString, begPos, true, true ));
1778 SetBegPos( ARG1_IND + i, begPos );
1779 prevLen = myArgs.Last().Length();
1781 myArgs.Remove( myArgs.Length() ); // no more args
1785 if ( myArgs.Length() < index )
1786 return theEmptyString;
1787 return myArgs( index );
1790 //================================================================================
1792 * \brief Check if char is a word part
1793 * \param c - The character to check
1794 * \retval bool - The check result
1796 //================================================================================
1798 static inline bool isWord(const char c, const bool dotIsWord)
1801 !isspace(c) && c != ',' && c != '=' && c != ')' && c != '(' && ( dotIsWord || c != '.');
1804 //================================================================================
1806 * \brief Looks for a word in the string and returns word's beginning
1807 * \param theString - The input string
1808 * \param theStartPos - The position to start the search, returning word's beginning
1809 * \param theForward - The search direction
1810 * \retval TCollection_AsciiString - The found word
1812 //================================================================================
1814 TCollection_AsciiString _pyCommand::GetWord( const TCollection_AsciiString & theString,
1816 const bool theForward,
1817 const bool dotIsWord )
1819 int beg = theStartPos, end = theStartPos;
1820 theStartPos = EMPTY;
1821 if ( beg < 1 || beg > theString.Length() )
1822 return theEmptyString;
1824 if ( theForward ) { // search forward
1826 while ( beg <= theString.Length() && !isWord( theString.Value( beg ), dotIsWord))
1828 if ( beg > theString.Length() )
1829 return theEmptyString; // no word found
1832 while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
1836 else { // search backward
1838 while ( end > 0 && !isWord( theString.Value( end ), dotIsWord))
1841 return theEmptyString; // no word found
1843 while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
1848 //cout << theString << " ---- " << beg << " - " << end << endl;
1849 return theString.SubString( beg, end );
1852 //================================================================================
1854 * \brief Look for position where not space char is
1855 * \param theString - The string
1856 * \param thePos - The position to search from and which returns result
1857 * \retval bool - false if there are only space after thePos in theString
1861 //================================================================================
1863 bool _pyCommand::SkipSpaces( const TCollection_AsciiString & theString, int & thePos )
1865 if ( thePos < 1 || thePos > theString.Length() )
1868 while ( thePos <= theString.Length() && isspace( theString.Value( thePos )))
1871 return thePos <= theString.Length();
1874 //================================================================================
1876 * \brief Modify a part of the command
1877 * \param thePartIndex - The index of the part
1878 * \param thePart - The new part string
1879 * \param theOldPart - The old part
1881 //================================================================================
1883 void _pyCommand::SetPart(int thePartIndex, const TCollection_AsciiString& thePart,
1884 TCollection_AsciiString& theOldPart)
1886 int pos = GetBegPos( thePartIndex );
1887 if ( pos <= Length() && theOldPart != thePart)
1889 TCollection_AsciiString seperator;
1891 pos = GetBegPos( thePartIndex + 1 );
1892 if ( pos < 1 ) return;
1893 switch ( thePartIndex ) {
1894 case RESULT_IND: seperator = " = "; break;
1895 case OBJECT_IND: seperator = "."; break;
1896 case METHOD_IND: seperator = "()"; break;
1900 myString.Remove( pos, theOldPart.Length() );
1901 if ( !seperator.IsEmpty() )
1902 myString.Insert( pos , seperator );
1903 myString.Insert( pos, thePart );
1904 // update starting positions of the following parts
1905 int posDelta = thePart.Length() + seperator.Length() - theOldPart.Length();
1906 for ( int i = thePartIndex + 1; i <= myBegPos.Length(); ++i ) {
1907 if ( myBegPos( i ) > 0 )
1908 myBegPos( i ) += posDelta;
1910 theOldPart = thePart;
1914 //================================================================================
1916 * \brief Set agrument
1917 * \param index - The argument index, it counts from 1
1918 * \param theArg - The argument string
1920 //================================================================================
1922 void _pyCommand::SetArg( int index, const TCollection_AsciiString& theArg)
1925 int argInd = ARG1_IND + index - 1;
1926 int pos = GetBegPos( argInd );
1927 if ( pos < 1 ) // no index-th arg exist, append inexistent args
1929 // find a closing parenthesis
1930 if ( int lastArgInd = GetNbArgs() ) {
1931 pos = GetBegPos( ARG1_IND + lastArgInd - 1 ) + GetArg( lastArgInd ).Length();
1932 while ( pos > 0 && pos <= Length() && myString.Value( pos ) != ')' )
1937 while ( pos > 0 && myString.Value( pos ) != ')' )
1940 if ( pos < 1 || myString.Value( pos ) != ')' ) { // no parentheses at all
1944 while ( myArgs.Length() < index ) {
1945 if ( myArgs.Length() )
1946 myString.Insert( pos++, "," );
1947 myArgs.Append("None");
1948 myString.Insert( pos, myArgs.Last() );
1949 SetBegPos( ARG1_IND + myArgs.Length() - 1, pos );
1950 pos += myArgs.Last().Length();
1953 SetPart( argInd, theArg, myArgs( index ));
1956 //================================================================================
1958 * \brief Empty arg list
1960 //================================================================================
1962 void _pyCommand::RemoveArgs()
1964 if ( int pos = myString.Location( '(', 1, Length() ))
1965 myString.Trunc( pos );
1968 if ( myBegPos.Length() >= ARG1_IND )
1969 myBegPos.Remove( ARG1_IND, myBegPos.Length() );
1972 //================================================================================
1974 * \brief Set dependent commands after this one
1976 //================================================================================
1978 bool _pyCommand::SetDependentCmdsAfter() const
1980 bool orderChanged = false;
1981 list< Handle(_pyCommand)>::const_reverse_iterator cmd = myDependentCmds.rbegin();
1982 for ( ; cmd != myDependentCmds.rend(); ++cmd ) {
1983 if ( (*cmd)->GetOrderNb() < GetOrderNb() ) {
1984 orderChanged = true;
1985 theGen->SetCommandAfter( *cmd, this );
1986 (*cmd)->SetDependentCmdsAfter();
1989 return orderChanged;
1991 //================================================================================
1993 * \brief Insert accessor method after theObjectID
1994 * \param theObjectID - id of the accessed object
1995 * \param theAcsMethod - name of the method giving access to the object
1996 * \retval bool - false if theObjectID is not found in the command string
1998 //================================================================================
2000 bool _pyCommand::AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod )
2002 if ( !theAcsMethod )
2004 // start object search from the object, i.e. ignore result
2006 int beg = GetBegPos( OBJECT_IND );
2007 if ( beg < 1 || beg > Length() )
2010 while (( beg = myString.Location( theObjectID, beg, Length() )))
2012 // check that theObjectID is not just a part of a longer ID
2013 int afterEnd = beg + theObjectID.Length();
2014 Standard_Character c = myString.Value( afterEnd );
2015 if ( !isalnum( c ) && c != ':' ) {
2016 // check if accessor method already present
2018 myString.Location( (char*) theAcsMethod, afterEnd, Length() ) != afterEnd+1) {
2020 int oldLen = Length();
2021 myString.Insert( afterEnd, (char*) theAcsMethod );
2022 myString.Insert( afterEnd, "." );
2023 // update starting positions of the parts following the modified one
2024 int posDelta = Length() - oldLen;
2025 for ( int i = 1; i <= myBegPos.Length(); ++i ) {
2026 if ( myBegPos( i ) > afterEnd )
2027 myBegPos( i ) += posDelta;
2032 beg = afterEnd; // is a part - next search
2037 //================================================================================
2039 * \brief Return method name giving access to an interaface object wrapped by python class
2040 * \retval const char* - method name
2042 //================================================================================
2044 const char* _pyObject::AccessorMethod() const
2048 //================================================================================
2050 * \brief Return ID of a father
2052 //================================================================================
2054 _pyID _pyObject::FatherID(const _pyID & childID)
2056 int colPos = childID.SearchFromEnd(':');
2058 return childID.SubString( 1, colPos-1 );