diff --git a/CHANGELOG.md b/CHANGELOG.md index 9add68a..a7d348d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,12 +45,13 @@ New rendering features: * The "Show/hide outlines" button is now independent from "Show/hide edges". New measurement/analysis features: + * New choice for base unit, meters. * New command for measuring total length of selected entities, "Analyze → Measure Perimeter". * New command for measuring center of mass, with live updates as the sketch changes, "Analyze → Center of Mass". * New option for displaying areas of closed contours. - * When selecting a point and a line, projected distance to to current + * When selecting a point and a line, projected distance to current workplane is displayed. Other new features: diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index b99ab42..d46e86f 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -75,13 +75,14 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 1, NULL, Command::NONE, 0, TN, NULL }, { 1, N_("Show Snap &Grid"), Command::SHOW_GRID, '>', TC, mView }, { 1, N_("Use &Perspective Projection"), Command::PERSPECTIVE_PROJ, '`', TC, mView }, +{ 1, N_("Dimension &Units"), Command::NONE, 0, TN, NULL }, +{ 2, N_("Dimensions in &Inches"), Command::UNITS_INCHES, 0, TR, mView }, +{ 2, N_("Dimensions in &Millimeters"), Command::UNITS_MM, 0, TR, mView }, +{ 2, N_("Dimensions in M&eters"), Command::UNITS_METERS, 0, TR, mView }, { 1, NULL, Command::NONE, 0, TN, NULL }, { 1, N_("Show &Toolbar"), Command::SHOW_TOOLBAR, 0, TC, mView }, { 1, N_("Show Property Bro&wser"), Command::SHOW_TEXT_WND, '\t', TC, mView }, { 1, NULL, Command::NONE, 0, TN, NULL }, -{ 1, N_("Dimensions in &Inches"), Command::UNITS_INCHES, 0, TR, mView }, -{ 1, N_("Dimensions in &Millimeters"), Command::UNITS_MM, 0, TR, mView }, -{ 1, NULL, Command::NONE, 0, TN, NULL }, { 1, N_("&Full Screen"), Command::FULL_SCREEN, C|F(11), TC, mView }, { 0, N_("&New Group"), Command::NONE, 0, TN, NULL }, @@ -605,6 +606,12 @@ void GraphicsWindow::MenuView(Command id) { SS.GW.EnsureValidActives(); break; + case Command::UNITS_METERS: + SS.viewUnits = Unit::METERS; + SS.ScheduleShowTW(); + SS.GW.EnsureValidActives(); + break; + case Command::FULL_SCREEN: ToggleFullScreen(); SS.GW.EnsureValidActives(); @@ -671,12 +678,14 @@ void GraphicsWindow::EnsureValidActives() { switch(SS.viewUnits) { case Unit::MM: case Unit::INCHES: + case Unit::METERS: break; default: SS.viewUnits = Unit::MM; break; } RadioMenuByCmd(Command::UNITS_MM, SS.viewUnits == Unit::MM); + RadioMenuByCmd(Command::UNITS_METERS, SS.viewUnits == Unit::METERS); RadioMenuByCmd(Command::UNITS_INCHES, SS.viewUnits == Unit::INCHES); ShowTextWindow(SS.GW.showTextWindow); diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 6b1b38f..1c98d50 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -250,25 +250,29 @@ void SolveSpaceUI::DoLater() { } double SolveSpaceUI::MmPerUnit() { - if(viewUnits == Unit::INCHES) { - return 25.4; - } else { - return 1.0; + switch(viewUnits) { + case Unit::INCHES: return 25.4; + case Unit::METERS: return 1000.0; + case Unit::MM: return 1.0; } + return 1.0; } const char *SolveSpaceUI::UnitName() { - if(viewUnits == Unit::INCHES) { - return "inch"; - } else { - return "mm"; + switch(viewUnits) { + case Unit::INCHES: return "inch"; + case Unit::METERS: return "m"; + case Unit::MM: return "mm"; } + return ""; } + std::string SolveSpaceUI::MmToString(double v) { - if(viewUnits == Unit::INCHES) { - return ssprintf("%.*f", afterDecimalInch, v/25.4); - } else { - return ssprintf("%.*f", afterDecimalMm, v); + switch(viewUnits) { + case Unit::INCHES: return ssprintf("%.*f", afterDecimalInch, v / 25.4); + case Unit::METERS: return ssprintf("%.*f", afterDecimalMm, v / 1000.0); + case Unit::MM: return ssprintf("%.*f", afterDecimalMm, v); } + return ""; } double SolveSpaceUI::ExprToMm(Expr *e) { return (e->Eval()) * MmPerUnit(); diff --git a/src/solvespace.h b/src/solvespace.h index 29e227c..1306ae4 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -151,7 +151,8 @@ DialogChoice LocateImportedFileYesNoCancel(const Platform::Path &filename, enum class Unit : uint32_t { MM = 0, - INCHES + INCHES, + METERS }; struct FileFilter; diff --git a/src/ui.h b/src/ui.h index 38e8539..b5a6db4 100644 --- a/src/ui.h +++ b/src/ui.h @@ -146,6 +146,7 @@ enum class Command : uint32_t { SHOW_TEXT_WND, UNITS_INCHES, UNITS_MM, + UNITS_METERS, FULL_SCREEN, // Edit UNDO,