Skip to content

Commit

Permalink
Support Amplifiers and refactor canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixdor committed Jul 17, 2024
1 parent 816633b commit 6eb62b2
Show file tree
Hide file tree
Showing 19 changed files with 600 additions and 150 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/main.spec
/build
/dist
/packaged
/packaged
/releases
10 changes: 10 additions & 0 deletions auxiliar/Calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def magnitude(self, start_point, final_point):
)
return magnitude

def difference(self, start_point, final_point):

x1 = start_point.x()
y1 = start_point.y()
x2 = final_point.x()
y2 = final_point.y()

difference = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2))
return difference

def angle(self, magnitude, start_point, final_point):

x1 = start_point.x()
Expand Down
77 changes: 64 additions & 13 deletions components/ComponentsCreator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from PyQt6.QtCore import Qt

from auxiliar.Calculate import Calculate
from components.ComponentsSelector import ComponentsSelector
from components.Latex import Latex
Expand Down Expand Up @@ -28,15 +30,16 @@ def create_traceable_final(self, canvas, path_svg):
canvas.devicePixelRatio(),
start_point, end_point,
tool,
canvas.current_label.text()
canvas.current_label.text(),
Qt.GlobalColor.black
)
else:
draw_comp = self.draw_component.line(start_point, end_point)
draw_comp = self.draw_component.line(start_point, end_point, Qt.GlobalColor.black)
canvas.update()

latex_comp = self.latex.get_one_pin(
start_point / canvas.cell_size,
end_point / canvas.cell_size,
start_point,
end_point,
tool.latex,
current_label)

Expand Down Expand Up @@ -70,26 +73,30 @@ def create_traceable(self, canvas):
end_point = canvas.end_point
current_label = canvas.current_label.text()

if start_point != end_point:
difference = self.calculate.difference(start_point, end_point)

if difference > 40 or tool.name == 'Wire':

if tool.name != 'Wire':
draw_comp = self.draw_component.two_pins(
canvas.scene, canvas.devicePixelRatio(),
start_point, end_point,
tool.image, tool.image_static, current_label
tool.image, tool.image_static, current_label,
Qt.GlobalColor.black
)
else:
draw_comp = self.draw_component.two_pins_no_img(
canvas.scene,
start_point, end_point,
current_label
current_label,
Qt.GlobalColor.black
)
canvas.update()

latex_comp = self.latex.get_two_pin(
tool.name,
start_point / canvas.cell_size,
end_point / canvas.cell_size,
start_point,
end_point,
tool.latex,
current_label)

Expand All @@ -116,11 +123,10 @@ def create_traceable(self, canvas):
self.history.new_event_undo(1, None, new_comp)
self.history.list_redo.clear()

def create_transistor(self, canvas, path_svg):
def create_transistor(self, canvas, point, path_svg):
if os.path.exists(path_svg):

tool = canvas.tool
point = canvas.end_point
current_label = canvas.current_label.text()

