- Working project and draw on exiting
This commit is contained in:
92
main.py
92
main.py
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
import names
|
||||
from PySide6.QtCore import Qt, QPoint
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy, QInputDialog
|
||||
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy, QInputDialog, QDialog, QVBoxLayout, QHBoxLayout, QLabel, QDoubleSpinBox, QCheckBox, QPushButton
|
||||
from Gui import Ui_fluencyCAD # Import the generated GUI module
|
||||
from drawing_modules.vtk_widget import VTKWidget
|
||||
from drawing_modules.vysta_widget import PyVistaWidget
|
||||
@@ -13,6 +13,44 @@ from mesh_modules import simple_mesh, vesta_mesh, interactor_mesh
|
||||
|
||||
# main, draw_widget, gl_widget
|
||||
|
||||
class ExtrudeDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle('Extrude Options')
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# Length input
|
||||
length_layout = QHBoxLayout()
|
||||
length_label = QLabel('Extrude Length (mm):')
|
||||
self.length_input = QDoubleSpinBox()
|
||||
self.length_input.setDecimals(2)
|
||||
self.length_input.setRange(0, 1000) # Adjust range as needed
|
||||
length_layout.addWidget(length_label)
|
||||
length_layout.addWidget(self.length_input)
|
||||
|
||||
# Symmetric checkbox
|
||||
self.symmetric_checkbox = QCheckBox('Symmetric Extrude')
|
||||
|
||||
# OK and Cancel buttons
|
||||
button_layout = QHBoxLayout()
|
||||
ok_button = QPushButton('OK')
|
||||
cancel_button = QPushButton('Cancel')
|
||||
ok_button.clicked.connect(self.accept)
|
||||
cancel_button.clicked.connect(self.reject)
|
||||
button_layout.addWidget(ok_button)
|
||||
button_layout.addWidget(cancel_button)
|
||||
|
||||
# Add all widgets to main layout
|
||||
layout.addLayout(length_layout)
|
||||
layout.addWidget(self.symmetric_checkbox)
|
||||
layout.addLayout(button_layout)
|
||||
|
||||
self.setLayout(layout)
|
||||
|
||||
def get_values(self):
|
||||
return self.length_input.value(), self.symmetric_checkbox.isChecked()
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -184,7 +222,6 @@ class MainWindow(QMainWindow):
|
||||
return points_for_interact
|
||||
|
||||
def add_sketch(self):
|
||||
|
||||
name = f"sketch-{str(names.get_first_name())}"
|
||||
points_for_sdf = self.convert_points_for_sdf()
|
||||
|
||||
@@ -281,6 +318,8 @@ class MainWindow(QMainWindow):
|
||||
return point.x(), point.y()
|
||||
|
||||
def send_extrude(self):
|
||||
is_symmetric = None
|
||||
length = None
|
||||
selected = self.ui.sketch_list.currentItem()
|
||||
name = selected.text()
|
||||
points = self.model['sketch'][name]['sketch_points']
|
||||
@@ -290,25 +329,31 @@ class MainWindow(QMainWindow):
|
||||
#detect loop that causes problems in mesh generation
|
||||
del points[-1]
|
||||
|
||||
length, ok = QInputDialog.getDouble(self, 'Extrude Length', 'Enter a mm value:', decimals=2)
|
||||
#TODO : Implement cancel
|
||||
"""length, ok = QInputDialog.getDouble(self, 'Extrude Length', 'Enter a mm value:', decimals=2)
|
||||
#TODO : Implement cancel"""
|
||||
|
||||
dialog = ExtrudeDialog(self)
|
||||
if dialog.exec():
|
||||
length, is_symmetric = dialog.get_values()
|
||||
print(f"Extrude length: {length}, Symmetric: {is_symmetric}")
|
||||
else:
|
||||
length = 0
|
||||
print("Extrude cancelled")
|
||||
|
||||
#Create and draw Interactor
|
||||
geo = Geometry()
|
||||
|
||||
# Get the nromal form the 3d widget for extrusion
|
||||
if self.custom_3D_Widget.selected_normal is not None:
|
||||
normal = self.custom_3D_Widget.selected_normal.tolist()
|
||||
print("normal", normal)
|
||||
angle = geo.angle_between_normals([0, 1, 0], normal)
|
||||
print("Angle", angle)
|
||||
f = geo.extrude_shape(points, length, angle, normal)
|
||||
f = geo.mirror_body(f)
|
||||
# Rotation is done in vtk matrix trans
|
||||
angle = 0
|
||||
normal = [0, 0, 1]
|
||||
f = geo.extrude_shape(points, length, angle, normal, is_symmetric)
|
||||
|
||||
if not is_symmetric:
|
||||
origin_z_lvl = length / 2
|
||||
else:
|
||||
normal = [0,0,-1]
|
||||
angle = 0
|
||||
f = geo.extrude_shape(points, length, angle, normal)
|
||||
origin_z_lvl = 0
|
||||
|
||||
self.calc_sketch_projection_3d(lines, origin_z_lvl, length)
|
||||
|
||||
name_op = f"extrd-{name}"
|
||||
element = {
|
||||
@@ -322,7 +367,7 @@ class MainWindow(QMainWindow):
|
||||
self.ui.body_list.addItem(name_op)
|
||||
items = self.ui.body_list.findItems(name_op, Qt.MatchExactly)[0]
|
||||
self.ui.body_list.setCurrentItem(items)
|
||||
self.calc_sketch_projection_3d(lines, 0, length)
|
||||
|
||||
self.draw_mesh()
|
||||
|
||||
def send_cut(self):
|
||||
@@ -375,16 +420,26 @@ class Geometry:
|
||||
|
||||
return angle_rad
|
||||
|
||||
def offset_syn(self, f, length):
|
||||
f = f.translate((0,0, length / 2))
|
||||
return f
|
||||
|
||||
def distance(self, p1, p2):
|
||||
"""Calculate the distance between two points."""
|
||||
print("p1", p1)
|
||||
print("p2", p2)
|
||||
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
|
||||
|
||||
def extrude_shape(self, points, length: float, angle, normal):
|
||||
def extrude_shape(self, points, length: float, angle, normal, symet: bool = True):
|
||||
"""2D to 3D sdf always first"""
|
||||
f = polygon(points).rotate(angle)
|
||||
f = f.extrude(length).orient(normal) # orient(normal)
|
||||
|
||||
if not symet:
|
||||
print("Offsetting", symet)
|
||||
f = f.extrude(length).orient(normal).translate((0, 0, length/2)) # orient(normal)
|
||||
|
||||
else:
|
||||
f = f.extrude(length).orient(normal)
|
||||
|
||||
return f
|
||||
|
||||
@@ -393,7 +448,6 @@ class Geometry:
|
||||
|
||||
return f
|
||||
|
||||
|
||||
def cut_shapes(self, sdf_object1, sdf_object2):
|
||||
f = difference(sdf_object1, sdf_object2) # equivalent
|
||||
return f
|
||||
|
||||
Reference in New Issue
Block a user