Allow using m (in addition to mm and inch) as base unit.

pull/252/merge
EvilSpirit 2017-03-30 09:24:06 +07:00 committed by whitequark
parent 6ad5c684d8
commit a16c204304
5 changed files with 33 additions and 17 deletions

View File

@ -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:

View File

@ -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);

View File

@ -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();

View File

@ -151,7 +151,8 @@ DialogChoice LocateImportedFileYesNoCancel(const Platform::Path &filename,
enum class Unit : uint32_t {
MM = 0,
INCHES
INCHES,
METERS
};
struct FileFilter;

View File

@ -146,6 +146,7 @@ enum class Command : uint32_t {
SHOW_TEXT_WND,
UNITS_INCHES,
UNITS_MM,
UNITS_METERS,
FULL_SCREEN,
// Edit
UNDO,