- Added new buttons and settings
This commit is contained in:
parent
3e88e41e4b
commit
878b6093b7
@ -264,7 +264,7 @@ class SketchWidget(QWidget):
|
||||
def update_ui_points(self, point_list: list):
|
||||
# Print initial state of slv_points_main
|
||||
# print("Initial slv_points_main:", self.slv_points_main)
|
||||
print("Change list:", point_list)
|
||||
#print("Change list:", point_list)
|
||||
|
||||
if len(point_list) > 0:
|
||||
for tbu_points_idx in point_list:
|
||||
@ -291,7 +291,7 @@ class SketchWidget(QWidget):
|
||||
if event.button() == Qt.LeftButton and not self.mouse_mode:
|
||||
self.drag_buffer[1] = local_event_pos
|
||||
|
||||
print("Le main buffer", self.drag_buffer)
|
||||
#print("Le main buffer", self.drag_buffer)
|
||||
|
||||
if not None in self.main_buffer and len(self.main_buffer) == 2:
|
||||
entry = self.drag_buffer[0]
|
||||
@ -343,7 +343,7 @@ class SketchWidget(QWidget):
|
||||
|
||||
self.line_draw_buffer[1] = point
|
||||
|
||||
print("Buffer state", self.line_draw_buffer)
|
||||
#print("Buffer state", self.line_draw_buffer)
|
||||
|
||||
if self.line_draw_buffer[0] and self.line_draw_buffer[1]:
|
||||
|
||||
@ -367,7 +367,7 @@ class SketchWidget(QWidget):
|
||||
self.main_buffer[1] = self.get_handle_from_ui_point(self.hovered_point)
|
||||
|
||||
if self.main_buffer[0] and self.main_buffer[1]:
|
||||
print("buf", self.main_buffer)
|
||||
# print("buf", self.main_buffer)
|
||||
|
||||
self.sketch.coincident(self.main_buffer[0], self.main_buffer[1], self.sketch.wp)
|
||||
|
||||
@ -387,7 +387,7 @@ class SketchWidget(QWidget):
|
||||
self.main_buffer = [None, None]
|
||||
|
||||
if event.button() == Qt.LeftButton and self.mouse_mode == "pt_line":
|
||||
print("ptline")
|
||||
#print("ptline")
|
||||
line_selected = None
|
||||
|
||||
if self.hovered_point and not self.main_buffer[1]:
|
||||
@ -418,7 +418,7 @@ class SketchWidget(QWidget):
|
||||
self.main_buffer = [None, None]
|
||||
|
||||
if event.button() == Qt.LeftButton and self.mouse_mode == "pb_con_mid":
|
||||
print("ptline")
|
||||
#print("ptline")
|
||||
line_selected = None
|
||||
|
||||
if self.hovered_point and not self.main_buffer[1]:
|
||||
@ -490,7 +490,7 @@ class SketchWidget(QWidget):
|
||||
e2 = None
|
||||
|
||||
if self.hovered_point:
|
||||
print("buf point")
|
||||
# print("buf point")
|
||||
# Get the point as UI point as buffer
|
||||
self.main_buffer[0] = self.hovered_point
|
||||
|
||||
@ -562,7 +562,7 @@ class SketchWidget(QWidget):
|
||||
|
||||
if closest_point != self.hovered_point:
|
||||
self.hovered_point = closest_point
|
||||
print(self.hovered_point)
|
||||
#print(self.hovered_point)
|
||||
|
||||
for line in self.sketch.lines:
|
||||
p1 = line.crd1.ui_point
|
||||
@ -700,6 +700,10 @@ class SketchWidget(QWidget):
|
||||
pen_normal = QPen(Qt.gray)
|
||||
pen_normal.setWidthF(2 / self.zoom)
|
||||
|
||||
pen_planned = QPen(Qt.gray)
|
||||
pen_planned.setStyle(Qt.PenStyle.DotLine)
|
||||
pen_planned.setWidthF(2 / self.zoom)
|
||||
|
||||
pen_construct = QPen(Qt.cyan)
|
||||
pen_construct.setStyle(Qt.PenStyle.DotLine)
|
||||
pen_construct.setWidthF(1 / self.zoom)
|
||||
@ -726,16 +730,76 @@ class SketchWidget(QWidget):
|
||||
if self.mouse_mode == "line" and self.line_draw_buffer[0] and self.dynamic_line_end is not None:
|
||||
start_point = self.line_draw_buffer[0].ui_point
|
||||
end_point = self.dynamic_line_end
|
||||
painter.setPen(Qt.red) # Use a different color for the dynamic line
|
||||
painter.setPen(pen_planned) # Use a different color for the dynamic line
|
||||
painter.drawLine(start_point, end_point)
|
||||
|
||||
# Calculate the direction of the line
|
||||
dx = end_point.x() - start_point.x()
|
||||
dy = end_point.y() - start_point.y()
|
||||
|
||||
# Swap and negate to get a perpendicular vector
|
||||
perp_dx = -dy
|
||||
perp_dy = dx
|
||||
|
||||
# Normalize the perpendicular vector
|
||||
length = (perp_dx ** 2 + perp_dy ** 2) ** 0.5
|
||||
if length == 0: # Prevent division by zero
|
||||
return
|
||||
perp_dx /= length
|
||||
perp_dy /= length
|
||||
|
||||
# Fixed length for the perpendicular lines
|
||||
fixed_length = 40 # Adjust as needed
|
||||
half_length = fixed_length #fixed_length / 2
|
||||
|
||||
# Calculate endpoints for the perpendicular line at the start
|
||||
start_perp_start_x = start_point.x() + perp_dx
|
||||
start_perp_start_y = start_point.y() + perp_dy
|
||||
|
||||
start_perp_end_x = start_point.x() + perp_dx * half_length * (1 / self.zoom)
|
||||
start_perp_end_y = start_point.y() + perp_dy * half_length * (1 / self.zoom)
|
||||
|
||||
start_perp_end_x_conn_line = start_point.x() + perp_dx * half_length * 0.75 * (1 / self.zoom)
|
||||
start_perp_end_y_conn_line = start_point.y() + perp_dy * half_length * 0.75 * (1 / self.zoom)
|
||||
|
||||
# Draw the perpendicular line at the start
|
||||
painter.setPen(pen_construct) # Different color for the perpendicular line
|
||||
painter.drawLine(
|
||||
QPointF(start_perp_start_x, start_perp_start_y),
|
||||
QPointF(start_perp_end_x, start_perp_end_y)
|
||||
)
|
||||
|
||||
# Calculate endpoints for the perpendicular line at the end
|
||||
end_perp_start_x = end_point.x() + perp_dx
|
||||
end_perp_start_y = end_point.y() + perp_dy
|
||||
|
||||
end_perp_end_x = end_point.x() + perp_dx * half_length * (1 / self.zoom)
|
||||
end_perp_end_y = end_point.y() + perp_dy * half_length * (1 / self.zoom)
|
||||
|
||||
end_perp_end_x_conn_line = end_point.x() + perp_dx * half_length * .75 * (1 / self.zoom)
|
||||
end_perp_end_y_conn_line = end_point.y() + perp_dy * half_length * .75 * (1 / self.zoom)
|
||||
|
||||
|
||||
# Draw the perpendicular line at the end
|
||||
painter.drawLine(
|
||||
QPointF(end_perp_start_x, end_perp_start_y),
|
||||
QPointF(end_perp_end_x, end_perp_end_y)
|
||||
)
|
||||
|
||||
painter.drawLine(
|
||||
QPointF(end_perp_end_x_conn_line, end_perp_end_y_conn_line),
|
||||
QPointF(start_perp_end_x_conn_line, start_perp_end_y_conn_line)
|
||||
)
|
||||
|
||||
# Save painter state
|
||||
painter.save()
|
||||
painter.setPen(pen_text)
|
||||
|
||||
# Calculate the distance and midpoint
|
||||
dis = self.distance(start_point, end_point)
|
||||
mid = self.calculate_midpoint(start_point, end_point)
|
||||
mid = self.calculate_midpoint(QPointF(start_perp_end_x_conn_line, start_perp_end_y_conn_line), QPointF(end_perp_end_x_conn_line, end_perp_end_y_conn_line))
|
||||
|
||||
#mid = self.calculate_midpoint(start_point, end_point)
|
||||
|
||||
# Transform for text
|
||||
painter.translate(mid.x(), mid.y()) # Move to the midpoint
|
||||
|
Loading…
x
Reference in New Issue
Block a user