Commit: 6ae5775c01cff66e32d0b0d12ef98f1b78ba8b95
Author: Lukas Tönne
Date:   Tue Feb 3 12:54:08 2015 +0100
Branches: temp_hair_modifiers
https://developer.blender.org/rB6ae5775c01cff66e32d0b0d12ef98f1b78ba8b95

Operators for adding, removing and moving particle modifiers.

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

M       source/blender/blenkernel/BKE_particle.h
M       source/blender/blenkernel/intern/particle_modifier.c
M       source/blender/editors/include/ED_particle.h
M       source/blender/editors/physics/CMakeLists.txt
A       source/blender/editors/physics/particle_modifier.c
M       source/blender/editors/physics/physics_intern.h
M       source/blender/makesdna/DNA_particle_types.h
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/RNA_enum_types.h
M       source/blender/makesrna/intern/rna_particle.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h 
b/source/blender/blenkernel/BKE_particle.h
index ed10f60..ccdcb47 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -356,6 +356,10 @@ BLI_INLINE void psys_frand_vec(ParticleSystem *psys, 
unsigned int seed, float ve
 void particle_modifier_types_init(void);
 struct ParticleModifierTypeInfo 
*particle_modifier_type_info_get(ParticleModifierType type);
 void particle_modifier_foreachIDLink(struct Object *ob, struct ParticleSystem 
*psys, IDWalkParticleFunc walk, void *userData);
+struct ParticleModifierData *particle_modifier_new(int type);
+void particle_modifier_free(struct ParticleModifierData *md);
+void particle_modifier_unique_name(struct ListBase *modifiers, struct 
ParticleModifierData *md);
+struct ParticleModifierData *particle_modifier_findByName(struct Object *ob, 
struct ParticleSystem *psys, const char *name);
 
 int count_particles(struct ParticleSystem *psys);
 int count_particles_mod(struct ParticleSystem *psys, int totgr, int cur);
diff --git a/source/blender/blenkernel/intern/particle_modifier.c 
b/source/blender/blenkernel/intern/particle_modifier.c
index d6ed199..3ee43bc 100644
--- a/source/blender/blenkernel/intern/particle_modifier.c
+++ b/source/blender/blenkernel/intern/particle_modifier.c
@@ -29,13 +29,20 @@
  *  \ingroup bke
  */
 
+#include "MEM_guardedalloc.h"
+
 #include "BLI_utildefines.h"
+#include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
 
 #include "DNA_particle_types.h"
 
 #include "BKE_particle.h"
 
+#include "BLF_translation.h"
+
 static ParticleModifierTypeInfo 
*particle_modifier_types[NUM_PARTICLE_MODIFIER_TYPES];
 
 static ParticleModifierTypeInfo modifierType_None = {
@@ -80,3 +87,42 @@ void particle_modifier_foreachIDLink(Object *ob, 
ParticleSystem *psys, IDWalkPar
                        mti->foreachIDLink(md, ob, psys, walk, userData);
        }
 }
+
+ParticleModifierData  *particle_modifier_new(int type)
+{
+       ParticleModifierTypeInfo *mti = particle_modifier_type_info_get(type);
+       ParticleModifierData *md = MEM_callocN(mti->structSize, 
mti->structName);
+       
+       /* note, this name must be made unique later */
+       BLI_strncpy(md->name, DATA_(mti->name), sizeof(md->name));
+
+       md->type = type;
+
+       if (mti->initData) mti->initData(md);
+
+       return md;
+}
+
+void particle_modifier_free(ParticleModifierData *md)
+{
+       ParticleModifierTypeInfo *mti = 
particle_modifier_type_info_get(md->type);
+
+       if (mti->freeData) mti->freeData(md);
+       if (md->error) MEM_freeN(md->error);
+
+       MEM_freeN(md);
+}
+
+void particle_modifier_unique_name(ListBase *modifiers, ParticleModifierData 
*md)
+{
+       if (modifiers && md) {
+               ParticleModifierTypeInfo *mti = 
particle_modifier_type_info_get(md->type);
+               
+               BLI_uniquename(modifiers, md, DATA_(mti->name), '.', 
offsetof(ModifierData, name), sizeof(md->name));
+       }
+}
+
+ParticleModifierData *particle_modifier_findByName(Object *UNUSED(ob), 
ParticleSystem *psys, const char *name)
+{
+       return BLI_findstring(&(psys->modifiers), name, 
offsetof(ParticleModifierData, name));
+}
diff --git a/source/blender/editors/include/ED_particle.h 
b/source/blender/editors/include/ED_particle.h
index 7c8a2b7..85fe5c0 100644
--- a/source/blender/editors/include/ED_particle.h
+++ b/source/blender/editors/include/ED_particle.h
@@ -41,6 +41,16 @@ struct rcti;
 struct wmKeyConfig;
 struct PTCacheEdit;
 struct Scene;
+struct Main;
+struct ParticleModifierData;
+struct ReportList;
+
+struct ParticleModifierData *ED_particle_modifier_add(struct ReportList 
*reports, struct Main *bmain, struct Scene *scene,
+                                                      struct Object *ob, 
struct ParticleSystem *psys, const char *name, int type);
+bool ED_particle_modifier_remove(struct ReportList *reports, struct Main 
*bmain, struct Object *ob, struct ParticleSystem *psys, struct 
ParticleModifierData *md);
+void ED_particle_modifier_clear(struct Main *bmain, struct Object *ob, struct 
ParticleSystem *psys);
+int ED_particle_modifier_move_up(struct ReportList *reports, struct Object 
*ob, struct ParticleSystem *psys, struct ParticleModifierData *md);
+int ED_particle_modifier_move_down(struct ReportList *reports, struct Object 
*ob, struct ParticleSystem *psys, struct ParticleModifierData *md);
 
 /* particle edit mode */
 void PE_free_ptcache_edit(struct PTCacheEdit *edit);
diff --git a/source/blender/editors/physics/CMakeLists.txt 
b/source/blender/editors/physics/CMakeLists.txt
index f291af4..8d2a3ba 100644
--- a/source/blender/editors/physics/CMakeLists.txt
+++ b/source/blender/editors/physics/CMakeLists.txt
@@ -40,6 +40,7 @@ set(SRC
        dynamicpaint_ops.c
        particle_boids.c
        particle_edit.c
+       particle_modifier.c
        particle_object.c
        particle_shapekey.c
        physics_fluid.c
diff --git a/source/blender/editors/physics/particle_modifier.c 
b/source/blender/editors/physics/particle_modifier.c
new file mode 100644
index 0000000..cf2d064
--- /dev/null
+++ b/source/blender/editors/physics/particle_modifier.c
@@ -0,0 +1,435 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/physics/particle_modifier.c
+ *  \ingroup edphys
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+#include "BLI_string_utf8.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_main.h"
+#include "BKE_object.h"
+#include "BKE_particle.h"
+#include "BKE_report.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_object.h"
+#include "ED_particle.h"
+#include "ED_physics.h"
+#include "ED_screen.h"
+
+#include "physics_intern.h"
+
+/******************************** API ****************************/
+
+ParticleModifierData *ED_particle_modifier_add(ReportList *UNUSED(reports), 
Main *UNUSED(bmain), Scene *UNUSED(scene), Object *ob, ParticleSystem *psys, 
const char *name, int type)
+{
+       ParticleModifierData *new_md = NULL;
+       
+       /* get new modifier data to add */
+       new_md = particle_modifier_new(type);
+       BLI_addtail(&psys->modifiers, new_md);
+       
+       if (name) {
+               BLI_strncpy_utf8(new_md->name, name, sizeof(new_md->name));
+       }
+       
+       /* make sure modifier data has unique name */
+       particle_modifier_unique_name(&psys->modifiers, new_md);
+       
+       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       
+       return new_md;
+}
+
+static bool particle_modifier_remove(Main *UNUSED(bmain), Object *UNUSED(ob), 
ParticleSystem *psys, ParticleModifierData *md,
+                                   bool *r_sort_depsgraph)
+{
+       *r_sort_depsgraph = false;
+       
+       /* It seems on rapid delete it is possible to
+        * get called twice on same modifier, so make
+        * sure it is in list. */
+       if (BLI_findindex(&psys->modifiers, md) == -1) {
+               return 0;
+       }
+
+       BLI_remlink(&psys->modifiers, md);
+       particle_modifier_free(md);
+
+       return 1;
+}
+
+bool ED_particle_modifier_remove(ReportList *reports, Main *bmain, Object *ob, 
ParticleSystem *psys, ParticleModifierData *md)
+{
+       bool sort_depsgraph = false;
+       bool ok;
+
+       ok = particle_modifier_remove(bmain, ob, psys, md, &sort_depsgraph);
+
+       if (!ok) {
+               BKE_reportf(reports, RPT_ERROR, "Modifier '%s' not in particle 
system '%s'", md->name, psys->name);
+               return 0;
+       }
+
+       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       DAG_relations_tag_update(bmain);
+
+       return 1;
+}
+
+void ED_particle_modifier_clear(Main *bmain, Object *ob, ParticleSystem *psys)
+{
+       ParticleModifierData *md = ob->modifiers.first;
+       bool sort_depsgraph = false;
+
+       if (!md)
+               return;
+
+       while (md) {
+               ParticleModifierData *next_md;
+
+               next_md = md->next;
+
+               particle_modifier_remove(bmain, ob, psys, md, &sort_depsgraph);
+
+               md = next_md;
+       }
+
+       DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+       DAG_relations_tag_update(bmain);
+}
+
+int ED_particle_modifier_move_up(ReportList *UNUSED(reports), Object 
*UNUSED(ob), ParticleSystem *psys, ParticleModifierData *md)
+{
+       if (md->prev) {
+               BLI_remlink(&psys->modifiers, md);
+               BLI_insertlinkbefore(&psys->modifiers, md->prev, md);
+       }
+
+       return 1;
+}
+
+int ED_particle_modifier_move_down(ReportList *UNUSED(reports), Object 
*UNUSED(ob), ParticleSystem *psys, ParticleModifierData *md)
+{
+       if (md->next) {
+               BLI_remlink(&psys->modifiers, md);
+               BLI_insertlinkafter(&psys->modifiers, md->next, md);
+       }
+
+       return 1;
+}
+
+/************************ add modifier operator *********************/
+
+static int particle_modifier_add_poll(bContext *C)
+{
+       Object *ob;
+       if (!ED_operator_object_active_editable(C))
+               return false;
+       
+       ob = ED_object_active_context(C);
+       if (psys_get_current(ob) == NULL)
+               return false;
+       
+       return true;
+}
+
+static int particle_modifier_add_exec(bContext *C, wmOperator *op)
+{
+       Main *bmain = CTX_data_main(C);
+       Scene *scene = CTX_data_scene(C);
+       Object *ob = ED_object_active_context(C);
+       ParticleSystem *psys = psys_get_current(ob);
+       int type = RNA_enum_get(op->ptr, "type");
+
+       if (!ED_particle_modifier_add(op->reports, bmain, scene, ob, psys, 
NULL, type))
+               return OPERATOR_CANCELLED;
+
+       WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+static Enu

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to