# 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
# *                                                                         *
# ***************************************************************************



class MaterialProperties(ObjectProperties):

    _allowed = ('type', 'thickness', 'thickness_tolerance', 'hole_width_tolerance',
                'laser_beam_diameter', 'name', 'label', 'link_name',
                # For cross Part
                'dog_bone', 'node_type', 'node_thickness') #'freecad_object_index'
    TYPE_LASER_CUT = 1
    NODE_NO = "No node"
    NODE_SINGLE_SHORT = 'Single short'
    NODE_SINGLE_LONG = 'Single long'
    NODE_DUAL_SHORT = 'Dual short'

    def __init__(self, **kwargs):
        super(MaterialProperties, self).__init__(**kwargs)
        self.freecad_object = None
        #if not hasattr(self, 'freecad_object_index'):
        #    raise ValueError("Must defined freecad object")
        if not hasattr(self, 'type'):
            self.type = self.TYPE_LASER_CUT
        if not hasattr(self, 'thickness'):
            self.thickness = 5.0
            try:
                #self.thickness = retrieve_thickness_from_biggest_face(self.freecad_object)
                self.thickness = retrieve_thickness_from_biggest_face(kwargs['freecad_object'])
                # FreeCAD.Console.PrintError("found : %f\n" % self.thickness)

# 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

# *                                                                         *
# ***************************************************************************



class MaterialProperties(ObjectProperties):

    _allowed = ('type', 'thickness', 'thickness_tolerance', 'hole_width_tolerance',
                'laser_beam_diameter', 'name', 'label', 'link_name',
                # For cross Part
                'dog_bone', 'node_type', 'node_thickness') #'freecad_object_index'
    TYPE_LASER_CUT = 1
    NODE_NO = "No node"
    NODE_SINGLE_SHORT = 'Single short'
    NODE_SINGLE_LONG = 'Single long'
    NODE_DUAL_SHORT = 'Dual short'

    def __init__(self, **kwargs):
        super(MaterialProperties, self).__init__(**kwargs)
        self.freecad_object = None
        #if not hasattr(self, 'freecad_object_index'):
        #    raise ValueError("Must defined freecad object")
        if not hasattr(self, 'type'):
            self.type = self.TYPE_LASER_CUT
        if not hasattr(self, 'thickness'):
            self.thickness = 5.0
            try:
                #self.thickness = retrieve_thickness_from_biggest_face(self.freecad_object)
                self.thickness = retrieve_thickness_from_biggest_face(kwargs['freecad_object'])
                # FreeCAD.Console.PrintError("found : %f\n" % self.thickness)

            except ValueError as e: