Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2020-11-13 15:17:17 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-11-13 17:21:15 +0300
commite9b955b99cd3cde127b52bff8c4559e2d57eeeb0 (patch)
tree1bdc8ebdada1b23948ef59c5751ca6f43f2fe636 /source/blender/editors/gpencil/gpencil_trace_ops.c
parent50ccf346f0b8bbf91811a88ba5f31a85dcab8467 (diff)
GPencil: Remove ID from operators to fix T82597
Instead to use the ID of the object, now the parameter is an Enum with Selected object or New. If use selected mode, the first grease pencil object selected is used. If none of the selected objects is a grease pencil object, a new object is created. Small cleanup changes to the original patch. Differential Revision: https://developer.blender.org/D9529
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_trace_ops.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_trace_ops.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/source/blender/editors/gpencil/gpencil_trace_ops.c b/source/blender/editors/gpencil/gpencil_trace_ops.c
index 2d04c31e60d..75683c9ccf3 100644
--- a/source/blender/editors/gpencil/gpencil_trace_ops.c
+++ b/source/blender/editors/gpencil/gpencil_trace_ops.c
@@ -38,6 +38,7 @@
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_material.h"
@@ -320,7 +321,13 @@ static int gpencil_trace_image_exec(bContext *C, wmOperator *op)
job->image = (Image *)job->ob_active->data;
job->frame_target = CFRA;
- job->ob_gpencil = (Object *)RNA_pointer_get(op->ptr, "target").data;
+ /* Create a new grease pencil object or resuse selected. */
+ eGP_TargetObjectMode target = RNA_enum_get(op->ptr, "target");
+ job->ob_gpencil = (target == GP_TARGET_OB_SELECTED) ?
+ BKE_view_layer_first_selected_object_by_type(
+ CTX_data_view_layer(C), job->v3d, OB_GPENCIL) :
+ NULL;
+
job->was_ob_created = false;
job->threshold = RNA_float_get(op->ptr, "threshold");
@@ -368,15 +375,8 @@ static int gpencil_trace_image_invoke(bContext *C, wmOperator *op, const wmEvent
return WM_operator_props_dialog_popup(C, op, 250);
}
-static bool rna_GPencil_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
-{
- return ((Object *)value.owner_id)->type == OB_GPENCIL;
-}
-
void GPENCIL_OT_trace_image(wmOperatorType *ot)
{
- PropertyRNA *prop;
-
static const EnumPropertyItem turnpolicy_type[] = {
{POTRACE_TURNPOLICY_BLACK,
"BLACK",
@@ -412,6 +412,12 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
{0, NULL, 0, NULL, NULL},
};
+ static const EnumPropertyItem target_object_modes[] = {
+ {GP_TARGET_OB_NEW, "NEW", 0, "New Object", ""},
+ {GP_TARGET_OB_SELECTED, "SELECTED", 0, "Selected Object", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
/* identifiers */
ot->name = "Trace Image to Grease Pencil";
ot->idname = "GPENCIL_OT_trace_image";
@@ -426,15 +432,13 @@ void GPENCIL_OT_trace_image(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
- prop = RNA_def_pointer_runtime(
- ot->srna,
- "target",
- &RNA_Object,
- "Target Object",
- "Target grease pencil object name. Leave empty to create a new object");
- RNA_def_property_poll_runtime(prop, rna_GPencil_object_poll);
-
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ ot->prop = RNA_def_enum(ot->srna,
+ "target",
+ target_object_modes,
+ GP_TARGET_OB_NEW,
+ "Target Object",
+ "Target grease pencil");
+ RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
RNA_def_int(ot->srna, "thickness", 10, 1, 1000, "Thickness", "", 1, 1000);
RNA_def_int(