Enable exhaustive switch coverage warnings as an error, and use them.

Specifically, this enables -Wswitch=error on GCC/Clang and its MSVC
equivalent; the exact way it is handled varies slightly, but what
they all have in common is that in a switch statement over an
enumeration, any enumerand that is not explicitly (via case:) or
implicitly (via default:) handled in the switch triggers an error.

Moreover, we also change the switch statements in three ways:

  * Switch statements that ought to be extended every time a new
    enumerand is added (e.g. Entity::DrawOrGetDistance(), are changed
    to explicitly list every single enumerand, and not have a
    default: branch.

    Note that the assertions are kept because it is legal for
    a enumeration to have a value unlike any of its defined
    enumerands, and we can e.g. read garbage from a file, or
    an uninitialized variable. This requires some rearranging if
    a default: branch is undesired.

  * Switch statements that ought to only ever see a few select
    enumerands, are changed to always assert in the default: branch.

  * Switch statements that do something meaningful for a few
    enumerands, and ignore everything else, are changed to do nothing
    in a default: branch, under the assumption that changing them
    every time an enumerand is added or removed would just result
    in noise and catch no bugs.

This commit also removes the {Request,Entity,Constraint}::UNKNOWN and
Entity::DATUM_POINT enumerands, as those were just fancy names for
zeroes. They mess up switch exhaustiveness checks and most of the time
were not the best way to implement what they did anyway.
pull/10/head
whitequark 2016-05-25 06:55:50 +00:00
parent 4128a5d8d4
commit 1249f8496e
25 changed files with 226 additions and 188 deletions

View File

@ -51,6 +51,10 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
# Same for the (C99) __func__ special variable; we use it only in C++ code. # Same for the (C99) __func__ special variable; we use it only in C++ code.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__func__=__FUNCTION__") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__func__=__FUNCTION__")
# We rely on these /we flags. They correspond to the GNU-style flags below as
# follows: /w4062=-Wswitch
set(WARNING_FLAGS "${WARNING_FLAGS} /we4062")
endif() endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
@ -65,8 +69,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang) if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion") set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion")
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}") # We rely on these -Werror flags.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${WARNING_FLAGS}") set(WARNING_FLAGS "${WARNING_FLAGS} -Werror=switch")
endif() endif()
if(MINGW) if(MINGW)
@ -97,6 +101,9 @@ if(SANITIZE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
# dependencies # dependencies
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)

View File

@ -104,7 +104,6 @@ void SBsp3::InsertHow(BspClass how, STriangle *tr, SMesh *instead) {
more = m; more = m;
break; break;
} }
default: ssassert(false, "Unexpected BSP insert type");
} }
return; return;

View File

@ -373,6 +373,7 @@ void Constraint::MenuConstrain(Command id) {
c.entityA = gs.entity[0]; c.entityA = gs.entity[0];
c.ptA = gs.point[0]; c.ptA = gs.point[0];
c.ptB = gs.point[1]; c.ptB = gs.point[1];
c.type = Type::SYMMETRIC;
} else if(gs.lineSegments == 1 && } else if(gs.lineSegments == 1 &&
((gs.workplanes == 1 && gs.n == 2) || ((gs.workplanes == 1 && gs.n == 2) ||
(gs.n == 1))) (gs.n == 1)))
@ -382,6 +383,7 @@ void Constraint::MenuConstrain(Command id) {
c.entityA = gs.entity[1-i]; c.entityA = gs.entity[1-i];
c.ptA = line->point[0]; c.ptA = line->point[0];
c.ptB = line->point[1]; c.ptB = line->point[1];
c.type = Type::SYMMETRIC;
} else if(SS.GW.LockedInWorkplane() } else if(SS.GW.LockedInWorkplane()
&& gs.lineSegments == 2 && gs.n == 2) && gs.lineSegments == 2 && gs.n == 2)
{ {
@ -415,9 +417,7 @@ void Constraint::MenuConstrain(Command id) {
"(symmetric about workplane)\n"); "(symmetric about workplane)\n");
return; return;
} }
if(c.type != Type::UNKNOWN) { if(c.entityA.v == Entity::NO_ENTITY.v) {
// Already done, symmetry about a line segment in a workplane
} else if(c.entityA.v == Entity::NO_ENTITY.v) {
// Horizontal / vertical symmetry, implicit symmetry plane // Horizontal / vertical symmetry, implicit symmetry plane
// normal to the workplane // normal to the workplane
if(c.workplane.v == Entity::FREE_IN_3D.v) { if(c.workplane.v == Entity::FREE_IN_3D.v) {
@ -442,11 +442,7 @@ void Constraint::MenuConstrain(Command id) {
Entity::NO_ENTITY); Entity::NO_ENTITY);
DeleteAllConstraintsFor(Type::VERTICAL, (gs.entity[0]), DeleteAllConstraintsFor(Type::VERTICAL, (gs.entity[0]),
Entity::NO_ENTITY); Entity::NO_ENTITY);
} }
} else {
// Symmetry with a symmetry plane specified explicitly.
c.type = Type::SYMMETRIC;
} }
AddConstraint(&c); AddConstraint(&c);
break; break;

View File

