Dump Python: dump groups operations; correct processing of removed objects.

This commit is contained in:
jfa 2005-03-28 10:11:37 +00:00
parent 8d1da03971
commit 304f30c5ca
4 changed files with 260 additions and 83 deletions

View File

@ -288,6 +288,8 @@ public:
void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString); void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString);
void RemoveLastFromPythonScript (int theStudyID);
static void AddToCurrentPyScript (const TCollection_AsciiString& theString); static void AddToCurrentPyScript (const TCollection_AsciiString& theString);
void SavePython (SALOMEDS::Study_ptr theStudy); void SavePython (SALOMEDS::Study_ptr theStudy);

View File

@ -33,12 +33,14 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
SALOMEDS::SObject_var aValue = Itr->Value(); SALOMEDS::SObject_var aValue = Itr->Value();
TCollection_AsciiString aName (aValue->GetName()); TCollection_AsciiString aName (aValue->GetName());
int p, p2 = 1, e = aName.Length(); if (aName.Length() > 0) {
while ((p = aName.FirstLocationNotInSet(s, p2, e))) { int p, p2 = 1, e = aName.Length();
aName.SetValue(p, '_'); while ((p = aName.FirstLocationNotInSet(s, p2, e))) {
p2 = p; aName.SetValue(p, '_');
p2 = p;
}
aMap.Bind(TCollection_AsciiString(aValue->GetID()), aName);
} }
aMap.Bind(TCollection_AsciiString(aValue->GetID()), aName);
} }
// Get trace of restored study // Get trace of restored study
@ -80,6 +82,19 @@ void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiStri
myPythonScripts[theStudyID]->Append(theString); 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 //function : AddToCurrentPyScript
//purpose : //purpose :
@ -232,16 +247,6 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
aScript += "\n"; aScript += "\n";
aScript += aNewLines; 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 // Find entries to be replaced by names
Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript); Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript);
@ -251,9 +256,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
return aScript; return aScript;
// Replace entries by the names // Replace entries by the names
TColStd_SequenceOfAsciiString seqRemoved;
Resource_DataMapOfAsciiStringAsciiString mapRemoved;
Resource_DataMapOfAsciiStringAsciiString aNames; Resource_DataMapOfAsciiStringAsciiString aNames;
Standard_Integer objectCounter = 0, aStart = 1, aScriptLength = aScript.Length(); 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) { for (Standard_Integer i = 1; i <= aLen; i += 2) {
anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1); anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1);
@ -271,10 +278,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
theObjectNames(anEntry) = aName; theObjectNames(anEntry) = aName;
} }
} else { } else {
// ? Removed Object ?
do { do {
aName = aBaseName + TCollection_AsciiString(++objectCounter); aName = aBaseName + TCollection_AsciiString(++objectCounter);
} while (theObjectNames.IsBound(aName)); } while (theObjectNames.IsBound(aName));
theObjectNames.Bind(anEntry, aName); theObjectNames.Bind(anEntry, aName);
seqRemoved.Append(aName);
mapRemoved.Bind(anEntry, "1");
} }
theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects 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; aStart = aSeq->Value(i + 1) + 1;
} }
// add final part of the script // add final part of aScript
if (aSeq->Value(aLen) < aScriptLength) if (aSeq->Value(aLen) < aScriptLength)
anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, 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 // Set object names
anUpdatedScript += "\n\tisGUIMode = 1"; anUpdatedScript += "\n\tisGUIMode = 1";
anUpdatedScript += "\n\tif isGUIMode:"; anUpdatedScript += "\n\tif isGUIMode:";
@ -297,13 +316,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
Resource_DataMapOfAsciiStringAsciiString mapEntries; Resource_DataMapOfAsciiStringAsciiString mapEntries;
for (Standard_Integer i = 1; i <= aLen; i += 2) { for (Standard_Integer i = 1; i <= aLen; i += 2) {
anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1)); 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); aName = theObjectNames.Find(anEntry);
mapEntries.Bind(anEntry, aName); mapEntries.Bind(anEntry, aName);
anUpdatedScript += "\n\t\tsmeshgui.SetName(salome.ObjectToID("; anUpdatedScript += "\n\t\tsmeshgui.SetName(salome.ObjectToID(";
anUpdatedScript += aName + "), \"" + aName + "\")"; anUpdatedScript += aName + "), \"" + aName + "\")";
//anUpdatedScript += "\n\t\tsmeshgui.SetName(\"";
//anUpdatedScript += anEntry + "\", \"" + aName + "\")";
} }
} }
anUpdatedScript += "\n\n\t\tsalome.sg.updateObjBrowser(0)"; anUpdatedScript += "\n\n\t\tsalome.sg.updateObjBrowser(0)";

