Skip to content

Commit 0d55476

Browse files
authored
Merge d3db17e into 518a5a1
2 parents 518a5a1 + d3db17e commit 0d55476

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed

component_sketch.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
USED,
2727
INPUT,
2828
OUTPUT,
29+
CLOCK,
2930
)
3031
from component_params import BOARD_830_PTS_PARAMS, DIP14_PARAMS
3132
from utils import resource_path
@@ -2645,6 +2646,45 @@ def draw_pin_io(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZ
26452646
)
26462647
params["tags"].append(arrow_head_id)
26472648

2649+
elif element_type == CLOCK:
2650+
x_start = x_distance + x_origin + 0 * scale
2651+
y_start = y_distance + y_origin - 7 * scale
2652+
2653+
2654+
l1 = 5 * scale
2655+
h = 5 * scale
2656+
l2 = 5 * scale
2657+
2658+
# Draw the first horizontal line '_'
2659+
line1_id = self.canvas.create_line(
2660+
x_start, y_start,
2661+
x_start + l1, y_start,
2662+
fill="#404040",
2663+
width=2,
2664+
tags=(element_id, interactive_tag, outline_tag),
2665+
)
2666+
params["tags"].append(line1_id)
2667+
2668+
# Draw the vertical line '|'
2669+
line2_id = self.canvas.create_line(
2670+
x_start + l1, y_start,
2671+
x_start + l1, y_start - h,
2672+
fill="#404040",
2673+
width=2,
2674+
tags=(element_id, interactive_tag, outline_tag),
2675+
)
2676+
params["tags"].append(line2_id)
2677+
2678+
# Draw the second horizontal line '_'
2679+
line3_id = self.canvas.create_line(
2680+
x_start + l1, y_start - h,
2681+
x_start + l1 + l2, y_start - h,
2682+
fill="#404040",
2683+
width=2,
2684+
tags=(element_id, interactive_tag, outline_tag),
2685+
)
2686+
params["tags"].append(line3_id)
2687+
26482688
self.current_dict_circuit[element_id] = params
26492689

26502690
print("coord : " + str(coord[0][0]) + "," + str(coord[0][1]))

dataCDLT.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
USED = 1
99
INPUT = 0
1010
OUTPUT = 1
11+
CLOCK = 2
1112
NO = 0
1213
YES = 1
1314
LEFT = 0

menus.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from breadboard import Breadboard
1919

20-
from dataCDLT import INPUT, OUTPUT, USED
20+
from dataCDLT import INPUT, OUTPUT, USED, CLOCK
2121

