2.5: Particle edit mode more functional now. Transform, brush
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 25 Feb 2009 19:29:58 +0000 (19:29 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 25 Feb 2009 19:29:58 +0000 (19:29 +0000)
editing, paint cursor, radial control, mouse/border/circle/lasso
select, mirroring, bad level calls fixed, etc.

16 files changed:
source/blender/blenkernel/BKE_particle.h
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/include/ED_mesh.h
source/blender/editors/include/ED_particle.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/physics/editparticle.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_manipulator.c
source/blender/makesdna/DNA_particle_types.h
source/blender/makesdna/DNA_scene_types.h

index 616bf737889f77b4cd128bd80e151c96ae58b385..8bf6d91e325bf8e46196da507cceb696f418e270 100644 (file)
@@ -139,15 +139,20 @@ typedef struct ParticleUndo {
        char name[64];
 } ParticleUndo;
 
-typedef struct ParticleEdit{
+typedef struct ParticleEdit {
        ListBase undo;
        struct ParticleUndo *curundo;
-       struct KDTree *emitter_field;
+
        ParticleEditKey **keys;
+       int totkeys;
+
        int *mirror_cache;
+
+       struct KDTree *emitter_field;
        float *emitter_cosnos;
 
-       int totkeys;
+       char sel_col[3];
+       char nosel_col[3];
 } ParticleEdit;
 
 typedef struct ParticleThreadContext {
@@ -244,6 +249,7 @@ void psys_find_parents(struct Object *ob, struct ParticleSystemModifierData *psm
 
 void psys_cache_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra, int editupdate);
 void psys_cache_child_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra, int editupdate);
+void psys_update_world_cos(struct Object *ob, struct ParticleSystem *psys);
 int do_guide(struct Scene *scene, struct ParticleKey *state, int pa_num, float time, struct ListBase *lb);
 float psys_get_size(struct Object *ob, struct Material *ma, struct ParticleSystemModifierData *psmd, struct IpoCurve *icu_size, struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleData *pa, float *vg_size);
 float psys_get_timestep(struct ParticleSettings *part);
index cac95a85d54865f9048bf98dc7c7f132514bcb95..2b1dcc782c63e27f1e74a85f066de9e512fc3e8e 100644 (file)
@@ -391,7 +391,8 @@ void psys_free(Object *ob, ParticleSystem * psys)
 
                free_keyed_keys(psys);
 
-               //XXX PE_free_particle_edit(psys);
+               if(psys->edit && psys->free_edit)
+                       psys->free_edit(psys);
 
                if(psys->particles){
                        MEM_freeN(psys->particles);
@@ -2338,7 +2339,6 @@ void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra
        int k,i;
        int steps = (int)pow(2.0, (double)psys->part->draw_step);
        int totpart = psys->totpart;
-       char nosel[4], sel[4];
        float sel_col[3];
        float nosel_col[3];
        float length, vec[3];
@@ -2350,25 +2350,25 @@ void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra
        if((psys->flag & PSYS_HAIR_DONE)==0 && (psys->flag & PSYS_KEYED)==0)
                return;
 
-       if(psys->renderdata)
+       if(psys->renderdata) {
                steps = (int)pow(2.0, (double)psys->part->ren_step);
-       else if(psys_in_edit_mode(scene, psys)){
+       }
+       else if(psys_in_edit_mode(scene, psys)) {
                edit=psys->edit;
                
                //timed = edit->draw_timed;
 
-               //XXX PE_get_colors(sel,nosel);
-               if(pset->brushtype == PE_BRUSH_WEIGHT){
+               if(pset->brushtype == PE_BRUSH_WEIGHT) {
                        sel_col[0] = sel_col[1] = sel_col[2] = 1.0f;
                        nosel_col[0] = nosel_col[1] = nosel_col[2] = 0.0f;
                }
                else{
-                       sel_col[0] = (float)sel[0] / 255.0f;
-                       sel_col[1] = (float)sel[1] / 255.0f;
-                       sel_col[2] = (float)sel[2] / 255.0f;
-                       nosel_col[0] = (float)nosel[0] / 255.0f;
-                       nosel_col[1] = (float)nosel[1] / 255.0f;
-                       nosel_col[2] = (float)nosel[2] / 255.0f;
+                       sel_col[0] = (float)edit->sel_col[0] / 255.0f;
+                       sel_col[1] = (float)edit->sel_col[1] / 255.0f;
+                       sel_col[2] = (float)edit->sel_col[2] / 255.0f;
+                       nosel_col[0] = (float)edit->nosel_col[0] / 255.0f;
+                       nosel_col[1] = (float)edit->nosel_col[1] / 255.0f;
+                       nosel_col[2] = (float)edit->nosel_col[2] / 255.0f;
                }
        }
 
index 516cdc7612532c9e671688685ad9a5a54db5d3be..afb4fb68c8c158e08d712c270e13022a14b49e50 100644 (file)
@@ -4174,6 +4174,30 @@ static void psys_update_path_cache(Scene *scene, Object *ob, ParticleSystemModif
                psys_free_path_cache(psys);
 }
 
+/* calculate and store key locations in world coordinates */
+void psys_update_world_cos(Object *ob, ParticleSystem *psys)
+{
+       ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
+       ParticleData *pa;
+       ParticleEditKey *key;
+       int i, k, totpart;
+       float hairmat[4][4];
+
+       if(psys==0 || psys->edit==0)
+               return;
+
+       totpart= psys->totpart;
+
+       for(i=0, pa=psys->particles; i<totpart; i++, pa++) {
+               psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
+
+               for(k=0, key=psys->edit->keys[i]; k<pa->totkey; k++, key++) {
+                       VECCOPY(key->world_co,key->co);
+                       Mat4MulVecfl(hairmat, key->world_co);
+               }
+       }
+}
+
 static void hair_step(Scene *scene, Object *ob, ParticleSystemModifierData *psmd, ParticleSystem *psys, float cfra)
 {
        ParticleSettings *part = psys->part;
@@ -4200,7 +4224,7 @@ static void hair_step(Scene *scene, Object *ob, ParticleSystemModifierData *psmd
                precalc_effectors(scene, ob,psys,psmd,cfra);
                
        if(psys_in_edit_mode(scene, psys))
-               ; //XXX PE_recalc_world_cos(ob, psys);
+               psys_update_world_cos(ob, psys);
 
        psys_update_path_cache(scene, ob,psmd,psys,cfra);
 }
index 104c058984bec9421767433c4731b834de27bc64..cfad2ae579f8d3499c267e548a04232ec2cdc65c 100644 (file)
@@ -2941,6 +2941,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
                }
 
                psys->edit = 0;
+               psys->free_edit = NULL;
                psys->pathcache = 0;
                psys->childcache = 0;
                psys->pathcachebufs.first = psys->pathcachebufs.last = 0;
@@ -3852,6 +3853,9 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                sce->toolsettings->vpaint= newdataadr(fd, sce->toolsettings->vpaint);
                sce->toolsettings->wpaint= newdataadr(fd, sce->toolsettings->wpaint);
                sce->toolsettings->sculpt= newdataadr(fd, sce->toolsettings->sculpt);
+               sce->toolsettings->imapaint.paintcursor= NULL;
+               sce->toolsettings->particle.paintcursor= NULL;
+
                if(sce->toolsettings->sculpt)
                        sce->toolsettings->sculpt->session= MEM_callocN(sizeof(SculptSession), "reload sculpt session");
        }
index 0353fb8c28d7439ad9cf26447c9afdea98e9ee32..022d8fe49a8020f64d28af4c6e4074ae10f9f2f3 100644 (file)
@@ -71,9 +71,10 @@ struct CustomData;
 
 /* meshtools.c */
 
-intptr_t       mesh_octree_table(Object *ob, struct EditMesh *em, float *co, char mode);
-struct EditVert   *editmesh_get_x_mirror_vert(Object *ob, struct EditMesh *em, float *co);
-int                    mesh_get_x_mirror_vert(Object *ob, int index);
+intptr_t       mesh_octree_table(struct Object *ob, struct EditMesh *em, float *co, char mode);
+struct EditVert   *editmesh_get_x_mirror_vert(struct Object *ob, struct EditMesh *em, float *co);
+int                    mesh_get_x_mirror_vert(struct Object *ob, int index);
+int                    *mesh_get_x_mirror_faces(struct Object *ob, struct EditMesh *em);
 
 /* mesh_ops.c */
 void           ED_operatortypes_mesh(void);
index b20db0cb7e8a1aa6ba38e622ec77c914721cf8a0..0e5d7302837aceb05e20889d09a8ec8370e730af 100644 (file)
 #ifndef ED_PARTICLE_H
 #define ED_PARTICLE_H
 
+struct bContext;
 struct Object;
-struct ParticleSystem;
 struct ParticleEditSettings;
+struct ParticleSystem;
 struct RadialControl;
-struct ViewContext;
 struct rcti;
 struct wmWindowManager;
 
 /* particle edit mode */
-void PE_set_particle_edit(struct Scene *scene);
-void PE_create_particle_edit(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
-void PE_free_particle_edit(struct ParticleSystem *psys);
-
 void PE_change_act(void *ob_v, void *act_v);
 void PE_change_act_psys(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
 int PE_can_edit(struct ParticleSystem *psys);
@@ -51,38 +47,17 @@ int PE_can_edit(struct ParticleSystem *psys);
 struct ParticleSystem *PE_get_current(struct Scene *scene, struct Object *ob);
 short PE_get_current_num(struct Object *ob);
 int PE_minmax(struct Scene *scene, float *min, float *max);
-void PE_get_colors(char sel[4], char nosel[4]);
 struct ParticleEditSettings *PE_settings(Scene *scene);
-struct RadialControl **PE_radialcontrol(void);
 
 /* update calls */
 void PE_hide_keys_time(struct Scene *scene, struct ParticleSystem *psys, float cfra);
 void PE_update_object(struct Scene *scene, struct Object *ob, int useflag);
-void PE_update_selection(struct Scene *scene, struct Object *ob, int useflag);
-void PE_recalc_world_cos(struct Object *ob, struct ParticleSystem *psys);
 
 /* selection tools */
-void PE_select_root(void);
-void PE_select_tip(void);
-void PE_deselectall(void);
-void PE_select_linked(void);
-void PE_select_less(void);
-void PE_select_more(void);
-
-void PE_mouse_particles(void);
-void PE_border_select(struct ViewContext *vc, struct rcti *rect, int select);
-void PE_circle_select(struct ViewContext *vc, int selecting, short *mval, float rad);
-void PE_lasso_select(struct ViewContext *vc, short mcords[][2], short moves, short select);
-
-/* tools */
-void PE_hide(int mode);
-void PE_rekey(void);
-void PE_subdivide(Object *ob);
-int PE_brush_particles(void);
-void PE_remove_doubles(void);
-void PE_selectbrush_menu(Scene *scene);
-void PE_remove_doubles(void);
-void PE_radialcontrol_start(const int mode);
+int PE_mouse_particles(struct bContext *C, short *mval, int extend);
+int PE_border_select(struct bContext *C, struct rcti *rect, int select);
+int PE_circle_select(struct bContext *C, int selecting, short *mval, float rad);
+int PE_lasso_select(struct bContext *C, short mcords[][2], short moves, short select);
 
 /* undo */
 void PE_undo_push(Scene *scene, char *str);
index 1ab61da83bb744feae7e3f276ad5077be229b590..128af0fd36ae690756985964cf2cb1ddc6369118 100644 (file)
@@ -127,6 +127,8 @@ void view3d_get_transformation(struct ViewContext *vc, struct Object *ob, struct
 
 /* XXX should move to arithb.c */
 int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2);
+int lasso_inside(short mcords[][2], short moves, short sx, short sy);
+int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, int y1);
 
 /* modes */
 void ED_view3d_exit_paint_modes(struct bContext *C);
index 4751bd7bb3374f04887172004c16a1b5c212fd4c..b3c7be688f276295fd1c8e61f79fabe3fded7d48 100644 (file)
@@ -70,6 +70,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "ED_mesh.h"
 #include "ED_particle.h"
 #include "ED_view3d.h"
 
 
 #include "physics_intern.h"
 
+static void PE_create_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys);
 static void ParticleUndo_clear(ParticleSystem *psys);
 
-#define LOOP_PARTICLES(i,pa) for(i=0, pa=psys->particles; i<totpart; i++, pa++)
-#define LOOP_KEYS(k,key) if(psys->edit)for(k=0, key=psys->edit->keys[i]; k<pa->totkey; k++, key++)
-
-/* XXX */
-static void error() {}
-static int lasso_inside() {return 0;}
-static void *mesh_get_x_mirror_faces() {return NULL;}
-
-#define RADIALCONTROL_SIZE             0
-#define RADIALCONTROL_STRENGTH 0
-#define RADIALCONTROL_NONE             0
-/* XXX */
-
+#define LOOP_PARTICLES(i, pa) for(i=0, pa=psys->particles; i<totpart; i++, pa++)
+#define LOOP_KEYS(k, key) if(psys->edit)for(k=0, key=psys->edit->keys[i]; k<pa->totkey; k++, key++)
 
 /**************************** utilities *******************************/
 
@@ -130,10 +121,10 @@ static int PE_poll_3dview(bContext *C)
        return (psys && psys->edit && (G.f & G_PARTICLEEDIT));
 }
 
-void PE_free_particle_edit(ParticleSystem *psys)
+static void PE_free_particle_edit(ParticleSystem *psys)
 {
-       ParticleEdit *edit=psys->edit;
-       int i, totpart=psys->totpart;
+       ParticleEdit *edit= psys->edit;
+       int i, totpart= psys->totpart;
 
        if(edit==0) return;
 
@@ -164,6 +155,7 @@ void PE_free_particle_edit(ParticleSystem *psys)
        MEM_freeN(edit);
 
        psys->edit= NULL;
+       psys->free_edit= NULL;
 }
 
 /************************************************/
@@ -180,45 +172,6 @@ ParticleEditSettings *PE_settings(Scene *scene)
        return &scene->toolsettings->particle;
 }
 
-void PE_change_act(void *ob_v, void *act_v)
-{
-       Scene *scene= NULL; // XXX
-       Object *ob= ob_v;
-       ParticleSystem *psys;
-       short act= *((short*)act_v) - 1;
-
-       if((psys=psys_get_current(ob)))
-               psys->flag &= ~PSYS_CURRENT;
-
-       if(act>=0) {
-               if((psys=BLI_findlink(&ob->particlesystem,act))) {
-                       psys->flag |= PSYS_CURRENT;
-
-                       if(psys_check_enabled(ob, psys)) {
-                               if(G.f & G_PARTICLEEDIT && !psys->edit)
-                                       PE_create_particle_edit(scene, ob, psys);
-                               PE_recalc_world_cos(ob, psys);
-                       }
-               }
-       }
-}
-
-void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys)
-{
-       ParticleSystem *p;
-       
-       if((p=psys_get_current(ob)))
-               p->flag &= ~PSYS_CURRENT;
-       
-       psys->flag |= PSYS_CURRENT;
-       
-       if(psys_check_enabled(ob, psys)) {
-               if(G.f & G_PARTICLEEDIT && !psys->edit)
-                       PE_create_particle_edit(scene, ob, psys);
-               PE_recalc_world_cos(ob, psys);
-       }
-}
-
 /* always gets atleast the first particlesystem even if PSYS_CURRENT flag is not set */
 ParticleSystem *PE_get_current(Scene *scene, Object *ob)
 {
@@ -239,7 +192,9 @@ ParticleSystem *PE_get_current(Scene *scene, Object *ob)
                psys->flag |= PSYS_CURRENT;
        }
 
-       if(psys && psys_check_enabled(ob, psys)) // XXX && (ob == scene->obact) && (G.f & G_PARTICLEEDIT))
+       /* 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->part->type == PART_HAIR && psys->flag & PSYS_EDITED)
                        if(psys->edit == NULL)
                                PE_create_particle_edit(scene, ob, psys);
@@ -268,11 +223,11 @@ void PE_hide_keys_time(Scene *scene, ParticleSystem *psys, float cfra)
        ParticleData *pa;
        ParticleEditKey *key;
        ParticleEditSettings *pset=PE_settings(scene);
-       int i, k, totpart=psys->totpart;
+       int i, k, totpart= psys->totpart;
 
        if(pset->draw_timed && scene->selectmode==SCE_SELECT_POINT) {
-               LOOP_PARTICLES(i,pa) {
-                       LOOP_KEYS(k,key) {
+               LOOP_PARTICLES(i, pa) {
+                       LOOP_KEYS(k, key) {
                                if(fabs(cfra-*key->time) < pset->draw_timed)
                                        key->flag &= ~PEK_HIDE;
                                else {
@@ -283,8 +238,8 @@ void PE_hide_keys_time(Scene *scene, ParticleSystem *psys, float cfra)
                }
        }
        else {
-               LOOP_PARTICLES(i,pa) {
-                       LOOP_KEYS(k,key) {
+               LOOP_PARTICLES(i, pa) {
+                       LOOP_KEYS(k, key) {
                                key->flag &= ~PEK_HIDE;
                        }
                }
@@ -337,6 +292,9 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
 
        view3d_set_viewcontext(C, &data->vc);
        view3d_get_transformation(&data->vc, data->ob, &data->mats);
+
+       if((data->vc.v3d->drawtype>OB_WIRE) && (data->vc.v3d->flag & V3D_ZBUF_SELECT))
+               view3d_validate_backbuf(&data->vc);
 }
 
 /*************************** selection utilities *******************************/
@@ -386,7 +344,7 @@ static int key_test_depth(PEData *data, float co[3])
        }
 }
 
