# Path: lasercut/roundedboxproperties.py
# class RoundedBoxProperties(ObjectProperties):
# 
#     _allowed = ('nb_face', 'inradius', 'height', 'side_length', 'max_side_length', 'thickness', 'cut')
# 
#     def __init__(self, **kwargs):
#         super(RoundedBoxProperties, self).__init__(**kwargs)
#         if not hasattr(self, 'nb_face'):
#             self.nb_face = int(5)
#         if not hasattr(self, 'inradius'):
#             self.inradius = 50.
#         if not hasattr(self, 'height'):
#             self.height = 30.
#         if not hasattr(self, 'thickness'):
#             self.thickness = 3.
#         if not hasattr(self, 'cut_nb'):
#             self.cut = int(0)
# 
#         self.side_length = 0.
#         self.max_side_length = 0.
#         self.compute_information(True)
# 
#     def compute_information(self, update_side_length = False):
#         circumradius =  self.inradius / math.cos(math.pi / float(self.nb_face))
#         self.max_side_length = 2 * circumradius * math.sin(math.pi / float(self.nb_face))
#         self.max_side_length = round(self.max_side_length - 0.01, 2)
# 
#         if update_side_length is True or self.side_length >= self.max_side_length :
#             self.side_length = math.floor(self.max_side_length * 0.75)
# 
#         if self.cut > self.nb_face:
#             self.cut = int(self.nb_face)
# 
# class TopBottomRoundedProperties(ObjectProperties):
#     _allowed = ('position', 'height_shift', 'radius_outside')
# 
#     POSITION_OUTSIDE = "Outside"
#     POSITION_INSIDE = "Inside"
# 
#     def __init__(self, **kwargs):
#         super(TopBottomRoundedProperties, self).__init__(**kwargs)
#         if not hasattr(self, 'position'):
#             self.position = self.POSITION_INSIDE
#         if not hasattr(self, 'height_shift'):
#             self.height_shift = 0.
#         if not hasattr(self, 'radius_outside'):
#             self.radius_outside = 0.
# 
# Path: lasercut/makehinges.py
# def do_intersection(seg1, seg2):
#     da = seg1.B - seg1.A
#     db = seg2.B - seg2.A
#     dc = seg2.A - seg1.A
# 
#     coplanar_val = dc.dot(da.cross(db))
#     if not compare_value(coplanar_val, 0.):
#         raise ValueError("Not coplanar (seg1: %s, seg2: %s) => res: %s" %(str(seg1), str(seg2), str(coplanar_val)))
# 
#     a = dc.cross(db).dot(da.cross(db))
#     s = dc.cross(db).dot(da.cross(db)) / da.cross(db).dot(da.cross(db))
#     if s >= 10e-6:
#         da.scale(s, s, s)
#         ip = seg1.A.add(da)
#         return ip
#     else:
#         raise ValueError("Wrong scale")


from FreeCAD import Gui
from lasercut.roundedboxproperties import RoundedBoxProperties, TopBottomRoundedProperties
from lasercut.makehinges import do_intersection
import FreeCAD
import FreeCADGui
import Part
import math
import lasercut.helper as helper
            face_2 = create_shape(mid_point_a, seg_b.A, seg_b.B, mid_point_b)
            part_2 = face_2.extrude(FreeCAD.Vector(0, 0, height))
            part_2.translate(FreeCAD.Vector(0, 0., -height/2))

            part_list.append({'shape': part_1, 'name': "side_face_%d_a" % index})
            part_list.append({'shape': part_2, 'name': "side_face_%d_b" % index})
        index += 1

    return part_list


def create_shape(p1, p2, p3, p4):
    l1 = Part.makeLine(p1, p2)
    l2 = Part.makeLine(p2, p3)
    l3 = Part.makeLine(p3, p4)
    l4 = Part.makeLine(p4, p1)

    wire = Part.Wire([l1, l2, l3, l4])
    face = Part.Face(wire)
    return face


def retrieve_segments_arc(polygon_segment):
    arcs_segment_list = []

    nb_face = len(polygon_segment)
    for index in range(nb_face):
        first_segment = polygon_segment[index][1]
        second_segment = polygon_segment[(index + 1) % nb_face][0]


