import numpy as np
from math import pi
from gdshelpers.geometry.chip import Cell
from gdshelpers.parts.waveguide import Waveguide
from gdshelpers.parts.coupler import GratingCoupler

coupler_params = {
    'width': 1.3,
    'full_opening_angle': np.deg2rad(40),
    'grating_period': 1.155,
    'grating_ff': 0.85,
    'n_gratings': 20,
    'taper_length': 16.
}

left_coupler = GratingCoupler.make_traditional_coupler((0,0), **coupler_params)
right_coupler = GratingCoupler.make_traditional_coupler((250,0), **coupler_params)

wg = Waveguide.make_at_port(left_coupler.port)
wg.add_straight_segment_until_y(50)
wg.add_bend(np.deg2rad(-45), 10)
wg.add_straight_segment_until_x(50)
wg.add_bend(np.deg2rad(-30), 10)
wg.add_route_single_circle_to_port(right_coupler.port, 10)

cell = Cell('SIMPLE_DEVICE')
cell.add_to_layer(1, left_coupler, wg, right_coupler)
cell.show()