0022172: [CEA 790] create the groups corresponding to domains

1) Do not erase "mesh.Compute()" command if the next command
   "[ group1, group2 ] = mesh.GetGroups()" dumps groups created by some algorithm.

2) Clear "mesh.RemoveGroup( group )" command
3) Clear "[ group1, group2 ] = mesh.GetGroups()" command if the groups
   are removed later.
This commit is contained in:
eap 2013-05-24 11:55:12 +00:00
parent 7b5176ec4d
commit 0f7414545b
2 changed files with 80 additions and 6 deletions

View File

@ -1407,7 +1407,7 @@ bool _pyGen::IsNotPublished(const _pyID& theObjID) const
//================================================================================ //================================================================================
/*! /*!
* \brief Remove object name from myObjectNames that leads to that SetName() for * \brief Add an object to myRemovedObjIDs that leads to that SetName() for
* this object is not dumped * this object is not dumped
* \param [in] theObjID - entry of the object whose creation command was eliminated * \param [in] theObjID - entry of the object whose creation command was eliminated
*/ */
@ -1616,31 +1616,61 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
myGroups.push_back( group ); myGroups.push_back( group );
theGen->AddObject( group ); theGen->AddObject( group );
} }
// ----------------------------------------------------------------------
// update list of groups // update list of groups
else if ( method == "GetGroups" ) else if ( method == "GetGroups" )
{ {
bool allGroupsRemoved = true;
TCollection_AsciiString grIDs = theCommand->GetResultValue(); TCollection_AsciiString grIDs = theCommand->GetResultValue();
list< _pyID > idList = theCommand->GetStudyEntries( grIDs ); list< _pyID > idList = theCommand->GetStudyEntries( grIDs );
list< _pyID >::iterator grID = idList.begin(); list< _pyID >::iterator grID = idList.begin();
const int nbGroupsBefore = myGroups.size();
Handle(_pyObject) obj;
for ( ; grID != idList.end(); ++grID ) for ( ; grID != idList.end(); ++grID )
{ {
Handle(_pyObject) obj = theGen->FindObject( *grID ); obj = theGen->FindObject( *grID );
if ( obj.IsNull() ) if ( obj.IsNull() )
{ {
Handle(_pyGroup) group = new _pyGroup( theCommand, *grID ); Handle(_pyGroup) group = new _pyGroup( theCommand, *grID );
theGen->AddObject( group ); theGen->AddObject( group );
myGroups.push_back( group ); myGroups.push_back( group );
obj = group;
} }
if ( !obj->CanClear() )
allGroupsRemoved = false;
}
if ( nbGroupsBefore == myGroups.size() ) // no new _pyGroup created
obj->AddProcessedCmd( theCommand ); // to clear theCommand if all groups are removed
if ( !allGroupsRemoved && !theGen->IsToKeepAllCommands() )
{
// check if the preceding command is Compute();
// if GetGroups() is just after Compute(), this can mean that the groups
// were created by some algorithm and hence Compute() should not be discarded
std::list< Handle(_pyCommand) >& cmdList = theGen->GetCommands();
std::list< Handle(_pyCommand) >::iterator cmd = cmdList.begin();
while ( (*cmd)->GetMethod() == "GetGroups" )
++cmd;
if ( myLastComputeCmd == (*cmd))
// protect last Compute() from clearing by the next Compute()
myLastComputeCmd.Nullify();
} }
} }
// ----------------------------------------------------------------------
// notify a group about full removal // notify a group about full removal
else if ( method == "RemoveGroupWithContents" ) else if ( method == "RemoveGroupWithContents" ||
method == "RemoveGroup")
{ {
if ( !theGen->IsToKeepAllCommands() ) { // snapshot mode if ( !theGen->IsToKeepAllCommands() ) { // snapshot mode
const _pyID groupID = theCommand->GetArg( 1 ); const _pyID groupID = theCommand->GetArg( 1 );
Handle(_pyGroup) grp = Handle(_pyGroup)::DownCast( theGen->FindObject( groupID )); Handle(_pyGroup) grp = Handle(_pyGroup)::DownCast( theGen->FindObject( groupID ));
if ( !grp.IsNull() ) if ( !grp.IsNull() )
grp->RemovedWithContents(); {
if ( method == "RemoveGroupWithContents" )
grp->RemovedWithContents();
// to clear RemoveGroup() if the group creation is cleared
grp->AddProcessedCmd( theCommand );
}
} }
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -4018,6 +4048,10 @@ _pyGroup::_pyGroup(const Handle(_pyCommand)& theCreationCmd, const _pyID & id)
} }
myFilter = filter; myFilter = filter;
} }
else if ( method == "GetGroups" )
{
myCanClearCreationCmd = ( theCreationCmd->GetNbResultValues() == 1 );
}
else else
{ {
// theCreationCmd does something else apart from creation of this group // theCreationCmd does something else apart from creation of this group
@ -4026,6 +4060,45 @@ _pyGroup::_pyGroup(const Handle(_pyCommand)& theCreationCmd, const _pyID & id)
} }
} }
//================================================================================
/*!
* \brief Check if "[ group1, group2 ] = mesh.GetGroups()" creation command
* can be cleared
*/
//================================================================================
bool _pyGroup::CanClear()
{
if ( IsInStudy() )
return false;
if ( !myCanClearCreationCmd && myCreationCmd->GetMethod() == "GetGroups" )
{
TCollection_AsciiString grIDs = myCreationCmd->GetResultValue();
list< _pyID > idList = myCreationCmd->GetStudyEntries( grIDs );
list< _pyID >::iterator grID = idList.begin();
if ( GetID() == *grID )
{
myCanClearCreationCmd = true;
list< Handle(_pyGroup ) > groups;
for ( ; grID != idList.end(); ++grID )
{
Handle(_pyGroup) group = Handle(_pyGroup)::DownCast( theGen->FindObject( *grID ));
if ( group.IsNull() ) continue;
groups.push_back( group );
if ( group->IsInStudy() )
myCanClearCreationCmd = false;
}
// set myCanClearCreationCmd == true to all groups
list< Handle(_pyGroup ) >::iterator group = groups.begin();
for ( ; group != groups.end(); ++group )
(*group)->myCanClearCreationCmd = myCanClearCreationCmd;
}
}
return myCanClearCreationCmd;
}
//================================================================================ //================================================================================
/*! /*!
* \brief set myCanClearCreationCmd = true if the main action of the creation * \brief set myCanClearCreationCmd = true if the main action of the creation

View File

@ -594,6 +594,7 @@ public:
virtual void Process( const Handle(_pyCommand)& theCommand); virtual void Process( const Handle(_pyCommand)& theCommand);
virtual void Flush(); virtual void Flush();
virtual void Free() { myFilter.Nullify(); } virtual void Free() { myFilter.Nullify(); }
virtual bool CanClear();
void RemovedWithContents(); void RemovedWithContents();
DEFINE_STANDARD_RTTI (_pyGroup) DEFINE_STANDARD_RTTI (_pyGroup)