diff --git a/src/group.cpp b/src/group.cpp index 706e5ef..b8ed86c 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -51,6 +51,26 @@ bool Group::IsVisible(void) { return true; } +int Group::GetNumConstraints(void) { + int num = 0; + for(int i = 0; i < SK.constraint.n; i++) { + Constraint *c = &SK.constraint.elem[i]; + if(c->group.v != h.v) continue; + num++; + } + return num; +} + +Vector Group::ExtrusionGetVector() { + return Vector::From(h.param(0), h.param(1), h.param(2)); +} + +void Group::ExtrusionForceVectorTo(const Vector &v) { + SK.GetParam(h.param(0))->val = v.x; + SK.GetParam(h.param(1))->val = v.y; + SK.GetParam(h.param(2))->val = v.z; +} + void Group::MenuGroup(int id) { Group g = {}; g.visible = true; diff --git a/src/sketch.h b/src/sketch.h index 65e0821..d39e476 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -236,6 +236,9 @@ public: void AddEq(IdList *l, Expr *expr, int index); void GenerateEquations(IdList *l); bool IsVisible(void); + int GetNumConstraints(); + Vector ExtrusionGetVector(); + void ExtrusionForceVectorTo(const Vector &v); // Assembling the curves into loops, and into a piecewise linear polygon // at the same time. diff --git a/src/textscreens.cpp b/src/textscreens.cpp index 5cf4eeb..09ba563 100644 --- a/src/textscreens.cpp +++ b/src/textscreens.cpp @@ -191,7 +191,15 @@ void TextWindow::ScreenChangeGroupOption(int link, uint32_t v) { case 'k': g->skipFirst = true; break; case 'K': g->skipFirst = false; break; - case 'c': g->meshCombine = v; break; + case 'c': + // When an extrude group is first created, it's positioned for a union + // extrusion. If no constraints were added, flip it when we switch between + // union and difference modes to avoid manual work doing the smae. + if(g->meshCombine != v && g->GetNumConstraints() == 0) { + g->ExtrusionForceVectorTo(g->ExtrusionGetVector().Negated()); + } + g->meshCombine = v; + break; case 'P': g->suppress = !(g->suppress); break;