Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-08-10 18:26:37 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-08-10 18:45:16 +0300
commit8d37aaeca1f9dc74224da378cecd392fd1cf361b (patch)
tree29729f23ebaa74f607ad6ec4e260112fee924b27 /source/blender
parent8f837e0ac586fb010c7c6133ddbdc09546f7f851 (diff)
Data previews: add utils to generate/clear previews.
Not much to add, you can now clear previews from current .blend file, or a set of non-opened files. Likewise, you can generate previews (for mat/tex, objects, groups, scenes, ...).
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_idcode.h3
-rw-r--r--source/blender/blenkernel/intern/idcode.c84
-rw-r--r--source/blender/editors/include/UI_interface_icons.h5
-rw-r--r--source/blender/editors/interface/interface_icons.c66
-rw-r--r--source/blender/makesdna/DNA_ID.h35
-rw-r--r--source/blender/makesrna/intern/rna_ID.c21
-rw-r--r--source/blender/python/intern/bpy_app.c15
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c68
8 files changed, 291 insertions, 6 deletions
diff --git a/source/blender/blenkernel/BKE_idcode.h b/source/blender/blenkernel/BKE_idcode.h
index 420df77ff1e..ebad0d42232 100644
--- a/source/blender/blenkernel/BKE_idcode.h
+++ b/source/blender/blenkernel/BKE_idcode.h
@@ -39,6 +39,9 @@ int BKE_idcode_from_name(const char *name);
bool BKE_idcode_is_linkable(int code);
bool BKE_idcode_is_valid(int code);
+int BKE_idcode_to_idfilter(const int idcode);
+int BKE_idcode_from_idfilter(const int idfilter);
+
/**
* Return an ID code and steps the index forward 1.
*
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index 091d8a6ea17..3101d7874a6 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -166,6 +166,90 @@ int BKE_idcode_from_name(const char *name)
}
/**
+ * Convert an idcode into an idfilter (e.g. ID_OB -> FILTER_ID_OB).
+ */
+int BKE_idcode_to_idfilter(const int idcode)
+{
+#define CASE_IDFILTER(_id) case ID_##_id: return FILTER_ID_##_id
+
+ switch (idcode) {
+ CASE_IDFILTER(AC);
+ CASE_IDFILTER(AR);
+ CASE_IDFILTER(BR);
+ CASE_IDFILTER(CA);
+ CASE_IDFILTER(CU);
+ CASE_IDFILTER(GD);
+ CASE_IDFILTER(GR);
+ CASE_IDFILTER(IM);
+ CASE_IDFILTER(LA);
+ CASE_IDFILTER(LS);
+ CASE_IDFILTER(LT);
+ CASE_IDFILTER(MA);
+ CASE_IDFILTER(MB);
+ CASE_IDFILTER(MC);
+ CASE_IDFILTER(ME);
+ CASE_IDFILTER(MSK);
+ CASE_IDFILTER(NT);
+ CASE_IDFILTER(OB);
+ CASE_IDFILTER(PAL);
+ CASE_IDFILTER(PC);
+ CASE_IDFILTER(SCE);
+ CASE_IDFILTER(SPK);
+ CASE_IDFILTER(SO);
+ CASE_IDFILTER(TE);
+ CASE_IDFILTER(TXT);
+ CASE_IDFILTER(VF);
+ CASE_IDFILTER(WO);
+ default:
+ return 0;
+ }
+
+#undef CASE_IDFILTER
+}
+
+/**
+ * Convert an idfilter into an idcode (e.g. FILTER_ID_OB -> ID_OB).
+ */
+int BKE_idcode_from_idfilter(const int idfilter)
+{
+#define CASE_IDFILTER(_id) case FILTER_ID_##_id: return ID_##_id
+
+ switch (idfilter) {
+ CASE_IDFILTER(AC);
+ CASE_IDFILTER(AR);
+ CASE_IDFILTER(BR);
+ CASE_IDFILTER(CA);
+ CASE_IDFILTER(CU);
+ CASE_IDFILTER(GD);
+ CASE_IDFILTER(GR);
+ CASE_IDFILTER(IM);
+ CASE_IDFILTER(LA);
+ CASE_IDFILTER(LS);
+ CASE_IDFILTER(LT);
+ CASE_IDFILTER(MA);
+ CASE_IDFILTER(MB);
+ CASE_IDFILTER(MC);
+ CASE_IDFILTER(ME);
+ CASE_IDFILTER(MSK);
+ CASE_IDFILTER(NT);
+ CASE_IDFILTER(OB);
+ CASE_IDFILTER(PAL);
+ CASE_IDFILTER(PC);
+ CASE_IDFILTER(SCE);
+ CASE_IDFILTER(SPK);
+ CASE_IDFILTER(SO);
+ CASE_IDFILTER(TE);
+ CASE_IDFILTER(TXT);
+ CASE_IDFILTER(VF);
+ CASE_IDFILTER(WO);
+ default:
+ return 0;
+ }
+
+#undef CASE_IDFILTER
+}
+
+/**
* Convert an idcode into a name (plural).
*
* \param code The code to convert.
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index 634dd3d5bbc..945ac1b6db9 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -34,9 +34,12 @@
struct bContext;
struct ID;
+struct Scene;
struct PreviewImage;
struct PointerRNA;
+enum eIconSizes;
+
typedef struct IconFile {
struct IconFile *next, *prev;
char filename[256]; /* FILE_MAXFILE size */
@@ -60,6 +63,7 @@ int UI_icon_get_height(int icon_id);
void UI_id_icon_render(
const struct bContext *C, struct Scene *scene, struct ID *id, const bool big, const bool use_job);
+int UI_preview_render_size(enum eIconSizes size);
void UI_icon_draw(float x, float y, int icon_id);
void UI_icon_draw_preview(float x, float y, int icon_id);
@@ -78,5 +82,6 @@ int UI_iconfile_get_index(const char *filename);
struct PreviewImage *UI_icon_to_preview(int icon_id);
int UI_rnaptr_icon_get(struct bContext *C, struct PointerRNA *ptr, int rnaicon, const bool big);
+int UI_idcode_icon_get(const int idcode);
#endif /* __UI_INTERFACE_ICONS_H__ */
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index db1eacf57dc..95139c5656e 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -900,7 +900,7 @@ void UI_icons_init(int first_dyn_id)
/* Render size for preview images and icons
*/
-static int preview_render_size(enum eIconSizes size)
+int UI_preview_render_size(enum eIconSizes size)
{
switch (size) {
case ICON_SIZE_ICON:
@@ -916,7 +916,7 @@ static int preview_render_size(enum eIconSizes size)
*/
static void icon_create_rect(struct PreviewImage *prv_img, enum eIconSizes size)
{
- unsigned int render_size = preview_render_size(size);
+ unsigned int render_size = UI_preview_render_size(size);
if (!prv_img) {
if (G.debug & G_DEBUG)
@@ -1399,6 +1399,68 @@ int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, const bool big
return rnaicon;
}
+int UI_idcode_icon_get(const int idcode)
+{
+ switch (idcode) {
+ case ID_AC:
+ return ICON_ANIM_DATA;
+ case ID_AR:
+ return ICON_ARMATURE_DATA;
+ case ID_BR:
+ return ICON_BRUSH_DATA;
+ case ID_CA:
+ return ICON_CAMERA_DATA;
+ case ID_CU:
+ return ICON_CURVE_DATA;
+ case ID_GD:
+ return ICON_GREASEPENCIL;
+ case ID_GR:
+ return ICON_GROUP;
+ case ID_IM:
+ return ICON_IMAGE_DATA;
+ case ID_LA:
+ return ICON_LAMP_DATA;
+ case ID_LS:
+ return ICON_LINE_DATA;
+ case ID_LT:
+ return ICON_LATTICE_DATA;
+ case ID_MA:
+ return ICON_MATERIAL_DATA;
+ case ID_MB:
+ return ICON_META_DATA;
+ case ID_MC:
+ return ICON_CLIP;
+ case ID_ME:
+ return ICON_MESH_DATA;
+ case ID_MSK:
+ return ICON_MOD_MASK; /* TODO! this would need its own icon! */
+ case ID_NT:
+ return ICON_NODETREE;
+ case ID_OB:
+ return ICON_OBJECT_DATA;
+ case ID_PAL:
+ return ICON_COLOR; /* TODO! this would need its own icon! */
+ case ID_PC:
+ return ICON_CURVE_BEZCURVE; /* TODO! this would need its own icon! */
+ case ID_SCE:
+ return ICON_SCENE_DATA;
+ case ID_SPK:
+ return ICON_SPEAKER;
+ case ID_SO:
+ return ICON_SOUND;
+ case ID_TE:
+ return ICON_TEXTURE_DATA;
+ case ID_TXT:
+ return ICON_TEXT;
+ case ID_VF:
+ return ICON_FONT_DATA;
+ case ID_WO:
+ return ICON_WORLD_DATA;
+ default:
+ return ICON_NONE;
+ }
+}
+
static void icon_draw_at_size(
float x, float y, int icon_id, float aspect, float alpha,
enum eIconSizes size, const bool nocreate)
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 6b9de26f0a4..88e728c0e37 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -290,6 +290,41 @@ enum {
LIB_ID_RECALC_ALL = (LIB_ID_RECALC | LIB_ID_RECALC_DATA),
};
+/* To filter ID types (filter_id) */
+/* XXX We cannot put all needed IDs inside an enum...
+ * We'll have to see whether we can fit all needed ones inside 32 values,
+ * or if we need to fallback to longlong defines :/
+ */
+enum {
+ FILTER_ID_AC = (1 << 0),
+ FILTER_ID_AR = (1 << 1),
+ FILTER_ID_BR = (1 << 2),
+ FILTER_ID_CA = (1 << 3),
+ FILTER_ID_CU = (1 << 4),
+ FILTER_ID_GD = (1 << 5),
+ FILTER_ID_GR = (1 << 6),
+ FILTER_ID_IM = (1 << 7),
+ FILTER_ID_LA = (1 << 8),
+ FILTER_ID_LS = (1 << 9),
+ FILTER_ID_LT = (1 << 10),
+ FILTER_ID_MA = (1 << 11),
+ FILTER_ID_MB = (1 << 12),
+ FILTER_ID_MC = (1 << 13),
+ FILTER_ID_ME = (1 << 14),
+ FILTER_ID_MSK = (1 << 15),
+ FILTER_ID_NT = (1 << 16),
+ FILTER_ID_OB = (1 << 17),
+ FILTER_ID_PAL = (1 << 18),
+ FILTER_ID_PC = (1 << 19),
+ FILTER_ID_SCE = (1 << 20),
+ FILTER_ID_SPK = (1 << 21),
+ FILTER_ID_SO = (1 << 22),
+ FILTER_ID_TE = (1 << 23),
+ FILTER_ID_TXT = (1 << 24),
+ FILTER_ID_VF = (1 << 25),
+ FILTER_ID_WO = (1 << 26),
+};
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 65db92ab9e6..19b5a1b8219 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -472,14 +472,14 @@ static void rna_ImagePreview_size_set(PointerRNA *ptr, const int *values, enum e
BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
}
- BKE_previewimg_ensure(prv_img, size);
+ BKE_previewimg_clear_single(prv_img, size);
if (values[0] && values[1]) {
prv_img->rect[size] = MEM_callocN(values[0] * values[1] * sizeof(unsigned int), "prv_rect");
- }
- prv_img->w[size] = values[0];
- prv_img->h[size] = values[1];
+ prv_img->w[size] = values[0];
+ prv_img->h[size] = values[1];
+ }
prv_img->flag[size] |= (PRV_CHANGED | PRV_USER_EDITED);
}
@@ -600,6 +600,14 @@ static void rna_ImagePreview_icon_reload(PreviewImage *prv)
}
}
+static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
+{
+ ID *id = (ID *)ptr->data;
+ PreviewImage *prv_img = BKE_previewimg_id_ensure(id);
+
+ return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
+}
+
#else
static void rna_def_ID_properties(BlenderRNA *brna)
@@ -840,6 +848,11 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Library", "Library file the datablock is linked from");
+ prop = RNA_def_pointer(srna, "preview", "ImagePreview", "Preview",
+ "Preview image and icon of this datablock (None if not supported for this type of data)");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_pointer_funcs(prop, "rna_IDPreview_get", NULL, NULL, NULL);
+
/* functions */
func = RNA_def_function(srna, "copy", "rna_ID_copy");
RNA_def_function_ui_description(func, "Create a copy of this datablock (not supported for all datablocks)");
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 1cf0c44fd87..90d97cad880 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -50,6 +50,10 @@
#include "BKE_blender.h"
#include "BKE_global.h"
+#include "DNA_ID.h"
+
+#include "UI_interface_icons.h"
+
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
@@ -298,6 +302,14 @@ static PyObject *bpy_app_driver_dict_get(PyObject *UNUSED(self), void *UNUSED(cl
return Py_INCREF_RET(bpy_pydriver_Dict);
}
+PyDoc_STRVAR(bpy_app_preview_render_size_doc,
+"Reference size for icon/preview renders (read-only)"
+);
+static PyObject *bpy_app_preview_render_size_get(PyObject *UNUSED(self), void *closure)
+{
+ return PyLong_FromLong((long)UI_preview_render_size(GET_INT_FROM_POINTER(closure)));
+}
+
static PyObject *bpy_app_autoexec_fail_message_get(PyObject *UNUSED(self), void *UNUSED(closure))
{
return PyC_UnicodeFromByte(G.autoexec_fail);
@@ -322,6 +334,9 @@ static PyGetSetDef bpy_app_getsets[] = {
{(char *)"tempdir", bpy_app_tempdir_get, NULL, (char *)bpy_app_tempdir_doc, NULL},
{(char *)"driver_namespace", bpy_app_driver_dict_get, NULL, (char *)bpy_app_driver_dict_doc, NULL},
+ {(char *)"render_icon_size", bpy_app_preview_render_size_get, NULL, (char *)bpy_app_preview_render_size_doc, (void *)ICON_SIZE_ICON},
+ {(char *)"render_preview_size", bpy_app_preview_render_size_get, NULL, (char *)bpy_app_preview_render_size_doc, (void *)ICON_SIZE_PREVIEW},
+
/* security */
{(char *)"autoexec_fail", bpy_app_global_flag_get, NULL, NULL, (void *)G_SCRIPT_AUTOEXEC_FAIL},
{(char *)"autoexec_fail_quiet", bpy_app_global_flag_get, NULL, NULL, (void *)G_SCRIPT_AUTOEXEC_FAIL_QUIET},
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 37d434faa6e..1455b7000e9 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -74,6 +74,7 @@
#include "BKE_brush.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
+#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
#include "BKE_library.h"
@@ -4897,6 +4898,72 @@ static void WM_OT_previews_ensure(wmOperatorType *ot)
ot->exec = previews_ensure_exec;
}
+/* *************************** Datablocks previews clear ************* */
+
+/* Only types supporting previews currently. */
+static EnumPropertyItem preview_id_type_items[] = {
+ {FILTER_ID_SCE, "SCENE", 0, "Scenes", ""},
+ {FILTER_ID_GR, "GROUP", 0, "Groups", ""},
+ {FILTER_ID_OB, "OBJECT", 0, "Objects", ""},
+ {FILTER_ID_MA, "MATERIAL", 0, "Materials", ""},
+ {FILTER_ID_LA, "LAMP", 0, "Lamps", ""},
+ {FILTER_ID_WO, "WORLD", 0, "Worlds", ""},
+ {FILTER_ID_TE, "TEXTURE", 0, "Textures", ""},
+ {FILTER_ID_IM, "IMAGE", 0, "Images", ""},
+#if 0 /* XXX TODO */
+ {FILTER_ID_BR, "BRUSH", 0, "Brushes", ""},
+#endif
+ {0, NULL, 0, NULL, NULL}
+};
+
+static int previews_clear_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ ListBase *lb[] = {&bmain->object, &bmain->group,
+ &bmain->mat, &bmain->world, &bmain->lamp, &bmain->tex, &bmain->image, NULL};
+ int i;
+
+ const int id_filters = RNA_enum_get(op->ptr, "id_type");
+
+ for (i = 0; lb[i]; i++) {
+ ID *id = lb[i]->first;
+
+ if (!id) continue;
+
+// printf("%s: %d, %d, %d -> %d\n", id->name, GS(id->name), BKE_idcode_to_idfilter(GS(id->name)),
+// id_filters, BKE_idcode_to_idfilter(GS(id->name)) & id_filters);
+
+ if (!id || !(BKE_idcode_to_idfilter(GS(id->name)) & id_filters)) {
+ continue;
+ }
+
+ for (; id; id = id->next) {
+ PreviewImage *prv_img = BKE_previewimg_id_ensure(id);
+
+ BKE_previewimg_clear(prv_img);
+ }
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static void WM_OT_previews_clear(wmOperatorType *ot)
+{
+ ot->name = "Clear DataBlock Previews";
+ ot->idname = "WM_OT_previews_clear";
+ ot->description = "Clear datablock previews (only for some types like objects, materials, textures, etc.)";
+
+ ot->exec = previews_clear_exec;
+ ot->invoke = WM_menu_invoke;
+
+ ot->prop = RNA_def_enum_flag(ot->srna, "id_type", preview_id_type_items,
+ FILTER_ID_SCE | FILTER_ID_OB | FILTER_ID_GR |
+ FILTER_ID_MA | FILTER_ID_LA | FILTER_ID_WO | FILTER_ID_TE | FILTER_ID_IM,
+ "DataBlock Type", "Which datablock previews to clear");
+}
+
+/* *************************** Doc from UI ************* */
+
static int doc_view_manual_ui_context_exec(bContext *C, wmOperator *UNUSED(op))
{
PointerRNA ptr_props;
@@ -5025,6 +5092,7 @@ void wm_operatortype_init(void)
WM_operatortype_append(WM_OT_console_toggle);
#endif
WM_operatortype_append(WM_OT_previews_ensure);
+ WM_operatortype_append(WM_OT_previews_clear);
WM_operatortype_append(WM_OT_doc_view_manual_ui_context);
}