2222
MICROCONTROLLER_PINS = {
2323
"Arduino Mega": {
@@ -193,11 +193,17 @@ def show_correspondence_table(self):
193193
# Gather pin_io objects from current_dict_circuit
194194
pin_ios = [value for key, value in self.current_dict_circuit.items() if key.startswith("_io_")]
195195

196-
# Separate pin_ios into inputs and outputs
196+
# Separate pin_ios into inputs, outputs, and clocks
197197
input_pin_ios = [pin for pin in pin_ios if pin["type"] == INPUT]
198198
output_pin_ios = [pin for pin in pin_ios if pin["type"] == OUTPUT]
199+
clock_pin_ios = [pin for pin in pin_ios if pin["type"] == CLOCK]
199200

200-
# Check if we have more pin_ios than available pins
201+
# Ensure only one CLOCK type
202+
if len(clock_pin_ios) > 1:
203+
messagebox.showerror("Clock Error", "Only one CLOCK is allowed.")
204+
return
205+
206+
# Check pin counts
201207
if len(input_pin_ios) > len(input_pins):
202208
messagebox.showerror(
203209
"Too Many Inputs",
@@ -216,21 +222,21 @@ def show_correspondence_table(self):
216222
# Create a new window for the correspondence table
217223
table_window = tk.Toplevel(self.parent)
218224
table_window.title("Correspondence Table")
219-
table_window.geometry("400x300")
225+
table_window.geometry("500x350")
220226

221227
# Create a Treeview widget for the table
222-
tree = ttk.Treeview(table_window, columns=("ID", "Type", "MCU Pin"), show="headings", height=10)
228+
tree = ttk.Treeview(table_window, columns=("ID", "Type", "MCU Pin"), show="headings", height=15)
223229
tree.pack(expand=True, fill="both", padx=10, pady=10)
224230

225231
# Define columns and headings
226232
tree.column("ID", anchor="center", width=120)
227-
tree.column("Type", anchor="center", width=80)
233+
tree.column("Type", anchor="center", width=120)
228234
tree.column("MCU Pin", anchor="center", width=120)
229235
tree.heading("ID", text="Pin IO ID")
230236
tree.heading("Type", text="Type")
231237
tree.heading("MCU Pin", text="MCU Pin")
232238

233-
# Populate the table with input and output pin mappings
239+
# Populate the table with input, output, and clock pin mappings
234240
for idx, pin_io in enumerate(input_pin_ios):
235241
mcu_pin = input_pins[idx]
236242
pin_number = pin_io["id"].split("_")[-1]
@@ -241,6 +247,11 @@ def show_correspondence_table(self):
241247
pin_number = pin_io["id"].split("_")[-1]
242248
tree.insert("", "end", values=(pin_number, "Output", mcu_pin))
243249

250+
if clock_pin_ios:
251+
clock_pin = pin_mappings["clock_pin"]
252+
pin_number = clock_pin_ios[0]["id"].split("_")[-1]
253+
tree.insert("", "end", values=(pin_number, "clk input", clock_pin))
254+
244255
# Add a scrollbar if the list gets too long
245256
scrollbar = ttk.Scrollbar(table_window, orient="vertical", command=tree.yview)
246257
tree.configure(yscroll=scrollbar.set)

toolbar.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tkinter import messagebox, colorchooser
1313
import os
1414
from component_sketch import ComponentSketcher
15-
from dataCDLT import INPUT, OUTPUT, FREE
15+
from dataCDLT import INPUT, OUTPUT, FREE, CLOCK
1616
from utils import resource_path
1717

1818

@@ -76,6 +76,7 @@ def create_topbar(self, parent: tk.Tk):
7676
# self.create_button("Power", left_frame, images) # à ajouter après si besoin
7777
self.create_button("Input", left_frame, images)
7878
self.create_button("Output", left_frame, images)
79+
self.create_button("Clock", left_frame, images)
7980

8081
# Create the color chooser and Delete button in the right frame
8182
self.color_button = tk.Button(
@@ -96,7 +97,7 @@ def load_images(self) -> dict[str, tk.PhotoImage | None]:
9697
"""
9798
Loads PNG images from the 'icons' folder, scales them, and stores them in the images dictionary.
9899
"""
99-
icon_names = ["connection", "power", "input", "output", "delete"]
100+
icon_names = ["connection", "power", "input", "output", "delete", "clock"]
100101
icons_folder = Path(resource_path("Assets/Icons")).resolve()
101102
images: dict[str, tk.PhotoImage | None] = {}
102103
for name in icon_names:
@@ -337,19 +338,26 @@ def canvas_click(self, event):
337338
self.sketcher.wire_drag_data["creating_wire"] = False
338339
print("Wire placement completed.")
339340

340-
elif self.tool_mode in ("Input", "Output") and self.sketcher.matrix[f"{col},{line}"]["state"] == FREE:
341+
elif self.tool_mode in ("Input", "Output", "Clock") and self.sketcher.matrix[f"{col},{line}"]["state"] == FREE:
341342
# pin_io placement logic
342-
type_const = INPUT if self.tool_mode == "Input" else OUTPUT
343-
model_pin_io = [
344-
(
345-
self.sketcher.draw_pin_io,
346-
1,
347-
{"color": self.selected_color, "type": type_const, "coord": [(col, line)], "matrix": self.sketcher.matrix},
348-
)
349-
]
350-
self.sketcher.circuit(x_origin, y_origin, model=model_pin_io)
351-
# Optionally deactivate after placement
352-
# self.cancel_pin_io_placement()
343+
type_const = None
344+
if self.tool_mode == "Clock":
345+
type_const = CLOCK
346+
elif self.tool_mode == "Output":
347+
type_const = OUTPUT
348+
elif self.tool_mode == "Input":
349+
type_const = INPUT
350+
if type_const is not None:
351+
model_pin_io = [
352+
(
353+
self.sketcher.draw_pin_io,
354+
1,
355+
{"color": self.selected_color, "type": type_const, "coord": [(col, line)], "matrix": self.sketcher.matrix},
356+
)
357+
]
358+
self.sketcher.circuit(x_origin, y_origin, model=model_pin_io)
359+
# Optionally deactivate after placement
360+
# self.cancel_pin_io_placement()
353361

354362
def cancel_placement(self, _=None):
355363
"""

0 commit comments

Comments
 (0)