+//================================================================================
+/*!
+ * \brief Analyze my erasability depending on myReferredObjs
+ */
+//================================================================================
+
+bool _pyHypothesis::CanClear()
+{
+ if ( IsInStudy() )
+ {
+ list< Handle(_pyObject) >::iterator obj = myReferredObjs.begin();
+ for ( ; obj != myReferredObjs.end(); ++obj )
+ if ( (*obj)->CanClear() )
+ return true;
+ return false;
+ }
+ return true;
+}
+
+//================================================================================
+/*!
+ * \brief Clear my commands depending on usage by meshes
+ */
+//================================================================================
+
+void _pyHypothesis::ClearCommands()
+{
+ // if ( !theGen->IsToKeepAllCommands() )
+ // {
+ // bool isUsed = false;
+ // int lastComputeOrder = 0;
+ // list<Handle(_pyCommand) >::iterator cmd = myComputeCmds.begin();
+ // for ( ; cmd != myComputeCmds.end(); ++cmd )
+ // if ( ! (*cmd)->IsEmpty() )
+ // {
+ // isUsed = true;
+ // if ( (*cmd)->GetOrderNb() > lastComputeOrder )
+ // lastComputeOrder = (*cmd)->GetOrderNb();
+ // }
+ // if ( !isUsed )
+ // {
+ // SetRemovedFromStudy( true );
+ // }
+ // else
+ // {
+ // // clear my commands invoked after lastComputeOrder
+ // // map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
+ // // for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
+ // // {
+ // // list< Handle(_pyCommand)> & cmds = m2c->second;
+ // // if ( !cmds.empty() && cmds.back()->GetOrderNb() > lastComputeOrder )
+ // // cmds.back()->Clear();
+ // // }
+ // }
+ // }
+ _pyObject::ClearCommands();
+}
+
+//================================================================================
+/*!
+ * \brief Find arguments that are objects like mesh, group, geometry
+ * \param meshes - referred meshes (directly or indirrectly)
+ * \retval bool - false if a referred geometry is not in the study
+ */
+//================================================================================
+
+bool _pyHypothesis::GetReferredMeshesAndGeom( list< Handle(_pyMesh) >& meshes )
+{
+ if ( IsAlgo() ) return true;
+
+ bool geomPublished = true;
+ TColStd_SequenceOfAsciiString args; args = myArgs;
+
+ list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
+ for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
+ for ( int nb = (*cmd)->GetNbArgs(); nb; --nb )
+ args.Append( (*cmd)->GetArg( nb ));
+ }
+
+ for ( int i = 1; i <= args.Length(); ++i )
+ {
+ list< _pyID > idList = _pyCommand::GetStudyEntries( args( i ));
+ list< _pyID >::iterator id = idList.begin();
+ for ( ; id != idList.end(); ++id )
+ {
+ Handle(_pyObject) obj = theGen->FindObject( *id );
+ if ( obj.IsNull() )
+ {
+ if ( theGen->IsGeomObject( *id ) && theGen->IsNotPublished( *id ))
+ geomPublished = false;
+ }
+ else
+ {
+ myReferredObjs.push_back( obj );
+ Handle(_pyMesh) mesh = ObjectToMesh( obj );
+ if ( !mesh.IsNull() )
+ meshes.push_back( mesh );
+ }
+ }
+ }
+ return geomPublished;
+}
+
+//================================================================================
+/*!
+ * \brief Remember theCommand setting a parameter
+ */
+//================================================================================
+
+void _pyHypothesis::rememberCmdOfParameter( const Handle(_pyCommand) & theCommand )
+{
+ // parameters are discriminated by method name
+ TCollection_AsciiString method = theCommand->GetMethod();
+
+ // discriminate commands setting different parameters via one method
+ // by passing parameter names like e.g. SetOption("size", "0.2")
+ if ( theCommand->GetString().FirstLocationInSet( "'\"", 1, theCommand->Length() ) &&
+ theCommand->GetNbArgs() > 1 )
+ {
+ // mangle method by appending a 1st textual arg (what if it's a variable name?!!!)
+ for ( int iArg = 1; iArg <= theCommand->GetNbArgs(); ++iArg )
+ {
+ const TCollection_AsciiString& arg = theCommand->GetArg( iArg );
+ if ( arg.Value(1) != '\"' && arg.Value(1) != '\'' ) continue;
+ if ( !isalpha( arg.Value(2))) continue;
+ method += arg;
+ break;
+ }
+ }
+ // parameters are discriminated by method name
+ list< Handle(_pyCommand)>& cmds = myMeth2Commands[ theCommand->GetMethod() ];
+ if ( !cmds.empty() && !isCmdUsedForCompute( cmds.back() ))
+ {
+ cmds.back()->Clear(); // previous parameter value has not been used
+ cmds.back() = theCommand;
+ }
+ else
+ {
+ cmds.push_back( theCommand );
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Return true if a setting parameter command ha been used to compute mesh
+ */
+//================================================================================
+
+bool _pyHypothesis::isCmdUsedForCompute( const Handle(_pyCommand) & cmd,
+ _pyCommand::TAddr avoidComputeAddr ) const
+{
+ bool isUsed = false;
+ map< _pyCommand::TAddr, list<Handle(_pyCommand) > >::const_iterator addr2cmds =
+ myComputeAddr2Cmds.begin();
+ for ( ; addr2cmds != myComputeAddr2Cmds.end() && !isUsed; ++addr2cmds )
+ {
+ if ( addr2cmds->first == avoidComputeAddr ) continue;
+ const list<Handle(_pyCommand)> & cmds = addr2cmds->second;
+ isUsed = ( std::find( cmds.begin(), cmds.end(), cmd ) != cmds.end() );
+ }
+ return isUsed;
+}
+
+//================================================================================
+/*!
+ * \brief Save commands setting parameters as they are used for a mesh computation
+ */
+//================================================================================
+
+void _pyHypothesis::MeshComputed( const Handle(_pyCommand)& theComputeCmd )
+{
+ myComputeCmds.push_back( theComputeCmd );
+ list<Handle(_pyCommand)>& savedCmds = myComputeAddr2Cmds[ theComputeCmd->GetAddress() ];
+
+ map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
+ for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
+ savedCmds.push_back( m2c->second.back() );
+}
+
+//================================================================================
+/*!
+ * \brief Clear commands setting parameters as a mesh computed using them is cleared
+ */
+//================================================================================
+
+void _pyHypothesis::ComputeDiscarded( const Handle(_pyCommand)& theComputeCmd )
+{
+ list<Handle(_pyCommand)>& savedCmds = myComputeAddr2Cmds[ theComputeCmd->GetAddress() ];
+
+ list<Handle(_pyCommand)>::iterator cmd = savedCmds.begin();
+ for ( ; cmd != savedCmds.end(); ++cmd )
+ {
+ // check if a cmd has been used to compute another mesh
+ if ( isCmdUsedForCompute( *cmd, theComputeCmd->GetAddress() ))
+ continue;
+ // check if a cmd is a sole command setting its parameter;
+ // don't use method name for search as it can change
+ map<TCollection_AsciiString, list<Handle(_pyCommand)> >::iterator
+ m2cmds = myMeth2Commands.begin();
+ for ( ; m2cmds != myMeth2Commands.end(); ++m2cmds )
+ {
+ list< Handle(_pyCommand)>& cmds = m2cmds->second;
+ list< Handle(_pyCommand)>::iterator cmdIt = std::find( cmds.begin(), cmds.end(), *cmd );
+ if ( cmdIt != cmds.end() )
+ {
+ if ( cmds.back() != *cmd )
+ {
+ cmds.erase( cmdIt );
+ (*cmd)->Clear();
+ }
+ break;
+ }
+ }
+ }
+ myComputeAddr2Cmds.erase( theComputeCmd->GetAddress() );
+}
+// void _pyHypothesis::ComputeSaved( const Handle(_pyCommand)& theComputeCommand )
+// {
+// }
+
+