- UI workflow improvements

- Remove specific item
-
This commit is contained in:
bklronin
2024-06-15 23:03:27 +02:00
parent 055a90b62e
commit 92a870e834
5 changed files with 472 additions and 343 deletions

130
main.py
View File

@@ -1,23 +1,22 @@
import uuid
import names
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy
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 sdf import *
import python_solvespace
# main, draw_widget, gl_widget
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)
@@ -36,7 +35,7 @@ class MainWindow(QMainWindow):
### Main Model
self.model = {
'sketch': {},
'operations': {},
'operation': {},
}
self.list_selected = []
@@ -46,17 +45,30 @@ class MainWindow(QMainWindow):
### Sketches
self.ui.pb_nw_sktch.pressed.connect(self.add_sketch)
self.ui.pb_del_sketch.pressed.connect(self.reset_pos_list)
self.ui.pb_del_sketch.pressed.connect(self.del_sketch)
self.ui.pb_edt_sktch.pressed.connect(self.edit_sketch)
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)
def act_line_mode(self):
if not self.ui.pb_linetool.isChecked():
self.sketchWidget.line_mode = True
self.sketchWidget.points = []
else:
self.sketchWidget.line_mode = False
def view_update(self):
print("Update")
name = self.ui.element_list.currentItem().text()
print("selcted_for disp", name)
model = self.model['operations'][name]['sdf_object']
print("selected_for disp", name)
model = self.model['operation'][name]['sdf_object']
mesh = model.generate(samples=2**12)
self.openGLWidget.load_mesh_direct(mesh)
@@ -67,48 +79,111 @@ class MainWindow(QMainWindow):
print(f"Selected item: {name}")
def add_sketch(self):
p_list = []
name = f"sketch-{str(uuid.uuid4())}"
name = f"sketch-{str(names.get_first_name())}"
points = self.sketchWidget.points
for ps in points:
p_list.append((ps.x(), ps.y()))
element = {
'id': name,
'type': 'polygon',
'sketch_points': p_list,
'sketch_points': points,
}
self.model['sketch'][element['id']] = element
print(self.model)
self.ui.element_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)
def edit_sketch(self):
name = self.ui.element_list.currentItem().text()
self.sketchWidget.clear_sketch()
points = self.model['sketch'][name]['sketch_points']
print("points", points)
self.sketchWidget.set_points(points)
def del_sketch(self):
print("Deleting")
name = self.ui.element_list.currentItem() # Get the current item
print(self.model)
if name is not None:
item_name = name.text()
print("obj_name", item_name)
# 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
self.sketchWidget.clear_sketch()
self.model['sketch'].pop(item_name) # Remove the item from the sketch dictionary
print(f"Removed sketch: {item_name}")
# 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
self.sketchWidget.clear_sketch()
self.model['operation'].pop(item_name) # Remove the item from the operation dictionary
print(f"Removed operation: {item_name}")
else:
print(f"Item '{item_name}' not found in either 'sketch' or 'operation' dictionary.")
else:
print("No item selected.")
def translate_points_tup(self, points):
"""QPoints from Display to mesh data
input: Qpoints
output: Tuple X,Y
"""
p_list = []
for ps in points:
p_list.append((ps.x(), ps.y()))
return p_list
def send_extrude(self):
selected = self.ui.element_list.currentItem()
name = selected.text()
points = self.model['sketch'][name]['sketch_points']
# UI to mesh
points = self.translate_points_tup(points)
length , ok = QInputDialog.getDouble(self, 'Extrude Length', 'Enter a mm value:', decimals=2)
#TODO : Implement cancel
geo = Geometry()
f = geo.extrude_shape(points)
f = geo.extrude_shape(points, length)
name_op = f"extrd-{name}"
element = {
'id': name,
'id': name_op,
'type': 'extrude',
'sdf_object': f,
}
name_op = f"extrd-{name}"
self.model['operations'][name_op] = element
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])
items = self.ui.element_list.findItems(name_op, Qt.MatchExactly)[0]
self.ui.element_list.setCurrentItem(items)
self.view_update()
def send_cut(self):
name = self.ui.element_list.currentItem().text()
points = self.model['operations'][name]['sdf_object']
points = self.model['operation'][name]['sdf_object']
self.list_selected.append(points)
print(self.list_selected)
@@ -123,7 +198,7 @@ class MainWindow(QMainWindow):
}
name_op = f"cut-{name}"
self.model['operations'][name_op] = element
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])
@@ -137,9 +212,7 @@ class MainWindow(QMainWindow):
self.openGLWidget.update()
def reset_pos_list(self):
print("Deleting")
self.sketchWidget.clear_sketch()
""" def check_current_tab(self):
@@ -167,9 +240,10 @@ class Geometry:
print("p2", p2)
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
def extrude_shape(self, points):
def extrude_shape(self, points, length: float):
"""2D to 3D sdf always first"""
f = polygon(points).extrude(100)
f = polygon(points).extrude(length)
return f