Salome HOME
PAL15881 New NETGEN capability: is it possible to do only a 2D mesh ?
authoreap <eap@opencascade.com>
Fri, 20 Jul 2007 11:13:12 +0000 (11:13 +0000)
committereap <eap@opencascade.com>
Fri, 20 Jul 2007 11:13:12 +0000 (11:13 +0000)
      changes reflection modifications in smesh.py

src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_2smeshpy.hxx

index e2e60cf4ea8d867b993f95eda28a33b5b4579b44..be6628fafffd89a21bd8e6c99d1c1787ab00c8d1 100644 (file)
@@ -41,6 +41,7 @@ IMPLEMENT_STANDARD_HANDLE (_pyObject          ,Standard_Transient);
 IMPLEMENT_STANDARD_HANDLE (_pyCommand         ,Standard_Transient);
 IMPLEMENT_STANDARD_HANDLE (_pyGen             ,_pyObject);
 IMPLEMENT_STANDARD_HANDLE (_pyMesh            ,_pyObject);
+IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor      ,_pyObject);
 IMPLEMENT_STANDARD_HANDLE (_pyHypothesis      ,_pyObject);
 IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm       ,_pyHypothesis);
 IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis);
@@ -50,6 +51,7 @@ IMPLEMENT_STANDARD_RTTIEXT(_pyObject          ,Standard_Transient);
 IMPLEMENT_STANDARD_RTTIEXT(_pyCommand         ,Standard_Transient);
 IMPLEMENT_STANDARD_RTTIEXT(_pyGen             ,_pyObject);
 IMPLEMENT_STANDARD_RTTIEXT(_pyMesh            ,_pyObject);
+IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor      ,_pyObject);
 IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis      ,_pyObject);
 IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm       ,_pyHypothesis);
 IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis);
@@ -74,11 +76,39 @@ static TCollection_AsciiString theEmptyString;
 #undef DUMP_CONVERSION
 #endif
 
+namespace {
+
+  //================================================================================
+  /*!
+   * \brief Set of TCollection_AsciiString initialized by C array of C strings
+   */
+  //================================================================================
+
+  struct TStringSet: public set<TCollection_AsciiString>
+  {
+    /*!
+     * \brief Filling. The last string must be ""
+     */
+    void Insert(const char* names[]) {
+      for ( int i = 0; names[i][0] ; ++i )
+        insert( (char*) names[i] );
+    }
+    /*!
+     * \brief Check if a string is in
+     */
+    bool Contains(const TCollection_AsciiString& name ) {
+      return find( name ) != end();
+    }
+  };
+}
+
 //================================================================================
 /*!
  * \brief Convert python script using commands of smesh.py
   * \param theScript - Input script
   * \retval TCollection_AsciiString - Convertion result
+  *
+  * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
  */
 //================================================================================
 
@@ -147,6 +177,17 @@ _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod
   GetCreationCmd()->GetString() += "=";
 }
 
