From d6352114af56c2790a01b7f1294251c04876497c Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 26 Apr 2012 07:05:13 +0000 Subject: [PATCH] 0021557: EDF 2161 SMESH: Duplicate elements and nodes 1) Convert DoubleNodeElemGroup2New() 2) Fix _pyCommand::GetResultValue(int res); 3) Add _pyGroup::Flush() to prevent clearing "DoubleNode...() command if a group created by it is removed --- src/SMESH_I/SMESH_2smeshpy.cxx | 70 +++++++++++++++++++++++++--------- src/SMESH_I/SMESH_2smeshpy.hxx | 4 +- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index 3f98c6d6e..9a1f356fe 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -511,7 +511,10 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand method == "DoubleNodeGroupNew" || method == "DoubleNodeGroupsNew" || method == "DoubleNodeElemGroupNew" || - method == "DoubleNodeElemGroupsNew" ) + method == "DoubleNodeElemGroupsNew"|| + method == "DoubleNodeElemGroup2New"|| + method == "DoubleNodeElemGroups2New" + ) groups = aCommand->GetResultValue(); else if ( method == "MakeBoundaryMesh" ) groups = aCommand->GetResultValue(2); @@ -718,7 +721,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand ) { for(int ind = 0;indGetNbResultValues();ind++) { - const _pyID& meshID = theCommand->GetResultValue(ind+1); + _pyID meshID = theCommand->GetResultValue(ind+1); if ( !theCommand->IsStudyEntry( meshID ) ) continue; Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind+1)); myMeshes.insert( make_pair( mesh->GetID(), mesh )); @@ -1962,18 +1965,29 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand) isPyMeshMethod=true; theCommand->SetMethod("FindCoincidentNodesOnPart"); } - // DoubleNodeElemGroupNew() -> DoubleNodeElemGroup() - // DoubleNodeGroupNew() -> DoubleNodeGroup() - // DoubleNodeGroupsNew() -> DoubleNodeGroups() - // DoubleNodeElemGroupsNew() -> DoubleNodeElemGroups() + // DoubleNode...New(...) -> DoubleNode...(...,True) if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" || method == "DoubleNodeElemGroupsNew" || method == "DoubleNodeGroupNew" || - method == "DoubleNodeGroupsNew")) + method == "DoubleNodeGroupsNew" || + method == "DoubleNodeElemGroup2New" || + method == "DoubleNodeElemGroups2New")) { isPyMeshMethod=true; - theCommand->SetMethod( method.SubString( 1, method.Length()-3)); - theCommand->SetArg(theCommand->GetNbArgs()+1,"True"); + const int excessLen = 3 + int( method.Value( method.Length()-3 ) == '2' ); + theCommand->SetMethod( method.SubString( 1, method.Length()-excessLen)); + if ( excessLen == 3 ) + { + theCommand->SetArg(theCommand->GetNbArgs()+1,"True"); + } + else if ( theCommand->GetArg(4) == "0" || + theCommand->GetArg(5) == "0" ) + { + // [ nothing, Group ] = DoubleNodeGroup2New(,,,False, True) -> + // Group = DoubleNodeGroup2New(,,,False, True) + _pyID groupID = theCommand->GetResultValue( 1 + int( theCommand->GetArg(4) == "0")); + theCommand->SetResultValue( groupID ); + } } // ConvertToQuadraticObject(bool,obj) -> ConvertToQuadratic(bool,obj) // ConvertFromQuadraticObject(obj) -> ConvertFromQuadratic(obj) @@ -3027,22 +3041,25 @@ const int _pyCommand::GetNbResultValues() //================================================================================ /*! * \brief Return substring of python command looking like - * ResultValue1 , ResultValue1,... = Obj.Meth() with res index + * ResultValue1 , ResultValue2,... = Obj.Meth() with res index * \retval const TCollection_AsciiString & - ResultValue with res index substring */ //================================================================================ -const TCollection_AsciiString & _pyCommand::GetResultValue(int res) +TCollection_AsciiString _pyCommand::GetResultValue(int res) { int begPos = 1; - int Nb=0; + if ( SkipSpaces( myString, begPos ) && myString.Value( begPos ) == '[' ) + ++begPos; // skip [, else the whole list is returned int endPos = myString.Location( "=", 1, Length() ); + int Nb=0; while ( begPos < endPos) { - myRes = GetWord( myString, begPos, true ); - begPos = begPos + myRes.Length(); + _AString result = GetWord( myString, begPos, true ); + begPos = begPos + result.Length(); Nb++; - if(res == Nb){ - myRes.RemoveAll('[');myRes.RemoveAll(']'); - return myRes; + if(res == Nb) { + result.RemoveAll('['); + result.RemoveAll(']'); + return result; } if(Nb>res) break; @@ -3350,8 +3367,6 @@ std::list< _pyID > _pyCommand::GetStudyEntries( const TCollection_AsciiString& s * \param theString - The string * \param thePos - The position to search from and which returns result * \retval bool - false if there are only space after thePos in theString - * - * */ //================================================================================ @@ -3803,6 +3818,23 @@ void _pyGroup::Process( const Handle(_pyCommand)& theCommand) theGen->AddMeshAccessorMethod( theCommand ); } +//================================================================================ +/*! + * \brief Prevent clearing "DoubleNode...() command if a group created by it is removed + * + * + */ +//================================================================================ + +void _pyGroup::Flush() +{ + if ( !theGen->IsToKeepAllCommands() && + myCreationCmd && myCreationCmd->MethodStartsFrom("DoubleNode") ) + { + myCreationCmd.Nullify(); + } +} + //================================================================================ /*! * \brief Constructor of _pyFilter diff --git a/src/SMESH_I/SMESH_2smeshpy.hxx b/src/SMESH_I/SMESH_2smeshpy.hxx index 21f2c11ba..1fccb3750 100644 --- a/src/SMESH_I/SMESH_2smeshpy.hxx +++ b/src/SMESH_I/SMESH_2smeshpy.hxx @@ -123,7 +123,7 @@ public: _AString GetIndentation(); const _AString & GetResultValue(); const int GetNbResultValues(); - const _AString & GetResultValue(int res); + _AString GetResultValue(int res); const _AString & GetObject(); const _AString & GetMethod(); const _AString & GetArg( int index ); @@ -582,7 +582,7 @@ class _pyGroup: public _pySubMesh public: _pyGroup(const Handle(_pyCommand)& theCreationCmd, const _pyID & id=_pyID()); virtual void Process( const Handle(_pyCommand)& theCommand); - virtual void Flush() {} + virtual void Flush(); virtual void Free() { myFilter.Nullify(); } DEFINE_STANDARD_RTTI (_pyGroup) -- 2.39.2