Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / editors / physics / editparticle.c
index a9fc65bdc37e543ec42159698e0c14449031729b..b92632b45afcf8d9bd0e8b9a1d0e699f76bd4138 100644 (file)
@@ -104,21 +104,13 @@ static int PE_poll(bContext *C)
        
        psys= PE_get_current(scene, ob);
 
        
        psys= PE_get_current(scene, ob);
 
-       return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
+       return (psys && psys->edit && (ob && ob->mode & OB_MODE_PARTICLE_EDIT));
 }
 
 static int PE_poll_3dview(bContext *C)
 {
 }
 
 static int PE_poll_3dview(bContext *C)
 {
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       ParticleSystem *psys;
-
-       if(!scene || !ob || !CTX_wm_region_view3d(C))
-               return 0;
-       
-       psys= PE_get_current(scene, ob);
-
-       return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
+       return PE_poll(C) && CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
+               CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
 }
 
 static void PE_free_particle_edit(ParticleSystem *psys)
 }
 
 static void PE_free_particle_edit(ParticleSystem *psys)
@@ -164,7 +156,7 @@ static void PE_free_particle_edit(ParticleSystem *psys)
 
 int PE_can_edit(ParticleSystem *psys)
 {
 
 int PE_can_edit(ParticleSystem *psys)
 {
-       return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
+       return (psys && psys->edit);
 }
 
 ParticleEditSettings *PE_settings(Scene *scene)
 }
 
 ParticleEditSettings *PE_settings(Scene *scene)
@@ -194,7 +186,7 @@ ParticleSystem *PE_get_current(Scene *scene, Object *ob)
 
        /* this happens when Blender is started with particle
         * edit mode enabled XXX there's a draw error then? */
 
        /* this happens when Blender is started with particle
         * edit mode enabled XXX there's a draw error then? */
-       if(psys && psys_check_enabled(ob, psys) && (ob == OBACT) && (G.f & G_PARTICLEEDIT))
+       if(psys && psys_check_enabled(ob, psys) && (ob == OBACT) && (ob->mode & OB_MODE_PARTICLE_EDIT))
                if(psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED)
                        if(psys->edit == NULL)
                                PE_create_particle_edit(scene, ob, psys);
                if(psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED)
                        if(psys->edit == NULL)
                                PE_create_particle_edit(scene, ob, psys);
@@ -225,7 +217,7 @@ void PE_hide_keys_time(Scene *scene, ParticleSystem *psys, float cfra)
        ParticleEditSettings *pset=PE_settings(scene);
        int i, k, totpart= psys->totpart;
 
        ParticleEditSettings *pset=PE_settings(scene);
        int i, k, totpart= psys->totpart;
 