draw_comp = self.draw_component.transistor(
Expand All @@ -132,7 +138,52 @@ def create_transistor(self, canvas, path_svg):

latex_comp = self.latex.get_transistor(
len(canvas.components) + 1,
point / canvas.cell_size,
point,
tool.latex,
current_label
)

new_comp = ObjComponent(
num=len(canvas.components) + 1,
name=tool.name,
group_name=tool.group_name,
class_name=tool.class_name,
seed_latex=tool.latex,
middle_point=point,
angle=0,
positions=[point],
label=current_label,
drawables=draw_comp,
latex=latex_comp
)

canvas.components.append(new_comp)

self.history.new_event_undo(1, None, new_comp)
self.history.list_redo.clear()

else:
print("No found image")

def create_amplifier(self, canvas, path_svg):

if os.path.exists(path_svg):

tool = canvas.tool
point = canvas.end_point
current_label = canvas.current_label.text()

draw_comp = self.draw_component.amplifier(
canvas.scene, canvas.devicePixelRatio(), canvas.end_point,
path_svg, canvas.current_label.text(),
)

canvas.update()

latex_comp = self.latex.get_amplifier(
len(canvas.components) + 1,
point.x(),
point.y(),
tool.latex,
current_label
)
Expand Down Expand Up @@ -175,7 +226,7 @@ def create_transformer(self, canvas, path_svg):

latex_comp = self.latex.get_transformer(
len(canvas.components) + 1,
point / canvas.cell_size,
point,
tool.latex,
current_label
)
Expand Down
34 changes: 27 additions & 7 deletions components/ComponentsEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def label(self, canvas, input_text):
if component.class_name == 'Traceable_Final':

if component.group_name == 'Power Supplies':
item_label = drawer.label1_center(
item_label = drawer.label_center_horizontal(
name_tool=component.name,
pos_point=component.positions[1],
label=input_text
Expand All @@ -59,8 +59,8 @@ def label(self, canvas, input_text):
component.drawables.append(item_label)

new_latext = self.latex.get_one_pin(
start_point=component.positions[0] / canvas.cell_size,
final_point=component.positions[1] / canvas.cell_size,
start_point=component.positions[0],
final_point=component.positions[1],
latex=component.seed_latex,
label=input_text
)
Expand All @@ -81,8 +81,8 @@ def label(self, canvas, input_text):

new_latext = self.latex.get_two_pin(
component.name,
start_point=component.positions[0] / canvas.cell_size,
final_point=component.positions[1] / canvas.cell_size,
start_point=component.positions[0],
final_point=component.positions[1],
latex=component.seed_latex,
label=input_text
)
Expand All @@ -101,7 +101,27 @@ def label(self, canvas, input_text):

new_latext = self.latex.get_transistor(
id_node=component.num,
point=component.middle_point / canvas.cell_size,
point=component.middle_point,
latex=component.seed_latex,
label=input_text
)
component.latex = new_latext

elif component.class_name == 'Amplifier':

item_label = drawer.label_center(
pos_point=component.middle_point,
label=input_text
)

component.drawables.remove(draw)
canvas.scene.removeItem(draw)
component.drawables.append(item_label)

new_latext = self.latex.get_amplifier(
id_node=component.num,
x=component.middle_point.x(),
y=component.middle_point.y(),
latex=component.seed_latex,
label=input_text
)
Expand All @@ -120,7 +140,7 @@ def label(self, canvas, input_text):

new_latext = self.latex.get_transformer(
id_node=component.num,
point=component.middle_point / canvas.cell_size,
point=component.middle_point,
latex=component.seed_latex,
label=input_text
)
Expand Down
5 changes: 4 additions & 1 deletion components/ComponentsSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
from PyQt6.QtGui import QColor
from PyQt6.QtWidgets import QGraphicsTextItem, QGraphicsLineItem, QGraphicsRectItem

from ui.Resources import Resources


class ComponentsSelector:

def __init__(self):
super().__init__()
self.resources = Resources()

def unselect(self, canvas):

Expand Down Expand Up @@ -65,7 +68,7 @@ def select(self, canvas, component):
canvas.rect_select.setBrush(Qt.GlobalColor.transparent)
pen = canvas.rect_select.pen()
pen.setStyle(Qt.PenStyle.DotLine)
pen.setColor(QColor('#DB6725'))
pen.setColor(self.resources.get_color_shadow())
pen.setWidth(2)
canvas.rect_select.setPen(pen)

Expand Down
64 changes: 43 additions & 21 deletions components/Latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@

class Latex:

def __init__(self):
super().__init__()
self.cell_size = 50

def get_one_pin(self, start_point, final_point, latex, label):
draws = []
x1 = str(start_point.x())
y1 = str(start_point.y())
x2 = str(final_point.x())
y2 = str(final_point.y())
x1 = str(start_point.x() / self.cell_size)
y1 = str(start_point.y() / self.cell_size)
x2 = str(final_point.x() / self.cell_size)
y2 = str(final_point.y() / self.cell_size)

draw_text = '\\draw (' + x1 + ",-" + y1 + ')to(' + x2 + ',-' + y2 + ') ' + latex + '{' + label + '}' + ';'
draw_text = '\\draw(' + x1 + ",-" + y1 + ')to(' + x2 + ',-' + y2 + ') ' + latex + '{' + label + '}' + ';'
draws.append(draw_text)

return draws

def get_two_pin(self, name_tool, start_point, final_point, latex, label):
draws = []
x1 = str(start_point.x())
y1 = str(start_point.y())
x2 = str(final_point.x())
y2 = str(final_point.y())
x1 = str(start_point.x() / self.cell_size)
y1 = str(start_point.y() / self.cell_size)
x2 = str(final_point.x() / self.cell_size)
y2 = str(final_point.y() / self.cell_size)

if name_tool == 'Ramp Oscilloscope':
draws.append('\\ctikzset{bipoles/oscope/waveform=ramps}')
Expand All @@ -45,10 +49,14 @@ def get_transistor(self, id_node, point, latex, label):
draws = []
node = 'Q' + str(id_node)
top = QPoint(point.x(), point.y() - 1)
top_x = (point.x() / self.cell_size)
top_y = (point.y() / self.cell_size) - 0.5
button = QPoint(point.x(), point.y() + 1)
middle = QPoint(point.x() - 1, point.y())
x = str(point.x())
y = str(point.y())
button_x = (point.x() / self.cell_size)
button_y = (point.y() / self.cell_size) + 0.5

x = str(point.x() / self.cell_size)
y = str(point.y() / self.cell_size)

if latex.__contains__('mos'):
draw_properties = '\\ctikzset{tripoles/mos style/arrows}'
Expand All @@ -60,16 +68,13 @@ def get_transistor(self, id_node, point, latex, label):
else:
conf = ['E', 'B', 'C']

draw_node = '\\draw (' + x + ",-" + y + ') ' + latex + '(' + node + ')' + '{' + label + '}' + ';'
draw_line_top = '\\draw[short](' + node + '.' + conf[0] + ')to(' + str(top.x()) + ',-' + str(top.y()) + ');'
draw_line_middle = '\\draw[short](' + node + '.' + conf[1] + ')to(' + str(middle.x()) + ',-' + str(
middle.y()) + ');'
draw_line_button = '\\draw[short](' + node + '.' + conf[2] + ')to(' + str(button.x()) + ',-' + str(
button.y()) + ');'
draw_node = '\\draw(' + x + ",-" + y + ') ' + latex + '(' + node + ')' + '{' + label + '}' + ';'
draw_line_top = '\\draw[short](' + node + '.' + conf[0] + ')to(' + str(top_x) + ',-' + str(top_y) + ');'
draw_line_button = '\\draw[short](' + node + '.' + conf[2] + ')to(' + str(button_x) + ',-' + str(
button_y) + ');'

draws.append(draw_node)
draws.append(draw_line_top)
draws.append(draw_line_middle)
draws.append(draw_line_button)

return draws
Expand All @@ -78,11 +83,28 @@ def get_transformer(self, id_node, point, latex, label):

draws = []
node = 'Q' + str(id_node)
x = str(point.x())
y = str(point.y())
x = str(point.x() / self.cell_size)
y = str(point.y() / self.cell_size)

draw_node = '\\draw (' + x + ",-" + y + ') ' + latex + '(' + node + ')' + '{' + label + '}' + ';'
draws.append(draw_node)

return draws

def get_amplifier(self, id_node, x, y, latex, label):

draws = []
node = 'Q' + str(id_node)

x_int = x / self.cell_size
x = str((x / self.cell_size) + 0.22)
y = str(y / self.cell_size)

draw_node = '\\draw (' + x + ",-" + y + ') ' + latex + '(' + node + ')' + '{' + label + '}' + ';'
draw_out = '\\draw[short](' + node + '.out)to(+' + str(x_int+1.5) + ', -' + y + ');'

draws.append(draw_node)
draws.append(draw_out)

return draws

Expand Down
Loading

0 comments on commit 6eb62b2

Please sign in to comment.