+//================================================================================
+/*!
+ * \brief name of SMESH_Gen in smesh.py
+ */
+//================================================================================
+
+const char* _pyGen::AccessorMethod() const
+{
+  return SMESH_2smeshpy::GenName();
+}
+
 //================================================================================
 /*!
  * \brief Convert a command using a specific converter
@@ -177,9 +218,21 @@ 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 ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
+      _pyID editorID = aCommand->GetResultValue();
+      Handle(_pyMeshEditor) editor = new _pyMeshEditor( aCommand );
+      myMeshEditors.insert( make_pair( editorID, editor ));
+      return aCommand;
+    }
     id_mesh->second->Process( aCommand );
     return aCommand;
   }
+  // SMESH_MeshEditor method?
+  map< _pyID, Handle(_pyMeshEditor) >::iterator id_editor = myMeshEditors.find( objID );
+  if ( id_editor != myMeshEditors.end() ) {
+    id_editor->second->Process( aCommand );
+    return aCommand;
+  }
   // SMESH_Hypothesis method?
   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
   for ( ; hyp != myHypos.end(); ++hyp )
@@ -230,6 +283,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
   // CreateHypothesis( theHypType, theLibName )
   // Compute( mesh, geom )
 
+  // mesh creation
   if ( theCommand->GetMethod() == "CreateMesh" ||
        theCommand->GetMethod() == "CreateEmptyMesh" )
   {
@@ -267,14 +321,29 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
     myHasPattern = true;
   }
 
-  // smeshgen.Method() --> smesh.smesh.Method()
-  theCommand->SetObject( SMESH_2smeshpy::GenName() );
-
   // Concatenate( [mesh1, ...], ... )
   if ( theCommand->GetMethod() == "Concatenate" )
   {
     AddMeshAccessorMethod( theCommand );
   }
+
+  // Replace name of SMESH_Gen
+
+  // names of SMESH_Gen methods fully equal to methods defined in smesh.py
+  static TStringSet smeshpyMethods;
+  if ( smeshpyMethods.empty() ) {
+    const char * names[] =
+      { "SetEmbeddedMode","IsEmbeddedMode","SetCurrentStudy","GetCurrentStudy",
+        "GetPattern","GetSubShapesId",
+        "" }; // <- mark of array end
+    smeshpyMethods.Insert( names );
+  }
+  if ( smeshpyMethods.Contains( theCommand->GetMethod() ))
+    // smeshgen.Method() --> smesh.Method()
+    theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
+  else
+    // smeshgen.Method() --> smesh.smesh.Method()
+    theCommand->SetObject( SMESH_2smeshpy::GenName() );
 }
 
 //================================================================================
@@ -367,13 +436,13 @@ Handle(_pyHypothesis) _pyGen::FindHyp( const _pyID& theHypID )
 //================================================================================
 
 Handle(_pyHypothesis) _pyGen::FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
-                                      const TCollection_AsciiString& theAlgoType )
+                                        const Handle(_pyHypothesis)& theHypothesis )
 {
   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
   for ( ; hyp != myHypos.end(); ++hyp )
     if ( !hyp->IsNull() &&
          (*hyp)->IsAlgo() &&
-         (*hyp)->GetType() == theAlgoType &&
+         theHypothesis->CanBeCreatedBy( (*hyp)->GetAlgoType() ) &&
          (*hyp)->GetGeom() == theGeom &&
          (*hyp)->GetMesh() == theMesh )
       return *hyp;
@@ -530,7 +599,8 @@ _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd):
 
 void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
 {
-  // smesh.py wraps the following methods:
+  // some methods of SMESH_Mesh interface needs special conversion
+  // to methods of Mesh python class
   //
   // 1. GetSubMesh(geom, name) + AddHypothesis(geom, algo)
   //     --> in Mesh_Algorithm.Create(mesh, geom, hypo, so)
@@ -538,21 +608,16 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
   //     --> in Mesh_Algorithm.Hypothesis(hyp, args, so)
   // 3. CreateGroupFromGEOM(type, name, grp)
   //     --> in Mesh.Group(grp, name="")
-  // 4. ExportToMED(f, opt, version)
-  //     --> in Mesh.ExportToMED( f, version, opt=0 )
-  // 5. ExportMED(f, opt)
-  //     --> in Mesh.ExportMED( f,opt=0 )
-  // 6. ExportDAT(f)
-  //     --> in Mesh.ExportDAT( f )
-  // 7. ExportUNV(f)
-  //     --> in Mesh.ExportUNV(f)
-  // 8. ExportSTL(f, ascii)
-  //     --> in Mesh.ExportSTL(f, ascii=1)
+  // 4. ExportToMED(f, auto_groups, version)
+  //     --> in Mesh.ExportMED( f, auto_groups, version )
+  // 5. etc
 
   const TCollection_AsciiString method = theCommand->GetMethod();
+  // ----------------------------------------------------------------------
   if ( method == "GetSubMesh" ) {
     mySubmeshes.push_back( theCommand );
   }
+  // ----------------------------------------------------------------------
   else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO )
     myAddHypCmds.push_back( theCommand );
     // set mesh to hypo
@@ -564,6 +629,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
         hyp->SetMesh( this->GetID() );
     }
   }
+  // ----------------------------------------------------------------------
   else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
     _pyID grp = theCommand->GetArg( 3 );
     if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
@@ -575,16 +641,18 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
       AddMeshAccess( theCommand );
     }
   }
-  else if ( method == "ExportToMED" ) {//(f, opt, version)
-    // --> (f, version, opt)
-    _pyID opt = theCommand->GetArg( 2 );
-    _pyID ver = theCommand->GetArg( 3 );
-    theCommand->SetArg( 2, ver );
-    theCommand->SetArg( 3, opt );
+  // ----------------------------------------------------------------------
+  else if ( method == "ExportToMED" ) { // ExportToMED() --> ExportMED()
+    theCommand->SetMethod( "ExportMED" );
+  }
+  // ----------------------------------------------------------------------
+  else if ( method == "CreateGroup" ) { // CreateGroup() --> CreateEmptyGroup()
+    theCommand->SetMethod( "CreateEmptyGroup" );
   }
+  // ----------------------------------------------------------------------
   else if ( method == "RemoveHypothesis" ) // (geom, hyp)
   {
-    const _pyID & hypID = theCommand->GetArg( 2 );
+    _pyID hypID = theCommand->GetArg( 2 );
 
     // check if this mesh still has corresponding addition command
     bool hasAddCmd = false;
@@ -604,62 +672,55 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
     }
     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
     if ( ! hasAddCmd ) { // hypo addition already wrapped
-      // access to wrapped mesh
-      AddMeshAccess( theCommand );
-      // access to wrapped algo
-      if ( !hyp.IsNull() && hyp->IsAlgo() && hyp->IsWrapped() )
-        theCommand->SetArg( 2, theCommand->GetArg( 2 ) + ".GetAlgorithm()" );
+      // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
+      _pyID geom = theCommand->GetArg( 1 );
+      theCommand->RemoveArgs();
+      theCommand->SetArg( 1, hypID );
+      if ( geom != GetGeom() )
+        theCommand->SetArg( 2, geom );
     }
     // remove hyp from myHypos
     myHypos.remove( hyp );
   }
-
-  // leave only one "  mesh_editor_<nb> = mesh.GetMeshEditor()"
-  else if ( theCommand->GetMethod() == "GetMeshEditor")
-  {
-    if ( myHasEditor )
-      theCommand->Clear();
-    else
-      AddMeshAccess( theCommand );
-    myHasEditor = true;
-  }
-
-  // apply theCommand to the mesh wrapped by smeshpy mesh
+  // add accessor method if necessary
   else
   {
-    AddMeshAccess( theCommand );
+    if ( NeedMeshAccess( theCommand ))
+      // apply theCommand to the mesh wrapped by smeshpy mesh
+      AddMeshAccess( theCommand );
   }
 }
 
-namespace {
-
-  //================================================================================
-  /*!
-   * \brief add addition result treatement command
-    * \param addCmd - hypothesis addition command
-   */
-  //================================================================================
+//================================================================================
+/*!
+ * \brief Return True if addition of accesor method is needed
+ */
+//================================================================================
 
