00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESH_2smeshpy.hxx"
00029
00030 #include "utilities.h"
00031 #include "SMESH_PythonDump.hxx"
00032 #include "SMESH_NoteBook.hxx"
00033 #include "Resource_DataMapOfAsciiStringAsciiString.hxx"
00034
00035 #include "SMESH_Gen_i.hxx"
00036
00037
00038
00039
00040
00041 IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient);
00042 IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
00043 IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject);
00044 IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject);
00045 IMPLEMENT_STANDARD_HANDLE (_pySubMesh ,_pyObject);
00046 IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor ,_pyObject);
00047 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis ,_pyObject);
00048 IMPLEMENT_STANDARD_HANDLE (_pySelfEraser ,_pyObject);
00049 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
00050 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
00051 IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis);
00052
00053 IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient);
00054 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient);
00055 IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject);
00056 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject);
00057 IMPLEMENT_STANDARD_RTTIEXT(_pySubMesh ,_pyObject);
00058 IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject);
00059 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject);
00060 IMPLEMENT_STANDARD_RTTIEXT(_pySelfEraser ,_pyObject);
00061 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis);
00062 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
00063 IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis);
00064 IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis);
00065 IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis);
00066
00067 using namespace std;
00068 using SMESH::TPythonDump;
00069
00074 static Handle(_pyGen) theGen;
00075
00076 static TCollection_AsciiString theEmptyString;
00077
00078
00079
00080 #if !defined(_DEBUG_) && defined(DUMP_CONVERSION)
00081 #undef DUMP_CONVERSION
00082 #endif
00083
00084
00085 namespace {
00086
00087
00091
00092
00093 struct TStringSet: public set<TCollection_AsciiString>
00094 {
00098 void Insert(const char* names[]) {
00099 for ( int i = 0; names[i][0] ; ++i )
00100 insert( (char*) names[i] );
00101 }
00105 bool Contains(const TCollection_AsciiString& name ) {
00106 return find( name ) != end();
00107 }
00108 };
00109 }
00110
00111
00119
00120
00121 TCollection_AsciiString
00122 SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
00123 Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
00124 Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
00125 {
00126 theGen = new _pyGen( theEntry2AccessorMethod, theObjectNames );
00127
00128
00129
00130 SMESH_NoteBook * aNoteBook = new SMESH_NoteBook();
00131
00132 int from = 1, end = theScript.Length(), to;
00133 while ( from < end && ( to = theScript.Location( "\n", from, end )))
00134 {
00135 if ( to != from )
00136
00137 aNoteBook->AddCommand( theScript.SubString( from, to - 1 ));
00138 from = to + 1;
00139 }
00140
00141 aNoteBook->ReplaceVariables();
00142
00143 TCollection_AsciiString aNoteScript = aNoteBook->GetResultScript();
00144 delete aNoteBook;
00145 aNoteBook = 0;
00146
00147
00148 from = 1, end = aNoteScript.Length();
00149 while ( from < end && ( to = aNoteScript.Location( "\n", from, end )))
00150 {
00151 if ( to != from )
00152
00153 theGen->AddCommand( aNoteScript.SubString( from, to - 1 ));
00154 from = to + 1;
00155 }
00156
00157
00158 theGen->Flush();
00159 #ifdef DUMP_CONVERSION
00160 MESSAGE_BEGIN ( std::endl << " ######## RESULT ######## " << std::endl<< std::endl );
00161 #endif
00162
00163
00164 list< Handle(_pyCommand) >::iterator cmd;
00165 bool orderChanges;
00166 do {
00167 orderChanges = false;
00168 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
00169 if ( (*cmd)->SetDependentCmdsAfter() )
00170 orderChanges = true;
00171 } while ( orderChanges );
00172
00173
00174 TCollection_AsciiString aScript;
00175 for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
00176 {
00177 #ifdef DUMP_CONVERSION
00178 MESSAGE_ADD ( "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << std::endl );
00179 #endif
00180 if ( !(*cmd)->IsEmpty() ) {
00181 aScript += "\n";
00182 aScript += (*cmd)->GetString();
00183 }
00184 }
00185 aScript += "\n";
00186
00187 theGen.Nullify();
00188
00189 return aScript;
00190 }
00191
00192
00196
00197
00198 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
00199 Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
00200 : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
00201 myID2AccessorMethod( theEntry2AccessorMethod ),
00202 myObjectNames( theObjectNames )
00203 {
00204 myNbCommands = 0;
00205
00206 GetCreationCmd()->GetString() += "=";
00207 }
00208
00209
00213
00214
00215 const char* _pyGen::AccessorMethod() const
00216 {
00217 return SMESH_2smeshpy::GenName();
00218 }
00219
00220
00225
00226
00227 Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
00228 {
00229
00230 myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
00231
00232 Handle(_pyCommand) aCommand = myCommands.back();
00233 #ifdef DUMP_CONVERSION
00234 MESSAGE ( "## COM " << myNbCommands << ": "<< aCommand->GetString() );
00235 #endif
00236
00237 _pyID objID = aCommand->GetObject();
00238
00239 if ( objID.IsEmpty() )
00240 return aCommand;
00241
00242
00243 if ( objID == this->GetID() || objID == SMESH_2smeshpy::GenName()) {
00244 this->Process( aCommand );
00245 return aCommand;
00246 }
00247
00248
00249 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
00250 if ( id_mesh != myMeshes.end() )
00251 {
00252
00253 if ( aCommand->GetMethod() == "GetMeshEditor" ) {
00254 _pyID editorID = aCommand->GetResultValue();
00255 Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
00256 myMeshEditors.insert( make_pair( editorID, editor ));
00257 return aCommand;
00258 }
00259
00260 else if ( aCommand->GetMethod() == "GetSubMesh" ) {
00261 _pyID subMeshID = aCommand->GetResultValue();
00262 Handle(_pySubMesh) subMesh = new _pySubMesh( aCommand );
00263 myObjects.insert( make_pair( subMeshID, subMesh ));
00264 }
00265
00266 id_mesh->second->Process( aCommand );
00267 return aCommand;
00268 }
00269
00270
00271 map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
00272 if ( id_editor != myMeshEditors.end() )
00273 {
00274 id_editor->second->Process( aCommand );
00275 TCollection_AsciiString processedCommand = aCommand->GetString();
00276
00277 if ( aCommand->GetMethod().Search("MakeMesh") != -1 ) {
00278 Handle(_pyMesh) mesh = new _pyMesh( aCommand, aCommand->GetResultValue() );
00279 aCommand->GetString() = processedCommand;
00280 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
00281 }
00282 if ( aCommand->GetMethod() == "MakeBoundaryMesh") {
00283 _pyID meshID = aCommand->GetResultValue(0);
00284 if ( !myMeshes.count( meshID ) )
00285 {
00286 Handle(_pyMesh) mesh = new _pyMesh( aCommand, meshID );
00287 aCommand->GetString() = processedCommand;
00288 myMeshes.insert( make_pair( meshID, mesh ));
00289 }
00290 }
00291 return aCommand;
00292 }
00293
00294 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
00295 for ( ; hyp != myHypos.end(); ++hyp )
00296 if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
00297 (*hyp)->Process( aCommand );
00298 return aCommand;
00299 }
00300
00301
00302 map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.find( objID );
00303 if ( id_obj != myObjects.end() ) {
00304 id_obj->second->Process( aCommand );
00305 return aCommand;
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 AddMeshAccessorMethod( aCommand );
00317
00318
00319
00320
00321
00322
00323
00324 char wrongCommand[] = "SMESH.Filter.Criterion(";
00325 if ( int beg = theCommand.Location( wrongCommand, 1, theCommand.Length() ))
00326 {
00327 _pyCommand tmpCmd( theCommand.SubString( beg, theCommand.Length() ), -1);
00328
00329 const int wrongNbArgs = 9, missingArg = 5;
00330 if ( tmpCmd.GetNbArgs() == wrongNbArgs )
00331 {
00332 for ( int i = wrongNbArgs; i > missingArg; --i )
00333 tmpCmd.SetArg( i + 1, tmpCmd.GetArg( i ));
00334 tmpCmd.SetArg( missingArg, "''");
00335 aCommand->GetString().Trunc( beg - 1 );
00336 aCommand->GetString() += tmpCmd.GetString();
00337 }
00338 }
00339 return aCommand;
00340 }
00341
00342
00347
00348
00349 void _pyGen::Process( const Handle(_pyCommand)& theCommand )
00350 {
00351
00352
00353
00354
00355
00356
00357
00358 TCollection_AsciiString method = theCommand->GetMethod();
00359
00360 if ( method == "CreateMesh" || method == "CreateEmptyMesh")
00361 {
00362 Handle(_pyMesh) mesh = new _pyMesh( theCommand );
00363 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
00364 return;
00365 }
00366 if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL" || method == "CopyMesh" )
00367 {
00368 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
00369 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
00370 return;
00371 }
00372 if( method == "CreateMeshesFromMED")
00373 {
00374 for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
00375 {
00376 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
00377 myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));
00378 }
00379 }
00380
00381
00382 if ( method == "CreateHypothesis" )
00383 {
00384
00385 const TCollection_AsciiString & aLibName = theCommand->GetArg( 2 );
00386 if ( aLibName.Search( "StdMeshersEngine" ) != -1 ) {
00387
00388 TCollection_AsciiString arg = theCommand->GetArg( 1 );
00389 theCommand->RemoveArgs();
00390 theCommand->SetArg( 1, arg );
00391 }
00392
00393 myHypos.push_back( _pyHypothesis::NewHypothesis( theCommand ));
00394 return;
00395 }
00396
00397
00398 if ( method == "Compute" )
00399 {
00400 const _pyID& meshID = theCommand->GetArg( 1 );
00401 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
00402 if ( id_mesh != myMeshes.end() ) {
00403 theCommand->SetObject( meshID );
00404 theCommand->RemoveArgs();
00405 id_mesh->second->Flush();
00406 return;
00407 }
00408 }
00409
00410
00411 if ( method == "Evaluate" )
00412 {
00413 const _pyID& meshID = theCommand->GetArg( 1 );
00414 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( meshID );
00415 if ( id_mesh != myMeshes.end() ) {
00416 theCommand->SetObject( meshID );
00417 _pyID geom = theCommand->GetArg( 2 );
00418 theCommand->RemoveArgs();
00419 theCommand->SetArg( 1, geom );
00420 return;
00421 }
00422 }
00423
00424
00425
00426 if ( method == "GetPattern" || method == "CreateFilterManager" ) {
00427 Handle(_pyObject) obj = new _pySelfEraser( theCommand );
00428 if ( !myObjects.insert( make_pair( obj->GetID(), obj )).second )
00429 theCommand->Clear();
00430 }
00431
00432
00433 if ( method == "Concatenate" || method == "ConcatenateWithGroups")
00434 {
00435 if ( method == "ConcatenateWithGroups" ) {
00436 theCommand->SetMethod( "Concatenate" );
00437 theCommand->SetArg( theCommand->GetNbArgs() + 1, "True" );
00438 }
00439 Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
00440 myMeshes.insert( make_pair( mesh->GetID(), mesh ));
00441 AddMeshAccessorMethod( theCommand );
00442 }
00443
00444
00445
00446
00447 static TStringSet smeshpyMethods;
00448 if ( smeshpyMethods.empty() ) {
00449 const char * names[] =
00450 { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
00451 "GetPattern","GetSubShapesId",
00452 "" };
00453 smeshpyMethods.Insert( names );
00454 }
00455 if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
00456
00457 theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
00458 else
00459
00460 theCommand->SetObject( SMESH_2smeshpy::GenName() );
00461 }
00462
00463
00467
00468
00469 void _pyGen::Flush()
00470 {
00471
00472 myLastCommand = new _pyCommand();
00473
00474 map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.begin();
00475 for ( ; id_mesh != myMeshes.end(); ++id_mesh )
00476 if ( ! id_mesh->second.IsNull() )
00477 id_mesh->second->Flush();
00478
00479 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
00480 for ( ; hyp != myHypos.end(); ++hyp )
00481 if ( !hyp->IsNull() ) {
00482 (*hyp)->Flush();
00483
00484 if ( !(*hyp)->IsWrapped() )
00485 (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
00486 }
00487
00488 map< _pyID, Handle(_pyObject) >::iterator id_obj = myObjects.begin();
00489 for ( ; id_obj != myObjects.end(); ++id_obj )
00490 if ( ! id_obj->second.IsNull() )
00491 id_obj->second->Flush();
00492
00493 myLastCommand->SetOrderNb( ++myNbCommands );
00494 myCommands.push_back( myLastCommand );
00495 }
00496
00497
00503
00504
00505 bool _pyGen::AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const
00506 {
00507 bool added = false;
00508 map< _pyID, Handle(_pyMesh) >::const_iterator id_mesh = myMeshes.begin();
00509 for ( ; id_mesh != myMeshes.end(); ++id_mesh ) {
00510 if ( theCmd->AddAccessorMethod( id_mesh->first, id_mesh->second->AccessorMethod() ))
00511 added = true;
00512 }
00513 return added;
00514 }
00515
00516
00522
00523
00524 bool _pyGen::AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const
00525 {
00526 bool added = false;
00527 list< Handle(_pyHypothesis) >::const_iterator hyp = myHypos.begin();
00528 for ( ; hyp != myHypos.end(); ++hyp ) {
00529 if ( (*hyp)->IsAlgo() &&
00530 theCmd->AddAccessorMethod( (*hyp)->GetID(), (*hyp)->AccessorMethod() ))
00531 added = true;
00532 }
00533 return added;
00534 }
00535
00536
00542
00543
00544 Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
00545 {
00546 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
00547 for ( ; hyp != myHypos.end(); ++hyp )
00548 if ( !hyp->IsNull() && theHypID == (*hyp)->GetID() )
00549 return *hyp;
00550 return Handle(_pyHypothesis)();
00551 }
00552
00553
00561
00562
00563 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
00564 const Handle(_pyHypothesis)& theHypothesis )
00565 {
00566 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
00567 for ( ; hyp != myHypos.end(); ++hyp )
00568 if ( !hyp->IsNull() &&
00569 (*hyp)->IsAlgo() &&
00570 theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
00571 (*hyp)->GetGeom() == theGeom &&
00572 (*hyp)->GetMesh() == theMesh )
00573 return *hyp;
00574 return 0;
00575 }
00576
00577
00583
00584
00585 Handle(_pySubMesh) _pyGen::FindSubMesh( const _pyID& theSubMeshID )
00586 {
00587 map< _pyID, Handle(_pyObject) >::iterator id_subMesh = myObjects.find(theSubMeshID);
00588 if ( id_subMesh != myObjects.end() )
00589 return Handle(_pySubMesh)::DownCast( id_subMesh->second );
00590 return Handle(_pySubMesh)();
00591 }
00592
00593
00594
00600
00601
00602 void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 )
00603 {
00604 list< Handle(_pyCommand) >::iterator pos1, pos2;
00605 pos1 = find( myCommands.begin(), myCommands.end(), theCmd1 );
00606 pos2 = find( myCommands.begin(), myCommands.end(), theCmd2 );
00607 myCommands.insert( pos1, theCmd2 );
00608 myCommands.insert( pos2, theCmd1 );
00609 myCommands.erase( pos1 );
00610 myCommands.erase( pos2 );
00611
00612 int nb1 = theCmd1->GetOrderNb();
00613 theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
00614 theCmd2->SetOrderNb( nb1 );
00615
00616
00617 }
00618
00619
00625
00626
00627 void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
00628 {
00629 setNeighbourCommand( theCmd, theAfterCmd, true );
00630 }
00631
00632
00638
00639
00640 void _pyGen::SetCommandBefore( Handle(_pyCommand) theCmd, Handle(_pyCommand) theBeforeCmd )
00641 {
00642 setNeighbourCommand( theCmd, theBeforeCmd, false );
00643 }
00644
00645
00651
00652
00653 void _pyGen::setNeighbourCommand( Handle(_pyCommand)& theCmd,
00654 Handle(_pyCommand)& theOtherCmd,
00655 const bool theIsAfter )
00656 {
00657 list< Handle(_pyCommand) >::iterator pos;
00658 pos = find( myCommands.begin(), myCommands.end(), theCmd );
00659 myCommands.erase( pos );
00660 pos = find( myCommands.begin(), myCommands.end(), theOtherCmd );
00661 myCommands.insert( (theIsAfter ? ++pos : pos), theCmd );
00662
00663 int i = 1;
00664 for ( pos = myCommands.begin(); pos != myCommands.end(); ++pos)
00665 (*pos)->SetOrderNb( i++ );
00666 }
00667
00668
00673
00674
00675 Handle(_pyCommand)& _pyGen::GetLastCommand()
00676 {
00677 return myLastCommand;
00678 }
00679
00680
00686
00687
00688 void _pyGen::SetAccessorMethod(const _pyID& theID, const char* theMethod )
00689 {
00690 myID2AccessorMethod.Bind( theID, (char*) theMethod );
00691 }
00692
00693
00698
00699
00700 _pyID _pyGen::GenerateNewID( const _pyID& theID )
00701 {
00702 int index = 1;
00703 _pyID aNewID;
00704 do {
00705 aNewID = theID + _pyID( ":" ) + _pyID( index++ );
00706 }
00707 while ( myObjectNames.IsBound( aNewID ) );
00708
00709 myObjectNames.Bind( aNewID, myObjectNames.IsBound( theID )
00710 ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ))
00711 : _pyID( "A" ) + aNewID );
00712 return aNewID;
00713 }
00714
00715
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00781
00782
00783 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd)
00784 : _pyObject(theCreationCmd), myHasEditor(false)
00785 {
00786
00787 Handle(_pyCommand) creationCmd = GetCreationCmd();
00788
00789
00790
00791
00792 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
00793 creationCmd->SetMethod( "Mesh" );
00794
00795 theGen->SetAccessorMethod( GetID(), "GetMesh()" );
00796 }
00797
00798
00803
00804 _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString& id):
00805 _pyObject(theCreationCmd), myHasEditor(false)
00806 {
00807
00808 Handle(_pyCommand) creationCmd = GetCreationCmd();
00809 creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
00810 theGen->SetAccessorMethod( id, "GetMesh()" );
00811 }
00812
00813
00818
00819
00820 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
00821 {
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835 const TCollection_AsciiString method = theCommand->GetMethod();
00836
00837 if ( method == "GetSubMesh" ) {
00838 Handle(_pySubMesh) subMesh = theGen->FindSubMesh( theCommand->GetResultValue() );
00839 if ( !subMesh.IsNull() ) {
00840 subMesh->SetCreator( this );
00841 mySubmeshes.push_back( subMesh );
00842 }
00843 }
00844
00845 else if ( method == "AddHypothesis" ) {
00846 myAddHypCmds.push_back( theCommand );
00847
00848 const _pyID& hypID = theCommand->GetArg( 2 );
00849 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
00850 if ( !hyp.IsNull() ) {
00851 myHypos.push_back( hyp );
00852 if ( hyp->GetMesh().IsEmpty() )
00853 hyp->SetMesh( this->GetID() );
00854 }
00855 }
00856
00857 else if ( method == "CreateGroupFromGEOM" ) {
00858 _pyID grp = theCommand->GetArg( 3 );
00859
00860
00861
00862
00863
00864
00865
00866
00867 _pyID type = theCommand->GetArg( 1 );
00868 _pyID name = theCommand->GetArg( 2 );
00869 theCommand->SetMethod( "GroupOnGeom" );
00870 theCommand->RemoveArgs();
00871 theCommand->SetArg( 1, grp );
00872 theCommand->SetArg( 2, name );
00873 theCommand->SetArg( 3, type );
00874
00875 }
00876
00877 else if ( method == "ExportToMED" ||
00878 method == "ExportToMEDX" ) {
00879 theCommand->SetMethod( "ExportMED" );
00880 }
00881
00882 else if ( method == "CreateGroup" ) {
00883 theCommand->SetMethod( "CreateEmptyGroup" );
00884 }
00885
00886 else if ( method == "RemoveHypothesis" )
00887 {
00888 _pyID hypID = theCommand->GetArg( 2 );
00889
00890
00891 bool hasAddCmd = false;
00892 list< Handle(_pyCommand) >::iterator cmd = myAddHypCmds.begin();
00893 while ( cmd != myAddHypCmds.end() )
00894 {
00895
00896 if ( hypID == (*cmd)->GetArg( 2 )) {
00897 theCommand->Clear();
00898 (*cmd)->Clear();
00899 cmd = myAddHypCmds.erase( cmd );
00900 hasAddCmd = true;
00901 }
00902 else {
00903 ++cmd;
00904 }
00905 }
00906 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
00907 if ( ! hasAddCmd && hypID.Length() != 0 ) {
00908
00909 _pyID geom = theCommand->GetArg( 1 );
00910 theCommand->RemoveArgs();
00911 theCommand->SetArg( 1, hypID );
00912 if ( geom != GetGeom() )
00913 theCommand->SetArg( 2, geom );
00914 }
00915
00916 myHypos.remove( hyp );
00917 }
00918
00919 else if ( theCommand->GetMethod() == "GetMeshOrder" ||
00920 theCommand->GetMethod() == "SetMeshOrder" ) {
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930 const bool isArg = theCommand->GetMethod() == "SetMeshOrder";
00931 const TCollection_AsciiString& cmdStr = theCommand->GetString();
00932 int begPos = ( cmdStr.Search( "[" )) + 1;
00933 int endPos = (isArg ? cmdStr.Search( ")" ) : cmdStr.Search( "=" )) - 1;
00934 if ( begPos != -1 && begPos < endPos && endPos <= cmdStr.Length() ) {
00935 TCollection_AsciiString aSubStr = cmdStr.SubString( begPos, endPos );
00936 Standard_Integer index = 1;
00937 TCollection_AsciiString anIDStr = aSubStr.Token("\t ,[]", index++);
00938 while ( !anIDStr.IsEmpty() ) {
00939 Handle(_pySubMesh) subMesh = theGen->FindSubMesh( anIDStr );
00940 if ( !subMesh.IsNull() )
00941 subMesh->Process( theCommand );
00942 anIDStr = aSubStr.Token("\t ,[]", index++);
00943 }
00944 }
00945 }
00946
00947 else
00948 {
00949 if ( NeedMeshAccess( theCommand ))
00950
00951 AddMeshAccess( theCommand );
00952 }
00953 }
00954
00955
00959
00960
00961 bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
00962 {
00963
00964
00965 static TStringSet sameMethods;
00966 if ( sameMethods.empty() ) {
00967 const char * names[] =
00968 { "ExportDAT","ExportUNV","ExportSTL", "RemoveGroup","RemoveGroupWithContents",
00969 "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
00970 "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
00971 "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
00972 "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
00973 "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
00974 "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
00975 "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
00976 "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
00977 "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
00978 "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
00979 "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
00980 "Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder"
00981 ,"" };
00982 sameMethods.Insert( names );
00983 }
00984
00985 return !sameMethods.Contains( theCommand->GetMethod() );
00986 }
00987
00988
00992
00993
00994 void _pyMesh::Flush()
00995 {
00996 list < Handle(_pyCommand) >::iterator cmd;
00997
00998
00999
01000 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
01001 {
01002 Handle(_pyCommand) addCmd = *cmd;
01003
01004 _pyID algoID = addCmd->GetArg( 2 );
01005 Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
01006 if ( algo.IsNull() || !algo->IsAlgo() )
01007 continue;
01008
01009
01010 if ( algo->IsWrapped() ) {
01011 _pyID localAlgoID = theGen->GenerateNewID( algoID );
01012 TCollection_AsciiString aNewCmdStr = localAlgoID +
01013 TCollection_AsciiString( " = " ) + theGen->GetID() +
01014 TCollection_AsciiString( ".CreateHypothesis( \"" ) + algo->GetAlgoType() +
01015 TCollection_AsciiString( "\" )" );
01016
01017 Handle(_pyCommand) newCmd = theGen->AddCommand( aNewCmdStr );
01018 Handle(_pyAlgorithm) newAlgo = Handle(_pyAlgorithm)::DownCast(theGen->FindHyp( localAlgoID ));
01019 if ( !newAlgo.IsNull() ) {
01020 newAlgo->Assign( algo, this->GetID() );
01021 newAlgo->SetCreationCmd( newCmd );
01022 algo = newAlgo;
01023
01024 theGen->SetCommandBefore( newCmd, addCmd );
01025 }
01026 else
01027 newCmd->Clear();
01028 }
01029 _pyID geom = addCmd->GetArg( 1 );
01030 bool isLocalAlgo = ( geom != GetGeom() );
01031
01032
01033 if ( algo->Addition2Creation( addCmd, this->GetID() ))
01034 {
01035
01036 GetCreationCmd()->AddDependantCmd( addCmd );
01037
01038 if ( isLocalAlgo ) {
01039
01040 addCmd->SetArg( addCmd->GetNbArgs() + 1,
01041 TCollection_AsciiString( "geom=" ) + geom );
01042
01043 list < Handle(_pySubMesh) >::iterator smIt;
01044 for ( smIt = mySubmeshes.begin(); smIt != mySubmeshes.end(); ++smIt ) {
01045 Handle(_pySubMesh) subMesh = *smIt;
01046 Handle(_pyCommand) subCmd = subMesh->GetCreationCmd();
01047 if ( geom == subCmd->GetArg( 1 )) {
01048 subCmd->SetObject( algo->GetID() );
01049 subCmd->RemoveArgs();
01050 subMesh->SetCreator( algo );
01051 }
01052 }
01053 }
01054 }
01055 else
01056 {
01057
01058 addCmd->RemoveArgs();
01059 addCmd->SetArg( 1, algoID );
01060 if ( isLocalAlgo )
01061 addCmd->SetArg( 2, geom );
01062 }
01063 }
01064
01065
01066
01067 for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
01068 {
01069 Handle(_pyCommand) addCmd = *cmd;
01070 _pyID hypID = addCmd->GetArg( 2 );
01071 Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
01072 if ( hyp.IsNull() || hyp->IsAlgo() )
01073 continue;
01074 bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
01075 if ( !converted ) {
01076
01077 _pyID geom = addCmd->GetArg( 1 );
01078 addCmd->RemoveArgs();
01079 addCmd->SetArg( 1, hypID );
01080 if ( geom != GetGeom() )
01081 addCmd->SetArg( 2, geom );
01082 }
01083 }
01084
01085
01086
01087
01088
01089
01090
01091 myAddHypCmds.clear();
01092 mySubmeshes.clear();
01093
01094
01095 list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
01096 for ( ; hyp != myHypos.end(); ++hyp )
01097 (*hyp)->Flush();
01098 }
01099
01100
01104
01105
01106 _pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
01107 _pyObject( theCreationCmd )
01108 {
01109 myMesh = theCreationCmd->GetObject();
01110 myCreationCmdStr = theCreationCmd->GetString();
01111 theCreationCmd->Clear();
01112 }
01113
01114
01118
01119
01120 void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
01121 {
01122
01123
01124 static TStringSet sameMethods;
01125 if ( sameMethods.empty() ) {
01126 const char * names[] = {
01127 "RemoveElements","RemoveNodes","RemoveOrphanNodes","AddNode","Add0DElement","AddEdge","AddFace","AddPolygonalFace",
01128 "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode", "MoveClosestNodeToPoint",
01129 "InverseDiag","DeleteDiag","Reorient","ReorientObject","TriToQuad","SplitQuad","SplitQuadObject",
01130 "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
01131 "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
01132 "RotationSweep","RotationSweepObject","RotationSweepObject1D","RotationSweepObject2D",
01133 "ExtrusionSweep","AdvancedExtrusion","ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D",
01134 "ExtrusionAlongPath","ExtrusionAlongPathObject","ExtrusionAlongPathX",
01135 "ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D",
01136 "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
01137 "FindCoincidentNodes","MergeNodes","FindEqualElements",
01138 "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
01139 "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
01140 "GetLastCreatedElems",
01141 "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
01142 "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh"
01143 ,"" };
01144 sameMethods.Insert( names );
01145 }
01146
01147
01148
01149 static TStringSet diffLastTwoArgsMethods;
01150 if (diffLastTwoArgsMethods.empty() ) {
01151 const char * names[] = {
01152 "MirrorMakeGroups","MirrorObjectMakeGroups",
01153 "TranslateMakeGroups","TranslateObjectMakeGroups",
01154 "RotateMakeGroups","RotateObjectMakeGroups",
01155 ""};
01156 diffLastTwoArgsMethods.Insert( names );
01157 }
01158
01159 const TCollection_AsciiString & method = theCommand->GetMethod();
01160 bool isPyMeshMethod = sameMethods.Contains( method );
01161 if ( !isPyMeshMethod )
01162 {
01163
01164
01165
01166 int pos = method.Search("MakeGroups");
01167 if( pos != -1)
01168 {
01169 isPyMeshMethod = true;
01170
01171
01172 TCollection_AsciiString aMethod = theCommand->GetMethod();
01173 int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
01174 aMethod.Trunc(pos-1);
01175 theCommand->SetMethod(aMethod);
01176
01177
01178 while(nbArgsToAdd--)
01179 theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
01180 }
01181 }
01182
01183
01184 if ( !isPyMeshMethod && method == "ExtrusionAlongPathObjX")
01185 {
01186 isPyMeshMethod=true;
01187 theCommand->SetMethod("ExtrusionAlongPathX");
01188 }
01189
01190
01191 if ( !isPyMeshMethod && method == "FindCoincidentNodesOnPartBut")
01192 {
01193 isPyMeshMethod=true;
01194 theCommand->SetMethod("FindCoincidentNodesOnPart");
01195 }
01196
01197
01198
01199
01200 if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" ||
01201 method == "DoubleNodeElemGroupsNew" ||
01202 method == "DoubleNodeGroupNew" ||
01203 method == "DoubleNodeGroupsNew"))
01204 {
01205 isPyMeshMethod=true;
01206 theCommand->SetMethod( method.SubString( 1, method.Length()-3));
01207 theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
01208 }
01209
01210
01211 if ( !isPyMeshMethod && ( method == "ConvertToQuadraticObject" ||
01212 method == "ConvertFromQuadraticObject" ))
01213 {
01214 isPyMeshMethod=true;
01215 theCommand->SetMethod( method.SubString( 1, method.Length()-6));
01216
01217 bool isFromQua = ( method.Value( 8 ) == 'F' );
01218 Handle(_pySubMesh) sm = theGen->FindSubMesh( theCommand->GetArg( isFromQua ? 1 : 2 ));
01219 if ( !sm.IsNull() )
01220 sm->Process( theCommand );
01221 }
01222
01223
01224
01225
01226
01227 if ( isPyMeshMethod )
01228 {
01229 theCommand->SetObject( myMesh );
01230 }
01231 else
01232 {
01233
01234 theGen->AddMeshAccessorMethod( theCommand );
01235 if ( !myCreationCmdStr.IsEmpty() ) {
01236 GetCreationCmd()->GetString() = myCreationCmdStr;
01237 myCreationCmdStr.Clear();
01238 }
01239 }
01240 }
01241
01242
01247
01248
01249 _pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
01250 _pyObject( theCreationCmd )
01251 {
01252 myIsAlgo = myIsWrapped = false;
01253 }
01254
01255
01261
01262
01263 Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& theCreationCmd)
01264 {
01265
01266 ASSERT (( theCreationCmd->GetMethod() == "CreateHypothesis"));
01267
01268 Handle(_pyHypothesis) hyp, algo;
01269
01270
01271 const TCollection_AsciiString & hypTypeQuoted = theCreationCmd->GetArg( 1 );
01272 if ( hypTypeQuoted.IsEmpty() )
01273 return hyp;
01274
01275 TCollection_AsciiString hypType =
01276 hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
01277
01278 algo = new _pyAlgorithm( theCreationCmd );
01279 hyp = new _pyHypothesis( theCreationCmd );
01280
01281
01282 if ( hypType == "Regular_1D" ) {
01283
01284
01285
01286 algo->SetConvMethodAndType("Segment", hypType.ToCString());
01287 }
01288 else if ( hypType == "CompositeSegment_1D" ) {
01289 algo->SetConvMethodAndType("Segment", "Regular_1D");
01290 algo->myArgs.Append( "algo=smesh.COMPOSITE");
01291 }
01292 else if ( hypType == "LocalLength" ) {
01293
01294 hyp->SetConvMethodAndType( "LocalLength", "Regular_1D");
01295
01296
01297 hyp->AddArgMethod( "SetLength" );
01298 }
01299 else if ( hypType == "MaxLength" ) {
01300
01301 hyp->SetConvMethodAndType( "MaxSize", "Regular_1D");
01302
01303
01304 hyp->AddArgMethod( "SetLength" );
01305 }
01306 else if ( hypType == "NumberOfSegments" ) {
01307 hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
01308 hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
01309
01310 hyp->AddArgMethod( "SetNumberOfSegments" );
01311
01312 hyp->AddArgMethod( "SetScaleFactor" );
01313 hyp->AddArgMethod( "SetReversedEdges" );
01314 }
01315 else if ( hypType == "Arithmetic1D" ) {
01316 hyp = new _pyComplexParamHypo( theCreationCmd );
01317 hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
01318 hyp->AddArgMethod( "SetStartLength" );
01319 hyp->AddArgMethod( "SetEndLength" );
01320 hyp->AddArgMethod( "SetReversedEdges" );
01321 }
01322 else if ( hypType == "StartEndLength" ) {
01323 hyp = new _pyComplexParamHypo( theCreationCmd );
01324 hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
01325 hyp->AddArgMethod( "SetStartLength" );
01326 hyp->AddArgMethod( "SetEndLength" );
01327 hyp->AddArgMethod( "SetReversedEdges" );
01328 }
01329 else if ( hypType == "Deflection1D" ) {
01330 hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
01331 hyp->AddArgMethod( "SetDeflection" );
01332 }
01333 else if ( hypType == "Propagation" ) {
01334 hyp->SetConvMethodAndType( "Propagation", "Regular_1D");
01335 }
01336 else if ( hypType == "QuadraticMesh" ) {
01337 hyp->SetConvMethodAndType( "QuadraticMesh", "Regular_1D");
01338 }
01339 else if ( hypType == "AutomaticLength" ) {
01340 hyp->SetConvMethodAndType( "AutomaticLength", "Regular_1D");
01341 hyp->AddArgMethod( "SetFineness");
01342 }
01343 else if ( hypType == "SegmentLengthAroundVertex" ) {
01344 hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
01345 hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
01346 hyp->AddArgMethod( "SetLength" );
01347 }
01348
01349 else if ( hypType == "Python_1D" ) {
01350 algo->SetConvMethodAndType( "Segment", hypType.ToCString());
01351 algo->myArgs.Append( "algo=smesh.PYTHON");
01352 }
01353 else if ( hypType == "PythonSplit1D" ) {
01354 hyp->SetConvMethodAndType( "PythonSplit1D", "Python_1D");
01355 hyp->AddArgMethod( "SetNumberOfSegments");
01356 hyp->AddArgMethod( "SetPythonLog10RatioFunction");
01357 }
01358
01359 else if ( hypType == "MEFISTO_2D" ) {
01360 algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
01361 }
01362 else if ( hypType == "MaxElementArea" ) {
01363 hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
01364 hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
01365 hyp->AddArgMethod( "SetMaxElementArea");
01366 }
01367 else if ( hypType == "LengthFromEdges" ) {
01368 hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
01369 hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
01370 }
01371
01372 else if ( hypType == "Quadrangle_2D" ) {
01373 algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
01374 }
01375 else if ( hypType == "QuadranglePreference" ) {
01376 hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
01377 hyp->SetConvMethodAndType( "SetQuadAllowed", "NETGEN_2D_ONLY");
01378 }
01379 else if ( hypType == "TrianglePreference" ) {
01380 hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
01381 }
01382
01383 else if ( hypType == "RadialQuadrangle_1D2D" ) {
01384 algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
01385 algo->myArgs.Append( "algo=smesh.RADIAL_QUAD" );
01386 }
01387 else if ( hypType == "NumberOfLayers2D" ) {
01388 hyp->SetConvMethodAndType( "NumberOfLayers", "RadialQuadrangle_1D2D");
01389 hyp->AddArgMethod( "SetNumberOfLayers" );
01390 }
01391 else if ( hypType == "LayerDistribution2D" ) {
01392 hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get2DHypothesis" );
01393 hyp->SetConvMethodAndType( "LayerDistribution", "RadialQuadrangle_1D2D");
01394 }
01395
01396 else if ( hypType == "BLSURF" ) {
01397 algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
01398 algo->myArgs.Append( "algo=smesh.BLSURF" );
01399 }
01400 else if ( hypType == "BLSURF_Parameters") {
01401 hyp->SetConvMethodAndType( "Parameters", "BLSURF");
01402 }
01403
01404 else if ( hypType == "NETGEN_2D") {
01405 algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
01406 algo->myArgs.Append( "algo=smesh.NETGEN" );
01407 }
01408 else if ( hypType == "NETGEN_Parameters_2D") {
01409 hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D");
01410 }
01411 else if ( hypType == "NETGEN_SimpleParameters_2D") {
01412 hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D");
01413 hyp->myArgs.Append( "which=smesh.SIMPLE" );
01414 }
01415 else if ( hypType == "NETGEN_2D3D") {
01416 algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
01417 algo->myArgs.Append( "algo=smesh.FULL_NETGEN" );
01418 }
01419 else if ( hypType == "NETGEN_Parameters") {
01420 hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D3D");
01421 }
01422 else if ( hypType == "NETGEN_SimpleParameters_3D") {
01423 hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D3D");
01424 hyp->myArgs.Append( "which=smesh.SIMPLE" );
01425 }
01426 else if ( hypType == "NETGEN_2D_ONLY") {
01427 algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
01428 algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
01429 }
01430 else if ( hypType == "NETGEN_3D") {
01431 algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
01432 algo->myArgs.Append( "algo=smesh.NETGEN" );
01433 }
01434 else if ( hypType == "MaxElementVolume") {
01435 hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
01436 hyp->AddArgMethod( "SetMaxElementVolume" );
01437 }
01438
01439 else if ( hypType == "GHS3D_3D" ) {
01440 algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
01441 algo->myArgs.Append( "algo=smesh.GHS3D" );
01442 }
01443 else if ( hypType == "GHS3D_Parameters") {
01444 hyp->SetConvMethodAndType( "Parameters", "GHS3D_3D");
01445 }
01446
01447 else if ( hypType == "BLSURF" ) {
01448 algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
01449 }
01450
01451 else if ( hypType == "Projection_1D" ) {
01452 algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
01453 }
01454 else if ( hypType == "ProjectionSource1D" ) {
01455 hyp->SetConvMethodAndType( "SourceEdge", "Projection_1D");
01456 hyp->AddArgMethod( "SetSourceEdge");
01457 hyp->AddArgMethod( "SetSourceMesh");
01458
01459 hyp->AddArgMethod( "SetVertexAssociation", 2 );
01460 }
01461
01462 else if ( hypType == "Projection_2D" ) {
01463 algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
01464 }
01465 else if ( hypType == "ProjectionSource2D" ) {
01466 hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
01467 hyp->AddArgMethod( "SetSourceFace");
01468 hyp->AddArgMethod( "SetSourceMesh");
01469 hyp->AddArgMethod( "SetVertexAssociation", 4 );
01470 }
01471
01472 else if ( hypType == "Projection_3D" ) {
01473 algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
01474 }
01475 else if ( hypType == "ProjectionSource3D" ) {
01476 hyp->SetConvMethodAndType( "SourceShape3D", "Projection_3D");
01477 hyp->AddArgMethod( "SetSource3DShape");
01478 hyp->AddArgMethod( "SetSourceMesh");
01479 hyp->AddArgMethod( "SetVertexAssociation", 4 );
01480 }
01481
01482 else if ( hypType == "Prism_3D" ) {
01483 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
01484 }
01485
01486 else if ( hypType == "RadialPrism_3D" ) {
01487 algo->SetConvMethodAndType( "Prism", hypType.ToCString());
01488 }
01489 else if ( hypType == "NumberOfLayers" ) {
01490 hyp->SetConvMethodAndType( "NumberOfLayers", "RadialPrism_3D");
01491 hyp->AddArgMethod( "SetNumberOfLayers" );
01492 }
01493 else if ( hypType == "LayerDistribution" ) {
01494 hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get3DHypothesis" );
01495 hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
01496 }
01497
01498 return algo->IsValid() ? algo : hyp;
01499 }
01500
01501
01508
01509
01510 bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
01511 const _pyID& theMesh)
01512 {
01513 ASSERT(( theCmd->GetMethod() == "AddHypothesis" ));
01514
01515 if ( !IsWrappable( theMesh ))
01516 return false;
01517
01518 myGeom = theCmd->GetArg( 1 );
01519
01520 Handle(_pyHypothesis) algo;
01521 if ( !IsAlgo() ) {
01522
01523 algo = theGen->FindAlgo( myGeom, theMesh, this );
01524 if ( algo.IsNull() )
01525 return false;
01526
01527
01528 algo->GetCreationCmd()->AddDependantCmd( theCmd );
01529 }
01530 myIsWrapped = true;
01531
01532
01533 theCmd->SetResultValue( GetID() );
01534 theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
01535 theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
01536
01537 theCmd->RemoveArgs();
01538 for ( int i = 1; i <= myArgs.Length(); ++i ) {
01539 if ( !myArgs( i ).IsEmpty() )
01540 theCmd->SetArg( i, myArgs( i ));
01541 else
01542 theCmd->SetArg( i, "[]");
01543 }
01544
01545 GetCreationCmd()->Clear();
01546
01547
01548 SetCreationCmd( theCmd );
01549
01550
01551
01552 list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
01553 for ( ; argCmd != myArgCommands.end(); ++argCmd )
01554 (*argCmd)->Clear();
01555
01556
01557 Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
01558 list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
01559 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
01560 afterCmd->AddDependantCmd( *cmd );
01561 }
01562
01563 return myIsWrapped;
01564 }
01565
01566
01571
01572
01573 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
01574 {
01575 ASSERT( !myIsAlgo );
01576
01577 int nbArgs = 0;
01578 for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
01579 if ( myArgMethods( i ) == theCommand->GetMethod() ) {
01580 while ( myArgs.Length() < nbArgs + myNbArgsByMethod( i ))
01581 myArgs.Append( "[]" );
01582 for ( int iArg = 1; iArg <= myNbArgsByMethod( i ); ++iArg )
01583 myArgs( nbArgs + iArg ) = theCommand->GetArg( iArg );
01584 myArgCommands.push_back( theCommand );
01585 return;
01586 }
01587 nbArgs += myNbArgsByMethod( i );
01588 }
01589 myUnknownCommands.push_back( theCommand );
01590 }
01591
01592
01596
01597
01598 void _pyHypothesis::Flush()
01599 {
01600 if ( IsWrapped() ) {
01601 }
01602 else {
01603 list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
01604 for ( ; cmd != myArgCommands.end(); ++cmd ) {
01605
01606 theGen->AddMeshAccessorMethod( *cmd );
01607
01608 theGen->AddAlgoAccessorMethod( *cmd );
01609 }
01610 cmd = myUnknownCommands.begin();
01611 for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
01612
01613 theGen->AddMeshAccessorMethod( *cmd );
01614
01615 theGen->AddAlgoAccessorMethod( *cmd );
01616 }
01617 }
01618
01619 myArgCommands.clear();
01620 myUnknownCommands.clear();
01621 }
01622
01623
01627
01628
01629 void _pyHypothesis::ClearAllCommands()
01630 {
01631 GetCreationCmd()->Clear();
01632 list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
01633 for ( ; cmd != myArgCommands.end(); ++cmd )
01634 ( *cmd )->Clear();
01635 cmd = myUnknownCommands.begin();
01636 for ( ; cmd != myUnknownCommands.end(); ++cmd )
01637 ( *cmd )->Clear();
01638 }
01639
01640
01641
01645
01646
01647 void _pyHypothesis::Assign( const Handle(_pyHypothesis)& theOther,
01648 const _pyID& theMesh )
01649 {
01650 myIsWrapped = false;
01651 myMesh = theMesh;
01652
01653
01654 myIsAlgo = theOther->myIsAlgo;
01655 myGeom = theOther->myGeom;
01656 myType2CreationMethod = theOther->myType2CreationMethod;
01657 myArgs = theOther->myArgs;
01658 myArgMethods = theOther->myArgMethods;
01659 myNbArgsByMethod = theOther->myNbArgsByMethod;
01660 myArgCommands = theOther->myArgCommands;
01661 myUnknownCommands = theOther->myUnknownCommands;
01662 }
01663
01664
01669
01670
01671 void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
01672 {
01673 if( theCommand->GetMethod() == "SetLength" )
01674 {
01675
01676
01677
01678 ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
01679 int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
01680 while ( myArgs.Length() < i )
01681 myArgs.Append( "[]" );
01682 myArgs( i ) = theCommand->GetArg( 1 );
01683 myArgCommands.push_back( theCommand );
01684 }
01685 else
01686 {
01687 _pyHypothesis::Process( theCommand );
01688 }
01689 }
01690
01694
01695
01696 void _pyComplexParamHypo::Flush()
01697 {
01698 if ( IsWrapped() )
01699 {
01700 list < Handle(_pyCommand) >::iterator cmd = myUnknownCommands.begin();
01701 for ( ; cmd != myUnknownCommands.end(); ++cmd )
01702 if ((*cmd)->GetMethod() == "SetObjectEntry" )
01703 (*cmd)->Clear();
01704 }
01705 }
01706
01707
01712
01713
01714 void _pyLayerDistributionHypo::Process( const Handle(_pyCommand)& theCommand)
01715 {
01716 if ( theCommand->GetMethod() != "SetLayerDistribution" )
01717 return;
01718
01719 _pyID newName;
01720
01721 const _pyID& hyp1dID = theCommand->GetArg( 1 );
01722 Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
01723 if ( hyp1d.IsNull() )
01724 hyp1d = my1dHyp;
01725 else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() ) {
01726
01727
01728 my1dHyp->ClearAllCommands();
01729 }
01730 my1dHyp = hyp1d;
01731
01732 if ( !myArgCommands.empty() )
01733 myArgCommands.front()->Clear();
01734 myArgCommands.push_back( theCommand );
01735 }
01736
01737
01744
01745
01746 bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
01747 const _pyID& theMesh)
01748 {
01749 myIsWrapped = false;
01750
01751 if ( my1dHyp.IsNull() )
01752 return false;
01753
01754
01755 theAdditionCmd->AddDependantCmd( myArgCommands.front() );
01756
01757 _pyID geom = theAdditionCmd->GetArg( 1 );
01758
01759 Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
01760 if ( !algo.IsNull() )
01761 {
01762 my1dHyp->SetMesh( theMesh );
01763 my1dHyp->SetConvMethodAndType(my1dHyp->GetAlgoCreationMethod().ToCString(),
01764 algo->GetAlgoType().ToCString());
01765 if ( !my1dHyp->Addition2Creation( theAdditionCmd, theMesh ))
01766 return false;
01767
01768
01769 myArgCommands.back()->Clear();
01770
01771
01772
01773
01774 GetCreationCmd()->SetObject( algo->GetID() );
01775 GetCreationCmd()->SetMethod( myAlgoMethod );
01776 GetCreationCmd()->RemoveArgs();
01777 theAdditionCmd->AddDependantCmd( GetCreationCmd() );
01778 myIsWrapped = true;
01779 }
01780 return myIsWrapped;
01781 }
01782
01783
01787
01788
01789 void _pyLayerDistributionHypo::Flush()
01790 {
01791
01792
01793 if ( !my1dHyp.IsNull() )
01794 {
01795 _pyID hyp1dID = my1dHyp->GetCreationCmd()->GetResultValue();
01796
01797
01798 _pyID newName;
01799 if ( my1dHyp->IsWrapped() ) {
01800 newName = my1dHyp->GetCreationCmd()->GetMethod();
01801 }
01802 else {
01803 TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
01804 newName = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
01805 }
01806 newName += "_Distribution";
01807 my1dHyp->GetCreationCmd()->SetResultValue( newName );
01808
01809 list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
01810 list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
01811 for ( ; cmdIt != cmds.end(); ++cmdIt ) {
01812 const _pyID& objID = (*cmdIt)->GetObject();
01813 if ( objID == hyp1dID ) {
01814 my1dHyp->Process( *cmdIt );
01815 my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
01816 ( *cmdIt )->SetObject( newName );
01817 }
01818 }
01819
01820 if ( !myArgCommands.empty() && !myArgCommands.back()->IsEmpty() )
01821 myArgCommands.back()->SetArg( 1, newName );
01822 }
01823 }
01824
01825
01832
01833
01834 bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
01835 const _pyID& theMesh)
01836 {
01837 if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
01838
01839 bool scaleDistrType = false;
01840 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
01841 for ( ; cmd != myUnknownCommands.rend(); ++cmd ) {
01842 if ( (*cmd)->GetMethod() == "SetDistrType" ) {
01843 if ( (*cmd)->GetArg( 1 ) == "1" ) {
01844 scaleDistrType = true;
01845 (*cmd)->Clear();
01846 }
01847 else if ( !scaleDistrType ) {
01848
01849 myArgs.Remove( 2, myArgs.Length() );
01850 break;
01851 }
01852 }
01853 }
01854 }
01855 return _pyHypothesis::Addition2Creation( theCmd, theMesh );
01856 }
01857
01858
01862
01863
01864 void _pyNumberOfSegmentsHyp::Flush()
01865 {
01866
01867 list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
01868 int distrTypeNb = 0;
01869 for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
01870 if ( (*cmd)->GetMethod() == "SetDistrType" )
01871 distrTypeNb = (*cmd)->GetOrderNb();
01872 else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" )
01873 (*cmd)->Clear();
01874
01875
01876 list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
01877 for ( int i = 0; i < 2; ++i ) {
01878 set<TCollection_AsciiString> uniqueMethods;
01879 list<Handle(_pyCommand)> & cmdList = *cmds[i];
01880 for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
01881 {
01882 bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
01883 const TCollection_AsciiString& method = (*cmd)->GetMethod();
01884 if ( !clear || method == "SetNumberOfSegments" ) {
01885 bool isNewInSet = uniqueMethods.insert( method ).second;
01886 clear = !isNewInSet;
01887 }
01888 if ( clear )
01889 (*cmd)->Clear();
01890 }
01891 cmdList.clear();
01892 }
01893 }
01894
01895
01903
01904
01905 bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
01906 const _pyID& theMeshID)
01907 {
01908 if ( IsWrappable( theMeshID )) {
01909
01910 _pyID vertex = theCmd->GetArg( 1 );
01911
01912
01913
01914
01915 Handle(_pyHypothesis) algo;
01916 _pyID geom = vertex;
01917 while ( algo.IsNull() && !geom.IsEmpty()) {
01918
01919 geom = FatherID( geom );
01920 algo = theGen->FindAlgo( geom, theMeshID, this );
01921 }
01922 if ( algo.IsNull() )
01923 return false;
01924
01925 theCmd->SetArg( 1, geom );
01926
01927
01928 if ( myArgs.Length() < 1) myArgs.Append( "1" );
01929 myArgs.Append( vertex );
01930
01931
01932
01933 return _pyHypothesis::Addition2Creation( theCmd, theMeshID );
01934 }
01935 return false;
01936 }
01937
01938
01943
01944
01945 _pyAlgorithm::_pyAlgorithm(const Handle(_pyCommand)& theCreationCmd)
01946 : _pyHypothesis( theCreationCmd )
01947 {
01948 myIsAlgo = true;
01949 }
01950
01951
01958
01959
01960 bool _pyAlgorithm::Addition2Creation( const Handle(_pyCommand)& theCmd,
01961 const _pyID& theMeshID)
01962 {
01963
01964 if ( _pyHypothesis::Addition2Creation( theCmd, theMeshID )) {
01965 theGen->SetAccessorMethod( GetID(), "GetAlgorithm()" );
01966 return true;
01967 }
01968 return false;
01969 }
01970
01971
01977
01978
01979 int _pyCommand::GetBegPos( int thePartIndex )
01980 {
01981 if ( IsEmpty() )
01982 return EMPTY;
01983 if ( myBegPos.Length() < thePartIndex )
01984 return UNKNOWN;
01985 return myBegPos( thePartIndex );
01986 }
01987
01988
01994
01995
01996 void _pyCommand::SetBegPos( int thePartIndex, int thePosition )
01997 {
01998 while ( myBegPos.Length() < thePartIndex )
01999 myBegPos.Append( UNKNOWN );
02000 myBegPos( thePartIndex ) = thePosition;
02001 }
02002
02003
02008
02009
02010 TCollection_AsciiString _pyCommand::GetIndentation()
02011 {
02012 int end = 1;
02013 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
02014 GetWord( myString, end, true );
02015 else
02016 end = GetBegPos( RESULT_IND );
02017 return myString.SubString( 1, end - 1 );
02018 }
02019
02020
02025
02026
02027 const TCollection_AsciiString & _pyCommand::GetResultValue()
02028 {
02029 if ( GetBegPos( RESULT_IND ) == UNKNOWN )
02030 {
02031 int begPos = myString.Location( "=", 1, Length() );
02032 if ( begPos )
02033 myRes = GetWord( myString, begPos, false );
02034 else
02035 begPos = EMPTY;
02036 SetBegPos( RESULT_IND, begPos );
02037 }
02038 return myRes;
02039 }
02040
02041
02046
02047
02048 const int _pyCommand::GetNbResultValues()
02049 {
02050 int begPos = 1;
02051 int Nb=0;
02052 int endPos = myString.Location( "=", 1, Length() );
02053 TCollection_AsciiString str = "";
02054 while ( begPos < endPos) {
02055 str = GetWord( myString, begPos, true );
02056 begPos = begPos+ str.Length();
02057 Nb++;
02058 }
02059 return (Nb-1);
02060 }
02061
02062
02063
02069
02070 const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
02071 {
02072 int begPos = 1;
02073 int Nb=0;
02074 int endPos = myString.Location( "=", 1, Length() );
02075 while ( begPos < endPos) {
02076 myRes = GetWord( myString, begPos, true );
02077 begPos = begPos + myRes.Length();
02078 Nb++;
02079 if(res == Nb){
02080 myRes.RemoveAll('[');myRes.RemoveAll(']');
02081 return myRes;
02082 }
02083 if(Nb>res)
02084 break;
02085 }
02086 return theEmptyString;
02087 }
02088
02089
02094
02095
02096 const TCollection_AsciiString & _pyCommand::GetObject()
02097 {
02098 if ( GetBegPos( OBJECT_IND ) == UNKNOWN )
02099 {
02100
02101 int begPos = GetBegPos( RESULT_IND ) + myRes.Length();
02102 if ( begPos < 1 ) {
02103 begPos = myString.Location( "=", 1, Length() ) + 1;
02104
02105 int nb1 = 0;
02106 int nb2 = 0;
02107 for ( int i = 1; i < begPos-1; i++ ) {
02108 if ( myString.Value( i )=='\'' )
02109 nb1 += 1;
02110 else if ( myString.Value( i )=='"' )
02111 nb2 += 1;
02112 }
02113
02114
02115 if ( nb1 % 2 != 0 || nb2 % 2 != 0 )
02116 begPos = 1;
02117 }
02118 myObj = GetWord( myString, begPos, true );
02119
02120
02121 if ( int bracketPos = myString.Location( "(", begPos, Length() )) {
02122
02123 int dotPos = begPos+myObj.Length();
02124 while ( dotPos+1 < bracketPos ) {
02125 if ( int pos = myString.Location( ".", dotPos+1, bracketPos ))
02126 dotPos = pos;
02127 else
02128 break;
02129 }
02130 if ( dotPos > begPos+myObj.Length() )
02131 myObj = myString.SubString( begPos, dotPos-1 );
02132 }
02133
02134 SetBegPos( OBJECT_IND, begPos );
02135 }
02136
02137 return myObj;
02138 }
02139
02140
02145
02146
02147 const TCollection_AsciiString & _pyCommand::GetMethod()
02148 {
02149 if ( GetBegPos( METHOD_IND ) == UNKNOWN )
02150 {
02151
02152 int begPos = GetBegPos( OBJECT_IND ) + myObj.Length();
02153 bool forward = true;
02154 if ( begPos < 1 ) {
02155 begPos = myString.Location( "(", 1, Length() ) - 1;
02156 forward = false;
02157 }
02158
02159 myMeth = GetWord( myString, begPos, forward );
02160 SetBegPos( METHOD_IND, begPos );
02161 }
02162
02163 return myMeth;
02164 }
02165
02166
02171
02172
02173 const TCollection_AsciiString & _pyCommand::GetArg( int index )
02174 {
02175 if ( GetBegPos( ARG1_IND ) == UNKNOWN )
02176 {
02177
02178 int begPos = GetBegPos( METHOD_IND ) + myMeth.Length();
02179 if ( begPos < 1 )
02180 begPos = myString.Location( "(", 1, Length() ) + 1;
02181
02182 int i = 0, prevLen = 0, nbNestings = 0;
02183 while ( begPos != EMPTY ) {
02184 begPos += prevLen;
02185 if( myString.Value( begPos ) == '(' )
02186 nbNestings++;
02187
02188 while ( begPos <= Length() && isspace( myString.Value( begPos )))
02189 ++begPos;
02190 if ( begPos > Length() )
02191 break;
02192 if ( myString.Value( begPos ) == ')' ) {
02193 nbNestings--;
02194 if( nbNestings == 0 )
02195 break;
02196 }
02197 myArgs.Append( GetWord( myString, begPos, true, true ));
02198 SetBegPos( ARG1_IND + i, begPos );
02199 prevLen = myArgs.Last().Length();
02200 if ( prevLen == 0 )
02201 myArgs.Remove( myArgs.Length() );
02202 i++;
02203 }
02204 }
02205 if ( myArgs.Length() < index )
02206 return theEmptyString;
02207 return myArgs( index );
02208 }
02209
02210
02216
02217
02218 static inline bool isWord(const char c, const bool dotIsWord)
02219 {
02220 return
02221 !isspace(c) && c != ',' && c != '=' && c != ')' && c != '(' && ( dotIsWord || c != '.');
02222 }
02223
02224
02232
02233
02234 TCollection_AsciiString _pyCommand::GetWord( const TCollection_AsciiString & theString,
02235 int & theStartPos,
02236 const bool theForward,
02237 const bool dotIsWord )
02238 {
02239 int beg = theStartPos, end = theStartPos;
02240 theStartPos = EMPTY;
02241 if ( beg < 1 || beg > theString.Length() )
02242 return theEmptyString;
02243
02244 if ( theForward ) {
02245
02246 while ( beg <= theString.Length() && !isWord( theString.Value( beg ), dotIsWord))
02247 ++beg;
02248 if ( beg > theString.Length() )
02249 return theEmptyString;
02250
02251 end = beg + 1;
02252 char begChar = theString.Value( beg );
02253 if ( begChar == '"' || begChar == '\'' || begChar == '[') {
02254 char endChar = ( begChar == '[' ) ? ']' : begChar;
02255
02256 while ( end < theString.Length() &&
02257 ( theString.Value( end ) != endChar || theString.Value( end-1 ) == '\\'))
02258 ++end;
02259 }
02260 else {
02261 while ( end <= theString.Length() && isWord( theString.Value( end ), dotIsWord))
02262 ++end;
02263 --end;
02264 }
02265 }
02266 else {
02267
02268 while ( end > 0 && !isWord( theString.Value( end ), dotIsWord))
02269 --end;
02270 if ( end == 0 )
02271 return theEmptyString;
02272 beg = end - 1;
02273 char endChar = theString.Value( end );
02274 if ( endChar == '"' || endChar == '\'' ) {
02275
02276 while ( beg > 1 &&
02277 ( theString.Value( beg ) != endChar || theString.Value( beg-1 ) == '\\'))
02278 --beg;
02279 }
02280 else {
02281 while ( beg > 0 && isWord( theString.Value( beg ), dotIsWord))
02282 --beg;
02283 ++beg;
02284 }
02285 }
02286 theStartPos = beg;
02287
02288 return theString.SubString( beg, end );
02289 }
02290
02291
02300
02301
02302 bool _pyCommand::SkipSpaces( const TCollection_AsciiString & theString, int & thePos )
02303 {
02304 if ( thePos < 1 || thePos > theString.Length() )
02305 return false;
02306
02307 while ( thePos <= theString.Length() && isspace( theString.Value( thePos )))
02308 ++thePos;
02309
02310 return thePos <= theString.Length();
02311 }
02312
02313
02320
02321
02322 void _pyCommand::SetPart(int thePartIndex, const TCollection_AsciiString& thePart,
02323 TCollection_AsciiString& theOldPart)
02324 {
02325 int pos = GetBegPos( thePartIndex );
02326 if ( pos <= Length() && theOldPart != thePart)
02327 {
02328 TCollection_AsciiString seperator;
02329 if ( pos < 1 ) {
02330 pos = GetBegPos( thePartIndex + 1 );
02331 if ( pos < 1 ) return;
02332 switch ( thePartIndex ) {
02333 case RESULT_IND: seperator = " = "; break;
02334 case OBJECT_IND: seperator = "."; break;
02335 case METHOD_IND: seperator = "()"; break;
02336 default:;
02337 }
02338 }
02339 myString.Remove( pos, theOldPart.Length() );
02340 if ( !seperator.IsEmpty() )
02341 myString.Insert( pos , seperator );
02342 myString.Insert( pos, thePart );
02343
02344 int posDelta = thePart.Length() + seperator.Length() - theOldPart.Length();
02345 for ( int i = thePartIndex + 1; i <= myBegPos.Length(); ++i ) {
02346 if ( myBegPos( i ) > 0 )
02347 myBegPos( i ) += posDelta;
02348 }
02349 theOldPart = thePart;
02350 }
02351 }
02352
02353
02359
02360
02361 void _pyCommand::SetArg( int index, const TCollection_AsciiString& theArg)
02362 {
02363 FindAllArgs();
02364 int argInd = ARG1_IND + index - 1;
02365 int pos = GetBegPos( argInd );
02366 if ( pos < 1 )
02367 {
02368
02369 if ( GetNbArgs() != 0 && index <= GetNbArgs() ) {
02370 int lastArgInd = GetNbArgs();
02371 pos = GetBegPos( ARG1_IND + lastArgInd - 1 ) + GetArg( lastArgInd ).Length();
02372 while ( pos > 0 && pos <= Length() && myString.Value( pos ) != ')' )
02373 ++pos;
02374 }
02375 else {
02376 pos = Length();
02377 while ( pos > 0 && myString.Value( pos ) != ')' )
02378 --pos;
02379 }
02380 if ( pos < 1 || myString.Value( pos ) != ')' ) {
02381 myString += "()";
02382 pos = Length();
02383 }
02384 while ( myArgs.Length() < index ) {
02385 if ( myArgs.Length() )
02386 myString.Insert( pos++, "," );
02387 myArgs.Append("None");
02388 myString.Insert( pos, myArgs.Last() );
02389 SetBegPos( ARG1_IND + myArgs.Length() - 1, pos );
02390 pos += myArgs.Last().Length();
02391 }
02392 }
02393 SetPart( argInd, theArg, myArgs( index ));
02394 }
02395
02396
02400
02401
02402 void _pyCommand::RemoveArgs()
02403 {
02404 if ( int pos = myString.Location( '(', 1, Length() ))
02405 myString.Trunc( pos );
02406 myString += ")";
02407 myArgs.Clear();
02408 if ( myBegPos.Length() >= ARG1_IND )
02409 myBegPos.Remove( ARG1_IND, myBegPos.Length() );
02410 }
02411
02412
02416
02417
02418 bool _pyCommand::SetDependentCmdsAfter() const
02419 {
02420 bool orderChanged = false;
02421 list< Handle(_pyCommand)>::const_reverse_iterator cmd = myDependentCmds.rbegin();
02422 for ( ; cmd != myDependentCmds.rend(); ++cmd ) {
02423 if ( (*cmd)->GetOrderNb() < GetOrderNb() ) {
02424 orderChanged = true;
02425 theGen->SetCommandAfter( *cmd, this );
02426 (*cmd)->SetDependentCmdsAfter();
02427 }
02428 }
02429 return orderChanged;
02430 }
02431
02438
02439
02440 bool _pyCommand::AddAccessorMethod( _pyID theObjectID, const char* theAcsMethod )
02441 {
02442 if ( !theAcsMethod )
02443 return false;
02444
02445 GetObject();
02446 int beg = GetBegPos( OBJECT_IND );
02447 if ( beg < 1 || beg > Length() )
02448 return false;
02449 bool added = false;
02450 while (( beg = myString.Location( theObjectID, beg, Length() )))
02451 {
02452
02453 int afterEnd = beg + theObjectID.Length();
02454 Standard_Character c = myString.Value( afterEnd );
02455 if ( !isalnum( c ) && c != ':' ) {
02456
02457 if ( c != '.' ||
02458 myString.Location( (char*) theAcsMethod, afterEnd, Length() ) != afterEnd+1) {
02459
02460 int oldLen = Length();
02461 myString.Insert( afterEnd, (char*) theAcsMethod );
02462 myString.Insert( afterEnd, "." );
02463
02464 int posDelta = Length() - oldLen;
02465 for ( int i = 1; i <= myBegPos.Length(); ++i ) {
02466 if ( myBegPos( i ) > afterEnd )
02467 myBegPos( i ) += posDelta;
02468 }
02469 added = true;
02470 }
02471 }
02472 beg = afterEnd;
02473 }
02474 return added;
02475 }
02476
02477
02482
02483
02484 const char* _pyObject::AccessorMethod() const
02485 {
02486 return 0;
02487 }
02488
02492
02493
02494 _pyID _pyObject::FatherID(const _pyID & childID)
02495 {
02496 int colPos = childID.SearchFromEnd(':');
02497 if ( colPos > 0 )
02498 return childID.SubString( 1, colPos-1 );
02499 return "";
02500 }
02501
02502
02506
02507
02508 void _pySelfEraser::Flush()
02509 {
02510 if ( GetNbCalls() == 0 )
02511 GetCreationCmd()->Clear();
02512 }
02513
02514
02518
02519
02520 void _pySubMesh::Process( const Handle(_pyCommand)& theCommand )
02521 {
02522 _pyObject::Process(theCommand);
02523 GetCreationCmd()->AddDependantCmd( theCommand );
02524 }
02525
02526
02530
02531
02532 void _pySubMesh::Flush()
02533 {
02534 if ( GetNbCalls() == 0 )
02535 theGen->GetLastCommand()->AddDependantCmd( GetCreationCmd() );
02536 else if ( !myCreator.IsNull() )
02537
02538 myCreator->GetCreationCmd()->AddDependantCmd( GetCreationCmd() );
02539 }