2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Top-level implementation of the program's main window, in which a graphical
|
|
|
|
// representation of the model is drawn and edited by the user.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-03-27 09:53:51 +00:00
|
|
|
#include "solvespace.h"
|
2008-03-26 09:18:12 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
typedef void MenuHandler(Command id);
|
|
|
|
using MenuKind = Platform::MenuItem::Indicator;
|
|
|
|
struct MenuEntry {
|
|
|
|
int level; // 0 == on menu bar, 1 == one level down
|
|
|
|
const char *label; // or NULL for a separator
|
|
|
|
Command cmd; // command ID
|
|
|
|
int accel; // keyboard accelerator
|
|
|
|
MenuKind kind;
|
|
|
|
MenuHandler *fn;
|
|
|
|
};
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
#define mView (&GraphicsWindow::MenuView)
|
|
|
|
#define mEdit (&GraphicsWindow::MenuEdit)
|
2009-12-04 08:08:41 +00:00
|
|
|
#define mClip (&GraphicsWindow::MenuClipboard)
|
2008-04-13 10:57:41 +00:00
|
|
|
#define mReq (&GraphicsWindow::MenuRequest)
|
2008-04-14 10:28:32 +00:00
|
|
|
#define mCon (&Constraint::MenuConstrain)
|
2015-03-23 17:49:04 +00:00
|
|
|
#define mFile (&SolveSpaceUI::MenuFile)
|
2008-04-27 09:03:01 +00:00
|
|
|
#define mGrp (&Group::MenuGroup)
|
2015-03-23 17:49:04 +00:00
|
|
|
#define mAna (&SolveSpaceUI::MenuAnalyze)
|
|
|
|
#define mHelp (&SolveSpaceUI::MenuHelp)
|
2018-07-11 10:48:38 +00:00
|
|
|
#define SHIFT_MASK 0x100
|
|
|
|
#define CTRL_MASK 0x200
|
|
|
|
#define FN_MASK 0x400
|
|
|
|
|
2013-09-20 17:54:57 +00:00
|
|
|
#define S SHIFT_MASK
|
|
|
|
#define C CTRL_MASK
|
2018-07-11 10:48:38 +00:00
|
|
|
#define F FN_MASK
|
|
|
|
#define KN MenuKind::NONE
|
|
|
|
#define KC MenuKind::CHECK_MARK
|
|
|
|
#define KR MenuKind::RADIO_MARK
|
|
|
|
const MenuEntry Menu[] = {
|
|
|
|
//lv label cmd accel kind
|
|
|
|
{ 0, N_("&File"), Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&New"), Command::NEW, C|'n', KN, mFile },
|
|
|
|
{ 1, N_("&Open..."), Command::OPEN, C|'o', KN, mFile },
|
|
|
|
{ 1, N_("Open &Recent"), Command::OPEN_RECENT, 0, KN, mFile },
|
|
|
|
{ 1, N_("&Save"), Command::SAVE, C|'s', KN, mFile },
|
|
|
|
{ 1, N_("Save &As..."), Command::SAVE_AS, 0, KN, mFile },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
2018-07-17 18:51:00 +00:00
|
|
|
{ 1, N_("Export &Image..."), Command::EXPORT_IMAGE, 0, KN, mFile },
|
2018-07-11 10:48:38 +00:00
|
|
|
{ 1, N_("Export 2d &View..."), Command::EXPORT_VIEW, 0, KN, mFile },
|
|
|
|
{ 1, N_("Export 2d &Section..."), Command::EXPORT_SECTION, 0, KN, mFile },
|
|
|
|
{ 1, N_("Export 3d &Wireframe..."), Command::EXPORT_WIREFRAME, 0, KN, mFile },
|
|
|
|
{ 1, N_("Export Triangle &Mesh..."), Command::EXPORT_MESH, 0, KN, mFile },
|
|
|
|
{ 1, N_("Export &Surfaces..."), Command::EXPORT_SURFACES, 0, KN, mFile },
|
|
|
|
{ 1, N_("Im&port..."), Command::IMPORT, 0, KN, mFile },
|
2015-03-24 06:45:53 +00:00
|
|
|
#ifndef __APPLE__
|
2018-07-11 10:48:38 +00:00
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("E&xit"), Command::EXIT, C|'q', KN, mFile },
|
2015-03-24 06:45:53 +00:00
|
|
|
#endif
|
2015-03-18 17:02:11 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
{ 0, N_("&Edit"), Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&Undo"), Command::UNDO, C|'z', KN, mEdit },
|
|
|
|
{ 1, N_("&Redo"), Command::REDO, C|'y', KN, mEdit },
|
|
|
|
{ 1, N_("Re&generate All"), Command::REGEN_ALL, ' ', KN, mEdit },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Snap Selection to &Grid"), Command::SNAP_TO_GRID, '.', KN, mEdit },
|
|
|
|
{ 1, N_("Rotate Imported &90°"), Command::ROTATE_90, '9', KN, mEdit },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Cu&t"), Command::CUT, C|'x', KN, mClip },
|
|
|
|
{ 1, N_("&Copy"), Command::COPY, C|'c', KN, mClip },
|
|
|
|
{ 1, N_("&Paste"), Command::PASTE, C|'v', KN, mClip },
|
|
|
|
{ 1, N_("Paste &Transformed..."), Command::PASTE_TRANSFORM, C|'t', KN, mClip },
|
|
|
|
{ 1, N_("&Delete"), Command::DELETE, '\x7f', KN, mClip },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Select &Edge Chain"), Command::SELECT_CHAIN, C|'e', KN, mEdit },
|
|
|
|
{ 1, N_("Select &All"), Command::SELECT_ALL, C|'a', KN, mEdit },
|
|
|
|
{ 1, N_("&Unselect All"), Command::UNSELECT_ALL, '\x1b', KN, mEdit },
|
|
|
|
|
|
|
|
{ 0, N_("&View"), Command::NONE, 0, KN, mView },
|
|
|
|
{ 1, N_("Zoom &In"), Command::ZOOM_IN, '+', KN, mView },
|
|
|
|
{ 1, N_("Zoom &Out"), Command::ZOOM_OUT, '-', KN, mView },
|
|
|
|
{ 1, N_("Zoom To &Fit"), Command::ZOOM_TO_FIT, 'f', KN, mView },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Align View to &Workplane"), Command::ONTO_WORKPLANE, 'w', KN, mView },
|
|
|
|
{ 1, N_("Nearest &Ortho View"), Command::NEAREST_ORTHO, F|2, KN, mView },
|
|
|
|
{ 1, N_("Nearest &Isometric View"), Command::NEAREST_ISO, F|3, KN, mView },
|
|
|
|
{ 1, N_("&Center View At Point"), Command::CENTER_VIEW, F|4, KN, mView },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Show Snap &Grid"), Command::SHOW_GRID, '>', KC, mView },
|
|
|
|
{ 1, N_("Use &Perspective Projection"), Command::PERSPECTIVE_PROJ, '`', KC, mView },
|
|
|
|
{ 1, N_("Dimension &Units"), Command::NONE, 0, KN, NULL },
|
|
|
|
{ 2, N_("Dimensions in &Millimeters"), Command::UNITS_MM, 0, KR, mView },
|
|
|
|
{ 2, N_("Dimensions in M&eters"), Command::UNITS_METERS, 0, KR, mView },
|
|
|
|
{ 2, N_("Dimensions in &Inches"), Command::UNITS_INCHES, 0, KR, mView },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Show &Toolbar"), Command::SHOW_TOOLBAR, 0, KC, mView },
|
|
|
|
{ 1, N_("Show Property Bro&wser"), Command::SHOW_TEXT_WND, '\t', KC, mView },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&Full Screen"), Command::FULL_SCREEN, C|F|11, KC, mView },
|
|
|
|
|
|
|
|
{ 0, N_("&New Group"), Command::NONE, 0, KN, mGrp },
|
|
|
|
{ 1, N_("Sketch In &3d"), Command::GROUP_3D, S|'3', KN, mGrp },
|
|
|
|
{ 1, N_("Sketch In New &Workplane"), Command::GROUP_WRKPL, S|'w', KN, mGrp },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Step &Translating"), Command::GROUP_TRANS, S|'t', KN, mGrp },
|
|
|
|
{ 1, N_("Step &Rotating"), Command::GROUP_ROT, S|'r', KN, mGrp },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("E&xtrude"), Command::GROUP_EXTRUDE, S|'x', KN, mGrp },
|
|
|
|
{ 1, N_("&Lathe"), Command::GROUP_LATHE, S|'l', KN, mGrp },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Link / Assemble..."), Command::GROUP_LINK, S|'i', KN, mGrp },
|
|
|
|
{ 1, N_("Link Recent"), Command::GROUP_RECENT, 0, KN, mGrp },
|
|
|
|
|
|
|
|
{ 0, N_("&Sketch"), Command::NONE, 0, KN, mReq },
|
|
|
|
{ 1, N_("In &Workplane"), Command::SEL_WORKPLANE, '2', KR, mReq },
|
|
|
|
{ 1, N_("Anywhere In &3d"), Command::FREE_IN_3D, '3', KR, mReq },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Datum &Point"), Command::DATUM_POINT, 'p', KN, mReq },
|
|
|
|
{ 1, N_("&Workplane"), Command::WORKPLANE, 0, KN, mReq },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Line &Segment"), Command::LINE_SEGMENT, 's', KN, mReq },
|
|
|
|
{ 1, N_("C&onstruction Line Segment"), Command::CONSTR_SEGMENT, S|'s', KN, mReq },
|
|
|
|
{ 1, N_("&Rectangle"), Command::RECTANGLE, 'r', KN, mReq },
|
|
|
|
{ 1, N_("&Circle"), Command::CIRCLE, 'c', KN, mReq },
|
|
|
|
{ 1, N_("&Arc of a Circle"), Command::ARC, 'a', KN, mReq },
|
|
|
|
{ 1, N_("&Bezier Cubic Spline"), Command::CUBIC, 'b', KN, mReq },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&Text in TrueType Font"), Command::TTF_TEXT, 't', KN, mReq },
|
|
|
|
{ 1, N_("&Image"), Command::IMAGE, 0, KN, mReq },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("To&ggle Construction"), Command::CONSTRUCTION, 'g', KN, mReq },
|
|
|
|
{ 1, N_("Tangent &Arc at Point"), Command::TANGENT_ARC, S|'a', KN, mReq },
|
|
|
|
{ 1, N_("Split Curves at &Intersection"), Command::SPLIT_CURVES, 'i', KN, mReq },
|
|
|
|
|
|
|
|
{ 0, N_("&Constrain"), Command::NONE, 0, KN, mCon },
|
|
|
|
{ 1, N_("&Distance / Diameter"), Command::DISTANCE_DIA, 'd', KN, mCon },
|
|
|
|
{ 1, N_("Re&ference Dimension"), Command::REF_DISTANCE, S|'d', KN, mCon },
|
|
|
|
{ 1, N_("A&ngle"), Command::ANGLE, 'n', KN, mCon },
|
|
|
|
{ 1, N_("Reference An&gle"), Command::REF_ANGLE, S|'n', KN, mCon },
|
|
|
|
{ 1, N_("Other S&upplementary Angle"), Command::OTHER_ANGLE, 'u', KN, mCon },
|
|
|
|
{ 1, N_("Toggle R&eference Dim"), Command::REFERENCE, 'e', KN, mCon },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&Horizontal"), Command::HORIZONTAL, 'h', KN, mCon },
|
|
|
|
{ 1, N_("&Vertical"), Command::VERTICAL, 'v', KN, mCon },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&On Point / Curve / Plane"), Command::ON_ENTITY, 'o', KN, mCon },
|
|
|
|
{ 1, N_("E&qual Length / Radius / Angle"), Command::EQUAL, 'q', KN, mCon },
|
|
|
|
{ 1, N_("Length Ra&tio"), Command::RATIO, 'z', KN, mCon },
|
|
|
|
{ 1, N_("Length Diff&erence"), Command::DIFFERENCE, 'j', KN, mCon },
|
|
|
|
{ 1, N_("At &Midpoint"), Command::AT_MIDPOINT, 'm', KN, mCon },
|
|
|
|
{ 1, N_("S&ymmetric"), Command::SYMMETRIC, 'y', KN, mCon },
|
|
|
|
{ 1, N_("Para&llel / Tangent"), Command::PARALLEL, 'l', KN, mCon },
|
|
|
|
{ 1, N_("&Perpendicular"), Command::PERPENDICULAR, '[', KN, mCon },
|
|
|
|
{ 1, N_("Same Orient&ation"), Command::ORIENTED_SAME, 'x', KN, mCon },
|
|
|
|
{ 1, N_("Lock Point Where &Dragged"), Command::WHERE_DRAGGED, ']', KN, mCon },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Comment"), Command::COMMENT, ';', KN, mCon },
|
|
|
|
|
|
|
|
{ 0, N_("&Analyze"), Command::NONE, 0, KN, mAna },
|
|
|
|
{ 1, N_("Measure &Volume"), Command::VOLUME, C|S|'v', KN, mAna },
|
|
|
|
{ 1, N_("Measure A&rea"), Command::AREA, C|S|'a', KN, mAna },
|
|
|
|
{ 1, N_("Measure &Perimeter"), Command::PERIMETER, C|S|'p', KN, mAna },
|
|
|
|
{ 1, N_("Show &Interfering Parts"), Command::INTERFERENCE, C|S|'i', KN, mAna },
|
|
|
|
{ 1, N_("Show &Naked Edges"), Command::NAKED_EDGES, C|S|'n', KN, mAna },
|
|
|
|
{ 1, N_("Show &Center of Mass"), Command::CENTER_OF_MASS, C|S|'c', KN, mAna },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("Show Degrees of &Freedom"), Command::SHOW_DOF, C|S|'f', KN, mAna },
|
|
|
|
{ 1, NULL, Command::NONE, 0, KN, NULL },
|
|
|
|
{ 1, N_("&Trace Point"), Command::TRACE_PT, C|S|'t', KN, mAna },
|
|
|
|
{ 1, N_("&Stop Tracing..."), Command::STOP_TRACING, C|S|'s', KN, mAna },
|
|
|
|
{ 1, N_("Step &Dimension..."), Command::STEP_DIM, C|S|'d', KN, mAna },
|
|
|
|
|
|
|
|
{ 0, N_("&Help"), Command::NONE, 0, KN, mHelp },
|
|
|
|
{ 1, N_("&Language"), Command::LOCALE, 0, KN, mHelp },
|
|
|
|
{ 1, N_("&Website / Manual"), Command::WEBSITE, 0, KN, mHelp },
|
2015-03-24 06:45:53 +00:00
|
|
|
#ifndef __APPLE__
|
2018-07-11 10:48:38 +00:00
|
|
|
{ 1, N_("&About"), Command::ABOUT, 0, KN, mHelp },
|
2015-03-24 06:45:53 +00:00
|
|
|
#endif
|
2018-07-11 10:48:38 +00:00
|
|
|
{ -1, 0, Command::NONE, 0, KN, NULL }
|
2008-03-26 09:18:12 +00:00
|
|
|
};
|
2013-09-20 18:16:38 +00:00
|
|
|
#undef S
|
|
|
|
#undef C
|
|
|
|
#undef F
|
2018-07-11 10:48:38 +00:00
|
|
|
#undef KN
|
|
|
|
#undef KC
|
|
|
|
#undef KR
|
|
|
|
|
|
|
|
void GraphicsWindow::ActivateCommand(Command cmd) {
|
|
|
|
for(int i = 0; Menu[i].level >= 0; i++) {
|
|
|
|
if(cmd == Menu[i].cmd) {
|
|
|
|
(Menu[i].fn)((Command)Menu[i].cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 18:16:38 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
Platform::KeyboardEvent GraphicsWindow::AcceleratorForCommand(Command cmd) {
|
|
|
|
int rawAccel = 0;
|
|
|
|
for(int i = 0; Menu[i].level >= 0; i++) {
|
|
|
|
if(cmd == Menu[i].cmd) {
|
|
|
|
rawAccel = Menu[i].accel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 19:01:00 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
Platform::KeyboardEvent accel = {};
|
|
|
|
if(rawAccel & SHIFT_MASK) {
|
|
|
|
accel.shiftDown = true;
|
|
|
|
}
|
|
|
|
if(rawAccel & CTRL_MASK) {
|
|
|
|
accel.controlDown = true;
|
2016-04-17 10:01:44 +00:00
|
|
|
}
|
2018-07-11 10:48:38 +00:00
|
|
|
if(rawAccel & FN_MASK) {
|
|
|
|
accel.key = Platform::KeyboardEvent::Key::FUNCTION;
|
|
|
|
accel.num = rawAccel & 0xff;
|
|
|
|
} else {
|
|
|
|
accel.key = Platform::KeyboardEvent::Key::CHARACTER;
|
|
|
|
accel.chr = (char)(rawAccel & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return accel;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::KeyboardEvent(Platform::KeyboardEvent event) {
|
|
|
|
using Platform::KeyboardEvent;
|
|
|
|
|
|
|
|
if(event.type == KeyboardEvent::Type::RELEASE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(event.key == KeyboardEvent::Key::CHARACTER) {
|
|
|
|
if(event.chr == '\b') {
|
|
|
|
// Treat backspace identically to escape.
|
|
|
|
MenuEdit(Command::UNSELECT_ALL);
|
|
|
|
return true;
|
|
|
|
} else if(event.chr == '=') {
|
|
|
|
// Treat = as +. This is specific to US (and US-compatible) keyboard layouts,
|
|
|
|
// but makes zooming from keyboard much more usable on these.
|
|
|
|
// Ideally we'd have a platform-independent way of binding to a particular
|
|
|
|
// physical key regardless of shift status...
|
|
|
|
MenuView(Command::ZOOM_IN);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// On some platforms, the OS does not handle some or all keyboard accelerators,
|
|
|
|
// so handle them here.
|
|
|
|
for(int i = 0; Menu[i].level >= 0; i++) {
|
|
|
|
if(AcceleratorForCommand(Menu[i].cmd).Equals(event)) {
|
|
|
|
ActivateCommand(Menu[i].cmd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::PopulateMainMenu() {
|
|
|
|
bool unique = false;
|
2018-07-12 19:29:44 +00:00
|
|
|
Platform::MenuBarRef mainMenu = Platform::GetOrCreateMainMenu(&unique);
|
2018-07-11 10:48:38 +00:00
|
|
|
if(unique) mainMenu->Clear();
|
|
|
|
|
|
|
|
Platform::MenuRef currentSubMenu;
|
|
|
|
std::vector<Platform::MenuRef> subMenuStack;
|
|
|
|
for(int i = 0; Menu[i].level >= 0; i++) {
|
|
|
|
while(Menu[i].level > 0 && Menu[i].level <= (int)subMenuStack.size()) {
|
|
|
|
currentSubMenu = subMenuStack.back();
|
|
|
|
subMenuStack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Menu[i].label == NULL) {
|
|
|
|
currentSubMenu->AddSeparator();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string label = Translate(Menu[i].label);
|
|
|
|
if(Menu[i].level == 0) {
|
|
|
|
currentSubMenu = mainMenu->AddSubMenu(label);
|
|
|
|
} else if(Menu[i].cmd == Command::OPEN_RECENT) {
|
|
|
|
openRecentMenu = currentSubMenu->AddSubMenu(label);
|
|
|
|
} else if(Menu[i].cmd == Command::GROUP_RECENT) {
|
|
|
|
linkRecentMenu = currentSubMenu->AddSubMenu(label);
|
|
|
|
} else if(Menu[i].cmd == Command::LOCALE) {
|
|
|
|
Platform::MenuRef localeMenu = currentSubMenu->AddSubMenu(label);
|
|
|
|
for(const Locale &locale : Locales()) {
|
|
|
|
localeMenu->AddItem(locale.displayName, [&]() {
|
|
|
|
SetLocale(locale.Culture());
|
2018-07-16 10:37:41 +00:00
|
|
|
Platform::GetSettings()->FreezeString("Locale", locale.Culture());
|
2018-07-11 10:48:38 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.UpdateWindowTitles();
|
2018-07-11 10:48:38 +00:00
|
|
|
PopulateMainMenu();
|
2018-07-12 19:29:44 +00:00
|
|
|
EnsureValidActives();
|
2018-07-11 10:48:38 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if(Menu[i].fn == NULL) {
|
|
|
|
subMenuStack.push_back(currentSubMenu);
|
|
|
|
currentSubMenu = currentSubMenu->AddSubMenu(label);
|
|
|
|
} else {
|
|
|
|
Platform::MenuItemRef menuItem = currentSubMenu->AddItem(label);
|
|
|
|
menuItem->SetIndicator(Menu[i].kind);
|
|
|
|
if(Menu[i].accel != 0) {
|
|
|
|
menuItem->SetAccelerator(AcceleratorForCommand(Menu[i].cmd));
|
|
|
|
}
|
|
|
|
menuItem->onTrigger = std::bind(Menu[i].fn, Menu[i].cmd);
|
|
|
|
|
|
|
|
if(Menu[i].cmd == Command::SHOW_GRID) {
|
|
|
|
showGridMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::PERSPECTIVE_PROJ) {
|
|
|
|
perspectiveProjMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::SHOW_TOOLBAR) {
|
|
|
|
showToolbarMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::SHOW_TEXT_WND) {
|
|
|
|
showTextWndMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::FULL_SCREEN) {
|
|
|
|
fullScreenMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::UNITS_MM) {
|
|
|
|
unitsMmMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::UNITS_METERS) {
|
|
|
|
unitsMetersMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::UNITS_INCHES) {
|
|
|
|
unitsInchesMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::SEL_WORKPLANE) {
|
|
|
|
inWorkplaneMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::FREE_IN_3D) {
|
|
|
|
in3dMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::UNDO) {
|
|
|
|
undoMenuItem = menuItem;
|
|
|
|
} else if(Menu[i].cmd == Command::REDO) {
|
|
|
|
redoMenuItem = menuItem;
|
|
|
|
}
|
|
|
|
}
|
2016-04-17 10:01:44 +00:00
|
|
|
}
|
2018-07-11 10:48:38 +00:00
|
|
|
|
|
|
|
PopulateRecentFiles();
|
|
|
|
SS.UndoEnableMenus();
|
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
window->SetMenuBar(mainMenu);
|
2018-07-11 10:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PopulateMenuWithPathnames(Platform::MenuRef menu,
|
|
|
|
std::vector<Platform::Path> pathnames,
|
|
|
|
std::function<void(const Platform::Path &)> onTrigger) {
|
|
|
|
menu->Clear();
|
|
|
|
if(pathnames.empty()) {
|
|
|
|
Platform::MenuItemRef menuItem = menu->AddItem(_("(no recent files)"));
|
|
|
|
menuItem->SetEnabled(false);
|
2016-04-17 10:01:44 +00:00
|
|
|
} else {
|
2018-07-11 10:48:38 +00:00
|
|
|
for(Platform::Path pathname : pathnames) {
|
|
|
|
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw);
|
|
|
|
menuItem->onTrigger = [=]() { onTrigger(pathname); };
|
|
|
|
}
|
2013-09-20 19:01:00 +00:00
|
|
|
}
|
2018-07-11 10:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::PopulateRecentFiles() {
|
|
|
|
PopulateMenuWithPathnames(openRecentMenu, SS.recentFiles, [](const Platform::Path &path) {
|
|
|
|
if(!SS.OkayToStartNewFile()) return;
|
|
|
|
SS.Load(path);
|
|
|
|
});
|
|
|
|
|
|
|
|
PopulateMenuWithPathnames(linkRecentMenu, SS.recentFiles, [](const Platform::Path &path) {
|
|
|
|
Group::MenuGroup(Command::GROUP_LINK, path);
|
|
|
|
});
|
2013-09-20 19:01:00 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::Init() {
|
2018-07-12 19:29:44 +00:00
|
|
|
scale = 5;
|
2008-06-12 07:31:41 +00:00
|
|
|
offset = Vector::From(0, 0, 0);
|
|
|
|
projRight = Vector::From(1, 0, 0);
|
|
|
|
projUp = Vector::From(0, 1, 0);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-08-24 01:32:25 +00:00
|
|
|
// Make sure those are valid; could get a mouse move without a mouse
|
|
|
|
// down if someone depresses the button, then drags into our window.
|
|
|
|
orig.projRight = projRight;
|
|
|
|
orig.projUp = projUp;
|
|
|
|
|
2008-06-14 23:31:36 +00:00
|
|
|
// And with the last group active
|
2016-02-17 10:03:07 +00:00
|
|
|
activeGroup = SK.groupOrder.elem[SK.groupOrder.n - 1];
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetGroup(activeGroup)->Activate();
|
2008-05-25 13:11:44 +00:00
|
|
|
|
2008-06-14 09:51:25 +00:00
|
|
|
showWorkplanes = false;
|
2008-05-05 06:18:01 +00:00
|
|
|
showNormals = true;
|
2008-04-11 12:47:14 +00:00
|
|
|
showPoints = true;
|
|
|
|
showConstraints = true;
|
2008-05-28 10:34:55 +00:00
|
|
|
showShaded = true;
|
2009-03-18 04:26:04 +00:00
|
|
|
showEdges = true;
|
2008-06-01 04:31:28 +00:00
|
|
|
showMesh = false;
|
2016-03-14 16:14:24 +00:00
|
|
|
showOutlines = false;
|
2016-08-13 09:02:12 +00:00
|
|
|
drawOccludedAs = DrawOccludedAs::INVISIBLE;
|
2008-04-27 05:00:12 +00:00
|
|
|
|
|
|
|
showTextWindow = true;
|
2008-06-13 04:41:27 +00:00
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
showSnapGrid = false;
|
2009-09-23 10:59:59 +00:00
|
|
|
context.active = false;
|
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
if(!window) {
|
|
|
|
window = Platform::CreateWindow();
|
|
|
|
if(window) {
|
|
|
|
canvas = CreateRenderer();
|
|
|
|
if(canvas) {
|
|
|
|
persistentCanvas = canvas->CreateBatch();
|
|
|
|
persistentDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace std::placeholders;
|
|
|
|
window->onClose = std::bind(&SolveSpaceUI::MenuFile, Command::EXIT);
|
|
|
|
window->onRender = std::bind(&GraphicsWindow::Paint, this);
|
|
|
|
window->onKeyboardEvent = std::bind(&GraphicsWindow::KeyboardEvent, this, _1);
|
|
|
|
window->onMouseEvent = std::bind(&GraphicsWindow::MouseEvent, this, _1);
|
|
|
|
window->onEditingDone = std::bind(&GraphicsWindow::EditControlDone, this, _1);
|
|
|
|
window->SetMinContentSize(720, 670);
|
|
|
|
PopulateMainMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 04:41:27 +00:00
|
|
|
// Do this last, so that all the menus get updated correctly.
|
2016-04-16 02:16:47 +00:00
|
|
|
ClearSuper();
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::AnimateOntoWorkplane() {
|
2008-05-27 02:22:20 +00:00
|
|
|
if(!LockedInWorkplane()) return;
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *w = SK.GetEntity(ActiveWorkplane());
|
2008-05-27 02:22:20 +00:00
|
|
|
Quaternion quatf = w->Normal()->NormalGetNum();
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector offsetf = (SK.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1);
|
2008-05-27 02:22:20 +00:00
|
|
|
|
2009-01-02 04:06:47 +00:00
|
|
|
AnimateOnto(quatf, offsetf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::AnimateOnto(Quaternion quatf, Vector offsetf) {
|
2008-04-25 08:26:15 +00:00
|
|
|
// Get our initial orientation and translation.
|
2008-06-01 08:45:11 +00:00
|
|
|
Quaternion quat0 = Quaternion::From(projRight, projUp);
|
2008-05-05 11:17:00 +00:00
|
|
|
Vector offset0 = offset;
|
2008-04-25 08:26:15 +00:00
|
|
|
|
|
|
|
// Make sure we take the shorter of the two possible paths.
|
|
|
|
double mp = (quatf.Minus(quat0)).Magnitude();
|
|
|
|
double mm = (quatf.Plus(quat0)).Magnitude();
|
|
|
|
if(mp > mm) {
|
|
|
|
quatf = quatf.ScaledBy(-1);
|
|
|
|
mp = mm;
|
|
|
|
}
|
2008-05-11 10:40:37 +00:00
|
|
|
double mo = (offset0.Minus(offsetf)).Magnitude()*scale;
|
2008-04-25 08:26:15 +00:00
|
|
|
|
|
|
|
// Animate transition, unless it's a tiny move.
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
int32_t dt = (mp < 0.01 && mo < 10) ? (-20) :
|
|
|
|
(int32_t)(100 + 1000*mp + 0.4*mo);
|
2009-09-29 11:35:19 +00:00
|
|
|
// Don't ever animate for longer than 2000 ms; we can get absurdly
|
|
|
|
// long translations (as measured in pixels) if the user zooms out, moves,
|
|
|
|
// and then zooms in again.
|
|
|
|
if(dt > 2000) dt = 2000;
|
2013-10-28 04:28:39 +00:00
|
|
|
int64_t tn, t0 = GetMilliseconds();
|
2008-04-25 08:26:15 +00:00
|
|
|
double s = 0;
|
2008-05-14 14:23:58 +00:00
|
|
|
Quaternion dq = quatf.Times(quat0.Inverse());
|
2008-04-25 08:26:15 +00:00
|
|
|
do {
|
|
|
|
offset = (offset0.ScaledBy(1 - s)).Plus(offsetf.ScaledBy(s));
|
2008-05-14 14:23:58 +00:00
|
|
|
Quaternion quat = (dq.ToThe(s)).Times(quat0);
|
2008-04-25 08:26:15 +00:00
|
|
|
quat = quat.WithMagnitude(1);
|
|
|
|
|
|
|
|
projRight = quat.RotationU();
|
|
|
|
projUp = quat.RotationV();
|
2018-07-12 19:29:44 +00:00
|
|
|
window->Redraw();
|
2008-04-25 08:26:15 +00:00
|
|
|
|
|
|
|
tn = GetMilliseconds();
|
|
|
|
s = (tn - t0)/((double)dt);
|
|
|
|
} while((tn - t0) < dt);
|
|
|
|
|
|
|
|
projRight = quatf.RotationU();
|
|
|
|
projUp = quatf.RotationV();
|
|
|
|
offset = offsetf;
|
2018-07-12 19:29:44 +00:00
|
|
|
Invalidate();
|
2010-02-28 18:55:49 +00:00
|
|
|
// If the view screen is open, then we need to refresh it.
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-25 08:26:15 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 10:38:38 +00:00
|
|
|
void GraphicsWindow::HandlePointForZoomToFit(Vector p, Point2d *pmax, Point2d *pmin,
|
2018-07-12 19:29:44 +00:00
|
|
|
double *wmin, bool usePerspective,
|
|
|
|
const Camera &camera)
|
2008-06-11 04:22:52 +00:00
|
|
|
{
|
2008-06-17 19:12:25 +00:00
|
|
|
double w;
|
2018-07-12 19:29:44 +00:00
|
|
|
Vector pp = camera.ProjectPoint4(p, &w);
|
2016-01-30 10:38:38 +00:00
|
|
|
// If usePerspective is true, then we calculate a perspective projection of the point.
|
2009-05-29 05:40:17 +00:00
|
|
|
// If not, then we do a parallel projection regardless of the current
|
|
|
|
// scale factor.
|
2016-01-30 10:38:38 +00:00
|
|
|
if(usePerspective) {
|
2008-06-17 19:12:25 +00:00
|
|
|
pp = pp.ScaledBy(1.0/w);
|
|
|
|
}
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
pmax->x = max(pmax->x, pp.x);
|
|
|
|
pmax->y = max(pmax->y, pp.y);
|
|
|
|
pmin->x = min(pmin->x, pp.x);
|
|
|
|
pmin->y = min(pmin->y, pp.y);
|
|
|
|
*wmin = min(*wmin, w);
|
|
|
|
}
|
2016-01-30 10:38:38 +00:00
|
|
|
void GraphicsWindow::LoopOverPoints(const std::vector<Entity *> &entities,
|
2016-08-01 14:00:00 +00:00
|
|
|
const std::vector<Constraint *> &constraints,
|
2016-03-25 07:32:11 +00:00
|
|
|
const std::vector<hEntity> &faces,
|
2016-01-30 10:38:38 +00:00
|
|
|
Point2d *pmax, Point2d *pmin, double *wmin,
|
2018-07-12 19:29:44 +00:00
|
|
|
bool usePerspective, bool includeMesh,
|
|
|
|
const Camera &camera) {
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2016-01-30 10:38:38 +00:00
|
|
|
for(Entity *e : entities) {
|
2009-04-14 04:19:23 +00:00
|
|
|
if(e->IsPoint()) {
|
2018-07-12 19:29:44 +00:00
|
|
|
HandlePointForZoomToFit(e->PointGetNum(), pmax, pmin, wmin, usePerspective, camera);
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
} else if(e->type == Entity::Type::CIRCLE) {
|
2009-04-14 04:19:23 +00:00
|
|
|
// Lots of entities can extend outside the bbox of their points,
|
|
|
|
// but circles are particularly bad. We want to get things halfway
|
|
|
|
// reasonable without the mesh, because a zoom to fit is used to
|
|
|
|
// set the zoom level to set the chord tol.
|
|
|
|
double r = e->CircleGetRadiusNum();
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector c = SK.GetEntity(e->point[0])->PointGetNum();
|
|
|
|
Quaternion q = SK.GetEntity(e->normal)->NormalGetNum();
|
2016-08-01 14:00:00 +00:00
|
|
|
for(int j = 0; j < 4; j++) {
|
2009-04-14 04:19:23 +00:00
|
|
|
Vector p = (j == 0) ? (c.Plus(q.RotationU().ScaledBy( r))) :
|
|
|
|
(j == 1) ? (c.Plus(q.RotationU().ScaledBy(-r))) :
|
|
|
|
(j == 2) ? (c.Plus(q.RotationV().ScaledBy( r))) :
|
|
|
|
(c.Plus(q.RotationV().ScaledBy(-r)));
|
2018-07-12 19:29:44 +00:00
|
|
|
HandlePointForZoomToFit(p, pmax, pmin, wmin, usePerspective, camera);
|
2016-01-30 10:38:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-12 05:05:43 +00:00
|
|
|
// We have to iterate children points, because we can select entities without points
|
2016-01-30 10:38:38 +00:00
|
|
|
for(int i = 0; i < MAX_POINTS_IN_ENTITY; i++) {
|
|
|
|
if(e->point[i].v == 0) break;
|
|
|
|
Vector p = SK.GetEntity(e->point[i])->PointGetNum();
|
2018-07-12 19:29:44 +00:00
|
|
|
HandlePointForZoomToFit(p, pmax, pmin, wmin, usePerspective, camera);
|
2009-04-14 04:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
2009-05-21 09:06:26 +00:00
|
|
|
|
2016-08-01 14:00:00 +00:00
|
|
|
for(Constraint *c : constraints) {
|
|
|
|
std::vector<Vector> refs;
|
2018-07-12 19:29:44 +00:00
|
|
|
c->GetReferencePoints(camera, &refs);
|
2016-08-01 14:00:00 +00:00
|
|
|
for(Vector p : refs) {
|
2018-07-12 19:29:44 +00:00
|
|
|
HandlePointForZoomToFit(p, pmax, pmin, wmin, usePerspective, camera);
|
2016-08-01 14:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 07:32:11 +00:00
|
|
|
if(!includeMesh && faces.empty()) return;
|
2016-01-30 10:38:38 +00:00
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.GetGroup(activeGroup);
|
2009-05-21 09:06:26 +00:00
|
|
|
g->GenerateDisplayItems();
|
2016-08-01 14:00:00 +00:00
|
|
|
for(int i = 0; i < g->displayMesh.l.n; i++) {
|
2009-05-21 09:06:26 +00:00
|
|
|
STriangle *tr = &(g->displayMesh.l.elem[i]);
|
2016-03-25 07:32:11 +00:00
|
|
|
if(!includeMesh) {
|
|
|
|
bool found = false;
|
|
|
|
for(const hEntity &face : faces) {
|
|
|
|
if(face.v != tr->meta.face) continue;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!found) continue;
|
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
HandlePointForZoomToFit(tr->a, pmax, pmin, wmin, usePerspective, camera);
|
|
|
|
HandlePointForZoomToFit(tr->b, pmax, pmin, wmin, usePerspective, camera);
|
|
|
|
HandlePointForZoomToFit(tr->c, pmax, pmin, wmin, usePerspective, camera);
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
2016-03-25 07:32:11 +00:00
|
|
|
if(!includeMesh) return;
|
2016-08-01 14:00:00 +00:00
|
|
|
for(int i = 0; i < g->polyLoops.l.n; i++) {
|
2009-10-29 07:16:28 +00:00
|
|
|
SContour *sc = &(g->polyLoops.l.elem[i]);
|
2016-08-01 14:00:00 +00:00
|
|
|
for(int j = 0; j < sc->l.n; j++) {
|
2018-07-12 19:29:44 +00:00
|
|
|
HandlePointForZoomToFit(sc->l.elem[j].p, pmax, pmin, wmin, usePerspective, camera);
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-17 19:12:25 +00:00
|
|
|
}
|
2016-01-30 10:38:38 +00:00
|
|
|
void GraphicsWindow::ZoomToFit(bool includingInvisibles, bool useSelection) {
|
2018-07-12 19:29:44 +00:00
|
|
|
if(!window) return;
|
|
|
|
|
|
|
|
scale = ZoomToFit(GetCamera(), includingInvisibles, useSelection);
|
|
|
|
}
|
|
|
|
double GraphicsWindow::ZoomToFit(const Camera &camera,
|
|
|
|
bool includingInvisibles, bool useSelection) {
|
2016-01-30 10:38:38 +00:00
|
|
|
std::vector<Entity *> entities;
|
2016-08-01 14:00:00 +00:00
|
|
|
std::vector<Constraint *> constraints;
|
2016-03-25 07:32:11 +00:00
|
|
|
std::vector<hEntity> faces;
|
|
|
|
|
|
|
|
if(useSelection) {
|
2016-01-30 10:38:38 +00:00
|
|
|
for(int i = 0; i < selection.n; i++) {
|
|
|
|
Selection *s = &selection.elem[i];
|
2016-08-01 14:00:00 +00:00
|
|
|
if(s->entity.v != 0) {
|
|
|
|
Entity *e = SK.entity.FindById(s->entity);
|
|
|
|
if(e->IsFace()) {
|
|
|
|
faces.push_back(e->h);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entities.push_back(e);
|
|
|
|
}
|
|
|
|
if(s->constraint.v != 0) {
|
|
|
|
Constraint *c = SK.constraint.FindById(s->constraint);
|
|
|
|
constraints.push_back(c);
|
2016-03-25 07:32:11 +00:00
|
|
|
}
|
2016-01-30 10:38:38 +00:00
|
|
|
}
|
2016-03-25 07:32:11 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 14:00:00 +00:00
|
|
|
bool selectionUsed = !entities.empty() || !constraints.empty() || !faces.empty();
|
2016-03-25 07:32:11 +00:00
|
|
|
|
|
|
|
if(!selectionUsed) {
|
2016-08-01 14:00:00 +00:00
|
|
|
for(Entity &e : SK.entity) {
|
2016-01-30 10:38:38 +00:00
|
|
|
// we don't want to handle separate points, because we will iterate them inside entities.
|
2016-08-01 14:00:00 +00:00
|
|
|
if(e.IsPoint()) continue;
|
|
|
|
if(!includingInvisibles && !e.IsVisible()) continue;
|
|
|
|
entities.push_back(&e);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Constraint &c : SK.constraint) {
|
|
|
|
if(!c.IsVisible()) continue;
|
|
|
|
constraints.push_back(&c);
|
2016-01-30 10:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
// On the first run, ignore perspective.
|
|
|
|
Point2d pmax = { -1e12, -1e12 }, pmin = { 1e12, 1e12 };
|
|
|
|
double wmin = 1;
|
2016-08-01 14:00:00 +00:00
|
|
|
LoopOverPoints(entities, constraints, faces, &pmax, &pmin, &wmin,
|
2018-07-12 19:29:44 +00:00
|
|
|
/*usePerspective=*/false, /*includeMesh=*/!selectionUsed,
|
|
|
|
camera);
|
2008-06-11 04:22:52 +00:00
|
|
|
|
|
|
|
double xm = (pmax.x + pmin.x)/2, ym = (pmax.y + pmin.y)/2;
|
|
|
|
double dx = pmax.x - pmin.x, dy = pmax.y - pmin.y;
|
|
|
|
|
|
|
|
offset = offset.Plus(projRight.ScaledBy(-xm)).Plus(
|
|
|
|
projUp. ScaledBy(-ym));
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
// And based on this, we calculate the scale and offset
|
2018-07-12 19:29:44 +00:00
|
|
|
double scale;
|
2013-10-21 21:29:25 +00:00
|
|
|
if(EXACT(dx == 0 && dy == 0)) {
|
2008-06-11 04:22:52 +00:00
|
|
|
scale = 5;
|
|
|
|
} else {
|
|
|
|
double scalex = 1e12, scaley = 1e12;
|
2018-07-12 19:29:44 +00:00
|
|
|
if(EXACT(dx != 0)) scalex = 0.9*camera.width /dx;
|
|
|
|
if(EXACT(dy != 0)) scaley = 0.9*camera.height/dy;
|
2008-06-17 19:12:25 +00:00
|
|
|
scale = min(scalex, scaley);
|
|
|
|
|
2015-03-27 15:43:28 +00:00
|
|
|
scale = min(300.0, scale);
|
2009-03-15 23:04:45 +00:00
|
|
|
scale = max(0.003, scale);
|
2008-06-17 19:12:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then do another run, considering the perspective.
|
|
|
|
pmax.x = -1e12; pmax.y = -1e12;
|
|
|
|
pmin.x = 1e12; pmin.y = 1e12;
|
|
|
|
wmin = 1;
|
2016-08-01 14:00:00 +00:00
|
|
|
LoopOverPoints(entities, constraints, faces, &pmax, &pmin, &wmin,
|
2018-07-12 19:29:44 +00:00
|
|
|
/*usePerspective=*/true, /*includeMesh=*/!selectionUsed,
|
|
|
|
camera);
|
2008-06-17 19:12:25 +00:00
|
|
|
|
|
|
|
// Adjust the scale so that no points are behind the camera
|
|
|
|
if(wmin < 0.1) {
|
2018-07-12 19:29:44 +00:00
|
|
|
double k = camera.tangent;
|
2008-06-17 19:12:25 +00:00
|
|
|
// w = 1+k*scale*z
|
|
|
|
double zmin = (wmin - 1)/(k*scale);
|
|
|
|
// 0.1 = 1 + k*scale*zmin
|
|
|
|
// (0.1 - 1)/(k*zmin) = scale
|
|
|
|
scale = min(scale, (0.1 - 1)/(k*zmin));
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
|
|
|
|
return scale;
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void GraphicsWindow::MenuView(Command id) {
|
2008-04-12 15:17:58 +00:00
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::ZOOM_IN:
|
2008-04-12 15:17:58 +00:00
|
|
|
SS.GW.scale *= 1.2;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::ZOOM_OUT:
|
2008-04-12 15:17:58 +00:00
|
|
|
SS.GW.scale /= 1.2;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::ZOOM_TO_FIT:
|
2016-01-30 10:38:38 +00:00
|
|
|
SS.GW.ZoomToFit(/*includingInvisibles=*/false, /*useSelection=*/true);
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SHOW_GRID:
|
2009-09-29 11:35:19 +00:00
|
|
|
SS.GW.showSnapGrid = !SS.GW.showSnapGrid;
|
|
|
|
if(SS.GW.showSnapGrid && !SS.GW.LockedInWorkplane()) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Message(_("No workplane is active, so the grid will not appear."));
|
2009-09-29 11:35:19 +00:00
|
|
|
}
|
|
|
|
SS.GW.EnsureValidActives();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2009-09-29 11:35:19 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::PERSPECTIVE_PROJ:
|
2010-05-03 05:15:28 +00:00
|
|
|
SS.usePerspectiveProj = !SS.usePerspectiveProj;
|
2009-09-29 11:35:19 +00:00
|
|
|
if(SS.cameraTangent < 1e-6) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("The perspective factor is set to zero, so the view will "
|
|
|
|
"always be a parallel projection.\n\n"
|
|
|
|
"For a perspective projection, modify the perspective "
|
|
|
|
"factor in the configuration screen. A value around 0.3 "
|
|
|
|
"is typical."));
|
2009-09-29 11:35:19 +00:00
|
|
|
}
|
|
|
|
SS.GW.EnsureValidActives();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2009-09-29 11:35:19 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::ONTO_WORKPLANE:
|
2015-03-22 13:23:40 +00:00
|
|
|
if(SS.GW.LockedInWorkplane()) {
|
|
|
|
SS.GW.AnimateOntoWorkplane();
|
|
|
|
SS.ScheduleShowTW();
|
2010-05-03 05:04:42 +00:00
|
|
|
break;
|
2015-03-22 13:23:40 +00:00
|
|
|
} // if not in 2d mode fall through and use ORTHO logic
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::NEAREST_ORTHO:
|
|
|
|
case Command::NEAREST_ISO: {
|
2009-01-02 04:06:47 +00:00
|
|
|
static const Vector ortho[3] = {
|
|
|
|
Vector::From(1, 0, 0),
|
|
|
|
Vector::From(0, 1, 0),
|
|
|
|
Vector::From(0, 0, 1)
|
|
|
|
};
|
|
|
|
double sqrt2 = sqrt(2.0), sqrt6 = sqrt(6.0);
|
|
|
|
Quaternion quat0 = Quaternion::From(SS.GW.projRight, SS.GW.projUp);
|
|
|
|
Quaternion quatf = quat0;
|
|
|
|
double dmin = 1e10;
|
|
|
|
|
|
|
|
// There are 24 possible views; 3*2*2*2
|
|
|
|
int i, j, negi, negj;
|
|
|
|
for(i = 0; i < 3; i++) {
|
|
|
|
for(j = 0; j < 3; j++) {
|
|
|
|
if(i == j) continue;
|
|
|
|
for(negi = 0; negi < 2; negi++) {
|
|
|
|
for(negj = 0; negj < 2; negj++) {
|
|
|
|
Vector ou = ortho[i], ov = ortho[j];
|
|
|
|
if(negi) ou = ou.ScaledBy(-1);
|
|
|
|
if(negj) ov = ov.ScaledBy(-1);
|
|
|
|
Vector on = ou.Cross(ov);
|
|
|
|
|
|
|
|
Vector u, v;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(id == Command::NEAREST_ORTHO || id == Command::ONTO_WORKPLANE) {
|
2009-01-02 04:06:47 +00:00
|
|
|
u = ou;
|
|
|
|
v = ov;
|
|
|
|
} else {
|
|
|
|
u =
|
|
|
|
ou.ScaledBy(1/sqrt2).Plus(
|
|
|
|
on.ScaledBy(-1/sqrt2));
|
|
|
|
v =
|
|
|
|
ou.ScaledBy(-1/sqrt6).Plus(
|
|
|
|
ov.ScaledBy(2/sqrt6).Plus(
|
|
|
|
on.ScaledBy(-1/sqrt6)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Quaternion quatt = Quaternion::From(u, v);
|
|
|
|
double d = min(
|
|
|
|
(quatt.Minus(quat0)).Magnitude(),
|
|
|
|
(quatt.Plus(quat0)).Magnitude());
|
|
|
|
if(d < dmin) {
|
|
|
|
dmin = d;
|
|
|
|
quatf = quatt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SS.GW.AnimateOnto(quatf, SS.GW.offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::CENTER_VIEW:
|
2009-01-13 06:56:05 +00:00
|
|
|
SS.GW.GroupSelection();
|
|
|
|
if(SS.GW.gs.n == 1 && SS.GW.gs.points == 1) {
|
|
|
|
Quaternion quat0;
|
|
|
|
// Offset is the selected point, quaternion is same as before
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector pt = SK.GetEntity(SS.GW.gs.point[0])->PointGetNum();
|
2009-01-13 06:56:05 +00:00
|
|
|
quat0 = Quaternion::From(SS.GW.projRight, SS.GW.projUp);
|
|
|
|
SS.GW.AnimateOnto(quat0, pt.ScaledBy(-1));
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
} else {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Select a point; this point will become the center "
|
|
|
|
"of the view on screen."));
|
2009-01-13 06:56:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SHOW_TOOLBAR:
|
2009-01-02 10:38:36 +00:00
|
|
|
SS.showToolbar = !SS.showToolbar;
|
|
|
|
SS.GW.EnsureValidActives();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2009-01-02 10:38:36 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SHOW_TEXT_WND:
|
2013-10-25 05:04:16 +00:00
|
|
|
SS.GW.showTextWindow = !SS.GW.showTextWindow;
|
2008-04-22 13:14:15 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::UNITS_INCHES:
|
|
|
|
SS.viewUnits = Unit::INCHES;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-22 13:14:15 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::UNITS_MM:
|
|
|
|
SS.viewUnits = Unit::MM;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2013-10-25 05:04:16 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
2017-03-30 02:24:06 +00:00
|
|
|
case Command::UNITS_METERS:
|
|
|
|
SS.viewUnits = Unit::METERS;
|
|
|
|
SS.ScheduleShowTW();
|
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::FULL_SCREEN:
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.window->SetFullScreen(!SS.GW.window->IsFullScreen());
|
2013-10-25 05:04:16 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2008-04-12 15:17:58 +00:00
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2008-04-12 15:17:58 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::EnsureValidActives() {
|
2008-04-18 07:06:37 +00:00
|
|
|
bool change = false;
|
|
|
|
// The active group must exist, and not be the references.
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.group.FindByIdNoOops(activeGroup);
|
2008-04-18 07:06:37 +00:00
|
|
|
if((!g) || (g->h.v == Group::HGROUP_REFERENCES.v)) {
|
|
|
|
int i;
|
2016-02-17 10:03:07 +00:00
|
|
|
for(i = 0; i < SK.groupOrder.n; i++) {
|
|
|
|
if(SK.groupOrder.elem[i].v != Group::HGROUP_REFERENCES.v) {
|
2008-04-18 07:06:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 10:03:07 +00:00
|
|
|
if(i >= SK.groupOrder.n) {
|
2008-06-02 11:43:27 +00:00
|
|
|
// This can happen if the user deletes all the groups in the
|
|
|
|
// sketch. It's difficult to prevent that, because the last
|
|
|
|
// group might have been deleted automatically, because it failed
|
|
|
|
// a dependency. There needs to be something, so create a plane
|
|
|
|
// drawing group and activate that. They should never be able
|
|
|
|
// to delete the references, though.
|
|
|
|
activeGroup = SS.CreateDefaultDrawingGroup();
|
2016-02-18 11:11:59 +00:00
|
|
|
// We've created the default group, but not the workplane entity;
|
|
|
|
// do it now so that drawing mode isn't switched to "Free in 3d".
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::ALL);
|
2008-06-02 11:43:27 +00:00
|
|
|
} else {
|
2016-02-17 10:03:07 +00:00
|
|
|
activeGroup = SK.groupOrder.elem[i];
|
2008-06-02 11:43:27 +00:00
|
|
|
}
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetGroup(activeGroup)->Activate();
|
2008-04-18 07:06:37 +00:00
|
|
|
change = true;
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
// The active coordinate system must also exist.
|
2008-05-27 02:22:20 +00:00
|
|
|
if(LockedInWorkplane()) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.entity.FindByIdNoOops(ActiveWorkplane());
|
2008-05-17 23:48:58 +00:00
|
|
|
if(e) {
|
|
|
|
hGroup hgw = e->group;
|
|
|
|
if(hgw.v != activeGroup.v && SS.GroupsInOrder(activeGroup, hgw)) {
|
|
|
|
// The active workplane is in a group that comes after the
|
|
|
|
// active group; so any request or constraint will fail.
|
2008-05-27 02:22:20 +00:00
|
|
|
SetWorkplaneFreeIn3d();
|
2008-05-17 23:48:58 +00:00
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
} else {
|
2008-05-27 02:22:20 +00:00
|
|
|
SetWorkplaneFreeIn3d();
|
2008-05-17 23:48:58 +00:00
|
|
|
change = true;
|
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
2008-04-18 11:11:48 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
if(!window) return;
|
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
// And update the checked state for various menus
|
2008-05-27 02:22:20 +00:00
|
|
|
bool locked = LockedInWorkplane();
|
2018-07-11 10:48:38 +00:00
|
|
|
in3dMenuItem->SetActive(!locked);
|
|
|
|
inWorkplaneMenuItem->SetActive(locked);
|
2008-04-22 13:14:15 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
SS.UndoEnableMenus();
|
|
|
|
|
2008-06-14 09:51:25 +00:00
|
|
|
switch(SS.viewUnits) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Unit::MM:
|
2017-03-30 02:24:06 +00:00
|
|
|
case Unit::METERS:
|
2018-07-11 10:48:38 +00:00
|
|
|
case Unit::INCHES:
|
2008-04-22 13:14:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.viewUnits = Unit::MM;
|
2010-01-04 00:35:28 +00:00
|
|
|
break;
|
2008-04-22 13:14:15 +00:00
|
|
|
}
|
2018-07-11 10:48:38 +00:00
|
|
|
unitsMmMenuItem->SetActive(SS.viewUnits == Unit::MM);
|
|
|
|
unitsMetersMenuItem->SetActive(SS.viewUnits == Unit::METERS);
|
|
|
|
unitsInchesMenuItem->SetActive(SS.viewUnits == Unit::INCHES);
|
2008-04-27 05:00:12 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
if(SS.TW.window) SS.TW.window->SetVisible(SS.GW.showTextWindow);
|
2018-07-11 10:48:38 +00:00
|
|
|
showTextWndMenuItem->SetActive(SS.GW.showTextWindow);
|
2008-04-27 05:00:12 +00:00
|
|
|
|
2018-07-11 10:48:38 +00:00
|
|
|
showGridMenuItem->SetActive(SS.GW.showSnapGrid);
|
|
|
|
perspectiveProjMenuItem->SetActive(SS.usePerspectiveProj);
|
|
|
|
showToolbarMenuItem->SetActive(SS.showToolbar);
|
2018-07-12 19:29:44 +00:00
|
|
|
fullScreenMenuItem->SetActive(SS.GW.window->IsFullScreen());
|
2009-01-02 10:38:36 +00:00
|
|
|
|
2015-03-18 17:02:11 +00:00
|
|
|
if(change) SS.ScheduleShowTW();
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::SetWorkplaneFreeIn3d() {
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetGroup(activeGroup)->activeWorkplane = Entity::FREE_IN_3D;
|
2008-05-27 02:22:20 +00:00
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
hEntity GraphicsWindow::ActiveWorkplane() {
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.group.FindByIdNoOops(activeGroup);
|
2008-06-01 00:26:41 +00:00
|
|
|
if(g) {
|
|
|
|
return g->activeWorkplane;
|
|
|
|
} else {
|
|
|
|
return Entity::FREE_IN_3D;
|
|
|
|
}
|
2008-05-27 02:22:20 +00:00
|
|
|
}
|
2016-05-05 05:54:05 +00:00
|
|
|
bool GraphicsWindow::LockedInWorkplane() {
|
2008-05-27 02:22:20 +00:00
|
|
|
return (SS.GW.ActiveWorkplane().v != Entity::FREE_IN_3D.v);
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::ForceTextWindowShown() {
|
2008-09-17 10:13:37 +00:00
|
|
|
if(!showTextWindow) {
|
|
|
|
showTextWindow = true;
|
2018-07-11 10:48:38 +00:00
|
|
|
showTextWndMenuItem->SetActive(true);
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.TW.window->SetVisible(true);
|
2008-09-17 10:13:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::DeleteTaggedRequests() {
|
2009-07-08 09:36:18 +00:00
|
|
|
// Rewrite any point-coincident constraints that were affected by this
|
|
|
|
// deletion.
|
|
|
|
Request *r;
|
|
|
|
for(r = SK.request.First(); r; r = SK.request.NextAfter(r)) {
|
|
|
|
if(!r->tag) continue;
|
|
|
|
FixConstraintsForRequestBeingDeleted(r->h);
|
|
|
|
}
|
|
|
|
// and then delete the tagged requests.
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.request.RemoveTagged();
|
2009-01-03 12:27:33 +00:00
|
|
|
|
|
|
|
// An edit might be in progress for the just-deleted item. So
|
|
|
|
// now it's not.
|
2018-07-12 19:29:44 +00:00
|
|
|
window->HideEditor();
|
2010-07-12 07:51:12 +00:00
|
|
|
SS.TW.HideEditControl();
|
2009-01-03 12:27:33 +00:00
|
|
|
// And clear out the selection, which could contain that item.
|
|
|
|
ClearSuper();
|
|
|
|
// And regenerate to get rid of what it generates, plus anything
|
|
|
|
// that references it (since the regen code checks for that).
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::ALL);
|
2009-01-03 12:27:33 +00:00
|
|
|
EnsureValidActives();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-01-03 12:27:33 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
Vector GraphicsWindow::SnapToGrid(Vector p) {
|
|
|
|
if(!LockedInWorkplane()) return p;
|
|
|
|
|
|
|
|
EntityBase *wrkpl = SK.GetEntity(ActiveWorkplane()),
|
|
|
|
*norm = wrkpl->Normal();
|
|
|
|
Vector wo = SK.GetEntity(wrkpl->point[0])->PointGetNum(),
|
|
|
|
wu = norm->NormalU(),
|
|
|
|
wv = norm->NormalV(),
|
|
|
|
wn = norm->NormalN();
|
|
|
|
|
|
|
|
Vector pp = (p.Minus(wo)).DotInToCsys(wu, wv, wn);
|
|
|
|
pp.x = floor((pp.x / SS.gridSpacing) + 0.5)*SS.gridSpacing;
|
|
|
|
pp.y = floor((pp.y / SS.gridSpacing) + 0.5)*SS.gridSpacing;
|
|
|
|
pp.z = 0;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
return pp.ScaleOutOfCsys(wu, wv, wn).Plus(wo);
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void GraphicsWindow::MenuEdit(Command id) {
|
2008-04-12 15:17:58 +00:00
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::UNSELECT_ALL:
|
2008-06-01 04:31:28 +00:00
|
|
|
SS.GW.GroupSelection();
|
2009-09-18 08:14:15 +00:00
|
|
|
// If there's nothing selected to de-select, and no operation
|
|
|
|
// to cancel, then perhaps they want to return to the home
|
|
|
|
// screen in the text window.
|
2009-09-29 11:35:19 +00:00
|
|
|
if(SS.GW.gs.n == 0 &&
|
|
|
|
SS.GW.gs.constraints == 0 &&
|
2016-05-23 10:15:38 +00:00
|
|
|
SS.GW.pending.operation == Pending::NONE)
|
2009-09-29 11:35:19 +00:00
|
|
|
{
|
2018-07-12 19:29:44 +00:00
|
|
|
if(!(SS.TW.window->IsEditorVisible() ||
|
|
|
|
SS.GW.window->IsEditorVisible()))
|
2009-09-24 15:52:48 +00:00
|
|
|
{
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(SS.TW.shown.screen == TextWindow::Screen::STYLE_INFO) {
|
|
|
|
SS.TW.GoToScreen(TextWindow::Screen::LIST_OF_STYLES);
|
2009-09-18 08:14:15 +00:00
|
|
|
} else {
|
|
|
|
SS.TW.ClearSuper();
|
|
|
|
}
|
2008-06-02 11:43:27 +00:00
|
|
|
}
|
2008-06-01 04:31:28 +00:00
|
|
|
}
|
2008-06-01 00:26:41 +00:00
|
|
|
SS.GW.ClearSuper();
|
2010-07-12 07:51:12 +00:00
|
|
|
SS.TW.HideEditControl();
|
2009-01-25 09:19:59 +00:00
|
|
|
SS.nakedEdges.Clear();
|
2010-01-14 05:24:32 +00:00
|
|
|
SS.justExportedInfo.draw = false;
|
2017-01-17 16:57:27 +00:00
|
|
|
SS.centerOfMass.draw = false;
|
2010-03-01 17:23:57 +00:00
|
|
|
// This clears the marks drawn to indicate which points are
|
|
|
|
// still free to drag.
|
|
|
|
Param *p;
|
|
|
|
for(p = SK.param.First(); p; p = SK.param.NextAfter(p)) {
|
|
|
|
p->free = false;
|
|
|
|
}
|
2016-01-27 04:07:54 +00:00
|
|
|
if(SS.exportMode) {
|
|
|
|
SS.exportMode = false;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::ALL);
|
2016-01-27 04:07:54 +00:00
|
|
|
}
|
2017-02-17 03:18:34 +00:00
|
|
|
SS.GW.persistentDirty = true;
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SELECT_ALL: {
|
2009-11-03 18:54:49 +00:00
|
|
|
Entity *e;
|
|
|
|
for(e = SK.entity.First(); e; e = SK.entity.NextAfter(e)) {
|
|
|
|
if(e->group.v != SS.GW.activeGroup.v) continue;
|
|
|
|
if(e->IsFace() || e->IsDistance()) continue;
|
2009-11-04 07:59:23 +00:00
|
|
|
if(!e->IsVisible()) continue;
|
2009-11-03 18:54:49 +00:00
|
|
|
|
2010-01-03 10:26:15 +00:00
|
|
|
SS.GW.MakeSelected(e->h);
|
2009-11-03 18:54:49 +00:00
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-11-03 18:54:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SELECT_CHAIN: {
|
2009-11-03 18:54:49 +00:00
|
|
|
Entity *e;
|
|
|
|
int newlySelected = 0;
|
|
|
|
bool didSomething;
|
|
|
|
do {
|
|
|
|
didSomething = false;
|
|
|
|
for(e = SK.entity.First(); e; e = SK.entity.NextAfter(e)) {
|
|
|
|
if(e->group.v != SS.GW.activeGroup.v) continue;
|
|
|
|
if(!e->HasEndpoints()) continue;
|
2009-11-04 07:59:23 +00:00
|
|
|
if(!e->IsVisible()) continue;
|
2009-11-03 18:54:49 +00:00
|
|
|
|
|
|
|
Vector st = e->EndpointStart(),
|
|
|
|
fi = e->EndpointFinish();
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-11-03 18:54:49 +00:00
|
|
|
bool onChain = false, alreadySelected = false;
|
|
|
|
List<Selection> *ls = &(SS.GW.selection);
|
|
|
|
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
|
|
|
|
if(!s->entity.v) continue;
|
|
|
|
if(s->entity.v == e->h.v) {
|
|
|
|
alreadySelected = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Entity *se = SK.GetEntity(s->entity);
|
|
|
|
if(!se->HasEndpoints()) continue;
|
|
|
|
|
|
|
|
Vector sst = se->EndpointStart(),
|
|
|
|
sfi = se->EndpointFinish();
|
|
|
|
|
|
|
|
if(sst.Equals(st) || sst.Equals(fi) ||
|
|
|
|
sfi.Equals(st) || sfi.Equals(fi))
|
|
|
|
{
|
|
|
|
onChain = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(onChain && !alreadySelected) {
|
2010-01-03 10:26:15 +00:00
|
|
|
SS.GW.MakeSelected(e->h);
|
2009-11-03 18:54:49 +00:00
|
|
|
newlySelected++;
|
|
|
|
didSomething = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(didSomething);
|
|
|
|
if(newlySelected == 0) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("No additional entities share endpoints with the selected entities."));
|
2009-11-03 18:54:49 +00:00
|
|
|
}
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-11-03 18:54:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::ROTATE_90: {
|
2009-06-21 20:39:42 +00:00
|
|
|
SS.GW.GroupSelection();
|
|
|
|
Entity *e = NULL;
|
|
|
|
if(SS.GW.gs.n == 1 && SS.GW.gs.points == 1) {
|
|
|
|
e = SK.GetEntity(SS.GW.gs.point[0]);
|
|
|
|
} else if(SS.GW.gs.n == 1 && SS.GW.gs.entities == 1) {
|
|
|
|
e = SK.GetEntity(SS.GW.gs.entity[0]);
|
|
|
|
}
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
|
|
|
|
hGroup hg = e ? e->group : SS.GW.activeGroup;
|
|
|
|
Group *g = SK.GetGroup(hg);
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(g->type != Group::Type::LINKED) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("To use this command, select a point or other "
|
|
|
|
"entity from an linked part, or make a link "
|
|
|
|
"group the active group."));
|
2009-06-21 20:39:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SS.UndoRemember();
|
|
|
|
// Rotate by ninety degrees about the coordinate axis closest
|
|
|
|
// to the screen normal.
|
|
|
|
Vector norm = SS.GW.projRight.Cross(SS.GW.projUp);
|
|
|
|
norm = norm.ClosestOrtho();
|
|
|
|
norm = norm.WithMagnitude(1);
|
|
|
|
Quaternion qaa = Quaternion::From(norm, PI/2);
|
|
|
|
|
2009-07-20 19:05:33 +00:00
|
|
|
g->TransformImportedBy(Vector::From(0, 0, 0), qaa);
|
2009-06-21 20:39:42 +00:00
|
|
|
|
|
|
|
// and regenerate as necessary.
|
|
|
|
SS.MarkGroupDirty(hg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SNAP_TO_GRID: {
|
2009-09-29 11:35:19 +00:00
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("No workplane is active. Activate a workplane "
|
|
|
|
"(with Sketch -> In Workplane) to define the plane "
|
|
|
|
"for the snap grid."));
|
2009-09-29 11:35:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
SS.GW.GroupSelection();
|
2016-04-18 06:40:42 +00:00
|
|
|
if(SS.GW.gs.points == 0 && SS.GW.gs.constraintLabels == 0) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Can't snap these items to grid; select points, "
|
|
|
|
"text comments, or constraints with a label. "
|
|
|
|
"To snap a line, select its endpoints."));
|
2009-09-29 11:35:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
SS.UndoRemember();
|
2009-12-04 08:08:41 +00:00
|
|
|
|
|
|
|
List<Selection> *ls = &(SS.GW.selection);
|
|
|
|
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
|
|
|
|
if(s->entity.v) {
|
|
|
|
hEntity hp = s->entity;
|
|
|
|
Entity *ep = SK.GetEntity(hp);
|
|
|
|
if(!ep->IsPoint()) continue;
|
|
|
|
|
|
|
|
Vector p = ep->PointGetNum();
|
|
|
|
ep->PointForceTo(SS.GW.SnapToGrid(p));
|
|
|
|
SS.GW.pending.points.Add(&hp);
|
|
|
|
SS.MarkGroupDirty(ep->group);
|
|
|
|
} else if(s->constraint.v) {
|
|
|
|
Constraint *c = SK.GetConstraint(s->constraint);
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
std::vector<Vector> refs;
|
|
|
|
c->GetReferencePoints(SS.GW.GetCamera(), &refs);
|
|
|
|
c->disp.offset = c->disp.offset.Plus(SS.GW.SnapToGrid(refs[0]).Minus(refs[0]));
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
2009-09-29 11:35:19 +00:00
|
|
|
}
|
2009-11-03 18:54:49 +00:00
|
|
|
// Regenerate, with these points marked as dragged so that they
|
|
|
|
// get placed as close as possible to our snap grid.
|
|
|
|
SS.GW.ClearPending();
|
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
SS.GW.ClearSelection();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2009-09-29 11:35:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::UNDO:
|
2008-06-04 10:22:30 +00:00
|
|
|
SS.UndoUndo();
|
|
|
|
break;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::REDO:
|
2008-06-04 10:22:30 +00:00
|
|
|
SS.UndoRedo();
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::REGEN_ALL:
|
2016-11-29 16:49:20 +00:00
|
|
|
SS.images.clear();
|
|
|
|
SS.ReloadAllLinked(SS.saveFile);
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::UNTIL_ACTIVE);
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-06-30 09:34:03 +00:00
|
|
|
break;
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void GraphicsWindow::MenuRequest(Command id) {
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *s;
|
2008-04-13 10:57:41 +00:00
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SEL_WORKPLANE: {
|
2008-04-18 07:06:37 +00:00
|
|
|
SS.GW.GroupSelection();
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
2008-06-06 11:35:28 +00:00
|
|
|
|
2008-04-27 03:26:27 +00:00
|
|
|
if(SS.GW.gs.n == 1 && SS.GW.gs.workplanes == 1) {
|
2008-06-06 11:35:28 +00:00
|
|
|
// A user-selected workplane
|
|
|
|
g->activeWorkplane = SS.GW.gs.entity[0];
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
} else if(g->type == Group::Type::DRAWING_WORKPLANE) {
|
2008-06-06 11:35:28 +00:00
|
|
|
// The group's default workplane
|
|
|
|
g->activeWorkplane = g->h.entity(0);
|
2017-01-07 06:41:13 +00:00
|
|
|
Message(_("No workplane selected. Activating default workplane "
|
|
|
|
"for this group."));
|
2008-04-25 08:26:15 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("No workplane is selected, and the active group does "
|
|
|
|
"not have a default workplane. Try selecting a "
|
|
|
|
"workplane, or activating a sketch-in-new-workplane "
|
|
|
|
"group."));
|
2008-04-25 08:26:15 +00:00
|
|
|
break;
|
2008-04-18 07:06:37 +00:00
|
|
|
}
|
2008-04-27 03:26:27 +00:00
|
|
|
// Align the view with the selected workplane
|
2008-05-27 02:22:20 +00:00
|
|
|
SS.GW.AnimateOntoWorkplane();
|
2008-05-17 23:48:58 +00:00
|
|
|
SS.GW.ClearSuper();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-18 07:06:37 +00:00
|
|
|
break;
|
2008-04-25 08:26:15 +00:00
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::FREE_IN_3D:
|
2008-05-27 02:22:20 +00:00
|
|
|
SS.GW.SetWorkplaneFreeIn3d();
|
2008-04-18 07:06:37 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate();
|
2008-04-18 07:06:37 +00:00
|
|
|
break;
|
2008-07-14 02:45:11 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::TANGENT_ARC:
|
2008-07-14 02:45:11 +00:00
|
|
|
SS.GW.GroupSelection();
|
|
|
|
if(SS.GW.gs.n == 1 && SS.GW.gs.points == 1) {
|
2009-01-03 12:27:33 +00:00
|
|
|
SS.GW.MakeTangentArc();
|
2010-05-16 16:36:23 +00:00
|
|
|
} else if(SS.GW.gs.n != 0) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("Bad selection for tangent arc at point. Select a "
|
|
|
|
"single point, or select nothing to set up arc "
|
|
|
|
"parameters."));
|
2008-07-14 02:45:11 +00:00
|
|
|
} else {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.GoToScreen(TextWindow::Screen::TANGENT_ARC);
|
2010-05-16 16:36:23 +00:00
|
|
|
SS.GW.ForceTextWindowShown();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate(); // repaint toolbar
|
2008-07-14 02:45:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-05-16 16:36:23 +00:00
|
|
|
|
2017-01-07 06:41:13 +00:00
|
|
|
case Command::ARC: s = _("click point on arc (draws anti-clockwise)"); goto c;
|
|
|
|
case Command::DATUM_POINT: s = _("click to place datum point"); goto c;
|
|
|
|
case Command::LINE_SEGMENT: s = _("click first point of line segment"); goto c;
|
|
|
|
case Command::CONSTR_SEGMENT:
|
|
|
|
s = _("click first point of construction line segment"); goto c;
|
|
|
|
case Command::CUBIC: s = _("click first point of cubic segment"); goto c;
|
|
|
|
case Command::CIRCLE: s = _("click center of circle"); goto c;
|
|
|
|
case Command::WORKPLANE: s = _("click origin of workplane"); goto c;
|
|
|
|
case Command::RECTANGLE: s = _("click one corner of rectangle"); goto c;
|
|
|
|
case Command::TTF_TEXT: s = _("click top left of text"); goto c;
|
2016-11-29 16:49:20 +00:00
|
|
|
case Command::IMAGE:
|
|
|
|
if(!SS.ReloadLinkedImage(SS.saveFile, &SS.GW.pending.filename,
|
|
|
|
/*canCancel=*/true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s = _("click top left of image"); goto c;
|
2008-04-13 10:57:41 +00:00
|
|
|
c:
|
2016-05-23 10:15:38 +00:00
|
|
|
SS.GW.pending.operation = GraphicsWindow::Pending::COMMAND;
|
|
|
|
SS.GW.pending.command = id;
|
2008-05-05 06:18:01 +00:00
|
|
|
SS.GW.pending.description = s;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2018-07-12 19:29:44 +00:00
|
|
|
SS.GW.Invalidate(); // repaint toolbar
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::CONSTRUCTION: {
|
2009-11-04 07:59:23 +00:00
|
|
|
SS.UndoRemember();
|
2008-05-07 04:17:29 +00:00
|
|
|
SS.GW.GroupSelection();
|
2010-01-07 08:02:13 +00:00
|
|
|
if(SS.GW.gs.entities == 0) {
|
2017-01-07 06:41:13 +00:00
|
|
|
Error(_("No entities are selected. Select entities before "
|
|
|
|
"trying to toggle their construction state."));
|
2010-01-07 08:02:13 +00:00
|
|
|
}
|
2008-05-07 04:17:29 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.GW.gs.entities; i++) {
|
|
|
|
hEntity he = SS.GW.gs.entity[i];
|
|
|
|
if(!he.isFromRequest()) continue;
|
2009-04-19 05:53:16 +00:00
|
|
|
Request *r = SK.GetRequest(he.request());
|
2008-05-07 04:17:29 +00:00
|
|
|
r->construction = !(r->construction);
|
2008-06-02 11:43:27 +00:00
|
|
|
SS.MarkGroupDirty(r->group);
|
2008-05-07 04:17:29 +00:00
|
|
|
}
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::SPLIT_CURVES:
|
2009-01-03 12:27:33 +00:00
|
|
|
SS.GW.SplitLinesOrCurves();
|
|
|
|
break;
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2008-04-12 15:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::ClearSuper() {
|
2018-07-12 19:29:44 +00:00
|
|
|
if(window) window->HideEditor();
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearPending();
|
|
|
|
ClearSelection();
|
|
|
|
hover.Clear();
|
|
|
|
EnsureValidActives();
|
|
|
|
}
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
void GraphicsWindow::ToggleBool(bool *v) {
|
|
|
|
*v = !*v;
|
2008-04-11 12:47:14 +00:00
|
|
|
|
2008-06-02 05:38:12 +00:00
|
|
|
// The faces are shown as special stippling on the shaded triangle mesh,
|
|
|
|
// so not meaningful to show them and hide the shaded.
|
2010-05-03 05:04:42 +00:00
|
|
|
if(!showShaded) showFaces = false;
|
2008-06-02 05:38:12 +00:00
|
|
|
|
2016-11-18 15:26:01 +00:00
|
|
|
// If the mesh or edges were previously hidden, they haven't been generated,
|
|
|
|
// and if we are going to show them, we need to generate them first.
|
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
if(*v && (g->displayOutlines.l.n == 0 && (v == &showEdges || v == &showOutlines))) {
|
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::UNTIL_ACTIVE);
|
2016-08-14 00:55:27 +00:00
|
|
|
}
|
2009-05-29 05:40:17 +00:00
|
|
|
|
2018-07-12 19:29:44 +00:00
|
|
|
Invalidate(/*clearPersistent=*/true);
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-11 12:47:14 +00:00
|
|
|
}
|
|
|
|
|
Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.
Moreover, we also change the switch statements in three ways:
* Switch statements that ought to be extended every time a new
enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
to explicitly list every single enumerand, and not have a
default: branch.
Note that the assertions are kept because it is legal for
a enumeration to have a value unlike any of its defined
enumerands, and we can e.g. read garbage from a file, or
an uninitialized variable. This requires some rearranging if
a default: branch is undesired.
* Switch statements that ought to only ever see a few select
enumerands, are changed to always assert in the default: branch.
* Switch statements that do something meaningful for a few
enumerands, and ignore everything else, are changed to do nothing
in a default: branch, under the assumption that changing them
every time an enumerand is added or removed would just result
in noise and catch no bugs.
This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-25 06:55:50 +00:00
|
|
|
bool GraphicsWindow::SuggestLineConstraint(hRequest request, Constraint::Type *type) {
|
2015-03-29 22:26:07 +00:00
|
|
|
if(LockedInWorkplane()) {
|
|
|
|
Entity *ptA = SK.GetEntity(request.entity(1)),
|
|
|
|
*ptB = SK.GetEntity(request.entity(2));
|
|
|
|
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
|
|
|
|
ptA->PointGetExprsInWorkplane(ActiveWorkplane(), &au, &av);
|
|
|
|
ptB->PointGetExprsInWorkplane(ActiveWorkplane(), &bu, &bv);
|
|
|
|
|
2015-11-19 05:30:31 +00:00
|
|
|
double du = au->Minus(bu)->Eval();
|
|
|
|
double dv = av->Minus(bv)->Eval();
|
2015-03-29 22:26:07 +00:00
|
|
|
|
2015-11-19 05:30:31 +00:00
|
|
|
const double TOLERANCE_RATIO = 0.02;
|
Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.
Moreover, we also change the switch statements in three ways:
* Switch statements that ought to be extended every time a new
enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
to explicitly list every single enumerand, and not have a
default: branch.
Note that the assertions are kept because it is legal for
a enumeration to have a value unlike any of its defined
enumerands, and we can e.g. read garbage from a file, or
an uninitialized variable. This requires some rearranging if
a default: branch is undesired.
* Switch statements that ought to only ever see a few select
enumerands, are changed to always assert in the default: branch.
* Switch statements that do something meaningful for a few
enumerands, and ignore everything else, are changed to do nothing
in a default: branch, under the assumption that changing them
every time an enumerand is added or removed would just result
in noise and catch no bugs.
This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-25 06:55:50 +00:00
|
|
|
if(fabs(dv) > LENGTH_EPS && fabs(du / dv) < TOLERANCE_RATIO) {
|
|
|
|
*type = Constraint::Type::VERTICAL;
|
|
|
|
return true;
|
|
|
|
} else if(fabs(du) > LENGTH_EPS && fabs(dv / du) < TOLERANCE_RATIO) {
|
|
|
|
*type = Constraint::Type::HORIZONTAL;
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-29 22:26:07 +00:00
|
|
|
}
|
Enable exhaustive switch coverage warnings as an error, and use them.
Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.
Moreover, we also change the switch statements in three ways:
* Switch statements that ought to be extended every time a new
enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
to explicitly list every single enumerand, and not have a
default: branch.
Note that the assertions are kept because it is legal for
a enumeration to have a value unlike any of its defined
enumerands, and we can e.g. read garbage from a file, or
an uninitialized variable. This requires some rearranging if
a default: branch is undesired.
* Switch statements that ought to only ever see a few select
enumerands, are changed to always assert in the default: branch.
* Switch statements that do something meaningful for a few
enumerands, and ignore everything else, are changed to do nothing
in a default: branch, under the assumption that changing them
every time an enumerand is added or removed would just result
in noise and catch no bugs.
This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
2016-05-25 06:55:50 +00:00
|
|
|
return false;
|
2015-03-29 22:26:07 +00:00
|
|
|
}
|