]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
Merge from BR_V7_periodicity 22/08/2013
authorbourcier <bourcier>
Thu, 22 Aug 2013 12:54:55 +0000 (12:54 +0000)
committerbourcier <bourcier>
Thu, 22 Aug 2013 12:54:55 +0000 (12:54 +0000)
24 files changed:
Makefile.am
configure.ac
idl/BLSURFPlugin_Algorithm.idl
resources/BLSURFPlugin.xml
src/BLSURFPlugin/BLSURFPluginBuilder.py
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx
tests/Makefile.am [new file with mode: 0644]
tests/test_enforced_internal_vertex.py [new file with mode: 0644]
tests/test_enforced_vertex.py [new file with mode: 0644]
tests/test_periodicity.py [new file with mode: 0644]
tests/test_periodicity_2D.py [new file with mode: 0644]
tests/test_periodicity_2D_precad.py [new file with mode: 0644]
tests/test_periodicity_precad.py [new file with mode: 0644]
tests/test_periodicity_reflexion.py [new file with mode: 0644]
tests/test_periodicity_reflexion_2D.py [new file with mode: 0644]
tests/test_periodicity_reflexion_2D_precad.py [new file with mode: 0644]
tests/test_periodicity_reflexion_precad.py [new file with mode: 0644]
tests/test_periodicity_with_points_2D_precad.py [new file with mode: 0644]
tests/test_precad_intersections.py [new file with mode: 0644]

index 2c52a4d734eb541d86290abd324b33fbe564d79a..e88f1cf31770c903c3cf3809fc3a565c090e4741 100644 (file)
@@ -37,9 +37,9 @@ else !BLSURFPLUGIN_ENABLE_GUI
                     -I ${SMESH_ROOT_DIR}/adm_local/unix/config_files
 endif
 
-SUBDIRS = idl adm_local resources src bin doc
+SUBDIRS = idl adm_local resources src bin doc tests
 
-DIST_SUBDIRS = idl adm_local resources src bin doc 
+DIST_SUBDIRS = idl adm_local resources src bin doc tests
 
 DISTCLEANFILES = a.out aclocal.m4 configure local-install.sh hack_libtool
 
index 8f119b707eb1709c0e455477346ae3505ad507d4..fd469b9f7df341736b983864e8516a049b5f681d 100644 (file)
@@ -442,6 +442,7 @@ AC_OUTPUT([ \
   src/Makefile \
   src/BLSURFPlugin/Makefile \
   src/GUI/Makefile \
+  tests/Makefile \
   BLSURFPLUGIN_version.h \
   Makefile \
 ])
index c03c31ca50c200dddc3c7608b7c428b89b3d9d27..fe664b1404601b4b2f62c2b9361615ae23b61d91 100644 (file)
@@ -426,6 +426,22 @@ module BLSURFPlugin
 //    TFaceEntryInternalVerticesList GetAllInternalEnforcedVerticesFaces();
     ///////////////////////
     
+
+    ///////////////////////
+    // PERIODICITY       //
+    ///////////////////////
+
+    void AddPreCadFacesPeriodicity(in GEOM::GEOM_Object theFace1, in GEOM::GEOM_Object theFace2) raises (SALOME::SALOME_Exception);
+    void AddPreCadFacesPeriodicityWithVertices(in GEOM::GEOM_Object theFace1, in GEOM::GEOM_Object theFace2, in GEOM::ListOfGO theSourceVertices, in GEOM::ListOfGO theTargetVertices) raises (SALOME::SALOME_Exception);
+    void AddPreCadEdgesPeriodicity(in GEOM::GEOM_Object theEdge1, in GEOM::GEOM_Object theEdge2) raises (SALOME::SALOME_Exception);
+    void AddPreCadEdgesPeriodicityWithVertices(in GEOM::GEOM_Object theEdge1, in GEOM::GEOM_Object theEdge2, in GEOM::ListOfGO theSourceVertices, in GEOM::ListOfGO theTargetVertices) raises (SALOME::SALOME_Exception);
+    void AddFacePeriodicity(in GEOM::GEOM_Object theFace1, in GEOM::GEOM_Object theFace2) raises (SALOME::SALOME_Exception);
+    void AddEdgePeriodicity(in GEOM::GEOM_Object theFace1, in GEOM::GEOM_Object theEdge1, in GEOM::GEOM_Object theFace2, in GEOM::GEOM_Object theEdge2, in long edge_orientation) raises (SALOME::SALOME_Exception);
+    void AddEdgePeriodicityWithoutFaces(in GEOM::GEOM_Object theEdge1, in GEOM::GEOM_Object theEdge2, in long edge_orientation) raises (SALOME::SALOME_Exception);
+    void AddVertexPeriodicity(in GEOM::GEOM_Object theEdge1, in GEOM::GEOM_Object theVertex1, in GEOM::GEOM_Object theEdge2, in GEOM::GEOM_Object theVertex2) raises (SALOME::SALOME_Exception);
+    
+    ///////////////////////
+
     /*!
      * Sets the file for export resulting mesh in GMF format
      */
index 56f7615f211a1ba504ff03721ca7adf6b35c43a9..3f6b3fdd1c173e0638840e944da3dcef9944ecc4 100644 (file)
@@ -56,7 +56,8 @@
           SetEnforcedVertexGeomWithGroup,
           UnsetEnforcedVertex,
           UnsetEnforcedVertexGeom,
-          UnsetEnforcedVertices
+          UnsetEnforcedVertices,
+          AddPreCadFacesPeriodicity
         </accumulative-methods>
       </python-wrap>
     </hypothesis>
index 60bffad999665dc173c835df52f864905e7e0eaf..7754191c57702d038f22d7f1ee8c9c267bf1bacb 100644 (file)
@@ -424,6 +424,95 @@ class BLSURF_Algorithm(Mesh_Algorithm):
       pass
     return self.params
 
+  #-----------------------------------------
+  # Periodicity (BLSURF with PreCAD)
+  #-----------------------------------------
+  
+  ## Defines periodicity between two groups of faces, using PreCAD
+  #  @param theFace1 : GEOM face (or group, compound) to associate with theFace2
+  #  @param theFace2 : GEOM face (or group, compound) associated with theFace1
+  #  @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
+  #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
+  #  @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
+  #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
+  def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
+    """calls preCad function:
+    status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
+          integer *fid1, integer size1, integer *fid2, integer size2,
+          periodicity_transformation_t transf, void *user data);
+    """
+    if theSourceVertices and theTargetVertices:
+      self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
+    else:
+      self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
+    pass
+
+  ## Defines periodicity between two groups of edges, using PreCAD
+  #  @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
+  #  @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
+  #  @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
+  #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
+  #  @param  theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
+  #    If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
+  def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
+    """calls preCad function:
+    status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
+          integer *eid1, integer size1, integer *eid2, integer size2,
+          periodicity_transformation_t transf, void *user data);
+    """
+    if theSourceVertices and theTargetVertices:
+        self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
+    else:
+        self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
+    pass
+
+
+  #-----------------------------------------
+  # Periodicity (BLSURF without PreCAD)
+  #-----------------------------------------
+
+
+  ## Defines periodicity between two faces, without using PreCAD.
+  #  User has to call AddEdgePeriodicity with the edges of the face,
+  #  and AddVertexPeriodicity with the vertices of each edge.
+  #  @param theFace1 : GEOM face to associate with theFace2
+  #  @param theFace2 : GEOM face associated with theFace1
+  def AddFacePeriodicity(self, theFace1, theFace2):
+    self.Parameters().AddFacePeriodicity(theFace1, theFace2)
+    pass
+      
+  ## Defines periodicity between two edges belonging to two periodic faces, without using PreCAD.
+  #  To be used with AddFacePeriodicity.
+  #  User has to call AddVertexPeriodicity with the vertices of each edge
+  #  @param theFace1 : GEOM face to associate with theFace2
+  #  @param theEdge1 : GEOM edge to associate with theEdge2
+  #  @param theFace2 : GEOM face associated with theFace1
+  #  @param theEdge2 : GEOM edge associated with theEdge1
+  #  @param theEdgeOrientation : -1 (reversed), 0 (unknown) or 1 (forward)
+  def AddEdgePeriodicity(self, theFace1, theEdge1, theFace2, theEdge2, theEdgeOrientation=0):
+    self.Parameters().AddEdgePeriodicity(theFace1, theEdge1, theFace2, theEdge2, theEdgeOrientation)
+    pass
+
+  ## Defines periodicity between two edges without face periodicity, without using PreCAD.
+  #  User has to call AddVertexPeriodicity with the vertices of each edge.
+  #  @param theEdge1 : GEOM edge to associate with theEdge2
+  #  @param theEdge2 : GEOM edge associated with theEdge1
+  #  @param theEdgeOrientation : -1 (reversed), 0 (unknown) or 1 (forward)
+  def AddEdgePeriodicityWithoutFaces(self, theEdge1, theEdge2, theEdgeOrientation=0):
+    self.Parameters().AddEdgePeriodicityWithoutFaces(theEdge1, theEdge2, theEdgeOrientation)
+    pass
+      
+  ## Defines periodicity between two vertices.
+  #  To be used with AddFacePeriodicity and AddEdgePeriodicity.
+  #  @param theEdge1 : GEOM edge to associate with theEdge2
+  #  @param theVertex1 : GEOM face to associate with theVertex2
+  #  @param theEdge2 : GEOM edge associated with theEdge1
+  #  @param theVertex2 : GEOM face associated with theVertex1
+  def AddVertexPeriodicity(self, theEdge1, theVertex1, theEdge2, theVertex2):
+    self.Parameters().AddVertexPeriodicity(theEdge1, theVertex1, theEdge2, theVertex2)
+    pass
+
+
   #=====================
   # Obsolete methods
   #=====================
index a32f622143b7a6b96209dedaf5a109f390c6c8ee..25610e56a4780b8a266ce8ddcea33e170d4dccd6 100644 (file)
@@ -689,6 +689,215 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction
 //     MESSAGE("point OK");
 }
 
