[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43244] trunk/blender: Camera tracking: tracks copy/paste operator

Sergey Sharybin sergey.vfx at gmail.com
Mon Jan 9 21:18:49 CET 2012


Revision: 43244
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43244
Author:   nazgul
Date:     2012-01-09 20:18:48 +0000 (Mon, 09 Jan 2012)
Log Message:
-----------
Camera tracking: tracks copy/paste operator

This commit implements basic clipboard support for movie tracking data
int clip editor. Used own implementation of clipboard like it's done
for sequencer.
Ideally it needed to be switched to more general clipboard system, but
currently this system is designed for text data only and it need to
be re-designed itself. But this feature is quite useful since object
tracking is implemented, so it should be OK to live with such own
implementation for a while.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_clip.py
    trunk/blender/source/blender/blenkernel/BKE_tracking.h
    trunk/blender/source/blender/blenkernel/intern/tracking.c
    trunk/blender/source/blender/editors/space_clip/clip_intern.h
    trunk/blender/source/blender/editors/space_clip/space_clip.c
    trunk/blender/source/blender/editors/space_clip/tracking_ops.c
    trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2012-01-09 20:18:48 UTC (rev 43244)
@@ -856,6 +856,10 @@
         layout.operator("clip.clean_tracks")
 
         layout.separator()
+        layout.operator("clip.copy_tracks")
+        layout.operator("clip.paste_tracks")
+
+        layout.separator()
         props = layout.operator("clip.track_markers",
             text="Track Frame Backwards")
         props.backwards = True

Modified: trunk/blender/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_tracking.h	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/source/blender/blenkernel/BKE_tracking.h	2012-01-09 20:18:48 UTC (rev 43244)
@@ -97,6 +97,12 @@
 struct MovieTrackingReconstruction *BKE_tracking_object_reconstruction(struct MovieTracking *tracking,
 			struct MovieTrackingObject *object);
 
+/* clipboard */
+void BKE_tracking_free_clipboard(void);
+void BKE_tracking_clipboard_copy_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
+int BKE_tracking_clipboard_has_tracks(void);
+void BKE_tracking_clipboard_paste_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object);
+
 /* 2D tracking */
 struct MovieTrackingContext *BKE_tracking_context_new(struct MovieClip *clip, struct MovieClipUser *user,
 			short backwards, short sequence);

Modified: trunk/blender/source/blender/blenkernel/intern/tracking.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/tracking.c	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/source/blender/blenkernel/intern/tracking.c	2012-01-09 20:18:48 UTC (rev 43244)
@@ -70,6 +70,10 @@
 	struct libmv_CameraIntrinsics *intrinsics;
 } MovieDistortion;
 
+static struct {
+	ListBase tracks;
+} tracking_clipboard;
+
 /*********************** common functions *************************/
 
 void BKE_tracking_init_settings(MovieTracking *tracking)
@@ -578,6 +582,72 @@
 		BKE_tracking_distortion_destroy(tracking->camera.intrinsics);
 }
 
+static MovieTrackingTrack *duplicate_track(MovieTrackingTrack *track)
+{
+	MovieTrackingTrack *new_track;
+
+	new_track = MEM_callocN(sizeof(MovieTrackingTrack), "tracksMapMerge new_track");
+
+	*new_track= *track;
+	new_track->next = new_track->prev = NULL;
+
+	new_track->markers = MEM_dupallocN(new_track->markers);
+
+	return new_track;
+}
+
+/*********************** clipboard *************************/
+
+void BKE_tracking_free_clipboard(void)
+{
+	MovieTrackingTrack *track = tracking_clipboard.tracks.first, *next_track;
+
+	while (track) {
+		next_track = track->next;
+
+		BKE_tracking_free_track(track);
+		MEM_freeN(track);
+
+		track = next_track;
+	}
+}
+
+void BKE_tracking_clipboard_copy_tracks(MovieTracking *tracking, MovieTrackingObject *object)
+{
+	ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object);
+	MovieTrackingTrack *track = tracksbase->first;
+
+	while (track) {
+		if (TRACK_SELECTED(track)) {
+			MovieTrackingTrack *new_track = duplicate_track(track);
+
+			BLI_addtail(&tracking_clipboard.tracks, new_track);
+		}
+
+		track = track->next;
+	}
+}
+
+int BKE_tracking_clipboard_has_tracks(void)
+{
+	return tracking_clipboard.tracks.first != NULL;
+}
+
+void BKE_tracking_clipboard_paste_tracks(MovieTracking *tracking, MovieTrackingObject *object)
+{
+	ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object);
+	MovieTrackingTrack *track = tracking_clipboard.tracks.first;
+
+	while (track) {
+		MovieTrackingTrack *new_track = duplicate_track(track);
+
+		BLI_addtail(tracksbase, new_track);
+		BKE_track_unique_name(tracksbase, new_track);
+
+		track = track->next;
+	}
+}
+
 /*********************** tracks map *************************/
 
 typedef struct TracksMap {
@@ -700,9 +770,7 @@
 			}
 		}
 
-		new_track= MEM_callocN(sizeof(MovieTrackingTrack), "tracksMapMerge new_track");
-		*new_track= *track;
-		new_track->markers= MEM_dupallocN(new_track->markers);
+		new_track= duplicate_track(track);
 
 		BLI_ghash_remove(map->hash, track, NULL, NULL); /* XXX: are we actually need this */
 		BLI_ghash_insert(map->hash, track, new_track);

Modified: trunk/blender/source/blender/editors/space_clip/clip_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_intern.h	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/source/blender/editors/space_clip/clip_intern.h	2012-01-09 20:18:48 UTC (rev 43244)
@@ -145,4 +145,7 @@
 void CLIP_OT_tracking_object_new(struct wmOperatorType *ot);
 void CLIP_OT_tracking_object_remove(struct wmOperatorType *ot);
 
