# Path: lasercut/helper.py
# class ObjectProperties(object):
#     def __init__(self, **kwargs):
#         self.obj_class = str(type(self).__name__)
#         for k, v in kwargs.items():
#             if not hasattr(self, "_allowed") or str(k) in self._allowed:
#                 setattr(self, k, v)
#             #else:
#             #    FreeCAD.Console.PrintWarning(str(k) + " is not allowed for " + str(type(self)))
# 
# def sort_quad_vertex(list_edges, reverse):
#     list_points = []
#     if not reverse:
#         list_points = [list_edges[0].Vertexes[0].Point, list_edges[0].Vertexes[1].Point]
#     else:
#         list_points = [list_edges[0].Vertexes[1].Point, list_edges[0].Vertexes[0].Point]
#     for edge in list_edges[1:-1]:
#         vertex1 = edge.Vertexes[0].Point
#         vertex2 = edge.Vertexes[1].Point
# 
#         if compare_freecad_vector(vertex1, list_points[-1]):
#             list_points.append(vertex2)
#         elif compare_freecad_vector(vertex2, list_points[-1]):
#             list_points.append(vertex1)
#         else:
#             return None
# 
#     return list_points
# 
# def biggest_area_faces(freecad_shape):
#     sorted_list = sort_area_shape_faces(freecad_shape)
#     biggest_area_face = sorted_list[-1]
# #       contains : 0:normal, 1:area mm2, 2; list of faces
#     return biggest_area_face
# 
# def sort_area_shape_list(faces_list):
#     return sort_area_face_common(faces_list, compare_freecad_vector)
# 
# def compare_value(value1, value2, epsilon=10e-6):
#     value = value1 - value2
#     if math.fabs(value) < epsilon:
#         return True
#     return False


import FreeCAD
import Part
import collections
from lasercut.helper import ObjectProperties, sort_quad_vertex, biggest_area_faces, sort_area_shape_list, compare_value
        if compare_value(thickness, self.thickness) is False:
            FreeCAD.Console.PrintError("Recomputed thickness for %s is different (%f != %f)\n" % (self.name, thickness, self.thickness))


# Prendre la normal la plus présente en terme de surface (biggest_area_faces)
# appliquer  une transformation pour orienter la normal vers Z
# l'éppaiseur et le Zlength du boundedbox (ce sera donc l'éppaisseur max)
def retrieve_thickness_from_bounded_box():
    return None


# Prend les deux premiere faces ayant la même normal (géré exception !! si une seule face)
# Pour chaque face recupere les points et calcule la plus petite distance entre chaque point
# de la premiere face et ceux de la deuxième face. La distance la plus petite est l'éppaisseur estimé.
def retrieve_thickness_from_biggest_face(freecad_object):
    area_faces = biggest_area_faces(freecad_object.Shape)
    # order faces by normals
    sub_areas_face = sort_area_shape_list(area_faces[2])
    # TODO : check if normals at opposite
    #list_edges_face1 = Part.__sortEdges__(area_faces[2][0].Edges)
    #list_edges_face2 = Part.__sortEdges__(area_faces[2][1].Edges)
    list_edges_face1 = Part.__sortEdges__(sub_areas_face[0][2][0].Edges)
    list_edges_face2 = Part.__sortEdges__(sub_areas_face[1][2][0].Edges)

    list_pts_face1 = sort_quad_vertex(list_edges_face1, False)
    if list_pts_face1 is None:
        list_pts_face1 = sort_quad_vertex(list_edges_face1, True)
    if list_pts_face1 is None:
        raise ValueError("Error sorting vertex")


# Path: lasercut/helper.py
# class ObjectProperties(object):
#     def __init__(self, **kwargs):
#         self.obj_class = str(type(self).__name__)
#         for k, v in kwargs.items():
#             if not hasattr(self, "_allowed") or str(k) in self._allowed:
#                 setattr(self, k, v)
#             #else:
#             #    FreeCAD.Console.PrintWarning(str(k) + " is not allowed for " + str(type(self)))
# 
# def sort_quad_vertex(list_edges, reverse):
#     list_points = []
#     if not reverse:
#         list_points = [list_edges[0].Vertexes[0].Point, list_edges[0].Vertexes[1].Point]
#     else:
#         list_points = [list_edges[0].Vertexes[1].Point, list_edges[0].Vertexes[0].Point]
#     for edge in list_edges[1:-1]:
#         vertex1 = edge.Vertexes[0].Point
#         vertex2 = edge.Vertexes[1].Point
# 
#         if compare_freecad_vector(vertex1, list_points[-1]):
#             list_points.append(vertex2)
#         elif compare_freecad_vector(vertex2, list_points[-1]):
#             list_points.append(vertex1)
#         else:
#             return None
# 
#     return list_points
# 
# def biggest_area_faces(freecad_shape):
#     sorted_list = sort_area_shape_faces(freecad_shape)
#     biggest_area_face = sorted_list[-1]
# #       contains : 0:normal, 1:area mm2, 2; list of faces
#     return biggest_area_face
# 
# def sort_area_shape_list(faces_list):
#     return sort_area_face_common(faces_list, compare_freecad_vector)
# 
# def compare_value(value1, value2, epsilon=10e-6):
#     value = value1 - value2
#     if math.fabs(value) < epsilon:
#         return True
#     return False


# Path: lasercut/material.py
import FreeCAD
import Part
import collections
from lasercut.helper import ObjectProperties, sort_quad_vertex, biggest_area_faces, sort_area_shape_list, compare_value

        if compare_value(thickness, self.thickness) is False:
            FreeCAD.Console.PrintError("Recomputed thickness for %s is different (%f != %f)\n" % (self.name, thickness, self.thickness))


# Prendre la normal la plus présente en terme de surface (biggest_area_faces)
# appliquer  une transformation pour orienter la normal vers Z
# l'éppaiseur et le Zlength du boundedbox (ce sera donc l'éppaisseur max)
def retrieve_thickness_from_bounded_box():
    return None


# Prend les deux premiere faces ayant la même normal (géré exception !! si une seule face)
# Pour chaque face recupere les points et calcule la plus petite distance entre chaque point
# de la premiere face et ceux de la deuxième face. La distance la plus petite est l'éppaisseur estimé.
def retrieve_thickness_from_biggest_face(freecad_object):
    area_faces = biggest_area_faces(freecad_object.Shape)
    # order faces by normals
    sub_areas_face = sort_area_shape_list(area_faces[2])
    # TODO : check if normals at opposite
    #list_edges_face1 = Part.__sortEdges__(area_faces[2][0].Edges)
    #list_edges_face2 = Part.__sortEdges__(area_faces[2][1].Edges)
    list_edges_face1 = Part.__sortEdges__(sub_areas_face[0][2][0].Edges)
    list_edges_face2 = Part.__sortEdges__(sub_areas_face[1][2][0].Edges)

    list_pts_face1 = sort_quad_vertex(list_edges_face1, False)
    if list_pts_face1 is None:
        list_pts_face1 = sort_quad_vertex(list_edges_face1, True)
    if list_pts_face1 is None:
        raise ValueError("Error sorting vertex")


    list_pts_face2 = sort_quad_vertex(list_edges_face2, False)