- Bsic sketch to object approach
This commit is contained in:
124
main.py
124
main.py
@@ -23,6 +23,7 @@ class ExtrudeDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle('Extrude Options')
|
||||
|
||||
def create_hline():
|
||||
line = QLabel()
|
||||
line.setStyleSheet("border-top: 1px solid #cccccc;") # Light grey line
|
||||
@@ -76,6 +77,7 @@ class ExtrudeDialog(QDialog):
|
||||
def get_values(self):
|
||||
return self.length_input.value(), self.symmetric_checkbox.isChecked() ,self.invert_checkbox.isChecked(), self.cut_checkbox.isChecked(), self.union_checkbox.isChecked(), self.rounded_checkbox.isChecked()
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
send_command = Signal(str)
|
||||
|
||||
@@ -100,7 +102,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
### Main Model
|
||||
self.model = {
|
||||
'sketch': {},
|
||||
'sketches': {},
|
||||
'operation': {},
|
||||
}
|
||||
self.list_selected = []
|
||||
@@ -145,8 +147,6 @@ class MainWindow(QMainWindow):
|
||||
|
||||
"""Project -> Timeline -> Component -> Sketch -> Body / Interactor -> Connector -> Assembly -> PB Render"""
|
||||
|
||||
|
||||
|
||||
def on_flip_face(self):
|
||||
self.send_command.emit("flip")
|
||||
|
||||
@@ -208,7 +208,7 @@ class MainWindow(QMainWindow):
|
||||
def draw_mesh(self):
|
||||
name = self.ui.body_list.currentItem().text()
|
||||
print("selected_for disp", name)
|
||||
model = self.project.timeline[-1].body.sdf_body
|
||||
model = self.project.timeline[-1].body[name].sdf_body
|
||||
|
||||
vesta = vesta_mesh
|
||||
model_data = vesta.generate_mesh_from_sdf(model, resolution=64, threshold=0)
|
||||
@@ -234,6 +234,8 @@ class MainWindow(QMainWindow):
|
||||
compo = Component()
|
||||
compo.id = "New Compo"
|
||||
compo.descript = "Initial Component"
|
||||
compo.sketches = {}
|
||||
compo.body = {}
|
||||
self.project.timeline.append(compo)
|
||||
|
||||
# Create a horizontal layout
|
||||
@@ -257,61 +259,67 @@ class MainWindow(QMainWindow):
|
||||
horizontal_layout.setAlignment(Qt.AlignLeft)
|
||||
|
||||
def add_new_sketch_origin(self):
|
||||
self.sketchWidget.clear_sketch()
|
||||
self.sketchWidget.create_workplane()
|
||||
name = f"sketches-{str(names.get_first_name())}"
|
||||
sketch = Sketch()
|
||||
sketch.id = name
|
||||
sketch.origin = [0,0,0]
|
||||
sketch.slv_points = []
|
||||
sketch.slv_lines = []
|
||||
sketch.proj_points = []
|
||||
sketch.proj_lines = []
|
||||
self.sketchWidget.set_sketch(sketch)
|
||||
|
||||
def add_new_sketch_wp(self):
|
||||
self.sketchWidget.clear_sketch()
|
||||
#edges = [((-158.0, -20.0, -25.0), (286.0, -195.0, -25.0)), ((-158.0, -20.0, 25.0), (-158.0, -20.0, -25.0))]
|
||||
points = self.custom_3D_Widget.project_tosketch_points
|
||||
normal = self.custom_3D_Widget.selected_normal
|
||||
selected_lines = self.custom_3D_Widget.project_tosketch_lines
|
||||
print("Selected lines", selected_lines)
|
||||
|
||||
name = f"sketches-{str(names.get_first_name())}"
|
||||
sketch = Sketch()
|
||||
sketch.id = name
|
||||
sketch.origin = self.custom_3D_Widget.centroid
|
||||
sketch.normal = self.custom_3D_Widget.selected_normal
|
||||
sketch.slv_points = []
|
||||
sketch.slv_lines = []
|
||||
sketch.proj_points = self.custom_3D_Widget.project_tosketch_points
|
||||
sketch.proj_lines = self.custom_3D_Widget.project_tosketch_lines
|
||||
self.sketchWidget.set_sketch(sketch)
|
||||
self.sketchWidget.create_workplane_projected()
|
||||
self.sketchWidget.create_proj_points(points)
|
||||
self.sketchWidget.create_proj_lines(selected_lines)
|
||||
self.sketchWidget.convert_proj_points()
|
||||
self.sketchWidget.convert_proj_lines()
|
||||
self.sketchWidget.update()
|
||||
|
||||
# CLear all selections after it has been projected
|
||||
self.custom_3D_Widget.project_tosketch_points.clear()
|
||||
self.custom_3D_Widget.project_tosketch_lines.clear()
|
||||
self.custom_3D_Widget.clear_actors_projection()
|
||||
self.custom_3D_Widget.clear_actors_normals()
|
||||
#self.custom_3D_Widget.clear_actors_projection()
|
||||
|
||||
#self.sketchWidget.create_workplane_space(edges, normal)
|
||||
|
||||
def add_sketch(self):
|
||||
name = f"sketch-{str(names.get_first_name())}"
|
||||
|
||||
sketch = Sketch()
|
||||
sketch.id = name
|
||||
sketch.slv_points = self.sketchWidget.slv_points_main
|
||||
sketch.slv_lines = self.sketchWidget.slv_lines_main
|
||||
sketch = self.sketchWidget.get_sketch()
|
||||
sketch.convert_points_for_sdf()
|
||||
|
||||
self.project.timeline[-1].sketch = sketch
|
||||
self.project.timeline[-1].sketches[sketch.id] = sketch
|
||||
|
||||
self.ui.sketch_list.addItem(name)
|
||||
self.ui.sketch_list.addItem(sketch.id)
|
||||
self.ui.pb_linetool.setChecked(False)
|
||||
self.sketchWidget.line_mode = False
|
||||
|
||||
items = self.ui.sketch_list.findItems(name, Qt.MatchExactly)[0]
|
||||
items = self.ui.sketch_list.findItems(sketch.id, Qt.MatchExactly)[0]
|
||||
self.ui.sketch_list.setCurrentItem(items)
|
||||
|
||||
def edit_sketch(self):
|
||||
name = self.ui.sketch_list.currentItem().text()
|
||||
#self.sketchWidget.clear_sketch()
|
||||
|
||||
self.sketchWidget.slv_points_main = self.model['sketch'][name]['point_list']
|
||||
self.sketchWidget.slv_lines_main = self.model['sketch'][name]['line_list']
|
||||
self.sketchWidget.solv = self.model['sketch'][name]['solver']
|
||||
selected = self.ui.sketch_list.currentItem()
|
||||
name = selected.text()
|
||||
# TODO: add selected element from timeline
|
||||
sel_compo = self.project.timeline[-1]
|
||||
sketch = sel_compo.sketches[name]
|
||||
|
||||
self.sketchWidget.set_sketch(sketch)
|
||||
|
||||
self.sketchWidget.update()
|
||||
print("model",self.model)
|
||||
print("widget", self.sketchWidget.slv_points_main)
|
||||
|
||||
def del_sketch(self):
|
||||
# Old
|
||||
print("Deleting")
|
||||
name = self.ui.sketch_list.currentItem() # Get the current item
|
||||
|
||||
@@ -321,14 +329,14 @@ class MainWindow(QMainWindow):
|
||||
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:
|
||||
# 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['sketch'].pop(item_name) # Remove the item from the sketch dictionary
|
||||
print(f"Removed sketch: {item_name}")
|
||||
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']:
|
||||
@@ -340,7 +348,7 @@ class MainWindow(QMainWindow):
|
||||
print(f"Removed operation: {item_name}")
|
||||
|
||||
else:
|
||||
print(f"Item '{item_name}' not found in either 'sketch' or 'operation' dictionary.")
|
||||
print(f"Item '{item_name}' not found in either 'sketches' or 'operation' dictionary.")
|
||||
else:
|
||||
print("No item selected.")
|
||||
|
||||
@@ -374,7 +382,7 @@ class MainWindow(QMainWindow):
|
||||
name = selected.text()
|
||||
# TODO: add selected element from timeline
|
||||
sel_compo = self.project.timeline[-1]
|
||||
sketch = sel_compo.sketch
|
||||
sketch = sel_compo.sketches[name]
|
||||
points = sketch.sdf_points
|
||||
|
||||
if points[-1] == points[0]:
|
||||
@@ -389,7 +397,6 @@ class MainWindow(QMainWindow):
|
||||
length = 0
|
||||
print("Extrude cancelled")
|
||||
|
||||
|
||||
normal = self.custom_3D_Widget.selected_normal
|
||||
#print("Normie enter", normal)
|
||||
if normal is None:
|
||||
@@ -408,21 +415,25 @@ class MainWindow(QMainWindow):
|
||||
f = sketch.extrude(length, is_symmetric, invert, 0)
|
||||
|
||||
name_op = f"extrd-{name}"
|
||||
sel_compo.body = Body()
|
||||
sel_compo.body.sketch = sketch #we add the sketch for reference here
|
||||
sel_compo.body.id = name_op
|
||||
sel_compo.body.sdf_body = f
|
||||
sel_compo.body
|
||||
body = Body()
|
||||
body.sketch = sketch #we add the sketches for reference here
|
||||
body.id = name_op
|
||||
body.sdf_body = f
|
||||
|
||||
### Interactor
|
||||
sel_compo.interactor = Interactor()
|
||||
sel_compo.interactor.add_lines_for_interactor(sketch.slv_lines)
|
||||
interactor = Interactor()
|
||||
interactor.add_lines_for_interactor(sketch.slv_lines)
|
||||
|
||||
if not invert:
|
||||
edges = interactor_mesh.generate_mesh(sel_compo.interactor.lines, 0, length)
|
||||
edges = interactor_mesh.generate_mesh(interactor.lines, 0, length)
|
||||
else:
|
||||
edges = interactor_mesh.generate_mesh(sel_compo.interactor.lines, 0, -length)
|
||||
edges = interactor_mesh.generate_mesh(interactor.lines, 0, -length)
|
||||
|
||||
offset_vector = sel_compo.interactor.vector_to_centroid(None, centroid, normal)
|
||||
body.interactor = interactor
|
||||
sel_compo.body[name_op] = body
|
||||
|
||||
offset_vector = interactor.vector_to_centroid(None, centroid, normal)
|
||||
#print("off_ved", offset_vector)
|
||||
if len(offset_vector) == 0 :
|
||||
offset_vector = [0, 0, 0]
|
||||
@@ -483,7 +494,7 @@ class Assembly:
|
||||
class Component:
|
||||
"""The base container combining all related elements
|
||||
id : The unique ID
|
||||
sketch : the base sketch, bodys can contain additonal sketches for features
|
||||
sketches : the base sketches, bodys can contain additonal sketches for features
|
||||
interactor : A smiplified model used as interactor
|
||||
body : The body class that contains the actual 3d information
|
||||
connector : Vector and Nomral information for assembly
|
||||
@@ -491,9 +502,8 @@ class Component:
|
||||
materil : Speicfy a material for pbr rendering
|
||||
"""
|
||||
id = None
|
||||
sketch = None
|
||||
interactor = None
|
||||
body = None
|
||||
sketches: dict = None
|
||||
body: dict = None
|
||||
connector = None
|
||||
|
||||
# Description
|
||||
@@ -531,7 +541,7 @@ class Code:
|
||||
|
||||
@dataclass
|
||||
class Sketch:
|
||||
"""All of the 2D Information of a sketch"""
|
||||
"""All of the 2D Information of a sketches"""
|
||||
id = None
|
||||
|
||||
# Space Information
|
||||
@@ -539,7 +549,7 @@ class Sketch:
|
||||
slv_plane = None
|
||||
normal = None
|
||||
|
||||
# Points in UI form the sketch widget
|
||||
# Points in UI form the sketches widget
|
||||
ui_points: list = None
|
||||
ui_lines: list = None
|
||||
|
||||
@@ -553,6 +563,9 @@ class Sketch:
|
||||
proj_points: list = None
|
||||
proj_lines: list = None
|
||||
|
||||
# Workingplane
|
||||
working_plane = None
|
||||
|
||||
def translate_points_tup(self, point: QPoint):
|
||||
"""QPoints from Display to mesh data
|
||||
input: Qpoints
|
||||
@@ -712,6 +725,7 @@ class Body:
|
||||
id = None
|
||||
sketch = None
|
||||
height = None
|
||||
interactor = None
|
||||
sdf_body = None
|
||||
|
||||
def mirror_body(self, sdf_object3d):
|
||||
|
||||
Reference in New Issue
Block a user