+void CLIP_OT_copy_tracks(struct wmOperatorType *ot);
+void CLIP_OT_paste_tracks(struct wmOperatorType *ot);
+
 #endif /* ED_CLIP_INTERN_H */

Modified: trunk/blender/source/blender/editors/space_clip/space_clip.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-01-09 20:18:48 UTC (rev 43244)
@@ -377,6 +377,10 @@
 	/* object tracking */
 	WM_operatortype_append(CLIP_OT_tracking_object_new);
 	WM_operatortype_append(CLIP_OT_tracking_object_remove);
+
+	/* clipboard */
+	WM_operatortype_append(CLIP_OT_copy_tracks);
+	WM_operatortype_append(CLIP_OT_paste_tracks);
 }
 
 static void clip_keymap(struct wmKeyConfig *keyconf)

Modified: trunk/blender/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/tracking_ops.c	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/source/blender/editors/space_clip/tracking_ops.c	2012-01-09 20:18:48 UTC (rev 43244)
@@ -1220,21 +1220,39 @@
 	return tot;
 }
 
+static void clear_invisible_track_selection(SpaceClip *sc, MovieClip *clip)
+{
+	ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
+	int hidden = 0;
+
+	if ((sc->flag&SC_SHOW_MARKER_PATTERN)==0)
+		hidden |= TRACK_AREA_PAT;
+
+	if ((sc->flag&SC_SHOW_MARKER_SEARCH)==0)
+		hidden |= TRACK_AREA_SEARCH;
+
+	if (hidden) {
+		MovieTrackingTrack *track = tracksbase->first;
+
+		while(track) {
+			BKE_tracking_track_flag(track, hidden, SELECT, 1);
+
+			track = track->next;
+		}
+	}
+}
+
 static void track_init_markers(SpaceClip *sc, MovieClip *clip, int *frames_limit_r)
 {
 	ListBase *tracksbase= BKE_tracking_get_tracks(&clip->tracking);
 	MovieTrackingTrack *track;
-	int framenr= sc->user.framenr, hidden= 0;
+	int framenr= sc->user.framenr;
 	int frames_limit= 0;
 
-	if((sc->flag&SC_SHOW_MARKER_PATTERN)==0) hidden|= TRACK_AREA_PAT;
-	if((sc->flag&SC_SHOW_MARKER_SEARCH)==0) hidden|= TRACK_AREA_SEARCH;
+	clear_invisible_track_selection(sc, clip);
 
 	track= tracksbase->first;
 	while(track) {
-		if(hidden)
-			BKE_tracking_track_flag(track, hidden, SELECT, 1);
-
 		if(TRACK_SELECTED(track)) {
 			if((track->flag&TRACK_HIDDEN)==0 && (track->flag&TRACK_LOCKED)==0) {
 				BKE_tracking_ensure_marker(track, framenr);
@@ -3504,3 +3522,74 @@
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
+
+/********************** copy tracks to clipboard operator *********************/
+
+static int copy_tracks_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	SpaceClip *sc = CTX_wm_space_clip(C);
+	MovieClip *clip = ED_space_clip(sc);
+	MovieTracking *tracking = &clip->tracking;
+	MovieTrackingObject *object = BKE_tracking_active_object(tracking);
+
+	clear_invisible_track_selection(sc, clip);
+
+	BKE_tracking_clipboard_copy_tracks(tracking, object);
+
+	return OPERATOR_FINISHED;
+}
+
+void CLIP_OT_copy_tracks(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Copy Tracks";
+	ot->description = "Copy selected tracks to clipboard";
+	ot->idname = "CLIP_OT_copy_tracks";
+
+	/* api callbacks */
+	ot->exec = copy_tracks_exec;
+	ot->poll = ED_space_clip_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER;
+}
+
+/********************** paste tracks from clipboard operator *********************/
+
+static int paste_tracks_poll(bContext *C)
+{
+	if (ED_space_clip_poll(C)) {
+		return BKE_tracking_clipboard_has_tracks();
+	}
+
+	return 0;
+}
+
+static int paste_tracks_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	SpaceClip *sc = CTX_wm_space_clip(C);
+	MovieClip *clip = ED_space_clip(sc);
+	MovieTracking *tracking = &clip->tracking;
+	MovieTrackingObject *object = BKE_tracking_active_object(tracking);
+
+	BKE_tracking_clipboard_paste_tracks(tracking, object);
+
+	WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
+
+	return OPERATOR_FINISHED;
+}
+
+void CLIP_OT_paste_tracks(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Paste Tracks";
+	ot->description = "Paste tracks from clipboard";
+	ot->idname = "CLIP_OT_paste_tracks";
+
+	/* api callbacks */
+	ot->exec = paste_tracks_exec;
+	ot->poll = paste_tracks_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}

Modified: trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c	2012-01-09 20:18:36 UTC (rev 43243)
+++ trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c	2012-01-09 20:18:48 UTC (rev 43244)
@@ -60,6 +60,7 @@
 #include "BKE_packedFile.h"
 #include "BKE_sequencer.h" /* free seq clipboard */
 #include "BKE_material.h" /* clear_matcopybuf */
+#include "BKE_tracking.h" /* free tracking clipboard */
 
 #include "BLI_listbase.h"
 #include "BLI_string.h"
@@ -375,6 +376,7 @@
 		wm_free_reports(C);			/* before free_blender! - since the ListBases get freed there */
 
 	seq_free_clipboard(); /* sequencer.c */
+	BKE_tracking_free_clipboard();
 		
 	free_blender();				/* blender.c, does entire library and spacetypes */
 //	free_matcopybuf();



More information about the Bf-blender-cvs mailing list