@ -212,7 +212,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
switch(type) { switch(type) {
case Type::PT_PT_DISTANCE: case Type::PT_PT_DISTANCE:
AddEq(l, Distance(workplane, ptA, ptB)->Minus(exA), 0); AddEq(l, Distance(workplane, ptA, ptB)->Minus(exA), 0);
break; return;
case Type::PROJ_PT_DISTANCE: { case Type::PROJ_PT_DISTANCE: {
ExprVector pA = SK.GetEntity(ptA)->PointGetExprs(), ExprVector pA = SK.GetEntity(ptA)->PointGetExprs(),
@ -223,18 +223,18 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
pp = pp.WithMagnitude(Expr::From(1.0)); pp = pp.WithMagnitude(Expr::From(1.0));
AddEq(l, (dp.Dot(pp))->Minus(exA), 0); AddEq(l, (dp.Dot(pp))->Minus(exA), 0);
break; return;
} }
case Type::PT_LINE_DISTANCE: case Type::PT_LINE_DISTANCE:
AddEq(l, AddEq(l,
PointLineDistance(workplane, ptA, entityA)->Minus(exA), 0); PointLineDistance(workplane, ptA, entityA)->Minus(exA), 0);
break; return;
case Type::PT_PLANE_DISTANCE: { case Type::PT_PLANE_DISTANCE: {
ExprVector pt = SK.GetEntity(ptA)->PointGetExprs(); ExprVector pt = SK.GetEntity(ptA)->PointGetExprs();
AddEq(l, (PointPlaneDistance(pt, entityA))->Minus(exA), 0); AddEq(l, (PointPlaneDistance(pt, entityA))->Minus(exA), 0);
break; return;
} }
case Type::PT_FACE_DISTANCE: { case Type::PT_FACE_DISTANCE: {
@ -243,7 +243,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
ExprVector p0 = f->FaceGetPointExprs(); ExprVector p0 = f->FaceGetPointExprs();
ExprVector n = f->FaceGetNormalExprs(); ExprVector n = f->FaceGetNormalExprs();
AddEq(l, (pt.Minus(p0)).Dot(n)->Minus(exA), 0); AddEq(l, (pt.Minus(p0)).Dot(n)->Minus(exA), 0);
break; return;
} }
case Type::EQUAL_LENGTH_LINES: { case Type::EQUAL_LENGTH_LINES: {
@ -251,7 +251,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
EntityBase *b = SK.GetEntity(entityB); EntityBase *b = SK.GetEntity(entityB);
AddEq(l, Distance(workplane, a->point[0], a->point[1])->Minus( AddEq(l, Distance(workplane, a->point[0], a->point[1])->Minus(
Distance(workplane, b->point[0], b->point[1])), 0); Distance(workplane, b->point[0], b->point[1])), 0);
break; return;
} }
// These work on distance squared, since the pt-line distances are // These work on distance squared, since the pt-line distances are
@ -261,13 +261,13 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
Expr *d1 = Distance(workplane, forLen->point[0], forLen->point[1]); Expr *d1 = Distance(workplane, forLen->point[0], forLen->point[1]);
Expr *d2 = PointLineDistance(workplane, ptA, entityB); Expr *d2 = PointLineDistance(workplane, ptA, entityB);
AddEq(l, (d1->Square())->Minus(d2->Square()), 0); AddEq(l, (d1->Square())->Minus(d2->Square()), 0);
break; return;
} }
case Type::EQ_PT_LN_DISTANCES: { case Type::EQ_PT_LN_DISTANCES: {
Expr *d1 = PointLineDistance(workplane, ptA, entityA); Expr *d1 = PointLineDistance(workplane, ptA, entityA);
Expr *d2 = PointLineDistance(workplane, ptB, entityB); Expr *d2 = PointLineDistance(workplane, ptB, entityB);
AddEq(l, (d1->Square())->Minus(d2->Square()), 0); AddEq(l, (d1->Square())->Minus(d2->Square()), 0);
break; return;
} }
case Type::LENGTH_RATIO: { case Type::LENGTH_RATIO: {
@ -276,7 +276,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
Expr *la = Distance(workplane, a->point[0], a->point[1]); Expr *la = Distance(workplane, a->point[0], a->point[1]);
Expr *lb = Distance(workplane, b->point[0], b->point[1]); Expr *lb = Distance(workplane, b->point[0], b->point[1]);
AddEq(l, (la->Div(lb))->Minus(exA), 0); AddEq(l, (la->Div(lb))->Minus(exA), 0);
break; return;
} }
case Type::LENGTH_DIFFERENCE: { case Type::LENGTH_DIFFERENCE: {
@ -285,14 +285,14 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
Expr *la = Distance(workplane, a->point[0], a->point[1]); Expr *la = Distance(workplane, a->point[0], a->point[1]);
Expr *lb = Distance(workplane, b->point[0], b->point[1]); Expr *lb = Distance(workplane, b->point[0], b->point[1]);
AddEq(l, (la->Minus(lb))->Minus(exA), 0); AddEq(l, (la->Minus(lb))->Minus(exA), 0);
break; return;
} }
case Type::DIAMETER: { case Type::DIAMETER: {
EntityBase *circle = SK.GetEntity(entityA); EntityBase *circle = SK.GetEntity(entityA);
Expr *r = circle->CircleGetRadiusExpr(); Expr *r = circle->CircleGetRadiusExpr();
AddEq(l, (r->Times(Expr::From(2)))->Minus(exA), 0); AddEq(l, (r->Times(Expr::From(2)))->Minus(exA), 0);
break; return;
} }
case Type::EQUAL_RADIUS: { case Type::EQUAL_RADIUS: {
@ -300,7 +300,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
EntityBase *c2 = SK.GetEntity(entityB); EntityBase *c2 = SK.GetEntity(entityB);
AddEq(l, (c1->CircleGetRadiusExpr())->Minus( AddEq(l, (c1->CircleGetRadiusExpr())->Minus(
c2->CircleGetRadiusExpr()), 0); c2->CircleGetRadiusExpr()), 0);
break; return;
} }
case Type::EQUAL_LINE_ARC_LEN: { case Type::EQUAL_LINE_ARC_LEN: {
@ -343,7 +343,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
// And write the equation; r*theta = L // And write the equation; r*theta = L
AddEq(l, (r->Times(theta))->Minus(ll), 0); AddEq(l, (r->Times(theta))->Minus(ll), 0);
break; return;
} }
case Type::POINTS_COINCIDENT: { case Type::POINTS_COINCIDENT: {
@ -363,14 +363,14 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
AddEq(l, au->Minus(bu), 0); AddEq(l, au->Minus(bu), 0);
AddEq(l, av->Minus(bv), 1); AddEq(l, av->Minus(bv), 1);
} }
break; return;
} }
case Type::PT_IN_PLANE: case Type::PT_IN_PLANE:
// This one works the same, whether projected or not. // This one works the same, whether projected or not.
AddEq(l, PointPlaneDistance( AddEq(l, PointPlaneDistance(
SK.GetEntity(ptA)->PointGetExprs(), entityA), 0); SK.GetEntity(ptA)->PointGetExprs(), entityA), 0);
break; return;
case Type::PT_ON_FACE: { case Type::PT_ON_FACE: {
// a plane, n dot (p - p0) = 0 // a plane, n dot (p - p0) = 0
@ -379,7 +379,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
ExprVector p0 = f->FaceGetPointExprs(); ExprVector p0 = f->FaceGetPointExprs();
ExprVector n = f->FaceGetNormalExprs(); ExprVector n = f->FaceGetNormalExprs();
AddEq(l, (p.Minus(p0)).Dot(n), 0); AddEq(l, (p.Minus(p0)).Dot(n), 0);
break; return;
} }
case Type::PT_ON_LINE: case Type::PT_ON_LINE:
@ -412,7 +412,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
} else { } else {
AddEq(l, PointLineDistance(workplane, ptA, entityA), 0); AddEq(l, PointLineDistance(workplane, ptA, entityA), 0);
} }
break; return;
case Type::PT_ON_CIRCLE: { case Type::PT_ON_CIRCLE: {
// This actually constrains the point to lie on the cylinder. // This actually constrains the point to lie on the cylinder.
@ -430,7 +430,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
AddEq(l, AddEq(l,
((du->Square())->Plus(dv->Square()))->Minus(r->Square()), 0); ((du->Square())->Plus(dv->Square()))->Minus(r->Square()), 0);
break; return;
} }
case Type::AT_MIDPOINT: case Type::AT_MIDPOINT:
@ -470,7 +470,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
AddEq(l, PointPlaneDistance(m, entityB), 0); AddEq(l, PointPlaneDistance(m, entityB), 0);
} }
} }
break; return;
case Type::SYMMETRIC: case Type::SYMMETRIC:
if(workplane.v == EntityBase::FREE_IN_3D.v) { if(workplane.v == EntityBase::FREE_IN_3D.v) {
@ -521,7 +521,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
plane->WorkplaneGetPlaneExprs(&n, &d); plane->WorkplaneGetPlaneExprs(&n, &d);
AddEq(l, (n.Cross(u.Cross(v))).Dot(pa.Minus(pb)), 1); AddEq(l, (n.Cross(u.Cross(v))).Dot(pa.Minus(pb)), 1);
} }
break; return;
case Type::SYMMETRIC_HORIZ: case Type::SYMMETRIC_HORIZ:
case Type::SYMMETRIC_VERT: { case Type::SYMMETRIC_VERT: {
@ -539,7 +539,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
AddEq(l, au->Minus(bu), 0); AddEq(l, au->Minus(bu), 0);
AddEq(l, av->Plus(bv), 1); AddEq(l, av->Plus(bv), 1);
} }
break; return;
} }
case Type::SYMMETRIC_LINE: { case Type::SYMMETRIC_LINE: {
@ -572,7 +572,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
(dlu->Times(lav->Minus(pbv)))); (dlu->Times(lav->Minus(pbv))));
AddEq(l, dista->Plus(distb), 1); AddEq(l, dista->Plus(distb), 1);
break; return;
} }
case Type::HORIZONTAL: case Type::HORIZONTAL:
@ -594,7 +594,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
b->PointGetExprsInWorkplane(workplane, &bu, &bv); b->PointGetExprsInWorkplane(workplane, &bu, &bv);
AddEq(l, (type == Type::HORIZONTAL) ? av->Minus(bv) : au->Minus(bu), 0); AddEq(l, (type == Type::HORIZONTAL) ? av->Minus(bv) : au->Minus(bu), 0);
break; return;
} }
case Type::SAME_ORIENTATION: { case Type::SAME_ORIENTATION: {
@ -621,7 +621,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
} else { } else {
AddEq(l, d2, 2); AddEq(l, d2, 2);
} }
break; return;
} }
case Type::PERPENDICULAR: case Type::PERPENDICULAR:
@ -650,7 +650,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
// is equal to zero, perpendicular. // is equal to zero, perpendicular.
AddEq(l, c, 0); AddEq(l, c, 0);
} }
break; return;
} }
case Type::EQUAL_ANGLE: { case Type::EQUAL_ANGLE: {
@ -669,7 +669,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
Expr *ccd = DirectionCosine(workplane, ce, de); Expr *ccd = DirectionCosine(workplane, ce, de);
AddEq(l, cab->Minus(ccd), 0); AddEq(l, cab->Minus(ccd), 0);
break; return;
} }
case Type::ARC_LINE_TANGENT: { case Type::ARC_LINE_TANGENT: {
@ -684,7 +684,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
// The line is perpendicular to the radius // The line is perpendicular to the radius
AddEq(l, ld.Dot(ac.Minus(ap)), 0); AddEq(l, ld.Dot(ac.Minus(ap)), 0);
break; return;
} }
case Type::CUBIC_LINE_TANGENT: { case Type::CUBIC_LINE_TANGENT: {
@ -708,7 +708,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
ExprVector wn = w->Normal()->NormalExprsN(); ExprVector wn = w->Normal()->NormalExprsN();
AddEq(l, (a.Cross(b)).Dot(wn), 0); AddEq(l, (a.Cross(b)).Dot(wn), 0);
} }
break; return;
} }
case Type::CURVE_CURVE_TANGENT: { case Type::CURVE_CURVE_TANGENT: {
@ -746,7 +746,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
} else { } else {
AddEq(l, (dir[0]).Dot(dir[1]), 0); AddEq(l, (dir[0]).Dot(dir[1]), 0);
} }
break; return;
} }
case Type::PARALLEL: { case Type::PARALLEL: {
@ -765,7 +765,7 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
ExprVector wn = w->Normal()->NormalExprsN(); ExprVector wn = w->Normal()->NormalExprsN();
AddEq(l, (a.Cross(b)).Dot(wn), 0); AddEq(l, (a.Cross(b)).Dot(wn), 0);
} }
break; return;
} }
case Type::WHERE_DRAGGED: { case Type::WHERE_DRAGGED: {
@ -783,13 +783,12 @@ void ConstraintBase::GenerateReal(IdList<Equation,hEquation> *l) const {
AddEq(l, u->Minus(Expr::From(u->Eval())), 0); AddEq(l, u->Minus(Expr::From(u->Eval())), 0);
AddEq(l, v->Minus(Expr::From(v->Eval())), 1); AddEq(l, v->Minus(Expr::From(v->Eval())), 1);
} }
break; return;
} }
case Type::COMMENT: case Type::COMMENT:
break; return;
default: ssassert(false, "Unexpected constraint ID");
} }
ssassert(false, "Unexpected constraint ID");
} }

