[Bf-blender-cvs] [5f02cc2d3ab] functions: simple clear cache operator

Jacques Lucke noreply at git.blender.org
Wed Jul 10 17:18:29 CEST 2019


Commit: 5f02cc2d3abb9359aa4903ac8fd0401daef4f21b
Author: Jacques Lucke
Date:   Wed Jul 10 17:17:26 2019 +0200
Branches: functions
https://developer.blender.org/rB5f02cc2d3abb9359aa4903ac8fd0401daef4f21b

simple clear cache operator

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/editors/object/CMakeLists.txt
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_ops.c
M	source/blender/makesrna/RNA_access.h

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 53d3a8c451e..c755f0fff2a 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1663,6 +1663,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
     def BPARTICLES(self, layout, ob, md):
         layout.prop(md, "bparticles_tree")
+        layout.operator("object.bparticles_clear_cache", text="Clear Cache")
 
 
 class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index eaef9313431..714b95cb259 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -31,6 +31,7 @@ set(INC
   ../../modifiers
   ../../python
   ../../shader_fx
+  ../../simulations
   ../../render/extern/include
   ../../windowmanager
   ../../../../intern/glew-mx
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index b9350052093..5889be27ada 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -168,6 +168,7 @@ void OBJECT_OT_skin_radii_equalize(struct wmOperatorType *ot);
 void OBJECT_OT_skin_armature_create(struct wmOperatorType *ot);
 void OBJECT_OT_laplaciandeform_bind(struct wmOperatorType *ot);
 void OBJECT_OT_surfacedeform_bind(struct wmOperatorType *ot);
+void OBJECT_OT_bparticles_clear_cache(struct wmOperatorType *ot);
 
 /* grease pencil modifiers */
 void OBJECT_OT_gpencil_modifier_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 08012842c37..e6bf5f86eaf 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -86,6 +86,8 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "BParticles.h"
+
 #include "object_intern.h"
 
 static void modifier_skin_customdata_delete(struct Object *ob);
@@ -2524,3 +2526,54 @@ void OBJECT_OT_surfacedeform_bind(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
   edit_modifier_properties(ot);
 }
+
+/************************ BParticles ***********************/
+
+static bool bparticles_clear_cache_poll(bContext *C)
+{
+  return edit_modifier_poll_generic(C, &RNA_BParticlesModifier, 0);
+}
+
+static int bparticles_clear_cache_exec(bContext *C, wmOperator *op)
+{
+  Object *ob = ED_object_active_context(C);
+  BParticlesModifierData *bpmd = (BParticlesModifierData *)edit_modifier_property_get(
+      op, ob, eModifierType_BParticles);
+
+  if (bpmd == NULL) {
+    return OPERATOR_CANCELLED;
+  }
+
+  BParticles_modifier_free_cache(bpmd);
+
+  DEG_id_tag_update(&ob->id, ID_RECALC_ALL);
+  WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+  return OPERATOR_FINISHED;
+}
+
+static int bparticles_clear_cache_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+  if (edit_modifier_invoke_properties(C, op)) {
+    return bparticles_clear_cache_exec(C, op);
+  }
+  else {
+    return OPERATOR_CANCELLED;
+  }
+}
+
+void OBJECT_OT_bparticles_clear_cache(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Clear BParticles Cache";
+  ot->description = "Clear the cache for the modifier";
+  ot->idname = "OBJECT_OT_bparticles_clear_cache";
+
+  /* api callbacks */
+  ot->poll = bparticles_clear_cache_poll;
+  ot->invoke = bparticles_clear_cache_invoke;
+  ot->exec = bparticles_clear_cache_exec;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+  edit_modifier_properties(ot);
+}
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index b653c7fa70c..e160f73e3aa 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -257,6 +257,8 @@ void ED_operatortypes_object(void)
   WM_operatortype_append(OBJECT_OT_hide_view_clear);
   WM_operatortype_append(OBJECT_OT_hide_view_set);
   WM_operatortype_append(OBJECT_OT_hide_collection);
+
+  WM_operatortype_append(OBJECT_OT_bparticles_clear_cache);
 }
 
 void ED_operatormacros_object(void)
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 30e24917b83..aa23dd2e1f9 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -89,6 +89,7 @@ extern StructRNA RNA_Bone;
 extern StructRNA RNA_BoneGroup;
 extern StructRNA RNA_BoolProperty;
 extern StructRNA RNA_BooleanModifier;
+extern StructRNA RNA_BParticlesModifier;
 extern StructRNA RNA_Brush;
 extern StructRNA RNA_BrushCapabilitiesImagePaint;
 extern StructRNA RNA_BrushCapabilitiesVertexPaint;



More information about the Bf-blender-cvs mailing list