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
|
|
|
|
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)
|
2013-09-20 17:54:57 +00:00
|
|
|
#define DEL DELETE_KEY
|
|
|
|
#define ESC ESCAPE_KEY
|
|
|
|
#define S SHIFT_MASK
|
|
|
|
#define C CTRL_MASK
|
|
|
|
#define F(k) (FUNCTION_KEY_BASE+(k))
|
2015-03-18 17:02:11 +00:00
|
|
|
#define IN MENU_ITEM_NORMAL
|
|
|
|
#define IC MENU_ITEM_CHECK
|
|
|
|
#define IR MENU_ITEM_RADIO
|
2008-03-26 09:18:12 +00:00
|
|
|
const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
|
2013-09-20 18:16:38 +00:00
|
|
|
//level
|
2015-03-18 17:02:11 +00:00
|
|
|
// label id accel ty fn
|
|
|
|
{ 0, "&File", 0, 0, IN, NULL },
|
|
|
|
{ 1, "&New", MNU_NEW, C|'N', IN, mFile },
|
|
|
|
{ 1, "&Open...", MNU_OPEN, C|'O', IN, mFile },
|
|
|
|
{ 1, "Open &Recent", MNU_OPEN_RECENT, 0, IN, mFile },
|
|
|
|
{ 1, "&Save", MNU_SAVE, C|'S', IN, mFile },
|
|
|
|
{ 1, "Save &As...", MNU_SAVE_AS, 0, IN, mFile },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Export &Image...", MNU_EXPORT_PNG, 0, IN, mFile },
|
|
|
|
{ 1, "Export 2d &View...", MNU_EXPORT_VIEW, 0, IN, mFile },
|
|
|
|
{ 1, "Export 2d &Section...", MNU_EXPORT_SECTION, 0, IN, mFile },
|
|
|
|
{ 1, "Export 3d &Wireframe...", MNU_EXPORT_WIREFRAME, 0, IN, mFile },
|
|
|
|
{ 1, "Export Triangle &Mesh...", MNU_EXPORT_MESH, 0, IN, mFile },
|
|
|
|
{ 1, "Export &Surfaces...", MNU_EXPORT_SURFACES,0, IN, mFile },
|
2015-03-24 06:45:53 +00:00
|
|
|
#ifndef __APPLE__
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "E&xit", MNU_EXIT, C|'Q', IN, mFile },
|
2015-03-24 06:45:53 +00:00
|
|
|
#endif
|
2015-03-18 17:02:11 +00:00
|
|
|
|
|
|
|
{ 0, "&Edit", 0, 0, IN, NULL },
|
|
|
|
{ 1, "&Undo", MNU_UNDO, C|'Z', IN, mEdit },
|
|
|
|
{ 1, "&Redo", MNU_REDO, C|'Y', IN, mEdit },
|
|
|
|
{ 1, "Re&generate All", MNU_REGEN_ALL, ' ', IN, mEdit },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Snap Selection to &Grid", MNU_SNAP_TO_GRID, '.', IN, mEdit },
|
|
|
|
{ 1, "Rotate Imported &90°", MNU_ROTATE_90, '9', IN, mEdit },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Cu&t", MNU_CUT, C|'X', IN, mClip },
|
|
|
|
{ 1, "&Copy", MNU_COPY, C|'C', IN, mClip },
|
|
|
|
{ 1, "&Paste", MNU_PASTE, C|'V', IN, mClip },
|
|
|
|
{ 1, "Paste &Transformed...", MNU_PASTE_TRANSFORM,C|'T', IN, mClip },
|
|
|
|
{ 1, "&Delete", MNU_DELETE, DEL, IN, mClip },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Select &Edge Chain", MNU_SELECT_CHAIN, C|'E', IN, mEdit },
|
|
|
|
{ 1, "Select &All", MNU_SELECT_ALL, C|'A', IN, mEdit },
|
|
|
|
{ 1, "&Unselect All", MNU_UNSELECT_ALL, ESC, IN, mEdit },
|
|
|
|
|
|
|
|
{ 0, "&View", 0, 0, IN, NULL },
|
|
|
|
{ 1, "Zoom &In", MNU_ZOOM_IN, '+', IN, mView },
|
|
|
|
{ 1, "Zoom &Out", MNU_ZOOM_OUT, '-', IN, mView },
|
|
|
|
{ 1, "Zoom To &Fit", MNU_ZOOM_TO_FIT, 'F', IN, mView },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Align View to &Workplane", MNU_ONTO_WORKPLANE, 'W', IN, mView },
|
|
|
|
{ 1, "Nearest &Ortho View", MNU_NEAREST_ORTHO, F(2), IN, mView },
|
|
|
|
{ 1, "Nearest &Isometric View", MNU_NEAREST_ISO, F(3), IN, mView },
|
|
|
|
{ 1, "&Center View At Point", MNU_CENTER_VIEW, F(4), IN, mView },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Show Snap &Grid", MNU_SHOW_GRID, '>', IC, mView },
|
|
|
|
{ 1, "Use &Perspective Projection", MNU_PERSPECTIVE_PROJ,'`', IC, mView },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
2015-03-24 23:38:06 +00:00
|
|
|
#if defined(__APPLE__)
|
2015-03-24 22:47:34 +00:00
|
|
|
{ 1, "Show Menu &Bar", MNU_SHOW_MENU_BAR, C|F(12), IC, mView },
|
2013-10-25 05:04:16 +00:00
|
|
|
#endif
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, "Show &Toolbar", MNU_SHOW_TOOLBAR, 0, IC, mView },
|
|
|
|
{ 1, "Show Text &Window", MNU_SHOW_TEXT_WND, '\t', IC, mView },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Dimensions in &Inches", MNU_UNITS_INCHES, 0, IR, mView },
|
|
|
|
{ 1, "Dimensions in &Millimeters", MNU_UNITS_MM, 0, IR, mView },
|
2015-03-24 23:38:06 +00:00
|
|
|
#if defined(HAVE_GTK) || defined(__APPLE__)
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
2015-03-24 22:47:34 +00:00
|
|
|
{ 1, "&Full Screen", MNU_FULL_SCREEN, C|F(11), IC, mView },
|
2013-10-25 05:04:16 +00:00
|
|
|
#endif
|
2013-09-20 19:01:00 +00:00
|
|
|
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 0, "&New Group", 0, 0, IN, NULL },
|
|
|
|
{ 1, "Sketch In &3d", MNU_GROUP_3D, S|'3', IN, mGrp },
|
|
|
|
{ 1, "Sketch In New &Workplane", MNU_GROUP_WRKPL, S|'W', IN, mGrp },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Step &Translating", MNU_GROUP_TRANS, S|'T', IN, mGrp },
|
|
|
|
{ 1, "Step &Rotating", MNU_GROUP_ROT, S|'R', IN, mGrp },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "E&xtrude", MNU_GROUP_EXTRUDE, S|'X', IN, mGrp },
|
|
|
|
{ 1, "&Lathe", MNU_GROUP_LATHE, S|'L', IN, mGrp },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Import / Assemble...", MNU_GROUP_IMPORT, S|'I', IN, mGrp },
|
|
|
|
{ 1, "Import Recent", MNU_GROUP_RECENT, 0, IN, mGrp },
|
|
|
|
|
|
|
|
{ 0, "&Sketch", 0, 0, IN, NULL },
|
|
|
|
{ 1, "In &Workplane", MNU_SEL_WORKPLANE, '2', IR, mReq },
|
|
|
|
{ 1, "Anywhere In &3d", MNU_FREE_IN_3D, '3', IR, mReq },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Datum &Point", MNU_DATUM_POINT, 'P', IN, mReq },
|
|
|
|
{ 1, "&Workplane", MNU_WORKPLANE, 0, IN, mReq },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Line &Segment", MNU_LINE_SEGMENT, 'S', IN, mReq },
|
2015-07-06 02:45:28 +00:00
|
|
|
{ 1, "C&onstruction Line Segment", MNU_CONSTR_SEGMENT, S|'S', IN, mReq },
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, "&Rectangle", MNU_RECTANGLE, 'R', IN, mReq },
|
|
|
|
{ 1, "&Circle", MNU_CIRCLE, 'C', IN, mReq },
|
|
|
|
{ 1, "&Arc of a Circle", MNU_ARC, 'A', IN, mReq },
|
|
|
|
{ 1, "&Bezier Cubic Spline", MNU_CUBIC, 'B', IN, mReq },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "&Text in TrueType Font", MNU_TTF_TEXT, 'T', IN, mReq },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "To&ggle Construction", MNU_CONSTRUCTION, 'G', IN, mReq },
|
|
|
|
{ 1, "Tangent &Arc at Point", MNU_TANGENT_ARC, S|'A', IN, mReq },
|
|
|
|
{ 1, "Split Curves at &Intersection", MNU_SPLIT_CURVES, 'I', IN, mReq },
|
|
|
|
|
|
|
|
{ 0, "&Constrain", 0, 0, IN, NULL },
|
|
|
|
{ 1, "&Distance / Diameter", MNU_DISTANCE_DIA, 'D', IN, mCon },
|
2015-07-06 02:20:18 +00:00
|
|
|
{ 1, "Re&ference Dimension", MNU_REF_DISTANCE, S|'D', IN, mCon },
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, "A&ngle", MNU_ANGLE, 'N', IN, mCon },
|
2015-07-06 02:20:18 +00:00
|
|
|
{ 1, "Reference An&gle", MNU_REF_ANGLE, S|'N', IN, mCon },
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, "Other S&upplementary Angle", MNU_OTHER_ANGLE, 'U', IN, mCon },
|
|
|
|
{ 1, "Toggle R&eference Dim", MNU_REFERENCE, 'E', IN, mCon },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "&Horizontal", MNU_HORIZONTAL, 'H', IN, mCon },
|
|
|
|
{ 1, "&Vertical", MNU_VERTICAL, 'V', IN, mCon },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "&On Point / Curve / Plane", MNU_ON_ENTITY, 'O', IN, mCon },
|
|
|
|
{ 1, "E&qual Length / Radius / Angle", MNU_EQUAL, 'Q', IN, mCon },
|
|
|
|
{ 1, "Length Ra&tio", MNU_RATIO, 'Z', IN, mCon },
|
2015-10-27 10:28:33 +00:00
|
|
|
{ 1, "Length Diff&erence", MNU_DIFFERENCE, 'J', IN, mCon },
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, "At &Midpoint", MNU_AT_MIDPOINT, 'M', IN, mCon },
|
|
|
|
{ 1, "S&ymmetric", MNU_SYMMETRIC, 'Y', IN, mCon },
|
|
|
|
{ 1, "Para&llel / Tangent", MNU_PARALLEL, 'L', IN, mCon },
|
|
|
|
{ 1, "&Perpendicular", MNU_PERPENDICULAR, '[', IN, mCon },
|
|
|
|
{ 1, "Same Orient&ation", MNU_ORIENTED_SAME, 'X', IN, mCon },
|
|
|
|
{ 1, "Lock Point Where &Dragged", MNU_WHERE_DRAGGED, ']', IN, mCon },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Comment", MNU_COMMENT, ';', IN, mCon },
|
|
|
|
|
|
|
|
{ 0, "&Analyze", 0, 0, IN, NULL },
|
|
|
|
{ 1, "Measure &Volume", MNU_VOLUME, C|S|'V', IN, mAna },
|
|
|
|
{ 1, "Measure &Area", MNU_AREA, C|S|'A', IN, mAna },
|
|
|
|
{ 1, "Show &Interfering Parts", MNU_INTERFERENCE, C|S|'I', IN, mAna },
|
|
|
|
{ 1, "Show &Naked Edges", MNU_NAKED_EDGES, C|S|'N', IN, mAna },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "Show Degrees of &Freedom", MNU_SHOW_DOF, C|S|'F', IN, mAna },
|
|
|
|
{ 1, NULL, 0, 0, IN, NULL },
|
|
|
|
{ 1, "&Trace Point", MNU_TRACE_PT, C|S|'T', IN, mAna },
|
|
|
|
{ 1, "&Stop Tracing...", MNU_STOP_TRACING, C|S|'S', IN, mAna },
|
|
|
|
{ 1, "Step &Dimension...", MNU_STEP_DIM, C|S|'D', IN, mAna },
|
|
|
|
|
|
|
|
{ 0, "&Help", 0, 0, IN, NULL },
|
|
|
|
{ 1, "&Website / Manual", MNU_WEBSITE, 0, IN, mHelp },
|
2015-03-24 06:45:53 +00:00
|
|
|
#ifndef __APPLE__
|
2015-03-18 17:02:11 +00:00
|
|
|
{ 1, "&About", MNU_ABOUT, 0, IN, mHelp },
|
2015-03-24 06:45:53 +00:00
|
|
|
#endif
|
2015-03-18 17:02:11 +00:00
|
|
|
|
|
|
|
{ -1, 0, 0, 0, IN, 0 }
|
2008-03-26 09:18:12 +00:00
|
|
|
};
|
|
|
|
|
2013-09-20 18:16:38 +00:00
|
|
|
#undef DEL
|
|
|
|
#undef ESC
|
|
|
|
#undef S
|
|
|
|
#undef C
|
|
|
|
#undef F
|
2015-03-18 17:02:11 +00:00
|
|
|
#undef IN
|
|
|
|
#undef IC
|
|
|
|
#undef IR
|
2013-09-20 18:16:38 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
bool SolveSpace::MakeAcceleratorLabel(int accel, char *out) {
|
2013-09-20 19:01:00 +00:00
|
|
|
if(!accel) {
|
|
|
|
out[0] = '\0';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ctrl = accel & GraphicsWindow::CTRL_MASK ? "Ctrl+" : "";
|
|
|
|
const char *shift = accel & GraphicsWindow::SHIFT_MASK ? "Shift+" : "";
|
|
|
|
|
|
|
|
char buf[8];
|
|
|
|
buf[0] = (char)(accel & 0xff);
|
|
|
|
buf[1] = '\0';
|
|
|
|
|
|
|
|
if(accel >= GraphicsWindow::FUNCTION_KEY_BASE + 1 &&
|
|
|
|
accel <= GraphicsWindow::FUNCTION_KEY_BASE + 12) {
|
|
|
|
sprintf(buf, "F%d", accel - GraphicsWindow::FUNCTION_KEY_BASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *key = buf;
|
|
|
|
|
|
|
|
switch(accel) {
|
|
|
|
case '\t': key = "Tab"; break;
|
|
|
|
case ' ': key = "Space"; break;
|
|
|
|
|
|
|
|
case GraphicsWindow::ESCAPE_KEY: key = "Esc"; break;
|
|
|
|
case GraphicsWindow::DELETE_KEY: key = "Del"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(key[0] < '!' || key[0] > '~') oops();
|
|
|
|
if(key[0] >= 'a' && key[0] <= 'z') oops();
|
|
|
|
|
|
|
|
sprintf(out, "%s%s%s", ctrl, shift, key);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
void GraphicsWindow::Init(void) {
|
2008-05-11 10:40:37 +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-02 10:54:22 +00:00
|
|
|
showHdnLines = false;
|
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;
|
2008-04-27 05:00:12 +00:00
|
|
|
|
|
|
|
showTextWindow = true;
|
|
|
|
ShowTextWindow(showTextWindow);
|
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;
|
|
|
|
|
2008-06-13 04:41:27 +00:00
|
|
|
// Do this last, so that all the menus get updated correctly.
|
|
|
|
EnsureValidActives();
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 04:06:47 +00:00
|
|
|
void GraphicsWindow::AnimateOntoWorkplane(void) {
|
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();
|
|
|
|
PaintGraphics();
|
|
|
|
|
|
|
|
tn = GetMilliseconds();
|
|
|
|
s = (tn - t0)/((double)dt);
|
|
|
|
} while((tn - t0) < dt);
|
|
|
|
|
|
|
|
projRight = quatf.RotationU();
|
|
|
|
projUp = quatf.RotationV();
|
|
|
|
offset = offsetf;
|
|
|
|
InvalidateGraphics();
|
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,
|
|
|
|
double *wmin, bool usePerspective)
|
2008-06-11 04:22:52 +00:00
|
|
|
{
|
2008-06-17 19:12:25 +00:00
|
|
|
double w;
|
|
|
|
Vector pp = 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,
|
|
|
|
Point2d *pmax, Point2d *pmin, double *wmin,
|
|
|
|
bool usePerspective, bool includeMesh) {
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
int i, j;
|
2016-01-30 10:38:38 +00:00
|
|
|
for(Entity *e : entities) {
|
2009-04-14 04:19:23 +00:00
|
|
|
if(e->IsPoint()) {
|
2016-01-30 10:38:38 +00:00
|
|
|
HandlePointForZoomToFit(e->PointGetNum(), pmax, pmin, wmin, usePerspective);
|
2009-04-14 04:19:23 +00:00
|
|
|
} else if(e->type == Entity::CIRCLE) {
|
|
|
|
// 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();
|
2009-04-14 04:19:23 +00:00
|
|
|
for(j = 0; j < 4; j++) {
|
|
|
|
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)));
|
2016-01-30 10:38:38 +00:00
|
|
|
HandlePointForZoomToFit(p, pmax, pmin, wmin, usePerspective);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We have to iterate children points, because we can select entites without points
|
|
|
|
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();
|
|
|
|
HandlePointForZoomToFit(p, pmax, pmin, wmin, usePerspective);
|
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-01-30 10:38:38 +00:00
|
|
|
if(!includeMesh) return;
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.GetGroup(activeGroup);
|
2009-05-21 09:06:26 +00:00
|
|
|
g->GenerateDisplayItems();
|
|
|
|
for(i = 0; i < g->displayMesh.l.n; i++) {
|
|
|
|
STriangle *tr = &(g->displayMesh.l.elem[i]);
|
2016-01-30 10:38:38 +00:00
|
|
|
HandlePointForZoomToFit(tr->a, pmax, pmin, wmin, usePerspective);
|
|
|
|
HandlePointForZoomToFit(tr->b, pmax, pmin, wmin, usePerspective);
|
|
|
|
HandlePointForZoomToFit(tr->c, pmax, pmin, wmin, usePerspective);
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
2009-10-29 07:16:28 +00:00
|
|
|
for(i = 0; i < g->polyLoops.l.n; i++) {
|
|
|
|
SContour *sc = &(g->polyLoops.l.elem[i]);
|
2008-06-11 04:22:52 +00:00
|
|
|
for(j = 0; j < sc->l.n; j++) {
|
2016-01-30 10:38:38 +00:00
|
|
|
HandlePointForZoomToFit(sc->l.elem[j].p, pmax, pmin, wmin, usePerspective);
|
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) {
|
|
|
|
std::vector<Entity *> entities;
|
|
|
|
bool selectionUsed = useSelection && selection.n > 0;
|
|
|
|
if(selectionUsed) {
|
|
|
|
for(int i = 0; i < selection.n; i++) {
|
|
|
|
Selection *s = &selection.elem[i];
|
|
|
|
if(s->entity.v == 0) continue;
|
|
|
|
Entity *e = SK.entity.FindById(s->entity);
|
|
|
|
entities.push_back(e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(int i = 0; i<SK.entity.n; i++) {
|
|
|
|
Entity *e = &(SK.entity.elem[i]);
|
|
|
|
// we don't want to handle separate points, because we will iterate them inside entities.
|
|
|
|
if(e->IsPoint()) continue;
|
|
|
|
if(!includingInvisibles && !e->IsVisible()) continue;
|
|
|
|
entities.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-01-30 10:38:38 +00:00
|
|
|
LoopOverPoints(entities, &pmax, &pmin, &wmin,
|
|
|
|
/*usePerspective=*/false, /*includeMesh=*/!selectionUsed);
|
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
|
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;
|
2013-10-21 21:29:25 +00:00
|
|
|
if(EXACT(dx != 0)) scalex = 0.9*width /dx;
|
|
|
|
if(EXACT(dy != 0)) scaley = 0.9*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-01-30 10:38:38 +00:00
|
|
|
LoopOverPoints(entities, &pmax, &pmin, &wmin,
|
|
|
|
/*usePerspective=*/true, /*includeMesh=*/!selectionUsed);
|
2008-06-17 19:12:25 +00:00
|
|
|
|
|
|
|
// Adjust the scale so that no points are behind the camera
|
|
|
|
if(wmin < 0.1) {
|
2009-09-29 11:35:19 +00:00
|
|
|
double k = SS.CameraTangent();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void GraphicsWindow::MenuView(int id) {
|
2008-04-12 15:17:58 +00:00
|
|
|
switch(id) {
|
|
|
|
case MNU_ZOOM_IN:
|
|
|
|
SS.GW.scale *= 1.2;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_ZOOM_OUT:
|
|
|
|
SS.GW.scale /= 1.2;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_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;
|
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
case MNU_SHOW_GRID:
|
|
|
|
SS.GW.showSnapGrid = !SS.GW.showSnapGrid;
|
|
|
|
if(SS.GW.showSnapGrid && !SS.GW.LockedInWorkplane()) {
|
|
|
|
Message("No workplane is active, so the grid will not "
|
|
|
|
"appear.");
|
|
|
|
}
|
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
InvalidateGraphics();
|
|
|
|
break;
|
|
|
|
|
2010-05-03 05:15:28 +00:00
|
|
|
case MNU_PERSPECTIVE_PROJ:
|
|
|
|
SS.usePerspectiveProj = !SS.usePerspectiveProj;
|
2009-09-29 11:35:19 +00:00
|
|
|
if(SS.cameraTangent < 1e-6) {
|
|
|
|
Error("The perspective factor is set to zero, so the view will "
|
2010-01-16 18:15:40 +00:00
|
|
|
"always be a parallel projection.\n\n"
|
2009-12-04 08:08:41 +00:00
|
|
|
"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();
|
|
|
|
InvalidateGraphics();
|
|
|
|
break;
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
case MNU_ONTO_WORKPLANE:
|
2015-03-22 13:23:40 +00:00
|
|
|
if(SS.GW.LockedInWorkplane()) {
|
|
|
|
SS.GW.AnimateOntoWorkplane();
|
|
|
|
SS.GW.ClearSuper();
|
|
|
|
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
|
2009-01-02 04:06:47 +00:00
|
|
|
case MNU_NEAREST_ORTHO:
|
|
|
|
case MNU_NEAREST_ISO: {
|
|
|
|
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;
|
2015-03-22 13:23:40 +00:00
|
|
|
if(id == MNU_NEAREST_ORTHO || id == MNU_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;
|
|
|
|
}
|
|
|
|
|
2009-01-13 06:56:05 +00:00
|
|
|
case MNU_CENTER_VIEW:
|
|
|
|
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 {
|
|
|
|
Error("Select a point; this point will become the center "
|
|
|
|
"of the view on screen.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-10-25 05:04:16 +00:00
|
|
|
case MNU_SHOW_MENU_BAR:
|
|
|
|
ToggleMenuBar();
|
2008-04-27 05:00:12 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
2013-10-25 05:04:16 +00:00
|
|
|
InvalidateGraphics();
|
2008-04-27 05:00:12 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
case MNU_SHOW_TOOLBAR:
|
|
|
|
SS.showToolbar = !SS.showToolbar;
|
|
|
|
SS.GW.EnsureValidActives();
|
2009-09-29 11:35:19 +00:00
|
|
|
InvalidateGraphics();
|
2009-01-02 10:38:36 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-25 05:04:16 +00:00
|
|
|
case MNU_SHOW_TEXT_WND:
|
|
|
|
SS.GW.showTextWindow = !SS.GW.showTextWindow;
|
2008-04-22 13:14:15 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_UNITS_INCHES:
|
2015-03-23 17:49:04 +00:00
|
|
|
SS.viewUnits = SolveSpaceUI::UNIT_INCHES;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-22 13:14:15 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
2013-10-25 05:04:16 +00:00
|
|
|
case MNU_UNITS_MM:
|
2015-03-23 17:49:04 +00:00
|
|
|
SS.viewUnits = SolveSpaceUI::UNIT_MM;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2013-10-25 05:04:16 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_FULL_SCREEN:
|
|
|
|
ToggleFullScreen();
|
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
2008-04-18 07:06:37 +00:00
|
|
|
void GraphicsWindow::EnsureValidActives(void) {
|
|
|
|
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();
|
|
|
|
} 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
|
|
|
|
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();
|
2013-09-19 04:59:18 +00:00
|
|
|
RadioMenuById(MNU_FREE_IN_3D, !locked);
|
|
|
|
RadioMenuById(MNU_SEL_WORKPLANE, 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) {
|
2015-03-23 17:49:04 +00:00
|
|
|
case SolveSpaceUI::UNIT_MM:
|
|
|
|
case SolveSpaceUI::UNIT_INCHES:
|
2008-04-22 13:14:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-03-23 17:49:04 +00:00
|
|
|
SS.viewUnits = SolveSpaceUI::UNIT_MM;
|
2010-01-04 00:35:28 +00:00
|
|
|
break;
|
2008-04-22 13:14:15 +00:00
|
|
|
}
|
2015-03-23 17:49:04 +00:00
|
|
|
RadioMenuById(MNU_UNITS_MM, SS.viewUnits == SolveSpaceUI::UNIT_MM);
|
|
|
|
RadioMenuById(MNU_UNITS_INCHES, SS.viewUnits == SolveSpaceUI::UNIT_INCHES);
|
2008-04-27 05:00:12 +00:00
|
|
|
|
|
|
|
ShowTextWindow(SS.GW.showTextWindow);
|
|
|
|
CheckMenuById(MNU_SHOW_TEXT_WND, SS.GW.showTextWindow);
|
|
|
|
|
2015-03-24 23:38:06 +00:00
|
|
|
#if defined(__APPLE__)
|
2013-10-25 05:04:16 +00:00
|
|
|
CheckMenuById(MNU_SHOW_MENU_BAR, MenuBarIsVisible());
|
|
|
|
#endif
|
2009-01-02 10:38:36 +00:00
|
|
|
CheckMenuById(MNU_SHOW_TOOLBAR, SS.showToolbar);
|
2010-05-03 05:15:28 +00:00
|
|
|
CheckMenuById(MNU_PERSPECTIVE_PROJ, SS.usePerspectiveProj);
|
2009-09-29 11:35:19 +00:00
|
|
|
CheckMenuById(MNU_SHOW_GRID, SS.GW.showSnapGrid);
|
2015-03-24 23:38:06 +00:00
|
|
|
#if defined(HAVE_GTK) || defined(__APPLE__)
|
2013-10-25 05:04:16 +00:00
|
|
|
CheckMenuById(MNU_FULL_SCREEN, FullScreenIsActive());
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
void GraphicsWindow::SetWorkplaneFreeIn3d(void) {
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetGroup(activeGroup)->activeWorkplane = Entity::FREE_IN_3D;
|
2008-05-27 02:22:20 +00:00
|
|
|
}
|
|
|
|
hEntity GraphicsWindow::ActiveWorkplane(void) {
|
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
|
|
|
}
|
|
|
|
bool GraphicsWindow::LockedInWorkplane(void) {
|
|
|
|
return (SS.GW.ActiveWorkplane().v != Entity::FREE_IN_3D.v);
|
|
|
|
}
|
|
|
|
|
2008-09-17 10:13:37 +00:00
|
|
|
void GraphicsWindow::ForceTextWindowShown(void) {
|
|
|
|
if(!showTextWindow) {
|
|
|
|
showTextWindow = true;
|
|
|
|
CheckMenuById(MNU_SHOW_TEXT_WND, true);
|
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
|
|
|
ShowTextWindow(true);
|
2008-09-17 10:13:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-03 12:27:33 +00:00
|
|
|
void GraphicsWindow::DeleteTaggedRequests(void) {
|
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.
|
|
|
|
HideGraphicsEditControl();
|
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).
|
2016-01-27 09:09:45 +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);
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void GraphicsWindow::MenuEdit(int id) {
|
2008-04-12 15:17:58 +00:00
|
|
|
switch(id) {
|
|
|
|
case MNU_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 &&
|
|
|
|
SS.GW.pending.operation == 0)
|
|
|
|
{
|
2009-09-24 15:52:48 +00:00
|
|
|
if(!(TextEditControlIsVisible() ||
|
|
|
|
GraphicsEditControlIsVisible()))
|
|
|
|
{
|
2009-09-18 08:14:15 +00:00
|
|
|
if(SS.TW.shown.screen == TextWindow::SCREEN_STYLE_INFO) {
|
|
|
|
SS.TW.GoToScreen(TextWindow::SCREEN_LIST_OF_STYLES);
|
|
|
|
} 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;
|
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;
|
|
|
|
SS.GenerateAll(SolveSpaceUI::GENERATE_ALL);
|
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
|
2009-12-21 16:44:00 +00:00
|
|
|
case MNU_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
|
|
|
}
|
|
|
|
InvalidateGraphics();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-11-03 18:54:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MNU_SELECT_CHAIN: {
|
|
|
|
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) {
|
2010-01-03 10:26:15 +00:00
|
|
|
Error("No additional entities share endpoints with the "
|
|
|
|
"selected entities.");
|
2009-11-03 18:54:49 +00:00
|
|
|
}
|
|
|
|
InvalidateGraphics();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-11-03 18:54:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-21 20:39:42 +00:00
|
|
|
case MNU_ROTATE_90: {
|
|
|
|
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);
|
|
|
|
if(g->type != Group::IMPORTED) {
|
|
|
|
Error("To use this command, select a point or other "
|
|
|
|
"entity from an imported part, or make an import "
|
|
|
|
"group the active group.");
|
|
|
|
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);
|
|
|
|
SS.GenerateAll();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
case MNU_SNAP_TO_GRID: {
|
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
|
|
|
Error("No workplane is active. Select a workplane to define "
|
|
|
|
"the plane for the snap grid.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SS.GW.GroupSelection();
|
2009-12-04 08:08:41 +00:00
|
|
|
if(SS.GW.gs.points == 0 && SS.GW.gs.comments == 0) {
|
|
|
|
Error("Can't snap these items to grid; select points or "
|
2009-09-29 11:35:19 +00:00
|
|
|
"text comments. To snap a line, select its endpoints.");
|
|
|
|
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);
|
|
|
|
if(c->type != Constraint::COMMENT) continue;
|
|
|
|
|
|
|
|
c->disp.offset = SS.GW.SnapToGrid(c->disp.offset);
|
|
|
|
}
|
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.GenerateAll();
|
|
|
|
SS.GW.ClearPending();
|
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
SS.GW.ClearSelection();
|
|
|
|
InvalidateGraphics();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
case MNU_UNDO:
|
|
|
|
SS.UndoUndo();
|
|
|
|
break;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
case MNU_REDO:
|
|
|
|
SS.UndoRedo();
|
|
|
|
break;
|
|
|
|
|
2008-06-30 09:34:03 +00:00
|
|
|
case MNU_REGEN_ALL:
|
|
|
|
SS.ReloadAllImported();
|
2016-01-27 09:09:45 +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;
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void GraphicsWindow::MenuRequest(int id) {
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *s;
|
2008-04-13 10:57:41 +00:00
|
|
|
switch(id) {
|
2008-04-27 03:26:27 +00:00
|
|
|
case MNU_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];
|
|
|
|
} else if(g->type == Group::DRAWING_WORKPLANE) {
|
|
|
|
// The group's default workplane
|
|
|
|
g->activeWorkplane = g->h.entity(0);
|
2010-05-03 05:04:42 +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()) {
|
2010-05-03 05:04:42 +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
|
|
|
}
|
2008-04-27 03:26:27 +00:00
|
|
|
case MNU_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();
|
2009-09-29 11:35:19 +00:00
|
|
|
InvalidateGraphics();
|
2008-04-18 07:06:37 +00:00
|
|
|
break;
|
2008-07-14 02:45:11 +00:00
|
|
|
|
2010-05-16 16:36:23 +00:00
|
|
|
case MNU_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) {
|
|
|
|
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 {
|
2010-05-16 16:36:23 +00:00
|
|
|
SS.TW.GoToScreen(TextWindow::SCREEN_TANGENT_ARC);
|
|
|
|
SS.GW.ForceTextWindowShown();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2015-03-29 21:37:21 +00:00
|
|
|
InvalidateGraphics(); // repaint toolbar
|
2008-07-14 02:45:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-05-16 16:36:23 +00:00
|
|
|
|
|
|
|
case MNU_ARC: s = "click point on arc (draws anti-clockwise)"; goto c;
|
2008-04-13 10:57:41 +00:00
|
|
|
case MNU_DATUM_POINT: s = "click to place datum point"; goto c;
|
|
|
|
case MNU_LINE_SEGMENT: s = "click first point of line segment"; goto c;
|
2015-07-06 02:45:28 +00:00
|
|
|
case MNU_CONSTR_SEGMENT: s = "click first point of construction line segment"; goto c;
|
2008-04-25 12:07:17 +00:00
|
|
|
case MNU_CUBIC: s = "click first point of cubic segment"; goto c;
|
2008-05-05 06:18:01 +00:00
|
|
|
case MNU_CIRCLE: s = "click center of circle"; goto c;
|
2008-05-05 11:17:00 +00:00
|
|
|
case MNU_WORKPLANE: s = "click origin of workplane"; goto c;
|
2008-07-08 06:30:13 +00:00
|
|
|
case MNU_RECTANGLE: s = "click one corner of rectangle"; goto c;
|
2008-06-30 09:09:17 +00:00
|
|
|
case MNU_TTF_TEXT: s = "click top left of text"; goto c;
|
2008-04-13 10:57:41 +00:00
|
|
|
c:
|
2008-05-05 06:18:01 +00:00
|
|
|
SS.GW.pending.operation = id;
|
|
|
|
SS.GW.pending.description = s;
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2015-03-29 21:37:21 +00:00
|
|
|
InvalidateGraphics(); // repaint toolbar
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-07 04:17:29 +00:00
|
|
|
case MNU_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) {
|
|
|
|
Error("No entities are selected. Select entities before "
|
|
|
|
"trying to toggle their construction state.");
|
|
|
|
}
|
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();
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll();
|
2008-05-07 04:17:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-03 12:27:33 +00:00
|
|
|
case MNU_SPLIT_CURVES:
|
|
|
|
SS.GW.SplitLinesOrCurves();
|
|
|
|
break;
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
void GraphicsWindow::ClearSuper(void) {
|
2008-06-01 00:26:41 +00:00
|
|
|
HideGraphicsEditControl();
|
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
|
|
|
|
2009-05-29 05:40:17 +00:00
|
|
|
// We might need to regenerate the mesh and edge list, since the edges
|
|
|
|
// wouldn't have been generated if they were previously hidden.
|
2010-05-03 05:04:42 +00:00
|
|
|
if(showEdges) (SK.GetGroup(activeGroup))->displayDirty = true;
|
2009-05-29 05:40:17 +00:00
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll();
|
2008-04-11 12:47:14 +00:00
|
|
|
InvalidateGraphics();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2008-04-11 12:47:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 22:26:07 +00:00
|
|
|
GraphicsWindow::SuggestedConstraint GraphicsWindow::SuggestLineConstraint(hRequest request) {
|
|
|
|
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;
|
|
|
|
if(fabs(dv) > LENGTH_EPS && fabs(du / dv) < TOLERANCE_RATIO)
|
2015-03-29 22:26:07 +00:00
|
|
|
return SUGGESTED_VERTICAL;
|
2015-11-19 05:30:31 +00:00
|
|
|
else if(fabs(du) > LENGTH_EPS && fabs(dv / du) < TOLERANCE_RATIO)
|
2015-03-29 22:26:07 +00:00
|
|
|
return SUGGESTED_HORIZONTAL;
|
|
|
|
else
|
|
|
|
return SUGGESTED_NONE;
|
|
|
|
} else {
|
|
|
|
return SUGGESTED_NONE;
|
|
|
|
}
|
|
|
|
}
|