2008-04-01 10:48:44 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
const hEntity Entity::NO_CSYS = { 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-12 14:12:26 +00:00
|
|
|
char *Group::DescriptionString(void) {
|
|
|
|
static char ret[100];
|
|
|
|
if(name.str[0]) {
|
2008-04-13 10:57:41 +00:00
|
|
|
sprintf(ret, "g%04x-%s", h.v, name.str);
|
2008-04-12 14:12:26 +00:00
|
|
|
} else {
|
2008-04-13 10:57:41 +00:00
|
|
|
sprintf(ret, "g%04x-(unnamed)", h.v);
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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-09 08:39:01 +00:00
|
|
|
case Request::CSYS_2D:
|
2008-04-13 10:57:41 +00:00
|
|
|
et = Entity::CSYS_2D; points = 1; params = 4; goto c;
|
|
|
|
|
|
|
|
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-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;
|
|
|
|
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));
|
|
|
|
p.csys = csys;
|
|
|
|
// points start from entity 1, except for datum point case
|
|
|
|
p.h = h.entity(i+(et ? 1 : 0));
|
|
|
|
p.symbolic = true;
|
2008-04-18 07:06:37 +00:00
|
|
|
if(csys.v == Entity::NO_CSYS.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-19 11:09:47 +00:00
|
|
|
p.param.h[0] = AddParam(param, h.param(16 + 3*i + 0));
|
|
|
|
p.param.h[1] = AddParam(param, h.param(16 + 3*i + 1));
|
|
|
|
p.param.h[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-19 11:09:47 +00:00
|
|
|
p.param.h[0] = AddParam(param, h.param(16 + 3*i + 0));
|
|
|
|
p.param.h[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);
|
|
|
|
e.assoc[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++) {
|
|
|
|
e.param.h[i] = AddParam(param, h.param(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|