style cleanup: editors / mesh & object
[blender-staging.git] / source / blender / editors / object / object_shapekey.c
index 9e31fc2d765b0de394ac8b57b0316522f5098f21..bd88bbda32c97f5d60109089d642c0a98eb09796 100644 (file)
@@ -78,11 +78,11 @@ static void ED_object_shape_key_add(bContext *C, Scene *scene, Object *ob, int f
 {
        KeyBlock *kb;
        if ((kb = object_insert_shape_key(scene, ob, NULL, from_mix))) {
-               Key *key= ob_get_key(ob);
+               Key *key = ob_get_key(ob);
                /* for absolute shape keys, new keys may not be added last */
                ob->shapenr = BLI_findindex(&key->block, kb) + 1;
 
-               WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+               WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
        }
 }
 
@@ -90,26 +90,26 @@ static void ED_object_shape_key_add(bContext *C, Scene *scene, Object *ob, int f
 
 static int ED_object_shape_key_remove(bContext *C, Object *ob)
 {
-       Main *bmain= CTX_data_main(C);
+       Main *bmain = CTX_data_main(C);
        KeyBlock *kb, *rkb;
        Key *key;
        //IpoCurve *icu;
 
-       key= ob_get_key(ob);
-       if (key==NULL)
+       key = ob_get_key(ob);
+       if (key == NULL)
                return 0;
        
-       kb= BLI_findlink(&key->block, ob->shapenr-1);
+       kb = BLI_findlink(&key->block, ob->shapenr - 1);
 
        if (kb) {
-               for (rkb= key->block.first; rkb; rkb= rkb->next)
-                       if (rkb->relative == ob->shapenr-1)
-                               rkb->relative= 0;
+               for (rkb = key->block.first; rkb; rkb = rkb->next)
+                       if (rkb->relative == ob->shapenr - 1)
+                               rkb->relative = 0;
 
                BLI_remlink(&key->block, kb);
                key->totkey--;
-               if (key->refkey== kb) {
-                       key->refkey= key->block.first;
+               if (key->refkey == kb) {
+                       key->refkey = key->block.first;
 
                        if (key->refkey) {
                                /* apply new basis key on original data */
@@ -136,16 +136,16 @@ static int ED_object_shape_key_remove(bContext *C, Object *ob)
                }
        }
        
-       if (key->totkey==0) {
-               if (GS(key->from->name)==ID_ME) ((Mesh *)key->from)->key= NULL;
-               else if (GS(key->from->name)==ID_CU) ((Curve *)key->from)->key= NULL;
-               else if (GS(key->from->name)==ID_LT) ((Lattice *)key->from)->key= NULL;
+       if (key->totkey == 0) {
+               if (GS(key->from->name) == ID_ME) ((Mesh *)key->from)->key = NULL;
+               else if (GS(key->from->name) == ID_CU) ((Curve *)key->from)->key = NULL;
+               else if (GS(key->from->name) == ID_LT) ((Lattice *)key->from)->key = NULL;
 
                free_libblock_us(&(bmain->key), key);
        }
        
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
        return 1;
 }
@@ -155,53 +155,53 @@ static int object_shape_key_mirror(bContext *C, Object *ob)
        KeyBlock *kb;
        Key *key;
 
-       key= ob_get_key(ob);
-       if (key==NULL)
+       key = ob_get_key(ob);
+       if (key == NULL)
                return 0;
        
-       kb= BLI_findlink(&key->block, ob->shapenr-1);
+       kb = BLI_findlink(&key->block, ob->shapenr - 1);
 
        if (kb) {
                int i1, i2;
                float *fp1, *fp2;
                float tvec[3];
-               char *tag_elem= MEM_callocN(sizeof(char) * kb->totelem, "shape_key_mirror");
+               char *tag_elem = MEM_callocN(sizeof(char) * kb->totelem, "shape_key_mirror");
 
 
-               if (ob->type==OB_MESH) {
-                       Mesh *me= ob->data;
+               if (ob->type == OB_MESH) {
+                       Mesh *me = ob->data;
                        MVert *mv;
 
                        mesh_octree_table(ob, NULL, NULL, 's');
 
-                       for (i1=0, mv=me->mvert; i1<me->totvert; i1++, mv++) {
-                               i2= mesh_get_x_mirror_vert(ob, i1);
-                               if (i2==i1) {
-                                       fp1= ((float *)kb->data) + i1*3;
+                       for (i1 = 0, mv = me->mvert; i1 < me->totvert; i1++, mv++) {
+                               i2 = mesh_get_x_mirror_vert(ob, i1);
+                               if (i2 == i1) {
+                                       fp1 = ((float *)kb->data) + i1 * 3;
                                        fp1[0] = -fp1[0];
-                                       tag_elem[i1]= 1;
+                                       tag_elem[i1] = 1;
                                }
                                else if (i2 != -1) {
-                                       if (tag_elem[i1]==0 && tag_elem[i2]==0) {
-                                               fp1= ((float *)kb->data) + i1*3;
-                                               fp2= ((float *)kb->data) + i2*3;
+                                       if (tag_elem[i1] == 0 && tag_elem[i2] == 0) {
+                                               fp1 = ((float *)kb->data) + i1 * 3;
+                                               fp2 = ((float *)kb->data) + i2 * 3;
 
-                                               copy_v3_v3(tvec,        fp1);
-                                               copy_v3_v3(fp1, fp2);
-                                               copy_v3_v3(fp2, tvec);
+                                               copy_v3_v3(tvec,    fp1);
+                                               copy_v3_v3(fp1, fp2);
+                                               copy_v3_v3(fp2, tvec);
 
                                                /* flip x axis */
                                                fp1[0] = -fp1[0];
                                                fp2[0] = -fp2[0];
                                        }
-                                       tag_elem[i1]= tag_elem[i2]= 1;
+                                       tag_elem[i1] = tag_elem[i2] = 1;
                                }
                        }
 
                        mesh_octree_table(ob, NULL, NULL, 'e');
                }
                else if (ob->type == OB_LATTICE) {
-                       Lattice *lt= ob->data;
+                       Lattice *lt = ob->data;
                        int i1, i2;
                        float *fp1, *fp2;
                        int u, v, w;
@@ -213,28 +213,28 @@ static int object_shape_key_mirror(bContext *C, Object *ob)
 
                        /* if (lt->editlatt) lt= lt->editlatt->latt; */
 
-                       for (w=0; w<lt->pntsw; w++) {
-                               for (v=0; v<lt->pntsv; v++) {
-                                       for (u=0; u<pntsu_half; u++) {
-                                               int u_inv= (lt->pntsu - 1) - u;
+                       for (w = 0; w < lt->pntsw; w++) {
+                               for (v = 0; v < lt->pntsv; v++) {
+                                       for (u = 0; u < pntsu_half; u++) {
+                                               int u_inv = (lt->pntsu - 1) - u;
                                                float tvec[3];
                                                if (u == u_inv) {
-                                                       i1= LT_INDEX(lt, u, v, w);
-                                                       fp1= ((float *)kb->data) + i1*3;
-                                                       fp1[0]= -fp1[0];
+                                                       i1 = LT_INDEX(lt, u, v, w);
+                                                       fp1 = ((float *)kb->data) + i1 * 3;
+                                                       fp1[0] = -fp1[0];
                                                }
                                                else {
-                                                       i1= LT_INDEX(lt, u, v, w);
-                                                       i2= LT_INDEX(lt, u_inv, v, w);
+                                                       i1 = LT_INDEX(lt, u, v, w);
+                                                       i2 = LT_INDEX(lt, u_inv, v, w);
 
-                                                       fp1= ((float *)kb->data) + i1*3;
-                                                       fp2= ((float *)kb->data) + i2*3;
+                                                       fp1 = ((float *)kb->data) + i1 * 3;
+                                                       fp2 = ((float *)kb->data) + i2 * 3;
 
                                                        copy_v3_v3(tvec, fp1);
                                                        copy_v3_v3(fp1, fp2);
                                                        copy_v3_v3(fp2, tvec);
-                                                       fp1[0]= -fp1[0];
-                                                       fp2[0]= -fp2[0];
+                                                       fp1[0] = -fp1[0];
+                                                       fp2[0] = -fp2[0];
                                                }
                                        }
                                }
@@ -245,7 +245,7 @@ static int object_shape_key_mirror(bContext *C, Object *ob)
        }
        
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
        return 1;
 }
@@ -254,22 +254,22 @@ static int object_shape_key_mirror(bContext *C, Object *ob)
 
 static int shape_key_mode_poll(bContext *C)
 {
-       Object *ob= ED_object_context(C);
-       ID *data= (ob)? ob->data: NULL;
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
        return (ob && !ob->id.lib && data && !data->lib && ob->mode != OB_MODE_EDIT);
 }
 
 static int shape_key_poll(bContext *C)
 {
-       Object *ob= ED_object_context(C);
-       ID *data= (ob)? ob->data: NULL;
+       Object *ob = ED_object_context(C);
+       ID *data = (ob) ? ob->data : NULL;
        return (ob && !ob->id.lib && data && !data->lib);
 }
 
 static int shape_key_add_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= ED_object_context(C);
+       Scene *scene = CTX_data_scene(C);
+       Object *ob = ED_object_context(C);
        int from_mix = RNA_boolean_get(op->ptr, "from_mix");
 
        ED_object_shape_key_add(C, scene, ob, from_mix);
@@ -289,7 +289,7 @@ void OBJECT_OT_shape_key_add(wmOperatorType *ot)
        ot->exec = shape_key_add_exec;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        /* properties */
        RNA_def_boolean(ot->srna, "from_mix", 1, "From Mix", "Create the new shape key from the existing mix of keys");
@@ -297,7 +297,7 @@ void OBJECT_OT_shape_key_add(wmOperatorType *ot)
 
 static int shape_key_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
 
        if (!ED_object_shape_key_remove(C, ob))
                return OPERATOR_CANCELLED;
@@ -317,23 +317,23 @@ void OBJECT_OT_shape_key_remove(wmOperatorType *ot)
        ot->exec = shape_key_remove_exec;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
 static int shape_key_clear_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Object *ob= ED_object_context(C);
-       Key *key= ob_get_key(ob);
-       KeyBlock *kb= ob_get_keyblock(ob);
+       Object *ob = ED_object_context(C);
+       Key *key = ob_get_key(ob);
+       KeyBlock *kb = ob_get_keyblock(ob);
 
        if (!key || !kb)
                return OPERATOR_CANCELLED;
        
-       for (kb=key->block.first; kb; kb=kb->next)
-               kb->curval= 0.0f;
+       for (kb = key->block.first; kb; kb = kb->next)
+               kb->curval = 0.0f;
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
        
        return OPERATOR_FINISHED;
 }
@@ -350,7 +350,7 @@ void OBJECT_OT_shape_key_clear(wmOperatorType *ot)
        ot->exec = shape_key_clear_exec;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
 /* starting point and step size could be optional */
@@ -364,11 +364,11 @@ static int shape_key_retime_exec(bContext *C, wmOperator *UNUSED(op))
        if (!key || !kb)
                return OPERATOR_CANCELLED;
 
-       for (kb=key->block.first; kb; kb=kb->next)
+       for (kb = key->block.first; kb; kb = kb->next)
                kb->pos = (cfra += 0.1f);
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
        return OPERATOR_FINISHED;
 }
@@ -385,12 +385,12 @@ void OBJECT_OT_shape_key_retime(wmOperatorType *ot)
        ot->exec = shape_key_retime_exec;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
 static int shape_key_mirror_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
 
        if (!object_shape_key_mirror(C, ob))
                return OPERATOR_CANCELLED;
@@ -409,28 +409,28 @@ void OBJECT_OT_shape_key_mirror(wmOperatorType *ot)
        ot->exec = shape_key_mirror_exec;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
 
 static int shape_key_move_exec(bContext *C, wmOperator *op)
 {
-       Object *ob= ED_object_context(C);
+       Object *ob = ED_object_context(C);
 
-       int type= RNA_enum_get(op->ptr, "type");
-       Key *key= ob_get_key(ob);
+       int type = RNA_enum_get(op->ptr, "type");
+       Key *key = ob_get_key(ob);
 
        if (key) {
                KeyBlock *kb, *kb_other;
-               int shapenr_act= ob->shapenr-1;
-               int shapenr_swap= shapenr_act + type;
-               kb= BLI_findlink(&key->block, shapenr_act);
+               int shapenr_act = ob->shapenr - 1;
+               int shapenr_swap = shapenr_act + type;
+               kb = BLI_findlink(&key->block, shapenr_act);
 
-               if ((type==-1 && kb->prev==NULL) || (type==1 && kb->next==NULL)) {
+               if ((type == -1 && kb->prev == NULL) || (type == 1 && kb->next == NULL)) {
                        return OPERATOR_CANCELLED;
                }
 
-               for (kb_other= key->block.first; kb_other; kb_other= kb_other->next) {
+               for (kb_other = key->block.first; kb_other; kb_other = kb_other->next) {
                        if (kb_other->relative == shapenr_act) {
                                kb_other->relative += type;
                        }
@@ -439,16 +439,16 @@ static int shape_key_move_exec(bContext *C, wmOperator *op)
                        }
                }
 
-               if (type==-1) {
+               if (type == -1) {
                        /* move back */
-                       kb_other= kb->prev;
+                       kb_other = kb->prev;
                        BLI_remlink(&key->block, kb);
                        BLI_insertlinkbefore(&key->block, kb_other, kb);
                        ob->shapenr--;
                }
                else {
                        /* move next */
-                       kb_other= kb->next;
+                       kb_other = kb->next;
                        BLI_remlink(&key->block, kb);
                        BLI_insertlinkafter(&key->block, kb_other, kb);
                        ob->shapenr++;
@@ -458,7 +458,7 @@ static int shape_key_move_exec(bContext *C, wmOperator *op)
        }
 
        DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+       WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
        return OPERATOR_FINISHED;
 }
@@ -480,7 +480,7 @@ void OBJECT_OT_shape_key_move(wmOperatorType *ot)
        ot->exec = shape_key_move_exec;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
 }