+// One sub-shape to get ids from
+BLSURFPlugin_BLSURF::TListOfIDs _getSubShapeIDsInMainShape(TopoDS_Shape theMainShape, TopoDS_Shape theSubShape,
+    TopAbs_ShapeEnum theShapeType)
+{
+  BLSURFPlugin_BLSURF::TListOfIDs face_ids;
+  TopTools_IndexedMapOfShape anIndices;
+  anIndices.Clear();
+  TopExp::MapShapes(theMainShape, theShapeType, anIndices);
+
+//  Standard_Boolean result = BRepTools::Write(theMainShape,"main_shape.brep");
+
+  for (TopExp_Explorer face_iter(theSubShape,theShapeType);face_iter.More();face_iter.Next())
+    {
+      int face_id = anIndices.FindIndex(face_iter.Current());
+      if (face_id == 0)
+        throw SALOME_Exception ( SMESH_Comment("Sub_shape not found in main_shape"));
+      face_ids.push_back(face_id);
+//      std::ostringstream o;
+//      o << "face_" << face_id << ".brep";
+//      std::string face_name = o.str();
+//      const TopoDS_Face& face = TopoDS::Face(face_iter.Current());
+//      Standard_Boolean result = BRepTools::Write(face,face_name.c_str());
+    }
+
+  return face_ids;
+}
+
+void BLSURFPlugin_BLSURF::addCoordsFromVertex(BLSURFPlugin_Hypothesis::TEntry theVertexEntry, std::vector<double> &theVerticesCoords)
+{
+  if (theVertexEntry!="")
+    {
+      TopoDS_Shape aShape = entryToShape(theVertexEntry);
+
+      gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
+      double theX, theY, theZ;
+      theX = aPnt.X();
+      theY = aPnt.Y();
+      theZ = aPnt.Z();
+
+      theVerticesCoords.push_back(theX);
+      theVerticesCoords.push_back(theY);
+      theVerticesCoords.push_back(theZ);
+    }
+}
+
+/////////////////////////////////////////////////////////
+void BLSURFPlugin_BLSURF::createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity)
+{
+  MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity");
+
+  TopoDS_Shape geomShape1 = entryToShape(preCadPeriodicity.shape1Entry);
+  TopoDS_Shape geomShape2 = entryToShape(preCadPeriodicity.shape2Entry);
+
+  TListOfIDs theFace1_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape1, TopAbs_FACE);
+  TListOfIDs theFace2_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape2, TopAbs_FACE);
+
+  TPreCadPeriodicityIDs preCadFacesPeriodicityIDs;
+  preCadFacesPeriodicityIDs.shape1IDs = theFace1_ids;
+  preCadFacesPeriodicityIDs.shape2IDs = theFace2_ids;
+
+  for (size_t i = 0; i<preCadPeriodicity.theSourceVerticesEntries.size(); i++)
+    addCoordsFromVertex(preCadPeriodicity.theSourceVerticesEntries[i], preCadFacesPeriodicityIDs.theSourceVerticesCoords);
+
+  for (size_t i = 0; i<preCadPeriodicity.theTargetVerticesEntries.size(); i++)
+    addCoordsFromVertex(preCadPeriodicity.theTargetVerticesEntries[i], preCadFacesPeriodicityIDs.theTargetVerticesCoords);
+
+
+  _preCadFacesIDsPeriodicityVector.push_back(preCadFacesPeriodicityIDs);
+  MESSAGE("_preCadFacesIDsPeriodicityVector.size() = " << _preCadFacesIDsPeriodicityVector.size());
+  MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity END");
+
+}
+
+/////////////////////////////////////////////////////////
+void BLSURFPlugin_BLSURF::createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity)
+{
+  MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity");
+
+  TopoDS_Shape geomShape1 = entryToShape(preCadPeriodicity.shape1Entry);
+  TopoDS_Shape geomShape2 = entryToShape(preCadPeriodicity.shape2Entry);
+
+  TListOfIDs theEdge1_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape1, TopAbs_EDGE);
+  TListOfIDs theEdge2_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape2, TopAbs_EDGE);
+
+  TPreCadPeriodicityIDs preCadEdgesPeriodicityIDs;
+  preCadEdgesPeriodicityIDs.shape1IDs = theEdge1_ids;
+  preCadEdgesPeriodicityIDs.shape2IDs = theEdge2_ids;
+
+  for (size_t i = 0; i<preCadPeriodicity.theSourceVerticesEntries.size(); i++)
+    addCoordsFromVertex(preCadPeriodicity.theSourceVerticesEntries[i], preCadEdgesPeriodicityIDs.theSourceVerticesCoords);
+
+  for (size_t i = 0; i<preCadPeriodicity.theTargetVerticesEntries.size(); i++)
+    addCoordsFromVertex(preCadPeriodicity.theTargetVerticesEntries[i], preCadEdgesPeriodicityIDs.theTargetVerticesCoords);
+
+
+  _preCadEdgesIDsPeriodicityVector.push_back(preCadEdgesPeriodicityIDs);
+  MESSAGE("_preCadEdgesIDsPeriodicityVector.size() = " << _preCadEdgesIDsPeriodicityVector.size());
+  MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity END");
+
+}
+
+/////////////////////////////////////////////////////////
+void BLSURFPlugin_BLSURF::createFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theFace1,  BLSURFPlugin_Hypothesis::TEntry theFace2)
+{
+  MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity");
+
+  TopoDS_Shape GeomShape1 = entryToShape(theFace1);
+  TopoDS_Shape GeomShape2 = entryToShape(theFace2);
+
+  TListOfIDs theFace1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomShape1, TopAbs_FACE);
+  TListOfIDs theFace2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomShape2, TopAbs_FACE);
+
+  // Only one face id, since only a face can be selected
+  int theFace1_id = theFace1_ids[0];
+  int theFace2_id = theFace2_ids[0];
+
+  std::pair<int, int> pairOfFacesID = std::make_pair(theFace1_id, theFace2_id);
+
+  _facesIDsPeriodicityVector.push_back(pairOfFacesID);
+  MESSAGE("_facesIDsPeriodicityVector.size() = " << _facesIDsPeriodicityVector.size());
+  MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity END");
+
+}
+
+
+/////////////////////////////////////////////////////////
+void BLSURFPlugin_BLSURF::createEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theFace1, BLSURFPlugin_Hypothesis::TEntry theEdge1,
+    BLSURFPlugin_Hypothesis::TEntry theFace2, BLSURFPlugin_Hypothesis::TEntry theEdge2, int edge_orientation)
+{
+  MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity");
+
+  TEdgePeriodicityIDs edgePeriodicityIDs;
+
+  if (theFace1 != "")
+    {
+      TopoDS_Shape GeomFace1 = entryToShape(theFace1);
+      TListOfIDs theFace1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomFace1, TopAbs_FACE);
+      // Only one face id, since only a face can be selected
+      edgePeriodicityIDs.theFace1ID = theFace1_ids[0];
+    }
+  else
+    edgePeriodicityIDs.theFace1ID = 0;
+  if (theFace2 != "")
+    {
+      TopoDS_Shape GeomFace2 = entryToShape(theFace2);
+      TListOfIDs theFace2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomFace2, TopAbs_FACE);
+      edgePeriodicityIDs.theFace2ID = theFace2_ids[0];
+    }
+  else
+    edgePeriodicityIDs.theFace2ID = 0;
+
+  TopoDS_Shape GeomEdge1 = entryToShape(theEdge1);
+  TopoDS_Shape GeomEdge2 = entryToShape(theEdge2);
+
+  TListOfIDs theEdge1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge1, TopAbs_EDGE);
+  TListOfIDs theEdge2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge2, TopAbs_EDGE);
+
+  if (edge_orientation == 0 and GeomEdge1.Closed())
+    {
+      // if edge is closed, we have to set its orientation
+      MESSAGE("GeomEdge1.Orientation() = " << GeomEdge1.Orientation());
+      MESSAGE("GeomEdge2.Orientation() = " << GeomEdge2.Orientation());
+      if(GeomEdge1.Orientation() == TopAbs_FORWARD)
+        edge_orientation = CAD_ORIENTATION_REVERSED;
+      else
+        edge_orientation = CAD_ORIENTATION_FORWARD;
+    }
+
+  // Only one edge id, since only a edge can be selected
+  edgePeriodicityIDs.theEdge1ID = theEdge1_ids[0];
+  edgePeriodicityIDs.theEdge2ID = theEdge2_ids[0];
+  edgePeriodicityIDs.edge_orientation = edge_orientation;
+
+  _edgesIDsPeriodicityVector.push_back(edgePeriodicityIDs);
+  MESSAGE("_edgesIDsPeriodicityVector.size() = " << _edgesIDsPeriodicityVector.size());
+  MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity END");
+
+}
+
+
+/////////////////////////////////////////////////////////
+void BLSURFPlugin_BLSURF::createVerticesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theEdge1, BLSURFPlugin_Hypothesis::TEntry theVertex1,
+    BLSURFPlugin_Hypothesis::TEntry theEdge2, BLSURFPlugin_Hypothesis::TEntry theVertex2)
+{
+  MESSAGE("BLSURFPlugin_BLSURF::createVerticesPeriodicity");
+
+  TopoDS_Shape GeomEdge1 = entryToShape(theEdge1);
+  TopoDS_Shape GeomVertex1 = entryToShape(theVertex1);
+  TopoDS_Shape GeomEdge2 = entryToShape(theEdge2);
+  TopoDS_Shape GeomVertex2 = entryToShape(theVertex2);
+
+  TListOfIDs theEdge1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge1, TopAbs_EDGE);
+  TListOfIDs vertices1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomVertex1, TopAbs_VERTEX);
+  TListOfIDs theEdge2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge2, TopAbs_EDGE);
+  TListOfIDs vertices2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomVertex2, TopAbs_VERTEX);
+
+  // Only one vertex id, since only a vertex can be selected
+  TVertexPeriodicityIDs vertexPeriodicityIDs;
+  vertexPeriodicityIDs.theEdge1ID = theEdge1_ids[0];
+  vertexPeriodicityIDs.theVertex1ID = vertices1_ids[0];
+  vertexPeriodicityIDs.theEdge2ID = theEdge2_ids[0];
+  vertexPeriodicityIDs.theVertex2ID = vertices2_ids[0];
+
+  _verticesIDsPeriodicityVector.push_back(vertexPeriodicityIDs);
+  MESSAGE("_verticesIDsPeriodicityVector.size() = " << _verticesIDsPeriodicityVector.size());
+  MESSAGE("BLSURFPlugin_BLSURF::createVerticesPeriodicity END");
+
+}
+
 /////////////////////////////////////////////////////////
 
 void BLSURFPlugin_BLSURF::SetParameters(
@@ -1201,6 +1410,72 @@ void BLSURFPlugin_BLSURF::SetParameters(
 // #endif
     }
   }
+
+  // PERIODICITY
+
+   // reset vectors
+   _preCadFacesIDsPeriodicityVector.clear();
+   _preCadEdgesIDsPeriodicityVector.clear();
+   _facesIDsPeriodicityVector.clear();
+   _edgesIDsPeriodicityVector.clear();
+   _verticesIDsPeriodicityVector.clear();
+
+  MESSAGE("SetParameters preCadFacesPeriodicityVector");
+  const BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector preCadFacesPeriodicityVector = BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(hyp);
+
+  for (std::size_t i = 0; i<preCadFacesPeriodicityVector.size(); i++){
+    MESSAGE("SetParameters preCadFacesPeriodicityVector[" << i << "]");
+    createPreCadFacesPeriodicity(theGeomShape, preCadFacesPeriodicityVector[i]);
+  }
+  MESSAGE("_preCadFacesIDsPeriodicityVector.size() = " << _preCadFacesIDsPeriodicityVector.size());
+
+  MESSAGE("SetParameters preCadEdgesPeriodicityVector");
+  const BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector preCadEdgesPeriodicityVector = BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(hyp);
+
+  for (std::size_t i = 0; i<preCadEdgesPeriodicityVector.size(); i++){
+    MESSAGE("SetParameters preCadEdgesPeriodicityVector[" << i << "]");
+    createPreCadEdgesPeriodicity(theGeomShape, preCadEdgesPeriodicityVector[i]);
+  }
+  MESSAGE("_preCadEdgesIDsPeriodicityVector.size() = " << _preCadEdgesIDsPeriodicityVector.size());
+
+  if ( _preCadFacesIDsPeriodicityVector.size() > 0 or _preCadEdgesIDsPeriodicityVector.size() > 0 )
+    {
+      MESSAGE("USING PRECAD FOR PERIODICITY")
+      *use_precad = true;
+      precad_set_param(pcs, "verbose",                to_string(_verb).c_str());
+    }
+
+  MESSAGE("SetParameters facesPeriodicityVector");
+  const BLSURFPlugin_Hypothesis::TFacesPeriodicityVector facesPeriodicityVector = BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(hyp);
+
+  for (std::size_t i = 0; i<facesPeriodicityVector.size(); i++){
+    MESSAGE("SetParameters facesPeriodicityVector[" << i << "]");
+    createFacesPeriodicity(theGeomShape, facesPeriodicityVector[i].first, facesPeriodicityVector[i].second);
+  }
+  MESSAGE("_facesIDsPeriodicityVector.size() = " << _facesIDsPeriodicityVector.size());
+
+
+  MESSAGE("SetParameters edgesPeriodicityVector");
+  const BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector edgesPeriodicityVector = BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(hyp);
+
+  for (std::size_t i = 0; i<edgesPeriodicityVector.size(); i++){
+    MESSAGE("SetParameters edgesPeriodicityVector[" << i << "]");
+    // TODO: passer directement en paramètre edgesPeriodicityVector[i] plutôt que tous ces attributs
+    createEdgesPeriodicity(theGeomShape, edgesPeriodicityVector[i].theFace1Entry, edgesPeriodicityVector[i].theEdge1Entry,
+        edgesPeriodicityVector[i].theFace2Entry, edgesPeriodicityVector[i].theEdge2Entry, edgesPeriodicityVector[i].edge_orientation);
+  }
+  MESSAGE("_edgesIDsPeriodicityVector.size() = " << _edgesIDsPeriodicityVector.size());
+
+  MESSAGE("SetParameters verticesPeriodicityVector");
+  const BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector verticesPeriodicityVector = BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(hyp);
+
+  for (std::size_t i = 0; i<verticesPeriodicityVector.size(); i++){
+    MESSAGE("SetParameters verticesPeriodicityVector[" << i << "]");
+    // TODO: passer directement en paramètre verticesPeriodicityVector[i] plutôt que tous ces attributs
+    createVerticesPeriodicity(theGeomShape, verticesPeriodicityVector[i].theEdge1Entry, verticesPeriodicityVector[i].theVertex1Entry,
+        verticesPeriodicityVector[i].theEdge2Entry, verticesPeriodicityVector[i].theVertex2Entry);
+  }
+  MESSAGE("_verticesIDsPeriodicityVector.size() = " << _verticesIDsPeriodicityVector.size());
 }
 
 //================================================================================
@@ -1242,15 +1517,21 @@ namespace
     cadsurf_session_t* _css;
     cad_t *           _cad;
     dcad_t *          _dcad;
+    cad_t *           _cleanc;
+    dcad_t *          _cleandc;
   public:
     BLSURF_Cleaner(context_t *       ctx,
                    cadsurf_session_t* css,
                    cad_t *           cad,
-                   dcad_t *          dcad)
+                   dcad_t *          dcad,
+                   cad_t *           cleanc,
+                   dcad_t *          cleandc)
       : _ctx ( ctx  ),
         _css ( css  ),
         _cad ( cad  ),
-        _dcad( dcad )
+        _dcad( dcad ),
+        _cleanc( cleanc ),
+        _cleandc( cleandc )
     {
     }
     ~BLSURF_Cleaner()
@@ -1289,6 +1570,8 @@ namespace
 
         cad_delete(_cad); _cad = 0;
         dcad_delete(_dcad); _dcad = 0;
+        cad_delete(_cleanc); _cleanc = 0;
+        dcad_delete(_cleandc); _cleandc = 0;
         if ( !exceptContext )
         {
           context_delete(_ctx); _ctx = 0;
@@ -1692,13 +1975,16 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
   // PreCAD
   // If user requests it, send the CAD through Distene preprocessor : PreCAD
   cad_t *cleanc = NULL; // preprocessed cad
+  dcad_t *cleandc = NULL; // preprocessed dcad
   precad_session_t *pcs = precad_session_new(ctx);
+  // Give both dcad and cad to precad
+  precad_data_set_dcad(pcs, dcad);
   precad_data_set_cad(pcs, c);
 
   cadsurf_session_t *css = cadsurf_session_new(ctx);
 
   // an object that correctly deletes all cadsurf objects at destruction
-  BLSURF_Cleaner cleaner( ctx,css,c,dcad );
+  BLSURF_Cleaner cleaner( ctx,css,c,dcad,cleanc,cleandc );
 
   MESSAGE("BEGIN SetParameters");
   bool use_precad = false;
@@ -1709,6 +1995,8 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
                 _hypothesis, css, pcs, aShape, &use_precad);
   MESSAGE("END SetParameters");
 
+  MESSAGE("_preCadFacesIDsPeriodicityVector.size() = " << _preCadFacesIDsPeriodicityVector.size());
+
   haveQuadraticSubMesh = haveQuadraticSubMesh || (_hypothesis != NULL && _hypothesis->GetQuadraticMesh());
   helper.SetIsQuadratic( haveQuadraticSubMesh );
 
@@ -1759,6 +2047,10 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
     if (fmap.FindIndex(f) > 0)
       continue;
     iface = fmap.Add(f);
+//    std::string aFileName = "fmap_face_";
+//    aFileName.append(to_string(iface));
+//    aFileName.append(".brep");
+//    BRepTools::Write(f,aFileName.c_str());
 
     surfaces.push_back(BRep_Tool::Surface(f));
 
@@ -1952,6 +2244,11 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
       if (ic <= 0)
         ic = emap.Add(e);
 
+//      std::string aFileName = "fmap_edge_";
+//      aFileName.append(to_string(ic));
+//      aFileName.append(".brep");
+//      BRepTools::Write(e,aFileName.c_str());
+
       double tmin,tmax;
       curves.push_back(BRep_Tool::CurveOnSurface(e, f, tmin, tmax));
 
@@ -2079,6 +2376,12 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
           if ( sm->IsMeshComputed() )
             edgeSubmeshes.insert( sm->GetSubMeshDS() );
         }
+
+//        std::string aFileName = "fmap_vertex_";
+//        aFileName.append(to_string(*ip));
+//        aFileName.append(".brep");
+//        BRepTools::Write(v,aFileName.c_str());
+
         if (HasSizeMapOnVertex){
           vertexKey = VerticesWithSizeMap.FindIndex(v);
           if (VertexId2SizeMap.find(vertexKey)!=VertexId2SizeMap.end()){
@@ -2147,20 +2450,208 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
     }
   }
 
