2008-04-14 10:28:32 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2008-05-26 09:56:50 +00:00
|
|
|
const hConstraint Constraint::NO_CONSTRAINT = { 0 };
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
char *Constraint::DescriptionString(void) {
|
|
|
|
static char ret[1024];
|
2008-06-01 00:26:41 +00:00
|
|
|
|
|
|
|
char *s;
|
|
|
|
switch(type) {
|
|
|
|
case POINTS_COINCIDENT: s = "pts-coincident"; break;
|
|
|
|
case PT_PT_DISTANCE: s = "pt-pt-distance"; break;
|
|
|
|
case PT_LINE_DISTANCE: s = "pt-line-distance"; break;
|
|
|
|
case PT_PLANE_DISTANCE: s = "pt-plane-distance"; break;
|
2008-06-06 08:46:55 +00:00
|
|
|
case PT_FACE_DISTANCE: s = "pt-face-distance"; break;
|
2008-06-01 00:26:41 +00:00
|
|
|
case PT_IN_PLANE: s = "pt-in-plane"; break;
|
|
|
|
case PT_ON_LINE: s = "pt-on-line"; break;
|
|
|
|
case PT_ON_FACE: s = "pt-on-face"; break;
|
|
|
|
case EQUAL_LENGTH_LINES:s = "eq-length"; break;
|
2008-06-14 11:16:14 +00:00
|
|
|
case EQ_LEN_PT_LINE_D: s = "eq-length-and-pt-ln-dist"; break;
|
|
|
|
case EQ_PT_LN_DISTANCES:s = "eq-pt-line-distances"; break;
|
2008-06-01 00:26:41 +00:00
|
|
|
case LENGTH_RATIO: s = "length-ratio"; break;
|
|
|
|
case SYMMETRIC: s = "symmetric"; break;
|
|
|
|
case SYMMETRIC_HORIZ: s = "symmetric-h"; break;
|
|
|
|
case SYMMETRIC_VERT: s = "symmetric-v"; break;
|
|
|
|
case AT_MIDPOINT: s = "at-midpoint"; break;
|
|
|
|
case HORIZONTAL: s = "horizontal"; break;
|
|
|
|
case VERTICAL: s = "vertical"; break;
|
|
|
|
case DIAMETER: s = "diameter"; break;
|
|
|
|
case PT_ON_CIRCLE: s = "pt-on-circle"; break;
|
|
|
|
case SAME_ORIENTATION: s = "same-orientation"; break;
|
|
|
|
case ANGLE: s = "angle"; break;
|
|
|
|
case PARALLEL: s = "parallel"; break;
|
|
|
|
case EQUAL_RADIUS: s = "eq-radius"; break;
|
2008-06-12 08:58:58 +00:00
|
|
|
case COMMENT: s = "comment"; break;
|
2008-06-01 00:26:41 +00:00
|
|
|
default: s = "???"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(ret, "c%03x-%s", h.v, s);
|
2008-04-27 09:03:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-05-17 23:48:58 +00:00
|
|
|
void Constraint::AddConstraint(Constraint *c) {
|
2008-06-04 10:22:30 +00:00
|
|
|
AddConstraint(c, true);
|
|
|
|
}
|
|
|
|
void Constraint::AddConstraint(Constraint *c, bool rememberForUndo) {
|
|
|
|
if(rememberForUndo) SS.UndoRemember();
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
SS.constraint.AddAndAssignId(c);
|
2008-04-27 05:00:12 +00:00
|
|
|
|
2008-06-02 11:43:27 +00:00
|
|
|
SS.MarkGroupDirty(c->group);
|
2008-06-03 18:28:41 +00:00
|
|
|
SS.later.generateAll = true;
|
2008-04-14 10:28:32 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
void Constraint::Constrain(int type, hEntity ptA, hEntity ptB, hEntity entityA)
|
|
|
|
{
|
2008-04-23 07:29:19 +00:00
|
|
|
Constraint c;
|
|
|
|
memset(&c, 0, sizeof(c));
|
|
|
|
c.group = SS.GW.activeGroup;
|
2008-05-27 02:22:20 +00:00
|
|
|
c.workplane = SS.GW.ActiveWorkplane();
|
2008-05-08 07:30:30 +00:00
|
|
|
c.type = type;
|
2008-04-23 07:29:19 +00:00
|
|
|
c.ptA = ptA;
|
|
|
|
c.ptB = ptB;
|
2008-05-08 07:30:30 +00:00
|
|
|
c.entityA = entityA;
|
2008-06-04 10:22:30 +00:00
|
|
|
AddConstraint(&c, false);
|
2008-04-23 07:29:19 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
void Constraint::ConstrainCoincident(hEntity ptA, hEntity ptB) {
|
|
|
|
Constrain(POINTS_COINCIDENT, ptA, ptB, Entity::NO_ENTITY);
|
2008-05-07 04:17:29 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
void Constraint::MenuConstrain(int id) {
|
|
|
|
Constraint c;
|
|
|
|
memset(&c, 0, sizeof(c));
|
|
|
|
c.group = SS.GW.activeGroup;
|
2008-05-27 02:22:20 +00:00
|
|
|
c.workplane = SS.GW.ActiveWorkplane();
|
2008-04-14 10:28:32 +00:00
|
|
|
|
|
|
|
SS.GW.GroupSelection();
|
|
|
|
#define gs (SS.GW.gs)
|
|
|
|
|
|
|
|
switch(id) {
|
2008-04-27 05:00:12 +00:00
|
|
|
case GraphicsWindow::MNU_DISTANCE_DIA: {
|
2008-04-14 10:28:32 +00:00
|
|
|
if(gs.points == 2 && gs.n == 2) {
|
|
|
|
c.type = PT_PT_DISTANCE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.ptB = gs.point[1];
|
|
|
|
} else if(gs.lineSegments == 1 && gs.n == 1) {
|
|
|
|
c.type = PT_PT_DISTANCE;
|
2008-04-19 11:09:47 +00:00
|
|
|
Entity *e = SS.GetEntity(gs.entity[0]);
|
2008-04-27 03:26:27 +00:00
|
|
|
c.ptA = e->point[0];
|
|
|
|
c.ptB = e->point[1];
|
2008-05-08 07:30:30 +00:00
|
|
|
} else if(gs.workplanes == 1 && gs.points == 1 && gs.n == 2) {
|
|
|
|
c.type = PT_PLANE_DISTANCE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
} else if(gs.lineSegments == 1 && gs.points == 1 && gs.n == 2) {
|
|
|
|
c.type = PT_LINE_DISTANCE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.entity[0];
|
2008-06-06 08:46:55 +00:00
|
|
|
} else if(gs.faces == 1 && gs.points == 1 && gs.n == 2) {
|
|
|
|
c.type = PT_FACE_DISTANCE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.face[0];
|
2008-05-07 08:19:37 +00:00
|
|
|
} else if(gs.circlesOrArcs == 1 && gs.n == 1) {
|
|
|
|
c.type = DIAMETER;
|
|
|
|
c.entityA = gs.entity[0];
|
2008-04-14 10:28:32 +00:00
|
|
|
} else {
|
|
|
|
Error("Bad selection for distance / diameter constraint.");
|
|
|
|
return;
|
|
|
|
}
|
2008-05-07 08:19:37 +00:00
|
|
|
if(c.type == PT_PT_DISTANCE) {
|
|
|
|
Vector n = SS.GW.projRight.Cross(SS.GW.projUp);
|
|
|
|
Vector a = SS.GetEntity(c.ptA)->PointGetNum();
|
|
|
|
Vector b = SS.GetEntity(c.ptB)->PointGetNum();
|
2008-05-11 10:40:37 +00:00
|
|
|
c.disp.offset = n.Cross(a.Minus(b));
|
|
|
|
c.disp.offset = (c.disp.offset).WithMagnitude(50/SS.GW.scale);
|
2008-05-07 08:19:37 +00:00
|
|
|
} else {
|
2008-06-01 08:45:11 +00:00
|
|
|
c.disp.offset = Vector::From(0, 0, 0);
|
2008-05-07 08:19:37 +00:00
|
|
|
}
|
2008-04-27 05:00:12 +00:00
|
|
|
|
2008-06-14 08:43:38 +00:00
|
|
|
c.valA = 0;
|
2008-04-22 10:53:42 +00:00
|
|
|
c.ModifyToSatisfy();
|
2008-04-14 10:28:32 +00:00
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
2008-04-27 05:00:12 +00:00
|
|
|
}
|
2008-04-14 10:28:32 +00:00
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
case GraphicsWindow::MNU_ON_ENTITY:
|
|
|
|
if(gs.points == 2 && gs.n == 2) {
|
|
|
|
c.type = POINTS_COINCIDENT;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.ptB = gs.point[1];
|
2008-05-05 11:17:00 +00:00
|
|
|
} else if(gs.points == 1 && gs.workplanes == 1 && gs.n == 2) {
|
2008-04-21 08:16:38 +00:00
|
|
|
c.type = PT_IN_PLANE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.entity[0];
|
2008-04-28 09:40:02 +00:00
|
|
|
} else if(gs.points == 1 && gs.lineSegments == 1 && gs.n == 2) {
|
|
|
|
c.type = PT_ON_LINE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.entity[0];
|
2008-05-08 07:30:30 +00:00
|
|
|
} else if(gs.points == 1 && gs.circlesOrArcs == 1 && gs.n == 2) {
|
|
|
|
c.type = PT_ON_CIRCLE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.entity[0];
|
2008-06-02 03:31:37 +00:00
|
|
|
} else if(gs.points == 1 && gs.faces == 1 && gs.n == 2) {
|
|
|
|
c.type = PT_ON_FACE;
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityA = gs.face[0];
|
2008-04-21 08:16:38 +00:00
|
|
|
} else {
|
|
|
|
Error("Bad selection for on point / curve / plane constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-04-22 05:00:49 +00:00
|
|
|
case GraphicsWindow::MNU_EQUAL:
|
|
|
|
if(gs.lineSegments == 2 && gs.n == 2) {
|
|
|
|
c.type = EQUAL_LENGTH_LINES;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.entityB = gs.entity[1];
|
2008-06-14 11:16:14 +00:00
|
|
|
} else if(gs.lineSegments == 2 && gs.points == 2 && gs.n == 4) {
|
|
|
|
c.type = EQ_PT_LN_DISTANCES;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityB = gs.entity[1];
|
|
|
|
c.ptB = gs.point[1];
|
|
|
|
} else if(gs.lineSegments == 1 && gs.points == 2 && gs.n == 3) {
|
|
|
|
// The same line segment for the distances, but different
|
|
|
|
// points.
|
|
|
|
c.type = EQ_PT_LN_DISTANCES;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.entityB = gs.entity[0];
|
|
|
|
c.ptB = gs.point[1];
|
|
|
|
} else if(gs.lineSegments == 2 && gs.points == 1 && gs.n == 3) {
|
|
|
|
c.type = EQ_LEN_PT_LINE_D;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.entityB = gs.entity[1];
|
|
|
|
c.ptA = gs.point[0];
|
2008-05-12 10:01:44 +00:00
|
|
|
} else if(gs.circlesOrArcs == 2 && gs.n == 2) {
|
|
|
|
c.type = EQUAL_RADIUS;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.entityB = gs.entity[1];
|
2008-04-22 05:00:49 +00:00
|
|
|
} else {
|
|
|
|
Error("Bad selection for equal length / radius constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
case GraphicsWindow::MNU_RATIO:
|
|
|
|
if(gs.lineSegments == 2 && gs.n == 2) {
|
|
|
|
c.type = LENGTH_RATIO;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.entityB = gs.entity[1];
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for length ratio constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-14 08:43:38 +00:00
|
|
|
c.valA = 0;
|
2008-05-11 10:40:37 +00:00
|
|
|
c.ModifyToSatisfy();
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
case GraphicsWindow::MNU_AT_MIDPOINT:
|
|
|
|
if(gs.lineSegments == 1 && gs.points == 1 && gs.n == 2) {
|
|
|
|
c.type = AT_MIDPOINT;
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.ptA = gs.point[0];
|
2008-05-05 11:17:00 +00:00
|
|
|
} else if(gs.lineSegments == 1 && gs.workplanes == 1 && gs.n == 2) {
|
2008-05-01 06:53:50 +00:00
|
|
|
c.type = AT_MIDPOINT;
|
2008-05-05 11:17:00 +00:00
|
|
|
int i = SS.GetEntity(gs.entity[0])->IsWorkplane() ? 1 : 0;
|
2008-05-01 06:53:50 +00:00
|
|
|
c.entityA = gs.entity[i];
|
|
|
|
c.entityB = gs.entity[1-i];
|
2008-04-30 08:14:32 +00:00
|
|
|
} else {
|
|
|
|
Error("Bad selection for at midpoint constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_SYMMETRIC:
|
2008-05-13 10:38:21 +00:00
|
|
|
if(gs.points == 2 &&
|
|
|
|
((gs.workplanes == 1 && gs.n == 3) ||
|
|
|
|
(gs.n == 2)))
|
|
|
|
{
|
2008-04-30 08:14:32 +00:00
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
c.ptA = gs.point[0];
|
|
|
|
c.ptB = gs.point[1];
|
2008-05-13 10:38:21 +00:00
|
|
|
} else if(gs.lineSegments == 1 &&
|
|
|
|
((gs.workplanes == 1 && gs.n == 2) ||
|
|
|
|
(gs.n == 1)))
|
|
|
|
{
|
2008-05-05 11:17:00 +00:00
|
|
|
int i = SS.GetEntity(gs.entity[0])->IsWorkplane() ? 1 : 0;
|
2008-04-30 08:14:32 +00:00
|
|
|
Entity *line = SS.GetEntity(gs.entity[i]);
|
|
|
|
c.entityA = gs.entity[1-i];
|
|
|
|
c.ptA = line->point[0];
|
|
|
|
c.ptB = line->point[1];
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for symmetric constraint.");
|
|
|
|
return;
|
|
|
|
}
|
2008-05-13 10:38:21 +00:00
|
|
|
if(c.entityA.v == Entity::NO_ENTITY.v) {
|
|
|
|
if(c.workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
Error("Must be locked in to workplane when constraining "
|
|
|
|
"symmetric without an explicit symmetry plane.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Vector pa = SS.GetEntity(c.ptA)->PointGetNum();
|
|
|
|
Vector pb = SS.GetEntity(c.ptB)->PointGetNum();
|
|
|
|
Vector dp = pa.Minus(pb);
|
|
|
|
Entity *norm = SS.GetEntity(c.workplane)->Normal();;
|
|
|
|
Vector u = norm->NormalU(), v = norm->NormalV();
|
|
|
|
if(fabs(dp.Dot(u)) > fabs(dp.Dot(v))) {
|
|
|
|
c.type = SYMMETRIC_HORIZ;
|
|
|
|
} else {
|
|
|
|
c.type = SYMMETRIC_VERT;
|
|
|
|
}
|
2008-06-11 04:22:52 +00:00
|
|
|
if(gs.lineSegments == 1) {
|
|
|
|
// If this line segment is already constrained horiz or
|
|
|
|
// vert, then auto-remove that redundant constraint.
|
|
|
|
SS.constraint.ClearTags();
|
|
|
|
for(int i = 0; i < SS.constraint.n; i++) {
|
|
|
|
Constraint *ct = &(SS.constraint.elem[i]);
|
|
|
|
if(ct->type != HORIZONTAL && ct->type != VERTICAL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(ct->entityA.v != (gs.entity[0]).v) continue;
|
|
|
|
ct->tag = 1;
|
|
|
|
}
|
|
|
|
SS.constraint.RemoveTagged();
|
|
|
|
// And no need to do anything special, since nothing
|
|
|
|
// ever depends on a constraint.
|
|
|
|
}
|
2008-05-13 10:38:21 +00:00
|
|
|
} else {
|
|
|
|
// Symmetry with a symmetry plane specified explicitly.
|
|
|
|
c.type = SYMMETRIC;
|
|
|
|
}
|
2008-04-30 08:14:32 +00:00
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
case GraphicsWindow::MNU_VERTICAL:
|
|
|
|
case GraphicsWindow::MNU_HORIZONTAL: {
|
|
|
|
hEntity ha, hb;
|
2008-04-27 05:00:12 +00:00
|
|
|
if(c.workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
Error("Select workplane before constraining horiz/vert.");
|
|
|
|
return;
|
|
|
|
}
|
2008-04-23 07:29:19 +00:00
|
|
|
if(gs.lineSegments == 1 && gs.n == 1) {
|
|
|
|
c.entityA = gs.entity[0];
|
|
|
|
Entity *e = SS.GetEntity(c.entityA);
|
2008-04-27 03:26:27 +00:00
|
|
|
ha = e->point[0];
|
|
|
|
hb = e->point[1];
|
2008-04-23 07:29:19 +00:00
|
|
|
} else if(gs.points == 2 && gs.n == 2) {
|
|
|
|
ha = c.ptA = gs.point[0];
|
|
|
|
hb = c.ptB = gs.point[1];
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for horizontal / vertical constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(id == GraphicsWindow::MNU_HORIZONTAL) {
|
|
|
|
c.type = HORIZONTAL;
|
|
|
|
} else {
|
|
|
|
c.type = VERTICAL;
|
|
|
|
}
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
case GraphicsWindow::MNU_ORIENTED_SAME:
|
|
|
|
if(gs.anyNormals == 2 && gs.n == 2) {
|
|
|
|
c.type = SAME_ORIENTATION;
|
|
|
|
c.entityA = gs.anyNormal[0];
|
|
|
|
c.entityB = gs.anyNormal[1];
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for same orientation constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
case GraphicsWindow::MNU_OTHER_ANGLE:
|
|
|
|
if(gs.constraints == 1 && gs.n == 0) {
|
|
|
|
Constraint *c = SS.GetConstraint(gs.constraint[0]);
|
|
|
|
if(c->type == ANGLE) {
|
|
|
|
c->otherAngle = !(c->otherAngle);
|
|
|
|
c->ModifyToSatisfy();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Error("Must select an angle constraint.");
|
2008-06-11 04:22:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_REFERENCE:
|
|
|
|
if(gs.constraints == 1 && gs.n == 0) {
|
|
|
|
Constraint *c = SS.GetConstraint(gs.constraint[0]);
|
2008-06-12 08:58:58 +00:00
|
|
|
if(c->HasLabel() && c->type != COMMENT) {
|
2008-06-11 04:22:52 +00:00
|
|
|
(c->reference) = !(c->reference);
|
|
|
|
SS.GetGroup(c->group)->clean = false;
|
|
|
|
SS.GenerateAll();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Error("Must select a constraint with associated label.");
|
|
|
|
return;
|
2008-05-17 11:15:14 +00:00
|
|
|
|
|
|
|
case GraphicsWindow::MNU_ANGLE:
|
|
|
|
if(gs.vectors == 2 && gs.n == 2) {
|
|
|
|
c.type = ANGLE;
|
|
|
|
c.entityA = gs.vector[0];
|
|
|
|
c.entityB = gs.vector[1];
|
2008-06-14 08:43:38 +00:00
|
|
|
c.valA = 0;
|
2008-05-17 11:15:14 +00:00
|
|
|
c.otherAngle = true;
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for angle constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
c.ModifyToSatisfy();
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
case GraphicsWindow::MNU_PARALLEL:
|
|
|
|
if(gs.vectors == 2 && gs.n == 2) {
|
|
|
|
c.type = PARALLEL;
|
|
|
|
c.entityA = gs.vector[0];
|
|
|
|
c.entityB = gs.vector[1];
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for parallel constraint.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-06-12 08:58:58 +00:00
|
|
|
case GraphicsWindow::MNU_COMMENT:
|
|
|
|
c.type = COMMENT;
|
|
|
|
c.comment.strcpy("NEW COMMENT -- DOUBLE-CLICK TO EDIT");
|
2008-06-14 08:43:38 +00:00
|
|
|
c.disp.offset = SS.GW.offset.ScaledBy(-1);
|
2008-06-12 08:58:58 +00:00
|
|
|
AddConstraint(&c);
|
|
|
|
break;
|
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
case GraphicsWindow::MNU_SOLVE_NOW:
|
2008-06-04 10:22:30 +00:00
|
|
|
SS.ReloadAllImported();
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll(0, INT_MAX);
|
2008-04-20 11:35:10 +00:00
|
|
|
return;
|
|
|
|
|
2008-04-14 10:28:32 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
InvalidateGraphics();
|
|
|
|
}
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
Expr *Constraint::VectorsParallel(int eq, ExprVector a, ExprVector b) {
|
|
|
|
ExprVector r = a.Cross(b);
|
|
|
|
// Hairy ball theorem screws me here. There's no clean solution that I
|
2008-06-03 18:28:41 +00:00
|
|
|
// know, so let's pivot on the initial numerical guess. Our caller
|
|
|
|
// has ensured that if one of our input vectors is already known (e.g.
|
|
|
|
// it's from a previous group), then that one's in a; so that one's
|
|
|
|
// not going to move, and we should pivot on that one.
|
|
|
|
double mx = fabs((a.x)->Eval());
|
|
|
|
double my = fabs((a.y)->Eval());
|
|
|
|
double mz = fabs((a.z)->Eval());
|
2008-04-30 08:14:32 +00:00
|
|
|
// The basis vector in which the vectors have the LEAST energy is the
|
|
|
|
// one that we should look at most (e.g. if both vectors lie in the xy
|
|
|
|
// plane, then the z component of the cross product is most important).
|
|
|
|
// So find the strongest component of a and b, and that's the component
|
|
|
|
// of the cross product to ignore.
|
|
|
|
double m = max(mx, max(my, mz));
|
|
|
|
Expr *e0, *e1;
|
|
|
|
if(m == mx) { e0 = r.y; e1 = r.z; }
|
|
|
|
else if(m == my) { e0 = r.z; e1 = r.x; }
|
|
|
|
else if(m == mz) { e0 = r.x; e1 = r.y; }
|
|
|
|
else oops();
|
|
|
|
|
|
|
|
if(eq == 0) return e0;
|
|
|
|
if(eq == 1) return e1;
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
|
2008-04-28 09:40:02 +00:00
|
|
|
Expr *Constraint::PointLineDistance(hEntity wrkpl, hEntity hpt, hEntity hln) {
|
|
|
|
Entity *ln = SS.GetEntity(hln);
|
|
|
|
Entity *a = SS.GetEntity(ln->point[0]);
|
|
|
|
Entity *b = SS.GetEntity(ln->point[1]);
|
|
|
|
|
|
|
|
Entity *p = SS.GetEntity(hpt);
|
|
|
|
|
|
|
|
if(wrkpl.v == Entity::FREE_IN_3D.v) {
|
|
|
|
ExprVector ep = p->PointGetExprs();
|
|
|
|
|
|
|
|
ExprVector ea = a->PointGetExprs();
|
|
|
|
ExprVector eb = b->PointGetExprs();
|
|
|
|
ExprVector eab = ea.Minus(eb);
|
|
|
|
Expr *m = eab.Magnitude();
|
|
|
|
|
|
|
|
return ((eab.Cross(ea.Minus(ep))).Magnitude())->Div(m);
|
|
|
|
} else {
|
|
|
|
Expr *ua, *va, *ub, *vb;
|
|
|
|
a->PointGetExprsInWorkplane(wrkpl, &ua, &va);
|
|
|
|
b->PointGetExprsInWorkplane(wrkpl, &ub, &vb);
|
|
|
|
|
|
|
|
Expr *du = ua->Minus(ub);
|
|
|
|
Expr *dv = va->Minus(vb);
|
|
|
|
|
|
|
|
Expr *u, *v;
|
|
|
|
p->PointGetExprsInWorkplane(wrkpl, &u, &v);
|
|
|
|
|
|
|
|
Expr *m = ((du->Square())->Plus(dv->Square()))->Sqrt();
|
|
|
|
|
|
|
|
Expr *proj = (dv->Times(ua->Minus(u)))->Minus(
|
|
|
|
(du->Times(va->Minus(v))));
|
|
|
|
|
|
|
|
return proj->Div(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
Expr *Constraint::PointPlaneDistance(ExprVector p, hEntity hpl) {
|
|
|
|
ExprVector n;
|
|
|
|
Expr *d;
|
2008-05-05 11:17:00 +00:00
|
|
|
SS.GetEntity(hpl)->WorkplaneGetPlaneExprs(&n, &d);
|
2008-04-30 08:14:32 +00:00
|
|
|
return (p.Dot(n))->Minus(d);
|
|
|
|
}
|
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
Expr *Constraint::Distance(hEntity wrkpl, hEntity hpa, hEntity hpb) {
|
2008-04-20 11:35:10 +00:00
|
|
|
Entity *pa = SS.GetEntity(hpa);
|
|
|
|
Entity *pb = SS.GetEntity(hpb);
|
|
|
|
if(!(pa->IsPoint() && pb->IsPoint())) oops();
|
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
if(wrkpl.v == Entity::FREE_IN_3D.v) {
|
|
|
|
// This is true distance
|
|
|
|
ExprVector ea, eb, eab;
|
|
|
|
ea = pa->PointGetExprs();
|
|
|
|
eb = pb->PointGetExprs();
|
|
|
|
eab = ea.Minus(eb);
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
return eab.Magnitude();
|
|
|
|
} else {
|
|
|
|
// This is projected distance, in the given workplane.
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
|
|
|
|
pa->PointGetExprsInWorkplane(wrkpl, &au, &av);
|
|
|
|
pb->PointGetExprsInWorkplane(wrkpl, &bu, &bv);
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
Expr *du = au->Minus(bu);
|
|
|
|
Expr *dv = av->Minus(bv);
|
2008-04-20 11:35:10 +00:00
|
|
|
|
2008-04-27 05:00:12 +00:00
|
|
|
return ((du->Square())->Plus(dv->Square()))->Sqrt();
|
|
|
|
}
|
2008-04-20 11:35:10 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 06:53:50 +00:00
|
|
|
ExprVector Constraint::PointInThreeSpace(hEntity workplane, Expr *u, Expr *v) {
|
|
|
|
Entity *w = SS.GetEntity(workplane);
|
2008-05-05 11:17:00 +00:00
|
|
|
|
|
|
|
ExprVector ub = w->Normal()->NormalExprsU();
|
|
|
|
ExprVector vb = w->Normal()->NormalExprsV();
|
|
|
|
ExprVector ob = w->WorkplaneGetOffsetExprs();
|
2008-05-01 06:53:50 +00:00
|
|
|
|
|
|
|
return (ub.ScaledBy(u)).Plus(vb.ScaledBy(v)).Plus(ob);
|
|
|
|
}
|
|
|
|
|
2008-04-22 10:53:42 +00:00
|
|
|
void Constraint::ModifyToSatisfy(void) {
|
2008-05-17 11:15:14 +00:00
|
|
|
if(type == ANGLE) {
|
|
|
|
Vector a = SS.GetEntity(entityA)->VectorGetNum();
|
|
|
|
Vector b = SS.GetEntity(entityB)->VectorGetNum();
|
|
|
|
if(otherAngle) a = a.ScaledBy(-1);
|
|
|
|
if(workplane.v != Entity::FREE_IN_3D.v) {
|
|
|
|
a = a.ProjectVectorInto(workplane);
|
|
|
|
b = b.ProjectVectorInto(workplane);
|
|
|
|
}
|
|
|
|
double c = (a.Dot(b))/(a.Magnitude() * b.Magnitude());
|
2008-06-14 08:43:38 +00:00
|
|
|
valA = acos(c)*180/PI;
|
2008-05-17 11:15:14 +00:00
|
|
|
} else {
|
|
|
|
// We'll fix these ones up by looking at their symbolic equation;
|
|
|
|
// that means no extra work.
|
|
|
|
IdList<Equation,hEquation> l;
|
|
|
|
// An uninit IdList could lead us to free some random address, bad.
|
2008-06-11 04:22:52 +00:00
|
|
|
ZERO(&l);
|
|
|
|
// Generate the equations even if this is a reference dimension
|
|
|
|
GenerateReal(&l);
|
2008-05-17 11:15:14 +00:00
|
|
|
if(l.n != 1) oops();
|
|
|
|
|
|
|
|
// These equations are written in the form f(...) - d = 0, where
|
2008-06-14 08:43:38 +00:00
|
|
|
// d is the value of the valA.
|
|
|
|
valA += (l.elem[0].e)->Eval();
|
2008-05-17 11:15:14 +00:00
|
|
|
|
|
|
|
l.Clear();
|
|
|
|
}
|
2008-04-22 10:53:42 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
void Constraint::AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index) {
|
|
|
|
Equation eq;
|
|
|
|
eq.e = expr;
|
|
|
|
eq.h = h.equation(index);
|
|
|
|
l->Add(&eq);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
2008-06-11 04:22:52 +00:00
|
|
|
if(!reference) {
|
|
|
|
GenerateReal(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Constraint::GenerateReal(IdList<Equation,hEquation> *l) {
|
2008-06-14 08:43:38 +00:00
|
|
|
Expr *exA = Expr::From(valA);
|
2008-05-17 11:15:14 +00:00
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
switch(type) {
|
|
|
|
case PT_PT_DISTANCE:
|
2008-05-17 11:15:14 +00:00
|
|
|
AddEq(l, Distance(workplane, ptA, ptB)->Minus(exA), 0);
|
2008-04-20 11:35:10 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
case PT_LINE_DISTANCE:
|
|
|
|
AddEq(l,
|
2008-05-17 11:15:14 +00:00
|
|
|
PointLineDistance(workplane, ptA, entityA)->Minus(exA), 0);
|
2008-05-08 07:30:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PT_PLANE_DISTANCE: {
|
|
|
|
ExprVector pt = SS.GetEntity(ptA)->PointGetExprs();
|
2008-05-17 11:15:14 +00:00
|
|
|
AddEq(l, (PointPlaneDistance(pt, entityA))->Minus(exA), 0);
|
2008-05-08 07:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-06 08:46:55 +00:00
|
|
|
case PT_FACE_DISTANCE: {
|
|
|
|
ExprVector pt = SS.GetEntity(ptA)->PointGetExprs();
|
|
|
|
Entity *f = SS.GetEntity(entityA);
|
|
|
|
ExprVector p0 = f->FaceGetPointExprs();
|
|
|
|
ExprVector n = f->FaceGetNormalExprs();
|
2008-06-14 08:43:38 +00:00
|
|
|
AddEq(l, (pt.Minus(p0)).Dot(n)->Minus(exA), 0);
|
2008-06-06 08:46:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-22 05:00:49 +00:00
|
|
|
case EQUAL_LENGTH_LINES: {
|
|
|
|
Entity *a = SS.GetEntity(entityA);
|
|
|
|
Entity *b = SS.GetEntity(entityB);
|
2008-04-27 05:00:12 +00:00
|
|
|
AddEq(l, Distance(workplane, a->point[0], a->point[1])->Minus(
|
|
|
|
Distance(workplane, b->point[0], b->point[1])), 0);
|
2008-04-22 05:00:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-14 11:16:14 +00:00
|
|
|
// These work on distance squared, since the pt-line distances are
|
|
|
|
// signed, and we want the absolute value.
|
|
|
|
case EQ_LEN_PT_LINE_D: {
|
|
|
|
Entity *forLen = SS.GetEntity(entityA);
|
|
|
|
Expr *d1 = Distance(workplane, forLen->point[0], forLen->point[1]);
|
|
|
|
Expr *d2 = PointLineDistance(workplane, ptA, entityB);
|
|
|
|
AddEq(l, (d1->Square())->Minus(d2->Square()), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EQ_PT_LN_DISTANCES: {
|
|
|
|
Expr *d1 = PointLineDistance(workplane, ptA, entityA);
|
|
|
|
Expr *d2 = PointLineDistance(workplane, ptB, entityB);
|
|
|
|
AddEq(l, (d1->Square())->Minus(d2->Square()), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
case LENGTH_RATIO: {
|
|
|
|
Entity *a = SS.GetEntity(entityA);
|
|
|
|
Entity *b = SS.GetEntity(entityB);
|
|
|
|
Expr *la = Distance(workplane, a->point[0], a->point[1]);
|
|
|
|
Expr *lb = Distance(workplane, b->point[0], b->point[1]);
|
2008-05-17 11:15:14 +00:00
|
|
|
AddEq(l, (la->Div(lb))->Minus(exA), 0);
|
2008-05-11 10:40:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-07 08:19:37 +00:00
|
|
|
case DIAMETER: {
|
|
|
|
Entity *circle = SS.GetEntity(entityA);
|
2008-05-12 10:01:44 +00:00
|
|
|
Expr *r = circle->CircleGetRadiusExpr();
|
2008-06-01 08:45:11 +00:00
|
|
|
AddEq(l, (r->Times(Expr::From(2)))->Minus(exA), 0);
|
2008-05-07 08:19:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-12 10:01:44 +00:00
|
|
|
case EQUAL_RADIUS: {
|
|
|
|
Entity *c1 = SS.GetEntity(entityA);
|
|
|
|
Entity *c2 = SS.GetEntity(entityB);
|
|
|
|
AddEq(l, (c1->CircleGetRadiusExpr())->Minus(
|
|
|
|
c2->CircleGetRadiusExpr()), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-21 08:16:38 +00:00
|
|
|
case POINTS_COINCIDENT: {
|
2008-04-22 13:14:15 +00:00
|
|
|
Entity *a = SS.GetEntity(ptA);
|
|
|
|
Entity *b = SS.GetEntity(ptB);
|
2008-04-27 05:00:12 +00:00
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
ExprVector pa = a->PointGetExprs();
|
|
|
|
ExprVector pb = b->PointGetExprs();
|
|
|
|
AddEq(l, pa.x->Minus(pb.x), 0);
|
|
|
|
AddEq(l, pa.y->Minus(pb.y), 1);
|
|
|
|
AddEq(l, pa.z->Minus(pb.z), 2);
|
2008-04-23 07:29:19 +00:00
|
|
|
} else {
|
2008-04-27 05:00:12 +00:00
|
|
|
Expr *au, *av;
|
|
|
|
Expr *bu, *bv;
|
|
|
|
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
|
|
|
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
|
|
|
AddEq(l, au->Minus(bu), 0);
|
|
|
|
AddEq(l, av->Minus(bv), 1);
|
2008-04-22 13:14:15 +00:00
|
|
|
}
|
2008-04-21 08:16:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
case PT_IN_PLANE:
|
2008-04-27 05:00:12 +00:00
|
|
|
// This one works the same, whether projected or not.
|
2008-04-30 08:14:32 +00:00
|
|
|
AddEq(l, PointPlaneDistance(
|
|
|
|
SS.GetEntity(ptA)->PointGetExprs(), entityA), 0);
|
2008-04-21 08:16:38 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
case PT_ON_FACE: {
|
|
|
|
// a plane, n dot (p - p0) = 0
|
|
|
|
ExprVector p = SS.GetEntity(ptA)->PointGetExprs();
|
|
|
|
Entity *f = SS.GetEntity(entityA);
|
|
|
|
ExprVector p0 = f->FaceGetPointExprs();
|
|
|
|
ExprVector n = f->FaceGetNormalExprs();
|
|
|
|
AddEq(l, (p.Minus(p0)).Dot(n), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-28 09:40:02 +00:00
|
|
|
case PT_ON_LINE:
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
Entity *ln = SS.GetEntity(entityA);
|
|
|
|
Entity *a = SS.GetEntity(ln->point[0]);
|
|
|
|
Entity *b = SS.GetEntity(ln->point[1]);
|
|
|
|
Entity *p = SS.GetEntity(ptA);
|
|
|
|
|
|
|
|
ExprVector ep = p->PointGetExprs();
|
|
|
|
ExprVector ea = a->PointGetExprs();
|
|
|
|
ExprVector eb = b->PointGetExprs();
|
|
|
|
ExprVector eab = ea.Minus(eb);
|
2008-06-04 06:39:32 +00:00
|
|
|
|
|
|
|
// Construct a vector from the point to either endpoint of
|
|
|
|
// the line segment, and choose the longer of these.
|
2008-04-30 08:14:32 +00:00
|
|
|
ExprVector eap = ea.Minus(ep);
|
2008-06-04 06:39:32 +00:00
|
|
|
ExprVector ebp = eb.Minus(ep);
|
|
|
|
ExprVector elp =
|
|
|
|
(ebp.Magnitude()->Eval() > eap.Magnitude()->Eval()) ?
|
|
|
|
ebp : eap;
|
2008-04-30 08:14:32 +00:00
|
|
|
|
2008-06-03 18:28:41 +00:00
|
|
|
if(p->group.v == group.v) {
|
2008-06-04 06:39:32 +00:00
|
|
|
AddEq(l, VectorsParallel(0, eab, elp), 0);
|
|
|
|
AddEq(l, VectorsParallel(1, eab, elp), 1);
|
2008-06-03 18:28:41 +00:00
|
|
|
} else {
|
2008-06-04 06:39:32 +00:00
|
|
|
AddEq(l, VectorsParallel(0, elp, eab), 0);
|
|
|
|
AddEq(l, VectorsParallel(1, elp, eab), 1);
|
2008-06-03 18:28:41 +00:00
|
|
|
}
|
2008-04-28 09:40:02 +00:00
|
|
|
} else {
|
|
|
|
AddEq(l, PointLineDistance(workplane, ptA, entityA), 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-08 07:30:30 +00:00
|
|
|
case PT_ON_CIRCLE: {
|
|
|
|
Entity *circle = SS.GetEntity(entityA);
|
|
|
|
hEntity center = circle->point[0];
|
2008-05-16 06:34:06 +00:00
|
|
|
Expr *radius = circle->CircleGetRadiusExpr();
|
2008-05-08 07:30:30 +00:00
|
|
|
AddEq(l, Distance(workplane, ptA, center)->Minus(radius), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
case AT_MIDPOINT:
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
Entity *ln = SS.GetEntity(entityA);
|
|
|
|
ExprVector a = SS.GetEntity(ln->point[0])->PointGetExprs();
|
|
|
|
ExprVector b = SS.GetEntity(ln->point[1])->PointGetExprs();
|
2008-06-01 08:45:11 +00:00
|
|
|
ExprVector m = (a.Plus(b)).ScaledBy(Expr::From(0.5));
|
2008-04-30 08:14:32 +00:00
|
|
|
|
2008-05-01 06:53:50 +00:00
|
|
|
if(ptA.v) {
|
|
|
|
ExprVector p = SS.GetEntity(ptA)->PointGetExprs();
|
|
|
|
AddEq(l, (m.x)->Minus(p.x), 0);
|
|
|
|
AddEq(l, (m.y)->Minus(p.y), 1);
|
|
|
|
AddEq(l, (m.z)->Minus(p.z), 2);
|
|
|
|
} else {
|
|
|
|
AddEq(l, PointPlaneDistance(m, entityB), 0);
|
|
|
|
}
|
2008-04-30 08:14:32 +00:00
|
|
|
} else {
|
|
|
|
Entity *ln = SS.GetEntity(entityA);
|
|
|
|
Entity *a = SS.GetEntity(ln->point[0]);
|
|
|
|
Entity *b = SS.GetEntity(ln->point[1]);
|
|
|
|
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
|
|
|
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
2008-06-01 08:45:11 +00:00
|
|
|
Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
|
|
|
|
Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));
|
2008-04-30 08:14:32 +00:00
|
|
|
|
2008-05-01 06:53:50 +00:00
|
|
|
if(ptA.v) {
|
|
|
|
Entity *p = SS.GetEntity(ptA);
|
|
|
|
Expr *pu, *pv;
|
|
|
|
p->PointGetExprsInWorkplane(workplane, &pu, &pv);
|
|
|
|
AddEq(l, pu->Minus(mu), 0);
|
|
|
|
AddEq(l, pv->Minus(mv), 1);
|
|
|
|
} else {
|
|
|
|
ExprVector m = PointInThreeSpace(workplane, mu, mv);
|
|
|
|
AddEq(l, PointPlaneDistance(m, entityB), 0);
|
|
|
|
}
|
2008-04-30 08:14:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SYMMETRIC:
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
Entity *plane = SS.GetEntity(entityA);
|
|
|
|
Entity *ea = SS.GetEntity(ptA);
|
|
|
|
Entity *eb = SS.GetEntity(ptB);
|
|
|
|
ExprVector a = ea->PointGetExprs();
|
|
|
|
ExprVector b = eb->PointGetExprs();
|
|
|
|
|
|
|
|
// The midpoint of the line connecting the symmetric points
|
|
|
|
// lies on the plane of the symmetry.
|
2008-06-01 08:45:11 +00:00
|
|
|
ExprVector m = (a.Plus(b)).ScaledBy(Expr::From(0.5));
|
2008-04-30 08:14:32 +00:00
|
|
|
AddEq(l, PointPlaneDistance(m, plane->h), 0);
|
|
|
|
|
|
|
|
// And projected into the plane of symmetry, the points are
|
|
|
|
// coincident.
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
ea->PointGetExprsInWorkplane(plane->h, &au, &av);
|
|
|
|
eb->PointGetExprsInWorkplane(plane->h, &bu, &bv);
|
2008-06-06 11:35:28 +00:00
|
|
|
AddEq(l, au->Minus(bu), 1);
|
|
|
|
AddEq(l, av->Minus(bv), 2);
|
2008-04-30 08:14:32 +00:00
|
|
|
} else {
|
|
|
|
Entity *plane = SS.GetEntity(entityA);
|
|
|
|
Entity *a = SS.GetEntity(ptA);
|
|
|
|
Entity *b = SS.GetEntity(ptB);
|
|
|
|
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
|
|
|
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
2008-06-01 08:45:11 +00:00
|
|
|
Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
|
|
|
|
Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));
|
2008-04-30 08:14:32 +00:00
|
|
|
|
2008-05-01 06:53:50 +00:00
|
|
|
ExprVector m = PointInThreeSpace(workplane, mu, mv);
|
|
|
|
AddEq(l, PointPlaneDistance(m, plane->h), 0);
|
2008-04-30 08:14:32 +00:00
|
|
|
|
|
|
|
// Construct a vector within the workplane that is normal
|
|
|
|
// to the symmetry pane's normal (i.e., that lies in the
|
|
|
|
// plane of symmetry). The line connecting the points is
|
|
|
|
// perpendicular to that constructed vector.
|
2008-05-01 06:53:50 +00:00
|
|
|
Entity *w = SS.GetEntity(workplane);
|
2008-05-05 11:17:00 +00:00
|
|
|
ExprVector u = w->Normal()->NormalExprsU();
|
|
|
|
ExprVector v = w->Normal()->NormalExprsV();
|
2008-05-01 06:53:50 +00:00
|
|
|
|
2008-04-30 08:14:32 +00:00
|
|
|
ExprVector pa = a->PointGetExprs();
|
|
|
|
ExprVector pb = b->PointGetExprs();
|
|
|
|
ExprVector n;
|
|
|
|
Expr *d;
|
2008-05-05 11:17:00 +00:00
|
|
|
plane->WorkplaneGetPlaneExprs(&n, &d);
|
2008-04-30 08:14:32 +00:00
|
|
|
AddEq(l, (n.Cross(u.Cross(v))).Dot(pa.Minus(pb)), 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-13 10:38:21 +00:00
|
|
|
case SYMMETRIC_HORIZ:
|
|
|
|
case SYMMETRIC_VERT: {
|
|
|
|
Entity *a = SS.GetEntity(ptA);
|
|
|
|
Entity *b = SS.GetEntity(ptB);
|
|
|
|
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
|
|
|
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
|
|
|
|
|
|
|
if(type == SYMMETRIC_HORIZ) {
|
|
|
|
AddEq(l, av->Minus(bv), 0);
|
2008-06-06 11:35:28 +00:00
|
|
|
AddEq(l, au->Plus(bu), 1);
|
2008-05-13 10:38:21 +00:00
|
|
|
} else {
|
|
|
|
AddEq(l, au->Minus(bu), 0);
|
2008-06-06 11:35:28 +00:00
|
|
|
AddEq(l, av->Plus(bv), 1);
|
2008-05-13 10:38:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-23 07:29:19 +00:00
|
|
|
case HORIZONTAL:
|
|
|
|
case VERTICAL: {
|
|
|
|
hEntity ha, hb;
|
|
|
|
if(entityA.v) {
|
|
|
|
Entity *e = SS.GetEntity(entityA);
|
2008-04-27 03:26:27 +00:00
|
|
|
ha = e->point[0];
|
|
|
|
hb = e->point[1];
|
2008-04-23 07:29:19 +00:00
|
|
|
} else {
|
|
|
|
ha = ptA;
|
|
|
|
hb = ptB;
|
|
|
|
}
|
|
|
|
Entity *a = SS.GetEntity(ha);
|
|
|
|
Entity *b = SS.GetEntity(hb);
|
2008-04-27 05:00:12 +00:00
|
|
|
|
|
|
|
Expr *au, *av, *bu, *bv;
|
|
|
|
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
|
|
|
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
|
|
|
|
|
|
|
AddEq(l, (type == HORIZONTAL) ? av->Minus(bv) : au->Minus(bu), 0);
|
2008-04-23 07:29:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
case SAME_ORIENTATION: {
|
|
|
|
Entity *a = SS.GetEntity(entityA);
|
|
|
|
Entity *b = SS.GetEntity(entityB);
|
2008-06-03 18:28:41 +00:00
|
|
|
if(b->group.v != group.v) {
|
|
|
|
SWAP(Entity *, a, b);
|
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
ExprVector au = a->NormalExprsU(),
|
|
|
|
av = a->NormalExprsV(),
|
|
|
|
an = a->NormalExprsN();
|
|
|
|
ExprVector bu = b->NormalExprsU(),
|
|
|
|
bv = b->NormalExprsV(),
|
|
|
|
bn = b->NormalExprsN();
|
|
|
|
|
|
|
|
AddEq(l, VectorsParallel(0, an, bn), 0);
|
|
|
|
AddEq(l, VectorsParallel(1, an, bn), 1);
|
2008-05-11 02:57:47 +00:00
|
|
|
Expr *d1 = au.Dot(bv);
|
|
|
|
Expr *d2 = au.Dot(bu);
|
|
|
|
// Allow either orientation for the coordinate system, depending
|
|
|
|
// on how it was drawn.
|
|
|
|
if(fabs(d1->Eval()) < fabs(d2->Eval())) {
|
|
|
|
AddEq(l, d1, 2);
|
|
|
|
} else {
|
|
|
|
AddEq(l, d2, 2);
|
|
|
|
}
|
2008-05-09 05:33:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-17 11:15:14 +00:00
|
|
|
case ANGLE: {
|
|
|
|
Entity *a = SS.GetEntity(entityA);
|
|
|
|
Entity *b = SS.GetEntity(entityB);
|
|
|
|
ExprVector ae = a->VectorGetExprs();
|
|
|
|
ExprVector be = b->VectorGetExprs();
|
2008-06-01 08:45:11 +00:00
|
|
|
if(otherAngle) ae = ae.ScaledBy(Expr::From(-1));
|
2008-05-17 11:15:14 +00:00
|
|
|
Expr *c;
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
Expr *mags = (ae.Magnitude())->Times(be.Magnitude());
|
|
|
|
c = (ae.Dot(be))->Div(mags);
|
|
|
|
} else {
|
|
|
|
Entity *w = SS.GetEntity(workplane);
|
|
|
|
ExprVector u = w->Normal()->NormalExprsU();
|
|
|
|
ExprVector v = w->Normal()->NormalExprsV();
|
|
|
|
Expr *ua = u.Dot(ae);
|
|
|
|
Expr *va = v.Dot(ae);
|
|
|
|
Expr *ub = u.Dot(be);
|
|
|
|
Expr *vb = v.Dot(be);
|
|
|
|
Expr *maga = (ua->Square()->Plus(va->Square()))->Sqrt();
|
|
|
|
Expr *magb = (ub->Square()->Plus(vb->Square()))->Sqrt();
|
|
|
|
Expr *dot = (ua->Times(ub))->Plus(va->Times(vb));
|
|
|
|
c = dot->Div(maga->Times(magb));
|
|
|
|
}
|
2008-06-01 08:45:11 +00:00
|
|
|
Expr *rads = exA->Times(Expr::From(PI/180));
|
2008-05-17 11:15:14 +00:00
|
|
|
AddEq(l, c->Minus(rads->Cos()), 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-09 05:33:23 +00:00
|
|
|
case PARALLEL: {
|
2008-06-03 18:28:41 +00:00
|
|
|
Entity *ea = SS.GetEntity(entityA), *eb = SS.GetEntity(entityB);
|
|
|
|
if(eb->group.v != group.v) {
|
|
|
|
SWAP(Entity *, ea, eb);
|
|
|
|
}
|
|
|
|
ExprVector a = ea->VectorGetExprs();
|
|
|
|
ExprVector b = eb->VectorGetExprs();
|
2008-05-09 05:33:23 +00:00
|
|
|
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
AddEq(l, VectorsParallel(0, a, b), 0);
|
|
|
|
AddEq(l, VectorsParallel(1, a, b), 1);
|
|
|
|
} else {
|
|
|
|
Entity *w = SS.GetEntity(workplane);
|
|
|
|
ExprVector wn = w->Normal()->NormalExprsN();
|
|
|
|
AddEq(l, (a.Cross(b)).Dot(wn), 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-12 08:58:58 +00:00
|
|
|
case COMMENT:
|
|
|
|
break;
|
|
|
|
|
2008-04-20 11:35:10 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|