First commit and merge from trunk for testing.
authorIan Thompson <quornian@googlemail.com>
Mon, 26 May 2008 23:04:37 +0000 (23:04 +0000)
committerIan Thompson <quornian@googlemail.com>
Mon, 26 May 2008 23:04:37 +0000 (23:04 +0000)
Merge: 14970-14988

14 files changed:
1  2 
source/blender/blenkernel/BKE_curve.h
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/font.c
source/blender/blenlib/intern/freetypefont.c
source/blender/blenlib/intern/psfont.c
source/blender/include/BDR_editcurve.h
source/blender/nodes/intern/Makefile
source/blender/python/api2_2x/Particle.c
source/blender/src/buttons_editing.c
source/blender/src/editarmature.c
source/blender/src/editcurve.c
source/blender/src/poseobject.c
source/blender/src/transform_conversions.c

index 604446750471d8122d0007df4301314a2beab2d9,604446750471d8122d0007df4301314a2beab2d9..45d8193b16fd9d21b56a21c079b3f87b657e6400
@@@ -39,8 -39,8 +39,8 @@@ struct ListBase
  struct BezTriple;
  struct BevList;
  
--#define KNOTSU(nu)        ( (nu)->orderu+ (nu)->pntsu+ (nu->orderu-1)*((nu)->flagu & 1) )
--#define KNOTSV(nu)        ( (nu)->orderv+ (nu)->pntsv+ (nu->orderv-1)*((nu)->flagv & 1) )
++#define KNOTSU(nu)        ( (nu)->orderu+ (nu)->pntsu+ (nu->orderu-1)*((nu)->flagu & CU_CYCLIC) )
++#define KNOTSV(nu)        ( (nu)->orderv+ (nu)->pntsv+ (nu->orderv-1)*((nu)->flagv & CU_CYCLIC) )
  
  
  void unlink_curve( struct Curve *cu);
