2008-04-01 10:48:44 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2008-04-27 03:26:27 +00:00
|
|
|
const hEntity Entity::FREE_IN_3D = { 0 };
|
2008-05-08 07:30:30 +00:00
|
|
|
const hEntity Entity::NO_ENTITY = { 0 };
|
2008-05-11 06:09:46 +00:00
|
|
|
const hParam Param::NO_PARAM = { 0 };
|
|
|
|
#define NO_PARAM (Param::NO_PARAM)
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
const hGroup Group::HGROUP_REFERENCES = { 1 };
|
|
|
|
const hRequest Request::HREQUEST_REFERENCE_XY = { 1 };
|
|
|
|
const hRequest Request::HREQUEST_REFERENCE_YZ = { 2 };
|
|
|
|
const hRequest Request::HREQUEST_REFERENCE_ZX = { 3 };
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
void Group::AddParam(IdList<Param,hParam> *param, hParam hp, double v) {
|
|
|
|
Param pa;
|
|
|
|
memset(&pa, 0, sizeof(pa));
|
|
|
|
pa.h = hp;
|
|
|
|
pa.val = v;
|
|
|
|
|
|
|
|
param->Add(&pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::MenuGroup(int id) {
|
|
|
|
Group g;
|
|
|
|
memset(&g, 0, sizeof(g));
|
|
|
|
g.visible = true;
|
|
|
|
|
|
|
|
switch(id) {
|
2008-05-11 02:57:47 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_3D:
|
2008-04-27 09:03:01 +00:00
|
|
|
g.type = DRAWING;
|
2008-05-11 06:09:46 +00:00
|
|
|
g.name.strcpy("draw-in-3d");
|
2008-04-27 09:03:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_GROUP_EXTRUDE:
|
|
|
|
g.type = EXTRUDE;
|
2008-05-11 06:09:46 +00:00
|
|
|
g.opA = SS.GW.activeGroup;
|
2008-04-27 09:03:01 +00:00
|
|
|
g.name.strcpy("extrude");
|
|
|
|
break;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_ROT:
|
|
|
|
g.type = ROTATE;
|
|
|
|
g.opA = SS.GW.activeGroup;
|
|
|
|
g.name.strcpy("rotate");
|
|
|
|
break;
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
|
|
|
|
SS.group.AddAndAssignId(&g);
|
|
|
|
SS.GenerateAll(SS.GW.solving == GraphicsWindow::SOLVE_ALWAYS);
|
|
|
|
SS.GW.activeGroup = g.h;
|
|
|
|
SS.TW.Show();
|
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
char *Group::DescriptionString(void) {
|
|
|
|
static char ret[100];
|
|
|
|
if(name.str[0]) {
|
2008-04-28 07:18:39 +00:00
|
|
|
sprintf(ret, "g%03x-%s", h.v, name.str);
|
2008-04-12 14:12:26 +00:00
|
|
|
} else {
|
2008-04-28 07:18:39 +00:00
|
|
|
sprintf(ret, "g%03x-(unnamed)", h.v);
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
void Group::Generate(IdList<Entity,hEntity> *entity,
|
|
|
|
IdList<Param,hParam> *param)
|
|
|
|
{
|
2008-05-07 04:17:29 +00:00
|
|
|
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
|
|
|
|
gn = gn.WithMagnitude(200/SS.GW.scale);
|
2008-04-27 09:03:01 +00:00
|
|
|
int i;
|
|
|
|
switch(type) {
|
|
|
|
case DRAWING:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case EXTRUDE:
|
2008-05-07 04:17:29 +00:00
|
|
|
AddParam(param, h.param(0), gn.x);
|
|
|
|
AddParam(param, h.param(1), gn.y);
|
|
|
|
AddParam(param, h.param(2), gn.z);
|
2008-04-27 09:03:01 +00:00
|
|
|
for(i = 0; i < entity->n; i++) {
|
|
|
|
Entity *e = &(entity->elem[i]);
|
|
|
|
if(e->group.v != opA.v) continue;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
CopyEntity(e->h, 0,
|
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM,
|
|
|
|
true, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ROTATE:
|
|
|
|
// The translation vector
|
|
|
|
AddParam(param, h.param(0), 100);
|
|
|
|
AddParam(param, h.param(1), 100);
|
|
|
|
AddParam(param, h.param(2), 100);
|
|
|
|
// The rotation quaternion
|
|
|
|
AddParam(param, h.param(3), 1);
|
|
|
|
AddParam(param, h.param(4), 0);
|
|
|
|
AddParam(param, h.param(5), 0);
|
|
|
|
AddParam(param, h.param(6), 0);
|
|
|
|
|
|
|
|
for(i = 0; i < entity->n; i++) {
|
|
|
|
Entity *e = &(entity->elem[i]);
|
|
|
|
if(e->group.v != opA.v) continue;
|
|
|
|
|
|
|
|
CopyEntity(e->h, 0,
|
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
h.param(3), h.param(4), h.param(5), h.param(6),
|
|
|
|
false, false);
|
2008-04-27 09:03:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
|
|
|
|
if(type == ROTATE) {
|
|
|
|
// Normalize the quaternion
|
|
|
|
ExprQuaternion q = {
|
|
|
|
Expr::FromParam(h.param(3)),
|
|
|
|
Expr::FromParam(h.param(4)),
|
|
|
|
Expr::FromParam(h.param(5)),
|
|
|
|
Expr::FromParam(h.param(6)) };
|
|
|
|
Equation eq;
|
|
|
|
eq.e = (q.Magnitude())->Minus(Expr::FromConstant(1));
|
|
|
|
eq.h = h.equation(0);
|
|
|
|
l->Add(&eq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
hEntity Group::Remap(hEntity in, int copyNumber) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < remap.n; i++) {
|
|
|
|
EntityMap *em = &(remap.elem[i]);
|
|
|
|
if(em->input.v == in.v && em->copyNumber == copyNumber) {
|
|
|
|
// We already have a mapping for this entity.
|
|
|
|
return h.entity(em->h.v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We don't have a mapping yet, so create one.
|
|
|
|
EntityMap em;
|
|
|
|
em.input = in;
|
|
|
|
em.copyNumber = copyNumber;
|
|
|
|
remap.AddAndAssignId(&em);
|
|
|
|
return h.entity(em.h.v);
|
|
|
|
}
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
void Group::CopyEntity(hEntity in, int a, hParam dx, hParam dy, hParam dz,
|
2008-05-11 06:09:46 +00:00
|
|
|
hParam qw, hParam qvx, hParam qvy, hParam qvz,
|
|
|
|
bool transOnly, bool isExtrusion)
|
2008-05-05 06:18:01 +00:00
|
|
|
{
|
2008-04-27 09:03:01 +00:00
|
|
|
Entity *ep = SS.GetEntity(in);
|
|
|
|
|
|
|
|
Entity en;
|
|
|
|
memset(&en, 0, sizeof(en));
|
|
|
|
en.type = ep->type;
|
|
|
|
en.h = Remap(ep->h, a);
|
|
|
|
en.group = h;
|
|
|
|
|
|
|
|
switch(ep->type) {
|
|
|
|
case Entity::WORKPLANE:
|
|
|
|
// Don't copy these.
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Entity::LINE_SEGMENT:
|
|
|
|
en.point[0] = Remap(ep->point[0], a);
|
|
|
|
en.point[1] = Remap(ep->point[1], a);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Entity::CUBIC:
|
|
|
|
en.point[0] = Remap(ep->point[0], a);
|
|
|
|
en.point[1] = Remap(ep->point[1], a);
|
|
|
|
en.point[2] = Remap(ep->point[2], a);
|
|
|
|
en.point[3] = Remap(ep->point[3], a);
|
|
|
|
break;
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case Entity::CIRCLE:
|
|
|
|
en.point[0] = Remap(ep->point[0], a);
|
|
|
|
en.normal = Remap(ep->normal, a);
|
2008-05-07 08:19:37 +00:00
|
|
|
en.distance = Remap(ep->distance, a);
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
case Entity::POINT_N_TRANS:
|
|
|
|
case Entity::POINT_N_ROT_TRANS:
|
2008-04-27 09:03:01 +00:00
|
|
|
case Entity::POINT_IN_3D:
|
|
|
|
case Entity::POINT_IN_2D:
|
2008-05-11 06:09:46 +00:00
|
|
|
if(transOnly) {
|
|
|
|
en.type = Entity::POINT_N_TRANS;
|
|
|
|
en.param[0] = dx;
|
|
|
|
en.param[1] = dy;
|
|
|
|
en.param[2] = dz;
|
|
|
|
en.numPoint = ep->PointGetNum();
|
|
|
|
} else {
|
|
|
|
en.type = Entity::POINT_N_ROT_TRANS;
|
|
|
|
en.param[0] = dx;
|
|
|
|
en.param[1] = dy;
|
|
|
|
en.param[2] = dz;
|
|
|
|
en.param[3] = qw;
|
|
|
|
en.param[4] = qvx;
|
|
|
|
en.param[5] = qvy;
|
|
|
|
en.param[6] = qvz;
|
|
|
|
en.numPoint = ep->PointGetNum();
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
|
|
|
|
if(isExtrusion) {
|
|
|
|
if(a != 0) oops();
|
|
|
|
SS.entity.Add(&en);
|
2008-05-07 04:17:29 +00:00
|
|
|
|
|
|
|
hEntity np = en.h;
|
|
|
|
memset(&en, 0, sizeof(en));
|
2008-05-05 06:18:01 +00:00
|
|
|
en.point[0] = ep->h;
|
2008-05-07 04:17:29 +00:00
|
|
|
en.point[1] = np;
|
|
|
|
en.group = h;
|
2008-05-05 06:18:01 +00:00
|
|
|
en.h = Remap(ep->h, 1);
|
|
|
|
en.type = Entity::LINE_SEGMENT;
|
|
|
|
// And then this line segment gets added
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
case Entity::NORMAL_N_COPY:
|
|
|
|
case Entity::NORMAL_N_ROT:
|
2008-05-05 06:18:01 +00:00
|
|
|
case Entity::NORMAL_IN_3D:
|
|
|
|
case Entity::NORMAL_IN_2D:
|
2008-05-11 06:09:46 +00:00
|
|
|
if(transOnly) {
|
|
|
|
en.type = Entity::NORMAL_N_COPY;
|
|
|
|
en.numNormal = ep->NormalGetNum();
|
|
|
|
} else {
|
|
|
|
en.type = Entity::NORMAL_N_ROT;
|
|
|
|
en.numNormal = ep->NormalGetNum();
|
|
|
|
en.param[0] = qw;
|
|
|
|
en.param[1] = qvx;
|
|
|
|
en.param[2] = qvy;
|
|
|
|
en.param[3] = qvz;
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
en.point[0] = Remap(ep->point[0], a);
|
2008-04-27 09:03:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
case Entity::DISTANCE_N_COPY:
|
2008-05-07 08:19:37 +00:00
|
|
|
case Entity::DISTANCE:
|
2008-05-11 06:09:46 +00:00
|
|
|
en.type = Entity::DISTANCE_N_COPY;
|
2008-05-07 08:19:37 +00:00
|
|
|
en.numDistance = ep->DistanceGetNum();
|
|
|
|
break;
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
default:
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
SS.entity.Add(&en);
|
|
|
|
}
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
void Group::MakePolygons(void) {
|
2008-05-07 04:17:29 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < faces.n; i++) {
|
|
|
|
(faces.elem[i]).Clear();
|
|
|
|
}
|
2008-05-02 10:54:22 +00:00
|
|
|
faces.Clear();
|
|
|
|
if(type == DRAWING) {
|
|
|
|
edges.l.Clear();
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
|
|
|
Entity *e = &(SS.entity.elem[i]);
|
|
|
|
if(e->group.v != h.v) continue;
|
2008-04-28 07:18:39 +00:00
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
e->GenerateEdges(&edges);
|
|
|
|
}
|
|
|
|
SPolygon poly;
|
|
|
|
memset(&poly, 0, sizeof(poly));
|
|
|
|
SEdge error;
|
|
|
|
if(edges.AssemblePolygon(&poly, &error)) {
|
|
|
|
polyError.yes = false;
|
2008-05-05 09:47:23 +00:00
|
|
|
poly.normal = poly.ComputeNormal();
|
2008-05-02 10:54:22 +00:00
|
|
|
faces.Add(&poly);
|
|
|
|
} else {
|
|
|
|
polyError.yes = true;
|
|
|
|
polyError.notClosedAt = error;
|
|
|
|
poly.Clear();
|
|
|
|
}
|
|
|
|
} else if(type == EXTRUDE) {
|
|
|
|
Vector translate;
|
|
|
|
translate.x = SS.GetParam(h.param(0))->val;
|
|
|
|
translate.y = SS.GetParam(h.param(1))->val;
|
|
|
|
translate.z = SS.GetParam(h.param(2))->val;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
edges.l.Clear();
|
|
|
|
Group *src = SS.GetGroup(opA);
|
|
|
|
if(src->faces.n != 1) return;
|
|
|
|
|
|
|
|
(src->faces.elem[0]).MakeEdgesInto(&edges);
|
|
|
|
|
|
|
|
SPolygon poly;
|
|
|
|
SEdge error;
|
|
|
|
|
|
|
|
// The bottom
|
|
|
|
memset(&poly, 0, sizeof(poly));
|
|
|
|
if(!edges.AssemblePolygon(&poly, &error)) oops();
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector n = poly.ComputeNormal();
|
|
|
|
if(translate.Dot(n) > 0) {
|
|
|
|
n = n.ScaledBy(-1);
|
|
|
|
}
|
|
|
|
poly.normal = n;
|
|
|
|
poly.FixContourDirections();
|
|
|
|
poly.FixContourDirections();
|
2008-05-02 10:54:22 +00:00
|
|
|
faces.Add(&poly);
|
|
|
|
|
2008-05-05 09:47:23 +00:00
|
|
|
// Regenerate the edges, with the contour directions fixed up.
|
|
|
|
edges.l.Clear();
|
|
|
|
poly.MakeEdgesInto(&edges);
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
// The sides
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < edges.l.n; i++) {
|
|
|
|
SEdge *edge = &(edges.l.elem[i]);
|
|
|
|
memset(&poly, 0, sizeof(poly));
|
|
|
|
poly.AddEmptyContour();
|
|
|
|
poly.AddPoint(edge->a);
|
|
|
|
poly.AddPoint(edge->b);
|
|
|
|
poly.AddPoint((edge->b).Plus(translate));
|
|
|
|
poly.AddPoint((edge->a).Plus(translate));
|
|
|
|
poly.AddPoint(edge->a);
|
2008-05-05 09:47:23 +00:00
|
|
|
poly.normal = ((edge->a).Minus(edge->b).Cross(n)).WithMagnitude(1);
|
2008-05-02 10:54:22 +00:00
|
|
|
faces.Add(&poly);
|
2008-05-05 09:47:23 +00:00
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
edge->a = (edge->a).Plus(translate);
|
|
|
|
edge->b = (edge->b).Plus(translate);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The top
|
|
|
|
memset(&poly, 0, sizeof(poly));
|
|
|
|
if(!edges.AssemblePolygon(&poly, &error)) oops();
|
2008-05-05 09:47:23 +00:00
|
|
|
poly.normal = n.ScaledBy(-1);
|
2008-05-02 10:54:22 +00:00
|
|
|
faces.Add(&poly);
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
2008-05-02 10:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::Draw(void) {
|
|
|
|
if(!visible) return;
|
|
|
|
|
|
|
|
if(polyError.yes) {
|
2008-04-25 08:26:15 +00:00
|
|
|
glxColor4d(1, 0, 0, 0.2);
|
2008-04-25 07:04:09 +00:00
|
|
|
glLineWidth(10);
|
|
|
|
glBegin(GL_LINES);
|
2008-05-02 10:54:22 +00:00
|
|
|
glxVertex3v(polyError.notClosedAt.a);
|
|
|
|
glxVertex3v(polyError.notClosedAt.b);
|
2008-04-25 07:04:09 +00:00
|
|
|
glEnd();
|
|
|
|
glLineWidth(1);
|
2008-04-25 08:26:15 +00:00
|
|
|
glxColor3d(1, 0, 0);
|
|
|
|
glPushMatrix();
|
2008-05-02 10:54:22 +00:00
|
|
|
glxTranslatev(polyError.notClosedAt.b);
|
2008-04-27 03:26:27 +00:00
|
|
|
glxOntoWorkplane(SS.GW.projRight, SS.GW.projUp);
|
2008-04-25 08:26:15 +00:00
|
|
|
glxWriteText("not closed contour!");
|
|
|
|
glPopMatrix();
|
2008-05-02 10:54:22 +00:00
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
GLfloat vec[] = { 0, 0, 0.5, 1.0 };
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, vec);
|
|
|
|
for(i = 0; i < faces.n; i++) {
|
|
|
|
glxFillPolygon(&(faces.elem[i]));
|
2008-05-05 09:47:23 +00:00
|
|
|
#if 0
|
|
|
|
// Debug stuff to show normals to the faces on-screen
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glxMarkPolygonNormal(&(faces.elem[i]));
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
#endif
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
}
|
|
|
|
glDisable(GL_LIGHTING);
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
hParam Request::AddParam(IdList<Param,hParam> *param, hParam hp) {
|
2008-04-09 08:39:01 +00:00
|
|
|
Param pa;
|
|
|
|
memset(&pa, 0, sizeof(pa));
|
2008-04-19 11:09:47 +00:00
|
|
|
pa.h = hp;
|
2008-04-12 16:28:48 +00:00
|
|
|
param->Add(&pa);
|
2008-04-19 11:09:47 +00:00
|
|
|
return hp;
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
void Request::Generate(IdList<Entity,hEntity> *entity,
|
|
|
|
IdList<Param,hParam> *param)
|
|
|
|
{
|
2008-04-09 08:39:01 +00:00
|
|
|
int points = 0;
|
|
|
|
int params = 0;
|
2008-04-13 10:57:41 +00:00
|
|
|
int et = 0;
|
2008-05-05 06:18:01 +00:00
|
|
|
bool hasNormal = false;
|
2008-05-07 08:19:37 +00:00
|
|
|
bool hasDistance = false;
|
2008-04-09 08:39:01 +00:00
|
|
|
int i;
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
Entity e;
|
|
|
|
memset(&e, 0, sizeof(e));
|
|
|
|
switch(type) {
|
2008-04-27 03:26:27 +00:00
|
|
|
case Request::WORKPLANE:
|
2008-05-05 06:18:01 +00:00
|
|
|
et = Entity::WORKPLANE;
|
|
|
|
points = 1;
|
|
|
|
hasNormal = true;
|
|
|
|
break;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
case Request::DATUM_POINT:
|
2008-05-05 06:18:01 +00:00
|
|
|
et = 0;
|
|
|
|
points = 1;
|
|
|
|
break;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
case Request::LINE_SEGMENT:
|
2008-05-05 06:18:01 +00:00
|
|
|
et = Entity::LINE_SEGMENT;
|
|
|
|
points = 2;
|
|
|
|
break;
|
2008-04-25 12:07:17 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case Request::CIRCLE:
|
|
|
|
et = Entity::CIRCLE;
|
|
|
|
points = 1;
|
|
|
|
params = 1;
|
|
|
|
hasNormal = true;
|
2008-05-07 08:19:37 +00:00
|
|
|
hasDistance = true;
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
2008-04-19 11:09:47 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case Request::CUBIC:
|
|
|
|
et = Entity::CUBIC;
|
|
|
|
points = 4;
|
2008-04-08 12:54:53 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
default: oops();
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
|
|
|
|
// Generate the entity that's specific to this request.
|
|
|
|
e.type = et;
|
|
|
|
e.group = group;
|
|
|
|
e.workplane = workplane;
|
2008-05-07 04:17:29 +00:00
|
|
|
e.construction = construction;
|
2008-05-05 06:18:01 +00:00
|
|
|
e.h = h.entity(0);
|
|
|
|
|
|
|
|
// And generate entities for the points
|
|
|
|
for(i = 0; i < points; i++) {
|
|
|
|
Entity p;
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
p.workplane = workplane;
|
|
|
|
// points start from entity 1, except for datum point case
|
|
|
|
p.h = h.entity(i+(et ? 1 : 0));
|
|
|
|
p.group = group;
|
|
|
|
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
p.type = Entity::POINT_IN_3D;
|
|
|
|
// params for x y z
|
|
|
|
p.param[0] = AddParam(param, h.param(16 + 3*i + 0));
|
|
|
|
p.param[1] = AddParam(param, h.param(16 + 3*i + 1));
|
|
|
|
p.param[2] = AddParam(param, h.param(16 + 3*i + 2));
|
|
|
|
} else {
|
|
|
|
p.type = Entity::POINT_IN_2D;
|
|
|
|
// params for u v
|
|
|
|
p.param[0] = AddParam(param, h.param(16 + 3*i + 0));
|
|
|
|
p.param[1] = AddParam(param, h.param(16 + 3*i + 1));
|
|
|
|
}
|
|
|
|
entity->Add(&p);
|
|
|
|
e.point[i] = p.h;
|
|
|
|
}
|
|
|
|
if(hasNormal) {
|
|
|
|
Entity n;
|
|
|
|
memset(&n, 0, sizeof(n));
|
|
|
|
n.workplane = workplane;
|
2008-05-07 08:19:37 +00:00
|
|
|
n.h = h.entity(32);
|
2008-05-05 06:18:01 +00:00
|
|
|
n.group = group;
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
n.type = Entity::NORMAL_IN_3D;
|
|
|
|
n.param[0] = AddParam(param, h.param(32+0));
|
|
|
|
n.param[1] = AddParam(param, h.param(32+1));
|
|
|
|
n.param[2] = AddParam(param, h.param(32+2));
|
|
|
|
n.param[3] = AddParam(param, h.param(32+3));
|
|
|
|
} else {
|
|
|
|
n.type = Entity::NORMAL_IN_2D;
|
|
|
|
// and this is just a copy of the workplane quaternion,
|
|
|
|
// so no params required
|
|
|
|
}
|
|
|
|
if(points < 1) oops();
|
|
|
|
// The point determines where the normal gets displayed on-screen;
|
|
|
|
// it's entirely cosmetic.
|
|
|
|
n.point[0] = e.point[0];
|
|
|
|
entity->Add(&n);
|
|
|
|
e.normal = n.h;
|
|
|
|
}
|
2008-05-07 08:19:37 +00:00
|
|
|
if(hasDistance) {
|
|
|
|
Entity d;
|
|
|
|
memset(&d, 0, sizeof(d));
|
|
|
|
d.workplane = workplane;
|
|
|
|
d.h = h.entity(64);
|
|
|
|
d.group = group;
|
|
|
|
d.type = Entity::DISTANCE;
|
|
|
|
d.param[0] = AddParam(param, h.param(64));
|
|
|
|
entity->Add(&d);
|
|
|
|
e.distance = d.h;
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
// And generate any params not associated with the point that
|
|
|
|
// we happen to need.
|
|
|
|
for(i = 0; i < params; i++) {
|
|
|
|
e.param[i] = AddParam(param, h.param(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(et) entity->Add(&e);
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
char *Request::DescriptionString(void) {
|
|
|
|
static char ret[100];
|
|
|
|
if(name.str[0]) {
|
|
|
|
sprintf(ret, "r%03x-%s", h.v, name.str);
|
|
|
|
} else {
|
|
|
|
sprintf(ret, "r%03x-(unnamed)", h.v);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|