From 8e484beec10ece94fcf926c48915c76d0f9975c6 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 3 Dec 2009 11:14:34 -0800 Subject: [PATCH] Add a warning when zero-length edges appear in the sketch, since those screw a lot of things up. And add data structure for clipboard entities, though no code yet. [git-p4: depot-paths = "//depot/solvespace/": change = 2082] --- groupmesh.cpp | 41 ++++++++++++++++++++++++++++++++++------- sketch.h | 18 ++++++++++++++++-- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/groupmesh.cpp b/groupmesh.cpp index 62c04bd..d770ce1 100644 --- a/groupmesh.cpp +++ b/groupmesh.cpp @@ -2,7 +2,10 @@ #define gs (SS.GW.gs) -void Group::AssembleLoops(bool *allClosed, bool *allCoplanar) { +void Group::AssembleLoops(bool *allClosed, + bool *allCoplanar, + bool *allNonZeroLen) +{ SBezierList sbl; ZERO(&sbl); @@ -16,6 +19,22 @@ void Group::AssembleLoops(bool *allClosed, bool *allCoplanar) { e->GenerateBezierCurves(&sbl); } + 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]; + return; + } + } + // 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. @@ -35,12 +54,14 @@ void Group::GenerateLoops(void) { if(type == DRAWING_3D || type == DRAWING_WORKPLANE || type == ROTATE || type == TRANSLATE || type == IMPORTED) { - bool allClosed, allCoplanar; - AssembleLoops(&allClosed, &allCoplanar); + bool allClosed, allCoplanar, allNonZeroLen; + AssembleLoops(&allClosed, &allCoplanar, &allNonZeroLen); if(!allCoplanar) { polyError.how = POLY_NOT_COPLANAR; } else if(!allClosed) { polyError.how = POLY_NOT_CLOSED; + } else if(!allNonZeroLen) { + polyError.how = POLY_ZERO_LEN_EDGE; } else { polyError.how = POLY_GOOD; // The self-intersecting check is kind of slow, so don't run it @@ -474,15 +495,21 @@ void Group::Draw(void) { glEnable(GL_DEPTH_TEST); } } else if(polyError.how == POLY_NOT_COPLANAR || - polyError.how == POLY_SELF_INTERSECTING) + polyError.how == POLY_SELF_INTERSECTING || + polyError.how == POLY_ZERO_LEN_EDGE) { // These errors occur at points, not lines if(type == DRAWING_WORKPLANE) { glDisable(GL_DEPTH_TEST); glxColorRGB(Style::Color(Style::DRAW_ERROR)); - char *msg = (polyError.how == POLY_NOT_COPLANAR) ? - "points not all coplanar!" : - "contour is self-intersecting!"; + char *msg; + 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!"; + } glxWriteText(msg, DEFAULT_TEXT_HEIGHT, polyError.errorPointAt, SS.GW.projRight, SS.GW.projUp, NULL, NULL); diff --git a/sketch.h b/sketch.h index 30b9a0c..f12b241 100644 --- a/sketch.h +++ b/sketch.h @@ -148,6 +148,7 @@ public: static const int POLY_NOT_CLOSED = 1; static const int POLY_NOT_COPLANAR = 2; static const int POLY_SELF_INTERSECTING = 3; + static const int POLY_ZERO_LEN_EDGE = 4; struct { int how; SEdge notClosedAt; @@ -216,7 +217,7 @@ public: // Assembling the curves into loops, and into a piecewise linear polygon // at the same time. - void AssembleLoops(bool *allClosed, bool *allCoplanar); + void AssembleLoops(bool *allClosed, bool *allCoplanar, bool *allNonZeroLen); void GenerateLoops(void); // And the mesh stuff Group *PreviousGroup(void); @@ -276,6 +277,7 @@ public: char *DescriptionString(void); }; +#define MAX_POINTS_IN_ENTITY (12) class EntityBase { public: int tag; @@ -322,7 +324,7 @@ public: // When it comes time to draw an entity, we look here to get the // defining variables. - hEntity point[12]; + hEntity point[MAX_POINTS_IN_ENTITY]; int extraPoints; hEntity normal; hEntity distance; @@ -764,5 +766,17 @@ inline bool hEquation::isFromConstraint(void) inline hConstraint hEquation::constraint(void) { hConstraint r; r.v = (v >> 16); return r; } +// The format for entities stored on the clipboard. +class ClipboardEntity { +public: + int type; + Vector point[MAX_POINTS_IN_ENTITY]; + int extraPoints; + + hStyle style; + NameStr str; + NameStr font; + bool construction; +}; #endif