-       if(pset->draw_timed && scene->selectmode==SCE_SELECT_POINT) {
+       if(pset->draw_timed && pset->selectmode==SCE_SELECT_POINT) {
                LOOP_PARTICLES(i, pa) {
                        LOOP_KEYS(k, key) {
                                if(fabs(cfra-*key->time) < pset->draw_timed)
                LOOP_PARTICLES(i, pa) {
                        LOOP_KEYS(k, key) {
                                if(fabs(cfra-*key->time) < pset->draw_timed)
@@ -271,6 +263,7 @@ typedef struct PEData {
        float smoothfac;
        float weightfac;
        float growfac;
        float smoothfac;
        float weightfac;
        float growfac;
+       int totrekey;
 
        int invert;
        int tot;
 
        int invert;
        int tot;
@@ -425,11 +418,12 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, int nearest)
        ParticleEdit *edit= psys->edit;
        ParticleData *pa;
        ParticleEditKey *key;
        ParticleEdit *edit= psys->edit;
        ParticleData *pa;
        ParticleEditKey *key;
+       ParticleEditSettings *pset= PE_settings(data->scene);
        int i, k, totpart, nearest_pa, nearest_key;
        float dist= data->rad;
 
        /* in path select mode we have no keys */
        int i, k, totpart, nearest_pa, nearest_key;
        float dist= data->rad;
 
        /* in path select mode we have no keys */
-       if(data->scene->selectmode==SCE_SELECT_PATH)
+       if(pset->selectmode==SCE_SELECT_PATH)
                return;
 
        totpart= psys->totpart;
                return;
 
        totpart= psys->totpart;
@@ -439,7 +433,7 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, int nearest)
        LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
        LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
-               if(data->scene->selectmode == SCE_SELECT_END) {
+               if(pset->selectmode == SCE_SELECT_END) {
                        /* only do end keys */
                        key= edit->keys[i] + pa->totkey-1;
 
                        /* only do end keys */
                        key= edit->keys[i] + pa->totkey-1;
 
@@ -481,18 +475,19 @@ static void foreach_mouse_hit_particle(PEData *data, ForParticleFunc func, int s
        ParticleSystem *psys= data->psys;
        ParticleData *pa;
        ParticleEditKey *key;
        ParticleSystem *psys= data->psys;
        ParticleData *pa;
        ParticleEditKey *key;
+       ParticleEditSettings *pset= PE_settings(data->scene);
        int i, k, totpart;
 
        totpart= psys->totpart;
 
        /* all is selected in path mode */
        int i, k, totpart;
 
        totpart= psys->totpart;
 
        /* all is selected in path mode */
-       if(data->scene->selectmode==SCE_SELECT_PATH)
+       if(pset->selectmode==SCE_SELECT_PATH)
                selected=0;
 
        LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                selected=0;
 
        LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
-               if(data->scene->selectmode==SCE_SELECT_END) {
+               if(pset->selectmode==SCE_SELECT_END) {
                        /* only do end keys */
                        key= psys->edit->keys[i] + pa->totkey-1;
 
                        /* only do end keys */
                        key= psys->edit->keys[i] + pa->totkey-1;
 
@@ -522,6 +517,7 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected
        ParticleData *pa;
        ParticleEditKey *key;
        ParticleSystemModifierData *psmd=0;
        ParticleData *pa;
        ParticleEditKey *key;
        ParticleSystemModifierData *psmd=0;
+       ParticleEditSettings *pset= PE_settings(data->scene);
        int i, k, totpart;
        float mat[4][4], imat[4][4];
 
        int i, k, totpart;
        float mat[4][4], imat[4][4];
 
@@ -529,7 +525,7 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected
        totpart= psys->totpart;
 
        /* all is selected in path mode */
        totpart= psys->totpart;
 
        /* all is selected in path mode */
-       if(data->scene->selectmode==SCE_SELECT_PATH)
+       if(pset->selectmode==SCE_SELECT_PATH)
                selected= 0;
 
        Mat4One(imat);
                selected= 0;
 
        Mat4One(imat);
@@ -541,7 +537,7 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected
                psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, pa, mat);
                Mat4Invert(imat,mat);
 
                psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, pa, mat);
                Mat4Invert(imat,mat);
 
-               if(data->scene->selectmode==SCE_SELECT_END) {
+               if(pset->selectmode==SCE_SELECT_END) {
                        /* only do end keys */
                        key= psys->edit->keys[i] + pa->totkey-1;
 
                        /* only do end keys */
                        key= psys->edit->keys[i] + pa->totkey-1;
 
@@ -610,6 +606,7 @@ static int count_selected_keys(Scene *scene, ParticleSystem *psys)
 {
        ParticleData *pa;
        ParticleEditKey *key;
 {
        ParticleData *pa;
        ParticleEditKey *key;
+       ParticleEditSettings *pset= PE_settings(scene);
        int i, k, totpart, sel= 0;
 
        totpart= psys->totpart;
        int i, k, totpart, sel= 0;
 
        totpart= psys->totpart;
@@ -619,12 +616,12 @@ static int count_selected_keys(Scene *scene, ParticleSystem *psys)
 
                key= psys->edit->keys[i];
 
 
                key= psys->edit->keys[i];
 
-               if(scene->selectmode==SCE_SELECT_POINT) {
+               if(pset->selectmode==SCE_SELECT_POINT) {
                        for(k=0; k<pa->totkey; k++,key++)
                                if(key->flag & PEK_SELECT)
                                        sel++;
                }
                        for(k=0; k<pa->totkey; k++,key++)
                                if(key->flag & PEK_SELECT)
                                        sel++;
                }
-               else if(scene->selectmode==SCE_SELECT_END) {
+               else if(pset->selectmode==SCE_SELECT_END) {
                        key += pa->totkey-1;
 
                        if(key->flag & PEK_SELECT)
                        key += pa->totkey-1;
 
                        if(key->flag & PEK_SELECT)
@@ -1454,6 +1451,7 @@ int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select)
        ParticleEdit *edit;
        ParticleData *pa;
        ParticleEditKey *key;
        ParticleEdit *edit;
        ParticleData *pa;
        ParticleEditKey *key;
+       ParticleEditSettings *pset= PE_settings(scene);
        float co[3], mat[4][4];
        short vertco[2];
        int i, k, totpart;
        float co[3], mat[4][4];
        short vertco[2];
        int i, k, totpart;
@@ -1470,7 +1468,7 @@ int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select)
 
                psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, mat);
 
 
                psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, mat);
 
-               if(scene->selectmode==SCE_SELECT_POINT) {
+               if(pset->selectmode==SCE_SELECT_POINT) {
                        LOOP_KEYS(k, key) {
                                VECCOPY(co, key->co);
                                Mat4MulVecfl(mat, co);
                        LOOP_KEYS(k, key) {
                                VECCOPY(co, key->co);
                                Mat4MulVecfl(mat, co);
@@ -1487,7 +1485,7 @@ int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select)
                                }
                        }
                }
                                }
                        }
                }
-               else if(scene->selectmode==SCE_SELECT_END) {
+               else if(pset->selectmode==SCE_SELECT_END) {
                        key= edit->keys[i] + pa->totkey - 1;
 
                        VECCOPY(co, key->co);
                        key= edit->keys[i] + pa->totkey - 1;
 
                        VECCOPY(co, key->co);
@@ -1743,7 +1741,6 @@ static void rekey_particle(PEData *data, int pa_index)
        ParticleSystem *psys= data->psys;
        ParticleData *pa= &psys->particles[pa_index];
        ParticleEdit *edit= psys->edit;
        ParticleSystem *psys= data->psys;
        ParticleData *pa= &psys->particles[pa_index];
        ParticleEdit *edit= psys->edit;
-       ParticleEditSettings *pset= PE_settings(data->scene);
        ParticleKey state;
        HairKey *key, *new_keys;
        ParticleEditKey *ekey;
        ParticleKey state;
        HairKey *key, *new_keys;
        ParticleEditKey *ekey;
@@ -1752,19 +1749,19 @@ static void rekey_particle(PEData *data, int pa_index)
 
        pa->flag |= PARS_REKEY;
 
 
        pa->flag |= PARS_REKEY;
 
-       key= new_keys= MEM_callocN(pset->totrekey * sizeof(HairKey),"Hair re-key keys");
+       key= new_keys= MEM_callocN(data->totrekey * sizeof(HairKey),"Hair re-key keys");
 
        /* root and tip stay the same */
        VECCOPY(key->co, pa->hair->co);
 
        /* root and tip stay the same */
        VECCOPY(key->co, pa->hair->co);
-       VECCOPY((key + pset->totrekey - 1)->co, (pa->hair + pa->totkey - 1)->co);
+       VECCOPY((key + data->totrekey - 1)->co, (pa->hair + pa->totkey - 1)->co);
 
        sta= key->time= pa->hair->time;
 
        sta= key->time= pa->hair->time;
-       end= (key + pset->totrekey - 1)->time= (pa->hair + pa->totkey - 1)->time;
-       dval= (end - sta) / (float)(pset->totrekey - 1);
+       end= (key + data->totrekey - 1)->time= (pa->hair + pa->totkey - 1)->time;
+       dval= (end - sta) / (float)(data->totrekey - 1);
 
        /* interpolate new keys from old ones */
 
        /* interpolate new keys from old ones */
-       for(k=1,key++; k<pset->totrekey-1; k++,key++) {
-               state.time= (float)k / (float)(pset->totrekey-1);
+       for(k=1,key++; k<data->totrekey-1; k++,key++) {
+               state.time= (float)k / (float)(data->totrekey-1);
                psys_get_particle_on_path(data->scene, data->ob, psys, pa_index, &state, 0);
                VECCOPY(key->co, state.co);
                key->time= sta + k * dval;
                psys_get_particle_on_path(data->scene, data->ob, psys, pa_index, &state, 0);
                VECCOPY(key->co, state.co);
                key->time= sta + k * dval;
@@ -1775,7 +1772,7 @@ static void rekey_particle(PEData *data, int pa_index)
                MEM_freeN(pa->hair);
        pa->hair= new_keys;
 
                MEM_freeN(pa->hair);
        pa->hair= new_keys;
 
-       pa->totkey=pset->totrekey;
+       pa->totkey=data->totrekey;
 
        if(edit->keys[pa_index])
                MEM_freeN(edit->keys[pa_index]);
 
        if(edit->keys[pa_index])
                MEM_freeN(edit->keys[pa_index]);
@@ -1793,14 +1790,11 @@ static void rekey_particle(PEData *data, int pa_index)
 static int rekey_exec(bContext *C, wmOperator *op)
 {
        PEData data;
 static int rekey_exec(bContext *C, wmOperator *op)
 {
        PEData data;
-       ParticleEditSettings *pset;
 
        PE_set_data(C, &data);
 
 
        PE_set_data(C, &data);
 
-       pset= PE_settings(data.scene);
-       pset->totrekey= RNA_int_get(op->ptr, "keys");
-
-       data.dval= 1.0f / (float)(pset->totrekey-1);
+       data.dval= 1.0f / (float)(data.totrekey-1);
+       data.totrekey= RNA_int_get(op->ptr, "keys");
 
        foreach_selected_particle(&data, rekey_particle);
        
 
        foreach_selected_particle(&data, rekey_particle);
        
@@ -1821,7 +1815,7 @@ void PARTICLE_OT_rekey(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= rekey_exec;
        
        /* api callbacks */
        ot->exec= rekey_exec;
-       ot->invoke= WM_operator_redo;
+       ot->invoke= WM_operator_props_popup;
        ot->poll= PE_poll;
 
        /* flags */
        ot->poll= PE_poll;
 
        /* flags */
@@ -2267,7 +2261,7 @@ static void toggle_particle_cursor(bContext *C, int enable)
                pset->paintcursor = NULL;
        }
        else if(enable)
                pset->paintcursor = NULL;
        }
        else if(enable)
-               pset->paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), PE_poll, brush_drawcursor, NULL);
+               pset->paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), PE_poll_3dview, brush_drawcursor, NULL);
 }
 
 /********************* radial control operator *********************/
 }
 
 /********************* radial control operator *********************/
@@ -2277,7 +2271,7 @@ static int brush_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *eve
        ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
        ParticleBrushData *brush;
        int mode = RNA_enum_get(op->ptr, "mode");
        ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
        ParticleBrushData *brush;
        int mode = RNA_enum_get(op->ptr, "mode");
-       float original_value;
+       float original_value=1.0f;
 
        if(pset->brushtype < 0)
                return OPERATOR_CANCELLED;
 
        if(pset->brushtype < 0)
                return OPERATOR_CANCELLED;
@@ -2339,7 +2333,7 @@ void PARTICLE_OT_brush_radial_control(wmOperatorType *ot)
        ot->poll= PE_poll;
        
        /* flags */
        ot->poll= PE_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 }
 
 /*************************** delete operator **************************/
 }
 
 /*************************** delete operator **************************/
@@ -2349,7 +2343,7 @@ enum { DEL_PARTICLE, DEL_KEY };
 static EnumPropertyItem delete_type_items[]= {
        {DEL_PARTICLE, "PARTICLE", 0, "Particle", ""},
        {DEL_KEY, "KEY", 0, "Key", ""},
 static EnumPropertyItem delete_type_items[]= {
        {DEL_PARTICLE, "PARTICLE", 0, "Particle", ""},
        {DEL_KEY, "KEY", 0, "Key", ""},
-       {0, NULL, NULL}};
+       {0, NULL, 0, NULL, NULL}};
 
 static void set_delete_particle(PEData *data, int pa_index)
 {
 
 static void set_delete_particle(PEData *data, int pa_index)
 {
@@ -3074,11 +3068,13 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
        ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
        ParticleBrushData *brush= &pset->brush[pset->brushtype];
        ARegion *ar= CTX_wm_region(C);
        ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
        ParticleBrushData *brush= &pset->brush[pset->brushtype];
        ARegion *ar= CTX_wm_region(C);
-       float vec1[3], vec2[3];
+       float vec1[3], vec2[3], mousef[2];
        short mval[2], mvalo[2];
        int flip, mouse[2], dx, dy, removed= 0, selected= 0;
 
        short mval[2], mvalo[2];
        int flip, mouse[2], dx, dy, removed= 0, selected= 0;
 
-       RNA_int_get_array(itemptr, "mouse", mouse);
+       RNA_float_get_array(itemptr, "mouse", mousef);
+       mouse[0] = mousef[0];
+       mouse[1] = mousef[1];
        flip= RNA_boolean_get(itemptr, "flip");
 
        if(bedit->first) {
        flip= RNA_boolean_get(itemptr, "flip");
 
        if(bedit->first) {
@@ -3289,7 +3285,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event)
 {
        ARegion *ar= CTX_wm_region(C);
        PointerRNA itemptr;
 {
        ARegion *ar= CTX_wm_region(C);
        PointerRNA itemptr;
-       int mouse[2];
+       float mouse[2];
 
        mouse[0]= event->x - ar->winrct.xmin;
        mouse[1]= event->y - ar->winrct.ymin;
 
        mouse[0]= event->x - ar->winrct.xmin;
        mouse[1]= event->y - ar->winrct.ymin;
@@ -3297,7 +3293,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event)
        /* fill in stroke */
        RNA_collection_add(op->ptr, "stroke", &itemptr);
 
        /* fill in stroke */
        RNA_collection_add(op->ptr, "stroke", &itemptr);
 
-       RNA_int_set_array(&itemptr, "mouse", mouse);
+       RNA_float_set_array(&itemptr, "mouse", mouse);
        RNA_boolean_set(&itemptr, "flip", event->shift != 0); // XXX hardcoded
 
        /* apply */
        RNA_boolean_set(&itemptr, "flip", event->shift != 0); // XXX hardcoded
 
        /* apply */
@@ -3353,7 +3349,7 @@ void PARTICLE_OT_brush_edit(wmOperatorType *ot)
        ot->poll= PE_poll_3dview;
 
        /* flags */
        ot->poll= PE_poll_3dview;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 
        /* properties */
        RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
 
        /* properties */
        RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
@@ -3565,7 +3561,7 @@ void PE_undo_menu(Scene *scene, Object *ob)
        ParticleEdit *edit= 0;
        ParticleUndo *undo;
        DynStr *ds;
        ParticleEdit *edit= 0;
        ParticleUndo *undo;
        DynStr *ds;
-       short event;
+       short event=0;
        char *menu;
 
        if(!PE_can_edit(psys)) return;
        char *menu;
 
        if(!PE_can_edit(psys)) return;
@@ -3708,7 +3704,7 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
                psys->flag |= PSYS_CURRENT;
        }
 
                psys->flag |= PSYS_CURRENT;
        }
 
-       if(!(G.f & G_PARTICLEEDIT)) {
+       if(!(ob->mode & OB_MODE_PARTICLE_EDIT)) {
                if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) {
                        if(psys_check_enabled(ob, psys)) {
                                if(psys->edit==NULL)
                if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) {
                        if(psys_check_enabled(ob, psys)) {
                                if(psys->edit==NULL)
@@ -3718,12 +3714,12 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
                        }
                }
 
                        }
                }
 
-               G.f |= G_PARTICLEEDIT;
+               ob->mode |= OB_MODE_PARTICLE_EDIT;
                toggle_particle_cursor(C, 1);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
        }
        else {
                toggle_particle_cursor(C, 1);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
        }
        else {
-               G.f &= ~G_PARTICLEEDIT;
+               ob->mode &= ~OB_MODE_PARTICLE_EDIT;
                toggle_particle_cursor(C, 0);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
        }
                toggle_particle_cursor(C, 0);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
        }
@@ -3771,7 +3767,7 @@ static int set_editable_exec(bContext *C, wmOperator *op)
                if(psys_check_enabled(ob, psys)) {
                        psys->flag |= PSYS_EDITED;
 
                if(psys_check_enabled(ob, psys)) {
                        psys->flag |= PSYS_EDITED;
 
-                       if(G.f & G_PARTICLEEDIT)
+                       if(ob->mode & OB_MODE_PARTICLE_EDIT)
                                PE_create_particle_edit(scene, ob, psys);
                }
                else
                                PE_create_particle_edit(scene, ob, psys);
                }
                else
@@ -3812,7 +3808,7 @@ void PE_change_act(void *ob_v, void *act_v)
                        psys->flag |= PSYS_CURRENT;
 
                        if(psys_check_enabled(ob, psys)) {
                        psys->flag |= PSYS_CURRENT;
 
                        if(psys_check_enabled(ob, psys)) {
-                               if(G.f & G_PARTICLEEDIT && !psys->edit)
+                               if(ob->mode & OB_MODE_PARTICLE_EDIT && !psys->edit)
                                        PE_create_particle_edit(scene, ob, psys);
                                psys_update_world_cos(ob, psys);
                        }
                                        PE_create_particle_edit(scene, ob, psys);
                                psys_update_world_cos(ob, psys);
                        }
@@ -3830,7 +3826,7 @@ void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys)
        psys->flag |= PSYS_CURRENT;
        
        if(psys_check_enabled(ob, psys)) {
        psys->flag |= PSYS_CURRENT;
        
        if(psys_check_enabled(ob, psys)) {
-               if(G.f & G_PARTICLEEDIT && !psys->edit)
+               if(ob->mode & OB_MODE_PARTICLE_EDIT && !psys->edit)
                        PE_create_particle_edit(scene, ob, psys);
 
                psys_update_world_cos(ob, psys);
                        PE_create_particle_edit(scene, ob, psys);
 
                psys_update_world_cos(ob, psys);
@@ -3842,6 +3838,7 @@ void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys)
 static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Scene *scene= CTX_data_scene(C);
 static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Scene *scene= CTX_data_scene(C);
+       ParticleEditSettings *pset=PE_settings(scene);
        uiPopupMenu *pup;
        uiLayout *layout;
 
        uiPopupMenu *pup;
        uiLayout *layout;
 
@@ -3849,7 +3846,7 @@ static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
        layout= uiPupMenuLayout(pup);
 
        uiItemO(layout, NULL, 0, "PARTICLE_OT_rekey");
        layout= uiPupMenuLayout(pup);
 
        uiItemO(layout, NULL, 0, "PARTICLE_OT_rekey");
-       if(scene->selectmode & SCE_SELECT_POINT) {
+       if(pset->selectmode & SCE_SELECT_POINT) {
                uiItemO(layout, NULL, 0, "PARTICLE_OT_subdivide");
                uiItemO(layout, NULL, 0, "PARTICLE_OT_select_first");
                uiItemO(layout, NULL, 0, "PARTICLE_OT_select_last");
                uiItemO(layout, NULL, 0, "PARTICLE_OT_subdivide");
                uiItemO(layout, NULL, 0, "PARTICLE_OT_select_first");
                uiItemO(layout, NULL, 0, "PARTICLE_OT_select_last");