1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_2D_Algo_i.hxx
24 // Author : Paul RASCLE, EDF
27 // File : SMESH_2smeshpy.cxx
28 // Created : Fri Nov 18 13:20:10 2005
29 // Author : Edward AGAPOV (eap)
31 #include "SMESH_2smeshpy.hxx"
33 #include "utilities.h"
34 #include "SMESH_PythonDump.hxx"
35 #include "Resource_DataMapOfAsciiStringAsciiString.hxx"
37 #include "SMESH_Gen_i.hxx"
38 /* SALOME headers that include CORBA headers that include windows.h
39 * that defines GetObject symbol as GetObjectA should stand before SALOME headers
40 * that declare methods named GetObject - to apply the same rules of GetObject renaming
41 * and thus to avoid mess with GetObject symbol on Windows */
43 IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient);
44 IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
45 IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject);
46 IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject);
47 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor ,_pyObject);
48 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis ,_pyObject);
49 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
50 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
51 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis);
53 IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient);
54 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient);
55 IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject);
56 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject);
57 IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject);
58 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject);
59 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis);
60 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
61 IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis);
62 IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis);
63 IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis);
66 using SMESH::TPythonDump;
69 * \brief Container of commands into which the initial script is split.
70 * It also contains data coresponding to SMESH_Gen contents
72 static Handle(_pyGen) theGen;
74 static TCollection_AsciiString theEmptyString;
76 //#define DUMP_CONVERSION
78 #if !defined(_DEBUG_) && defined(DUMP_CONVERSION)
79 #undef DUMP_CONVERSION
85 //================================================================================
87 * \brief Set of TCollection_AsciiString initialized by C array of C strings
89 //================================================================================
91 struct TStringSet: public set<TCollection_AsciiString>
94 * \brief Filling. The last string must be ""
96 void Insert(const char* names[]) {
97 for ( int i = 0; names[i][0] ; ++i )
98 insert( (char*) names[i] );
101 * \brief Check if a string is in
103 bool Contains(const TCollection_AsciiString& name ) {
104 return find( name ) != end();
109 //================================================================================
111 * \brief Convert python script using commands of smesh.py
112 * \param theScript - Input script
113 * \retval TCollection_AsciiString - Convertion result
115 * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
117 //================================================================================
119 TCollection_AsciiString
120 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
121 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
123 theGen = new _pyGen( theEntry2AccessorMethod );
125 // split theScript into separate commands
126 int from = 1, end = theScript.Length(), to;
127 while ( from < end && ( to = theScript.Location( "\n", from, end )))
130 // cut out and store a command
131 theGen->AddCommand( theScript.SubString( from, to - 1 ));
136 #ifdef DUMP_CONVERSION
137 MESSAGE_BEGIN ( std::endl << " ######## RESULT ######## " << std::endl<< std::endl );
139 // reorder commands after conversion
140 list< Handle(_pyCommand) >::iterator cmd;
143 orderChanges = false;
144 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
145 if ( (*cmd)->SetDependentCmdsAfter() )
147 } while ( orderChanges );
149 // concat commands back into a script
150 TCollection_AsciiString aScript;
151 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
153 #ifdef DUMP_CONVERSION
154 MESSAGE_ADD ( "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << std::endl );
156 if ( !(*cmd)->IsEmpty() ) {
158 aScript += (*cmd)->GetString();
168 //================================================================================
170 * \brief _pyGen constructor
172 //================================================================================
174 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
175 : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
176 myID2AccessorMethod( theEntry2AccessorMethod )
179 myHasPattern = false;
180 // make that GetID() to return TPythonDump::SMESHGenName()
181 GetCreationCmd()->GetString() += "=";
184 //================================================================================
186 * \brief name of SMESH_Gen in smesh.py
188 //================================================================================
190 const char* _pyGen::AccessorMethod() const
192 return SMESH_2smeshpy::GenName();
195 //================================================================================
197 * \brief Convert a command using a specific converter
198 * \param theCommand - the command to convert
200 //================================================================================
202 Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
204 // store theCommand in the sequence
205 myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
207 Handle(_pyCommand) aCommand = myCommands.back();
208 #ifdef DUMP_CONVERSION
209 MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
212 _pyID objID = aCommand->GetObject();
214 if ( objID.IsEmpty() )
218 if ( objID == this->GetID() ) {
219 this->Process( aCommand );
222 // SMESH_Mesh method?
223 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
224 if ( id_mesh != myMeshes.end() ) {
225 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
226 _pyID editorID = aCommand->GetResultValue();
227 Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
228 myMeshEditors.insert( make_pair( editorID, editor ));
231 id_mesh->second->Process( aCommand );
234 // SMESH_MeshEditor method?
235 map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
236 if ( id_editor != myMeshEditors.end() ) {
237 id_editor->second->Process( aCommand );
238 TCollection_AsciiString processedCommand = aCommand->GetString();
239 // some commands of SMESH_MeshEditor create meshes
240 if ( aCommand->GetMethod().Search("MakeMesh") != -1 ) {
241 Handle(_pyMesh) mesh = new _pyMesh( aCommand, aCommand->GetResultValue() );
242 aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
243 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
247 // SMESH_Hypothesis method?
248 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
249 for ( ; hyp != myHypos.end(); ++hyp )
250 if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
251 (*hyp)->Process( aCommand );
255 // Add access to a wrapped mesh
256 AddMeshAccessorMethod( aCommand );
258 // Add access to a wrapped algorithm
259 // AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
261 // PAL12227. PythonDump was not updated at proper time; result is
262 // aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
263 // TypeError: __init__() takes exactly 11 arguments (10 given)
264 char wrongCommand[] = "SMESH.Filter.Criterion(";
265 if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
267 _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
268 // there must be 10 arguments, 5-th arg ThresholdID is missing,
269 const int wrongNbArgs = 9, missingArg = 5;
270 if ( tmpCmd.GetNbArgs() == wrongNbArgs )
272 for ( int i = wrongNbArgs; i > missingArg; --i )
273 tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
274 tmpCmd.SetArg( missingArg, "''");
275 aCommand->GetString().Trunc( beg - 1 );
276 aCommand->GetString() += tmpCmd.GetString();
282 //================================================================================
284 * \brief Convert the command or remember it for later conversion
285 * \param theCommand - The python command calling a method of SMESH_Gen
287 //================================================================================
289 void _pyGen::Process( const Handle(_pyCommand)& theCommand )
291 // there are methods to convert:
292 // CreateMesh( shape )
293 // Concatenate( [mesh1, ...], ... )
294 // CreateHypothesis( theHypType, theLibName )
295 // Compute( mesh, geom )
297 TCollection_AsciiString method = theCommand->GetMethod();
298 if ( method == "CreateMesh" || method == "CreateEmptyMesh")
300 Handle(_pyMesh) mesh = new _pyMesh( theCommand );
301 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
304 if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL")
306 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
307 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
310 if( method == "CreateMeshesFromMED")
312 for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
314 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
315 myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));
319 // CreateHypothesis()
320 if ( method == "CreateHypothesis" )
322 myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
326 // smeshgen.Compute( mesh, geom ) --> mesh.Compute()
327 if ( method == "Compute" )
329 const _pyID& meshID = theCommand->GetArg( 1 );
330 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
331 if ( id_mesh != myMeshes.end() ) {
332 theCommand->SetObject( meshID );
333 theCommand->RemoveArgs();
334 id_mesh->second->Flush();
339 // leave only one smeshgen.GetPattern() in the script
340 if ( method == "GetPattern" ) {
341 if ( myHasPattern ) {
348 // Concatenate( [mesh1, ...], ... )
349 if ( method == "Concatenate" || method == "ConcatenateWithGroups")
351 if ( method == "ConcatenateWithGroups" ) {
352 theCommand->SetMethod( "Concatenate" );
353 theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
355 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
356 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
357 AddMeshAccessorMethod( theCommand );
360 // Replace name of SMESH_Gen
362 // names of SMESH_Gen methods fully equal to methods defined in smesh.py
363 static TStringSet smeshpyMethods;
364 if ( smeshpyMethods.empty() ) {
365 const char * names[] =
366 { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
367 "GetPattern","GetSubShapesId",
368 "" }; // <- mark of array end
369 smeshpyMethods.Insert( names );
371 if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
372 // smeshgen.Method() --> smesh.Method()
373 theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
375 // smeshgen.Method() --> smesh.smesh.Method()
376 theCommand->SetObject( SMESH_2smeshpy::GenName() );
379 //================================================================================
381 * \brief Convert the remembered commands
383 //================================================================================
387 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
388 for ( ; id_mesh != myMeshes.end(); ++id_mesh )
389 if ( ! id_mesh->second.IsNull() )
390 id_mesh->second->Flush();
392 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
393 for ( ; hyp != myHypos.end(); ++hyp )
394 if ( !hyp->IsNull() ) {
396 // smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
397 if ( !(*hyp)->IsWrapped() )
398 (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
402 //================================================================================
404 * \brief Add access method to mesh that is an argument
405 * \param theCmd - command to add access method
406 * \retval bool - true if added
408 //================================================================================
410 bool _pyGen::AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const
413 map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
414 for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
415 if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
421 //================================================================================
423 * \brief Add access method to algo that is an object or an argument
424 * \param theCmd - command to add access method
425 * \retval bool - true if added
427 //================================================================================
429 bool _pyGen::AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const
432 list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
433 for ( ; hyp != myHypos.end(); ++hyp ) {
434 if ( (*hyp)->IsAlgo() && /*(*hyp)->IsWrapped() &&*/
435 theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
441 //================================================================================
443 * \brief Find hypothesis by ID (entry)
444 * \param theHypID - The hypothesis ID
445 * \retval Handle(_pyHypothesis) - The found hypothesis
447 //================================================================================
449 Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
451 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
452 for ( ; hyp != myHypos.end(); ++hyp )
453 if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
455 return Handle(_pyHypothesis)();
458 //================================================================================
460 * \brief Find algorithm the created algorithm
461 * \param theGeom - The shape ID the algorithm was created on
462 * \param theMesh - The mesh ID that created the algorithm
463 * \param dim - The algo dimension
464 * \retval Handle(_pyHypothesis) - The found algo
466 //================================================================================
468 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
469 const Handle(_pyHypothesis)& theHypothesis )
471 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
472 for ( ; hyp != myHypos.end(); ++hyp )
473 if ( !hyp->IsNull() &&
475 theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
476 (*hyp)->GetGeom() == theGeom &&
477 (*hyp)->GetMesh() == theMesh )
482 //================================================================================
484 * \brief Change order of commands in the script
485 * \param theCmd1 - One command
486 * \param theCmd2 - Another command
488 //================================================================================
490 void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 )
492 list< Handle(_pyCommand) >::iterator pos1, pos2;
493 pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
494 pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
495 myCommands.insert( pos1, theCmd2 );
496 myCommands.insert( pos2, theCmd1 );
497 myCommands.erase( pos1 );
498 myCommands.erase( pos2 );
500 int nb1 = theCmd1->GetOrderNb();
501 theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
502 theCmd2->SetOrderNb( nb1 );
503 // cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
504 // << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
507 //================================================================================
509 * \brief Set one command after the other
510 * \param theCmd - Command to move
511 * \param theAfterCmd - Command ater which to insert the first one
513 //================================================================================
515 void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
518 //cout << "SET\t" << theAfterCmd->GetString() << endl << "BEFORE\t" << theCmd->GetString() << endl<<endl;
520 list< Handle(_pyCommand) >::iterator pos;
521 pos = find( myCommands.begin(), myCommands.end(), theCmd );
522 myCommands.erase( pos );
523 pos = find( myCommands.begin(), myCommands.end(), theAfterCmd );
524 myCommands.insert( ++pos, theCmd );
527 for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
528 (*pos)->SetOrderNb( i++ );
531 //================================================================================
533 * \brief Set method to access to object wrapped with python class
534 * \param theID - The wrapped object entry
535 * \param theMethod - The accessor method
537 //================================================================================
539 void _pyGen::SetAccessorMethod(const _pyID& theID, const char* theMethod )
541 myID2AccessorMethod.Bind( theID, (char*) theMethod );
544 //================================================================================
546 * \brief Find out type of geom group
547 * \param grpID - The geom group entry
548 * \retval int - The type
550 //================================================================================
552 static bool sameGroupType( const _pyID& grpID,
553 const TCollection_AsciiString& theType)
555 // define group type as smesh.Mesh.Group() does
557 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
558 SALOMEDS::SObject_var aSObj = study->FindObjectID( grpID.ToCString() );
559 if ( !aSObj->_is_nil() ) {
560 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
561 if ( !aGeomObj->_is_nil() ) {
562 switch ( aGeomObj->GetShapeType() ) {
563 case GEOM::VERTEX: type = SMESH::NODE; break;
564 case GEOM::EDGE: type = SMESH::EDGE; break;
565 case GEOM::FACE: type = SMESH::FACE; break;
567 case GEOM::SHELL: type = SMESH::VOLUME; break;
568 case GEOM::COMPOUND: {
569 GEOM::GEOM_Gen_ptr aGeomGen = SMESH_Gen_i::GetSMESHGen()->GetGeomEngine();
570 if ( !aGeomGen->_is_nil() ) {
571 GEOM::GEOM_IGroupOperations_var aGrpOp =
572 aGeomGen->GetIGroupOperations( study->StudyId() );
573 if ( !aGrpOp->_is_nil() ) {
574 switch ( aGrpOp->GetType( aGeomObj )) {
575 case TopAbs_VERTEX: type = SMESH::NODE; break;
576 case TopAbs_EDGE: type = SMESH::EDGE; break;
577 case TopAbs_FACE: type = SMESH::FACE; break;
578 case TopAbs_SOLID: type = SMESH::VOLUME; break;
589 MESSAGE("Type of the group " << grpID << " not found");
592 if ( theType.IsIntegerValue() )
593 return type == theType.IntegerValue();
596 case SMESH::NODE: return theType.Location( "NODE", 1, theType.Length() );
597 case SMESH::EDGE: return theType.Location( "EDGE", 1, theType.Length() );
598 case SMESH::FACE: return theType.Location( "FACE", 1, theType.Length() );
599 case SMESH::VOLUME: return theType.Location( "VOLUME", 1, theType.Length() );
605 //================================================================================
608 * \param theCreationCmd -
610 //================================================================================
612 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd)
613 : _pyObject(theCreationCmd), myHasEditor(false)
615 // convert my creation command
616 Handle(_pyCommand) creationCmd = GetCreationCmd();
617 //TCollection_AsciiString str = creationCmd->GetMethod();
618 // if(str != "CreateMeshesFromUNV" &&
619 // str != "CreateMeshesFromMED" &&
620 // str != "CreateMeshesFromSTL")
621 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
622 creationCmd->SetMethod( "Mesh" );
624 theGen->SetAccessorMethod( GetID(), "GetMesh()" );
627 //================================================================================
630 * \param theCreationCmd -
632 //================================================================================
633 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString& id):
634 _pyObject(theCreationCmd), myHasEditor(false)
636 // convert my creation command
637 Handle(_pyCommand) creationCmd = GetCreationCmd();
638 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
639 theGen->SetAccessorMethod( id, "GetMesh()" );
642 //================================================================================
644 * \brief Convert a IDL API command of SMESH::Mesh to a method call of python Mesh
645 * \param theCommand - Engine method called for this mesh
647 //================================================================================
649 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
651 // some methods of SMESH_Mesh interface needs special conversion
652 // to methods of Mesh python class
654 // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
655 // --> in Mesh_Algorithm.Create(mesh, geom, hypo, so)
656 // 2. AddHypothesis(geom, hyp)
657 // --> in Mesh_Algorithm.Hypothesis(hyp, args, so)
658 // 3. CreateGroupFromGEOM(type, name, grp)
659 // --> in Mesh.Group(grp, name="")
660 // 4. ExportToMED(f, auto_groups, version)
661 // --> in Mesh.ExportMED( f, auto_groups, version )
664 const TCollection_AsciiString method = theCommand->GetMethod();
665 // ----------------------------------------------------------------------
666 if ( method == "GetSubMesh" ) {
667 mySubmeshes.push_back( theCommand );
669 // ----------------------------------------------------------------------
670 else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO )
671 myAddHypCmds.push_back( theCommand );
673 const _pyID& hypID = theCommand->GetArg( 2 );
674 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
675 if ( !hyp.IsNull() ) {
676 myHypos.push_back( hyp );
677 if ( hyp->GetMesh().IsEmpty() )
678 hyp->SetMesh( this->GetID() );
681 // ----------------------------------------------------------------------
682 else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
683 _pyID grp = theCommand->GetArg( 3 );
684 if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
685 theCommand->SetMethod( "Group" );
686 theCommand->RemoveArgs();
687 theCommand->SetArg( 1, grp );
690 AddMeshAccess( theCommand );
693 // ----------------------------------------------------------------------
694 else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
695 theCommand->SetMethod( "ExportMED" );
697 // ----------------------------------------------------------------------
698 else if ( method == "CreateGroup" ) { // CreateGroup() --> CreateEmptyGroup()
699 theCommand->SetMethod( "CreateEmptyGroup" );
701 // ----------------------------------------------------------------------
702 else if ( method == "RemoveHypothesis" ) // (geom, hyp)
704 _pyID hypID = theCommand->GetArg( 2 );
706 // check if this mesh still has corresponding addition command
707 bool hasAddCmd = false;
708 list< Handle(_pyCommand) >::iterator cmd = myAddHypCmds.begin();
709 while ( cmd != myAddHypCmds.end() )
711 // AddHypothesis(geom, hyp)
712 if ( hypID == (*cmd)->GetArg( 2 )) { // erase both (add and remove) commands
715 cmd = myAddHypCmds.erase( cmd );
722 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
723 if ( ! hasAddCmd && hypID.Length() != 0 ) { // hypo addition already wrapped
724 // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
725 _pyID geom = theCommand->GetArg( 1 );
726 theCommand->RemoveArgs();
727 theCommand->SetArg( 1, hypID );
728 if ( geom != GetGeom() )
729 theCommand->SetArg( 2, geom );
731 // remove hyp from myHypos
732 myHypos.remove( hyp );
734 // add accessor method if necessary
737 if ( NeedMeshAccess( theCommand ))
738 // apply theCommand to the mesh wrapped by smeshpy mesh
739 AddMeshAccess( theCommand );
743 //================================================================================
745 * \brief Return True if addition of accesor method is needed
747 //================================================================================
749 bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
751 // names of SMESH_Mesh methods fully equal to methods of class Mesh, so
752 // no conversion is needed for them at all:
753 static TStringSet sameMethods;
754 if ( sameMethods.empty() ) {
755 const char * names[] =
756 { "ExportDAT","ExportUNV","ExportSTL", "RemoveGroup","RemoveGroupWithContents",
757 "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
758 "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
759 "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
760 "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
761 "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
762 "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
763 "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
764 "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
765 "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
766 "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
767 "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
769 ,"" }; // <- mark of end
770 sameMethods.Insert( names );
773 return !sameMethods.Contains( theCommand->GetMethod() );
776 //================================================================================
778 * \brief Convert creation and addition of all algos and hypos
780 //================================================================================
782 void _pyMesh::Flush()
784 list < Handle(_pyCommand) >::iterator cmd, cmd2;
786 // try to convert algo addition like this:
787 // mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
788 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
790 Handle(_pyCommand) addCmd = *cmd;
791 _pyID algoID = addCmd->GetArg( 2 );
792 Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
793 if ( algo.IsNull() || !algo->IsAlgo() )
796 _pyID geom = addCmd->GetArg( 1 );
797 bool isLocalAlgo = ( geom != GetGeom() );
798 if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
800 // wrapped algo is created atfer mesh creation
801 GetCreationCmd()->AddDependantCmd( addCmd );
804 // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
805 addCmd->SetArg( addCmd->GetNbArgs() + 1,
806 TCollection_AsciiString( "geom=" ) + geom );
807 // sm = mesh.GetSubMesh(geom, name) --> sm = ALGO.GetSubMesh()
808 for ( cmd2 = mySubmeshes.begin(); cmd2 != mySubmeshes.end(); ++cmd2 ) {
809 Handle(_pyCommand) subCmd = *cmd2;
810 if ( geom == subCmd->GetArg( 1 )) {
811 subCmd->SetObject( algo->GetID() );
812 subCmd->RemoveArgs();
813 addCmd->AddDependantCmd( subCmd );
818 else // KO - ALGO was already created
820 // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
821 addCmd->RemoveArgs();
822 addCmd->SetArg( 1, algoID );
824 addCmd->SetArg( 2, geom );
828 // try to convert hypo addition like this:
829 // mesh.AddHypothesis(geom, HYPO ) --> HYPO = algo.Hypo()
830 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
832 Handle(_pyCommand) addCmd = *cmd;
833 _pyID hypID = addCmd->GetArg( 2 );
834 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
835 if ( hyp.IsNull() || hyp->IsAlgo() )
837 bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
839 // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
840 _pyID geom = addCmd->GetArg( 1 );
841 addCmd->RemoveArgs();
842 addCmd->SetArg( 1, hypID );
843 if ( geom != GetGeom() )
844 addCmd->SetArg( 2, geom );
848 // sm = mesh.GetSubMesh(geom, name) --> sm = mesh.GetMesh().GetSubMesh(geom, name)
849 // for ( cmd = mySubmeshes.begin(); cmd != mySubmeshes.end(); ++cmd ) {
850 // Handle(_pyCommand) subCmd = *cmd;
851 // if ( subCmd->GetNbArgs() > 0 )
852 // AddMeshAccess( subCmd );
854 myAddHypCmds.clear();
858 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
859 for ( ; hyp != myHypos.end(); ++hyp )
863 //================================================================================
865 * \brief MeshEditor convert its commands to ones of mesh
867 //================================================================================
869 _pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
870 _pyObject( theCreationCmd )
872 myMesh = theCreationCmd->GetObject();
873 myCreationCmdStr = theCreationCmd->GetString();
874 theCreationCmd->Clear();
877 //================================================================================
879 * \brief convert its commands to ones of mesh
881 //================================================================================
883 void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
885 // names of SMESH_MeshEditor methods fully equal to methods of class Mesh, so
886 // commands calling this methods are converted to calls of methods of Mesh
887 static TStringSet sameMethods;
888 if ( sameMethods.empty() ) {
889 const char * names[] = {
890 "RemoveElements","RemoveNodes","AddNode","AddEdge","AddFace","AddPolygonalFace",
891 "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode",
892 "InverseDiag","DeleteDiag","Reorient","ReorientObject","SplitQuad","SplitQuadObject",
893 "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
894 "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
895 "RotationSweep","RotationSweepObject","ExtrusionSweep","AdvancedExtrusion",
896 "ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D","Mirror",
897 "MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
898 "FindCoincidentNodes","FindCoincidentNodesOnPart","MergeNodes","FindEqualElements",
899 "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
900 "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
901 "GetLastCreatedElems",
902 "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
903 "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh"
904 ,"" }; // <- mark of the end
905 sameMethods.Insert( names );
908 // names of SMESH_MeshEditor methods which differ from methods of class Mesh
909 // only last two arguments
910 static TStringSet diffLastTwoArgsMethods;
911 if (diffLastTwoArgsMethods.empty() ){
912 const char * names[] = {
913 "MirrorMakeGroups","MirrorObjectMakeGroups",
914 "TranslateMakeGroups","TranslateObjectMakeGroups",
915 "RotateMakeGroups","RotateObjectMakeGroups",
916 ""};// <- mark of the end
917 diffLastTwoArgsMethods.Insert( names );
920 if ( sameMethods.Contains( theCommand->GetMethod() )) {
921 theCommand->SetObject( myMesh );
923 // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
924 // so let _pyMesh care of it (TMP?)
925 // if ( theCommand->GetMethod().Search("MakeMesh") != -1 )
926 // _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod()
930 //Replace SMESH_MeshEditor "MakeGroups" functions on the Mesh
931 //functions with the flag "theMakeGroups = True" like:
932 //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
933 int pos = theCommand->GetMethod().Search("MakeGroups");
935 // 1. Remove "MakeGroups" from the Command
936 TCollection_AsciiString aMethod = theCommand->GetMethod();
937 int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
938 aMethod.Trunc(pos-1);
939 theCommand->SetMethod(aMethod);
941 // 2. Set Mesh object instead of SMESH_MeshEditor
942 theCommand->SetObject( myMesh );
944 // 3. And add last "True" argument
946 theCommand->SetArg(theCommand->GetNbArgs()+1,"True ");
949 // editor creation command is needed only if any editor function is called
950 theGen->AddMeshAccessorMethod( theCommand ); // for *Object()
951 if ( !myCreationCmdStr.IsEmpty() ) {
952 GetCreationCmd()->GetString() = myCreationCmdStr;
953 myCreationCmdStr.Clear();
959 //================================================================================
961 * \brief _pyHypothesis constructor
962 * \param theCreationCmd -
964 //================================================================================
966 _pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
967 _pyObject( theCreationCmd )
969 myIsAlgo = myIsWrapped = /*myIsConverted = myIsLocal = myDim = */false;
972 //================================================================================
974 * \brief Creates algorithm or hypothesis
975 * \param theCreationCmd - The engine command creating a hypothesis
976 * \retval Handle(_pyHypothesis) - Result _pyHypothesis
978 //================================================================================
980 Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& theCreationCmd)
982 // theCreationCmd: CreateHypothesis( "theHypType", "theLibName" )
983 ASSERT (( theCreationCmd->GetMethod() == "CreateHypothesis"));
985 Handle(_pyHypothesis) hyp, algo;
988 const TCollection_AsciiString & hypTypeQuoted = theCreationCmd->GetArg( 1 );
989 if ( hypTypeQuoted.IsEmpty() )
992 TCollection_AsciiString hypType =
993 hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
995 algo = new _pyAlgorithm( theCreationCmd );
996 hyp = new _pyHypothesis( theCreationCmd );
998 // 1D Regular_1D ----------
999 if ( hypType == "Regular_1D" ) {
1000 // set mesh's method creating algo,
1001 // i.e. convertion result will be "regular1d = Mesh.Segment()",
1002 // and set hypType by which algo creating a hypothesis is searched for
1003 algo->SetConvMethodAndType("Segment", hypType.ToCString());
1005 else if ( hypType == "CompositeSegment_1D" ) {
1006 algo->SetConvMethodAndType("Segment", "Regular_1D");
1007 algo->myArgs.Append( "algo=smesh.COMPOSITE");
1009 else if ( hypType == "LocalLength" ) {
1010 // set algo's method creating hyp, and algo type
1011 hyp->SetConvMethodAndType( "LocalLength", "Regular_1D");
1012 // set method whose 1 arg will become the 1-st arg of hyp creation command
1013 // i.e. convertion result will be "locallength = regular1d.LocalLength(<arg of SetLength()>)"
1014 hyp->AddArgMethod( "SetLength" );
1016 else if ( hypType == "NumberOfSegments" ) {
1017 hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
1018 hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
1019 // arg of SetNumberOfSegments() will become the 1-st arg of hyp creation command
1020 hyp->AddArgMethod( "SetNumberOfSegments" );
1021 // arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
1022 hyp->AddArgMethod( "SetScaleFactor" );
1024 else if ( hypType == "Arithmetic1D" ) {
1025 hyp = new _pyComplexParamHypo( theCreationCmd );
1026 hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
1028 else if ( hypType == "StartEndLength" ) {
1029 hyp = new _pyComplexParamHypo( theCreationCmd );
1030 hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
1032 else if ( hypType == "Deflection1D" ) {
1033 hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
1034 hyp->AddArgMethod( "SetDeflection" );
1036 else if ( hypType == "Propagation" ) {
1037 hyp->SetConvMethodAndType( "Propagation", "Regular_1D");
1039 else if ( hypType == "QuadraticMesh" ) {
1040 hyp->SetConvMethodAndType( "QuadraticMesh", "Regular_1D");
1042 else if ( hypType == "AutomaticLength" ) {
1043 hyp->SetConvMethodAndType( "AutomaticLength", "Regular_1D");
1044 hyp->AddArgMethod( "SetFineness");
1046 else if ( hypType == "SegmentLengthAroundVertex" ) {
1047 hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
1048 hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
1049 hyp->AddArgMethod( "SetLength" );
1051 // 1D Python_1D ----------
1052 else if ( hypType == "Python_1D" ) {
1053 algo->SetConvMethodAndType( "Segment", hypType.ToCString());
1054 algo->myArgs.Append( "algo=smesh.PYTHON");
1056 else if ( hypType == "PythonSplit1D" ) {
1057 hyp->SetConvMethodAndType( "PythonSplit1D", "Python_1D");
1058 hyp->AddArgMethod( "SetNumberOfSegments");
1059 hyp->AddArgMethod( "SetPythonLog10RatioFunction");
1061 // MEFISTO_2D ----------
1062 else if ( hypType == "MEFISTO_2D" ) { // MEFISTO_2D
1063 algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
1065 else if ( hypType == "MaxElementArea" ) {
1066 hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
1067 hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
1068 hyp->AddArgMethod( "SetMaxElementArea");
1070 else if ( hypType == "LengthFromEdges" ) {
1071 hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
1072 hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
1074 // Quadrangle_2D ----------
1075 else if ( hypType == "Quadrangle_2D" ) {
1076 algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
1078 else if ( hypType == "QuadranglePreference" ) {
1079 hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
1080 hyp->SetConvMethodAndType( "QuadranglePreference", "NETGEN_2D_ONLY");
1082 else if ( hypType == "TrianglePreference" ) {
1083 hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
1085 // NETGEN ----------
1086 // else if ( hypType == "NETGEN_2D") { // 1D-2D
1087 // algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1088 // algo->myArgs.Append( "algo=smesh.NETGEN" );
1090 else if ( hypType == "NETGEN_2D_ONLY") { // 2D
1091 algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
1092 algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
1094 else if ( hypType == "NETGEN_3D") { // 3D
1095 algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
1096 algo->myArgs.Append( "algo=smesh.NETGEN" );
1098 else if ( hypType == "MaxElementVolume") {
1099 hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
1100 hyp->AddArgMethod( "SetMaxElementVolume" );
1102 // GHS3D_3D ----------
1103 else if ( hypType == "GHS3D_3D" ) {
1104 algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
1105 algo->myArgs.Append( "algo=smesh.GHS3D" );
1107 // Hexa_3D ---------
1108 else if ( hypType == "Hexa_3D" ) {
1109 algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
1111 // Repetitive Projection_1D ---------
1112 else if ( hypType == "Projection_1D" ) {
1113 algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
1115 else if ( hypType == "ProjectionSource1D" ) {
1116 hyp->SetConvMethodAndType( "SourceEdge", "Projection_1D");
1117 hyp->AddArgMethod( "SetSourceEdge");
1118 hyp->AddArgMethod( "SetSourceMesh");
1119 // 2 args of SetVertexAssociation() will become the 3-th and 4-th args of hyp creation command
1120 hyp->AddArgMethod( "SetVertexAssociation", 2 );
1122 // Projection_2D ---------
1123 else if ( hypType == "Projection_2D" ) {
1124 algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
1126 else if ( hypType == "ProjectionSource2D" ) {
1127 hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
1128 hyp->AddArgMethod( "SetSourceFace");
1129 hyp->AddArgMethod( "SetSourceMesh");
1130 hyp->AddArgMethod( "SetVertexAssociation", 4 );
1132 // Projection_3D ---------
1133 else if ( hypType == "Projection_3D" ) {
1134 algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
1136 else if ( hypType == "ProjectionSource3D" ) {
1137 hyp->SetConvMethodAndType( "SourceShape3D", "Projection_3D");
1138 hyp->AddArgMethod( "SetSource3DShape");
1139 hyp->AddArgMethod( "SetSourceMesh");
1140 hyp->AddArgMethod( "SetVertexAssociation", 4 );
1142 // Prism_3D ---------
1143 else if ( hypType == "Prism_3D" ) {
1144 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1146 // RadialPrism_3D ---------
1147 else if ( hypType == "RadialPrism_3D" ) {
1148 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
1150 else if ( hypType == "NumberOfLayers" ) {
1151 hyp->SetConvMethodAndType( "NumberOfLayers", "RadialPrism_3D");
1152 hyp->AddArgMethod( "SetNumberOfLayers" );
1154 else if ( hypType == "LayerDistribution" ) {
1155 hyp = new _pyLayerDistributionHypo( theCreationCmd );
1156 hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
1159 if ( algo->IsValid() ) {
1165 //================================================================================
1167 * \brief Convert the command adding a hypothesis to mesh into a smesh command
1168 * \param theCmd - The command like mesh.AddHypothesis( geom, hypo )
1169 * \param theAlgo - The algo that can create this hypo
1170 * \retval bool - false if the command cant be converted
1172 //================================================================================
1174 bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
1175 const _pyID& theMesh)
1177 ASSERT(( theCmd->GetMethod() == "AddHypothesis" ));
1179 if ( !IsWrappable( theMesh ))
1182 myGeom = theCmd->GetArg( 1 );
1184 Handle(_pyHypothesis) algo;
1186 // find algo created on myGeom in theMesh
1187 algo = theGen->FindAlgo( myGeom, theMesh, this );
1188 if ( algo.IsNull() )
1190 algo->GetCreationCmd()->AddDependantCmd( theCmd );
1194 // mesh.AddHypothesis(geom,hyp) --> hyp = <theMesh or algo>.myCreationMethod(args)
1195 theCmd->SetResultValue( GetID() );
1196 theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
1197 theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
1199 theCmd->RemoveArgs();
1200 for ( int i = 1; i <= myArgs.Length(); ++i ) {
1201 if ( !myArgs( i ).IsEmpty() )
1202 theCmd->SetArg( i, myArgs( i ));
1204 theCmd->SetArg( i, "[]");
1206 // set a new creation command
1207 GetCreationCmd()->Clear();
1208 SetCreationCmd( theCmd );
1210 // clear commands setting arg values
1211 list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
1212 for ( ; argCmd != myArgCommands.end(); ++argCmd )
1215 // set unknown arg commands after hypo creation
1216 Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
1217 list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
1218 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1219 afterCmd->AddDependantCmd( *cmd );
1225 //================================================================================
1227 * \brief Remember hypothesis parameter values
1228 * \param theCommand - The called hypothesis method
1230 //================================================================================
1232 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
1234 ASSERT( !myIsAlgo );
1237 for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
1238 if ( myArgMethods( i ) == theCommand->GetMethod() ) {
1239 while ( myArgs.Length() < nbArgs + myNbArgsByMethod( i ))
1240 myArgs.Append( "[]" );
1241 for ( int iArg = 1; iArg <= myNbArgsByMethod( i ); ++iArg )
1242 myArgs( nbArgs + iArg ) = theCommand->GetArg( iArg ); // arg value
1243 myArgCommands.push_back( theCommand );
1246 nbArgs += myNbArgsByMethod( i );
1248 myUnknownCommands.push_back( theCommand );
1251 //================================================================================
1253 * \brief Finish conversion
1255 //================================================================================
1257 void _pyHypothesis::Flush()
1259 if ( IsWrapped() ) {
1262 list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
1263 for ( ; cmd != myArgCommands.end(); ++cmd ) {
1264 // Add access to a wrapped mesh
1265 theGen->AddMeshAccessorMethod( *cmd );
1266 // Add access to a wrapped algorithm
1267 theGen->AddAlgoAccessorMethod( *cmd );
1269 cmd = myUnknownCommands.begin();
1270 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
1271 // Add access to a wrapped mesh
1272 theGen->AddMeshAccessorMethod( *cmd );
1273 // Add access to a wrapped algorithm
1274 theGen->AddAlgoAccessorMethod( *cmd );
1277 // forget previous hypothesis modifications
1278 myArgCommands.clear();
1279 myUnknownCommands.clear();
1282 //================================================================================
1284 * \brief clear creation, arg and unkown commands
1286 //================================================================================
1288 void _pyHypothesis::ClearAllCommands()
1290 GetCreationCmd()->Clear();
1291 list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
1292 for ( ; cmd != myArgCommands.end(); ++cmd )
1294 cmd = myUnknownCommands.begin();
1295 for ( ; cmd != myUnknownCommands.end(); ++cmd )
1299 //================================================================================
1301 * \brief Remember hypothesis parameter values
1302 * \param theCommand - The called hypothesis method
1304 //================================================================================
1306 void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
1308 // ex: hyp.SetLength(start, 1)
1309 // hyp.SetLength(end, 0)
1310 ASSERT(( theCommand->GetMethod() == "SetLength" ));
1311 ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
1312 int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
1313 while ( myArgs.Length() < i )
1314 myArgs.Append( "[]" );
1315 myArgs( i ) = theCommand->GetArg( 1 ); // arg value
1316 myArgCommands.push_back( theCommand );
1319 //================================================================================
1321 * \brief Convert methods of 1D hypotheses to my own methods
1322 * \param theCommand - The called hypothesis method
1324 //================================================================================
1326 void _pyLayerDistributionHypo::Process( const Handle(_pyCommand)& theCommand)
1328 if ( theCommand->GetMethod() != "SetLayerDistribution" )
1331 _pyID newName; // name for 1D hyp = "HypType" + "_Distribution"
1333 const _pyID& hyp1dID = theCommand->GetArg( 1 );
1334 Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
1335 if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
1337 else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() ) {
1338 // 1D hypo is already set, so distribution changes and the old
1339 // 1D hypo is thrown away
1340 my1dHyp->ClearAllCommands();
1343 if ( my1dHyp.IsNull() )
1344 return; // something wrong :(
1346 // make a new name for 1D hyp = "HypType" + "_Distribution"
1347 if ( my1dHyp->GetCreationCmd()->GetMethod() == "CreateHypothesis" ) {
1348 // not yet converted creation cmd
1349 TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
1350 TCollection_AsciiString hypType = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
1351 newName = hypType + "_Distribution";
1352 my1dHyp->GetCreationCmd()->SetResultValue( newName );
1355 // already converted creation cmd
1356 newName = my1dHyp->GetCreationCmd()->GetResultValue();
1359 // as creation of 1D hyp was written later then it's edition,
1360 // we need to find all it's edition calls and process them
1361 list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
1362 list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
1363 for ( ; cmdIt != cmds.end(); ++cmdIt ) {
1364 const _pyID& objID = (*cmdIt)->GetObject();
1365 if ( objID == hyp1dID ) {
1366 my1dHyp->Process( *cmdIt );
1367 my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
1368 ( *cmdIt )->SetObject( newName );
1371 if ( !myArgCommands.empty() )
1372 myArgCommands.front()->Clear();
1373 theCommand->SetArg( 1, newName );
1374 myArgCommands.push_back( theCommand );
1375 // copy hyp1d's creation method and args
1376 // myCreationMethod = hyp1d->GetCreationMethod();
1377 // myArgs = hyp1d->GetArgs();
1378 // // make them cleared at conversion
1379 // myArgCommands = hyp1d->GetArgCommands();
1381 // // to be cleared at convertion only
1382 // myArgCommands.push_back( theCommand );
1385 //================================================================================
1388 * \param theAdditionCmd -
1392 //================================================================================
1394 bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
1395 const _pyID& theMesh)
1397 myIsWrapped = false;
1399 if ( my1dHyp.IsNull() )
1402 // set "SetLayerDistribution()" after addition cmd
1403 theAdditionCmd->AddDependantCmd( myArgCommands.front() );
1405 _pyID geom = theAdditionCmd->GetArg( 1 );
1407 my1dHyp->SetMesh( theMesh );
1408 if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
1411 // clear "SetLayerDistribution()" cmd
1412 myArgCommands.front()->Clear();
1414 // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
1416 // find RadialPrism algo created on <geom> for theMesh
1417 Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
1418 if ( !algo.IsNull() ) {
1419 GetCreationCmd()->SetObject( algo->GetID() );
1420 GetCreationCmd()->SetMethod( "Get3DHypothesis" );
1421 GetCreationCmd()->RemoveArgs();
1422 theAdditionCmd->AddDependantCmd( GetCreationCmd() );
1428 //================================================================================
1432 //================================================================================
1434 void _pyLayerDistributionHypo::Flush()
1436 //my1dHyp.Nullify();
1437 //_pyHypothesis::Flush();
1440 //================================================================================
1442 * \brief additionally to Addition2Creation, clears SetDistrType() command
1443 * \param theCmd - AddHypothesis() command
1444 * \param theMesh - mesh to which a hypothesis is added
1445 * \retval bool - convertion result
1447 //================================================================================
1449 bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1450 const _pyID& theMesh)
1452 if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
1453 // scale factor (2-nd arg) is provided: clear SetDistrType(1) command
1454 bool scaleDistrType = false;
1455 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1456 for ( ; cmd != myUnknownCommands.rend(); ++cmd ) {
1457 if ( (*cmd)->GetMethod() == "SetDistrType" ) {
1458 if ( (*cmd)->GetArg( 1 ) == "1" ) {
1459 scaleDistrType = true;
1462 else if ( !scaleDistrType ) {
1463 // distribution type changed: remove scale factor from args
1464 myArgs.Remove( 2, myArgs.Length() );
1470 return _pyHypothesis::Addition2Creation( theCmd, theMesh );
1473 //================================================================================
1475 * \brief remove repeated commands defining distribution
1477 //================================================================================
1479 void _pyNumberOfSegmentsHyp::Flush()
1481 // find number of the last SetDistrType() command
1482 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
1483 int distrTypeNb = 0;
1484 for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
1485 if ( (*cmd)->GetMethod() == "SetDistrType" )
1486 distrTypeNb = (*cmd)->GetOrderNb();
1488 // clear commands before the last SetDistrType()
1489 list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
1490 for ( int i = 0; i < 2; ++i ) {
1491 set<TCollection_AsciiString> uniqueMethods;
1492 list<Handle(_pyCommand)> & cmdList = *cmds[i];
1493 for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
1495 bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
1496 const TCollection_AsciiString& method = (*cmd)->GetMethod();
1497 if ( !clear || method == "SetNumberOfSegments" ) {
1498 bool isNewInSet = uniqueMethods.insert( method ).second;
1499 clear = !isNewInSet;
1508 //================================================================================
1510 * \brief Convert the command adding "SegmentLengthAroundVertex" to mesh
1511 * into regular1D.LengthNearVertex( length, vertex )
1512 * \param theCmd - The command like mesh.AddHypothesis( vertex, SegmentLengthAroundVertex )
1513 * \param theMesh - The mesh needing this hypo
1514 * \retval bool - false if the command cant be converted
1516 //================================================================================
1518 bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
1519 const _pyID& theMeshID)
1521 if ( IsWrappable( theMeshID )) {
1523 _pyID vertex = theCmd->GetArg( 1 );
1525 // the problem here is that segment algo will not be found
1526 // by pyHypothesis::Addition2Creation() for <vertex>, so we try to find
1527 // geometry where segment algorithm is assigned
1528 Handle(_pyHypothesis) algo;
1529 _pyID geom = vertex;
1530 while ( algo.IsNull() && !geom.IsEmpty()) {
1531 // try to find geom as a father of <vertex>
1532 geom = FatherID( geom );
1533 algo = theGen->FindAlgo( geom, theMeshID, this );
1535 if ( algo.IsNull() )
1536 return false; // also possible to find geom as brother of veretex...
1537 // set geom instead of vertex
1538 theCmd->SetArg( 1, geom );
1540 // set vertex as a second arg
1541 if ( myArgs.Length() < 1) myArgs.Append( "1" ); // :(
1542 myArgs.Append( vertex );
1544 // mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) -->
1545 // theMeshID.LengthNearVertex( length, vertex )
1546 return _pyHypothesis::Addition2Creation( theCmd, theMeshID );
1551 //================================================================================
1553 * \brief _pyAlgorithm constructor
1554 * \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)"
1556 //================================================================================
1558 _pyAlgorithm::_pyAlgorithm(const Handle(_pyCommand)& theCreationCmd)
1559 : _pyHypothesis( theCreationCmd )
1564 //================================================================================
1566 * \brief Convert the command adding an algorithm to mesh
1567 * \param theCmd - The command like mesh.AddHypothesis( geom, algo )
1568 * \param theMesh - The mesh needing this algo
1569 * \retval bool - false if the command cant be converted
1571 //================================================================================
1573 bool _pyAlgorithm::Addition2Creation( const Handle(_pyCommand)& theCmd,
1574 const _pyID& theMeshID)
1576 // mesh.AddHypothesis(geom,algo) --> theMeshID.myCreationMethod()
1577 if ( _pyHypothesis::Addition2Creation( theCmd, theMeshID )) {
1578 theGen->SetAccessorMethod( GetID(), "GetAlgorithm()" );
1584 //================================================================================
1586 * \brief Return starting position of a part of python command
1587 * \param thePartIndex - The index of command part
1588 * \retval int - Part position
1590 //================================================================================
1592 int _pyCommand::GetBegPos( int thePartIndex )
1596 if ( myBegPos.Length() < thePartIndex )
1598 return myBegPos( thePartIndex );
1601 //================================================================================
1603 * \brief Store starting position of a part of python command
1604 * \param thePartIndex - The index of command part
1605 * \param thePosition - Part position
1607 //================================================================================
1609 void _pyCommand::SetBegPos( int thePartIndex, int thePosition )
1611 while ( myBegPos.Length() < thePartIndex )
1612 myBegPos.Append( UNKNOWN );
1613 myBegPos( thePartIndex ) = thePosition;
1616 //================================================================================
1618 * \brief Returns whitespace symbols at the line beginning
1619 * \retval TCollection_AsciiString - result
1621 //================================================================================
1623 TCollection_AsciiString _pyCommand::GetIndentation()
1626 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
1627 GetWord( myString, end, true );
1629 end = GetBegPos( RESULT_IND );
1630 return myString.SubString( 1, end - 1 );
1633 //================================================================================
1635 * \brief Return substring of python command looking like ResultValue = Obj.Meth()
1636 * \retval const TCollection_AsciiString & - ResultValue substring
1638 //================================================================================
1640 const TCollection_AsciiString & _pyCommand::GetResultValue()
1642 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
1644 int begPos = myString.Location( "=", 1, Length() );
1646 myRes = GetWord( myString, begPos, false );
1649 SetBegPos( RESULT_IND, begPos );
1654 //================================================================================
1656 * \brief Return number of python command result value ResultValue = Obj.Meth()
1659 //================================================================================
1661 const int _pyCommand::GetNbResultValues()
1665 int endPos = myString.Location( "=", 1, Length() );
1666 TCollection_AsciiString str = "";
1667 while ( begPos < endPos) {
1668 str = GetWord( myString, begPos, true );
1669 begPos = begPos+ str.Length();
1676 //================================================================================
1678 * \brief Return substring of python command looking like
1679 * ResultValue1 , ResultValue1,... = Obj.Meth() with res index
1680 * \retval const TCollection_AsciiString & - ResultValue with res index substring
1682 //================================================================================
1683 const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
1687 int endPos = myString.Location( "=", 1, Length() );
1688 while ( begPos < endPos) {
1689 myRes = GetWord( myString, begPos, true );
1690 begPos = begPos + myRes.Length();
1693 myRes.RemoveAll('[');myRes.RemoveAll(']');
1699 return theEmptyString;
1702 //================================================================================
1704 * \brief Return substring of python command looking like ResVal = Object.Meth()
1705 * \retval const TCollection_AsciiString & - Object substring
1707 //================================================================================
1709 const TCollection_AsciiString & _pyCommand::GetObject()
1711 if ( GetBegPos( OBJECT_IND ) == UNKNOWN )
1714 int begPos = GetBegPos( RESULT_IND ) + myRes.Length();
1716 begPos = myString.Location( "=", 1, Length() ) + 1;
1717 // is '=' in the string argument (for example, name) or not
1718 int nb1 = 0; // number of ' character at the left of =
1719 int nb2 = 0; // number of " character at the left of =
1720 for ( int i = 1; i < begPos-1; i++ ) {
1721 if ( IsEqual(myString.Value( i ), "'" ) )
1723 else if ( IsEqual( myString.Value( i ), '"' ) )
1726 // if number of ' or " is not divisible by 2,
1727 // then get an object at the start of the command
1728 if ( nb1 % 2 != 0 || nb2 % 2 != 0 )
1732 myObj = GetWord( myString, begPos, true );
1733 SetBegPos( OBJECT_IND, begPos );
1739 //================================================================================
1741 * \brief Return substring of python command looking like ResVal = Obj.Method()
1742 * \retval const TCollection_AsciiString & - Method substring
1744 //================================================================================
1746 const TCollection_AsciiString & _pyCommand::GetMethod()
1748 if ( GetBegPos( METHOD_IND ) == UNKNOWN )
1751 int begPos = GetBegPos( OBJECT_IND ) + myObj.Length();
1752 bool forward = true;
1754 begPos = myString.Location( "(", 1, Length() ) - 1;
1758 myMeth = GetWord( myString, begPos, forward );
1759 SetBegPos( METHOD_IND, begPos );
1765 //================================================================================
1767 * \brief Return substring of python command looking like ResVal = Obj.Meth(Arg1,...)
1768 * \retval const TCollection_AsciiString & - Arg<index> substring
1770 //================================================================================
1772 const TCollection_AsciiString & _pyCommand::GetArg( int index )
1774 if ( GetBegPos( ARG1_IND ) == UNKNOWN )
1777 int begPos = GetBegPos( METHOD_IND ) + myMeth.Length();
1779 begPos = myString.Location( "(", 1, Length() ) + 1;
1781 int i = 0, prevLen = 0;
1782 while ( begPos != EMPTY ) {
1784 // check if we are looking at the closing parenthesis
1785 while ( begPos <= Length() && isspace( myString.Value( begPos )))
1787 if ( begPos > Length() || myString.Value( begPos ) == ')' )
1789 myArgs.Append( GetWord( myString, begPos, true, true ));
1790 SetBegPos( ARG1_IND + i, begPos );
1791 prevLen = myArgs.Last().Length();
1793 myArgs.Remove( myArgs.Length() ); // no more args
1797 if ( myArgs.Length() < index )
1798 return theEmptyString;
1799 return myArgs( index );
1802 //================================================================================
1804 * \brief Check if char is a word part
1805 * \param c - The character to check
1806 * \retval bool - The check result
1808 //================================================================================
1810 static inline bool isWord(const char c, const bool dotIsWord)
1813 !isspace(c) && c != ',' && c != '=' && c != ')' && c != '(' && ( dotIsWord || c != '.');
1816 //================================================================================
1818 * \brief Looks for a word in the string and returns word's beginning
1819 * \param theString - The input string
1820 * \param theStartPos - The position to start the search, returning word's beginning
1821 * \param theForward - The search direction
1822 * \retval TCollection_AsciiString - The found word
1824 //================================================================================
1826 TCollection_AsciiString _pyCommand::GetWord( const TCollection_AsciiString & theString,
1828 const bool theForward,
1829 const bool dotIsWord )
1831 int beg = theStartPos, end = theStartPos;
1832 theStartPos = EMPTY;
1833 if ( beg < 1 || beg > theString.Length() )
1834 return theEmptyString;
1836 if ( theForward ) { // search forward
1838 while ( beg <= theString.Length() && !isWord( theString.Value( beg ), dotIsWord))
1840 if ( beg > theString.Length() )
1841 return theEmptyString; // no word found
1844 char begChar = theString.Value( beg );
1845 if ( begChar == '"' || begChar == '\'' ) {
1846 // end is at the corresponding quoting mark
1847 while ( end < theString.Length() &&
1848 ( theString.Value( end ) != begChar || theString.Value( end-1 ) == '\\'))
1852 while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
1857 else { // search backward
1859 while ( end > 0 && !isWord( theString.Value( end ), dotIsWord))
1862 return theEmptyString; // no word found
1864 char endChar = theString.Value( end );
1865 if ( endChar == '"' || endChar == '\'' ) {
1866 // beg is at the corresponding quoting mark
1868 ( theString.Value( beg ) != endChar || theString.Value( beg-1 ) == '\\'))
1872 while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
1878 //cout << theString << " ---- " << beg << " - " << end << endl;
1879 return theString.SubString( beg, end );
1882 //================================================================================
1884 * \brief Look for position where not space char is
1885 * \param theString - The string
1886 * \param thePos - The position to search from and which returns result
1887 * \retval bool - false if there are only space after thePos in theString
1891 //================================================================================
1893 bool _pyCommand::SkipSpaces( const TCollection_AsciiString & theString, int & thePos )
1895 if ( thePos < 1 || thePos > theString.Length() )
1898 while ( thePos <= theString.Length() && isspace( theString.Value( thePos )))
1901 return thePos <= theString.Length();
1904 //================================================================================
1906 * \brief Modify a part of the command
1907 * \param thePartIndex - The index of the part
1908 * \param thePart - The new part string
1909 * \param theOldPart - The old part
1911 //================================================================================
1913 void _pyCommand::SetPart(int thePartIndex, const TCollection_AsciiString& thePart,
1914 TCollection_AsciiString& theOldPart)
1916 int pos = GetBegPos( thePartIndex );
1917 if ( pos <= Length() && theOldPart != thePart)
1919 TCollection_AsciiString seperator;
1921 pos = GetBegPos( thePartIndex + 1 );
1922 if ( pos < 1 ) return;
1923 switch ( thePartIndex ) {
1924 case RESULT_IND: seperator = " = "; break;
1925 case OBJECT_IND: seperator = "."; break;
1926 case METHOD_IND: seperator = "()"; break;
1930 myString.Remove( pos, theOldPart.Length() );
1931 if ( !seperator.IsEmpty() )
1932 myString.Insert( pos , seperator );
1933 myString.Insert( pos, thePart );
1934 // update starting positions of the following parts
1935 int posDelta = thePart.Length() + seperator.Length() - theOldPart.Length();
1936 for ( int i = thePartIndex + 1; i <= myBegPos.Length(); ++i ) {
1937 if ( myBegPos( i ) > 0 )
1938 myBegPos( i ) += posDelta;
1940 theOldPart = thePart;
1944 //================================================================================
1946 * \brief Set agrument
1947 * \param index - The argument index, it counts from 1
1948 * \param theArg - The argument string
1950 //================================================================================
1952 void _pyCommand::SetArg( int index, const TCollection_AsciiString& theArg)
1955 int argInd = ARG1_IND + index - 1;
1956 int pos = GetBegPos( argInd );
1957 if ( pos < 1 ) // no index-th arg exist, append inexistent args
1959 // find a closing parenthesis
1960 if ( int lastArgInd = GetNbArgs() ) {
1961 pos = GetBegPos( ARG1_IND + lastArgInd - 1 ) + GetArg( lastArgInd ).Length();
1962 while ( pos > 0 && pos <= Length() && myString.Value( pos ) != ')' )
1967 while ( pos > 0 && myString.Value( pos ) != ')' )
1970 if ( pos < 1 || myString.Value( pos ) != ')' ) { // no parentheses at all
1974 while ( myArgs.Length() < index ) {
1975 if ( myArgs.Length() )
1976 myString.Insert( pos++, "," );
1977 myArgs.Append("None");
1978 myString.Insert( pos, myArgs.Last() );
1979 SetBegPos( ARG1_IND + myArgs.Length() - 1, pos );
1980 pos += myArgs.Last().Length();
1983 SetPart( argInd, theArg, myArgs( index ));
1986 //================================================================================
1988 * \brief Empty arg list
1990 //================================================================================
1992 void _pyCommand::RemoveArgs()
1994 if ( int pos = myString.Location( '(', 1, Length() ))
1995 myString.Trunc( pos );
1998 if ( myBegPos.Length() >= ARG1_IND )
1999 myBegPos.Remove( ARG1_IND, myBegPos.Length() );
2002 //================================================================================
2004 * \brief Set dependent commands after this one
2006 //================================================================================
2008 bool _pyCommand::SetDependentCmdsAfter() const
2010 bool orderChanged = false;
2011 list< Handle(_pyCommand)>::const_reverse_iterator cmd = myDependentCmds.rbegin();
2012 for ( ; cmd != myDependentCmds.rend(); ++cmd ) {
2013 if ( (*cmd)->GetOrderNb() < GetOrderNb() ) {
2014 orderChanged = true;
2015 theGen->SetCommandAfter( *cmd, this );
2016 (*cmd)->SetDependentCmdsAfter();
2019 return orderChanged;
2021 //================================================================================
2023 * \brief Insert accessor method after theObjectID
2024 * \param theObjectID - id of the accessed object
2025 * \param theAcsMethod - name of the method giving access to the object
2026 * \retval bool - false if theObjectID is not found in the command string
2028 //================================================================================
2030 bool _pyCommand::AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod )
2032 if ( !theAcsMethod )
2034 // start object search from the object, i.e. ignore result
2036 int beg = GetBegPos( OBJECT_IND );
2037 if ( beg < 1 || beg > Length() )
2040 while (( beg = myString.Location( theObjectID, beg, Length() )))
2042 // check that theObjectID is not just a part of a longer ID
2043 int afterEnd = beg + theObjectID.Length();
2044 Standard_Character c = myString.Value( afterEnd );
2045 if ( !isalnum( c ) && c != ':' ) {
2046 // check if accessor method already present
2048 myString.Location( (char*) theAcsMethod, afterEnd, Length() ) != afterEnd+1) {
2050 int oldLen = Length();
2051 myString.Insert( afterEnd, (char*) theAcsMethod );
2052 myString.Insert( afterEnd, "." );
2053 // update starting positions of the parts following the modified one
2054 int posDelta = Length() - oldLen;
2055 for ( int i = 1; i <= myBegPos.Length(); ++i ) {
2056 if ( myBegPos( i ) > afterEnd )
2057 myBegPos( i ) += posDelta;
2062 beg = afterEnd; // is a part - next search
2067 //================================================================================
2069 * \brief Return method name giving access to an interaface object wrapped by python class
2070 * \retval const char* - method name
2072 //================================================================================
2074 const char* _pyObject::AccessorMethod() const
2078 //================================================================================
2080 * \brief Return ID of a father
2082 //================================================================================
2084 _pyID _pyObject::FatherID(const _pyID & childID)
2086 int colPos = childID.SearchFromEnd(':');
2088 return childID.SubString( 1, colPos-1 );