Checkpoint before solvespace integration

This commit is contained in:
bklronin
2024-06-18 09:53:39 +02:00
parent 92a870e834
commit a64971e0fe
5 changed files with 525 additions and 355 deletions

68
main.py
View File

@@ -5,9 +5,9 @@ from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy, QInputDialog
from Gui import Ui_fluencyCAD # Import the generated GUI module
from drawing_modules.gl_widget import OpenGLWidget
from drawing_modules.draw_widget2d import SnapLineWidget
from drawing_modules.draw_widget2d import SketchWidget
from sdf import *
import python_solvespace
from python_solvespace import SolverSystem, ResultFlag
# main, draw_widget, gl_widget
@@ -26,7 +26,7 @@ class MainWindow(QMainWindow):
size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
#self.openGLWidget.setSizePolicy(size_policy)
self.sketchWidget = SnapLineWidget()
self.sketchWidget = SketchWidget()
layout2 = self.ui.sketch_tab.layout() # Get the layout of self.ui.gl_canvas
layout2.addWidget(self.sketchWidget)
size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
@@ -40,8 +40,8 @@ class MainWindow(QMainWindow):
self.list_selected = []
#self.ui.pb_apply_code.pressed.connect(self.check_current_tab)
self.ui.element_list.currentItemChanged.connect(self.on_item_changed)
self.ui.element_list.itemChanged.connect(self.view_update)
self.ui.sketch_list.currentItemChanged.connect(self.on_item_changed)
self.ui.sketch_list.itemChanged.connect(self.view_update)
### Sketches
self.ui.pb_nw_sktch.pressed.connect(self.add_sketch)
@@ -50,10 +50,10 @@ class MainWindow(QMainWindow):
self.ui.pb_linetool.pressed.connect(self.act_line_mode)
### Operations
self.ui.pb_extrdop.pressed.connect(self.send_extrude)
self.ui.pb_cutop.pressed.connect(self.send_cut)
self.ui.pb_del_body.pressed.connect(self.del_body)
def act_line_mode(self):
if not self.ui.pb_linetool.isChecked():
@@ -64,9 +64,10 @@ class MainWindow(QMainWindow):
def view_update(self):
print("Update")
name = self.ui.element_list.currentItem().text()
name = self.ui.body_list.currentItem().text()
print("selected_for disp", name)
model = self.model['operation'][name]['sdf_object']
mesh = model.generate(samples=2**12)
@@ -91,15 +92,15 @@ class MainWindow(QMainWindow):
self.model['sketch'][element['id']] = element
print(self.model)
self.ui.element_list.addItem(name)
self.ui.sketch_list.addItem(name)
self.ui.pb_linetool.setChecked(False)
self.sketchWidget.line_mode = False
items = self.ui.element_list.findItems(name, Qt.MatchExactly)[0]
self.ui.element_list.setCurrentItem(items)
items = self.ui.sketch_list.findItems(name, Qt.MatchExactly)[0]
self.ui.sketch_list.setCurrentItem(items)
def edit_sketch(self):
name = self.ui.element_list.currentItem().text()
name = self.ui.sketch_list.currentItem().text()
self.sketchWidget.clear_sketch()
points = self.model['sketch'][name]['sketch_points']
print("points", points)
@@ -107,7 +108,7 @@ class MainWindow(QMainWindow):
def del_sketch(self):
print("Deleting")
name = self.ui.element_list.currentItem() # Get the current item
name = self.ui.sketch_list.currentItem() # Get the current item
print(self.model)
@@ -118,8 +119,8 @@ class MainWindow(QMainWindow):
# Check if the 'sketch' key exists in the model dictionary
if 'sketch' in self.model and item_name in self.model['sketch']:
if self.model['sketch'][item_name]['id'] == item_name:
row = self.ui.element_list.row(name) # Get the row of the current item
self.ui.element_list.takeItem(row) # Remove the item from the list widget
row = self.ui.sketch_list.row(name) # Get the row of the current item
self.ui.sketch_list.takeItem(row) # Remove the item from the list widget
self.sketchWidget.clear_sketch()
self.model['sketch'].pop(item_name) # Remove the item from the sketch dictionary
print(f"Removed sketch: {item_name}")
@@ -127,8 +128,8 @@ class MainWindow(QMainWindow):
# Check if the 'operation' key exists in the model dictionary
elif 'operation' in self.model and item_name in self.model['operation']:
if self.model['operation'][item_name]['id'] == item_name:
row = self.ui.element_list.row(name) # Get the row of the current item
self.ui.element_list.takeItem(row) # Remove the item from the list widget
row = self.ui.sketch_list.row(name) # Get the row of the current item
self.ui.sketch_list.takeItem(row) # Remove the item from the list widget
self.sketchWidget.clear_sketch()
self.model['operation'].pop(item_name) # Remove the item from the operation dictionary
print(f"Removed operation: {item_name}")
@@ -137,6 +138,25 @@ class MainWindow(QMainWindow):
print(f"Item '{item_name}' not found in either 'sketch' or 'operation' dictionary.")
else:
print("No item selected.")
def update_body(self):
pass
def del_body(self):
print("Deleting")
name = self.ui.body_list.currentItem() # Get the current item
if name is not None:
item_name = name.text()
print("obj_name", item_name)
# Check if the 'operation' key exists in the model dictionary
if 'operation' in self.model and item_name in self.model['operation']:
if self.model['operation'][item_name]['id'] == item_name:
row = self.ui.body_list.row(name) # Get the row of the current item
self.ui.body_list.takeItem(row) # Remove the item from the list widget
self.model['operation'].pop(item_name) # Remove the item from the operation dictionary
print(f"Removed operation: {item_name}")
self.openGLWidget.clear_mesh()
def translate_points_tup(self, points):
"""QPoints from Display to mesh data
@@ -152,7 +172,7 @@ class MainWindow(QMainWindow):
def send_extrude(self):
selected = self.ui.element_list.currentItem()
selected = self.ui.sketch_list.currentItem()
name = selected.text()
points = self.model['sketch'][name]['sketch_points']
@@ -175,14 +195,14 @@ class MainWindow(QMainWindow):
self.model['operation'][name_op] = element
self.ui.element_list.addItem(name_op)
items = self.ui.element_list.findItems(name_op, Qt.MatchExactly)[0]
self.ui.element_list.setCurrentItem(items)
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.view_update()
def send_cut(self):
name = self.ui.element_list.currentItem().text()
name = self.ui.sketch_list.currentItem().text()
points = self.model['operation'][name]['sdf_object']
self.list_selected.append(points)
print(self.list_selected)
@@ -199,9 +219,9 @@ class MainWindow(QMainWindow):
name_op = f"cut-{name}"
self.model['operation'][name_op] = element
self.ui.element_list.addItem(name_op)
items = self.ui.element_list.findItems(name_op, Qt.MatchExactly)
self.ui.element_list.setCurrentItem(items[0])
self.ui.body_list.addItem(name_op)
items = self.ui.sketch_list.findItems(name_op, Qt.MatchExactly)
self.ui.body_list.setCurrentItem(items[0])
self.view_update()
else: