#ifdef DUMP_CONVERSION
cout << endl << " ######## RESULT ######## " << endl<< endl;
#endif
+ // reorder commands after conversion
+ list< Handle(_pyCommand) >::iterator cmd;
+ bool orderChanges;
+ do {
+ orderChanges = false;
+ for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
+ if ( (*cmd)->SetDependentCmdsAfter() )
+ orderChanges = true;
+ } while ( orderChanges );
+
// concat commands back into a script
TCollection_AsciiString aScript;
- list< Handle(_pyCommand) >::iterator cmd = theGen->GetCommands().begin();
- for ( ; cmd != theGen->GetCommands().end(); ++cmd ) {
+ for ( cmd = theGen->GetCommands().begin(); cmd != theGen->GetCommands().end(); ++cmd )
+ {
#ifdef DUMP_CONVERSION
cout << "## COM " << (*cmd)->GetOrderNb() << ": "<< (*cmd)->GetString() << endl;
#endif
if ( !hyp->IsNull() ) {
(*hyp)->Flush();
// smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
- if ( !(*hyp)->GetCreationCmd()->IsEmpty() )
+ if ( !(*hyp)->IsWrapped() )
(*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
}
}
int nb1 = theCmd1->GetOrderNb();
theCmd1->SetOrderNb( theCmd2->GetOrderNb() );
theCmd2->SetOrderNb( nb1 );
+// cout << "BECOME " << theCmd1->GetOrderNb() << "\t" << theCmd1->GetString() << endl
+// << "BECOME " << theCmd2->GetOrderNb() << "\t" << theCmd2->GetString() << endl << endl;
}
+
//================================================================================
/*!
* \brief Set one command after the other
void _pyGen::SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd )
{
+// cout << "SET\t" << theCmd->GetString() << endl << "AFTER\t" << theAfterCmd->GetString() << endl << endl;
list< Handle(_pyCommand) >::iterator pos;
pos = find( myCommands.begin(), myCommands.end(), theCmd );
myCommands.erase( pos );
theGen->SetAccessorMethod( GetID(), "GetMesh()" );
}
-//================================================================================
-/*!
- case brief:
- default:
- * \param theCommand - Engine method called for this mesh
- */
-//================================================================================
-
//================================================================================
/*!
* \brief Convert a IDL API command of SMESH::Mesh to a method call of python Mesh
void _pyMesh::Flush()
{
list < Handle(_pyCommand) >::iterator cmd, cmd2;
- map< _pyID, Handle(_pyCommand) > algo2additionCmd;
// try to convert algo addition like this:
// mesh.AddHypothesis(geom, ALGO ) --> ALGO = mesh.Algo()
_pyID geom = addCmd->GetArg( 1 );
if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
{
- algo2additionCmd[ algo->GetID() ] = addCmd;
+ // wrapped algo is created atfer mesh creation
+ GetCreationCmd()->AddDependantCmd( addCmd );
if ( geom != GetGeom() ) // local algo
{
if ( geom == subCmd->GetArg( 1 )) {
subCmd->SetObject( algo->GetID() );
subCmd->RemoveArgs();
- if ( addCmd->GetOrderNb() > subCmd->GetOrderNb() )
- theGen->SetCommandAfter( subCmd, addCmd );
+ addCmd->AddDependantCmd( subCmd );
}
}
}
if ( !algo.IsNull() && hyp->Addition2Creation( addCmd, this->GetID() )) // OK
{
addCmd->SetObject( algo->GetID() );
- Handle(_pyCommand) algoCmd = algo2additionCmd[ algo->GetID() ];
- if ( !algoCmd.IsNull() && algoCmd->GetOrderNb() > addCmd->GetOrderNb() )
- // algo was created later than hyp
- theGen->ExchangeCommands( algoCmd, addCmd );
+ algo->GetCreationCmd()->AddDependantCmd( addCmd );
}
else
{
else
theCmd->SetArg( i, "[]");
}
+ // set a new creation command
+ GetCreationCmd()->Clear();
+ SetCreationCmd( theCmd );
// clear commands setting arg values
list < Handle(_pyCommand) >::iterator argCmd = myArgCommands.begin();
Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
- if ( !(*cmd)->IsEmpty() && afterCmd->GetOrderNb() > (*cmd)->GetOrderNb() ) {
- theGen->SetCommandAfter( *cmd, afterCmd );
- afterCmd = *cmd;
- }
+ afterCmd->AddDependantCmd( *cmd );
}
myArgCommands.clear();
myUnknownCommands.clear();
void _pyHypothesis::Flush()
{
- if ( IsWrapped() )
- GetCreationCmd()->Clear();
+// if ( IsWrapped() )
+// GetCreationCmd()->Clear();
}
//================================================================================
bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
const _pyID& theMesh)
{
- if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
+ if ( IsWrappable( theMesh ) && myArgs.Length() > 0 ) {
list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
// clear SetDistrType()
if ( myBegPos.Length() >= ARG1_IND )
myBegPos.Remove( ARG1_IND, myBegPos.Length() );
}
+
+//================================================================================
+/*!
+ * \brief Set dependent commands after this one
+ */
+//================================================================================
+
+bool _pyCommand::SetDependentCmdsAfter() const
+{
+ bool orderChanged = false;
+ list< Handle(_pyCommand)>::const_iterator cmd = myDependentCmds.begin();
+ for ( ; cmd != myDependentCmds.end(); ++cmd ) {
+ if ( (*cmd)->GetOrderNb() < GetOrderNb() ) {
+ orderChanged = true;
+ theGen->SetCommandAfter( *cmd, this );
+ (*cmd)->SetDependentCmdsAfter();
+ }
+ }
+ return orderChanged;
+}
TCollection_AsciiString myRes, myObj, myMeth;
TColStd_SequenceOfAsciiString myArgs;
TColStd_SequenceOfInteger myBegPos; //!< where myRes, myObj, ... begin
+ std::list< Handle(_pyCommand) > myDependentCmds;
enum { UNKNOWN=-1, EMPTY=0, RESULT_IND, OBJECT_IND, METHOD_IND, ARG1_IND };
int GetBegPos( int thePartIndex );
void SetBegPos( int thePartIndex, int thePosition );
static TCollection_AsciiString GetWord( const TCollection_AsciiString & theSring,
int & theStartPos, const bool theForward,
const bool dotIsWord = false);
+ void AddDependantCmd( Handle(_pyCommand) cmd)
+ { return myDependentCmds.push_back( cmd ); }
+ bool SetDependentCmdsAfter() const;
+
DEFINE_STANDARD_RTTI (_pyCommand)
};
class _pyObject: public Standard_Transient
{
- Handle(_pyCommand) myCreationCmd;
+ Handle(_pyCommand) myCreationCmd;
public:
_pyObject(const Handle(_pyCommand)& theCreationCmd): myCreationCmd(theCreationCmd) {}
const _pyID& GetID() { return myCreationCmd->GetResultValue(); }
const Handle(_pyCommand)& GetCreationCmd() { return myCreationCmd; }
+ void SetCreationCmd( Handle(_pyCommand) cmd ) { myCreationCmd = cmd; }
int GetCommandNb() { return myCreationCmd->GetOrderNb(); }
virtual void Process(const Handle(_pyCommand) & theCommand) = 0;
virtual void Flush() = 0;