from src.deFIBrillator import FIBG2, plot_stream_file, print_streamfile_time
from time import perf_counter


def main():

    for dwelltime in [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 2.5, 5, 7.5, 10]:

        # Set up FIB
        fib = FIBG2()
        fib.set_fov(10, "um")
        fib.set_beam(fib.Beams.Acceleration30kV.nA0_28)
        print(fib)

        curr = "0.28nA"

        # Create pattern
        pat = fib.new_pattern()
        pat.set_dwell_time(dwelltime, "us")
        pat.set_material(pat.Materials.Au)
        pat.set_depth(177, "nm")
        pat.set_scan_style(pat.ScanStyles.contour_inward)

        # Create bounds
        bounds = pat.add.rectangle()

        # Create honeycomb lattice
        lattice = pat.add.lattice(rows=int(12 / 2), cols=int(10 / 2), alpha=350*2 + 100, beta=350*2 + 100, gamma=60,
                                  shape=pat.add.regular_polygon(inner_radius=350, millable=False))
        bounds.x_span = lattice.x_max * 2 - 800
        bounds.y_span = lattice.y_max * 2 - 800

        # Add text
        txt = pat.add.text(f"{dwelltime} μs {curr} In", fontsize=300, millable=True)
        txt.place_next_to("y_max", bounds, offset=450)

        # Create streamfiles
        filename = r"C:\Users\mgnso\Desktop\Master thesis\Code\defibrillator\tests\Inwards\0.46nA\12800xMag_0.8.str"
        # pat.write_stream(filename)
        print_streamfile_time(filename)
        # plot_stream_file(filename)


def sudomain():
    # Set up FIB
    fib = FIBG2()
    fib.set_fov(10, "um")
    fib.set_beam(fib.Beams.Acceleration30kV.nA0_28)
    print(fib)

    # Create pattern
    pat = fib.new_pattern()
    pat.set_dwell_time(0.5, "us")
    pat.set_material(pat.Materials.Au)
    pat.set_depth(177, "nm")
    pat.set_scan_style(pat.ScanStyles.contour_inward)

    # Create hexagon placed to the left
    pat.add.regular_polygon(millable=True, inner_radius=350, x=-400)

    # Create new pattern with another hexagon, different dwell time same depth
    # Create pattern
    pat2 = fib.new_pattern()
    pat2.set_dwell_time(1, "us")
    pat2.set_material(pat2.Materials.Au)
    pat2.set_depth(177, "nm")
    pat2.set_scan_style(pat2.ScanStyles.contour_inward)

    # Create hexagon placed to the left
    pat2.add.regular_polygon(millable=True, inner_radius=350, x=400)

    # Create two stream files. Try to join them later
    pat.write_stream("left_hex")
    pat2.write_stream("right_hex")



sudomain()