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-05-08 07:30:30 +00:00
|
|
|
const hEntity Entity::NO_ENTITY = { 0 };
|
2008-05-11 06:09:46 +00:00
|
|
|
const hParam Param::NO_PARAM = { 0 };
|
|
|
|
#define NO_PARAM (Param::NO_PARAM)
|
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-06-02 03:31:37 +00:00
|
|
|
#define gs (SS.GW.gs)
|
|
|
|
|
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;
|
2008-06-02 11:43:27 +00:00
|
|
|
ZERO(&g);
|
2008-04-27 09:03:01 +00:00
|
|
|
g.visible = true;
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
if(id >= RECENT_IMPORT && id < (RECENT_IMPORT + MAX_RECENT)) {
|
|
|
|
strcpy(g.impFile, RecentFile[id-RECENT_IMPORT]);
|
|
|
|
id = GraphicsWindow::MNU_GROUP_IMPORT;
|
|
|
|
}
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
SS.GW.GroupSelection();
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
switch(id) {
|
2008-05-11 02:57:47 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_3D:
|
2008-05-11 10:40:37 +00:00
|
|
|
g.type = DRAWING_3D;
|
2008-05-11 06:09:46 +00:00
|
|
|
g.name.strcpy("draw-in-3d");
|
2008-04-27 09:03:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_WRKPL:
|
|
|
|
g.type = DRAWING_WORKPLANE;
|
|
|
|
g.name.strcpy("draw-in-plane");
|
|
|
|
if(gs.points == 1 && gs.n == 1) {
|
2008-05-17 08:02:39 +00:00
|
|
|
g.subtype = WORKPLANE_BY_POINT_ORTHO;
|
2008-05-11 10:40:37 +00:00
|
|
|
|
|
|
|
Vector u = SS.GW.projRight, v = SS.GW.projUp;
|
|
|
|
u = u.ClosestOrtho();
|
|
|
|
v = v.Minus(u.ScaledBy(v.Dot(u)));
|
|
|
|
v = v.ClosestOrtho();
|
|
|
|
|
2008-06-01 08:45:11 +00:00
|
|
|
g.predef.q = Quaternion::From(u, v);
|
2008-06-01 08:29:59 +00:00
|
|
|
g.predef.origin = gs.point[0];
|
2008-05-11 10:40:37 +00:00
|
|
|
} else if(gs.points == 1 && gs.lineSegments == 2 && gs.n == 3) {
|
2008-05-17 08:02:39 +00:00
|
|
|
g.subtype = WORKPLANE_BY_LINE_SEGMENTS;
|
2008-05-11 10:40:37 +00:00
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
g.predef.origin = gs.point[0];
|
|
|
|
g.predef.entityB = gs.entity[0];
|
|
|
|
g.predef.entityC = gs.entity[1];
|
2008-05-11 10:40:37 +00:00
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
Vector ut = SS.GetEntity(g.predef.entityB)->VectorGetNum();
|
|
|
|
Vector vt = SS.GetEntity(g.predef.entityC)->VectorGetNum();
|
2008-05-11 10:40:37 +00:00
|
|
|
ut = ut.WithMagnitude(1);
|
|
|
|
vt = vt.WithMagnitude(1);
|
|
|
|
|
|
|
|
if(fabs(SS.GW.projUp.Dot(vt)) < fabs(SS.GW.projUp.Dot(ut))) {
|
|
|
|
SWAP(Vector, ut, vt);
|
2008-06-01 08:29:59 +00:00
|
|
|
g.predef.swapUV = true;
|
2008-05-11 10:40:37 +00:00
|
|
|
}
|
2008-06-01 08:29:59 +00:00
|
|
|
if(SS.GW.projRight.Dot(ut) < 0) g.predef.negateU = true;
|
|
|
|
if(SS.GW.projUp. Dot(vt) < 0) g.predef.negateV = true;
|
2008-05-11 10:40:37 +00:00
|
|
|
} else {
|
|
|
|
Error("Bad selection for new drawing in workplane.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
break;
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_EXTRUDE:
|
|
|
|
g.type = EXTRUDE;
|
2008-05-11 06:09:46 +00:00
|
|
|
g.opA = SS.GW.activeGroup;
|
2008-05-30 07:32:30 +00:00
|
|
|
g.color = RGB(100, 100, 100);
|
2008-06-01 08:29:59 +00:00
|
|
|
g.predef.entityB = SS.GW.ActiveWorkplane();
|
2008-05-27 06:36:59 +00:00
|
|
|
g.subtype = ONE_SIDED;
|
2008-04-27 09:03:01 +00:00
|
|
|
g.name.strcpy("extrude");
|
|
|
|
break;
|
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_ROT: {
|
|
|
|
Vector n;
|
|
|
|
if(gs.points == 1 && gs.n == 1 && SS.GW.LockedInWorkplane()) {
|
|
|
|
g.predef.p = (SS.GetEntity(gs.point[0]))->PointGetNum();
|
|
|
|
Entity *w = SS.GetEntity(SS.GW.ActiveWorkplane());
|
|
|
|
n = (w->Normal()->NormalN());
|
|
|
|
g.activeWorkplane = w->h;
|
|
|
|
} else if(gs.points == 1 && gs.vectors == 1 && gs.n == 2) {
|
|
|
|
g.predef.p = (SS.GetEntity(gs.point[0]))->PointGetNum();
|
|
|
|
n = SS.GetEntity(gs.vector[0])->VectorGetNum();
|
|
|
|
} else {
|
|
|
|
Error("Bad selection for new rotation.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
n = n.WithMagnitude(1);
|
2008-06-01 08:45:11 +00:00
|
|
|
g.predef.q = Quaternion::From(0, n.x, n.y, n.z);
|
2008-05-11 06:09:46 +00:00
|
|
|
g.type = ROTATE;
|
|
|
|
g.opA = SS.GW.activeGroup;
|
2008-06-01 08:45:11 +00:00
|
|
|
g.exprA = Expr::From(3)->DeepCopyKeep();
|
2008-05-27 06:36:59 +00:00
|
|
|
g.subtype = ONE_SIDED;
|
2008-05-11 06:09:46 +00:00
|
|
|
g.name.strcpy("rotate");
|
2008-06-01 08:29:59 +00:00
|
|
|
SS.GW.ClearSelection();
|
2008-05-11 06:09:46 +00:00
|
|
|
break;
|
2008-06-01 08:29:59 +00:00
|
|
|
}
|
2008-05-11 06:09:46 +00:00
|
|
|
|
2008-05-27 06:36:59 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_TRANS:
|
|
|
|
g.type = TRANSLATE;
|
|
|
|
g.opA = SS.GW.activeGroup;
|
2008-06-01 08:45:11 +00:00
|
|
|
g.exprA = Expr::From(3)->DeepCopyKeep();
|
2008-05-27 06:36:59 +00:00
|
|
|
g.subtype = ONE_SIDED;
|
|
|
|
g.name.strcpy("translate");
|
|
|
|
break;
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
case GraphicsWindow::MNU_GROUP_IMPORT: {
|
|
|
|
g.type = IMPORTED;
|
|
|
|
g.opA = SS.GW.activeGroup;
|
|
|
|
if(strlen(g.impFile) == 0) {
|
|
|
|
if(!GetOpenFile(g.impFile, SLVS_EXT, SLVS_PATTERN)) return;
|
|
|
|
}
|
|
|
|
g.name.strcpy("import");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
|
|
|
|
SS.group.AddAndAssignId(&g);
|
2008-05-29 10:10:12 +00:00
|
|
|
if(g.type == IMPORTED) {
|
|
|
|
SS.ReloadAllImported();
|
|
|
|
}
|
2008-06-02 09:31:26 +00:00
|
|
|
SS.GenerateAll();
|
2008-04-27 09:03:01 +00:00
|
|
|
SS.GW.activeGroup = g.h;
|
2008-05-11 10:40:37 +00:00
|
|
|
if(g.type == DRAWING_WORKPLANE) {
|
2008-05-27 02:22:20 +00:00
|
|
|
SS.GetGroup(g.h)->activeWorkplane = g.h.entity(0);
|
2008-05-11 10:40:37 +00:00
|
|
|
}
|
2008-06-02 05:38:12 +00:00
|
|
|
SS.GetGroup(g.h)->Activate();
|
2008-05-27 02:22:20 +00:00
|
|
|
SS.GW.AnimateOntoWorkplane();
|
2008-05-26 09:56:50 +00:00
|
|
|
TextWindow::ScreenSelectGroup(0, g.h.v);
|
2008-04-27 09:03:01 +00:00
|
|
|
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-06-02 05:38:12 +00:00
|
|
|
void Group::Activate(void) {
|
|
|
|
if(type == EXTRUDE || type == IMPORTED) {
|
|
|
|
SS.GW.showFaces = true;
|
|
|
|
} else {
|
|
|
|
SS.GW.showFaces = false;
|
|
|
|
}
|
2008-06-02 11:43:27 +00:00
|
|
|
SS.MarkGroupDirty(h); // for good measure; shouldn't be needed
|
|
|
|
SS.GenerateAll();
|
2008-06-02 05:38:12 +00:00
|
|
|
SS.TW.Show();
|
|
|
|
}
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
void Group::Generate(IdList<Entity,hEntity> *entity,
|
|
|
|
IdList<Param,hParam> *param)
|
|
|
|
{
|
2008-05-07 04:17:29 +00:00
|
|
|
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
|
2008-05-27 06:36:59 +00:00
|
|
|
Vector gp = SS.GW.projRight.Plus(SS.GW.projUp);
|
2008-06-01 08:29:59 +00:00
|
|
|
Vector gc = (SS.GW.offset).ScaledBy(-1);
|
2008-05-07 04:17:29 +00:00
|
|
|
gn = gn.WithMagnitude(200/SS.GW.scale);
|
2008-05-27 06:36:59 +00:00
|
|
|
gp = gp.WithMagnitude(200/SS.GW.scale);
|
|
|
|
int a, i;
|
2008-04-27 09:03:01 +00:00
|
|
|
switch(type) {
|
2008-05-11 10:40:37 +00:00
|
|
|
case DRAWING_3D:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAWING_WORKPLANE: {
|
|
|
|
Quaternion q;
|
2008-05-17 08:02:39 +00:00
|
|
|
if(subtype == WORKPLANE_BY_LINE_SEGMENTS) {
|
2008-06-01 08:29:59 +00:00
|
|
|
Vector u = SS.GetEntity(predef.entityB)->VectorGetNum();
|
|
|
|
Vector v = SS.GetEntity(predef.entityC)->VectorGetNum();
|
2008-05-11 10:40:37 +00:00
|
|
|
u = u.WithMagnitude(1);
|
|
|
|
Vector n = u.Cross(v);
|
|
|
|
v = (n.Cross(u)).WithMagnitude(1);
|
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
if(predef.swapUV) SWAP(Vector, u, v);
|
|
|
|
if(predef.negateU) u = u.ScaledBy(-1);
|
|
|
|
if(predef.negateV) v = v.ScaledBy(-1);
|
2008-06-01 08:45:11 +00:00
|
|
|
q = Quaternion::From(u, v);
|
2008-05-17 08:02:39 +00:00
|
|
|
} else if(subtype == WORKPLANE_BY_POINT_ORTHO) {
|
2008-05-11 10:40:37 +00:00
|
|
|
// Already given, numerically.
|
2008-06-01 08:29:59 +00:00
|
|
|
q = predef.q;
|
2008-05-11 10:40:37 +00:00
|
|
|
} else oops();
|
|
|
|
|
|
|
|
Entity normal;
|
|
|
|
memset(&normal, 0, sizeof(normal));
|
|
|
|
normal.type = Entity::NORMAL_N_COPY;
|
|
|
|
normal.numNormal = q;
|
|
|
|
normal.point[0] = h.entity(2);
|
|
|
|
normal.group = h;
|
|
|
|
normal.h = h.entity(1);
|
|
|
|
entity->Add(&normal);
|
|
|
|
|
|
|
|
Entity point;
|
|
|
|
memset(&point, 0, sizeof(point));
|
|
|
|
point.type = Entity::POINT_N_COPY;
|
2008-06-01 08:29:59 +00:00
|
|
|
point.numPoint = SS.GetEntity(predef.origin)->PointGetNum();
|
2008-05-11 10:40:37 +00:00
|
|
|
point.group = h;
|
|
|
|
point.h = h.entity(2);
|
|
|
|
entity->Add(&point);
|
|
|
|
|
|
|
|
Entity wp;
|
|
|
|
memset(&wp, 0, sizeof(wp));
|
|
|
|
wp.type = Entity::WORKPLANE;
|
|
|
|
wp.normal = normal.h;
|
|
|
|
wp.point[0] = point.h;
|
|
|
|
wp.group = h;
|
|
|
|
wp.h = h.entity(0);
|
|
|
|
entity->Add(&wp);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-27 09:03:01 +00:00
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
case EXTRUDE: {
|
2008-05-07 04:17:29 +00:00
|
|
|
AddParam(param, h.param(0), gn.x);
|
|
|
|
AddParam(param, h.param(1), gn.y);
|
|
|
|
AddParam(param, h.param(2), gn.z);
|
2008-05-17 08:02:39 +00:00
|
|
|
int ai, af;
|
2008-05-27 06:36:59 +00:00
|
|
|
if(subtype == ONE_SIDED) {
|
|
|
|
ai = 0; af = 2;
|
|
|
|
} else if(subtype == TWO_SIDED) {
|
2008-05-17 08:02:39 +00:00
|
|
|
ai = -1; af = 1;
|
|
|
|
} else oops();
|
2008-06-02 03:31:37 +00:00
|
|
|
|
|
|
|
// Get some arbitrary point in the sketch, that will be used
|
|
|
|
// as a reference when defining top and bottom faces.
|
|
|
|
hEntity pt = { 0 };
|
2008-04-27 09:03:01 +00:00
|
|
|
for(i = 0; i < entity->n; i++) {
|
|
|
|
Entity *e = &(entity->elem[i]);
|
|
|
|
if(e->group.v != opA.v) continue;
|
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
if(e->IsPoint()) pt = e->h;
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
e->CalculateNumerical();
|
2008-05-17 08:02:39 +00:00
|
|
|
hEntity he = e->h; e = NULL;
|
|
|
|
// As soon as I call CopyEntity, e may become invalid! That
|
|
|
|
// adds entities, which may cause a realloc.
|
2008-06-01 08:29:59 +00:00
|
|
|
CopyEntity(SS.GetEntity(he), ai, REMAP_BOTTOM,
|
2008-05-11 06:09:46 +00:00
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM,
|
2008-06-01 08:29:59 +00:00
|
|
|
true, false);
|
|
|
|
CopyEntity(SS.GetEntity(he), af, REMAP_TOP,
|
2008-05-17 08:02:39 +00:00
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM,
|
2008-06-01 08:29:59 +00:00
|
|
|
true, false);
|
|
|
|
MakeExtrusionLines(he);
|
2008-05-11 06:09:46 +00:00
|
|
|
}
|
2008-06-02 03:31:37 +00:00
|
|
|
// Remapped versions of that arbitrary point will be used to
|
|
|
|
// provide points on the plane faces.
|
|
|
|
MakeExtrusionTopBottomFaces(pt);
|
2008-05-11 06:09:46 +00:00
|
|
|
break;
|
2008-06-02 03:31:37 +00:00
|
|
|
}
|
2008-05-11 06:09:46 +00:00
|
|
|
|
2008-05-27 06:36:59 +00:00
|
|
|
case TRANSLATE: {
|
|
|
|
// The translation vector
|
|
|
|
AddParam(param, h.param(0), gp.x);
|
|
|
|
AddParam(param, h.param(1), gp.y);
|
|
|
|
AddParam(param, h.param(2), gp.z);
|
|
|
|
|
|
|
|
int n = (int)(exprA->Eval());
|
|
|
|
for(a = 0; a < n; a++) {
|
|
|
|
for(i = 0; i < entity->n; i++) {
|
|
|
|
Entity *e = &(entity->elem[i]);
|
|
|
|
if(e->group.v != opA.v) continue;
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
e->CalculateNumerical();
|
2008-06-01 08:29:59 +00:00
|
|
|
CopyEntity(e,
|
|
|
|
a*2 - (subtype == ONE_SIDED ? 0 : (n-1)),
|
|
|
|
(a == (n - 1)) ? REMAP_LAST : a,
|
2008-05-27 06:36:59 +00:00
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM,
|
2008-06-01 08:29:59 +00:00
|
|
|
true, false);
|
2008-05-27 06:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-06-01 08:29:59 +00:00
|
|
|
case ROTATE: {
|
|
|
|
// The center of rotation
|
|
|
|
AddParam(param, h.param(0), gc.x);
|
|
|
|
AddParam(param, h.param(1), gc.y);
|
|
|
|
AddParam(param, h.param(2), gc.z);
|
2008-05-11 06:09:46 +00:00
|
|
|
// The rotation quaternion
|
2008-06-01 08:29:59 +00:00
|
|
|
AddParam(param, h.param(3), 15*PI/180);
|
|
|
|
AddParam(param, h.param(4), gn.x);
|
|
|
|
AddParam(param, h.param(5), gn.y);
|
|
|
|
AddParam(param, h.param(6), gn.z);
|
2008-05-11 06:09:46 +00:00
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
int n = (int)(exprA->Eval());
|
|
|
|
for(a = 0; a < n; a++) {
|
|
|
|
for(i = 0; i < entity->n; i++) {
|
|
|
|
Entity *e = &(entity->elem[i]);
|
|
|
|
if(e->group.v != opA.v) continue;
|
2008-05-11 06:09:46 +00:00
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
e->CalculateNumerical();
|
|
|
|
CopyEntity(e,
|
|
|
|
a*2 - (subtype == ONE_SIDED ? 0 : (n-1)),
|
|
|
|
(a == (n - 1)) ? REMAP_LAST : a,
|
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
h.param(3), h.param(4), h.param(5), h.param(6),
|
|
|
|
false, true);
|
|
|
|
}
|
2008-05-29 10:10:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-06-01 08:29:59 +00:00
|
|
|
}
|
2008-05-29 10:10:12 +00:00
|
|
|
case IMPORTED:
|
|
|
|
// The translation vector
|
|
|
|
AddParam(param, h.param(0), gp.x);
|
|
|
|
AddParam(param, h.param(1), gp.y);
|
|
|
|
AddParam(param, h.param(2), gp.z);
|
|
|
|
// The rotation quaternion
|
|
|
|
AddParam(param, h.param(3), 1);
|
|
|
|
AddParam(param, h.param(4), 0);
|
|
|
|
AddParam(param, h.param(5), 0);
|
|
|
|
AddParam(param, h.param(6), 0);
|
|
|
|
|
|
|
|
for(i = 0; i < impEntity.n; i++) {
|
|
|
|
Entity *ie = &(impEntity.elem[i]);
|
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
CopyEntity(ie, 0, 0,
|
2008-05-11 06:09:46 +00:00
|
|
|
h.param(0), h.param(1), h.param(2),
|
|
|
|
h.param(3), h.param(4), h.param(5), h.param(6),
|
2008-06-01 08:29:59 +00:00
|
|
|
false, false);
|
2008-04-27 09:03:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
void Group::AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index) {
|
|
|
|
Equation eq;
|
|
|
|
eq.e = expr;
|
|
|
|
eq.h = h.equation(index);
|
|
|
|
l->Add(&eq);
|
|
|
|
}
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
|
2008-05-16 06:34:06 +00:00
|
|
|
Equation eq;
|
2008-06-01 08:29:59 +00:00
|
|
|
ZERO(&eq);
|
|
|
|
if(type == IMPORTED) {
|
2008-05-11 06:09:46 +00:00
|
|
|
// Normalize the quaternion
|
|
|
|
ExprQuaternion q = {
|
2008-06-01 08:45:11 +00:00
|
|
|
Expr::From(h.param(3)),
|
|
|
|
Expr::From(h.param(4)),
|
|
|
|
Expr::From(h.param(5)),
|
|
|
|
Expr::From(h.param(6)) };
|
|
|
|
AddEq(l, (q.Magnitude())->Minus(Expr::From(1)), 0);
|
2008-06-01 08:29:59 +00:00
|
|
|
} else if(type == ROTATE) {
|
|
|
|
// The axis and center of rotation are specified numerically
|
2008-06-01 08:45:11 +00:00
|
|
|
#define EC(x) (Expr::From(x))
|
|
|
|
#define EP(x) (Expr::From(h.param(x)))
|
2008-06-01 08:29:59 +00:00
|
|
|
AddEq(l, (EC(predef.p.x))->Minus(EP(0)), 0);
|
|
|
|
AddEq(l, (EC(predef.p.y))->Minus(EP(1)), 1);
|
|
|
|
AddEq(l, (EC(predef.p.z))->Minus(EP(2)), 2);
|
|
|
|
// param 3 is the angle, which is free
|
|
|
|
AddEq(l, (EC(predef.q.vx))->Minus(EP(4)), 3);
|
|
|
|
AddEq(l, (EC(predef.q.vy))->Minus(EP(5)), 4);
|
|
|
|
AddEq(l, (EC(predef.q.vz))->Minus(EP(6)), 5);
|
2008-05-16 06:34:06 +00:00
|
|
|
} else if(type == EXTRUDE) {
|
2008-06-01 08:29:59 +00:00
|
|
|
if(predef.entityB.v != Entity::FREE_IN_3D.v) {
|
2008-05-29 10:10:12 +00:00
|
|
|
// The extrusion path is locked along a line, normal to the
|
|
|
|
// specified workplane.
|
2008-06-01 08:29:59 +00:00
|
|
|
Entity *w = SS.GetEntity(predef.entityB);
|
2008-05-16 06:34:06 +00:00
|
|
|
ExprVector u = w->Normal()->NormalExprsU();
|
|
|
|
ExprVector v = w->Normal()->NormalExprsV();
|
|
|
|
ExprVector extruden = {
|
2008-06-01 08:45:11 +00:00
|
|
|
Expr::From(h.param(0)),
|
|
|
|
Expr::From(h.param(1)),
|
|
|
|
Expr::From(h.param(2)) };
|
2008-06-01 08:29:59 +00:00
|
|
|
|
|
|
|
AddEq(l, u.Dot(extruden), 0);
|
|
|
|
AddEq(l, v.Dot(extruden), 1);
|
2008-05-16 06:34:06 +00:00
|
|
|
}
|
2008-05-11 06:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
void Group::MakeExtrusionLines(hEntity in) {
|
2008-05-17 08:02:39 +00:00
|
|
|
Entity *ep = SS.GetEntity(in);
|
|
|
|
|
|
|
|
Entity en;
|
2008-06-02 03:31:37 +00:00
|
|
|
ZERO(&en);
|
|
|
|
if(ep->IsPoint()) {
|
|
|
|
// A point gets extruded to form a line segment
|
|
|
|
en.point[0] = Remap(ep->h, REMAP_TOP);
|
|
|
|
en.point[1] = Remap(ep->h, REMAP_BOTTOM);
|
|
|
|
en.group = h;
|
|
|
|
en.h = Remap(ep->h, REMAP_PT_TO_LINE);
|
|
|
|
en.type = Entity::LINE_SEGMENT;
|
|
|
|
SS.entity.Add(&en);
|
|
|
|
} else if(ep->type == Entity::LINE_SEGMENT) {
|
|
|
|
// A line gets extruded to form a plane face; an endpoint of the
|
|
|
|
// original line is a point in the plane, and the line is in the plane.
|
|
|
|
Vector a = SS.GetEntity(ep->point[0])->PointGetNum();
|
|
|
|
Vector b = SS.GetEntity(ep->point[1])->PointGetNum();
|
|
|
|
Vector ab = b.Minus(a);
|
|
|
|
|
|
|
|
en.param[0] = h.param(0);
|
|
|
|
en.param[1] = h.param(1);
|
|
|
|
en.param[2] = h.param(2);
|
|
|
|
en.numPoint = a;
|
|
|
|
en.numVector = ab;
|
|
|
|
|
|
|
|
en.group = h;
|
|
|
|
en.h = Remap(ep->h, REMAP_LINE_TO_FACE);
|
|
|
|
en.type = Entity::FACE_XPROD;
|
|
|
|
SS.entity.Add(&en);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::MakeExtrusionTopBottomFaces(hEntity pt) {
|
|
|
|
if(pt.v == 0) return;
|
|
|
|
Group *src = SS.GetGroup(opA);
|
|
|
|
Vector n = src->poly.normal;
|
|
|
|
|
|
|
|
Entity en;
|
|
|
|
ZERO(&en);
|
|
|
|
en.type = Entity::FACE_NORMAL_PT;
|
2008-05-17 08:02:39 +00:00
|
|
|
en.group = h;
|
2008-06-02 03:31:37 +00:00
|
|
|
|
|
|
|
en.numNormal = Quaternion::From(0, n.x, n.y, n.z);
|
|
|
|
en.point[0] = Remap(pt, REMAP_TOP);
|
|
|
|
en.h = Remap(Entity::NO_ENTITY, REMAP_TOP);
|
|
|
|
SS.entity.Add(&en);
|
|
|
|
|
|
|
|
en.point[0] = Remap(pt, REMAP_BOTTOM);
|
|
|
|
en.h = Remap(Entity::NO_ENTITY, REMAP_BOTTOM);
|
2008-05-17 08:02:39 +00:00
|
|
|
SS.entity.Add(&en);
|
|
|
|
}
|
|
|
|
|
2008-06-01 08:29:59 +00:00
|
|
|
void Group::CopyEntity(Entity *ep, int timesApplied, int remap,
|
|
|
|
hParam dx, hParam dy, hParam dz,
|
2008-05-11 06:09:46 +00:00
|
|
|
hParam qw, hParam qvx, hParam qvy, hParam qvz,
|
2008-06-01 08:29:59 +00:00
|
|
|
bool asTrans, bool asAxisAngle)
|
2008-05-05 06:18:01 +00:00
|
|
|
{
|
2008-04-27 09:03:01 +00:00
|
|
|
Entity en;
|
|
|
|
memset(&en, 0, sizeof(en));
|
|
|
|
en.type = ep->type;
|
2008-06-01 08:29:59 +00:00
|
|
|
en.h = Remap(ep->h, remap);
|
|
|
|
en.timesApplied = timesApplied;
|
2008-04-27 09:03:01 +00:00
|
|
|
en.group = h;
|
2008-05-25 14:36:03 +00:00
|
|
|
en.construction = ep->construction;
|
2008-04-27 09:03:01 +00:00
|
|
|
|
|
|
|
switch(ep->type) {
|
|
|
|
case Entity::WORKPLANE:
|
|
|
|
// Don't copy these.
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Entity::LINE_SEGMENT:
|
2008-06-01 08:29:59 +00:00
|
|
|
en.point[0] = Remap(ep->point[0], remap);
|
|
|
|
en.point[1] = Remap(ep->point[1], remap);
|
2008-04-27 09:03:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Entity::CUBIC:
|
2008-06-01 08:29:59 +00:00
|
|
|
en.point[0] = Remap(ep->point[0], remap);
|
|
|
|
en.point[1] = Remap(ep->point[1], remap);
|
|
|
|
en.point[2] = Remap(ep->point[2], remap);
|
|
|
|
en.point[3] = Remap(ep->point[3], remap);
|
2008-04-27 09:03:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case Entity::CIRCLE:
|
2008-06-01 08:29:59 +00:00
|
|
|
en.point[0] = Remap(ep->point[0], remap);
|
|
|
|
en.normal = Remap(ep->normal, remap);
|
|
|
|
en.distance = Remap(ep->distance, remap);
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-12 10:01:44 +00:00
|
|
|
case Entity::ARC_OF_CIRCLE:
|
2008-06-01 08:29:59 +00:00
|
|
|
en.point[0] = Remap(ep->point[0], remap);
|
|
|
|
en.point[1] = Remap(ep->point[1], remap);
|
|
|
|
en.point[2] = Remap(ep->point[2], remap);
|
|
|
|
en.normal = Remap(ep->normal, remap);
|
2008-05-12 10:01:44 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-11 10:40:37 +00:00
|
|
|
case Entity::POINT_N_COPY:
|
2008-05-11 06:09:46 +00:00
|
|
|
case Entity::POINT_N_TRANS:
|
|
|
|
case Entity::POINT_N_ROT_TRANS:
|
2008-06-01 08:29:59 +00:00
|
|
|
case Entity::POINT_N_ROT_AA:
|
2008-04-27 09:03:01 +00:00
|
|
|
case Entity::POINT_IN_3D:
|
|
|
|
case Entity::POINT_IN_2D:
|
2008-06-01 08:29:59 +00:00
|
|
|
if(asTrans) {
|
2008-05-11 06:09:46 +00:00
|
|
|
en.type = Entity::POINT_N_TRANS;
|
|
|
|
en.param[0] = dx;
|
|
|
|
en.param[1] = dy;
|
|
|
|
en.param[2] = dz;
|
|
|
|
} else {
|
2008-06-01 08:29:59 +00:00
|
|
|
if(asAxisAngle) {
|
|
|
|
en.type = Entity::POINT_N_ROT_AA;
|
|
|
|
} else {
|
|
|
|
en.type = Entity::POINT_N_ROT_TRANS;
|
|
|
|
}
|
2008-05-11 06:09:46 +00:00
|
|
|
en.param[0] = dx;
|
|
|
|
en.param[1] = dy;
|
|
|
|
en.param[2] = dz;
|
|
|
|
en.param[3] = qw;
|
|
|
|
en.param[4] = qvx;
|
|
|
|
en.param[5] = qvy;
|
|
|
|
en.param[6] = qvz;
|
2008-05-05 06:18:01 +00:00
|
|
|
}
|
2008-05-29 10:10:12 +00:00
|
|
|
en.numPoint = ep->actPoint;
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
case Entity::NORMAL_N_COPY:
|
|
|
|
case Entity::NORMAL_N_ROT:
|
2008-06-01 08:29:59 +00:00
|
|
|
case Entity::NORMAL_N_ROT_AA:
|
2008-05-05 06:18:01 +00:00
|
|
|
case Entity::NORMAL_IN_3D:
|
|
|
|
case Entity::NORMAL_IN_2D:
|
2008-06-01 08:29:59 +00:00
|
|
|
if(asTrans) {
|
2008-05-11 06:09:46 +00:00
|
|
|
en.type = Entity::NORMAL_N_COPY;
|
|
|
|
} else {
|
2008-06-01 08:29:59 +00:00
|
|
|
if(asAxisAngle) {
|
|
|
|
en.type = Entity::NORMAL_N_ROT_AA;
|
|
|
|
} else {
|
|
|
|
en.type = Entity::NORMAL_N_ROT;
|
|
|
|
}
|
2008-05-11 06:09:46 +00:00
|
|
|
en.param[0] = qw;
|
|
|
|
en.param[1] = qvx;
|
|
|
|
en.param[2] = qvy;
|
|
|
|
en.param[3] = qvz;
|
|
|
|
}
|
2008-05-29 10:10:12 +00:00
|
|
|
en.numNormal = ep->actNormal;
|
2008-06-01 08:29:59 +00:00
|
|
|
en.point[0] = Remap(ep->point[0], remap);
|
2008-04-27 09:03:01 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-11 06:09:46 +00:00
|
|
|
case Entity::DISTANCE_N_COPY:
|
2008-05-07 08:19:37 +00:00
|
|
|
case Entity::DISTANCE:
|
2008-05-11 06:09:46 +00:00
|
|
|
en.type = Entity::DISTANCE_N_COPY;
|
2008-05-29 10:10:12 +00:00
|
|
|
en.numDistance = ep->actDistance;
|
2008-05-07 08:19:37 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
case Entity::FACE_NORMAL_PT:
|
|
|
|
case Entity::FACE_XPROD:
|
|
|
|
case Entity::FACE_N_ROT_TRANS:
|
|
|
|
if(asTrans || asAxisAngle) return;
|
|
|
|
|
|
|
|
en.type = Entity::FACE_N_ROT_TRANS;
|
|
|
|
en.param[0] = dx;
|
|
|
|
en.param[1] = dy;
|
|
|
|
en.param[2] = dz;
|
|
|
|
en.param[3] = qw;
|
|
|
|
en.param[4] = qvx;
|
|
|
|
en.param[5] = qvy;
|
|
|
|
en.param[6] = qvz;
|
|
|
|
en.numPoint = ep->numPoint;
|
|
|
|
en.numNormal = ep->numNormal;
|
|
|
|
break;
|
|
|
|
|
2008-04-27 09:03:01 +00:00
|
|
|
default:
|
|
|
|
oops();
|
|
|
|
}
|
|
|
|
SS.entity.Add(&en);
|
|
|
|
}
|
|
|
|
|
2008-06-01 00:26:41 +00:00
|
|
|
void Group::TagEdgesFromLineSegments(SEdgeList *el) {
|
|
|
|
int i, j;
|
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
|
|
|
Entity *e = &(SS.entity.elem[i]);
|
|
|
|
if(e->group.v != opA.v) continue;
|
|
|
|
if(e->type != Entity::LINE_SEGMENT) continue;
|
|
|
|
|
|
|
|
Vector p0 = SS.GetEntity(e->point[0])->PointGetNum();
|
|
|
|
Vector p1 = SS.GetEntity(e->point[1])->PointGetNum();
|
|
|
|
|
|
|
|
for(j = 0; j < el->l.n; j++) {
|
|
|
|
SEdge *se = &(el->l.elem[j]);
|
2008-06-02 03:31:37 +00:00
|
|
|
if((p0.Equals(se->a) && p1.Equals(se->b))) se->tag = e->h.v;
|
|
|
|
if((p0.Equals(se->b) && p1.Equals(se->a))) se->tag = e->h.v;
|
2008-06-01 00:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
void Group::GeneratePolygon(void) {
|
2008-05-21 03:58:14 +00:00
|
|
|
poly.Clear();
|
2008-05-19 09:23:49 +00:00
|
|
|
|
2008-06-01 09:46:02 +00:00
|
|
|
if(type == DRAWING_3D || type == DRAWING_WORKPLANE ||
|
|
|
|
type == ROTATE || type == TRANSLATE)
|
|
|
|
{
|
2008-06-02 09:31:26 +00:00
|
|
|
SEdgeList edges; ZERO(&edges);
|
2008-05-02 10:54:22 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.entity.n; i++) {
|
|
|
|
Entity *e = &(SS.entity.elem[i]);
|
|
|
|
if(e->group.v != h.v) continue;
|
2008-04-28 07:18:39 +00:00
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
e->GenerateEdges(&edges);
|
|
|
|
}
|
|
|
|
SEdge error;
|
2008-05-21 03:58:14 +00:00
|
|
|
if(edges.AssemblePolygon(&poly, &error)) {
|
2008-05-02 10:54:22 +00:00
|
|
|
polyError.yes = false;
|
2008-05-21 03:58:14 +00:00
|
|
|
poly.normal = poly.ComputeNormal();
|
2008-05-23 10:05:07 +00:00
|
|
|
poly.FixContourDirections();
|
2008-05-02 10:54:22 +00:00
|
|
|
} else {
|
|
|
|
polyError.yes = true;
|
|
|
|
polyError.notClosedAt = error;
|
2008-05-21 03:58:14 +00:00
|
|
|
poly.Clear();
|
2008-05-02 10:54:22 +00:00
|
|
|
}
|
2008-06-02 09:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::GenerateMesh(void) {
|
|
|
|
SMesh outm;
|
|
|
|
ZERO(&outm);
|
|
|
|
if(type == EXTRUDE) {
|
|
|
|
SEdgeList edges;
|
|
|
|
ZERO(&edges);
|
2008-05-23 10:05:07 +00:00
|
|
|
int i;
|
|
|
|
Group *src = SS.GetGroup(opA);
|
2008-06-02 09:31:26 +00:00
|
|
|
Vector translate = Vector::From(h.param(0), h.param(1), h.param(2));
|
|
|
|
|
2008-05-23 10:05:07 +00:00
|
|
|
Vector tbot, ttop;
|
2008-05-27 06:36:59 +00:00
|
|
|
if(subtype == ONE_SIDED) {
|
2008-06-01 08:45:11 +00:00
|
|
|
tbot = Vector::From(0, 0, 0); ttop = translate.ScaledBy(2);
|
2008-05-17 08:02:39 +00:00
|
|
|
} else {
|
2008-05-23 10:05:07 +00:00
|
|
|
tbot = translate.ScaledBy(-1); ttop = translate.ScaledBy(1);
|
2008-05-17 08:02:39 +00:00
|
|
|
}
|
2008-05-23 10:05:07 +00:00
|
|
|
bool flipBottom = translate.Dot(src->poly.normal) > 0;
|
|
|
|
|
|
|
|
// Get a triangulation of the source poly; this is not a closed mesh.
|
|
|
|
SMesh srcm; ZERO(&srcm);
|
|
|
|
(src->poly).TriangulateInto(&srcm);
|
|
|
|
|
2008-05-30 06:09:41 +00:00
|
|
|
STriMeta meta = { 0, color };
|
|
|
|
|
2008-05-23 10:05:07 +00:00
|
|
|
// Do the bottom; that has normal pointing opposite from translate
|
2008-06-02 03:31:37 +00:00
|
|
|
meta.face = Remap(Entity::NO_ENTITY, REMAP_BOTTOM).v;
|
2008-05-23 10:05:07 +00:00
|
|
|
for(i = 0; i < srcm.l.n; i++) {
|
|
|
|
STriangle *st = &(srcm.l.elem[i]);
|
|
|
|
Vector at = (st->a).Plus(tbot),
|
|
|
|
bt = (st->b).Plus(tbot),
|
|
|
|
ct = (st->c).Plus(tbot);
|
|
|
|
if(flipBottom) {
|
2008-05-30 06:09:41 +00:00
|
|
|
outm.AddTriangle(meta, ct, bt, at);
|
2008-05-23 10:05:07 +00:00
|
|
|
} else {
|
2008-05-30 06:09:41 +00:00
|
|
|
outm.AddTriangle(meta, at, bt, ct);
|
2008-05-23 10:05:07 +00:00
|
|
|
}
|
2008-05-17 08:02:39 +00:00
|
|
|
}
|
2008-05-23 10:05:07 +00:00
|
|
|
// And the top; that has the normal pointing the same dir as translate
|
2008-06-02 03:31:37 +00:00
|
|
|
meta.face = Remap(Entity::NO_ENTITY, REMAP_TOP).v;
|
2008-05-23 10:05:07 +00:00
|
|
|
for(i = 0; i < srcm.l.n; i++) {
|
|
|
|
STriangle *st = &(srcm.l.elem[i]);
|
|
|
|
Vector at = (st->a).Plus(ttop),
|
|
|
|
bt = (st->b).Plus(ttop),
|
|
|
|
ct = (st->c).Plus(ttop);
|
|
|
|
if(flipBottom) {
|
2008-05-30 06:09:41 +00:00
|
|
|
outm.AddTriangle(meta, at, bt, ct);
|
2008-05-23 10:05:07 +00:00
|
|
|
} else {
|
2008-05-30 06:09:41 +00:00
|
|
|
outm.AddTriangle(meta, ct, bt, at);
|
2008-05-23 10:05:07 +00:00
|
|
|
}
|
2008-05-05 09:47:23 +00:00
|
|
|
}
|
2008-05-23 10:05:07 +00:00
|
|
|
srcm.Clear();
|
|
|
|
// Get the source polygon to extrude, and break it down to edges
|
2008-05-22 10:28:28 +00:00
|
|
|
edges.Clear();
|
2008-05-23 10:05:07 +00:00
|
|
|
(src->poly).MakeEdgesInto(&edges);
|
2008-05-05 09:47:23 +00:00
|
|
|
|
2008-06-01 00:26:41 +00:00
|
|
|
edges.l.ClearTags();
|
|
|
|
TagEdgesFromLineSegments(&edges);
|
2008-05-23 10:05:07 +00:00
|
|
|
// The sides; these are quads, represented as two triangles.
|
2008-05-02 10:54:22 +00:00
|
|
|
for(i = 0; i < edges.l.n; i++) {
|
|
|
|
SEdge *edge = &(edges.l.elem[i]);
|
2008-05-23 10:05:07 +00:00
|
|
|
Vector abot = (edge->a).Plus(tbot), bbot = (edge->b).Plus(tbot);
|
|
|
|
Vector atop = (edge->a).Plus(ttop), btop = (edge->b).Plus(ttop);
|
2008-06-02 03:31:37 +00:00
|
|
|
// We tagged the edges that came from line segments; their
|
|
|
|
// triangles should be associated with that plane face.
|
|
|
|
if(edge->tag) {
|
|
|
|
hEntity hl = { edge->tag };
|
|
|
|
hEntity hf = Remap(hl, REMAP_LINE_TO_FACE);
|
|
|
|
meta.face = hf.v;
|
|
|
|
} else {
|
|
|
|
meta.face = 0;
|
|
|
|
}
|
2008-05-23 10:05:07 +00:00
|
|
|
if(flipBottom) {
|
2008-05-30 06:09:41 +00:00
|
|
|
outm.AddTriangle(meta, bbot, abot, atop);
|
|
|
|
outm.AddTriangle(meta, bbot, atop, btop);
|
2008-05-23 10:05:07 +00:00
|
|
|
} else {
|
2008-05-30 06:09:41 +00:00
|
|
|
outm.AddTriangle(meta, abot, bbot, atop);
|
|
|
|
outm.AddTriangle(meta, bbot, btop, atop);
|
2008-05-23 10:05:07 +00:00
|
|
|
}
|
2008-05-02 10:54:22 +00:00
|
|
|
}
|
2008-06-02 09:31:26 +00:00
|
|
|
edges.Clear();
|
2008-05-29 10:10:12 +00:00
|
|
|
} else if(type == IMPORTED) {
|
|
|
|
// Triangles are just copied over, with the appropriate transformation
|
|
|
|
// applied.
|
|
|
|
Vector offset = {
|
|
|
|
SS.GetParam(h.param(0))->val,
|
|
|
|
SS.GetParam(h.param(1))->val,
|
|
|
|
SS.GetParam(h.param(2))->val };
|
|
|
|
Quaternion q = {
|
|
|
|
SS.GetParam(h.param(3))->val,
|
|
|
|
SS.GetParam(h.param(4))->val,
|
|
|
|
SS.GetParam(h.param(5))->val,
|
|
|
|
SS.GetParam(h.param(6))->val };
|
|
|
|
|
|
|
|
for(int i = 0; i < impMesh.l.n; i++) {
|
|
|
|
STriangle st = impMesh.l.elem[i];
|
2008-06-02 03:31:37 +00:00
|
|
|
|
|
|
|
if(st.meta.face != 0) {
|
|
|
|
hEntity he = { st.meta.face };
|
|
|
|
st.meta.face = Remap(he, 0).v;
|
|
|
|
}
|
2008-05-29 10:10:12 +00:00
|
|
|
st.a = q.Rotate(st.a).Plus(offset);
|
|
|
|
st.b = q.Rotate(st.b).Plus(offset);
|
|
|
|
st.c = q.Rotate(st.c).Plus(offset);
|
|
|
|
outm.AddTriangle(&st);
|
|
|
|
}
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
2008-05-25 13:11:44 +00:00
|
|
|
|
|
|
|
// So our group's mesh appears in outm. Combine this with the previous
|
|
|
|
// group's mesh, using the requested operation.
|
|
|
|
mesh.Clear();
|
|
|
|
SMesh *a = PreviousGroupMesh();
|
|
|
|
if(meshCombine == COMBINE_AS_UNION) {
|
|
|
|
mesh.MakeFromUnion(a, &outm);
|
|
|
|
} else {
|
|
|
|
mesh.MakeFromDifference(a, &outm);
|
|
|
|
}
|
|
|
|
outm.Clear();
|
2008-05-02 10:54:22 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 09:31:26 +00:00
|
|
|
SMesh *Group::PreviousGroupMesh(void) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < SS.group.n; i++) {
|
|
|
|
Group *g = &(SS.group.elem[i]);
|
|
|
|
if(g->h.v == h.v) break;
|
|
|
|
}
|
|
|
|
if(i == 0 || i >= SS.group.n) oops();
|
|
|
|
return &(SS.group.elem[i-1].mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-02 10:54:22 +00:00
|
|
|
void Group::Draw(void) {
|
2008-05-25 13:11:44 +00:00
|
|
|
// Show this even if the group is not visible. It's already possible
|
|
|
|
// to show or hide just this with the "show solids" flag.
|
2008-05-23 10:05:07 +00:00
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
int specColor;
|
2008-06-01 08:29:59 +00:00
|
|
|
if(type != EXTRUDE && type != IMPORTED) {
|
2008-06-02 03:31:37 +00:00
|
|
|
specColor = RGB(25, 25, 25); // force the color to something dim
|
2008-05-25 13:11:44 +00:00
|
|
|
} else {
|
2008-06-02 03:31:37 +00:00
|
|
|
specColor = -1; // use the model color
|
2008-05-25 13:11:44 +00:00
|
|
|
}
|
|
|
|
// The back faces are drawn in red; should never seem them, since we
|
|
|
|
// draw closed shells, so that's a debugging aid.
|
2008-05-23 10:05:07 +00:00
|
|
|
GLfloat mpb[] = { 1.0f, 0.1f, 0.1f, 1.0 };
|
|
|
|
glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE, mpb);
|
|
|
|
|
2008-06-02 03:31:37 +00:00
|
|
|
// When we fill the mesh, we need to know which triangles are selected
|
|
|
|
// or hovered, in order to draw them differently.
|
|
|
|
DWORD mh = 0, ms1 = 0, ms2 = 0;
|
|
|
|
hEntity he = SS.GW.hover.entity;
|
|
|
|
if(he.v != 0 && SS.GetEntity(he)->IsFace()) {
|
|
|
|
mh = he.v;
|
|
|
|
}
|
|
|
|
SS.GW.GroupSelection();
|
|
|
|
if(gs.faces > 0) ms1 = gs.face[0].v;
|
|
|
|
if(gs.faces > 1) ms2 = gs.face[1].v;
|
|
|
|
|
2008-05-25 13:11:44 +00:00
|
|
|
glEnable(GL_LIGHTING);
|
2008-06-02 03:31:37 +00:00
|
|
|
if(SS.GW.showShaded) glxFillMesh(specColor, &mesh, mh, ms1, ms2);
|
2008-05-25 13:11:44 +00:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
|
2008-05-28 10:34:55 +00:00
|
|
|
if(SS.GW.showMesh) glxDebugMesh(&mesh);
|
2008-05-25 13:11:44 +00:00
|
|
|
|
2008-05-28 10:34:55 +00:00
|
|
|
if(!SS.GW.showShaded) return;
|
2008-05-02 10:54:22 +00:00
|
|
|
if(polyError.yes) {
|
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);
|
2008-05-02 10:54:22 +00:00
|
|
|
glxVertex3v(polyError.notClosedAt.a);
|
|
|
|
glxVertex3v(polyError.notClosedAt.b);
|
2008-04-25 07:04:09 +00:00
|
|
|
glEnd();
|
|
|
|
glLineWidth(1);
|
2008-04-25 08:26:15 +00:00
|
|
|
glxColor3d(1, 0, 0);
|
|
|
|
glPushMatrix();
|
2008-05-02 10:54:22 +00:00
|
|
|
glxTranslatev(polyError.notClosedAt.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-05-02 10:54:22 +00:00
|
|
|
} else {
|
2008-06-01 08:29:59 +00:00
|
|
|
glxColor4d(0, 0.1, 0.1, 0.5);
|
2008-05-25 13:11:44 +00:00
|
|
|
glPolygonOffset(-1, -1);
|
|
|
|
glxFillPolygon(&poly);
|
|
|
|
glPolygonOffset(0, 0);
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-05-05 06:18:01 +00:00
|
|
|
bool hasNormal = false;
|
2008-05-07 08:19:37 +00:00
|
|
|
bool hasDistance = false;
|
2008-04-09 08:39:01 +00:00
|
|
|
int i;
|
|
|
|
|
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:
|
2008-05-05 06:18:01 +00:00
|
|
|
et = Entity::WORKPLANE;
|
|
|
|
points = 1;
|
|
|
|
hasNormal = true;
|
|
|
|
break;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
|
|
|
case Request::DATUM_POINT:
|
2008-05-05 06:18:01 +00:00
|
|
|
et = 0;
|
|
|
|
points = 1;
|
|
|
|
break;
|
2008-04-13 10:57:41 +00:00
|
|
|
|
2008-04-09 08:39:01 +00:00
|
|
|
case Request::LINE_SEGMENT:
|
2008-05-05 06:18:01 +00:00
|
|
|
et = Entity::LINE_SEGMENT;
|
|
|
|
points = 2;
|
|
|
|
break;
|
2008-04-25 12:07:17 +00:00
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case Request::CIRCLE:
|
|
|
|
et = Entity::CIRCLE;
|
|
|
|
points = 1;
|
|
|
|
params = 1;
|
|
|
|
hasNormal = true;
|
2008-05-07 08:19:37 +00:00
|
|
|
hasDistance = true;
|
2008-05-05 06:18:01 +00:00
|
|
|
break;
|
2008-04-19 11:09:47 +00:00
|
|
|
|
2008-05-12 10:01:44 +00:00
|
|
|
case Request::ARC_OF_CIRCLE:
|
|
|
|
et = Entity::ARC_OF_CIRCLE;
|
|
|
|
points = 3;
|
|
|
|
hasNormal = true;
|
|
|
|
break;
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
case Request::CUBIC:
|
|
|
|
et = Entity::CUBIC;
|
|
|
|
points = 4;
|
2008-04-08 12:54:53 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-05 06:18:01 +00:00
|
|
|
default: oops();
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
|
|
|
|
// Generate the entity that's specific to this request.
|
|
|
|
e.type = et;
|
|
|
|
e.group = group;
|
|
|
|
e.workplane = workplane;
|
2008-05-07 04:17:29 +00:00
|
|
|
e.construction = construction;
|
2008-05-05 06:18:01 +00:00
|
|
|
e.h = h.entity(0);
|
|
|
|
|
|
|
|
// And generate entities for the points
|
|
|
|
for(i = 0; i < points; i++) {
|
|
|
|
Entity p;
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
p.workplane = workplane;
|
|
|
|
// points start from entity 1, except for datum point case
|
|
|
|
p.h = h.entity(i+(et ? 1 : 0));
|
|
|
|
p.group = group;
|
|
|
|
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
p.type = Entity::POINT_IN_3D;
|
|
|
|
// params for x y z
|
|
|
|
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));
|
|
|
|
} else {
|
|
|
|
p.type = Entity::POINT_IN_2D;
|
|
|
|
// params for u v
|
|
|
|
p.param[0] = AddParam(param, h.param(16 + 3*i + 0));
|
|
|
|
p.param[1] = AddParam(param, h.param(16 + 3*i + 1));
|
|
|
|
}
|
|
|
|
entity->Add(&p);
|
|
|
|
e.point[i] = p.h;
|
|
|
|
}
|
|
|
|
if(hasNormal) {
|
|
|
|
Entity n;
|
|
|
|
memset(&n, 0, sizeof(n));
|
|
|
|
n.workplane = workplane;
|
2008-05-07 08:19:37 +00:00
|
|
|
n.h = h.entity(32);
|
2008-05-05 06:18:01 +00:00
|
|
|
n.group = group;
|
|
|
|
if(workplane.v == Entity::FREE_IN_3D.v) {
|
|
|
|
n.type = Entity::NORMAL_IN_3D;
|
|
|
|
n.param[0] = AddParam(param, h.param(32+0));
|
|
|
|
n.param[1] = AddParam(param, h.param(32+1));
|
|
|
|
n.param[2] = AddParam(param, h.param(32+2));
|
|
|
|
n.param[3] = AddParam(param, h.param(32+3));
|
|
|
|
} else {
|
|
|
|
n.type = Entity::NORMAL_IN_2D;
|
|
|
|
// and this is just a copy of the workplane quaternion,
|
|
|
|
// so no params required
|
|
|
|
}
|
|
|
|
if(points < 1) oops();
|
|
|
|
// The point determines where the normal gets displayed on-screen;
|
|
|
|
// it's entirely cosmetic.
|
|
|
|
n.point[0] = e.point[0];
|
|
|
|
entity->Add(&n);
|
|
|
|
e.normal = n.h;
|
|
|
|
}
|
2008-05-07 08:19:37 +00:00
|
|
|
if(hasDistance) {
|
|
|
|
Entity d;
|
|
|
|
memset(&d, 0, sizeof(d));
|
|
|
|
d.workplane = workplane;
|
|
|
|
d.h = h.entity(64);
|
|
|
|
d.group = group;
|
|
|
|
d.type = Entity::DISTANCE;
|
|
|
|
d.param[0] = AddParam(param, h.param(64));
|
|
|
|
entity->Add(&d);
|
|
|
|
e.distance = d.h;
|
|
|
|
}
|
2008-05-05 06:18:01 +00:00
|
|
|
// And generate any params not associated with the point that
|
|
|
|
// we happen to need.
|
|
|
|
for(i = 0; i < params; i++) {
|
|
|
|
e.param[i] = AddParam(param, h.param(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(et) entity->Add(&e);
|
2008-04-08 12:54:53 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 14:12:26 +00:00
|
|
|
char *Request::DescriptionString(void) {
|
2008-06-02 09:41:39 +00:00
|
|
|
char *s;
|
|
|
|
if(h.v == Request::HREQUEST_REFERENCE_XY.v) {
|
|
|
|
s = "#XY";
|
|
|
|
} else if(h.v == Request::HREQUEST_REFERENCE_YZ.v) {
|
|
|
|
s = "#YZ";
|
|
|
|
} else if(h.v == Request::HREQUEST_REFERENCE_ZX.v) {
|
|
|
|
s = "#ZX";
|
2008-04-12 14:12:26 +00:00
|
|
|
} else {
|
2008-06-02 09:41:39 +00:00
|
|
|
switch(type) {
|
|
|
|
case WORKPLANE: s = "workplane"; break;
|
|
|
|
case DATUM_POINT: s = "datum-point"; break;
|
|
|
|
case LINE_SEGMENT: s = "line-segment"; break;
|
|
|
|
case CUBIC: s = "cubic-bezier"; break;
|
|
|
|
case CIRCLE: s = "circle"; break;
|
|
|
|
case ARC_OF_CIRCLE: s = "arc-of-circle"; break;
|
|
|
|
default: s = "???"; break;
|
|
|
|
}
|
2008-04-12 14:12:26 +00:00
|
|
|
}
|
2008-06-02 09:41:39 +00:00
|
|
|
static char ret[100];
|
|
|
|
sprintf(ret, "r%03x-%s", h.v, s);
|
2008-04-12 14:12:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|