diff options
45 files changed, 316 insertions, 157 deletions
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index dfac6d1798e..3fac56ba554 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -565,8 +565,7 @@ function(SETUP_BLENDER_SORTED_LIBS) set(BLENDER_SORTED_LIBS bf_windowmanager - # needed twice because of text undo - bf_editor_util + bf_editor_undo bf_editor_space_api bf_editor_space_action diff --git a/doc/doxygen/doxygen.source.h b/doc/doxygen/doxygen.source.h index ebc20940529..6f159bb74df 100644 --- a/doc/doxygen/doxygen.source.h +++ b/doc/doxygen/doxygen.source.h @@ -320,6 +320,10 @@ * \ingroup editors */ +/** \defgroup edundo undo utilities + * \ingroup editors + */ + /** \defgroup spuv UV editing * \ingroup editors */ diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt index c7ce4b44803..06f412b7019 100644 --- a/source/blender/editors/CMakeLists.txt +++ b/source/blender/editors/CMakeLists.txt @@ -60,6 +60,7 @@ if(WITH_BLENDER) add_subdirectory(space_userpref) add_subdirectory(space_view3d) add_subdirectory(transform) + add_subdirectory(undo) add_subdirectory(util) add_subdirectory(uvedit) add_subdirectory(screen) diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 8d77460e197..8106be79521 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -62,7 +62,7 @@ #include "UI_resources.h" #include "ED_anim_api.h" -#include "ED_util.h" +#include "ED_undo.h" /* ********************************************** */ /* UI STUFF */ diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index 2fb216c2ef8..3dd41f25e09 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -42,7 +42,7 @@ #include "BKE_context.h" #include "ED_armature.h" -#include "ED_util.h" +#include "ED_undo.h" #include "BIF_retarget.h" diff --git a/source/blender/editors/curve/editcurve_add.c b/source/blender/editors/curve/editcurve_add.c index 281f6c3c22e..f269799973f 100644 --- a/source/blender/editors/curve/editcurve_add.c +++ b/source/blender/editors/curve/editcurve_add.c @@ -53,7 +53,7 @@ #include "ED_object.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "ED_view3d.h" #include "ED_curve.h" diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c index 5775835e5ff..4eb2abaefad 100644 --- a/source/blender/editors/curve/editcurve_undo.c +++ b/source/blender/editors/curve/editcurve_undo.c @@ -61,10 +61,16 @@ typedef struct { ListBase fcurves, drivers; int actnu; int flag; + + /* Stored in the object, needed since users may change the active key while in edit-mode. */ + struct { + short shapenr; + } obedit; + size_t undo_size; } UndoCurve; -static void undocurve_to_editcurve(UndoCurve *ucu, Curve *cu) +static void undocurve_to_editcurve(UndoCurve *ucu, Curve *cu, short *r_shapenr) { ListBase *undobase = &ucu->nubase; ListBase *editbase = BKE_curve_editNurbs_get(cu); @@ -103,10 +109,11 @@ static void undocurve_to_editcurve(UndoCurve *ucu, Curve *cu) cu->actvert = ucu->actvert; cu->actnu = ucu->actnu; cu->flag = ucu->flag; + *r_shapenr = ucu->obedit.shapenr; ED_curve_updateAnimPaths(cu); } -static void undocurve_from_editcurve(UndoCurve *ucu, Curve *cu) +static void undocurve_from_editcurve(UndoCurve *ucu, Curve *cu, const short shapenr) { BLI_assert(BLI_array_is_zeroed(ucu, 1)); ListBase *nubase = BKE_curve_editNurbs_get(cu); @@ -150,6 +157,8 @@ static void undocurve_from_editcurve(UndoCurve *ucu, Curve *cu) ucu->actvert = cu->actvert; ucu->actnu = cu->actnu; ucu->flag = cu->flag; + + ucu->obedit.shapenr = shapenr; } static void undocurve_free_data(UndoCurve *uc) @@ -197,7 +206,7 @@ static bool curve_undosys_step_encode(struct bContext *C, UndoStep *us_p) { CurveUndoStep *us = (CurveUndoStep *)us_p; us->obedit_ref.ptr = editcurve_object_from_context(C); - undocurve_from_editcurve(&us->data, us->obedit_ref.ptr->data); + undocurve_from_editcurve(&us->data, us->obedit_ref.ptr->data, us->obedit_ref.ptr->shapenr); us->step.data_size = us->data.undo_size; return true; } @@ -210,7 +219,7 @@ static void curve_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UN CurveUndoStep *us = (CurveUndoStep *)us_p; Object *obedit = us->obedit_ref.ptr; - undocurve_to_editcurve(&us->data, obedit->data); + undocurve_to_editcurve(&us->data, obedit->data, &obedit->shapenr); DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } diff --git a/source/blender/editors/include/ED_undo.h b/source/blender/editors/include/ED_undo.h new file mode 100644 index 00000000000..044d69cfced --- /dev/null +++ b/source/blender/editors/include/ED_undo.h @@ -0,0 +1,62 @@ +/* + * ***** 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file ED_undo.h + * \ingroup editors + */ + +#ifndef __ED_UNDO_H__ +#define __ED_UNDO_H__ + +struct bContext; +struct wmOperator; +struct wmOperatorType; +struct UndoStack; + +/* undo.c */ +void ED_undo_push(struct bContext *C, const char *str); +void ED_undo_push_op(struct bContext *C, struct wmOperator *op); +void ED_undo_grouped_push(struct bContext *C, const char *str); +void ED_undo_grouped_push_op(struct bContext *C, struct wmOperator *op); +void ED_undo_pop_op(struct bContext *C, struct wmOperator *op); +void ED_undo_pop(struct bContext *C); +void ED_undo_redo(struct bContext *C); +void ED_OT_undo(struct wmOperatorType *ot); +void ED_OT_undo_push(struct wmOperatorType *ot); +void ED_OT_redo(struct wmOperatorType *ot); +void ED_OT_undo_redo(struct wmOperatorType *ot); +void ED_OT_undo_history(struct wmOperatorType *ot); + +int ED_undo_operator_repeat(struct bContext *C, struct wmOperator *op); +/* convenience since UI callbacks use this mostly*/ +void ED_undo_operator_repeat_cb(struct bContext *C, void *arg_op, void *arg_unused); +void ED_undo_operator_repeat_cb_evt(struct bContext *C, void *arg_op, int arg_unused); + +bool ED_undo_is_valid(const struct bContext *C, const char *undoname); + +/* undo_system_types.c */ +void ED_undosys_type_init(void); +void ED_undosys_type_free(void); + +/* memfile_undo.c */ +struct MemFile *ED_undosys_stack_memfile_get_active(struct UndoStack *ustack); + +#endif /* __ED_UNDO_H__ */ + diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 5a373cebac1..2653585dacc 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -32,11 +32,9 @@ #define __ED_UTIL_H__ struct bContext; -struct SpaceLink; -struct wmOperator; struct wmOperatorType; -struct UndoStack; struct ScrArea; +struct SpaceLink; struct PackedFile; /* ed_util.c */ @@ -50,36 +48,6 @@ void ED_spacedata_id_remap(struct ScrArea *sa, struct SpaceLink *sl, struct I void ED_OT_flush_edits(struct wmOperatorType *ot); -/* ************** Undo ************************ */ - -/* undo.c */ -void ED_undo_push(struct bContext *C, const char *str); -void ED_undo_push_op(struct bContext *C, struct wmOperator *op); -void ED_undo_grouped_push(struct bContext *C, const char *str); -void ED_undo_grouped_push_op(struct bContext *C, struct wmOperator *op); -void ED_undo_pop_op(struct bContext *C, struct wmOperator *op); -void ED_undo_pop(struct bContext *C); -void ED_undo_redo(struct bContext *C); -void ED_OT_undo(struct wmOperatorType *ot); -void ED_OT_undo_push(struct wmOperatorType *ot); -void ED_OT_redo(struct wmOperatorType *ot); -void ED_OT_undo_redo(struct wmOperatorType *ot); -void ED_OT_undo_history(struct wmOperatorType *ot); - -int ED_undo_operator_repeat(struct bContext *C, struct wmOperator *op); -/* convenience since UI callbacks use this mostly*/ -void ED_undo_operator_repeat_cb(struct bContext *C, void *arg_op, void *arg_unused); -void ED_undo_operator_repeat_cb_evt(struct bContext *C, void *arg_op, int arg_unused); - -bool ED_undo_is_valid(const struct bContext *C, const char *undoname); - -/* undo_system_types.c */ -void ED_undosys_type_init(void); -void ED_undosys_type_free(void); - -/* memfile_undo.c */ -struct MemFile *ED_undosys_stack_memfile_get_active(struct UndoStack *ustack); - /* ************** XXX OLD CRUFT WARNING ************* */ void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert); diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 8a2baa53d30..e01121ed277 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -77,7 +77,7 @@ #include "DEG_depsgraph.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "ED_keyframing.h" #include "UI_interface.h" diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 75b657e1e29..af14c57fade 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -79,7 +79,7 @@ #include "ED_screen.h" #include "ED_object.h" #include "ED_render.h" -#include "ED_util.h" +#include "ED_undo.h" #include "RNA_access.h" diff --git a/source/blender/editors/mesh/editmesh_bisect.c b/source/blender/editors/mesh/editmesh_bisect.c index 1937a9f6891..741d16206cd 100644 --- a/source/blender/editors/mesh/editmesh_bisect.c +++ b/source/blender/editors/mesh/editmesh_bisect.c @@ -58,7 +58,7 @@ #ifdef USE_MANIPULATOR #include "ED_manipulator_library.h" -#include "ED_util.h" +#include "ED_undo.h" #endif static int mesh_bisect_exec(bContext *C, wmOperator *op); diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c index 657c3eb2a40..64980b84a0b 100644 --- a/source/blender/editors/mesh/editmesh_extrude.c +++ b/source/blender/editors/mesh/editmesh_extrude.c @@ -62,7 +62,7 @@ #ifdef USE_MANIPULATOR #include "ED_manipulator_library.h" -#include "ED_util.h" +#include "ED_undo.h" #endif /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 593c1aa3d35..dab45a03b8a 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -100,7 +100,7 @@ #include "ED_lattice.h" #include "ED_object.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "ED_image.h" #include "RNA_access.h" diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index f128a15ca6f..e1e5c788b02 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -77,6 +77,7 @@ #include "ED_render.h" #include "ED_screen.h" #include "ED_util.h" +#include "ED_undo.h" #include "ED_view3d.h" #include "RE_pipeline.h" diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 27e127ab078..c24d08d5fed 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -79,6 +79,7 @@ #include "ED_screen_types.h" #include "ED_sequencer.h" #include "ED_util.h" +#include "ED_undo.h" #include "ED_view3d.h" #include "RNA_access.h" diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index fc1b6877f5e..2a703ebb46c 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -51,7 +51,7 @@ #include "WM_types.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "RNA_access.h" diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c index 1504ce1a7ba..d2a7244eded 100644 --- a/source/blender/editors/space_clip/clip_toolbar.c +++ b/source/blender/editors/space_clip/clip_toolbar.c @@ -49,7 +49,7 @@ #include "WM_api.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index 49f498b3419..c79652795ac 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -64,7 +64,7 @@ #include "ED_anim_api.h" #include "ED_keyframing.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index c6fd70a60dd..9bdc92f98ab 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -56,7 +56,7 @@ #include "BKE_main.h" #include "BKE_sca.h" -#include "ED_util.h" +#include "ED_undo.h" #include "BLT_translation.h" diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index 1047c498e4d..241ab60fe43 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -53,7 +53,7 @@ #include "ED_node.h" /* own include */ -#include "ED_util.h" +#include "ED_undo.h" /************************* Node Socket Manipulation **************************/ diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index e720eedbb22..018756f2a99 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -57,7 +57,7 @@ #include "ED_object.h" #include "ED_screen.h" #include "ED_sequencer.h" -#include "ED_util.h" +#include "ED_undo.h" #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 1da1efc9cf4..c19dcc0e1cb 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -73,7 +73,7 @@ #include "ED_scene.h" #include "ED_screen.h" #include "ED_sequencer.h" -#include "ED_util.h" +#include "ED_undo.h" #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index bf4abf1852d..35a37590642 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -55,7 +55,7 @@ #include "WM_types.h" #include "ED_mesh.h" -#include "ED_util.h" +#include "ED_undo.h" #include "ED_screen.h" #include "UI_interface.h" diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c index 5e3c783c1b6..dfa64bd2015 100644 --- a/source/blender/editors/space_view3d/view3d_toolbar.c +++ b/source/blender/editors/space_view3d/view3d_toolbar.c @@ -55,7 +55,7 @@ #include "RNA_access.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "UI_interface.h" #include "UI_resources.h" diff --git a/source/blender/editors/undo/CMakeLists.txt b/source/blender/editors/undo/CMakeLists.txt new file mode 100644 index 00000000000..89832604ed8 --- /dev/null +++ b/source/blender/editors/undo/CMakeLists.txt @@ -0,0 +1,45 @@ +# ***** 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. +# +# Contributor(s): Jacques Beaurain. +# +# ***** END GPL LICENSE BLOCK ***** + +set(INC + ../include + ../../blenkernel + ../../blenlib + ../../blentranslation + ../../makesdna + ../../makesrna + ../../windowmanager + ../../../../intern/guardedalloc + ../../../../intern/clog +) + +set(SRC + ed_undo.c + memfile_undo.c + undo_system_types.c + + undo_intern.h +) + +if(WITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) +endif() + +blender_add_lib(bf_editor_undo "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/undo/ed_undo.c index 99e90eb73e8..691ba066bf9 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -26,16 +26,13 @@ */ /** \file blender/editors/util/undo.c - * \ingroup edutil + * \ingroup edundo */ -#include <stdlib.h> #include <string.h> -#include <math.h> #include "MEM_guardedalloc.h" -#include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BLI_utildefines.h" @@ -45,26 +42,13 @@ #include "BKE_blender_undo.h" #include "BKE_context.h" #include "BKE_global.h" -#include "BKE_library_override.h" -#include "BKE_main.h" #include "BKE_screen.h" #include "BKE_undo_system.h" -#include "DEG_depsgraph.h" - -#include "ED_armature.h" -#include "ED_particle.h" -#include "ED_curve.h" #include "ED_gpencil.h" -#include "ED_lattice.h" -#include "ED_mball.h" -#include "ED_mesh.h" -#include "ED_object.h" #include "ED_render.h" #include "ED_screen.h" -#include "ED_paint.h" -#include "ED_util.h" -#include "ED_text.h" +#include "ED_undo.h" #include "WM_api.h" #include "WM_types.h" @@ -75,9 +59,11 @@ #include "UI_interface.h" #include "UI_resources.h" -#include "util_intern.h" - -/* ***************** generic undo system ********************* */ +/* -------------------------------------------------------------------- */ +/** \name Generic Undo System Access + * + * Non-operator undo editor functions. + * \{ */ void ED_undo_push(bContext *C, const char *str) { @@ -204,6 +190,12 @@ bool ED_undo_is_valid(const bContext *C, const char *undoname) return BKE_undosys_stack_has_undo(wm->undo_stack, undoname); } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Undo, Undo Push & Redo Operators + * \{ */ + static int ed_undo_exec(bContext *C, wmOperator *UNUSED(op)) { /* "last operator" should disappear, later we can tie this with undo stack nicer */ @@ -234,19 +226,17 @@ static int ed_undo_redo_exec(bContext *C, wmOperator *UNUSED(op)) static int ed_undo_redo_poll(bContext *C) { wmOperator *last_op = WM_operator_last_redo(C); - return last_op && ED_operator_screenactive(C) && + return last_op && ED_operator_screenactive(C) && WM_operator_check_ui_enabled(C, last_op->type->name); } -/* ********************** */ - void ED_OT_undo(wmOperatorType *ot) { /* identifiers */ ot->name = "Undo"; ot->description = "Undo previous action"; ot->idname = "ED_OT_undo"; - + /* api callbacks */ ot->exec = ed_undo_exec; ot->poll = ED_operator_screenactive; @@ -258,7 +248,7 @@ void ED_OT_undo_push(wmOperatorType *ot) ot->name = "Undo Push"; ot->description = "Add an undo state (internal use only)"; ot->idname = "ED_OT_undo_push"; - + /* api callbacks */ ot->exec = ed_undo_push_exec; @@ -273,7 +263,7 @@ void ED_OT_redo(wmOperatorType *ot) ot->name = "Redo"; ot->description = "Redo previous action"; ot->idname = "ED_OT_redo"; - + /* api callbacks */ ot->exec = ed_redo_exec; ot->poll = ED_operator_screenactive; @@ -285,12 +275,18 @@ void ED_OT_undo_redo(wmOperatorType *ot) ot->name = "Undo and Redo"; ot->description = "Undo and redo previous action"; ot->idname = "ED_OT_undo_redo"; - + /* api callbacks */ ot->exec = ed_undo_redo_exec; ot->poll = ed_undo_redo_poll; } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Operator Repeat + * \{ */ + /* ui callbacks should call this rather than calling WM_operator_repeat() themselves */ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op) { @@ -376,8 +372,11 @@ void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int UNUSED(arg_ev ED_undo_operator_repeat(C, (wmOperator *)arg_op); } +/** \} */ -/* ************************** */ +/* -------------------------------------------------------------------- */ +/** \name Undo History Operator + * \{ */ /* create enum based on undo items */ static const EnumPropertyItem *rna_undo_itemf(bContext *C, int *totitem) @@ -393,7 +392,6 @@ static const EnumPropertyItem *rna_undo_itemf(bContext *C, int *totitem) for (UndoStep *us = wm->undo_stack->steps.first; us; us = us->next, i++) { if (us->skip == false) { item_tmp.identifier = us->name; - /* XXX This won't work with non-default contexts (e.g. operators) :/ */ item_tmp.name = IFACE_(us->name); if (us == wm->undo_stack->step_active) { item_tmp.icon = ICON_RESTRICT_VIEW_OFF; @@ -426,7 +424,7 @@ static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE const int col_size = 20 + totitem / 12; int i, c; bool add_col = true; - + for (c = 0, i = totitem; i--;) { if (add_col && !(c % col_size)) { column = uiLayoutColumn(split, false); @@ -438,12 +436,12 @@ static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE add_col = true; } } - + MEM_freeN((void *)item); - + UI_popup_menu_end(C, pup); } - + } return OPERATOR_CANCELLED; } @@ -468,14 +466,14 @@ void ED_OT_undo_history(wmOperatorType *ot) ot->name = "Undo History"; ot->description = "Redo specific action in history"; ot->idname = "ED_OT_undo_history"; - + /* api callbacks */ ot->invoke = undo_history_invoke; ot->exec = undo_history_exec; ot->poll = ED_operator_screenactive; - + RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX); } - +/** \} */ diff --git a/source/blender/editors/util/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c index 69904b7f1b4..756c46b4e8a 100644 --- a/source/blender/editors/util/memfile_undo.c +++ b/source/blender/editors/undo/memfile_undo.c @@ -19,9 +19,9 @@ */ /** \file blender/editors/util/memfile_undo.c - * \ingroup edutil + * \ingroup edundo * - * Wrapper between 'BKE_undo.h' and 'BKE_undo_system.h' + * Wrapper between 'ED_undo.h' and 'BKE_undo_system.h' API's. */ #include "BLI_utildefines.h" @@ -37,13 +37,13 @@ #include "WM_types.h" #include "ED_object.h" -#include "ED_util.h" +#include "ED_undo.h" #include "ED_render.h" #include "../blenloader/BLO_undofile.h" -#include "util_intern.h" +#include "undo_intern.h" /** Store workspace modes in undo steps, this may be removed if find a better way to handle. */ #define USE_WORKSPACE_OBJECT_MODE_HACK diff --git a/source/blender/editors/util/util_intern.h b/source/blender/editors/undo/undo_intern.h index 6eda3900e91..671f9637d65 100644 --- a/source/blender/editors/util/util_intern.h +++ b/source/blender/editors/undo/undo_intern.h @@ -15,30 +15,21 @@ * 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) 2008 Blender Foundation. - * All rights reserved. - * - * - * Contributor(s): Blender Foundation - * * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/editors/util/util_intern.h - * \ingroup edutil +/** \file blender/editors/undo/undo_intern.h + * \ingroup edundo */ - -#ifndef __UTIL_INTERN_H__ -#define __UTIL_INTERN_H__ +#ifndef __UNDO_INTERN_H__ +#define __UNDO_INTERN_H__ /* internal exports only */ struct UndoType; -struct Main; -struct Scene; /* memfile_undo.c */ void ED_memfile_undosys_type(struct UndoType *ut); -#endif /* __UTIL_INTERN_H__ */ +#endif /* __UNDO_INTERN_H__ */ diff --git a/source/blender/editors/util/undo_system_types.c b/source/blender/editors/undo/undo_system_types.c index a326d9eb859..f1ef444337c 100644 --- a/source/blender/editors/util/undo_system_types.c +++ b/source/blender/editors/undo/undo_system_types.c @@ -19,7 +19,7 @@ */ /** \file blender/editors/util/undo_system_types.c - * \ingroup edutil + * \ingroup edundo */ #include <string.h> @@ -36,8 +36,8 @@ #include "ED_particle.h" #include "ED_sculpt.h" #include "ED_text.h" -#include "ED_util.h" -#include "util_intern.h" +#include "ED_undo.h" +#include "undo_intern.h" /* Keep last */ #include "BKE_undo_system.h" diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index bd9077a2fca..24cfde90804 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -42,12 +42,8 @@ set(INC_SYS set(SRC ed_transverts.c ed_util.c - memfile_undo.c numinput.c - undo.c - undo_system_types.c - util_intern.h # general includes ../include/BIF_gl.h ../include/BIF_glutil.h diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 979b7d9b814..cc8a38d5bf4 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -68,7 +68,6 @@ #include "MEM_guardedalloc.h" - #ifdef WITH_AVI # include "AVI_avi.h" #endif @@ -83,6 +82,8 @@ #include "IMB_indexer.h" #ifdef WITH_FFMPEG +# include "BKE_global.h" /* ENDIAN_ORDER */ + # include <libavformat/avformat.h> # include <libavcodec/avcodec.h> # include <libavutil/rational.h> diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index 2b6963b9170..9dfe926ddff 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -43,7 +43,6 @@ #include "BLI_fileops.h" #include "BLI_string.h" - #include "imbuf.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -52,6 +51,7 @@ #include "IMB_anim.h" #ifdef WITH_FFMPEG +#include "BKE_global.h" /* G.debug */ #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavdevice/avdevice.h> diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c index 6af0e5b73ea..a6d91fc3d90 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.c +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c @@ -43,6 +43,7 @@ #ifdef WITH_ALEMBIC # include "ABC_alembic.h" +# include "BKE_global.h" #endif static void initData(ModifierData *md) diff --git a/source/blender/python/BPY_extern_clog.h b/source/blender/python/BPY_extern_clog.h new file mode 100644 index 00000000000..fbe7139ba1b --- /dev/null +++ b/source/blender/python/BPY_extern_clog.h @@ -0,0 +1,35 @@ +/* + * ***** 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. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file BPY_extern_clog.h + * \ingroup python + * + * Logging defines. + */ + +#ifndef __BPY_EXTERN_CLOG_H__ +#define __BPY_EXTERN_CLOG_H__ + + +/* bpy_interface.c */ +extern struct CLG_LogRef *BPY_LOG_RNA; +extern struct CLG_LogRef *BPY_LOG_CONTEXT; + +#endif /* __BPY_EXTERN_CLOG_H__ */ diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 36609c6f29b..62ef1b773c7 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -38,6 +38,8 @@ #include "python_utildefines.h" +#include "BLI_string.h" + #ifndef MATH_STANDALONE /* only for BLI_strncpy_wchar_from_utf8, should replace with py funcs but too late in release now */ #include "BLI_string_utf8.h" @@ -225,22 +227,49 @@ int PyC_ParseBool(PyObject *o, void *p) /* for debugging */ void PyC_ObSpit(const char *name, PyObject *var) { + const char *null_str = "<null>"; fprintf(stderr, "<%s> : ", name); if (var == NULL) { - fprintf(stderr, "<NIL>"); + fprintf(stderr, "%s\n", null_str); } else { PyObject_Print(var, stderr, 0); - fprintf(stderr, " ref:%d ", (int)var->ob_refcnt); - fprintf(stderr, " ptr:%p", (void *)var); - - fprintf(stderr, " type:"); - if (Py_TYPE(var)) - fprintf(stderr, "%s", Py_TYPE(var)->tp_name); - else - fprintf(stderr, "<NIL>"); + const PyTypeObject *type = Py_TYPE(var); + fprintf(stderr, + " ref:%d, ptr:%p, type: %s\n", + (int)var->ob_refcnt, (void *)var, type ? type->tp_name : null_str); + } +} + +/** + * A version of #PyC_ObSpit that writes into a string (and doesn't take a name argument). + * Use for logging. + */ +void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var) +{ + /* No name, creator of string can manage that. */ + const char *null_str = "<null>"; + if (var == NULL) { + BLI_snprintf(result, result_len, "%s", null_str); + } + else { + const PyTypeObject *type = Py_TYPE(var); + PyObject *var_str = PyObject_Repr(var); + if (var_str == NULL) { + /* We could print error here, but this may be used for generating errors - so don't for now. */ + PyErr_Clear(); + } + BLI_snprintf( + result, result_len, + " ref=%d, ptr=%p, type=%s, value=%.200s", + (int)var->ob_refcnt, + (void *)var, + type ? type->tp_name : null_str, + var_str ? _PyUnicode_AsString(var_str) : "<error>"); + if (var_str != NULL) { + Py_DECREF(var_str); + } } - fprintf(stderr, "\n"); } void PyC_LineSpit(void) diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 25c88799027..e4d6d3fe557 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -31,6 +31,7 @@ #include "BLI_utildefines_variadic.h" void PyC_ObSpit(const char *name, PyObject *var); +void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var); void PyC_LineSpit(void); void PyC_StackSpit(void); PyObject * PyC_ExceptionBuffer(void); diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index a71478cdb15..f9098529772 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -23,7 +23,7 @@ # # ***** END GPL LICENSE BLOCK ***** -set(INC +set(INC .. ../../blenkernel ../../blenlib @@ -35,9 +35,10 @@ set(INC ../../makesdna ../../makesrna ../../windowmanager - ../../../../intern/cycles/blender - ../../../../intern/opencolorio + ../../../../intern/clog ../../../../intern/guardedalloc + ../../../../intern/opencolorio + ../../../../intern/cycles/blender ) set(INC_SYS @@ -119,6 +120,7 @@ set(SRC bpy_utils_units.h gpu.h ../BPY_extern.h + ../BPY_extern_clog.h ) # only to check if buildinfo is available diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 11a233461d8..7156bed0c2b 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -33,6 +33,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "BLI_utildefines.h" #include "BLI_path_util.h" #include "BLI_fileops.h" @@ -76,6 +78,9 @@ #include "../bmesh/bmesh_py_api.h" #include "../mathutils/mathutils.h" +/* Logging types to use anywhere in the Python modules. */ +CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_CONTEXT, "bpy.context"); +CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna"); /* for internal use, when starting and ending python scripts */ @@ -803,8 +808,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult * CTX_data_list_add(result, ptr->id.data, ptr->type, ptr->data); } else { - printf("PyContext: '%s' list item not a valid type in sequece type '%s'\n", - member, Py_TYPE(item)->tp_name); + CLOG_INFO(BPY_LOG_CONTEXT, 1, + "'%s' list item not a valid type in sequence type '%s'", + member, Py_TYPE(item)->tp_name); } } @@ -816,16 +822,14 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult * if (done == false) { if (item) { - printf("PyContext '%s' not a valid type\n", member); + CLOG_INFO(BPY_LOG_CONTEXT, 1, "'%s' not a valid type", member); } else { - printf("PyContext '%s' not found\n", member); + CLOG_INFO(BPY_LOG_CONTEXT, 1, "'%s' not found\n", member); } } else { - if (G.debug & G_DEBUG_PYTHON) { - printf("PyContext '%s' found\n", member); - } + CLOG_INFO(BPY_LOG_CONTEXT, 2, "'%s' found", member); } if (use_gil) diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 2aff61dc2b8..a0009d407dc 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -45,6 +45,7 @@ #include "BLI_utildefines.h" #include "BPY_extern.h" +#include "BPY_extern_clog.h" #include "bpy_rna.h" #include "bpy_rna_anim.h" @@ -61,6 +62,8 @@ #include "RNA_define.h" /* RNA_def_property_free_identifier */ #include "RNA_access.h" +#include "CLG_log.h" + #include "MEM_guardedalloc.h" #include "BKE_main.h" @@ -1418,10 +1421,11 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val) const char *ptr_name = RNA_struct_name_get_alloc(ptr, NULL, 0, NULL); /* prefer not fail silently in case of api errors, maybe disable it later */ - printf("RNA Warning: Current value \"%d\" " - "matches no enum in '%s', '%s', '%s'\n", - val, RNA_struct_identifier(ptr->type), - ptr_name, RNA_property_identifier(prop)); + CLOG_WARN(BPY_LOG_RNA, + "Current value \"%d\" " + "matches no enum in '%s', '%s', '%s'\n", + val, RNA_struct_identifier(ptr->type), + ptr_name, RNA_property_identifier(prop)); #if 0 /* gives python decoding errors while generating docs :( */ char error_str[256]; @@ -6605,7 +6609,7 @@ static PyObject *pyrna_srna_ExternalType(StructRNA *srna) if (bpy_types == NULL) { PyErr_Print(); PyErr_Clear(); - fprintf(stderr, "%s: failed to find 'bpy_types' module\n", __func__); + CLOG_ERROR(BPY_LOG_RNA, "failed to find 'bpy_types' module\n"); return NULL; } bpy_types_dict = PyModule_GetDict(bpy_types); /* borrow */ @@ -6623,20 +6627,22 @@ static PyObject *pyrna_srna_ExternalType(StructRNA *srna) PyObject *tp_slots = PyDict_GetItem(((PyTypeObject *)newclass)->tp_dict, bpy_intern_str___slots__); if (tp_slots == NULL) { - fprintf(stderr, "%s: expected class '%s' to have __slots__ defined\n\nSee bpy_types.py\n", __func__, idname); + CLOG_ERROR(BPY_LOG_RNA, "expected class '%s' to have __slots__ defined, see bpy_types.py\n", idname); newclass = NULL; } else if (PyTuple_GET_SIZE(tp_bases)) { PyObject *base = PyTuple_GET_ITEM(tp_bases, 0); if (base_compare != base) { - fprintf(stderr, "%s: incorrect subclassing of SRNA '%s'\nSee bpy_types.py\n", __func__, idname); - PyC_ObSpit("Expected! ", base_compare); + char pyob_info[256]; + PyC_ObSpitStr(pyob_info, sizeof(pyob_info), base_compare); + CLOG_ERROR(BPY_LOG_RNA, + "incorrect subclassing of SRNA '%s', expected '%s', see bpy_types.py\n", + idname, pyob_info); newclass = NULL; } else { - if (G.debug & G_DEBUG_PYTHON) - fprintf(stderr, "SRNA Subclassed: '%s'\n", idname); + CLOG_INFO(BPY_LOG_RNA, 2, "SRNA sub-classed: '%s'\n", idname); } } } @@ -6734,7 +6740,7 @@ static PyObject *pyrna_srna_Subtype(StructRNA *srna) } else { /* this should not happen */ - printf("%s: error registering '%s'\n", __func__, idname); + CLOG_ERROR(BPY_LOG_RNA, "error registering '%s'", idname); PyErr_Print(); PyErr_Clear(); } @@ -6800,7 +6806,7 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) Py_DECREF(tp); /* srna owns, cant hold a ref */ } else { - fprintf(stderr, "%s: could not make type\n", __func__); + CLOG_WARN(BPY_LOG_RNA, "could not make type '%s'", RNA_struct_identifier(ptr->type)); pyrna = (BPy_StructRNA *) PyObject_GC_New(BPy_StructRNA, &pyrna_struct_Type); #ifdef USE_WEAKREFS pyrna->in_weakreflist = NULL; @@ -7607,8 +7613,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param py_class = RNA_struct_py_type_get(ptr->type); /* rare case. can happen when registering subclasses */ if (py_class == NULL) { - fprintf(stderr, "%s: unable to get python class for rna struct '%.200s'\n", - __func__, RNA_struct_identifier(ptr->type)); + CLOG_WARN(BPY_LOG_RNA, "unable to get Python class for rna struct '%.200s'\n", RNA_struct_identifier(ptr->type)); return -1; } diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c index e0ca3634261..ed9d1e9c0e5 100644 --- a/source/blender/python/intern/bpy_rna_array.c +++ b/source/blender/python/intern/bpy_rna_array.c @@ -28,6 +28,8 @@ #include <Python.h> +#include "CLG_log.h" + #include "BLI_utildefines.h" #include "RNA_types.h" @@ -39,6 +41,8 @@ #include "RNA_access.h" +#include "BPY_extern_clog.h" + #include "../generic/py_capi_utils.h" #define USE_MATHUTILS @@ -785,8 +789,7 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, len = RNA_property_multi_array_length(ptr, prop, arraydim); if (index >= len || index < 0) { /* this shouldn't happen because higher level funcs must check for invalid index */ - if (G.debug & G_DEBUG_PYTHON) - printf("%s: invalid index %d for array with length=%d\n", __func__, index, len); + CLOG_WARN(BPY_LOG_RNA, "invalid index %d for array with length=%d", index, len); PyErr_SetString(PyExc_IndexError, "out of range"); return NULL; diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 4a4a993b386..33bbb624192 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -69,6 +69,7 @@ #include "ED_screen.h" #include "ED_view3d.h" #include "ED_util.h" +#include "ED_undo.h" #include "RNA_access.h" diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index bb9ff0ab8eb..897a6308dd3 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -106,6 +106,7 @@ #include "ED_screen.h" #include "ED_view3d.h" #include "ED_util.h" +#include "ED_undo.h" #include "GHOST_C-api.h" #include "GHOST_Path-api.h" diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 534b20ff22e..4c7c2cc96e4 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -114,6 +114,7 @@ #include "ED_space_api.h" #include "ED_screen.h" #include "ED_util.h" +#include "ED_undo.h" #include "UI_interface.h" #include "BLF_api.h" diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index ebe68bc8f35..e19ec6ca265 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -99,7 +99,7 @@ #include "ED_numinput.h" #include "ED_screen.h" -#include "ED_util.h" +#include "ED_undo.h" #include "ED_view3d.h" #include "RNA_access.h" |