-static int key_inside_circle(PEData *data, float co[3], float *distance)
+static int key_inside_circle(PEData *data, float rad, float co[3], float *distance)
 {
        float dx, dy, dist;
        short sco[2];
@@ -400,7 +358,7 @@ static int key_inside_circle(PEData *data, float co[3], float *distance)
        dy= data->mval[1] - sco[1];
        dist= sqrt(dx*dx + dy*dy);
 
-       if(dist > data->rad)
+       if(dist > rad)
                return 0;
 
        if(key_test_depth(data, co)) {
@@ -432,7 +390,7 @@ static int key_inside_rect(PEData *data, float co[3])
 static int key_inside_test(PEData *data, float co[3])
 {
        if(data->mval)
-               return key_inside_circle(data, co, NULL);
+               return key_inside_circle(data, data->rad, co, NULL);
        else
                return key_inside_rect(data, co);
 }
@@ -448,7 +406,7 @@ static int particle_is_selected(ParticleSystem *psys, ParticleData *pa)
        sel= 0;
        i= pa - psys->particles;
 
-       LOOP_KEYS(k,key)
+       LOOP_KEYS(k, key)
                if(key->flag & PEK_SELECT)
                        return 1;
        
@@ -486,7 +444,7 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, int nearest)
                        key= edit->keys[i] + pa->totkey-1;
 
                        if(nearest) {
-                               if(key_inside_circle(data, key->world_co, &dist)) {
+                               if(key_inside_circle(data, dist, key->world_co, &dist)) {
                                        nearest_pa= i;
                                        nearest_key= pa->totkey-1;
                                }
@@ -502,7 +460,7 @@ static void for_mouse_hit_keys(PEData *data, ForKeyFunc func, int nearest)
                                if(key->flag & PEK_HIDE) continue;
 
                                if(nearest) {
-                                       if(key_inside_circle(data, key->world_co, &dist)) {
+                                       if(key_inside_circle(data, dist, key->world_co, &dist)) {
                                                nearest_pa= i;
                                                nearest_key= k;
                                        }
@@ -539,16 +497,16 @@ static void foreach_mouse_hit_particle(PEData *data, ForParticleFunc func, int s
                        key= psys->edit->keys[i] + pa->totkey-1;
 
                        if(selected==0 || key->flag & PEK_SELECT)
-                               if(key_inside_circle(data, key->world_co, &data->dist))
+                               if(key_inside_circle(data, data->rad, key->world_co, &data->dist))
                                        func(data, i);
                }
                else {
                        /* do all keys */
-                       LOOP_KEYS(k,key) {
+                       LOOP_KEYS(k, key) {
                                if(key->flag & PEK_HIDE) continue;
 
                                if(selected==0 || key->flag & PEK_SELECT) {
-                                       if(key_inside_circle(data, key->world_co, &data->dist)) {
+                                       if(key_inside_circle(data, data->rad, key->world_co, &data->dist)) {
                                                func(data, i);
                                                break;
                                        }
@@ -577,7 +535,7 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected
        Mat4One(imat);
        Mat4One(mat);
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, pa, mat);
@@ -588,16 +546,16 @@ static void foreach_mouse_hit_key(PEData *data, ForKeyMatFunc func, int selected
                        key= psys->edit->keys[i] + pa->totkey-1;
 
                        if(selected==0 || key->flag & PEK_SELECT)
-                               if(key_inside_circle(data, key->world_co, &data->dist))
+                               if(key_inside_circle(data, data->rad, key->world_co, &data->dist))
                                        func(data, mat, imat, i, pa->totkey-1);
                }
                else {
                        /* do all keys */
-                       LOOP_KEYS(k,key) {
+                       LOOP_KEYS(k, key) {
                                if(key->flag&PEK_HIDE) continue;
 
                                if(selected==0 || key->flag & PEK_SELECT)
-                                       if(key_inside_circle(data, key->world_co, &data->dist))
+                                       if(key_inside_circle(data, data->rad, key->world_co, &data->dist))
                                                func(data, mat, imat, i, k);
                        }
                }
@@ -612,7 +570,7 @@ static void foreach_selected_particle(PEData *data, ForParticleFunc func)
 
        totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa)
+       LOOP_PARTICLES(i, pa)
                if(particle_is_selected(psys, pa))
                        func(data, i);
 }
@@ -626,12 +584,12 @@ static void foreach_selected_key(PEData *data, ForKeyFunc func)
 
        totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                key= psys->edit->keys[i];
 
-               LOOP_KEYS(k,key)
+               LOOP_KEYS(k, key)
                        if(key->flag & PEK_SELECT)
                                func(data, i, k);
        }
@@ -656,7 +614,7 @@ static int count_selected_keys(Scene *scene, ParticleSystem *psys)
 
        totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                key= psys->edit->keys[i];
@@ -698,7 +656,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
        tree= BLI_kdtree_new(totpart);
 
        /* insert particles into kd tree */
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                psys_mat_hair_to_orco(ob, psmd->dm, psys->part->from, pa, mat);
                VECCOPY(co, pa->hair[0].co);
                Mat4MulVecfl(mat, co);
@@ -711,7 +669,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
        if(!edit->mirror_cache)
                edit->mirror_cache= MEM_callocN(sizeof(int)*totpart, "PE mirror cache");
        
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                psys_mat_hair_to_orco(ob, psmd->dm, psys->part->from, pa, mat);
                VECCOPY(co, pa->hair[0].co);
                Mat4MulVecfl(mat, co);
@@ -727,7 +685,7 @@ static void PE_update_mirror_cache(Object *ob, ParticleSystem *psys)
        }
 
        /* make sure mirrors are in two directions */
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(edit->mirror_cache[i]) {
                        index= edit->mirror_cache[i];
                        if(edit->mirror_cache[index] != i)
@@ -818,7 +776,7 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
 
        /* we delay settings the PARS_EDIT_RECALC for mirrored particles
         * to avoid doing mirror twice */
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_EDIT_RECALC) {
                        PE_mirror_particle(ob, psmd->dm, psys, pa, NULL);
 
@@ -827,7 +785,7 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
                }
        }
 
-       LOOP_PARTICLES(i,pa)
+       LOOP_PARTICLES(i, pa)
                if(pa->flag & PARS_EDIT_RECALC)
                        if(edit->mirror_cache[i] != -1)
                                psys->particles[edit->mirror_cache[i]].flag |= PARS_EDIT_RECALC;
@@ -856,21 +814,21 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, ParticleSystem *psys)
        if((pset->flag & PE_DEFLECT_EMITTER)==0)
                return;
 
-       edit=psys->edit;
-       totpart=psys->totpart;
+       edit= psys->edit;
+       totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(!(pa->flag & PARS_EDIT_RECALC))
                        continue;
                
                psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, pa, hairmat);
                
-               LOOP_KEYS(k,key) {
+               LOOP_KEYS(k, key) {
                        Mat4MulVecfl(hairmat, key->co);
                }
        //}
 
-       //LOOP_PARTICLES(i,pa) {
+       //LOOP_PARTICLES(i, pa) {
                key=psys->edit->keys[i]+1;
 
                dist_1st=VecLenf((key-1)->co,key->co);
@@ -904,11 +862,11 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, ParticleSystem *psys)
                }
        //}
 
-       //LOOP_PARTICLES(i,pa) {
+       //LOOP_PARTICLES(i, pa) {
                
                Mat4Invert(hairimat,hairmat);
 
-               LOOP_KEYS(k,key) {
+               LOOP_KEYS(k, key) {
                        Mat4MulVecfl(hairimat, key->co);
                }
        }
@@ -929,10 +887,10 @@ void PE_apply_lengths(Scene *scene, ParticleSystem *psys)
        if((pset->flag & PE_KEEP_LENGTHS)==0)
                return;
 
-       edit=psys->edit;
-       totpart=psys->totpart;
+       edit= psys->edit;
+       totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(!(pa->flag & PARS_EDIT_RECALC))
                        continue;
                
@@ -963,10 +921,10 @@ static void pe_iterate_lengths(Scene *scene, ParticleSystem *psys)
        if((pset->flag & PE_KEEP_LENGTHS)==0)
                return;
 
-       edit=psys->edit;
-       totpart=psys->totpart;
+       edit= psys->edit;
+       totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(!(pa->flag & PARS_EDIT_RECALC))
                        continue;
 
@@ -1018,36 +976,14 @@ static void recalc_lengths(ParticleSystem *psys)
 
        totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                key= psys->edit->keys[i];
                for(k=0; k<pa->totkey-1; k++, key++) {
                        key->length= VecLenf(key->co, (key + 1)->co);
                }
        }
 }
