2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* The Original Code is Copyright (C) 2012 Blender Foundation.
19
* All rights reserved.
22
* Contributor(s): Blender Foundation,
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file blender/editors/mask/mask_relationships.c
34
#include "BLI_string.h"
36
#include "BKE_context.h"
37
#include "BKE_depsgraph.h"
39
#include "BKE_tracking.h"
41
#include "DNA_mask_types.h"
42
#include "DNA_object_types.h" /* SELECT */
47
#include "ED_screen.h"
48
#include "ED_clip.h" /* frame remapping functions */
49
#include "ED_mask.h" /* own include */
51
#include "mask_intern.h" /* own include */
53
static int mask_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
55
Mask *mask = CTX_data_edit_mask(C);
58
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
62
if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
66
for (spline = masklay->splines.first; spline; spline = spline->next) {
67
for (i = 0; i < spline->tot_point; i++) {
68
MaskSplinePoint *point = &spline->points[i];
70
if (MASKPOINT_ISSEL_ANY(point)) {
71
point->parent.id = NULL;
77
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
78
DAG_id_tag_update(&mask->id, 0);
80
return OPERATOR_FINISHED;
83
void MASK_OT_parent_clear(wmOperatorType *ot)
86
ot->name = "Clear Parent";
87
ot->description = "Clear the mask's parenting";
88
ot->idname = "MASK_OT_parent_clear";
91
ot->exec = mask_parent_clear_exec;
93
ot->poll = ED_maskedit_mask_poll;
96
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
99
static int mask_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
101
Mask *mask = CTX_data_edit_mask(C);
107
MovieTrackingTrack *track;
108
MovieTrackingMarker *marker;
109
MovieTrackingObject *tracking_object;
114
float marker_pos_ofs[2];
115
float parmask_pos[2];
117
if ((NULL == (sc = CTX_wm_space_clip(C))) ||
118
(NULL == (clip = sc->clip)) ||
119
(NULL == (track = clip->tracking.act_track)) ||
120
(NULL == (tracking_object = BKE_tracking_object_get_active(&clip->tracking))))
122
return OPERATOR_CANCELLED;
125
framenr = ED_space_clip_get_clip_frame_number(sc);
126
marker = BKE_tracking_marker_get(track, framenr);
128
add_v2_v2v2(marker_pos_ofs, marker->pos, track->offset);
130
BKE_mask_coord_from_movieclip(clip, &sc->user, parmask_pos, marker_pos_ofs);
132
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
136
if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
140
for (spline = masklay->splines.first; spline; spline = spline->next) {
141
for (i = 0; i < spline->tot_point; i++) {
142
MaskSplinePoint *point = &spline->points[i];
144
if (MASKPOINT_ISSEL_ANY(point)) {
145
point->parent.id_type = ID_MC;
146
point->parent.id = &clip->id;
147
BLI_strncpy(point->parent.parent, tracking_object->name, sizeof(point->parent.parent));
148
BLI_strncpy(point->parent.sub_parent, track->name, sizeof(point->parent.sub_parent));
150
copy_v2_v2(point->parent.parent_orig, parmask_pos);
156
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
157
DAG_id_tag_update(&mask->id, 0);
159
return OPERATOR_FINISHED;
162
/** based on #OBJECT_OT_parent_set */
163
void MASK_OT_parent_set(wmOperatorType *ot)
166
ot->name = "Make Parent";
167
ot->description = "Set the mask's parenting";
168
ot->idname = "MASK_OT_parent_set";
171
//ot->invoke = mask_parent_set_invoke;
172
ot->exec = mask_parent_set_exec;
174
ot->poll = ED_maskedit_mask_poll;
177
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;