From 304f30c5ca3e409e41060eb3611562d4ec72b79c Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 28 Mar 2005 10:11:37 +0000 Subject: [PATCH] Dump Python: dump groups operations; correct processing of removed objects. --- src/SMESH_I/SMESH_Gen_i.hxx | 2 + src/SMESH_I/SMESH_Gen_i_DumpPython.cxx | 69 ++++--- src/SMESH_I/SMESH_Group_i.cxx | 23 +++ src/SMESH_I/SMESH_Mesh_i.cxx | 249 +++++++++++++++++++------ 4 files changed, 260 insertions(+), 83 deletions(-) diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 97dd9b241..7c96b038c 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -288,6 +288,8 @@ public: void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString); + void RemoveLastFromPythonScript (int theStudyID); + static void AddToCurrentPyScript (const TCollection_AsciiString& theString); void SavePython (SALOMEDS::Study_ptr theStudy); diff --git a/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx b/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx index cd2c578fc..adfb83764 100644 --- a/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx +++ b/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx @@ -12,17 +12,17 @@ //function : DumpPython //purpose : //======================================================================= -Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, +Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy, + CORBA::Boolean isPublished, CORBA::Boolean& isValidScript) { SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy); if (CORBA::is_nil(aStudy)) - return new Engines::TMPFile(0); + return new Engines::TMPFile(0); SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType()); if (CORBA::is_nil(aSO)) - return new Engines::TMPFile(0); + return new Engines::TMPFile(0); // Map study entries to object names Resource_DataMapOfAsciiStringAsciiString aMap; @@ -33,12 +33,14 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy, SALOMEDS::SObject_var aValue = Itr->Value(); TCollection_AsciiString aName (aValue->GetName()); - int p, p2 = 1, e = aName.Length(); - while ((p = aName.FirstLocationNotInSet(s, p2, e))) { - aName.SetValue(p, '_'); - p2 = p; - } - aMap.Bind(TCollection_AsciiString(aValue->GetID()), aName); + if (aName.Length() > 0) { + int p, p2 = 1, e = aName.Length(); + while ((p = aName.FirstLocationNotInSet(s, p2, e))) { + aName.SetValue(p, '_'); + p2 = p; + } + aMap.Bind(TCollection_AsciiString(aValue->GetID()), aName); + } } // Get trace of restored study @@ -80,6 +82,19 @@ void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiStri myPythonScripts[theStudyID]->Append(theString); } +//============================================================================= +/*! + * RemoveLastFromPythonScript + */ +//============================================================================= +void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID) +{ + if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) { + int aLen = myPythonScripts[theStudyID]->Length(); + myPythonScripts[theStudyID]->Remove(aLen); + } +} + //======================================================================= //function : AddToCurrentPyScript //purpose : @@ -232,16 +247,6 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl aScript += "\n"; aScript += aNewLines; } -// if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) { -// aScript += "\n"; -// Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[theStudyID]; -// Standard_Integer istr, aLen = aPythonScript->Length(); -// for (istr = 1; istr <= aLen; istr++) { -// aScript += "\n\t"; -// aScript += aPythonScript->Value(istr); -// } -// aScript += "\n"; -// } // Find entries to be replaced by names Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript); @@ -251,9 +256,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl return aScript; // Replace entries by the names + TColStd_SequenceOfAsciiString seqRemoved; + Resource_DataMapOfAsciiStringAsciiString mapRemoved; Resource_DataMapOfAsciiStringAsciiString aNames; Standard_Integer objectCounter = 0, aStart = 1, aScriptLength = aScript.Length(); - TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("geomObj_"); + TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("smeshObj_"); for (Standard_Integer i = 1; i <= aLen; i += 2) { anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1); @@ -271,10 +278,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl theObjectNames(anEntry) = aName; } } else { + // ? Removed Object ? do { aName = aBaseName + TCollection_AsciiString(++objectCounter); } while (theObjectNames.IsBound(aName)); theObjectNames.Bind(anEntry, aName); + seqRemoved.Append(aName); + mapRemoved.Bind(anEntry, "1"); } theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects @@ -283,10 +293,19 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl aStart = aSeq->Value(i + 1) + 1; } - // add final part of the script + // add final part of aScript if (aSeq->Value(aLen) < aScriptLength) anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength); + // Remove removed objects + anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()"; + for (int ir = 1; ir <= seqRemoved.Length(); ir++) { + anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR("; + anUpdatedScript += seqRemoved.Value(ir); + anUpdatedScript += "))\n\tif SO is not None: aStudyBuilder.RemoveObjectWithChildren(SO)"; + } + anUpdatedScript += "\n"; + // Set object names anUpdatedScript += "\n\tisGUIMode = 1"; anUpdatedScript += "\n\tif isGUIMode:"; @@ -297,13 +316,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl Resource_DataMapOfAsciiStringAsciiString mapEntries; for (Standard_Integer i = 1; i <= aLen; i += 2) { anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1)); - if (theObjectNames.IsBound(anEntry) && !mapEntries.IsBound(anEntry)) { + if (theObjectNames.IsBound(anEntry) && + !mapEntries.IsBound(anEntry) && + !mapRemoved.IsBound(anEntry)) { aName = theObjectNames.Find(anEntry); mapEntries.Bind(anEntry, aName); anUpdatedScript += "\n\t\tsmeshgui.SetName(salome.ObjectToID("; anUpdatedScript += aName + "), \"" + aName + "\")"; - //anUpdatedScript += "\n\t\tsmeshgui.SetName(\""; - //anUpdatedScript += anEntry + "\", \"" + aName + "\")"; } } anUpdatedScript += "\n\n\t\tsalome.sg.updateObjBrowser(0)"; diff --git a/src/SMESH_I/SMESH_Group_i.cxx b/src/SMESH_I/SMESH_Group_i.cxx index 78ca52898..a262d795b 100644 --- a/src/SMESH_I/SMESH_Group_i.cxx +++ b/src/SMESH_I/SMESH_Group_i.cxx @@ -204,6 +204,13 @@ CORBA::Boolean SMESH_GroupBase_i::IsEmpty() void SMESH_Group_i::Clear() { + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, _this()) += ".Clear()"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Clear the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); if (aGroupDS) { aGroupDS->Clear(); @@ -235,6 +242,14 @@ CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID ) CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs ) { + // Update Python script + TCollection_AsciiString aStr ("nbAdd = "); + SMESH_Gen_i::AddObject(aStr, _this()) += ".Add("; + SMESH_Gen_i::AddArray(aStr, theIDs) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Add elements to the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); if (aGroupDS) { int nbAdd = 0; @@ -293,6 +308,14 @@ SMESH::long_array* SMESH_GroupBase_i::GetListOfID() CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs ) { + // Update Python script + TCollection_AsciiString aStr ("nbDel = "); + SMESH_Gen_i::AddObject(aStr, _this()) += ".Remove("; + SMESH_Gen_i::AddArray(aStr, theIDs) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Remove elements from the group SMESHDS_Group* aGroupDS = dynamic_cast( GetGroupDS() ); if (aGroupDS) { int nbDel = 0; diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index b78af329c..79ac885d2 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -337,21 +337,12 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubS if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status ); // Update Python script - SALOMEDS::SObject_var aMeshSO = SMESH_Gen_i::ObjectToSObject(_gen_i->GetCurrentStudy(), _this()); - SALOMEDS::SObject_var aHypoSO = SMESH_Gen_i::ObjectToSObject(_gen_i->GetCurrentStudy(), anHyp); - TCollection_AsciiString aStr ("status = "); - aStr += aMeshSO->GetID(); - aStr += ".AddHypothesis(salome.IDToObject(\""; - aStr += aSubShapeObject->GetStudyEntry(); - aStr += "\"), "; - aStr += aHypoSO->GetID(); - aStr += ")"; - - _gen_i->AddToPythonScript(_gen_i->GetCurrentStudy()->StudyId(), aStr); + SMESH_Gen_i::AddObject(aStr, _this()) += ".AddHypothesis("; + SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", "; + SMESH_Gen_i::AddObject(aStr, anHyp) += ")"; - aStr = "print \"AddHypothesis: \", status"; - _gen_i->AddToPythonScript(_gen_i->GetCurrentStudy()->StudyId(), aStr); + SMESH_Gen_i::AddToCurrentPyScript(aStr); return ConvertHypothesisStatus(status); } @@ -417,6 +408,14 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aS _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(), aSubShapeObject, anHyp ); + // Update Python script + TCollection_AsciiString aStr ("status = "); + SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveHypothesis("; + SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", "; + SMESH_Gen_i::AddObject(aStr, anHyp) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + return ConvertHypothesisStatus(status); } @@ -525,9 +524,21 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShap if ( subMesh->_is_nil() ) subMesh = createSubMesh( aSubShapeObject ); - if ( _gen_i->CanPublishInStudy( subMesh )) - _gen_i->PublishSubMesh (_gen_i->GetCurrentStudy(), aMesh, - subMesh, aSubShapeObject, theName ); + if ( _gen_i->CanPublishInStudy( subMesh )) { + SALOMEDS::SObject_var aSO = + _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh, + subMesh, aSubShapeObject, theName ); + + // Update Python script + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = "; + SMESH_Gen_i::AddObject(aStr, _this()) += ".GetSubMesh("; + SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", \""; + aStr += (char*)theName; + aStr += "\")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + } } catch(SALOME_Exception & S_ex) { THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); @@ -560,12 +571,49 @@ void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh ) aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() ); aStudy->NewBuilder()->RemoveObjectWithChildren( anSO ); + + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveSubMesh("; + aStr += anSO->GetID(); + aStr += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); } } removeSubMesh( theSubMesh, aSubShapeObject.in() ); } +//============================================================================= +/*! + * ElementTypeString + */ +//============================================================================= +inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType) +{ + TCollection_AsciiString aStr; + switch (theElemType) { + case SMESH::ALL: + aStr = "SMESH.ALL"; + break; + case SMESH::NODE: + aStr = "SMESH.NODE"; + break; + case SMESH::EDGE: + aStr = "SMESH.EDGE"; + break; + case SMESH::FACE: + aStr = "SMESH.FACE"; + break; + case SMESH::VOLUME: + aStr = "SMESH.VOLUME"; + break; + default: + break; + } + return aStr; +} //============================================================================= /*! @@ -581,8 +629,19 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType SMESH::SMESH_Group_var aNewGroup = SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName )); - _gen_i->PublishGroup( _gen_i->GetCurrentStudy(), _this(), - aNewGroup, GEOM::GEOM_Object::_nil(), theName); + if ( _gen_i->CanPublishInStudy( aNewGroup ) ) { + SALOMEDS::SObject_var aSO = + _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(), + aNewGroup, GEOM::GEOM_Object::_nil(), theName); + + // Update Python script + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = "; + SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroup("; + aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + } return aNewGroup._retn(); } @@ -593,9 +652,9 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType * */ //============================================================================= -SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM( SMESH::ElementType theElemType, - const char* theName, - GEOM::GEOM_Object_ptr theGeomObj) +SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType, + const char* theName, + GEOM::GEOM_Object_ptr theGeomObj) throw(SALOME::SALOME_Exception) { Unexpect aCatch(SALOME_SalomeException); @@ -605,13 +664,25 @@ SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM( SMESH::ElementTy if ( !aShape.IsNull() ) { aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow ( createGroup( theElemType, theName, aShape )); - if ( _gen_i->CanPublishInStudy( aNewGroup ) ) - _gen_i->PublishGroup( _gen_i->GetCurrentStudy(), _this(), - aNewGroup, theGeomObj, theName ); + if ( _gen_i->CanPublishInStudy( aNewGroup ) ) { + SALOMEDS::SObject_var aSO = + _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(), + aNewGroup, theGeomObj, theName); + + // Update Python script + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = "; + SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroupFromGEOM("; + aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\", "; + SMESH_Gen_i::AddObject(aStr, theGeomObj) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + } } return aNewGroup._retn(); } + //============================================================================= /*! * @@ -631,10 +702,20 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup ) SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); if ( !aStudy->_is_nil() ) { - // Remove group's SObject SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup ); - if ( !aGroupSO->_is_nil() ) + + if ( !aGroupSO->_is_nil() ) { + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroup("; + aStr += aGroupSO->GetID(); + aStr += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Remove group's SObject aStudy->NewBuilder()->RemoveObject( aGroupSO ); + } } // Remove the group from SMESH data structures @@ -659,13 +740,26 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup SMESH::long_array_var anIds = aGroup->GetListOfID(); SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor(); - + + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroupWithContents("; + SMESH_Gen_i::AddObject(aStr, theGroup) += ")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + + // Remove contents if ( aGroup->GetType() == SMESH::NODE ) aMeshEditor->RemoveNodes( anIds ); else aMeshEditor->RemoveElements( anIds ); - + + // Remove group RemoveGroup( theGroup ); + + // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup() + _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId()); + _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId()); } //============================================================================= @@ -681,13 +775,12 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr the { try { - SMESH::SMESH_Group_var aResGrp; - if ( theGroup1->_is_nil() || theGroup2->_is_nil() || theGroup1->GetType() != theGroup2->GetType() ) return SMESH::SMESH_Group::_nil(); - aResGrp = CreateGroup( theGroup1->GetType(), theName ); + // Create Union + SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName ); if ( aResGrp->_is_nil() ) return SMESH::SMESH_Group::_nil(); @@ -712,6 +805,21 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr the aResGrp->Add( aResIds ); + // Clear python lines, created by CreateGroup() and Add() + SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); + _gen_i->RemoveLastFromPythonScript(aStudy->StudyId()); + _gen_i->RemoveLastFromPythonScript(aStudy->StudyId()); + + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, aResGrp) += " = "; + SMESH_Gen_i::AddObject(aStr, _this()) += ".UnionGroups("; + SMESH_Gen_i::AddObject(aStr, theGroup1) += ", "; + SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \""; + aStr += TCollection_AsciiString((char*)theName) + "\")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + return aResGrp._retn(); } catch( ... ) @@ -731,21 +839,20 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr const char* theName ) throw (SALOME::SALOME_Exception) { - SMESH::SMESH_Group_var aResGrp; - if ( theGroup1->_is_nil() || theGroup2->_is_nil() || theGroup1->GetType() != theGroup2->GetType() ) - return aResGrp; - - aResGrp = CreateGroup( theGroup1->GetType(), theName ); + return SMESH::SMESH_Group::_nil(); + + // Create Intersection + SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName ); if ( aResGrp->_is_nil() ) return aResGrp; - + SMESH::long_array_var anIds1 = theGroup1->GetListOfID(); SMESH::long_array_var anIds2 = theGroup2->GetListOfID(); - + TColStd_MapOfInteger aMap1; - + for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ ) aMap1.Add( anIds1[ i1 ] ); @@ -754,15 +861,30 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ ) if ( aMap1.Contains( anIds2[ i2 ] ) ) aSeq.Append( anIds2[ i2 ] ); - + SMESH::long_array_var aResIds = new SMESH::long_array; aResIds->length( aSeq.Length() ); - + for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ ) aResIds[ resI ] = aSeq( resI + 1 ); - + aResGrp->Add( aResIds ); - + + // Clear python lines, created by CreateGroup() and Add() + SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); + _gen_i->RemoveLastFromPythonScript(aStudy->StudyId()); + _gen_i->RemoveLastFromPythonScript(aStudy->StudyId()); + + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, aResGrp) += " = "; + SMESH_Gen_i::AddObject(aStr, _this()) += ".IntersectGroups("; + SMESH_Gen_i::AddObject(aStr, theGroup1) += ", "; + SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \""; + aStr += TCollection_AsciiString((char*)theName) + "\")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + return aResGrp._retn(); } @@ -777,21 +899,20 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr const char* theName ) throw (SALOME::SALOME_Exception) { - SMESH::SMESH_Group_var aResGrp; - if ( theGroup1->_is_nil() || theGroup2->_is_nil() || theGroup1->GetType() != theGroup2->GetType() ) - return aResGrp; - - aResGrp = CreateGroup( theGroup1->GetType(), theName ); + return SMESH::SMESH_Group::_nil(); + + // Perform Cutting + SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName ); if ( aResGrp->_is_nil() ) return aResGrp; - + SMESH::long_array_var anIds1 = theGroup1->GetListOfID(); SMESH::long_array_var anIds2 = theGroup2->GetListOfID(); - + TColStd_MapOfInteger aMap2; - + for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ ) aMap2.Add( anIds2[ i2 ] ); @@ -806,9 +927,24 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ ) aResIds[ resI ] = aSeq( resI + 1 ); - + aResGrp->Add( aResIds ); - + + // Clear python lines, created by CreateGroup() and Add() + SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); + _gen_i->RemoveLastFromPythonScript(aStudy->StudyId()); + _gen_i->RemoveLastFromPythonScript(aStudy->StudyId()); + + // Update Python script + TCollection_AsciiString aStr; + SMESH_Gen_i::AddObject(aStr, aResGrp) += " = "; + SMESH_Gen_i::AddObject(aStr, _this()) += ".CutGroups("; + SMESH_Gen_i::AddObject(aStr, theGroup1) += ", "; + SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \""; + aStr += TCollection_AsciiString((char*)theName) + "\")"; + + SMESH_Gen_i::AddToCurrentPyScript(aStr); + return aResGrp._retn(); } @@ -1068,13 +1204,10 @@ void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl) SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor() { // Update Python script - SALOMEDS::SObject_var aSO = - SMESH_Gen_i::ObjectToSObject(_gen_i->GetCurrentStudy(), _this()); TCollection_AsciiString aStr ("mesh_editor = "); - aStr += aSO->GetID(); - aStr += ".GetMeshEditor()"; + SMESH_Gen_i::AddObject(aStr, _this()) += ".GetMeshEditor()"; - _gen_i->AddToPythonScript(_gen_i->GetCurrentStudy()->StudyId(), aStr); + SMESH_Gen_i::AddToCurrentPyScript(aStr); // Create MeshEditor SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl ); -- 2.39.2