# Path: lasercut/material.py
# 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:
#                 FreeCAD.Console.PrintError(e)
#         if not hasattr(self, 'thickness_tolerance'):
#             self.thickness_tolerance = 0.1 * self.thickness
#         if not hasattr(self, 'laser_beam_diameter'):
#             self.laser_beam_diameter = self.thickness / 15.0
#         if not hasattr(self, 'new_name'):
#             self.new_name = "%s_tab" % kwargs['freecad_object'].Label
#         if not hasattr(self, 'hole_width_tolerance'):
#             self.hole_width_tolerance = 0.0
#         # For cross part
#         if not hasattr(self, 'dog_bone'):
#             self.dog_bone = True
#         if not hasattr(self, 'node_type'):
#             self.node_type = self.NODE_NO
#         if not hasattr(self, 'node_thickness'):
#             self.node_thickness = 0.05 * self.thickness
#         if not hasattr(self, 'link_name'):
#             self.link_name = ""
# 
#     def recomputeInit(self, freecad_obj):
#         self.freecad_object = freecad_obj
#         thickness = retrieve_thickness_from_biggest_face(freecad_obj)
#         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))


import Part
import FreeCAD
import itertools
import lasercut.helper as helper
from lasercut.material import MaterialProperties
    wire = Part.Wire([l1, a2])
    face = Part.Face(wire)
    node = face.extrude(FreeCAD.Vector(0, thickness, 0))

    return node


def make_node_yz(width, height, thickness,  x_positive = True):

    p1 = FreeCAD.Vector(-thickness/2.0, 0, height / 2.0)
    p2 = FreeCAD.Vector(-thickness/2.0, 0, -height / 2.0)
    if x_positive is True:
        pa = FreeCAD.Vector(-thickness/2.0, width, 0.)
    else:
        pa = FreeCAD.Vector(-thickness/2.0, -width, 0.)

    l1 = Part.makeLine(p1, p2)
    a2 = Part.Arc(p2, pa, p1).toShape()
    wire = Part.Wire([l1, a2])
    face = Part.Face(wire)
    node = face.extrude(FreeCAD.Vector(thickness, 0, 0))

    return node

# noeud court = 1/4 hauteur
# noeud long = 1/2 hauteur
# 2 neouds court = 2 * 1/4 hauteur espace de 16 % de la hateur au centre

def make_nodes_xz(shape, x_length, thickness, z_length, node_type, node_thickness):


# Path: lasercut/material.py
# 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:
#                 FreeCAD.Console.PrintError(e)
#         if not hasattr(self, 'thickness_tolerance'):
#             self.thickness_tolerance = 0.1 * self.thickness
#         if not hasattr(self, 'laser_beam_diameter'):
#             self.laser_beam_diameter = self.thickness / 15.0
#         if not hasattr(self, 'new_name'):
#             self.new_name = "%s_tab" % kwargs['freecad_object'].Label
#         if not hasattr(self, 'hole_width_tolerance'):
#             self.hole_width_tolerance = 0.0
#         # For cross part
#         if not hasattr(self, 'dog_bone'):
#             self.dog_bone = True
#         if not hasattr(self, 'node_type'):
#             self.node_type = self.NODE_NO
#         if not hasattr(self, 'node_thickness'):
#             self.node_thickness = 0.05 * self.thickness
#         if not hasattr(self, 'link_name'):
#             self.link_name = ""
# 
#     def recomputeInit(self, freecad_obj):
#         self.freecad_object = freecad_obj
#         thickness = retrieve_thickness_from_biggest_face(freecad_obj)
#         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))


# Path: lasercut/crosspart.py
import Part
import FreeCAD
import itertools
import lasercut.helper as helper
from lasercut.material import MaterialProperties

    wire = Part.Wire([l1, a2])
    face = Part.Face(wire)
    node = face.extrude(FreeCAD.Vector(0, thickness, 0))

    return node


def make_node_yz(width, height, thickness,  x_positive = True):

    p1 = FreeCAD.Vector(-thickness/2.0, 0, height / 2.0)
    p2 = FreeCAD.Vector(-thickness/2.0, 0, -height / 2.0)
    if x_positive is True:
        pa = FreeCAD.Vector(-thickness/2.0, width, 0.)
    else:
        pa = FreeCAD.Vector(-thickness/2.0, -width, 0.)

    l1 = Part.makeLine(p1, p2)
    a2 = Part.Arc(p2, pa, p1).toShape()
    wire = Part.Wire([l1, a2])
    face = Part.Face(wire)
    node = face.extrude(FreeCAD.Vector(thickness, 0, 0))

    return node

# noeud court = 1/4 hauteur
# noeud long = 1/2 hauteur
# 2 neouds court = 2 * 1/4 hauteur espace de 16 % de la hateur au centre

def make_nodes_xz(shape, x_length, thickness, z_length, node_type, node_thickness):


    if node_type == MaterialProperties.NODE_NO: