bug 11389. Fix ordering of commands

This commit is contained in:
eap 2006-03-09 15:41:08 +00:00
parent 4b91a5486b
commit 2386054951
2 changed files with 55 additions and 27 deletions

View File

@ -100,10 +100,20 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
#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
@ -247,7 +257,7 @@ void _pyGen::Flush()
if ( !hyp->IsNull() ) {
(*hyp)->Flush();
// smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
if ( !(*hyp)->GetCreationCmd()->IsEmpty() )
if ( !(*hyp)->IsWrapped() )
(*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
}
}
@ -314,7 +324,10 @@ void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) th
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
@ -325,6 +338,7 @@ void _pyGen::ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) th
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 );
@ -427,14 +441,6 @@ _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd): _pyObject(theCreation
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
@ -536,7 +542,6 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
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()
@ -551,7 +556,8 @@ void _pyMesh::Flush()
_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
{
@ -564,8 +570,7 @@ void _pyMesh::Flush()
if ( geom == subCmd->GetArg( 1 )) {
subCmd->SetObject( algo->GetID() );
subCmd->RemoveArgs();
if ( addCmd->GetOrderNb() > subCmd->GetOrderNb() )
theGen->SetCommandAfter( subCmd, addCmd );
addCmd->AddDependantCmd( subCmd );
}
}
}
@ -596,10 +601,7 @@ void _pyMesh::Flush()
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
{
@ -809,6 +811,9 @@ bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
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();
@ -828,10 +833,7 @@ bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
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();
@ -870,8 +872,8 @@ void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
void _pyHypothesis::Flush()
{
if ( IsWrapped() )
GetCreationCmd()->Clear();
// if ( IsWrapped() )
// GetCreationCmd()->Clear();
}
//================================================================================
@ -906,7 +908,7 @@ void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
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()
@ -1268,3 +1270,23 @@ void _pyCommand::RemoveArgs()
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;
}

View File

@ -84,6 +84,7 @@ class _pyCommand: public Standard_Transient
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 );
@ -118,6 +119,10 @@ public:
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)
};
@ -128,11 +133,12 @@ typedef TCollection_AsciiString _pyID;
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;