diff --git a/component_sketch.py b/component_sketch.py index 76b9ef9..17b9acb 100644 --- a/component_sketch.py +++ b/component_sketch.py @@ -26,6 +26,7 @@ USED, INPUT, OUTPUT, + CLOCK, ) from component_params import BOARD_830_PTS_PARAMS, DIP14_PARAMS from utils import resource_path @@ -2645,6 +2646,45 @@ def draw_pin_io(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZ ) params["tags"].append(arrow_head_id) + elif element_type == CLOCK: + x_start = x_distance + x_origin + 0 * scale + y_start = y_distance + y_origin - 7 * scale + + + l1 = 5 * scale + h = 5 * scale + l2 = 5 * scale + + # Draw the first horizontal line '_' + line1_id = self.canvas.create_line( + x_start, y_start, + x_start + l1, y_start, + fill="#404040", + width=2, + tags=(element_id, interactive_tag, outline_tag), + ) + params["tags"].append(line1_id) + + # Draw the vertical line '|' + line2_id = self.canvas.create_line( + x_start + l1, y_start, + x_start + l1, y_start - h, + fill="#404040", + width=2, + tags=(element_id, interactive_tag, outline_tag), + ) + params["tags"].append(line2_id) + + # Draw the second horizontal line '_' + line3_id = self.canvas.create_line( + x_start + l1, y_start - h, + x_start + l1 + l2, y_start - h, + fill="#404040", + width=2, + tags=(element_id, interactive_tag, outline_tag), + ) + params["tags"].append(line3_id) + self.current_dict_circuit[element_id] = params print("coord : " + str(coord[0][0]) + "," + str(coord[0][1])) diff --git a/dataCDLT.py b/dataCDLT.py index 8a1883a..deb74b1 100644 --- a/dataCDLT.py +++ b/dataCDLT.py @@ -8,6 +8,7 @@ USED = 1 INPUT = 0 OUTPUT = 1 +CLOCK = 2 NO = 0 YES = 1 LEFT = 0 diff --git a/menus.py b/menus.py index 2bcf6ac..cadca39 100644 --- a/menus.py +++ b/menus.py @@ -17,7 +17,7 @@ from breadboard import Breadboard -from dataCDLT import INPUT, OUTPUT, USED +from dataCDLT import INPUT, OUTPUT, USED, CLOCK MICROCONTROLLER_PINS = { "Arduino Mega": { @@ -193,11 +193,17 @@ def show_correspondence_table(self): # Gather pin_io objects from current_dict_circuit pin_ios = [value for key, value in self.current_dict_circuit.items() if key.startswith("_io_")] - # Separate pin_ios into inputs and outputs + # Separate pin_ios into inputs, outputs, and clocks input_pin_ios = [pin for pin in pin_ios if pin["type"] == INPUT] output_pin_ios = [pin for pin in pin_ios if pin["type"] == OUTPUT] + clock_pin_ios = [pin for pin in pin_ios if pin["type"] == CLOCK] - # Check if we have more pin_ios than available pins + # Ensure only one CLOCK type + if len(clock_pin_ios) > 1: + messagebox.showerror("Clock Error", "Only one CLOCK is allowed.") + return + + # Check pin counts if len(input_pin_ios) > len(input_pins): messagebox.showerror( "Too Many Inputs", @@ -216,21 +222,21 @@ def show_correspondence_table(self): # Create a new window for the correspondence table table_window = tk.Toplevel(self.parent) table_window.title("Correspondence Table") - table_window.geometry("400x300") + table_window.geometry("500x350") # Create a Treeview widget for the table - tree = ttk.Treeview(table_window, columns=("ID", "Type", "MCU Pin"), show="headings", height=10) + tree = ttk.Treeview(table_window, columns=("ID", "Type", "MCU Pin"), show="headings", height=15) tree.pack(expand=True, fill="both", padx=10, pady=10) # Define columns and headings tree.column("ID", anchor="center", width=120) - tree.column("Type", anchor="center", width=80) + tree.column("Type", anchor="center", width=120) tree.column("MCU Pin", anchor="center", width=120) tree.heading("ID", text="Pin IO ID") tree.heading("Type", text="Type") tree.heading("MCU Pin", text="MCU Pin") - # Populate the table with input and output pin mappings + # Populate the table with input, output, and clock pin mappings for idx, pin_io in enumerate(input_pin_ios): mcu_pin = input_pins[idx] pin_number = pin_io["id"].split("_")[-1] @@ -241,6 +247,11 @@ def show_correspondence_table(self): pin_number = pin_io["id"].split("_")[-1] tree.insert("", "end", values=(pin_number, "Output", mcu_pin)) + if clock_pin_ios: + clock_pin = pin_mappings["clock_pin"] + pin_number = clock_pin_ios[0]["id"].split("_")[-1] + tree.insert("", "end", values=(pin_number, "clk input", clock_pin)) + # Add a scrollbar if the list gets too long scrollbar = ttk.Scrollbar(table_window, orient="vertical", command=tree.yview) tree.configure(yscroll=scrollbar.set) diff --git a/toolbar.py b/toolbar.py index 9729d4b..aebf58e 100644 --- a/toolbar.py +++ b/toolbar.py @@ -12,7 +12,7 @@ from tkinter import messagebox, colorchooser import os from component_sketch import ComponentSketcher -from dataCDLT import INPUT, OUTPUT, FREE +from dataCDLT import INPUT, OUTPUT, FREE, CLOCK from utils import resource_path @@ -76,6 +76,7 @@ def create_topbar(self, parent: tk.Tk): # self.create_button("Power", left_frame, images) # à ajouter après si besoin self.create_button("Input", left_frame, images) self.create_button("Output", left_frame, images) + self.create_button("Clock", left_frame, images) # Create the color chooser and Delete button in the right frame self.color_button = tk.Button( @@ -96,7 +97,7 @@ def load_images(self) -> dict[str, tk.PhotoImage | None]: """ Loads PNG images from the 'icons' folder, scales them, and stores them in the images dictionary. """ - icon_names = ["connection", "power", "input", "output", "delete"] + icon_names = ["connection", "power", "input", "output", "delete", "clock"] icons_folder = Path(resource_path("Assets/Icons")).resolve() images: dict[str, tk.PhotoImage | None] = {} for name in icon_names: @@ -337,19 +338,26 @@ def canvas_click(self, event): self.sketcher.wire_drag_data["creating_wire"] = False print("Wire placement completed.") - elif self.tool_mode in ("Input", "Output") and self.sketcher.matrix[f"{col},{line}"]["state"] == FREE: + elif self.tool_mode in ("Input", "Output", "Clock") and self.sketcher.matrix[f"{col},{line}"]["state"] == FREE: # pin_io placement logic - type_const = INPUT if self.tool_mode == "Input" else OUTPUT - model_pin_io = [ - ( - self.sketcher.draw_pin_io, - 1, - {"color": self.selected_color, "type": type_const, "coord": [(col, line)], "matrix": self.sketcher.matrix}, - ) - ] - self.sketcher.circuit(x_origin, y_origin, model=model_pin_io) - # Optionally deactivate after placement - # self.cancel_pin_io_placement() + type_const = None + if self.tool_mode == "Clock": + type_const = CLOCK + elif self.tool_mode == "Output": + type_const = OUTPUT + elif self.tool_mode == "Input": + type_const = INPUT + if type_const is not None: + model_pin_io = [ + ( + self.sketcher.draw_pin_io, + 1, + {"color": self.selected_color, "type": type_const, "coord": [(col, line)], "matrix": self.sketcher.matrix}, + ) + ] + self.sketcher.circuit(x_origin, y_origin, model=model_pin_io) + # Optionally deactivate after placement + # self.cancel_pin_io_placement() def cancel_placement(self, _=None): """