Blender V4.3
gpencil_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include <cmath>
11#include <cstddef>
12#include <cstdio>
13#include <cstdlib>
14#include <cstring>
15
16#include "DNA_object_enums.h"
17#include "MEM_guardedalloc.h"
18
19#include "BLI_ghash.h"
20#include "BLI_lasso_2d.hh"
21#include "BLI_math_matrix.h"
22#include "BLI_math_vector.h"
23#include "BLI_string.h"
24#include "BLI_utildefines.h"
25
26#include "BLT_translation.hh"
27
30#include "DNA_material_types.h"
31#include "DNA_meshdata_types.h"
32#include "DNA_object_types.h"
33#include "DNA_scene_types.h"
34#include "DNA_screen_types.h"
35#include "DNA_space_types.h"
36#include "DNA_view3d_types.h"
37
38#include "BKE_brush.hh"
39#include "BKE_context.hh"
40#include "BKE_deform.hh"
41#include "BKE_global.hh"
44#include "BKE_gpencil_legacy.h"
45#include "BKE_lib_id.hh"
46#include "BKE_main.hh"
47#include "BKE_material.h"
48#include "BKE_paint.hh"
49#include "BKE_report.hh"
50#include "BKE_scene.hh"
51
52#include "UI_interface.hh"
53#include "UI_resources.hh"
54
55#include "WM_api.hh"
56#include "WM_message.hh"
57#include "WM_toolsystem.hh"
58#include "WM_types.hh"
59
60#include "RNA_access.hh"
61#include "RNA_define.hh"
62
63#include "UI_view2d.hh"
64
65#include "ED_gpencil_legacy.hh"
66#include "ED_image.hh"
67#include "ED_object.hh"
68#include "ED_outliner.hh"
69#include "ED_screen.hh"
71#include "ED_view3d.hh"
72
73#include "ANIM_keyframing.hh"
74
75#include "DEG_depsgraph.hh"
78
79#include "gpencil_intern.hh"
80
81/* -------------------------------------------------------------------- */
93
94/* Hash for hanging on to all the colors used by strokes in the buffer
95 *
96 * This is needed to prevent dangling and unsafe pointers when pasting across data-blocks,
97 * or after a color used by a stroke in the buffer gets deleted (via user action or undo).
98 */
100
102{
103 bGPDstroke *gps, *gpsn;
104
105 /* Free the colors buffer.
106 * NOTE: This is done before the strokes so that the pointers are still safe. */
110 }
111
112 /* Free the stroke buffer */
113 for (gps = static_cast<bGPDstroke *>(gpencil_strokes_copypastebuf.first); gps; gps = gpsn) {
114 gpsn = gps->next;
115
116 if (gps->points) {
117 MEM_freeN(gps->points);
118 }
119 if (gps->dvert) {
121 MEM_freeN(gps->dvert);
122 }
123
125
127 }
128
130}
131
134/* -------------------------------------------------------------------- */
139{
142
143 /* only if there's an active layer with an active frame */
144 return (gpl && gpl->actframe);
145}
146
147/* delete active frame - wrapper around API calls */
149{
150 const bool is_annotation = STREQ(op->idname, "GPENCIL_OT_annotation_active_frame_delete");
151
152 bGPdata *gpd = (!is_annotation) ? ED_gpencil_data_get_active(C) :
154
156
157 Scene *scene = CTX_data_scene(C);
158
160
161 /* if there's no existing Grease-Pencil data there, add some */
162 if (gpd == nullptr) {
163 BKE_report(op->reports, RPT_ERROR, "No grease pencil data");
164 return OPERATOR_CANCELLED;
165 }
166 if (ELEM(nullptr, gpl, gpf)) {
167 BKE_report(op->reports, RPT_ERROR, "No active frame to delete");
168 return OPERATOR_CANCELLED;
169 }
170
171 /* delete it... */
173
174 /* notifiers */
177
178 return OPERATOR_FINISHED;
179}
180
182{
183 /* identifiers */
184 ot->name = "Delete Active Frame";
185 ot->idname = "GPENCIL_OT_annotation_active_frame_delete";
186 ot->description = "Delete the active frame for the active Annotation Layer";
187
189
190 /* callbacks */
193}
194
Functions to insert, delete or modify keyframes.
Scene * CTX_data_scene(const bContext *C)
support for deformation groups and hooks.
void BKE_gpencil_free_stroke_weights(struct bGPDstroke *gps)
bool BKE_gpencil_layer_frame_delete(struct bGPDlayer *gpl, struct bGPDframe *gpf)
struct bGPDframe * BKE_gpencil_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
struct bGPDlayer * BKE_gpencil_layer_active_get(struct bGPdata *gpd)
@ GP_GETFRAME_USE_PREV
General operations, lookup, etc. for materials.
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:860
void BLI_freelinkN(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:269
#define ELEM(...)
#define STREQ(a, b)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1021
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1041
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define ND_DATA
Definition WM_types.hh:475
#define NA_EDITED
Definition WM_types.hh:550
#define NC_GPENCIL
Definition WM_types.hh:366
void ED_gpencil_strokes_copybuf_free()
static bool annotation_actframe_delete_poll(bContext *C)
static GHash * gpencil_strokes_copypastebuf_colors
void GPENCIL_OT_annotation_active_frame_delete(wmOperatorType *ot)
ListBase gpencil_strokes_copypastebuf
static int gpencil_actframe_delete_exec(bContext *C, wmOperator *op)
bGPdata * ED_annotation_data_get_active(const bContext *C)
bGPdata * ED_gpencil_data_get_active(const bContext *C)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void * last
void * first
bGPDtriangle * triangles
struct MDeformVert * dvert
struct bGPDstroke * next
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
struct ReportList * reports
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4125