-  void addErrorTreatmentCmd( Handle(_pyCommand) & addCmd,
-                             const bool           isAlgo)
-  {
-    return; // TO DEBUD - TreatHypoStatus() is not placed right after addCmd
-    // addCmd: status = mesh.AddHypothesis( geom, hypo )
-    // treatement command:
-    //    def TreatHypoStatus(status, hypName, geomName, isAlgo):
-    TCollection_AsciiString status = addCmd->GetResultValue();
-    if ( !status.IsEmpty() ) {
-      const _pyID& geomID = addCmd->GetArg( 1 );
-      const _pyID& hypoID = addCmd->GetArg( 2 );
-      TCollection_AsciiString cmdStr = addCmd->GetIndentation() +
-        SMESH_2smeshpy::SmeshpyName() + ".TreatHypoStatus( " + status + ", " +
-        SMESH_2smeshpy::SmeshpyName() + ".GetName(" + hypoID + "), " +
-        SMESH_2smeshpy::SmeshpyName() + ".GetName(" + geomID + "), " +
-        (char*)( isAlgo ? "True" : "False" ) + " )";
-      Handle(_pyCommand) cmd = theGen->AddCommand( cmdStr );
-      addCmd->AddDependantCmd( cmd, true );
-    }
-  }
+bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
+{
+  // names of SMESH_Mesh methods fully equal to methods of class Mesh, so
+  // no conversion is needed for them at all:
+  static TStringSet sameMethods;
+  if ( sameMethods.empty() ) {
+    const char * names[] =
+      { "ExportDAT","ExportUNV","ExportSTL", "RemoveGroup","RemoveGroupWithContents",
+        "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog",
+        "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements",
+        "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles",
+        "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes",
+        "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder",
+        "NbPyramids","NbPyramidsOfOrder","NbPrisms","NbPrismsOfOrder","NbPolyhedrons",
+        "NbSubMesh","GetElementsId","GetElementsByType","GetNodesId","GetElementType",
+        "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
+        "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
+        "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
+        "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList",
+        "" }; // <- mark of end
+    sameMethods.Insert( names );
+  }
+
+  return !sameMethods.Contains( theCommand->GetMethod() );
 }
 
 //================================================================================