@@@ -84,5 -84,5 +84,12 @@@ void switchdirectionNurb( struct Nurb *
  float (*curve_getVertexCos(struct Curve *cu, struct ListBase *lb, int *numVerts_r))[3];
  void curve_applyVertexCos(struct Curve *cu, struct ListBase *lb, float (*vertexCos)[3]);
  
++/* nurb checks if they can be drawn, also clamp order func */
++int check_valid_nurb_u( struct Nurb *nu);
++int check_valid_nurb_v( struct Nurb *nu);
++
++int clamp_nurb_order_u( struct Nurb *nu);
++int clamp_nurb_order_v( struct Nurb *nu);
++
  #endif
  
index d02a7c0ab9e617c4f9ba255f70219f16fdef9e9d,d02a7c0ab9e617c4f9ba255f70219f16fdef9e9d..396bdda9c10528b7013b1b9a16aadcab9c1b1b7c
@@@ -348,9 -348,9 +348,9 @@@ void freeNurb(Nurb *nu
        if(nu->bp) MEM_freeN(nu->bp);
        nu->bp= 0;
        if(nu->knotsu) MEM_freeN(nu->knotsu);
--      nu->knotsu= 0;
++      nu->knotsu= NULL;
        if(nu->knotsv) MEM_freeN(nu->knotsv);
--      nu->knotsv= 0;
++      nu->knotsv= NULL;
        /* if(nu->trim.first) freeNurblist(&(nu->trim)); */
  
        MEM_freeN(nu);
@@@ -393,7 -393,7 +393,7 @@@ Nurb *duplicateNurb(Nurb *nu
                        (BPoint*)MEM_mallocN((len)* sizeof(BPoint),"duplicateNurb3");
                memcpy(newnu->bp, nu->bp, len*sizeof(BPoint));
                
--              newnu->knotsu=newnu->knotsv= 0;
++              newnu->knotsu= newnu->knotsv= NULL;
                
                if(nu->knotsu) {
                        len= KNOTSU(nu);
@@@ -506,6 -506,6 +506,7 @@@ static void calcknots(float *knots, sho
                }
        }
        else if(type==2) {
++              /* Warning, the order MUST be 2 or 4, if this is not enforced, the displist will be corrupt */
                if(order==4) {
                        k= 0.34;
                        for(a=0;a<t;a++) {
                                knots[a]= (float)floor(k);
                        }
                }
++              else {
++                      printf("bez nurb curve order is not 3 or 4, should never happen\n");
++              }
        }
  }
  
@@@ -529,7 -529,7 +533,8 @@@ static void makecyclicknots(float *knot
        int a, b, order2, c;
  
        if(knots==0) return;
--        order2=order-1;
++
++      order2=order-1;
  
        /* do first long rows (order -1), remove identical knots at endpoints */
        if(order>2) {
  }
  
  
--void makeknots(Nurb *nu, short uv, short type)        /* 0: uniform, 1: endpoints, 2: bezier */
++/* type - 0: uniform, 1: endpoints, 2: bezier, note, cyclic nurbs are always uniform */
++void makeknots(Nurb *nu, short uv, short type)
  {
        if( (nu->type & 7)==CU_NURBS ) {
--              if(uv & 1) {
++              if(uv == 1) {
                        if(nu->knotsu) MEM_freeN(nu->knotsu);
--                      if(nu->pntsu>1) {
++                      if(check_valid_nurb_u(nu)) {
                                nu->knotsu= MEM_callocN(4+sizeof(float)*KNOTSU(nu), "makeknots");
--                              calcknots(nu->knotsu, nu->pntsu, nu->orderu, type);
--                              if(nu->flagu & 1) makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu);
++                              if(nu->flagu & CU_CYCLIC) {
++                                      calcknots(nu->knotsu, nu->pntsu, nu->orderu, 0);  /* cyclic should be uniform */
++                                      makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu);
++                              } else {
++                                      calcknots(nu->knotsu, nu->pntsu, nu->orderu, type);
++                              }
                        }
--                      else nu->knotsu= 0;
--              }
--              if(uv & 2) {
++                      else nu->knotsu= NULL;
++              
++              } else if(uv == 2) {
                        if(nu->knotsv) MEM_freeN(nu->knotsv);
--                      if(nu->pntsv>1) {
++                      if(check_valid_nurb_v(nu)) {
                                nu->knotsv= MEM_callocN(4+sizeof(float)*KNOTSV(nu), "makeknots");
--                              calcknots(nu->knotsv, nu->pntsv, nu->orderv, type);
--                              if(nu->flagv & 1) makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv);
++                              if(nu->flagv & CU_CYCLIC) {
++                                      calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0);  /* cyclic should be uniform */
++                                      makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv);
++                              } else {
++                                      calcknots(nu->knotsv, nu->pntsv, nu->orderv, type);
++                              }
                        }
--                      else nu->knotsv= 0;
++                      else nu->knotsv= NULL;
                }
        }
  }
@@@ -645,7 -645,7 +659,7 @@@ void makeNurbfaces(Nurb *nu, float *dat
        int i, j, iofs, jofs, cycl, len, resolu, resolv;
        int istart, iend, jsta, jen, *jstart, *jend, ratcomp;
  
--      if(nu->knotsu==0 || nu->knotsv==0) return;
++      if(nu->knotsu==NULL || nu->knotsv==NULL) return;
        if(nu->orderu>nu->pntsu) return;
        if(nu->orderv>nu->pntsv) return;
        if(data==0) return;
  
        fp= nu->knotsu;
        ustart= fp[nu->orderu-1];
--      if(nu->flagu & 1) uend= fp[nu->pntsu+nu->orderu-1];
++      if(nu->flagu & CU_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1];
        else uend= fp[nu->pntsu];
--      ustep= (uend-ustart)/(resolu-1+(nu->flagu & 1));
++      ustep= (uend-ustart)/(resolu-1+(nu->flagu & CU_CYCLIC));
        basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbfaces3");
  
        fp= nu->knotsv;
        vstart= fp[nu->orderv-1];
        
--      if(nu->flagv & 1) vend= fp[nu->pntsv+nu->orderv-1];
++      if(nu->flagv & CU_CYCLIC) vend= fp[nu->pntsv+nu->orderv-1];
        else vend= fp[nu->pntsv];
--      vstep= (vend-vstart)/(resolv-1+(nu->flagv & 1));
++      vstep= (vend-vstart)/(resolv-1+(nu->flagv & CU_CYCLIC));
        len= KNOTSV(nu);
        basisv= (float *)MEM_mallocN(sizeof(float)*len*resolv, "makeNurbfaces3");
        jstart= (int *)MEM_mallocN(sizeof(float)*resolv, "makeNurbfaces4");
        jend= (int *)MEM_mallocN(sizeof(float)*resolv, "makeNurbfaces5");
  
        /* precalculation of basisv and jstart,jend */
--      if(nu->flagv & 1) cycl= nu->orderv-1; 
++      if(nu->flagv & CU_CYCLIC) cycl= nu->orderv-1; 
        else cycl= 0;
        v= vstart;
        basis= basisv;
                v+= vstep;
        }
  
--      if(nu->flagu & 1) cycl= nu->orderu-1; 
++      if(nu->flagu & CU_CYCLIC) cycl= nu->orderu-1; 
        else cycl= 0;
        in= data;
        u= ustart;
@@@ -803,7 -803,7 +817,7 @@@ void makeNurbcurve(Nurb *nu, float *dat
        float *basisu, *sum, *fp,  *in;
        int i, len, istart, iend, cycl;
  
--      if(nu->knotsu==0) return;
++      if(nu->knotsu==NULL) return;
        if(nu->orderu>nu->pntsu) return;
        if(data==0) return;
  
  
        fp= nu->knotsu;
        ustart= fp[nu->orderu-1];
--      if(nu->flagu & 1) uend= fp[nu->pntsu+nu->orderu-1];
++      if(nu->flagu & CU_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1];
        else uend= fp[nu->pntsu];
--      ustep= (uend-ustart)/(resolu-1+(nu->flagu & 1));
++      ustep= (uend-ustart)/(resolu-1+(nu->flagu & CU_CYCLIC));
        basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3");
  
--      if(nu->flagu & 1) cycl= nu->orderu-1; 
++      if(nu->flagu & CU_CYCLIC) cycl= nu->orderu-1; 
        else cycl= 0;
  
        in= data;
@@@ -1425,14 -1425,14 +1439,14 @@@ static void alfa_bezpart(BezTriple *pre
        
        /* returns a point */
        if(prevbezt==nu->bezt) {
--              if(nu->flagu & 1) pprev= last;
++              if(nu->flagu & CU_CYCLIC) pprev= last;
                else pprev= prevbezt;
        }
        else pprev= prevbezt-1;
        
        /* next point */
        if(bezt==last) {
--              if(nu->flagu & 1) next= nu->bezt;
++              if(nu->flagu & CU_CYCLIC) next= nu->bezt;
                else next= bezt;
        }
        else next= bezt+1;
@@@ -1478,7 -1478,7 +1492,7 @@@ void makeBevelList(Object *ob
        while(nu) {
                /* check we are a single point? also check we are not a surface and that the orderu is sane,
                 * enforced in the UI but can go wrong possibly */
--              if(nu->pntsu<2 || ((nu->type & 7)==CU_NURBS && nu->pntsu < nu->orderu)) {
++              if(!check_valid_nurb_u(nu)) {
                        bl= MEM_callocN(sizeof(BevList)+1*sizeof(BevPoint), "makeBevelList");
                        BLI_addtail(&(cu->bev), bl);
                        bl->nr= 0;
                                bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList");
                                BLI_addtail(&(cu->bev), bl);
        
--                              if(nu->flagu & 1) bl->poly= 0;
++                              if(nu->flagu & CU_CYCLIC) bl->poly= 0;
                                else bl->poly= -1;
                                bl->nr= len;
                                bl->flag= 0;
                        }
                        else if((nu->type & 7)==CU_BEZIER) {
        
--                              len= resolu*(nu->pntsu+ (nu->flagu & 1) -1)+1;  /* in case last point is not cyclic */
++                              len= resolu*(nu->pntsu+ (nu->flagu & CU_CYCLIC) -1)+1;  /* in case last point is not cyclic */
                                bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList");
                                BLI_addtail(&(cu->bev), bl);
        
--                              if(nu->flagu & 1) bl->poly= 0;
++                              if(nu->flagu & CU_CYCLIC) bl->poly= 0;
                                else bl->poly= -1;
                                bevp= (BevPoint *)(bl+1);
        
                                a= nu->pntsu-1;
                                bezt= nu->bezt;
--                              if(nu->flagu & 1) {
++                              if(nu->flagu & CU_CYCLIC) {
                                        a++;
                                        prevbezt= nu->bezt+(nu->pntsu-1);
                                }
                                MEM_freeN(data);
                                MEM_freeN(data_a);
                                
--                              if((nu->flagu & 1)==0) {            /* not cyclic: endpoint */
++                              if((nu->flagu & CU_CYCLIC)==0) {            /* not cyclic: endpoint */
                                        bevp->x= prevbezt->vec[1][0];
                                        bevp->y= prevbezt->vec[1][1];
                                        bevp->z= prevbezt->vec[1][2];
                                        BLI_addtail(&(cu->bev), bl);
                                        bl->nr= len;
                                        bl->flag= 0;
--                                      if(nu->flagu & 1) bl->poly= 0;
++                                      if(nu->flagu & CU_CYCLIC) bl->poly= 0;
                                        else bl->poly= -1;
                                        bevp= (BevPoint *)(bl+1);
        
@@@ -2209,7 -2209,7 +2223,7 @@@ void calchandlesNurb(Nurb *nu) /* first
        
        a= nu->pntsu;
        bezt= nu->bezt;
--      if(nu->flagu & 1) prev= bezt+(a-1);
++      if(nu->flagu & CU_CYCLIC) prev= bezt+(a-1);
        else prev= 0;
        next= bezt+1;
  
                calchandleNurb(bezt, prev, next, 0);
                prev= bezt;
                if(a==1) {
--                      if(nu->flagu & 1) next= nu->bezt;
++                      if(nu->flagu & CU_CYCLIC) next= nu->bezt;
                        else next= 0;
                }
                else next++;
@@@ -2608,3 -2608,3 +2622,63 @@@ void curve_applyVertexCos(Curve *cu, Li
                }
        }
  }
++
++int check_valid_nurb_u( struct Nurb *nu )
++{
++      if (nu==NULL)                                           return 0;
++      if (nu->pntsu <= 1)                                     return 0;
++      if ((nu->type & 7)!=CU_NURBS)           return 1; /* not a nurb, lets assume its valid */
++      
++      if (nu->pntsu < nu->orderu)                     return 0;
++      if (((nu->flag & CU_CYCLIC)==0) && ((nu->flagu>>1) & 2)) { /* Bezier U Endpoints */
++              if (nu->orderu==4) {
++                      if (nu->pntsu < 5)                      return 0; /* bezier with 4 orderu needs 5 points */
++              } else if (nu->orderu != 3)             return 0; /* order must be 3 or 4 */
++      }
++      return 1;
++}
++int check_valid_nurb_v( struct Nurb *nu)
++{
++      if (nu==NULL)                                           return 0;
++      if (nu->pntsv <= 1)                                     return 0;
++      if ((nu->type & 7)!=CU_NURBS)           return 1; /* not a nurb, lets assume its valid */
++      
++      if (nu->pntsv < nu->orderv)                     return 0;
++      if (((nu->flag & CU_CYCLIC)==0) && ((nu->flagv>>1) & 2)) { /* Bezier V Endpoints */
++              if (nu->orderv==4) {
++                      if (nu->pntsv < 5)                      return 0; /* bezier with 4 orderu needs 5 points */
++              } else if (nu->orderv != 3)             return 0; /* order must be 3 or 4 */
++      }
++      return 1;
++}
++
++int clamp_nurb_order_u( struct Nurb *nu )
++{
++      int change = 0;
++      if(nu->pntsu<nu->orderu) {
++              nu->orderu= nu->pntsu;
++              change= 1;
++      }
++      if(((nu->flag & CU_CYCLIC)==0) && (nu->flagu>>1)&2) {
++              CLAMP(nu->orderu, 3,4);
++              change= 1;
++      }
++      return change;
++}
++
++int clamp_nurb_order_v( struct Nurb *nu)
++{
++      int change = 0;
++      if(nu->pntsv<nu->orderv) {
++              nu->orderv= nu->pntsv;
++              change= 1;
++      }
++      if(((nu->flag & CU_CYCLIC)==0) && (nu->flagv>>1)&2) {
++              CLAMP(nu->orderv, 3,4);
++              change= 1;
++      }
++      return change;
++}
++
++
++
index aa43644105688601834530d7b52bfcd0443d6fcc,aa43644105688601834530d7b52bfcd0443d6fcc..298e4b81d5bae9b9f4742f914967151f530a0427
@@@ -783,7 -783,7 +783,7 @@@ static void curve_to_displist(Curve *cu
                        else
                                resolu= nu->resolu;
                        
--                      if(nu->pntsu<2 || ((nu->type & 7)==CU_NURBS && nu->pntsu < nu->orderu));
++                      if(!check_valid_nurb_u(nu));
                        else if((nu->type & 7)==CU_BEZIER) {
                                
                                /* count */
  
                                data= dl->verts;
  
--                              if(nu->flagu & 1) {
++                              if(nu->flagu & CU_CYCLIC) {
                                        dl->type= DL_POLY;
                                        a= nu->pntsu;
                                }
                                dl->charidx = nu->charidx;
  
                                data= dl->verts;
--                              if(nu->flagu & 1) dl->type= DL_POLY;
++                              if(nu->flagu & CU_CYCLIC) dl->type= DL_POLY;
                                else dl->type= DL_SEGM;
                                makeNurbcurve(nu, data, resolu, 3);
                        }
                                dl->charidx = nu->charidx;
  
                                data= dl->verts;
--                              if(nu->flagu & 1) dl->type= DL_POLY;
++                              if(nu->flagu & CU_CYCLIC) dl->type= DL_POLY;
                                else dl->type= DL_SEGM;
                                
                                a= len;
@@@ -1330,7 -1330,7 +1330,7 @@@ void makeDispListSurf(Object *ob, ListB
                                dl->rt= nu->flag;
                                
                                data= dl->verts;
--                              if(nu->flagu & 1) dl->type= DL_POLY;
++                              if(nu->flagu & CU_CYCLIC) dl->type= DL_POLY;
                                else dl->type= DL_SEGM;
                                
                                makeNurbcurve(nu, data, nu->resolu, 3);
index 09c939629903d40cdb44036c229910dd346cfe41,09c939629903d40cdb44036c229910dd346cfe41..52275e507dde916be38794beef77814408a613c6
@@@ -440,7 -440,7 +440,7 @@@ static void build_underline(Curve *cu, 
        if (nu2 == NULL) return;
        nu2->resolu= cu->resolu;
        nu2->bezt = NULL;
--      nu2->knotsu = nu2->knotsv = 0;
++      nu2->knotsu = nu2->knotsv = NULL;
        nu2->flag= 0;
        nu2->charidx = charidx+1000;
        if (mat_nr > 0) nu2->mat_nr= mat_nr-1;
@@@ -529,7 -529,7 +529,7 @@@ static void buildchar(Curve *cu, unsign
                        memcpy(nu2, nu1, sizeof(struct Nurb));
                        nu2->resolu= cu->resolu;
                        nu2->bp = 0;
--                      nu2->knotsu = nu2->knotsv = 0;
++                      nu2->knotsu = nu2->knotsv = NULL;
                        nu2->flag= CU_SMOOTH;
                        nu2->charidx = charidx;
                        if (info->mat_nr) {
index 464f97d294d0b359850d3be0da39e7b83f03c1cf,464f97d294d0b359850d3be0da39e7b83f03c1cf..8b979f9ed2330f6e6a012d0e9bf922077925c313
@@@ -150,7 -150,7 +150,7 @@@ void freetypechar_to_vchar(FT_Face face
                        nu->type= CU_BEZIER+CU_2D;
                        nu->pntsu = onpoints[j];
                        nu->resolu= 8;
--                      nu->flagu= 1;
++                      nu->flagu= CU_CYCLIC;
                        nu->bezt = bezt;
  
                        //individual curve loop, start-end
index 8cdc0601c7e5ed5da3aa8409c52ff8f43addc68b,8cdc0601c7e5ed5da3aa8409c52ff8f43addc68b..498c87cdef96dc5df563192945d24e271586345e
@@@ -2017,7 -2017,7 +2017,7 @@@ static VFontData *objfnt_to_vfontdata(o
                                                nu->type= CU_BEZIER+CU_2D;
                                                nu->pntsu = count;
                                                nu->resolu= 8;
--                                              nu->flagu= 1;
++                                              nu->flagu= CU_CYCLIC;
                                                nu->bezt = bezt;
                                                stop = 0;
  
index 9e25550ce04410b173216bd36ae7a20c4b314101,9e25550ce04410b173216bd36ae7a20c4b314101..4604359fcc92d62e0ffe8cfdb6716cfa7ef5142b
@@@ -37,6 -37,6 +37,9 @@@ struct BezTriple
  struct BPoint;
  struct BezTripleNurb;
  
++void set_actNurb(struct Nurb *nu);
++struct Nurb * get_actNurb( void );
++
  short isNurbsel(struct Nurb *nu);
  int isNurbsel_count(struct Nurb *nu);
  void printknots(void);
index 12b3616df256594049c27b18d5f0ff5a6270d4bd,12b3616df256594049c27b18d5f0ff5a6270d4bd..7cf2411ed84b11aa800331e2eaf6871e4f361817
@@@ -35,8 -35,8 +35,6 @@@ include nan_compile.m
  
  CFLAGS += $(LEVEL_1_C_WARNINGS)
  
--CPPFLAGS +=  -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
--CPPFLAGS += -I../../python
  CPPFLAGS += -I../../blenkernel
  CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
  CPPFLAGS += -I../../makesdna
index 15307cc2be580c770cd94a6e04059f9af3729ad4,15307cc2be580c770cd94a6e04059f9af3729ad4..f0a32db0623e446b02b435ed109bd09123945a78
@@@ -828,7 -828,7 +828,7 @@@ static PyObject *Part_GetLoc( BPy_PartS
                /* little hack to calculate hair steps in render mode */
                psys->renderdata = (void*)(int)1;
  
--              psys_cache_paths(ob, psys, cfra, 0);
++              psys_cache_paths(ob, psys, cfra, 1);
  
                psys->renderdata = NULL;
  
index 592a8c1b7aa43b3f05ffbb9b41e9f0609f0c5b26,f3744fec68bf4f44ed84660a55e73950d912c89e..1365baf075a18a2bb18c3a9371d8c5c00be85aa7
@@@ -3071,7 -3094,7 +3071,6 @@@ static void editing_panel_font_type(Obj
  
  void do_curvebuts(unsigned short event)
  {
--      extern Nurb *lastnu;
        extern ListBase editNurb;  /* from editcurve */
        Object *ob;
        Curve *cu;
                                if(isNurbsel(nu)) {
                                        if((nu->type & 7)==CU_NURBS) {
                                                if(event<B_UNIFV) {
--                                                      nu->flagu &= 1;
--                                                      nu->flagu += ((event-B_UNIFU)<<1);
++                                                      nu->flagu &= CU_CYCLIC; /* disable all flags except for CU_CYCLIC */
++                                                      nu->flagu |= ((event-B_UNIFU)<<1);
++                                                      clamp_nurb_order_u(nu);
                                                        makeknots(nu, 1, nu->flagu>>1);
                                                }
                                                else if(nu->pntsv>1) {
--                                                      nu->flagv &= 1;
--                                                      nu->flagv += ((event-B_UNIFV)<<1);
++                                                      nu->flagv &= CU_CYCLIC; /* disable all flags except for CU_CYCLIC */
++                                                      nu->flagv |= ((event-B_UNIFV)<<1);
++                                                      clamp_nurb_order_v(nu);
                                                        makeknots(nu, 2, nu->flagv>>1);
                                                }
                                        }
                break;
        case B_SETORDER:
                if(G.obedit) {
--                      nu= lastnu;
++                      nu= get_actNurb();
                        if(nu && (nu->type & 7)==CU_NURBS ) {
--                              if(nu->orderu>nu->pntsu) {
--                                      nu->orderu= nu->pntsu;
++                              if(clamp_nurb_order_u(nu)) {
                                        scrarea_queue_winredraw(curarea);
                                }
                                makeknots(nu, 1, nu->flagu>>1);
--                              if(nu->orderv>nu->pntsv) {
--                                      nu->orderv= nu->pntsv;
++                              if(clamp_nurb_order_v(nu)) {
                                        scrarea_queue_winredraw(curarea);
                                }
                                makeknots(nu, 2, nu->flagv>>1);
@@@ -3273,7 -3296,7 +3272,6 @@@ static void editing_panel_curve_tools(O
  {
        Nurb *nu;
        extern ListBase editNurb;  /* from editcurve */
--      extern Nurb *lastnu;
        uiBlock *block;
        short *sp;
  
        uiBlockEndAlign(block);
  
        if(ob==G.obedit) {
--              nu= lastnu;
--              if(nu==NULL) nu= lastnu= editNurb.first;
++              nu= get_actNurb();
++              if(nu==NULL && editNurb.first) {
++                      nu= editNurb.first;
++                      set_actNurb(nu);
++              }
                if(nu) {
                        if (ob->type==OB_CURVE) {
                                uiDefBut(block, LABEL, 0, "Tilt",
index 172e06f5add32a26640e1f4c66a918940cff81a3,172e06f5add32a26640e1f4c66a918940cff81a3..c166a9df7629b38871d2c9d5fe0baa77cf132e6a
@@@ -4097,16 -4097,16 +4097,34 @@@ void transform_armature_mirror_update(v
                        if (eboflip) {
                                /* we assume X-axis flipping for now */
                                if (ebo->flag & BONE_TIPSEL) {
++                                      EditBone *children;
++                                      
                                        eboflip->tail[0]= -ebo->tail[0];
                                        eboflip->tail[1]= ebo->tail[1];
                                        eboflip->tail[2]= ebo->tail[2];
                                        eboflip->rad_tail= ebo->rad_tail;
++
++                                      /* Also move connected children, in case children's name aren't mirrored properly */
++                                      for (children=G.edbo.first; children; children=children->next) {
++                                              if (children->parent == eboflip && children->flag & BONE_CONNECTED) {
++                                                      VECCOPY(children->head, eboflip->tail);
++                                                      children->rad_head = ebo->rad_tail;
++                                              }
++                                      }
                                }
                                if (ebo->flag & BONE_ROOTSEL) {
                                        eboflip->head[0]= -ebo->head[0];
                                        eboflip->head[1]= ebo->head[1];
                                        eboflip->head[2]= ebo->head[2];
                                        eboflip->rad_head= ebo->rad_head;
++                                      
++                                      /* Also move connected parent, in case parent's name isn't mirrored properly */
++                                      if (eboflip->parent && eboflip->flag & BONE_CONNECTED)
++                                      {
++                                              EditBone *parent = eboflip->parent;
++                                              VECCOPY(parent->tail, eboflip->head);
++                                              parent->rad_tail = ebo->rad_head;
++                                      }
                                }
                                if (ebo->flag & BONE_SELECTED) {
                                        eboflip->dist= ebo->dist;
index 7572391b3838010c54b38753cddd38538eea2616,7572391b3838010c54b38753cddd38538eea2616..bd0abe83ee4b0fa4669de2ba725898b694369de4
@@@ -99,7 -99,7 +99,7 @@@
  
  ListBase editNurb;
  BPoint *lastselbp;
--Nurb *lastnu;         /* for selected */
++int actnu;            /* for selected */
  
  
  /*  void freeNurblist(ListBase *lb); already declared in the kernel */
@@@ -109,6 -109,6 +109,23 @@@ float nurbcircle[8][2]= 
        {0.0,  1.0}, { 1.0,  1.0}, { 1.0, 0.0}, { 1.0, -1.0}
  };
  
++
++/* this replaces the active flag used in uv/face mode */
++void set_actNurb(Nurb *nu)
++{
++      if (nu==NULL) {
++              actnu = -1;
++      } else {
++              actnu = BLI_findindex(&editNurb, nu);
++      }
++}
++
++Nurb * get_actNurb( void )
++{
++      return BLI_findlink(&editNurb, actnu);
++}
++
++
  /* ******************* SELECTION FUNCTIONS ********************* */
  
  /* returns 1 in case (de)selection was successful */
@@@ -318,14 -318,14 +335,14 @@@ void load_editNurb(
                                BLI_addtail(&(cu->nurb), newnu);
                                
                                if((nu->type & 7)==CU_NURBS) {
--                                      if(nu->pntsu < nu->orderu) nu->orderu= nu->pntsu;
++                                      clamp_nurb_order_u(nu);
                                }
                        }
                }
                
        }
        
--      lastnu= NULL;   /* for selected */
++      set_actNurb(NULL);
  }
  
  void make_editNurb()
        else G.obedit= NULL;
        
        countall();
--      
--      lastnu= NULL;   /* for selected */
++      set_actNurb(NULL);
  }
  
  void remake_editNurb()
@@@ -457,8 -457,8 +473,7 @@@ void separate_nurb(
        countall();
        allqueue(REDRAWVIEW3D, 0);
        allqueue(REDRAWBUTSEDIT, 0);
--
--      lastnu= NULL;   /* for selected */
++      set_actNurb(NULL);
  }
  
  /* ******************* FLAGS ********************* */
@@@ -640,7 -640,7 +655,7 @@@ void deleteflagNurb(short flag
                }
                if(a==0) {
                        BLI_remlink(&editNurb, nu);
--                      freeNurb(nu);
++                      freeNurb(nu); nu=NULL;
                }
                else {
                        /* is nurb in U direction selected */
                                nu->pntsv= newv;
                                MEM_freeN(nu->bp);
                                nu->bp= newbp;
--                              if(nu->orderv>nu->pntsv) nu->orderv= nu->pntsv;
++                              clamp_nurb_order_v(nu);
  
                                makeknots(nu, 2, nu->flagv>>1);
                        }
                                                nu->pntsu= nu->pntsv;
                                                nu->pntsv= 1;
                                                SWAP(short, nu->orderu, nu->orderv);
--                                              if(nu->orderu>nu->pntsu) nu->orderu= nu->pntsu;
++                                              clamp_nurb_order_u(nu);
                                                if(nu->knotsv) MEM_freeN(nu->knotsv);
--                                              nu->knotsv= 0;
++                                              nu->knotsv= NULL;
                                        }
                                        else {
                                                nu->pntsu= newu;
--                                              if(nu->orderu>nu->pntsu) nu->orderu= nu->pntsu;
++                                              clamp_nurb_order_u(nu);
                                        }
                                        makeknots(nu, 1, nu->flagu>>1);
                                }
@@@ -878,7 -878,7 +893,7 @@@ void adduplicateflagNurb(short flag
                                        newnu = (Nurb*)MEM_mallocN(sizeof(Nurb), "adduplicateN");  
                                        memcpy(newnu, nu, sizeof(Nurb));
                                        BLI_addtail(&editNurb, newnu);
--                                      lastnu= newnu;
++                                      set_actNurb(newnu);
                                        newnu->pntsu= enda-starta+1;
                                        newnu->bezt=
                                                (BezTriple*)MEM_mallocN((enda - starta + 1) * sizeof(BezTriple), "adduplicateN");  
                                                bezt1++;
                                        }
  
--                                      if(nu->flagu & 1) {
--                                              if(starta!=0 || enda!=nu->pntsu-1) newnu->flagu--;
++                                      if(nu->flagu & CU_CYCLIC) {
++                                              if(starta!=0 || enda!=nu->pntsu-1) {
++                                                      newnu->flagu &= ~CU_CYCLIC;
++                                              }
                                        }
                                }
                                bezt++;
                                if(enda>=starta) {
                                        newnu = (Nurb*)MEM_mallocN(sizeof(Nurb), "adduplicateN3");  
                                        memcpy(newnu, nu, sizeof(Nurb));
--                                      lastnu= newnu;
++                                      set_actNurb(newnu);
                                        BLI_addtail(&editNurb, newnu);
                                        newnu->pntsu= enda-starta+1;
                                        newnu->bp = (BPoint*)MEM_mallocN((enda-starta+1) * sizeof(BPoint), "adduplicateN4");
                                                bp1++;
                                        }
  
--                                      if(nu->flagu & 1) {
--                                              if(starta!=0 || enda!=nu->pntsu-1) newnu->flagu--;
++                                      if(nu->flagu & CU_CYCLIC) {
++                                              if(starta!=0 || enda!=nu->pntsu-1) {
++                                                      newnu->flagu &= ~CU_CYCLIC;
++                                              }
                                        }
  
                                        /* knots */
--                                      newnu->knotsu= 0;
++                                      newnu->knotsu= NULL;
                                        makeknots(newnu, 1, newnu->flagu>>1);
                                }
                                bp++;
                                        newnu = (Nurb*)MEM_mallocN(sizeof(Nurb), "adduplicateN5");
                                        memcpy(newnu, nu, sizeof(Nurb));
                                        BLI_addtail(&editNurb, newnu);
--                                      lastnu= newnu;
++                                      set_actNurb(newnu);
                                        newnu->pntsu= newu;
                                        newnu->pntsv= newv;
                                        newnu->bp =
                                                (BPoint*)MEM_mallocN(newu * newv * sizeof(BPoint), "adduplicateN6");
--                                      newnu->orderu= MIN2(nu->orderu, newu);
--                                      newnu->orderv= MIN2(nu->orderv, newv);
--
++                                      clamp_nurb_order_u(newnu);
++                                      clamp_nurb_order_v(newnu);
++                                      
++                                      newnu->knotsu= newnu->knotsv= NULL;
++                                      
                                        bp= newnu->bp;
                                        bp1= nu->bp;
                                        for(a=0; a<nu->pntsv; a++) {
                                                        }
                                                }
                                        }
--                                      if(nu->pntsu==newnu->pntsu) {
--                                              newnu->knotsu= MEM_mallocN(sizeof(float)*KNOTSU(nu), "adduplicateN6");
--                                              memcpy(newnu->knotsu, nu->knotsu, sizeof(float)*KNOTSU(nu));
--                                      }
--                                      else {
--                                              newnu->knotsu= 0;
--                                              makeknots(newnu, 1, newnu->flagu>>1);
--                                      }
--                                      if(nu->pntsv==newnu->pntsv) {
--                                              newnu->knotsv= MEM_mallocN(sizeof(float)*KNOTSV(nu), "adduplicateN7");
--                                              memcpy(newnu->knotsv, nu->knotsv, sizeof(float)*KNOTSV(nu));
++                                      if (check_valid_nurb_u(newnu)) {
++                                              if(nu->pntsu==newnu->pntsu && nu->knotsu) {
++                                                      newnu->knotsu= MEM_dupallocN( nu->knotsu );
++                                              } else {
++                                                      makeknots(newnu, 1, newnu->flagu>>1);
++                                              }
                                        }
--                                      else {
--                                              newnu->knotsv= 0;
--                                              makeknots(newnu, 2, newnu->flagv>>1);
++                                      if (check_valid_nurb_v(newnu)) {
++                                              if(nu->pntsv==newnu->pntsv && nu->knotsv) {
++                                                      newnu->knotsv= MEM_dupallocN( nu->knotsv );
++                                              } else {
++                                                      makeknots(newnu, 2, newnu->flagv>>1);
++                                              }
                                        }
--
                                }
                                MEM_freeN(usel);
                        }
                nu= nu->prev;
        }
        
--      /* lastnu changed */
++      /* actnu changed */
        allqueue(REDRAWBUTSEDIT, 0);
  }
  
@@@ -1569,7 -1569,7 +1587,7 @@@ void subdivideNurb(
             newly created. Old points are discarded.
          */
                        /* count */
--                      if(nu->flagu & 1) {
++                      if(nu->flagu & CU_CYCLIC) {
                                a= nu->pntsu;
                                bezt= nu->bezt;
                                prevbezt= bezt+(a-1);
                                beztnew =
                                        (BezTriple*)MEM_mallocN((amount + nu->pntsu) * sizeof(BezTriple), "subdivNurb");
                                beztn= beztnew;
--                              if(nu->flagu & 1) {
++                              if(nu->flagu & CU_CYCLIC) {
                                        a= nu->pntsu;
                                        bezt= nu->bezt;
                                        prevbezt= bezt+(a-1);
                                                VecMidf(beztn->vec[1], vec+9, vec+12);
                                                VECCOPY(beztn->vec[2], vec+12);
                                                /* handle of next bezt */
--                                              if(a==0 && (nu->flagu & 1)) {VECCOPY(beztnew->vec[0], vec+6);}
++                                              if(a==0 && (nu->flagu & CU_CYCLIC)) {VECCOPY(beztnew->vec[0], vec+6);}
                                                else {VECCOPY(bezt->vec[0], vec+6);}
                                                
                                                beztn->radius = (prevbezt->radius + bezt->radius)/2.0f;
                                        bezt++;
                                }
                                /* last point */
--                              if((nu->flagu & 1)==0) memcpy(beztn, prevbezt, sizeof(BezTriple));
++                              if((nu->flagu & CU_CYCLIC)==0) memcpy(beztn, prevbezt, sizeof(BezTriple));
  
                                MEM_freeN(nu->bezt);
                                nu->bezt= beztnew;
             stable... nzc 30-5-'00
           */
                        /* count */
--                      if(nu->flagu & 1) {
++                      if(nu->flagu & CU_CYCLIC) {
                                a= nu->pntsu*nu->pntsv;
                                bp= nu->bp;
                                prevbp= bp+(a-1);
                                        (BPoint*)MEM_mallocN((amount + nu->pntsu) * sizeof(BPoint), "subdivNurb2");
                                bpn= bpnew;
  
--                              if(nu->flagu & 1) {
++                              if(nu->flagu & CU_CYCLIC) {
                                        a= nu->pntsu;
                                        bp= nu->bp;
                                        prevbp= bp+(a-1);
                                        prevbp= bp;
                                        bp++;
                                }
--                              if((nu->flagu & 1)==0) memcpy(bpn, prevbp, sizeof(BPoint));     /* last point */
++                              if((nu->flagu & CU_CYCLIC)==0) memcpy(bpn, prevbp, sizeof(BPoint));     /* last point */
  
                                MEM_freeN(nu->bp);
                                nu->bp= bpnew;
@@@ -2075,7 -2075,7 +2093,7 @@@ int convertspline(short type, Nurb *nu
                        nu->type &= ~7;
                        nu->type+= 4;
                        nu->orderu= 4;
--                      nu->flagu &= 1;
++                      nu->flagu &= CU_CYCLIC; /* disable all flags except for cyclic */
                        nu->flagu += 4;
                        makeknots(nu, 1, nu->flagu>>1);
                        a= nu->pntsu*nu->pntsv;
                        nu->orderv= 1;
                        nu->type &= ~7;
                        nu->type+= type;
--                      if(nu->flagu & 1) c= nu->orderu-1; 
++                      if(nu->flagu & CU_CYCLIC) c= nu->orderu-1; 
                        else c= 0;
                        if(type== 4) {
--                              nu->flagu &= 1;
++                              nu->flagu &= CU_CYCLIC; /* disable all flags except for cyclic */
                                nu->flagu += 4;
                                makeknots(nu, 1, nu->flagu>>1);
                        }
                if(type==0) {                   /* to Poly */
                        nu->type &= ~7;
                        if(nu->knotsu) MEM_freeN(nu->knotsu); /* python created nurbs have a knotsu of zero */
--                      nu->knotsu= 0;
++                      nu->knotsu= NULL;
                        if(nu->knotsv) MEM_freeN(nu->knotsv);
--                      nu->knotsv= 0;
++                      nu->knotsv= NULL;
                }
                else if(type==CU_BEZIER) {              /* to Bezier */
                        nr= nu->pntsu/3;
                                MEM_freeN(nu->bp);
                                nu->bp= 0;
                                MEM_freeN(nu->knotsu);
--                              nu->knotsu= 0;
++                              nu->knotsu= NULL;
                                nu->pntsu= nr;
                                nu->type &= ~7;
                                nu->type+= 1;
@@@ -2481,7 -2481,7 +2499,7 @@@ void merge_nurb(
        BLI_freelistN(&nsortbase);
        
        countall();
--      lastnu= NULL;
++      set_actNurb(NULL);
  
        DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
  
@@@ -2527,7 -2527,7 +2545,7 @@@ void addsegment_nurb(
        
        /* find both nurbs and points, nu1 will be put behind nu2 */
        for(nu= editNurb.first; nu; nu= nu->next) {
--              if((nu->flagu & 1)==0) {    /* not cyclic */
++              if((nu->flagu & CU_CYCLIC)==0) {    /* not cyclic */
                        if( (nu->type & 7)==CU_BEZIER ) {
                                bezt= nu->bezt;
                                if(nu1==0) {
                                nu1->bezt= bezt;
                                nu1->pntsu+= nu2->pntsu;
                                BLI_remlink(&editNurb, nu2);
--                              freeNurb(nu2);
++                              freeNurb(nu2); nu2= NULL;
                                calchandlesNurb(nu1);
                        }
                        else {
                                                }
                                        }
                                }
--                              freeNurb(nu2);
++                              freeNurb(nu2); nu2= NULL;
                        }
                }
                
--              lastnu= NULL;   /* for selected */
++              set_actNurb(NULL);      /* for selected */
  
                DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);     
  
@@@ -2704,8 -2704,8 +2722,8 @@@ void mouse_nurb(
  
        rightmouse_transform();
        
--      if(nu!=lastnu) {
--              lastnu= nu;
++      if(nu!=get_actNurb()) {
++              set_actNurb(nu);
                allqueue(REDRAWBUTSEDIT, 0);
        }
        
@@@ -2808,7 -2808,7 +2826,7 @@@ static void spin_nurb(float *dvec, shor
                for(nu= editNurb.first; nu; nu= nu->next) {
                        if(isNurbsel(nu)) {
                                nu->orderv= 4;
--                              nu->flagv |= 1;
++                              nu->flagv |= CU_CYCLIC;
                                makeknots(nu, 2, nu->flagv>>1);
                        }
                }
@@@ -3006,8 -3006,8 +3024,8 @@@ void makecyclicNurb(
                                bp= nu->bp;
                                while(a--) {
                                        if( bp->f1 & SELECT ) {
--                                              if(nu->flagu & CU_CYCLIC) nu->flagu--;
--                                              else nu->flagu++;
++                                              if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
++                                              else nu->flagu |= CU_CYCLIC;
                                                break;
                                        }
                                        bp++;
                                bezt= nu->bezt;
                                while(a--) {
                                        if( BEZSELECTED_HIDDENHANDLES(bezt) ) {
--                                              if(nu->flagu & CU_CYCLIC) nu->flagu--;
--                                              else nu->flagu++;
++                                              if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
++                                              else nu->flagu |= CU_CYCLIC;
                                                break;
                                        }
                                        bezt++;
                                calchandlesNurb(nu);
                        }
                        else if(nu->pntsv==1 && (nu->type & 7)==CU_NURBS) {
--                              a= nu->pntsu;
--                              bp= nu->bp;
--                              while(a--) {
--                                      if( bp->f1 & SELECT ) {
--                                              if(nu->flagu & CU_CYCLIC) nu->flagu--;
--                                              else {
--                                                      nu->flagu++;
--                                                      nu->flagu &= ~2;        /* endpoint flag, fixme */
--                                                      fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
--                                                      b= (nu->orderu+nu->pntsu);
--                                                      memcpy(fp, nu->knotsu, sizeof(float)*b);
--                                                      MEM_freeN(nu->knotsu);
--                                                      nu->knotsu= fp;
++                              if (nu->knotsu) { /* if check_valid_nurb_u fails the knotsu can be NULL */
++                                      a= nu->pntsu;
++                                      bp= nu->bp;
++                                      while(a--) {
++                                              if( bp->f1 & SELECT ) {
++                                                      if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
++                                                      else {
++                                                              nu->flagu |= CU_CYCLIC;
++                                                              nu->flagu &= ~2;        /* endpoint flag, fixme */
++                                                              fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
++                                                              b= (nu->orderu+nu->pntsu);
++                                                              memcpy(fp, nu->knotsu, sizeof(float)*b);
++                                                              MEM_freeN(nu->knotsu);
++                                                              nu->knotsu= fp;
                                                        
--                                                      makeknots(nu, 1, 0);    /* 1==u  0==uniform */
++                                                              makeknots(nu, 1, 0);    /* 1==u  0==uniform */
                                                        
++                                                      }
++                                                      break;
                                                }
--                                              break;
++                                              bp++;
                                        }
--                                      bp++;
                                }
                        }
                        else if(nu->type==CU_NURBS) {
        
                                        if( bp->f1 & SELECT) {
                                                if(cyclmode==1 && nu->pntsu>1) {
--                                                      if(nu->flagu & CU_CYCLIC) nu->flagu--;
++                                                      if(nu->flagu & CU_CYCLIC) nu->flagu &= ~CU_CYCLIC;
                                                        else {
--                                                              nu->flagu++;
--                                                              fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
--                                                              b= (nu->orderu+nu->pntsu);
--                                                              memcpy(fp, nu->knotsu, sizeof(float)*b);
--                                                              MEM_freeN(nu->knotsu);
--                                                              nu->knotsu= fp;
++                                                              nu->flagu |= CU_CYCLIC;
++                                                              if (check_valid_nurb_u(nu)) {
++                                                                      fp= MEM_mallocN(sizeof(float)*KNOTSU(nu), "makecyclicN");
++                                                                      b= (nu->orderu+nu->pntsu);
++                                                                      if (nu->knotsu) { /* null if check_valid_nurb_u failed before but is valid now */
++                                                                              memcpy(fp, nu->knotsu, sizeof(float)*b);
++                                                                              MEM_freeN(nu->knotsu);
++                                                                      }
++                                                                      nu->knotsu= fp;
                                                                
--                                                              makeknots(nu, 1, 0);    /* 1==u  0==uniform */
++                                                                      makeknots(nu, 1, 0);    /* 1==u  0==uniform */
++                                                              }
                                                        }
                                                }
                                                if(cyclmode==2 && nu->pntsv>1) {
                                                        if(nu->flagv & 1) nu->flagv--;
                                                        else {
                                                                nu->flagv++;
--                                                              fp= MEM_mallocN(sizeof(float)*KNOTSV(nu), "makecyclicN");
--                                                              b= (nu->orderv+nu->pntsv);
--                                                              memcpy(fp, nu->knotsv, sizeof(float)*b);
--                                                              MEM_freeN(nu->knotsv);
--                                                              nu->knotsv= fp;
++                                                              if (check_valid_nurb_v(nu)) {
++                                                                      fp= MEM_mallocN(sizeof(float)*KNOTSV(nu), "makecyclicN");
++                                                                      b= (nu->orderv+nu->pntsv);
++                                                                      if (nu->knotsv) { /* null if check_valid_nurb_v failed before but is valid now */
++                                                                              memcpy(fp, nu->knotsv, sizeof(float)*b);
++                                                                              MEM_freeN(nu->knotsv);
++                                                                      }
++                                                                      nu->knotsv= fp;
                                                                
--                                                              makeknots(nu, 2, 0);    /* 2==v  0==uniform */
++                                                                      makeknots(nu, 2, 0);    /* 2==v  0==uniform */
++                                                              }
                                                        }
                                                }
                                                break;
@@@ -3638,7 -3638,7 +3666,7 @@@ void delNurb(
                                        }
                                        if(a==0) {
                                                BLI_remlink(&editNurb, nu);
--                                              freeNurb(nu);
++                                              freeNurb(nu); nu= NULL;
                                        }
                                }
                        }
                                        }
                                        if(a==0) {
                                                BLI_remlink(&editNurb, nu);
--                                              freeNurb(nu);
++                                              freeNurb(nu); nu= NULL;
                                        }
                                }
                        }
                        
--                      /* Never allow the order to exceed the number of points */
--                      if ((nu->type & 7)==CU_NURBS && (nu->pntsu < nu->orderu)) {
--                              nu->orderu = nu->pntsu;
++                      /* Never allow the order to exceed the number of points
++                      - note, this is ok but changes unselected nurbs, disable for now */
++                      /*
++                      if ((nu!= NULL) && ((nu->type & 7)==CU_NURBS)) {
++                              clamp_nurb_order_u(nu);
                        }
++                      */
                        nu= next;
                }
                /* 2nd loop, delete small pieces: just for curves */
                                        MEM_freeN(nu->bp);
                                        nu->bp= bp1;
                                        
--                                      /* Never allow the order to exceed the number of points */
--                                      if ((nu->type & 7)==CU_NURBS && (nu->pntsu < nu->orderu)) {
--                                              nu->orderu = nu->pntsu;
--                                      }
++                                      /* Never allow the order to exceed the number of points\
++                                      - note, this is ok but changes unselected nurbs, disable for now */
++                                      /*
++                                      if ((nu->type & 7)==CU_NURBS) {
++                                              clamp_nurb_order_u(nu);
++                                      }*/
                                }
                                makeknots(nu, 1, nu->flagu>>1);
                        }
                                                bezt2= bezt+1;
                                                if( (bezt2->f1 & SELECT) || (bezt2->f2 & SELECT) || (bezt2->f3 & SELECT) ) ;
                                                else {  /* maybe do not make cyclic */
--                                                      if(a==0 && (nu->flagu & 1) ) {
++                                                      if(a==0 && (nu->flagu & CU_CYCLIC) ) {
                                                                bezt2= bezt+(nu->pntsu-1);
                                                                if( (bezt2->f1 & SELECT) || (bezt2->f2 & SELECT) || (bezt2->f3 & SELECT) ) {
--                                                                      nu->flagu--;
++                                                                      nu->flagu &= ~CU_CYCLIC;
                                                                        DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                                                        allqueue(REDRAWVIEW3D, 0);
                                                                        allqueue(REDRAWBUTSEDIT, 0);
                                                bp2= bp+1;
                                                if( bp2->f1 & 1 ) ;
                                                else {  /* maybe do not make cyclic */
--                                                      if(a==0 && (nu->flagu & 1) ) {
++                                                      if(a==0 && (nu->flagu & CU_CYCLIC) ) {
                                                                bp2= bp+(nu->pntsu-1);
--                                                              if( bp2->f1 & 1 ) {
--                                                                      nu->flagu--;
++                                                              if( bp2->f1 & SELECT ) {
++                                                                      nu->flagu &= ~CU_CYCLIC;
                                                                        DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
                                                                        allqueue(REDRAWVIEW3D, 0);
                                                                        allqueue(REDRAWBUTSEDIT, 0);
                        if(bezt1) {
                                if(nu1->pntsu==2) {     /* remove completely */
                                        BLI_remlink(&editNurb, nu);
--                                      freeNurb(nu);
++                                      freeNurb(nu); nu = NULL;
                                }
--                              else if(nu1->flagu & 1) {       /* cyclic */
++                              else if(nu1->flagu & CU_CYCLIC) {       /* cyclic */
                                        bezt =
                                                (BezTriple*)MEM_mallocN((cut+1) * sizeof(BezTriple), "delNurb1");
                                        memcpy(bezt, nu1->bezt,(cut+1)*sizeof(BezTriple));
                                        a= nu1->pntsu-cut-1;
                                        memcpy(nu1->bezt, bezt2, a*sizeof(BezTriple));
                                        memcpy(nu1->bezt+a, bezt, (cut+1)*sizeof(BezTriple));
--                                      nu1->flagu--;
++                                      nu1->flagu &= ~CU_CYCLIC;
                                        MEM_freeN(bezt);
                                        calchandlesNurb(nu);
                                }
                        else if(bp1) {
                                if(nu1->pntsu==2) {     /* remove completely */
                                        BLI_remlink(&editNurb, nu);
--                                      freeNurb(nu);
++                                      freeNurb(nu); nu= NULL;
                                }
--                              else if(nu1->flagu & 1) {       /* cyclic */
++                              else if(nu1->flagu & CU_CYCLIC) {       /* cyclic */
                                        bp =
                                                (BPoint*)MEM_mallocN((cut+1) * sizeof(BPoint), "delNurb5");
                                        memcpy(bp, nu1->bp,(cut+1)*sizeof(BPoint));
                                        a= nu1->pntsu-cut-1;
                                        memcpy(nu1->bp, bp2, a*sizeof(BPoint));
                                        memcpy(nu1->bp+a, bp, (cut+1)*sizeof(BPoint));
--                                      nu1->flagu--;
++                                      nu1->flagu &= ~CU_CYCLIC;
                                        MEM_freeN(bp);
                                }
                                else {                  /* add new curve */
@@@ -4151,7 -4151,7 +4184,7 @@@ Nurb *addNurbprim(int type, int stype, 
                if((type & 7)==CU_BEZIER) {
                        nu->pntsu= 4;
                        nu->bezt= callocstructN(BezTriple, 4, "addNurbprim1");
--                      nu->flagu= 1;
++                      nu->flagu= CU_CYCLIC;
                        bezt= nu->bezt;
  
                        for(a=0;a<3;a++) {
                        nu->pntsv= 1;
                        nu->orderu= 4;
                        nu->bp= callocstructN(BPoint, 8, "addNurbprim6");
--                      nu->flagu= 1;
++                      nu->flagu= CU_CYCLIC;
                        bp= nu->bp;
  
                        for(a=0; a<8; a++) {
@@@ -4592,10 -4592,10 +4625,6 @@@ static void undoCurve_to_editCurve(voi
  {
        ListBase *lb= lbv;
        Nurb *nu, *newnu;
--      int nr, lastnunr= 0;
--
--      /* we try to restore lastnu too, for buttons */
--      for(nu= editNurb.first; nu; nu = nu->next, lastnunr++) if(nu==lastnu) break;
        
        freeNurblist(&editNurb);
  
                newnu= duplicateNurb(nu);
                BLI_addtail(&editNurb, newnu);
        }
--      /* restore */
--      for(nr=0, lastnu= editNurb.first; lastnu; lastnu = lastnu->next, nr++) if(nr==lastnunr) break;
--      
  }
  
  static void *editCurve_to_undoCurve(void)
index 4c97a8fdbdf20ce7078a04805ca10810ef8abce6,4c97a8fdbdf20ce7078a04805ca10810ef8abce6..dcceea971f7f30e3299f6ba6cca02fb8bc6384ac
@@@ -659,6 -659,6 +659,10 @@@ void pose_copy_menu(void
                                                free_constraints(&pchan->constraints);
                                                copy_constraints(&pchan->constraints, &pchanact->constraints);
                                                pchan->constflag = pchanact->constflag;
++                                              
++                                              if (ob->pose) {
++                                                      ob->pose->flag |= POSE_RECALC;
++                                              }
                                        }
                                                break;
                                        case 6: /* Transform Locks */
                }
                BLI_freelistN(&const_copy);
                update_pose_constraint_flags(ob->pose); /* we could work out the flags but its simpler to do this */
++              
++              if (ob->pose) {
++                      ob->pose->flag |= POSE_RECALC;
++              }
        }
        
        DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);   // and all its relations
index f69218664ea44cdcf22180aa575b21e91080bd98,f69218664ea44cdcf22180aa575b21e91080bd98..4be525f494574eabdf25e1835b009146b1ebd831
@@@ -4054,6 -4054,6 +4054,7 @@@ void createTransData(TransInfo *t
                t->flag |= T_POINTS;
        }
        else {
++              t->flag &= ~T_PROP_EDIT; /* no proportional edit in object mode */
                createTransObject(t);
                t->flag |= T_OBJECT;
        }