Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.cxx
index dfb378f245374942c3cbcde707e2a473220d9af9..767c325827692f09fccd4edfb3a7491a78a45a6c 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
@@ -247,7 +247,8 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand
 
   // SMESH_Mesh method?
   map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
-  if ( id_mesh != myMeshes.end() ) {
+  if ( id_mesh != myMeshes.end() )
+  {
     // check for mesh editor object
     if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
       _pyID editorID = aCommand->GetResultValue();
@@ -268,7 +269,8 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand
 
   // SMESH_MeshEditor method?
   map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
-  if ( id_editor != myMeshEditors.end() ) {
+  if ( id_editor != myMeshEditors.end() )
+  {
     id_editor->second->Process( aCommand );
     TCollection_AsciiString processedCommand = aCommand->GetString();
     // some commands of SMESH_MeshEditor create meshes
@@ -277,6 +279,15 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand
       aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
       myMeshes.insert( make_pair( mesh->GetID(), mesh ));
     }
+    if ( aCommand->GetMethod() == "MakeBoundaryMesh") {
+      _pyID meshID = aCommand->GetResultValue(0);
+      if ( !myMeshes.count( meshID ) )
+      {
+        Handle(_pyMesh) mesh = new _pyMesh( aCommand, meshID );
+        aCommand->GetString() = processedCommand; // discard changes made by _pyMesh
+        myMeshes.insert( make_pair( meshID, mesh ));
+      }
+    }
     return aCommand;
   }
   // SMESH_Hypothesis method?
@@ -352,7 +363,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
     return;
   }
-  if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL")
+  if ( method == "CreateMeshesFromUNV" || method == "CreateMeshesFromSTL" || method == "CopyMesh" )
   {
     Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue() );
     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
@@ -709,58 +720,58 @@ _pyID _pyGen::GenerateNewID( const _pyID& theID )
  */
 //================================================================================
 
-static bool sameGroupType( const _pyID&                   grpID,
-                           const TCollection_AsciiString& theType)
-{
-  // define group type as smesh.Mesh.Group() does
-  int type = -1;
-  SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
-  SALOMEDS::SObject_var aSObj = study->FindObjectID( grpID.ToCString() );
-  if ( !aSObj->_is_nil() ) {
-    GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
-    if ( !aGeomObj->_is_nil() ) {
-      switch ( aGeomObj->GetShapeType() ) {
-      case GEOM::VERTEX: type = SMESH::NODE; break;
-      case GEOM::EDGE:   type = SMESH::EDGE; break;
-      case GEOM::FACE:   type = SMESH::FACE; break;
-      case GEOM::SOLID:
-      case GEOM::SHELL:  type = SMESH::VOLUME; break;
-      case GEOM::COMPOUND: {
-        GEOM::GEOM_Gen_ptr aGeomGen = SMESH_Gen_i::GetSMESHGen()->GetGeomEngine();
-        if ( !aGeomGen->_is_nil() ) {
-          GEOM::GEOM_IGroupOperations_var aGrpOp =
-            aGeomGen->GetIGroupOperations( study->StudyId() );
-          if ( !aGrpOp->_is_nil() ) {
-            switch ( aGrpOp->GetType( aGeomObj )) {
-            case TopAbs_VERTEX: type = SMESH::NODE; break;
-            case TopAbs_EDGE:   type = SMESH::EDGE; break;
-            case TopAbs_FACE:   type = SMESH::FACE; break;
-            case TopAbs_SOLID:  type = SMESH::VOLUME; break;
-            default:;
-            }
-          }
-        }
-      }
-      default:;
-      }
-    }
-  }
-  if ( type < 0 ) {
-    MESSAGE("Type of the group " << grpID << " not found");
-    return false;
-  }
-  if ( theType.IsIntegerValue() )
-    return type == theType.IntegerValue();
-
-  switch ( type ) {
-  case SMESH::NODE:   return theType.Location( "NODE", 1, theType.Length() );
-  case SMESH::EDGE:   return theType.Location( "EDGE", 1, theType.Length() );
-  case SMESH::FACE:   return theType.Location( "FACE", 1, theType.Length() );
-  case SMESH::VOLUME: return theType.Location( "VOLUME", 1, theType.Length() );
-  default:;
-  }
-  return false;
-}
+// static bool sameGroupType( const _pyID&                   grpID,
+//                            const TCollection_AsciiString& theType)
+// {
+//   // define group type as smesh.Mesh.Group() does
+//   int type = -1;
+//   SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
+//   SALOMEDS::SObject_var aSObj = study->FindObjectID( grpID.ToCString() );
+//   if ( !aSObj->_is_nil() ) {
+//     GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
+//     if ( !aGeomObj->_is_nil() ) {
+//       switch ( aGeomObj->GetShapeType() ) {
+//       case GEOM::VERTEX: type = SMESH::NODE; break;
+//       case GEOM::EDGE:   type = SMESH::EDGE; break;
+//       case GEOM::FACE:   type = SMESH::FACE; break;
+//       case GEOM::SOLID:
+//       case GEOM::SHELL:  type = SMESH::VOLUME; break;
+//       case GEOM::COMPOUND: {
+//         GEOM::GEOM_Gen_ptr aGeomGen = SMESH_Gen_i::GetSMESHGen()->GetGeomEngine();
+//         if ( !aGeomGen->_is_nil() ) {
+//           GEOM::GEOM_IGroupOperations_var aGrpOp =
+//             aGeomGen->GetIGroupOperations( study->StudyId() );
+//           if ( !aGrpOp->_is_nil() ) {
+//             switch ( aGrpOp->GetType( aGeomObj )) {
+//             case TopAbs_VERTEX: type = SMESH::NODE; break;
+//             case TopAbs_EDGE:   type = SMESH::EDGE; break;
+//             case TopAbs_FACE:   type = SMESH::FACE; break;
+//             case TopAbs_SOLID:  type = SMESH::VOLUME; break;
+//             default:;
+//             }
+//           }
+//         }
+//       }
+//       default:;
+//       }
+//     }
+//   }
+//   if ( type < 0 ) {
+//     MESSAGE("Type of the group " << grpID << " not found");
+//     return false;
+//   }
+//   if ( theType.IsIntegerValue() )
+//     return type == theType.IntegerValue();
+
+//   switch ( type ) {
+//   case SMESH::NODE:   return theType.Location( "NODE", 1, theType.Length() );
+//   case SMESH::EDGE:   return theType.Location( "EDGE", 1, theType.Length() );
+//   case SMESH::FACE:   return theType.Location( "FACE", 1, theType.Length() );
+//   case SMESH::VOLUME: return theType.Location( "VOLUME", 1, theType.Length() );
+//   default:;
+//   }
+//   return false;
+// }
 
 //================================================================================
 /*!
@@ -845,12 +856,14 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
   // ----------------------------------------------------------------------
   else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
     _pyID grp = theCommand->GetArg( 3 );
-    if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
-      theCommand->SetMethod( "Group" );
-      theCommand->RemoveArgs();
-      theCommand->SetArg( 1, grp );
-    }
-    else {
+    // VSR 24/12/2010. PAL21106: always use GroupOnGeom() function on dump
+    // next if(){...} section is commented
+    //if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
+    //  theCommand->SetMethod( "Group" );
+    //  theCommand->RemoveArgs();
+    //  theCommand->SetArg( 1, grp );
+    //}
+    //else {
       _pyID type = theCommand->GetArg( 1 );
       _pyID name = theCommand->GetArg( 2 );
       theCommand->SetMethod( "GroupOnGeom" );
@@ -858,7 +871,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
       theCommand->SetArg( 1, grp );
       theCommand->SetArg( 2, name );
       theCommand->SetArg( 3, type );
-    }
+    //}
   }
   // ----------------------------------------------------------------------
   else if ( method == "ExportToMED" ||   // ExportToMED() --> ExportMED()
@@ -1118,14 +1131,15 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
       "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
       "RotationSweep","RotationSweepObject","RotationSweepObject1D","RotationSweepObject2D",
       "ExtrusionSweep","AdvancedExtrusion","ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D",
-      "ExtrusionAlongPath","ExtrusionAlongPathObject","ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D",
+      "ExtrusionAlongPath","ExtrusionAlongPathObject","ExtrusionAlongPathX",
+      "ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D",
       "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
       "FindCoincidentNodes",/*"FindCoincidentNodesOnPart",*/"MergeNodes","FindEqualElements",
       "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
       "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
       "GetLastCreatedElems",
       "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
-      "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh"
+      "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh","MakeBoundaryMesh"
       ,"" }; // <- mark of the end
     sameMethods.Insert( names );
   }
