2008-03-25 10:02:13 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
|
|
|
SolveSpace SS;
|
|
|
|
|
|
|
|
void SolveSpace::Init(void) {
|
2008-04-14 10:28:32 +00:00
|
|
|
constraint.Clear();
|
2008-04-08 12:54:53 +00:00
|
|
|
request.Clear();
|
2008-04-14 10:28:32 +00:00
|
|
|
group.Clear();
|
|
|
|
|
2008-03-28 10:00:37 +00:00
|
|
|
entity.Clear();
|
|
|
|
point.Clear();
|
|
|
|
param.Clear();
|
|
|
|
|
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-13 14:28:35 +00:00
|
|
|
g.csys.v = Request::HREQUEST_REFERENCE_XY.v << 10;
|
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-13 10:57:41 +00:00
|
|
|
TW.Init();
|
|
|
|
GW.Init();
|
|
|
|
|
2008-04-11 12:47:14 +00:00
|
|
|
TW.Show();
|
2008-04-13 10:57:41 +00:00
|
|
|
GenerateAll();
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
void SolveSpace::GenerateAll(void) {
|
2008-03-26 09:18:12 +00:00
|
|
|
int i;
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
IdList<Param,hParam> prev;
|
|
|
|
param.MoveSelfInto(&prev);
|
|
|
|
|
2008-04-08 12:54:53 +00:00
|
|
|
entity.Clear();
|
2008-04-12 16:28:48 +00:00
|
|
|
point.Clear();
|
2008-04-08 12:54:53 +00:00
|
|
|
for(i = 0; i < request.elems; i++) {
|
2008-04-12 16:28:48 +00:00
|
|
|
request.elem[i].t.Generate(&entity, &point, ¶m);
|
2008-03-26 09:18:12 +00:00
|
|
|
}
|
2008-04-08 12:54:53 +00:00
|
|
|
|
2008-04-13 10:57:41 +00:00
|
|
|
for(i = 0; i < param.elems; i++) {
|
|
|
|
Param *p = prev.FindByIdNoOops(param.elem[i].t.h);
|
|
|
|
if(p) {
|
|
|
|
param.elem[i].t.val = p->val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
ForceReferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SolveSpace::ForceReferences(void) {
|
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
|
|
|
};
|
2008-04-12 16:28:48 +00:00
|
|
|
for(int i = 0; i < 3; i++) {
|
2008-04-09 08:39:01 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-12 16:28:48 +00:00
|
|
|
void SolveSpace::Solve(void) {
|
|
|
|
}
|
|
|
|
|