syedwaqarumer commited on
Commit
ada5868
·
verified ·
1 Parent(s): cd7cbcb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+ import matplotlib.patches as patches
4
+
5
+ # Function to generate a basic PCB design
6
+ def generate_pcb_design(board_width, board_height, components):
7
+ fig, ax = plt.subplots(figsize=(8, 8))
8
+
9
+ # Set the dimensions of the PCB board
10
+ ax.set_xlim(0, board_width)
11
+ ax.set_ylim(0, board_height)
12
+
13
+ # Configure the plot to represent a PCB (green board with components)
14
+ ax.set_facecolor("#2E8B57") # PCB typical green color
15
+ boundary_color = 'white'
16
+ boundary_thickness = 2
17
+
18
+ # Loop through components and place them on the PCB
19
+ for component in components:
20
+ component_type, x_pos, y_pos, width, height, label = component
21
+
22
+ # Draw the component as a rectangle
23
+ ax.add_patch(patches.Rectangle((x_pos, y_pos), width, height,
24
+ edgecolor=boundary_color, facecolor='gray', lw=boundary_thickness))
25
+
26
+ # Add label to the component
27
+ ax.text(x_pos + width / 2, y_pos + height / 2, label,
28
+ ha='center', va='center', fontsize=10, color='white', weight='bold')
29
+
30
+ # Draw traces (lines between components)
31
+ for i in range(len(components) - 1):
32
+ start_component = components[i]
33
+ end_component = components[i + 1]
34
+ start_x = start_component[1] + start_component[3] / 2 # Midpoint of width
35
+ start_y = start_component[2] + start_component[4] / 2 # Midpoint of height
36
+ end_x = end_component[1] + end_component[3] / 2
37
+ end_y = end_component[2] + end_component[4] / 2
38
+
39
+ # Draw a line (trace) between the two components
40
+ ax.plot([start_x, end_x], [start_y, end_y], color='yellow', lw=2)
41
+
42
+ ax.set_aspect('equal')
43
+ ax.set_axis_off() # Hide axes for cleaner appearance
44
+
45
+ st.pyplot(fig)
46
+
47
+ # Streamlit app title
48
+ st.title("PCB Design Generator")
49
+
50
+ # Get input from the user for PCB dimensions
51
+ board_width = st.number_input("PCB Board Width (mm)", value=100)
52
+ board_height = st.number_input("PCB Board Height (mm)", value=80)
53
+
54
+ num_components = st.slider("Number of Components", 1, 10, 4)
55
+ components = []
56
+
57
+ # Input component details
58
+ for i in range(num_components):
59
+ st.subheader(f"Component {i + 1} Details")
60
+ component_type = st.selectbox(f"Component {i + 1} Type", ["Resistor", "Capacitor", "IC", "Diode", "Transistor"])
61
+ x_pos = st.number_input(f"Component {i + 1} X Position (mm)", value=10)
62
+ y_pos = st.number_input(f"Component {i + 1} Y Position (mm)", value=10)
63
+ width = st.number_input(f"Component {i + 1} Width (mm)", value=10)
64
+ height = st.number_input(f"Component {i + 1} Height (mm)", value=5)
65
+ label = st.text_input(f"Component {i + 1} Label", value=f"{component_type} {i + 1}")
66
+ components.append((component_type, x_pos, y_pos, width, height, label))
67
+
68
+ # Generate button
69
+ if st.button("Generate PCB Layout"):
70
+ generate_pcb_design(board_width, board_height, components)