@@ -1146,7 +1160,7 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
   bool isPyMeshMethod = sameMethods.Contains( method );
   if ( !isPyMeshMethod )
   {
-    //Replace SMESH_MeshEditor "MakeGroups" functions on the Mesh 
+    //Replace SMESH_MeshEditor "MakeGroups" functions by the Mesh 
     //functions with the flag "theMakeGroups = True" like:
     //SMESH_MeshEditor.CmdMakeGroups => Mesh.Cmd(...,True)
     int pos = method.Search("MakeGroups");
@@ -1166,6 +1180,13 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
     }
   }
 
+  // set "ExtrusionAlongPathX()" instead of "ExtrusionAlongPathObjX()"
+  if ( !isPyMeshMethod && method == "ExtrusionAlongPathObjX")
+  {
+    isPyMeshMethod=true;
+    theCommand->SetMethod("ExtrusionAlongPathX");
+  }
+
   // set "FindCoincidentNodesOnPart()" instead of "FindCoincidentNodesOnPartBut()"
   if ( !isPyMeshMethod && method == "FindCoincidentNodesOnPartBut")
   {
@@ -1173,12 +1194,31 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
     theCommand->SetMethod("FindCoincidentNodesOnPart");
   }
   // DoubleNodeElemGroupNew() -> DoubleNodeElemGroup()
