2009-09-29 13:14:47 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// The root function to paint our graphics window, after setting up all the
|
|
|
|
// views and such appropriately. Also contains all the stuff to manage the
|
|
|
|
// selection.
|
2013-07-28 22:08:34 +00:00
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
2009-09-29 13:14:47 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2008-06-06 08:14:37 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
|
|
|
bool GraphicsWindow::Selection::Equals(Selection *b) {
|
|
|
|
if(entity.v != b->entity.v) return false;
|
|
|
|
if(constraint.v != b->constraint.v) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicsWindow::Selection::IsEmpty(void) {
|
|
|
|
if(entity.v) return false;
|
|
|
|
if(constraint.v) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-24 15:52:48 +00:00
|
|
|
bool GraphicsWindow::Selection::IsStylable(void) {
|
|
|
|
if(entity.v) return true;
|
|
|
|
if(constraint.v) {
|
|
|
|
Constraint *c = SK.GetConstraint(constraint);
|
|
|
|
if(c->type == Constraint::COMMENT) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-03 18:54:49 +00:00
|
|
|
bool GraphicsWindow::Selection::HasEndpoints(void) {
|
|
|
|
if(!entity.v) return false;
|
|
|
|
Entity *e = SK.GetEntity(entity);
|
|
|
|
return e->HasEndpoints();
|
|
|
|
}
|
|
|
|
|
2008-06-06 08:14:37 +00:00
|
|
|
void GraphicsWindow::Selection::Clear(void) {
|
|
|
|
entity.v = constraint.v = 0;
|
|
|
|
emphasized = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::Selection::Draw(void) {
|
2013-08-26 19:36:00 +00:00
|
|
|
Vector refp = Vector::From(0, 0, 0);
|
2008-06-06 08:14:37 +00:00
|
|
|
if(entity.v) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.GetEntity(entity);
|
2008-06-06 08:14:37 +00:00
|
|
|
e->Draw();
|
|
|
|
if(emphasized) refp = e->GetReferencePos();
|
|
|
|
}
|
|
|
|
if(constraint.v) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Constraint *c = SK.GetConstraint(constraint);
|
2008-06-06 08:14:37 +00:00
|
|
|
c->Draw();
|
|
|
|
if(emphasized) refp = c->GetReferencePos();
|
|
|
|
}
|
|
|
|
if(emphasized && (constraint.v || entity.v)) {
|
2009-09-17 07:32:36 +00:00
|
|
|
// We want to emphasize this constraint or entity, by drawing a thick
|
|
|
|
// line from the top left corner of the screen to the reference point
|
|
|
|
// of that entity or constraint.
|
2008-06-06 08:14:37 +00:00
|
|
|
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);
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
RgbColor rgb = Style::Color(Style::HOVERED);
|
|
|
|
glColor4d(rgb.redF(), rgb.greenF(), rgb.blueF(), 0.2);
|
2008-06-06 08:14:37 +00:00
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(topLeft);
|
|
|
|
ssglVertex3v(refp);
|
2008-06-06 08:14:37 +00:00
|
|
|
glEnd();
|
|
|
|
glLineWidth(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::ClearSelection(void) {
|
2009-11-03 18:54:49 +00:00
|
|
|
selection.Clear();
|
2008-06-06 08:14:37 +00:00
|
|
|
SS.later.showTW = true;
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::ClearNonexistentSelectionItems(void) {
|
|
|
|
bool change = false;
|
2009-11-03 18:54:49 +00:00
|
|
|
Selection *s;
|
|
|
|
selection.ClearTags();
|
|
|
|
for(s = selection.First(); s; s = selection.NextAfter(s)) {
|
2009-04-19 05:53:16 +00:00
|
|
|
if(s->constraint.v && !(SK.constraint.FindByIdNoOops(s->constraint))) {
|
2009-11-03 18:54:49 +00:00
|
|
|
s->tag = 1;
|
2008-06-06 08:14:37 +00:00
|
|
|
change = true;
|
|
|
|
}
|
2009-04-19 05:53:16 +00:00
|
|
|
if(s->entity.v && !(SK.entity.FindByIdNoOops(s->entity))) {
|
2009-11-03 18:54:49 +00:00
|
|
|
s->tag = 1;
|
2008-06-06 08:14:37 +00:00
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
}
|
2009-11-03 18:54:49 +00:00
|
|
|
selection.RemoveTagged();
|
2008-06-06 08:14:37 +00:00
|
|
|
if(change) InvalidateGraphics();
|
|
|
|
}
|
|
|
|
|
2009-12-21 16:44:00 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-01-03 10:26:15 +00:00
|
|
|
// Is this entity/constraint selected?
|
2009-12-21 16:44:00 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-01-03 10:26:15 +00:00
|
|
|
bool GraphicsWindow::IsSelected(hEntity he) {
|
|
|
|
Selection s;
|
|
|
|
ZERO(&s);
|
|
|
|
s.entity = he;
|
|
|
|
return IsSelected(&s);
|
|
|
|
}
|
|
|
|
bool GraphicsWindow::IsSelected(Selection *st) {
|
2009-12-21 16:44:00 +00:00
|
|
|
Selection *s;
|
|
|
|
for(s = selection.First(); s; s = selection.NextAfter(s)) {
|
2010-01-03 10:26:15 +00:00
|
|
|
if(s->Equals(st)) {
|
2009-12-21 16:44:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-09-23 10:59:59 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-01-03 10:26:15 +00:00
|
|
|
// Unselect an item, if it is selected. We can either unselect just that item,
|
|
|
|
// or also unselect any coincident points. The latter is useful if the user
|
|
|
|
// somehow selects two coincident points (like with select all), because it
|
|
|
|
// would otherwise be impossible to de-select the lower of the two.
|
2009-09-23 10:59:59 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-01-03 10:26:15 +00:00
|
|
|
void GraphicsWindow::MakeUnselected(hEntity he, bool coincidentPointTrick) {
|
2009-11-03 18:54:49 +00:00
|
|
|
Selection stog;
|
|
|
|
ZERO(&stog);
|
|
|
|
stog.entity = he;
|
2010-01-03 10:26:15 +00:00
|
|
|
MakeUnselected(&stog, coincidentPointTrick);
|
2009-11-03 18:54:49 +00:00
|
|
|
}
|
2010-01-03 10:26:15 +00:00
|
|
|
void GraphicsWindow::MakeUnselected(Selection *stog, bool coincidentPointTrick){
|
2009-11-03 18:54:49 +00:00
|
|
|
if(stog->IsEmpty()) return;
|
|
|
|
|
|
|
|
Selection *s;
|
2009-09-23 10:59:59 +00:00
|
|
|
|
|
|
|
// If an item was selected, then we just un-select it.
|
2009-11-03 18:54:49 +00:00
|
|
|
bool wasSelected = false;
|
|
|
|
selection.ClearTags();
|
|
|
|
for(s = selection.First(); s; s = selection.NextAfter(s)) {
|
|
|
|
if(s->Equals(stog)) {
|
|
|
|
s->tag = 1;
|
2009-09-23 10:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-04 07:52:58 +00:00
|
|
|
// If two points are coincident, then it's impossible to hover one of
|
|
|
|
// them. But make sure to deselect both, to avoid mysterious seeming
|
|
|
|
// inability to deselect if the bottom one did somehow get selected.
|
2010-01-03 10:26:15 +00:00
|
|
|
if(stog->entity.v && coincidentPointTrick) {
|
2009-11-04 07:52:58 +00:00
|
|
|
Entity *e = SK.GetEntity(stog->entity);
|
|
|
|
if(e->IsPoint()) {
|
|
|
|
Vector ep = e->PointGetNum();
|
|
|
|
for(s = selection.First(); s; s = selection.NextAfter(s)) {
|
|
|
|
if(!s->entity.v) continue;
|
|
|
|
if(s->entity.v == stog->entity.v) continue;
|
|
|
|
Entity *se = SK.GetEntity(s->entity);
|
|
|
|
if(!se->IsPoint()) continue;
|
|
|
|
if(ep.Equals(se->PointGetNum())) {
|
|
|
|
s->tag = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-03 10:26:15 +00:00
|
|
|
selection.RemoveTagged();
|
|
|
|
}
|
2009-12-21 16:44:00 +00:00
|
|
|
|
2010-01-03 10:26:15 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Select an item, if it isn't selected already.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void GraphicsWindow::MakeSelected(hEntity he) {
|
|
|
|
Selection stog;
|
|
|
|
ZERO(&stog);
|
|
|
|
stog.entity = he;
|
|
|
|
MakeSelected(&stog);
|
|
|
|
}
|
|
|
|
void GraphicsWindow::MakeSelected(Selection *stog) {
|
|
|
|
if(stog->IsEmpty()) return;
|
|
|
|
if(IsSelected(stog)) return;
|
2009-09-23 10:59:59 +00:00
|
|
|
|
2009-11-03 18:54:49 +00:00
|
|
|
if(stog->entity.v != 0 && SK.GetEntity(stog->entity)->IsFace()) {
|
2009-09-23 10:59:59 +00:00
|
|
|
// In the interest of speed for the triangle drawing code,
|
|
|
|
// only two faces may be selected at a time.
|
|
|
|
int c = 0;
|
2010-01-03 10:26:15 +00:00
|
|
|
Selection *s;
|
2009-11-03 18:54:49 +00:00
|
|
|
selection.ClearTags();
|
|
|
|
for(s = selection.First(); s; s = selection.NextAfter(s)) {
|
|
|
|
hEntity he = s->entity;
|
2009-09-23 10:59:59 +00:00
|
|
|
if(he.v != 0 && SK.GetEntity(he)->IsFace()) {
|
|
|
|
c++;
|
2009-11-03 18:54:49 +00:00
|
|
|
if(c >= 2) s->tag = 1;
|
2009-09-23 10:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-03 18:54:49 +00:00
|
|
|
selection.RemoveTagged();
|
2009-09-23 10:59:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 18:54:49 +00:00
|
|
|
selection.Add(stog);
|
2009-09-23 10:59:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 07:52:58 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Select everything that lies within the marquee view-aligned rectangle. For
|
|
|
|
// points, we test by the point location. For normals, we test by the normal's
|
|
|
|
// associated point. For anything else, we test by any piecewise linear edge.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void GraphicsWindow::SelectByMarquee(void) {
|
|
|
|
Point2d begin = ProjectPoint(orig.marqueePoint);
|
|
|
|
double xmin = min(orig.mouse.x, begin.x),
|
|
|
|
xmax = max(orig.mouse.x, begin.x),
|
|
|
|
ymin = min(orig.mouse.y, begin.y),
|
|
|
|
ymax = max(orig.mouse.y, begin.y);
|
|
|
|
|
|
|
|
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-04 07:52:58 +00:00
|
|
|
|
|
|
|
if(e->IsPoint() || e->IsNormal()) {
|
|
|
|
Vector p = e->IsPoint() ? e->PointGetNum() :
|
|
|
|
SK.GetEntity(e->point[0])->PointGetNum();
|
|
|
|
Point2d pp = ProjectPoint(p);
|
|
|
|
if(pp.x >= xmin && pp.x <= xmax &&
|
|
|
|
pp.y >= ymin && pp.y <= ymax)
|
|
|
|
{
|
2010-01-03 10:26:15 +00:00
|
|
|
MakeSelected(e->h);
|
2009-11-04 07:52:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Use the 3d bounding box test routines, to avoid duplication;
|
|
|
|
// so let our bounding square become a bounding box that certainly
|
|
|
|
// includes the z = 0 plane.
|
|
|
|
Vector ptMin = Vector::From(xmin, ymin, -1),
|
|
|
|
ptMax = Vector::From(xmax, ymax, 1);
|
|
|
|
SEdgeList sel;
|
|
|
|
ZERO(&sel);
|
2009-11-04 07:59:23 +00:00
|
|
|
e->GenerateEdges(&sel, true);
|
2009-11-04 07:52:58 +00:00
|
|
|
SEdge *se;
|
|
|
|
for(se = sel.l.First(); se; se = sel.l.NextAfter(se)) {
|
|
|
|
Point2d ppa = ProjectPoint(se->a),
|
|
|
|
ppb = ProjectPoint(se->b);
|
|
|
|
Vector ptA = Vector::From(ppa.x, ppa.y, 0),
|
|
|
|
ptB = Vector::From(ppb.x, ppb.y, 0);
|
|
|
|
if(Vector::BoundingBoxIntersectsLine(ptMax, ptMin,
|
|
|
|
ptA, ptB, true) ||
|
|
|
|
!ptA.OutsideAndNotOn(ptMax, ptMin) ||
|
|
|
|
!ptB.OutsideAndNotOn(ptMax, ptMin))
|
|
|
|
{
|
2010-01-03 10:26:15 +00:00
|
|
|
MakeSelected(e->h);
|
2009-11-04 07:52:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sel.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 10:59:59 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Sort the selection according to various critieria: the entities and
|
|
|
|
// constraints separately, counts of certain types of entities (circles,
|
|
|
|
// lines, etc.), and so on.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-06-06 08:14:37 +00:00
|
|
|
void GraphicsWindow::GroupSelection(void) {
|
|
|
|
memset(&gs, 0, sizeof(gs));
|
|
|
|
int i;
|
2009-11-03 18:54:49 +00:00
|
|
|
for(i = 0; i < selection.n && i < MAX_SELECTED; i++) {
|
|
|
|
Selection *s = &(selection.elem[i]);
|
2008-06-06 08:14:37 +00:00
|
|
|
if(s->entity.v) {
|
|
|
|
(gs.n)++;
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.entity.FindById(s->entity);
|
2008-06-06 08:14:37 +00:00
|
|
|
// A list of points, and a list of all entities that aren't points.
|
|
|
|
if(e->IsPoint()) {
|
|
|
|
gs.point[(gs.points)++] = s->entity;
|
|
|
|
} else {
|
|
|
|
gs.entity[(gs.entities)++] = s->entity;
|
2009-09-24 15:52:48 +00:00
|
|
|
(gs.stylables)++;
|
2008-06-06 08:14:37 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Faces (which are special, associated/drawn with triangles)
|
|
|
|
if(e->IsFace()) {
|
|
|
|
gs.face[(gs.faces)++] = s->entity;
|
|
|
|
}
|
|
|
|
|
2009-11-03 18:54:49 +00:00
|
|
|
if(e->HasEndpoints()) {
|
|
|
|
(gs.withEndpoints)++;
|
|
|
|
}
|
|
|
|
|
2008-06-06 08:14:37 +00:00
|
|
|
// And some aux counts too
|
|
|
|
switch(e->type) {
|
2009-11-10 03:57:24 +00:00
|
|
|
case Entity::WORKPLANE: (gs.workplanes)++; break;
|
|
|
|
case Entity::LINE_SEGMENT: (gs.lineSegments)++; break;
|
|
|
|
case Entity::CUBIC: (gs.cubics)++; break;
|
|
|
|
case Entity::CUBIC_PERIODIC: (gs.periodicCubics)++; break;
|
2008-06-06 08:14:37 +00:00
|
|
|
|
|
|
|
case Entity::ARC_OF_CIRCLE:
|
2008-07-13 12:44:05 +00:00
|
|
|
(gs.circlesOrArcs)++;
|
|
|
|
(gs.arcs)++;
|
|
|
|
break;
|
|
|
|
|
2008-06-06 08:14:37 +00:00
|
|
|
case Entity::CIRCLE: (gs.circlesOrArcs)++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(s->constraint.v) {
|
|
|
|
gs.constraint[(gs.constraints)++] = s->constraint;
|
2009-09-24 15:52:48 +00:00
|
|
|
Constraint *c = SK.GetConstraint(s->constraint);
|
|
|
|
if(c->type == Constraint::COMMENT) {
|
|
|
|
(gs.stylables)++;
|
2009-09-29 11:35:19 +00:00
|
|
|
(gs.comments)++;
|
2009-09-24 15:52:48 +00:00
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWindow::HitTestMakeSelection(Point2d mp) {
|
|
|
|
int i;
|
|
|
|
double d, dmin = 1e12;
|
|
|
|
Selection s;
|
|
|
|
ZERO(&s);
|
|
|
|
|
2008-06-18 09:18:51 +00:00
|
|
|
// Always do the entities; we might be dragging something that should
|
|
|
|
// be auto-constrained, and we need the hover for that.
|
2009-04-19 05:53:16 +00:00
|
|
|
for(i = 0; i < SK.entity.n; i++) {
|
|
|
|
Entity *e = &(SK.entity.elem[i]);
|
2008-06-06 08:14:37 +00:00
|
|
|
// Don't hover whatever's being dragged.
|
2009-10-21 04:46:01 +00:00
|
|
|
if(e->h.request().v == pending.point.request().v) {
|
|
|
|
// The one exception is when we're creating a new cubic; we
|
|
|
|
// want to be able to hover the first point, because that's
|
|
|
|
// how we turn it into a periodic spline.
|
|
|
|
if(!e->IsPoint()) continue;
|
|
|
|
if(!e->h.isFromRequest()) continue;
|
|
|
|
Request *r = SK.GetRequest(e->h.request());
|
|
|
|
if(r->type != Request::CUBIC) continue;
|
|
|
|
if(r->extraPoints < 2) continue;
|
|
|
|
if(e->h.v != r->h.entity(1).v) continue;
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
|
|
|
|
d = e->GetDistance(mp);
|
|
|
|
if(d < 10 && d < dmin) {
|
|
|
|
memset(&s, 0, sizeof(s));
|
|
|
|
s.entity = e->h;
|
|
|
|
dmin = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-18 09:18:51 +00:00
|
|
|
// The constraints and faces happen only when nothing's in progress.
|
|
|
|
if(pending.operation == 0) {
|
|
|
|
// Constraints
|
2009-04-19 05:53:16 +00:00
|
|
|
for(i = 0; i < SK.constraint.n; i++) {
|
|
|
|
d = SK.constraint.elem[i].GetDistance(mp);
|
2008-06-18 09:18:51 +00:00
|
|
|
if(d < 10 && d < dmin) {
|
|
|
|
memset(&s, 0, sizeof(s));
|
2009-04-19 05:53:16 +00:00
|
|
|
s.constraint = SK.constraint.elem[i].h;
|
2008-06-18 09:18:51 +00:00
|
|
|
dmin = d;
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 09:18:51 +00:00
|
|
|
// Faces, from the triangle mesh; these are lowest priority
|
|
|
|
if(s.constraint.v == 0 && s.entity.v == 0 && showShaded && showFaces) {
|
2009-10-08 07:55:09 +00:00
|
|
|
Group *g = SK.GetGroup(activeGroup);
|
|
|
|
SMesh *m = &(g->displayMesh);
|
|
|
|
|
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
|
|
|
uint32_t v = m->FirstIntersectionWith(mp);
|
2008-06-18 09:18:51 +00:00
|
|
|
if(v) {
|
|
|
|
s.entity.v = v;
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!s.Equals(&hover)) {
|
|
|
|
hover = s;
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-29 13:14:47 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Project a point in model space to screen space, exactly as gl would; return
|
|
|
|
// units are pixels.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Point2d GraphicsWindow::ProjectPoint(Vector p) {
|
|
|
|
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) {
|
|
|
|
p = p.Plus(offset);
|
|
|
|
|
|
|
|
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;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-11-04 07:52:58 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Return a point in the plane parallel to the screen and through the offset,
|
|
|
|
// that projects onto the specified (x, y) coordinates.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Vector GraphicsWindow::UnProjectPoint(Point2d p) {
|
|
|
|
Vector orig = offset.ScaledBy(-1);
|
|
|
|
|
|
|
|
// Note that we ignoring the effects of perspective. Since our returned
|
|
|
|
// point has the same component normal to the screen as the offset, it
|
|
|
|
// will have z = 0 after the rotation is applied, thus w = 1. So this is
|
|
|
|
// correct.
|
|
|
|
orig = orig.Plus(projRight.ScaledBy(p.x / scale)).Plus(
|
|
|
|
projUp. ScaledBy(p.y / scale));
|
|
|
|
return orig;
|
|
|
|
}
|
|
|
|
|
2009-09-29 13:14:47 +00:00
|
|
|
void GraphicsWindow::NormalizeProjectionVectors(void) {
|
2010-01-04 00:35:28 +00:00
|
|
|
if(projRight.Magnitude() < LENGTH_EPS) {
|
|
|
|
projRight = Vector::From(1, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-09-29 13:14:47 +00:00
|
|
|
Vector norm = projRight.Cross(projUp);
|
2010-01-04 00:35:28 +00:00
|
|
|
// If projRight and projUp somehow ended up parallel, then pick an
|
|
|
|
// arbitrary projUp normal to projRight.
|
|
|
|
if(norm.Magnitude() < LENGTH_EPS) {
|
|
|
|
norm = projRight.Normal(0);
|
|
|
|
}
|
2009-09-29 13:14:47 +00:00
|
|
|
projUp = norm.Cross(projRight);
|
|
|
|
|
2009-11-04 07:52:58 +00:00
|
|
|
projUp = projUp.WithMagnitude(1);
|
|
|
|
projRight = projRight.WithMagnitude(1);
|
2009-09-29 13:14:47 +00:00
|
|
|
}
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
Vector GraphicsWindow::VectorFromProjs(Vector rightUpForward) {
|
2008-06-06 08:14:37 +00:00
|
|
|
Vector n = projRight.Cross(projUp);
|
2008-06-11 04:22:52 +00:00
|
|
|
|
|
|
|
Vector r = (projRight.ScaledBy(rightUpForward.x));
|
|
|
|
r = r.Plus(projUp.ScaledBy(rightUpForward.y));
|
|
|
|
r = r.Plus(n.ScaledBy(rightUpForward.z));
|
2008-06-06 08:14:37 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
void GraphicsWindow::Paint(void) {
|
2008-06-11 04:54:56 +00:00
|
|
|
int i;
|
2008-06-06 08:14:37 +00:00
|
|
|
havePainted = true;
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
int w, h;
|
|
|
|
GetGraphicsWindowSize(&w, &h);
|
|
|
|
width = w; height = h;
|
2008-06-06 08:14:37 +00:00
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glScaled(scale*2.0/w, scale*2.0/h, scale*1.0/30000);
|
|
|
|
|
|
|
|
double mat[16];
|
2008-06-17 19:12:25 +00:00
|
|
|
// Last thing before display is to apply the perspective
|
2009-09-29 11:35:19 +00:00
|
|
|
double clp = SS.CameraTangent()*scale;
|
2008-06-17 19:12:25 +00:00
|
|
|
MakeMatrix(mat, 1, 0, 0, 0,
|
|
|
|
0, 1, 0, 0,
|
|
|
|
0, 0, 1, 0,
|
|
|
|
0, 0, clp, 1);
|
|
|
|
glMultMatrixd(mat);
|
|
|
|
// Before that, we apply the rotation
|
|
|
|
Vector n = projUp.Cross(projRight);
|
|
|
|
MakeMatrix(mat, projRight.x, projRight.y, projRight.z, 0,
|
|
|
|
projUp.x, projUp.y, projUp.z, 0,
|
|
|
|
n.x, n.y, n.z, 0,
|
|
|
|
0, 0, 0, 1);
|
|
|
|
glMultMatrixd(mat);
|
|
|
|
// And before that, the translation
|
|
|
|
MakeMatrix(mat, 1, 0, 0, offset.x,
|
|
|
|
0, 1, 0, offset.y,
|
|
|
|
0, 0, 1, offset.z,
|
2008-06-06 08:14:37 +00:00
|
|
|
0, 0, 0, 1);
|
|
|
|
glMultMatrixd(mat);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
2008-08-15 07:37:19 +00:00
|
|
|
// don't enable GL_POLYGON_SMOOTH; that looks ugly on some graphics cards,
|
|
|
|
// drawn with leaks in the mesh
|
2008-06-06 08:14:37 +00:00
|
|
|
glEnable(GL_POLYGON_OFFSET_LINE);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
|
|
|
|
// At the same depth, we want later lines drawn over earlier.
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
if(SS.AllGroupsOkay()) {
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
glClearColor(SS.backgroundColor.redF(),
|
|
|
|
SS.backgroundColor.greenF(),
|
|
|
|
SS.backgroundColor.blueF(), 1.0f);
|
2008-06-11 04:54:56 +00:00
|
|
|
} else {
|
2009-09-17 07:32:36 +00:00
|
|
|
// Draw a different background whenever we're having solve problems.
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
RgbColor rgb = Style::Color(Style::DRAW_ERROR);
|
|
|
|
glClearColor(0.4f*rgb.redF(), 0.4f*rgb.greenF(), 0.4f*rgb.blueF(), 1.0f);
|
2008-09-17 10:13:37 +00:00
|
|
|
// And show the text window, which has info to debug it
|
|
|
|
ForceTextWindowShown();
|
2008-06-11 04:54:56 +00:00
|
|
|
}
|
2009-11-08 04:50:38 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2009-11-20 08:43:10 +00:00
|
|
|
glClearDepth(1.0);
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
2008-06-06 08:14:37 +00:00
|
|
|
|
2009-11-08 01:11:38 +00:00
|
|
|
if(SS.bgImage.fromFile) {
|
|
|
|
// If a background image is loaded, then we draw it now as a texture.
|
|
|
|
// This handles the resizing for us nicely.
|
2010-04-26 07:52:49 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, TEXTURE_BACKGROUND_IMG);
|
2009-11-08 01:11:38 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
|
|
|
|
SS.bgImage.rw, SS.bgImage.rh,
|
|
|
|
0,
|
|
|
|
GL_RGB, GL_UNSIGNED_BYTE,
|
|
|
|
SS.bgImage.fromFile);
|
|
|
|
|
|
|
|
double tw = ((double)SS.bgImage.w) / SS.bgImage.rw,
|
|
|
|
th = ((double)SS.bgImage.h) / SS.bgImage.rh;
|
|
|
|
|
|
|
|
double mmw = SS.bgImage.w / SS.bgImage.scale,
|
|
|
|
mmh = SS.bgImage.h / SS.bgImage.scale;
|
|
|
|
|
|
|
|
Vector origin = SS.bgImage.origin;
|
|
|
|
origin = origin.DotInToCsys(projRight, projUp, n);
|
|
|
|
// Place the depth of our origin at the point that corresponds to
|
|
|
|
// w = 1, so that it's unaffected by perspective.
|
|
|
|
origin.z = (offset.ScaledBy(-1)).Dot(n);
|
|
|
|
origin = origin.ScaleOutOfCsys(projRight, projUp, n);
|
|
|
|
|
2009-11-20 08:43:10 +00:00
|
|
|
// Place the background at the very back of the Z order, though, by
|
|
|
|
// mucking with the depth range.
|
|
|
|
glDepthRange(1, 1);
|
2009-11-08 01:11:38 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2d(0, 0);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(origin);
|
2009-11-08 01:11:38 +00:00
|
|
|
|
|
|
|
glTexCoord2d(0, th);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(origin.Plus(projUp.ScaledBy(mmh)));
|
2009-11-08 01:11:38 +00:00
|
|
|
|
|
|
|
glTexCoord2d(tw, th);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(origin.Plus(projRight.ScaledBy(mmw).Plus(
|
|
|
|
projUp. ScaledBy(mmh))));
|
2009-11-08 01:11:38 +00:00
|
|
|
|
|
|
|
glTexCoord2d(tw, 0);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(origin.Plus(projRight.ScaledBy(mmw)));
|
2009-11-08 01:11:38 +00:00
|
|
|
glEnd();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(0);
|
2009-11-08 01:11:38 +00:00
|
|
|
|
2008-06-25 05:14:49 +00:00
|
|
|
// Nasty case when we're reloading the imported files; could be that
|
|
|
|
// we get an error, so a dialog pops up, and a message loop starts, and
|
|
|
|
// we have to get called to paint ourselves. If the sketch is screwed
|
|
|
|
// up, then we could trigger an oops trying to draw.
|
|
|
|
if(!SS.allConsistent) return;
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
// Let's use two lights, at the user-specified locations
|
|
|
|
GLfloat f;
|
2008-06-06 08:14:37 +00:00
|
|
|
glEnable(GL_LIGHT0);
|
2008-06-11 04:22:52 +00:00
|
|
|
f = (GLfloat)SS.lightIntensity[0];
|
|
|
|
GLfloat li0[] = { f, f, f, 1.0f };
|
2008-06-09 09:03:21 +00:00
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, li0);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, li0);
|
2008-06-11 04:22:52 +00:00
|
|
|
|
2008-06-09 09:03:21 +00:00
|
|
|
glEnable(GL_LIGHT1);
|
2008-06-11 04:22:52 +00:00
|
|
|
f = (GLfloat)SS.lightIntensity[1];
|
|
|
|
GLfloat li1[] = { f, f, f, 1.0f };
|
2008-06-09 09:03:21 +00:00
|
|
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, li1);
|
|
|
|
glLightfv(GL_LIGHT1, GL_SPECULAR, li1);
|
|
|
|
|
2008-06-11 04:30:18 +00:00
|
|
|
Vector ld;
|
|
|
|
ld = VectorFromProjs(SS.lightDir[0]);
|
|
|
|
GLfloat ld0[4] = { (GLfloat)ld.x, (GLfloat)ld.y, (GLfloat)ld.z, 0 };
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, ld0);
|
|
|
|
ld = VectorFromProjs(SS.lightDir[1]);
|
|
|
|
GLfloat ld1[4] = { (GLfloat)ld.x, (GLfloat)ld.y, (GLfloat)ld.z, 0 };
|
|
|
|
glLightfv(GL_LIGHT1, GL_POSITION, ld1);
|
2008-06-09 09:03:21 +00:00
|
|
|
|
2008-08-11 10:56:08 +00:00
|
|
|
if(SS.drawBackFaces) {
|
|
|
|
// For debugging, draw the backs of the triangles in red, so that we
|
|
|
|
// notice when a shell is open
|
|
|
|
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1);
|
|
|
|
} else {
|
|
|
|
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 0);
|
|
|
|
}
|
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
GLfloat ambient[4] = { (float)SS.ambientIntensity,
|
|
|
|
(float)SS.ambientIntensity,
|
|
|
|
(float)SS.ambientIntensity, 1 };
|
2008-06-06 08:14:37 +00:00
|
|
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglUnlockColor();
|
2008-06-06 08:14:37 +00:00
|
|
|
|
2009-09-29 11:35:19 +00:00
|
|
|
if(showSnapGrid && LockedInWorkplane()) {
|
|
|
|
hEntity he = ActiveWorkplane();
|
|
|
|
EntityBase *wrkpl = SK.GetEntity(he),
|
|
|
|
*norm = wrkpl->Normal();
|
|
|
|
Vector wu, wv, wn, wp;
|
|
|
|
wp = SK.GetEntity(wrkpl->point[0])->PointGetNum();
|
|
|
|
wu = norm->NormalU();
|
|
|
|
wv = norm->NormalV();
|
|
|
|
wn = norm->NormalN();
|
|
|
|
|
|
|
|
double g = SS.gridSpacing;
|
|
|
|
|
|
|
|
double umin = VERY_POSITIVE, umax = VERY_NEGATIVE,
|
|
|
|
vmin = VERY_POSITIVE, vmax = VERY_NEGATIVE;
|
|
|
|
int a;
|
|
|
|
for(a = 0; a < 4; a++) {
|
|
|
|
// Ideally, we would just do +/- half the width and height; but
|
|
|
|
// allow some extra slop for rounding.
|
|
|
|
Vector horiz = projRight.ScaledBy((0.6*width)/scale + 2*g),
|
|
|
|
vert = projUp. ScaledBy((0.6*height)/scale + 2*g);
|
|
|
|
if(a == 2 || a == 3) horiz = horiz.ScaledBy(-1);
|
|
|
|
if(a == 1 || a == 3) vert = vert. ScaledBy(-1);
|
|
|
|
Vector tp = horiz.Plus(vert).Minus(offset);
|
|
|
|
|
|
|
|
// Project the point into our grid plane, normal to the screen
|
|
|
|
// (not to the grid plane). If the plane is on edge then this is
|
|
|
|
// impossible so don't try to draw the grid.
|
|
|
|
bool parallel;
|
|
|
|
Vector tpp = Vector::AtIntersectionOfPlaneAndLine(
|
|
|
|
wn, wn.Dot(wp),
|
|
|
|
tp, tp.Plus(n),
|
|
|
|
¶llel);
|
|
|
|
if(parallel) goto nogrid;
|
|
|
|
|
|
|
|
tpp = tpp.Minus(wp);
|
|
|
|
double uu = tpp.Dot(wu),
|
|
|
|
vv = tpp.Dot(wv);
|
|
|
|
|
|
|
|
umin = min(uu, umin);
|
|
|
|
umax = max(uu, umax);
|
|
|
|
vmin = min(vv, vmin);
|
|
|
|
vmax = max(vv, vmax);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i, j, i0, i1, j0, j1;
|
|
|
|
|
|
|
|
i0 = (int)(umin / g);
|
|
|
|
i1 = (int)(umax / g);
|
|
|
|
j0 = (int)(vmin / g);
|
|
|
|
j1 = (int)(vmax / g);
|
|
|
|
|
|
|
|
if(i0 > i1 || i1 - i0 > 400) goto nogrid;
|
|
|
|
if(j0 > j1 || j1 - j0 > 400) goto nogrid;
|
|
|
|
|
|
|
|
glLineWidth(1);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGBa(Style::Color(Style::DATUM), 0.3);
|
2009-09-29 11:35:19 +00:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
for(i = i0 + 1; i < i1; i++) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(wp.Plus(wu.ScaledBy(i*g)).Plus(wv.ScaledBy(j0*g)));
|
|
|
|
ssglVertex3v(wp.Plus(wu.ScaledBy(i*g)).Plus(wv.ScaledBy(j1*g)));
|
2009-09-29 11:35:19 +00:00
|
|
|
}
|
|
|
|
for(j = j0 + 1; j < j1; j++) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(wp.Plus(wu.ScaledBy(i0*g)).Plus(wv.ScaledBy(j*g)));
|
|
|
|
ssglVertex3v(wp.Plus(wu.ScaledBy(i1*g)).Plus(wv.ScaledBy(j*g)));
|
2009-09-29 11:35:19 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Clear the depth buffer, so that the grid is at the very back of
|
|
|
|
// the Z order.
|
|
|
|
glClear(GL_DEPTH_BUFFER_BIT);
|
|
|
|
nogrid:;
|
|
|
|
}
|
|
|
|
|
2009-11-29 11:20:45 +00:00
|
|
|
// Draw the active group; this does stuff like the mesh and edges.
|
|
|
|
(SK.GetGroup(activeGroup))->Draw();
|
|
|
|
|
|
|
|
// Now draw the entities
|
|
|
|
if(showHdnLines) glDisable(GL_DEPTH_TEST);
|
|
|
|
Entity::DrawAll();
|
|
|
|
|
2009-10-29 07:16:28 +00:00
|
|
|
// Draw filled paths in all groups, when those filled paths were requested
|
2009-11-29 11:20:45 +00:00
|
|
|
// specially by assigning a style with a fill color, or when the filled
|
|
|
|
// paths are just being filled by default. This should go last, to make
|
|
|
|
// the transparency work.
|
2009-10-29 07:16:28 +00:00
|
|
|
Group *g;
|
|
|
|
for(g = SK.group.First(); g; g = SK.group.NextAfter(g)) {
|
|
|
|
if(!(g->IsVisible())) continue;
|
|
|
|
g->DrawFilledPaths();
|
|
|
|
}
|
|
|
|
|
2008-06-06 08:14:37 +00:00
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
// Draw the constraints
|
2009-04-19 05:53:16 +00:00
|
|
|
for(i = 0; i < SK.constraint.n; i++) {
|
|
|
|
SK.constraint.elem[i].Draw();
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 11:27:22 +00:00
|
|
|
// Draw the traced path, if one exists
|
2009-09-17 07:32:36 +00:00
|
|
|
glLineWidth(Style::Width(Style::ANALYZE));
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(Style::Color(Style::ANALYZE));
|
2008-07-20 11:27:22 +00:00
|
|
|
SContour *sc = &(SS.traced.path);
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
for(i = 0; i < sc->l.n; i++) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(sc->l.elem[i].p);
|
2008-07-20 11:27:22 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
2009-01-25 09:19:59 +00:00
|
|
|
// And the naked edges, if the user did Analyze -> Show Naked Edges.
|
2009-09-17 07:32:36 +00:00
|
|
|
glLineWidth(Style::Width(Style::DRAW_ERROR));
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(Style::Color(Style::DRAW_ERROR));
|
|
|
|
ssglDrawEdges(&(SS.nakedEdges), true);
|
2009-01-25 09:19:59 +00:00
|
|
|
|
2008-06-06 08:14:37 +00:00
|
|
|
// Then redraw whatever the mouse is hovering over, highlighted.
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglLockColorTo(Style::Color(Style::HOVERED));
|
2008-06-06 08:14:37 +00:00
|
|
|
hover.Draw();
|
|
|
|
|
|
|
|
// And finally draw the selection, same mechanism.
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglLockColorTo(Style::Color(Style::SELECTED));
|
2009-11-03 18:54:49 +00:00
|
|
|
for(Selection *s = selection.First(); s; s = selection.NextAfter(s)) {
|
|
|
|
s->Draw();
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
2009-01-02 10:38:36 +00:00
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglUnlockColor();
|
2009-09-17 07:32:36 +00:00
|
|
|
|
2009-11-04 07:52:58 +00:00
|
|
|
// If a marquee selection is in progress, then draw the selection
|
|
|
|
// rectangle, as an outline and a transparent fill.
|
|
|
|
if(pending.operation == DRAGGING_MARQUEE) {
|
|
|
|
Point2d begin = ProjectPoint(orig.marqueePoint);
|
|
|
|
double xmin = min(orig.mouse.x, begin.x),
|
|
|
|
xmax = max(orig.mouse.x, begin.x),
|
|
|
|
ymin = min(orig.mouse.y, begin.y),
|
|
|
|
ymax = max(orig.mouse.y, begin.y);
|
|
|
|
|
|
|
|
Vector tl = UnProjectPoint(Point2d::From(xmin, ymin)),
|
|
|
|
tr = UnProjectPoint(Point2d::From(xmax, ymin)),
|
|
|
|
br = UnProjectPoint(Point2d::From(xmax, ymax)),
|
|
|
|
bl = UnProjectPoint(Point2d::From(xmin, ymax));
|
|
|
|
|
|
|
|
glLineWidth((GLfloat)1.3);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(Style::Color(Style::HOVERED));
|
2009-11-04 07:52:58 +00:00
|
|
|
glBegin(GL_LINE_LOOP);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tl);
|
|
|
|
ssglVertex3v(tr);
|
|
|
|
ssglVertex3v(br);
|
|
|
|
ssglVertex3v(bl);
|
2009-11-04 07:52:58 +00:00
|
|
|
glEnd();
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGBa(Style::Color(Style::HOVERED), 0.10);
|
2009-11-04 07:52:58 +00:00
|
|
|
glBegin(GL_QUADS);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tl);
|
|
|
|
ssglVertex3v(tr);
|
|
|
|
ssglVertex3v(br);
|
|
|
|
ssglVertex3v(bl);
|
2009-11-04 07:52:58 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2010-01-14 05:24:32 +00:00
|
|
|
// An extra line, used to indicate the origin when rotating within the
|
|
|
|
// plane of the monitor.
|
2010-01-04 00:35:28 +00:00
|
|
|
if(SS.extraLine.draw) {
|
2009-11-10 03:57:24 +00:00
|
|
|
glLineWidth(1);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglLockColorTo(Style::Color(Style::DATUM));
|
2009-11-10 03:57:24 +00:00
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(SS.extraLine.ptA);
|
|
|
|
ssglVertex3v(SS.extraLine.ptB);
|
2009-11-10 03:57:24 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2010-01-14 05:24:32 +00:00
|
|
|
// A note to indicate the origin in the just-exported file.
|
|
|
|
if(SS.justExportedInfo.draw) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(Style::Color(Style::DATUM));
|
2010-01-14 05:24:32 +00:00
|
|
|
Vector p = SS.justExportedInfo.pt,
|
|
|
|
u = SS.justExportedInfo.u,
|
|
|
|
v = SS.justExportedInfo.v;
|
|
|
|
|
|
|
|
glLineWidth(1.5);
|
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(p.Plus(u.WithMagnitude(-15/scale)));
|
|
|
|
ssglVertex3v(p.Plus(u.WithMagnitude(30/scale)));
|
|
|
|
ssglVertex3v(p.Plus(v.WithMagnitude(-15/scale)));
|
|
|
|
ssglVertex3v(p.Plus(v.WithMagnitude(30/scale)));
|
2010-01-14 05:24:32 +00:00
|
|
|
glEnd();
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglWriteText("(x, y) = (0, 0) for file just exported",
|
2010-01-14 05:24:32 +00:00
|
|
|
DEFAULT_TEXT_HEIGHT,
|
|
|
|
p.Plus(u.ScaledBy(10/scale)).Plus(v.ScaledBy(10/scale)),
|
|
|
|
u, v, NULL, NULL);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglWriteText("press Esc to clear this message",
|
2010-01-14 05:24:32 +00:00
|
|
|
DEFAULT_TEXT_HEIGHT,
|
|
|
|
p.Plus(u.ScaledBy(40/scale)).Plus(
|
|
|
|
v.ScaledBy(-(DEFAULT_TEXT_HEIGHT)/scale)),
|
|
|
|
u, v, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2009-01-02 10:38:36 +00:00
|
|
|
// And finally the toolbar.
|
|
|
|
if(SS.showToolbar) {
|
|
|
|
ToolbarDraw();
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|