Skip to content

Commit 06ac5b2

Browse files
committed
save and open inclusion
1 parent 5db4c47 commit 06ac5b2

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

breadboard.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def draw_matrix_points(self, scale=1): # used to debug the matrix
183183
radius = 2 * scale # Adjust size as needed
184184
self.canvas.create_oval(x - radius, y - radius, x + radius, y + radius, fill=color, outline="")
185185

186-
def draw_blank_board_model(self, x_origin: int = 50, y_origin: int = 10):
186+
def draw_blank_board_model(self, x_origin: int = 50, y_origin: int = 10, battery_pos_wire_end=None, battery_neg_wire_end=None):
187187
"""
188188
Draws a blank breadboard model on the canvas.
189189
"""
@@ -253,4 +253,9 @@ def draw_blank_board_model(self, x_origin: int = 50, y_origin: int = 10):
253253

254254
battery_x = x_origin + 1200 # Adjust as needed for proper positioning
255255
battery_y = y_origin + 300 # Adjust as needed for proper positioning
256-
self.sketcher.draw_battery(battery_x, battery_y)
256+
self.sketcher.draw_battery(
257+
battery_x,
258+
battery_y,
259+
pos_wire_end=battery_pos_wire_end,
260+
neg_wire_end=battery_neg_wire_end,
261+
)

component_sketch.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,15 +2673,15 @@ def clear_board(self):
26732673
# TODO Khalid update the Circuit instance
26742674

26752675

2676-
def draw_battery(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZONTAL, **kwargs):
2676+
def draw_battery(self, x_distance, y_distance, scale=1, width=-1, direction=HORIZONTAL, pos_wire_end=None, neg_wire_end=None, **kwargs):
26772677
"""
26782678
Draws a battery at the given coordinates with two hanging wires.
26792679
"""
26802680
if width != -1:
26812681
scale = width / 9.0
26822682

26832683
inter_space = 15 * scale
2684-
thickness = 1 * self.scale_factor # Adjusted thickness
2684+
thickness = 1 * self.scale_factor
26852685

26862686
battery_id = '_battery'
26872687

@@ -2777,15 +2777,21 @@ def draw_battery(self, x_distance, y_distance, scale=1, width=-1, direction=HORI
27772777
pos_wire_id = '_battery_pos_wire'
27782778
pos_wire_start_x = battery_x
27792779
pos_wire_start_y = battery_y + battery_height - 15 * scale
2780-
pos_wire_end_x = battery_x - 100 * scale # Wires go to the left
2781-
pos_wire_end_y = pos_wire_start_y
2780+
if pos_wire_end:
2781+
pos_wire_end_x, pos_wire_end_y = pos_wire_end
2782+
else:
2783+
pos_wire_end_x = battery_x - 100 * scale # Wires go to the left
2784+
pos_wire_end_y = pos_wire_start_y
27822785

27832786
# Negative wire (from the '-' sign at the top)
27842787
neg_wire_id = '_battery_neg_wire'
27852788
neg_wire_start_x = battery_x
27862789
neg_wire_start_y = battery_y + 15 * scale
2787-
neg_wire_end_x = battery_x - 100 * scale # Wires go to the left
2788-
neg_wire_end_y = neg_wire_start_y
2790+
if neg_wire_end:
2791+
neg_wire_end_x, neg_wire_end_y = neg_wire_end
2792+
else:
2793+
neg_wire_end_x = battery_x - 100 * scale # Wires go to the left
2794+
neg_wire_end_y = neg_wire_start_y
27892795

27902796
# Use draw_battery_wire to draw the wires with similar appearance to draw_wire
27912797
# Positive wire

menus.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from breadboard import Breadboard
1515

16-
from dataCDLT import INPUT, OUTPUT
16+
from dataCDLT import INPUT, OUTPUT, USED
1717

1818
MICROCONTROLLER_PINS = {
1919
"Arduino Mega": {
@@ -117,7 +117,7 @@ def __init__(
117117
"NodeMCU ESP32"
118118
],
119119
"Ports": ["Configure Ports"],
120-
"Export": ["Show Correspondence Table"],
120+
"Export": ["Correspondence Table"],
121121
"Help": ["Documentation", "About"],
122122
}
123123

@@ -344,6 +344,8 @@ def new_file(self):
344344
# Clear the canvas and reset the circuit
345345
self.board.sketcher.clear_board()
346346
self.board.fill_matrix_1260_pts()
347+
self.board.draw_blank_board_model()
348+
347349
print("New file created.")
348350
messagebox.showinfo("New File", "A new circuit has been created.")
349351

@@ -363,6 +365,23 @@ def open_file(self):
363365
x_o, y_o = self.board.sketcher.id_origins["xyOrigin"]
364366
self.board.sketcher.circuit(x_o, y_o, model=[])
365367

368+
battery_pos_wire_end = None
369+
battery_neg_wire_end = None
370+
371+
for key, val in circuit_data.items():
372+
if key == "_battery_pos_wire":
373+
battery_pos_wire_end = val['end']
374+
elif key == "_battery_neg_wire":
375+
battery_neg_wire_end = val['end']
376+
377+
# Redraw the blank board model, including the battery with wire positions
378+
self.board.draw_blank_board_model(
379+
x_o,
380+
y_o,
381+
battery_pos_wire_end=battery_pos_wire_end,
382+
battery_neg_wire_end=battery_neg_wire_end,
383+
)
384+
366385
for key, val in circuit_data.items():
367386
if "chip" in key:
368387
x, y = val["XY"]
@@ -378,7 +397,7 @@ def open_file(self):
378397
]
379398
self.board.sketcher.circuit(x, y, model=model_chip)
380399

381-
elif "wire" in key:
400+
elif "wire" in key and not key.startswith("_battery"):
382401
model_wire = [
383402
(
384403
self.board.sketcher.draw_wire,
@@ -433,6 +452,8 @@ def save_file(self):
433452
comp_data["label"] = comp_data["type"]
434453
if "wire" in key:
435454
comp_data.pop("XY", None) # Remove XY, will be recalculated anyway
455+
if key == "_battery":
456+
comp_data.pop("battery_rect", None)
436457
# Save the data to a JSON file
437458
with open(file_path, "w", encoding="utf-8") as file:
438459
json.dump(circuit_data, file, indent=4)

0 commit comments

Comments
 (0)