View File

@ -271,7 +271,9 @@ void GraphicsWindow::GroupSelection() {
(gs.arcs)++; (gs.arcs)++;
break; break;
case Entity::Type::CIRCLE: (gs.circlesOrArcs)++; break; case Entity::Type::CIRCLE: (gs.circlesOrArcs)++; break;
default: break;
} }
} }
if(s->constraint.v) { if(s->constraint.v) {
@ -680,21 +682,20 @@ nogrid:;
// Draw the "pending" constraint, i.e. a constraint that would be // Draw the "pending" constraint, i.e. a constraint that would be
// placed on a line that is almost horizontal or vertical // placed on a line that is almost horizontal or vertical
if(SS.GW.pending.operation == Pending::DRAGGING_NEW_LINE_POINT) { if(SS.GW.pending.operation == Pending::DRAGGING_NEW_LINE_POINT &&
if(SS.GW.pending.suggestion != Constraint::Type::UNKNOWN) { SS.GW.pending.hasSuggestion) {
Constraint c = {}; Constraint c = {};
c.group = SS.GW.activeGroup; c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane(); c.workplane = SS.GW.ActiveWorkplane();
c.type = SS.GW.pending.suggestion; c.type = SS.GW.pending.suggestion;
c.ptA = Entity::NO_ENTITY; c.ptA = Entity::NO_ENTITY;
c.ptB = Entity::NO_ENTITY; c.ptB = Entity::NO_ENTITY;
c.entityA = SS.GW.pending.request.entity(0); c.entityA = SS.GW.pending.request.entity(0);
c.entityB = Entity::NO_ENTITY; c.entityB = Entity::NO_ENTITY;
c.other = false; c.other = false;
c.other2 = false; c.other2 = false;
// Only draw. // Only draw.
c.Draw(); c.Draw();
}
} }
// Draw the traced path, if one exists // Draw the traced path, if one exists

View File

@ -536,7 +536,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoLineWithArrows(ref, ap, bp, false); DoLineWithArrows(ref, ap, bp, false);
DoLabel(ref, labelPos, gr, gu); DoLabel(ref, labelPos, gr, gu);
break; return;
} }
case Type::PROJ_PT_DISTANCE: { case Type::PROJ_PT_DISTANCE: {
@ -556,7 +556,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoLineWithArrows(ref, ap, bpp, false); DoLineWithArrows(ref, ap, bpp, false);
DoLabel(ref, labelPos, gr, gu); DoLabel(ref, labelPos, gr, gu);
break; return;
} }
case Type::PT_FACE_DISTANCE: case Type::PT_FACE_DISTANCE:
@ -583,7 +583,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
} }
DoLabel(ref, labelPos, gr, gu); DoLabel(ref, labelPos, gr, gu);
break; return;
} }
case Type::PT_LINE_DISTANCE: { case Type::PT_LINE_DISTANCE: {
@ -635,7 +635,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Vector c2 = (lA.ScaledBy(1-t)).Plus(lB.ScaledBy(t)); Vector c2 = (lA.ScaledBy(1-t)).Plus(lB.ScaledBy(t));
DoProjectedPoint(&c2); DoProjectedPoint(&c2);
} }
break; return;
} }
case Type::DIAMETER: { case Type::DIAMETER: {
@ -657,7 +657,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Vector topLeft; Vector topLeft;
DoLabel(ref, &topLeft, gr, gu); DoLabel(ref, &topLeft, gr, gu);
if(labelPos) *labelPos = topLeft; if(labelPos) *labelPos = topLeft;
break; return;
} }
case Type::POINTS_COINCIDENT: { case Type::POINTS_COINCIDENT: {
@ -671,7 +671,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
// constraint cannot be selected. But that's okay. // constraint cannot be selected. But that's okay.
dogd.dmin = min(dogd.dmin, pp.DistanceTo(dogd.mp) - 3); dogd.dmin = min(dogd.dmin, pp.DistanceTo(dogd.mp) - 3);
} }
break; return;
} }
if(dogd.drawing) { if(dogd.drawing) {
@ -704,7 +704,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
} }
} }
break; return;
} }
case Type::PT_ON_CIRCLE: case Type::PT_ON_CIRCLE:
@ -733,7 +733,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
LineDrawOrGetDistance(p.Plus (r).Minus(d), p.Minus(r).Minus(d)); LineDrawOrGetDistance(p.Plus (r).Minus(d), p.Minus(r).Minus(d));
LineDrawOrGetDistance(p.Minus(r).Minus(d), p.Minus(r).Plus (d)); LineDrawOrGetDistance(p.Minus(r).Minus(d), p.Minus(r).Plus (d));
LineDrawOrGetDistance(p.Minus(r).Plus (d), p.Plus (r).Plus (d)); LineDrawOrGetDistance(p.Minus(r).Plus (d), p.Plus (r).Plus (d));
break; return;
} }
case Type::WHERE_DRAGGED: { case Type::WHERE_DRAGGED: {
@ -753,7 +753,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
ur = ur.RotatedAbout(p, gn, PI/2); ur = ur.RotatedAbout(p, gn, PI/2);
uu = uu.RotatedAbout(p, gn, PI/2); uu = uu.RotatedAbout(p, gn, PI/2);
} }
break; return;
} }
case Type::SAME_ORIENTATION: { case Type::SAME_ORIENTATION: {
@ -769,7 +769,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
LineDrawOrGetDistance(p.Plus(u), p.Minus(u).Plus(n)); LineDrawOrGetDistance(p.Plus(u), p.Minus(u).Plus(n));
LineDrawOrGetDistance(p.Minus(u), p.Plus(u).Plus(n)); LineDrawOrGetDistance(p.Minus(u), p.Plus(u).Plus(n));
} }
break; return;
} }
case Type::EQUAL_ANGLE: { case Type::EQUAL_ANGLE: {
@ -800,7 +800,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
dc.WithMagnitude(40/SS.GW.scale), &ref, /*trim=*/false); dc.WithMagnitude(40/SS.GW.scale), &ref, /*trim=*/false);
if(refps) refps[1] = ref; if(refps) refps[1] = ref;
break; return;
} }
case Type::ANGLE: { case Type::ANGLE: {
@ -820,7 +820,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoArcForAngle(a0, da, b0, db, disp.offset, &ref, /*trim=*/true); DoArcForAngle(a0, da, b0, db, disp.offset, &ref, /*trim=*/true);
DoLabel(ref, labelPos, gr, gu); DoLabel(ref, labelPos, gr, gu);
if(refps) refps[0] = refps[1] = ref; if(refps) refps[0] = refps[1] = ref;
break; return;
} }
case Type::PERPENDICULAR: { case Type::PERPENDICULAR: {
@ -859,7 +859,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
LineDrawOrGetDistance(m, m.Plus(u)); LineDrawOrGetDistance(m, m.Plus(u));
if(refps) refps[i] = m; if(refps) refps[i] = m;
} }
break; return;
} }
case Type::CURVE_CURVE_TANGENT: case Type::CURVE_CURVE_TANGENT:
@ -937,7 +937,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Point2d ref = SS.GW.ProjectPoint(textAt); Point2d ref = SS.GW.ProjectPoint(textAt);
dogd.dmin = min(dogd.dmin, ref.DistanceTo(dogd.mp)-10); dogd.dmin = min(dogd.dmin, ref.DistanceTo(dogd.mp)-10);
} }
break; return;
} }
case Type::PARALLEL: { case Type::PARALLEL: {
@ -952,7 +952,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
LineDrawOrGetDistance(p.Minus(u), p.Minus(u).Plus(n)); LineDrawOrGetDistance(p.Minus(u), p.Minus(u).Plus(n));
if(refps) refps[i] = p.Plus(n.ScaledBy(0.5)); if(refps) refps[i] = p.Plus(n.ScaledBy(0.5));
} }
break; return;
} }
case Type::EQUAL_RADIUS: { case Type::EQUAL_RADIUS: {
@ -961,7 +961,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoEqualRadiusTicks(i == 0 ? entityA : entityB, &ref); DoEqualRadiusTicks(i == 0 ? entityA : entityB, &ref);
if(refps) refps[i] = ref; if(refps) refps[i] = ref;
} }
break; return;
} }
case Type::EQUAL_LINE_ARC_LEN: { case Type::EQUAL_LINE_ARC_LEN: {
@ -976,7 +976,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
refps[0] = refa; refps[0] = refa;
refps[1] = refb; refps[1] = refb;
} }
break; return;
} }
case Type::LENGTH_RATIO: case Type::LENGTH_RATIO:
@ -1001,7 +1001,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Vector ref = ((a.Plus(b)).ScaledBy(0.5)).Plus(disp.offset); Vector ref = ((a.Plus(b)).ScaledBy(0.5)).Plus(disp.offset);
DoLabel(ref, labelPos, gr, gu); DoLabel(ref, labelPos, gr, gu);
} }
break; return;
} }
case Type::EQ_LEN_PT_LINE_D: { case Type::EQ_LEN_PT_LINE_D: {
@ -1031,7 +1031,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Vector refb; Vector refb;
DoEqualLenTicks(pt, closest, gn, &refb); DoEqualLenTicks(pt, closest, gn, &refb);
if(refps) refps[1] = refb; if(refps) refps[1] = refb;
break; return;
} }
case Type::EQ_PT_LN_DISTANCES: { case Type::EQ_PT_LN_DISTANCES: {
@ -1055,7 +1055,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoEqualLenTicks(pt, closest, gn, &ref); DoEqualLenTicks(pt, closest, gn, &ref);
if(refps) refps[i] = ref; if(refps) refps[i] = ref;
} }
break; return;
} }
{ {
@ -1099,7 +1099,7 @@ s:
LineDrawOrGetDistance(tip, tip.Minus(d.RotatedAbout(gn, 0.6))); LineDrawOrGetDistance(tip, tip.Minus(d.RotatedAbout(gn, 0.6)));
LineDrawOrGetDistance(tip, tip.Minus(d.RotatedAbout(gn, -0.6))); LineDrawOrGetDistance(tip, tip.Minus(d.RotatedAbout(gn, -0.6)));
} }
break; return;
} }
case Type::AT_MIDPOINT: case Type::AT_MIDPOINT:
@ -1173,7 +1173,7 @@ s:
} }
} }
} }
break; return;
case Type::COMMENT: { case Type::COMMENT: {
if(dogd.drawing && disp.style.v) { if(dogd.drawing && disp.style.v) {
@ -1191,11 +1191,10 @@ s:
} }
if(refps) refps[0] = refps[1] = disp.offset; if(refps) refps[0] = refps[1] = disp.offset;
DoLabel(disp.offset, labelPos, u, v); DoLabel(disp.offset, labelPos, u, v);
break; return;
} }
default: ssassert(false, "Unexpected constraint type");
} }
ssassert(false, "Unexpected constraint type");
} }
void Constraint::Draw() { void Constraint::Draw() {

View File

@ -223,8 +223,17 @@ Vector Entity::GetReferencePos() {
return b.Plus(a.Minus(b).ScaledBy(0.5)); return b.Plus(a.Minus(b).ScaledBy(0.5));
} }
default: ssassert(false, "Unexpected entity type"); case Type::DISTANCE:
case Type::DISTANCE_N_COPY:
case Type::FACE_NORMAL_PT:
case Type::FACE_XPROD:
case Type::FACE_N_ROT_TRANS:
case Type::FACE_N_TRANS:
case Type::FACE_N_ROT_AA:
case Type::WORKPLANE:
break;
} }
ssassert(false, "Unexpected entity type");
} }
bool Entity::IsStylable() const { bool Entity::IsStylable() const {
@ -574,7 +583,7 @@ void Entity::DrawOrGetDistance() {
Point2d pp = SS.GW.ProjectPoint(v); Point2d pp = SS.GW.ProjectPoint(v);
dogd.dmin = pp.DistanceTo(dogd.mp) - 6; dogd.dmin = pp.DistanceTo(dogd.mp) - 6;
} }
break; return;
} }
case Type::NORMAL_N_COPY: case Type::NORMAL_N_COPY:
@ -643,13 +652,13 @@ void Entity::DrawOrGetDistance() {
} }
if(dogd.drawing) if(dogd.drawing)
ssglDepthRangeLockToFront(false); ssglDepthRangeLockToFront(false);
break; return;
} }
case Type::DISTANCE: case Type::DISTANCE:
case Type::DISTANCE_N_COPY: case Type::DISTANCE_N_COPY:
// These are used only as data structures, nothing to display. // These are used only as data structures, nothing to display.
break; return;
case Type::WORKPLANE: { case Type::WORKPLANE: {
Vector p; Vector p;
@ -703,7 +712,7 @@ void Entity::DrawOrGetDistance() {
// the plane. // the plane.
dogd.dmin += 3; dogd.dmin += 3;
} }
break; return;
} }
case Type::LINE_SEGMENT: case Type::LINE_SEGMENT:
@ -711,9 +720,17 @@ void Entity::DrawOrGetDistance() {
case Type::ARC_OF_CIRCLE: case Type::ARC_OF_CIRCLE:
case Type::CUBIC: case Type::CUBIC:
case Type::CUBIC_PERIODIC: case Type::CUBIC_PERIODIC:
case Type::TTF_TEXT: case Type::TTF_TEXT: {
// Nothing but the curve(s). // Nothing but the curves; generate the rational polynomial curves for
break; // everything, then piecewise linearize them, and display those.
SEdgeList *sel = GetOrGenerateEdges();
dogd.data = -1;
for(int i = 0; i < sel->l.n; i++) {
SEdge *se = &(sel->l.elem[i]);
LineDrawOrGetDistance(se->a, se->b, true, se->auxB);
}
return;
}
case Type::FACE_NORMAL_PT: case Type::FACE_NORMAL_PT:
case Type::FACE_XPROD: case Type::FACE_XPROD:
@ -721,18 +738,8 @@ void Entity::DrawOrGetDistance() {
case Type::FACE_N_TRANS: case Type::FACE_N_TRANS:
case Type::FACE_N_ROT_AA: case Type::FACE_N_ROT_AA:
// Do nothing; these are drawn with the triangle mesh // Do nothing; these are drawn with the triangle mesh
break; return;
default: ssassert(false, "Unexpected entity type");
}
// And draw the curves; generate the rational polynomial curves for
// everything, then piecewise linearize them, and display those.
SEdgeList *sel = GetOrGenerateEdges();
dogd.data = -1;
for(int i = 0; i < sel->l.n; i++) {
SEdge *se = &(sel->l.elem[i]);
LineDrawOrGetDistance(se->a, se->b, true, se->auxB);
} }
ssassert(false, "Unexpected entity type");
} }

