from .basic import gds_logo
from ..primitives.shape_elements import el_line, el_arc_path, el_boundary, el_wedge, el_path, el_rect
from ..primitives.text_elements import el_polygon_text
from ..geometry.shapes.basic import shape_ellipse_arc
from ..geometry.transforms.magnification import gds_magnification
from ..geometry.transforms.rotation import gds_rotation
from ..constants import TEXT_ALIGN_LEFT, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, TEXT_ALIGN_BOTTOM, TEXT_ALIGN_MIDDLE, PATH_TYPE_ROUNDED

__all__ = ["gds_imec_logo", "gds_intec_logo", "gds_ugent_logo"]


class gds_intec_logo(gds_logo):
    name_prefix = "logo_intec_"

    def __calc__(self):        
        logo_size = (1.0, 1.1)
        scale = min([self.size[0]/logo_size[0],self.size[1]/logo_size[1]])
        line_width = scale * 0.05
        self.add_el(el_polygon_text(self.layer,'INTEC', (scale/2, 0.0), (TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM), 1, scale * 0.19))
        self.add_el(el_line(self.layer, (0.0,0.3*scale), (scale, 0.3 * scale), line_width, PATH_TYPE_ROUNDED))
        self.add_el(el_line(self.layer, (0.0,0.4*scale), (scale, 0.4 * scale), line_width, PATH_TYPE_ROUNDED))
        self.add_el(el_line(self.layer, (0.0,0.5*scale), (0.4 * scale, 0.5 * scale), line_width, PATH_TYPE_ROUNDED))
        self.add_el(el_line(self.layer, (0.6 * scale ,0.5*scale), (scale, 0.5 * scale), line_width, PATH_TYPE_ROUNDED))
        self.add_el(el_arc_path(self.layer, (0.5 * scale ,0.6 * scale), 0.1 * scale, line_width, 0.0, 180.0, 10.0, PATH_TYPE_ROUNDED))
        self.add_el(el_arc_path(self.layer, (0.5 * scale ,0.6 * scale), 0.2 * scale, line_width, 0.0, 180.0, 10.0, PATH_TYPE_ROUNDED))
        self.add_el(el_arc_path(self.layer, (0.5 * scale ,0.6 * scale), 0.3 * scale, line_width, 0.0, 180.0, 10.0, PATH_TYPE_ROUNDED))
        self.add_el(el_arc_path(self.layer, (0.5 * scale ,0.6 * scale), 0.4 * scale, line_width, 0.0, 180.0, 10.0, PATH_TYPE_ROUNDED))
        self.add_el(el_arc_path(self.layer, (0.5 * scale ,0.6 * scale), 0.5 * scale, line_width, 0.0, 180.0, 10.0, PATH_TYPE_ROUNDED))


class gds_ugent_logo(gds_logo):
    name_prefix = "logo_ugent_"

    def __calc__(self):        
        logo_size = (1.0, 1.05)
        scale = min([self.size[0]/logo_size[0],self.size[1]/logo_size[1]])
        line_width = scale * 0.025
        self.add_el(el_polygon_text(self.layer,'UNIVERSITEIT', (scale/2, scale* 0.25), (TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM), 1,  scale * 0.12))
        self.add_el(el_polygon_text(self.layer,'GENT', (scale/2, scale*  0.05), (TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM), 1,  scale * 0.12))
        self.add_el(el_line(self.layer, (0.0,0.0), (scale, 0.0), line_width))
        self.add_el(el_line(self.layer, (0.15*scale,0.45*scale), (0.85*scale, 0.45 * scale), line_width))
        self.add_el(el_line(self.layer, (0.18*scale,0.5*scale), (0.82*scale, 0.5 * scale), line_width))
        self.add_el(el_line(self.layer, (0.15*scale,0.85*scale), (0.85*scale, 0.85 * scale), line_width))
        self.add_el(el_line(self.layer, (0.18*scale,0.8*scale), (0.82*scale, 0.8 * scale), line_width))
        self.add_el(el_path(self.layer, [(0.14*scale,0.9*scale),(scale/2.0,1.05*scale),(0.86*scale, 0.9 * scale)], line_width))
        self.add_el(el_boundary(self.layer, [(0.20 * scale, 0.88*scale), (0.8*scale, 0.88 * scale), (0.8*scale, 0.89*scale), (scale/2.0, 1.0* scale), (0.2 * scale, 0.89 * scale), (0.20 * scale, 0.88 * scale)]))
        self.add_el(el_wedge(self.layer, (scale * 0.25,scale * 0.53), (scale * 0.25, scale * 0.77), scale * 0.06, scale * 0.04))
        self.add_el(el_wedge(self.layer, (scale * 0.35,scale * 0.53), (scale * 0.35, scale * 0.77), scale * 0.06, scale * 0.04))
        self.add_el(el_wedge(self.layer, (scale * 0.45,scale * 0.53), (scale * 0.45, scale * 0.77), scale * 0.06, scale * 0.04))
        self.add_el(el_wedge(self.layer, (scale * 0.55,scale * 0.53), (scale * 0.55, scale * 0.77), scale * 0.06, scale * 0.04))
        self.add_el(el_wedge(self.layer, (scale * 0.65,scale * 0.53), (scale * 0.65, scale * 0.77), scale * 0.06, scale * 0.04))
        self.add_el(el_wedge(self.layer, (scale * 0.75,scale * 0.53), (scale * 0.75, scale * 0.77), scale * 0.06, scale * 0.04))

