Checkpoint before solvespace integration

This commit is contained in:
bklronin
2024-06-18 09:53:39 +02:00
parent 92a870e834
commit a64971e0fe
5 changed files with 525 additions and 355 deletions

View File

@@ -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()

View File

@@ -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):