2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Routines to generate our watertight brep shells from the operations
|
|
|
|
// and entities specified by the user in each group; templated to work either
|
|
|
|
// on an SShell of ratpoly surfaces or on an SMesh of triangles.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-06-06 08:14:37 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
|
|
|
#define gs (SS.GW.gs)
|
|
|
|
|
2009-12-03 19:14:34 +00:00
|
|
|
void Group::AssembleLoops(bool *allClosed,
|
|
|
|
bool *allCoplanar,
|
|
|
|
bool *allNonZeroLen)
|
|
|
|
{
|
2009-01-19 03:51:00 +00:00
|
|
|
SBezierList sbl;
|
|
|
|
ZERO(&sbl);
|
2009-01-19 03:33:15 +00:00
|
|
|
|
2008-02-10 12:43:48 +00:00
|
|
|
int i;
|
2009-04-19 05:53:16 +00:00
|
|
|
for(i = 0; i < SK.entity.n; i++) {
|
|
|
|
Entity *e = &(SK.entity.elem[i]);
|
2008-02-10 12:43:48 +00:00
|
|
|
if(e->group.v != h.v) continue;
|
2009-01-19 03:33:15 +00:00
|
|
|
if(e->construction) continue;
|
2009-06-14 04:36:38 +00:00
|
|
|
if(e->forceHidden) continue;
|
2008-02-10 12:43:48 +00:00
|
|
|
|
2009-01-19 03:51:00 +00:00
|
|
|
e->GenerateBezierCurves(&sbl);
|
2008-02-10 12:43:48 +00:00
|
|
|
}
|
2009-01-19 03:33:15 +00:00
|
|
|
|
2009-12-03 19:14:34 +00:00
|
|
|
SBezier *sb;
|
|
|
|
*allNonZeroLen = true;
|
|
|
|
for(sb = sbl.l.First(); sb; sb = sbl.l.NextAfter(sb)) {
|
|
|
|
for(i = 1; i <= sb->deg; i++) {
|
|
|
|
if(!(sb->ctrl[i]).Equals(sb->ctrl[0])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i > sb->deg) {
|
|
|
|
// This is a zero-length edge.
|
|
|
|
*allNonZeroLen = false;
|
|
|
|
polyError.errorPointAt = sb->ctrl[0];
|
2013-09-19 04:33:12 +00:00
|
|
|
goto done;
|
2009-12-03 19:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-29 07:16:28 +00:00
|
|
|
// Try to assemble all these Beziers into loops. The closed loops go into
|
|
|
|
// bezierLoops, with the outer loops grouped with their holes. The
|
|
|
|
// leftovers, if any, go in bezierOpens.
|
|
|
|
bezierLoops.FindOuterFacesFrom(&sbl, &polyLoops, NULL,
|
|
|
|
SS.ChordTolMm(),
|
|
|
|
allClosed, &(polyError.notClosedAt),
|
|
|
|
allCoplanar, &(polyError.errorPointAt),
|
|
|
|
&bezierOpens);
|
2013-09-19 04:33:12 +00:00
|
|
|
done:
|
2009-01-19 03:51:00 +00:00
|
|
|
sbl.Clear();
|
2008-02-10 12:43:48 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 03:33:15 +00:00
|
|
|
void Group::GenerateLoops(void) {
|
2009-10-29 07:16:28 +00:00
|
|
|
polyLoops.Clear();
|
|
|
|
bezierLoops.Clear();
|
|
|
|
bezierOpens.Clear();
|
2008-06-06 08:14:37 +00:00
|
|
|
|
|
|
|
if(type == DRAWING_3D || type == DRAWING_WORKPLANE ||
|
2008-02-13 16:15:33 +00:00
|
|
|
type == ROTATE || type == TRANSLATE || type == IMPORTED)
|
2008-06-06 08:14:37 +00:00
|
|
|
{
|
2013-09-16 20:22:14 +00:00
|
|
|
bool allClosed = false, allCoplanar = false, allNonZeroLen = false;
|
2009-12-03 19:14:34 +00:00
|
|
|
AssembleLoops(&allClosed, &allCoplanar, &allNonZeroLen);
|
2009-10-29 07:16:28 +00:00
|
|
|
if(!allCoplanar) {
|
|
|
|
polyError.how = POLY_NOT_COPLANAR;
|
|
|
|
} else if(!allClosed) {
|
|
|
|
polyError.how = POLY_NOT_CLOSED;
|
2009-12-03 19:14:34 +00:00
|
|
|
} else if(!allNonZeroLen) {
|
|
|
|
polyError.how = POLY_ZERO_LEN_EDGE;
|
2009-10-29 07:16:28 +00:00
|
|
|
} else {
|
2008-06-12 04:36:33 +00:00
|
|
|
polyError.how = POLY_GOOD;
|
2009-10-29 07:16:28 +00:00
|
|
|
// The self-intersecting check is kind of slow, so don't run it
|
|
|
|
// unless requested.
|
|
|
|
if(SS.checkClosedContour) {
|
|
|
|
if(polyLoops.SelfIntersecting(&(polyError.errorPointAt))) {
|
|
|
|
polyError.how = POLY_SELF_INTERSECTING;
|
|
|
|
}
|
2009-01-23 03:30:30 +00:00
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 11:37:07 +00:00
|
|
|
void SShell::RemapFaces(Group *g, int remap) {
|
|
|
|
SSurface *ss;
|
|
|
|
for(ss = surface.First(); ss; ss = surface.NextAfter(ss)){
|
|
|
|
hEntity face = { ss->face };
|
|
|
|
if(face.v == Entity::NO_ENTITY.v) continue;
|
|
|
|
|
|
|
|
face = g->Remap(face, remap);
|
|
|
|
ss->face = face.v;
|
|
|
|
}
|
|
|
|
}
|
2008-06-21 22:49:57 +00:00
|
|
|
|
2009-05-24 11:37:07 +00:00
|
|
|
void SMesh::RemapFaces(Group *g, int remap) {
|
|
|
|
STriangle *tr;
|
|
|
|
for(tr = l.First(); tr; tr = l.NextAfter(tr)) {
|
|
|
|
hEntity face = { tr->meta.face };
|
|
|
|
if(face.v == Entity::NO_ENTITY.v) continue;
|
|
|
|
|
|
|
|
face = g->Remap(face, remap);
|
|
|
|
tr->meta.face = face.v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2009-07-20 01:47:59 +00:00
|
|
|
void Group::GenerateForStepAndRepeat(T *steps, T *outs) {
|
2009-05-24 11:37:07 +00:00
|
|
|
T workA, workB;
|
2009-03-15 23:04:45 +00:00
|
|
|
ZERO(&workA);
|
|
|
|
ZERO(&workB);
|
2009-05-24 11:37:07 +00:00
|
|
|
T *soFar = &workA, *scratch = &workB;
|
2009-03-15 23:04:45 +00:00
|
|
|
|
2008-06-21 22:49:57 +00:00
|
|
|
int n = (int)valA, a0 = 0;
|
|
|
|
if(subtype == ONE_SIDED && skipFirst) {
|
|
|
|
a0++; n++;
|
|
|
|
}
|
|
|
|
int a;
|
|
|
|
for(a = a0; a < n; a++) {
|
|
|
|
int ap = a*2 - (subtype == ONE_SIDED ? 0 : (n-1));
|
|
|
|
int remap = (a == (n - 1)) ? REMAP_LAST : a;
|
|
|
|
|
2009-05-24 11:37:07 +00:00
|
|
|
T transd;
|
2009-03-15 23:04:45 +00:00
|
|
|
ZERO(&transd);
|
2008-06-21 22:49:57 +00:00
|
|
|
if(type == TRANSLATE) {
|
|
|
|
Vector trans = Vector::From(h.param(0), h.param(1), h.param(2));
|
|
|
|
trans = trans.ScaledBy(ap);
|
2009-10-09 12:57:10 +00:00
|
|
|
transd.MakeFromTransformationOf(steps,
|
2009-12-15 12:26:22 +00:00
|
|
|
trans, Quaternion::IDENTITY, 1.0);
|
2008-06-21 22:49:57 +00:00
|
|
|
} else {
|
|
|
|
Vector trans = Vector::From(h.param(0), h.param(1), h.param(2));
|
2009-04-19 05:53:16 +00:00
|
|
|
double theta = ap * SK.GetParam(h.param(3))->val;
|
2008-06-21 22:49:57 +00:00
|
|
|
double c = cos(theta), s = sin(theta);
|
|
|
|
Vector axis = Vector::From(h.param(4), h.param(5), h.param(6));
|
|
|
|
Quaternion q = Quaternion::From(c, s*axis.x, s*axis.y, s*axis.z);
|
2009-03-15 23:04:45 +00:00
|
|
|
// Rotation is centered at t; so A(x - t) + t = Ax + (t - At)
|
2009-05-24 11:37:07 +00:00
|
|
|
transd.MakeFromTransformationOf(steps,
|
2009-12-15 12:26:22 +00:00
|
|
|
trans.Minus(q.Rotate(trans)), q, 1.0);
|
2008-06-21 22:49:57 +00:00
|
|
|
}
|
|
|
|
|
2009-03-16 05:11:06 +00:00
|
|
|
// We need to rewrite any plane face entities to the transformed ones.
|
2009-05-24 11:37:07 +00:00
|
|
|
transd.RemapFaces(this, remap);
|
2009-03-16 05:11:06 +00:00
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
// And tack this transformed copy on to the return.
|
|
|
|
if(soFar->IsEmpty()) {
|
|
|
|
scratch->MakeFromCopyOf(&transd);
|
2009-05-20 03:04:36 +00:00
|
|
|
} else {
|
2009-07-20 01:47:59 +00:00
|
|
|
scratch->MakeFromUnionOf(soFar, &transd);
|
2008-06-21 22:49:57 +00:00
|
|
|
}
|
2009-03-15 23:04:45 +00:00
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
SWAP(T *, scratch, soFar);
|
2009-03-15 23:04:45 +00:00
|
|
|
scratch->Clear();
|
|
|
|
transd.Clear();
|
2008-06-21 22:49:57 +00:00
|
|
|
}
|
2009-03-15 23:04:45 +00:00
|
|
|
|
2009-05-24 11:37:07 +00:00
|
|
|
outs->Clear();
|
|
|
|
*outs = *soFar;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2009-07-20 01:47:59 +00:00
|
|
|
void Group::GenerateForBoolean(T *prevs, T *thiss, T *outs, int how) {
|
2009-05-24 11:37:07 +00:00
|
|
|
// If this group contributes no new mesh, then our running mesh is the
|
|
|
|
// same as last time, no combining required. Likewise if we have a mesh
|
|
|
|
// but it's suppressed.
|
|
|
|
if(thiss->IsEmpty() || suppress) {
|
|
|
|
outs->MakeFromCopyOf(prevs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// So our group's shell appears in thisShell. Combine this with the
|
|
|
|
// previous group's shell, using the requested operation.
|
2009-07-20 01:47:59 +00:00
|
|
|
if(how == COMBINE_AS_UNION) {
|
2009-05-24 11:37:07 +00:00
|
|
|
outs->MakeFromUnionOf(prevs, thiss);
|
2009-07-20 01:47:59 +00:00
|
|
|
} else if(how == COMBINE_AS_DIFFERENCE) {
|
2009-05-24 11:37:07 +00:00
|
|
|
outs->MakeFromDifferenceOf(prevs, thiss);
|
|
|
|
} else {
|
|
|
|
outs->MakeFromAssemblyOf(prevs, thiss);
|
|
|
|
}
|
2008-06-21 22:49:57 +00:00
|
|
|
}
|
|
|
|
|
2009-05-30 08:49:09 +00:00
|
|
|
void Group::GenerateShellAndMesh(void) {
|
|
|
|
bool prevBooleanFailed = booleanFailed;
|
|
|
|
booleanFailed = false;
|
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
Group *srcg = this;
|
|
|
|
|
2009-01-19 10:37:10 +00:00
|
|
|
thisShell.Clear();
|
2009-05-24 11:37:07 +00:00
|
|
|
thisMesh.Clear();
|
|
|
|
runningShell.Clear();
|
|
|
|
runningMesh.Clear();
|
2008-06-21 10:18:20 +00:00
|
|
|
|
2009-10-29 07:16:28 +00:00
|
|
|
// Don't attempt a lathe or extrusion unless the source section is good:
|
|
|
|
// planar and not self-intersecting.
|
|
|
|
bool haveSrc = true;
|
|
|
|
if(type == EXTRUDE || type == LATHE) {
|
|
|
|
Group *src = SK.GetGroup(opA);
|
|
|
|
if(src->polyError.how != POLY_GOOD) {
|
|
|
|
haveSrc = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-21 22:49:57 +00:00
|
|
|
if(type == TRANSLATE || type == ROTATE) {
|
2009-07-20 01:47:59 +00:00
|
|
|
// A step and repeat gets merged against the group's prevous group,
|
|
|
|
// not our own previous group.
|
|
|
|
srcg = SK.GetGroup(opA);
|
2009-05-24 11:37:07 +00:00
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
GenerateForStepAndRepeat<SShell>(&(srcg->thisShell), &thisShell);
|
|
|
|
GenerateForStepAndRepeat<SMesh> (&(srcg->thisMesh), &thisMesh);
|
2009-10-29 07:16:28 +00:00
|
|
|
} else if(type == EXTRUDE && haveSrc) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *src = SK.GetGroup(opA);
|
2008-06-06 08:14:37 +00:00
|
|
|
Vector translate = Vector::From(h.param(0), h.param(1), h.param(2));
|
|
|
|
|
|
|
|
Vector tbot, ttop;
|
|
|
|
if(subtype == ONE_SIDED) {
|
|
|
|
tbot = Vector::From(0, 0, 0); ttop = translate.ScaledBy(2);
|
|
|
|
} else {
|
|
|
|
tbot = translate.ScaledBy(-1); ttop = translate.ScaledBy(1);
|
|
|
|
}
|
2009-10-29 07:16:28 +00:00
|
|
|
|
|
|
|
SBezierLoopSetSet *sblss = &(src->bezierLoops);
|
|
|
|
SBezierLoopSet *sbls;
|
|
|
|
for(sbls = sblss->l.First(); sbls; sbls = sblss->l.NextAfter(sbls)) {
|
|
|
|
int is = thisShell.surface.n;
|
|
|
|
// Extrude this outer contour (plus its inner contours, if present)
|
|
|
|
thisShell.MakeFromExtrusionOf(sbls, tbot, ttop, color);
|
|
|
|
|
|
|
|
// And for any plane faces, annotate the model with the entity for
|
|
|
|
// that face, so that the user can select them with the mouse.
|
|
|
|
Vector onOrig = sbls->point;
|
|
|
|
int i;
|
|
|
|
for(i = is; i < thisShell.surface.n; i++) {
|
|
|
|
SSurface *ss = &(thisShell.surface.elem[i]);
|
|
|
|
hEntity face = Entity::NO_ENTITY;
|
|
|
|
|
|
|
|
Vector p = ss->PointAt(0, 0),
|
|
|
|
n = ss->NormalAt(0, 0).WithMagnitude(1);
|
|
|
|
double d = n.Dot(p);
|
|
|
|
|
|
|
|
if(i == is || i == (is + 1)) {
|
|
|
|
// These are the top and bottom of the shell.
|
|
|
|
if(fabs((onOrig.Plus(ttop)).Dot(n) - d) < LENGTH_EPS) {
|
|
|
|
face = Remap(Entity::NO_ENTITY, REMAP_TOP);
|
|
|
|
ss->face = face.v;
|
|
|
|
}
|
|
|
|
if(fabs((onOrig.Plus(tbot)).Dot(n) - d) < LENGTH_EPS) {
|
|
|
|
face = Remap(Entity::NO_ENTITY, REMAP_BOTTOM);
|
|
|
|
ss->face = face.v;
|
|
|
|
}
|
|
|
|
continue;
|
2009-03-15 23:04:45 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 07:16:28 +00:00
|
|
|
// So these are the sides
|
|
|
|
if(ss->degm != 1 || ss->degn != 1) continue;
|
|
|
|
|
|
|
|
Entity *e;
|
|
|
|
for(e = SK.entity.First(); e; e = SK.entity.NextAfter(e)) {
|
|
|
|
if(e->group.v != opA.v) continue;
|
|
|
|
if(e->type != Entity::LINE_SEGMENT) continue;
|
|
|
|
|
|
|
|
Vector a = SK.GetEntity(e->point[0])->PointGetNum(),
|
|
|
|
b = SK.GetEntity(e->point[1])->PointGetNum();
|
|
|
|
a = a.Plus(ttop);
|
|
|
|
b = b.Plus(ttop);
|
|
|
|
// Could get taken backwards, so check all cases.
|
|
|
|
if((a.Equals(ss->ctrl[0][0]) && b.Equals(ss->ctrl[1][0])) ||
|
|
|
|
(b.Equals(ss->ctrl[0][0]) && a.Equals(ss->ctrl[1][0])) ||
|
|
|
|
(a.Equals(ss->ctrl[0][1]) && b.Equals(ss->ctrl[1][1])) ||
|
|
|
|
(b.Equals(ss->ctrl[0][1]) && a.Equals(ss->ctrl[1][1])))
|
|
|
|
{
|
|
|
|
face = Remap(e->h, REMAP_LINE_TO_FACE);
|
|
|
|
ss->face = face.v;
|
|
|
|
break;
|
|
|
|
}
|
2009-03-15 23:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-29 07:16:28 +00:00
|
|
|
} else if(type == LATHE && haveSrc) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *src = SK.GetGroup(opA);
|
2008-06-06 11:35:28 +00:00
|
|
|
|
2009-04-29 02:42:44 +00:00
|
|
|
Vector pt = SK.GetEntity(predef.origin)->PointGetNum(),
|
|
|
|
axis = SK.GetEntity(predef.entityB)->VectorGetNum();
|
2008-06-06 11:35:28 +00:00
|
|
|
axis = axis.WithMagnitude(1);
|
|
|
|
|
2009-10-29 07:16:28 +00:00
|
|
|
SBezierLoopSetSet *sblss = &(src->bezierLoops);
|
|
|
|
SBezierLoopSet *sbls;
|
|
|
|
for(sbls = sblss->l.First(); sbls; sbls = sblss->l.NextAfter(sbls)) {
|
|
|
|
thisShell.MakeFromRevolutionOf(sbls, pt, axis, color);
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
} else if(type == IMPORTED) {
|
2009-05-19 07:26:38 +00:00
|
|
|
// The imported shell or mesh are copied over, with the appropriate
|
|
|
|
// transformation applied. We also must remap the face entities.
|
2008-06-06 08:14:37 +00:00
|
|
|
Vector offset = {
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetParam(h.param(0))->val,
|
|
|
|
SK.GetParam(h.param(1))->val,
|
|
|
|
SK.GetParam(h.param(2))->val };
|
2008-06-06 08:14:37 +00:00
|
|
|
Quaternion q = {
|
2009-04-19 05:53:16 +00:00
|
|
|
SK.GetParam(h.param(3))->val,
|
|
|
|
SK.GetParam(h.param(4))->val,
|
|
|
|
SK.GetParam(h.param(5))->val,
|
|
|
|
SK.GetParam(h.param(6))->val };
|
2008-06-06 08:14:37 +00:00
|
|
|
|
2009-12-15 12:26:22 +00:00
|
|
|
thisMesh.MakeFromTransformationOf(&impMesh, offset, q, scale);
|
2009-05-24 11:37:07 +00:00
|
|
|
thisMesh.RemapFaces(this, 0);
|
2009-05-19 07:26:38 +00:00
|
|
|
|
2009-12-15 12:26:22 +00:00
|
|
|
thisShell.MakeFromTransformationOf(&impShell, offset, q, scale);
|
2009-05-24 11:37:07 +00:00
|
|
|
thisShell.RemapFaces(this, 0);
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
if(srcg->meshCombine != COMBINE_AS_ASSEMBLE) {
|
2009-06-06 08:21:03 +00:00
|
|
|
thisShell.MergeCoincidentSurfaces();
|
|
|
|
}
|
2009-06-05 05:38:41 +00:00
|
|
|
|
2009-05-24 11:37:07 +00:00
|
|
|
// So now we've got the mesh or shell for this group. Combine it with
|
|
|
|
// the previous group's mesh or shell with the requested Boolean, and
|
|
|
|
// we're done.
|
2008-06-21 22:49:57 +00:00
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
Group *prevg = srcg->RunningMeshGroup();
|
2009-06-06 08:21:03 +00:00
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
if(prevg->runningMesh.IsEmpty() && thisMesh.IsEmpty() && !forceToMesh) {
|
|
|
|
SShell *prevs = &(prevg->runningShell);
|
|
|
|
GenerateForBoolean<SShell>(prevs, &thisShell, &runningShell,
|
|
|
|
srcg->meshCombine);
|
|
|
|
|
|
|
|
if(srcg->meshCombine != COMBINE_AS_ASSEMBLE) {
|
2009-06-06 08:21:03 +00:00
|
|
|
runningShell.MergeCoincidentSurfaces();
|
|
|
|
}
|
2009-05-30 08:49:09 +00:00
|
|
|
|
|
|
|
// If the Boolean failed, then we should note that in the text screen
|
|
|
|
// for this group.
|
|
|
|
booleanFailed = runningShell.booleanFailed;
|
|
|
|
if(booleanFailed != prevBooleanFailed) {
|
|
|
|
SS.later.showTW = true;
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
} else {
|
2009-05-24 11:37:07 +00:00
|
|
|
SMesh prevm, thism;
|
|
|
|
ZERO(&prevm);
|
|
|
|
ZERO(&thism);
|
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
prevm.MakeFromCopyOf(&(prevg->runningMesh));
|
|
|
|
prevg->runningShell.TriangulateInto(&prevm);
|
2009-05-24 11:37:07 +00:00
|
|
|
|
|
|
|
thism.MakeFromCopyOf(&thisMesh);
|
|
|
|
thisShell.TriangulateInto(&thism);
|
|
|
|
|
2009-05-28 07:07:54 +00:00
|
|
|
SMesh outm;
|
|
|
|
ZERO(&outm);
|
2009-07-20 01:47:59 +00:00
|
|
|
GenerateForBoolean<SMesh>(&prevm, &thism, &outm, srcg->meshCombine);
|
2009-05-28 07:07:54 +00:00
|
|
|
|
|
|
|
// And make sure that the output mesh is vertex-to-vertex.
|
|
|
|
SKdNode *root = SKdNode::From(&outm);
|
|
|
|
root->SnapToMesh(&outm);
|
|
|
|
root->MakeMeshInto(&runningMesh);
|
2009-05-24 11:37:07 +00:00
|
|
|
|
2009-05-28 07:07:54 +00:00
|
|
|
outm.Clear();
|
2009-05-24 11:37:07 +00:00
|
|
|
thism.Clear();
|
|
|
|
prevm.Clear();
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
2008-07-06 07:56:24 +00:00
|
|
|
|
2009-05-21 09:06:26 +00:00
|
|
|
displayDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::GenerateDisplayItems(void) {
|
2009-05-29 05:40:17 +00:00
|
|
|
// This is potentially slow (since we've got to triangulate a shell, or
|
|
|
|
// to find the emphasized edges for a mesh), so we will run it only
|
|
|
|
// if its inputs have changed.
|
2009-05-21 09:06:26 +00:00
|
|
|
if(displayDirty) {
|
2009-10-08 07:55:09 +00:00
|
|
|
Group *pg = RunningMeshGroup();
|
|
|
|
if(pg && thisMesh.IsEmpty() && thisShell.IsEmpty()) {
|
|
|
|
// We don't contribute any new solid model in this group, so our
|
|
|
|
// display items are identical to the previous group's; which means
|
|
|
|
// that we can just display those, and stop ourselves from
|
|
|
|
// recalculating for those every time we get a change in this group.
|
|
|
|
//
|
|
|
|
// Note that this can end up recursing multiple times (if multiple
|
|
|
|
// groups that contribute no solid model exist in sequence), but
|
|
|
|
// that's okay.
|
|
|
|
pg->GenerateDisplayItems();
|
|
|
|
|
|
|
|
displayMesh.Clear();
|
|
|
|
displayMesh.MakeFromCopyOf(&(pg->displayMesh));
|
|
|
|
|
|
|
|
displayEdges.Clear();
|
|
|
|
if(SS.GW.showEdges) {
|
|
|
|
SEdge *se;
|
|
|
|
SEdgeList *src = &(pg->displayEdges);
|
|
|
|
for(se = src->l.First(); se; se = src->l.NextAfter(se)) {
|
|
|
|
displayEdges.l.Add(se);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We do contribute new solid model, so we have to triangulate the
|
|
|
|
// shell, and edge-find the mesh.
|
|
|
|
displayMesh.Clear();
|
|
|
|
runningShell.TriangulateInto(&displayMesh);
|
|
|
|
STriangle *t;
|
|
|
|
for(t = runningMesh.l.First(); t; t = runningMesh.l.NextAfter(t)) {
|
|
|
|
STriangle trn = *t;
|
|
|
|
Vector n = trn.Normal();
|
|
|
|
trn.an = n;
|
|
|
|
trn.bn = n;
|
|
|
|
trn.cn = n;
|
|
|
|
displayMesh.AddTriangle(&trn);
|
|
|
|
}
|
2009-05-24 11:37:07 +00:00
|
|
|
|
2009-10-08 07:55:09 +00:00
|
|
|
displayEdges.Clear();
|
2009-05-29 05:40:17 +00:00
|
|
|
|
2009-10-08 07:55:09 +00:00
|
|
|
if(SS.GW.showEdges) {
|
|
|
|
runningShell.MakeEdgesInto(&displayEdges);
|
|
|
|
runningMesh.MakeEmphasizedEdgesInto(&displayEdges);
|
|
|
|
}
|
2009-05-29 05:40:17 +00:00
|
|
|
}
|
2009-05-24 11:37:07 +00:00
|
|
|
|
2009-05-21 09:06:26 +00:00
|
|
|
displayDirty = false;
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 10:02:02 +00:00
|
|
|
Group *Group::PreviousGroup(void) {
|
2008-06-06 08:14:37 +00:00
|
|
|
int i;
|
2009-04-19 05:53:16 +00:00
|
|
|
for(i = 0; i < SK.group.n; i++) {
|
|
|
|
Group *g = &(SK.group.elem[i]);
|
2008-06-06 08:14:37 +00:00
|
|
|
if(g->h.v == h.v) break;
|
|
|
|
}
|
2009-06-30 07:24:36 +00:00
|
|
|
if(i == 0 || i >= SK.group.n) return NULL;
|
2009-05-22 10:02:02 +00:00
|
|
|
return &(SK.group.elem[i-1]);
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|
2009-07-20 01:47:59 +00:00
|
|
|
Group *Group::RunningMeshGroup(void) {
|
|
|
|
if(type == TRANSLATE || type == ROTATE) {
|
|
|
|
return SK.GetGroup(opA)->RunningMeshGroup();
|
|
|
|
} else {
|
|
|
|
return PreviousGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 07:24:36 +00:00
|
|
|
void Group::DrawDisplayItems(int t) {
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
RgbColor specColor;
|
2009-06-30 07:24:36 +00:00
|
|
|
if(t == DRAWING_3D || t == DRAWING_WORKPLANE) {
|
2009-09-17 07:32:36 +00:00
|
|
|
// force the color to something dim
|
|
|
|
specColor = Style::Color(Style::DIM_SOLID);
|
2008-06-06 08:14:37 +00:00
|
|
|
} else {
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
specColor = RgbColor::Default(); // use the model color
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
// The back faces are drawn in red; should never seem them, since we
|
|
|
|
// draw closed shells, so that's a debugging aid.
|
2013-10-19 05:36:45 +00:00
|
|
|
GLfloat mpb[] = { 1.0f, 0.1f, 0.1f, 1.0f };
|
2008-06-06 08:14:37 +00:00
|
|
|
glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE, mpb);
|
|
|
|
|
|
|
|
// When we fill the mesh, we need to know which triangles are selected
|
|
|
|
// or hovered, in order to draw them differently.
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t mh = 0, ms1 = 0, ms2 = 0;
|
2008-06-06 08:14:37 +00:00
|
|
|
hEntity he = SS.GW.hover.entity;
|
2009-04-19 05:53:16 +00:00
|
|
|
if(he.v != 0 && SK.GetEntity(he)->IsFace()) {
|
2008-06-06 08:14:37 +00:00
|
|
|
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-07-06 07:56:24 +00:00
|
|
|
if(SS.GW.showShaded) {
|
|
|
|
glEnable(GL_LIGHTING);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglFillMesh(specColor, &displayMesh, mh, ms1, ms2);
|
2008-07-06 07:56:24 +00:00
|
|
|
glDisable(GL_LIGHTING);
|
2009-03-18 04:26:04 +00:00
|
|
|
}
|
|
|
|
if(SS.GW.showEdges) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(2);
|
|
|
|
ssglColorRGB(Style::Color(Style::SOLID_EDGE));
|
2009-09-17 07:32:36 +00:00
|
|
|
glLineWidth(Style::Width(Style::SOLID_EDGE));
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDrawEdges(&displayEdges, false);
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
if(SS.GW.showMesh) ssglDebugMesh(&displayMesh);
|
2009-06-30 07:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Group::Draw(void) {
|
|
|
|
// Everything here gets drawn whether or not the group is hidden; we
|
|
|
|
// can control this stuff independently, with show/hide solids, edges,
|
|
|
|
// mesh, etc.
|
|
|
|
|
2009-10-08 07:55:09 +00:00
|
|
|
GenerateDisplayItems();
|
|
|
|
DrawDisplayItems(type);
|
2008-06-06 08:14:37 +00:00
|
|
|
|
2009-10-01 10:35:11 +00:00
|
|
|
if(!SS.checkClosedContour) return;
|
|
|
|
|
|
|
|
// And finally show the polygons too, and any errors if it's not possible
|
|
|
|
// to assemble the lines into closed polygons.
|
2008-06-12 04:36:33 +00:00
|
|
|
if(polyError.how == POLY_NOT_CLOSED) {
|
2008-07-13 09:57:46 +00:00
|
|
|
// Report this error only in sketch-in-workplane groups; otherwise
|
|
|
|
// it's just a nuisance.
|
|
|
|
if(type == DRAWING_WORKPLANE) {
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGBa(Style::Color(Style::DRAW_ERROR), 0.2);
|
2009-09-17 07:32:36 +00:00
|
|
|
glLineWidth (Style::Width(Style::DRAW_ERROR));
|
2008-07-13 09:57:46 +00:00
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(polyError.notClosedAt.a);
|
|
|
|
ssglVertex3v(polyError.notClosedAt.b);
|
2008-07-13 09:57:46 +00:00
|
|
|
glEnd();
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(Style::Color(Style::DRAW_ERROR));
|
|
|
|
ssglWriteText("not closed contour, or not all same style!",
|
2009-10-30 10:38:34 +00:00
|
|
|
DEFAULT_TEXT_HEIGHT,
|
2009-07-03 20:55:57 +00:00
|
|
|
polyError.notClosedAt.b, SS.GW.projRight, SS.GW.projUp,
|
|
|
|
NULL, NULL);
|
2008-07-13 09:57:46 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
}
|
2009-01-23 03:30:30 +00:00
|
|
|
} else if(polyError.how == POLY_NOT_COPLANAR ||
|
2009-12-03 19:14:34 +00:00
|
|
|
polyError.how == POLY_SELF_INTERSECTING ||
|
|
|
|
polyError.how == POLY_ZERO_LEN_EDGE)
|
2009-01-23 03:30:30 +00:00
|
|
|
{
|
|
|
|
// These errors occur at points, not lines
|
2008-07-13 09:57:46 +00:00
|
|
|
if(type == DRAWING_WORKPLANE) {
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(Style::Color(Style::DRAW_ERROR));
|
2013-08-26 18:58:35 +00:00
|
|
|
const char *msg;
|
2009-12-03 19:14:34 +00:00
|
|
|
if(polyError.how == POLY_NOT_COPLANAR) {
|
|
|
|
msg = "points not all coplanar!";
|
|
|
|
} else if(polyError.how == POLY_SELF_INTERSECTING) {
|
|
|
|
msg = "contour is self-intersecting!";
|
|
|
|
} else {
|
|
|
|
msg = "zero-length edge!";
|
|
|
|
}
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglWriteText(msg, DEFAULT_TEXT_HEIGHT,
|
2009-07-03 20:55:57 +00:00
|
|
|
polyError.errorPointAt, SS.GW.projRight, SS.GW.projUp,
|
|
|
|
NULL, NULL);
|
2008-07-13 09:57:46 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
} else {
|
2009-10-29 07:16:28 +00:00
|
|
|
// The contours will get filled in DrawFilledPaths.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::FillLoopSetAsPolygon(SBezierLoopSet *sbls) {
|
|
|
|
SPolygon sp;
|
|
|
|
ZERO(&sp);
|
|
|
|
sbls->MakePwlInto(&sp);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(1);
|
|
|
|
ssglFillPolygon(&sp);
|
|
|
|
ssglDepthRangeOffset(0);
|
2009-10-29 07:16:28 +00:00
|
|
|
sp.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Group::DrawFilledPaths(void) {
|
|
|
|
SBezierLoopSet *sbls;
|
|
|
|
SBezierLoopSetSet *sblss = &bezierLoops;
|
|
|
|
for(sbls = sblss->l.First(); sbls; sbls = sblss->l.NextAfter(sbls)) {
|
2009-10-30 10:38:34 +00:00
|
|
|
if(sbls->l.n == 0 || sbls->l.elem[0].l.n == 0) continue;
|
|
|
|
// In an assembled loop, all the styles should be the same; so doesn't
|
|
|
|
// matter which one we grab.
|
|
|
|
SBezier *sb = &(sbls->l.elem[0].l.elem[0]);
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
hStyle hs = { (uint32_t)sb->auxA };
|
2009-10-30 10:38:34 +00:00
|
|
|
Style *s = Style::Get(hs);
|
|
|
|
if(s->filled) {
|
|
|
|
// This is a filled loop, where the user specified a fill color.
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGBa(s->fillColor, 1);
|
2009-10-29 07:16:28 +00:00
|
|
|
FillLoopSetAsPolygon(sbls);
|
|
|
|
} else {
|
|
|
|
if(h.v == SS.GW.activeGroup.v && SS.checkClosedContour &&
|
|
|
|
polyError.how == POLY_GOOD)
|
|
|
|
{
|
|
|
|
// If this is the active group, and we are supposed to check
|
|
|
|
// for closed contours, and we do indeed have a closed and
|
|
|
|
// non-intersecting contour, then fill it dimly.
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGBa(Style::Color(Style::CONTOUR_FILL), 0.5);
|
|
|
|
ssglDepthRangeOffset(1);
|
2009-10-29 07:16:28 +00:00
|
|
|
FillLoopSetAsPolygon(sbls);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(0);
|
2009-10-29 07:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-06 08:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|