@@ -677,19 +738,19 @@ void _pyMesh::Flush()
   for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
   {
     Handle(_pyCommand) addCmd = *cmd;
-    const _pyID& algoID = addCmd->GetArg( 2 );
+    _pyID algoID = addCmd->GetArg( 2 );
     Handle(_pyHypothesis) algo = theGen->FindHyp( algoID );
     if ( algo.IsNull() || !algo->IsAlgo() )
       continue;
     // try to convert
     _pyID geom = addCmd->GetArg( 1 );
+    bool isLocalAlgo = ( geom != GetGeom() );
     if ( algo->Addition2Creation( addCmd, this->GetID() )) // OK
     {
       // wrapped algo is created atfer mesh creation
       GetCreationCmd()->AddDependantCmd( addCmd );
 
-      if ( geom != GetGeom() ) // local algo
-      {
+      if ( isLocalAlgo ) {
         // mesh.AddHypothesis(geom, ALGO ) --> mesh.AlgoMethod(geom)
         addCmd->SetArg( addCmd->GetNbArgs() + 1,
                         TCollection_AsciiString( "geom=" ) + geom );
@@ -704,15 +765,13 @@ void _pyMesh::Flush()
         }
       }
     }
-    else // ALGO was already created
+    else // KO - ALGO was already created
     {
-      // mesh.AddHypothesis(geom, ALGO ) --> mesh.GetMesh().AddHypothesis(geom, ALGO )
-      AddMeshAccess( addCmd );
-      // mesh.GetMesh().AddHypothesis(geom, ALGO ) ->
-      // mesh.GetMesh().AddHypothesis(geom, ALGO.GetAlgorithm() )
-      addCmd->SetArg( 2, addCmd->GetArg( 2 ) + ".GetAlgorithm()" );
-      // add addition result treatement cmd
-      addErrorTreatmentCmd( addCmd, true );
+      // mesh.AddHypothesis(geom, ALGO) --> mesh.AddHypothesis(ALGO, geom=0)
+      addCmd->RemoveArgs();
+      addCmd->SetArg( 1, algoID );
+      if ( isLocalAlgo )
+        addCmd->SetArg( 2, geom );
     }
   }
 
@@ -721,24 +780,27 @@ void _pyMesh::Flush()
   for ( cmd = myAddHypCmds.begin(); cmd != myAddHypCmds.end(); ++cmd )
   {
     Handle(_pyCommand) addCmd = *cmd;
-    const _pyID& hypID = addCmd->GetArg( 2 );
+    _pyID hypID = addCmd->GetArg( 2 );
     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
     if ( hyp.IsNull() || hyp->IsAlgo() )
       continue;
-    if ( !hyp->Addition2Creation( addCmd, this->GetID() ))
-    {
-      AddMeshAccess( addCmd );
-      // add addition result treatement cmd
-      addErrorTreatmentCmd( addCmd, false );
+    bool converted = hyp->Addition2Creation( addCmd, this->GetID() );
+    if ( !converted ) {
+      // mesh.AddHypothesis(geom, HYP) --> mesh.AddHypothesis(HYP, geom=0)
+      _pyID geom = addCmd->GetArg( 1 );
+      addCmd->RemoveArgs();
+      addCmd->SetArg( 1, hypID );
+      if ( geom != GetGeom() )
+        addCmd->SetArg( 2, geom );
     }
   }
 
   // sm = mesh.GetSubMesh(geom, name) --> sm = mesh.GetMesh().GetSubMesh(geom, name)
-  for ( cmd = mySubmeshes.begin(); cmd != mySubmeshes.end(); ++cmd ) {
-    Handle(_pyCommand) subCmd = *cmd;
-    if ( subCmd->GetNbArgs() > 0 )
-      AddMeshAccess( subCmd );
-  }
+//   for ( cmd = mySubmeshes.begin(); cmd != mySubmeshes.end(); ++cmd ) {
+//     Handle(_pyCommand) subCmd = *cmd;
+//     if ( subCmd->GetNbArgs() > 0 )
+//       AddMeshAccess( subCmd );
+//   }
   myAddHypCmds.clear();
   mySubmeshes.clear();
 
@@ -748,6 +810,61 @@ void _pyMesh::Flush()
     (*hyp)->Flush();
 }
 
