2008-03-26 09:18:12 +00:00
|
|
|
#include <stdarg.h>
|
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 },
|
|
|
|
{ 1, "E&xit", MNU_EXIT, 0, mFile },
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
{ 0, "&Edit", 0, NULL },
|
|
|
|
{ 1, "&Undo\tCtrl+Z", 0, NULL },
|
|
|
|
{ 1, "&Redo\tCtrl+Y", 0, NULL },
|
|
|
|
{ 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-05-28 10:10:31 +00:00
|
|
|
{ 0, "&New Feature", 0, 0, NULL },
|
|
|
|
{ 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-05-28 10:10:31 +00:00
|
|
|
{ 1, "Extrusion\tShift+Ctrl+X", MNU_GROUP_EXTRUDE, 'X'|S|C,mGrp },
|
2008-04-22 10:53:42 +00:00
|
|
|
{ 1, NULL, 0, 0, NULL },
|
2008-05-28 10:10:31 +00:00
|
|
|
{ 1, "Import...\tShift+Ctrl+I", MNU_GROUP_IMPORT, 'I'|S|C,mGrp },
|
|
|
|
{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 },
|
|
|
|
{ 1, "Sym&bolic Variable\tB", 0, 'B', mReq },
|
|
|
|
{ 1, "&Import From File...\tI", 0, 'I', mReq },
|
|
|
|
{ 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-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 },
|
|
|
|
{ 1, "Same O&rientation\tShift+R", MNU_ORIENTED_SAME, 'R'|S, mCon },
|
2008-04-13 10:57:41 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
|
|
|
{ 1, "Sym&bolic Equation\tShift+B", 0, 'B'|S, NULL },
|
2008-04-20 11:35:10 +00:00
|
|
|
{ 1, NULL, 0, NULL },
|
|
|
|
{ 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));
|
|
|
|
|
|
|
|
offset.x = offset.y = offset.z = 0;
|
2008-05-11 10:40:37 +00:00
|
|
|
scale = 5;
|
2008-03-27 09:53:51 +00:00
|
|
|
projRight.x = 1; projRight.y = projRight.z = 0;
|
2008-04-12 15:17:58 +00:00
|
|
|
projUp.y = 1; projUp.z = projUp.x = 0;
|
2008-03-27 09:53:51 +00:00
|
|
|
|
2008-06-02 05:38:12 +00:00
|
|
|
// And with the latest visible group active, or failing that the first
|
|
|
|
// group after the references
|
2008-05-25 13:11:44 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.group.n; i++) {
|
|
|
|
Group *g = &(SS.group.elem[i]);
|
2008-06-02 05:38:12 +00:00
|
|
|
if(i == 1 || g->visible) activeGroup = g->h;
|
2008-05-25 13:11:44 +00:00
|
|
|
}
|
2008-06-02 05:38:12 +00:00
|
|
|
SS.GetGroup(activeGroup)->Activate();
|
2008-05-25 13:11:44 +00:00
|
|
|
|
|
|
|
EnsureValidActives();
|
|
|
|
|
2008-04-27 03:26:27 +00:00
|
|
|
showWorkplanes = true;
|
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-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-04-12 14:12:26 +00:00
|
|
|
Point2d GraphicsWindow::ProjectPoint(Vector p) {
|
|
|
|
p = p.Plus(offset);
|
|
|
|
|
|
|
|
Point2d r;
|
|
|
|
r.x = p.Dot(projRight) * scale;
|
2008-04-12 15:17:58 +00:00
|
|
|
r.y = p.Dot(projUp) * 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-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:
|
|
|
|
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:
|
|
|
|
SS.GW.viewUnits = UNIT_MM;
|
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_UNITS_INCHES:
|
|
|
|
SS.GW.viewUnits = UNIT_INCHES;
|
|
|
|
SS.GW.EnsureValidActives();
|
|
|
|
break;
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
2008-06-01 00:26:41 +00:00
|
|
|
char *GraphicsWindow::ToString(double v) {
|
|
|
|
static int WhichBuf;
|
|
|
|
static char Bufs[8][128];
|
|
|
|
|
|
|
|
WhichBuf++;
|
|
|
|
if(WhichBuf >= 8 || WhichBuf < 0) WhichBuf = 0;
|
|
|
|
|
|
|
|
char *s = Bufs[WhichBuf];
|
|
|
|
sprintf(s, "%.3f", v);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
double GraphicsWindow::FromString(char *s) {
|
|
|
|
return atof(s);
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
|
|
|
// And update the checked state for various menus
|
|
|
|
switch(viewUnits) {
|
|
|
|
case UNIT_MM:
|
|
|
|
case UNIT_INCHES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
viewUnits = UNIT_MM;
|
|
|
|
}
|
|
|
|
CheckMenuById(MNU_UNITS_MM, viewUnits == UNIT_MM);
|
|
|
|
CheckMenuById(MNU_UNITS_INCHES, viewUnits == 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-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-04-27 03:26:27 +00:00
|
|
|
if(SS.GW.gs.n == 1 && SS.GW.gs.workplanes == 1) {
|
2008-05-27 02:22:20 +00:00
|
|
|
SS.GetGroup(SS.GW.activeGroup)->activeWorkplane =
|
|
|
|
SS.GW.gs.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-05 06:18:01 +00:00
|
|
|
void GraphicsWindow::UpdateDraggedPoint(hEntity hp, double mx, double my) {
|
2008-04-19 11:09:47 +00:00
|
|
|
Entity *p = SS.GetEntity(hp);
|
2008-05-05 06:18:01 +00:00
|
|
|
Vector pos = p->PointGetNum();
|
|
|
|
UpdateDraggedNum(&pos, mx, my);
|
2008-04-19 11:44:44 +00:00
|
|
|
p->PointForceTo(pos);
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
void GraphicsWindow::UpdateDraggedNum(Vector *pos, double mx, double my) {
|
2008-04-14 10:28:32 +00:00
|
|
|
*pos = pos->Plus(projRight.ScaledBy((mx - orig.mouse.x)/scale));
|
|
|
|
*pos = pos->Plus(projUp.ScaledBy((my - orig.mouse.y)/scale));
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
orig.mouse.x = mx;
|
|
|
|
orig.mouse.y = my;
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
|
|
|
|
bool middleDown, bool rightDown, bool shiftDown, bool ctrlDown)
|
|
|
|
{
|
2008-04-21 10:12:04 +00:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
Point2d mp = { x, y };
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
// If the middle button is down, then mouse movement is used to pan and
|
|
|
|
// rotate our view. This wins over everything else.
|
2008-03-27 09:53:51 +00:00
|
|
|
if(middleDown) {
|
2008-04-12 14:12:26 +00:00
|
|
|
hover.Clear();
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
double dx = (x - orig.mouse.x) / scale;
|
|
|
|
double dy = (y - orig.mouse.y) / scale;
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
// When the view is locked, permit only translation (pan).
|
2008-04-25 08:26:15 +00:00
|
|
|
if(!(shiftDown || ctrlDown)) {
|
2008-04-12 15:17:58 +00:00
|
|
|
offset.x = orig.offset.x + dx*projRight.x + dy*projUp.x;
|
|
|
|
offset.y = orig.offset.y + dx*projRight.y + dy*projUp.y;
|
|
|
|
offset.z = orig.offset.z + dx*projRight.z + dy*projUp.z;
|
2008-04-25 08:26:15 +00:00
|
|
|
} else if(ctrlDown) {
|
2008-03-27 09:53:51 +00:00
|
|
|
double theta = atan2(orig.mouse.y, orig.mouse.x);
|
|
|
|
theta -= atan2(y, x);
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
Vector normal = orig.projRight.Cross(orig.projUp);
|
2008-03-27 09:53:51 +00:00
|
|
|
projRight = orig.projRight.RotatedAbout(normal, theta);
|
2008-04-12 15:17:58 +00:00
|
|
|
projUp = orig.projUp.RotatedAbout(normal, theta);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
|
|
|
NormalizeProjectionVectors();
|
2008-04-25 08:26:15 +00:00
|
|
|
} else {
|
2008-05-05 06:18:01 +00:00
|
|
|
double s = 0.3*(PI/180)*scale; // degrees per pixel
|
2008-04-12 15:17:58 +00:00
|
|
|
projRight = orig.projRight.RotatedAbout(orig.projUp, -s*dx);
|
|
|
|
projUp = orig.projUp.RotatedAbout(orig.projRight, s*dy);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
|
|
|
NormalizeProjectionVectors();
|
|
|
|
}
|
|
|
|
|
2008-04-11 11:13:47 +00:00
|
|
|
orig.projRight = projRight;
|
2008-04-12 15:17:58 +00:00
|
|
|
orig.projUp = projUp;
|
2008-04-11 11:13:47 +00:00
|
|
|
orig.offset = offset;
|
|
|
|
orig.mouse.x = x;
|
|
|
|
orig.mouse.y = y;
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
InvalidateGraphics();
|
2008-04-25 12:07:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
|
|
|
|
if(pending.operation == 0) {
|
|
|
|
double dm = orig.mouse.DistanceTo(mp);
|
|
|
|
// If we're currently not doing anything, then see if we should
|
|
|
|
// start dragging something.
|
|
|
|
if(leftDown && dm > 3) {
|
|
|
|
if(hover.entity.v) {
|
|
|
|
Entity *e = SS.GetEntity(hover.entity);
|
|
|
|
if(e->IsPoint()) {
|
|
|
|
// Start dragging this point.
|
|
|
|
ClearSelection();
|
|
|
|
pending.point = hover.entity;
|
|
|
|
pending.operation = DRAGGING_POINT;
|
|
|
|
} else if(e->type == Entity::CIRCLE) {
|
|
|
|
// Drag the radius.
|
|
|
|
ClearSelection();
|
|
|
|
pending.circle = hover.entity;
|
|
|
|
pending.operation = DRAGGING_RADIUS;
|
|
|
|
} else if(e->IsNormal()) {
|
|
|
|
ClearSelection();
|
|
|
|
pending.normal = hover.entity;
|
|
|
|
pending.operation = DRAGGING_NORMAL;
|
|
|
|
}
|
|
|
|
} else if(hover.constraint.v &&
|
|
|
|
SS.GetConstraint(hover.constraint)->HasLabel())
|
|
|
|
{
|
|
|
|
ClearSelection();
|
|
|
|
pending.constraint = hover.constraint;
|
|
|
|
pending.operation = DRAGGING_CONSTRAINT;
|
|
|
|
}
|
|
|
|
} else {
|
2008-06-01 00:26:41 +00:00
|
|
|
// Otherwise, just hit test and give up; but don't hit test
|
|
|
|
// if the mouse is down, because then the user could hover
|
|
|
|
// a point, mouse down (thus selecting it), and drag, in an
|
|
|
|
// effort to drag the point, but instead hover a different
|
|
|
|
// entity before we move far enough to start the drag.
|
|
|
|
if(!leftDown) HitTestMakeSelection(mp);
|
2008-04-28 09:40:02 +00:00
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
return;
|
2008-04-25 12:07:17 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
// If the user has started an operation from the menu, but not
|
|
|
|
// completed it, then just do the selection.
|
|
|
|
if(pending.operation < FIRST_PENDING) {
|
2008-04-25 12:07:17 +00:00
|
|
|
HitTestMakeSelection(mp);
|
2008-05-05 06:18:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-04-25 12:07:17 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
// We're currently dragging something; so do that. But if we haven't
|
|
|
|
// painted since the last time we solved, do nothing, because there's
|
|
|
|
// no sense solving a frame and not displaying it.
|
|
|
|
if(!havePainted) return;
|
|
|
|
switch(pending.operation) {
|
|
|
|
case DRAGGING_CONSTRAINT: {
|
|
|
|
Constraint *c = SS.constraint.FindById(pending.constraint);
|
|
|
|
UpdateDraggedNum(&(c->disp.offset), x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DRAGGING_NEW_LINE_POINT:
|
|
|
|
HitTestMakeSelection(mp);
|
|
|
|
// and fall through
|
|
|
|
case DRAGGING_NEW_POINT:
|
2008-05-11 06:09:46 +00:00
|
|
|
case DRAGGING_POINT: {
|
|
|
|
Entity *p = SS.GetEntity(pending.point);
|
|
|
|
if((p->type == Entity::POINT_N_ROT_TRANS) &&
|
|
|
|
(shiftDown || ctrlDown))
|
|
|
|
{
|
|
|
|
// These points also come with a rotation, which the user can
|
|
|
|
// edit by pressing shift or control.
|
|
|
|
Quaternion q = p->PointGetQuaternion();
|
|
|
|
Vector p3 = p->PointGetNum();
|
|
|
|
Point2d p2 = ProjectPoint(p3);
|
|
|
|
|
|
|
|
Vector u = q.RotationU(), v = q.RotationV();
|
|
|
|
if(ctrlDown) {
|
|
|
|
double d = mp.DistanceTo(p2);
|
|
|
|
if(d < 25) {
|
|
|
|
// Don't start dragging the position about the normal
|
|
|
|
// until we're a little ways out, to get a reasonable
|
|
|
|
// reference pos
|
|
|
|
orig.mouse = mp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
double theta = atan2(orig.mouse.y-p2.y, orig.mouse.x-p2.x);
|
|
|
|
theta -= atan2(y-p2.y, x-p2.x);
|
|
|
|
|
|
|
|
Vector gn = projRight.Cross(projUp);
|
|
|
|
u = u.RotatedAbout(gn, -theta);
|
|
|
|
v = v.RotatedAbout(gn, -theta);
|
|
|
|
} else {
|
|
|
|
double dx = -(x - orig.mouse.x);
|
|
|
|
double dy = -(y - orig.mouse.y);
|
|
|
|
double s = 0.3*(PI/180); // degrees per pixel
|
2008-06-03 18:28:41 +00:00
|
|
|
u = u.RotatedAbout(projUp, -s*dx);
|
|
|
|
u = u.RotatedAbout(projRight, s*dy);
|
|
|
|
v = v.RotatedAbout(projUp, -s*dx);
|
|
|
|
v = v.RotatedAbout(projRight, s*dy);
|
2008-05-11 06:09:46 +00:00
|
|
|
}
|
2008-06-01 08:45:11 +00:00
|
|
|
q = Quaternion::From(u, v);
|
2008-05-11 06:09:46 +00:00
|
|
|
p->PointForceQuaternionTo(q);
|
|
|
|
// Let's rotate about the selected point; so fix up the
|
|
|
|
// translation so that that point didn't move.
|
|
|
|
p->PointForceTo(p3);
|
|
|
|
orig.mouse = mp;
|
|
|
|
} else {
|
|
|
|
UpdateDraggedPoint(pending.point, x, y);
|
2008-05-12 10:01:44 +00:00
|
|
|
HitTestMakeSelection(mp);
|
2008-05-11 06:09:46 +00:00
|
|
|
}
|
2008-06-02 11:43:27 +00:00
|
|
|
SS.MarkGroupDirtyByEntity(pending.point);
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
2008-05-11 06:09:46 +00:00
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
case DRAGGING_NEW_CUBIC_POINT: {
|
|
|
|
UpdateDraggedPoint(pending.point, x, y);
|
|
|
|
HitTestMakeSelection(mp);
|
|
|
|
|
|
|
|
hRequest hr = pending.point.request();
|
|
|
|
Vector p0 = SS.GetEntity(hr.entity(1))->PointGetNum();
|
|
|
|
Vector p3 = SS.GetEntity(hr.entity(4))->PointGetNum();
|
|
|
|
Vector p1 = p0.ScaledBy(2.0/3).Plus(p3.ScaledBy(1.0/3));
|
|
|
|
SS.GetEntity(hr.entity(2))->PointForceTo(p1);
|
|
|
|
Vector p2 = p0.ScaledBy(1.0/3).Plus(p3.ScaledBy(2.0/3));
|
|
|
|
SS.GetEntity(hr.entity(3))->PointForceTo(p2);
|
2008-06-02 11:43:27 +00:00
|
|
|
|
|
|
|
SS.MarkGroupDirtyByEntity(pending.point);
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-12 10:01:44 +00:00
|
|
|
case DRAGGING_NEW_ARC_POINT: {
|
|
|
|
UpdateDraggedPoint(pending.point, x, y);
|
|
|
|
HitTestMakeSelection(mp);
|
|
|
|
|
|
|
|
hRequest hr = pending.point.request();
|
|
|
|
Vector ona = SS.GetEntity(hr.entity(2))->PointGetNum();
|
|
|
|
Vector onb = SS.GetEntity(hr.entity(3))->PointGetNum();
|
|
|
|
Vector center = (ona.Plus(onb)).ScaledBy(0.5);
|
|
|
|
|
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(center);
|
2008-06-02 11:43:27 +00:00
|
|
|
|
|
|
|
SS.MarkGroupDirtyByEntity(pending.point);
|
2008-05-12 10:01:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
case DRAGGING_NEW_RADIUS:
|
|
|
|
case DRAGGING_RADIUS: {
|
|
|
|
Entity *circle = SS.GetEntity(pending.circle);
|
|
|
|
Vector center = SS.GetEntity(circle->point[0])->PointGetNum();
|
|
|
|
Point2d c2 = ProjectPoint(center);
|
2008-05-11 10:40:37 +00:00
|
|
|
double r = c2.DistanceTo(mp)/scale;
|
2008-05-07 08:19:37 +00:00
|
|
|
SS.GetEntity(circle->distance)->DistanceForceTo(r);
|
2008-06-02 11:43:27 +00:00
|
|
|
|
|
|
|
SS.MarkGroupDirtyByEntity(pending.circle);
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DRAGGING_NORMAL: {
|
|
|
|
Entity *normal = SS.GetEntity(pending.normal);
|
|
|
|
Vector p = SS.GetEntity(normal->point[0])->PointGetNum();
|
|
|
|
Point2d p2 = ProjectPoint(p);
|
|
|
|
|
|
|
|
Quaternion q = normal->NormalGetNum();
|
|
|
|
Vector u = q.RotationU(), v = q.RotationV();
|
|
|
|
|
|
|
|
if(ctrlDown) {
|
|
|
|
double theta = atan2(orig.mouse.y-p2.y, orig.mouse.x-p2.x);
|
|
|
|
theta -= atan2(y-p2.y, x-p2.x);
|
|
|
|
|
|
|
|
Vector normal = orig.projRight.Cross(orig.projUp);
|
|
|
|
u = u.RotatedAbout(normal, -theta);
|
|
|
|
v = v.RotatedAbout(normal, -theta);
|
|
|
|
} else {
|
2008-05-05 11:17:00 +00:00
|
|
|
double dx = -(x - orig.mouse.x);
|
|
|
|
double dy = -(y - orig.mouse.y);
|
2008-05-05 06:18:01 +00:00
|
|
|
double s = 0.3*(PI/180); // degrees per pixel
|
|
|
|
u = u.RotatedAbout(orig.projUp, -s*dx);
|
|
|
|
u = u.RotatedAbout(orig.projRight, s*dy);
|
|
|
|
v = v.RotatedAbout(orig.projUp, -s*dx);
|
|
|
|
v = v.RotatedAbout(orig.projRight, s*dy);
|
|
|
|
}
|
|
|
|
orig.mouse = mp;
|
2008-06-01 08:45:11 +00:00
|
|
|
normal->NormalForceTo(Quaternion::From(u, v));
|
2008-06-02 11:43:27 +00:00
|
|
|
|
|
|
|
SS.MarkGroupDirtyByEntity(pending.normal);
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: oops();
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
2008-05-26 09:56:50 +00:00
|
|
|
if(pending.operation != 0 && pending.operation != DRAGGING_CONSTRAINT) {
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll();
|
2008-05-26 09:56:50 +00:00
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
havePainted = false;
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::Selection::Equals(Selection *b) {
|
2008-04-14 10:28:32 +00:00
|
|
|
if(entity.v != b->entity.v) return false;
|
|
|
|
if(constraint.v != b->constraint.v) return false;
|
2008-04-12 14:12:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool GraphicsWindow::Selection::IsEmpty(void) {
|
2008-04-14 10:28:32 +00:00
|
|
|
if(entity.v) return false;
|
|
|
|
if(constraint.v) return false;
|
2008-04-12 14:12:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void GraphicsWindow::Selection::Clear(void) {
|
2008-04-19 11:09:47 +00:00
|
|
|
entity.v = constraint.v = 0;
|
2008-05-26 09:56:50 +00:00
|
|
|
emphasized = false;
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
void GraphicsWindow::Selection::Draw(void) {
|
2008-05-26 09:56:50 +00:00
|
|
|
Vector refp;
|
|
|
|
if(entity.v) {
|
|
|
|
Entity *e = SS.GetEntity(entity);
|
|
|
|
e->Draw(-1);
|
|
|
|
if(emphasized) refp = e->GetReferencePos();
|
|
|
|
}
|
|
|
|
if(constraint.v) {
|
|
|
|
Constraint *c = SS.GetConstraint(constraint);
|
|
|
|
c->Draw();
|
|
|
|
if(emphasized) refp = c->GetReferencePos();
|
|
|
|
}
|
|
|
|
if(emphasized && (constraint.v || entity.v)) {
|
|
|
|
double s = 0.501/SS.GW.scale;
|
|
|
|
Vector topLeft = SS.GW.projRight.ScaledBy(-SS.GW.width*s);
|
|
|
|
topLeft = topLeft.Plus(SS.GW.projUp.ScaledBy(SS.GW.height*s));
|
|
|
|
topLeft = topLeft.Minus(SS.GW.offset);
|
|
|
|
|
|
|
|
glLineWidth(40);
|
|
|
|
glColor4d(1.0, 1.0, 0, 0.2);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glxVertex3v(topLeft);
|
|
|
|
glxVertex3v(refp);
|
|
|
|
glEnd();
|
|
|
|
glLineWidth(1);
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
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-05-05 06:18:01 +00:00
|
|
|
void GraphicsWindow::ClearPending(void) {
|
|
|
|
memset(&pending, 0, sizeof(pending));
|
|
|
|
}
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
void GraphicsWindow::HitTestMakeSelection(Point2d mp) {
|
2008-04-12 14:12:26 +00:00
|
|
|
int i;
|
|
|
|
double d, dmin = 1e12;
|
2008-04-23 07:29:19 +00:00
|
|
|
Selection s;
|
|
|
|
memset(&s, 0, sizeof(s));
|
2008-04-12 14:12:26 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
// Do the entities
|
2008-04-18 11:11:48 +00:00
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
2008-04-23 07:29:19 +00:00
|
|
|
Entity *e = &(SS.entity.elem[i]);
|
|
|
|
// Don't hover whatever's being dragged.
|
2008-05-05 06:18:01 +00:00
|
|
|
if(e->h.request().v == pending.point.request().v) continue;
|
2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
d = e->GetDistance(mp);
|
2008-04-12 14:12:26 +00:00
|
|
|
if(d < 10 && d < dmin) {
|
2008-04-23 07:29:19 +00:00
|
|
|
memset(&s, 0, sizeof(s));
|
|
|
|
s.entity = e->h;
|
2008-04-19 11:09:47 +00:00
|
|
|
dmin = d;
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
2008-04-14 10:28:32 +00:00
|
|
|
|
|
|
|
// Constraints
|
2008-04-18 11:11:48 +00:00
|
|
|
for(i = 0; i < SS.constraint.n; i++) {
|
2008-04-18 07:21:17 +00:00
|
|
|
d = SS.constraint.elem[i].GetDistance(mp);
|
2008-04-14 10:28:32 +00:00
|
|
|
if(d < 10 && d < dmin) {
|
2008-04-23 07:29:19 +00:00
|
|
|
memset(&s, 0, sizeof(s));
|
|
|
|
s.constraint = SS.constraint.elem[i].h;
|
2008-04-19 11:09:47 +00:00
|
|
|
dmin = d;
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-23 07:29:19 +00:00
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
// Faces, from the triangle mesh; these are lowest priority
|
2008-06-02 05:38:12 +00:00
|
|
|
if(s.constraint.v == 0 && s.entity.v == 0 && showShaded && showFaces) {
|
2008-06-02 03:31:37 +00:00
|
|
|
SMesh *m = &((SS.GetGroup(activeGroup))->mesh);
|
|
|
|
DWORD v = m->FirstIntersectionWith(mp);
|
|
|
|
if(v) {
|
|
|
|
s.entity.v = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
if(!s.Equals(&hover)) {
|
|
|
|
hover = s;
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
void GraphicsWindow::ClearSelection(void) {
|
|
|
|
for(int i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
selection[i].Clear();
|
|
|
|
}
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-12 15:17:58 +00:00
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
void GraphicsWindow::ClearNonexistentSelectionItems(void) {
|
|
|
|
bool change = false;
|
|
|
|
for(int i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
Selection *s = &(selection[i]);
|
|
|
|
if(s->constraint.v && !(SS.constraint.FindByIdNoOops(s->constraint))) {
|
|
|
|
s->constraint.v = 0;
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
if(s->entity.v && !(SS.entity.FindByIdNoOops(s->entity))) {
|
|
|
|
s->entity.v = 0;
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(change) InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:17:58 +00:00
|
|
|
void GraphicsWindow::GroupSelection(void) {
|
2008-04-21 08:16:38 +00:00
|
|
|
memset(&gs, 0, sizeof(gs));
|
2008-04-12 15:17:58 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
Selection *s = &(selection[i]);
|
|
|
|
if(s->entity.v) {
|
|
|
|
(gs.n)++;
|
|
|
|
|
|
|
|
Entity *e = SS.entity.FindById(s->entity);
|
2008-05-09 05:33:23 +00:00
|
|
|
// A list of points, and a list of all entities that aren't points.
|
2008-04-21 08:16:38 +00:00
|
|
|
if(e->IsPoint()) {
|
|
|
|
gs.point[(gs.points)++] = s->entity;
|
|
|
|
} else {
|
|
|
|
gs.entity[(gs.entities)++] = s->entity;
|
|
|
|
}
|
2008-05-09 05:33:23 +00:00
|
|
|
|
|
|
|
// And an auxiliary list of normals, including normals from
|
|
|
|
// workplanes.
|
|
|
|
if(e->IsNormal()) {
|
|
|
|
gs.anyNormal[(gs.anyNormals)++] = s->entity;
|
|
|
|
} else if(e->IsWorkplane()) {
|
|
|
|
gs.anyNormal[(gs.anyNormals)++] = e->Normal()->h;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And of vectors (i.e., stuff with a direction to constrain)
|
|
|
|
if(e->HasVector()) {
|
|
|
|
gs.vector[(gs.vectors)++] = s->entity;
|
|
|
|
}
|
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
// Faces (which are special, associated/drawn with triangles)
|
|
|
|
if(e->IsFace()) {
|
|
|
|
gs.face[(gs.faces)++] = s->entity;
|
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
// And some aux counts too
|
2008-04-14 10:28:32 +00:00
|
|
|
switch(e->type) {
|
2008-04-27 03:26:27 +00:00
|
|
|
case Entity::WORKPLANE: (gs.workplanes)++; break;
|
2008-04-14 10:28:32 +00:00
|
|
|
case Entity::LINE_SEGMENT: (gs.lineSegments)++; break;
|
2008-05-12 10:01:44 +00:00
|
|
|
|
|
|
|
case Entity::ARC_OF_CIRCLE:
|
2008-05-07 08:19:37 +00:00
|
|
|
case Entity::CIRCLE: (gs.circlesOrArcs)++; break;
|
2008-04-12 15:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-17 11:15:14 +00:00
|
|
|
if(s->constraint.v) {
|
|
|
|
gs.constraint[(gs.constraints)++] = s->constraint;
|
|
|
|
}
|
2008-04-12 15:17:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
void GraphicsWindow::MouseMiddleDown(double x, double y) {
|
2008-04-21 10:12:04 +00:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
orig.offset = offset;
|
2008-04-12 15:17:58 +00:00
|
|
|
orig.projUp = projUp;
|
2008-03-27 09:53:51 +00:00
|
|
|
orig.projRight = projRight;
|
|
|
|
orig.mouse.x = x;
|
|
|
|
orig.mouse.y = y;
|
|
|
|
}
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
hRequest GraphicsWindow::AddRequest(int type) {
|
|
|
|
Request r;
|
|
|
|
memset(&r, 0, sizeof(r));
|
|
|
|
r.group = activeGroup;
|
2008-06-01 08:29:59 +00:00
|
|
|
Group *g = SS.GetGroup(activeGroup);
|
|
|
|
if(g->type == Group::DRAWING_3D || g->type == Group::DRAWING_WORKPLANE) {
|
|
|
|
r.construction = false;
|
|
|
|
} else {
|
|
|
|
r.construction = true;
|
|
|
|
}
|
2008-05-27 02:22:20 +00:00
|
|
|
r.workplane = ActiveWorkplane();
|
2008-04-13 10:57:41 +00:00
|
|
|
r.type = type;
|
|
|
|
SS.request.AddAndAssignId(&r);
|
2008-05-08 07:30:30 +00:00
|
|
|
|
|
|
|
// We must regenerate the parameters, so that the code that tries to
|
|
|
|
// place this request's entities where the mouse is can do so. But
|
|
|
|
// we mustn't try to solve until reasonable values have been supplied
|
|
|
|
// for these new parameters, or else we'll get a numerical blowup.
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll(-1, -1);
|
2008-06-02 11:43:27 +00:00
|
|
|
SS.MarkGroupDirty(r.group);
|
2008-04-13 10:57:41 +00:00
|
|
|
return r.h;
|
|
|
|
}
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
bool GraphicsWindow::ConstrainPointByHovered(hEntity pt) {
|
|
|
|
if(!hover.entity.v) return false;
|
|
|
|
|
|
|
|
Entity *e = SS.GetEntity(hover.entity);
|
|
|
|
if(e->IsPoint()) {
|
|
|
|
Constraint::ConstrainCoincident(e->h, pt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(e->IsCircle()) {
|
|
|
|
Constraint::Constrain(Constraint::PT_ON_CIRCLE,
|
|
|
|
pt, Entity::NO_ENTITY, e->h);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(e->type == Entity::LINE_SEGMENT) {
|
|
|
|
Constraint::Constrain(Constraint::PT_ON_LINE,
|
|
|
|
pt, Entity::NO_ENTITY, e->h);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
void GraphicsWindow::MouseLeftDown(double mx, double my) {
|
2008-04-21 10:12:04 +00:00
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
// Make sure the hover is up to date.
|
2008-04-13 10:57:41 +00:00
|
|
|
MouseMoved(mx, my, false, false, false, false, false);
|
|
|
|
orig.mouse.x = mx;
|
|
|
|
orig.mouse.y = my;
|
|
|
|
|
|
|
|
// The current mouse location
|
|
|
|
Vector v = offset.ScaledBy(-1);
|
|
|
|
v = v.Plus(projRight.ScaledBy(mx/scale));
|
|
|
|
v = v.Plus(projUp.ScaledBy(my/scale));
|
|
|
|
|
|
|
|
hRequest hr;
|
2008-05-05 06:18:01 +00:00
|
|
|
switch(pending.operation) {
|
2008-04-13 10:57:41 +00:00
|
|
|
case MNU_DATUM_POINT:
|
|
|
|
hr = AddRequest(Request::DATUM_POINT);
|
2008-04-19 11:44:44 +00:00
|
|
|
SS.GetEntity(hr.entity(0))->PointForceTo(v);
|
2008-04-22 10:53:42 +00:00
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearSuper();
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
pending.operation = 0;
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MNU_LINE_SEGMENT:
|
|
|
|
hr = AddRequest(Request::LINE_SEGMENT);
|
2008-04-19 11:44:44 +00:00
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
2008-05-08 07:30:30 +00:00
|
|
|
ConstrainPointByHovered(hr.entity(1));
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearSuper();
|
2008-04-22 10:53:42 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
pending.operation = DRAGGING_NEW_LINE_POINT;
|
|
|
|
pending.point = hr.entity(2);
|
|
|
|
pending.description = "click to place next point of line";
|
|
|
|
SS.GetEntity(pending.point)->PointForceTo(v);
|
|
|
|
break;
|
|
|
|
|
2008-05-07 04:17:29 +00:00
|
|
|
case MNU_RECTANGLE: {
|
2008-05-27 02:22:20 +00:00
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
2008-05-17 06:04:55 +00:00
|
|
|
Error("Can't draw rectangle in 3d; select a workplane first.");
|
|
|
|
break;
|
|
|
|
}
|
2008-05-07 04:17:29 +00:00
|
|
|
hRequest lns[4];
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
lns[i] = AddRequest(Request::LINE_SEGMENT);
|
|
|
|
}
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
Constraint::ConstrainCoincident(
|
|
|
|
lns[i].entity(1), lns[(i+1)%4].entity(2));
|
|
|
|
SS.GetEntity(lns[i].entity(1))->PointForceTo(v);
|
|
|
|
SS.GetEntity(lns[i].entity(2))->PointForceTo(v);
|
|
|
|
}
|
|
|
|
for(i = 0; i < 4; i++) {
|
2008-05-08 07:30:30 +00:00
|
|
|
Constraint::Constrain(
|
|
|
|
(i % 2) ? Constraint::HORIZONTAL : Constraint::VERTICAL,
|
|
|
|
Entity::NO_ENTITY, Entity::NO_ENTITY,
|
|
|
|
lns[i].entity(0));
|
2008-05-07 04:17:29 +00:00
|
|
|
}
|
2008-05-12 10:01:44 +00:00
|
|
|
ConstrainPointByHovered(lns[2].entity(1));
|
2008-05-07 04:17:29 +00:00
|
|
|
|
|
|
|
pending.operation = DRAGGING_NEW_POINT;
|
|
|
|
pending.point = lns[1].entity(2);
|
|
|
|
pending.description = "click to place other corner of rectangle";
|
|
|
|
break;
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
case MNU_CIRCLE:
|
|
|
|
hr = AddRequest(Request::CIRCLE);
|
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
2008-05-07 08:19:37 +00:00
|
|
|
SS.GetEntity(hr.entity(32))->NormalForceTo(
|
2008-06-01 08:45:11 +00:00
|
|
|
Quaternion::From(SS.GW.projRight, SS.GW.projUp));
|
2008-05-08 07:30:30 +00:00
|
|
|
ConstrainPointByHovered(hr.entity(1));
|
2008-05-05 06:18:01 +00:00
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearSuper();
|
2008-05-05 06:18:01 +00:00
|
|
|
|
|
|
|
pending.operation = DRAGGING_NEW_RADIUS;
|
|
|
|
pending.circle = hr.entity(0);
|
|
|
|
pending.description = "click to set radius";
|
|
|
|
SS.GetParam(hr.param(0))->val = 0;
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-12 10:01:44 +00:00
|
|
|
case MNU_ARC:
|
2008-05-27 02:22:20 +00:00
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
2008-05-12 10:01:44 +00:00
|
|
|
Error("Can't draw arc in 3d; select a workplane first.");
|
|
|
|
ClearPending();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hr = AddRequest(Request::ARC_OF_CIRCLE);
|
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
|
|
|
SS.GetEntity(hr.entity(2))->PointForceTo(v);
|
|
|
|
SS.GetEntity(hr.entity(3))->PointForceTo(v);
|
|
|
|
ConstrainPointByHovered(hr.entity(2));
|
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearSuper();
|
2008-05-12 10:01:44 +00:00
|
|
|
|
|
|
|
pending.operation = DRAGGING_NEW_ARC_POINT;
|
|
|
|
pending.point = hr.entity(3);
|
|
|
|
pending.description = "click to place point";
|
|
|
|
break;
|
|
|
|
|
2008-04-25 12:07:17 +00:00
|
|
|
case MNU_CUBIC:
|
|
|
|
hr = AddRequest(Request::CUBIC);
|
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
|
|
|
SS.GetEntity(hr.entity(2))->PointForceTo(v);
|
|
|
|
SS.GetEntity(hr.entity(3))->PointForceTo(v);
|
|
|
|
SS.GetEntity(hr.entity(4))->PointForceTo(v);
|
2008-05-08 07:30:30 +00:00
|
|
|
ConstrainPointByHovered(hr.entity(1));
|
2008-04-25 12:07:17 +00:00
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearSuper();
|
2008-04-25 12:07:17 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
pending.operation = DRAGGING_NEW_CUBIC_POINT;
|
|
|
|
pending.point = hr.entity(4);
|
|
|
|
pending.description = "click to place next point of cubic";
|
2008-04-25 12:07:17 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-05 11:17:00 +00:00
|
|
|
case MNU_WORKPLANE:
|
|
|
|
hr = AddRequest(Request::WORKPLANE);
|
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
2008-05-07 08:19:37 +00:00
|
|
|
SS.GetEntity(hr.entity(32))->NormalForceTo(
|
2008-06-01 08:45:11 +00:00
|
|
|
Quaternion::From(SS.GW.projRight, SS.GW.projUp));
|
2008-05-08 07:30:30 +00:00
|
|
|
ConstrainPointByHovered(hr.entity(1));
|
2008-05-05 11:17:00 +00:00
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
ClearSuper();
|
2008-05-05 11:17:00 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case DRAGGING_RADIUS:
|
2008-04-23 07:29:19 +00:00
|
|
|
case DRAGGING_NEW_POINT:
|
2008-05-05 06:18:01 +00:00
|
|
|
// The MouseMoved event has already dragged it as desired.
|
|
|
|
ClearPending();
|
2008-04-23 07:29:19 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-12 10:01:44 +00:00
|
|
|
case DRAGGING_NEW_ARC_POINT:
|
2008-04-25 12:07:17 +00:00
|
|
|
case DRAGGING_NEW_CUBIC_POINT:
|
2008-05-08 07:30:30 +00:00
|
|
|
ConstrainPointByHovered(pending.point);
|
2008-05-05 06:18:01 +00:00
|
|
|
ClearPending();
|
2008-04-25 12:07:17 +00:00
|
|
|
break;
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
case DRAGGING_NEW_LINE_POINT: {
|
2008-05-08 07:30:30 +00:00
|
|
|
if(ConstrainPointByHovered(pending.point)) {
|
2008-05-05 06:18:01 +00:00
|
|
|
ClearPending();
|
2008-04-23 07:29:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Create a new line segment, so that we continue drawing.
|
|
|
|
hRequest hr = AddRequest(Request::LINE_SEGMENT);
|
|
|
|
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GetEntity(hr.entity(2))->PointForceTo(v);
|
2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
// Constrain the line segments to share an endpoint
|
2008-05-05 06:18:01 +00:00
|
|
|
Constraint::ConstrainCoincident(pending.point, hr.entity(1));
|
2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
// And drag an endpoint of the new line segment
|
2008-05-05 06:18:01 +00:00
|
|
|
pending.operation = DRAGGING_NEW_LINE_POINT;
|
|
|
|
pending.point = hr.entity(2);
|
|
|
|
pending.description = "click to place next point of next line";
|
2008-04-23 07:29:19 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
2008-04-23 07:29:19 +00:00
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
case 0:
|
|
|
|
default: {
|
2008-05-05 06:18:01 +00:00
|
|
|
ClearPending();
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
if(hover.IsEmpty()) break;
|
|
|
|
|
|
|
|
// If an item is hovered, then by clicking on it, we toggle its
|
|
|
|
// selection state.
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
if(selection[i].Equals(&hover)) {
|
|
|
|
selection[i].Clear();
|
|
|
|
break;
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
if(i != MAX_SELECTED) break;
|
|
|
|
|
2008-06-02 05:38:12 +00:00
|
|
|
if(hover.entity.v != 0 && SS.GetEntity(hover.entity)->IsFace()) {
|
|
|
|
// In the interest of speed for the triangle drawing code,
|
|
|
|
// only two faces may be selected at a time.
|
|
|
|
int c = 0;
|
|
|
|
for(i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
hEntity he = selection[i].entity;
|
|
|
|
if(he.v != 0 && SS.GetEntity(he)->IsFace()) {
|
|
|
|
c++;
|
|
|
|
if(c >= 2) selection[i].Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
for(i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
if(selection[i].IsEmpty()) {
|
|
|
|
selection[i] = hover;
|
|
|
|
break;
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
break;
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.showTW = true;
|
2008-04-13 10:57:41 +00:00
|
|
|
InvalidateGraphics();
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-22 10:53:42 +00:00
|
|
|
void GraphicsWindow::MouseLeftUp(double mx, double my) {
|
2008-05-05 06:18:01 +00:00
|
|
|
switch(pending.operation) {
|
2008-04-23 07:29:19 +00:00
|
|
|
case DRAGGING_POINT:
|
|
|
|
case DRAGGING_CONSTRAINT:
|
2008-05-05 06:18:01 +00:00
|
|
|
case DRAGGING_NORMAL:
|
|
|
|
case DRAGGING_RADIUS:
|
|
|
|
ClearPending();
|
2008-04-22 10:53:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break; // do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-21 10:12:04 +00:00
|
|
|
void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
|
|
|
|
if(GraphicsEditControlIsVisible()) return;
|
|
|
|
|
|
|
|
if(hover.constraint.v) {
|
2008-06-01 04:31:28 +00:00
|
|
|
constraintBeingEdited = hover.constraint;
|
|
|
|
ClearSuper();
|
|
|
|
|
|
|
|
Constraint *c = SS.GetConstraint(constraintBeingEdited);
|
2008-04-21 10:12:04 +00:00
|
|
|
Vector p3 = c->GetLabelPos();
|
|
|
|
Point2d p2 = ProjectPoint(p3);
|
|
|
|
ShowGraphicsEditControl((int)p2.x, (int)p2.y, c->exprA->Print());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::EditControlDone(char *s) {
|
2008-06-01 08:45:11 +00:00
|
|
|
Expr *e = Expr::From(s);
|
2008-04-21 10:12:04 +00:00
|
|
|
if(e) {
|
|
|
|
Constraint *c = SS.GetConstraint(constraintBeingEdited);
|
|
|
|
Expr::FreeKeep(&(c->exprA));
|
|
|
|
c->exprA = e->DeepCopyKeep();
|
2008-06-02 11:43:27 +00:00
|
|
|
|
2008-04-21 10:12:04 +00:00
|
|
|
HideGraphicsEditControl();
|
2008-06-02 11:43:27 +00:00
|
|
|
SS.MarkGroupDirty(c->group);
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll();
|
2008-04-21 10:12:04 +00:00
|
|
|
} else {
|
|
|
|
Error("Not a valid number or expression: '%s'", s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 10:48:44 +00:00
|
|
|
void GraphicsWindow::MouseScroll(double x, double y, int delta) {
|
|
|
|
double offsetRight = offset.Dot(projRight);
|
2008-04-12 15:17:58 +00:00
|
|
|
double offsetUp = offset.Dot(projUp);
|
2008-04-01 10:48:44 +00:00
|
|
|
|
|
|
|
double righti = x/scale - offsetRight;
|
2008-04-12 15:17:58 +00:00
|
|
|
double upi = y/scale - offsetUp;
|
2008-04-01 10:48:44 +00:00
|
|
|
|
|
|
|
if(delta > 0) {
|
2008-04-12 15:17:58 +00:00
|
|
|
scale *= 1.2;
|
2008-04-01 10:48:44 +00:00
|
|
|
} else {
|
2008-04-12 15:17:58 +00:00
|
|
|
scale /= 1.2;
|
2008-04-01 10:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double rightf = x/scale - offsetRight;
|
2008-04-12 15:17:58 +00:00
|
|
|
double upf = y/scale - offsetUp;
|
2008-04-01 10:48:44 +00:00
|
|
|
|
|
|
|
offset = offset.Plus(projRight.ScaledBy(rightf - righti));
|
2008-04-12 15:17:58 +00:00
|
|
|
offset = offset.Plus(projUp.ScaledBy(upf - upi));
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
Vector GraphicsWindow::VectorFromProjs(double right, double up, double fwd) {
|
|
|
|
Vector n = projRight.Cross(projUp);
|
|
|
|
Vector r = offset.ScaledBy(-1);
|
|
|
|
r = r.Plus(projRight.ScaledBy(right));
|
|
|
|
r = r.Plus(projUp.ScaledBy(up));
|
|
|
|
r = r.Plus(n.ScaledBy(fwd));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
void GraphicsWindow::Paint(int w, int h) {
|
2008-04-28 09:40:02 +00:00
|
|
|
havePainted = true;
|
2008-04-01 10:48:44 +00:00
|
|
|
width = w; height = h;
|
|
|
|
|
2008-03-27 09:53:51 +00:00
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2008-06-01 04:31:28 +00:00
|
|
|
glScaled(scale*2.0/w, scale*2.0/h, scale*1.0/30000);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
|
|
|
double tx = projRight.Dot(offset);
|
2008-04-12 15:17:58 +00:00
|
|
|
double ty = projUp.Dot(offset);
|
2008-05-02 10:54:22 +00:00
|
|
|
Vector n = projUp.Cross(projRight);
|
|
|
|
double tz = n.Dot(offset);
|
2008-03-27 09:53:51 +00:00
|
|
|
double mat[16];
|
|
|
|
MakeMatrix(mat, projRight.x, projRight.y, projRight.z, tx,
|
2008-04-12 15:17:58 +00:00
|
|
|
projUp.x, projUp.y, projUp.z, ty,
|
2008-05-02 10:54:22 +00:00
|
|
|
n.x, n.y, n.z, tz,
|
2008-03-27 09:53:51 +00:00
|
|
|
0, 0, 0, 1);
|
|
|
|
glMultMatrixd(mat);
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
|
2008-04-11 11:13:47 +00:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
2008-05-13 11:27:32 +00:00
|
|
|
glEnable(GL_POLYGON_OFFSET_LINE);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
2008-03-27 09:53:51 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2008-04-11 11:13:47 +00:00
|
|
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
2008-05-02 10:54:22 +00:00
|
|
|
glEnable(GL_NORMALIZE);
|
2008-05-17 08:02:39 +00:00
|
|
|
|
|
|
|
// At the same depth, we want later lines drawn over earlier.
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
2008-03-27 09:53:51 +00:00
|
|
|
|
|
|
|
glClearDepth(1.0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
Vector light = VectorFromProjs(-0.49*w/scale, 0.49*h/scale, 0);
|
|
|
|
GLfloat lightPos[4] =
|
|
|
|
{ (GLfloat)light.x, (GLfloat)light.y, (GLfloat)light.z, 0 };
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
|
|
|
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1);
|
|
|
|
GLfloat ambient[4] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
|
|
|
|
|
|
|
|
glxUnlockColor();
|
2008-04-11 12:47:14 +00:00
|
|
|
|
2008-04-22 10:53:42 +00:00
|
|
|
int i, a;
|
2008-05-25 13:11:44 +00:00
|
|
|
// Draw the groups; this fills the polygons in a drawing group, and
|
|
|
|
// draws the solid mesh.
|
2008-05-28 10:34:55 +00:00
|
|
|
(SS.GetGroup(activeGroup))->Draw();
|
2008-04-12 14:12:26 +00:00
|
|
|
|
2008-04-22 10:53:42 +00:00
|
|
|
// First, draw the entire scene. We don't necessarily want to draw
|
|
|
|
// things with normal z-buffering behaviour; e.g. we always want to
|
|
|
|
// draw a line segment in front of a reference. So we have three draw
|
|
|
|
// levels, and only the first gets normal depth testing.
|
|
|
|
for(a = 0; a <= 2; a++) {
|
2008-04-27 03:26:27 +00:00
|
|
|
// Three levels: 0 least prominent (e.g. a reference workplane), 1 is
|
2008-04-22 10:53:42 +00:00
|
|
|
// middle (e.g. line segment), 2 is always in front (e.g. point).
|
2008-05-02 10:54:22 +00:00
|
|
|
if(a >= 1 && showHdnLines) glDisable(GL_DEPTH_TEST);
|
2008-04-22 10:53:42 +00:00
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
|
|
|
SS.entity.elem[i].Draw(a);
|
|
|
|
}
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
2008-04-21 08:16:38 +00:00
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2008-04-21 08:16:38 +00:00
|
|
|
// Draw the constraints
|
2008-04-18 11:11:48 +00:00
|
|
|
for(i = 0; i < SS.constraint.n; i++) {
|
2008-04-18 07:21:17 +00:00
|
|
|
SS.constraint.elem[i].Draw();
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
// Then redraw whatever the mouse is hovering over, highlighted.
|
2008-04-12 14:12:26 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2008-04-19 11:09:47 +00:00
|
|
|
glxLockColorTo(1, 1, 0);
|
2008-04-12 14:12:26 +00:00
|
|
|
hover.Draw();
|
|
|
|
|
|
|
|
// And finally draw the selection, same mechanism.
|
2008-04-19 11:09:47 +00:00
|
|
|
glxLockColorTo(1, 0, 0);
|
2008-04-12 14:12:26 +00:00
|
|
|
for(i = 0; i < MAX_SELECTED; i++) {
|
|
|
|
selection[i].Draw();
|
|
|
|
}
|
2008-03-27 09:53:51 +00:00
|
|
|
}
|
|
|
|
|