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.
pull/4/head
EvilSpirit 2016-05-04 16:18:13 +06:00 committed by whitequark
parent affc88f342
commit a8465cbc8a
3 changed files with 32 additions and 1 deletions

View File

@ -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;

View File

@ -236,6 +236,9 @@ public:
void AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index);
void GenerateEquations(IdList<Equation,hEquation> *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.

View File

@ -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;