~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/mask/mask_relationships.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2012 Blender Foundation.
 
19
 * All rights reserved.
 
20
 *
 
21
 *
 
22
 * Contributor(s): Blender Foundation,
 
23
 *                 Campbell Barton
 
24
 *
 
25
 * ***** END GPL LICENSE BLOCK *****
 
26
 */
 
27
 
 
28
/** \file blender/editors/mask/mask_relationships.c
 
29
 *  \ingroup edmask
 
30
 */
 
31
 
 
32
 
 
33
#include "BLI_math.h"
 
34
#include "BLI_string.h"
 
35
 
 
36
#include "BKE_context.h"
 
37
#include "BKE_depsgraph.h"
 
38
#include "BKE_mask.h"
 
39
#include "BKE_tracking.h"
 
40
 
 
41
#include "DNA_mask_types.h"
 
42
#include "DNA_object_types.h"  /* SELECT */
 
43
 
 
44
#include "WM_api.h"
 
45
#include "WM_types.h"
 
46
 
 
47
#include "ED_screen.h"
 
48
#include "ED_clip.h"  /* frame remapping functions */
 
49
#include "ED_mask.h"  /* own include */
 
50
 
 
51
#include "mask_intern.h"  /* own include */
 
52
 
 
53
static int mask_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
 
54
{
 
55
        Mask *mask = CTX_data_edit_mask(C);
 
56
        MaskLayer *masklay;
 
57
 
 
58
        for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
 
59
                MaskSpline *spline;
 
60
                int i;
 
61
 
 
62
                if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
 
63
                        continue;
 
64
                }
 
65
 
 
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];
 
69
 
 
70
                                if (MASKPOINT_ISSEL_ANY(point)) {
 
71
                                        point->parent.id = NULL;
 
72
                                }
 
73
                        }
 
74
                }
 
75
        }
 
76
 
 
77
        WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
 
78
        DAG_id_tag_update(&mask->id, 0);
 
79
 
 
80
        return OPERATOR_FINISHED;
 
81
}
 
82
 
 
83
void MASK_OT_parent_clear(wmOperatorType *ot)
 
84
{
 
85
        /* identifiers */
 
86
        ot->name = "Clear Parent";
 
87
        ot->description = "Clear the mask's parenting";
 
88
        ot->idname = "MASK_OT_parent_clear";
 
89
 
 
90
        /* api callbacks */
 
91
        ot->exec = mask_parent_clear_exec;
 
92
 
 
93
        ot->poll = ED_maskedit_mask_poll;
 
94
 
 
95
        /* flags */
 
96
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
97
}
 
98
 
 
99
static int mask_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
 
100
{
 
101
        Mask *mask = CTX_data_edit_mask(C);
 
102
        MaskLayer *masklay;
 
103
 
 
104
        /* parent info */
 
105
        SpaceClip *sc;
 
106
        MovieClip *clip;
 
107
        MovieTrackingTrack *track;
 
108
        MovieTrackingMarker *marker;
 
109
        MovieTrackingObject *tracking_object;
 
110
        /* done */
 
111
 
 
112
        int framenr;
 
113
 
 
114
        float marker_pos_ofs[2];
 
115
        float parmask_pos[2];
 
116
 
 
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))))
 
121
        {
 
122
                return OPERATOR_CANCELLED;
 
123
        }
 
124
 
 
125
        framenr = ED_space_clip_get_clip_frame_number(sc);
 
126
        marker = BKE_tracking_marker_get(track, framenr);
 
127
 
 
128
        add_v2_v2v2(marker_pos_ofs, marker->pos, track->offset);
 
129
 
 
130
        BKE_mask_coord_from_movieclip(clip, &sc->user, parmask_pos, marker_pos_ofs);
 
131
 
 
132
        for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
 
133
                MaskSpline *spline;
 
134
                int i;
 
135
 
 
136
                if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) {
 
137
                        continue;
 
138
                }
 
139
 
 
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];
 
143
 
 
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));
 
149
 
 
150
                                        copy_v2_v2(point->parent.parent_orig, parmask_pos);
 
151
                                }
 
152
                        }
 
153
                }
 
154
        }
 
155
 
 
156
        WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
 
157
        DAG_id_tag_update(&mask->id, 0);
 
158
 
 
159
        return OPERATOR_FINISHED;
 
160
}
 
161
 
 
162
/** based on #OBJECT_OT_parent_set */
 
163
void MASK_OT_parent_set(wmOperatorType *ot)
 
164
{
 
165
        /* identifiers */
 
166
        ot->name = "Make Parent";
 
167
        ot->description = "Set the mask's parenting";
 
168
        ot->idname = "MASK_OT_parent_set";
 
169
 
 
170
        /* api callbacks */
 
171
        //ot->invoke = mask_parent_set_invoke;
 
172
        ot->exec = mask_parent_set_exec;
 
173
 
 
174
        ot->poll = ED_maskedit_mask_poll;
 
175
 
 
176
        /* flags */
 
177
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
178
}