2008-04-14 10:28:32 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
|
|
|
bool Constraint::HasLabel(void) {
|
|
|
|
switch(type) {
|
2008-05-08 07:30:30 +00:00
|
|
|
case PT_LINE_DISTANCE:
|
|
|
|
case PT_PLANE_DISTANCE:
|
2008-06-06 08:46:55 +00:00
|
|
|
case PT_FACE_DISTANCE:
|
2008-04-14 10:28:32 +00:00
|
|
|
case PT_PT_DISTANCE:
|
2008-05-07 08:19:37 +00:00
|
|
|
case DIAMETER:
|
2008-05-11 10:40:37 +00:00
|
|
|
case LENGTH_RATIO:
|
2008-05-17 11:15:14 +00:00
|
|
|
case ANGLE:
|
2008-06-12 08:58:58 +00:00
|
|
|
case COMMENT:
|
2008-04-14 10:28:32 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
void Constraint::LineDrawOrGetDistance(Vector a, Vector b) {
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glxVertex3v(a);
|
|
|
|
glxVertex3v(b);
|
|
|
|
glEnd();
|
|
|
|
} else {
|
|
|
|
Point2d ap = SS.GW.ProjectPoint(a);
|
|
|
|
Point2d bp = SS.GW.ProjectPoint(b);
|
|
|
|
|
|
|
|
double d = dogd.mp.DistanceToLine(ap, bp.Minus(ap), true);
|
|
|
|
dogd.dmin = min(dogd.dmin, d);
|
|
|
|
}
|
2008-05-26 09:56:50 +00:00
|
|
|
dogd.refp = (a.Plus(b)).ScaledBy(0.5);
|
2008-04-21 08:16:38 +00:00
|
|
|
}
|
|
|
|
|
2008-05-07 08:19:37 +00:00
|
|
|
double Constraint::EllipticalInterpolation(double rx, double ry, double theta) {
|
|
|
|
double ex = rx*cos(theta);
|
|
|
|
double ey = ry*sin(theta);
|
|
|
|
double v = sqrt(ex*ex + ey*ey);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-06-11 04:22:52 +00:00
|
|
|
char *Constraint::Label(void) {
|
|
|
|
static char Ret[1024];
|
|
|
|
if(type == ANGLE) {
|
2008-06-14 08:43:38 +00:00
|
|
|
sprintf(Ret, "%.2f", valA);
|
2008-06-11 04:22:52 +00:00
|
|
|
} else if(type == LENGTH_RATIO) {
|
2008-06-14 08:43:38 +00:00
|
|
|
sprintf(Ret, "%.3f:1", valA);
|
2008-06-12 08:58:58 +00:00
|
|
|
} else if(type == COMMENT) {
|
|
|
|
strcpy(Ret, comment.str);
|
2008-06-11 04:22:52 +00:00
|
|
|
} else {
|
2008-06-14 08:43:38 +00:00
|
|
|
// valA has units of distance
|
2008-06-14 09:51:25 +00:00
|
|
|
strcpy(Ret, SS.MmToString(fabs(valA)));
|
2008-06-11 04:22:52 +00:00
|
|
|
}
|
|
|
|
if(reference) {
|
|
|
|
strcat(Ret, " REF");
|
|
|
|
}
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2008-05-07 08:19:37 +00:00
|
|
|
void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
|
2008-06-11 04:22:52 +00:00
|
|
|
char *s = Label();
|
2008-06-12 08:58:58 +00:00
|
|
|
double swidth = glxStrWidth(s), sheight = glxStrHeight();
|
2008-05-07 08:19:37 +00:00
|
|
|
if(labelPos) {
|
|
|
|
// labelPos is from the top left corner (for the text box used to
|
|
|
|
// edit things), but ref is from the center.
|
2008-06-12 08:58:58 +00:00
|
|
|
*labelPos = ref.Minus(gr.WithMagnitude(swidth/2)).Minus(
|
|
|
|
gu.WithMagnitude(sheight/2));
|
2008-05-07 08:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glPushMatrix();
|
|
|
|
glxTranslatev(ref);
|
|
|
|
glxOntoWorkplane(gr, gu);
|
|
|
|
glxWriteTextRefCenter(s);
|
|
|
|
glPopMatrix();
|
|
|
|
} else {
|
2008-06-12 08:58:58 +00:00
|
|
|
double l = swidth/2 - sheight/2;
|
2008-07-06 07:56:24 +00:00
|
|
|
l = max(l, 5/SS.GW.scale);
|
2008-06-12 08:58:58 +00:00
|
|
|
Point2d a = SS.GW.ProjectPoint(ref.Minus(gr.WithMagnitude(l)));
|
|
|
|
Point2d b = SS.GW.ProjectPoint(ref.Plus (gr.WithMagnitude(l)));
|
|
|
|
double d = dogd.mp.DistanceToLine(a, b.Minus(a), true);
|
|
|
|
|
|
|
|
dogd.dmin = min(dogd.dmin, d - 3);
|
2008-05-26 09:56:50 +00:00
|
|
|
dogd.refp = ref;
|
2008-05-07 08:19:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
void Constraint::DoProjectedPoint(Vector *r) {
|
|
|
|
Vector p = r->ProjectInto(workplane);
|
|
|
|
glLineStipple(4, 0x5555);
|
|
|
|
glEnable(GL_LINE_STIPPLE);
|
|
|
|
LineDrawOrGetDistance(p, *r);
|
|
|
|
glDisable(GL_LINE_STIPPLE);
|
|
|
|
*r = p;
|
|
|
|
}
|
|
|
|
|
2008-06-14 11:16:14 +00:00
|
|
|
void Constraint::DoEqualLenTicks(Vector a, Vector b, Vector gn) {
|
|
|
|
Vector m = (a.ScaledBy(1.0/3)).Plus(b.ScaledBy(2.0/3));
|
|
|
|
Vector ab = a.Minus(b);
|
|
|
|
Vector n = (gn.Cross(ab)).WithMagnitude(10/SS.GW.scale);
|
|
|
|
|
|
|
|
LineDrawOrGetDistance(m.Minus(n), m.Plus(n));
|
|
|
|
}
|
|
|
|
|
2009-01-08 17:22:59 +00:00
|
|
|
void Constraint::DoEqualRadiusTicks(hEntity he) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *circ = SK.GetEntity(he);
|
2009-01-08 17:22:59 +00:00
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector center = SK.GetEntity(circ->point[0])->PointGetNum();
|
2009-01-08 17:22:59 +00:00
|
|
|
double r = circ->CircleGetRadiusNum();
|
|
|
|
Quaternion q = circ->Normal()->NormalGetNum();
|
|
|
|
Vector u = q.RotationU(), v = q.RotationV();
|
|
|
|
|
|
|
|
double theta;
|
|
|
|
if(circ->type == Entity::CIRCLE) {
|
|
|
|
theta = PI/2;
|
|
|
|
} else if(circ->type == Entity::ARC_OF_CIRCLE) {
|
|
|
|
double thetaa, thetab, dtheta;
|
|
|
|
circ->ArcGetAngles(&thetaa, &thetab, &dtheta);
|
|
|
|
theta = thetaa + dtheta/2;
|
|
|
|
} else oops();
|
|
|
|
|
|
|
|
Vector d = u.ScaledBy(cos(theta)).Plus(v.ScaledBy(sin(theta)));
|
|
|
|
d = d.ScaledBy(r);
|
|
|
|
Vector p = center.Plus(d);
|
|
|
|
Vector tick = d.WithMagnitude(10/SS.GW.scale);
|
|
|
|
LineDrawOrGetDistance(p.Plus(tick), p.Minus(tick));
|
|
|
|
}
|
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
void Constraint::DoArcForAngle(Vector a0, Vector da, Vector b0, Vector db,
|
|
|
|
Vector offset, Vector *ref)
|
|
|
|
{
|
|
|
|
Vector gr = SS.GW.projRight.ScaledBy(1/SS.GW.scale);
|
|
|
|
Vector gu = SS.GW.projUp.ScaledBy(1/SS.GW.scale);
|
|
|
|
|
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
a0 = a0.ProjectInto(workplane);
|
|
|
|
b0 = b0.ProjectInto(workplane);
|
|
|
|
da = da.ProjectVectorInto(workplane);
|
|
|
|
db = db.ProjectVectorInto(workplane);
|
|
|
|
}
|
|
|
|
|
2009-01-03 12:27:33 +00:00
|
|
|
bool skew;
|
|
|
|
Vector pi = Vector::AtIntersectionOfLines(a0, a0.Plus(da),
|
|
|
|
b0, b0.Plus(db), &skew);
|
|
|
|
|
|
|
|
if(!skew) {
|
2008-07-20 12:24:43 +00:00
|
|
|
*ref = pi.Plus(offset);
|
2009-01-03 12:27:33 +00:00
|
|
|
// We draw in a coordinate system centered at the intersection point.
|
|
|
|
// One basis vector is da, and the other is normal to da and in
|
|
|
|
// the plane that contains our lines (so normal to its normal).
|
|
|
|
Vector dna = (da.Cross(db)).Cross(da);
|
2008-07-20 12:24:43 +00:00
|
|
|
da = da.WithMagnitude(1); dna = dna.WithMagnitude(1);
|
2009-01-03 12:27:33 +00:00
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
Vector rm = (*ref).Minus(pi);
|
|
|
|
double rda = rm.Dot(da), rdna = rm.Dot(dna);
|
|
|
|
double r = sqrt(rda*rda + rdna*rdna);
|
|
|
|
double c = (da.Dot(db))/(da.Magnitude()*db.Magnitude());
|
|
|
|
double thetaf = acos(c);
|
|
|
|
|
|
|
|
Vector m = da.ScaledBy(cos(thetaf/2)).Plus(
|
|
|
|
dna.ScaledBy(sin(thetaf/2)));
|
|
|
|
if(m.Dot(rm) < 0) {
|
|
|
|
da = da.ScaledBy(-1); dna = dna.ScaledBy(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector prev = da.ScaledBy(r).Plus(pi);
|
|
|
|
int i, n = 30;
|
|
|
|
for(i = 0; i <= n; i++) {
|
|
|
|
double theta = (i*thetaf)/n;
|
|
|
|
Vector p = da. ScaledBy(r*cos(theta)).Plus(
|
|
|
|
dna.ScaledBy(r*sin(theta))).Plus(pi);
|
|
|
|
LineDrawOrGetDistance(prev, p);
|
|
|
|
prev = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
double tl = atan2(rm.Dot(gu), rm.Dot(gr));
|
|
|
|
double adj = EllipticalInterpolation(
|
|
|
|
glxStrWidth(Label())/2, glxStrHeight()/2, tl);
|
|
|
|
*ref = (*ref).Plus(rm.WithMagnitude(adj + 3/SS.GW.scale));
|
|
|
|
} else {
|
|
|
|
// The lines are skew; no wonderful way to illustrate that.
|
|
|
|
*ref = a0.Plus(b0);
|
|
|
|
*ref = (*ref).ScaledBy(0.5).Plus(disp.offset);
|
|
|
|
glPushMatrix();
|
|
|
|
gu = gu.WithMagnitude(1);
|
|
|
|
glxTranslatev((*ref).Plus(gu.ScaledBy(-1.5*glxStrHeight())));
|
|
|
|
glxOntoWorkplane(gr, gu);
|
|
|
|
glxWriteTextRefCenter("angle between skew lines");
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-21 10:12:04 +00:00
|
|
|
void Constraint::DrawOrGetDistance(Vector *labelPos) {
|
2008-04-21 08:16:38 +00:00
|
|
|
if(!SS.GW.showConstraints) return;
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.GetGroup(group);
|
2008-04-28 07:18:39 +00:00
|
|
|
// If the group is hidden, then the constraints are hidden and not
|
|
|
|
// able to be selected.
|
|
|
|
if(!(g->visible)) return;
|
2008-05-07 04:17:29 +00:00
|
|
|
// And likewise if the group is not the active group.
|
|
|
|
if(g->h.v != SS.GW.activeGroup.v) return;
|
2008-04-21 08:16:38 +00:00
|
|
|
|
2008-04-28 09:40:02 +00:00
|
|
|
// Unit vectors that describe our current view of the scene. One pixel
|
|
|
|
// long, not one actual unit.
|
|
|
|
Vector gr = SS.GW.projRight.ScaledBy(1/SS.GW.scale);
|
|
|
|
Vector gu = SS.GW.projUp.ScaledBy(1/SS.GW.scale);
|
|
|
|
Vector gn = (gr.Cross(gu)).WithMagnitude(1/SS.GW.scale);
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-05-25 14:36:03 +00:00
|
|
|
glxColor3d(1, 0.1, 1);
|
2008-04-14 10:28:32 +00:00
|
|
|
switch(type) {
|
|
|
|
case PT_PT_DISTANCE: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector ap = SK.GetEntity(ptA)->PointGetNum();
|
|
|
|
Vector bp = SK.GetEntity(ptB)->PointGetNum();
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
DoProjectedPoint(&ap);
|
|
|
|
DoProjectedPoint(&bp);
|
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
Vector ref = ((ap.Plus(bp)).ScaledBy(0.5)).Plus(disp.offset);
|
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
Vector ab = ap.Minus(bp);
|
|
|
|
Vector ar = ap.Minus(ref);
|
|
|
|
// Normal to a plan containing the line and the label origin.
|
|
|
|
Vector n = ab.Cross(ar);
|
|
|
|
Vector out = ab.Cross(n).WithMagnitude(1);
|
|
|
|
out = out.ScaledBy(-out.Dot(ar));
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
LineDrawOrGetDistance(ap, ap.Plus(out));
|
|
|
|
LineDrawOrGetDistance(bp, bp.Plus(out));
|
|
|
|
|
2008-05-07 08:19:37 +00:00
|
|
|
DoLabel(ref, labelPos, gr, gu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-06 08:46:55 +00:00
|
|
|
case PT_FACE_DISTANCE:
|
2008-05-08 07:30:30 +00:00
|
|
|
case PT_PLANE_DISTANCE: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector pt = SK.GetEntity(ptA)->PointGetNum();
|
|
|
|
Entity *enta = SK.GetEntity(entityA);
|
2008-06-06 08:46:55 +00:00
|
|
|
Vector n, p;
|
|
|
|
if(type == PT_PLANE_DISTANCE) {
|
|
|
|
n = enta->Normal()->NormalN();
|
|
|
|
p = enta->WorkplaneGetOffset();
|
|
|
|
} else {
|
|
|
|
n = enta->FaceGetNormalNum();
|
|
|
|
p = enta->FaceGetPointNum();
|
|
|
|
}
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
double d = (p.Minus(pt)).Dot(n);
|
|
|
|
|
|
|
|
Vector closest = pt.Plus(n.WithMagnitude(d));
|
|
|
|
LineDrawOrGetDistance(pt, closest);
|
|
|
|
|
|
|
|
Vector ref = ((closest.Plus(pt)).ScaledBy(0.5)).Plus(disp.offset);
|
|
|
|
DoLabel(ref, labelPos, gr, gu);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PT_LINE_DISTANCE: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector pt = SK.GetEntity(ptA)->PointGetNum();
|
|
|
|
Entity *line = SK.GetEntity(entityA);
|
|
|
|
Vector lA = SK.GetEntity(line->point[0])->PointGetNum();
|
|
|
|
Vector lB = SK.GetEntity(line->point[1])->PointGetNum();
|
2008-05-08 07:30:30 +00:00
|
|
|
|
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
lA = lA.ProjectInto(workplane);
|
|
|
|
lB = lB.ProjectInto(workplane);
|
|
|
|
DoProjectedPoint(&pt);
|
|
|
|
}
|
|
|
|
|
2008-06-14 11:16:14 +00:00
|
|
|
// Find the closest point on the line
|
|
|
|
Vector closest = pt.ClosestPointOnLine(lA, (lA.Minus(lB)));
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
LineDrawOrGetDistance(pt, closest);
|
|
|
|
Vector ref = ((closest.Plus(pt)).ScaledBy(0.5)).Plus(disp.offset);
|
|
|
|
DoLabel(ref, labelPos, gr, gu);
|
2008-05-08 08:12:23 +00:00
|
|
|
|
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
// Draw the projection marker from the closest point on the
|
|
|
|
// projected line to the projected point on the real line.
|
2008-06-14 11:16:14 +00:00
|
|
|
Vector lAB = (lA.Minus(lB));
|
2008-05-08 08:12:23 +00:00
|
|
|
double t = (lA.Minus(closest)).DivPivoting(lAB);
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector lA = SK.GetEntity(line->point[0])->PointGetNum();
|
|
|
|
Vector lB = SK.GetEntity(line->point[1])->PointGetNum();
|
2008-05-08 08:12:23 +00:00
|
|
|
|
|
|
|
Vector c2 = (lA.ScaledBy(1-t)).Plus(lB.ScaledBy(t));
|
|
|
|
DoProjectedPoint(&c2);
|
|
|
|
}
|
2008-05-08 07:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-07 08:19:37 +00:00
|
|
|
case DIAMETER: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *circle = SK.GetEntity(entityA);
|
|
|
|
Vector center = SK.GetEntity(circle->point[0])->PointGetNum();
|
2008-05-12 10:01:44 +00:00
|
|
|
double r = circle->CircleGetRadiusNum();
|
2008-05-07 08:19:37 +00:00
|
|
|
Vector ref = center.Plus(disp.offset);
|
|
|
|
|
|
|
|
double theta = atan2(disp.offset.Dot(gu), disp.offset.Dot(gr));
|
|
|
|
double adj = EllipticalInterpolation(
|
2008-06-11 04:22:52 +00:00
|
|
|
glxStrWidth(Label())/2, glxStrHeight()/2, theta);
|
2008-05-07 08:19:37 +00:00
|
|
|
|
|
|
|
Vector mark = ref.Minus(center);
|
|
|
|
mark = mark.WithMagnitude(mark.Magnitude()-r);
|
|
|
|
LineDrawOrGetDistance(ref.Minus(mark.WithMagnitude(adj)),
|
|
|
|
ref.Minus(mark));
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-05-07 08:19:37 +00:00
|
|
|
DoLabel(ref, labelPos, gr, gu);
|
2008-04-14 10:28:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
case POINTS_COINCIDENT: {
|
2008-04-22 10:53:42 +00:00
|
|
|
if(!dogd.drawing) {
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector p = SK.GetEntity(i == 0 ? ptA : ptB)-> PointGetNum();
|
2008-04-22 10:53:42 +00:00
|
|
|
Point2d pp = SS.GW.ProjectPoint(p);
|
|
|
|
// The point is selected within a radius of 7, from the
|
|
|
|
// same center; so if the point is visible, then this
|
|
|
|
// constraint cannot be selected. But that's okay.
|
|
|
|
dogd.dmin = min(dogd.dmin, pp.DistanceTo(dogd.mp) - 3);
|
2008-05-26 09:56:50 +00:00
|
|
|
dogd.refp = p;
|
2008-04-22 10:53:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int a = 0; a < 2; a++) {
|
|
|
|
Vector r = SS.GW.projRight.ScaledBy((a+1)/SS.GW.scale);
|
|
|
|
Vector d = SS.GW.projUp.ScaledBy((2-a)/SS.GW.scale);
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector p = SK.GetEntity(i == 0 ? ptA : ptB)-> PointGetNum();
|
2008-04-25 07:04:09 +00:00
|
|
|
glxColor3d(0.4, 0, 0.4);
|
2008-04-22 10:53:42 +00:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glxVertex3v(p.Plus (r).Plus (d));
|
|
|
|
glxVertex3v(p.Plus (r).Minus(d));
|
|
|
|
glxVertex3v(p.Minus(r).Minus(d));
|
|
|
|
glxVertex3v(p.Minus(r).Plus (d));
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
case PT_ON_CIRCLE:
|
2008-04-28 09:40:02 +00:00
|
|
|
case PT_ON_LINE:
|
2008-06-02 03:31:37 +00:00
|
|
|
case PT_ON_FACE:
|
2008-04-21 08:16:38 +00:00
|
|
|
case PT_IN_PLANE: {
|
2008-06-02 03:31:37 +00:00
|
|
|
double s = 8/SS.GW.scale;
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector p = SK.GetEntity(ptA)->PointGetNum();
|
2008-06-02 03:31:37 +00:00
|
|
|
Vector r, d;
|
|
|
|
if(type == PT_ON_FACE) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector n = SK.GetEntity(entityA)->FaceGetNormalNum();
|
2008-06-02 03:31:37 +00:00
|
|
|
r = n.Normal(0);
|
|
|
|
d = n.Normal(1);
|
|
|
|
} else if(type == PT_IN_PLANE) {
|
2009-04-20 07:30:09 +00:00
|
|
|
EntityBase *n = SK.GetEntity(entityA)->Normal();
|
2008-06-02 03:31:37 +00:00
|
|
|
r = n->NormalU();
|
|
|
|
d = n->NormalV();
|
|
|
|
} else {
|
|
|
|
r = gr;
|
|
|
|
d = gu;
|
|
|
|
s *= (6.0/8); // draw these a little smaller
|
|
|
|
}
|
|
|
|
r = r.WithMagnitude(s); d = d.WithMagnitude(s);
|
2008-04-21 08:16:38 +00:00
|
|
|
LineDrawOrGetDistance(p.Plus (r).Plus (d), p.Plus (r).Minus(d));
|
|
|
|
LineDrawOrGetDistance(p.Plus (r).Minus(d), p.Minus(r).Minus(d));
|
|
|
|
LineDrawOrGetDistance(p.Minus(r).Minus(d), p.Minus(r).Plus (d));
|
|
|
|
LineDrawOrGetDistance(p.Minus(r).Plus (d), p.Plus (r).Plus (d));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
case SAME_ORIENTATION: {
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.GetEntity(i == 0 ? entityA : entityB);
|
2008-05-09 05:33:23 +00:00
|
|
|
Quaternion q = e->NormalGetNum();
|
|
|
|
Vector n = q.RotationN().WithMagnitude(25/SS.GW.scale);
|
|
|
|
Vector u = q.RotationU().WithMagnitude(6/SS.GW.scale);
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector p = SK.GetEntity(e->point[0])->PointGetNum();
|
2008-05-09 05:33:23 +00:00
|
|
|
p = p.Plus(n.WithMagnitude(10/SS.GW.scale));
|
|
|
|
|
|
|
|
LineDrawOrGetDistance(p.Plus(u), p.Minus(u).Plus(n));
|
|
|
|
LineDrawOrGetDistance(p.Minus(u), p.Plus(u).Plus(n));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
case EQUAL_ANGLE: {
|
|
|
|
Vector ref;
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *a = SK.GetEntity(entityA);
|
|
|
|
Entity *b = SK.GetEntity(entityB);
|
|
|
|
Entity *c = SK.GetEntity(entityC);
|
|
|
|
Entity *d = SK.GetEntity(entityD);
|
2008-07-20 12:24:43 +00:00
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
Vector a0 = a->VectorGetRefPoint();
|
|
|
|
Vector b0 = b->VectorGetRefPoint();
|
2008-07-20 12:24:43 +00:00
|
|
|
Vector c0 = c->VectorGetRefPoint();
|
|
|
|
Vector d0 = d->VectorGetRefPoint();
|
2008-05-17 11:15:14 +00:00
|
|
|
Vector da = a->VectorGetNum();
|
|
|
|
Vector db = b->VectorGetNum();
|
2008-07-20 12:24:43 +00:00
|
|
|
Vector dc = c->VectorGetNum();
|
|
|
|
Vector dd = d->VectorGetNum();
|
2008-05-17 11:15:14 +00:00
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
if(other) da = da.ScaledBy(-1);
|
2008-05-17 11:15:14 +00:00
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
DoArcForAngle(a0, da, b0, db,
|
|
|
|
da.WithMagnitude(40/SS.GW.scale), &ref);
|
|
|
|
DoArcForAngle(c0, dc, d0, dd,
|
|
|
|
dc.WithMagnitude(40/SS.GW.scale), &ref);
|
2008-05-17 11:15:14 +00:00
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-17 11:15:14 +00:00
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
case ANGLE: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *a = SK.GetEntity(entityA);
|
|
|
|
Entity *b = SK.GetEntity(entityB);
|
2008-05-17 11:15:14 +00:00
|
|
|
|
2008-07-20 12:24:43 +00:00
|
|
|
Vector a0 = a->VectorGetRefPoint();
|
|
|
|
Vector b0 = b->VectorGetRefPoint();
|
|
|
|
Vector da = a->VectorGetNum();
|
|
|
|
Vector db = b->VectorGetNum();
|
|
|
|
if(other) da = da.ScaledBy(-1);
|
|
|
|
|
|
|
|
Vector ref;
|
|
|
|
DoArcForAngle(a0, da, b0, db, disp.offset, &ref);
|
2008-05-17 11:15:14 +00:00
|
|
|
DoLabel(ref, labelPos, gr, gu);
|
|
|
|
break;
|
2008-07-02 09:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case PERPENDICULAR: {
|
|
|
|
Vector u, v;
|
|
|
|
Vector rn, ru;
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
rn = gn;
|
|
|
|
ru = gu;
|
|
|
|
} else {
|
2009-04-20 07:30:09 +00:00
|
|
|
EntityBase *normal = SK.GetEntity(workplane)->Normal();
|
2008-07-02 09:21:29 +00:00
|
|
|
rn = normal->NormalN();
|
|
|
|
ru = normal->NormalV(); // ru meaning r_up, not u/v
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.GetEntity(i == 0 ? entityA : entityB);
|
2008-07-02 09:21:29 +00:00
|
|
|
|
|
|
|
if(i == 0) {
|
|
|
|
// Calculate orientation of perpendicular sign only
|
|
|
|
// once, so that it's the same both times it's drawn
|
|
|
|
u = e->VectorGetNum();
|
|
|
|
u = u.WithMagnitude(16/SS.GW.scale);
|
|
|
|
v = (rn.Cross(u)).WithMagnitude(16/SS.GW.scale);
|
|
|
|
if(fabs(u.Dot(ru)) < fabs(v.Dot(ru))) {
|
|
|
|
SWAP(Vector, u, v);
|
|
|
|
}
|
|
|
|
if(u.Dot(ru) < 0) u = u.ScaledBy(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector p = e->VectorGetRefPoint();
|
|
|
|
Vector s = p.Plus(u).Plus(v);
|
|
|
|
LineDrawOrGetDistance(s, s.Plus(v));
|
|
|
|
|
|
|
|
Vector m = s.Plus(v.ScaledBy(0.5));
|
|
|
|
LineDrawOrGetDistance(m, m.Plus(u));
|
|
|
|
}
|
|
|
|
break;
|
2008-07-13 12:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case CUBIC_LINE_TANGENT:
|
|
|
|
case ARC_LINE_TANGENT: {
|
|
|
|
Vector textAt, u, v;
|
|
|
|
|
|
|
|
if(type == ARC_LINE_TANGENT) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *arc = SK.GetEntity(entityA);
|
|
|
|
Entity *norm = SK.GetEntity(arc->normal);
|
|
|
|
Vector c = SK.GetEntity(arc->point[0])->PointGetNum();
|
2008-07-13 12:44:05 +00:00
|
|
|
Vector p =
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetEntity(arc->point[other ? 2 : 1])->PointGetNum();
|
2008-07-13 12:44:05 +00:00
|
|
|
Vector r = p.Minus(c);
|
|
|
|
textAt = p.Plus(r.WithMagnitude(14/SS.GW.scale));
|
|
|
|
u = norm->NormalU();
|
|
|
|
v = norm->NormalV();
|
|
|
|
} else {
|
|
|
|
Vector n;
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
u = gr;
|
|
|
|
v = gu;
|
|
|
|
n = gn;
|
|
|
|
} else {
|
2009-04-20 07:30:09 +00:00
|
|
|
EntityBase *wn = SK.GetEntity(workplane)->Normal();
|
2008-07-13 12:44:05 +00:00
|
|
|
u = wn->NormalU();
|
|
|
|
v = wn->NormalV();
|
|
|
|
n = wn->NormalN();
|
|
|
|
}
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *cubic = SK.GetEntity(entityA);
|
2008-07-13 12:44:05 +00:00
|
|
|
Vector p =
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetEntity(cubic->point[other ? 3 : 0])->PointGetNum();
|
|
|
|
Vector dir = SK.GetEntity(entityB)->VectorGetNum();
|
2008-07-13 12:44:05 +00:00
|
|
|
Vector out = n.Cross(dir);
|
|
|
|
textAt = p.Plus(out.WithMagnitude(14/SS.GW.scale));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glPushMatrix();
|
|
|
|
glxTranslatev(textAt);
|
|
|
|
glxOntoWorkplane(u, v);
|
|
|
|
glxWriteTextRefCenter("T");
|
|
|
|
glPopMatrix();
|
|
|
|
} else {
|
|
|
|
dogd.refp = textAt;
|
|
|
|
Point2d ref = SS.GW.ProjectPoint(dogd.refp);
|
|
|
|
dogd.dmin = min(dogd.dmin, ref.DistanceTo(dogd.mp)-10);
|
|
|
|
}
|
|
|
|
break;
|
2008-05-17 11:15:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
case PARALLEL: {
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.GetEntity(i == 0 ? entityA : entityB);
|
2008-05-11 10:40:37 +00:00
|
|
|
Vector n = e->VectorGetNum();
|
2008-05-09 05:33:23 +00:00
|
|
|
n = n.WithMagnitude(25/SS.GW.scale);
|
|
|
|
Vector u = (gn.Cross(n)).WithMagnitude(4/SS.GW.scale);
|
|
|
|
Vector p = e->VectorGetRefPoint();
|
|
|
|
|
|
|
|
LineDrawOrGetDistance(p.Plus(u), p.Plus(u).Plus(n));
|
|
|
|
LineDrawOrGetDistance(p.Minus(u), p.Minus(u).Plus(n));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-12 10:01:44 +00:00
|
|
|
case EQUAL_RADIUS: {
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-01-08 17:22:59 +00:00
|
|
|
DoEqualRadiusTicks(i == 0 ? entityA : entityB);
|
2008-05-12 10:01:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-08 17:22:59 +00:00
|
|
|
case EQUAL_LINE_ARC_LEN: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *line = SK.GetEntity(entityA);
|
2009-01-08 17:22:59 +00:00
|
|
|
DoEqualLenTicks(
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetEntity(line->point[0])->PointGetNum(),
|
|
|
|
SK.GetEntity(line->point[1])->PointGetNum(),
|
2009-01-08 17:22:59 +00:00
|
|
|
gn);
|
|
|
|
|
|
|
|
DoEqualRadiusTicks(entityB);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
case LENGTH_RATIO:
|
2008-04-22 05:00:49 +00:00
|
|
|
case EQUAL_LENGTH_LINES: {
|
2008-05-11 10:40:37 +00:00
|
|
|
Vector a, b;
|
2008-04-22 05:00:49 +00:00
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.GetEntity(i == 0 ? entityA : entityB);
|
|
|
|
a = SK.GetEntity(e->point[0])->PointGetNum();
|
|
|
|
b = SK.GetEntity(e->point[1])->PointGetNum();
|
2008-06-14 11:16:14 +00:00
|
|
|
|
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
DoProjectedPoint(&a);
|
|
|
|
DoProjectedPoint(&b);
|
|
|
|
}
|
|
|
|
|
|
|
|
DoEqualLenTicks(a, b, gn);
|
2008-04-22 05:00:49 +00:00
|
|
|
}
|
2008-05-11 10:40:37 +00:00
|
|
|
if(type == LENGTH_RATIO) {
|
|
|
|
Vector ref = ((a.Plus(b)).ScaledBy(0.5)).Plus(disp.offset);
|
|
|
|
DoLabel(ref, labelPos, gr, gu);
|
|
|
|
}
|
2008-04-22 05:00:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-14 11:16:14 +00:00
|
|
|
case EQ_LEN_PT_LINE_D: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *forLen = SK.GetEntity(entityA);
|
|
|
|
Vector a = SK.GetEntity(forLen->point[0])->PointGetNum(),
|
|
|
|
b = SK.GetEntity(forLen->point[1])->PointGetNum();
|
2008-06-14 11:16:14 +00:00
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
DoProjectedPoint(&a);
|
|
|
|
DoProjectedPoint(&b);
|
|
|
|
}
|
|
|
|
DoEqualLenTicks(a, b, gn);
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *ln = SK.GetEntity(entityB);
|
|
|
|
Vector la = SK.GetEntity(ln->point[0])->PointGetNum(),
|
|
|
|
lb = SK.GetEntity(ln->point[1])->PointGetNum();
|
|
|
|
Vector pt = SK.GetEntity(ptA)->PointGetNum();
|
2008-06-14 11:16:14 +00:00
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
DoProjectedPoint(&pt);
|
|
|
|
la = la.ProjectInto(workplane);
|
|
|
|
lb = lb.ProjectInto(workplane);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector closest = pt.ClosestPointOnLine(la, lb.Minus(la));
|
|
|
|
LineDrawOrGetDistance(pt, closest);
|
|
|
|
DoEqualLenTicks(pt, closest, gn);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EQ_PT_LN_DISTANCES: {
|
|
|
|
for(int i = 0; i < 2; i++) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *ln = SK.GetEntity(i == 0 ? entityA : entityB);
|
|
|
|
Vector la = SK.GetEntity(ln->point[0])->PointGetNum(),
|
|
|
|
lb = SK.GetEntity(ln->point[1])->PointGetNum();
|
|
|
|
Entity *pte = SK.GetEntity(i == 0 ? ptA : ptB);
|
2008-06-14 11:16:14 +00:00
|
|
|
Vector pt = pte->PointGetNum();
|
|
|
|
|
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
DoProjectedPoint(&pt);
|
|
|
|
la = la.ProjectInto(workplane);
|
|
|
|
lb = lb.ProjectInto(workplane);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector closest = pt.ClosestPointOnLine(la, lb.Minus(la));
|
|
|
|
|
|
|
|
LineDrawOrGetDistance(pt, closest);
|
|
|
|
DoEqualLenTicks(pt, closest, gn);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-13 10:38:21 +00:00
|
|
|
{
|
|
|
|
Vector n;
|
|
|
|
case SYMMETRIC:
|
2009-04-19 05:53:16 +00:00
|
|
|
n = SK.GetEntity(entityA)->Normal()->NormalN(); goto s;
|
2008-05-13 10:38:21 +00:00
|
|
|
case SYMMETRIC_HORIZ:
|
2009-04-19 05:53:16 +00:00
|
|
|
n = SK.GetEntity(workplane)->Normal()->NormalU(); goto s;
|
2008-05-13 10:38:21 +00:00
|
|
|
case SYMMETRIC_VERT:
|
2009-04-19 05:53:16 +00:00
|
|
|
n = SK.GetEntity(workplane)->Normal()->NormalV(); goto s;
|
2008-07-02 06:59:49 +00:00
|
|
|
case SYMMETRIC_LINE: {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *ln = SK.GetEntity(entityA);
|
|
|
|
Vector la = SK.GetEntity(ln->point[0])->PointGetNum(),
|
|
|
|
lb = SK.GetEntity(ln->point[1])->PointGetNum();
|
2008-07-02 06:59:49 +00:00
|
|
|
la = la.ProjectInto(workplane);
|
|
|
|
lb = lb.ProjectInto(workplane);
|
|
|
|
n = lb.Minus(la);
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector nw = SK.GetEntity(workplane)->Normal()->NormalN();
|
2008-07-02 06:59:49 +00:00
|
|
|
n = n.RotatedAbout(nw, PI/2);
|
|
|
|
goto s;
|
|
|
|
}
|
2008-05-13 10:38:21 +00:00
|
|
|
s:
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector a = SK.GetEntity(ptA)->PointGetNum();
|
|
|
|
Vector b = SK.GetEntity(ptB)->PointGetNum();
|
2008-07-02 06:59:49 +00:00
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
for(int i = 0; i < 2; i++) {
|
|
|
|
Vector tail = (i == 0) ? a : b;
|
|
|
|
Vector d = (i == 0) ? b : a;
|
|
|
|
d = d.Minus(tail);
|
|
|
|
// Project the direction in which the arrow is drawn normal
|
|
|
|
// to the symmetry plane; for projected symmetry constraints,
|
|
|
|
// they might not be in the same direction, even when the
|
|
|
|
// constraint is fully solved.
|
|
|
|
d = n.ScaledBy(d.Dot(n));
|
|
|
|
d = d.WithMagnitude(20/SS.GW.scale);
|
|
|
|
Vector tip = tail.Plus(d);
|
|
|
|
|
|
|
|
LineDrawOrGetDistance(tail, tip);
|
|
|
|
d = d.WithMagnitude(9/SS.GW.scale);
|
|
|
|
LineDrawOrGetDistance(tip, tip.Minus(d.RotatedAbout(gn, 0.6)));
|
|
|
|
LineDrawOrGetDistance(tip, tip.Minus(d.RotatedAbout(gn, -0.6)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AT_MIDPOINT:
|
2008-04-23 07:29:19 +00:00
|
|
|
case HORIZONTAL:
|
|
|
|
case VERTICAL:
|
|
|
|
if(entityA.v) {
|
2008-05-03 03:33:35 +00:00
|
|
|
Vector r, u, n;
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
r = gr; u = gu; n = gn;
|
|
|
|
} else {
|
2009-04-19 05:53:16 +00:00
|
|
|
r = SK.GetEntity(workplane)->Normal()->NormalU();
|
|
|
|
u = SK.GetEntity(workplane)->Normal()->NormalV();
|
2008-05-03 03:33:35 +00:00
|
|
|
n = r.Cross(u);
|
|
|
|
}
|
2008-04-30 08:14:32 +00:00
|
|
|
// For "at midpoint", this branch is always taken.
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *e = SK.GetEntity(entityA);
|
|
|
|
Vector a = SK.GetEntity(e->point[0])->PointGetNum();
|
|
|
|
Vector b = SK.GetEntity(e->point[1])->PointGetNum();
|
2008-04-23 07:29:19 +00:00
|
|
|
Vector m = (a.ScaledBy(0.5)).Plus(b.ScaledBy(0.5));
|
2008-05-03 03:33:35 +00:00
|
|
|
Vector offset = (a.Minus(b)).Cross(n);
|
2008-04-30 08:14:32 +00:00
|
|
|
offset = offset.WithMagnitude(13/SS.GW.scale);
|
2008-05-01 06:53:50 +00:00
|
|
|
// Draw midpoint constraint on other side of line, so that
|
|
|
|
// a line can be midpoint and horizontal at same time.
|
|
|
|
if(type == AT_MIDPOINT) offset = offset.ScaledBy(-1);
|
2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glPushMatrix();
|
2008-04-30 08:14:32 +00:00
|
|
|
glxTranslatev(m.Plus(offset));
|
2008-05-03 03:33:35 +00:00
|
|
|
glxOntoWorkplane(r, u);
|
2008-04-30 08:14:32 +00:00
|
|
|
glxWriteTextRefCenter(
|
|
|
|
(type == HORIZONTAL) ? "H" : (
|
|
|
|
(type == VERTICAL) ? "V" : (
|
|
|
|
(type == AT_MIDPOINT) ? "M" : NULL)));
|
2008-04-23 07:29:19 +00:00
|
|
|
glPopMatrix();
|
|
|
|
} else {
|
2008-05-26 09:56:50 +00:00
|
|
|
dogd.refp = m.Plus(offset);
|
|
|
|
Point2d ref = SS.GW.ProjectPoint(dogd.refp);
|
2008-04-23 07:29:19 +00:00
|
|
|
dogd.dmin = min(dogd.dmin, ref.DistanceTo(dogd.mp)-10);
|
|
|
|
}
|
|
|
|
} else {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector a = SK.GetEntity(ptA)->PointGetNum();
|
|
|
|
Vector b = SK.GetEntity(ptB)->PointGetNum();
|
2008-04-23 07:46:24 +00:00
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *w = SK.GetEntity(workplane);
|
2008-05-05 11:17:00 +00:00
|
|
|
Vector cu = w->Normal()->NormalU();
|
|
|
|
Vector cv = w->Normal()->NormalV();
|
|
|
|
Vector cn = w->Normal()->NormalN();
|
2008-04-23 07:29:19 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 2; i++) {
|
|
|
|
Vector o = (i == 0) ? a : b;
|
2008-04-23 07:46:24 +00:00
|
|
|
Vector oo = (i == 0) ? a.Minus(b) : b.Minus(a);
|
|
|
|
Vector d = (type == HORIZONTAL) ? cu : cv;
|
|
|
|
if(oo.Dot(d) < 0) d = d.ScaledBy(-1);
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
Vector dp = cn.Cross(d);
|
|
|
|
d = d.WithMagnitude(14/SS.GW.scale);
|
|
|
|
Vector c = o.Minus(d);
|
|
|
|
LineDrawOrGetDistance(o, c);
|
|
|
|
d = d.WithMagnitude(3/SS.GW.scale);
|
|
|
|
dp = dp.WithMagnitude(2/SS.GW.scale);
|
|
|
|
if(dogd.drawing) {
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glxVertex3v((c.Plus(d)).Plus(dp));
|
|
|
|
glxVertex3v((c.Minus(d)).Plus(dp));
|
|
|
|
glxVertex3v((c.Minus(d)).Minus(dp));
|
|
|
|
glxVertex3v((c.Plus(d)).Minus(dp));
|
|
|
|
glEnd();
|
|
|
|
} else {
|
|
|
|
Point2d ref = SS.GW.ProjectPoint(c);
|
|
|
|
dogd.dmin = min(dogd.dmin, ref.DistanceTo(dogd.mp)-6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-06-12 08:58:58 +00:00
|
|
|
case COMMENT:
|
|
|
|
DoLabel(disp.offset, labelPos, gr, gu);
|
|
|
|
break;
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Constraint::Draw(void) {
|
|
|
|
dogd.drawing = true;
|
2008-06-06 07:50:08 +00:00
|
|
|
glLineWidth(1);
|
2008-04-21 10:12:04 +00:00
|
|
|
DrawOrGetDistance(NULL);
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double Constraint::GetDistance(Point2d mp) {
|
|
|
|
dogd.drawing = false;
|
|
|
|
dogd.mp = mp;
|
|
|
|
dogd.dmin = 1e12;
|
|
|
|
|
2008-04-21 10:12:04 +00:00
|
|
|
DrawOrGetDistance(NULL);
|
2008-04-14 10:28:32 +00:00
|
|
|
|
|
|
|
return dogd.dmin;
|
|
|
|
}
|
|
|
|
|
2008-04-21 10:12:04 +00:00
|
|
|
Vector Constraint::GetLabelPos(void) {
|
|
|
|
dogd.drawing = false;
|
|
|
|
dogd.mp.x = 0; dogd.mp.y = 0;
|
|
|
|
dogd.dmin = 1e12;
|
|
|
|
|
|
|
|
Vector p;
|
|
|
|
DrawOrGetDistance(&p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2008-05-26 09:56:50 +00:00
|
|
|
Vector Constraint::GetReferencePos(void) {
|
|
|
|
dogd.drawing = false;
|
|
|
|
|
|
|
|
dogd.refp = SS.GW.offset.ScaledBy(-1);
|
|
|
|
DrawOrGetDistance(NULL);
|
|
|
|
|
|
|
|
return dogd.refp;
|
|
|
|
}
|
|
|
|
|