//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;
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
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 :
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);
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);
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
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:";
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)";
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);
}
_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);
}
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);
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;
+}
//=============================================================================
/*!
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();
}
*
*/
//=============================================================================
-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);
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();
}
+
//=============================================================================
/*!
*
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
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());
}
//=============================================================================
{
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();
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( ... )
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 ] );
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();
}
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 ] );
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();
}
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 );