Kill the remaining Design-tab UI freezes

query_topology: indexing a body face-by-face was quadratic — face_by_index
re-walks the explorer and edge_by_index rebuilds the whole indexed map on every
single call. On a 15.7k-face / 25.6k-edge imported solid this blew past the
MCP 15 s main-thread timeout with the UI frozen throughout. GeometryEngine
gains faces_of()/edges_of(), which enumerate once in the very same order (ids
stay interchangeable with the _by_index accessors, so fillet/up_to_face targets
are unaffected). Measured on that body: 15 s timeout -> 0.46 s.

Feature ops: every commit-time m_doc.recompute() (fillet, cut, shell, boolean,
extrude, ...) now goes through recompute_guarded(), which runs the rebuild on a
worker thread. Live-preview/drag paths stay inline on purpose — yielding inside
a drag would be worse than the stall.

run_off_ui_thread(): the progress dialog is now created only after 300 ms, so a
fast op does not flash a dialog, while input stays blocked (wxWindowDisabler)
for the whole operation since the worker owns the document.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVzKmX6Y1aEteit1HTXG4Q
This commit is contained in:
Tommaso Bianchi
2026-07-15 00:13:10 +02:00
co-authored by Claude Opus 4.8
parent 01aa6903f0
commit f4160595b0
5 changed files with 89 additions and 22 deletions
+10 -4
View File
@@ -291,10 +291,16 @@ const TopoDS_Shape& body_shape(DesignPanel* panel, const json& params)
json query_topology(DesignPanel* panel, const json& params)
{
const TopoDS_Shape& shape = body_shape(panel, params);
// Enumerate once. The _by_index accessors rescan the shape on every call (edge_by_index
// rebuilds the whole indexed map), so indexing a body face-by-face is quadratic: ~15 s on a
// 4.7k-face imported solid, on the UI thread. faces_of/edges_of keep the very same ids.
const std::vector<TopoDS_Face> all_faces = GeometryEngine::faces_of(shape);
const std::vector<TopoDS_Edge> all_edges = GeometryEngine::edges_of(shape);
json faces = json::array();
int nf = GeometryEngine::face_count(shape);
const int nf = int(all_faces.size());
for (int i = 0; i < nf; ++i) {
TopoDS_Face f = GeometryEngine::face_by_index(shape, i);
const TopoDS_Face& f = all_faces[i];
if (f.IsNull()) continue;
json jf{{"id", i}, {"centroid", vec3(GeometryEngine::face_centroid_world(f))},
{"normal", vec3(GeometryEngine::face_normal_world(f))}, {"kind", "planar"}};
@@ -304,9 +310,9 @@ json query_topology(DesignPanel* panel, const json& params)
faces.push_back(std::move(jf));
}
json edges = json::array();
int ne = GeometryEngine::edge_count(shape);
const int ne = int(all_edges.size());
for (int i = 0; i < ne; ++i) {
TopoDS_Edge e = GeometryEngine::edge_by_index(shape, i);
const TopoDS_Edge& e = all_edges[i];
if (e.IsNull()) continue;
std::vector<Vec3d> pts = GeometryEngine::sample_edge_world(e);
if (pts.size() < 2) continue;