diff --git a/Gui.py b/Gui.py index bb9fe69..a77a575 100644 --- a/Gui.py +++ b/Gui.py @@ -29,13 +29,92 @@ class Ui_fluencyCAD(object): self.centralwidget.setObjectName(u"centralwidget") self.gridLayout = QGridLayout(self.centralwidget) self.gridLayout.setObjectName(u"gridLayout") + self.InputTab = QTabWidget(self.centralwidget) + self.InputTab.setObjectName(u"InputTab") + sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.InputTab.sizePolicy().hasHeightForWidth()) + self.InputTab.setSizePolicy(sizePolicy) + self.sketch_tab = QWidget() + self.sketch_tab.setObjectName(u"sketch_tab") + self.verticalLayout_4 = QVBoxLayout(self.sketch_tab) + self.verticalLayout_4.setObjectName(u"verticalLayout_4") + self.InputTab.addTab(self.sketch_tab, "") + self.code_tab = QWidget() + self.code_tab.setObjectName(u"code_tab") + self.verticalLayout = QVBoxLayout(self.code_tab) + self.verticalLayout.setObjectName(u"verticalLayout") + self.textEdit = QTextEdit(self.code_tab) + self.textEdit.setObjectName(u"textEdit") + + self.verticalLayout.addWidget(self.textEdit) + + self.groupBox_7 = QGroupBox(self.code_tab) + self.groupBox_7.setObjectName(u"groupBox_7") + self.gridLayout_5 = QGridLayout(self.groupBox_7) + self.gridLayout_5.setObjectName(u"gridLayout_5") + self.pushButton_5 = QPushButton(self.groupBox_7) + self.pushButton_5.setObjectName(u"pushButton_5") + + self.gridLayout_5.addWidget(self.pushButton_5, 2, 0, 1, 1) + + self.pushButton_4 = QPushButton(self.groupBox_7) + self.pushButton_4.setObjectName(u"pushButton_4") + + self.gridLayout_5.addWidget(self.pushButton_4, 2, 1, 1, 1) + + self.pb_apply_code = QPushButton(self.groupBox_7) + self.pb_apply_code.setObjectName(u"pb_apply_code") + + self.gridLayout_5.addWidget(self.pb_apply_code, 1, 0, 1, 1) + + self.pushButton = QPushButton(self.groupBox_7) + self.pushButton.setObjectName(u"pushButton") + + self.gridLayout_5.addWidget(self.pushButton, 1, 1, 1, 1) + + + self.verticalLayout.addWidget(self.groupBox_7) + + self.InputTab.addTab(self.code_tab, "") + + self.gridLayout.addWidget(self.InputTab, 0, 2, 8, 1) + + self.groupBox = QGroupBox(self.centralwidget) + self.groupBox.setObjectName(u"groupBox") + self.gridLayout_3 = QGridLayout(self.groupBox) + self.gridLayout_3.setObjectName(u"gridLayout_3") + self.pb_extrdop = QPushButton(self.groupBox) + self.pb_extrdop.setObjectName(u"pb_extrdop") + + self.gridLayout_3.addWidget(self.pb_extrdop, 0, 0, 1, 1) + + self.pb_cutop = QPushButton(self.groupBox) + self.pb_cutop.setObjectName(u"pb_cutop") + + self.gridLayout_3.addWidget(self.pb_cutop, 0, 1, 1, 1) + + self.pb_arrayop = QPushButton(self.groupBox) + self.pb_arrayop.setObjectName(u"pb_arrayop") + + self.gridLayout_3.addWidget(self.pb_arrayop, 1, 0, 1, 1) + + self.pb_revop = QPushButton(self.groupBox) + self.pb_revop.setObjectName(u"pb_revop") + + self.gridLayout_3.addWidget(self.pb_revop, 1, 1, 1, 1) + + + self.gridLayout.addWidget(self.groupBox, 0, 5, 7, 1, Qt.AlignTop) + self.gl_box = QGroupBox(self.centralwidget) self.gl_box.setObjectName(u"gl_box") - sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(4) - sizePolicy.setHeightForWidth(self.gl_box.sizePolicy().hasHeightForWidth()) - self.gl_box.setSizePolicy(sizePolicy) + sizePolicy1 = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) + sizePolicy1.setHorizontalStretch(0) + sizePolicy1.setVerticalStretch(4) + sizePolicy1.setHeightForWidth(self.gl_box.sizePolicy().hasHeightForWidth()) + self.gl_box.setSizePolicy(sizePolicy1) font = QFont() font.setPointSize(12) self.gl_box.setFont(font) @@ -46,47 +125,15 @@ class Ui_fluencyCAD(object): self.horizontalLayout_4.setObjectName(u"horizontalLayout_4") self.horizontalLayout_4.setContentsMargins(12, -1, -1, -1) - self.gridLayout.addWidget(self.gl_box, 0, 4, 7, 1) - - self.groupBox_7 = QGroupBox(self.centralwidget) - self.groupBox_7.setObjectName(u"groupBox_7") - self.gridLayout_5 = QGridLayout(self.groupBox_7) - self.gridLayout_5.setObjectName(u"gridLayout_5") - self.pb_apply_code = QPushButton(self.groupBox_7) - self.pb_apply_code.setObjectName(u"pb_apply_code") - - self.gridLayout_5.addWidget(self.pb_apply_code, 0, 0, 1, 1) - - self.pushButton_5 = QPushButton(self.groupBox_7) - self.pushButton_5.setObjectName(u"pushButton_5") - - self.gridLayout_5.addWidget(self.pushButton_5, 2, 0, 1, 1) - - self.pushButton_2 = QPushButton(self.groupBox_7) - self.pushButton_2.setObjectName(u"pushButton_2") - - self.gridLayout_5.addWidget(self.pushButton_2, 4, 0, 1, 1) - - self.pushButton = QPushButton(self.groupBox_7) - self.pushButton.setObjectName(u"pushButton") - - self.gridLayout_5.addWidget(self.pushButton, 0, 1, 1, 1) - - self.pushButton_4 = QPushButton(self.groupBox_7) - self.pushButton_4.setObjectName(u"pushButton_4") - - self.gridLayout_5.addWidget(self.pushButton_4, 2, 1, 1, 1) - - - self.gridLayout.addWidget(self.groupBox_7, 6, 5, 1, 1, Qt.AlignBottom) + self.gridLayout.addWidget(self.gl_box, 0, 4, 8, 1) self.groupBox_2 = QGroupBox(self.centralwidget) self.groupBox_2.setObjectName(u"groupBox_2") - sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum) - sizePolicy1.setHorizontalStretch(0) - sizePolicy1.setVerticalStretch(0) - sizePolicy1.setHeightForWidth(self.groupBox_2.sizePolicy().hasHeightForWidth()) - self.groupBox_2.setSizePolicy(sizePolicy1) + sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + sizePolicy2.setHorizontalStretch(0) + sizePolicy2.setVerticalStretch(0) + sizePolicy2.setHeightForWidth(self.groupBox_2.sizePolicy().hasHeightForWidth()) + self.groupBox_2.setSizePolicy(sizePolicy2) self.gridLayout_2 = QGridLayout(self.groupBox_2) self.gridLayout_2.setObjectName(u"gridLayout_2") self.pb_rectool = QPushButton(self.groupBox_2) @@ -114,10 +161,85 @@ class Ui_fluencyCAD(object): self.gridLayout.addWidget(self.groupBox_2, 0, 0, 1, 1) + self.groupBox_5 = QGroupBox(self.centralwidget) + self.groupBox_5.setObjectName(u"groupBox_5") + sizePolicy3 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + sizePolicy3.setHorizontalStretch(0) + sizePolicy3.setVerticalStretch(0) + sizePolicy3.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth()) + self.groupBox_5.setSizePolicy(sizePolicy3) + self.groupBox_5.setMaximumSize(QSize(300, 16777215)) + self.verticalLayout_3 = QVBoxLayout(self.groupBox_5) + self.verticalLayout_3.setObjectName(u"verticalLayout_3") + self.sketch_list = QListWidget(self.groupBox_5) + self.sketch_list.setObjectName(u"sketch_list") + self.sketch_list.setSelectionRectVisible(True) + + self.verticalLayout_3.addWidget(self.sketch_list) + + self.groupBox_6 = QGroupBox(self.groupBox_5) + self.groupBox_6.setObjectName(u"groupBox_6") + sizePolicy2.setHeightForWidth(self.groupBox_6.sizePolicy().hasHeightForWidth()) + self.groupBox_6.setSizePolicy(sizePolicy2) + self.gridLayout_6 = QGridLayout(self.groupBox_6) + self.gridLayout_6.setObjectName(u"gridLayout_6") + self.gridLayout_6.setContentsMargins(2, 2, 2, 2) + self.pb_del_sketch = QPushButton(self.groupBox_6) + self.pb_del_sketch.setObjectName(u"pb_del_sketch") + + self.gridLayout_6.addWidget(self.pb_del_sketch, 0, 2, 1, 1) + + self.pb_nw_sktch = QPushButton(self.groupBox_6) + self.pb_nw_sktch.setObjectName(u"pb_nw_sktch") + + self.gridLayout_6.addWidget(self.pb_nw_sktch, 0, 0, 1, 1) + + self.pb_edt_sktch = QPushButton(self.groupBox_6) + self.pb_edt_sktch.setObjectName(u"pb_edt_sktch") + + self.gridLayout_6.addWidget(self.pb_edt_sktch, 0, 1, 1, 1) + + + self.verticalLayout_3.addWidget(self.groupBox_6) + + self.body_list = QListWidget(self.groupBox_5) + self.body_list.setObjectName(u"body_list") + self.body_list.setSelectionRectVisible(True) + + self.verticalLayout_3.addWidget(self.body_list) + + self.groupBox_8 = QGroupBox(self.groupBox_5) + self.groupBox_8.setObjectName(u"groupBox_8") + sizePolicy2.setHeightForWidth(self.groupBox_8.sizePolicy().hasHeightForWidth()) + self.groupBox_8.setSizePolicy(sizePolicy2) + self.gridLayout_8 = QGridLayout(self.groupBox_8) + self.gridLayout_8.setObjectName(u"gridLayout_8") + self.gridLayout_8.setContentsMargins(2, 2, 2, 2) + self.pb_del_body = QPushButton(self.groupBox_8) + self.pb_del_body.setObjectName(u"pb_del_body") + + self.gridLayout_8.addWidget(self.pb_del_body, 0, 2, 1, 1) + + self.pb_update_body = QPushButton(self.groupBox_8) + self.pb_update_body.setObjectName(u"pb_update_body") + + self.gridLayout_8.addWidget(self.pb_update_body, 0, 0, 1, 1) + + self.pb_edt_sktch_3 = QPushButton(self.groupBox_8) + self.pb_edt_sktch_3.setObjectName(u"pb_edt_sktch_3") + + self.gridLayout_8.addWidget(self.pb_edt_sktch_3, 0, 1, 1, 1) + + + self.verticalLayout_3.addWidget(self.groupBox_8) + + + self.gridLayout.addWidget(self.groupBox_5, 0, 3, 8, 1) + self.groupBox_3 = QGroupBox(self.centralwidget) self.groupBox_3.setObjectName(u"groupBox_3") - sizePolicy1.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth()) - self.groupBox_3.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth()) + self.groupBox_3.setSizePolicy(sizePolicy2) self.gridLayout_4 = QGridLayout(self.groupBox_3) self.gridLayout_4.setObjectName(u"gridLayout_4") self.pb_con_line = QPushButton(self.groupBox_3) @@ -143,103 +265,17 @@ class Ui_fluencyCAD(object): self.gridLayout.addWidget(self.groupBox_3, 1, 0, 1, 1) - self.groupBox = QGroupBox(self.centralwidget) - self.groupBox.setObjectName(u"groupBox") - self.gridLayout_3 = QGridLayout(self.groupBox) - self.gridLayout_3.setObjectName(u"gridLayout_3") - self.pb_extrdop = QPushButton(self.groupBox) - self.pb_extrdop.setObjectName(u"pb_extrdop") + self.groupBox_4 = QGroupBox(self.centralwidget) + self.groupBox_4.setObjectName(u"groupBox_4") + self.verticalLayout_2 = QVBoxLayout(self.groupBox_4) + self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.pushButton_2 = QPushButton(self.groupBox_4) + self.pushButton_2.setObjectName(u"pushButton_2") - self.gridLayout_3.addWidget(self.pb_extrdop, 0, 0, 1, 1) - - self.pb_cutop = QPushButton(self.groupBox) - self.pb_cutop.setObjectName(u"pb_cutop") - - self.gridLayout_3.addWidget(self.pb_cutop, 0, 1, 1, 1) - - self.pb_arrayop = QPushButton(self.groupBox) - self.pb_arrayop.setObjectName(u"pb_arrayop") - - self.gridLayout_3.addWidget(self.pb_arrayop, 1, 0, 1, 1) - - self.pb_revop = QPushButton(self.groupBox) - self.pb_revop.setObjectName(u"pb_revop") - - self.gridLayout_3.addWidget(self.pb_revop, 1, 1, 1, 1) + self.verticalLayout_2.addWidget(self.pushButton_2) - self.gridLayout.addWidget(self.groupBox, 0, 5, 6, 1, Qt.AlignTop) - - self.InputTab = QTabWidget(self.centralwidget) - self.InputTab.setObjectName(u"InputTab") - sizePolicy2 = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) - sizePolicy2.setHorizontalStretch(0) - sizePolicy2.setVerticalStretch(0) - sizePolicy2.setHeightForWidth(self.InputTab.sizePolicy().hasHeightForWidth()) - self.InputTab.setSizePolicy(sizePolicy2) - self.sketch_tab = QWidget() - self.sketch_tab.setObjectName(u"sketch_tab") - self.verticalLayout_4 = QVBoxLayout(self.sketch_tab) - self.verticalLayout_4.setObjectName(u"verticalLayout_4") - self.InputTab.addTab(self.sketch_tab, "") - self.code_tab = QWidget() - self.code_tab.setObjectName(u"code_tab") - self.verticalLayout = QVBoxLayout(self.code_tab) - self.verticalLayout.setObjectName(u"verticalLayout") - self.textEdit = QTextEdit(self.code_tab) - self.textEdit.setObjectName(u"textEdit") - - self.verticalLayout.addWidget(self.textEdit) - - self.InputTab.addTab(self.code_tab, "") - - self.gridLayout.addWidget(self.InputTab, 0, 2, 7, 1) - - self.groupBox_5 = QGroupBox(self.centralwidget) - self.groupBox_5.setObjectName(u"groupBox_5") - sizePolicy3 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - sizePolicy3.setHorizontalStretch(0) - sizePolicy3.setVerticalStretch(0) - sizePolicy3.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth()) - self.groupBox_5.setSizePolicy(sizePolicy3) - self.groupBox_5.setMaximumSize(QSize(300, 16777215)) - self.verticalLayout_3 = QVBoxLayout(self.groupBox_5) - self.verticalLayout_3.setObjectName(u"verticalLayout_3") - self.element_list = QListWidget(self.groupBox_5) - self.element_list.setObjectName(u"element_list") - self.element_list.setSelectionRectVisible(True) - - self.verticalLayout_3.addWidget(self.element_list) - - self.groupBox_6 = QGroupBox(self.groupBox_5) - self.groupBox_6.setObjectName(u"groupBox_6") - sizePolicy4 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) - sizePolicy4.setHorizontalStretch(0) - sizePolicy4.setVerticalStretch(0) - sizePolicy4.setHeightForWidth(self.groupBox_6.sizePolicy().hasHeightForWidth()) - self.groupBox_6.setSizePolicy(sizePolicy4) - self.gridLayout_6 = QGridLayout(self.groupBox_6) - self.gridLayout_6.setObjectName(u"gridLayout_6") - self.pb_del_sketch = QPushButton(self.groupBox_6) - self.pb_del_sketch.setObjectName(u"pb_del_sketch") - - self.gridLayout_6.addWidget(self.pb_del_sketch, 0, 2, 1, 1) - - self.pb_nw_sktch = QPushButton(self.groupBox_6) - self.pb_nw_sktch.setObjectName(u"pb_nw_sktch") - - self.gridLayout_6.addWidget(self.pb_nw_sktch, 0, 0, 1, 1) - - self.pb_edt_sktch = QPushButton(self.groupBox_6) - self.pb_edt_sktch.setObjectName(u"pb_edt_sktch") - - self.gridLayout_6.addWidget(self.pb_edt_sktch, 0, 1, 1, 1) - - - self.verticalLayout_3.addWidget(self.groupBox_6) - - - self.gridLayout.addWidget(self.groupBox_5, 0, 3, 7, 1) + self.gridLayout.addWidget(self.groupBox_4, 7, 5, 1, 1) fluencyCAD.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(fluencyCAD) @@ -260,34 +296,39 @@ class Ui_fluencyCAD(object): def retranslateUi(self, fluencyCAD): fluencyCAD.setWindowTitle(QCoreApplication.translate("fluencyCAD", u"fluencyCAD", None)) - self.gl_box.setTitle(QCoreApplication.translate("fluencyCAD", u"Model Viewer", None)) + self.InputTab.setTabText(self.InputTab.indexOf(self.sketch_tab), QCoreApplication.translate("fluencyCAD", u"Sketch", None)) self.groupBox_7.setTitle(QCoreApplication.translate("fluencyCAD", u"Executive", None)) - self.pb_apply_code.setText(QCoreApplication.translate("fluencyCAD", u"Apply Code", None)) self.pushButton_5.setText(QCoreApplication.translate("fluencyCAD", u"Load Code", None)) - self.pushButton_2.setText(QCoreApplication.translate("fluencyCAD", u"Export STL", None)) - self.pushButton.setText(QCoreApplication.translate("fluencyCAD", u"Delete Code", None)) self.pushButton_4.setText(QCoreApplication.translate("fluencyCAD", u"Save code", None)) - self.groupBox_2.setTitle(QCoreApplication.translate("fluencyCAD", u"Drawing", None)) - self.pb_rectool.setText(QCoreApplication.translate("fluencyCAD", u"Rctgl", None)) - self.pb_linetool.setText(QCoreApplication.translate("fluencyCAD", u"Line", None)) - self.pb_circtool.setText(QCoreApplication.translate("fluencyCAD", u"Circle", None)) - self.pb_slotool.setText(QCoreApplication.translate("fluencyCAD", u"Slot", None)) - self.groupBox_3.setTitle(QCoreApplication.translate("fluencyCAD", u"Constrain", None)) - self.pb_con_line.setText(QCoreApplication.translate("fluencyCAD", u"Pt_Line", None)) - self.pb_con_ptpt.setText(QCoreApplication.translate("fluencyCAD", u"Pt_Pt", None)) - self.pb_con_horiz.setText(QCoreApplication.translate("fluencyCAD", u"Horiz", None)) - self.pb_con_vert.setText(QCoreApplication.translate("fluencyCAD", u"Vert", None)) + self.pb_apply_code.setText(QCoreApplication.translate("fluencyCAD", u"Apply Code", None)) + self.pushButton.setText(QCoreApplication.translate("fluencyCAD", u"Delete Code", None)) + self.InputTab.setTabText(self.InputTab.indexOf(self.code_tab), QCoreApplication.translate("fluencyCAD", u"Code", None)) self.groupBox.setTitle(QCoreApplication.translate("fluencyCAD", u"Modify", None)) self.pb_extrdop.setText(QCoreApplication.translate("fluencyCAD", u"Extrd", None)) self.pb_cutop.setText(QCoreApplication.translate("fluencyCAD", u"Cut", None)) self.pb_arrayop.setText(QCoreApplication.translate("fluencyCAD", u"Arry", None)) self.pb_revop.setText(QCoreApplication.translate("fluencyCAD", u"Rev", None)) - self.InputTab.setTabText(self.InputTab.indexOf(self.sketch_tab), QCoreApplication.translate("fluencyCAD", u"Sketch", None)) - self.InputTab.setTabText(self.InputTab.indexOf(self.code_tab), QCoreApplication.translate("fluencyCAD", u"Code", None)) - self.groupBox_5.setTitle(QCoreApplication.translate("fluencyCAD", u"Components", None)) + self.gl_box.setTitle(QCoreApplication.translate("fluencyCAD", u"Model Viewer", None)) + self.groupBox_2.setTitle(QCoreApplication.translate("fluencyCAD", u"Drawing", None)) + self.pb_rectool.setText(QCoreApplication.translate("fluencyCAD", u"Rctgl", None)) + self.pb_linetool.setText(QCoreApplication.translate("fluencyCAD", u"Line", None)) + self.pb_circtool.setText(QCoreApplication.translate("fluencyCAD", u"Circle", None)) + self.pb_slotool.setText(QCoreApplication.translate("fluencyCAD", u"Slot", None)) + self.groupBox_5.setTitle(QCoreApplication.translate("fluencyCAD", u"Sketch", None)) self.groupBox_6.setTitle(QCoreApplication.translate("fluencyCAD", u"Tools", None)) - self.pb_del_sketch.setText(QCoreApplication.translate("fluencyCAD", u"Del Elmt", None)) + self.pb_del_sketch.setText(QCoreApplication.translate("fluencyCAD", u"Del sketch", None)) self.pb_nw_sktch.setText(QCoreApplication.translate("fluencyCAD", u"Add Sktch", None)) self.pb_edt_sktch.setText(QCoreApplication.translate("fluencyCAD", u"Edt Sktch", None)) + self.groupBox_8.setTitle(QCoreApplication.translate("fluencyCAD", u"Tools", None)) + self.pb_del_body.setText(QCoreApplication.translate("fluencyCAD", u"Del Bdy", None)) + self.pb_update_body.setText(QCoreApplication.translate("fluencyCAD", u"Bdy Upd", None)) + self.pb_edt_sktch_3.setText(QCoreApplication.translate("fluencyCAD", u"Nothing", None)) + self.groupBox_3.setTitle(QCoreApplication.translate("fluencyCAD", u"Constrain", None)) + self.pb_con_line.setText(QCoreApplication.translate("fluencyCAD", u"Pt_Line", None)) + self.pb_con_ptpt.setText(QCoreApplication.translate("fluencyCAD", u"Pt_Pt", None)) + self.pb_con_horiz.setText(QCoreApplication.translate("fluencyCAD", u"Horiz", None)) + self.pb_con_vert.setText(QCoreApplication.translate("fluencyCAD", u"Vert", None)) + self.groupBox_4.setTitle(QCoreApplication.translate("fluencyCAD", u"Export", None)) + self.pushButton_2.setText(QCoreApplication.translate("fluencyCAD", u"STL", None)) # retranslateUi diff --git a/drawing_modules/draw_widget2d.py b/drawing_modules/draw_widget2d.py index 5ad2408..5014333 100644 --- a/drawing_modules/draw_widget2d.py +++ b/drawing_modules/draw_widget2d.py @@ -1,20 +1,47 @@ from PySide6.QtWidgets import QApplication, QWidget, QMessageBox from PySide6.QtGui import QPainter, QPen, QColor from PySide6.QtCore import Qt, QPoint +from python_solvespace import SolverSystem, ResultFlag - -class SnapLineWidget(QWidget): +class SketchWidget(QWidget): def __init__(self): super().__init__() self.points = [] self.selected_line = None self.snapping_range = 20 # Range in pixels for snapping self.line_mode = False + self.solv = SolverSystem() + + def solve_constraint(self): + solv = SolverSystem() + wp = solv.create_2d_base() # Workplane (Entity) + p0 = solv.add_point_2d(0, 0, wp) # Entity + solv.dragged(p0, wp) # Make a constraint with the entity + ... + line0 = solv.add_line_2d(p0, p1, wp) # Create entity with others + ... + line1 = solv.add_line_2d(p0, p3, wp) + solv.angle(line0, line1, 45, wp) # Constrain two entities + line1 = solv.entity(-1) # Entity handle can be re-generated and negatively indexed + ... + if solv.solve() == ResultFlag.OKAY: + # Get the result (unpack from the entity or parameters) + # x and y are actually float type + dof = solv.dof() + x, y = solv.params(p2.params) + ... + else: + # Error! + # Get the list of all constraints + failures = solv.failures() + ... + def set_points(self, points: list): self.points = points #self.update() + def mousePressEvent(self, event): if event.button() == Qt.LeftButton and self.line_mode: self.points.append(event.pos()) @@ -53,10 +80,10 @@ class SnapLineWidget(QWidget): painter = QPainter(self) # Set the background color - painter.fillRect(self.rect(), QColor('white')) + painter.fillRect(self.rect(), QColor('black')) - pen = QPen(Qt.black) - pen.setWidth(1) + pen = QPen(Qt.gray) + pen.setWidth(2) painter.setPen(pen) for i in range(len(self.points) - 1): @@ -83,7 +110,7 @@ if __name__ == "__main__": import sys app = QApplication(sys.argv) - window = SnapLineWidget() + window = SketchWidget() window.setWindowTitle("Snap Line Widget") window.resize(800, 600) window.show() diff --git a/drawing_modules/gl_widget.py b/drawing_modules/gl_widget.py index e9c0c33..e762cce 100644 --- a/drawing_modules/gl_widget.py +++ b/drawing_modules/gl_widget.py @@ -73,6 +73,9 @@ class OpenGLWidget(QOpenGLWidget): except Exception as e: print(e) + def clear_mesh(self): + self.mesh_loaded = None + def initializeGL(self): glClearColor(0, 0, 0, 1) @@ -113,6 +116,9 @@ class OpenGLWidget(QOpenGLWidget): gluLookAt(cx, cy, cz + 100, cx, cy, cz, 0, 1, 0) self.draw_mesh_direct(self.mesh_loaded) + else: + glClearColor(0.0, 0.0, 0.0, 1.0) # Set the clear color (black with full opacity) + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Clear the color and depth buffers def draw_stl(self, vertices): diff --git a/gui.ui b/gui.ui index 3954a97..2c6fc70 100644 --- a/gui.ui +++ b/gui.ui @@ -15,7 +15,110 @@ - + + + + + 0 + 0 + + + + 0 + + + + Sketch + + + + + + Code + + + + + + + + + Executive + + + + + + Load Code + + + + + + + Save code + + + + + + + Apply Code + + + + + + + Delete Code + + + + + + + + + + + + + + Modify + + + + + + Extrd + + + + + + + Cut + + + + + + + Arry + + + + + + + Rev + + + + + + + @@ -41,54 +144,10 @@ - - - - Executive - - - - - - Apply Code - - - - - - - Load Code - - - - - - - Export STL - - - - - - - Delete Code - - - - - - - Save code - - - - - - - + 0 0 @@ -134,10 +193,141 @@ + + + + + 0 + 0 + + + + + 300 + 16777215 + + + + Sketch + + + + + + true + + + + + + + + 0 + 0 + + + + Tools + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Del sketch + + + + + + + Add Sktch + + + + + + + Edt Sktch + + + + + + + + + + true + + + + + + + + 0 + 0 + + + + Tools + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Del Bdy + + + + + + + Bdy Upd + + + + + + + Nothing + + + + + + + + + - + 0 0 @@ -177,133 +367,19 @@ - - + + - Modify + Export - - - - - Extrd - - - - - - - Cut - - - - - - - Arry - - - - - - - Rev - - - - - - - - - - - 0 - 0 - - - - 0 - - - - Sketch - - - - - - Code - - - - - - - - - - - - - - 0 - 0 - - - - - 300 - 16777215 - - - - Components - - + - - - true + + + STL - - - - - 0 - 0 - - - - Tools - - - - - - Del Elmt - - - - - - - Add Sktch - - - - - - - Edt Sktch - - - - - - diff --git a/main.py b/main.py index a913d65..89cebef 100644 --- a/main.py +++ b/main.py @@ -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: