From ff23a4a4712ba3b9dc9e5d7408c665b2602296e2 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 1 Aug 2016 13:18:58 +0000 Subject: [PATCH] =?UTF-8?q?Implement=20Analyze=20=E2=86=92=20Measure=20Per?= =?UTF-8?q?imeter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ src/graphicswin.cpp | 3 ++- src/solvespace.cpp | 24 ++++++++++++++++++++++++ src/ui.h | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c1c73..e18bccb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ New export/import features: * Three.js: allow configuring projection for exported model, and initially use the current viewport projection. +Other new features: + * New command for measuring total length of selected entities, + "Analyze → Measure Perimeter". + 2.2 --- diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index cb542c8..c8eb115 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -149,7 +149,8 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 0, "&Analyze", Command::NONE, 0, TN, NULL }, { 1, "Measure &Volume", Command::VOLUME, C|S|'V', TN, mAna }, -{ 1, "Measure &Area", Command::AREA, C|S|'A', TN, mAna }, +{ 1, "Measure A&rea", Command::AREA, C|S|'A', TN, mAna }, +{ 1, "Measure &Perimeter", Command::PERIMETER, C|S|'P', TN, mAna }, { 1, "Show &Interfering Parts", Command::INTERFERENCE, C|S|'I', TN, mAna }, { 1, "Show &Naked Edges", Command::NAKED_EDGES, C|S|'N', TN, mAna }, { 1, NULL, Command::NONE, 0, TN, NULL }, diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 5361dea..7115bc2 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -749,6 +749,30 @@ void SolveSpaceUI::MenuAnalyze(Command id) { break; } + case Command::PERIMETER: { + if(gs.n > 0 && gs.n == gs.entities) { + double perimeter = 0.0; + for(int i = 0; i < gs.entities; i++) { + Entity *e = SK.entity.FindById(gs.entity[i]); + SEdgeList *el = e->GetOrGenerateEdges(); + for(const SEdge &e : el->l) { + perimeter += e.b.Minus(e.a).Magnitude(); + } + } + + double scale = SS.MmPerUnit(); + Message("The total length of the selected entities is:\n\n" + " %.3f %s\n\n" + "Curves have been approximated as piecewise linear.\n" + "This introduces error, typically of around 1%%.", + perimeter / scale, + SS.UnitName()); + } else { + Error("Bad selection for perimeter; select line segments, arcs, and curves."); + } + break; + } + case Command::SHOW_DOF: // This works like a normal solve, except that it calculates // which variables are free/bound at the same time. diff --git a/src/ui.h b/src/ui.h index 7753ae3..f1be194 100644 --- a/src/ui.h +++ b/src/ui.h @@ -102,6 +102,7 @@ enum class Command : uint32_t { // Analyze VOLUME, AREA, + PERIMETER, INTERFERENCE, NAKED_EDGES, SHOW_DOF,