Commit: 202bb321343a5545d0d31d195f64b487d4c40c54
Author: Sergey Sharybin
Date:   Fri Jan 3 01:44:46 2014 +0600
https://developer.blender.org/rB202bb321343a5545d0d31d195f64b487d4c40c54

Fix T37056: Making segment flips curves it's not needed

Made the system around splines order a bit smarter, so
crating a segment between two splines wouldn't switch
direction if splines are selected in a way that they're
"co-linear".

It is possible to make things even smarter using active
point and so, but that i'd consider a TODO.

===================================================================

M       source/blender/editors/curve/editcurve.c

===================================================================

diff --git a/source/blender/editors/curve/editcurve.c 
b/source/blender/editors/curve/editcurve.c
index bc97515..6664433 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -4151,67 +4151,81 @@ static int make_segment_exec(bContext *C, wmOperator 
*op)
 
                if ((nu->flagu & CU_NURB_CYCLIC) == 0) {    /* not cyclic */
                        if (nu->type == CU_BEZIER) {
-                               if (nu1 == NULL) {
-                                       if (BEZSELECTED_HIDDENHANDLES(cu, 
nu->bezt)) {
-                                               nu1 = nu;
+                               if (BEZSELECTED_HIDDENHANDLES(cu, 
&(nu->bezt[nu->pntsu - 1]))) {
+                                       /* Last point is selected, preferred 
for nu2 */
+                                       if (nu2 == NULL) {
+                                               nu2 = nu;
                                        }
-                                       else {
-                                               if 
(BEZSELECTED_HIDDENHANDLES(cu, &(nu->bezt[nu->pntsu - 1]))) {
-                                                       nu1 = nu;
-                                                       
BKE_nurb_direction_switch(nu);
-                                                       
keyData_switchDirectionNurb(cu, nu);
+                                       else if (nu1 == NULL) {
+                                               nu1 = nu;
+
+                                               /* Just in case both of 
first/last CV are selected check
+                                                * whether we really need to 
switch the direction.
+                                                */
+                                               if 
(!BEZSELECTED_HIDDENHANDLES(cu, nu1->bezt)) {
+                                                       
BKE_nurb_direction_switch(nu1);
+                                                       
keyData_switchDirectionNurb(cu, nu1);
                                                }
                                        }
                                }
-                               else if (nu2 == NULL) {
-                                       if (BEZSELECTED_HIDDENHANDLES(cu, 
nu->bezt)) {
-                                               nu2 = nu;
-                                               BKE_nurb_direction_switch(nu);
-                                               keyData_switchDirectionNurb(cu, 
nu);
+                               else if (BEZSELECTED_HIDDENHANDLES(cu, 
nu->bezt)) {
+                                       /* First point is selected, preferred 
for nu1 */
+                                       if (nu1 == NULL) {
+                                               nu1 = nu;
                                        }
-                                       else {
-                                               if 
(BEZSELECTED_HIDDENHANDLES(cu, &(nu->bezt[nu->pntsu - 1]))) {
-                                                       nu2 = nu;
+                                       else if (nu2 == NULL) {
+                                               nu2 = nu;
+
+                                               /* Just in case both of 
first/last CV are selected check
+                                                * whether we really need to 
switch the direction.
+                                                */
+                                               if 
(!BEZSELECTED_HIDDENHANDLES(cu, &(nu->bezt[nu2->pntsu - 1]))) {
+                                                       
BKE_nurb_direction_switch(nu2);
+                                                       
keyData_switchDirectionNurb(cu, nu2);
                                                }
                                        }
                                }
-                               else {
-                                       break;
-                               }
                        }
                        else if (nu->pntsv == 1) {
+                               /* Same logic as above: if first point is 
selected spline is
+                                * preferred for nu1, if last point is selected 
spline is
+                                * preferred for u2u.
+                                */
+
                                bp = nu->bp;
-                               if (nu1 == NULL) {
-                                       if (bp->f1 & SELECT) {
-                                               nu1 = nu;
+                               if (bp[nu->pntsu - 1].f1 & SELECT)  {
+                                       if (nu2 == NULL) {
+                                               nu2 = nu;
                                        }
-                                       else {
-                                               bp = bp + (nu->pntsu - 1);
-                                               if (bp->f1 & SELECT) {
-                                                       nu1 = nu;
+                                       else if (nu1 == NULL) {
+                                               nu1 = nu;
+
+                                               if ((bp->f1 & SELECT) == 0) {
                                                        
BKE_nurb_direction_switch(nu);
                                                        
keyData_switchDirectionNurb(cu, nu);
                                                }
                                        }
                                }
-                               else if (nu2 == NULL) {
-                                       if (bp->f1 & SELECT) {
-                                               nu2 = nu;
-                                               BKE_nurb_direction_switch(nu);
-                                               keyData_switchDirectionNurb(cu, 
nu);
+                               else if (bp->f1 & SELECT) {
+                                       if (nu1 == NULL) {
+                                               nu1 = nu;
                                        }
-                                       else {
-                                               bp = bp + (nu->pntsu - 1);
-                                               if (bp->f1 & SELECT) {
-                                                       nu2 = nu;
+                                       else if (nu2 == NULL) {
+                                               nu2 = nu;
+
+                                               if ((bp[nu->pntsu - 1].f1 & 
SELECT) == 0) {
+                                                       
BKE_nurb_direction_switch(nu);
+                                                       
keyData_switchDirectionNurb(cu, nu);
                                                }
                                        }
                                }
-                               else {
-                                       break;
-                               }
                        }
                }
+
+               if (nu1 && nu2) {
+                       /* Got second spline, no need to loop over rest of the 
splines. */
+                       break;
+               }
        }
 
        if ((nu1 && nu2) && (nu1 != nu2)) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to