View File

@ -780,7 +780,7 @@ void EntityBase::GenerateEquations(IdList<Equation,hEquation> *l) const {
AddEq(l, ra->Minus(rb), 0); AddEq(l, ra->Minus(rb), 0);
break; break;
} }
default:; default: // Most entities do not generate equations.
// Most entities do not generate equations. break;
} }
} }

View File

@ -230,6 +230,10 @@ public:
type.path.push_back(0.0); type.path.push_back(0.0);
type.path.push_back(-sw); type.path.push_back(-sw);
break; break;
case StipplePattern::FREEHAND:
case StipplePattern::ZIGZAG:
ssassert(false, "Freehand and zigzag export not implemented");
} }
dxf->writeLineType(&type); dxf->writeLineType(&type);
} }
@ -419,6 +423,10 @@ public:
st->textAngle, st->textOrigin, c->GetStyle()); st->textAngle, st->textOrigin, c->GetStyle());
break; break;
} }
default:
// Other types of constraints do not have a DXF dimension equivalent.
break;
} }
} }
} }
@ -697,6 +705,9 @@ bool DxfFileWriter::NeedToOutput(Constraint *c) {
case Constraint::Type::ANGLE: case Constraint::Type::ANGLE:
case Constraint::Type::COMMENT: case Constraint::Type::COMMENT:
return c->IsVisible(); return c->IsVisible();
default: // See writeEntities().
break;
} }
return false; return false;
} }
@ -731,8 +742,6 @@ static std::string MakeStipplePattern(StipplePattern pattern, double scale, char
std::string result; std::string result;
switch(pattern) { switch(pattern) {
case StipplePattern::CONTINUOUS: case StipplePattern::CONTINUOUS:
case StipplePattern::FREEHAND:
case StipplePattern::ZIGZAG:
return ""; return "";
case StipplePattern::DASH: case StipplePattern::DASH:
@ -754,7 +763,9 @@ static std::string MakeStipplePattern(StipplePattern pattern, double scale, char
result = ssprintf("%.3f_%.3f", scale * 2.0, scale * 0.5); result = ssprintf("%.3f_%.3f", scale * 2.0, scale * 0.5);
break; break;
default: ssassert(false, "Unexpected stipple pattern"); case StipplePattern::FREEHAND:
case StipplePattern::ZIGZAG:
ssassert(false, "Freehand and zigzag export not implemented");
} }
std::replace(result.begin(), result.end(), '_', delimiter); std::replace(result.begin(), result.end(), '_', delimiter);
return result; return result;

View File

@ -284,8 +284,13 @@ int Expr::Children() const {
case Op::ACOS: case Op::ACOS:
return 1; return 1;
default: ssassert(false, "Unexpected operation"); case Op::PAREN:
case Op::BINARY_OP:
case Op::UNARY_OP:
case Op::ALL_RESOLVED:
break;
} }
ssassert(false, "Unexpected operation");
} }
int Expr::Nodes() const { int Expr::Nodes() const {
@ -353,8 +358,13 @@ double Expr::Eval() const {
case Op::ACOS: return acos(a->Eval()); case Op::ACOS: return acos(a->Eval());
case Op::ASIN: return asin(a->Eval()); case Op::ASIN: return asin(a->Eval());
default: ssassert(false, "Unexpected operation"); case Op::PAREN:
case Op::BINARY_OP:
case Op::UNARY_OP:
case Op::ALL_RESOLVED:
break;
} }
ssassert(false, "Unexpected operation");
} }
Expr *Expr::PartialWrt(hParam p) const { Expr *Expr::PartialWrt(hParam p) const {
@ -396,8 +406,13 @@ Expr *Expr::PartialWrt(hParam p) const {
return (From(-1)->Div((From(1)->Minus(a->Square()))->Sqrt())) return (From(-1)->Div((From(1)->Minus(a->Square()))->Sqrt()))
->Times(a->PartialWrt(p)); ->Times(a->PartialWrt(p));
default: ssassert(false, "Unexpected operation"); case Op::PAREN:
case Op::BINARY_OP:
case Op::UNARY_OP:
case Op::ALL_RESOLVED:
break;
} }
ssassert(false, "Unexpected operation");
} }
uint64_t Expr::ParamsUsed() const { uint64_t Expr::ParamsUsed() const {
@ -487,7 +502,11 @@ Expr *Expr::FoldConstants() {
} }
break; break;
default: ssassert(false, "Unexpected operation"); case Op::PAREN:
case Op::BINARY_OP:
case Op::UNARY_OP:
case Op::ALL_RESOLVED:
ssassert(false, "Unexpected operation");
} }
return n; return n;
} }
@ -547,7 +566,6 @@ hParam Expr::ReferencedParams(ParamList *pl) const {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string Expr::Print() const { std::string Expr::Print() const {
char c; char c;
switch(op) { switch(op) {
case Op::PARAM: return ssprintf("param(%08x)", parh.v); case Op::PARAM: return ssprintf("param(%08x)", parh.v);
@ -571,8 +589,13 @@ p:
case Op::ASIN: return "(asin " + a->Print() + ")"; case Op::ASIN: return "(asin " + a->Print() + ")";
case Op::ACOS: return "(acos " + a->Print() + ")"; case Op::ACOS: return "(acos " + a->Print() + ")";
default: ssassert(false, "Unexpected operation"); case Op::PAREN:
case Op::BINARY_OP:
case Op::UNARY_OP:
case Op::ALL_RESOLVED:
break;
} }
ssassert(false, "Unexpected operation");
} }

View File

@ -198,8 +198,6 @@ void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox)
last = i; last = i;
break; break;
} }
default: ssassert(false, "Unexpected generation mode");
} }
// If we're generating entities for display, first we need to find // If we're generating entities for display, first we need to find
@ -458,6 +456,9 @@ void SolveSpaceUI::MarkDraggedParams() {
sys.dragged.Add(&(pt->param[0])); sys.dragged.Add(&(pt->param[0]));
sys.dragged.Add(&(pt->param[1])); sys.dragged.Add(&(pt->param[1]));
break; break;
default: // Only the entities above can be dragged.
break;
} }
} }
} }
@ -469,6 +470,9 @@ void SolveSpaceUI::MarkDraggedParams() {
case Entity::Type::DISTANCE: case Entity::Type::DISTANCE:
sys.dragged.Add(&(dist->param[0])); sys.dragged.Add(&(dist->param[0]));
break; break;
default: // Only the entities above can be dragged.
break;
} }
} }
} }
@ -482,7 +486,9 @@ void SolveSpaceUI::MarkDraggedParams() {
sys.dragged.Add(&(norm->param[2])); sys.dragged.Add(&(norm->param[2]));
sys.dragged.Add(&(norm->param[3])); sys.dragged.Add(&(norm->param[3]));
break; break;
// other types are locked, so not draggable
default: // Only the entities above can be dragged.
break;
} }
} }
} }

