feat: Render unattached sketch vertices as circles
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -24,6 +24,18 @@
|
|||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
struct PntComparator {
|
||||||
|
bool operator()(const gp_Pnt& a, const gp_Pnt& b) const {
|
||||||
|
// A tolerance is needed for floating point comparisons
|
||||||
|
double tol = 1e-9;
|
||||||
|
if (std::abs(a.X() - b.X()) > tol) return a.X() < b.X();
|
||||||
|
if (std::abs(a.Y() - b.Y()) > tol) return a.Y() < b.Y();
|
||||||
|
if (std::abs(a.Z() - b.Z()) > tol) return a.Z() < b.Z();
|
||||||
|
return false; // They are considered equal
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ViewportWidget::ViewportWidget(QWidget *parent)
|
ViewportWidget::ViewportWidget(QWidget *parent)
|
||||||
: QOpenGLWidget(parent)
|
: QOpenGLWidget(parent)
|
||||||
@@ -735,7 +747,7 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
glPointSize(5.0f);
|
glPointSize(5.0f);
|
||||||
|
|
||||||
QVector<GLfloat> lineVertices;
|
QVector<GLfloat> lineVertices;
|
||||||
QVector<GLfloat> pointVertices;
|
QMap<gp_Pnt, int, PntComparator> vertexCounts;
|
||||||
|
|
||||||
for (const auto& obj : sketch->objects()) {
|
for (const auto& obj : sketch->objects()) {
|
||||||
if (obj->type() == SketchObject::ObjectType::Line) {
|
if (obj->type() == SketchObject::ObjectType::Line) {
|
||||||
@@ -745,8 +757,16 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
lineVertices << start.X() << start.Y() << start.Z();
|
lineVertices << start.X() << start.Y() << start.Z();
|
||||||
lineVertices << end.X() << end.Y() << end.Z();
|
lineVertices << end.X() << end.Y() << end.Z();
|
||||||
|
|
||||||
pointVertices << start.X() << start.Y() << start.Z();
|
vertexCounts[start]++;
|
||||||
pointVertices << end.X() << end.Y() << end.Z();
|
vertexCounts[end]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<GLfloat> pointVertices;
|
||||||
|
for (auto it = vertexCounts.constBegin(); it != vertexCounts.constEnd(); ++it) {
|
||||||
|
if (it.value() == 1) {
|
||||||
|
const gp_Pnt& p = it.key();
|
||||||
|
pointVertices << p.X() << p.Y() << p.Z();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,8 +778,13 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
glDrawArrays(GL_LINES, 0, lineVertices.size() / 3);
|
glDrawArrays(GL_LINES, 0, lineVertices.size() / 3);
|
||||||
}
|
}
|
||||||
if (!pointVertices.isEmpty()) {
|
if (!pointVertices.isEmpty()) {
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
m_vbo.allocate(pointVertices.constData(), pointVertices.size() * sizeof(GLfloat));
|
m_vbo.allocate(pointVertices.constData(), pointVertices.size() * sizeof(GLfloat));
|
||||||
glDrawArrays(GL_POINTS, 0, pointVertices.size() / 3);
|
glDrawArrays(GL_POINTS, 0, pointVertices.size() / 3);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
glDisable(GL_POINT_SMOOTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|||||||
Reference in New Issue
Block a user