class gds_imec_logo(gds_logo):
    name_prefix = "logo_imec_"
        
    def __calc__(self):
        logo_size = (112.0, 100.0)
        scale = min([self.size[0]/logo_size[0],self.size[1]/logo_size[1]])
        line_width = scale * 0.1
        # first ellipse
        sh1 = shape_ellipse_arc((0.0, 0.0), (88.8, 57.2), 98.3, 377)
        sh1 = gds_rotation((0.0, 0.0), 312)(sh1)
        sh1.move((12.5, 60))
        sh2 = shape_ellipse_arc((0.0, 0.0), (93.83, 61.840), 95.4, 378.2)
        sh2=gds_rotation((0.0, 0.0), 312)(sh2)
        sh2.move((11, 60))
        sh1.reverse()
        sh1 += (30.3, 83.0)
        sh1 += sh2
        sh1 += sh1[0]
        self += el_boundary(self.layer, gds_magnification((0.0, 0.0), scale)(sh1))
        
        # second ellipse
        sh1 = shape_ellipse_arc((0.0, 0.0), (73.2, 34.7), 138.5, 354.0)
        sh1.move((11.45, 35.8))
        sh2 = shape_ellipse_arc((0.0, 0.0), (78.2, 36.7), 133, 352.8)
        sh2.move((9.6, 35.23))
        sh2.reverse()
        sh1 += sh2
        sh1 += sh1[0]
        self += el_boundary(self.layer, gds_magnification((0.0, 0.0), scale)(sh1))
        

        # third ellipse
        sh1 = shape_ellipse_arc((0.0, 0.0), (42.8, 32.2), 96.0, 367.6)
        sh1= gds_rotation((0.0, 0.0), 47)(sh1)
        sh1.move((29.44, 22.71))
        sh2 = shape_ellipse_arc((0.0, 0.0), (46.7, 35.1), 94, 370.5)
        sh2=gds_rotation((0.0, 0.0), 47.5)(sh2)
        sh2.move((29.5, 21.75))
        sh2.reverse()
        sh2 += (15.84, 32.35)
        sh1 += (42.30, 40.4)
        sh1 += sh2
        sh1 += sh1[0]
        self += el_boundary(self.layer, gds_magnification((0.0, 0.0), scale)(sh1))

        self += el_polygon_text(self.layer,'IMEC', (5 * scale, scale* 64.0), (TEXT_ALIGN_LEFT, TEXT_ALIGN_MIDDLE), 1,  scale * 20.0)
    
    
class gds_old_imec_logo(gds_logo):
    name_prefix = "logo_imec_old_"
        
    def __calc__(self):
        logo_size = (0.9, 1.4)
        scale = min([self.size[0]/logo_size[0],self.size[1]/logo_size[1]])
        line_width = scale * 0.1
        self.add_el(el_polygon_text(self.layer,'IMEC', (scale*0.45, 0.0), (TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM), 1, scale * 0.2))
        self.add_el(el_path(self.layer, [(0.3 * scale, 0.4*scale),(0.3 * scale, 1.0*scale), (0.75 * scale, 1.0*scale),(0.75 * scale, 0.4*scale)], line_width))
        self.add_el(el_path(self.layer, [(0.9 * scale, 0.55*scale),(0.15 * scale, 0.55*scale), (0.15 * scale, 1.2*scale)], line_width))
        self.add_el(el_path(self.layer, [(0.9 * scale, 0.55*scale),(0.15 * scale, 0.55*scale), (0.15 * scale, 1.2*scale)], line_width))
        self.add_el(el_line(self.layer, (0.0 * scale, 0.85*scale), (0.75 * scale, 0.85*scale), line_width))
        self.add_el(el_line(self.layer, (0.5 * scale, 0.55*scale), (0.5 * scale, 1.2*scale), line_width))
        self.add_el(el_rect(self.layer, (0.15 * scale, 1.2*scale), (0.15*scale, 0.15*scale)))
        self.add_el(el_rect(self.layer, (0.75 * scale, 0.85*scale), (0.15*scale, 0.15*scale)))
        self.add_el(el_rect(self.layer, (0.5 * scale, 0.6*scale), (0.15*scale, 0.25*scale)))
        self.add_el(el_boundary(self.layer, [(0.37 * scale, 1.15*scale),(0.63 * scale, 1.15*scale), (0.5 * scale, 1.4*scale), (0.37* scale, 1.15 * scale)]))

