- 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

303
Gui.py
View File

@ -29,8 +29,64 @@ class Ui_fluencyCAD(object):
self.centralwidget.setObjectName(u"centralwidget")
self.gridLayout = QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(u"gridLayout")
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)
font = QFont()
font.setPointSize(12)
self.gl_box.setFont(font)
self.horizontalLayout_4 = QHBoxLayout(self.gl_box)
#ifndef Q_OS_MAC
self.horizontalLayout_4.setSpacing(-1)
#endif
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.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)
self.gridLayout_2 = QGridLayout(self.groupBox_2)
self.gridLayout_2.setObjectName(u"gridLayout_2")
self.pb_rectool = QPushButton(self.groupBox_2)
@ -40,6 +96,8 @@ class Ui_fluencyCAD(object):
self.pb_linetool = QPushButton(self.groupBox_2)
self.pb_linetool.setObjectName(u"pb_linetool")
self.pb_linetool.setCheckable(True)
self.pb_linetool.setAutoExclusive(True)
self.gridLayout_2.addWidget(self.pb_linetool, 0, 0, 1, 1, Qt.AlignTop)
@ -54,7 +112,36 @@ class Ui_fluencyCAD(object):
self.gridLayout_2.addWidget(self.pb_slotool, 1, 1, 1, 1, Qt.AlignTop)
self.gridLayout.addWidget(self.groupBox_2, 1, 0, 1, 1)
self.gridLayout.addWidget(self.groupBox_2, 0, 0, 1, 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)
self.gridLayout_4 = QGridLayout(self.groupBox_3)
self.gridLayout_4.setObjectName(u"gridLayout_4")
self.pb_con_line = QPushButton(self.groupBox_3)
self.pb_con_line.setObjectName(u"pb_con_line")
self.gridLayout_4.addWidget(self.pb_con_line, 0, 1, 1, 1)
self.pb_con_ptpt = QPushButton(self.groupBox_3)
self.pb_con_ptpt.setObjectName(u"pb_con_ptpt")
self.gridLayout_4.addWidget(self.pb_con_ptpt, 0, 0, 1, 1)
self.pb_con_horiz = QPushButton(self.groupBox_3)
self.pb_con_horiz.setObjectName(u"pb_con_horiz")
self.gridLayout_4.addWidget(self.pb_con_horiz, 1, 0, 1, 1)
self.pb_con_vert = QPushButton(self.groupBox_3)
self.pb_con_vert.setObjectName(u"pb_con_vert")
self.gridLayout_4.addWidget(self.pb_con_vert, 1, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_3, 1, 0, 1, 1)
self.groupBox = QGroupBox(self.centralwidget)
self.groupBox.setObjectName(u"groupBox")
@ -81,119 +168,15 @@ class Ui_fluencyCAD(object):
self.gridLayout_3.addWidget(self.pb_revop, 1, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox, 0, 5, 3, 1, Qt.AlignTop)
self.groupBox_6 = QGroupBox(self.centralwidget)
self.groupBox_6.setObjectName(u"groupBox_6")
self.verticalLayout_2 = QVBoxLayout(self.groupBox_6)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.pb_nw_sktch = QPushButton(self.groupBox_6)
self.pb_nw_sktch.setObjectName(u"pb_nw_sktch")
self.verticalLayout_2.addWidget(self.pb_nw_sktch)
self.pb_del_sketch = QPushButton(self.groupBox_6)
self.pb_del_sketch.setObjectName(u"pb_del_sketch")
self.verticalLayout_2.addWidget(self.pb_del_sketch)
self.pb_edt_sktch = QPushButton(self.groupBox_6)
self.pb_edt_sktch.setObjectName(u"pb_edt_sktch")
self.verticalLayout_2.addWidget(self.pb_edt_sktch)
self.pushButton_13 = QPushButton(self.groupBox_6)
self.pushButton_13.setObjectName(u"pushButton_13")
self.verticalLayout_2.addWidget(self.pushButton_13)
self.gridLayout.addWidget(self.groupBox_6, 0, 0, 1, 1)
self.groupBox_7 = QGroupBox(self.centralwidget)
self.groupBox_7.setObjectName(u"groupBox_7")
self.verticalLayout_5 = QVBoxLayout(self.groupBox_7)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.pb_apply_code = QPushButton(self.groupBox_7)
self.pb_apply_code.setObjectName(u"pb_apply_code")
self.verticalLayout_5.addWidget(self.pb_apply_code)
self.pushButton = QPushButton(self.groupBox_7)
self.pushButton.setObjectName(u"pushButton")
self.verticalLayout_5.addWidget(self.pushButton)
self.pushButton_5 = QPushButton(self.groupBox_7)
self.pushButton_5.setObjectName(u"pushButton_5")
self.verticalLayout_5.addWidget(self.pushButton_5)
self.pushButton_4 = QPushButton(self.groupBox_7)
self.pushButton_4.setObjectName(u"pushButton_4")
self.verticalLayout_5.addWidget(self.pushButton_4)
self.pushButton_2 = QPushButton(self.groupBox_7)
self.pushButton_2.setObjectName(u"pushButton_2")
self.verticalLayout_5.addWidget(self.pushButton_2)
self.gridLayout.addWidget(self.groupBox_7, 3, 0, 1, 1)
self.groupBox_3 = QGroupBox(self.centralwidget)
self.groupBox_3.setObjectName(u"groupBox_3")
self.gridLayout_4 = QGridLayout(self.groupBox_3)
self.gridLayout_4.setObjectName(u"gridLayout_4")
self.pb_con_line = QPushButton(self.groupBox_3)
self.pb_con_line.setObjectName(u"pb_con_line")
self.gridLayout_4.addWidget(self.pb_con_line, 0, 1, 1, 1)
self.pb_con_ptpt = QPushButton(self.groupBox_3)
self.pb_con_ptpt.setObjectName(u"pb_con_ptpt")
self.gridLayout_4.addWidget(self.pb_con_ptpt, 0, 0, 1, 1)
self.pb_con_horiz = QPushButton(self.groupBox_3)
self.pb_con_horiz.setObjectName(u"pb_con_horiz")
self.gridLayout_4.addWidget(self.pb_con_horiz, 1, 0, 1, 1)
self.pb_con_vert = QPushButton(self.groupBox_3)
self.pb_con_vert.setObjectName(u"pb_con_vert")
self.gridLayout_4.addWidget(self.pb_con_vert, 1, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_3, 2, 0, 1, 1)
self.groupBox_5 = QGroupBox(self.centralwidget)
self.groupBox_5.setObjectName(u"groupBox_5")
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth())
self.groupBox_5.setSizePolicy(sizePolicy)
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.verticalLayout_3.addWidget(self.element_list)
self.gridLayout.addWidget(self.groupBox_5, 0, 3, 4, 1)
self.gridLayout.addWidget(self.groupBox, 0, 5, 6, 1, Qt.AlignTop)
self.InputTab = QTabWidget(self.centralwidget)
self.InputTab.setObjectName(u"InputTab")
sizePolicy1 = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)
sizePolicy1.setHorizontalStretch(0)
sizePolicy1.setVerticalStretch(0)
sizePolicy1.setHeightForWidth(self.InputTab.sizePolicy().hasHeightForWidth())
self.InputTab.setSizePolicy(sizePolicy1)
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)
@ -210,26 +193,53 @@ class Ui_fluencyCAD(object):
self.InputTab.addTab(self.code_tab, "")
self.gridLayout.addWidget(self.InputTab, 0, 2, 4, 1)
self.gridLayout.addWidget(self.InputTab, 0, 2, 7, 1)
self.gl_box = QGroupBox(self.centralwidget)
self.gl_box.setObjectName(u"gl_box")
sizePolicy2 = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
sizePolicy2.setHorizontalStretch(0)
sizePolicy2.setVerticalStretch(4)
sizePolicy2.setHeightForWidth(self.gl_box.sizePolicy().hasHeightForWidth())
self.gl_box.setSizePolicy(sizePolicy2)
font = QFont()
font.setPointSize(12)
self.gl_box.setFont(font)
self.horizontalLayout_4 = QHBoxLayout(self.gl_box)
#ifndef Q_OS_MAC
self.horizontalLayout_4.setSpacing(-1)
#endif
self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
self.horizontalLayout_4.setContentsMargins(12, -1, -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.element_list = QListWidget(self.groupBox_5)
self.element_list.setObjectName(u"element_list")
self.element_list.setSelectionRectVisible(True)
self.gridLayout.addWidget(self.gl_box, 0, 4, 4, 1)
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)
fluencyCAD.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(fluencyCAD)
@ -250,35 +260,34 @@ 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.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.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.groupBox_6.setTitle(QCoreApplication.translate("fluencyCAD", u"Sketchtools", None))
self.pb_nw_sktch.setText(QCoreApplication.translate("fluencyCAD", u"Add Sketch", None))
self.pb_del_sketch.setText(QCoreApplication.translate("fluencyCAD", u"Sktch del", None))
self.pb_edt_sktch.setText(QCoreApplication.translate("fluencyCAD", u"Edt Sketch", None))
self.pushButton_13.setText(QCoreApplication.translate("fluencyCAD", u"PushButton", 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.setText(QCoreApplication.translate("fluencyCAD", u"Delete Code", None))
self.pushButton_5.setText(QCoreApplication.translate("fluencyCAD", u"Load Code", None))
self.pushButton_4.setText(QCoreApplication.translate("fluencyCAD", u"Save code", None))
self.pushButton_2.setText(QCoreApplication.translate("fluencyCAD", u"Export STL", 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_5.setTitle(QCoreApplication.translate("fluencyCAD", u"Components", 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.gl_box.setTitle(QCoreApplication.translate("fluencyCAD", u"Model Viewer", None))
self.groupBox_5.setTitle(QCoreApplication.translate("fluencyCAD", u"Components", 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_nw_sktch.setText(QCoreApplication.translate("fluencyCAD", u"Add Sktch", None))
self.pb_edt_sktch.setText(QCoreApplication.translate("fluencyCAD", u"Edt Sktch", None))
# retranslateUi

View File

@ -9,10 +9,14 @@ class SnapLineWidget(QWidget):
self.points = []
self.selected_line = None
self.snapping_range = 20 # Range in pixels for snapping
self.line_mode = False
def set_points(self, points: list):
self.points = points
#self.update()
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton :
if event.button() == Qt.LeftButton and self.line_mode:
self.points.append(event.pos())
self.update()

View File

@ -15,12 +15,12 @@ class OpenGLWidget(QOpenGLWidget):
self.lastPos = QPoint()
self.startPos = None
self.endPos = None
self.xRot = 0
self.xRot = 180
self.yRot = 0
self.zoom = -2
self.sketch = []
self.gl_width = self.width() / 1000
self.gl_height = self.height() / 1000
self.gl_width = self.width() / 100
self.gl_height = self.height() / 100
def map_value_to_range(self, value, value_min=0, value_max=1920, range_min=-1, range_max=1):
value = max(value_min, min(value_max, value))
@ -55,7 +55,8 @@ class OpenGLWidget(QOpenGLWidget):
return None, (0, 0, 0)
def load_mesh_direct(self, mesh) -> object:
def load_mesh_direct(self, mesh):
try:
stl_mesh = mesh
@ -68,9 +69,11 @@ class OpenGLWidget(QOpenGLWidget):
self.mesh_loaded = vertices
self.centroid = tuple(centroid)
print(f"Centroid: {self.centroid}")
self.update()
except Exception as e:
print(e)
def initializeGL(self):
glClearColor(0, 0, 0, 1)
glEnable(GL_DEPTH_TEST)
@ -85,7 +88,7 @@ class OpenGLWidget(QOpenGLWidget):
self.gl_width = self.width() / 1000
self.gl_height = self.height() / 1000
gluPerspective(45.0, aspect, 1.0, 10000.0)
gluPerspective(45.0, aspect, 0.01, 10.0)
glMatrixMode(GL_MODELVIEW)
@ -94,10 +97,10 @@ class OpenGLWidget(QOpenGLWidget):
glLoadIdentity()
glTranslatef(0, 0, self.zoom)
glRotatef(self.xRot, 0.0, 0.0, 0.0)
glRotatef(self.yRot, 0.0, 0.0, 0.0)
glRotatef(self.xRot, 1.0, 0.0, 0.0)
glRotatef(self.yRot, 0.0, 1.0, 0.0)
glColor3f(1.0, 1.0, 1.0)
glColor3f(0.9, 0.8, 0.8)
self.draw_area()
@ -136,14 +139,32 @@ class OpenGLWidget(QOpenGLWidget):
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
glLightfv(GL_LIGHT0, GL_POSITION, (0, 1, 1, 0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.6, 0.6, 0.6, 1.0))
glLightfv(GL_LIGHT0, GL_POSITION, (0, 0.6, 0.6, 0))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.4, 0.4, 0.4, 0.6))
glDisable(GL_LIGHTING)
glBegin(GL_TRIANGLES)
for vertex in points:
glVertex3fv(vertex)
glEnd()
self.update()
# Draw the lines (edges of the triangles)
#glDisable(GL_LIGHTING) # Disable lighting to avoid affecting the line color
glColor3f(0.0, 0.0, 0.0) # Set line color to black (or any color you prefer)
glBegin(GL_LINES)
for i in range(0, len(points), 3):
glVertex3fv(points[i])
glVertex3fv(points[i + 1])
glVertex3fv(points[i + 1])
glVertex3fv(points[i + 2])
glVertex3fv(points[i + 2])
glVertex3fv(points[i])
glEnd()
glEnable(GL_LIGHTING) # Re-enable lighting if further drawing requires it
def draw_area(self):
@ -174,7 +195,7 @@ class OpenGLWidget(QOpenGLWidget):
def wheelEvent(self, event):
delta = event.angleDelta().y()
self.zoom += delta / 120
self.zoom += delta / 200
self.update()
def aspect_ratio(self):

325
gui.ui
View File

@ -15,8 +15,84 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<item row="0" column="4" rowspan="7">
<widget class="QGroupBox" name="gl_box">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="title">
<string>Model Viewer</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>-1</number>
</property>
<property name="leftMargin">
<number>12</number>
</property>
</layout>
</widget>
</item>
<item row="6" column="5" alignment="Qt::AlignBottom">
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Executive</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QPushButton" name="pb_apply_code">
<property name="text">
<string>Apply Code</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>Load Code</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Export STL</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Delete Code</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>Save code</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Drawing</string>
</property>
@ -33,6 +109,12 @@
<property name="text">
<string>Line</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" alignment="Qt::AlignTop">
@ -52,126 +134,14 @@
</layout>
</widget>
</item>
<item row="0" column="5" rowspan="3" alignment="Qt::AlignTop">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Modify</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QPushButton" name="pb_extrdop">
<property name="text">
<string>Extrd</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pb_cutop">
<property name="text">
<string>Cut</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pb_arrayop">
<property name="text">
<string>Arry</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pb_revop">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Sketchtools</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pb_nw_sktch">
<property name="text">
<string>Add Sketch</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_del_sketch">
<property name="text">
<string>Sktch del</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_edt_sktch">
<property name="text">
<string>Edt Sketch</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_13">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Executive</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QPushButton" name="pb_apply_code">
<property name="text">
<string>Apply Code</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Delete Code</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>Load Code</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>Save code</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Export STL</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Constrain</string>
</property>
@ -207,31 +177,44 @@
</layout>
</widget>
</item>
<item row="0" column="3" rowspan="4">
<widget class="QGroupBox" name="groupBox_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<item row="0" column="5" rowspan="6" alignment="Qt::AlignTop">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Components</string>
<string>Modify</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListWidget" name="element_list"/>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QPushButton" name="pb_extrdop">
<property name="text">
<string>Extrd</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pb_cutop">
<property name="text">
<string extracomment="1. Bigger obj 2. smaller object">Cut</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pb_arrayop">
<property name="text">
<string>Arry</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pb_revop">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="2" rowspan="4">
<item row="0" column="2" rowspan="7">
<widget class="QTabWidget" name="InputTab">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
@ -260,29 +243,67 @@
</widget>
</widget>
</item>
<item row="0" column="4" rowspan="4">
<widget class="QGroupBox" name="gl_box">
<item row="0" column="3" rowspan="7">
<widget class="QGroupBox" name="groupBox_5">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Model Viewer</string>
<string>Components</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>-1</number>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListWidget" name="element_list">
<property name="selectionRectVisible">
<bool>true</bool>
</property>
<property name="leftMargin">
<number>12</number>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Tools</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="2">
<widget class="QPushButton" name="pb_del_sketch">
<property name="text">
<string>Del Elmt</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pb_nw_sktch">
<property name="text">
<string>Add Sktch</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pb_edt_sktch">
<property name="text">
<string>Edt Sktch</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>

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