diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c1c738..e18bccb4 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 cb542c85..c8eb1153 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 5361dea5..7115bc2c 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 7753ae33..f1be1940 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,