Skip to content

Commit b0a9264

Browse files
committed
Relax point coincident constraint
1 parent b316a88 commit b0a9264

1 file changed

Lines changed: 67 additions & 34 deletions

File tree

src/constraint.cpp

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void Constraint::MenuConstrain(Command id) {
134134

135135
SS.GW.GroupSelection();
136136
auto const &gs = SS.GW.gs;
137-
138137
switch(id) {
139138
case Command::DISTANCE_DIA:
140139
case Command::REF_DISTANCE: {
@@ -199,11 +198,20 @@ void Constraint::MenuConstrain(Command id) {
199198
break;
200199
}
201200

202-
case Command::ON_ENTITY:
203-
if(gs.points == 2 && gs.n == 2) {
204-
c.type = Type::POINTS_COINCIDENT;
205-
c.ptA = gs.point[0];
206-
c.ptB = gs.point[1];
201+
case Command::ON_ENTITY: {
202+
bool dontAddConstraint = false;
203+
if(gs.points % 2 == 0) {
204+
dontAddConstraint = true;
205+
for (int i = 0; i < gs.points / 2; i++) {
206+
Constraint c = {};
207+
c.group = SS.GW.activeGroup;
208+
c.workplane = SS.GW.ActiveWorkplane();
209+
c.type = Type::POINTS_COINCIDENT;
210+
int doubleI = i * 2;
211+
c.ptA = gs.point[doubleI];
212+
c.ptB = gs.point[doubleI + 1];
213+
AddConstraint(&c, i == 0);
214+
}
207215
} else if(gs.points == 1 && gs.workplanes == 1 && gs.n == 2) {
208216
c.type = Type::PT_IN_PLANE;
209217
c.ptA = gs.point[0];
@@ -230,14 +238,24 @@ void Constraint::MenuConstrain(Command id) {
230238
" * a point and a plane face (point on face)\n"));
231239
return;
232240
}
233-
AddConstraint(&c);
241+
if (!dontAddConstraint) {
242+
AddConstraint(&c);
243+
}
234244
break;
235-
236-
case Command::EQUAL:
237-
if(gs.lineSegments == 2 && gs.n == 2) {
238-
c.type = Type::EQUAL_LENGTH_LINES;
239-
c.entityA = gs.entity[0];
240-
c.entityB = gs.entity[1];
245+
}
246+
case Command::EQUAL: {
247+
bool dontAddConstraint = false;
248+
if(gs.n == gs.lineSegments) {
249+
dontAddConstraint = true;
250+
for (int i = 0; i < gs.lineSegments - 1; i++) {
251+
Constraint c = {};
252+
c.group = SS.GW.activeGroup;
253+
c.workplane = SS.GW.ActiveWorkplane();
254+
c.type = Type::EQUAL_LENGTH_LINES;
255+
c.entityA = gs.entity[i];
256+
c.entityB = gs.entity[i + 1];
257+
AddConstraint(&c, i == 0);
258+
}
241259
} else if(gs.lineSegments == 2 && gs.points == 2 && gs.n == 4) {
242260
c.type = Type::EQ_PT_LN_DISTANCES;
243261
c.entityA = gs.entity[0];
@@ -269,10 +287,17 @@ void Constraint::MenuConstrain(Command id) {
269287
c.entityB = gs.vector[1];
270288
c.entityC = gs.vector[1];
271289
c.entityD = gs.vector[2];
272-
} else if(gs.circlesOrArcs == 2 && gs.n == 2) {
273-
c.type = Type::EQUAL_RADIUS;
274-
c.entityA = gs.entity[0];
275-
c.entityB = gs.entity[1];
290+
} else if(gs.n == gs.circlesOrArcs) {
291+
dontAddConstraint = true;
292+
for (int i = 0; i < gs.circlesOrArcs - 1; i++) {
293+
Constraint c = {};
294+
c.group = SS.GW.activeGroup;
295+
c.workplane = SS.GW.ActiveWorkplane();
296+
c.type = Type::EQUAL_RADIUS;
297+
c.entityA = gs.entity[i];
298+
c.entityB = gs.entity[i + 1];
299+
AddConstraint(&c);
300+
}
276301
} else if(gs.arcs == 1 && gs.lineSegments == 1 && gs.n == 2) {
277302
c.type = Type::EQUAL_LINE_ARC_LEN;
278303
if(SK.GetEntity(gs.entity[0])->type == Entity::Type::ARC_OF_CIRCLE) {
@@ -313,9 +338,11 @@ void Constraint::MenuConstrain(Command id) {
313338
c.other = true;
314339
}
315340
}
316-
AddConstraint(&c);
341+
if (!dontAddConstraint) {
342+
AddConstraint(&c);
343+
}
317344
break;
318-
345+
}
319346
case Command::RATIO:
320347
if(gs.lineSegments == 2 && gs.n == 2) {
321348
c.type = Type::LENGTH_RATIO;
@@ -465,33 +492,39 @@ void Constraint::MenuConstrain(Command id) {
465492

466493
case Command::VERTICAL:
467494
case Command::HORIZONTAL: {
468-
hEntity ha, hb;
469495
if(c.workplane == Entity::FREE_IN_3D) {
470496
Error(_("Activate a workplane (with Sketch -> In Workplane) before "
471497
"applying a horizontal or vertical constraint."));
472498
return;
473499
}
474-
if(gs.lineSegments == 1 && gs.n == 1) {
475-
c.entityA = gs.entity[0];
476-
Entity *e = SK.GetEntity(c.entityA);
477-
ha = e->point[0];
478-
hb = e->point[1];
479-
} else if(gs.points == 2 && gs.n == 2) {
480-
ha = c.ptA = gs.point[0];
481-
hb = c.ptB = gs.point[1];
500+
if(gs.lineSegments == gs.n) {
501+
for (int i = 0; i < gs.lineSegments; i++) {
502+
Constraint c = {};
503+
c.group = SS.GW.activeGroup;
504+
c.workplane = SS.GW.ActiveWorkplane();
505+
c.type = id == Command::HORIZONTAL ? Type::HORIZONTAL : Type::VERTICAL;
506+
c.entityA = gs.entity[i];
507+
DeleteAllConstraintsFor(c.type, gs.entity[i], Entity::NO_ENTITY);
508+
AddConstraint(&c, i == 0);
509+
}
510+
} else if(gs.points % 2 == 0 && gs.n == gs.points) {
511+
for (int i = 0; i < gs.points / 2; i++) {
512+
Constraint c = {};
513+
c.group = SS.GW.activeGroup;
514+
c.workplane = SS.GW.ActiveWorkplane();
515+
c.type = id == Command::HORIZONTAL ? Type::HORIZONTAL : Type::VERTICAL;
516+
int doubleI = i * 2;
517+
c.ptA = gs.point[doubleI];
518+
c.ptB = gs.point[doubleI + 1];
519+
AddConstraint(&c, i == 0);
520+
}
482521
} else {
483522
Error(_("Bad selection for horizontal / vertical constraint. "
484523
"This constraint can apply to:\n\n"
485524
" * two points\n"
486525
" * a line segment\n"));
487526
return;
488527
}
489-
if(id == Command::HORIZONTAL) {
490-
c.type = Type::HORIZONTAL;
491-
} else {
492-
c.type = Type::VERTICAL;
493-
}
494-
AddConstraint(&c);
495528
break;
496529
}
497530

0 commit comments

Comments
 (0)