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)
|
2008-04-13 10:57:41 +00:00
|
|
|
#define mReq (&GraphicsWindow::MenuRequest)
|
2008-04-14 10:28:32 +00:00
|
|
|
#define mCon (&Constraint::MenuConstrain)
|
2008-04-18 11:11:48 +00:00
|
|
|
#define mFile (&SolveSpace::MenuFile)
|
2008-04-27 09:03:01 +00:00
|
|
|
#define mGrp (&Group::MenuGroup)
|
2008-04-13 10:57:41 +00:00
|
|
|
#define S 0x100
|
2008-04-18 11:11:48 +00:00
|
|
|
#define C 0x200
|
2008-03-26 09:18:12 +00:00
|
|
|
const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 0, "&File", 0, NULL },
|
2008-04-18 11:11:48 +00:00
|
|
|
{ 1, "&New\tCtrl+N", MNU_NEW, 'N'|C, mFile },
|
|
|
|
{ 1, "&Open...\tCtrl+O", MNU_OPEN, 'O'|C, mFile },
|
2008-05-28 10:10:31 +00:00
|
|
|
{10, "&Open Recent", MNU_OPEN_RECENT, 0, mFile },
|
2008-04-18 11:11:48 +00:00
|
|
|
{ 1, "&Save\tCtrl+S", MNU_SAVE, 'S'|C, mFile },
|
|
|
|
{ 1, "Save &As...", MNU_SAVE_AS, 0, mFile },
|
|
|
|
{ 1, NULL, 0, 0, NULL },
|
2008-06-18 08:35:14 +00:00
|
|
|
{ 1, "&Export Image...", MNU_EXPORT_PNG, 0, mFile },
|
|
|
|
{ 1, NULL, 0, 0, NULL },
|
2008-04-18 11:11:48 +00:00
|
|
|
{ 1, "E&xit", MNU_EXIT, 0, mFile },
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
{ 0, "&Edit", 0, NULL },
|
2008-06-04 10:22:30 +00:00
|
|
|
{ 1, "&Undo\tCtrl+Z", MNU_UNDO, 'Z'|C, mEdit },
|
|
|
|
{ 1, "&Redo\tCtrl+Y", MNU_REDO, 'Y'|C, mEdit },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-14 10:28:32 +00:00
|
|
|
{ 1, "&Delete\tDel", MNU_DELETE, 127, mEdit },
|
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, "&Unselect All\tEsc", MNU_UNSELECT_ALL, 27, mEdit },
|
|
|
|
|
|
|
|
{ 0, "&View", 0, NULL },
|
|
|
|
{ 1, "Zoom &In\t+", MNU_ZOOM_IN, '+', mView },
|
|
|
|
{ 1, "Zoom &Out\t-", MNU_ZOOM_OUT, '-', mView },
|
|
|
|
{ 1, "Zoom To &Fit\tF", MNU_ZOOM_TO_FIT, 'F', mView },
|
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-27 05:00:12 +00:00
|
|
|
{ 1, "Show Text &Window\tTab", MNU_SHOW_TEXT_WND, '\t', mView },
|
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-22 13:14:15 +00:00
|
|
|
{ 1, "Dimensions in &Inches", MNU_UNITS_INCHES, 0, mView },
|
|
|
|
{ 1, "Dimensions in &Millimeters", MNU_UNITS_MM, 0, mView },
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-06-06 11:35:28 +00:00
|
|
|
{ 0, "&New Group", 0, 0, NULL },
|
2008-06-21 10:18:20 +00:00
|
|
|
{ 1, "&Drawing in 3d\tShift+Ctrl+D", MNU_GROUP_3D, 'D'|S|C,mGrp },
|
|
|
|
{ 1, "Drawing in Workplane\tShift+Ctrl+W", MNU_GROUP_WRKPL, 'W'|S|C,mGrp },
|
2008-04-22 10:53:42 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-05-28 10:10:31 +00:00
|
|
|
{ 1, "Step &Translating\tShift+Ctrl+R", MNU_GROUP_TRANS, 'T'|S|C,mGrp },
|
|
|
|
{ 1, "Step &Rotating\tShift+Ctrl+T", MNU_GROUP_ROT, 'R'|S|C,mGrp },
|
2008-04-22 10:53:42 +00:00
|
|
|
{ 1, NULL, 0, 0, NULL },
|
2008-06-21 10:18:20 +00:00
|
|
|
{ 1, "E&xtrude\tShift+Ctrl+X", MNU_GROUP_EXTRUDE, 'X'|S|C,mGrp },
|
|
|
|
{ 1, "&Lathe\tShift+Ctrl+L", MNU_GROUP_LATHE, 'L'|S|C,mGrp },
|
|
|
|
{ 1, "&Sweep\tShift+Ctrl+S", MNU_GROUP_SWEEP, 'S'|S|C,mGrp },
|
2008-04-22 10:53:42 +00:00
|
|
|
{ 1, NULL, 0, 0, NULL },
|
2008-06-06 11:35:28 +00:00
|
|
|
{ 1, "Import / Assemble...\tShift+Ctrl+I", MNU_GROUP_IMPORT, 'I'|S|C,mGrp },
|
2008-05-28 10:10:31 +00:00
|
|
|
{11, "Import Recent", MNU_GROUP_RECENT, 0, mGrp },
|
2008-04-22 10:53:42 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 0, "&Request", 0, NULL },
|
2008-04-27 03:26:27 +00:00
|
|
|
{ 1, "Draw in &Workplane\tW", MNU_SEL_WORKPLANE, 'W', mReq },
|
|
|
|
{ 1, "Draw Anywhere in 3d\tQ", MNU_FREE_IN_3D, 'Q', mReq },
|
2008-04-18 07:06:37 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, "Datum &Point\tP", MNU_DATUM_POINT, 'P', mReq },
|
2008-05-05 11:17:00 +00:00
|
|
|
{ 1, "&Workplane (Coordinate S&ystem)\tY", MNU_WORKPLANE, 'Y', mReq },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
|
|
|
{ 1, "Line &Segment\tS", MNU_LINE_SEGMENT, 'S', mReq },
|
2008-04-22 10:53:42 +00:00
|
|
|
{ 1, "&Rectangle\tR", MNU_RECTANGLE, 'R', mReq },
|
2008-05-05 06:18:01 +00:00
|
|
|
{ 1, "&Circle\tC", MNU_CIRCLE, 'C', mReq },
|
2008-05-12 10:01:44 +00:00
|
|
|
{ 1, "&Arc of a Circle\tA", MNU_ARC, 'A', mReq },
|
2008-04-25 12:07:17 +00:00
|
|
|
{ 1, "&Cubic Segment\t3", MNU_CUBIC, '3', mReq },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-05-07 04:17:29 +00:00
|
|
|
{ 1, "To&ggle Construction\tG", MNU_CONSTRUCTION, 'G', mReq },
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
{ 0, "&Constrain", 0, NULL },
|
2008-04-14 10:28:32 +00:00
|
|
|
{ 1, "&Distance / Diameter\tShift+D", MNU_DISTANCE_DIA, 'D'|S, mCon },
|
2008-05-17 11:15:14 +00:00
|
|
|
{ 1, "A&ngle\tShift+N", MNU_ANGLE, 'N'|S, mCon },
|
|
|
|
{ 1, "Other S&upplementary Angle\tShift+U", MNU_OTHER_ANGLE, 'U'|S, mCon },
|
2008-06-11 04:22:52 +00:00
|
|
|
{ 1, "Toggle &Reference Dim\tShift+R", MNU_REFERENCE, 'R'|S, mCon },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-23 07:29:19 +00:00
|
|
|
{ 1, "&Horizontal\tShift+H", MNU_HORIZONTAL, 'H'|S, mCon },
|
|
|
|
{ 1, "&Vertical\tShift+V", MNU_VERTICAL, 'V'|S, mCon },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-21 08:16:38 +00:00
|
|
|
{ 1, "&On Point / Curve / Plane\tShift+O", MNU_ON_ENTITY, 'O'|S, mCon },
|
2008-04-22 05:00:49 +00:00
|
|
|
{ 1, "E&qual Length / Radius\tShift+Q", MNU_EQUAL, 'Q'|S, mCon },
|
2008-05-11 10:40:37 +00:00
|
|
|
{ 1, "Length Ra&tio\tShift+T", MNU_RATIO, 'T'|S, mCon },
|
2008-04-30 08:14:32 +00:00
|
|
|
{ 1, "At &Midpoint\tShift+M", MNU_AT_MIDPOINT, 'M'|S, mCon },
|
|
|
|
{ 1, "S&ymmetric\tShift+Y", MNU_SYMMETRIC, 'Y'|S, mCon },
|
2008-05-09 05:33:23 +00:00
|
|
|
{ 1, "Para&llel\tShift+L", MNU_PARALLEL, 'L'|S, mCon },
|
2008-06-11 04:22:52 +00:00
|
|
|
{ 1, "Same Orient&ation\tShift+A", MNU_ORIENTED_SAME, 'A'|S, mCon },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
2008-06-12 08:58:58 +00:00
|
|
|
{ 1, "Comment\tShift+C", MNU_COMMENT, 'C'|S, mCon },
|
|
|
|
{ 1, NULL, 0, NULL },
|
2008-04-20 11:35:10 +00:00
|
|
|
{ 1, "Solve Once Now\tSpace", MNU_SOLVE_NOW, ' ', mCon },
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
{ 0, "&Help", 0, NULL },
|
|
|
|
{ 1, "&About\t", 0, NULL },
|
2008-04-12 15:17:58 +00:00
|
|
|
{ -1 },
|
2008-03-26 09:18:12 +00:00
|
|
|
};
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
void GraphicsWindow::Init(void) {
|
2008-04-12 14:12:26 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
|
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-06-14 23:31:36 +00:00
|
|
|
// And with the last group active
|
|
|
|
activeGroup = SS.group.elem[SS.group.n-1].h;
|
2008-06-02 05:38:12 +00:00
|
|
|
SS.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;
|
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
|
|
|
|
|
|
|
// Do this last, so that all the menus get updated correctly.
|
|
|
|
EnsureValidActives();
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::NormalizeProjectionVectors(void) {
|
2008-04-12 15:17:58 +00:00
|
|
|
Vector norm = projRight.Cross(projUp);
|
|
|
|
projUp = norm.Cross(projRight);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
projUp = projUp.ScaledBy(1/projUp.Magnitude());
|
2008-03-27 09:53:51 +00:00
|
|
|
projRight = projRight.ScaledBy(1/projRight.Magnitude());
|
|
|
|
}
|
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Project a point in model space to screen space, exactly as gl would; return
|
|
|
|
// units are pixels.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-04-12 14:12:26 +00:00
|
|
|
Point2d GraphicsWindow::ProjectPoint(Vector p) {
|
2008-06-17 19:12:25 +00:00
|
|
|
Vector p3 = ProjectPoint3(p);
|
|
|
|
Point2d p2 = { p3.x, p3.y };
|
|
|
|
return p2;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Project a point in model space to screen space, exactly as gl would; return
|
|
|
|
// units are pixels. The z coordinate is also returned, also in pixels.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Vector GraphicsWindow::ProjectPoint3(Vector p) {
|
|
|
|
double w;
|
|
|
|
Vector r = ProjectPoint4(p, &w);
|
|
|
|
return r.ScaledBy(scale/w);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Project a point in model space halfway into screen space. The scale is
|
|
|
|
// not applied, and the perspective divide isn't applied; instead the w
|
|
|
|
// coordinate is returned separately.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Vector GraphicsWindow::ProjectPoint4(Vector p, double *w) {
|
2008-04-12 14:12:26 +00:00
|
|
|
p = p.Plus(offset);
|
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
Vector r;
|
|
|
|
r.x = p.Dot(projRight);
|
|
|
|
r.y = p.Dot(projUp);
|
|
|
|
r.z = p.Dot(projUp.Cross(projRight));
|
|
|
|
|
|
|
|
*w = 1 + r.z*SS.cameraTangent*scale;
|
2008-04-12 14:12:26 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
void GraphicsWindow::AnimateOntoWorkplane(void) {
|
|
|
|
if(!LockedInWorkplane()) return;
|
|
|
|
|
|
|
|
Entity *w = SS.GetEntity(ActiveWorkplane());
|
|
|
|
Quaternion quatf = w->Normal()->NormalGetNum();
|
|
|
|
Vector offsetf = (SS.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1);
|
|
|
|
|
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.
|
2008-05-11 10:40:37 +00:00
|
|
|
SDWORD dt = (mp < 0.01 && mo < 10) ? (-20) :
|
|
|
|
(SDWORD)(100 + 1000*mp + 0.4*mo);
|
2008-04-25 08:26:15 +00:00
|
|
|
SDWORD tn, t0 = GetMilliseconds();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
void GraphicsWindow::HandlePointForZoomToFit(Vector p,
|
2008-06-17 19:12:25 +00:00
|
|
|
Point2d *pmax, Point2d *pmin, double *wmin, bool div)
|
2008-06-11 04:22:52 +00:00
|
|
|
{
|
2008-06-17 19:12:25 +00:00
|
|
|
double w;
|
|
|
|
Vector pp = ProjectPoint4(p, &w);
|
|
|
|
if(div) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
void GraphicsWindow::LoopOverPoints(
|
|
|
|
Point2d *pmax, Point2d *pmin, double *wmin, bool div)
|
|
|
|
{
|
|
|
|
HandlePointForZoomToFit(Vector::From(0, 0, 0), pmax, pmin, wmin, div);
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2008-06-17 19:12:25 +00:00
|
|
|
int i, j;
|
2008-06-11 04:22:52 +00:00
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
|
|
|
Entity *e = &(SS.entity.elem[i]);
|
|
|
|
if(!e->IsPoint()) continue;
|
|
|
|
if(!e->IsVisible()) continue;
|
2008-06-17 19:12:25 +00:00
|
|
|
HandlePointForZoomToFit(e->PointGetNum(), pmax, pmin, wmin, div);
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
Group *g = SS.GetGroup(activeGroup);
|
2008-06-21 10:18:20 +00:00
|
|
|
for(i = 0; i < g->runningMesh.l.n; i++) {
|
|
|
|
STriangle *tr = &(g->runningMesh.l.elem[i]);
|
2008-06-17 19:12:25 +00:00
|
|
|
HandlePointForZoomToFit(tr->a, pmax, pmin, wmin, div);
|
|
|
|
HandlePointForZoomToFit(tr->b, pmax, pmin, wmin, div);
|
|
|
|
HandlePointForZoomToFit(tr->c, pmax, pmin, wmin, div);
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < g->poly.l.n; i++) {
|
|
|
|
SContour *sc = &(g->poly.l.elem[i]);
|
|
|
|
for(j = 0; j < sc->l.n; j++) {
|
2008-06-17 19:12:25 +00:00
|
|
|
HandlePointForZoomToFit(sc->l.elem[j].p, pmax, pmin, wmin, div);
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-17 19:12:25 +00:00
|
|
|
}
|
|
|
|
void GraphicsWindow::ZoomToFit(void) {
|
|
|
|
// On the first run, ignore perspective.
|
|
|
|
Point2d pmax = { -1e12, -1e12 }, pmin = { 1e12, 1e12 };
|
|
|
|
double wmin = 1;
|
|
|
|
LoopOverPoints(&pmax, &pmin, &wmin, false);
|
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));
|
2008-06-17 19:12:25 +00:00
|
|
|
|
|
|
|
// And based on this, we calculate the scale and offset
|
2008-06-11 04:22:52 +00:00
|
|
|
if(dx == 0 && dy == 0) {
|
|
|
|
scale = 5;
|
|
|
|
} else {
|
|
|
|
double scalex = 1e12, scaley = 1e12;
|
|
|
|
if(dx != 0) scalex = 0.9*width /dx;
|
|
|
|
if(dy != 0) scaley = 0.9*height/dy;
|
2008-06-17 19:12:25 +00:00
|
|
|
scale = min(scalex, scaley);
|
|
|
|
|
|
|
|
scale = min(100, scale);
|
|
|
|
scale = max(0.001, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then do another run, considering the perspective.
|
|
|
|
pmax.x = -1e12; pmax.y = -1e12;
|
|
|
|
pmin.x = 1e12; pmin.y = 1e12;
|
|
|
|
wmin = 1;
|
|
|
|
LoopOverPoints(&pmax, &pmin, &wmin, true);
|
|
|
|
|
|
|
|
// Adjust the scale so that no points are behind the camera
|
|
|
|
if(wmin < 0.1) {
|
|
|
|
double k = SS.cameraTangent;
|
|
|
|
// 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;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_ZOOM_OUT:
|
|
|
|
SS.GW.scale /= 1.2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_ZOOM_TO_FIT:
|
2008-06-11 04:22:52 +00:00
|
|
|
SS.GW.ZoomToFit();
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
case MNU_SHOW_TEXT_WND:
|
|
|
|
SS.GW.showTextWindow = !SS.GW.showTextWindow;
|
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
2008-04-22 13:14:15 +00:00
|
|
|
case MNU_UNITS_MM:
|
2008-06-14 09:51:25 +00:00
|
|
|
SS.viewUnits = SolveSpace::UNIT_MM;
|
2008-06-14 23:31:36 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-22 13:14:15 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_UNITS_INCHES:
|
2008-06-14 09:51:25 +00:00
|
|
|
SS.viewUnits = SolveSpace::UNIT_INCHES;
|
2008-06-14 23:31:36 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-22 13:14:15 +00:00
|
|
|
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.
|
2008-04-13 10:57:41 +00:00
|
|
|
Group *g = SS.group.FindByIdNoOops(activeGroup);
|
2008-04-18 07:06:37 +00:00
|
|
|
if((!g) || (g->h.v == Group::HGROUP_REFERENCES.v)) {
|
|
|
|
int i;
|
2008-04-18 11:11:48 +00:00
|
|
|
for(i = 0; i < SS.group.n; i++) {
|
2008-04-18 07:21:17 +00:00
|
|
|
if(SS.group.elem[i].h.v != Group::HGROUP_REFERENCES.v) {
|
2008-04-18 07:06:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-02 11:43:27 +00:00
|
|
|
if(i >= SS.group.n) {
|
|
|
|
// 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 {
|
|
|
|
activeGroup = SS.group.elem[i].h;
|
|
|
|
}
|
2008-06-02 05:38:12 +00:00
|
|
|
SS.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()) {
|
|
|
|
Entity *e = SS.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();
|
|
|
|
CheckMenuById(MNU_FREE_IN_3D, !locked);
|
|
|
|
CheckMenuById(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) {
|
|
|
|
case SolveSpace::UNIT_MM:
|
|
|
|
case SolveSpace::UNIT_INCHES:
|
2008-04-22 13:14:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-06-14 09:51:25 +00:00
|
|
|
SS.viewUnits = SolveSpace::UNIT_MM;
|
2008-04-22 13:14:15 +00:00
|
|
|
}
|
2008-06-14 09:51:25 +00:00
|
|
|
CheckMenuById(MNU_UNITS_MM, SS.viewUnits == SolveSpace::UNIT_MM);
|
|
|
|
CheckMenuById(MNU_UNITS_INCHES, SS.viewUnits == SolveSpace::UNIT_INCHES);
|
2008-04-27 05:00:12 +00:00
|
|
|
|
|
|
|
ShowTextWindow(SS.GW.showTextWindow);
|
|
|
|
CheckMenuById(MNU_SHOW_TEXT_WND, SS.GW.showTextWindow);
|
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
if(change) SS.later.showTW = true;
|
2008-04-13 10:57:41 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
void GraphicsWindow::SetWorkplaneFreeIn3d(void) {
|
|
|
|
SS.GetGroup(activeGroup)->activeWorkplane = Entity::FREE_IN_3D;
|
|
|
|
}
|
|
|
|
hEntity GraphicsWindow::ActiveWorkplane(void) {
|
2008-06-01 00:26:41 +00:00
|
|
|
Group *g = SS.group.FindByIdNoOops(activeGroup);
|
|
|
|
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-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();
|
|
|
|
if(SS.GW.gs.n == 0 && SS.GW.pending.operation == 0) {
|
2008-06-02 11:43:27 +00:00
|
|
|
if(!TextEditControlIsVisible()) {
|
|
|
|
SS.TW.ClearSuper();
|
|
|
|
}
|
2008-06-01 04:31:28 +00:00
|
|
|
}
|
2008-06-01 00:26:41 +00:00
|
|
|
SS.GW.ClearSuper();
|
2008-05-27 06:36:59 +00:00
|
|
|
HideTextEditControl();
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
case MNU_DELETE: {
|
|
|
|
int i;
|
|
|
|
SS.request.ClearTags();
|
2008-04-21 08:16:38 +00:00
|
|
|
SS.constraint.ClearTags();
|
2008-04-14 10:28:32 +00:00
|
|
|
for(i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
Selection *s = &(SS.GW.selection[i]);
|
2008-04-21 08:16:38 +00:00
|
|
|
hRequest r; r.v = 0;
|
2008-04-27 09:03:01 +00:00
|
|
|
if(s->entity.v && s->entity.isFromRequest()) {
|
2008-04-19 11:09:47 +00:00
|
|
|
r = s->entity.request();
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
2008-04-25 07:04:09 +00:00
|
|
|
if(r.v && !r.IsFromReferences()) {
|
|
|
|
SS.request.Tag(r, 1);
|
|
|
|
}
|
2008-04-21 08:16:38 +00:00
|
|
|
if(s->constraint.v) {
|
|
|
|
SS.constraint.Tag(s->constraint, 1);
|
|
|
|
}
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
|
|
|
SS.request.RemoveTagged();
|
2008-04-21 08:16:38 +00:00
|
|
|
SS.constraint.RemoveTagged();
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-06-01 00:26:41 +00:00
|
|
|
// An edit might be in progress for the just-deleted item. So
|
|
|
|
// now it's not.
|
2008-05-27 06:36:59 +00:00
|
|
|
HideGraphicsEditControl();
|
|
|
|
HideTextEditControl();
|
2008-06-01 00:26:41 +00:00
|
|
|
// And clear out the selection, which could contain that item.
|
|
|
|
SS.GW.ClearSuper();
|
2008-05-17 06:04:55 +00:00
|
|
|
// And regenerate to get rid of what it generates, plus anything
|
|
|
|
// that references it (since the regen code checks for that).
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll(0, INT_MAX);
|
2008-05-17 06:04:55 +00:00
|
|
|
SS.GW.EnsureValidActives();
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-14 10:28:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-04 10:22:30 +00:00
|
|
|
case MNU_UNDO:
|
|
|
|
SS.UndoUndo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_REDO:
|
|
|
|
SS.UndoRedo();
|
|
|
|
break;
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void GraphicsWindow::MenuRequest(int id) {
|
2008-04-13 10:57:41 +00:00
|
|
|
char *s;
|
|
|
|
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();
|
2008-06-06 11:35:28 +00:00
|
|
|
Group *g = SS.GetGroup(SS.GW.activeGroup);
|
|
|
|
|
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);
|
2008-04-25 08:26:15 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
2008-04-27 03:26:27 +00:00
|
|
|
Error("Select workplane (e.g., the XY plane) "
|
2008-04-18 07:06:37 +00:00
|
|
|
"before locking on.");
|
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();
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
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();
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-18 07:06:37 +00:00
|
|
|
break;
|
|
|
|
|
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;
|
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-12 10:01:44 +00:00
|
|
|
case MNU_ARC: s = "click point on arc (draws anti-clockwise)"; goto c;
|
2008-05-05 11:17:00 +00:00
|
|
|
case MNU_WORKPLANE: s = "click origin of workplane"; goto c;
|
2008-05-07 04:17:29 +00:00
|
|
|
case MNU_RECTANGLE: s = "click one corner of rectangular"; 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;
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-12 15:17:58 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-07 04:17:29 +00:00
|
|
|
case MNU_CONSTRUCTION: {
|
|
|
|
SS.GW.GroupSelection();
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.GW.gs.entities; i++) {
|
|
|
|
hEntity he = SS.GW.gs.entity[i];
|
|
|
|
if(!he.isFromRequest()) continue;
|
|
|
|
Request *r = SS.GetRequest(he.request());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
void GraphicsWindow::ToggleBool(int link, DWORD v) {
|
|
|
|
bool *vb = (bool *)v;
|
|
|
|
*vb = !*vb;
|
|
|
|
|
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.
|
|
|
|
if(!SS.GW.showShaded) SS.GW.showFaces = false;
|
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll();
|
2008-04-11 12:47:14 +00:00
|
|
|
InvalidateGraphics();
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-11 12:47:14 +00:00
|
|
|
}
|
|
|
|
|