-/* calculate and store key locations in world coordinates */
-void PE_recalc_world_cos(Object *ob, ParticleSystem *psys)
-{
-       ParticleSystemModifierData *psmd= psys_get_modifier(ob, psys);
-       ParticleData *pa;
-       ParticleEditKey *key;
-       int i, k, totpart;
-       float hairmat[4][4];
 
-       if(psys==0)
-               return;
-
-       totpart= psys->totpart;
-
-       LOOP_PARTICLES(i,pa) {
-               psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat);
-
-               LOOP_KEYS(k,key) {
-                       VECCOPY(key->world_co,key->co);
-                       Mat4MulVecfl(hairmat, key->world_co);
-               }
-       }
-}
 /* calculate a tree for finding nearest emitter's vertice */
 static void recalc_emitter_field(Object *ob, ParticleSystem *psys)
 {
@@ -1107,7 +1043,7 @@ static void recalc_emitter_field(Object *ob, ParticleSystem *psys)
        BLI_kdtree_balance(edit->emitter_field);
 }
 
-void PE_update_selection(Scene *scene, Object *ob, int useflag)
+static void PE_update_selection(Scene *scene, Object *ob, int useflag)
 {
        ParticleSystem *psys= PE_get_current(scene, ob);
        ParticleEdit *edit= psys->edit;
@@ -1123,12 +1059,12 @@ void PE_update_selection(Scene *scene, Object *ob, int useflag)
 
        /* flag all particles to be updated if not using flag */
        if(!useflag)
-               LOOP_PARTICLES(i,pa)
+               LOOP_PARTICLES(i, pa)
                        pa->flag |= PARS_EDIT_RECALC;
 
        /* flush edit key flag to hair key flag to preserve selection 
         * on save */
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                key= edit->keys[i];
 
                for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++)