+//================================================================================
+/*!
+ * \brief MeshEditor convert its commands to ones of mesh
+ */
+//================================================================================
+
+_pyMeshEditor::_pyMeshEditor(const Handle(_pyCommand)& theCreationCmd):
+  _pyObject( theCreationCmd )
+{
+  myMesh = theCreationCmd->GetObject();
+  myCreationCmdStr = theCreationCmd->GetString();
+  theCreationCmd->Clear();
+}
+
+//================================================================================
+/*!
+ * \brief convert its commands to ones of mesh
+ */
+//================================================================================
+
+void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
+{
+  // names of SMESH_MeshEditor methods fully equal to methods of class Mesh, so
+  // commands calling this methods are converted to calls of methods of Mesh
+  static TStringSet sameMethods;
+  if ( sameMethods.empty() ) {
+    const char * names[] = {
+      "RemoveElements","RemoveNodes","AddNode","AddEdge","AddFace","AddPolygonalFace",
+      "AddVolume","AddPolyhedralVolume","AddPolyhedralVolumeByFaces","MoveNode",
+      "InverseDiag","DeleteDiag","Reorient","ReorientObject","SplitQuad","SplitQuadObject",
+      "BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
+      "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
+      "RotationSweep","RotationSweepObject","ExtrusionSweep","AdvancedExtrusion",
+      "ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D","Mirror",
+      "MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
+      "FindCoincidentNodes","FindCoincidentNodesOnPart","MergeNodes","FindEqualElements",
+      "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
+      "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
+      "GetLastCreatedElems",
+      "" }; // <- mark of end
+    sameMethods.Insert( names );
+  }
+
+  if ( sameMethods.Contains( theCommand->GetMethod() )) {
+    theCommand->SetObject( myMesh );
+  }
+  else {
+    // editor creation command is needed only if any editor function is called
+    if ( !myCreationCmdStr.IsEmpty() ) {
+      GetCreationCmd()->GetString() = myCreationCmdStr;
+      myCreationCmdStr.Clear();
+    }
+  }
+}
+
 //================================================================================
 /*!
  * \brief _pyHypothesis constructor
@@ -850,25 +967,37 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
     hyp->AddArgMethod( "SetNumberOfSegments");
     hyp->AddArgMethod( "SetPythonLog10RatioFunction");
   }
-  // 2D ----------
-  else if ( hypType == "MEFISTO_2D" ) {
+  // MEFISTO_2D ----------
+  else if ( hypType == "MEFISTO_2D" ) { // MEFISTO_2D
     algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
   }
   else if ( hypType == "MaxElementArea" ) {
     hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
+    hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
     hyp->AddArgMethod( "SetMaxElementArea");
   }
   else if ( hypType == "LengthFromEdges" ) {
     hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
+    hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
   }
+  // Quadrangle_2D ----------
   else if ( hypType == "Quadrangle_2D" ) {
     algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
   }
   else if ( hypType == "QuadranglePreference" ) {
     hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
-  }
-  // 3D ----------
-  else if ( hypType == "NETGEN_3D") {
+    hyp->SetConvMethodAndType( "QuadranglePreference", "NETGEN_2D_ONLY");
+  }
+  // NETGEN ----------
+//   else if ( hypType == "NETGEN_2D") { // 1D-2D
+//     algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
+//     algo->myArgs.Append( "algo=smesh.NETGEN" );
+//   }
+  else if ( hypType == "NETGEN_2D_ONLY") { // 2D
+    algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
+    algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
+  }
+  else if ( hypType == "NETGEN_3D") { // 3D
     algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
     algo->myArgs.Append( "algo=smesh.NETGEN" );
   }
@@ -876,14 +1005,16 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
     hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
     hyp->AddArgMethod( "SetMaxElementVolume" );
   }
+  // GHS3D_3D ----------
   else if ( hypType == "GHS3D_3D" ) {
     algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
     algo->myArgs.Append( "algo=smesh.GHS3D" );
   }
+  // Hexa_3D ---------
   else if ( hypType == "Hexa_3D" ) {
     algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
   }
-  // Repetitive ---------
+  // Repetitive Projection_1D ---------
   else if ( hypType == "Projection_1D" ) {
     algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
   }
@@ -894,6 +1025,7 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
     // 2 args of SetVertexAssociation() will become the 3-th and 4-th args of hyp creation command
     hyp->AddArgMethod( "SetVertexAssociation", 2 );
   }
+  // Projection_2D ---------
   else if ( hypType == "Projection_2D" ) {
     algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
   }
@@ -903,6 +1035,7 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
     hyp->AddArgMethod( "SetSourceMesh");
     hyp->AddArgMethod( "SetVertexAssociation", 4 );
   }
+  // Projection_3D ---------
   else if ( hypType == "Projection_3D" ) {
     algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
   }
@@ -912,9 +1045,11 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
     hyp->AddArgMethod( "SetSourceMesh");
     hyp->AddArgMethod( "SetVertexAssociation", 4 );
   }
+  // Prism_3D ---------
   else if ( hypType == "Prism_3D" ) {
     algo->SetConvMethodAndType( "Prism", hypType.ToCString());
   }
+  // RadialPrism_3D ---------
   else if ( hypType == "RadialPrism_3D" ) {
     algo->SetConvMethodAndType( "Prism", hypType.ToCString());
   }
@@ -927,7 +1062,7 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
     hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
   }
 
-  if ( !algo->GetCreationMethod().IsEmpty() ) {
+  if ( algo->IsValid() ) {
     return algo;
   }
   return hyp;
@@ -955,7 +1090,7 @@ bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
   Handle(_pyHypothesis) algo;
   if ( !IsAlgo() ) {
     // find algo created on myGeom in theMesh
-    algo = theGen->FindAlgo( myGeom, theMesh, GetType() );
+    algo = theGen->FindAlgo( myGeom, theMesh, this );
     if ( algo.IsNull() )
       return false;
     algo->GetCreationCmd()->AddDependantCmd( theCmd );
@@ -965,7 +1100,7 @@ bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
   // mesh.AddHypothesis(geom,hyp) --> hyp = <theMesh or algo>.myCreationMethod(args)
   theCmd->SetResultValue( GetID() );
   theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
-  theCmd->SetMethod( myCreationMethod );
+  theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
   // set args
   theCmd->RemoveArgs();
   for ( int i = 1; i <= myArgs.Length(); ++i ) {
@@ -1185,7 +1320,7 @@ bool _pyLayerDistributionHypo::Addition2Creation( const Handle(_pyCommand)& theA
   // Convert my creation => me = RadialPrismAlgo.Get3DHypothesis()
 
   // find RadialPrism algo created on <geom> for theMesh
-  Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this->GetType() );
+  Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMesh, this );
   if ( !algo.IsNull() ) {
     GetCreationCmd()->SetObject( algo->GetID() );
     GetCreationCmd()->SetMethod( "Get3DHypothesis" );
@@ -1301,7 +1436,7 @@ bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand
     while ( algo.IsNull() && !geom.IsEmpty()) {
       // try to find geom as a father of <vertex>
       geom = FatherID( geom );
-      algo = theGen->FindAlgo( geom, theMeshID, GetType() );
+      algo = theGen->FindAlgo( geom, theMeshID, this );
     }
     if ( algo.IsNull() )
       return false; // also possible to find geom as brother of veretex...
index 2f1bc027c5abed7015147b8c1b17f7433ea06565..a09a84cd645a8be5e595505bbc49e5dc1d45a542 100644 (file)
 
 // ===========================================================================================
 /*!
- * \brief Tool converting SMESH engine calls into commands defined in smesh.py
- *
  * This file was created in order to respond to requirement of bug PAL10494:
  * SMESH python dump uses idl interface.
  *
  * The creation reason is that smesh.py commands defining hypotheses encapsulate
  * several SMESH engine method calls. As well, the dependencies between smesh.py
- * classes differ from ones between SMESH IDL interfaces.
+ * classes differ from ones between corresponding SMESH IDL interfaces.
  * 
- * The only API method here is SMESH_2smeshpy::ConvertScript(), the rest ones are
- * for internal usage
+ * Everything here is for internal usage by SMESH_2smeshpy::ConvertScript()
+ * declared in SMESH_PythonDump.hxx
  *
- * See comments to _pyHypothesis class to know how to assure convertion of a new hypothesis
+ * See comments to _pyHypothesis class to know how to assure convertion of a new
+ * type of hypothesis
  */
 // ===========================================================================================
 
 class Resource_DataMapOfAsciiStringAsciiString;
 