View File

@ -127,7 +127,6 @@ void ssglStippledLine(Vector a, Vector b, double width,
case StipplePattern::DOT: stipplePattern = "."; break; case StipplePattern::DOT: stipplePattern = "."; break;
case StipplePattern::FREEHAND: stipplePattern = "~"; break; case StipplePattern::FREEHAND: stipplePattern = "~"; break;
case StipplePattern::ZIGZAG: stipplePattern = "~__"; break; case StipplePattern::ZIGZAG: stipplePattern = "~__"; break;
default: ssassert(false, "Unexpected stipple pattern");
} }
ssglStippledLine(a, b, width, stipplePattern, stippleScale, maybeFat); ssglStippledLine(a, b, width, stipplePattern, stippleScale, maybeFat);
} }

View File

@ -1063,7 +1063,7 @@ void GraphicsWindow::ToggleBool(bool *v) {
SS.ScheduleShowTW(); SS.ScheduleShowTW();
} }
Constraint::Type GraphicsWindow::SuggestLineConstraint(hRequest request) { bool GraphicsWindow::SuggestLineConstraint(hRequest request, Constraint::Type *type) {
if(LockedInWorkplane()) { if(LockedInWorkplane()) {
Entity *ptA = SK.GetEntity(request.entity(1)), Entity *ptA = SK.GetEntity(request.entity(1)),
*ptB = SK.GetEntity(request.entity(2)); *ptB = SK.GetEntity(request.entity(2));
@ -1077,13 +1077,13 @@ Constraint::Type GraphicsWindow::SuggestLineConstraint(hRequest request) {
double dv = av->Minus(bv)->Eval(); double dv = av->Minus(bv)->Eval();
const double TOLERANCE_RATIO = 0.02; const double TOLERANCE_RATIO = 0.02;
if(fabs(dv) > LENGTH_EPS && fabs(du / dv) < TOLERANCE_RATIO) if(fabs(dv) > LENGTH_EPS && fabs(du / dv) < TOLERANCE_RATIO) {
return Constraint::Type::VERTICAL; *type = Constraint::Type::VERTICAL;
else if(fabs(du) > LENGTH_EPS && fabs(dv / du) < TOLERANCE_RATIO) return true;
return Constraint::Type::HORIZONTAL; } else if(fabs(du) > LENGTH_EPS && fabs(dv / du) < TOLERANCE_RATIO) {
else *type = Constraint::Type::HORIZONTAL;
return Constraint::Type::UNKNOWN; return true;
} else { }
return Constraint::Type::UNKNOWN;
} }
return false;
} }

View File

@ -346,7 +346,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
int a, i; int a, i;
switch(type) { switch(type) {
case Type::DRAWING_3D: case Type::DRAWING_3D:
break; return;
case Type::DRAWING_WORKPLANE: { case Type::DRAWING_WORKPLANE: {
Quaternion q; Quaternion q;
@ -388,7 +388,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
wp.group = h; wp.group = h;
wp.h = h.entity(0); wp.h = h.entity(0);
entity->Add(&wp); entity->Add(&wp);
break; return;
} }
case Type::EXTRUDE: { case Type::EXTRUDE: {
@ -428,7 +428,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
// Remapped versions of that arbitrary point will be used to // Remapped versions of that arbitrary point will be used to
// provide points on the plane faces. // provide points on the plane faces.
MakeExtrusionTopBottomFaces(entity, pt); MakeExtrusionTopBottomFaces(entity, pt);
break; return;
} }
case Type::LATHE: { case Type::LATHE: {
@ -469,7 +469,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
MakeLatheCircles(entity, param, he, axis_pos, axis_dir, ai); MakeLatheCircles(entity, param, he, axis_pos, axis_dir, ai);
ai++; ai++;
} }
break; return;
} }
case Type::TRANSLATE: { case Type::TRANSLATE: {
@ -497,7 +497,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
true, false); true, false);
} }
} }
break; return;
} }
case Type::ROTATE: { case Type::ROTATE: {
// The center of rotation // The center of rotation
@ -529,7 +529,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
false, true); false, true);
} }
} }
break; return;
} }
case Type::LINKED: case Type::LINKED:
// The translation vector // The translation vector
@ -549,10 +549,9 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
h.param(3), h.param(4), h.param(5), h.param(6), h.param(3), h.param(4), h.param(5), h.param(6),
false, false); false, false);
} }
break; return;
default: ssassert(false, "Unexpected group type");
} }
ssassert(false, "Unexpected group type");
} }
bool Group::IsSolvedOkay() { bool Group::IsSolvedOkay() {

View File

@ -446,8 +446,10 @@ bool Group::IsMeshGroup() {
case Group::Type::ROTATE: case Group::Type::ROTATE:
case Group::Type::TRANSLATE: case Group::Type::TRANSLATE:
return true; return true;
default:
return false;
} }
return false;
} }
void Group::DrawDisplayItems(Group::Type t) { void Group::DrawDisplayItems(Group::Type t) {

View File

@ -493,14 +493,16 @@ public:
processPoint(hr.entity(2)); processPoint(hr.entity(2));
if(constrainHV) { if(constrainHV) {
Constraint::Type cType = Constraint::Type::UNKNOWN; bool hasConstraint = false;
Constraint::Type cType;
if(fabs(p0.x - p1.x) < LENGTH_EPS) { if(fabs(p0.x - p1.x) < LENGTH_EPS) {
hasConstraint = true;
cType = Constraint::Type::VERTICAL; cType = Constraint::Type::VERTICAL;
} } else if(fabs(p0.y - p1.y) < LENGTH_EPS) {
else if(fabs(p0.y - p1.y) < LENGTH_EPS) { hasConstraint = true;
cType = Constraint::Type::HORIZONTAL; cType = Constraint::Type::HORIZONTAL;
} }
if(cType != Constraint::Type::UNKNOWN) { if(hasConstraint) {
Constraint::Constrain( Constraint::Constrain(
cType, cType,
Entity::NO_ENTITY, Entity::NO_ENTITY,

View File

@ -228,8 +228,6 @@ default: dbp("bad constraint type %d", sc->type); return;
case SolveResult::TOO_MANY_UNKNOWNS: case SolveResult::TOO_MANY_UNKNOWNS:
ssys->result = SLVS_RESULT_TOO_MANY_UNKNOWNS; ssys->result = SLVS_RESULT_TOO_MANY_UNKNOWNS;
break; break;
default: ssassert(false, "Unexpected solver result");
} }
// Write the new parameter values back to our caller. // Write the new parameter values back to our caller.

View File

@ -1013,8 +1013,6 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, EdgeKind how, bool coplanarIs
} }
} }
break; break;
default: ssassert(false, "Unexpected edge class");
} }
cnt++; cnt++;