# Path: lasercut/roundedboxproperties.py
# class RoundedBoxProperties(ObjectProperties):
# 
#     _allowed = ('nb_face', 'inradius', 'height', 'side_length', 'max_side_length', 'thickness', 'cut')
# 
#     def __init__(self, **kwargs):
#         super(RoundedBoxProperties, self).__init__(**kwargs)
#         if not hasattr(self, 'nb_face'):
#             self.nb_face = int(5)
#         if not hasattr(self, 'inradius'):
#             self.inradius = 50.
#         if not hasattr(self, 'height'):
#             self.height = 30.
#         if not hasattr(self, 'thickness'):
#             self.thickness = 3.
#         if not hasattr(self, 'cut_nb'):
#             self.cut = int(0)
# 
#         self.side_length = 0.
#         self.max_side_length = 0.
#         self.compute_information(True)
# 
#     def compute_information(self, update_side_length = False):
#         circumradius =  self.inradius / math.cos(math.pi / float(self.nb_face))
#         self.max_side_length = 2 * circumradius * math.sin(math.pi / float(self.nb_face))
#         self.max_side_length = round(self.max_side_length - 0.01, 2)
# 
#         if update_side_length is True or self.side_length >= self.max_side_length :
#             self.side_length = math.floor(self.max_side_length * 0.75)
# 
#         if self.cut > self.nb_face:
#             self.cut = int(self.nb_face)
# 
# class TopBottomRoundedProperties(ObjectProperties):
#     _allowed = ('position', 'height_shift', 'radius_outside')
# 
#     POSITION_OUTSIDE = "Outside"
#     POSITION_INSIDE = "Inside"
# 
#     def __init__(self, **kwargs):
#         super(TopBottomRoundedProperties, self).__init__(**kwargs)
#         if not hasattr(self, 'position'):
#             self.position = self.POSITION_INSIDE
#         if not hasattr(self, 'height_shift'):
#             self.height_shift = 0.
#         if not hasattr(self, 'radius_outside'):
#             self.radius_outside = 0.
# 
# Path: lasercut/makehinges.py
# def do_intersection(seg1, seg2):
#     da = seg1.B - seg1.A
#     db = seg2.B - seg2.A
#     dc = seg2.A - seg1.A
# 
#     coplanar_val = dc.dot(da.cross(db))
#     if not compare_value(coplanar_val, 0.):
#         raise ValueError("Not coplanar (seg1: %s, seg2: %s) => res: %s" %(str(seg1), str(seg2), str(coplanar_val)))
# 
#     a = dc.cross(db).dot(da.cross(db))
#     s = dc.cross(db).dot(da.cross(db)) / da.cross(db).dot(da.cross(db))
#     if s >= 10e-6:
#         da.scale(s, s, s)
#         ip = seg1.A.add(da)
#         return ip
#     else:
#         raise ValueError("Wrong scale")


# Path: lasercut/makeroundedbox.py
from FreeCAD import Gui
from lasercut.roundedboxproperties import RoundedBoxProperties, TopBottomRoundedProperties
from lasercut.makehinges import do_intersection
import FreeCAD
import FreeCADGui
import Part
import math
import lasercut.helper as helper

            face_2 = create_shape(mid_point_a, seg_b.A, seg_b.B, mid_point_b)
            part_2 = face_2.extrude(FreeCAD.Vector(0, 0, height))
            part_2.translate(FreeCAD.Vector(0, 0., -height/2))

            part_list.append({'shape': part_1, 'name': "side_face_%d_a" % index})
            part_list.append({'shape': part_2, 'name': "side_face_%d_b" % index})
        index += 1

    return part_list


def create_shape(p1, p2, p3, p4):
    l1 = Part.makeLine(p1, p2)
    l2 = Part.makeLine(p2, p3)
    l3 = Part.makeLine(p3, p4)
    l4 = Part.makeLine(p4, p1)

    wire = Part.Wire([l1, l2, l3, l4])
    face = Part.Face(wire)
    return face


def retrieve_segments_arc(polygon_segment):
    arcs_segment_list = []

    nb_face = len(polygon_segment)
    for index in range(nb_face):
        first_segment = polygon_segment[index][1]
        second_segment = polygon_segment[(index + 1) % nb_face][0]


        intersection_point = do_intersection(first_segment, second_segment)