-class SMESH_2smeshpy
-{
-public:
-  /*!
-   * \brief Convert a python script using commands of smesh.py
-   * \param theScript - Input script
-   * \param theEntry2AccessorMethod - The returning method names to access to
-   *        objects wrapped with python class
-   * \retval TCollection_AsciiString - Convertion result
-   */
-  static TCollection_AsciiString
-  ConvertScript(const TCollection_AsciiString& theScript,
-                Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
-
-  /*!
-   * \brief Return the name of the python file wrapping IDL API
-    * \retval TCollection_AsciiString - The file name
-   */
-  static char* SmeshpyName() { return "smesh"; }
-  static char* GenName() { return "smesh.smesh"; }
-};
-
 // ===========================================================================================
 // =====================
 //    INTERNAL STUFF
@@ -93,6 +70,7 @@ DEFINE_STANDARD_HANDLE (_pyCommand   ,Standard_Transient);
 DEFINE_STANDARD_HANDLE (_pyObject    ,Standard_Transient);
 DEFINE_STANDARD_HANDLE (_pyGen       ,_pyObject);
 DEFINE_STANDARD_HANDLE (_pyMesh      ,_pyObject);
+DEFINE_STANDARD_HANDLE (_pyMeshEditor,_pyObject);
 DEFINE_STANDARD_HANDLE (_pyHypothesis,_pyObject);
 DEFINE_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis);
 
