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-12 16:28:48 +00:00
|
|
|
void Request::AddParam(IdList<Param,hParam> *param, Entity *e, int index) {
|
2008-04-09 08:39:01 +00:00
|
|
|
Param pa;
|
|
|
|
memset(&pa, 0, sizeof(pa));
|
|
|
|
pa.h = e->param(index);
|
2008-04-12 16:28:48 +00:00
|
|
|
param->Add(&pa);
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
void Request::Generate(IdList<Entity,hEntity> *entity,
|
|
|
|
IdList<Point,hPoint> *point,
|
|
|
|
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));
|
2008-04-09 08:39:01 +00:00
|
|
|
e.h = this->entity(0);
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
bool shown = true;
|
2008-04-08 12:54:53 +00:00
|
|
|
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:
|
|
|
|
et = Entity::DATUM_POINT; points = 1; params = 0; goto c;
|
|
|
|
|
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: {
|
|
|
|
// Common routines, for all the requests that generate a single
|
|
|
|
// entity that's defined by a simple combination of pts and params.
|
|
|
|
for(i = 0; i < params; i++) {
|
2008-04-12 16:28:48 +00:00
|
|
|
AddParam(param, &e, i);
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
|
|
|
for(i = 0; i < points; i++) {
|
|
|
|
Point pt;
|
|
|
|
memset(&pt, 0, sizeof(pt));
|
|
|
|
pt.h = e.point(16 + 3*i);
|
|
|
|
if(g->csys.v == Entity::NO_CSYS.v) {
|
|
|
|
pt.type = Point::IN_FREE_SPACE;
|
|
|
|
// params for x y z
|
2008-04-12 16:28:48 +00:00
|
|
|
AddParam(param, &e, 16 + 3*i + 0);
|
|
|
|
AddParam(param, &e, 16 + 3*i + 1);
|
|
|
|
AddParam(param, &e, 16 + 3*i + 2);
|
2008-04-09 08:39:01 +00:00
|
|
|
} else {
|
|
|
|
pt.type = Point::IN_2D_CSYS;
|
|
|
|
pt.csys = g->csys;
|
|
|
|
// params for u v
|
2008-04-12 16:28:48 +00:00
|
|
|
AddParam(param, &e, 16 + 3*i + 0);
|
|
|
|
AddParam(param, &e, 16 + 3*i + 1);
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
2008-04-12 16:28:48 +00:00
|
|
|
point->Add(&pt);
|
2008-04-09 08:39:01 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
e.type = et;
|
2008-04-12 16:28:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
void Param::ForceTo(double v) {
|
|
|
|
val = v;
|
|
|
|
known = true;
|
|
|
|
}
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
void Point::ForceTo(Vector p) {
|
2008-04-08 12:54:53 +00:00
|
|
|
switch(type) {
|
2008-04-09 08:39:01 +00:00
|
|
|
case IN_FREE_SPACE:
|
2008-04-13 14:28:35 +00:00
|
|
|
SS.GetParam(param(0))->ForceTo(p.x);
|
|
|
|
SS.GetParam(param(1))->ForceTo(p.y);
|
|
|
|
SS.GetParam(param(2))->ForceTo(p.z);
|
2008-04-09 08:39:01 +00:00
|
|
|
break;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
case IN_2D_CSYS: {
|
|
|
|
Entity *c = SS.GetEntity(csys);
|
|
|
|
Vector u, v;
|
|
|
|
c->Get2dCsysBasisVectors(&u, &v);
|
|
|
|
SS.GetParam(param(0))->ForceTo(p.Dot(u));
|
|
|
|
SS.GetParam(param(1))->ForceTo(p.Dot(v));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
default:
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
Vector Point::GetCoords(void) {
|
2008-04-13 14:28:35 +00:00
|
|
|
Vector p;
|
2008-04-09 08:39:01 +00:00
|
|
|
switch(type) {
|
|
|
|
case IN_FREE_SPACE:
|
2008-04-13 14:28:35 +00:00
|
|
|
p.x = SS.GetParam(param(0))->val;
|
|
|
|
p.y = SS.GetParam(param(1))->val;
|
|
|
|
p.z = SS.GetParam(param(2))->val;
|
2008-04-08 12:54:53 +00:00
|
|
|
break;
|
2008-04-09 08:39:01 +00:00
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
case IN_2D_CSYS: {
|
|
|
|
Entity *c = SS.GetEntity(csys);
|
|
|
|
Vector u, v;
|
|
|
|
c->Get2dCsysBasisVectors(&u, &v);
|
|
|
|
p = u.ScaledBy(SS.GetParam(param(0))->val);
|
|
|
|
p = p.Plus(v.ScaledBy(SS.GetParam(param(1))->val));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
default:
|
|
|
|
oops();
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
|
2008-04-13 14:28:35 +00:00
|
|
|
return p;
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Point::Draw(void) {
|
|
|
|
Vector v = GetCoords();
|
|
|
|
|
|
|
|
double s = 4;
|
|
|
|
Vector r = SS.GW.projRight.ScaledBy(4/SS.GW.scale);
|
2008-04-12 15:17:58 +00:00
|
|
|
Vector d = SS.GW.projUp.ScaledBy(4/SS.GW.scale);
|
2008-04-12 14:12:26 +00:00
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glxVertex3v(v.Plus (r).Plus (d));
|
|
|
|
glxVertex3v(v.Plus (r).Minus(d));
|
|
|
|
glxVertex3v(v.Minus(r).Minus(d));
|
|
|
|
glxVertex3v(v.Minus(r).Plus (d));
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
double Point::GetDistance(Point2d mp) {
|
|
|
|
Vector v = GetCoords();
|
|
|
|
Point2d pp = SS.GW.ProjectPoint(v);
|
|
|
|
|
|
|
|
return pp.DistanceTo(mp);
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
2008-04-09 08:39:01 +00:00
|
|
|
|