View File

@ -276,15 +276,15 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
UpdateDraggedNum(&(c->disp.offset), x, y); UpdateDraggedNum(&(c->disp.offset), x, y);
orig.mouse = mp; orig.mouse = mp;
InvalidateGraphics(); InvalidateGraphics();
break; return;
} }
case Pending::DRAGGING_NEW_LINE_POINT: case Pending::DRAGGING_NEW_LINE_POINT:
if(!ctrlDown) { if(!ctrlDown) {
SS.GW.pending.suggestion = SS.GW.pending.hasSuggestion =
SS.GW.SuggestLineConstraint(SS.GW.pending.request); SS.GW.SuggestLineConstraint(SS.GW.pending.request, &SS.GW.pending.suggestion);
} else { } else {
SS.GW.pending.suggestion = Constraint::Type::UNKNOWN; SS.GW.pending.hasSuggestion = false;
} }
case Pending::DRAGGING_NEW_POINT: case Pending::DRAGGING_NEW_POINT:
UpdateDraggedPoint(pending.point, x, y); UpdateDraggedPoint(pending.point, x, y);
@ -453,17 +453,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
case Pending::DRAGGING_MARQUEE: case Pending::DRAGGING_MARQUEE:
orig.mouse = mp; orig.mouse = mp;
InvalidateGraphics(); InvalidateGraphics();
break; return;
default: ssassert(false, "Unexpected pending operation"); case Pending::NONE:
case Pending::COMMAND:
ssassert(false, "Unexpected pending operation");
} }
if(pending.operation != Pending::NONE && SS.GenerateAll();
pending.operation != Pending::DRAGGING_CONSTRAINT &&
pending.operation != Pending::DRAGGING_MARQUEE)
{
SS.GenerateAll();
}
} }
void GraphicsWindow::ClearPending() { void GraphicsWindow::ClearPending() {
@ -511,11 +508,9 @@ void GraphicsWindow::MouseRightUp(double x, double y) {
if(context.active) return; if(context.active) return;
if(pending.operation == Pending::DRAGGING_NEW_LINE_POINT) { if(pending.operation == Pending::DRAGGING_NEW_LINE_POINT && pending.hasSuggestion) {
if(SS.GW.pending.suggestion != Constraint::Type::UNKNOWN) { Constraint::Constrain(SS.GW.pending.suggestion,
Constraint::Constrain(SS.GW.pending.suggestion, Entity::NO_ENTITY, Entity::NO_ENTITY, pending.request.entity(0));
Entity::NO_ENTITY, Entity::NO_ENTITY, pending.request.entity(0));
}
} }
if(pending.operation == Pending::DRAGGING_NEW_LINE_POINT || if(pending.operation == Pending::DRAGGING_NEW_LINE_POINT ||
@ -1134,7 +1129,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
case Pending::DRAGGING_NEW_LINE_POINT: { case Pending::DRAGGING_NEW_LINE_POINT: {
// Constrain the line segment horizontal or vertical if close enough // Constrain the line segment horizontal or vertical if close enough
if(SS.GW.pending.suggestion != Constraint::Type::UNKNOWN) { if(SS.GW.pending.hasSuggestion) {
Constraint::Constrain(SS.GW.pending.suggestion, Constraint::Constrain(SS.GW.pending.suggestion,
Entity::NO_ENTITY, Entity::NO_ENTITY, pending.request.entity(0)); Entity::NO_ENTITY, Entity::NO_ENTITY, pending.request.entity(0));
} }

View File

@ -13,20 +13,20 @@ const hRequest Request::HREQUEST_REFERENCE_YZ = { 2 };
const hRequest Request::HREQUEST_REFERENCE_ZX = { 3 }; const hRequest Request::HREQUEST_REFERENCE_ZX = { 3 };
const EntReqTable::TableEntry EntReqTable::Table[] = { const EntReqTable::TableEntry EntReqTable::Table[] = {
// request type entity type pts xtra? norml dist description // request type entity type pts xtra? norml dist description
{ Request::Type::WORKPLANE, Entity::Type::WORKPLANE, 1, false, true, false, "workplane" }, { Request::Type::WORKPLANE, Entity::Type::WORKPLANE, 1, false, true, false, "workplane" },
{ Request::Type::DATUM_POINT, Entity::Type::DATUM_POINT, 1, false, false, false, "datum-point" }, { Request::Type::DATUM_POINT, (Entity::Type)0, 1, false, false, false, "datum-point" },
{ Request::Type::LINE_SEGMENT, Entity::Type::LINE_SEGMENT, 2, false, false, false, "line-segment" }, { Request::Type::LINE_SEGMENT, Entity::Type::LINE_SEGMENT, 2, false, false, false, "line-segment" },
{ Request::Type::CUBIC, Entity::Type::CUBIC, 4, true, false, false, "cubic-bezier" }, { Request::Type::CUBIC, Entity::Type::CUBIC, 4, true, false, false, "cubic-bezier" },
{ Request::Type::CUBIC_PERIODIC, Entity::Type::CUBIC_PERIODIC, 3, true, false, false, "periodic-cubic" }, { Request::Type::CUBIC_PERIODIC, Entity::Type::CUBIC_PERIODIC, 3, true, false, false, "periodic-cubic" },
{ Request::Type::CIRCLE, Entity::Type::CIRCLE, 1, false, true, true, "circle" }, { Request::Type::CIRCLE, Entity::Type::CIRCLE, 1, false, true, true, "circle" },
{ Request::Type::ARC_OF_CIRCLE, Entity::Type::ARC_OF_CIRCLE, 3, false, true, false, "arc-of-circle" }, { Request::Type::ARC_OF_CIRCLE, Entity::Type::ARC_OF_CIRCLE, 3, false, true, false, "arc-of-circle" },
{ Request::Type::TTF_TEXT, Entity::Type::TTF_TEXT, 2, false, true, false, "ttf-text" }, { Request::Type::TTF_TEXT, Entity::Type::TTF_TEXT, 2, false, true, false, "ttf-text" },
{ Request::Type::UNKNOWN, Entity::Type::UNKNOWN, 0, false, false, false, NULL }, { (Request::Type)0, (Entity::Type)0, 0, false, false, false, NULL },
}; };
const char *EntReqTable::DescriptionForRequest(Request::Type req) { const char *EntReqTable::DescriptionForRequest(Request::Type req) {
for(int i = 0; Table[i].reqType != Request::Type::UNKNOWN; i++) { for(int i = 0; Table[i].reqType != (Request::Type)0; i++) {
if(req == Table[i].reqType) { if(req == Table[i].reqType) {
return Table[i].description; return Table[i].description;
} }
@ -50,7 +50,7 @@ void EntReqTable::CopyEntityInfo(const TableEntry *te, int extraPoints,
bool EntReqTable::GetRequestInfo(Request::Type req, int extraPoints, bool EntReqTable::GetRequestInfo(Request::Type req, int extraPoints,
Entity::Type *ent, int *pts, bool *hasNormal, bool *hasDistance) Entity::Type *ent, int *pts, bool *hasNormal, bool *hasDistance)
{ {
for(int i = 0; Table[i].reqType != Request::Type::UNKNOWN; i++) { for(int i = 0; Table[i].reqType != (Request::Type)0; i++) {
const TableEntry *te = &(Table[i]); const TableEntry *te = &(Table[i]);
if(req == te->reqType) { if(req == te->reqType) {
CopyEntityInfo(te, extraPoints, CopyEntityInfo(te, extraPoints,
@ -64,7 +64,7 @@ bool EntReqTable::GetRequestInfo(Request::Type req, int extraPoints,
bool EntReqTable::GetEntityInfo(Entity::Type ent, int extraPoints, bool EntReqTable::GetEntityInfo(Entity::Type ent, int extraPoints,
Request::Type *req, int *pts, bool *hasNormal, bool *hasDistance) Request::Type *req, int *pts, bool *hasNormal, bool *hasDistance)
{ {
for(int i = 0; Table[i].reqType != Request::Type::UNKNOWN; i++) { for(int i = 0; Table[i].reqType != (Request::Type)0; i++) {
const TableEntry *te = &(Table[i]); const TableEntry *te = &(Table[i]);
if(ent == te->entType) { if(ent == te->entType) {
CopyEntityInfo(te, extraPoints, CopyEntityInfo(te, extraPoints,
@ -76,8 +76,9 @@ bool EntReqTable::GetEntityInfo(Entity::Type ent, int extraPoints,
} }
Request::Type EntReqTable::GetRequestForEntity(Entity::Type ent) { Request::Type EntReqTable::GetRequestForEntity(Entity::Type ent) {
Request::Type req = Request::Type::UNKNOWN; Request::Type req;
GetEntityInfo(ent, 0, &req, NULL, NULL, NULL); ssassert(GetEntityInfo(ent, 0, &req, NULL, NULL, NULL),
"No entity for request");
return req; return req;
} }
@ -86,14 +87,13 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
IdList<Param,hParam> *param) const IdList<Param,hParam> *param) const
{ {
int points = 0; int points = 0;
Entity::Type et = Entity::Type::UNKNOWN; Entity::Type et;
bool hasNormal = false; bool hasNormal = false;
bool hasDistance = false; bool hasDistance = false;
int i; int i;
Entity e = {}; Entity e = {};
EntReqTable::GetRequestInfo(type, extraPoints, EntReqTable::GetRequestInfo(type, extraPoints, &et, &points, &hasNormal, &hasDistance);
&et, &points, &hasNormal, &hasDistance);
// Generate the entity that's specific to this request. // Generate the entity that's specific to this request.
e.type = et; e.type = et;
@ -111,7 +111,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
Entity p = {}; Entity p = {};
p.workplane = workplane; p.workplane = workplane;
// points start from entity 1, except for datum point case // points start from entity 1, except for datum point case
p.h = h.entity(i+((et != Entity::Type::DATUM_POINT) ? 1 : 0)); p.h = h.entity(i+((et != (Entity::Type)0) ? 1 : 0));
p.group = group; p.group = group;
p.style = style; p.style = style;
@ -166,7 +166,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
e.distance = d.h; e.distance = d.h;
} }
if(et != Entity::Type::DATUM_POINT) entity->Add(&e); if(et != (Entity::Type)0) entity->Add(&e);
} }
std::string Request::DescriptionString() const { std::string Request::DescriptionString() const {

View File

@ -299,7 +299,6 @@ public:
// Types of requests // Types of requests
enum class Type : uint32_t { enum class Type : uint32_t {
UNKNOWN = 0,
WORKPLANE = 100, WORKPLANE = 100,
DATUM_POINT = 101, DATUM_POINT = 101,
LINE_SEGMENT = 200, LINE_SEGMENT = 200,
@ -340,8 +339,6 @@ public:
static const hEntity NO_ENTITY; static const hEntity NO_ENTITY;
enum class Type : uint32_t { enum class Type : uint32_t {
DATUM_POINT = 0,
UNKNOWN = 1000,
POINT_IN_3D = 2000, POINT_IN_3D = 2000,
POINT_IN_2D = 2001, POINT_IN_2D = 2001,
POINT_N_TRANS = 2010, POINT_N_TRANS = 2010,
@ -364,7 +361,6 @@ public:
FACE_N_TRANS = 5003, FACE_N_TRANS = 5003,
FACE_N_ROT_AA = 5004, FACE_N_ROT_AA = 5004,
WORKPLANE = 10000, WORKPLANE = 10000,
LINE_SEGMENT = 11000, LINE_SEGMENT = 11000,
CUBIC = 12000, CUBIC = 12000,
@ -609,7 +605,6 @@ public:
static const hConstraint NO_CONSTRAINT; static const hConstraint NO_CONSTRAINT;
enum class Type : uint32_t { enum class Type : uint32_t {
UNKNOWN = 0,
POINTS_COINCIDENT = 20, POINTS_COINCIDENT = 20,
PT_PT_DISTANCE = 30, PT_PT_DISTANCE = 30,
PT_PLANE_DISTANCE = 31, PT_PLANE_DISTANCE = 31,

View File

@ -419,9 +419,8 @@ bool SolveSpaceUI::OkayToStartNewFile() {
case DIALOG_CANCEL: case DIALOG_CANCEL:
return false; return false;
default: ssassert(false, "Unexpected dialog choice");
} }
ssassert(false, "Unexpected dialog choice");
} }
void SolveSpaceUI::UpdateWindowTitle() { void SolveSpaceUI::UpdateWindowTitle() {

View File

@ -221,7 +221,7 @@ static bool KeepRegion(SSurface::CombineAs type, bool opA, SShell::Class shell,
return (inShell && !inFace) || inSame; return (inShell && !inFace) || inSame;
} }
default: ssassert(false, "Unexpected shell type"); default: ssassert(false, "Unexpected combine type");
} }
} }
static bool KeepEdge(SSurface::CombineAs type, bool opA, static bool KeepEdge(SSurface::CombineAs type, bool opA,

View File

@ -503,6 +503,8 @@ void TextWindow::ShowGroupSolveInfo() {
case SolveResult::TOO_MANY_UNKNOWNS: case SolveResult::TOO_MANY_UNKNOWNS:
Printf(true, "Too many unknowns in a single group!"); Printf(true, "Too many unknowns in a single group!");
return; return;
default: ssassert(false, "Unexpected solve result");
} }
for(int i = 0; i < g->solved.remove.n; i++) { for(int i = 0; i < g->solved.remove.n; i++) {

View File

@ -598,13 +598,14 @@ public:
const char *description; const char *description;
Constraint::Type suggestion; bool hasSuggestion;
Constraint::Type suggestion;
} pending; } pending;
void ClearPending(); void ClearPending();
// The constraint that is being edited with the on-screen textbox. // The constraint that is being edited with the on-screen textbox.
hConstraint constraintBeingEdited; hConstraint constraintBeingEdited;
ConstraintBase::Type SuggestLineConstraint(hRequest lineSegment); bool SuggestLineConstraint(hRequest lineSegment, ConstraintBase::Type *type);
Vector SnapToGrid(Vector p); Vector SnapToGrid(Vector p);
bool ConstrainPointByHovered(hEntity pt); bool ConstrainPointByHovered(hEntity pt);