@@ -1141,7 +1077,7 @@ void PE_update_selection(Scene *scene, Object *ob, int useflag)
                psys_cache_child_paths(scene, ob, psys, cfra, 1);
 
        /* disable update flag */
-       LOOP_PARTICLES(i,pa)
+       LOOP_PARTICLES(i, pa)
                pa->flag &= ~PARS_EDIT_RECALC;
 }
 
@@ -1156,7 +1092,7 @@ void PE_update_object(Scene *scene, Object *ob, int useflag)
 
        /* flag all particles to be updated if not using flag */
        if(!useflag)
-               LOOP_PARTICLES(i,pa)
+               LOOP_PARTICLES(i, pa)
                        pa->flag |= PARS_EDIT_RECALC;
 
        /* do post process on particle edit keys */
@@ -1165,7 +1101,7 @@ void PE_update_object(Scene *scene, Object *ob, int useflag)
        PE_apply_lengths(scene, psys);
        if(pset->flag & PE_X_MIRROR)
                PE_apply_mirror(ob,psys);
-       PE_recalc_world_cos(ob,psys);
+       psys_update_world_cos(ob,psys);
        PE_hide_keys_time(scene, psys, cfra);
 
        /* regenerate path caches */
@@ -1175,121 +1111,10 @@ void PE_update_object(Scene *scene, Object *ob, int useflag)
                psys_cache_child_paths(scene, ob, psys, cfra, 1);
 
        /* disable update flag */
-       LOOP_PARTICLES(i,pa)
+       LOOP_PARTICLES(i, pa)
                pa->flag &= ~PARS_EDIT_RECALC;
 }
 
