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")
# Same for the (C99) __func__ special variable; we use it only in C++ code.
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()
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)
set(WARNING_FLAGS "${WARNING_FLAGS} -Wfloat-conversion")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${WARNING_FLAGS}")
# We rely on these -Werror flags.
set(WARNING_FLAGS "${WARNING_FLAGS} -Werror=switch")
endif()
if(MINGW)
@ -97,6 +101,9 @@ if(SANITIZE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
# dependencies
find_package(OpenGL REQUIRED)

View File

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

View File

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

View File

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

View File

@ -271,7 +271,9 @@ void GraphicsWindow::GroupSelection() {
(gs.arcs)++;
break;
case Entity::Type::CIRCLE: (gs.circlesOrArcs)++; break;
case Entity::Type::CIRCLE: (gs.circlesOrArcs)++; break;
default: break;
}
}
if(s->constraint.v) {
@ -680,21 +682,20 @@ nogrid:;
// Draw the "pending" constraint, i.e. a constraint that would be
// placed on a line that is almost horizontal or vertical
if(SS.GW.pending.operation == Pending::DRAGGING_NEW_LINE_POINT) {
if(SS.GW.pending.suggestion != Constraint::Type::UNKNOWN) {
Constraint c = {};
c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane();
c.type = SS.GW.pending.suggestion;
c.ptA = Entity::NO_ENTITY;
c.ptB = Entity::NO_ENTITY;
c.entityA = SS.GW.pending.request.entity(0);
c.entityB = Entity::NO_ENTITY;
c.other = false;
c.other2 = false;
// Only draw.
c.Draw();
}
if(SS.GW.pending.operation == Pending::DRAGGING_NEW_LINE_POINT &&
SS.GW.pending.hasSuggestion) {
Constraint c = {};
c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane();
c.type = SS.GW.pending.suggestion;
c.ptA = Entity::NO_ENTITY;
c.ptB = Entity::NO_ENTITY;
c.entityA = SS.GW.pending.request.entity(0);
c.entityB = Entity::NO_ENTITY;
c.other = false;
c.other2 = false;
// Only draw.
c.Draw();
}
// 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);
DoLabel(ref, labelPos, gr, gu);
break;
return;
}
case Type::PROJ_PT_DISTANCE: {
@ -556,7 +556,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoLineWithArrows(ref, ap, bpp, false);
DoLabel(ref, labelPos, gr, gu);
break;
return;
}
case Type::PT_FACE_DISTANCE:
@ -583,7 +583,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
}
DoLabel(ref, labelPos, gr, gu);
break;
return;
}
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));
DoProjectedPoint(&c2);
}
break;
return;
}
case Type::DIAMETER: {
@ -657,7 +657,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Vector topLeft;
DoLabel(ref, &topLeft, gr, gu);
if(labelPos) *labelPos = topLeft;
break;
return;
}
case Type::POINTS_COINCIDENT: {
@ -671,7 +671,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
// constraint cannot be selected. But that's okay.
dogd.dmin = min(dogd.dmin, pp.DistanceTo(dogd.mp) - 3);
}
break;
return;
}
if(dogd.drawing) {
@ -704,7 +704,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
}
}
break;
return;
}
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.Minus(r).Minus(d), p.Minus(r).Plus (d));
LineDrawOrGetDistance(p.Minus(r).Plus (d), p.Plus (r).Plus (d));
break;
return;
}
case Type::WHERE_DRAGGED: {
@ -753,7 +753,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
ur = ur.RotatedAbout(p, gn, PI/2);
uu = uu.RotatedAbout(p, gn, PI/2);
}
break;
return;
}
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.Minus(u), p.Plus(u).Plus(n));
}
break;
return;
}
case Type::EQUAL_ANGLE: {
@ -800,7 +800,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
dc.WithMagnitude(40/SS.GW.scale), &ref, /*trim=*/false);
if(refps) refps[1] = ref;
break;
return;
}
case Type::ANGLE: {
@ -820,7 +820,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoArcForAngle(a0, da, b0, db, disp.offset, &ref, /*trim=*/true);
DoLabel(ref, labelPos, gr, gu);
if(refps) refps[0] = refps[1] = ref;
break;
return;
}
case Type::PERPENDICULAR: {
@ -859,7 +859,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
LineDrawOrGetDistance(m, m.Plus(u));
if(refps) refps[i] = m;
}
break;
return;
}
case Type::CURVE_CURVE_TANGENT:
@ -937,7 +937,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Point2d ref = SS.GW.ProjectPoint(textAt);
dogd.dmin = min(dogd.dmin, ref.DistanceTo(dogd.mp)-10);
}
break;
return;
}
case Type::PARALLEL: {
@ -952,7 +952,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
LineDrawOrGetDistance(p.Minus(u), p.Minus(u).Plus(n));
if(refps) refps[i] = p.Plus(n.ScaledBy(0.5));
}
break;
return;
}
case Type::EQUAL_RADIUS: {
@ -961,7 +961,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoEqualRadiusTicks(i == 0 ? entityA : entityB, &ref);
if(refps) refps[i] = ref;
}
break;
return;
}
case Type::EQUAL_LINE_ARC_LEN: {
@ -976,7 +976,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
refps[0] = refa;
refps[1] = refb;
}
break;
return;
}
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);
DoLabel(ref, labelPos, gr, gu);
}
break;
return;
}
case Type::EQ_LEN_PT_LINE_D: {
@ -1031,7 +1031,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
Vector refb;
DoEqualLenTicks(pt, closest, gn, &refb);
if(refps) refps[1] = refb;
break;
return;
}
case Type::EQ_PT_LN_DISTANCES: {
@ -1055,7 +1055,7 @@ void Constraint::DrawOrGetDistance(Vector *labelPos, Vector *refps) {
DoEqualLenTicks(pt, closest, gn, &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)));
}
break;
return;
}
case Type::AT_MIDPOINT:
@ -1173,7 +1173,7 @@ s:
}
}
}
break;
return;
case Type::COMMENT: {
if(dogd.drawing && disp.style.v) {
@ -1191,11 +1191,10 @@ s:
}
if(refps) refps[0] = refps[1] = disp.offset;
DoLabel(disp.offset, labelPos, u, v);
break;
return;
}
default: ssassert(false, "Unexpected constraint type");
}
ssassert(false, "Unexpected constraint type");
}
void Constraint::Draw() {

View File

@ -223,8 +223,17 @@ Vector Entity::GetReferencePos() {
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 {
@ -574,7 +583,7 @@ void Entity::DrawOrGetDistance() {
Point2d pp = SS.GW.ProjectPoint(v);
dogd.dmin = pp.DistanceTo(dogd.mp) - 6;
}
break;
return;
}
case Type::NORMAL_N_COPY:
@ -643,13 +652,13 @@ void Entity::DrawOrGetDistance() {
}
if(dogd.drawing)
ssglDepthRangeLockToFront(false);
break;
return;
}
case Type::DISTANCE:
case Type::DISTANCE_N_COPY:
// These are used only as data structures, nothing to display.
break;
return;
case Type::WORKPLANE: {
Vector p;
@ -703,7 +712,7 @@ void Entity::DrawOrGetDistance() {
// the plane.
dogd.dmin += 3;
}
break;
return;
}
case Type::LINE_SEGMENT:
@ -711,9 +720,17 @@ void Entity::DrawOrGetDistance() {
case Type::ARC_OF_CIRCLE:
case Type::CUBIC:
case Type::CUBIC_PERIODIC:
case Type::TTF_TEXT:
// Nothing but the curve(s).
break;
case Type::TTF_TEXT: {
// Nothing but 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);
}
return;
}
case Type::FACE_NORMAL_PT:
case Type::FACE_XPROD:
@ -721,18 +738,8 @@ void Entity::DrawOrGetDistance() {
case Type::FACE_N_TRANS:
case Type::FACE_N_ROT_AA:
// Do nothing; these are drawn with the triangle mesh
break;
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);
return;
}
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);
break;
}
default:;
// Most entities do not generate equations.
default: // Most entities do not generate equations.
break;
}
}

