include <../modules/bidirectional_idt.scad>
include <../modules/wafer.scad>
include <../modules/parameter_text.scad>
// include <../pramas.scad>


// ================= openscad prams =================
$fa = 1;
$fs = 0.01;
// ================= openscad prams =================

// ================= meta =================
SCRIPT_VERSION="0.0.1";
// this really just need to be any mon font
FONT="Ubuntu Sans Mono:style=Regular";
test_number = 1;
// scale in m
scale_unit = 1e3;
// ================= meta =================


// ================= IDT =================
substrate = "LINBO";
// linbo
c = 3992.0;
// si
// c = 3159.0;
freq = 50.0e6;

// $fs = (c/freq);

// inout distance
distance = 50;

// number of finger
n_fingers = 50;

// should be 50-70
finger_length = 60; 

// for tweaking the design
gap = 0;

// for tweaking the design
thickness = 0;

has_id_number = true;
// ================= IDT =================

// ================= bond pad =================
leg_length = 0.003;
leg_width = 0.00001875;
leg_angle = 10;
size = 0.002;
bond_pad_shape = "square";
// ================= bond pad =================

// ================= text =================
info_block_offset_x=7;
info_block_offset_y=30;
info_block_scale=0.3;
title_text_size = 4;
prop_text_size = 2.5;
id_text_size = 1;
// ================= text =================

// ================= array spacings =================
number_of_idts_per_quadrent=4;
idt_x_spacing = 10;
idt_y_spacing = 12.5;
// ================= array spacings =================


// ================= wafers =================
wafer_size_inch = 4;
// ================= wafers =================

module params() {
    parameter_text(
        str("IDT ", substrate, "#", test_number),
        [
            str("c          (ms): ", c),
            str("freq       (Hz): ", freq),
            str("distance       : ", distance),
            str("n_fingers      : ", n_fingers),
            str("finger_length  : ", finger_length),
            str("gap            : ", gap),
            str("thickness      : ", thickness),
            str("leg_length     : ", leg_length),
            str("leg_angle      : ", leg_angle),
            str("size           : ", size),
            str("feat. size (mm): ", (c/freq)*1e3),
            str("version        : ", SCRIPT_VERSION)
        ]
    );
}



translate([info_block_offset_x, -info_block_offset_y, 0]) {
rotate([0, 0, -90]) 
scale([info_block_scale, info_block_scale, info_block_scale]) {
    params();
}
}

rotate([0, 0, 180])
translate([info_block_offset_x, -info_block_offset_y, 0]) {
rotate([0, 0, -90]) 
scale([info_block_scale, info_block_scale, info_block_scale]) {
    params();
}
}



if ($preview)
wafer(wafer_size_inch*0.0254*scale_unit);
// echo(str("number_of_idts_per_quadrent : ", number_of_idts_per_quadrent));
for (i=[0:number_of_idts_per_quadrent-1]) {
    translate([idt_x_spacing/4, 0, 0]) {
    translate([i * idt_x_spacing, idt_y_spacing/2, 0]) {
            bi_directional_idt(
                c, 
                freq, 
                n_fingers, 
                distance, 
                finger_length, 
                gap, 
                thickness, 
                post_scale=scale_unit,
                has_bond_pads = true,
                bond_pad_angle = leg_angle,
                bond_pad_leg_width = leg_width,
                bond_pad_leg_length = leg_length,
                bond_pad_size = size,
                has_id = has_id_number,
                id_number = i
            );
    }
    translate([i * idt_x_spacing, -idt_y_spacing/2, 0]) {
        scale([1, -1, 1]) {
            bi_directional_idt(
                c, 
                freq, 
                n_fingers, 
                distance, 
                finger_length, 
                gap, 
                thickness, 
                post_scale=scale_unit,
                has_bond_pads = true,
                bond_pad_angle = leg_angle,
                bond_pad_leg_width = leg_width,
                bond_pad_leg_length = leg_length,
                bond_pad_size = size,
                has_id = has_id_number,
                id_number = i + number_of_idts_per_quadrent,
                id_flip_dir = [1, -1, -1]
            );
       }
    }
    }

    scale([-1, 1, 1])
    translate([idt_x_spacing/4, 0, 0]) {
        
    translate([i * idt_x_spacing, idt_y_spacing/2, 0]) {
            bi_directional_idt(
                c, 
                freq, 
                n_fingers, 
                distance, 
                finger_length, 
                gap, 
                thickness, 
                post_scale=scale_unit,
                has_bond_pads = true,
                bond_pad_angle = leg_angle,
                bond_pad_leg_width = leg_width,
                bond_pad_leg_length = leg_length,
                bond_pad_size = size, 
                has_id = has_id_number,
                id_number = i + number_of_idts_per_quadrent*2,
                id_flip_dir = [-1, 1, 1]
            );
    }
    translate([i * idt_x_spacing, -idt_y_spacing/2, 0]) {
        scale([1, -1, 1]) {
            bi_directional_idt(
                c, 
                freq, 
                n_fingers, 
                distance, 
                finger_length, 
                gap, 
                thickness, 
                post_scale=scale_unit,
                has_bond_pads = true,
                bond_pad_angle = leg_angle,
                bond_pad_leg_width = leg_width,
                bond_pad_leg_length = leg_length,
                bond_pad_size = size, 
                has_id = has_id_number,
                id_number = i + number_of_idts_per_quadrent*3,
                id_flip_dir = [-1, -1, 1]
            );
        }
    }
    }
}

// bond_pad(
//     leg_length = 0.0075, 
//     leg_width = 0.00001875,
//     leg_angle = 20, 
//     size = 0.0075, 
//     bond_pad_shape = "square", 
//     post_scale = scale_unit
// );