From a8465cbc8a373f591809b080c26028c489ce9a81 Mon Sep 17 00:00:00 2001 From: EvilSpirit Date: Wed, 4 May 2016 16:18:13 +0600 Subject: [PATCH] Flip extrusion normal when switching between union and difference. This is done because a meaningful union extrusion is almost never a meaningful difference extrusion, and saves a bunch of common manual work. To avoid creating invalid sketches this isn't done when there are any constraints. --- src/group.cpp | 20 ++++++++++++++++++++ src/sketch.h | 3 +++ src/textscreens.cpp | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/group.cpp b/src/group.cpp index 706e5efc..b8ed86c4 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 65e08214..d39e476f 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 5cf4eeb5..09ba5634 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;