2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
template IdList<Request,hRequest>;
|
|
|
|
template IdList<Entity,hEntity>;
|
|
|
|
template IdList<Point,hPoint>;
|
|
|
|
|
2008-03-25 10:02:13 +00:00
|
|
|
SolveSpace SS;
|
|
|
|
|
|
|
|
void SolveSpace::Init(void) {
|
|
|
|
TW.Init();
|
2008-03-27 09:53:51 +00:00
|
|
|
GW.Init();
|
2008-03-25 10:02:13 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
request.Clear();
|
2008-03-28 10:00:37 +00:00
|
|
|
entity.Clear();
|
|
|
|
point.Clear();
|
|
|
|
param.Clear();
|
2008-04-08 12:54:53 +00:00
|
|
|
group.Clear();
|
2008-03-28 10:00:37 +00:00
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
// Our initial group, that contains the references.
|
|
|
|
Group g;
|
|
|
|
memset(&g, 0, sizeof(g));
|
2008-04-09 08:39:01 +00:00
|
|
|
g.csys = Entity::NO_CSYS;
|
2008-04-11 12:47:14 +00:00
|
|
|
g.name.strcpy("#references");
|
2008-04-09 08:39:01 +00:00
|
|
|
g.h = Group::HGROUP_REFERENCES;
|
|
|
|
group.Add(&g);
|
2008-04-01 10:48:44 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
g.csys = Entity::NO_CSYS;
|
2008-04-08 12:54:53 +00:00
|
|
|
g.name.strcpy("");
|
|
|
|
group.AddAndAssignId(&g);
|
|
|
|
|
|
|
|
|
|
|
|
// Let's create three two-d coordinate systems, for the coordinate
|
|
|
|
// planes; these are our references, present in every sketch.
|
|
|
|
Request r;
|
|
|
|
memset(&r, 0, sizeof(r));
|
2008-04-09 08:39:01 +00:00
|
|
|
r.type = Request::CSYS_2D;
|
2008-04-08 12:54:53 +00:00
|
|
|
r.group = Group::HGROUP_REFERENCES;
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
r.name.strcpy("#XY-csys");
|
2008-04-09 08:39:01 +00:00
|
|
|
r.h = Request::HREQUEST_REFERENCE_XY;
|
|
|
|
request.Add(&r);
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
r.name.strcpy("#YZ-csys");
|
2008-04-09 08:39:01 +00:00
|
|
|
r.h = Request::HREQUEST_REFERENCE_YZ;
|
|
|
|
request.Add(&r);
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
r.name.strcpy("#ZX-csys");
|
2008-04-09 08:39:01 +00:00
|
|
|
r.h = Request::HREQUEST_REFERENCE_ZX;
|
|
|
|
request.Add(&r);
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
TW.Show();
|
2008-04-08 12:54:53 +00:00
|
|
|
Solve();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SolveSpace::Solve(void) {
|
2008-03-26 09:18:12 +00:00
|
|
|
int i;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
|
|
|
entity.Clear();
|
|
|
|
for(i = 0; i < request.elems; i++) {
|
2008-04-09 08:39:01 +00:00
|
|
|
request.elem[i].t.Generate();
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
// Force the values of the paramters that define the three reference
|
|
|
|
// coordinate systems.
|
|
|
|
static const struct {
|
|
|
|
hRequest hr;
|
|
|
|
double a, b, c, d;
|
|
|
|
} Quat[] = {
|
|
|
|
{ Request::HREQUEST_REFERENCE_XY, 1, 0, 0, 0, },
|
2008-04-11 11:13:47 +00:00
|
|
|
{ Request::HREQUEST_REFERENCE_YZ, 0.5, -0.5, -0.5, -0.5, },
|
|
|
|
{ Request::HREQUEST_REFERENCE_ZX, 0.5, 0.5, 0.5, 0.5, },
|
2008-04-09 08:39:01 +00:00
|
|
|
};
|
|
|
|
for(i = 0; i < 3; i++) {
|
|
|
|
hEntity he;
|
|
|
|
he = request.FindById(Quat[i].hr)->entity(0);
|
|
|
|
Entity *e = entity.FindById(he);
|
|
|
|
// The origin for our coordinate system, always zero
|
|
|
|
Vector v = Vector::MakeFrom(0, 0, 0);
|
|
|
|
point.FindById(e->point(16))->ForceTo(v);
|
|
|
|
// The quaternion that defines the rotation, from the table.
|
|
|
|
param.FindById(e->param(0))->ForceTo(Quat[i].a);
|
|
|
|
param.FindById(e->param(1))->ForceTo(Quat[i].b);
|
|
|
|
param.FindById(e->param(2))->ForceTo(Quat[i].c);
|
|
|
|
param.FindById(e->param(3))->ForceTo(Quat[i].d);
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
2008-03-25 10:02:13 +00:00
|
|
|
}
|
|
|
|
|