diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-01-15 12:02:26 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-01-15 13:15:56 +0300 |
commit | 585574dc301904d0a3672b1956d50c8455a0e3e6 (patch) | |
tree | ab0b07c7c0aef9deb30f16b4cc6ee021c72bbcb3 /source/blender/editors/space_clip/tracking_ops_stabilize.c | |
parent | bdd79ef880ac26de4cef623518c845fa23892a90 (diff) |
Tracking: Split tracking_ops into smaller files
The file started to be rather really huge and difficult to follow.
Should be no functional changes.
Diffstat (limited to 'source/blender/editors/space_clip/tracking_ops_stabilize.c')
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops_stabilize.c | 242 |
1 files changed, 242 insertions, 0 deletions
diff --git a/source/blender/editors/space_clip/tracking_ops_stabilize.c b/source/blender/editors/space_clip/tracking_ops_stabilize.c new file mode 100644 index 00000000000..8d6173e1cea --- /dev/null +++ b/source/blender/editors/space_clip/tracking_ops_stabilize.c @@ -0,0 +1,242 @@ +/* + * ***** 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) 2016 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation, + * Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_clip/tracking_ops_stabilize.c + * \ingroup spclip + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_screen_types.h" +#include "DNA_space_types.h" + +#include "BLI_utildefines.h" + +#include "BKE_context.h" +#include "BKE_tracking.h" +#include "BKE_depsgraph.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_clip.h" + +#include "clip_intern.h" + +/********************* add 2d stabilization tracks operator ********************/ + +static int stabilize_2d_poll(bContext *C) +{ + if (ED_space_clip_tracking_poll(C)) { + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTrackingObject *tracking_object = + BKE_tracking_object_get_active(&clip->tracking); + return (tracking_object->flag & TRACKING_OBJECT_CAMERA) != 0; + } + return 0; +} + +static int stabilize_2d_add_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); + MovieTrackingStabilization *stab = &tracking->stabilization; + + bool update = false; + for (MovieTrackingTrack *track = tracksbase->first; + track != NULL; + track = track->next) + { + if (TRACK_VIEW_SELECTED(sc, track) && + (track->flag & TRACK_USE_2D_STAB) == 0) + { + track->flag |= TRACK_USE_2D_STAB; + stab->tot_track++; + update = true; + } + } + + if (update) { + stab->ok = 0; + DAG_id_tag_update(&clip->id, 0); + WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip); + } + + return OPERATOR_FINISHED; +} + +void CLIP_OT_stabilize_2d_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Stabilization Tracks"; + ot->description = "Add selected tracks to 2D stabilization tool"; + ot->idname = "CLIP_OT_stabilize_2d_add"; + + /* api callbacks */ + ot->exec = stabilize_2d_add_exec; + ot->poll = stabilize_2d_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/******************* remove 2d stabilization tracks operator ******************/ + +static int stabilize_2d_remove_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + MovieTrackingStabilization *stab = &tracking->stabilization; + ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); + int a = 0; + bool update = false; + + for (MovieTrackingTrack *track = tracksbase->first; + track != NULL; + track = track->next) + { + if (track->flag & TRACK_USE_2D_STAB) { + if (a == stab->act_track) { + track->flag &= ~TRACK_USE_2D_STAB; + stab->act_track--; + stab->tot_track--; + if (stab->act_track < 0) { + stab->act_track = 0; + } + update = true; + break; + } + a++; + } + } + + if (update) { + stab->ok = 0; + DAG_id_tag_update(&clip->id, 0); + WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip); + } + + return OPERATOR_FINISHED; +} + +void CLIP_OT_stabilize_2d_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Stabilization Track"; + ot->description = "Remove selected track from stabilization"; + ot->idname = "CLIP_OT_stabilize_2d_remove"; + + /* api callbacks */ + ot->exec = stabilize_2d_remove_exec; + ot->poll = stabilize_2d_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/******************* select 2d stabilization tracks operator ******************/ + +static int stabilize_2d_select_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); + bool update = false; + + for (MovieTrackingTrack *track = tracksbase->first; + track != NULL; + track = track->next) + { + if (track->flag & TRACK_USE_2D_STAB) { + BKE_tracking_track_flag_set(track, TRACK_AREA_ALL, SELECT); + update = true; + } + } + + if (update) { + WM_event_add_notifier(C, NC_MOVIECLIP | ND_SELECT, clip); + } + + return OPERATOR_FINISHED; +} + +void CLIP_OT_stabilize_2d_select(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Select Stabilization Tracks"; + ot->description = "Select tracks which are used for stabilization"; + ot->idname = "CLIP_OT_stabilize_2d_select"; + + /* api callbacks */ + ot->exec = stabilize_2d_select_exec; + ot->poll = stabilize_2d_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/***************** set 2d stabilization rotation track operator ****************/ + +static int stabilize_2d_set_rotation_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); + + if (act_track != NULL) { + MovieTrackingStabilization *stab = &tracking->stabilization; + stab->rot_track = act_track; + stab->ok = 0; + + DAG_id_tag_update(&clip->id, 0); + WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip); + } + + return OPERATOR_FINISHED; +} + +void CLIP_OT_stabilize_2d_set_rotation(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Set Rotation Track"; + ot->description = "Use active track to compensate rotation when " + "doing 2D stabilization"; + ot->idname = "CLIP_OT_stabilize_2d_set_rotation"; + + /* api callbacks */ + ot->exec = stabilize_2d_set_rotation_exec; + ot->poll = stabilize_2d_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} |