From 827169f5f309c7534471ca2c27509a51da97a4a4 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 19 Jan 2007 14:43:59 +0000 Subject: [PATCH] PAL13073 (Submesh hypothesises do not work for NETGEN 1D-2D-3D) add _pyCommand::GetIndentation() and addErrorTreatmentCmd() used to show status of not wrapped AddHypothesis() command --- src/SMESH_I/SMESH_2smeshpy.cxx | 62 +++++++++++++++++++++++++++++++--- src/SMESH_I/SMESH_2smeshpy.hxx | 3 +- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index e232506b6..b06a85624 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -153,7 +153,7 @@ _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod */ //================================================================================ -void _pyGen::AddCommand( const TCollection_AsciiString& theCommand) +Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand) { // store theCommand in the sequence myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands )); @@ -166,25 +166,25 @@ void _pyGen::AddCommand( const TCollection_AsciiString& theCommand) _pyID objID = aCommand->GetObject(); if ( objID.IsEmpty() ) - return; + return aCommand; // SMESH_Gen method? if ( objID == this->GetID() ) { this->Process( aCommand ); - return; + return aCommand; } // SMESH_Mesh method? map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID ); if ( id_mesh != myMeshes.end() ) { id_mesh->second->Process( aCommand ); - return; + return aCommand; } // SMESH_Hypothesis method? list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin(); for ( ; hyp != myHypos.end(); ++hyp ) if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) { (*hyp)->Process( aCommand ); - return; + return aCommand; } // Add access to a wrapped mesh @@ -211,6 +211,7 @@ void _pyGen::AddCommand( const TCollection_AsciiString& theCommand) aCommand->GetString() += tmpCmd.GetString(); } } + return aCommand; } //================================================================================ @@ -617,6 +618,36 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) } } +namespace { + + //================================================================================ + /*! + * \brief add addition result treatement command + * \param addCmd - hypothesis addition command + */ + //================================================================================ + + void addErrorTreatmentCmd( Handle(_pyCommand) & addCmd, + const bool isAlgo) + { + // addCmd: status = mesh.AddHypothesis( geom, hypo ) + // treatement command: + // def TreatHypoStatus(status, hypName, geomName, isAlgo): + TCollection_AsciiString status = addCmd->GetResultValue(); + if ( !status.IsEmpty() ) { + const _pyID& geomID = addCmd->GetArg( 1 ); + const _pyID& hypoID = addCmd->GetArg( 2 ); + TCollection_AsciiString cmdStr = addCmd->GetIndentation() + + SMESH_2smeshpy::SmeshpyName() + ".TreatHypoStatus( " + status + ", " + + SMESH_2smeshpy::SmeshpyName() + ".GetName(" + hypoID + "), " + + SMESH_2smeshpy::SmeshpyName() + ".GetName(" + geomID + "), " + + (char*)( isAlgo ? "True" : "False" ) + " )"; + Handle(_pyCommand) cmd = theGen->AddCommand( cmdStr ); + addCmd->AddDependantCmd( cmd ); + } + } +} + //================================================================================ /*! * \brief Convert creation and addition of all algos and hypos @@ -666,6 +697,8 @@ void _pyMesh::Flush() // mesh.GetMesh().AddHypothesis(geom, ALGO ) -> // mesh.GetMesh().AddHypothesis(geom, ALGO.GetAlgorithm() ) addCmd->SetArg( 2, addCmd->GetArg( 2 ) + ".GetAlgorithm()" ); + // add addition result treatement cmd + addErrorTreatmentCmd( addCmd, true ); } } @@ -690,6 +723,8 @@ void _pyMesh::Flush() else { AddMeshAccess( addCmd ); + // add addition result treatement cmd + addErrorTreatmentCmd( addCmd, false ); } } @@ -1293,6 +1328,23 @@ void _pyCommand::SetBegPos( int thePartIndex, int thePosition ) myBegPos( thePartIndex ) = thePosition; } +//================================================================================ +/*! + * \brief Returns whitespace symbols at the line beginning + * \retval TCollection_AsciiString - result + */ +//================================================================================ + +TCollection_AsciiString _pyCommand::GetIndentation() +{ + int end = 1; + if ( GetBegPos( RESULT_IND ) == UNKNOWN ) + GetWord( myString, end, true ); + else + end = GetBegPos( RESULT_IND ); + return myString.SubString( 1, end - 1 ); +} + //================================================================================ /*! * \brief Return substring of python command looking like ResultValue = Obj.Meth() diff --git a/src/SMESH_I/SMESH_2smeshpy.hxx b/src/SMESH_I/SMESH_2smeshpy.hxx index f5717cd2a..3443ed791 100644 --- a/src/SMESH_I/SMESH_2smeshpy.hxx +++ b/src/SMESH_I/SMESH_2smeshpy.hxx @@ -131,6 +131,7 @@ public: int Length() { return myString.Length(); } void Clear() { myString.Clear(); myBegPos.Clear(); } bool IsEmpty() const { return myString.IsEmpty(); } + TCollection_AsciiString GetIndentation(); const TCollection_AsciiString & GetResultValue(); const TCollection_AsciiString & GetObject(); const TCollection_AsciiString & GetMethod(); @@ -191,7 +192,7 @@ class _pyGen: public _pyObject public: _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod); //~_pyGen(); - void AddCommand( const TCollection_AsciiString& theCommand ); + Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand ); void Process( const Handle(_pyCommand)& theCommand ); void Flush(); Handle(_pyHypothesis) FindHyp( const _pyID& theHypID ); -- 2.39.2