A great renaming. 2d coordinate systems are now called workplanes,
and the associated entities are now just points. [git-p4: depot-paths = "//depot/solvespace/": change = 1690]
This commit is contained in:
parent
5bc3738ec4
commit
15476d4732
@ -32,8 +32,8 @@ void Constraint::MenuConstrain(int id) {
|
|||||||
} else if(gs.lineSegments == 1 && gs.n == 1) {
|
} else if(gs.lineSegments == 1 && gs.n == 1) {
|
||||||
c.type = PT_PT_DISTANCE;
|
c.type = PT_PT_DISTANCE;
|
||||||
Entity *e = SS.GetEntity(gs.entity[0]);
|
Entity *e = SS.GetEntity(gs.entity[0]);
|
||||||
c.ptA = e->assoc[0];
|
c.ptA = e->point[0];
|
||||||
c.ptB = e->assoc[1];
|
c.ptB = e->point[1];
|
||||||
} else {
|
} else {
|
||||||
Error("Bad selection for distance / diameter constraint.");
|
Error("Bad selection for distance / diameter constraint.");
|
||||||
return;
|
return;
|
||||||
@ -78,8 +78,8 @@ void Constraint::MenuConstrain(int id) {
|
|||||||
if(gs.lineSegments == 1 && gs.n == 1) {
|
if(gs.lineSegments == 1 && gs.n == 1) {
|
||||||
c.entityA = gs.entity[0];
|
c.entityA = gs.entity[0];
|
||||||
Entity *e = SS.GetEntity(c.entityA);
|
Entity *e = SS.GetEntity(c.entityA);
|
||||||
ha = e->assoc[0];
|
ha = e->point[0];
|
||||||
hb = e->assoc[1];
|
hb = e->point[1];
|
||||||
} else if(gs.points == 2 && gs.n == 2) {
|
} else if(gs.points == 2 && gs.n == 2) {
|
||||||
ha = c.ptA = gs.point[0];
|
ha = c.ptA = gs.point[0];
|
||||||
hb = c.ptB = gs.point[1];
|
hb = c.ptB = gs.point[1];
|
||||||
@ -89,18 +89,18 @@ void Constraint::MenuConstrain(int id) {
|
|||||||
}
|
}
|
||||||
Entity *ea = SS.GetEntity(ha);
|
Entity *ea = SS.GetEntity(ha);
|
||||||
Entity *eb = SS.GetEntity(hb);
|
Entity *eb = SS.GetEntity(hb);
|
||||||
if(ea->csys.v == Entity::NO_CSYS.v &&
|
if(ea->workplane.v == Entity::FREE_IN_3D.v &&
|
||||||
eb->csys.v == Entity::NO_CSYS.v)
|
eb->workplane.v == Entity::FREE_IN_3D.v)
|
||||||
{
|
{
|
||||||
Error("Horizontal/vertical constraint applies only to "
|
Error("Horizontal/vertical constraint applies only to "
|
||||||
"entities drawn in a 2d coordinate system.");
|
"entities drawn in a 2d coordinate system.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(eb->csys.v == SS.GW.activeCsys.v) {
|
if(eb->workplane.v == SS.GW.activeWorkplane.v) {
|
||||||
// We are constraining two points in two different csyss; so
|
// We are constraining two points in two different wrkpls; so
|
||||||
// we have two choices for the definitons of the coordinate
|
// we have two choices for the definitons of the coordinate
|
||||||
// directions. ptA's gets chosen, so make sure that's the
|
// directions. ptA's gets chosen, so make sure that's the
|
||||||
// active csys.
|
// active workplane.
|
||||||
hEntity t = c.ptA;
|
hEntity t = c.ptA;
|
||||||
c.ptA = c.ptB;
|
c.ptA = c.ptB;
|
||||||
c.ptB = t;
|
c.ptB = t;
|
||||||
@ -133,14 +133,14 @@ Expr *Constraint::Distance(hEntity hpa, hEntity hpb) {
|
|||||||
|
|
||||||
if(pa->type == Entity::POINT_IN_2D &&
|
if(pa->type == Entity::POINT_IN_2D &&
|
||||||
pb->type == Entity::POINT_IN_2D &&
|
pb->type == Entity::POINT_IN_2D &&
|
||||||
pa->csys.v == pb->csys.v)
|
pa->workplane.v == pb->workplane.v)
|
||||||
{
|
{
|
||||||
// A nice case; they are both in the same 2d csys, so I can write
|
// A nice case; they are both in the same workplane, so I can write
|
||||||
// the equation in terms of the basis vectors in that csys.
|
// the equation in terms of the basis vectors in that csys.
|
||||||
Expr *du = Expr::FromParam(pa->param.h[0])->Minus(
|
Expr *du = Expr::FromParam(pa->param[0])->Minus(
|
||||||
Expr::FromParam(pb->param.h[0]));
|
Expr::FromParam(pb->param[0]));
|
||||||
Expr *dv = Expr::FromParam(pa->param.h[1])->Minus(
|
Expr *dv = Expr::FromParam(pa->param[1])->Minus(
|
||||||
Expr::FromParam(pb->param.h[1]));
|
Expr::FromParam(pb->param[1]));
|
||||||
|
|
||||||
return ((du->Square())->Plus(dv->Square()))->Sqrt();
|
return ((du->Square())->Plus(dv->Square()))->Sqrt();
|
||||||
}
|
}
|
||||||
@ -188,8 +188,8 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||||||
case EQUAL_LENGTH_LINES: {
|
case EQUAL_LENGTH_LINES: {
|
||||||
Entity *a = SS.GetEntity(entityA);
|
Entity *a = SS.GetEntity(entityA);
|
||||||
Entity *b = SS.GetEntity(entityB);
|
Entity *b = SS.GetEntity(entityB);
|
||||||
AddEq(l, Distance(a->assoc[0], a->assoc[1])->Minus(
|
AddEq(l, Distance(a->point[0], a->point[1])->Minus(
|
||||||
Distance(b->assoc[0], b->assoc[1])), 0);
|
Distance(b->point[0], b->point[1])), 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,26 +210,26 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||||||
AddEq(l, eab.y, 1);
|
AddEq(l, eab.y, 1);
|
||||||
AddEq(l, eab.z, 2);
|
AddEq(l, eab.z, 2);
|
||||||
} else if(!(a->IsPointIn3d() || b->IsPointIn3d()) &&
|
} else if(!(a->IsPointIn3d() || b->IsPointIn3d()) &&
|
||||||
(a->csys.v == b->csys.v))
|
(a->workplane.v == b->workplane.v))
|
||||||
{
|
{
|
||||||
// Both in same csys, nice.
|
// Both in same workplane, nice.
|
||||||
AddEq(l, Expr::FromParam(a->param.h[0])->Minus(
|
AddEq(l, Expr::FromParam(a->param[0])->Minus(
|
||||||
Expr::FromParam(b->param.h[0])), 0);
|
Expr::FromParam(b->param[0])), 0);
|
||||||
AddEq(l, Expr::FromParam(a->param.h[1])->Minus(
|
AddEq(l, Expr::FromParam(a->param[1])->Minus(
|
||||||
Expr::FromParam(b->param.h[1])), 1);
|
Expr::FromParam(b->param[1])), 1);
|
||||||
} else {
|
} else {
|
||||||
// Either two 2 DOF points in different planes, or one
|
// Either two 2 DOF points in different planes, or one
|
||||||
// 3 DOF point and one 2 DOF point. Either way, write two
|
// 3 DOF point and one 2 DOF point. Either way, write two
|
||||||
// equations on the projection of a into b's plane.
|
// equations on the projection of a into b's plane.
|
||||||
ExprVector p3;
|
ExprVector p3;
|
||||||
p3 = a->PointGetExprs();
|
p3 = a->PointGetExprs();
|
||||||
Entity *csy = SS.GetEntity(b->csys);
|
Entity *w = SS.GetEntity(b->workplane);
|
||||||
ExprVector offset = csy->Csys2dGetOffsetExprs();
|
ExprVector offset = w->WorkplaneGetOffsetExprs();
|
||||||
p3 = p3.Minus(offset);
|
p3 = p3.Minus(offset);
|
||||||
ExprVector u, v;
|
ExprVector u, v;
|
||||||
csy->Csys2dGetBasisExprs(&u, &v);
|
w->WorkplaneGetBasisExprs(&u, &v);
|
||||||
AddEq(l, Expr::FromParam(b->param.h[0])->Minus(p3.Dot(u)), 0);
|
AddEq(l, Expr::FromParam(b->param[0])->Minus(p3.Dot(u)), 0);
|
||||||
AddEq(l, Expr::FromParam(b->param.h[1])->Minus(p3.Dot(v)), 1);
|
AddEq(l, Expr::FromParam(b->param[1])->Minus(p3.Dot(v)), 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -248,28 +248,28 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||||||
hEntity ha, hb;
|
hEntity ha, hb;
|
||||||
if(entityA.v) {
|
if(entityA.v) {
|
||||||
Entity *e = SS.GetEntity(entityA);
|
Entity *e = SS.GetEntity(entityA);
|
||||||
ha = e->assoc[0];
|
ha = e->point[0];
|
||||||
hb = e->assoc[1];
|
hb = e->point[1];
|
||||||
} else {
|
} else {
|
||||||
ha = ptA;
|
ha = ptA;
|
||||||
hb = ptB;
|
hb = ptB;
|
||||||
}
|
}
|
||||||
Entity *a = SS.GetEntity(ha);
|
Entity *a = SS.GetEntity(ha);
|
||||||
Entity *b = SS.GetEntity(hb);
|
Entity *b = SS.GetEntity(hb);
|
||||||
if(a->csys.v == Entity::NO_CSYS.v) {
|
if(a->workplane.v == Entity::FREE_IN_3D.v) {
|
||||||
Entity *t = a;
|
Entity *t = a;
|
||||||
a = b;
|
a = b;
|
||||||
b = t;
|
b = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(a->csys.v == b->csys.v) {
|
if(a->workplane.v == b->workplane.v) {
|
||||||
int i = (type == HORIZONTAL) ? 1 : 0;
|
int i = (type == HORIZONTAL) ? 1 : 0;
|
||||||
AddEq(l, Expr::FromParam(a->param.h[i])->Minus(
|
AddEq(l, Expr::FromParam(a->param[i])->Minus(
|
||||||
Expr::FromParam(b->param.h[i])), 0);
|
Expr::FromParam(b->param[i])), 0);
|
||||||
} else {
|
} else {
|
||||||
Entity *csy = SS.GetEntity(a->csys);
|
Entity *w = SS.GetEntity(a->workplane);
|
||||||
ExprVector u, v;
|
ExprVector u, v;
|
||||||
csy->Csys2dGetBasisExprs(&u, &v);
|
w->WorkplaneGetBasisExprs(&u, &v);
|
||||||
ExprVector norm = (type == HORIZONTAL) ? v : u;
|
ExprVector norm = (type == HORIZONTAL) ? v : u;
|
||||||
ExprVector pa = a->PointGetExprs();
|
ExprVector pa = a->PointGetExprs();
|
||||||
ExprVector pb = b->PointGetExprs();
|
ExprVector pb = b->PointGetExprs();
|
||||||
|
@ -55,7 +55,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) {
|
|||||||
if(dogd.drawing) {
|
if(dogd.drawing) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glxTranslatev(ref);
|
glxTranslatev(ref);
|
||||||
glxOntoCsys(gr, gu);
|
glxOntoWorkplane(gr, gu);
|
||||||
glxWriteText(exprA->Print());
|
glxWriteText(exprA->Print());
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
} else {
|
} else {
|
||||||
@ -114,8 +114,8 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) {
|
|||||||
case EQUAL_LENGTH_LINES: {
|
case EQUAL_LENGTH_LINES: {
|
||||||
for(int i = 0; i < 2; i++) {
|
for(int i = 0; i < 2; i++) {
|
||||||
Entity *e = SS.GetEntity(i == 0 ? entityA : entityB);
|
Entity *e = SS.GetEntity(i == 0 ? entityA : entityB);
|
||||||
Vector a = SS.GetEntity(e->assoc[0])->PointGetCoords();
|
Vector a = SS.GetEntity(e->point[0])->PointGetCoords();
|
||||||
Vector b = SS.GetEntity(e->assoc[1])->PointGetCoords();
|
Vector b = SS.GetEntity(e->point[1])->PointGetCoords();
|
||||||
Vector m = (a.ScaledBy(1.0/3)).Plus(b.ScaledBy(2.0/3));
|
Vector m = (a.ScaledBy(1.0/3)).Plus(b.ScaledBy(2.0/3));
|
||||||
Vector ab = a.Minus(b);
|
Vector ab = a.Minus(b);
|
||||||
Vector n = (gn.Cross(ab)).WithMagnitude(10/SS.GW.scale);
|
Vector n = (gn.Cross(ab)).WithMagnitude(10/SS.GW.scale);
|
||||||
@ -129,14 +129,14 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) {
|
|||||||
case VERTICAL:
|
case VERTICAL:
|
||||||
if(entityA.v) {
|
if(entityA.v) {
|
||||||
Entity *e = SS.GetEntity(entityA);
|
Entity *e = SS.GetEntity(entityA);
|
||||||
Vector a = SS.GetEntity(e->assoc[0])->PointGetCoords();
|
Vector a = SS.GetEntity(e->point[0])->PointGetCoords();
|
||||||
Vector b = SS.GetEntity(e->assoc[1])->PointGetCoords();
|
Vector b = SS.GetEntity(e->point[1])->PointGetCoords();
|
||||||
Vector m = (a.ScaledBy(0.5)).Plus(b.ScaledBy(0.5));
|
Vector m = (a.ScaledBy(0.5)).Plus(b.ScaledBy(0.5));
|
||||||
|
|
||||||
if(dogd.drawing) {
|
if(dogd.drawing) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glxTranslatev(m);
|
glxTranslatev(m);
|
||||||
glxOntoCsys(gr, gu);
|
glxOntoWorkplane(gr, gu);
|
||||||
glxWriteText(type == HORIZONTAL ? "H" : "V");
|
glxWriteText(type == HORIZONTAL ? "H" : "V");
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
} else {
|
} else {
|
||||||
@ -147,10 +147,10 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) {
|
|||||||
Vector a = SS.GetEntity(ptA)->PointGetCoords();
|
Vector a = SS.GetEntity(ptA)->PointGetCoords();
|
||||||
Vector b = SS.GetEntity(ptB)->PointGetCoords();
|
Vector b = SS.GetEntity(ptB)->PointGetCoords();
|
||||||
|
|
||||||
Entity *csy = SS.GetEntity(SS.GetEntity(ptA)->csys);
|
Entity *w = SS.GetEntity(SS.GetEntity(ptA)->workplane);
|
||||||
Vector cu, cv, cn;
|
Vector cu, cv, cn;
|
||||||
csy->Csys2dGetBasisVectors(&cu, &cv);
|
w->WorkplaneGetBasisVectors(&cu, &cv);
|
||||||
cn = csy->Csys2dGetNormalVector();
|
cn = w->WorkplaneGetNormalVector();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < 2; i++) {
|
for(i = 0; i < 2; i++) {
|
||||||
|
112
entity.cpp
112
entity.cpp
@ -5,10 +5,10 @@ char *Entity::DescriptionString(void) {
|
|||||||
return r->DescriptionString();
|
return r->DescriptionString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::Csys2dGetBasisVectors(Vector *u, Vector *v) {
|
void Entity::WorkplaneGetBasisVectors(Vector *u, Vector *v) {
|
||||||
double q[4];
|
double q[4];
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
q[i] = SS.GetParam(param.h[i])->val;
|
q[i] = SS.GetParam(param[i])->val;
|
||||||
}
|
}
|
||||||
Quaternion quat = Quaternion::MakeFrom(q[0], q[1], q[2], q[3]);
|
Quaternion quat = Quaternion::MakeFrom(q[0], q[1], q[2], q[3]);
|
||||||
|
|
||||||
@ -16,17 +16,17 @@ void Entity::Csys2dGetBasisVectors(Vector *u, Vector *v) {
|
|||||||
*v = quat.RotationV();
|
*v = quat.RotationV();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector Entity::Csys2dGetNormalVector(void) {
|
Vector Entity::WorkplaneGetNormalVector(void) {
|
||||||
Vector u, v;
|
Vector u, v;
|
||||||
Csys2dGetBasisVectors(&u, &v);
|
WorkplaneGetBasisVectors(&u, &v);
|
||||||
return u.Cross(v);
|
return u.Cross(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::Csys2dGetBasisExprs(ExprVector *u, ExprVector *v) {
|
void Entity::WorkplaneGetBasisExprs(ExprVector *u, ExprVector *v) {
|
||||||
Expr *a = Expr::FromParam(param.h[0]);
|
Expr *a = Expr::FromParam(param[0]);
|
||||||
Expr *b = Expr::FromParam(param.h[1]);
|
Expr *b = Expr::FromParam(param[1]);
|
||||||
Expr *c = Expr::FromParam(param.h[2]);
|
Expr *c = Expr::FromParam(param[2]);
|
||||||
Expr *d = Expr::FromParam(param.h[3]);
|
Expr *d = Expr::FromParam(param[3]);
|
||||||
|
|
||||||
Expr *two = Expr::FromConstant(2);
|
Expr *two = Expr::FromConstant(2);
|
||||||
|
|
||||||
@ -53,13 +53,13 @@ void Entity::Csys2dGetBasisExprs(ExprVector *u, ExprVector *v) {
|
|||||||
v->z = (v->z)->Plus(two->Times(c->Times(d)));
|
v->z = (v->z)->Plus(two->Times(c->Times(d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprVector Entity::Csys2dGetOffsetExprs(void) {
|
ExprVector Entity::WorkplaneGetOffsetExprs(void) {
|
||||||
return SS.GetEntity(assoc[0])->PointGetExprs();
|
return SS.GetEntity(point[0])->PointGetExprs();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Entity::HasPlane(void) {
|
bool Entity::HasPlane(void) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case CSYS_2D:
|
case WORKPLANE:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -67,11 +67,11 @@ bool Entity::HasPlane(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Entity::PlaneGetExprs(ExprVector *n, Expr **dn) {
|
void Entity::PlaneGetExprs(ExprVector *n, Expr **dn) {
|
||||||
if(type == CSYS_2D) {
|
if(type == WORKPLANE) {
|
||||||
Expr *a = Expr::FromParam(param.h[0]);
|
Expr *a = Expr::FromParam(param[0]);
|
||||||
Expr *b = Expr::FromParam(param.h[1]);
|
Expr *b = Expr::FromParam(param[1]);
|
||||||
Expr *c = Expr::FromParam(param.h[2]);
|
Expr *c = Expr::FromParam(param[2]);
|
||||||
Expr *d = Expr::FromParam(param.h[3]);
|
Expr *d = Expr::FromParam(param[3]);
|
||||||
|
|
||||||
Expr *two = Expr::FromConstant(2);
|
Expr *two = Expr::FromConstant(2);
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ void Entity::PlaneGetExprs(ExprVector *n, Expr **dn) {
|
|||||||
n->z = (n->z)->Minus(c->Square());
|
n->z = (n->z)->Minus(c->Square());
|
||||||
n->z = (n->z)->Plus (d->Square());
|
n->z = (n->z)->Plus (d->Square());
|
||||||
|
|
||||||
ExprVector p0 = SS.GetEntity(assoc[0])->PointGetExprs();
|
ExprVector p0 = SS.GetEntity(point[0])->PointGetExprs();
|
||||||
// The plane is n dot (p - p0) = 0, or
|
// The plane is n dot (p - p0) = 0, or
|
||||||
// n dot p - n dot p0 = 0
|
// n dot p - n dot p0 = 0
|
||||||
// so dn = n dot p0
|
// so dn = n dot p0
|
||||||
@ -117,12 +117,12 @@ bool Entity::IsPointIn3d(void) {
|
|||||||
bool Entity::PointIsKnown(void) {
|
bool Entity::PointIsKnown(void) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case POINT_IN_3D:
|
case POINT_IN_3D:
|
||||||
return SS.GetParam(param.h[0])->known &&
|
return SS.GetParam(param[0])->known &&
|
||||||
SS.GetParam(param.h[1])->known &&
|
SS.GetParam(param[1])->known &&
|
||||||
SS.GetParam(param.h[2])->known;
|
SS.GetParam(param[2])->known;
|
||||||
case POINT_IN_2D:
|
case POINT_IN_2D:
|
||||||
return SS.GetParam(param.h[0])->known &&
|
return SS.GetParam(param[0])->known &&
|
||||||
SS.GetParam(param.h[1])->known;
|
SS.GetParam(param[1])->known;
|
||||||
default: oops();
|
default: oops();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,17 +134,17 @@ bool Entity::PointIsFromReferences(void) {
|
|||||||
void Entity::PointForceTo(Vector p) {
|
void Entity::PointForceTo(Vector p) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case POINT_IN_3D:
|
case POINT_IN_3D:
|
||||||
SS.GetParam(param.h[0])->val = p.x;
|
SS.GetParam(param[0])->val = p.x;
|
||||||
SS.GetParam(param.h[1])->val = p.y;
|
SS.GetParam(param[1])->val = p.y;
|
||||||
SS.GetParam(param.h[2])->val = p.z;
|
SS.GetParam(param[2])->val = p.z;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POINT_IN_2D: {
|
case POINT_IN_2D: {
|
||||||
Entity *c = SS.GetEntity(csys);
|
Entity *c = SS.GetEntity(workplane);
|
||||||
Vector u, v;
|
Vector u, v;
|
||||||
c->Csys2dGetBasisVectors(&u, &v);
|
c->WorkplaneGetBasisVectors(&u, &v);
|
||||||
SS.GetParam(param.h[0])->val = p.Dot(u);
|
SS.GetParam(param[0])->val = p.Dot(u);
|
||||||
SS.GetParam(param.h[1])->val = p.Dot(v);
|
SS.GetParam(param[1])->val = p.Dot(v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: oops();
|
default: oops();
|
||||||
@ -155,17 +155,17 @@ Vector Entity::PointGetCoords(void) {
|
|||||||
Vector p;
|
Vector p;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case POINT_IN_3D:
|
case POINT_IN_3D:
|
||||||
p.x = SS.GetParam(param.h[0])->val;
|
p.x = SS.GetParam(param[0])->val;
|
||||||
p.y = SS.GetParam(param.h[1])->val;
|
p.y = SS.GetParam(param[1])->val;
|
||||||
p.z = SS.GetParam(param.h[2])->val;
|
p.z = SS.GetParam(param[2])->val;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POINT_IN_2D: {
|
case POINT_IN_2D: {
|
||||||
Entity *c = SS.GetEntity(csys);
|
Entity *c = SS.GetEntity(workplane);
|
||||||
Vector u, v;
|
Vector u, v;
|
||||||
c->Csys2dGetBasisVectors(&u, &v);
|
c->WorkplaneGetBasisVectors(&u, &v);
|
||||||
p = u.ScaledBy(SS.GetParam(param.h[0])->val);
|
p = u.ScaledBy(SS.GetParam(param[0])->val);
|
||||||
p = p.Plus(v.ScaledBy(SS.GetParam(param.h[1])->val));
|
p = p.Plus(v.ScaledBy(SS.GetParam(param[1])->val));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: oops();
|
default: oops();
|
||||||
@ -177,18 +177,18 @@ ExprVector Entity::PointGetExprs(void) {
|
|||||||
ExprVector r;
|
ExprVector r;
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case POINT_IN_3D:
|
case POINT_IN_3D:
|
||||||
r.x = Expr::FromParam(param.h[0]);
|
r.x = Expr::FromParam(param[0]);
|
||||||
r.y = Expr::FromParam(param.h[1]);
|
r.y = Expr::FromParam(param[1]);
|
||||||
r.z = Expr::FromParam(param.h[2]);
|
r.z = Expr::FromParam(param[2]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POINT_IN_2D: {
|
case POINT_IN_2D: {
|
||||||
Entity *c = SS.GetEntity(csys);
|
Entity *c = SS.GetEntity(workplane);
|
||||||
ExprVector u, v;
|
ExprVector u, v;
|
||||||
c->Csys2dGetBasisExprs(&u, &v);
|
c->WorkplaneGetBasisExprs(&u, &v);
|
||||||
|
|
||||||
r = u.ScaledBy(Expr::FromParam(param.h[0]));
|
r = u.ScaledBy(Expr::FromParam(param[0]));
|
||||||
r = r.Plus(v.ScaledBy(Expr::FromParam(param.h[1])));
|
r = r.Plus(v.ScaledBy(Expr::FromParam(param[1])));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: oops();
|
default: oops();
|
||||||
@ -254,7 +254,7 @@ void Entity::DrawOrGetDistance(int order) {
|
|||||||
if(!SS.GW.showPoints) break;
|
if(!SS.GW.showPoints) break;
|
||||||
|
|
||||||
Entity *isfor = SS.GetEntity(h.request().entity(0));
|
Entity *isfor = SS.GetEntity(h.request().entity(0));
|
||||||
if(!SS.GW.show2dCsyss && isfor->type == Entity::CSYS_2D) break;
|
if(!SS.GW.showWorkplanes && isfor->type == Entity::WORKPLANE) break;
|
||||||
|
|
||||||
Vector v = PointGetCoords();
|
Vector v = PointGetCoords();
|
||||||
|
|
||||||
@ -277,15 +277,15 @@ void Entity::DrawOrGetDistance(int order) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CSYS_2D: {
|
case WORKPLANE: {
|
||||||
if(order >= 0 && order != 0) break;
|
if(order >= 0 && order != 0) break;
|
||||||
if(!SS.GW.show2dCsyss) break;
|
if(!SS.GW.showWorkplanes) break;
|
||||||
|
|
||||||
Vector p;
|
Vector p;
|
||||||
p = SS.GetEntity(assoc[0])->PointGetCoords();
|
p = SS.GetEntity(point[0])->PointGetCoords();
|
||||||
|
|
||||||
Vector u, v;
|
Vector u, v;
|
||||||
Csys2dGetBasisVectors(&u, &v);
|
WorkplaneGetBasisVectors(&u, &v);
|
||||||
|
|
||||||
double s = (min(SS.GW.width, SS.GW.height))*0.4/SS.GW.scale;
|
double s = (min(SS.GW.width, SS.GW.height))*0.4/SS.GW.scale;
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ void Entity::DrawOrGetDistance(int order) {
|
|||||||
if(dogd.drawing) {
|
if(dogd.drawing) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glxTranslatev(mm);
|
glxTranslatev(mm);
|
||||||
glxOntoCsys(u, v);
|
glxOntoWorkplane(u, v);
|
||||||
glxWriteText(DescriptionString());
|
glxWriteText(DescriptionString());
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
@ -315,17 +315,17 @@ void Entity::DrawOrGetDistance(int order) {
|
|||||||
|
|
||||||
case LINE_SEGMENT: {
|
case LINE_SEGMENT: {
|
||||||
if(order >= 0 && order != 1) break;
|
if(order >= 0 && order != 1) break;
|
||||||
Vector a = SS.GetEntity(assoc[0])->PointGetCoords();
|
Vector a = SS.GetEntity(point[0])->PointGetCoords();
|
||||||
Vector b = SS.GetEntity(assoc[1])->PointGetCoords();
|
Vector b = SS.GetEntity(point[1])->PointGetCoords();
|
||||||
LineDrawOrGetDistanceOrEdge(a, b);
|
LineDrawOrGetDistanceOrEdge(a, b);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CUBIC: {
|
case CUBIC: {
|
||||||
Vector p0 = SS.GetEntity(assoc[0])->PointGetCoords();
|
Vector p0 = SS.GetEntity(point[0])->PointGetCoords();
|
||||||
Vector p1 = SS.GetEntity(assoc[1])->PointGetCoords();
|
Vector p1 = SS.GetEntity(point[1])->PointGetCoords();
|
||||||
Vector p2 = SS.GetEntity(assoc[2])->PointGetCoords();
|
Vector p2 = SS.GetEntity(point[2])->PointGetCoords();
|
||||||
Vector p3 = SS.GetEntity(assoc[3])->PointGetCoords();
|
Vector p3 = SS.GetEntity(point[3])->PointGetCoords();
|
||||||
int i, n = 20;
|
int i, n = 20;
|
||||||
Vector prev = p0;
|
Vector prev = p0;
|
||||||
for(i = 1; i <= n; i++) {
|
for(i = 1; i <= n; i++) {
|
||||||
|
31
file.cpp
31
file.cpp
@ -24,19 +24,19 @@ void SolveSpace::NewFile(void) {
|
|||||||
// planes; these are our references, present in every sketch.
|
// planes; these are our references, present in every sketch.
|
||||||
Request r;
|
Request r;
|
||||||
memset(&r, 0, sizeof(r));
|
memset(&r, 0, sizeof(r));
|
||||||
r.type = Request::CSYS_2D;
|
r.type = Request::WORKPLANE;
|
||||||
r.group = Group::HGROUP_REFERENCES;
|
r.group = Group::HGROUP_REFERENCES;
|
||||||
r.csys = Entity::NO_CSYS;
|
r.workplane = Entity::FREE_IN_3D;
|
||||||
|
|
||||||
r.name.strcpy("#XY-csys");
|
r.name.strcpy("#XY");
|
||||||
r.h = Request::HREQUEST_REFERENCE_XY;
|
r.h = Request::HREQUEST_REFERENCE_XY;
|
||||||
request.Add(&r);
|
request.Add(&r);
|
||||||
|
|
||||||
r.name.strcpy("#YZ-csys");
|
r.name.strcpy("#YZ");
|
||||||
r.h = Request::HREQUEST_REFERENCE_YZ;
|
r.h = Request::HREQUEST_REFERENCE_YZ;
|
||||||
request.Add(&r);
|
request.Add(&r);
|
||||||
|
|
||||||
r.name.strcpy("#ZX-csys");
|
r.name.strcpy("#ZX");
|
||||||
r.h = Request::HREQUEST_REFERENCE_ZX;
|
r.h = Request::HREQUEST_REFERENCE_ZX;
|
||||||
request.Add(&r);
|
request.Add(&r);
|
||||||
}
|
}
|
||||||
@ -54,22 +54,23 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = {
|
|||||||
|
|
||||||
{ 'r', "Request.h.v", 'x', &(SS.sv.r.h.v) },
|
{ 'r', "Request.h.v", 'x', &(SS.sv.r.h.v) },
|
||||||
{ 'r', "Request.type", 'd', &(SS.sv.r.type) },
|
{ 'r', "Request.type", 'd', &(SS.sv.r.type) },
|
||||||
{ 'r', "Request.csys.v", 'x', &(SS.sv.r.csys.v) },
|
{ 'r', "Request.workplane.v", 'x', &(SS.sv.r.workplane.v) },
|
||||||
{ 'r', "Request.group.v", 'x', &(SS.sv.r.group.v) },
|
{ 'r', "Request.group.v", 'x', &(SS.sv.r.group.v) },
|
||||||
{ 'r', "Request.name", 'N', &(SS.sv.r.name) },
|
{ 'r', "Request.name", 'N', &(SS.sv.r.name) },
|
||||||
{ 'r', "Request.construction", 'b', &(SS.sv.r.construction) },
|
{ 'r', "Request.construction", 'b', &(SS.sv.r.construction) },
|
||||||
|
|
||||||
{ 'e', "Entity.h.v", 'x', &(SS.sv.e.h.v) },
|
{ 'e', "Entity.h.v", 'x', &(SS.sv.e.h.v) },
|
||||||
{ 'e', "Entity.type", 'd', &(SS.sv.e.type) },
|
{ 'e', "Entity.type", 'd', &(SS.sv.e.type) },
|
||||||
{ 'e', "Entity.param.h[0].v", 'x', &(SS.sv.e.param.h[0].v) },
|
{ 'e', "Entity.param[0].v", 'x', &(SS.sv.e.param[0].v) },
|
||||||
{ 'e', "Entity.param.h[1].v", 'x', &(SS.sv.e.param.h[1].v) },
|
{ 'e', "Entity.param[1].v", 'x', &(SS.sv.e.param[1].v) },
|
||||||
{ 'e', "Entity.param.h[2].v", 'x', &(SS.sv.e.param.h[2].v) },
|
{ 'e', "Entity.param[2].v", 'x', &(SS.sv.e.param[2].v) },
|
||||||
{ 'e', "Entity.param.h[3].v", 'x', &(SS.sv.e.param.h[3].v) },
|
{ 'e', "Entity.param[3].v", 'x', &(SS.sv.e.param[3].v) },
|
||||||
{ 'e', "Entity.assoc[0].v", 'x', &(SS.sv.e.assoc[0].v) },
|
{ 'e', "Entity.point[0].v", 'x', &(SS.sv.e.point[0].v) },
|
||||||
{ 'e', "Entity.assoc[1].v", 'x', &(SS.sv.e.assoc[1].v) },
|
{ 'e', "Entity.point[1].v", 'x', &(SS.sv.e.point[1].v) },
|
||||||
{ 'e', "Entity.assoc[2].v", 'x', &(SS.sv.e.assoc[2].v) },
|
{ 'e', "Entity.point[2].v", 'x', &(SS.sv.e.point[2].v) },
|
||||||
{ 'e', "Entity.assoc[3].v", 'x', &(SS.sv.e.assoc[3].v) },
|
{ 'e', "Entity.point[3].v", 'x', &(SS.sv.e.point[3].v) },
|
||||||
{ 'e', "Entity.csys.v", 'x', &(SS.sv.e.csys.v) },
|
{ 'e', "Entity.direction.v", 'x', &(SS.sv.e.direction.v) },
|
||||||
|
{ 'e', "Entity.workplane.v", 'x', &(SS.sv.e.workplane.v) },
|
||||||
|
|
||||||
{ 'c', "Constraint.h.v", 'x', &(SS.sv.c.h.v) },
|
{ 'c', "Constraint.h.v", 'x', &(SS.sv.c.h.v) },
|
||||||
{ 'c', "Constraint.type", 'd', &(SS.sv.c.type) },
|
{ 'c', "Constraint.type", 'd', &(SS.sv.c.type) },
|
||||||
|
@ -46,7 +46,7 @@ void glxTranslatev(Vector u)
|
|||||||
glTranslated((GLdouble)u.x, (GLdouble)u.y, (GLdouble)u.z);
|
glTranslated((GLdouble)u.x, (GLdouble)u.y, (GLdouble)u.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glxOntoCsys(Vector u, Vector v)
|
void glxOntoWorkplane(Vector u, Vector v)
|
||||||
{
|
{
|
||||||
double mat[16];
|
double mat[16];
|
||||||
Vector n = u.Cross(v);
|
Vector n = u.Cross(v);
|
||||||
|
@ -46,8 +46,8 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
|
|||||||
{ 1, "New Boolean Union", 0, 0, NULL },
|
{ 1, "New Boolean Union", 0, 0, NULL },
|
||||||
|
|
||||||
{ 0, "&Request", 0, NULL },
|
{ 0, "&Request", 0, NULL },
|
||||||
{ 1, "Dra&w in 2d Coordinate System\tW", MNU_SEL_CSYS, 'W', mReq },
|
{ 1, "Draw in &Workplane\tW", MNU_SEL_WORKPLANE, 'W', mReq },
|
||||||
{ 1, "Draw Anywhere in 3d\tQ", MNU_NO_CSYS, 'Q', mReq },
|
{ 1, "Draw Anywhere in 3d\tQ", MNU_FREE_IN_3D, 'Q', mReq },
|
||||||
{ 1, NULL, 0, NULL },
|
{ 1, NULL, 0, NULL },
|
||||||
{ 1, "Datum &Point\tP", MNU_DATUM_POINT, 'P', mReq },
|
{ 1, "Datum &Point\tP", MNU_DATUM_POINT, 'P', mReq },
|
||||||
{ 1, "Datum A&xis\tX", 0, 'X', mReq },
|
{ 1, "Datum A&xis\tX", 0, 'X', mReq },
|
||||||
@ -99,9 +99,9 @@ void GraphicsWindow::Init(void) {
|
|||||||
|
|
||||||
// Start locked on to the XY plane.
|
// Start locked on to the XY plane.
|
||||||
hRequest r = Request::HREQUEST_REFERENCE_XY;
|
hRequest r = Request::HREQUEST_REFERENCE_XY;
|
||||||
activeCsys = r.entity(0);
|
activeWorkplane = r.entity(0);
|
||||||
|
|
||||||
show2dCsyss = true;
|
showWorkplanes = true;
|
||||||
showAxes = true;
|
showAxes = true;
|
||||||
showPoints = true;
|
showPoints = true;
|
||||||
showAllGroups = true;
|
showAllGroups = true;
|
||||||
@ -206,17 +206,17 @@ void GraphicsWindow::EnsureValidActives(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The active coordinate system must also exist.
|
// The active coordinate system must also exist.
|
||||||
if(activeCsys.v != Entity::NO_CSYS.v &&
|
if(activeWorkplane.v != Entity::FREE_IN_3D.v &&
|
||||||
!SS.entity.FindByIdNoOops(activeCsys))
|
!SS.entity.FindByIdNoOops(activeWorkplane))
|
||||||
{
|
{
|
||||||
activeCsys = Entity::NO_CSYS;
|
activeWorkplane = Entity::FREE_IN_3D;
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
if(change) SS.TW.Show();
|
if(change) SS.TW.Show();
|
||||||
|
|
||||||
bool in3d = (activeCsys.v == Entity::NO_CSYS.v);
|
bool in3d = (activeWorkplane.v == Entity::FREE_IN_3D.v);
|
||||||
CheckMenuById(MNU_NO_CSYS, in3d);
|
CheckMenuById(MNU_FREE_IN_3D, in3d);
|
||||||
CheckMenuById(MNU_SEL_CSYS, !in3d);
|
CheckMenuById(MNU_SEL_WORKPLANE, !in3d);
|
||||||
|
|
||||||
// And update the checked state for various menus
|
// And update the checked state for various menus
|
||||||
switch(viewUnits) {
|
switch(viewUnits) {
|
||||||
@ -288,32 +288,32 @@ void GraphicsWindow::MenuEdit(int id) {
|
|||||||
void GraphicsWindow::MenuRequest(int id) {
|
void GraphicsWindow::MenuRequest(int id) {
|
||||||
char *s;
|
char *s;
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case MNU_SEL_CSYS: {
|
case MNU_SEL_WORKPLANE: {
|
||||||
SS.GW.GroupSelection();
|
SS.GW.GroupSelection();
|
||||||
if(SS.GW.gs.n == 1 && SS.GW.gs.csyss == 1) {
|
if(SS.GW.gs.n == 1 && SS.GW.gs.workplanes == 1) {
|
||||||
SS.GW.activeCsys = SS.GW.gs.entity[0];
|
SS.GW.activeWorkplane = SS.GW.gs.entity[0];
|
||||||
SS.GW.ClearSelection();
|
SS.GW.ClearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SS.GW.activeCsys.v == Entity::NO_CSYS.v) {
|
if(SS.GW.activeWorkplane.v == Entity::FREE_IN_3D.v) {
|
||||||
Error("Select 2d coordinate system (e.g., the XY plane) "
|
Error("Select workplane (e.g., the XY plane) "
|
||||||
"before locking on.");
|
"before locking on.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Align the view with the selected csys
|
// Align the view with the selected workplane
|
||||||
Entity *e = SS.GetEntity(SS.GW.activeCsys);
|
Entity *e = SS.GetEntity(SS.GW.activeWorkplane);
|
||||||
Vector pr, pu;
|
Vector pr, pu;
|
||||||
e->Csys2dGetBasisVectors(&pr, &pu);
|
e->WorkplaneGetBasisVectors(&pr, &pu);
|
||||||
Quaternion quatf = Quaternion::MakeFrom(pr, pu);
|
Quaternion quatf = Quaternion::MakeFrom(pr, pu);
|
||||||
Vector offsetf = SS.GetEntity(e->assoc[0])->PointGetCoords();
|
Vector offsetf = SS.GetEntity(e->point[0])->PointGetCoords();
|
||||||
SS.GW.AnimateOnto(quatf, offsetf);
|
SS.GW.AnimateOnto(quatf, offsetf);
|
||||||
|
|
||||||
SS.GW.EnsureValidActives();
|
SS.GW.EnsureValidActives();
|
||||||
SS.TW.Show();
|
SS.TW.Show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MNU_NO_CSYS:
|
case MNU_FREE_IN_3D:
|
||||||
SS.GW.activeCsys = Entity::NO_CSYS;
|
SS.GW.activeWorkplane = Entity::FREE_IN_3D;
|
||||||
SS.GW.EnsureValidActives();
|
SS.GW.EnsureValidActives();
|
||||||
SS.TW.Show();
|
SS.TW.Show();
|
||||||
break;
|
break;
|
||||||
@ -517,7 +517,7 @@ void GraphicsWindow::GroupSelection(void) {
|
|||||||
gs.entity[(gs.entities)++] = s->entity;
|
gs.entity[(gs.entities)++] = s->entity;
|
||||||
}
|
}
|
||||||
switch(e->type) {
|
switch(e->type) {
|
||||||
case Entity::CSYS_2D: (gs.csyss)++; break;
|
case Entity::WORKPLANE: (gs.workplanes)++; break;
|
||||||
case Entity::LINE_SEGMENT: (gs.lineSegments)++; break;
|
case Entity::LINE_SEGMENT: (gs.lineSegments)++; break;
|
||||||
}
|
}
|
||||||
if(e->HasPlane()) (gs.planes)++;
|
if(e->HasPlane()) (gs.planes)++;
|
||||||
@ -539,7 +539,7 @@ hRequest GraphicsWindow::AddRequest(int type) {
|
|||||||
Request r;
|
Request r;
|
||||||
memset(&r, 0, sizeof(r));
|
memset(&r, 0, sizeof(r));
|
||||||
r.group = activeGroup;
|
r.group = activeGroup;
|
||||||
r.csys = activeCsys;
|
r.workplane = activeWorkplane;
|
||||||
r.type = type;
|
r.type = type;
|
||||||
SS.request.AddAndAssignId(&r);
|
SS.request.AddAndAssignId(&r);
|
||||||
SS.GenerateAll();
|
SS.GenerateAll();
|
||||||
@ -744,8 +744,8 @@ void GraphicsWindow::ToggleBool(int link, DWORD v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsWindow::ToggleAnyDatumShown(int link, DWORD v) {
|
void GraphicsWindow::ToggleAnyDatumShown(int link, DWORD v) {
|
||||||
bool t = !(SS.GW.show2dCsyss && SS.GW.showAxes && SS.GW.showPoints);
|
bool t = !(SS.GW.showWorkplanes && SS.GW.showAxes && SS.GW.showPoints);
|
||||||
SS.GW.show2dCsyss = t;
|
SS.GW.showWorkplanes = t;
|
||||||
SS.GW.showAxes = t;
|
SS.GW.showAxes = t;
|
||||||
SS.GW.showPoints = t;
|
SS.GW.showPoints = t;
|
||||||
|
|
||||||
@ -795,7 +795,7 @@ void GraphicsWindow::Paint(int w, int h) {
|
|||||||
// levels, and only the first gets normal depth testing.
|
// levels, and only the first gets normal depth testing.
|
||||||
glxUnlockColor();
|
glxUnlockColor();
|
||||||
for(a = 0; a <= 2; a++) {
|
for(a = 0; a <= 2; a++) {
|
||||||
// Three levels: 0 least prominent (e.g. a reference csys), 1 is
|
// Three levels: 0 least prominent (e.g. a reference workplane), 1 is
|
||||||
// middle (e.g. line segment), 2 is always in front (e.g. point).
|
// middle (e.g. line segment), 2 is always in front (e.g. point).
|
||||||
if(a == 1) glDisable(GL_DEPTH_TEST);
|
if(a == 1) glDisable(GL_DEPTH_TEST);
|
||||||
for(i = 0; i < SS.entity.n; i++) {
|
for(i = 0; i < SS.entity.n; i++) {
|
||||||
|
26
sketch.cpp
26
sketch.cpp
@ -1,6 +1,6 @@
|
|||||||
#include "solvespace.h"
|
#include "solvespace.h"
|
||||||
|
|
||||||
const hEntity Entity::NO_CSYS = { 0 };
|
const hEntity Entity::FREE_IN_3D = { 0 };
|
||||||
|
|
||||||
const hGroup Group::HGROUP_REFERENCES = { 1 };
|
const hGroup Group::HGROUP_REFERENCES = { 1 };
|
||||||
const hRequest Request::HREQUEST_REFERENCE_XY = { 1 };
|
const hRequest Request::HREQUEST_REFERENCE_XY = { 1 };
|
||||||
@ -44,7 +44,7 @@ void Group::Draw(void) {
|
|||||||
glxColor3d(1, 0, 0);
|
glxColor3d(1, 0, 0);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glxTranslatev(error.b);
|
glxTranslatev(error.b);
|
||||||
glxOntoCsys(SS.GW.projRight, SS.GW.projUp);
|
glxOntoWorkplane(SS.GW.projRight, SS.GW.projUp);
|
||||||
glxWriteText("not closed contour!");
|
glxWriteText("not closed contour!");
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
@ -72,8 +72,8 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
|
|||||||
Entity e;
|
Entity e;
|
||||||
memset(&e, 0, sizeof(e));
|
memset(&e, 0, sizeof(e));
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case Request::CSYS_2D:
|
case Request::WORKPLANE:
|
||||||
et = Entity::CSYS_2D; points = 1; params = 4; goto c;
|
et = Entity::WORKPLANE; points = 1; params = 4; goto c;
|
||||||
|
|
||||||
case Request::DATUM_POINT:
|
case Request::DATUM_POINT:
|
||||||
et = 0; points = 1; params = 0; goto c;
|
et = 0; points = 1; params = 0; goto c;
|
||||||
@ -92,29 +92,29 @@ c: {
|
|||||||
for(i = 0; i < points; i++) {
|
for(i = 0; i < points; i++) {
|
||||||
Entity p;
|
Entity p;
|
||||||
memset(&p, 0, sizeof(p));
|
memset(&p, 0, sizeof(p));
|
||||||
p.csys = csys;
|
p.workplane = workplane;
|
||||||
// points start from entity 1, except for datum point case
|
// points start from entity 1, except for datum point case
|
||||||
p.h = h.entity(i+(et ? 1 : 0));
|
p.h = h.entity(i+(et ? 1 : 0));
|
||||||
p.symbolic = true;
|
p.symbolic = true;
|
||||||
if(csys.v == Entity::NO_CSYS.v) {
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
||||||
p.type = Entity::POINT_IN_3D;
|
p.type = Entity::POINT_IN_3D;
|
||||||
// params for x y z
|
// params for x y z
|
||||||
p.param.h[0] = AddParam(param, h.param(16 + 3*i + 0));
|
p.param[0] = AddParam(param, h.param(16 + 3*i + 0));
|
||||||
p.param.h[1] = AddParam(param, h.param(16 + 3*i + 1));
|
p.param[1] = AddParam(param, h.param(16 + 3*i + 1));
|
||||||
p.param.h[2] = AddParam(param, h.param(16 + 3*i + 2));
|
p.param[2] = AddParam(param, h.param(16 + 3*i + 2));
|
||||||
} else {
|
} else {
|
||||||
p.type = Entity::POINT_IN_2D;
|
p.type = Entity::POINT_IN_2D;
|
||||||
// params for u v
|
// params for u v
|
||||||
p.param.h[0] = AddParam(param, h.param(16 + 3*i + 0));
|
p.param[0] = AddParam(param, h.param(16 + 3*i + 0));
|
||||||
p.param.h[1] = AddParam(param, h.param(16 + 3*i + 1));
|
p.param[1] = AddParam(param, h.param(16 + 3*i + 1));
|
||||||
}
|
}
|
||||||
entity->Add(&p);
|
entity->Add(&p);
|
||||||
e.assoc[i] = p.h;
|
e.point[i] = p.h;
|
||||||
}
|
}
|
||||||
// And generate any params not associated with the point that
|
// And generate any params not associated with the point that
|
||||||
// we happen to need.
|
// we happen to need.
|
||||||
for(i = 0; i < params; i++) {
|
for(i = 0; i < params; i++) {
|
||||||
e.param.h[i] = AddParam(param, h.param(i));
|
e.param[i] = AddParam(param, h.param(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(et) entity->Add(&e);
|
if(et) entity->Add(&e);
|
||||||
|
94
sketch.h
94
sketch.h
@ -47,6 +47,19 @@ public:
|
|||||||
inline hRequest request(void);
|
inline hRequest request(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class EntityId {
|
||||||
|
DWORD v; // entity ID, starting from 0
|
||||||
|
};
|
||||||
|
class EntityMap {
|
||||||
|
int tag;
|
||||||
|
|
||||||
|
EntityId h;
|
||||||
|
hEntity input;
|
||||||
|
int copyNumber;
|
||||||
|
// (input, copyNumber) gets mapped to ((Request)xxx).entity(h.v)
|
||||||
|
};
|
||||||
|
|
||||||
// A set of requests. Every request must have an associated group.
|
// A set of requests. Every request must have an associated group.
|
||||||
class Group {
|
class Group {
|
||||||
public:
|
public:
|
||||||
@ -69,27 +82,20 @@ public:
|
|||||||
SPolygon poly;
|
SPolygon poly;
|
||||||
|
|
||||||
NameStr name;
|
NameStr name;
|
||||||
|
|
||||||
char *DescriptionString(void);
|
char *DescriptionString(void);
|
||||||
|
|
||||||
|
// When a request generates entities from entities, and the source
|
||||||
|
// entities may have come from multiple requests, it's necessary to
|
||||||
|
// remap the entity ID so that it's still unique. We do this with a
|
||||||
|
// mapping list.
|
||||||
|
IdList<EntityId,EntityMap> remap;
|
||||||
|
hEntity Remap(hEntity in, int copyNumber);
|
||||||
|
|
||||||
void Draw(void);
|
void Draw(void);
|
||||||
|
|
||||||
SPolygon GetPolygon(void);
|
SPolygon GetPolygon(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EntityId {
|
|
||||||
DWORD v; // entity ID, starting from 0
|
|
||||||
};
|
|
||||||
class EntityMap {
|
|
||||||
int tag;
|
|
||||||
|
|
||||||
EntityId h;
|
|
||||||
hEntity input;
|
|
||||||
int copyNumber;
|
|
||||||
// (input, copyNumber) gets mapped to ((Request)xxx).entity(h.v)
|
|
||||||
};
|
|
||||||
|
|
||||||
// A user request for some primitive or derived operation; for example a
|
// A user request for some primitive or derived operation; for example a
|
||||||
// line, or a step and repeat.
|
// line, or a step and repeat.
|
||||||
class Request {
|
class Request {
|
||||||
@ -103,25 +109,19 @@ public:
|
|||||||
hRequest h;
|
hRequest h;
|
||||||
|
|
||||||
// Types of requests
|
// Types of requests
|
||||||
static const int CSYS_2D = 100;
|
static const int WORKPLANE = 100;
|
||||||
static const int DATUM_POINT = 101;
|
static const int DATUM_POINT = 101;
|
||||||
static const int LINE_SEGMENT = 200;
|
static const int LINE_SEGMENT = 200;
|
||||||
static const int CUBIC = 300;
|
static const int CUBIC = 300;
|
||||||
|
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
hEntity csys; // or Entity::NO_CSYS
|
hEntity workplane; // or Entity::FREE_IN_3D
|
||||||
hGroup group;
|
hGroup group;
|
||||||
|
|
||||||
NameStr name;
|
NameStr name;
|
||||||
bool construction;
|
bool construction;
|
||||||
|
|
||||||
// When a request generates entities from entities, and the source
|
|
||||||
// entities may have come from multiple requests, it's necessary to
|
|
||||||
// remap the entity ID so that it's still unique. We do this with a
|
|
||||||
// mapping list.
|
|
||||||
IdList<EntityId,EntityMap> remap;
|
|
||||||
hEntity Remap(hEntity in, int copyNumber);
|
|
||||||
|
|
||||||
hParam AddParam(IdList<Param,hParam> *param, hParam hp);
|
hParam AddParam(IdList<Param,hParam> *param, hParam hp);
|
||||||
void Generate(IdList<Entity,hEntity> *entity, IdList<Param,hParam> *param);
|
void Generate(IdList<Entity,hEntity> *entity, IdList<Param,hParam> *param);
|
||||||
|
|
||||||
@ -133,32 +133,36 @@ public:
|
|||||||
int tag;
|
int tag;
|
||||||
hEntity h;
|
hEntity h;
|
||||||
|
|
||||||
static const hEntity NO_CSYS;
|
static const hEntity FREE_IN_3D;
|
||||||
|
|
||||||
static const int CSYS_2D = 1000;
|
static const int WORKPLANE = 1000;
|
||||||
static const int POINT_IN_3D = 2000;
|
static const int POINT_IN_3D = 2000;
|
||||||
static const int POINT_IN_2D = 2001;
|
static const int POINT_IN_2D = 2001;
|
||||||
static const int LINE_SEGMENT = 3000;
|
static const int POINT_OFFSET = 2010;
|
||||||
static const int CUBIC = 4000;
|
static const int DIRECTION_QUATERNION = 3000;
|
||||||
|
static const int DIRECTION_OFFSET = 3010;
|
||||||
|
static const int LINE_SEGMENT = 10000;
|
||||||
|
static const int CUBIC = 11000;
|
||||||
|
|
||||||
|
static const int EDGE_LIST = 90000;
|
||||||
|
static const int FACE_LIST = 91000;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
bool symbolic;
|
bool symbolic;
|
||||||
// The params are usually handles to the symbolic variables, but may
|
|
||||||
// also be constants
|
|
||||||
union {
|
|
||||||
hParam h[16];
|
|
||||||
double v[16];
|
|
||||||
} param;
|
|
||||||
// Associated entities, e.g. the endpoints for a line segment
|
|
||||||
hEntity assoc[16];
|
|
||||||
|
|
||||||
hEntity csys; // or Entity::NO_CSYS
|
// When it comes time to draw an entity, we look here to get the
|
||||||
|
// defining variables.
|
||||||
|
hParam param[4];
|
||||||
|
hEntity point[4];
|
||||||
|
hEntity direction;
|
||||||
|
|
||||||
// Applies only for a CSYS_2D type
|
hEntity workplane; // or Entity::FREE_IN_3D
|
||||||
void Csys2dGetBasisVectors(Vector *u, Vector *v);
|
|
||||||
Vector Csys2dGetNormalVector(void);
|
// Applies only for a WORKPLANE type
|
||||||
void Csys2dGetBasisExprs(ExprVector *u, ExprVector *v);
|
void WorkplaneGetBasisVectors(Vector *u, Vector *v);
|
||||||
ExprVector Csys2dGetOffsetExprs(void);
|
Vector WorkplaneGetNormalVector(void);
|
||||||
|
void WorkplaneGetBasisExprs(ExprVector *u, ExprVector *v);
|
||||||
|
ExprVector WorkplaneGetOffsetExprs(void);
|
||||||
|
|
||||||
bool IsPoint(void);
|
bool IsPoint(void);
|
||||||
bool IsPointIn3d(void);
|
bool IsPointIn3d(void);
|
||||||
@ -244,7 +248,9 @@ public:
|
|||||||
hConstraint h;
|
hConstraint h;
|
||||||
|
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
hGroup group;
|
hGroup group;
|
||||||
|
hEntity workplane;
|
||||||
|
|
||||||
// These are the parameters for the constraint.
|
// These are the parameters for the constraint.
|
||||||
Expr *exprA;
|
Expr *exprA;
|
||||||
|
@ -67,7 +67,7 @@ void glxVertex3v(Vector u);
|
|||||||
void glxFillPolygon(SPolygon *p);
|
void glxFillPolygon(SPolygon *p);
|
||||||
void glxWriteText(char *str);
|
void glxWriteText(char *str);
|
||||||
void glxTranslatev(Vector u);
|
void glxTranslatev(Vector u);
|
||||||
void glxOntoCsys(Vector u, Vector v);
|
void glxOntoWorkplane(Vector u, Vector v);
|
||||||
void glxLockColorTo(double r, double g, double b);
|
void glxLockColorTo(double r, double g, double b);
|
||||||
void glxUnlockColor(void);
|
void glxUnlockColor(void);
|
||||||
void glxColor3d(double r, double g, double b);
|
void glxColor3d(double r, double g, double b);
|
||||||
|
20
textwin.cpp
20
textwin.cpp
@ -205,21 +205,21 @@ void TextWindow::ShowHeader(void) {
|
|||||||
} else {
|
} else {
|
||||||
// Navigation buttons
|
// Navigation buttons
|
||||||
char *cd;
|
char *cd;
|
||||||
if(SS.GW.activeCsys.v == Entity::NO_CSYS.v) {
|
if(SS.GW.activeWorkplane.v == Entity::FREE_IN_3D.v) {
|
||||||
cd = "free in 3d";
|
cd = "free in 3d";
|
||||||
} else {
|
} else {
|
||||||
cd = SS.GetEntity(SS.GW.activeCsys)->DescriptionString();
|
cd = SS.GetEntity(SS.GW.activeWorkplane)->DescriptionString();
|
||||||
}
|
}
|
||||||
Printf(" %Lb%f<<%E %Lh%fhome%E %CT csys:%CD %s",
|
Printf(" %Lb%f<<%E %Lh%fhome%E %CT workplane:%CD %s",
|
||||||
(DWORD)(&TextWindow::ScreenNavigation),
|
(DWORD)(&TextWindow::ScreenNavigation),
|
||||||
(DWORD)(&TextWindow::ScreenNavigation),
|
(DWORD)(&TextWindow::ScreenNavigation),
|
||||||
cd);
|
cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int datumColor;
|
int datumColor;
|
||||||
if(SS.GW.show2dCsyss && SS.GW.showAxes && SS.GW.showPoints) {
|
if(SS.GW.showWorkplanes && SS.GW.showAxes && SS.GW.showPoints) {
|
||||||
datumColor = 'S'; // shown
|
datumColor = 'S'; // shown
|
||||||
} else if(!(SS.GW.show2dCsyss || SS.GW.showAxes || SS.GW.showPoints)) {
|
} else if(!(SS.GW.showWorkplanes || SS.GW.showAxes || SS.GW.showPoints)) {
|
||||||
datumColor = 'H'; // hidden
|
datumColor = 'H'; // hidden
|
||||||
} else {
|
} else {
|
||||||
datumColor = 'M'; // mixed
|
datumColor = 'M'; // mixed
|
||||||
@ -227,13 +227,13 @@ void TextWindow::ShowHeader(void) {
|
|||||||
|
|
||||||
#define hs(b) ((b) ? 'S' : 'H')
|
#define hs(b) ((b) ? 'S' : 'H')
|
||||||
Printf("%CTshow: "
|
Printf("%CTshow: "
|
||||||
"%Cp%Ll%D%f2d-csys%E%CT "
|
"%Cp%Ll%D%fworkplane%E%CT "
|
||||||
"%Cp%Ll%D%faxes%E%CT "
|
"%Cp%Ll%D%faxes%E%CT "
|
||||||
"%Cp%Ll%D%fpoints%E%CT "
|
"%Cp%Ll%D%fpoints%E%CT "
|
||||||
"%Cp%Ll%fany-datum%E%CT",
|
"%Cp%Ll%fany-datum%E%CT",
|
||||||
hs(SS.GW.show2dCsyss), (DWORD)&(SS.GW.show2dCsyss), &(SS.GW.ToggleBool),
|
hs(SS.GW.showWorkplanes), (DWORD)&(SS.GW.showWorkplanes), &(SS.GW.ToggleBool),
|
||||||
hs(SS.GW.showAxes), (DWORD)&(SS.GW.showAxes), &(SS.GW.ToggleBool),
|
hs(SS.GW.showAxes), (DWORD)&(SS.GW.showAxes), &(SS.GW.ToggleBool),
|
||||||
hs(SS.GW.showPoints), (DWORD)&(SS.GW.showPoints), &(SS.GW.ToggleBool),
|
hs(SS.GW.showPoints), (DWORD)&(SS.GW.showPoints), &(SS.GW.ToggleBool),
|
||||||
datumColor, &(SS.GW.ToggleAnyDatumShown)
|
datumColor, &(SS.GW.ToggleAnyDatumShown)
|
||||||
);
|
);
|
||||||
Printf("%CT "
|
Printf("%CT "
|
||||||
@ -302,7 +302,7 @@ void TextWindow::ShowRequestInfo(void) {
|
|||||||
|
|
||||||
char *s;
|
char *s;
|
||||||
switch(r->type) {
|
switch(r->type) {
|
||||||
case Request::CSYS_2D: s = "2d coordinate system"; break;
|
case Request::WORKPLANE: s = "workplane"; break;
|
||||||
case Request::DATUM_POINT: s = "datum point"; break;
|
case Request::DATUM_POINT: s = "datum point"; break;
|
||||||
case Request::LINE_SEGMENT: s = "line segment"; break;
|
case Request::LINE_SEGMENT: s = "line segment"; break;
|
||||||
default: oops();
|
default: oops();
|
||||||
|
10
ui.h
10
ui.h
@ -93,8 +93,8 @@ public:
|
|||||||
// Edit
|
// Edit
|
||||||
MNU_DELETE,
|
MNU_DELETE,
|
||||||
// Request
|
// Request
|
||||||
MNU_SEL_CSYS,
|
MNU_SEL_WORKPLANE,
|
||||||
MNU_NO_CSYS,
|
MNU_FREE_IN_3D,
|
||||||
MNU_DATUM_POINT,
|
MNU_DATUM_POINT,
|
||||||
MNU_LINE_SEGMENT,
|
MNU_LINE_SEGMENT,
|
||||||
MNU_RECTANGLE,
|
MNU_RECTANGLE,
|
||||||
@ -147,7 +147,7 @@ public:
|
|||||||
Unit viewUnits;
|
Unit viewUnits;
|
||||||
|
|
||||||
hGroup activeGroup;
|
hGroup activeGroup;
|
||||||
hEntity activeCsys;
|
hEntity activeWorkplane;
|
||||||
void EnsureValidActives();
|
void EnsureValidActives();
|
||||||
|
|
||||||
// Operations that must be completed by doing something with the mouse
|
// Operations that must be completed by doing something with the mouse
|
||||||
@ -188,7 +188,7 @@ public:
|
|||||||
hEntity entity[MAX_SELECTED];
|
hEntity entity[MAX_SELECTED];
|
||||||
int points;
|
int points;
|
||||||
int entities;
|
int entities;
|
||||||
int csyss;
|
int workplanes;
|
||||||
int planes;
|
int planes;
|
||||||
int lineSegments;
|
int lineSegments;
|
||||||
int n;
|
int n;
|
||||||
@ -196,7 +196,7 @@ public:
|
|||||||
void GroupSelection(void);
|
void GroupSelection(void);
|
||||||
|
|
||||||
// This sets what gets displayed.
|
// This sets what gets displayed.
|
||||||
bool show2dCsyss;
|
bool showWorkplanes;
|
||||||
bool showAxes;
|
bool showAxes;
|
||||||
bool showPoints;
|
bool showPoints;
|
||||||
bool showAllGroups;
|
bool showAllGroups;
|
||||||
|
Loading…
Reference in New Issue
Block a user