remove repeated defining distribution for "Number of Segments" hypothesis

This commit is contained in:
eap 2006-04-13 07:58:51 +00:00
parent 4f9f3d8c77
commit a3d6485d92
2 changed files with 59 additions and 25 deletions

View File

@ -479,8 +479,11 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
// set mesh to hypo // set mesh to hypo
const _pyID& hypID = theCommand->GetArg( 2 ); const _pyID& hypID = theCommand->GetArg( 2 );
Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID ); Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
if ( !hyp.IsNull() && hyp->GetMesh().IsEmpty() ) if ( !hyp.IsNull() ) {
hyp->SetMesh( this->GetID() ); myHypos.push_back( hyp );
if ( hyp->GetMesh().IsEmpty() )
hyp->SetMesh( this->GetID() );
}
} }
else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp) else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
_pyID grp = theCommand->GetArg( 3 ); _pyID grp = theCommand->GetArg( 3 );
@ -510,7 +513,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
while ( cmd != myAddHypCmds.end() ) while ( cmd != myAddHypCmds.end() )
{ {
// AddHypothesis(geom, hyp) // AddHypothesis(geom, hyp)
if ( hypID == (*cmd)->GetArg( 2 )) { // erase both commands if ( hypID == (*cmd)->GetArg( 2 )) { // erase both (add and remove) commands
theCommand->Clear(); theCommand->Clear();
(*cmd)->Clear(); (*cmd)->Clear();
cmd = myAddHypCmds.erase( cmd ); cmd = myAddHypCmds.erase( cmd );
@ -520,17 +523,19 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
++cmd; ++cmd;
} }
} }
if ( ! hasAddCmd ) { Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
if ( ! hasAddCmd ) { // hypo addition already wrapped
// access to wrapped mesh // access to wrapped mesh
AddMeshAccess( theCommand ); AddMeshAccess( theCommand );
// access to wrapped algo // access to wrapped algo
Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
if ( !hyp.IsNull() && hyp->IsAlgo() && hyp->IsWrapped() ) if ( !hyp.IsNull() && hyp->IsAlgo() && hyp->IsWrapped() )
theCommand->SetArg( 2, theCommand->GetArg( 2 ) + ".GetAlgorithm()" ); theCommand->SetArg( 2, theCommand->GetArg( 2 ) + ".GetAlgorithm()" );
} }
// remove hyp from myHypos
myHypos.remove( hyp );
} }
// leave only one mesh_editor_<nb> = mesh.GetMeshEditor() // leave only one " mesh_editor_<nb> = mesh.GetMeshEditor()"
else if ( theCommand->GetMethod() == "GetMeshEditor") else if ( theCommand->GetMethod() == "GetMeshEditor")
{ {
if ( myHasEditor ) if ( myHasEditor )
@ -631,6 +636,11 @@ void _pyMesh::Flush()
} }
myAddHypCmds.clear(); myAddHypCmds.clear();
mySubmeshes.clear(); mySubmeshes.clear();
// flush hypotheses
list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
for ( ; hyp != myHypos.end(); ++hyp )
(*hyp)->Flush();
} }
//================================================================================ //================================================================================
@ -849,8 +859,6 @@ bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
for ( ; cmd != myUnknownCommands.end(); ++cmd ) { for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
afterCmd->AddDependantCmd( *cmd ); afterCmd->AddDependantCmd( *cmd );
} }
myArgCommands.clear();
myUnknownCommands.clear();
return myIsWrapped; return myIsWrapped;
} }
@ -886,8 +894,11 @@ void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
void _pyHypothesis::Flush() void _pyHypothesis::Flush()
{ {
// if ( IsWrapped() ) if ( IsWrapped() ) {
// GetCreationCmd()->Clear(); // forget previous hypothesis modifications
myArgCommands.clear();
myUnknownCommands.clear();
}
} }
//================================================================================ //================================================================================
@ -922,30 +933,51 @@ void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand)
bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd, bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
const _pyID& theMesh) const _pyID& theMesh)
{ {
if ( IsWrappable( theMesh ) && myArgs.Length() > 0 ) { if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
list<Handle(_pyCommand)> aNewCommandsList; // scale factor (2-nd arg) is provided: clear SetDistrType(1)
list<TCollection_AsciiString> aNewList; list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
list<TCollection_AsciiString>::iterator aNewListIter; for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
if ( (*cmd)->GetMethod() == "SetDistrType" ) {
list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin(); if ( (*cmd)->GetArg( 1 ) == "1" )
for ( ; cmd != myUnknownCommands.rend(); ++cmd ) { (*cmd)->Clear();
aNewListIter = find(aNewList.begin(),aNewList.end(),(*cmd)->GetMethod()); else {
if(aNewListIter == aNewList.end()){ // distribution type changed: remove scale factor from args
aNewList.push_front((*cmd)->GetMethod()); myArgs.Remove( 2, myArgs.Length() );
aNewCommandsList.push_front((*cmd)); break;
} else { }
(*cmd)->Clear();
} }
} }
myUnknownCommands = aNewCommandsList;
} }
return _pyHypothesis::Addition2Creation( theCmd, theMesh ); return _pyHypothesis::Addition2Creation( theCmd, theMesh );
} }
//================================================================================
/*!
* \brief remove repeated commands defining distribution
*/
//================================================================================
void _pyNumberOfSegmentsHyp::Flush()
{
const int nbCmdLists = 2;
list<Handle(_pyCommand)> * cmds[nbCmdLists] = { &myArgCommands, &myUnknownCommands };
for ( int i = 0; i < nbCmdLists; ++i ) {
set<TCollection_AsciiString> uniqueMethods;
list<Handle(_pyCommand)> & cmdList = *cmds[i];
list<Handle(_pyCommand)>::reverse_iterator cmd = cmdList.rbegin();
for ( ; cmd != cmdList.rend(); ++cmd ) {
bool isNewInSet = uniqueMethods.insert( (*cmd)->GetMethod() ).second;
if ( ! isNewInSet )
(*cmd)->Clear();
}
cmdList.clear();
}
}
//================================================================================ //================================================================================
/*! /*!
* \brief _pyAlgorithm constructor * \brief _pyAlgorithm constructor
* \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)" * \param theCreationCmd - The command like "algo = smeshgen.CreateHypothesis(type,lib)"
*/ */
//================================================================================ //================================================================================

View File

@ -180,6 +180,7 @@ private:
*/ */
class _pyMesh: public _pyObject class _pyMesh: public _pyObject
{ {
std::list< Handle(_pyHypothesis) > myHypos;
std::list< Handle(_pyCommand) > myAddHypCmds; std::list< Handle(_pyCommand) > myAddHypCmds;
std::list< Handle(_pyCommand) > mySubmeshes; std::list< Handle(_pyCommand) > mySubmeshes;
bool myHasEditor; bool myHasEditor;
@ -267,6 +268,7 @@ public:
_pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {} _pyNumberOfSegmentsHyp(const Handle(_pyCommand)& theCrCmd): _pyHypothesis(theCrCmd) {}
virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd, virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
const _pyID& theMesh); const _pyID& theMesh);
void Flush();
DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp) DEFINE_STANDARD_RTTI (_pyNumberOfSegmentsHyp)
}; };