-  if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" || method == "DoubleNodeGroupNew"))
+  // DoubleNodeGroupNew() -> DoubleNodeGroup()
+  // DoubleNodeGroupsNew() -> DoubleNodeGroups()
+  // DoubleNodeElemGroupsNew() -> DoubleNodeElemGroups()
+  if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew"  ||
+                            method == "DoubleNodeElemGroupsNew" ||
+                            method == "DoubleNodeGroupNew"      ||
+                            method == "DoubleNodeGroupsNew"))
   {
     isPyMeshMethod=true;
     theCommand->SetMethod( method.SubString( 1, method.Length()-3));
     theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
   }
+  // ConvertToQuadraticObject(bool,obj) -> ConvertToQuadratic(bool,obj)
+  // ConvertFromQuadraticObject(obj) -> ConvertFromQuadratic(obj)
+  if ( !isPyMeshMethod && ( method == "ConvertToQuadraticObject" ||
+                            method == "ConvertFromQuadraticObject" ))
+  {
+    isPyMeshMethod=true;
+    theCommand->SetMethod( method.SubString( 1, method.Length()-6));
+    // prevent moving creation of the converted sub-mesh to the end of the script
+    bool isFromQua = ( method.Value( 8 ) == 'F' );
+    Handle(_pySubMesh) sm = theGen->FindSubMesh( theCommand->GetArg( isFromQua ? 1 : 2 ));
+    if ( !sm.IsNull() )
+      sm->Process( theCommand );
+  }
 
   // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
   // so let _pyMesh care of it (TMP?)
@@ -2485,7 +2525,7 @@ void _pySubMesh::Process( const Handle(_pyCommand)& theCommand )
 
 //================================================================================
 /*!
- * \brief Clear creatin command if no commands invoked
+ * \brief Clear creation command if no commands invoked
  */
 //================================================================================