View File

@ -230,6 +230,10 @@ public:
type.path.push_back(0.0);
type.path.push_back(-sw);
break;
case StipplePattern::FREEHAND:
case StipplePattern::ZIGZAG:
ssassert(false, "Freehand and zigzag export not implemented");
}
dxf->writeLineType(&type);
}
@ -419,6 +423,10 @@ public:
st->textAngle, st->textOrigin, c->GetStyle());
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::COMMENT:
return c->IsVisible();
default: // See writeEntities().
break;
}
return false;
}
@ -731,8 +742,6 @@ static std::string MakeStipplePattern(StipplePattern pattern, double scale, char
std::string result;
switch(pattern) {
case StipplePattern::CONTINUOUS:
case StipplePattern::FREEHAND:
case StipplePattern::ZIGZAG:
return "";
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);
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);
return result;

View File

@ -284,8 +284,13 @@ int Expr::Children() const {
case Op::ACOS:
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 {
@ -353,8 +358,13 @@ double Expr::Eval() const {
case Op::ACOS: return acos(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 {
@ -396,8 +406,13 @@ Expr *Expr::PartialWrt(hParam p) const {
return (From(-1)->Div((From(1)->Minus(a->Square()))->Sqrt()))
->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 {
@ -487,7 +502,11 @@ Expr *Expr::FoldConstants() {
}
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;
}
@ -547,7 +566,6 @@ hParam Expr::ReferencedParams(ParamList *pl) const {
//-----------------------------------------------------------------------------
std::string Expr::Print() const {
char c;
switch(op) {
case Op::PARAM: return ssprintf("param(%08x)", parh.v);
@ -571,8 +589,13 @@ p:
case Op::ASIN: return "(asin " + 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;
break;
}
default: ssassert(false, "Unexpected generation mode");
}
// 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[1]));
break;
default: // Only the entities above can be dragged.
break;
}
}
}
@ -469,6 +470,9 @@ void SolveSpaceUI::MarkDraggedParams() {
case Entity::Type::DISTANCE:
sys.dragged.Add(&(dist->param[0]));
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[3]));
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::FREEHAND: stipplePattern = "~"; break;
case StipplePattern::ZIGZAG: stipplePattern = "~__"; break;
default: ssassert(false, "Unexpected stipple pattern");
}
ssglStippledLine(a, b, width, stipplePattern, stippleScale, maybeFat);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -228,8 +228,6 @@ default: dbp("bad constraint type %d", sc->type); return;
case SolveResult::TOO_MANY_UNKNOWNS:
ssys->result = SLVS_RESULT_TOO_MANY_UNKNOWNS;
break;
default: ssassert(false, "Unexpected solver result");
}
// 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;
default: ssassert(false, "Unexpected edge class");
}
cnt++;

