- Started Solvespace implementation solver

This commit is contained in:
bklronin 2024-06-19 17:14:58 +02:00
parent a64971e0fe
commit edbd5ed0d3
5 changed files with 374 additions and 177 deletions

152
Gui.py
View File

@ -127,47 +127,13 @@ class Ui_fluencyCAD(object):
self.gridLayout.addWidget(self.gl_box, 0, 4, 8, 1) self.gridLayout.addWidget(self.gl_box, 0, 4, 8, 1)
self.groupBox_2 = QGroupBox(self.centralwidget)
self.groupBox_2.setObjectName(u"groupBox_2")
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)
self.pb_rectool.setObjectName(u"pb_rectool")
self.gridLayout_2.addWidget(self.pb_rectool, 0, 1, 1, 1, Qt.AlignTop)
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)
self.pb_circtool = QPushButton(self.groupBox_2)
self.pb_circtool.setObjectName(u"pb_circtool")
self.gridLayout_2.addWidget(self.pb_circtool, 1, 0, 1, 1, Qt.AlignTop)
self.pb_slotool = QPushButton(self.groupBox_2)
self.pb_slotool.setObjectName(u"pb_slotool")
self.gridLayout_2.addWidget(self.pb_slotool, 1, 1, 1, 1, Qt.AlignTop)
self.gridLayout.addWidget(self.groupBox_2, 0, 0, 1, 1)
self.groupBox_5 = QGroupBox(self.centralwidget) self.groupBox_5 = QGroupBox(self.centralwidget)
self.groupBox_5.setObjectName(u"groupBox_5") self.groupBox_5.setObjectName(u"groupBox_5")
sizePolicy3 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) sizePolicy2 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
sizePolicy3.setHorizontalStretch(0) sizePolicy2.setHorizontalStretch(0)
sizePolicy3.setVerticalStretch(0) sizePolicy2.setVerticalStretch(0)
sizePolicy3.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth()) sizePolicy2.setHeightForWidth(self.groupBox_5.sizePolicy().hasHeightForWidth())
self.groupBox_5.setSizePolicy(sizePolicy3) self.groupBox_5.setSizePolicy(sizePolicy2)
self.groupBox_5.setMaximumSize(QSize(300, 16777215)) self.groupBox_5.setMaximumSize(QSize(300, 16777215))
self.verticalLayout_3 = QVBoxLayout(self.groupBox_5) self.verticalLayout_3 = QVBoxLayout(self.groupBox_5)
self.verticalLayout_3.setObjectName(u"verticalLayout_3") self.verticalLayout_3.setObjectName(u"verticalLayout_3")
@ -179,8 +145,11 @@ class Ui_fluencyCAD(object):
self.groupBox_6 = QGroupBox(self.groupBox_5) self.groupBox_6 = QGroupBox(self.groupBox_5)
self.groupBox_6.setObjectName(u"groupBox_6") self.groupBox_6.setObjectName(u"groupBox_6")
sizePolicy2.setHeightForWidth(self.groupBox_6.sizePolicy().hasHeightForWidth()) sizePolicy3 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
self.groupBox_6.setSizePolicy(sizePolicy2) sizePolicy3.setHorizontalStretch(0)
sizePolicy3.setVerticalStretch(0)
sizePolicy3.setHeightForWidth(self.groupBox_6.sizePolicy().hasHeightForWidth())
self.groupBox_6.setSizePolicy(sizePolicy3)
self.gridLayout_6 = QGridLayout(self.groupBox_6) self.gridLayout_6 = QGridLayout(self.groupBox_6)
self.gridLayout_6.setObjectName(u"gridLayout_6") self.gridLayout_6.setObjectName(u"gridLayout_6")
self.gridLayout_6.setContentsMargins(2, 2, 2, 2) self.gridLayout_6.setContentsMargins(2, 2, 2, 2)
@ -210,8 +179,8 @@ class Ui_fluencyCAD(object):
self.groupBox_8 = QGroupBox(self.groupBox_5) self.groupBox_8 = QGroupBox(self.groupBox_5)
self.groupBox_8.setObjectName(u"groupBox_8") self.groupBox_8.setObjectName(u"groupBox_8")
sizePolicy2.setHeightForWidth(self.groupBox_8.sizePolicy().hasHeightForWidth()) sizePolicy3.setHeightForWidth(self.groupBox_8.sizePolicy().hasHeightForWidth())
self.groupBox_8.setSizePolicy(sizePolicy2) self.groupBox_8.setSizePolicy(sizePolicy3)
self.gridLayout_8 = QGridLayout(self.groupBox_8) self.gridLayout_8 = QGridLayout(self.groupBox_8)
self.gridLayout_8.setObjectName(u"gridLayout_8") self.gridLayout_8.setObjectName(u"gridLayout_8")
self.gridLayout_8.setContentsMargins(2, 2, 2, 2) self.gridLayout_8.setContentsMargins(2, 2, 2, 2)
@ -236,19 +205,81 @@ class Ui_fluencyCAD(object):
self.gridLayout.addWidget(self.groupBox_5, 0, 3, 8, 1) self.gridLayout.addWidget(self.groupBox_5, 0, 3, 8, 1)
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.verticalLayout_2.addWidget(self.pushButton_2)
self.gridLayout.addWidget(self.groupBox_4, 7, 5, 1, 1)
self.groupBox_9 = QGroupBox(self.centralwidget)
self.groupBox_9.setObjectName(u"groupBox_9")
self.gridLayout_7 = QGridLayout(self.groupBox_9)
self.gridLayout_7.setObjectName(u"gridLayout_7")
self.pb_origin_wp = QPushButton(self.groupBox_9)
self.pb_origin_wp.setObjectName(u"pb_origin_wp")
self.gridLayout_7.addWidget(self.pb_origin_wp, 0, 0, 1, 1)
self.pb_origin_face = QPushButton(self.groupBox_9)
self.pb_origin_face.setObjectName(u"pb_origin_face")
self.gridLayout_7.addWidget(self.pb_origin_face, 0, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_9, 0, 0, 1, 1)
self.groupBox_2 = QGroupBox(self.centralwidget)
self.groupBox_2.setObjectName(u"groupBox_2")
sizePolicy3.setHeightForWidth(self.groupBox_2.sizePolicy().hasHeightForWidth())
self.groupBox_2.setSizePolicy(sizePolicy3)
self.gridLayout_2 = QGridLayout(self.groupBox_2)
self.gridLayout_2.setObjectName(u"gridLayout_2")
self.pb_rectool = QPushButton(self.groupBox_2)
self.pb_rectool.setObjectName(u"pb_rectool")
self.gridLayout_2.addWidget(self.pb_rectool, 1, 1, 1, 1, Qt.AlignTop)
self.pb_circtool = QPushButton(self.groupBox_2)
self.pb_circtool.setObjectName(u"pb_circtool")
self.gridLayout_2.addWidget(self.pb_circtool, 2, 0, 1, 1, Qt.AlignTop)
self.pb_slotool = QPushButton(self.groupBox_2)
self.pb_slotool.setObjectName(u"pb_slotool")
self.gridLayout_2.addWidget(self.pb_slotool, 2, 1, 1, 1, Qt.AlignTop)
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, 1, 0, 1, 1)
self.gridLayout.addWidget(self.groupBox_2, 1, 0, 1, 1)
self.groupBox_3 = QGroupBox(self.centralwidget) self.groupBox_3 = QGroupBox(self.centralwidget)
self.groupBox_3.setObjectName(u"groupBox_3") self.groupBox_3.setObjectName(u"groupBox_3")
sizePolicy2.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth()) sizePolicy3.setHeightForWidth(self.groupBox_3.sizePolicy().hasHeightForWidth())
self.groupBox_3.setSizePolicy(sizePolicy2) self.groupBox_3.setSizePolicy(sizePolicy3)
self.gridLayout_4 = QGridLayout(self.groupBox_3) self.gridLayout_4 = QGridLayout(self.groupBox_3)
self.gridLayout_4.setObjectName(u"gridLayout_4") self.gridLayout_4.setObjectName(u"gridLayout_4")
self.pb_con_line = QPushButton(self.groupBox_3) self.pb_con_line = QPushButton(self.groupBox_3)
self.pb_con_line.setObjectName(u"pb_con_line") self.pb_con_line.setObjectName(u"pb_con_line")
self.pb_con_line.setCheckable(True)
self.gridLayout_4.addWidget(self.pb_con_line, 0, 1, 1, 1) self.gridLayout_4.addWidget(self.pb_con_line, 0, 1, 1, 1)
self.pb_con_ptpt = QPushButton(self.groupBox_3) self.pb_con_ptpt = QPushButton(self.groupBox_3)
self.pb_con_ptpt.setObjectName(u"pb_con_ptpt") self.pb_con_ptpt.setObjectName(u"pb_con_ptpt")
self.pb_con_ptpt.setCheckable(True)
self.gridLayout_4.addWidget(self.pb_con_ptpt, 0, 0, 1, 1) self.gridLayout_4.addWidget(self.pb_con_ptpt, 0, 0, 1, 1)
@ -263,19 +294,7 @@ class Ui_fluencyCAD(object):
self.gridLayout_4.addWidget(self.pb_con_vert, 1, 1, 1, 1) self.gridLayout_4.addWidget(self.pb_con_vert, 1, 1, 1, 1)
self.gridLayout.addWidget(self.groupBox_3, 1, 0, 1, 1) self.gridLayout.addWidget(self.groupBox_3, 2, 0, 1, 1)
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.verticalLayout_2.addWidget(self.pushButton_2)
self.gridLayout.addWidget(self.groupBox_4, 7, 5, 1, 1)
fluencyCAD.setCentralWidget(self.centralwidget) fluencyCAD.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(fluencyCAD) self.menubar = QMenuBar(fluencyCAD)
@ -309,11 +328,6 @@ class Ui_fluencyCAD(object):
self.pb_arrayop.setText(QCoreApplication.translate("fluencyCAD", u"Arry", None)) self.pb_arrayop.setText(QCoreApplication.translate("fluencyCAD", u"Arry", None))
self.pb_revop.setText(QCoreApplication.translate("fluencyCAD", u"Rev", None)) self.pb_revop.setText(QCoreApplication.translate("fluencyCAD", u"Rev", None))
self.gl_box.setTitle(QCoreApplication.translate("fluencyCAD", u"Model Viewer", 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_5.setTitle(QCoreApplication.translate("fluencyCAD", u"Sketch", None))
self.groupBox_6.setTitle(QCoreApplication.translate("fluencyCAD", u"Tools", None)) self.groupBox_6.setTitle(QCoreApplication.translate("fluencyCAD", u"Tools", None))
self.pb_del_sketch.setText(QCoreApplication.translate("fluencyCAD", u"Del sketch", None)) self.pb_del_sketch.setText(QCoreApplication.translate("fluencyCAD", u"Del sketch", None))
@ -323,12 +337,20 @@ class Ui_fluencyCAD(object):
self.pb_del_body.setText(QCoreApplication.translate("fluencyCAD", u"Del Bdy", 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_update_body.setText(QCoreApplication.translate("fluencyCAD", u"Bdy Upd", None))
self.pb_edt_sktch_3.setText(QCoreApplication.translate("fluencyCAD", u"Nothing", None)) self.pb_edt_sktch_3.setText(QCoreApplication.translate("fluencyCAD", u"Nothing", None))
self.groupBox_4.setTitle(QCoreApplication.translate("fluencyCAD", u"Export", None))
self.pushButton_2.setText(QCoreApplication.translate("fluencyCAD", u"STL", None))
self.groupBox_9.setTitle(QCoreApplication.translate("fluencyCAD", u"Workplanes", None))
self.pb_origin_wp.setText(QCoreApplication.translate("fluencyCAD", u"WP Origin", None))
self.pb_origin_face.setText(QCoreApplication.translate("fluencyCAD", u" WP Face", None))
self.groupBox_2.setTitle(QCoreApplication.translate("fluencyCAD", u"Drawing", None))
self.pb_rectool.setText(QCoreApplication.translate("fluencyCAD", u"Rctgl", None))
self.pb_circtool.setText(QCoreApplication.translate("fluencyCAD", u"Circle", None))
self.pb_slotool.setText(QCoreApplication.translate("fluencyCAD", u"Slot", None))
self.pb_linetool.setText(QCoreApplication.translate("fluencyCAD", u"Line", None))
self.groupBox_3.setTitle(QCoreApplication.translate("fluencyCAD", u"Constrain", 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_line.setText(QCoreApplication.translate("fluencyCAD", u"Pt_Line", None))
self.pb_con_ptpt.setText(QCoreApplication.translate("fluencyCAD", u"Pt_Pt", 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_horiz.setText(QCoreApplication.translate("fluencyCAD", u"Horiz", None))
self.pb_con_vert.setText(QCoreApplication.translate("fluencyCAD", u"Vert", 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 # retranslateUi

View File

@ -1,3 +1,6 @@
import re
from copy import copy
from PySide6.QtWidgets import QApplication, QWidget, QMessageBox from PySide6.QtWidgets import QApplication, QWidget, QMessageBox
from PySide6.QtGui import QPainter, QPen, QColor from PySide6.QtGui import QPainter, QPen, QColor
from PySide6.QtCore import Qt, QPoint from PySide6.QtCore import Qt, QPoint
@ -6,61 +9,154 @@ from python_solvespace import SolverSystem, ResultFlag
class SketchWidget(QWidget): class SketchWidget(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.hovered_point = None
self.line_buffer = None
self.pt_pt_buffer = None
self.points = [] self.points = []
self.selected_line = None self.selected_line = None
self.snapping_range = 20 # Range in pixels for snapping self.snapping_range = 20 # Range in pixels for snapping
self.line_mode = False self.setMouseTracking(True)
self.mouse_mode = False
self.wp = None
self.solv = SolverSystem() self.solv = SolverSystem()
def solve_constraint(self): self.solventies = {}
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
... def create_worplane(self):
line0 = solv.add_line_2d(p0, p1, wp) # Create entity with others self.wp = self.solv.create_2d_base()
...
line1 = solv.add_line_2d(p0, p3, wp) def get_handle_nr(self, input_str: str) -> int:
solv.angle(line0, line1, 45, wp) # Constrain two entities # Define the regex pattern to extract the handle number
line1 = solv.entity(-1) # Entity handle can be re-generated and negatively indexed pattern = r"handle=(\d+)"
...
if solv.solve() == ResultFlag.OKAY: # Use re.search to find the handle number in the string
# Get the result (unpack from the entity or parameters) match = re.search(pattern, input_str)
# x and y are actually float type
dof = solv.dof() if match:
x, y = solv.params(p2.params) handle_number = int(match.group(1))
... print(f"Handle number: {handle_number}")
return int(handle_number)
else: else:
# Error! print("Handle number not found.")
# Get the list of all constraints
failures = solv.failures()
...
return 0
def set_points(self, points: list): def get_keys(self, d: dict, target: QPoint) -> list:
self.points = points result = []
#self.update() path = []
print(d)
print(target)
for k, v in d.items():
path.append(k)
if isinstance(v, dict):
self.get_keys(v, target)
if v == target:
result.append(copy(path))
path.pop()
return result
def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.LeftButton and self.line_mode: relation = {
self.points.append(event.pos()) 'handle_nr': None,
self.update() 'solv_handle': None
}
elif event.button() == Qt.RightButton: if event.button() == Qt.LeftButton and self.mouse_mode == "line":
for i in range(len(self.points) - 1):
if self.is_point_on_line(event.pos(), self.points[i], self.points[i + 1]):
self.selected_line = i
break
else:
self.selected_line = None
clicked_pos = event.pos()
# Paintline
"""self.points.append(clicked_pos)
self.update()"""
u = clicked_pos.x()
v = clicked_pos.y()
point = self.solv.add_point_2d(u, v, self.wp)
#print(point)
self.solv.dragged(point, self.wp)
# Solverline
if self.line_buffer:
line = self.solv.add_line_2d(self.line_buffer, point, self.wp)
#print(line)
self.line_buffer = point
# Track Relationship
handle_nr = self.get_handle_nr(str(point))
relation['handle_nr'] = handle_nr
relation['solv_handle'] = point
self.solventies[clicked_pos] = relation
self.points = list(self.solventies)
#print(self.points)
if event.button() == Qt.LeftButton and self.mouse_mode == "pt_pt":
point_solve_now = self.solventies[self.hovered_point]['solv_handle']
if self.pt_pt_buffer:
point_solve_old = self.solventies[self.pt_pt_buffer]['solv_handle']
print(point_solve_old)
print(point_solve_now)
self.solv.coincident(point_solve_now, point_solve_old, self.wp)
if self.solv.solve() == ResultFlag.OKAY:
# Get the result (unpack from the entity or parameters)
# x and y are actually float type
dof = self.solv.dof()
print(dof)
if self.pt_pt_buffer:
# Get the entry form the old point and copy it into new point with the new key and postion (key = postiion
move_point = self.solventies[self.pt_pt_buffer]
print(move_point)
del self.solventies[self.pt_pt_buffer]
self.solventies[self.hovered_point] = move_point
#print(f"Coordinates: {x1}, {y1}; {x2}, {y2}")
elif self.solv.solve() == ResultFlag.DIDNT_CONVERGE:
print("Solve_failed - Converge" )
elif self.solv.solve() == ResultFlag.TOO_MANY_UNKNOWNS:
print("Solve_failed - Unknowns" )
elif self.solv.solve() == ResultFlag.INCONSISTENT:
print("Solve_failed - Incons" )
self.points = []
self.points = list(self.solventies)
print(self.points)
self.pt_pt_buffer = self.hovered_point
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
if event.buttons() & Qt.RightButton: closest_point = None
if self.selected_line is not None: min_distance = float('inf')
self.points[self.selected_line] = event.pos() threshold = 10 # Distance threshold for highlighting
else:
self.points[-1] = event.pos() for point in self.points:
distance = (event.pos() - point).manhattanLength()
if distance < threshold and distance < min_distance:
closest_point = point
min_distance = distance
if closest_point != self.hovered_point:
self.hovered_point = closest_point
self.update() self.update()
def mouseDoubleClickEvent(self, event): def mouseDoubleClickEvent(self, event):
@ -69,6 +165,10 @@ class SketchWidget(QWidget):
def distance(self, p1, p2): def distance(self, p1, p2):
return ((p1.x() - p2.x()) ** 2 + (p1.y() - p2.y()) ** 2) ** 0.5 return ((p1.x() - p2.x()) ** 2 + (p1.y() - p2.y()) ** 2) ** 0.5
def set_points(self, points: list):
self.points = points
#self.update()
def is_point_on_line(self, p, p1, p2): def is_point_on_line(self, p, p1, p2):
distance1 = self.distance(p, p1) distance1 = self.distance(p, p1)
distance2 = self.distance(p, p2) distance2 = self.distance(p, p2)
@ -93,11 +193,18 @@ class SketchWidget(QWidget):
for point in self.points: for point in self.points:
painter.drawEllipse(point, 3, 3) painter.drawEllipse(point, 3, 3)
if self.selected_line is not None: #Highlight point hovered
if self.hovered_point:
highlight_pen = QPen(QColor(255, 0, 0))
highlight_pen.setWidth(2)
painter.setPen(highlight_pen)
painter.drawEllipse(self.hovered_point, 5, 5)
"""if self.selected_line is not None:
p1 = self.points[self.selected_line] p1 = self.points[self.selected_line]
p2 = self.points[self.selected_line + 1] p2 = self.points[self.selected_line + 1]
painter.setPen(QPen(Qt.red, 2)) painter.setPen(QPen(Qt.red, 2))
painter.drawLine(p1, p2) painter.drawLine(p1, p2)"""
painter.end() painter.end()
def clear_sketch(self): def clear_sketch(self):

View File

@ -0,0 +1,25 @@
from python_solvespace import SolverSystem, ResultFlag
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()
...

159
gui.ui
View File

@ -144,55 +144,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Drawing</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1" alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_rectool">
<property name="text">
<string>Rctgl</string>
</property>
</widget>
</item>
<item row="0" column="0" alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_linetool">
<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">
<widget class="QPushButton" name="pb_circtool">
<property name="text">
<string>Circle</string>
</property>
</widget>
</item>
<item row="1" column="1" alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_slotool">
<property name="text">
<string>Slot</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="3" rowspan="8"> <item row="0" column="3" rowspan="8">
<widget class="QGroupBox" name="groupBox_5"> <widget class="QGroupBox" name="groupBox_5">
<property name="sizePolicy"> <property name="sizePolicy">
@ -324,7 +275,95 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="7" column="5">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Export</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>STL</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_9">
<property name="title">
<string>Workplanes</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QPushButton" name="pb_origin_wp">
<property name="text">
<string>WP Origin</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pb_origin_face">
<property name="text">
<string> WP Face</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Drawing</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1" alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_rectool">
<property name="text">
<string>Rctgl</string>
</property>
</widget>
</item>
<item row="2" column="0" alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_circtool">
<property name="text">
<string>Circle</string>
</property>
</widget>
</item>
<item row="2" column="1" alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_slotool">
<property name="text">
<string>Slot</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pb_linetool">
<property name="text">
<string>Line</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
@ -341,6 +380,9 @@
<property name="text"> <property name="text">
<string>Pt_Line</string> <string>Pt_Line</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
@ -348,6 +390,9 @@
<property name="text"> <property name="text">
<string>Pt_Pt</string> <string>Pt_Pt</string>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
@ -367,22 +412,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="7" column="5">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Export</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>STL</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">

22
main.py
View File

@ -44,25 +44,39 @@ class MainWindow(QMainWindow):
self.ui.sketch_list.itemChanged.connect(self.view_update) self.ui.sketch_list.itemChanged.connect(self.view_update)
### Sketches ### Sketches
self.ui.pb_origin_wp.pressed.connect(self.add_wp_origin)
self.ui.pb_nw_sktch.pressed.connect(self.add_sketch) self.ui.pb_nw_sktch.pressed.connect(self.add_sketch)
self.ui.pb_del_sketch.pressed.connect(self.del_sketch) self.ui.pb_del_sketch.pressed.connect(self.del_sketch)
self.ui.pb_edt_sktch.pressed.connect(self.edit_sketch) self.ui.pb_edt_sktch.pressed.connect(self.edit_sketch)
###Modes
self.ui.pb_linetool.pressed.connect(self.act_line_mode) self.ui.pb_linetool.pressed.connect(self.act_line_mode)
self.ui.pb_con_ptpt.pressed.connect(self.act_constrain_pt_pt_mode)
### Operations ### Operations
self.ui.pb_extrdop.pressed.connect(self.send_extrude) self.ui.pb_extrdop.pressed.connect(self.send_extrude)
self.ui.pb_cutop.pressed.connect(self.send_cut) self.ui.pb_cutop.pressed.connect(self.send_cut)
self.ui.pb_del_body.pressed.connect(self.del_body) self.ui.pb_del_body.pressed.connect(self.del_body)
def add_wp_origin(self):
#Select orientation
#orientation, ok = Q .getDouble(self, 'Extrude Length', 'Enter a mm value:', decimals=2)
self.sketchWidget.create_worplane()
def act_line_mode(self): def act_line_mode(self):
if not self.ui.pb_linetool.isChecked(): if not self.ui.pb_linetool.isChecked():
self.sketchWidget.line_mode = True self.sketchWidget.mouse_mode = 'line'
self.sketchWidget.points = [] #self.sketchWidget.points = []
else: else:
self.sketchWidget.line_mode = False self.sketchWidget.mouse_mode = None
def act_constrain_pt_pt_mode(self):
if not self.ui.pb_linetool.isChecked():
self.sketchWidget.mouse_mode = 'pt_pt'
#self.sketchWidget.points = []
else:
self.sketchWidget.mouse_mode = None
def view_update(self): def view_update(self):