View File

@ -204,6 +204,13 @@ CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
void SMESH_Group_i::Clear() 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<SMESHDS_Group*>( GetGroupDS() ); SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
if (aGroupDS) { if (aGroupDS) {
aGroupDS->Clear(); 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 ) 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<SMESHDS_Group*>( GetGroupDS() ); SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
if (aGroupDS) { if (aGroupDS) {
int nbAdd = 0; 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 ) 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<SMESHDS_Group*>( GetGroupDS() ); SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
if (aGroupDS) { if (aGroupDS) {
int nbDel = 0; int nbDel = 0;

View File

@ -337,21 +337,12 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubS
if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status ); if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
// Update Python script // 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 = "); TCollection_AsciiString aStr ("status = ");
aStr += aMeshSO->GetID(); SMESH_Gen_i::AddObject(aStr, _this()) += ".AddHypothesis(";
aStr += ".AddHypothesis(salome.IDToObject(\""; SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
aStr += aSubShapeObject->GetStudyEntry(); SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
aStr += "\"), ";
aStr += aHypoSO->GetID();
aStr += ")";
_gen_i->AddToPythonScript(_gen_i->GetCurrentStudy()->StudyId(), aStr); SMESH_Gen_i::AddToCurrentPyScript(aStr);
aStr = "print \"AddHypothesis: \", status";
_gen_i->AddToPythonScript(_gen_i->GetCurrentStudy()->StudyId(), aStr);
return ConvertHypothesisStatus(status); 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(), _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
aSubShapeObject, anHyp ); 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); return ConvertHypothesisStatus(status);
} }
@ -525,9 +524,21 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShap
if ( subMesh->_is_nil() ) if ( subMesh->_is_nil() )
subMesh = createSubMesh( aSubShapeObject ); subMesh = createSubMesh( aSubShapeObject );
if ( _gen_i->CanPublishInStudy( subMesh )) if ( _gen_i->CanPublishInStudy( subMesh )) {
_gen_i->PublishSubMesh (_gen_i->GetCurrentStudy(), aMesh, SALOMEDS::SObject_var aSO =
subMesh, aSubShapeObject, theName ); _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) { catch(SALOME_Exception & S_ex) {
THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); 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() ); aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
aStudy->NewBuilder()->RemoveObjectWithChildren( anSO ); 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() ); 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_var aNewGroup =
SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName )); SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
_gen_i->PublishGroup( _gen_i->GetCurrentStudy(), _this(), if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
aNewGroup, GEOM::GEOM_Object::_nil(), theName); 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(); 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, SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
const char* theName, const char* theName,
GEOM::GEOM_Object_ptr theGeomObj) GEOM::GEOM_Object_ptr theGeomObj)
throw(SALOME::SALOME_Exception) throw(SALOME::SALOME_Exception)
{ {
Unexpect aCatch(SALOME_SalomeException); Unexpect aCatch(SALOME_SalomeException);
@ -605,13 +664,25 @@ SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM( SMESH::ElementTy
if ( !aShape.IsNull() ) { if ( !aShape.IsNull() ) {
aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
( createGroup( theElemType, theName, aShape )); ( createGroup( theElemType, theName, aShape ));
if ( _gen_i->CanPublishInStudy( aNewGroup ) ) if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
_gen_i->PublishGroup( _gen_i->GetCurrentStudy(), _this(), SALOMEDS::SObject_var aSO =
aNewGroup, theGeomObj, theName ); _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(); return aNewGroup._retn();
} }
//============================================================================= //=============================================================================
/*! /*!
* *
@ -631,10 +702,20 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
if ( !aStudy->_is_nil() ) { if ( !aStudy->_is_nil() ) {
// Remove group's SObject
SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup ); 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 ); aStudy->NewBuilder()->RemoveObject( aGroupSO );
}
} }
// Remove the group from SMESH data structures // Remove the group from SMESH data structures
@ -660,12 +741,25 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup
SMESH::long_array_var anIds = aGroup->GetListOfID(); SMESH::long_array_var anIds = aGroup->GetListOfID();
SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor(); 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 ) if ( aGroup->GetType() == SMESH::NODE )
aMeshEditor->RemoveNodes( anIds ); aMeshEditor->RemoveNodes( anIds );
else else
aMeshEditor->RemoveElements( anIds ); aMeshEditor->RemoveElements( anIds );
// Remove group
RemoveGroup( theGroup ); 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 try
{ {
SMESH::SMESH_Group_var aResGrp;
if ( theGroup1->_is_nil() || theGroup2->_is_nil() || if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
theGroup1->GetType() != theGroup2->GetType() ) theGroup1->GetType() != theGroup2->GetType() )
return SMESH::SMESH_Group::_nil(); 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() ) if ( aResGrp->_is_nil() )
return SMESH::SMESH_Group::_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 ); 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(); return aResGrp._retn();
} }
catch( ... ) catch( ... )
@ -731,13 +839,12 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr
const char* theName ) const char* theName )
throw (SALOME::SALOME_Exception) throw (SALOME::SALOME_Exception)
{ {
SMESH::SMESH_Group_var aResGrp;
if ( theGroup1->_is_nil() || theGroup2->_is_nil() || if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
theGroup1->GetType() != theGroup2->GetType() ) theGroup1->GetType() != theGroup2->GetType() )
return aResGrp; return SMESH::SMESH_Group::_nil();
aResGrp = CreateGroup( theGroup1->GetType(), theName ); // Create Intersection
SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
if ( aResGrp->_is_nil() ) if ( aResGrp->_is_nil() )
return aResGrp; return aResGrp;
@ -763,6 +870,21 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr
aResGrp->Add( aResIds ); 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(); return aResGrp._retn();
} }
@ -777,13 +899,12 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr
const char* theName ) const char* theName )
throw (SALOME::SALOME_Exception) throw (SALOME::SALOME_Exception)
{ {
SMESH::SMESH_Group_var aResGrp;
if ( theGroup1->_is_nil() || theGroup2->_is_nil() || if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
theGroup1->GetType() != theGroup2->GetType() ) theGroup1->GetType() != theGroup2->GetType() )
return aResGrp; return SMESH::SMESH_Group::_nil();
aResGrp = CreateGroup( theGroup1->GetType(), theName ); // Perform Cutting
SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
if ( aResGrp->_is_nil() ) if ( aResGrp->_is_nil() )
return aResGrp; return aResGrp;
@ -809,6 +930,21 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr
aResGrp->Add( aResIds ); 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(); return aResGrp._retn();
} }
@ -1068,13 +1204,10 @@ void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor() SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
{ {
// Update Python script // Update Python script
SALOMEDS::SObject_var aSO =
SMESH_Gen_i::ObjectToSObject(_gen_i->GetCurrentStudy(), _this());
TCollection_AsciiString aStr ("mesh_editor = "); TCollection_AsciiString aStr ("mesh_editor = ");
aStr += aSO->GetID(); SMESH_Gen_i::AddObject(aStr, _this()) += ".GetMeshEditor()";
aStr += ".GetMeshEditor()";
_gen_i->AddToPythonScript(_gen_i->GetCurrentStudy()->StudyId(), aStr); SMESH_Gen_i::AddToCurrentPyScript(aStr);
// Create MeshEditor // Create MeshEditor
SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl ); SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );