- delete sketch working

- added mid point snap
- added hovering line with distance
This commit is contained in:
bklronin
2025-01-01 21:35:43 +01:00
parent f5861b8bd1
commit e9383f76a2
2 changed files with 75 additions and 50 deletions

75
main.py
View File

@@ -6,7 +6,7 @@
import uuid
import names
from PySide6.QtCore import Qt, QPoint, Signal, QSize
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy, QInputDialog, QDialog, QVBoxLayout, QHBoxLayout, QLabel, QDoubleSpinBox, QCheckBox, QPushButton
from PySide6.QtWidgets import QApplication, QMainWindow, QSizePolicy, QInputDialog, QDialog, QVBoxLayout, QHBoxLayout, QLabel, QDoubleSpinBox, QCheckBox, QPushButton, QButtonGroup
from Gui import Ui_fluencyCAD # Import the generated GUI module
from drawing_modules.vtk_widget import VTKWidget
from drawing_modules.vysta_widget import PyVistaWidget
@@ -156,6 +156,7 @@ class MainWindow(QMainWindow):
self.project.timeline = timeline
self.new_component()
def new_component(self):
print("Creating a new component...")
@@ -164,6 +165,10 @@ class MainWindow(QMainWindow):
print("Initializing compo_layout...")
self.compo_layout = QHBoxLayout()
# Create a button group
self.compo_group = QButtonGroup(self)
self.compo_group.setExclusive(True) # Ensure exclusivity
# Ensure the QGroupBox has a layout
if not self.ui.compo_box.layout():
self.ui.compo_box.setLayout(QVBoxLayout()) # Set a default layout for QGroupBox
@@ -188,13 +193,19 @@ class MainWindow(QMainWindow):
button.setText(str(len(self.project.timeline)))
button.setFixedSize(QSize(40, 40)) # Set button size
button.setCheckable(True)
button.setAutoExclusive(True)
button.setChecked(False)
#button.setAutoExclusive(True)
button.released.connect(self.on_compo_change)
button.setChecked(True)
# Add button to the group
self.compo_group.addButton(button)
# Add the button to the layout
self.compo_layout.addWidget(button)
# We automatically switch to the new compo hence, refresh
self.on_compo_change()
print(f"Added component {compo.id} to the layout.")
def get_activated_compo(self):
@@ -285,6 +296,7 @@ class MainWindow(QMainWindow):
def on_compo_change(self):
self.custom_3D_Widget.clear_body_actors()
self.custom_3D_Widget.clear_actors_interactor()
self.custom_3D_Widget.clear_actors_projection()
compo_id = self.get_activated_compo()
if compo_id is not None:
@@ -301,16 +313,17 @@ class MainWindow(QMainWindow):
for body in self.project.timeline[compo_id].bodies:
self.ui.body_list.addItem(body)
item = self.ui.body_list.findItems(body , Qt.MatchExactly)[0]
self.ui.body_list.setCurrentItem(item)
self.draw_mesh()
if self.project.timeline[compo_id].bodies:
item = self.ui.body_list.findItems(body , Qt.MatchExactly)[0]
self.ui.body_list.setCurrentItem(item)
self.draw_mesh()
selected = self.ui.body_list.currentItem()
name = selected.text()
selected = self.ui.body_list.currentItem()
name = selected.text()
edges = self.project.timeline[compo_id].bodies[name].interactor.edges
offset_vec = self.project.timeline[compo_id].bodies[name].interactor.offset_vector
self.custom_3D_Widget.load_interactor_mesh(edges, offset_vec)
edges = self.project.timeline[compo_id].bodies[name].interactor.edges
offset_vec = self.project.timeline[compo_id].bodies[name].interactor.offset_vector
self.custom_3D_Widget.load_interactor_mesh(edges, offset_vec)
def edit_sketch(self):
selected = self.ui.sketch_list.currentItem()
@@ -323,40 +336,20 @@ class MainWindow(QMainWindow):
self.sketchWidget.update()
def del_sketch(self):
# Old
print("Deleting")
name = self.ui.sketch_list.currentItem() # Get the current item
selected = self.ui.sketch_list.currentItem()
name = selected.text()
sel_compo = self.project.timeline[self.get_activated_compo()]
sketch = sel_compo.sketches[name]
print(self.model)
if name is not None:
item_name = name.text()
print("obj_name", item_name)
# Check if the 'sketches' key exists in the model dictionary
if 'sketches' in self.model and item_name in self.model['sketches']:
if self.model['sketches'][item_name]['id'] == item_name:
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['sketches'].pop(item_name) # Remove the item from the sketches dictionary
print(f"Removed sketches: {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.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}")
else:
print(f"Item '{item_name}' not found in either 'sketches' or 'operation' dictionary.")
if sketch is not None:
sel_compo.sketches.pop(name)
row = self.ui.sketch_list.row(selected) # Get the row of the current item
self.ui.sketch_list.takeItem(row) # Remove the item from the list widget
self.sketchWidget.sketch = None
print(sketch)
else:
print("No item selected.")
def on_flip_face(self):
self.send_command.emit("flip")