View File

@ -276,15 +276,15 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
UpdateDraggedNum(&(c->disp.offset), x, y);
orig.mouse = mp;
InvalidateGraphics();
break;
return;
}
case Pending::DRAGGING_NEW_LINE_POINT:
if(!ctrlDown) {
SS.GW.pending.suggestion =
SS.GW.SuggestLineConstraint(SS.GW.pending.request);
SS.GW.pending.hasSuggestion =
SS.GW.SuggestLineConstraint(SS.GW.pending.request, &SS.GW.pending.suggestion);
} else {
SS.GW.pending.suggestion = Constraint::Type::UNKNOWN;
SS.GW.pending.hasSuggestion = false;
}
case Pending::DRAGGING_NEW_POINT:
UpdateDraggedPoint(pending.point, x, y);
@ -453,17 +453,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
case Pending::DRAGGING_MARQUEE:
orig.mouse = mp;
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 &&
pending.operation != Pending::DRAGGING_CONSTRAINT &&
pending.operation != Pending::DRAGGING_MARQUEE)
{
SS.GenerateAll();
}
SS.GenerateAll();
}
void GraphicsWindow::ClearPending() {
@ -511,11 +508,9 @@ void GraphicsWindow::MouseRightUp(double x, double y) {
if(context.active) return;
if(pending.operation == Pending::DRAGGING_NEW_LINE_POINT) {
if(SS.GW.pending.suggestion != Constraint::Type::UNKNOWN) {
Constraint::Constrain(SS.GW.pending.suggestion,
Entity::NO_ENTITY, Entity::NO_ENTITY, pending.request.entity(0));
}
if(pending.operation == Pending::DRAGGING_NEW_LINE_POINT && pending.hasSuggestion) {
Constraint::Constrain(SS.GW.pending.suggestion,
Entity::NO_ENTITY, Entity::NO_ENTITY, pending.request.entity(0));
}
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: {
// 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,
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 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::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::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::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::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) {
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) {
return Table[i].description;
}
@ -50,7 +50,7 @@ void EntReqTable::CopyEntityInfo(const TableEntry *te, int extraPoints,
bool EntReqTable::GetRequestInfo(Request::Type req, int extraPoints,
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]);
if(req == te->reqType) {
CopyEntityInfo(te, extraPoints,
@ -64,7 +64,7 @@ bool EntReqTable::GetRequestInfo(Request::Type req, int extraPoints,
bool EntReqTable::GetEntityInfo(Entity::Type ent, int extraPoints,
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]);
if(ent == te->entType) {
CopyEntityInfo(te, extraPoints,
@ -76,8 +76,9 @@ bool EntReqTable::GetEntityInfo(Entity::Type ent, int extraPoints,
}
Request::Type EntReqTable::GetRequestForEntity(Entity::Type ent) {
Request::Type req = Request::Type::UNKNOWN;
GetEntityInfo(ent, 0, &req, NULL, NULL, NULL);
Request::Type req;
ssassert(GetEntityInfo(ent, 0, &req, NULL, NULL, NULL),
"No entity for request");
return req;
}
@ -86,14 +87,13 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
IdList<Param,hParam> *param) const
{
int points = 0;
Entity::Type et = Entity::Type::UNKNOWN;
Entity::Type et;
bool hasNormal = false;
bool hasDistance = false;
int i;
Entity e = {};
EntReqTable::GetRequestInfo(type, extraPoints,
&et, &points, &hasNormal, &hasDistance);
EntReqTable::GetRequestInfo(type, extraPoints, &et, &points, &hasNormal, &hasDistance);
// Generate the entity that's specific to this request.
e.type = et;
@ -111,7 +111,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
Entity p = {};
p.workplane = workplane;
// 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.style = style;
@ -166,7 +166,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
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 {

View File

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

View File

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

View File

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

View File

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

View File

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