diff options
author | Nick Samarin <nicks1987@bigmir.net> | 2011-02-16 20:07:18 +0300 |
---|---|---|
committer | Nick Samarin <nicks1987@bigmir.net> | 2011-02-16 20:07:18 +0300 |
commit | c5f6a01dd5998976addd2085470bb73a150579e5 (patch) | |
tree | 42b3345fb3ea2e7607a6d1eec379b8ce23b5ffbc /source/blender/editors/util | |
parent | 4cf62f1e7e2bb28b47f79e4bd7c1482ab742ebbd (diff) | |
parent | 9e9e028f059f29d493dc020dda965a9bea8ffd6b (diff) |
synched with trunk at revision 34793
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/CMakeLists.txt | 60 | ||||
-rw-r--r-- | source/blender/editors/util/Makefile | 54 | ||||
-rw-r--r-- | source/blender/editors/util/SConscript | 2 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 100 | ||||
-rw-r--r-- | source/blender/editors/util/editmode_undo.c | 35 | ||||
-rw-r--r-- | source/blender/editors/util/numinput.c | 1 | ||||
-rw-r--r-- | source/blender/editors/util/undo.c | 115 | ||||
-rw-r--r-- | source/blender/editors/util/util_intern.h | 1 |
8 files changed, 290 insertions, 78 deletions
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index a67be4631de..221a65620dd 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -19,9 +19,7 @@ # # ***** END GPL LICENSE BLOCK ***** -FILE(GLOB SRC *.c *.cpp) - -SET(INC +set(INC ../include ../../blenkernel ../../blenlib @@ -32,4 +30,58 @@ SET(INC ../../../../intern/guardedalloc ) -BLENDERLIB(bf_editor_util "${SRC}" "${INC}") +set(SRC + ed_util.c + editmode_undo.c + numinput.c + undo.c + navmesh_conversion.cpp + + util_intern.h + # general includes + ../include/BIF_gl.h + ../include/BIF_glutil.h + ../include/ED_anim_api.h + ../include/ED_armature.h + ../include/ED_curve.h + ../include/ED_datafiles.h + ../include/ED_fileselect.h + ../include/ED_fluidsim.h + ../include/ED_gpencil.h + ../include/ED_image.h + ../include/ED_info.h + ../include/ED_keyframes_draw.h + ../include/ED_keyframes_edit.h + ../include/ED_keyframing.h + ../include/ED_lattice.h + ../include/ED_logic.h + ../include/ED_markers.h + ../include/ED_mball.h + ../include/ED_mesh.h + ../include/ED_navmesh_conversion.h + ../include/ED_node.h + ../include/ED_numinput.h + ../include/ED_object.h + ../include/ED_particle.h + ../include/ED_physics.h + ../include/ED_render.h + ../include/ED_screen.h + ../include/ED_screen_types.h + ../include/ED_sculpt.h + ../include/ED_sequencer.h + ../include/ED_sound.h + ../include/ED_space_api.h + ../include/ED_text.h + ../include/ED_transform.h + ../include/ED_types.h + ../include/ED_util.h + ../include/ED_uvedit.h + ../include/ED_view3d.h + ../include/UI_icons.h + ../include/UI_interface.h + ../include/UI_interface_icons.h + ../include/UI_resources.h + ../include/UI_view2d.h +) + +blender_add_lib(bf_editor_util "${SRC}" "${INC}") diff --git a/source/blender/editors/util/Makefile b/source/blender/editors/util/Makefile deleted file mode 100644 index 8535b3fb402..00000000000 --- a/source/blender/editors/util/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -# -# $Id$ -# -# ***** 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) 2007 Blender Foundation -# All rights reserved. -# -# The Original Code is: all of this file. -# -# Contributor(s): none yet. -# -# ***** END GPL LICENSE BLOCK ***** -# -# Makes module object directory and bounces make to subdirectories. - -LIBNAME = ed_util -DIR = $(OCGDIR)/blender/$(LIBNAME) - -include nan_compile.mk - -CFLAGS += $(LEVEL_1_C_WARNINGS) - -CPPFLAGS += -I$(NAN_GLEW)/include -CPPFLAGS += -I$(OPENGL_HEADERS) - -# not very neat.... -CPPFLAGS += -I../../windowmanager -CPPFLAGS += -I../../blenloader -CPPFLAGS += -I../../blenkernel -CPPFLAGS += -I../../blenlib -CPPFLAGS += -I../../makesdna -CPPFLAGS += -I../../makesrna -CPPFLAGS += -I../../imbuf -CPPFLAGS += -I../../python -CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include - -# own include - -CPPFLAGS += -I../include diff --git a/source/blender/editors/util/SConscript b/source/blender/editors/util/SConscript index 810874da865..ab48dd79e20 100644 --- a/source/blender/editors/util/SConscript +++ b/source/blender/editors/util/SConscript @@ -8,4 +8,4 @@ incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include' incs += ' ../../makesrna' incs += ' #extern/recastnavigation/Recast/Include' -env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core'], priority=[130] ) +env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core','player'], priority=[130,210] ) diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 0d3d8a48b60..081bda60ba2 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -27,18 +27,23 @@ */ #include <stdlib.h> +#include <string.h> #include <math.h> #include "MEM_guardedalloc.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_packedFile_types.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BKE_main.h" +#include "BKE_utildefines.h" +#include "BKE_packedFile.h" #include "ED_armature.h" #include "ED_mesh.h" @@ -48,6 +53,11 @@ #include "UI_interface.h" +#include "WM_types.h" +#include "RNA_access.h" + + + /* ********* general editor util funcs, not BKE stuff please! ********* */ void ED_editors_init(bContext *C) @@ -152,7 +162,7 @@ void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, fl } -int GetButStringLength(char *str) +int GetButStringLength(const char *str) { int rt; @@ -161,3 +171,91 @@ int GetButStringLength(char *str) return rt + 15; } + +void unpack_menu(bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, struct PackedFile *pf) +{ + PointerRNA props_ptr; + uiPopupMenu *pup; + uiLayout *layout; + char line[FILE_MAXDIR + FILE_MAXFILE + 100]; + + pup= uiPupMenuBegin(C, "Unpack file", ICON_NULL); + layout= uiPupMenuLayout(pup); + + sprintf(line, "Remove Pack"); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_REMOVE); + RNA_string_set(&props_ptr, "id", id_name); + + if(G.relbase_valid) { + char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; + + BLI_strncpy(local_name, abs_name, sizeof(local_name)); + BLI_splitdirstring(local_name, fi); + sprintf(local_name, "//%s/%s", folder, fi); + if(strcmp(abs_name, local_name)!=0) { + switch(checkPackedFile(local_name, pf)) { + case PF_NOFILE: + sprintf(line, "Create %s", local_name); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + + break; + case PF_EQUAL: + sprintf(line, "Use %s (identical)", local_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + + break; + case PF_DIFFERS: + sprintf(line, "Use %s (differs)", local_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + + sprintf(line, "Overwrite %s", local_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + } + } + } + + switch(checkPackedFile(abs_name, pf)) { + case PF_NOFILE: + sprintf(line, "Create %s", abs_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + case PF_EQUAL: + sprintf(line, "Use %s (identical)", abs_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + case PF_DIFFERS: + sprintf(line, "Use %s (differs)", abs_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + + sprintf(line, "Overwrite %s", abs_name); + //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); + props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); + RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); + RNA_string_set(&props_ptr, "id", id_name); + break; + } + + uiPupMenuEnd(C, pup); +} diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index 290c8a64881..85f343e3311 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -37,14 +37,15 @@ #include "DNA_object_types.h" #include "DNA_screen_types.h" -#include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_global.h" - #include "BLI_blenlib.h" #include "BLI_dynstr.h" +#include "BLI_utildefines.h" +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_global.h" + #include "ED_mesh.h" #include "UI_interface.h" @@ -55,7 +56,7 @@ Add this in your local code: -void undo_editmode_push(bContext *C, char *name, +void undo_editmode_push(bContext *C, const char *name, void * (*getdata)(bContext *C), // use context to retrieve current editdata void (*freedata)(void *), // pointer to function freeing data void (*to_editmode)(void *, void *), // data to editmode conversion @@ -74,7 +75,7 @@ void undo_editmode_menu(void) // history menu /* ********************************************************************* */ /* ****** XXX ***** */ -void error(const char *dummy) {} +void error(const char *UNUSED(arg)) {} /* ****** XXX ***** */ @@ -108,7 +109,7 @@ static void undo_restore(UndoElem *undo, void *editdata) } /* name can be a dynamic string */ -void undo_editmode_push(bContext *C, char *name, +void undo_editmode_push(bContext *C, const char *name, void * (*getdata)(bContext *C), void (*freedata)(void *), void (*to_editmode)(void *, void *), @@ -268,7 +269,7 @@ void undo_editmode_step(bContext *C, int step) EM_selectmode_to_scene(CTX_data_scene(C), obedit); } - DAG_id_flush_update(&obedit->id, OB_RECALC_DATA); + DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); /* XXX notifiers */ } @@ -313,6 +314,20 @@ void undo_editmode_name(bContext *C, const char *undoname) } } +/* undoname optionally, if NULL it just checks for existing undo steps */ +int undo_editmode_valid(const char *undoname) +{ + if(undoname) { + UndoElem *uel; + + for(uel= undobase.last; uel; uel= uel->prev) { + if(strcmp(undoname, uel->name)==0) + break; + } + return uel != NULL; + } + return undobase.last != undobase.first; +} /* ************** for interaction with menu/pullown */ @@ -341,7 +356,7 @@ void undo_editmode_menu(bContext *C) if(event>0) undo_number(C, event); } -static void do_editmode_undohistorymenu(bContext *C, void *arg, int event) +static void do_editmode_undohistorymenu(bContext *C, void *UNUSED(arg), int event) { Object *obedit= CTX_data_edit_object(C); @@ -351,7 +366,7 @@ static void do_editmode_undohistorymenu(bContext *C, void *arg, int event) } -uiBlock *editmode_undohistorymenu(bContext *C, ARegion *ar, void *arg_unused) +uiBlock *editmode_undohistorymenu(bContext *C, ARegion *ar, void *UNUSED(arg)) { uiBlock *block; UndoElem *uel; diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index 868aa8ac6af..ccdbe7dfd4e 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -30,6 +30,7 @@ #include <math.h> /* fabs */ #include <stdio.h> /* for sprintf */ +#include "BLI_utildefines.h" #include "WM_types.h" diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index e5128ea784a..0158719b2fb 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -36,13 +36,15 @@ #include "DNA_object_types.h" -#include "BKE_blender.h" -#include "BKE_context.h" - #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_dynstr.h" +#include "BLI_utildefines.h" +#include "BKE_blender.h" +#include "BKE_context.h" +#include "BKE_global.h" +#include "BKE_screen.h" #include "ED_armature.h" #include "ED_particle.h" @@ -63,7 +65,7 @@ /* ***************** generic undo system ********************* */ -void ED_undo_push(bContext *C, char *str) +void ED_undo_push(bContext *C, const char *str) { wmWindowManager *wm= CTX_wm_manager(C); Object *obedit= CTX_data_edit_object(C); @@ -156,9 +158,10 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) if(do_glob_undo) { if(U.uiflag & USER_GLOBALUNDO) { -#ifndef DISABLE_PYTHON + // note python defines not valid here anymore. + //#ifdef WITH_PYTHON // XXX BPY_scripts_clear_pyobjects(); -#endif + //#endif if(undoname) BKE_undo_name(C, undoname); else @@ -196,14 +199,60 @@ void ED_undo_pop_op(bContext *C, wmOperator *op) ed_undo_step(C, 0, op->type->name); } -static int ed_undo_exec(bContext *C, wmOperator *op) +/* name optionally, function used to check for operator redo panel */ +int ED_undo_valid(const bContext *C, const char *undoname) +{ + Object *obedit= CTX_data_edit_object(C); + Object *obact= CTX_data_active_object(C); + ScrArea *sa= CTX_wm_area(C); + + if(sa && sa->spacetype==SPACE_IMAGE) { + SpaceImage *sima= (SpaceImage *)sa->spacedata.first; + + if((obact && obact->mode & OB_MODE_TEXTURE_PAINT) || sima->flag & SI_DRAWTOOL) { + return 1; + } + } + + if(sa && sa->spacetype==SPACE_TEXT) { + return 1; + } + else if(obedit) { + if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE) { + return undo_editmode_valid(undoname); + } + } + else { + + /* if below tests fail, global undo gets executed */ + + if(obact && obact->mode & OB_MODE_TEXTURE_PAINT) { + if( ED_undo_paint_valid(UNDO_PAINT_IMAGE, undoname) ) + return 1; + } + else if(obact && obact->mode & OB_MODE_SCULPT) { + if( ED_undo_paint_valid(UNDO_PAINT_MESH, undoname) ) + return 1; + } + else if(obact && obact->mode & OB_MODE_PARTICLE_EDIT) { + return PE_undo_valid(CTX_data_scene(C)); + } + + if(U.uiflag & USER_GLOBALUNDO) { + return BKE_undo_valid(undoname); + } + } + return 0; +} + +static int ed_undo_exec(bContext *C, wmOperator *UNUSED(op)) { /* "last operator" should disappear, later we can tie ths with undo stack nicer */ WM_operator_stack_clear(C); return ed_undo_step(C, 1, NULL); } -static int ed_redo_exec(bContext *C, wmOperator *op) +static int ed_redo_exec(bContext *C, wmOperator *UNUSED(op)) { return ed_undo_step(C, -1, NULL); } @@ -260,3 +309,53 @@ void ED_OT_redo(wmOperatorType *ot) } +/* ui callbacks should call this rather then calling WM_operator_repeat() themselves */ +int ED_undo_operator_repeat(bContext *C, struct wmOperator *op) +{ + int ret= 0; + + if(op) { + ARegion *ar= CTX_wm_region(C); + ARegion *ar1= BKE_area_find_region_type(CTX_wm_area(C), RGN_TYPE_WINDOW); + + if(ar1) + CTX_wm_region_set(C, ar1); + + if(WM_operator_repeat_check(C, op) && WM_operator_poll(C, op->type)) { + int retval; + + if (G.f & G_DEBUG) + printf("redo_cb: operator redo %s\n", op->type->name); + ED_undo_pop_op(C, op); + retval= WM_operator_repeat(C, op); + if((retval & OPERATOR_FINISHED)==0) { + if (G.f & G_DEBUG) + printf("redo_cb: operator redo failed: %s, return %d\n", op->type->name, retval); + ED_undo_redo(C); + } + else { + ret= 1; + } + } + + /* set region back */ + CTX_wm_region_set(C, ar); + } + else { + if (G.f & G_DEBUG) { + printf("redo_cb: WM_operator_repeat_check returned false %s\n", op->type->name); + } + } + + return ret; +} + +void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void *UNUSED(arg_unused)) +{ + ED_undo_operator_repeat(C, (wmOperator *)arg_op); +} + +void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int UNUSED(arg_event)) +{ + ED_undo_operator_repeat(C, (wmOperator *)arg_op); +} diff --git a/source/blender/editors/util/util_intern.h b/source/blender/editors/util/util_intern.h index 73675ab4ef9..b5750c55c87 100644 --- a/source/blender/editors/util/util_intern.h +++ b/source/blender/editors/util/util_intern.h @@ -34,6 +34,7 @@ /* editmode_undo.c */ void undo_editmode_clear(void); void undo_editmode_name(bContext *C, const char *undoname); +int undo_editmode_valid(const char *undoname); #endif /* ED_UTIL_INTERN_H */ |