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-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) {
|
|
|
|
case GraphicsWindow::MNU_GROUP_DRAWING:
|
|
|
|
g.type = DRAWING;
|
|
|
|
g.name.strcpy("drawing");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GraphicsWindow::MNU_GROUP_EXTRUDE:
|
|
|
|
g.type = EXTRUDE;
|
|
|
|
g.opA.v = 2;
|
|
|
|
g.name.strcpy("extrude");
|
|
|
|
break;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
switch(type) {
|
|
|
|
case DRAWING:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case EXTRUDE:
|
|
|
|
AddParam(param, h.param(0), 50);
|
|
|
|
AddParam(param, h.param(1), 50);
|
|
|
|
AddParam(param, h.param(2), 50);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::CopyEntity(hEntity in, int a, hParam dx, hParam dy, hParam dz) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
case Entity::POINT_IN_3D:
|
|
|
|
case Entity::POINT_IN_2D:
|
|
|
|
en.type = Entity::POINT_XFRMD;
|
|
|
|
en.point[0] = ep->h;
|
|
|
|
en.param[0] = dx;
|
|
|
|
en.param[1] = dy;
|
|
|
|
en.param[2] = dz;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
SS.entity.Add(&en);
|
|
|
|
}
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
void Group::Draw(void) {
|
2008-04-28 07:18:39 +00:00
|
|
|
if(!visible) return;
|
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
edges.l.Clear();
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
|
|
|
Entity *e = &(SS.entity.elem[i]);
|
2008-04-27 09:03:01 +00:00
|
|
|
if(e->group.v != h.v) continue;
|
2008-04-25 07:04:09 +00:00
|
|
|
|
|
|
|
e->GenerateEdges(&edges);
|
|
|
|
}
|
|
|
|
SPolygon poly;
|
|
|
|
memset(&poly, 0, sizeof(poly));
|
|
|
|
SEdge error;
|
|
|
|
if(edges.AssemblePolygon(&poly, &error)) {
|
2008-04-25 08:26:15 +00:00
|
|
|
glxColor4d(0, 0, 1, 0.1);
|
2008-04-25 07:04:09 +00:00
|
|
|
glxFillPolygon(&poly);
|
|
|
|
} else {
|
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);
|
|
|
|
glxVertex3v(error.a);
|
|
|
|
glxVertex3v(error.b);
|
|
|
|
glEnd();
|
|
|
|
glLineWidth(1);
|
2008-04-25 08:26:15 +00:00
|
|
|
glxColor3d(1, 0, 0);
|
|
|
|
glPushMatrix();
|
|
|
|
glxTranslatev(error.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-04-25 07:04:09 +00:00
|
|
|
}
|
|
|
|
poly.Clear();
|
|
|
|
}
|
|
|
|
|
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-04-09 08:39:01 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
Group *g = SS.group.FindById(group);
|
|
|
|
|
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:
|
|
|
|
et = Entity::WORKPLANE; points = 1; params = 4; goto c;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
case Request::DATUM_POINT:
|
2008-04-19 11:09:47 +00:00
|
|
|
et = 0; points = 1; params = 0; goto c;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
case Request::LINE_SEGMENT:
|
2008-04-13 10:57:41 +00:00
|
|
|
et = Entity::LINE_SEGMENT; points = 2; params = 0; goto c;
|
2008-04-25 12:07:17 +00:00
|
|
|
|
|
|
|
case Request::CUBIC:
|
|
|
|
et = Entity::CUBIC; points = 4; params = 0; goto c;
|
2008-04-09 08:39:01 +00:00
|
|
|
c: {
|
2008-04-19 11:09:47 +00:00
|
|
|
// Generate the entity that's specific to this request.
|
|
|
|
e.type = et;
|
2008-04-27 09:03:01 +00:00
|
|
|
e.group = group;
|
2008-04-19 11:09:47 +00:00
|
|
|
e.h = h.entity(0);
|
|
|
|
|
|
|
|
// And generate entities for the points
|
2008-04-09 08:39:01 +00:00
|
|
|
for(i = 0; i < points; i++) {
|
2008-04-19 11:09:47 +00:00
|
|
|
Entity p;
|
|
|
|
memset(&p, 0, sizeof(p));
|
2008-04-27 03:26:27 +00:00
|
|
|
p.workplane = workplane;
|
2008-04-19 11:09:47 +00:00
|
|
|
// points start from entity 1, except for datum point case
|
|
|
|
p.h = h.entity(i+(et ? 1 : 0));
|
2008-04-27 09:03:01 +00:00
|
|
|
p.group = group;
|
|
|
|
|
2008-04-27 03:26:27 +00:00
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
2008-04-19 11:09:47 +00:00
|
|
|
p.type = Entity::POINT_IN_3D;
|
2008-04-09 08:39:01 +00:00
|
|
|
// params for x y z
|
2008-04-27 03:26:27 +00:00
|
|
|
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));
|
2008-04-09 08:39:01 +00:00
|
|
|
} else {
|
2008-04-19 11:09:47 +00:00
|
|
|
p.type = Entity::POINT_IN_2D;
|
2008-04-09 08:39:01 +00:00
|
|
|
// params for u v
|
2008-04-27 03:26:27 +00:00
|
|
|
p.param[0] = AddParam(param, h.param(16 + 3*i + 0));
|
|
|
|
p.param[1] = AddParam(param, h.param(16 + 3*i + 1));
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
2008-04-19 11:09:47 +00:00
|
|
|
entity->Add(&p);
|
2008-04-27 03:26:27 +00:00
|
|
|
e.point[i] = p.h;
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
2008-04-19 11:09:47 +00:00
|
|
|
// And generate any params not associated with the point that
|
|
|
|
// we happen to need.
|
|
|
|
for(i = 0; i < params; i++) {
|
2008-04-27 03:26:27 +00:00
|
|
|
e.param[i] = AddParam(param, h.param(i));
|
2008-04-19 11:09:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(et) entity->Add(&e);
|
2008-04-08 12:54:53 +00:00
|
|
|
break;
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
2008-04-08 12:54:53 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|