Salome HOME
Merge Python 3 porting.
authorrnv <rnv@opencascade.com>
Thu, 22 Jun 2017 15:25:40 +0000 (18:25 +0300)
committerrnv <rnv@opencascade.com>
Thu, 22 Jun 2017 15:26:37 +0000 (18:26 +0300)
1  2 
doc/salome/examples/blsurfdemo.py
src/BLSURFPlugin/BLSURFPluginBuilder.py
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx
tests/test_periodicity_reflexion_2D_precad.py
tests/test_proximity.py
tests/test_remove_tiny_edges.py

index 4d98941ec6d02422fe7af0bb4d040b16e99af344,e78717dbb134fb789bbb7f3b04e39eca7a77b9c4..953777fe1de2dca2aea335f54de519f70be7151d
@@@ -6,11 -6,11 +6,11 @@@ import salom
  salome.salome_init()
  import GEOM
  from salome.geom import geomBuilder
 -geompy = geomBuilder.New(salome.myStudy)
 +geompy = geomBuilder.New()
  
  import SMESH, SALOMEDS
  from salome.smesh import smeshBuilder
 -smesh =  smeshBuilder.New(salome.myStudy)
 +smesh =  smeshBuilder.New()
  
  # create a box
  box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
@@@ -72,8 -72,8 +72,8 @@@ algo2d.SetEnforcedVertex(Face_1, 150, 1
  
  # Retrieve and print the list of enforced vertices defines on Face_1
  enfList = algo2d.GetEnforcedVertices(Face_1)
- print "List of enforced vertices for Face_1: "
- print enfList
+ print("List of enforced vertices for Face_1: ")
+ print(enfList)
  
  # compute the mesh
  cadsurfMesh.Compute()
@@@ -81,8 -81,8 +81,8 @@@
  # Remove an enforced vertex and print the list
  algo2d.UnsetEnforcedVertex(Face_1, 50, 50, 50)
  enfList = algo2d.GetEnforcedVertices(Face_1)
- print "List of enforced vertices for Face_1: "
- print enfList
+ print("List of enforced vertices for Face_1: ")
+ print(enfList)
  
  # compute the mesh
  cadsurfMesh.Compute()
index 4548fa314698a9d019fc9cb19dd95c144cf1d3ce,873213066e03d9db7ca9695d4deb5f64a51a8962..6247dcf09687059c4eb55ccadce2c5195d7bfbaa
@@@ -86,7 -86,7 +86,7 @@@ class BLSURF_Algorithm(Mesh_Algorithm)
    def __init__(self, mesh, geom=0):
      Mesh_Algorithm.__init__(self)
      if noBLSURFPlugin:
-       print "Warning: BLSURFPlugin module unavailable"
+       print("Warning: BLSURFPlugin module unavailable")
      if mesh.GetMesh().HasShapeToMesh():
        self.Create(mesh, geom, self.algoType, LIBRARY)
      else:
    # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
    def SetTopology(self, way):
      if way != PreCAD and way != FromCAD:
-       print "Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way
+       print("Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way)
        way = FromCAD
      self.Parameters().SetTopology(way)
      pass
    def SetJacobianRectification( self, allowRectification ):
      self.Parameters().SetJacobianRectification( allowRectification )
  
 +  ## Set use_deprecated_patch_mesher parameter (compatibility with older versions of Meshgems)
 +  #  
 +  # the use_deprecated_patch_mesher parameter allows to keep the same behaviour than
 +  # in salome < 8.3 (meshgems 2.1.11 instead of meshgems >= 2.4.5)
 +  #  
 +  def SetUseDeprecatedPatchMesher( self, useDeprecatedPatchMesher ):
 +    self.Parameters().SetUseDeprecatedPatchMesher( useDeprecatedPatchMesher )
 +
    ## Set respect_geometry parameter
    #  
    #  This patch independent option can be deactivated to allow MeshGems-CADSurf
            for f in faces:
              ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
          else:
-           raise TypeError, \
-             "Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face)
+           raise TypeError("Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face))
          pass
        hpl.append( ids )
        pass
      """
      Obsolete function. Use SetMinSize.
      """
-     print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
+     print("Warning: SetPhyMin is obsolete. Please use SetMinSize")
      self.SetMinSize(theVal)
      pass
  
      """
      Obsolete function. Use SetMaxSize.
      """
-     print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
+     print("Warning: SetPhyMax is obsolete. Please use SetMaxSize")
      self.SetMaxSize(theVal)
      pass
  
      """
      Obsolete function. Use SetAngleMesh.
      """
-     print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
+     print("Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh")
      self.SetAngleMesh(theVal)
      pass
  
      """
      Obsolete function. Use SetAngleMesh.
      """
-     print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
+     print("Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh")
      self.SetAngleMesh(theVal)
      pass
  
      """
      Obsolete function. Use SetMinSize.
      """
-     print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
+     print("Warning: SetGeoMin is obsolete. Please use SetMinSize")
      self.SetMinSize(theVal)
      pass
  
      """
      Obsolete function. Use SetMaxSize.
      """
-     print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
+     print("Warning: SetGeoMax is obsolete. Please use SetMaxSize")
      self.SetMaxSize(theVal)
      pass
  
index cf6f1f65304e5c00d9ad8255d77f70ee8be3d78b,388c24658d63da26ab6debf4dbc208d32fa5ba7b..d6666d83a0ccd2087f0b3b6455f199ef9e0d075f
@@@ -146,8 -146,7 +146,7 @@@ namespac
    static PyTypeObject PyStdOut_Type = {
      /* The ob_type field must be initialized in the module init function
       * to be portable to Windows without using C++. */
-     PyObject_HEAD_INIT(NULL)
-     0,                            /*ob_size*/
+     PyVarObject_HEAD_INIT(NULL, 0)
      "PyOut",                      /*tp_name*/
      sizeof(PyStdOut),             /*tp_basicsize*/
      0,                            /*tp_itemsize*/
@@@ -242,9 -241,10 +241,9 @@@ bool HasSizeMapOnVertex=false
  //=============================================================================
  
  BLSURFPlugin_BLSURF::BLSURFPlugin_BLSURF(int        hypId,
 -                                         int        studyId,
                                           SMESH_Gen* gen,
                                           bool       theHasGEOM)
 -  : SMESH_2D_Algo(hypId, studyId, gen)
 +  : SMESH_2D_Algo(hypId, gen)
  {
    _name = theHasGEOM ? "MG-CADSurf" : "MG-CADSurf_NOGEOM";//"BLSURF";
    _shapeType = (1 << TopAbs_FACE); // 1 bit /shape type
    _supportSubmeshes = true;
    _requireShape = theHasGEOM;
  
 -  smeshGen_i = SMESH_Gen_i::GetSMESHGen();
 -  CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager");
 -  SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
 -
 -  myStudy = NULL;
 -  myStudy = aStudyMgr->GetStudyByID(_studyId);
 -
    /* Initialize the Python interpreter */
    assert(Py_IsInitialized());
    PyGILState_STATE gstate;
@@@ -495,16 -502,19 +494,16 @@@ projectionPoint getProjectionPoint(Topo
  /////////////////////////////////////////////////////////
  TopoDS_Shape BLSURFPlugin_BLSURF::entryToShape(std::string entry)
  {
 -  TopoDS_Shape S;
 -  if ( !entry.empty() )
 -  {
 -    GEOM::GEOM_Object_var aGeomObj;
 -    SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
 -    if (!aSObj->_is_nil()) {
 -      CORBA::Object_var obj = aSObj->GetObject();
 -      aGeomObj = GEOM::GEOM_Object::_narrow(obj);
 -      aSObj->UnRegister();
 -    }
 -    if ( !aGeomObj->_is_nil() )
 -      S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
 +  GEOM::GEOM_Object_var aGeomObj;
 +  TopoDS_Shape S = TopoDS_Shape();
 +  SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() );
 +  if (!aSObj->_is_nil()) {
 +    CORBA::Object_var obj = aSObj->GetObject();
 +    aGeomObj = GEOM::GEOM_Object::_narrow(obj);
 +    aSObj->UnRegister();
    }
 +  if ( !aGeomObj->_is_nil() )
 +    S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
    return S;
  }
  
@@@ -888,7 -898,6 +887,7 @@@ void BLSURFPlugin_BLSURF::SetParameters
    //int _precadProcess3DTopology  = BLSURFPlugin_Hypothesis::GetDefaultPreCADProcess3DTopology();
    //int _precadDiscardInput       = BLSURFPlugin_Hypothesis::GetDefaultPreCADDiscardInput();
  
 +  const BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector preCadFacesPeriodicityVector = BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(hyp);
  
    if (hyp) {
      _physicalMesh  = (int) hyp->GetPhysicalMesh();
  
      const BLSURFPlugin_Hypothesis::TOptionValues& opts = hyp->GetOptionValues();
      BLSURFPlugin_Hypothesis::TOptionValues::const_iterator opIt;
 -    for ( opIt = opts.begin(); opIt != opts.end(); ++opIt )
 +    for ( opIt = opts.begin(); opIt != opts.end(); ++opIt ){
 +      MESSAGE("OptionValue: " << opIt->first.c_str() << ", value: " << opIt->second.c_str());
        if ( !opIt->second.empty() ) {
 -        set_param(css, opIt->first.c_str(), opIt->second.c_str());
 +              // With MeshGems 2.4-5, there are issues with periodicity and multithread
 +              // => As a temporary workaround, we enforce to use only one thread if periodicity is used.
 +        if (opIt->first == "max_number_of_threads" && opIt->second != "1" && ! preCadFacesPeriodicityVector.empty()){
 +          std::cout << "INFO: Disabling multithread to avoid periodicity issues" << std::endl;
 +          set_param(css, opIt->first.c_str(), "1");
 +        }
 +        else
 +          set_param(css, opIt->first.c_str(), opIt->second.c_str());
        }
 +    }
  
      const BLSURFPlugin_Hypothesis::TOptionValues& custom_opts = hyp->GetCustomOptionValues();
      for ( opIt = custom_opts.begin(); opIt != custom_opts.end(); ++opIt )
     _preCadFacesIDsPeriodicityVector.clear();
     _preCadEdgesIDsPeriodicityVector.clear();
  
 -  const BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector preCadFacesPeriodicityVector = BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(hyp);
 -
    for (std::size_t i = 0; i<preCadFacesPeriodicityVector.size(); i++){
      createPreCadFacesPeriodicity(theGeomShape, preCadFacesPeriodicityVector[i]);
    }
@@@ -2394,7 -2396,7 +2393,7 @@@ bool BLSURFPlugin_BLSURF::compute(SMESH
        //   cout << o.str() << endl;
        if (_preCadFacesIDsPeriodicityVector[i].theSourceVerticesCoords.empty())
        {
 -        // If no source points, call peridoicity without transformation function
 +        // If no source points, call periodicity without transformation function
          meshgems_cad_periodicity_transformation_t periodicity_transformation = NULL;
          status = cad_add_face_multiple_periodicity_with_transformation_function(c, theFace1_ids_c, theFace1_ids.size(),
                                                                                  theFace2_ids_c, theFace2_ids.size(), periodicity_transformation, NULL);
      for (std::size_t i=0; i < _preCadEdgesIDsPeriodicityVector.size(); i++){
        std::vector<int> theEdge1_ids = _preCadEdgesIDsPeriodicityVector[i].shape1IDs;
        std::vector<int> theEdge2_ids = _preCadEdgesIDsPeriodicityVector[i].shape2IDs;
 -      // Use the address of the first element of the vector to initialise the array
 +      // Use the address of the first element of the vector to initialize the array
        int* theEdge1_ids_c = &theEdge1_ids[0];
        int* theEdge2_ids_c = &theEdge2_ids[0];
  
  
        if (_preCadEdgesIDsPeriodicityVector[i].theSourceVerticesCoords.empty())
        {
 -        // If no source points, call peridoicity without transformation function
 +        // If no source points, call periodicity without transformation function
          meshgems_cad_periodicity_transformation_t periodicity_transformation = NULL;
          status = cad_add_edge_multiple_periodicity_with_transformation_function(c, theEdge1_ids_c, theEdge1_ids.size(),
                                                                                  theEdge2_ids_c, theEdge2_ids.size(), periodicity_transformation, NULL);
index a4d182e1492bd6c185224d7e04ac42bc5991b1b0,e4138387510f190e02142ba37c25075835c4a4fc..9f159d7bf9a5ff6ee4e86022bb7818bb4fc6402e
@@@ -225,8 -225,7 +225,7 @@@ namespace 
    static PyTypeObject PyStdOut_Type = {
      /* The ob_type field must be initialized in the module init function
       * to be portable to Windows without using C++. */
-     PyObject_HEAD_INIT(NULL)
-     0,                            /*ob_size*/
+     PyVarObject_HEAD_INIT(NULL, 0)
      "PyOut",                      /*tp_name*/
      sizeof(PyStdOut),             /*tp_basicsize*/
      0,                            /*tp_itemsize*/
@@@ -475,8 -474,9 +474,8 @@@ BLSURFPluginGUI_HypothesisCreator::~BLS
  GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool() const
  {
    BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 -  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
 -  if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
 -    that->GeomToolSelected = new GeomSelectionTools(aStudy);
 +  if (that->GeomToolSelected == NULL) {
 +    that->GeomToolSelected = new GeomSelectionTools();
    }
    return that->GeomToolSelected;
  }
@@@ -1301,7 -1301,7 +1300,7 @@@ void BLSURFPluginGUI_HypothesisCreator:
      myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
      if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
        BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 -      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
 +      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
        if (CORBA::is_nil(measureOp))
          return;
        
@@@ -1488,7 -1488,7 +1487,7 @@@ void BLSURFPluginGUI_HypothesisCreator:
        if ( CORBA::is_nil(getGeomEngine()))
          return;
  
 -      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
 +      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
        if (CORBA::is_nil(measureOp))
          return;
  
@@@ -3437,8 -3437,10 +3436,8 @@@ LightApp_SelectionMgr* BLSURFPluginGUI_
  
  CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
  {
 -  SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
 -  SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
    CORBA::Object_var obj;
 -  SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() );
 +  SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.toStdString().c_str() );
    if (!aSObj->_is_nil()) {
      obj = aSObj->GetObject();
      aSObj->UnRegister();
index a6af83c63098d0260c08e032ca02b453f6cb6b88,11d21be8431ae737229725e1a58ef6cadddf4eb5..ba6853e344d3b06e6c3564b37850fce3012ba182
@@@ -11,7 -11,7 +11,7 @@@ import mat
  
  import GEOM
  from salome.geom import geomBuilder
 -geompy = geomBuilder.New(salome.myStudy)
 +geompy = geomBuilder.New()
  
  O = geompy.MakeVertex(0, 0, 0)
  OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
@@@ -74,7 -74,7 +74,7 @@@ geompy.addToStudy(p_haut_droite, "p_hau
  
  import SMESH
  from salome.smesh import smeshBuilder
 -smesh = smeshBuilder.New(salome.myStudy)
 +smesh = smeshBuilder.New()
  
  Mesh = smesh.Mesh(part, "Mesh")
  
@@@ -115,12 -115,12 +115,12 @@@ def checkProjection(gr, mesh_translated
          non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes))
          mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes)
          #raise Exception("Projection failed for %s"%name)
-         print "Projection failed for %s"%name
+         print("Projection failed for %s"%name)
          
  checkProjection(gr_right, bottom_rotated)
  
 -#salome.myStudyManager.SaveAs("test.hdf", salome.myStudy, 0)
 +#salome.myStudy.SaveAs("test.hdf", 0, 0)
  
  if salome.sg.hasDesktop():
 -  salome.sg.updateObjBrowser(True)
 +  salome.sg.updateObjBrowser()
    
diff --combined tests/test_proximity.py
index c177ef580cbd20efe2be9ed06501ac86ac7a44c1,6b783439118b10c2b2035502706ab118ef41b356..5a0230fe49d8408c3c03fcbc23a2292a788d1919
@@@ -4,6 -4,7 +4,6 @@@ import sy
  import salome
  
  salome.salome_init()
 -theStudy = salome.myStudy
  
  ###
  ### GEOM component
@@@ -15,7 -16,7 +15,7 @@@ import mat
  import SALOMEDS
  
  
 -geompy = geomBuilder.New(theStudy)
 +geompy = geomBuilder.New()
  
  # Create a box
  box = geompy.MakeBoxDXDYDZ(100, 100, 100)
@@@ -49,7 -50,7 +49,7 @@@ geompy.addToStudyInFather(part, gr_sphe
  import  SMESH, SALOMEDS
  from salome.smesh import smeshBuilder
  
 -smesh = smeshBuilder.New(theStudy)
 +smesh = smeshBuilder.New()
  Mesh_1 = smesh.Mesh(part, "Mesh_part")
  BLSURF = Mesh_1.Triangle(algo=smeshBuilder.BLSURF)
  BLSURF_Parameters_1 = BLSURF.Parameters()
@@@ -79,10 -80,10 +79,10 @@@ gr_mesh_spheres = Mesh_1.Group(gr_spher
  # Check the minimal area of the box faces to check the proximity
  min_area, max_area = Mesh_1.GetMinMax(SMESH.FT_Area, gr_mesh_box)
  
- print "min_area: ", min_area
+ print("min_area: ", min_area)
  
  if min_area > 1.5:
      raise Exception("Wrong minimal area on box. Proximity has not worked.")
  
  if salome.sg.hasDesktop():
 -  salome.sg.updateObjBrowser(True)
 +  salome.sg.updateObjBrowser()
index 426e37ee240b5c8c8376ecdfbd706bfd026f1d08,af91fb4fb71ea6151d36f2671edbdcbe6e5cfbaf..18f86599114e955546fddfdc85a1f37a2d3fc9c2
@@@ -4,7 -4,7 +4,7 @@@ import salom
  
  import GEOM
  from salome.geom import geomBuilder
 -geompy = geomBuilder.New(salome.myStudy)
 +geompy = geomBuilder.New()
  
  import math
  
@@@ -64,7 -64,7 +64,7 @@@ for i, face in enumerate(faces)
  
  import SMESH
  from salome.smesh import smeshBuilder
 -smesh = smeshBuilder.New(salome.myStudy)
 +smesh = smeshBuilder.New()
  
  Mesh = smesh.Mesh(part, "Mesh")
  
@@@ -101,10 -101,10 +101,10 @@@ for elem in elems
  min_length = min(edges_length)
  x1, y1, z1 = Mesh.GetNodeXYZ(node)
  
- print min_length
+ print(min_length)
  
  if min_length<tiny_edge_length:
      raise Exception("Small edge has not been removed")
  
  if salome.sg.hasDesktop():
 -  salome.sg.updateObjBrowser(True)
 +  salome.sg.updateObjBrowser()