@@ -198,20 +176,21 @@ public:
   void Flush();
   Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );
   Handle(_pyHypothesis) FindAlgo( const _pyID& theGeom, const _pyID& theMesh,
-                                 const TCollection_AsciiString& theAlgoType);
+                                  const Handle(_pyHypothesis)& theHypothesis);
   void ExchangeCommands( Handle(_pyCommand) theCmd1, Handle(_pyCommand) theCmd2 );
   void SetCommandAfter( Handle(_pyCommand) theCmd, Handle(_pyCommand) theAfterCmd );
   std::list< Handle(_pyCommand) >& GetCommands() { return myCommands; }
   void SetAccessorMethod(const _pyID& theID, const char* theMethod );
   bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const;
   bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const;
-  const char* AccessorMethod() const { return SMESH_2smeshpy::GenName(); }
+  const char* AccessorMethod() const;
 private:
-  std::map< _pyID, Handle(_pyMesh) > myMeshes;
-  std::list< Handle(_pyHypothesis) > myHypos;
-  std::list< Handle(_pyCommand) >    myCommands;
-  int                                myNbCommands;
-  bool                               myHasPattern;
+  std::map< _pyID, Handle(_pyMesh) >       myMeshes;
+  std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors;
+  std::list< Handle(_pyHypothesis) >       myHypos;
+  std::list< Handle(_pyCommand) >          myCommands;
+  int                                      myNbCommands;
+  bool                                     myHasPattern;
   Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
 
   DEFINE_STANDARD_RTTI (_pyGen)
@@ -236,6 +215,7 @@ public:
   void Flush();
   const char* AccessorMethod() const { return _pyMesh_ACCESS_METHOD; }
 private:
+  static bool NeedMeshAccess( const Handle(_pyCommand)& theCommand );
   static void AddMeshAccess( const Handle(_pyCommand)& theCommand )
   { theCommand->SetObject( theCommand->GetObject() + "." _pyMesh_ACCESS_METHOD ); }
 
@@ -243,20 +223,36 @@ private:
 };
 #undef _pyMesh_ACCESS_METHOD 
 
+// -------------------------------------------------------------------------------------
+/*!
+ * \brief MeshEditor convert its commands to ones of mesh
+ */
+// -------------------------------------------------------------------------------------
+class _pyMeshEditor: public _pyObject
+{
+  _pyID myMesh;
+  TCollection_AsciiString myCreationCmdStr;
+public:
+  _pyMeshEditor(const Handle(_pyCommand)& theCreationCmd);
+  void Process( const Handle(_pyCommand)& theCommand);
+  virtual void Flush() {}
+
+  DEFINE_STANDARD_RTTI (_pyMesh)
+};
+
 // -------------------------------------------------------------------------------------
 /*!
  * \brief Root class for hypothesis
  *
- * HOWTO assure convertion of a new hypothesis
- * In NewHypothesis():
- * 1. add a case for the name of the new hypothesis and
- * 2. initialize _pyHypothesis fields:
- *    . myDim - hypothesis dimention;
- *    . myType - type name of the algorithm creating the hypothesis;
- *    . myCreationMethod - method name of the algorithm creating the hypothesis;
- *    . append to myArgMethods interface methods setting param values in the
- *    order they are used when myCreationMethod is called. It is supposed that
- *    each interface method sets only one parameter, if it is not so, you are
+ * HOWTO assure convertion of a new type of hypothesis
+ * In _pyHypothesis::NewHypothesis():
+ * 1. add a case for the name of the new hypothesis
+ * 2. use SetConvMethodAndType() to set
+ *    . for algo: algorithm name and method of Mesh creating the algo
+ *    . for hypo: name of the algorithm and method creating the hypothesis
+ * 3. append to myArgMethods interface methods setting param values in the
+ *    order they are used when creation method is called. If arguments of
+ *    the creation method can't be easily got from calls of hypothesis methods, you are
  *    to derive a specific class from _pyHypothesis that would redefine Process(),
  *    see _pyComplexParamHypo for example
  */