+  ///////////////////////
+  // PERIODICITY       //
+  ///////////////////////
+
+  MESSAGE("BEFORE PERIODICITY");
+  MESSAGE("_preCadFacesIDsPeriodicityVector.size() = " << _preCadFacesIDsPeriodicityVector.size());
+  if (! _preCadFacesIDsPeriodicityVector.empty()){
+    MESSAGE("INTO PRECAD FACES PERIODICITY");
+    for (std::size_t i=0; i < _preCadFacesIDsPeriodicityVector.size(); i++){
+      std::vector<int> theFace1_ids = _preCadFacesIDsPeriodicityVector[i].shape1IDs;
+      std::vector<int> theFace2_ids = _preCadFacesIDsPeriodicityVector[i].shape2IDs;
+      int* theFace1_ids_c = &theFace1_ids[0];
+      int* theFace2_ids_c = &theFace2_ids[0];
+      std::ostringstream o;
+      o << "_preCadFacesIDsPeriodicityVector[" << i << "] = [";
+      for (std::size_t j=0; j < theFace1_ids.size(); j++)
+        o << theFace1_ids[j] << ", ";
+      o << "], [";
+      for (std::size_t j=0; j < theFace2_ids.size(); j++)
+        o << theFace2_ids[j] << ", ";
+      o << "]";
+      MESSAGE(o.str());
+      MESSAGE("theFace1_ids.size(): " << theFace1_ids.size());
+      MESSAGE("theFace2_ids.size(): " << theFace2_ids.size());
+      if (_preCadFacesIDsPeriodicityVector[i].theSourceVerticesCoords.empty())
+        {
+          // If no source points, call peridoicity without transformation function
+          MESSAGE("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);
+          if(status != STATUS_OK)
+            cout << "cad_add_face_multiple_periodicity_with_transformation_function failed with error code " << status << "\n";
+        }
+      else
+        {
+          // get the transformation vertices
+          MESSAGE("periodicity with transformation vertices");
+          double* theSourceVerticesCoords_c = &_preCadFacesIDsPeriodicityVector[i].theSourceVerticesCoords[0];
+          double* theTargetVerticesCoords_c = &_preCadFacesIDsPeriodicityVector[i].theTargetVerticesCoords[0];
+          int nbSourceVertices = _preCadFacesIDsPeriodicityVector[i].theSourceVerticesCoords.size()/3;
+          int nbTargetVertices = _preCadFacesIDsPeriodicityVector[i].theTargetVerticesCoords.size()/3;
+
+          MESSAGE("nbSourceVertices: " << nbSourceVertices << ", nbTargetVertices: " << nbTargetVertices);
+
+          status = cad_add_face_multiple_periodicity_with_transformation_function_by_points(c, theFace1_ids_c, theFace1_ids.size(),
+              theFace2_ids_c, theFace2_ids.size(), theSourceVerticesCoords_c, nbSourceVertices, theTargetVerticesCoords_c, nbTargetVertices);
+          if(status != STATUS_OK)
+            cout << "cad_add_face_multiple_periodicity_with_transformation_function_by_points failed with error code " << status << "\n";
+        }
+    }
+
+    MESSAGE("END PRECAD FACES PERIODICITY");
+  }
+
+  MESSAGE("_preCadEdgesIDsPeriodicityVector.size() = " << _preCadEdgesIDsPeriodicityVector.size());
+  if (! _preCadEdgesIDsPeriodicityVector.empty()){
+    MESSAGE("INTO PRECAD EDGES PERIODICITY");
+    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
+      int* theEdge1_ids_c = &theEdge1_ids[0];
+      int* theEdge2_ids_c = &theEdge2_ids[0];
+
+      std::ostringstream o;
+      o << "_preCadEdgesIDsPeriodicityVector[" << i << "] = [";
+      for (std::size_t j=0; j < theEdge1_ids.size(); j++)
+        o << theEdge1_ids[j] << ", ";
+      o << "], [";
+      for (std::size_t j=0; j < theEdge2_ids.size(); j++)
+        o << theEdge2_ids[j] << ", ";
+      o << "]";
+      MESSAGE(o.str());
+      MESSAGE("theEdge1_ids.size(): " << theEdge1_ids.size());
+      MESSAGE("theEdge2_ids.size(): " << theEdge2_ids.size());
+
+      if (_preCadEdgesIDsPeriodicityVector[i].theSourceVerticesCoords.empty())
+        {
+          // If no source points, call peridoicity without transformation function
+          MESSAGE("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);
+          if(status != STATUS_OK)
+            cout << "cad_add_edge_multiple_periodicity_with_transformation_function failed with error code " << status << "\n";
+        }
+      else
+        {
+          // get the transformation vertices
+          MESSAGE("periodicity with transformation vertices");
+          double* theSourceVerticesCoords_c = &_preCadEdgesIDsPeriodicityVector[i].theSourceVerticesCoords[0];
+          double* theTargetVerticesCoords_c = &_preCadEdgesIDsPeriodicityVector[i].theTargetVerticesCoords[0];
+          int nbSourceVertices = _preCadEdgesIDsPeriodicityVector[i].theSourceVerticesCoords.size()/3;
+          int nbTargetVertices = _preCadEdgesIDsPeriodicityVector[i].theTargetVerticesCoords.size()/3;
+
+          MESSAGE("nbSourceVertices: " << nbSourceVertices << ", nbTargetVertices: " << nbTargetVertices);
+
+          status = cad_add_edge_multiple_periodicity_with_transformation_function_by_points(c, theEdge1_ids_c, theEdge1_ids.size(),
+              theEdge2_ids_c, theEdge2_ids.size(), theSourceVerticesCoords_c, nbSourceVertices, theTargetVerticesCoords_c, nbTargetVertices);
+          if(status != STATUS_OK)
+            cout << "cad_add_edge_multiple_periodicity_with_transformation_function_by_points failed with error code " << status << "\n";
+          else
+            MESSAGE("cad_add_edge_multiple_periodicity_with_transformation_function_by_points succeeded.\n");
+        }
+    }
+
+    MESSAGE("END PRECAD EDGES PERIODICITY");
+  }
+
+  if (! _facesIDsPeriodicityVector.empty()){
+    MESSAGE("INTO FACE PERIODICITY");
+    for (std::size_t i=0; i < _facesIDsPeriodicityVector.size(); i++){
+      int theFace1 = _facesIDsPeriodicityVector[i].first;
+      int theFace2 = _facesIDsPeriodicityVector[i].second;
+      MESSAGE("_facesIDsPeriodicityVector[" << i << "] = (" << theFace1 << ", " << theFace2 << ")");
+      status = cad_add_face_periodicity(c, theFace1, theFace2);
+      if(status != STATUS_OK){
+        cout << "cad_add_face_periodicity failed with error code " << status << "\n";
+      }
+    }
+    MESSAGE("END FACE PERIODICITY");
+  }
+
+
+  if (! _edgesIDsPeriodicityVector.empty()){
+    MESSAGE("INTO EDGE PERIODICITY");
+    for (std::size_t i=0; i < _edgesIDsPeriodicityVector.size(); i++){
+      int theFace1 = _edgesIDsPeriodicityVector[i].theFace1ID;
+      int theEdge1 = _edgesIDsPeriodicityVector[i].theEdge1ID;
+      int theFace2 = _edgesIDsPeriodicityVector[i].theFace2ID;
+      int theEdge2 = _edgesIDsPeriodicityVector[i].theEdge2ID;
+      int edge_orientation = _edgesIDsPeriodicityVector[i].edge_orientation;
+      MESSAGE("_edgesIDsPeriodicityVector[" << i << "] = (" << theFace1 << ", " << theEdge1 << ", " << theFace2 << ", " << theEdge2 << ", " << edge_orientation << ")");
+      status = cad_add_edge_periodicity(c, theFace1, theEdge1, theFace2, theEdge2, edge_orientation);
+      if(status != STATUS_OK){
+        cout << "cad_add_edge_periodicity failed with error code " << status << "\n";
+      }
+    }
+    MESSAGE("END EDGE PERIODICITY");
+  }
+
+  if (! _verticesIDsPeriodicityVector.empty()){
+    MESSAGE("INTO VERTEX PERIODICITY");
+    for (std::size_t i=0; i < _verticesIDsPeriodicityVector.size(); i++){
+      int theEdge1 = _verticesIDsPeriodicityVector[i].theEdge1ID;
+      int theVertex1 = _verticesIDsPeriodicityVector[i].theVertex1ID;
+      int theEdge2 = _verticesIDsPeriodicityVector[i].theEdge2ID;
+      int theVertex2 = _verticesIDsPeriodicityVector[i].theVertex2ID;
+      MESSAGE("_verticesIDsPeriodicityVector[" << i << "] = (" << theEdge1 << ", " << theVertex1 << ", " << theEdge2 << ", " << theVertex2 << ")");
+      status = cad_add_point_periodicity(c, theEdge1, theVertex1, theEdge2, theVertex2);
+      if(status != STATUS_OK){
+        cout << "cad_add_vertex_periodicity failed with error code " << status << "\n";
+      }
+    }
+    MESSAGE("END VERTEX PERIODICITY");
+  }
+
+    ////
 
   if (use_precad) {
+    MESSAGE("use_precad");
     /* Now launch the PreCAD process */
     status = precad_process(pcs);
     if(status != STATUS_OK){
-      cout << "PreCAD processing failed with error code " << status << "\n";
+      // TODO: raise an error if status < 0.
+      cout << "================ WARNING =================== \n";
+      stringstream msg;
+      msg << "PreCAD processing failed with error code " << status << "\n";
+      msg << *mcud._error;
+      cout << msg.str();
+      cout << "============================================ \n";
+      // the text of _comment is set in message_cb by mcud->_error
+      // => No need to append msg to _comment
+      if (status > 0)
+        {
+          // TODO: fix the SIGSEGV of COMPERR_WARNING with 2 launches
+          error(COMPERR_WARNING, _comment);
+        }
+      if (status < 0)
+        {
+          error(_comment);
+        }
     }
     else {
       // retrieve the pre-processed CAD object
+
+      // dcad
+      cleandc = precad_new_dcad(pcs);
+      if(!cleandc){
+        cout << "Unable to retrieve PreCAD result on dcad \n";
+      }
+      else
+        cout << "PreCAD processing successfull on dcad \n";
+
+      // cad
       cleanc = precad_new_cad(pcs);
       if(!cleanc){
-        cout << "Unable to retrieve PreCAD result \n";
+        cout << "Unable to retrieve PreCAD result on cad \n";
       }
-      cout << "PreCAD processing successfull \n";
+      else
+        cout << "PreCAD processing successfull on cad \n";
 
       // #if BLSURF_VERSION_LONG >= "3.1.1"
       //       /* We can now get the updated sizemaps (if any) */
@@ -2184,9 +2675,18 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
     precad_session_delete(pcs);
   }
 
-  cadsurf_data_set_dcad(css, dcad);
+  if (cleandc) {
+    cout << "Give the pre-processed dcad object to the current BLSurf session \n";
+    cadsurf_data_set_dcad(css, cleandc);
+  }
+  else {
+    // Use the original one
+    cadsurf_data_set_dcad(css, dcad);
+  }
+
   if (cleanc) {
     // Give the pre-processed CAD object to the current BLSurf session
+    cout << "Give the pre-processed CAD object to the current BLSurf session \n";
     cadsurf_data_set_cad(css, cleanc);
   }
   else {
@@ -2843,7 +3343,8 @@ status_t message_cb(message_t *msg, void *user_data)
   message_get_description(msg, &desc);
   string err( desc );
   message_cb_user_data * mcud = (message_cb_user_data*)user_data;
-  if ( errnumber < 0 || err.find("license") != string::npos ) {
+  // Get all the error message and some warning messages related to license and periodicity
+  if ( errnumber < 0 || err.find("license") != string::npos || err.find("periodicity") != string::npos ) {
     // remove ^A from the tail
     int len = strlen( desc );
     while (len > 0 && desc[len-1] != '\n')
index 5ebbd56019fd7d96767b08a272b3e57384c0bc3e..dd6c55b7a1ec6fe865c3f67b3dc5caa6db481721 100644 (file)
@@ -94,10 +94,53 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
     virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
                           MapShapeNbElems& aResMap);
 
+    // List of ids
+    typedef std::vector<int> TListOfIDs;
+
+    // PreCad Edges periodicity
+    struct TPreCadPeriodicityIDs {
+      TListOfIDs shape1IDs;
+      TListOfIDs shape2IDs;
+      std::vector<double> theSourceVerticesCoords;
+      std::vector<double> theTargetVerticesCoords;
+    };
+
+    // Edge periodicity
+    struct TEdgePeriodicityIDs {
+      int theFace1ID;
+      int theEdge1ID;
+      int theFace2ID;
+      int theEdge2ID;
+      int edge_orientation;
+    };
+
+    // Vertex periodicity
+    struct TVertexPeriodicityIDs {
+      int theEdge1ID;
+      int theVertex1ID;
+      int theEdge2ID;
+      int theVertex2ID;
+    };
+
+    // Vector of pairs of ids
+    typedef std::vector< TPreCadPeriodicityIDs > TPreCadIDsPeriodicityVector;
+    typedef std::vector< std::pair<int, int> > TShapesIDsPeriodicityVector;
+    typedef std::vector< TEdgePeriodicityIDs > TEdgesIDsPeriodicityVector;
+    typedef std::vector< TVertexPeriodicityIDs > TVerticesIDsPeriodicityVector;
+
+
+
   protected:
     const BLSURFPlugin_Hypothesis* _hypothesis;
     bool                           _haveViscousLayers;
 
+    TPreCadIDsPeriodicityVector _preCadFacesIDsPeriodicityVector;
+    TPreCadIDsPeriodicityVector _preCadEdgesIDsPeriodicityVector;
+
+    TShapesIDsPeriodicityVector _facesIDsPeriodicityVector;
+    TEdgesIDsPeriodicityVector _edgesIDsPeriodicityVector;
+    TVerticesIDsPeriodicityVector _verticesIDsPeriodicityVector;
+
   private:
     bool compute(SMESH_Mesh&          aMesh,
                  const TopoDS_Shape&  aShape);
@@ -107,7 +150,15 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
                    const char *       option_value);
 
     TopoDS_Shape entryToShape(std::string entry);
+    void addCoordsFromVertex(BLSURFPlugin_Hypothesis::TEntry theVertexEntry, std::vector<double> &theVerticesCoords);
     void createEnforcedVertexOnFace(TopoDS_Shape FaceShape, BLSURFPlugin_Hypothesis::TEnfVertexList enfVertexList);
+    void createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity);
+    void createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity);
+    void createFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theFace1,  BLSURFPlugin_Hypothesis::TEntry theFace2);
+    void createEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theFace1, BLSURFPlugin_Hypothesis::TEntry theEdge1,
+        BLSURFPlugin_Hypothesis::TEntry theFace2, BLSURFPlugin_Hypothesis::TEntry theEdge2, int edge_orientation = 0);
+    void createVerticesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theEdge1, BLSURFPlugin_Hypothesis::TEntry theVertex1,
+        BLSURFPlugin_Hypothesis::TEntry theEdge2, BLSURFPlugin_Hypothesis::TEntry theVertex2);
     void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, SMDS_MeshNode* node, const TopoDS_Shape& ed);
     void BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, const TopoDS_Face& face, const gp_Pnt& P, const Standard_Real Tol);
 
