[Bf-blender-cvs] [45628cc] soc-2016-multiview: make a open secondary clip button
Tianwei Shen
noreply at git.blender.org
Wed Jul 20 13:33:02 CEST 2016
Commit: 45628cc8b6610d955ee453e3b9cfd2590737371a
Author: Tianwei Shen
Date: Wed Jul 20 19:31:41 2016 +0800
Branches: soc-2016-multiview
https://developer.blender.org/rB45628cc8b6610d955ee453e3b9cfd2590737371a
make a open secondary clip button
===================================================================
M release/scripts/startup/bl_ui/space_clip.py
M source/blender/editors/include/ED_clip.h
M source/blender/editors/space_clip/clip_buttons.c
M source/blender/editors/space_clip/clip_editor.c
M source/blender/editors/space_clip/clip_intern.h
M source/blender/editors/space_clip/clip_ops.c
M source/blender/editors/space_clip/space_clip.c
M source/blender/makesdna/DNA_space_types.h
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py
index 662821c..f4d53a2 100644
--- a/release/scripts/startup/bl_ui/space_clip.py
+++ b/release/scripts/startup/bl_ui/space_clip.py
@@ -158,6 +158,9 @@ class CLIP_HT_header(Header):
row = layout.row()
row.template_ID(sc, "clip", open="clip.open")
+ row = layout.row() # clip open for witness camera
+ row.template_ID(sc, "clip", open="clip.open_secondary")
+
if clip:
tracking = clip.tracking
active_object = tracking.objects.active
diff --git a/source/blender/editors/include/ED_clip.h b/source/blender/editors/include/ED_clip.h
index 5085803..631ec98 100644
--- a/source/blender/editors/include/ED_clip.h
+++ b/source/blender/editors/include/ED_clip.h
@@ -79,7 +79,9 @@ bool ED_space_clip_check_show_maskedit(struct SpaceClip *sc);
bool ED_space_clip_check_show_correspondence(struct SpaceClip *sc);
struct MovieClip *ED_space_clip_get_clip(struct SpaceClip *sc);
+struct MovieClip *ED_space_clip_get_secondary_clip(struct SpaceClip *sc);
void ED_space_clip_set_clip(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip);
+void ED_space_clip_set_secondary_clip(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *secondary_clip);
struct Mask *ED_space_clip_get_mask(struct SpaceClip *sc);
void ED_space_clip_set_mask(struct bContext *C, struct SpaceClip *sc, struct Mask *mask);
diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c
index 0378c68..91f28f8 100644
--- a/source/blender/editors/space_clip/clip_buttons.c
+++ b/source/blender/editors/space_clip/clip_buttons.c
@@ -105,8 +105,10 @@ void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const c
uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
- if (!compact)
+ if (!compact) {
uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
+ uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open_secondary", NULL);
+ }
if (clip) {
uiLayout *col;
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index e8cca39..dbc4c2e 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -576,6 +576,11 @@ MovieClip *ED_space_clip_get_clip(SpaceClip *sc)
return sc->clip;
}
+MovieClip *ED_space_clip_get_secondary_clip(SpaceClip *sc)
+{
+ return sc->secondary_clip;
+}
+
void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
{
MovieClip *old_clip;
@@ -623,6 +628,53 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl
WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
}
+void ED_space_clip_set_secondary_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *secondary_clip)
+{
+ MovieClip *old_clip;
+ bool old_clip_visible = false;
+
+ if (!screen && C)
+ screen = CTX_wm_screen(C);
+
+ old_clip = sc->secondary_clip;
+ sc->secondary_clip = secondary_clip;
+
+ id_us_ensure_real((ID *)sc->secondary_clip);
+
+ if (screen && sc->view == SC_VIEW_CLIP) {
+ ScrArea *area;
+ SpaceLink *sl;
+
+ for (area = screen->areabase.first; area; area = area->next) {
+ for (sl = area->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_CLIP) {
+ SpaceClip *cur_sc = (SpaceClip *) sl;
+
+ if (cur_sc != sc) {
+ if (cur_sc->view == SC_VIEW_CLIP) {
+ if (cur_sc->secondary_clip == old_clip)
+ old_clip_visible = true;
+ }
+ else {
+ if (cur_sc->secondary_clip == old_clip || cur_sc->clip == NULL) {
+ cur_sc->secondary_clip = secondary_clip;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* If clip is no longer visible on screen, free memory used by it's cache */
+ if (old_clip && old_clip != secondary_clip && !old_clip_visible) {
+ BKE_movieclip_clear_cache(old_clip);
+ }
+
+ if (C)
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
+}
+
/* ******** masking editing functions ******** */
Mask *ED_space_clip_get_mask(SpaceClip *sc)
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index 76383cb..69f39e1 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -94,6 +94,7 @@ void CLIP_OT_graph_disable_markers(struct wmOperatorType *ot);
/* clip_ops.c */
void CLIP_OT_open(struct wmOperatorType *ot);
+void CLIP_OT_open_secondary(struct wmOperatorType *ot);
void CLIP_OT_reload(struct wmOperatorType *ot);
void CLIP_OT_view_pan(struct wmOperatorType *ot);
void CLIP_OT_view_zoom(wmOperatorType *ot);
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 17cd9be..a7ec849 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -305,6 +305,133 @@ void CLIP_OT_open(wmOperatorType *ot)
WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
}
+/******************** open a secondary clip in Correspondence mode operator ********************/
+static int open_secondary_exec(bContext *C, wmOperator *op)
+{
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ bScreen *screen = CTX_wm_screen(C);
+ Main *bmain = CTX_data_main(C);
+ PropertyPointerRNA *pprop;
+ PointerRNA idptr;
+ MovieClip *clip = NULL;
+ char str[FILE_MAX];
+
+ if (RNA_collection_length(op->ptr, "files")) {
+ PointerRNA fileptr;
+ PropertyRNA *prop;
+ char dir_only[FILE_MAX], file_only[FILE_MAX];
+ bool relative = RNA_boolean_get(op->ptr, "relative_path");
+
+ RNA_string_get(op->ptr, "directory", dir_only);
+ if (relative)
+ BLI_path_rel(dir_only, G.main->name);
+
+ prop = RNA_struct_find_property(op->ptr, "files");
+ RNA_property_collection_lookup_int(op->ptr, prop, 0, &fileptr);
+ RNA_string_get(&fileptr, "name", file_only);
+
+ BLI_join_dirfile(str, sizeof(str), dir_only, file_only);
+ }
+ else {
+ BKE_report(op->reports, RPT_ERROR, "No files selected to be opened");
+
+ return OPERATOR_CANCELLED;
+ }
+
+ /* default to frame 1 if there's no scene in context */
+
+ errno = 0;
+
+ clip = BKE_movieclip_file_add_exists(bmain, str);
+
+ if (!clip) {
+ if (op->customdata)
+ MEM_freeN(op->customdata);
+
+ BKE_reportf(op->reports, RPT_ERROR, "Cannot read '%s': %s", str,
+ errno ? strerror(errno) : TIP_("unsupported movie clip format"));
+
+ return OPERATOR_CANCELLED;
+ }
+
+ if (!op->customdata)
+ open_init(C, op);
+
+ /* hook into UI */
+ pprop = op->customdata;
+
+ if (pprop->prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ id_us_min(&clip->id);
+
+ RNA_id_pointer_create(&clip->id, &idptr);
+ RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
+ RNA_property_update(C, &pprop->ptr, pprop->prop);
+ }
+ else if (sc) {
+ ED_space_clip_set_secondary_clip(C, screen, sc, clip);
+ }
+
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_ADDED, clip);
+
+ MEM_freeN(op->customdata);
+
+ return OPERATOR_FINISHED;
+}
+
+static int open_secondary_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ char path[FILE_MAX];
+ MovieClip *secondary_clip = NULL;
+
+ if (sc)
+ secondary_clip = ED_space_clip_get_secondary_clip(sc);
+
+ if (secondary_clip) {
+ BLI_strncpy(path, secondary_clip->name, sizeof(path));
+
+ BLI_path_abs(path, G.main->name);
+ BLI_parent_dir(path);
+ }
+ else {
+ BLI_strncpy(path, U.textudir, sizeof(path));
+ }
+
+ if (RNA_struct_property_is_set(op->ptr, "files"))
+ return open_secondary_exec(C, op);
+
+ if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
+ RNA_boolean_set(op->ptr, "relative_path", (U.flag & USER_RELPATHS) != 0);
+
+ open_init(C, op);
+
+ clip_filesel(C, op, path);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void CLIP_OT_open_secondary(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Open Secondary Clip";
+ ot->description = "Load a sequence of frames or a movie file in correspondence mode";
+ ot->idname = "CLIP_OT_open_secondary";
+
+ /* api callbacks */
+ ot->exec = open_secondary_exec;
+ ot->invoke = open_secondary_invoke;
+ ot->cancel = open_cancel;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ WM_operator_properties_filesel(
+ ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_OPENFILE,
+ WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
+}
/******************* reload clip operator *********************/
static int reload_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 508821a..18c6ef8 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -432,6 +432,7 @@ static void clip_operatortypes(void)
{
/* ** clip_ops.c ** */
WM_operatortype_append(CLIP_OT_open);
+ WM_operatortype_append(CLIP_OT_open_secondary);
WM_operatortype_append(CLIP_OT_reload);
WM_operatortype_append(CLIP_OT_view_pan);
WM_operatortype_append(CLIP_OT_view_zoom);
@@ -566,6 +567,8 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
keymap = WM_keymap_find(keyconf, "Clip", SPACE_CLIP, 0);
WM_keymap_add_item(keymap, "CLIP_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
+ //TODO(tianwei): think about a shortcut for open_secondary clip
+ //WM_keymap_add_item(keymap, "CLIP_OT_open_secondary", OKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "CLIP_OT_tools", TKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "CLIP_OT_properties", NKEY, KM_PRESS, 0, 0);
@@ -885,6 +888,8 @@ static void clip_dropboxes(void)
ListBase *lb = WM_dropboxmap_find("Clip", SPACE_CLIP, 0);
WM_dropbox_add(lb, "CLIP_OT_open", clip_drop_poll, clip_drop_copy);
+ //TODO(tianwei): think
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list