@@ -264,41 +260,43 @@ private:
 class _pyHypothesis: public _pyObject
 {
 protected:
-  bool    myIsAlgo, myIsWrapped; //myIsLocal, myIsConverted;
-  //int     myDim/*, myAdditionCmdNb*/;
-  _pyID    myGeom, myMesh;
-  TCollection_AsciiString       myCreationMethod, myType;
-  TColStd_SequenceOfAsciiString myArgs;
-  TColStd_SequenceOfAsciiString myArgMethods;
-  TColStd_SequenceOfInteger     myNbArgsByMethod;
+  bool    myIsAlgo, myIsWrapped;
+  _pyID   myGeom,   myMesh;
+  // a hypothesis can be used and created by different algos by different methods
+  std::map<TCollection_AsciiString, TCollection_AsciiString > myType2CreationMethod;
+  //TCollection_AsciiString       myCreationMethod, myType;
+  TColStd_SequenceOfAsciiString myArgs;           // creation arguments
+  TColStd_SequenceOfAsciiString myArgMethods;     // hypo methods setting myArgs
+  TColStd_SequenceOfInteger     myNbArgsByMethod; // nb args set by each method
   std::list<Handle(_pyCommand)>  myArgCommands;
   std::list<Handle(_pyCommand)>  myUnknownCommands;
 public:
   _pyHypothesis(const Handle(_pyCommand)& theCreationCmd);
-  void SetConvMethodAndType(const char* creationMethod, const char* type=0)
-  { myCreationMethod = (char*)creationMethod; if ( type ) myType = (char*)type; }
-//   void SetDimMethodType(const int dim, const char* creationMethod, const char* type=0)
-//   { myDim = dim; myCreationMethod = (char*)creationMethod; if ( type ) myType = (char*)type; }
+  void SetConvMethodAndType(const char* creationMethod, const char* type)
+  { myType2CreationMethod[ (char*)type ] = (char*)creationMethod; }
   void AddArgMethod(const char* method, const int nbArgs = 1)
   { myArgMethods.Append( (char*)method ); myNbArgsByMethod.Append( nbArgs ); }
   const TColStd_SequenceOfAsciiString& GetArgs() const { return myArgs; }
-  const TCollection_AsciiString& GetCreationMethod() const { return myCreationMethod; }
   const std::list<Handle(_pyCommand)>& GetArgCommands() const { return myArgCommands; }
   void ClearAllCommands();
   virtual bool IsAlgo() const { return myIsAlgo; }
+  bool IsValid() const { return !myType2CreationMethod.empty(); }
   bool IsWrapped() const { return myIsWrapped; }
-  //bool & IsConverted() { return myIsConverted; }
-  //int GetDim() const { return myDim; }
   const _pyID & GetGeom() const { return myGeom; }
   void SetMesh( const _pyID& theMeshId) { if ( myMesh.IsEmpty() ) myMesh = theMeshId; }
   const _pyID & GetMesh() const { return myMesh; }
-  const TCollection_AsciiString GetType() { return myType; }
+  const TCollection_AsciiString& GetAlgoType() const
+  { return myType2CreationMethod.begin()->first; }
+  const TCollection_AsciiString& GetAlgoCreationMethod() const
+  { return myType2CreationMethod.begin()->second; }
+  bool CanBeCreatedBy(const TCollection_AsciiString& algoType ) const
+  { return myType2CreationMethod.find( algoType ) != myType2CreationMethod.end(); }
+  const TCollection_AsciiString& GetCreationMethod(const TCollection_AsciiString& algoType) const
+  { return myType2CreationMethod.find( algoType )->second; }
   bool IsWrappable(const _pyID& theMesh) { return !myIsWrapped && myMesh == theMesh; }
   virtual bool Addition2Creation( const Handle(_pyCommand)& theAdditionCmd,
                                   const _pyID&              theMesh);
   static Handle(_pyHypothesis) NewHypothesis( const Handle(_pyCommand)& theCreationCmd);
-  //     bool HasMesh() const { return !myMesh.IsEmpty(); }
-  //     void SetGeom( const _pyID& theGeomID ) { myGeom = theGeomID; }
   void Process( const Handle(_pyCommand)& theCommand);
   void Flush();