53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy
|
|
from Gui import Ui_fluencyCAD # Import the generated GUI module
|
|
from modules.gl_widget import OpenGLWidget
|
|
from sdf import *
|
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
# Set up the UI from the generated GUI module
|
|
self.ui = Ui_fluencyCAD()
|
|
self.ui.setupUi(self)
|
|
|
|
self.openGLWidget = OpenGLWidget()
|
|
self.openGLWidget.setParent(self.ui.gl_canvas)
|
|
# Connect the resizeEvent of the parent widget to a function
|
|
self.ui.gl_canvas.resizeEvent = self.glCanvasResized
|
|
|
|
self.ui.pb_apply_code.pressed.connect(self.generate_mesh)
|
|
|
|
|
|
def generate_mesh(self):
|
|
code_bytes = self.ui.textEdit.toPlainText().encode('utf-8')
|
|
code_text = code_bytes.decode('utf-8')
|
|
save_string = "\nf.save('out.stl', samples=2**12)"
|
|
code_text += save_string
|
|
|
|
local_vars = {}
|
|
try:
|
|
print(code_text)
|
|
exec(code_text, globals(), local_vars)
|
|
|
|
# Retrieve the result from the captured local variables
|
|
result = local_vars.get('result')
|
|
print("Result:", result)
|
|
mesh = self.openGLWidget.load_stl("out.stl")
|
|
self.openGLWidget.draw_stl(mesh)
|
|
except Exception as e:
|
|
print("Error executing code:", e)
|
|
|
|
|
|
def glCanvasResized(self, event):
|
|
# Get the size of the gl_canvas
|
|
canvas_size = self.ui.gl_canvas.size()
|
|
# Resize the OpenGL widget to match the size of the gl_canvas
|
|
self.openGLWidget.resize(canvas_size)
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication([])
|
|
window = MainWindow()
|
|
window.show()
|
|
app.exec() |