# Path: lasercut/helper.py
# def transform(part, referentiel_face, transform_matrix=None, y_invert = False):
#     normal_face = referentiel_face.normalAt(0, 0)
#     # original center is (0,0,0)
#     transformed_center = referentiel_face.CenterOfMass #+ normal_face.normalize() * x_origin
#     if transform_matrix is None:
#         transform_matrix = get_matrix_transform(referentiel_face)
#     part.Placement = FreeCAD.Placement(transform_matrix).multiply(part.Placement)
#     part.translate(transformed_center)
#     if y_invert:
#         part.rotate(transformed_center, normal_face, 180.)
#     return part
# 
# def compare_freecad_vector(vector1, vector2, epsilon=10e-6):
#     vector = vector1.sub(vector2)
#     if math.fabs(vector.x) < epsilon and math.fabs(vector.y) < epsilon and math.fabs(vector.z) < epsilon:
#         return True
#     return False
# 
# def compare_value(value1, value2, epsilon=10e-6):
#     value = value1 - value2
#     if math.fabs(value) < epsilon:
#         return True
#     return False
# 
# class Segment:
#     def __init__(self, first=FreeCAD.Vector(0, 0, 0), second=FreeCAD.Vector(0, 0, 0)):
#         self.A = first
#         self.B = second
# 
#     def a(self):
#         return self.A
# 
#     def b(self):
#         return self.B * 1
# 
#     def clone_a(self):
#         return self.A * 1
# 
#     def clone_b(self):
#         return self.B * 1
# 
#     def vector(self):
#         return self.B.sub(self.A)
# 
#     def length(self):
#         return self.vector().Length
# 
#     def mid_point(self):
#         mid_point_b = self.A.add(self.B)
#         mid_point_b.scale(0.5, 0.5, 0.5)
#         return mid_point_b
# 
#     def get_angle(self, segment):
#         return self.vector().getAngle(segment.vector())
# 
#     def add(self, vector):
#         return Segment(self.A.add(vector), self.B.add(vector))
# 
#     def rotate_z(self, angle):
#         return Segment(rotate_vector_z(self.A, angle), rotate_vector_z(self.B, angle))
# 
#     def __repr__(self):
#         return "Segment A: " + str(self.A) + ", B: " + str(self.B)
# 
# def assemble_list_element(el_list):
#     if len(el_list) == 0:
#         return None
# 
#     part = el_list[0]
#     for el in el_list[1:]:
#         part = part.fuse(el)
# 
#     return part


import Part
import FreeCAD
import math
from lasercut.helper import transform, compare_freecad_vector, compare_value, Segment, assemble_list_element
# *                                                                         *
# *   This file is part of LCInterlocking module.                           *
# *   LCInterlocking module 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, or (at your option) any later version.    *
# *                                                                         *
# *   This module 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., 51 Franklin Street, Fifth Floor, Boston,            *
# *   MA  02110-1301  USA                                                   *
# *                                                                         *
# ***************************************************************************



def complete_hinges_properties(hinge, face_1, face_2, storeAll = False):
    edge1, edge2, extrusion_vector = get_coplanar_edge(face_1, face_2)
    seg_face_1, seg_face_2 = get_segment_from_edge(edge1, edge2)
    intersection_point = do_intersection(seg_face_1,seg_face_2)

    #print "intersection point : => " + str(intersection_point)
    #print "seg1 " +str(seg_face_1)
    #print "seg2 " +str(seg_face_2)


# Path: lasercut/helper.py
# def transform(part, referentiel_face, transform_matrix=None, y_invert = False):
#     normal_face = referentiel_face.normalAt(0, 0)
#     # original center is (0,0,0)
#     transformed_center = referentiel_face.CenterOfMass #+ normal_face.normalize() * x_origin
#     if transform_matrix is None:
#         transform_matrix = get_matrix_transform(referentiel_face)
#     part.Placement = FreeCAD.Placement(transform_matrix).multiply(part.Placement)
#     part.translate(transformed_center)
#     if y_invert:
#         part.rotate(transformed_center, normal_face, 180.)
#     return part
# 
# def compare_freecad_vector(vector1, vector2, epsilon=10e-6):
#     vector = vector1.sub(vector2)
#     if math.fabs(vector.x) < epsilon and math.fabs(vector.y) < epsilon and math.fabs(vector.z) < epsilon:
#         return True
#     return False
# 
# def compare_value(value1, value2, epsilon=10e-6):
#     value = value1 - value2
#     if math.fabs(value) < epsilon:
#         return True
#     return False
# 
# class Segment:
#     def __init__(self, first=FreeCAD.Vector(0, 0, 0), second=FreeCAD.Vector(0, 0, 0)):
#         self.A = first
#         self.B = second
# 
#     def a(self):
#         return self.A
# 
#     def b(self):
#         return self.B * 1
# 
#     def clone_a(self):
#         return self.A * 1
# 
#     def clone_b(self):
#         return self.B * 1
# 
#     def vector(self):
#         return self.B.sub(self.A)
# 
#     def length(self):
#         return self.vector().Length
# 
#     def mid_point(self):
#         mid_point_b = self.A.add(self.B)
#         mid_point_b.scale(0.5, 0.5, 0.5)
#         return mid_point_b
# 
#     def get_angle(self, segment):
#         return self.vector().getAngle(segment.vector())
# 
#     def add(self, vector):
#         return Segment(self.A.add(vector), self.B.add(vector))
# 
#     def rotate_z(self, angle):
#         return Segment(rotate_vector_z(self.A, angle), rotate_vector_z(self.B, angle))
# 
#     def __repr__(self):
#         return "Segment A: " + str(self.A) + ", B: " + str(self.B)
# 
# def assemble_list_element(el_list):
#     if len(el_list) == 0:
#         return None
# 
#     part = el_list[0]
#     for el in el_list[1:]:
#         part = part.fuse(el)
# 
#     return part


# Path: lasercut/makehinges.py
import Part
import FreeCAD
import math
from lasercut.helper import transform, compare_freecad_vector, compare_value, Segment, assemble_list_element

# *                                                                         *
# *   This file is part of LCInterlocking module.                           *
# *   LCInterlocking module 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, or (at your option) any later version.    *
# *                                                                         *
# *   This module 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., 51 Franklin Street, Fifth Floor, Boston,            *
# *   MA  02110-1301  USA                                                   *
# *                                                                         *
# ***************************************************************************



def complete_hinges_properties(hinge, face_1, face_2, storeAll = False):
    edge1, edge2, extrusion_vector = get_coplanar_edge(face_1, face_2)
    seg_face_1, seg_face_2 = get_segment_from_edge(edge1, edge2)
    intersection_point = do_intersection(seg_face_1,seg_face_2)

    #print "intersection point : => " + str(intersection_point)
    #print "seg1 " +str(seg_face_1)
    #print "seg2 " +str(seg_face_2)


    diff_length_test = compare_value(intersection_point.sub(seg_face_1.B).Length,