index 172b8988f164a257b448cb565e846494c3aad5f5..94a2695686484e5db790ac7a23ac0761df173533 100644 (file)
@@ -78,7 +78,9 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
   _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
   _GMFFileName(GetDefaultGMFFile()),
-  _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex())
+  _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
+  _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
+  _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector())
 {
   _name = "BLSURF_Parameters";
   _param_algo_dim = 2;
@@ -1203,6 +1205,116 @@ void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugi
   }
 }
 
+//=============================================================================
+BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
+    const BLSURFPlugin_Hypothesis* hyp) {
+  return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
+}
+
+//=============================================================================
+BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
+    const BLSURFPlugin_Hypothesis* hyp) {
+  return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
+}
+
+//=============================================================================
+BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
+    const BLSURFPlugin_Hypothesis* hyp) {
+  return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
+}
+
+//=============================================================================
+BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
+    const BLSURFPlugin_Hypothesis* hyp){
+  return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
+}
+
+//=============================================================================
+BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
+    const BLSURFPlugin_Hypothesis* hyp){
+  return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
+}
+
+//=======================================================================
+//function : AddPreCadFacesPeriodicity
+//=======================================================================
+void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
+    vector<TEntry> &theSourceVerticesEntries, vector<TEntry> &theTargetVerticesEntries) {
+
+  TPreCadPeriodicity preCadFacesPeriodicity;
+  preCadFacesPeriodicity.shape1Entry = theFace1Entry;
+  preCadFacesPeriodicity.shape2Entry = theFace2Entry;
+  preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
+  preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
+
+  _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
+
+  NotifySubMeshesHypothesisModification();
+}
+
+//=======================================================================
+//function : AddPreCadEdgesPeriodicity
+//=======================================================================
+void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
+    vector<TEntry> &theSourceVerticesEntries, vector<TEntry> &theTargetVerticesEntries) {
+
+  TPreCadPeriodicity preCadEdgesPeriodicity;
+  preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
+  preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
+  preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
+  preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
+
+  _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
+
+  NotifySubMeshesHypothesisModification();
+}
+
+//=======================================================================
+//function : AddFacePeriodicity
+//=======================================================================
+void BLSURFPlugin_Hypothesis::AddFacePeriodicity(TEntry theFace1Entry, TEntry theFace2Entry) {
+
+  std::pair< TEntry, TEntry > pairOfFacesEntries = std::make_pair(theFace1Entry, theFace2Entry);
+
+  _facesPeriodicityVector.push_back(pairOfFacesEntries);
+
+  NotifySubMeshesHypothesisModification();
+}
+
+
+//=======================================================================
+//function : AddEdgePeriodicity
+//=======================================================================
+void BLSURFPlugin_Hypothesis::AddEdgePeriodicity(TEntry theFace1Entry, TEntry theEdge1Entry, TEntry theFace2Entry, TEntry theEdge2Entry, int edge_orientation) {
+
+  TEdgePeriodicity edgePeriodicity;
+  edgePeriodicity.theFace1Entry = theFace1Entry;
+  edgePeriodicity.theEdge1Entry = theEdge1Entry;
+  edgePeriodicity.theFace2Entry = theFace2Entry;
+  edgePeriodicity.theEdge2Entry = theEdge2Entry;
+  edgePeriodicity.edge_orientation = edge_orientation;
+
+  _edgesPeriodicityVector.push_back(edgePeriodicity);
+
+  NotifySubMeshesHypothesisModification();
+}
+
+//=======================================================================
+//function : AddVertexPeriodicity
+//=======================================================================
+void BLSURFPlugin_Hypothesis::AddVertexPeriodicity(TEntry theEdge1Entry, TEntry theVertex1Entry, TEntry theEdge2Entry, TEntry theVertex2Entry) {
+
+  TVertexPeriodicity vertexPeriodicity;
+  vertexPeriodicity.theEdge1Entry = theEdge1Entry;
+  vertexPeriodicity.theVertex1Entry = theVertex1Entry;
+  vertexPeriodicity.theEdge2Entry = theEdge2Entry;
+  vertexPeriodicity.theVertex2Entry = theVertex2Entry;
+
+  _verticesPeriodicityVector.push_back(vertexPeriodicity);
+
+  NotifySubMeshesHypothesisModification();
+}
+
 //=============================================================================
 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
    // We must keep at least the same number of arguments when increasing the SALOME version
index 885bb90ec2e98266c4411aca5286237fd0deae33..ae1f40c8acf4b5d98ddc7cd5bdbcafeb7a3ba387 100644 (file)
@@ -216,6 +216,33 @@ public:
     }
   };
 
+  // PreCad Face and Edge periodicity
+  struct TPreCadPeriodicity {
+    TEntry shape1Entry;
+    TEntry shape2Entry;
+    std::vector<TEntry> theSourceVerticesEntries;
+    std::vector<TEntry> theTargetVerticesEntries;
+  };
+
+  // Edge periodicity
+  struct TEdgePeriodicity {
+    TEntry theFace1Entry;
+    TEntry theEdge1Entry;
+    TEntry theFace2Entry;
+    TEntry theEdge2Entry;
+    int edge_orientation;
+  };
+
+  // Vertex periodicity
+  struct TVertexPeriodicity {
+    TEntry theEdge1Entry;
+    TEntry theVertex1Entry;
+    TEntry theEdge2Entry;
+    TEntry theVertex2Entry;
+  };
+
+  typedef std::pair< TEntry, TEntry > TFacesPeriodicity;
+
   // List of enforced vertices
   typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
 
@@ -243,7 +270,13 @@ public:
   typedef std::map< TEnfGroupName , TEnfVertexList > TGroupNameEnfVertexListMap;
   */
 
+  // Vector of pairs of entries
+  typedef std::vector< TPreCadPeriodicity > TPreCadPeriodicityVector;
+  typedef std::vector< TFacesPeriodicity > TFacesPeriodicityVector;
+  typedef std::vector< TEdgePeriodicity > TEdgesPeriodicityVector;
+  typedef std::vector< TVertexPeriodicity > TVerticesPeriodicityVector;
   
+
   bool                  SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry, TEnfGroupName theGroupName,
                                           double x = 0.0, double y = 0.0, double z = 0.0);
   TEnfVertexList        GetEnfVertexList(const TEntry& theFaceEntry) throw (std::invalid_argument);
@@ -354,6 +387,35 @@ public:
   static TEnfVertexGroupNameMap     GetDefaultEnfVertexGroupNameMap() { return TEnfVertexGroupNameMap(); }
   */
 
+  static TPreCadPeriodicityVector GetDefaultPreCadFacesPeriodicityVector() { return TPreCadPeriodicityVector(); }
+  const TPreCadPeriodicityVector  _GetPreCadFacesPeriodicityVector() const { return _preCadFacesPeriodicityVector; }
+  static TPreCadPeriodicityVector GetPreCadFacesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp);
+
+  static TPreCadPeriodicityVector GetDefaultPreCadEdgesPeriodicityVector() { return TPreCadPeriodicityVector(); }
+  const TPreCadPeriodicityVector  _GetPreCadEdgesPeriodicityVector() const { return _preCadEdgesPeriodicityVector; }
+  static TPreCadPeriodicityVector GetPreCadEdgesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp);
+
+  static TFacesPeriodicityVector GetDefaultFacesPeriodicityVector() { return TFacesPeriodicityVector(); }
+  const TFacesPeriodicityVector  _GetFacesPeriodicityVector() const { return _facesPeriodicityVector; }
+  static TFacesPeriodicityVector GetFacesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp);
+
+  static TEdgesPeriodicityVector GetDefaultEdgesPeriodicityVector() { return TEdgesPeriodicityVector(); }
+  const TEdgesPeriodicityVector  _GetEdgesPeriodicityVector() const { return _edgesPeriodicityVector; }
+  static TEdgesPeriodicityVector GetEdgesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp);
+
+  static TVerticesPeriodicityVector GetDefaultVerticesPeriodicityVector() { return TVerticesPeriodicityVector(); }
+  const TVerticesPeriodicityVector  _GetVerticesPeriodicityVector() const { return _verticesPeriodicityVector; }
+  static TVerticesPeriodicityVector GetVerticesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp);
+
+  void AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
+      std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries);
+  void AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
+      std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries);
+
+  void AddFacePeriodicity(TEntry theFace1Entry, TEntry theFace2Entry);
+  void AddEdgePeriodicity(TEntry theFace1Entry, TEntry theEdge1Entry, TEntry theFace2Entry, TEntry theEdge2Entry, int edge_orientation = 0);
+  void AddVertexPeriodicity(TEntry theEdge1Entry, TEntry theVertex1Entry, TEntry theEdge2Entry, TEntry theVertex2Entry);
+
   static double undefinedDouble() { return -1.0; }
 
   typedef std::map< std::string, std::string > TOptionValues;
@@ -451,6 +513,13 @@ private:
   bool            _enforcedInternalVerticesAllFaces;
   TEnfGroupName   _enforcedInternalVerticesAllFacesGroup;
   
+  TPreCadPeriodicityVector _preCadFacesPeriodicityVector;
+  TPreCadPeriodicityVector _preCadEdgesPeriodicityVector;
+
+  TFacesPeriodicityVector _facesPeriodicityVector;
+  TEdgesPeriodicityVector _edgesPeriodicityVector;
+  TVerticesPeriodicityVector _verticesPeriodicityVector;
+
   std::string     _GMFFileName;
 //   bool            _GMFFileMode;
 