-/************************ particle edit toggle operator ************************/
-
-/* initialize needed data for bake edit */
-void PE_create_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys)
-{
-       ParticleEdit *edit=psys->edit;
-       ParticleData *pa;
-       ParticleEditKey *key;
-       HairKey *hkey;
-       int i, k, totpart=psys->totpart, alloc=1;
-
-       if((psys->flag & PSYS_EDITED)==0)
-               return;
-
-       if(edit) {
-               int newtotkeys= psys_count_keys(psys);
-               if(newtotkeys == edit->totkeys)
-                       alloc=0;
-       }
-
-       if(alloc) {
-               if(edit) {
-                       error("ParticleEdit exists allready! Poke jahka!");
-                       PE_free_particle_edit(psys);
-               }
-
-               edit=psys->edit=MEM_callocN(sizeof(ParticleEdit), "PE_create_particle_edit");
-
-               edit->keys=MEM_callocN(totpart*sizeof(ParticleEditKey*),"ParticleEditKey array");
-
-               LOOP_PARTICLES(i,pa) {
-                       key= edit->keys[i]= MEM_callocN(pa->totkey*sizeof(ParticleEditKey),"ParticleEditKeys");
-                       for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++) {
-                               key->co= hkey->co;
-                               key->time= &hkey->time;
-                               key->flag= hkey->editflag;
-                       }
-               }
-
-               edit->totkeys= psys_count_keys(psys);
-       }
-
-       recalc_lengths(psys);
-       recalc_emitter_field(ob, psys);
-       PE_recalc_world_cos(ob, psys);
-
-       if(alloc) {
-               ParticleUndo_clear(psys);
-               PE_undo_push(scene, "Original");
-       }
-}
-
-static int particle_edit_toggle_poll(bContext *C)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-
-       if(!scene || !ob || ob->id.lib)
-               return 0;
-       
-       return (ob->particlesystem.first != NULL);
-}
-
-static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
-{
-       Scene *scene= CTX_data_scene(C);
-       Object *ob= CTX_data_active_object(C);
-       ParticleSystem *psys= PE_get_current(scene, ob);
-       
-       if(psys==NULL) {
-               psys= ob->particlesystem.first;
-               psys->flag |= PSYS_CURRENT;
-       }
-
-       if(!(G.f & G_PARTICLEEDIT)) {
-               if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) {
-                       if(psys_check_enabled(ob, psys)) {
-                               if(psys->edit==NULL)
-                                       PE_create_particle_edit(scene, ob, psys);
-
-                               PE_recalc_world_cos(ob, psys);
-                       }
-               }
-
-               G.f |= G_PARTICLEEDIT;
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
-       }
-       else {
-               G.f &= ~G_PARTICLEEDIT;
-               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
-       }
-
-       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-
-       return OPERATOR_FINISHED;
-}
-
-void PARTICLE_OT_particle_edit_toggle(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Particle Edit Toggle";
-       ot->idname= "PARTICLE_OT_particle_edit_toggle";
-       
-       /* api callbacks */
-       ot->exec= particle_edit_toggle_exec;
-       ot->poll= particle_edit_toggle_poll;
-
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
 /************************************************/
 /*                     Edit Selections                                         */
 /************************************************/
@@ -1355,9 +1180,9 @@ static int de_select_all_exec(bContext *C, wmOperator *op)
        edit= psys->edit;
        totpart= psys->totpart;
        
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
-               LOOP_KEYS(k,key) {
+               LOOP_KEYS(k, key) {
                        if(key->flag & PEK_SELECT) {
                                sel= 1;
                                key->flag &= ~PEK_SELECT;
@@ -1367,9 +1192,9 @@ static int de_select_all_exec(bContext *C, wmOperator *op)
        }
 
        if(sel==0) {
-               LOOP_PARTICLES(i,pa) {
+               LOOP_PARTICLES(i, pa) {
                        if(pa->flag & PARS_HIDE) continue;
-                       LOOP_KEYS(k,key) {
+                       LOOP_KEYS(k, key) {
                                if(!(key->flag & PEK_SELECT)) {
                                        key->flag |= PEK_SELECT;
                                        pa->flag |= PARS_EDIT_RECALC;
@@ -1400,9 +1225,8 @@ void PARTICLE_OT_de_select_all(wmOperatorType *ot)
 
 /************************ pick select operator ************************/
 
-void PE_mouse_particles(void)
+int PE_mouse_particles(bContext *C, short *mval, int extend)
 {
-       bContext *C= NULL; // XXX
        PEData data;
        Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
@@ -1410,33 +1234,25 @@ void PE_mouse_particles(void)
        ParticleEdit *edit= 0;
        ParticleData *pa;
        ParticleEditKey *key;
-       short mval[2];
        int i, k, totpart;
-       int shift= 0; // XXX
        
-       if(!PE_can_edit(psys)) return;
+       if(!PE_can_edit(psys))
+               return OPERATOR_CANCELLED;
 
        edit= psys->edit;
-
        totpart= psys->totpart;
 
-       bglFlush();
-       glReadBuffer(GL_BACK);
-       glDrawBuffer(GL_BACK);
-//     persp(PERSP_VIEW);
-
-       if(shift)
-               LOOP_PARTICLES(i,pa) {
+       if(!extend) {
+               LOOP_PARTICLES(i, pa) {
                        if(pa->flag & PARS_HIDE) continue;
-                       LOOP_KEYS(k,key) {
+                       LOOP_KEYS(k, key) {
                                if(key->flag & PEK_SELECT) {
                                        key->flag &= ~PEK_SELECT;
                                        pa->flag |= PARS_EDIT_RECALC;
                                }
                        }
                }
-       
-       // XXX mval
+       }
 
        PE_set_view3d_data(C, &data);
        data.mval= mval;
@@ -1445,7 +1261,9 @@ void PE_mouse_particles(void)
        for_mouse_hit_keys(&data, toggle_key_select, 1);  /* nearest only */
 
        PE_update_selection(scene, ob, 1);
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, data.ob);
 
+       return OPERATOR_FINISHED;
 }
 
 /************************ select first operator ************************/
@@ -1530,6 +1348,8 @@ static int select_linked_exec(bContext *C, wmOperator *op)
        mval[0]= location[0];
        mval[1]= location[1];
 
+       view3d_operator_needs_opengl(C);
+
        PE_set_view3d_data(C, &data);
        data.mval= mval;
        data.rad=75.0f;
@@ -1575,64 +1395,60 @@ void PARTICLE_OT_select_linked(wmOperatorType *ot)
 
 /************************ border select operator ************************/
 
-void PE_border_select(ViewContext *vc, rcti *rect, int select)
+int PE_border_select(bContext *C, rcti *rect, int select)
 {
-       Scene *scene= vc->scene;
-       Object *ob= vc->obact;
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
        ParticleSystem *psys= PE_get_current(scene, ob);
        PEData data;
 
-       if(!PE_can_edit(psys)) return;
+       if(!PE_can_edit(psys))
+               return OPERATOR_CANCELLED;
 
-       memset(&data, 0, sizeof(data));
-       data.vc= *vc;
-       data.scene= scene;
-       data.ob= ob;
-       data.psys= psys;
+       PE_set_view3d_data(C, &data);
        data.rect= rect;
        data.select= select;
 
        for_mouse_hit_keys(&data, select_key, 0);
 
        PE_update_selection(scene, ob, 1);
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob);
 
-       /* XXX undo, notifier */
-       PE_undo_push(scene, "Border Select");
+       return OPERATOR_FINISHED;
 }
 
 /************************ circle select operator ************************/
 
-void PE_circle_select(ViewContext *vc, int selecting, short *mval, float rad)
+int PE_circle_select(bContext *C, int selecting, short *mval, float rad)
 {
-       Scene *scene= vc->scene;
-       Object *ob= vc->obact;
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
        ParticleSystem *psys= PE_get_current(scene, ob);
        PEData data;
 
-       if(!PE_can_edit(psys)) return;
+       if(!PE_can_edit(psys))
+               return OPERATOR_FINISHED;
 
-       memset(&data, 0, sizeof(data));
-       data.vc= *vc;
-       data.scene= scene;
-       data.ob= ob;
-       data.psys= psys;
-       data.mval=mval;
-       data.rad=rad;
+       PE_set_view3d_data(C, &data);
+       data.mval= mval;
+       data.rad= rad;
        data.select= selecting;
 
        for_mouse_hit_keys(&data, select_key, 0);
 
-       /* XXX undo, notifier */
-       PE_undo_push(scene, "Circle Select");
+       PE_update_selection(scene, ob, 1);
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob);
+
+       return OPERATOR_FINISHED;
 }
 
 /************************ lasso select operator ************************/
 
-void PE_lasso_select(ViewContext *vc, short mcords[][2], short moves, short select)
+int PE_lasso_select(bContext *C, short mcords[][2], short moves, short select)
 {
-       Scene *scene= vc->scene;
-       ARegion *ar= vc->ar;
-       Object *ob= OBACT;
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       ARegion *ar= CTX_wm_region(C);
        ParticleSystem *psys= PE_get_current(scene, ob);
        ParticleSystemModifierData *psmd;
        ParticleEdit *edit;
@@ -1642,19 +1458,20 @@ void PE_lasso_select(ViewContext *vc, short mcords[][2], short moves, short sele
        short vertco[2];
        int i, k, totpart;
 
-       if(!PE_can_edit(psys)) return;
+       if(!PE_can_edit(psys))
+               return OPERATOR_CANCELLED;
 
        psmd= psys_get_modifier(ob, psys);
-       edit=psys->edit;
-       totpart=psys->totpart;
+       edit= psys->edit;
+       totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, mat);
 
                if(scene->selectmode==SCE_SELECT_POINT) {
-                       LOOP_KEYS(k,key) {
+                       LOOP_KEYS(k, key) {
                                VECCOPY(co, key->co);
                                Mat4MulVecfl(mat, co);
                                project_short(ar, co, vertco);
@@ -1690,9 +1507,9 @@ void PE_lasso_select(ViewContext *vc, short mcords[][2], short moves, short sele
        }
 
        PE_update_selection(scene, ob, 1);
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, ob);
 
-       /* XXX undo, notifier */
-       PE_undo_push(scene, "Lasso select particles");
+       return OPERATOR_FINISHED;
 }
 
 /*************************** hide operator **************************/
@@ -2071,7 +1888,7 @@ static int remove_tagged_particles(Scene *scene, Object *ob, ParticleSystem *psy
                psmd= psys_get_modifier(ob, psys);
                totpart= psys->totpart;
 
-               LOOP_PARTICLES(i,pa)
+               LOOP_PARTICLES(i, pa)
                        if(pa->flag & PARS_TAG)
                                PE_mirror_particle(ob, psmd->dm, psys, pa, NULL);
        }
@@ -2140,7 +1957,7 @@ static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys)
                /* mirror key tags */
                psmd= psys_get_modifier(ob, psys);
 
-               LOOP_PARTICLES(i,pa) {
+               LOOP_PARTICLES(i, pa) {
                        LOOP_KEYS(k,ekey) {
                                if(ekey->flag & PEK_TAG) {
                                        PE_mirror_particle(ob, psmd->dm, psys, pa, NULL);
@@ -2150,7 +1967,7 @@ static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys)
                }
        }
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                new_totkey= pa->totkey;
                LOOP_KEYS(k,ekey) {
                        if(ekey->flag & PEK_TAG)
@@ -2164,7 +1981,7 @@ static void remove_tagged_keys(Scene *scene, Object *ob, ParticleSystem *psys)
 
        totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                new_totkey= pa->totkey;
                LOOP_KEYS(k,ekey) {
                        if(ekey->flag & PEK_TAG)
@@ -2293,7 +2110,7 @@ static int subdivide_exec(bContext *C, wmOperator *op)
        data.psys->edit->totkeys= psys_count_keys(data.psys);
        
        recalc_lengths(data.psys);
-       PE_recalc_world_cos(data.ob, data.psys);
+       psys_update_world_cos(data.ob, data.psys);
 
        PE_update_object(data.scene, data.ob, 1);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, data.ob);
@@ -2342,7 +2159,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op)
                tree=BLI_kdtree_new(totpart);
                        
                /* insert particles into kd tree */
-               LOOP_PARTICLES(i,pa) {
+               LOOP_PARTICLES(i, pa) {
                        if(particle_is_selected(psys, pa)) {
                                psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, pa, mat);
                                VECCOPY(co, pa->hair[0].co);
@@ -2354,7 +2171,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op)
                BLI_kdtree_balance(tree);
 
                /* tag particles to be removed */
-               LOOP_PARTICLES(i,pa) {
+               LOOP_PARTICLES(i, pa) {
                        if(particle_is_selected(psys, pa)) {
                                psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, pa, mat);
                                VECCOPY(co, pa->hair[0].co);
@@ -2389,7 +2206,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op)
 
        BKE_reportf(op->reports, RPT_INFO, "Remove %d double particles.", totremoved);
 
-       PE_recalc_world_cos(ob, psys);
+       psys_update_world_cos(ob, psys);
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob);
 
@@ -2413,47 +2230,119 @@ void PARTICLE_OT_remove_doubles(wmOperatorType *ot)
        RNA_def_float(ot->srna, "threshold", 0.0002f, 0.0f, FLT_MAX, "Threshold", "Threshold distance withing which particles are removed", 0.00001f, 0.1f);
 }
 
-/********************* radial control operator *********************/
+/************************ cursor drawing *******************************/
 
-/* XXX static */
-void PE_radialcontrol_callback(const int mode, const int val)
+static void brush_drawcursor(bContext *C, int x, int y, void *customdata)
 {
-       ParticleEditSettings *pset= NULL; // XXX PE_settings(scene);
+       ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
+       ParticleBrushData *brush;
+
+       if(pset->brushtype < 0)
+               return;
 
-       if(pset->brushtype>=0) {
-               ParticleBrushData *brush= &pset->brush[pset->brushtype];
+       brush= &pset->brush[pset->brushtype];
 
-               if(mode == RADIALCONTROL_SIZE)
-                       brush->size= val;
-               else if(mode == RADIALCONTROL_STRENGTH)
-                       brush->strength= val;
+       if(brush) {
+               glPushMatrix();
+
+               glTranslatef((float)x, (float)y, 0.0f);
+
+               glColor4ub(255, 255, 255, 128);
+               glEnable(GL_LINE_SMOOTH );
+               glEnable(GL_BLEND);
+               glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40);
+               glDisable(GL_BLEND);
+               glDisable(GL_LINE_SMOOTH );
+               
+               glPopMatrix();
        }
+}
 
-       (*PE_radialcontrol())= NULL;
+static void toggle_particle_cursor(bContext *C, int enable)
+{
+       ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
+
+       if(pset->paintcursor && !enable) {
+               WM_paint_cursor_end(CTX_wm_manager(C), pset->paintcursor);
+               pset->paintcursor = NULL;
+       }
+       else if(enable)
+               pset->paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), PE_poll, brush_drawcursor, NULL);
 }
 
-struct RadialControl **PE_radialcontrol(void)
+/********************* radial control operator *********************/
+
+static int brush_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       static struct RadialControl *rc= NULL;
-       return &rc;
+       ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
+       ParticleBrushData *brush;
+       int mode = RNA_enum_get(op->ptr, "mode");
+       float original_value;
+
+       if(pset->brushtype < 0)
+               return OPERATOR_CANCELLED;
+
+       brush= &pset->brush[pset->brushtype];
+
+       toggle_particle_cursor(C, 0);
+
+       if(mode == WM_RADIALCONTROL_SIZE)
+               original_value = brush->size;
+       else if(mode == WM_RADIALCONTROL_STRENGTH)
+               original_value = brush->strength;
+
+       RNA_float_set(op->ptr, "initial_value", original_value);
+
+       return WM_radial_control_invoke(C, op, event);
 }
 
-void PE_radialcontrol_start(const int mode)
+static int brush_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
-       ParticleEditSettings *pset= NULL; // XXX PE_settings(scene);
-       int orig= 1;
+       int ret = WM_radial_control_modal(C, op, event);
 
-       if(pset->brushtype>=0) {
-               ParticleBrushData *brush= &pset->brush[pset->brushtype];
-               
-               if(mode == RADIALCONTROL_SIZE)
-                       orig= brush->size;
-               else if(mode == RADIALCONTROL_STRENGTH)
-                       orig= brush->strength;
-               
-//             if(mode != RADIALCONTROL_NONE)
-//                     (*PE_radialcontrol())= radialcontrol_start(mode, PE_radialcontrol_callback, orig, 100, 0);
-       }
+       if(ret != OPERATOR_RUNNING_MODAL)
+               toggle_particle_cursor(C, 1);
+
+       return ret;
+}
+
+static int brush_radial_control_exec(bContext *C, wmOperator *op)
+{
+       ParticleEditSettings *pset= PE_settings(CTX_data_scene(C));
+       ParticleBrushData *brush;
+       int mode = RNA_enum_get(op->ptr, "mode");
+       float new_value = RNA_float_get(op->ptr, "new_value");
+       char str[256];
+
+       if(pset->brushtype < 0)
+               return OPERATOR_CANCELLED;
+
+       brush= &pset->brush[pset->brushtype];
+
+       if(mode == WM_RADIALCONTROL_SIZE)
+               brush->size= new_value;
+       else if(mode == WM_RADIALCONTROL_STRENGTH)
+               brush->strength= new_value;
+
+       WM_radial_control_string(op, str, 256);
+
+       return OPERATOR_FINISHED;
+}
+
+void PARTICLE_OT_brush_radial_control(wmOperatorType *ot)
+{
+       WM_OT_radial_control_partial(ot);
+
+       ot->name= "Brush Radial Control";
+       ot->idname= "PARTICLE_OT_brush_radial_control";
+
+       ot->invoke= brush_radial_control_invoke;
+       ot->modal= brush_radial_control_modal;
+       ot->exec= brush_radial_control_exec;
+       ot->poll= PE_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 /*************************** delete operator **************************/
@@ -2538,14 +2427,14 @@ static void PE_mirror_x(Scene *scene, Object *ob, int tagged)
        edit= psys->edit;
        psmd= psys_get_modifier(ob, psys);
 
-       mirrorfaces= mesh_get_x_mirror_faces(ob);
+       mirrorfaces= mesh_get_x_mirror_faces(ob, NULL);
 
        if(!edit->mirror_cache)
                PE_update_mirror_cache(ob, psys);
 
        totpart= psys->totpart;
        newtotpart= psys->totpart;
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                if(!tagged) {
@@ -2650,7 +2539,7 @@ static int mirror_exec(bContext *C, wmOperator *op)
        
        PE_mirror_x(scene, ob, 0);
 
-       PE_recalc_world_cos(ob, psys);
+       psys_update_world_cos(ob, psys);
        WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob);
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
 
@@ -3162,7 +3051,6 @@ static int brush_edit_init(bContext *C, wmOperator *op)
        if(pset->brushtype < 0)
                return 0;
 
-       // XXX
        initgrabz(ar->regiondata, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]);
 
        bedit= MEM_callocN(sizeof(BrushEdit), "BrushEdit");
@@ -3193,10 +3081,10 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
        RNA_int_get_array(itemptr, "mouse", mouse);
        flip= RNA_boolean_get(itemptr, "flip");
 
-       bglFlush();
-       glReadBuffer(GL_BACK);
-       glDrawBuffer(GL_BACK);
-//             persp(PERSP_VIEW);
+       if(bedit->first) {
+               bedit->lastmouse[0]= mouse[0];
+               bedit->lastmouse[1]= mouse[1];
+       }
 
        dx= mouse[0] - bedit->lastmouse[0];
        dy= mouse[1] - bedit->lastmouse[1];
@@ -3211,6 +3099,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
                (sqrt(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0))
                || bedit->first) {
 
+               view3d_operator_needs_opengl(C);
                selected= (short)count_selected_keys(scene, psys);
 
                switch(pset->brushtype) {
@@ -3359,7 +3248,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
                        if(pset->brushtype == PE_BRUSH_ADD && (pset->flag & PE_X_MIRROR))
                                PE_mirror_x(scene, ob, 1);
 
-                       PE_recalc_world_cos(ob,psys);
+                       psys_update_world_cos(ob,psys);
                        psys_free_path_cache(psys);
                        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
                }
@@ -3518,7 +3407,7 @@ static void get_ParticleUndo(ParticleSystem *psys, ParticleUndo *undo)
        HairKey *hkey;
        int i, k, totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->hair)
                        MEM_freeN(pa->hair);
 
@@ -3600,14 +3489,14 @@ void PE_undo_step(Scene *scene, int step)
        ParticleEdit *edit= 0;
 
        if(!PE_can_edit(psys)) return;
-       edit=psys->edit;
+       edit= psys->edit;
 
        if(step==0) {
                get_ParticleUndo(psys,edit->curundo);
        }
        else if(step==1) {
                
-               if(edit->curundo==NULL || edit->curundo->prev==NULL) error("No more steps to undo");
+               if(edit->curundo==NULL || edit->curundo->prev==NULL);
                else {
                        if(G.f & G_DEBUG) printf("undo %s\n", edit->curundo->name);
                        edit->curundo= edit->curundo->prev;
@@ -3617,7 +3506,7 @@ void PE_undo_step(Scene *scene, int step)
        else {
                /* curundo has to remain current situation! */
                
-               if(edit->curundo==NULL || edit->curundo->next==NULL) error("No more steps to redo");
+               if(edit->curundo==NULL || edit->curundo->next==NULL);
                else {
                        get_ParticleUndo(psys, edit->curundo->next);
                        edit->curundo= edit->curundo->next;
@@ -3702,12 +3591,6 @@ void PE_undo_menu(Scene *scene, Object *ob)
 
 /************************ utilities ******************************/
 
-void PE_get_colors(char sel[4], char nosel[4])
-{
-       UI_GetThemeColor3ubv(TH_EDGE_SELECT, sel);
-       UI_GetThemeColor3ubv(TH_WIRE, nosel);
-}
-
 int PE_minmax(Scene *scene, float *min, float *max)
 {
        Object *ob= OBACT;
@@ -3723,12 +3606,12 @@ int PE_minmax(Scene *scene, float *min, float *max)
        psmd= psys_get_modifier(ob, psys);
        totpart= psys->totpart;
 
-       LOOP_PARTICLES(i,pa) {
+       LOOP_PARTICLES(i, pa) {
                if(pa->flag & PARS_HIDE) continue;
 
                psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, mat);
 
-               LOOP_KEYS(k,key) {
+               LOOP_KEYS(k, key) {
                        if(key->flag & PEK_SELECT) {
                                VECCOPY(co, key->co);
                                Mat4MulVecfl(mat, co);
@@ -3746,6 +3629,214 @@ int PE_minmax(Scene *scene, float *min, float *max)
        return ok;
 }
 
+/************************ particle edit toggle operator ************************/
+
+/* initialize needed data for bake edit */
+static void PE_create_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys)
+{
+       ParticleEdit *edit= psys->edit;
+       ParticleData *pa;
+       ParticleEditKey *key;
+       HairKey *hkey;
+       int i, k, totpart= psys->totpart, alloc=1;
+
+       if((psys->flag & PSYS_EDITED)==0)
+               return;
+
+       if(edit) {
+               int newtotkeys= psys_count_keys(psys);
+
+               if(newtotkeys == edit->totkeys)
+                       alloc=0;
+       }
+
+       if(alloc) {
+               if(edit) {
+                       printf("ParticleEdit exists already! Poke jahka!");
+                       PE_free_particle_edit(psys);
+               }
+
+               edit= psys->edit=MEM_callocN(sizeof(ParticleEdit), "PE_create_particle_edit");
+               psys->free_edit= PE_free_particle_edit;
+
+               edit->keys=MEM_callocN(totpart*sizeof(ParticleEditKey*),"ParticleEditKey array");
+
+               LOOP_PARTICLES(i, pa) {
+                       key= edit->keys[i]= MEM_callocN(pa->totkey*sizeof(ParticleEditKey),"ParticleEditKeys");
+                       for(k=0, hkey=pa->hair; k<pa->totkey; k++, hkey++, key++) {
+                               key->co= hkey->co;
+                               key->time= &hkey->time;
+                               key->flag= hkey->editflag;
+                       }
+               }
+
+               edit->totkeys= psys_count_keys(psys);
+
+               UI_GetThemeColor3ubv(TH_EDGE_SELECT, edit->sel_col);
+               UI_GetThemeColor3ubv(TH_WIRE, edit->nosel_col);
+       }
+
+       recalc_lengths(psys);
+       recalc_emitter_field(ob, psys);
+       psys_update_world_cos(ob, psys);
+
+       if(alloc) {
+               ParticleUndo_clear(psys);
+               PE_undo_push(scene, "Original");
+       }
+}
+
+static int particle_edit_toggle_poll(bContext *C)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+
+       if(!scene || !ob || ob->id.lib)
+               return 0;
+       
+       return (ob->particlesystem.first != NULL);
+}
+
+static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       ParticleSystem *psys= PE_get_current(scene, ob);
+       
+       if(psys==NULL) {
+               psys= ob->particlesystem.first;
+               psys->flag |= PSYS_CURRENT;
+       }
+
+       if(!(G.f & G_PARTICLEEDIT)) {
+               if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) {
+                       if(psys_check_enabled(ob, psys)) {
+                               if(psys->edit==NULL)
+                                       PE_create_particle_edit(scene, ob, psys);
+
+                               psys_update_world_cos(ob, psys);
+                       }
+               }
+
+               G.f |= G_PARTICLEEDIT;
+               toggle_particle_cursor(C, 1);
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, NULL);
+       }
+       else {
+               G.f &= ~G_PARTICLEEDIT;
+               toggle_particle_cursor(C, 0);
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
+       }
+
+       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+
+       return OPERATOR_FINISHED;
+}
+
+void PARTICLE_OT_particle_edit_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Particle Edit Toggle";
+       ot->idname= "PARTICLE_OT_particle_edit_toggle";
+       
+       /* api callbacks */
+       ot->exec= particle_edit_toggle_exec;
+       ot->poll= particle_edit_toggle_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+
+/************************ set editable operator ************************/
+
+static int set_editable_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       ParticleSystem *psys= PE_get_current(scene, ob);
+       
+       if(psys->flag & PSYS_EDITED) {
+               if(1) { // XXX okee("Lose changes done in particle mode?")) {
+                       if(psys->edit)
+                               PE_free_particle_edit(psys);
+
+                       psys->flag &= ~PSYS_EDITED;
+                       psys->recalc |= PSYS_RECALC_HAIR;
+
+                       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+               }
+       }
+       else {
+               if(psys_check_enabled(ob, psys)) {
+                       psys->flag |= PSYS_EDITED;
+
+                       if(G.f & G_PARTICLEEDIT)
+                               PE_create_particle_edit(scene, ob, psys);
+               }
+               else
+                       BKE_report(op->reports, RPT_ERROR, "Particle system not enabled, skipping set editable");
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+void PARTICLE_OT_set_editable(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Set Editable";
+       ot->idname= "PARTICLE_OT_set_editable";
+       
+       /* api callbacks */
+       ot->exec= set_editable_exec;
+       ot->poll= particle_edit_toggle_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/*********************** change active **************************/
+
+void PE_change_act(void *ob_v, void *act_v)
+{
+       Scene *scene= NULL; // XXX
+       Object *ob= ob_v;
+       ParticleSystem *psys;
+       short act= *((short*)act_v) - 1;
+
+       if((psys=psys_get_current(ob)))
+               psys->flag &= ~PSYS_CURRENT;
+
+       if(act>=0) {
+               if((psys=BLI_findlink(&ob->particlesystem,act))) {
+                       psys->flag |= PSYS_CURRENT;
+
+                       if(psys_check_enabled(ob, psys)) {
+                               if(G.f & G_PARTICLEEDIT && !psys->edit)
+                                       PE_create_particle_edit(scene, ob, psys);
+                               psys_update_world_cos(ob, psys);
+                       }
+               }
+       }
+}
+
+void PE_change_act_psys(Scene *scene, Object *ob, ParticleSystem *psys)
+{
+       ParticleSystem *p;
+       
+       if((p=psys_get_current(ob)))
+               p->flag &= ~PSYS_CURRENT;
+       
+       psys->flag |= PSYS_CURRENT;
+       
+       if(psys_check_enabled(ob, psys)) {
+               if(G.f & G_PARTICLEEDIT && !psys->edit)
+                       PE_create_particle_edit(scene, ob, psys);
+
+               psys_update_world_cos(ob, psys);
+       }
+}
+
 /*********************** specials menu **************************/
 
 static int specials_menu_invoke(bContext *C, wmOperator *op, wmEvent *event)
@@ -3801,10 +3892,12 @@ void ED_operatortypes_particle(void)
 
        WM_operatortype_append(PARTICLE_OT_set_brush);
        WM_operatortype_append(PARTICLE_OT_brush_edit);
+       WM_operatortype_append(PARTICLE_OT_brush_radial_control);
 
        WM_operatortype_append(PARTICLE_OT_specials_menu);
 
        WM_operatortype_append(PARTICLE_OT_particle_edit_toggle);
+       WM_operatortype_append(PARTICLE_OT_set_editable);
 }
 
 void ED_keymap_particle(wmWindowManager *wm)
@@ -3826,6 +3919,8 @@ void ED_keymap_particle(wmWindowManager *wm)
 
        WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
+       RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_brush_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
+       RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_brush_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
 
        WM_keymap_add_item(keymap, "PARTICLE_OT_specials_menu", WKEY, KM_PRESS, 0, 0);
 }
index 998e346836f2fb3948e4b22fd8d6f43056d47852..fd6719d63bb025f3fb0573113ccffd67b97060ad 100644 (file)
@@ -5136,7 +5136,8 @@ void PAINT_OT_texture_paint_toggle(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-/* ************ texture paint radial control *************/
+/************* texture paint radial control *************/
+
 static int texture_paint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        ToolSettings *ts = CTX_data_scene(C)->toolsettings;
@@ -5178,3 +5179,4 @@ void PAINT_OT_texture_paint_radial_control(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
+
index 1623c7feef1619147a732b0d819e05d1964f89d5..a9860402f74858f6e3063c65aeea8d454e4c52ef 100644 (file)
@@ -1890,7 +1890,6 @@ static int vpaint_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
 void PAINT_OT_vertex_paint(wmOperatorType *ot)
 {
-       
        /* identifiers */
        ot->name= "Vertex Paint";
        ot->idname= "PAINT_OT_vertex_paint";
@@ -1903,6 +1902,5 @@ void PAINT_OT_vertex_paint(wmOperatorType *ot)
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
 }
 
index 706ce8c9d400e8c7dce16af4ab02e5dc265c192b..80728a772441e935f50aa1793075813324fb93af 100644 (file)
@@ -1082,6 +1082,7 @@ void backdrawview3d(Scene *scene, ARegion *ar, View3D *v3d)
 
        if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT);
        else if((G.f & G_TEXTUREPAINT) && scene->toolsettings && (scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_DISABLE));
+       else if((G.f & G_PARTICLEEDIT) && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT));
        else if(scene->obedit && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT));
        else {
                v3d->flag &= ~V3D_NEEDBACKBUFDRAW;
@@ -2090,6 +2091,12 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                v3d->flag |= V3D_NEEDBACKBUFDRAW;
                // XXX addafterqueue(ar->win, BACKBUFDRAW, 1);
        }
+
+       if((G.f & G_PARTICLEEDIT) && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) {
+               v3d->flag |= V3D_NEEDBACKBUFDRAW;
+               // XXX addafterqueue(ar->win, BACKBUFDRAW, 1);
+       }
+
        // test for backbuf select
        if(scene->obedit && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) {
                
index f4525b97128a341297cefcfada3b7b83948b25d1..b6098e52a892f3be32938f9266ef611e97d8e722 100644 (file)
@@ -689,7 +689,7 @@ static void do_lasso_select_node(short mcords[][2], short moves, short select)
 }
 #endif
 
-void view3d_lasso_select(ViewContext *vc, short mcords[][2], short moves, short select)
+void view3d_lasso_select(bContext *C, ViewContext *vc, short mcords[][2], short moves, short select)
 {
        if(vc->obedit==NULL) {
                if(FACESEL_PAINT_TEST)
@@ -697,7 +697,7 @@ void view3d_lasso_select(ViewContext *vc, short mcords[][2], short moves, short
                else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT))
                        ;
                else if(G.f & G_PARTICLEEDIT)
-                       PE_lasso_select(vc, mcords, moves, select);
+                       PE_lasso_select(C, mcords, moves, select);
                else  
                        do_lasso_select_objects(vc, mcords, moves, select);
        }
@@ -747,7 +747,7 @@ static int view3d_lasso_select_exec(bContext *C, wmOperator *op)
                view3d_set_viewcontext(C, &vc);
                
                select= RNA_enum_is_equal(op->ptr, "type", "SELECT");
-               view3d_lasso_select(&vc, mcords, i, select);
+               view3d_lasso_select(C, &vc, mcords, i, select);
                
                return OPERATOR_FINISHED;
        }
@@ -1349,8 +1349,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
                return OPERATOR_FINISHED;
        }
        else if(obedit==NULL && (G.f & G_PARTICLEEDIT)) {
-               PE_border_select(&vc, &rect, (val==LEFTMOUSE));
-               return OPERATOR_FINISHED;
+               return PE_border_select(C, &rect, (val==LEFTMOUSE));
        }
        
        if(obedit) {
@@ -1580,6 +1579,8 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        mouse_nurb(C, event->mval, extend);
                        
        }
+       else if(G.f & G_PARTICLEEDIT)
+               PE_mouse_particles(C, event->mval, extend);
        else 
                mouse_select(C, event->mval, extend, 0);
 
@@ -1799,7 +1800,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
                if(CTX_data_edit_object(C))
                        obedit_circle_select(&vc, selecting, mval, (float)radius);
                else
-                       PE_circle_select(&vc, selecting, mval, (float)radius);
+                       return PE_circle_select(C, selecting, mval, (float)radius);
        }
        else {
                Base *base;
index 641b538a3ed45d843e0b52513b41fea9ecfa66c6..3b2c1bfe4954fbd766e6ecab8a415ee29620a56f 100644 (file)
@@ -1601,13 +1601,11 @@ static void createTransLatticeVerts(bContext *C, TransInfo *t)
 /* ******************* particle edit **************** */
 static void createTransParticleVerts(bContext *C, TransInfo *t)
 {
-       // TRANSFORM_FIX_ME
-#if 0
        TransData *td = NULL;
        TransDataExtension *tx;
-       Base *base = BASACT;
-       Object *ob = OBACT;
-       ParticleSystem *psys = PE_get_current(ob);
+       Base *base = CTX_data_active_base(C);
+       Object *ob = CTX_data_active_object(C);
+       ParticleSystem *psys = PE_get_current(t->scene, ob);
        ParticleSystemModifierData *psmd = NULL;
        ParticleEditSettings *pset = PE_settings(t->scene);
        ParticleData *pa = NULL;
@@ -1715,15 +1713,13 @@ static void createTransParticleVerts(bContext *C, TransInfo *t)
                if (propmode && head != tail)
                        calc_distanceCurveVerts(head, tail - 1);
        }
-#endif
 }
 
 void flushTransParticles(TransInfo *t)
 {
-#if 0 // TRANSFORM_FIX_ME
        Scene *scene = t->scene;
        Object *ob = OBACT;
-       ParticleSystem *psys = PE_get_current(ob);
+       ParticleSystem *psys = PE_get_current(scene, ob);
        ParticleSystemModifierData *psmd;
        ParticleData *pa;
        ParticleEditKey *key;
@@ -1755,7 +1751,6 @@ void flushTransParticles(TransInfo *t)
        }
 
        PE_update_object(scene, OBACT, 1);
-#endif
 }
 
 /* ********************* mesh ****************** */
@@ -4630,11 +4625,9 @@ void special_aftertrans_update(TransInfo *t)
                //      allqueue(REDRAWBUTSEDIT, 0);
                
        }
-#if 0 // TRANSFORM_FIX_ME
        else if(G.f & G_PARTICLEEDIT) {
                ;
        }
-#endif
        else { 
                /* Objects */
                // XXX ideally, this would go through context iterators, but we don't have context iterator access here,
@@ -4999,8 +4992,7 @@ void createTransData(bContext *C, TransInfo *t)
                }
                CTX_DATA_END;
        }
-#if 0 // TRANSFORM_FIX_ME
-       else if (G.f & G_PARTICLEEDIT && PE_can_edit(PE_get_current(ob))) {
+       else if (G.f & G_PARTICLEEDIT && PE_can_edit(PE_get_current(scene, ob))) {
                createTransParticleVerts(C, t);
 
                if(t->data && t->flag & T_PROP_EDIT) {
@@ -5011,7 +5003,6 @@ void createTransData(bContext *C, TransInfo *t)
 
                t->flag |= T_POINTS;
        }
-#endif
        else {
                View3D *v3d = t->view;
                RegionView3D *rv3d = t->ar->regiondata;
index 9308cf73af85beaea9d251ec59ed6b690ffe7532..99d7805b938d37d26f2ba6d13eb889e14f6ff312 100644 (file)
@@ -405,16 +405,18 @@ int calc_manipulator_stats(ScrArea *sa)
                ParticleEditKey *ek;
                int k;
 
-               if(psys->edit){
-                       for(a=0; a<psys->totpart; a++,pa++){
+               if(psys->edit) {
+                       for(a=0; a<psys->totpart; a++,pa++) {
                                if(pa->flag & PARS_HIDE) continue;
-                               for(k=0, ek=psys->edit->keys[a]; k<pa->totkey; k++,ek++){
-                                       if(ek->flag & PEK_SELECT){
+
+                               for(k=0, ek=psys->edit->keys[a]; k<pa->totkey; k++, ek++) {
+                                       if(ek->flag & PEK_SELECT) {
                                                calc_tw_center(ek->world_co);
                                                totsel++;
                                        }
                                }
                        }
+
                        /* selection center */
                        if(totsel)
                                VecMulf(G.scene->twcent, 1.0f/(float)totsel);   // centroid!
index 7dd69b2151c59026b451046bc022dfaa97e2da58..2e232c2e1d4288b140206ec31ed154e9b300b650 100644 (file)
@@ -179,7 +179,8 @@ typedef struct ParticleSystem{                              /* note, make sure all (runtime) are NULL's in
        ParticleData *particles;                                /* (parent) particles */
        ChildParticle *child;                                   /* child particles */
 
-       struct ParticleEdit *edit;                              /* particle editmode (runtime) */
+       struct ParticleEdit *edit;                                              /* particle editmode (runtime) */
+       void (*free_edit)(struct ParticleSystem *sys);  /* free callback */
 
        struct ParticleCacheKey **pathcache;    /* path cache (runtime) */
        struct ParticleCacheKey **childcache;   /* child cache (runtime) */
index ce3d627863ea940412e33aa098abe52cb591286d..047fcd3b94e8e55b6843ca976bfc3ebf15cccad7 100644 (file)
@@ -370,6 +370,7 @@ typedef struct ParticleEditSettings {
        short brushtype;
 
        ParticleBrushData brush[7]; /* 7 = PE_TOT_BRUSH */
+       void *paintcursor;                      /* runtime */
 
        float emitterdist;
        int draw_timed;