Implement Analyze → Measure Perimeter.

pull/33/head
whitequark 2016-08-01 13:18:58 +00:00
parent 9a1ceaa5c8
commit ff23a4a471
4 changed files with 31 additions and 1 deletions

View File

@ -8,6 +8,10 @@ New export/import features:
* Three.js: allow configuring projection for exported model, and initially * Three.js: allow configuring projection for exported model, and initially
use the current viewport projection. use the current viewport projection.
Other new features:
* New command for measuring total length of selected entities,
"Analyze → Measure Perimeter".
2.2 2.2
--- ---

View File

@ -149,7 +149,8 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
{ 0, "&Analyze", Command::NONE, 0, TN, NULL }, { 0, "&Analyze", Command::NONE, 0, TN, NULL },
{ 1, "Measure &Volume", Command::VOLUME, C|S|'V', TN, mAna }, { 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 &Interfering Parts", Command::INTERFERENCE, C|S|'I', TN, mAna },
{ 1, "Show &Naked Edges", Command::NAKED_EDGES, C|S|'N', TN, mAna }, { 1, "Show &Naked Edges", Command::NAKED_EDGES, C|S|'N', TN, mAna },
{ 1, NULL, Command::NONE, 0, TN, NULL }, { 1, NULL, Command::NONE, 0, TN, NULL },

View File

@ -749,6 +749,30 @@ void SolveSpaceUI::MenuAnalyze(Command id) {
break; 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: case Command::SHOW_DOF:
// This works like a normal solve, except that it calculates // This works like a normal solve, except that it calculates
// which variables are free/bound at the same time. // which variables are free/bound at the same time.

View File

@ -102,6 +102,7 @@ enum class Command : uint32_t {
// Analyze // Analyze
VOLUME, VOLUME,
AREA, AREA,
PERIMETER,
INTERFERENCE, INTERFERENCE,
NAKED_EDGES, NAKED_EDGES,
SHOW_DOF, SHOW_DOF,