index 496cf4043c4ae8cc6db2863a543bc0a46f4deca6..066021e406534cee3d147a8b36497e257751acea 100644 (file)
@@ -2584,6 +2584,446 @@ void BLSURFPlugin_Hypothesis_i::SetInternalEnforcedVertexEntry(const char* theFa
  */
 ///////////////////////
 
+///////////////////////
+// PERIODICITY       //
+///////////////////////
+
+
+std::string BLSURFPlugin_Hypothesis_i::ShapeTypeToString(GEOM::shape_type theShapeType)
+{
+//enum shape_type { COMPOUND, COMPSOLID, SOLID, SHELL, FACE, WIRE, EDGE, VERTEX, SHAPE /*, __max_shape_type=0xffffffff */ };
+  std::map<GEOM::shape_type, std::string> MapShapeTypeToString;
+  MapShapeTypeToString[GEOM::COMPOUND] = std::string("COMPOUND");
+  MapShapeTypeToString[GEOM::COMPSOLID] = std::string("COMPSOLID");
+  MapShapeTypeToString[GEOM::SOLID] = std::string("SOLID");
+  MapShapeTypeToString[GEOM::SHELL] = std::string("SHELL");
+  MapShapeTypeToString[GEOM::FACE] = std::string("FACE");
+  MapShapeTypeToString[GEOM::WIRE] = std::string("WIRE");
+  MapShapeTypeToString[GEOM::EDGE] = std::string("EDGE");
+  MapShapeTypeToString[GEOM::VERTEX] = std::string("VERTEX");
+  MapShapeTypeToString[GEOM::SHAPE] = std::string("SHAPE");
+  std::string txtShapeType = MapShapeTypeToString[theShapeType];
+  return txtShapeType;
+}
+
+void BLSURFPlugin_Hypothesis_i::CheckShapeTypes(GEOM::GEOM_Object_ptr shape, std::vector<GEOM::shape_type> theShapeTypes)
+{
+  // Check shape types
+  bool ok = false;
+  std::stringstream typesTxt;
+  for (std::size_t i=0; i<theShapeTypes.size(); i++)
+    {
+      GEOM::shape_type theShapeType = theShapeTypes[i];
+      if (shape->GetShapeType() == theShapeType)
+        ok = true;
+      typesTxt << ShapeTypeToString(theShapeType);
+      if (i < theShapeTypes.size()-1 )
+        typesTxt << ", ";
+    }
+  if (!ok){
+    std::stringstream msg;
+    msg << "shape shape type is not in" << typesTxt;
+    MESSAGE(msg);
+    THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(), SALOME::BAD_PARAM);
+  }
+}
+
+void BLSURFPlugin_Hypothesis_i::CheckShapeType(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType)
+{
+  // Check shape type
+  if (shape->GetShapeType() != theShapeType) {
+    std::stringstream msg;
+    msg << "shape shape type is not " << ShapeTypeToString(theShapeType);
+    MESSAGE(msg);
+    THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(), SALOME::BAD_PARAM);
+  }
+}
+
+std::string BLSURFPlugin_Hypothesis_i::PublishIfNeeded(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType, std::string prefix)
+{
+  // Check shape is published in the object browser
+  string shapeEntry = shape->GetStudyEntry();
+
+  GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
+  SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
+  string aName;
+
+  // Publish shape if needed
+  if (shapeEntry.empty()) {
+    if (shape->GetShapeType() == theShapeType)
+      aName = prefix;
+    aName += shape->GetEntry();
+    SALOMEDS::SObject_wrap theSFace1 = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, shape, aName.c_str());
+    if (!theSFace1->_is_nil())
+      shapeEntry = theSFace1->GetID();
+  }
+  if (shapeEntry.empty())
+    THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
+  return shapeEntry;
+}
+
+// Format the output of two vectors to use it in MESSAGE and PythonDump
+std::string BLSURFPlugin_Hypothesis_i::FormatVerticesEntries(vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries)
+{
+  std::stringstream listEntriesTxt;
+
+  if (!theSourceVerticesEntries.empty())
+    {
+      listEntriesTxt << ", [" ;
+      for (size_t i = 0; i<theSourceVerticesEntries.size(); i++)
+        {
+          if (i>0)
+            listEntriesTxt << ", ";
+          listEntriesTxt << theSourceVerticesEntries[i];
+        }
+
+      listEntriesTxt << "], [" ;
+      for (size_t i = 0; i<theTargetVerticesEntries.size(); i++)
+        {
+          if (i>0)
+            listEntriesTxt << ", ";
+          listEntriesTxt << theTargetVerticesEntries[i];
+        }
+      listEntriesTxt << "]" ;
+    }
+  return listEntriesTxt.str();
+}
+
+
+void BLSURFPlugin_Hypothesis_i::AddPreCadFacesPeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
+throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+  const GEOM::ListOfGO theSourceVertices;
+  const GEOM::ListOfGO theTargetVertices;
+  AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices);
+}
+
+
+void BLSURFPlugin_Hypothesis_i::AddPreCadFacesPeriodicityWithVertices(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2,
+    const GEOM::ListOfGO& theSourceVertices, const GEOM::ListOfGO& theTargetVertices)
+throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+
+  size_t theLength = theSourceVertices.length();
+  if (theLength != theTargetVertices.length())
+    THROW_SALOME_CORBA_EXCEPTION( "The sizes of theSourceVertices and theTargetVertices must be the same" ,SALOME::BAD_PARAM );
+
+  std::vector<GEOM::shape_type> allowedShapeTypes;
+  allowedShapeTypes.push_back(GEOM::FACE);
+  allowedShapeTypes.push_back(GEOM::COMPOUND);
+
+  string prefix1 = "Source_face_";
+  CheckShapeTypes(theFace1, allowedShapeTypes);
+  string theFace1Entry = PublishIfNeeded(theFace1, GEOM::FACE, prefix1);
+
+  string prefix2 = "Target_face_";
+  CheckShapeTypes(theFace2, allowedShapeTypes);
+  string theFace2Entry = PublishIfNeeded(theFace2, GEOM::FACE, prefix2);
+
+  string prefix3 = "Source_vertex_";
+  vector<string> theSourceVerticesEntries (theLength) ;
+  GEOM::GEOM_Object_ptr theVtx_i;
+  string theEntry_i;
+  for (size_t ind = 0; ind < theLength; ind++) {
+      theVtx_i = theSourceVertices[ind];
+      theEntry_i = PublishIfNeeded(theVtx_i, GEOM::VERTEX, prefix3);
+      theSourceVerticesEntries[ind] = theEntry_i;
+  }
+
+  string prefix4 = "Target_vertex_";
+  vector<string> theTargetVerticesEntries (theLength) ;
+  for (size_t ind = 0; ind < theLength; ind++) {
+      theVtx_i = theTargetVertices[ind];
+      theEntry_i = PublishIfNeeded(theVtx_i, GEOM::VERTEX, prefix4);
+      theTargetVerticesEntries[ind] = theEntry_i;
+  }
+
+  string theFace2Name = theFace2->GetName();
+  MESSAGE("IDL : theFace1->GetName : " << theFace1->GetName());
+  MESSAGE("IDL : theFace2->GetName : " << theFace2->GetName());
+  MESSAGE("IDL : AddPreCadFacesPeriodicity( "<< theFace1Entry << ", " << theFace2Entry <<  ")");
+  try {
+      AddPreCadFacesPeriodicityEntry(theFace1Entry.c_str(), theFace2Entry.c_str(),
+          theSourceVerticesEntries, theTargetVerticesEntries);
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+}
+
+
+void BLSURFPlugin_Hypothesis_i::AddPreCadFacesPeriodicityEntry(const char* theFace1Entry, const char* theFace2Entry,
+    vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries)
+    throw (SALOME::SALOME_Exception)
+{
+
+  ASSERT(myBaseImpl);
+
+  string listEntriesTxt = FormatVerticesEntries(theSourceVerticesEntries, theTargetVerticesEntries);
+
+  MESSAGE("IDL : AddPreCadFacesPeriodicityEntry(" << theFace1Entry << ", " << theFace2Entry << listEntriesTxt.c_str() << ")");
+
+  this->GetImpl()->AddPreCadFacesPeriodicity(theFace1Entry, theFace2Entry,
+      theSourceVerticesEntries, theTargetVerticesEntries);
+
+  SMESH::TPythonDump pd;
+  if (!theSourceVerticesEntries.empty())
+    {
+      pd << _this() << ".AddPreCadFacesPeriodicityWithVertices(" << theFace1Entry << ", " << theFace2Entry;
+      pd << listEntriesTxt.c_str();
+      pd << ")";
+    }
+  else
+    pd << _this() << ".AddPreCadFacesPeriodicity(" << theFace1Entry << ", " << theFace2Entry << ")";
+  MESSAGE("IDL : AddPreCadFacesPeriodicityEntry END");
+}
+
+void BLSURFPlugin_Hypothesis_i::AddPreCadEdgesPeriodicity(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2)
+      throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+  const GEOM::ListOfGO theSourceVertices;
+  const GEOM::ListOfGO theTargetVertices;
+  AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices);
+}
+
+void BLSURFPlugin_Hypothesis_i::AddPreCadEdgesPeriodicityWithVertices(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2,
+    const GEOM::ListOfGO& theSourceVertices, const GEOM::ListOfGO& theTargetVertices)
+      throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+
+  size_t theLength = theSourceVertices.length();
+  if (theLength != theTargetVertices.length())
+    THROW_SALOME_CORBA_EXCEPTION( "The sizes of theSourceVertices and theTargetVertices must be the same" ,SALOME::BAD_PARAM );
+
+  std::vector<GEOM::shape_type> allowedShapeTypes;
+  allowedShapeTypes.push_back(GEOM::EDGE);
+  allowedShapeTypes.push_back(GEOM::COMPOUND);
+
+  string prefix1 = "Source_edge_";
+  CheckShapeTypes(theEdge1, allowedShapeTypes);
+  string theEdge1Entry = PublishIfNeeded(theEdge1, GEOM::EDGE, prefix1);
+
+  string prefix2 = "Target_edge_";
+  CheckShapeTypes(theEdge2, allowedShapeTypes);
+  string theEdge2Entry = PublishIfNeeded(theEdge2, GEOM::EDGE, prefix2);
+
+  string prefix3 = "Source_vertex_";
+  vector<string> theSourceVerticesEntries (theLength) ;
+  GEOM::GEOM_Object_ptr theVtx_i;
+  string theEntry_i;
+  for (size_t ind = 0; ind < theLength; ind++) {
+      theVtx_i = theSourceVertices[ind];
+      theEntry_i = PublishIfNeeded(theVtx_i, GEOM::VERTEX, prefix3);
+      theSourceVerticesEntries[ind] = theEntry_i;
+  }
+
+  string prefix4 = "Target_vertex_";
+  vector<string> theTargetVerticesEntries (theLength) ;
+  for (size_t ind = 0; ind < theLength; ind++) {
+      theVtx_i = theTargetVertices[ind];
+      theEntry_i = PublishIfNeeded(theVtx_i, GEOM::VERTEX, prefix4);
+      theTargetVerticesEntries[ind] = theEntry_i;
+  }
+
+  string theEdge2Name = theEdge2->GetName();
+  MESSAGE("IDL : theEdge1->GetName : " << theEdge1->GetName());
+  MESSAGE("IDL : theEdge2->GetName : " << theEdge2->GetName());
+  MESSAGE("IDL : AddPreCadEdgesPeriodicity( "<< theEdge1Entry << ", " << theEdge2Entry << ")");
+  try {
+      AddPreCadEdgesPeriodicityEntry(theEdge1Entry.c_str(), theEdge2Entry.c_str(),
+          theSourceVerticesEntries, theTargetVerticesEntries);
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+}
+
+
+void BLSURFPlugin_Hypothesis_i::AddPreCadEdgesPeriodicityEntry(const char* theEdge1Entry, const char* theEdge2Entry,
+    vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries)
+    throw (SALOME::SALOME_Exception)
+{
+
+  ASSERT(myBaseImpl);
+
+  string listEntriesTxt = FormatVerticesEntries(theSourceVerticesEntries, theTargetVerticesEntries);
+
+  MESSAGE("IDL : AddPreCadEdgesPeriodicityEntry(" << theEdge1Entry << ", " << theEdge2Entry << listEntriesTxt.c_str() << ")");
+  this->GetImpl()->AddPreCadEdgesPeriodicity(theEdge1Entry, theEdge2Entry,
+      theSourceVerticesEntries, theTargetVerticesEntries);
+
+  SMESH::TPythonDump pd;
+  if (!theSourceVerticesEntries.empty())
+    {
+      pd << _this() << ".AddPreCadEdgesPeriodicityWithVertices(" << theEdge1Entry << ", " << theEdge2Entry;
+      pd << listEntriesTxt.c_str();
+      pd << ")";
+    }
+  else
+    pd << _this() << ".AddPreCadEdgesPeriodicity(" << theEdge1Entry << ", " << theEdge2Entry << ")";
+
+  MESSAGE("IDL : AddPreCadEdgesPeriodicityEntry END");
+}
+
+void BLSURFPlugin_Hypothesis_i::AddFacePeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
+    throw (SALOME::SALOME_Exception)
+{
+  ASSERT(myBaseImpl);
+
+  string prefix1 = "Source_face_";
+  CheckShapeType(theFace1, GEOM::FACE);
+  string theFace1Entry = PublishIfNeeded(theFace1, GEOM::FACE, prefix1);
+  string prefix2 = "Target_face_";
+  CheckShapeType(theFace2, GEOM::FACE);
+  string theFace2Entry = PublishIfNeeded(theFace2, GEOM::FACE, prefix2);
+
+  MESSAGE("IDL : theFace1->GetName : " << theFace1->GetName());
+  MESSAGE("IDL : theFace2->GetName : " << theFace2->GetName());
+  MESSAGE("IDL : AddFacePeriodicity( "<< theFace1Entry << ", " << theFace2Entry << ")");
+  try {
+      AddFacePeriodicityEntry(theFace1Entry.c_str(), theFace2Entry.c_str());
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+
+
+}
+
+void BLSURFPlugin_Hypothesis_i::AddFacePeriodicityEntry(const char* theFace1Entry, const char* theFace2Entry)
+    throw (SALOME::SALOME_Exception){
+
+  ASSERT(myBaseImpl);
+
+  MESSAGE("IDL : AddFacePeriodicityEntry(" << theFace1Entry << ", " << theFace2Entry << ")");
+  this->GetImpl()->AddFacePeriodicity(theFace1Entry, theFace2Entry);
+  SMESH::TPythonDump pd;
+  pd << _this() << ".AddFacePeriodicity(" << theFace1Entry << ", " << theFace2Entry << ")";
+  MESSAGE("IDL : AddFacePeriodicityEntry END");
+}
+
+
+void BLSURFPlugin_Hypothesis_i::AddEdgePeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theEdge1,
+    GEOM::GEOM_Object_ptr theFace2, GEOM::GEOM_Object_ptr theEdge2, int edge_orientation)
+    throw (SALOME::SALOME_Exception){
+  ASSERT(myBaseImpl);
+
+  string prefix_theFace1 = "Source_face_";
+  CheckShapeType(theFace1, GEOM::FACE);
+  string theFace1Entry = PublishIfNeeded(theFace1, GEOM::FACE, prefix_theFace1);
+  string prefix_theFace2 = "Target_face_";
+  CheckShapeType(theFace2, GEOM::FACE);
+  string theFace2Entry = PublishIfNeeded(theFace2, GEOM::FACE, prefix_theFace2);
+
+  string prefix_theEdge1 = "Source_edge_";
+  CheckShapeType(theEdge1, GEOM::EDGE);
+  string theEdge1Entry = PublishIfNeeded(theEdge1, GEOM::EDGE, prefix_theEdge1);
+  string prefix_theEdge2 = "Target_edge_";
+  CheckShapeType(theEdge2, GEOM::EDGE);
+  string theEdge2Entry = PublishIfNeeded(theEdge2, GEOM::EDGE, prefix_theEdge2);
+
+  MESSAGE("IDL : theFace1->GetName : " << theFace1->GetName());
+  MESSAGE("IDL : theEdge1->GetName : " << theEdge1->GetName());
+  MESSAGE("IDL : theFace2->GetName : " << theFace2->GetName());
+  MESSAGE("IDL : theEdge2->GetName : " << theEdge2->GetName());
+  MESSAGE("IDL : AddEdgePeriodicity( "<< theFace1Entry << ", " << theEdge1Entry << ", " << theFace2Entry << ", "  << theEdge2Entry << ", " << edge_orientation << ")");
+  try {
+      AddEdgePeriodicityEntry(theFace1Entry.c_str(), theEdge1Entry.c_str(), theFace2Entry.c_str(), theEdge2Entry.c_str(), edge_orientation);
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+
+
+}
+
+void BLSURFPlugin_Hypothesis_i::AddEdgePeriodicityWithoutFaces(GEOM::GEOM_Object_ptr theEdge1,
+    GEOM::GEOM_Object_ptr theEdge2, int edge_orientation)
+    throw (SALOME::SALOME_Exception){
+  ASSERT(myBaseImpl);
+
+  string theFace1Entry = "";
+  string theFace2Entry = "";
+
+  string prefix_theEdge1 = "Source_edge_";
+  CheckShapeType(theEdge1, GEOM::EDGE);
+  string theEdge1Entry = PublishIfNeeded(theEdge1, GEOM::EDGE, prefix_theEdge1);
+  string prefix_theEdge2 = "Target_edge_";
+  CheckShapeType(theEdge2, GEOM::EDGE);
+  string theEdge2Entry = PublishIfNeeded(theEdge2, GEOM::EDGE, prefix_theEdge2);
+
+  MESSAGE("IDL : theEdge1->GetName : " << theEdge1->GetName());
+  MESSAGE("IDL : theEdge2->GetName : " << theEdge2->GetName());
+  MESSAGE("IDL : AddEdgePeriodicity( "<< theFace1Entry << ", " << theEdge1Entry << ", " << theFace2Entry << ", "  << theEdge2Entry << ", " << edge_orientation << ")");
+  try {
+      AddEdgePeriodicityEntry(theFace1Entry.c_str(), theEdge1Entry.c_str(), theFace2Entry.c_str(), theEdge2Entry.c_str(), edge_orientation);
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+
+
+}
+
+void BLSURFPlugin_Hypothesis_i::AddEdgePeriodicityEntry(const char* theFace1Entry, const char* theEdge1Entry, const char* theFace2Entry, const char* theEdge2Entry, const int edge_orientation)
+    throw (SALOME::SALOME_Exception){
+
+  ASSERT(myBaseImpl);
+
+  MESSAGE("IDL : AddEdgePeriodicityEntry(" << theFace1Entry << ", " << theEdge1Entry << ", " << theFace2Entry << ", "  << theEdge2Entry << ", " << edge_orientation << ")");
+  this->GetImpl()->AddEdgePeriodicity(theFace1Entry, theEdge1Entry, theFace2Entry, theEdge2Entry, edge_orientation);
+  SMESH::TPythonDump pd;
+  if (theFace1Entry)
+    pd << _this() << ".AddEdgePeriodicity(" << theFace1Entry << ", " << theEdge1Entry << ", " << theFace2Entry << ", "  << theEdge2Entry << ", " << edge_orientation <<")";
+  else
+    pd << _this() << ".AddEdgePeriodicityWithoutFaces(" << theEdge1Entry << ", " << theEdge2Entry << ", " << edge_orientation <<")";
+  MESSAGE("IDL : AddEdgePeriodicityEntry END");
+}
+
+void BLSURFPlugin_Hypothesis_i::AddVertexPeriodicity(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theVertex1,
+    GEOM::GEOM_Object_ptr theEdge2, GEOM::GEOM_Object_ptr theVertex2)
+    throw (SALOME::SALOME_Exception){
+  ASSERT(myBaseImpl);
+
+  string prefix_theEdge1 = "Source_edge_";
+  CheckShapeType(theEdge1, GEOM::EDGE);
+  string theEdge1Entry = PublishIfNeeded(theEdge1, GEOM::EDGE, prefix_theEdge1);
+  string prefix_theEdge2 = "Target_edge_";
+  CheckShapeType(theEdge2, GEOM::EDGE);
+  string theEdge2Entry = PublishIfNeeded(theEdge2, GEOM::EDGE, prefix_theEdge2);
+
+  string prefix_theVertex1 = "Source_vertex_";
+  CheckShapeType(theVertex1, GEOM::VERTEX);
+  string theVertex1Entry = PublishIfNeeded(theVertex1, GEOM::VERTEX, prefix_theVertex1);
+  string prefix_theVertex2 = "Target_vertex_";
+  CheckShapeType(theVertex2, GEOM::VERTEX);
+  string theVertex2Entry = PublishIfNeeded(theVertex2, GEOM::VERTEX, prefix_theVertex2);
+
+  MESSAGE("IDL : theEdge1->GetName : " << theEdge1->GetName());
+  MESSAGE("IDL : theVertex1->GetName : " << theVertex1->GetName());
+  MESSAGE("IDL : theEdge2->GetName : " << theEdge2->GetName());
+  MESSAGE("IDL : theVertex2->GetName : " << theVertex2->GetName());
+  MESSAGE("IDL : AddVertexPeriodicity( "<< theEdge1Entry << ", " << theVertex1Entry << ", " << theEdge2Entry << ", "  << theVertex2Entry << ")");
+  try {
+      AddVertexPeriodicityEntry(theEdge1Entry.c_str(), theVertex1Entry.c_str(), theEdge2Entry.c_str(), theVertex2Entry.c_str());
+  } catch (SALOME_Exception& ex) {
+    THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+  }
+
+
+}
+
+void BLSURFPlugin_Hypothesis_i::AddVertexPeriodicityEntry(const char* theEdge1Entry, const char* theVertex1Entry, const char* theEdge2Entry, const char* theVertex2Entry)
+    throw (SALOME::SALOME_Exception){
+
+  ASSERT(myBaseImpl);
+
+  MESSAGE("IDL : AddVertexPeriodicityEntry(" << theEdge1Entry << ", " << theVertex1Entry << ", " << theEdge2Entry << ", "  << theVertex2Entry << ")");
+  this->GetImpl()->AddVertexPeriodicity(theEdge1Entry, theVertex1Entry, theEdge2Entry, theVertex2Entry);
+  SMESH::TPythonDump pd;
+  pd << _this() << ".AddVertexPeriodicity(" << theEdge1Entry << ", " << theVertex1Entry << ", " << theEdge2Entry << ", "  << theVertex2Entry << ")";
+  MESSAGE("IDL : AddVertexPeriodicityEntry END");
+}
+
 
 //================================================================================
 /*!
index 62cb6570edf6779f6b89b5ac3480f164f0427cb9..c34d82a8894d689957cfaafb83a7d765abc3151e 100644 (file)
@@ -254,6 +254,55 @@ public:
 //  CORBA::Boolean GetInternalEnforcedVertex(GEOM::GEOM_Object_ptr theFace) throw (SALOME::SALOME_Exception);
 //  CORBA::Boolean GetInternalEnforcedVertexEntry(const char* theFaceEntry) throw (SALOME::SALOME_Exception);
   
+  ///////////////////////
+  // PERIODICITY       //
+  ///////////////////////
+
+  void AddPreCadFacesPeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
+      throw (SALOME::SALOME_Exception);
+
+  void AddPreCadFacesPeriodicityWithVertices(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2,
+      const GEOM::ListOfGO& theSourceVertices, const GEOM::ListOfGO& theTargetVertices)
+      throw (SALOME::SALOME_Exception);
+
+  void AddPreCadFacesPeriodicityEntry(const char* theFace1Entry, const char* theFace2Entry,
+      vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries)
+      throw (SALOME::SALOME_Exception);
+
+  void AddPreCadEdgesPeriodicity(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2)
+      throw (SALOME::SALOME_Exception);
+
+  void AddPreCadEdgesPeriodicityWithVertices(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2,
+      const GEOM::ListOfGO& theSourceVertices, const GEOM::ListOfGO& theTargetVertices)
+      throw (SALOME::SALOME_Exception);
+
+  void AddPreCadEdgesPeriodicityEntry(const char* theEdge1Entry, const char* theEdge2Entry,
+      vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries)
+      throw (SALOME::SALOME_Exception);
+
+  void AddFacePeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
+      throw (SALOME::SALOME_Exception);
+
+  void AddFacePeriodicityEntry(const char* theFace1Entry, const char* theFace2Entry)
+    throw (SALOME::SALOME_Exception);
+
+  void AddEdgePeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theEdge1,
+      GEOM::GEOM_Object_ptr theFace2, GEOM::GEOM_Object_ptr theEdge2, int edge_orientation = 0)
+      throw (SALOME::SALOME_Exception);
+
+  void AddEdgePeriodicityWithoutFaces(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2, int edge_orientation = 0)
+      throw (SALOME::SALOME_Exception);
+
+  void AddEdgePeriodicityEntry(const char* theFace1Entry, const char* theEdge1Entry, const char* theFace2Entry, const char* theEdge2Entry, int edge_orientation = 0)
+    throw (SALOME::SALOME_Exception);
+
+  void AddVertexPeriodicity(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theVertex1,
+      GEOM::GEOM_Object_ptr theEdge2, GEOM::GEOM_Object_ptr theVertex2)
+      throw (SALOME::SALOME_Exception);
+
+  void AddVertexPeriodicityEntry(const char* theEdge1Entry, const char* theVertex1Entry, const char* theEdge2Entry, const char* theVertex2Entry)
+    throw (SALOME::SALOME_Exception);
+
   ///////////////////////
   
   /*!
@@ -292,6 +341,17 @@ public:
   CORBA::Boolean GetPreCADRemoveNanoEdges();
   void SetPreCADEpsNano(CORBA::Double epsNano);
   CORBA::Double GetPreCADEpsNano();
+
+private:
+  ///////////////////////
+  // PERIODICITY       //
+  ///////////////////////
+  std::string ShapeTypeToString(GEOM::shape_type theShapeType);
+  void CheckShapeType(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType);
+  void CheckShapeTypes(GEOM::GEOM_Object_ptr shape, std::vector<GEOM::shape_type> theShapeTypes);
+  std::string PublishIfNeeded(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType, std::string prefix);
+  std::string FormatVerticesEntries(vector<string> &theSourceVerticesEntries, vector<string> &theTargetVerticesEntries);
+
 };
 
 #endif
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..7534495
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# 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.
+#
+# 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
+#
+
+include $(top_srcdir)/adm_local/unix/make_common_starter.am
+
+# ===============================================================
+# Files to be installed
+# ===============================================================
+#
+
+# Scripts to be installed.
+dist_salomescript_DATA = \
+    test_enforced_internal_vertex.py \
+    test_enforced_vertex.py \
+    test_periodicity_2D_precad.py \
+    test_periodicity_2D.py \
+    test_periodicity_precad.py \
+    test_periodicity.py \
+    test_periodicity_reflexion_2D_precad.py \
+    test_periodicity_reflexion_2D.py \
+    test_periodicity_reflexion_precad.py \
+    test_periodicity_reflexion.py \
+    test_periodicity_with_points_2D_precad.py \
+    test_precad_intersections.py
+
+mypkgpythondir = $(salomepythondir)/salome/BLSURFPlugin
diff --git a/tests/test_enforced_internal_vertex.py b/tests/test_enforced_internal_vertex.py
new file mode 100644 (file)
index 0000000..c7f3661
--- /dev/null
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+
+import salome
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+r = 10
+dist = 10
+dist_coin = 10.1
+
+p1 = geompy.MakeVertex(0., 0., 0.)
+p2 = geompy.MakeVertex(100., 100., 100.)
+box = geompy.MakeBoxTwoPnt(p1, p2)
+geompy.addToStudy(box, "box")
+
+p3 = geompy.MakeVertex(dist_coin, 0, dist_coin)
+geompy.addToStudy(p3, "p3")
+
+part = geompy.MakePartition([box], [p3])
+geompy.addToStudy(part, "part")
+
+left = geompy.GetFaceNearPoint(box, p3)
+geompy.addToStudyInFather(box, left, "left")
+
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+
+algo2d.SetInternalEnforcedVertexAllFaces(True)
+
+Mesh.Compute()
+
+id_node = Mesh.FindNodeClosestTo(dist_coin, 0, dist_coin)
+
+x, y, z = Mesh.GetNodeXYZ(id_node)
+
+assert("%.2f, %.2f, %.2f"%(x, y, z) == "%.2f, %.2f, %.2f"%(dist_coin, 0, dist_coin))
+
+salome.sg.updateObjBrowser(0)
+
diff --git a/tests/test_enforced_vertex.py b/tests/test_enforced_vertex.py
new file mode 100644 (file)
index 0000000..f22b392
--- /dev/null
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+
+import salome
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+r = 10
+dist = 10
+dist_coin = 10.1
+
+p1 = geompy.MakeVertex(0., 0., 0.)
+p2 = geompy.MakeVertex(100., 100., 100.)
+box = geompy.MakeBoxTwoPnt(p1, p2)
+geompy.addToStudy(box, "box")
+
+p3 = geompy.MakeVertex(dist_coin, 0, dist_coin)
+geompy.addToStudy(p3, "p3")
+
+left = geompy.GetFaceNearPoint(box, p3)
+geompy.addToStudyInFather(box, left, "left")
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(box, "Mesh")
+
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+
+algo2d.SetEnforcedVertex(left, dist_coin, 0, dist_coin)
+
+Mesh.Compute()
+
+id_node = Mesh.FindNodeClosestTo(dist_coin, 0, dist_coin)
+
+x, y, z = Mesh.GetNodeXYZ(id_node)
+
+assert("%.2f, %.2f, %.2f"%(x, y, z) == "%.2f, %.2f, %.2f"%(dist_coin, 0, dist_coin))
+
+
+salome.sg.updateObjBrowser(0)
+
diff --git a/tests/test_periodicity.py b/tests/test_periodicity.py
new file mode 100644 (file)
index 0000000..b6e5de4
--- /dev/null
@@ -0,0 +1,187 @@
+# -*- coding: utf-8 -*-
+
+import salome
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import math
+
+simple = False
+
+r = 10
+dist = 10
+
+p1 = geompy.MakeVertex(0., 0., 0.)
+p2 = geompy.MakeVertex(100., 100., 100.)
+box = geompy.MakeBoxTwoPnt(p1, p2)
+geompy.addToStudy(box, "box")
+
+p3 = geompy.MakeVertex(25., 5., 25.)
+sphere1 = geompy.MakeSpherePntR(p3, 15.)
+geompy.addToStudy(sphere1, "sphere1")
+
+sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
+geompy.addToStudy(sphere1_trans, "sphere1_trans")
+
+sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
+geompy.addToStudy(sphere1_trans, "sphere1_trans")
+
+p4 = geompy.MakeVertex(5, 50, 90)
+sphere2 = geompy.MakeSpherePntR(p4, 20.)
+
+sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0)
+geompy.addToStudy(sphere2_trans, "sphere2_trans")
+
+sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100)
+geompy.addToStudy(sphere2_trans2, "sphere2_trans2")
+
+sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100)
+geompy.addToStudy(sphere2_trans3, "sphere2_trans3")
+
+if simple:
+    part = box
+else:
+    part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(left, left_faces)
+geompy.addToStudyInFather(part, left, "left")
+
+right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(right, right_faces)
+geompy.addToStudyInFather(part, right, "right")
+
+back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
+back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(back, back_faces)
+geompy.addToStudyInFather(part, back, "back")
+
+front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
+front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(front, front_faces)
+geompy.addToStudyInFather(part, front, "front")
+
+bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(bottom, bottom_faces)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(top, top_faces)
+geompy.addToStudyInFather(part, top, "top")
+
+sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(sources, left_faces)
+geompy.UnionList(sources, back_faces)
+geompy.UnionList(sources, top_faces)
+geompy.addToStudyInFather(part, sources, "sources")
+
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
+
+def proj_x(shape1):
+    shape2 = geompy.MakeTranslation(shape1, 100, 0., 0)
+    return shape2
+    
+def proj_y(shape1):
+    shape2 = geompy.MakeTranslation(shape1, 0, 100., 0)
+    return shape2
+
+def proj_z(shape1):
+    shape2 = geompy.MakeTranslation(shape1, 0, 0, 100.)
+    return shape2
+
+def AddAdvancedFacesPeriodicity(faces1, faces2, f_transf):
+    # Periodicity left/right
+    source_faces = geompy.SubShapeAll(faces1, geompy.ShapeType["FACE"])
+    i = 0
+    j = 0
+    k = 0
+    for source_face in source_faces:
+        geompy.addToStudyInFather(faces1, source_face, "source_face_%i"%i)
+        p_source = geompy.MakeVertexInsideFace(source_face)
+        p_target = f_transf(p_source)
+        target_face = geompy.GetFaceNearPoint(faces2, p_target)
+        geompy.addToStudyInFather(faces2, target_face, "target_face_%i"%i)
+        algo2d.AddFacePeriodicity(source_face, target_face)
+        i += 1
+        
+        source_edges = geompy.SubShapeAll(source_face, geompy.ShapeType["EDGE"])
+        for source_edge in source_edges:
+            geompy.addToStudyInFather(faces1, source_edge, "source_edge_%i"%(j))
+            p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
+            p_target = f_transf(p_source)
+            target_edge = geompy.GetEdgeNearPoint(faces2, p_target)
+            geompy.addToStudyInFather(faces2, target_edge, "target_edge_%i"%(j))
+            algo2d.AddEdgePeriodicity(source_face, source_edge, target_face, target_edge)
+            j += 1
+            
+            source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
+            for source_vertex in source_vertices:
+                geompy.addToStudyInFather(faces1, source_vertex, "source_vertex_%i"%(k))
+                target_vertex_tmp = f_transf(source_vertex)
+                target_vertex = geompy.GetSame(faces2, target_vertex_tmp)
+                geompy.addToStudyInFather(faces2, target_vertex, "target_vertex_%i"%(k))
+                algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
+                k += 1
+    pass
+
+AddAdvancedFacesPeriodicity(back, front, proj_x)
+AddAdvancedFacesPeriodicity(left, right, proj_y)
+AddAdvancedFacesPeriodicity(bottom, top, proj_z)
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_front = Mesh.Group(front)
+gr_back = Mesh.Group(back)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' )
+front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' )
+bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_right, left_translated)
+checkProjection(gr_back, front_translated)
+checkProjection(gr_top, bottom_translated)
+
+salome.sg.updateObjBrowser(0)
+
diff --git a/tests/test_periodicity_2D.py b/tests/test_periodicity_2D.py
new file mode 100644 (file)
index 0000000..405093e
--- /dev/null
@@ -0,0 +1,137 @@
+# -*- coding: iso-8859-1 -*-
+
+import salome
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import math
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
+Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
+vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
+Curve_1 = geompy.MakeInterpol(vertices, True, True)
+
+part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p1 = geompy.MakeVertex(-5, -5, 0)
+p2 = geompy.MakeVertex(5, 5, 0)
+left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(left, left_edges)
+geompy.addToStudyInFather(part, left, "left")
+
+right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(right, right_edges)
+geompy.addToStudyInFather(part, right, "right")
+
+bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(bottom, bottom_edges)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(top, top_edges)
+geompy.addToStudyInFather(part, top, "top")
+
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetVerbosity(10)
+#algo2d.SetTopology(smesh.PreCAD)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+#algo2d.SetGradation(1.05)
+algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
+
+# Periodicity
+
+def proj_x(shape1):
+    shape2 = geompy.MakeTranslation(shape1, 10, 0., 0)
+    return shape2
+    
+def proj_y(shape1):
+    shape2 = geompy.MakeTranslation(shape1, 0, 10., 0)
+    return shape2
+
+def AddAdvancedEdgesPeriodicity(edges1, edges2, f_transf):
+    source_edges = geompy.SubShapeAll(edges1, geompy.ShapeType["EDGE"])
+    j = 0
+    k = 0
+    for source_edge in source_edges:
+        geompy.addToStudyInFather(edges1, source_edge, "source_edge_%i"%j)
+        p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
+        p_target = f_transf(p_source)
+        target_edge = geompy.GetEdgeNearPoint(part, p_target)
+        geompy.addToStudyInFather(edges2, target_edge, "target_edge_%i"%j)
+        algo2d.AddEdgePeriodicityWithoutFaces(source_edge, target_edge)
+        
+        j += 1
+        
+        source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
+        for source_vertex in source_vertices:
+            geompy.addToStudyInFather(edges1, source_vertex, "source_vertex_%i"%k)
+            target_vertex_tmp = geompy.MakeTranslation(source_vertex, 10, 0., 0)
+            target_vertex_tmp = f_transf(source_vertex)
+            target_vertex = geompy.GetSame(part, target_vertex_tmp)
+            geompy.addToStudyInFather(edges2, target_vertex, "target_vertex_%i"%k)
+            algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
+            
+            k += 1
+    
+AddAdvancedEdgesPeriodicity(left, right, proj_x)
+AddAdvancedEdgesPeriodicity(bottom, top, proj_y)
+
+Mesh.Compute()
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' )
+bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_right, left_translated)
+checkProjection(gr_top, bottom_translated)
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(1)
diff --git a/tests/test_periodicity_2D_precad.py b/tests/test_periodicity_2D_precad.py
new file mode 100644 (file)
index 0000000..f9806ce
--- /dev/null
@@ -0,0 +1,111 @@
+# -*- coding: iso-8859-1 -*-
+
+import sys
+import salome
+
+###
+### GEOM component
+###
+
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
+Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
+vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
+Curve_1 = geompy.MakeInterpol(vertices, True, True)
+
+part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p1 = geompy.MakeVertex(-5, -5, 0)
+p2 = geompy.MakeVertex(5, 5, 0)
+left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(left, left_edges)
+geompy.addToStudyInFather(part, left, "left")
+
+right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(right, right_edges)
+geompy.addToStudyInFather(part, right, "right")
+
+bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(bottom, bottom_edges)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(top, top_edges)
+geompy.addToStudyInFather(part, top, "top")
+
+source_face = geompy.GetFaceNearPoint(part, p1)
+geompy.addToStudyInFather(part, source_face, "source_face")
+
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+#algo2d.SetGradation(1.05)
+
+# Periodicity
+#algo2d.SetVerbosity(10)
+algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
+algo2d.AddPreCadEdgesPeriodicity(left, right)
+algo2d.AddPreCadEdgesPeriodicity(bottom, top)
+
+
+Mesh.Compute()
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' )
+bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_right, left_translated)
+checkProjection(gr_top, bottom_translated)
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(1)
+  
diff --git a/tests/test_periodicity_precad.py b/tests/test_periodicity_precad.py
new file mode 100644 (file)
index 0000000..8a10dda
--- /dev/null
@@ -0,0 +1,140 @@
+# -*- coding: utf-8 -*-
+
+import salome
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+simple = False
+
+r = 10
+dist = 10
+
+p1 = geompy.MakeVertex(0., 0., 0.)
+p2 = geompy.MakeVertex(100., 100., 100.)
+box = geompy.MakeBoxTwoPnt(p1, p2)
+geompy.addToStudy(box, "box")
+
+p3 = geompy.MakeVertex(25., 5., 25.)
+sphere1 = geompy.MakeSpherePntR(p3, 15.)
+geompy.addToStudy(sphere1, "sphere1")
+
+sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
+geompy.addToStudy(sphere1_trans, "sphere1_trans")
+
+sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0)
+geompy.addToStudy(sphere1_trans, "sphere1_trans")
+
+p4 = geompy.MakeVertex(5, 50, 90)
+sphere2 = geompy.MakeSpherePntR(p4, 20.)
+
+sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0)
+geompy.addToStudy(sphere2_trans, "sphere2_trans")
+
+sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100)
+geompy.addToStudy(sphere2_trans2, "sphere2_trans2")
+
+sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100)
+geompy.addToStudy(sphere2_trans3, "sphere2_trans3")
+
+if simple:
+    part = box
+else:
+    part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(left, left_faces)
+geompy.addToStudyInFather(part, left, "left")
+
+right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(right, right_faces)
+geompy.addToStudyInFather(part, right, "right")
+
+back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
+back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(back, back_faces)
+geompy.addToStudyInFather(part, back, "back")
+
+front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
+front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(front, front_faces)
+geompy.addToStudyInFather(part, front, "front")
+
+bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(bottom, bottom_faces)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(top, top_faces)
+geompy.addToStudyInFather(part, top, "top")
+
+sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(sources, left_faces)
+geompy.UnionList(sources, back_faces)
+geompy.UnionList(sources, top_faces)
+geompy.addToStudyInFather(part, sources, "sources")
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+algo2d.SetVerbosity(1)
+
+# Periodicity
+#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
+algo2d.AddPreCadFacesPeriodicity(left, right)
+algo2d.AddPreCadFacesPeriodicity(front, back)
+algo2d.AddPreCadFacesPeriodicity(bottom, top)
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_front = Mesh.Group(front)
+gr_back = Mesh.Group(back)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' )
+front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' )
+bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_right, left_translated)
+checkProjection(gr_back, front_translated)
+checkProjection(gr_top, bottom_translated)
+
+salome.sg.updateObjBrowser(0)
+
diff --git a/tests/test_periodicity_reflexion.py b/tests/test_periodicity_reflexion.py
new file mode 100644 (file)
index 0000000..ed4f134
--- /dev/null
@@ -0,0 +1,159 @@
+# -*- coding: utf-8 -*-
+
+import salome
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import math
+
+simple = False
+
+r = 10
+dist = 10
+
+p1 = geompy.MakeVertex(0., 0., 0.)
+p2 = geompy.MakeVertex(100., 100., 100.)
+box = geompy.MakeBoxTwoPnt(p1, p2)
+geompy.addToStudy(box, "box")
+
+p3 = geompy.MakeVertex(25., 5., 25.)
+sphere1 = geompy.MakeSpherePntR(p3, 15.)
+geompy.addToStudy(sphere1, "sphere1")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p4 = geompy.MakeVertex(100., 0., 0.)
+axe = geompy.MakePrismVecH(p4, Vz, 1)
+geompy.addToStudy(axe, "axe")
+
+sphere1_rota = geompy.MakeRotation(sphere1, axe, -math.pi/2.)
+geompy.addToStudy(sphere1_rota, "sphere1_rota")
+
+part = geompy.MakePartition([box], [sphere1, sphere1_rota])
+geompy.addToStudy(part, "part")
+
+left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(left, left_faces)
+geompy.addToStudyInFather(part, left, "left")
+
+right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(right, right_faces)
+geompy.addToStudyInFather(part, right, "right")
+
+back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
+back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(back, back_faces)
+geompy.addToStudyInFather(part, back, "back")
+
+front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
+front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(front, front_faces)
+geompy.addToStudyInFather(part, front, "front")
+
+bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(bottom, bottom_faces)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(top, top_faces)
+geompy.addToStudyInFather(part, top, "top")
+
+sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(sources, left_faces)
+geompy.UnionList(sources, back_faces)
+geompy.UnionList(sources, top_faces)
+geompy.addToStudyInFather(part, sources, "sources")
+
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
+
+def rota_z(shape1):
+    shape2 = geompy.MakeRotation(shape1, axe, -math.pi/2)
+    return shape2
+
+def AddAdvancedFacesPeriodicity(faces1, faces2, f_transf):
+    # Periodicity left/right
+    source_faces = geompy.SubShapeAll(faces1, geompy.ShapeType["FACE"])
+    i = 0
+    j = 0
+    k = 0
+    for source_face in source_faces:
+        geompy.addToStudyInFather(faces1, source_face, "source_face_%i"%i)
+        p_source = geompy.MakeVertexInsideFace(source_face)
+        p_target = f_transf(p_source)
+        target_face = geompy.GetFaceNearPoint(faces2, p_target)
+        geompy.addToStudyInFather(faces2, target_face, "target_face_%i"%i)
+        algo2d.AddFacePeriodicity(source_face, target_face)
+        i += 1
+        
+        source_edges = geompy.SubShapeAll(source_face, geompy.ShapeType["EDGE"])
+        for source_edge in source_edges:
+            geompy.addToStudyInFather(faces1, source_edge, "source_edge_%i"%(j))
+            p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
+            p_target = f_transf(p_source)
+            target_edge = geompy.GetEdgeNearPoint(faces2, p_target)
+            geompy.addToStudyInFather(faces2, target_edge, "target_edge_%i"%(j))
+            algo2d.AddEdgePeriodicity(source_face, source_edge, target_face, target_edge)
+            j += 1
+            
+            source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
+            for source_vertex in source_vertices:
+                geompy.addToStudyInFather(faces1, source_vertex, "source_vertex_%i"%(k))
+                target_vertex_tmp = f_transf(source_vertex)
+                target_vertex = geompy.GetSame(faces2, target_vertex_tmp)
+                geompy.addToStudyInFather(faces2, target_vertex, "target_vertex_%i"%(k))
+                algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
+                k += 1
+    pass
+
+AddAdvancedFacesPeriodicity(left, front, rota_z)
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_front = Mesh.Group(front)
+gr_back = Mesh.Group(back)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_rotated = Mesh.RotateObjectMakeMesh( gr_left, axe, -math.pi/2, NewMeshName='left_rotated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_front, left_rotated)
+
+salome.sg.updateObjBrowser(0)
+
diff --git a/tests/test_periodicity_reflexion_2D.py b/tests/test_periodicity_reflexion_2D.py
new file mode 100644 (file)
index 0000000..7405bad
--- /dev/null
@@ -0,0 +1,132 @@
+# -*- coding: iso-8859-1 -*-
+
+import salome
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import math
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
+Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
+vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
+Curve_1 = geompy.MakeInterpol(vertices, True, True)
+
+part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p1 = geompy.MakeVertex(-5, -5, 0)
+p2 = geompy.MakeVertex(5, 5, 0)
+left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(left, left_edges)
+geompy.addToStudyInFather(part, left, "left")
+
+right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(right, right_edges)
+geompy.addToStudyInFather(part, right, "right")
+
+bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(bottom, bottom_edges)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(top, top_edges)
+geompy.addToStudyInFather(part, top, "top")
+
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetVerbosity(1)
+#algo2d.SetTopology(smesh.PreCAD)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+#algo2d.SetGradation(1.05)
+algo2d.SetOptionValue( 'periodic_tolerance', '1e-2' )
+
+# Periodicity
+
+p_axe = geompy.MakeVertex(5, -5, 0)
+axe = geompy.MakePrismVecH(p_axe, Vz, 1)
+def rota_z(shape1):
+    shape2 = geompy.MakeRotation(shape1, axe, -math.pi/2)
+    return shape2
+
+def AddAdvancedEdgesPeriodicity(edges1, edges2, f_transf):
+    source_edges = geompy.SubShapeAll(edges1, geompy.ShapeType["EDGE"])
+    j = 0
+    k = 0
+    for source_edge in source_edges:
+        geompy.addToStudyInFather(edges1, source_edge, "source_edge_%i"%j)
+        p_source = geompy.MakeVertexOnCurve(source_edge, 0.5)
+        p_target = f_transf(p_source)
+        target_edge = geompy.GetEdgeNearPoint(part, p_target)
+        geompy.addToStudyInFather(edges2, target_edge, "target_edge_%i"%j)
+        algo2d.AddEdgePeriodicityWithoutFaces(source_edge, target_edge)
+        
+        j += 1
+        
+        source_vertices = geompy.SubShapeAll(source_edge, geompy.ShapeType["VERTEX"])
+        for source_vertex in source_vertices:
+            geompy.addToStudyInFather(edges1, source_vertex, "source_vertex_%i"%k)
+            target_vertex_tmp = geompy.MakeTranslation(source_vertex, 10, 0., 0)
+            target_vertex_tmp = f_transf(source_vertex)
+            target_vertex = geompy.GetSame(part, target_vertex_tmp)
+            geompy.addToStudyInFather(edges2, target_vertex, "target_vertex_%i"%k)
+            algo2d.AddVertexPeriodicity(source_edge, source_vertex, target_edge, target_vertex)
+            
+            k += 1
+    
+AddAdvancedEdgesPeriodicity(bottom, right, rota_z)
+
+Mesh.Compute()
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+bottom_rotated = Mesh.RotateObjectMakeMesh( gr_bottom, axe, -math.pi/2, NewMeshName='bottom_rotated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_right, bottom_rotated)
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(1)
diff --git a/tests/test_periodicity_reflexion_2D_precad.py b/tests/test_periodicity_reflexion_2D_precad.py
new file mode 100644 (file)
index 0000000..5eed201
--- /dev/null
@@ -0,0 +1,126 @@
+# -*- coding: iso-8859-1 -*-
+
+import sys
+import salome
+
+###
+### GEOM component
+###
+
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
+Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
+vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
+Curve_1 = geompy.MakeInterpol(vertices, True, True)
+
+part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p1 = geompy.MakeVertex(-5, -5, 0)
+p2 = geompy.MakeVertex(5, 5, 0)
+left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(left, left_edges)
+geompy.addToStudyInFather(part, left, "left")
+
+right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(right, right_edges)
+geompy.addToStudyInFather(part, right, "right")
+
+bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(bottom, bottom_edges)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(top, top_edges)
+geompy.addToStudyInFather(part, top, "top")
+
+source_face = geompy.GetFaceNearPoint(part, p1)
+geompy.addToStudyInFather(part, source_face, "source_face")
+
+# To define a rotation, we have to set at least 3 source vertices not aligned.
+p_bas_gauche = geompy.MakeVertex(-5, -5, 0)
+geompy.addToStudy(p_bas_gauche, "p_bas_gauche")
+p_bas_mil = geompy.MakeVertex(0, -4, 0)
+geompy.addToStudy(p_bas_mil, "p_bas_mil")
+p_bas_droite = geompy.MakeVertex(5, -5, 0)
+geompy.addToStudy(p_bas_droite, "p_bas_droite")
+
+# Target vertices
+p_mil_droite = geompy.MakeVertex(4, 0, 0)
+geompy.addToStudy(p_mil_droite, "p_mil_droite")
+p_haut_droite = geompy.MakeVertex(5, 5, 0)
+geompy.addToStudy(p_haut_droite, "p_haut_droite")
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+#algo2d.SetGradation(1.05)
+
+#algo2d.SetOptionValue( 'debug', '1' )
+#algo2d.SetPreCADOptionValue( 'debug', '1' )
+
+# Periodicity
+#algo2d.SetVerbosity(10)
+algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
+algo2d.AddPreCadEdgesPeriodicity(bottom, right, [p_bas_droite, p_bas_mil, p_bas_gauche], [p_bas_droite, p_mil_droite, p_haut_droite])
+
+
+Mesh.Compute()
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+axe = geompy.MakePrismVecH(p_bas_droite, Vz, 1)
+bottom_rotated = Mesh.RotateObjectMakeMesh( gr_bottom, axe, -math.pi/2, NewMeshName='bottom_rotated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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
+        
+checkProjection(gr_right, bottom_rotated)
+
+#salome.myStudyManager.SaveAs("test.hdf", salome.myStudy, 0)
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(1)
+  
diff --git a/tests/test_periodicity_reflexion_precad.py b/tests/test_periodicity_reflexion_precad.py
new file mode 100644 (file)
index 0000000..5da7dd9
--- /dev/null
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+
+import salome
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+simple = False
+
+r = 10
+dist = 10
+
+p1 = geompy.MakeVertex(0., 0., 0.)
+p2 = geompy.MakeVertex(100., 100., 100.)
+box = geompy.MakeBoxTwoPnt(p1, p2)
+geompy.addToStudy(box, "box")
+
+p3 = geompy.MakeVertex(50., 5., 25.)
+sphere1 = geompy.MakeSpherePntR(p3, 15.)
+geompy.addToStudy(sphere1, "sphere1")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p4 = geompy.MakeVertex(100., 0., 0.)
+axe = geompy.MakePrismVecH(p4, Vz, 1)
+geompy.addToStudy(axe, "axe")
+
+sphere1_rota = geompy.MakeRotation(sphere1, axe, -math.pi/2.)
+geompy.addToStudy(sphere1_rota, "sphere1_rota")
+
+part = geompy.MakePartition([box], [sphere1, sphere1_rota])
+geompy.addToStudy(part, "part")
+
+left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(left, left_faces)
+geompy.addToStudyInFather(part, left, "left")
+
+right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(right, right_faces)
+geompy.addToStudyInFather(part, right, "right")
+
+back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON)
+back = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(back, back_faces)
+geompy.addToStudyInFather(part, back, "back")
+
+front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON)
+front = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(front, front_faces)
+geompy.addToStudyInFather(part, front, "front")
+
+bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(bottom, bottom_faces)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
+geompy.UnionList(top, top_faces)
+geompy.addToStudyInFather(part, top, "top")
+
+p1_rota = geompy.MakeRotation(p1, axe, -math.pi/2.)
+geompy.addToStudy(sphere1_rota, "sphere1_rota")
+
+p5 = geompy.MakeVertex(100, 0, 100)
+geompy.addToStudy(p5, "p5")
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+
+# Periodicity
+#algo2d.SetVerbosity(10)
+#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
+algo2d.AddPreCadFacesPeriodicity(left, front, [p1, p4, p5], [p1_rota, p4, p5])
+
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_front = Mesh.Group(front)
+gr_back = Mesh.Group(back)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_rotated = Mesh.RotateObjectMakeMesh( gr_left, axe, -math.pi/2, NewMeshName='left_rotated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_front, left_rotated)
+
+salome.sg.updateObjBrowser(0)
+
diff --git a/tests/test_periodicity_with_points_2D_precad.py b/tests/test_periodicity_with_points_2D_precad.py
new file mode 100644 (file)
index 0000000..5322376
--- /dev/null
@@ -0,0 +1,125 @@
+# -*- coding: iso-8859-1 -*-
+
+import sys
+import salome
+
+###
+### GEOM component
+###
+
+import math
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
+Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 )
+vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True)
+Curve_1 = geompy.MakeInterpol(vertices, True, True)
+
+part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"])
+geompy.addToStudy(part, "part")
+
+Vx = geompy.MakeVectorDXDYDZ(1, 0, 0)
+Vy = geompy.MakeVectorDXDYDZ(0, 1, 0)
+Vz = geompy.MakeVectorDXDYDZ(0, 0, 1)
+
+p1 = geompy.MakeVertex(-5, -5, 0)
+p2 = geompy.MakeVertex(5, 5, 0)
+left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON)
+left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(left, left_edges)
+geompy.addToStudyInFather(part, left, "left")
+
+right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON)
+right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(right, right_edges)
+geompy.addToStudyInFather(part, right, "right")
+
+bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON)
+bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(bottom, bottom_edges)
+geompy.addToStudyInFather(part, bottom, "bottom")
+
+top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON)
+top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
+geompy.UnionList(top, top_edges)
+geompy.addToStudyInFather(part, top, "top")
+
+source_face = geompy.GetFaceNearPoint(part, p1)
+geompy.addToStudyInFather(part, source_face, "source_face")
+
+p_bas_gauche = geompy.MakeVertex(-5, -5, 0)
+geompy.addToStudy(p_bas_gauche, "p_bas_gauche")
+p_bas_mil = geompy.MakeVertex(0, -4, 0)
+geompy.addToStudy(p_bas_mil, "p_bas_mil")
+p_bas_droite = geompy.MakeVertex(5, -5, 0)
+geompy.addToStudy(p_bas_droite, "p_bas_droite")
+p_haut_gauche = geompy.MakeVertex(-5, 5, 0)
+geompy.addToStudy(p_haut_gauche, "p_haut_gauche")
+p_haut_mil = geompy.MakeVertex(0, 6, 0)
+geompy.addToStudy(p_haut_mil, "p_haut_mil")
+p_haut_droite = geompy.MakeVertex(5, 5, 0)
+geompy.addToStudy(p_haut_droite, "p_haut_droite")
+
+# Mesh
+# ====
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+Mesh = smesh.Mesh(part, "Mesh")
+
+algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF)
+algo2d.SetGeometricMesh( 1 )
+algo2d.SetAngleMesh( 4 )
+algo2d.SetPhySize( 8 )
+#algo2d.SetGradation(1.05)
+
+# Periodicity
+#algo2d.SetVerbosity(10)
+algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2")
+algo2d.AddPreCadEdgesPeriodicity(bottom, top, [p_bas_gauche, p_bas_mil, p_bas_droite], [p_haut_gauche, p_haut_mil, p_haut_droite])
+
+# debug
+#algo2d.SetOptionValue( 'debug', '1' )
+#algo2d.SetPreCADOptionValue( 'debug', '1' )
+
+Mesh.Compute()
+
+gr_left = Mesh.Group(left)
+gr_right = Mesh.Group(right)
+gr_bottom = Mesh.Group(bottom)
+gr_top = Mesh.Group(top)
+
+Mesh.Compute()
+
+left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' )
+bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' )
+
+def checkProjection(gr, mesh_translated, tol=1e-7):
+    name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0]
+    mesh_source = smesh.CopyMesh(gr, gr.GetName())
+    mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name)
+    ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol)
+    coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist]
+    mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes)
+    mesh_nodes = mesh_check.GetNodesId()
+    if len(ll_coincident_nodes) != mesh_translated.NbNodes():
+        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)
+        
+checkProjection(gr_top, bottom_translated)
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(1)
+  
+
diff --git a/tests/test_precad_intersections.py b/tests/test_precad_intersections.py
new file mode 100644 (file)
index 0000000..544c71d
--- /dev/null
@@ -0,0 +1,82 @@
+# -*- coding: iso-8859-1 -*-
+
+###
+### This file is generated automatically by SALOME v6.6.0 with dump python functionality
+###
+
+import sys
+import salome
+
+salome.salome_init()
+theStudy = salome.myStudy
+
+import salome_notebook
+notebook = salome_notebook.notebook
+sys.path.insert( 0, r'/export/home/bourcier/salome/tests')
+
+###
+### GEOM component
+###
+
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+
+geompy.init_geom(theStudy)
+
+geomObj_1 = geompy.MakeBoxDXDYDZ(100, 100, 100)
+geomObj_2 = geompy.MakeVertex(-2, 60, 40)
+geomObj_3 = geompy.MakeSpherePntR(geomObj_2, 10)
+geomObj_4 = geompy.MakeVertex(70, 20, 60)
+geomObj_5 = geompy.MakeSpherePntR(geomObj_4, 15)
+geomObj_6 = geompy.MakeCompound([geomObj_3, geomObj_5])
+geomObj_7 = geompy.GetInPlaceByHistory(geomObj_6, geomObj_3)
+geomObj_8 = geompy.GetInPlaceByHistory(geomObj_6, geomObj_5)
+Face_1 = geompy.MakeFaceHW(10, 10, 1)
+Translation_1 = geompy.MakeTranslation(Face_1, 10.0001, 0.0001, 0)
+Translation_2 = geompy.MakeTranslation(Face_1, 5, -9.99995, 0)
+Partition_1 = geompy.MakePartition([Face_1, Translation_1, Translation_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0)
+geompy.addToStudy( Face_1, 'Face_1' )
+geompy.addToStudy( Translation_1, 'Translation_1' )
+geompy.addToStudy( Translation_2, 'Translation_2' )
+geompy.addToStudy( Partition_1, 'Partition_1' )
+
+p_axe = geompy.MakeVertex(5, -5, 0)
+axe = geompy.MakePrismDXDYDZ(p_axe, 0, 0, 1)
+vertices = geompy.GetShapesOnCylinder(Partition_1, geompy.ShapeType["VERTEX"], axe, 1e-3, GEOM.ST_IN)
+gr_vertices = geompy.CreateGroup(Partition_1, geompy.ShapeType["VERTEX"])
+geompy.UnionList(gr_vertices, vertices)
+geompy.addToStudyInFather(Partition_1, gr_vertices, "vertices")
+
+###
+### SMESH component
+###
+
+import SMESH
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+
+Mesh_1 = smesh.Mesh(Partition_1)
+
+BLSURF_1 = Mesh_1.Triangle(algo=smeshBuilder.BLSURF)
+BLSURF_Parameters = BLSURF_1.Parameters()
+BLSURF_Parameters.SetPhySize( 5 )
+BLSURF_Parameters.SetTopology( 3 )
+
+Mesh_1.Compute()
+
+# Check that vertices are merged by preCAD preprocessing
+nodes = []
+for p in vertices:
+    x, y, z = geompy.PointCoordinates(p)
+    id_node = Mesh_1.FindNodeClosestTo(x, y, z)
+    nodes.append(id_node)
+
+nodes = set(nodes)
+
+assert(len(nodes) == 1)
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(1)