- Fixed redraw when component changed

This commit is contained in:
bklronin 2025-04-13 16:40:54 +02:00
parent 4d7b2cdbad
commit 6cf70b9ae2
2 changed files with 20 additions and 18 deletions

View File

@ -32,4 +32,4 @@ So far these are the elements:
- Code: A special type that directly builds bodys from sdfCAD code.
- Body: The 3D meshed result from sdfCAD
- Sketch: The base to draw new entities.
- Interactor: A special component mesh that is used to manipulate the bodys in 3d view.
- Interactor (edges): A special component mesh that is used to manipulate the bodys in 3d view.

36
main.py
View File

@ -285,7 +285,7 @@ class MainWindow(QMainWindow):
# Register sketch to timeline
### Add selection compo here
compo_id = self.get_activated_compo()
print("newsketch_name", sketch.id)
#print("newsketch_name", sketch.id)
self.project.timeline[compo_id].sketches[sketch.id] = sketch
# Add Item to slection menu
@ -299,6 +299,7 @@ class MainWindow(QMainWindow):
self.ui.sketch_list.setCurrentItem(items)
def on_compo_change(self):
'''This function redraws the sdf and helper mesh from available bodies and adds the names back to the list entries'''
self.custom_3D_Widget.clear_body_actors()
self.custom_3D_Widget.clear_actors_interactor()
self.custom_3D_Widget.clear_actors_projection()
@ -308,27 +309,27 @@ class MainWindow(QMainWindow):
self.ui.sketch_list.clear()
self.ui.body_list.clear()
print("id", compo_id)
print("sketch_registry", self.project.timeline[compo_id].sketches)
#print("id", compo_id)
#print("sketch_registry", self.project.timeline[compo_id].sketches)
for sketch in self.project.timeline[compo_id].sketches:
print(sketch)
#print(sketch)
self.ui.sketch_list.addItem(sketch)
for body in self.project.timeline[compo_id].bodies:
self.ui.body_list.addItem(body)
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()
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()
@ -382,7 +383,7 @@ class MainWindow(QMainWindow):
model_data = vesta.generate_mesh_from_sdf(model, resolution=64, threshold=0)
vertices, faces = model_data
vesta.save_mesh_as_stl(vertices, faces, 'test.stl')
#vesta.save_mesh_as_stl(vertices, faces, 'test.stl')
self.custom_3D_Widget.render_from_points_direct_with_faces(vertices, faces)
def on_item_changed(self, current_item, previous_item):
@ -426,8 +427,9 @@ class MainWindow(QMainWindow):
#print(sketch)
points = sketch.sdf_points
# detect loop that causes problems in mesh generation
if points[-1] == points[0]:
#detect loop that causes problems in mesh generation
print("overlap")
del points[-1]
dialog = ExtrudeDialog(self)
@ -446,8 +448,8 @@ class MainWindow(QMainWindow):
centroid = self.custom_3D_Widget.centroid
if centroid is None:
centroid = [0, 0, 0]
else:
centroid = list(centroid)
"""else:
centroid = list(centroid)"""
#print("This centroid ", centroid)
sketch.origin = centroid