GPencil: Refactor Append operators
Now the operators work like other areas of Blender using the list of selected objects. Also, the name has been changed to: ```Layers: - Copy Layer to Selected - Copy All Layers to Selected Materials: - Copy Material to Selected - Copy All Materials to Selected``` Reviewed By: mendio, pablovazquez, pepeland Differential Revision: https://developer.blender.org/D11216
This commit is contained in:
parent
8c80267352
commit
f6cb9433d4
|
@ -113,8 +113,8 @@ class GPENCIL_MT_layer_context_menu(Menu):
|
|||
layout.operator("gpencil.layer_merge", icon='SORT_ASC', text="Merge Down")
|
||||
|
||||
layout.separator()
|
||||
layout.menu("VIEW3D_MT_gpencil_append_active_layer")
|
||||
layout.menu("VIEW3D_MT_gpencil_append_all_layers")
|
||||
layout.operator("gpencil.layer_duplicate_object", text="Copy Layer to Selected").only_active=True
|
||||
layout.operator("gpencil.layer_duplicate_object", text="Copy All Layers to Selected").only_active=False
|
||||
|
||||
|
||||
class DATA_PT_gpencil_layers(DataButtonsPanel, Panel):
|
||||
|
|
|
@ -46,16 +46,18 @@ class GPENCIL_MT_material_context_menu(Menu):
|
|||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("object.material_slot_remove_unused")
|
||||
layout.operator("gpencil.stroke_merge_material", text="Merge Similar")
|
||||
|
||||
layout.separator()
|
||||
layout.operator("gpencil.material_to_vertex_color", text="Convert Materials to Vertex Color")
|
||||
layout.operator("gpencil.extract_palette_vertex", text="Extract Palette from Vertex Color")
|
||||
|
||||
layout.separator()
|
||||
layout.menu("VIEW3D_MT_gpencil_append_active_material")
|
||||
layout.menu("VIEW3D_MT_gpencil_append_all_materials")
|
||||
|
||||
layout.operator("gpencil.materials_copy_to_object", text="Copy Material to Selected").only_active = True
|
||||
layout.operator("gpencil.materials_copy_to_object", text="Copy All Materials to Selected").only_active = False
|
||||
|
||||
layout.separator()
|
||||
|
||||
layout.operator("gpencil.stroke_merge_material", text="Merge Similar")
|
||||
layout.operator("object.material_slot_remove_unused")
|
||||
|
||||
|
||||
class GPENCIL_UL_matslots(UIList):
|
||||
|
|
|
@ -4956,75 +4956,6 @@ class VIEW3D_MT_assign_material(Menu):
|
|||
icon='LAYER_ACTIVE' if mat == mat_active else 'BLANK1').material = mat.name
|
||||
|
||||
|
||||
def gpencil_layer_append_menu_items(context, layout, only_active):
|
||||
done = False
|
||||
view_layer = context.view_layer
|
||||
obact = context.active_object
|
||||
gpl = context.active_gpencil_layer
|
||||
|
||||
done = False
|
||||
if gpl is not None:
|
||||
for ob in view_layer.objects:
|
||||
if ob.type == 'GPENCIL' and ob != obact:
|
||||
op = layout.operator("gpencil.layer_duplicate_object", text=ob.name)
|
||||
op.object = ob.name
|
||||
op.only_active = only_active
|
||||
done = True
|
||||
|
||||
if done is False:
|
||||
layout.label(text="No destination object", icon='ERROR')
|
||||
else:
|
||||
layout.label(text="No layer to copy", icon='ERROR')
|
||||
|
||||
|
||||
class VIEW3D_MT_gpencil_append_active_layer(Menu):
|
||||
bl_label = "Append Active Layer to Object"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
gpencil_layer_append_menu_items(context, layout, True)
|
||||
|
||||
|
||||
class VIEW3D_MT_gpencil_append_all_layers(Menu):
|
||||
bl_label = "Append All Layers to Object"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
gpencil_layer_append_menu_items(context, layout, False)
|
||||
|
||||
|
||||
def gpencil_material_menu_items(context, layout, only_selected):
|
||||
done = False
|
||||
view_layer = context.view_layer
|
||||
obact = context.active_object
|
||||
|
||||
for ob in view_layer.objects:
|
||||
if ob.type == 'GPENCIL' and ob != obact:
|
||||
op = layout.operator("gpencil.materials_append_to_object", text=ob.name)
|
||||
op.object = ob.name
|
||||
op.only_selected = only_selected
|
||||
done = True
|
||||
|
||||
if done is False:
|
||||
layout.label(text="No destination object", icon='ERROR')
|
||||
|
||||
|
||||
class VIEW3D_MT_gpencil_append_active_material(Menu):
|
||||
bl_label = "Append Active Material to Object"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
gpencil_material_menu_items(context, layout, True)
|
||||
|
||||
|
||||
class VIEW3D_MT_gpencil_append_all_materials(Menu):
|
||||
bl_label = "Append All Materials to Object"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
gpencil_material_menu_items(context, layout, False)
|
||||
|
||||
|
||||
class VIEW3D_MT_edit_gpencil(Menu):
|
||||
bl_label = "Grease Pencil"
|
||||
|
||||
|
@ -7689,10 +7620,6 @@ classes = (
|
|||
VIEW3D_MT_weight_gpencil,
|
||||
VIEW3D_MT_gpencil_animation,
|
||||
VIEW3D_MT_gpencil_simplify,
|
||||
VIEW3D_MT_gpencil_append_active_layer,
|
||||
VIEW3D_MT_gpencil_append_all_layers,
|
||||
VIEW3D_MT_gpencil_append_active_material,
|
||||
VIEW3D_MT_gpencil_append_all_materials,
|
||||
VIEW3D_MT_gpencil_autoweights,
|
||||
VIEW3D_MT_gpencil_edit_context_menu,
|
||||
VIEW3D_MT_edit_curve,
|
||||
|
|
|
@ -108,7 +108,10 @@ void BKE_gpencil_stroke_select_index_reset(struct bGPDstroke *gps);
|
|||
|
||||
struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
|
||||
struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);
|
||||
struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive);
|
||||
struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd,
|
||||
const char *name,
|
||||
const bool setactive,
|
||||
const bool add_to_header);
|
||||
struct bGPdata *BKE_gpencil_data_addnew(struct Main *bmain, const char name[]);
|
||||
|
||||
struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src,
|
||||
|
|
|
@ -653,9 +653,13 @@ bGPDframe *BKE_gpencil_frame_addcopy(bGPDlayer *gpl, int cframe)
|
|||
* \param gpd: Grease pencil data-block
|
||||
* \param name: Name of the layer
|
||||
* \param setactive: Set as active
|
||||
* \param add_to_header: Used to force the layer added at header
|
||||
* \return Pointer to new layer
|
||||
*/
|
||||
bGPDlayer *BKE_gpencil_layer_addnew(bGPdata *gpd, const char *name, bool setactive)
|
||||
bGPDlayer *BKE_gpencil_layer_addnew(bGPdata *gpd,
|
||||
const char *name,
|
||||
const bool setactive,
|
||||
const bool add_to_header)
|
||||
{
|
||||
bGPDlayer *gpl = NULL;
|
||||
bGPDlayer *gpl_active = NULL;
|
||||
|
@ -671,14 +675,18 @@ bGPDlayer *BKE_gpencil_layer_addnew(bGPdata *gpd, const char *name, bool setacti
|
|||
gpl_active = BKE_gpencil_layer_active_get(gpd);
|
||||
|
||||
/* Add to data-block. */
|
||||
if (gpl_active == NULL) {
|
||||
BLI_addtail(&gpd->layers, gpl);
|
||||
if (add_to_header) {
|
||||
BLI_addhead(&gpd->layers, gpl);
|
||||
}
|
||||
else {
|
||||
/* if active layer, add after that layer */
|
||||
BLI_insertlinkafter(&gpd->layers, gpl_active, gpl);
|
||||
if (gpl_active == NULL) {
|
||||
BLI_addtail(&gpd->layers, gpl);
|
||||
}
|
||||
else {
|
||||
/* if active layer, add after that layer */
|
||||
BLI_insertlinkafter(&gpd->layers, gpl_active, gpl);
|
||||
}
|
||||
}
|
||||
|
||||
/* annotation vs GP Object behavior is slightly different */
|
||||
if (gpd->flag & GP_DATA_ANNOTATIONS) {
|
||||
/* set default color of new strokes for this layer */
|
||||
|
|
|
@ -515,7 +515,7 @@ void BKE_gpencil_convert_curve(Main *bmain,
|
|||
if (collection != NULL) {
|
||||
gpl = BKE_gpencil_layer_named_get(gpd, collection->id.name + 2);
|
||||
if (gpl == NULL) {
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, collection->id.name + 2, true);
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, collection->id.name + 2, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ void BKE_gpencil_convert_curve(Main *bmain,
|
|||
if (gpl == NULL) {
|
||||
gpl = BKE_gpencil_layer_active_get(gpd);
|
||||
if (gpl == NULL) {
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2439,7 +2439,7 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
|
|||
/* Create Layer and Frame. */
|
||||
bGPDlayer *gpl_fill = BKE_gpencil_layer_named_get(gpd, element_name);
|
||||
if (gpl_fill == NULL) {
|
||||
gpl_fill = BKE_gpencil_layer_addnew(gpd, element_name, true);
|
||||
gpl_fill = BKE_gpencil_layer_addnew(gpd, element_name, true, false);
|
||||
}
|
||||
bGPDframe *gpf_fill = BKE_gpencil_layer_frame_get(
|
||||
gpl_fill, CFRA + frame_offset, GP_GETFRAME_ADD_NEW);
|
||||
|
@ -2492,7 +2492,7 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
|
|||
/* Create Layer and Frame. */
|
||||
bGPDlayer *gpl_stroke = BKE_gpencil_layer_named_get(gpd, element_name);
|
||||
if (gpl_stroke == NULL) {
|
||||
gpl_stroke = BKE_gpencil_layer_addnew(gpd, element_name, true);
|
||||
gpl_stroke = BKE_gpencil_layer_addnew(gpd, element_name, true, false);
|
||||
}
|
||||
bGPDframe *gpf_stroke = BKE_gpencil_layer_frame_get(
|
||||
gpl_stroke, CFRA + frame_offset, GP_GETFRAME_ADD_NEW);
|
||||
|
|
|
@ -1548,7 +1548,7 @@ static void annotation_paint_initstroke(tGPsdata *p,
|
|||
if (p->gpl == NULL) {
|
||||
/* tag for annotations */
|
||||
p->gpd->flag |= GP_DATA_ANNOTATIONS;
|
||||
p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("Note"), true);
|
||||
p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("Note"), true, false);
|
||||
|
||||
if (p->custom_color[3]) {
|
||||
copy_v3_v3(p->gpl->color, p->custom_color);
|
||||
|
|
|
@ -90,7 +90,7 @@ void ED_gpencil_create_blank(bContext *C, Object *ob, float UNUSED(mat[4][4]))
|
|||
ob->actcol = color_black + 1;
|
||||
|
||||
/* layers */
|
||||
bGPDlayer *layer = BKE_gpencil_layer_addnew(gpd, "GP_Layer", true);
|
||||
bGPDlayer *layer = BKE_gpencil_layer_addnew(gpd, "GP_Layer", true, false);
|
||||
|
||||
/* frames */
|
||||
BKE_gpencil_frame_addnew(layer, CFRA);
|
||||
|
|
|
@ -96,7 +96,7 @@ void ED_gpencil_create_lineart(bContext *C, Object *ob)
|
|||
ob->actcol = color_black + 1;
|
||||
|
||||
/* layers */
|
||||
bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true);
|
||||
bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true, false);
|
||||
|
||||
/* frames */
|
||||
BKE_gpencil_frame_addnew(lines, 0);
|
||||
|
|
|
@ -837,8 +837,8 @@ void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
|
|||
|
||||
/* layers */
|
||||
/* NOTE: For now, we just add new layers, to make it easier to separate out old/new instances */
|
||||
bGPDlayer *Fills = BKE_gpencil_layer_addnew(gpd, "Fills", false);
|
||||
bGPDlayer *Lines = BKE_gpencil_layer_addnew(gpd, "Lines", true);
|
||||
bGPDlayer *Fills = BKE_gpencil_layer_addnew(gpd, "Fills", false, false);
|
||||
bGPDlayer *Lines = BKE_gpencil_layer_addnew(gpd, "Lines", true, false);
|
||||
|
||||
/* frames */
|
||||
/* NOTE: No need to check for existing, as this will take care of it for us */
|
||||
|
|
|
@ -225,8 +225,8 @@ void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
|
|||
ob->actcol = color_black + 1;
|
||||
|
||||
/* layers */
|
||||
bGPDlayer *colors = BKE_gpencil_layer_addnew(gpd, "Colors", false);
|
||||
bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true);
|
||||
bGPDlayer *colors = BKE_gpencil_layer_addnew(gpd, "Colors", false, false);
|
||||
bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true, false);
|
||||
|
||||
/* frames */
|
||||
bGPDframe *frame_color = BKE_gpencil_frame_addnew(colors, CFRA);
|
||||
|
|
|
@ -1857,7 +1857,7 @@ static int image_to_gpencil_exec(bContext *C, wmOperator *op)
|
|||
|
||||
/* Add layer and frame. */
|
||||
bGPdata *gpd = (bGPdata *)ob->data;
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, "Image Layer", true);
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, "Image Layer", true, false);
|
||||
bGPDframe *gpf = BKE_gpencil_frame_addnew(gpl, CFRA);
|
||||
done = BKE_gpencil_from_image(sima, gpd, gpf, size, is_mask);
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ static int gpencil_data_add_exec(bContext *C, wmOperator *op)
|
|||
gpd->flag |= GP_DATA_ANNOTATIONS;
|
||||
|
||||
/* add new layer (i.e. a "note") */
|
||||
BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true);
|
||||
BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true, false);
|
||||
|
||||
/* notifiers */
|
||||
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
||||
|
@ -231,7 +231,7 @@ static int gpencil_layer_add_exec(bContext *C, wmOperator *op)
|
|||
|
||||
/* mark as annotation */
|
||||
(*gpd_ptr)->flag |= GP_DATA_ANNOTATIONS;
|
||||
BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true);
|
||||
BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true, false);
|
||||
gpd = *gpd_ptr;
|
||||
}
|
||||
else {
|
||||
|
@ -239,7 +239,7 @@ static int gpencil_layer_add_exec(bContext *C, wmOperator *op)
|
|||
Object *ob = CTX_data_active_object(C);
|
||||
if ((ob != NULL) && (ob->type == OB_GPENCIL)) {
|
||||
gpd = (bGPdata *)ob->data;
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true, false);
|
||||
/* Add a new frame to make it visible in Dopesheet. */
|
||||
if (gpl != NULL) {
|
||||
gpl->actframe = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_ADD_NEW);
|
||||
|
@ -524,7 +524,6 @@ enum {
|
|||
|
||||
static bool gpencil_layer_duplicate_object_poll(bContext *C)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
|
||||
return false;
|
||||
|
@ -537,99 +536,75 @@ static bool gpencil_layer_duplicate_object_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* check there are more grease pencil objects */
|
||||
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
||||
if ((base->object != ob) && (base->object->type == OB_GPENCIL)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int gpencil_layer_duplicate_object_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
char name[MAX_ID_NAME - 2];
|
||||
RNA_string_get(op->ptr, "object", name);
|
||||
|
||||
if (name[0] == '\0') {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
const bool only_active = RNA_boolean_get(op->ptr, "only_active");
|
||||
|
||||
Object *ob_dst = (Object *)BKE_scene_object_find_by_name(scene, name);
|
||||
|
||||
int mode = RNA_enum_get(op->ptr, "mode");
|
||||
const int mode = RNA_enum_get(op->ptr, "mode");
|
||||
|
||||
Object *ob_src = CTX_data_active_object(C);
|
||||
bGPdata *gpd_src = (bGPdata *)ob_src->data;
|
||||
bGPDlayer *gpl_active = BKE_gpencil_layer_active_get(gpd_src);
|
||||
|
||||
/* Sanity checks. */
|
||||
if (ELEM(NULL, gpd_src, ob_dst)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
/* Cannot copy itself and check destination type. */
|
||||
if ((ob_src == ob_dst) || (ob_dst->type != OB_GPENCIL)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
bGPdata *gpd_dst = (bGPdata *)ob_dst->data;
|
||||
/* Disable destination active layer to keep order. */
|
||||
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_dst->layers) {
|
||||
gpl->flag &= ~GP_LAYER_ACTIVE;
|
||||
}
|
||||
|
||||
LISTBASE_FOREACH (bGPDlayer *, gpl_src, &gpd_src->layers) {
|
||||
if ((only_active) && (gpl_src != gpl_active)) {
|
||||
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
|
||||
if ((ob == ob_src) || (ob->type != OB_GPENCIL)) {
|
||||
continue;
|
||||
}
|
||||
/* Create new layer. */
|
||||
bGPDlayer *gpl_dst = BKE_gpencil_layer_addnew(gpd_dst, gpl_src->info, true);
|
||||
/* Need to copy some variables (not all). */
|
||||
gpl_dst->onion_flag = gpl_src->onion_flag;
|
||||
gpl_dst->thickness = gpl_src->thickness;
|
||||
gpl_dst->line_change = gpl_src->line_change;
|
||||
copy_v4_v4(gpl_dst->tintcolor, gpl_src->tintcolor);
|
||||
gpl_dst->opacity = gpl_src->opacity;
|
||||
|
||||
/* Create all frames. */
|
||||
LISTBASE_FOREACH (bGPDframe *, gpf_src, &gpl_src->frames) {
|
||||
|
||||
if ((mode == GP_LAYER_COPY_OBJECT_ACT_FRAME) && (gpf_src != gpl_src->actframe)) {
|
||||
bGPdata *gpd_dst = (bGPdata *)ob->data;
|
||||
LISTBASE_FOREACH_BACKWARD (bGPDlayer *, gpl_src, &gpd_src->layers) {
|
||||
if ((only_active) && (gpl_src != gpl_active)) {
|
||||
continue;
|
||||
}
|
||||
/* Create new layer (adding at head of the list). */
|
||||
bGPDlayer *gpl_dst = BKE_gpencil_layer_addnew(gpd_dst, gpl_src->info, true, true);
|
||||
/* Need to copy some variables (not all). */
|
||||
gpl_dst->onion_flag = gpl_src->onion_flag;
|
||||
gpl_dst->thickness = gpl_src->thickness;
|
||||
gpl_dst->line_change = gpl_src->line_change;
|
||||
copy_v4_v4(gpl_dst->tintcolor, gpl_src->tintcolor);
|
||||
gpl_dst->opacity = gpl_src->opacity;
|
||||
|
||||
/* Create new frame. */
|
||||
bGPDframe *gpf_dst = BKE_gpencil_frame_addnew(gpl_dst, gpf_src->framenum);
|
||||
/* Create all frames. */
|
||||
LISTBASE_FOREACH (bGPDframe *, gpf_src, &gpl_src->frames) {
|
||||
|
||||
/* Copy strokes. */
|
||||
LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
|
||||
|
||||
/* Make copy of source stroke. */
|
||||
bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
|
||||
|
||||
/* Check if material is in destination object,
|
||||
* otherwise add the slot with the material. */
|
||||
Material *ma_src = BKE_object_material_get(ob_src, gps_src->mat_nr + 1);
|
||||
if (ma_src != NULL) {
|
||||
int idx = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma_src);
|
||||
|
||||
/* Reassign the stroke material to the right slot in destination object. */
|
||||
gps_dst->mat_nr = idx;
|
||||
if ((mode == GP_LAYER_COPY_OBJECT_ACT_FRAME) && (gpf_src != gpl_src->actframe)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Add new stroke to frame. */
|
||||
BLI_addtail(&gpf_dst->strokes, gps_dst);
|
||||
/* Create new frame. */
|
||||
bGPDframe *gpf_dst = BKE_gpencil_frame_addnew(gpl_dst, gpf_src->framenum);
|
||||
|
||||
/* Copy strokes. */
|
||||
LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
|
||||
|
||||
/* Make copy of source stroke. */
|
||||
bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
|
||||
|
||||
/* Check if material is in destination object,
|
||||
* otherwise add the slot with the material. */
|
||||
Material *ma_src = BKE_object_material_get(ob_src, gps_src->mat_nr + 1);
|
||||
if (ma_src != NULL) {
|
||||
int idx = BKE_gpencil_object_material_ensure(bmain, ob, ma_src);
|
||||
|
||||
/* Reassign the stroke material to the right slot in destination object. */
|
||||
gps_dst->mat_nr = idx;
|
||||
}
|
||||
|
||||
/* Add new stroke to frame. */
|
||||
BLI_addtail(&gpf_dst->strokes, gps_dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* notifiers */
|
||||
DEG_id_tag_update(&gpd_dst->id,
|
||||
ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
|
||||
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
|
||||
}
|
||||
/* notifiers */
|
||||
DEG_id_tag_update(&gpd_dst->id,
|
||||
ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
|
||||
DEG_id_tag_update(&ob_dst->id, ID_RECALC_COPY_ON_WRITE);
|
||||
CTX_DATA_END;
|
||||
|
||||
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
|
@ -648,7 +623,7 @@ void GPENCIL_OT_layer_duplicate_object(wmOperatorType *ot)
|
|||
/* identifiers */
|
||||
ot->name = "Duplicate Layer to New Object";
|
||||
ot->idname = "GPENCIL_OT_layer_duplicate_object";
|
||||
ot->description = "Make a copy of the active Grease Pencil layer to new object";
|
||||
ot->description = "Make a copy of the active Grease Pencil layer to selected object";
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = gpencil_layer_duplicate_object_exec;
|
||||
|
@ -657,17 +632,11 @@ void GPENCIL_OT_layer_duplicate_object(wmOperatorType *ot)
|
|||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
ot->prop = RNA_def_string(
|
||||
ot->srna, "object", NULL, MAX_ID_NAME - 2, "Object", "Name of the destination object");
|
||||
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
RNA_def_enum(ot->srna, "mode", copy_mode, GP_LAYER_COPY_OBJECT_ALL_FRAME, "Mode", "");
|
||||
|
||||
prop = RNA_def_boolean(ot->srna,
|
||||
"only_active",
|
||||
true,
|
||||
"Only Active",
|
||||
"Append only active Layer, uncheck to append all layers");
|
||||
"Copy only active Layer, uncheck to append all layers");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
}
|
||||
|
||||
|
@ -1461,7 +1430,7 @@ static int gpencil_layer_change_exec(bContext *C, wmOperator *op)
|
|||
/* Get layer or create new one */
|
||||
if (layer_num == -1) {
|
||||
/* Create layer */
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true, false);
|
||||
}
|
||||
else {
|
||||
/* Try to get layer */
|
||||
|
@ -3608,9 +3577,8 @@ void GPENCIL_OT_set_active_material(wmOperatorType *ot)
|
|||
}
|
||||
|
||||
/* ********************* Append Materials in a new object ************************** */
|
||||
static bool gpencil_materials_append_to_object_poll(bContext *C)
|
||||
static bool gpencil_materials_copy_to_object_poll(bContext *C)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
|
||||
return false;
|
||||
|
@ -3620,85 +3588,64 @@ static bool gpencil_materials_append_to_object_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* check there are more grease pencil objects */
|
||||
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
||||
if ((base->object != ob) && (base->object->type == OB_GPENCIL)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int gpencil_materials_append_to_object_exec(bContext *C, wmOperator *op)
|
||||
static int gpencil_materials_copy_to_object_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
char name[MAX_ID_NAME - 2];
|
||||
RNA_string_get(op->ptr, "object", name);
|
||||
|
||||
if (name[0] == '\0') {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
const bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
|
||||
|
||||
Object *ob_dst = (Object *)BKE_scene_object_find_by_name(scene, name);
|
||||
const bool only_active = RNA_boolean_get(op->ptr, "only_active");
|
||||
Object *ob_src = CTX_data_active_object(C);
|
||||
Material *ma_active = BKE_gpencil_material(ob_src, ob_src->actcol);
|
||||
|
||||
/* Sanity checks. */
|
||||
if (ELEM(NULL, ob_src, ob_dst)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
/* Cannot copy itself and check destination type. */
|
||||
if ((ob_src == ob_dst) || (ob_dst->type != OB_GPENCIL)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* Duplicate materials. */
|
||||
for (int i = 0; i < ob_src->totcol; i++) {
|
||||
Material *ma_src = BKE_object_material_get(ob_src, i + 1);
|
||||
if (only_selected && ma_src != ma_active) {
|
||||
CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
|
||||
if ((ob == ob_src) || (ob->type != OB_GPENCIL)) {
|
||||
continue;
|
||||
}
|
||||
/* Duplicate materials. */
|
||||
for (int i = 0; i < ob_src->totcol; i++) {
|
||||
Material *ma_src = BKE_object_material_get(ob_src, i + 1);
|
||||
if (only_active && ma_src != ma_active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ma_src != NULL) {
|
||||
BKE_gpencil_object_material_ensure(bmain, ob_dst, ma_src);
|
||||
if (ma_src != NULL) {
|
||||
BKE_gpencil_object_material_ensure(bmain, ob, ma_src);
|
||||
}
|
||||
}
|
||||
|
||||
/* notifiers */
|
||||
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
/* notifiers */
|
||||
DEG_id_tag_update(&ob_dst->id, ID_RECALC_COPY_ON_WRITE);
|
||||
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void GPENCIL_OT_materials_append_to_object(wmOperatorType *ot)
|
||||
void GPENCIL_OT_materials_copy_to_object(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name = "Append Materials to New Object";
|
||||
ot->idname = "GPENCIL_OT_materials_append_to_object";
|
||||
ot->name = "Copy Materials to Selected Object";
|
||||
ot->idname = "GPENCIL_OT_materials_copy_to_object";
|
||||
ot->description = "Append Materials of the active Grease Pencil to other object";
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = gpencil_materials_append_to_object_exec;
|
||||
ot->poll = gpencil_materials_append_to_object_poll;
|
||||
ot->exec = gpencil_materials_copy_to_object_exec;
|
||||
ot->poll = gpencil_materials_copy_to_object_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
ot->prop = RNA_def_string(
|
||||
ot->srna, "object", NULL, MAX_ID_NAME - 2, "Object", "Name of the destination object");
|
||||
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna,
|
||||
"only_selected",
|
||||
"only_active",
|
||||
true,
|
||||
"Only Selected",
|
||||
"Append only selected material, uncheck to append all materials");
|
||||
"Only Active",
|
||||
"Append only active material, uncheck to append all materials");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
}
|
||||
|
||||
|
|
|
@ -1677,7 +1677,7 @@ static int gpencil_strokes_paste_exec(bContext *C, wmOperator *op)
|
|||
|
||||
if (gpl == NULL) {
|
||||
/* no active layer - let's just create one */
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true, false);
|
||||
}
|
||||
else if ((BKE_gpencil_layer_is_editable(gpl) == false) && (type == GP_COPY_TO_ACTIVE)) {
|
||||
BKE_report(
|
||||
|
@ -1835,7 +1835,7 @@ static int gpencil_move_to_layer_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
else {
|
||||
/* Create a new layer. */
|
||||
target_layer = BKE_gpencil_layer_addnew(gpd, "GP_Layer", true);
|
||||
target_layer = BKE_gpencil_layer_addnew(gpd, "GP_Layer", true, false);
|
||||
}
|
||||
|
||||
if (target_layer == NULL) {
|
||||
|
@ -4600,7 +4600,7 @@ static int gpencil_stroke_separate_exec(bContext *C, wmOperator *op)
|
|||
if (gps->flag & GP_STROKE_SELECT) {
|
||||
/* add layer if not created before */
|
||||
if (gpl_dst == NULL) {
|
||||
gpl_dst = BKE_gpencil_layer_addnew(gpd_dst, gpl->info, false);
|
||||
gpl_dst = BKE_gpencil_layer_addnew(gpd_dst, gpl->info, false, false);
|
||||
}
|
||||
|
||||
/* add frame if not created before */
|
||||
|
|
|
@ -1689,7 +1689,7 @@ static tGPDfill *gpencil_session_init_fill(bContext *C, wmOperator *op)
|
|||
tgpf->gpd = gpd;
|
||||
tgpf->gpl = BKE_gpencil_layer_active_get(gpd);
|
||||
if (tgpf->gpl == NULL) {
|
||||
tgpf->gpl = BKE_gpencil_layer_addnew(tgpf->gpd, DATA_("GP_Layer"), true);
|
||||
tgpf->gpl = BKE_gpencil_layer_addnew(tgpf->gpd, DATA_("GP_Layer"), true, false);
|
||||
}
|
||||
|
||||
tgpf->lock_axis = ts->gp_sculpt.lock_axis;
|
||||
|
|
|
@ -538,7 +538,7 @@ void GPENCIL_OT_material_lock_unused(struct wmOperatorType *ot);
|
|||
void GPENCIL_OT_material_select(struct wmOperatorType *ot);
|
||||
void GPENCIL_OT_material_set(struct wmOperatorType *ot);
|
||||
void GPENCIL_OT_set_active_material(struct wmOperatorType *ot);
|
||||
void GPENCIL_OT_materials_append_to_object(struct wmOperatorType *ot);
|
||||
void GPENCIL_OT_materials_copy_to_object(struct wmOperatorType *ot);
|
||||
|
||||
/* convert old 2.7 files to 2.8 */
|
||||
void GPENCIL_OT_convert_old_files(struct wmOperatorType *ot);
|
||||
|
|
|
@ -651,7 +651,7 @@ void ED_operatortypes_gpencil(void)
|
|||
|
||||
WM_operatortype_append(GPENCIL_OT_material_to_vertex_color);
|
||||
WM_operatortype_append(GPENCIL_OT_extract_palette_vertex);
|
||||
WM_operatortype_append(GPENCIL_OT_materials_append_to_object);
|
||||
WM_operatortype_append(GPENCIL_OT_materials_copy_to_object);
|
||||
|
||||
WM_operatortype_append(GPENCIL_OT_transform_fill);
|
||||
WM_operatortype_append(GPENCIL_OT_reset_transform_fill);
|
||||
|
|
|
@ -2120,7 +2120,7 @@ static void gpencil_paint_initstroke(tGPsdata *p,
|
|||
/* get active layer (or add a new one if non-existent) */
|
||||
p->gpl = BKE_gpencil_layer_active_get(p->gpd);
|
||||
if (p->gpl == NULL) {
|
||||
p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("GP_Layer"), true);
|
||||
p->gpl = BKE_gpencil_layer_addnew(p->gpd, DATA_("GP_Layer"), true, false);
|
||||
changed = true;
|
||||
if (p->custom_color[3]) {
|
||||
copy_v3_v3(p->gpl->color, p->custom_color);
|
||||
|
|
|
@ -314,7 +314,7 @@ static void gpencil_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
|
|||
|
||||
/* if layer doesn't exist, create a new one */
|
||||
if (gpl == NULL) {
|
||||
gpl = BKE_gpencil_layer_addnew(tgpi->gpd, DATA_("Primitives"), true);
|
||||
gpl = BKE_gpencil_layer_addnew(tgpi->gpd, DATA_("Primitives"), true, false);
|
||||
}
|
||||
tgpi->gpl = gpl;
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ static void trace_initialize_job_data(TraceJob *trace_job)
|
|||
trace_job->gpd = (bGPdata *)trace_job->ob_gpencil->data;
|
||||
trace_job->gpl = BKE_gpencil_layer_active_get(trace_job->gpd);
|
||||
if (trace_job->gpl == NULL) {
|
||||
trace_job->gpl = BKE_gpencil_layer_addnew(trace_job->gpd, DATA_("Trace"), true);
|
||||
trace_job->gpl = BKE_gpencil_layer_addnew(trace_job->gpd, DATA_("Trace"), true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -446,7 +446,7 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
|
|||
|
||||
gpl = view3d_ruler_layer_get(gpd);
|
||||
if (gpl == NULL) {
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, ruler_name, false);
|
||||
gpl = BKE_gpencil_layer_addnew(gpd, ruler_name, false, false);
|
||||
copy_v4_v4(gpl->color, U.gpencil_new_layer_col);
|
||||
gpl->thickness = 1;
|
||||
gpl->flag |= GP_LAYER_HIDE | GP_LAYER_IS_RULER;
|
||||
|
|
|
@ -102,7 +102,7 @@ bool GpencilImporterSVG::read()
|
|||
bGPDlayer *gpl = (bGPDlayer *)BLI_findstring(
|
||||
&gpd_->layers, layer_id, offsetof(bGPDlayer, info));
|
||||
if (gpl == nullptr) {
|
||||
gpl = BKE_gpencil_layer_addnew(gpd_, layer_id, true);
|
||||
gpl = BKE_gpencil_layer_addnew(gpd_, layer_id, true, false);
|
||||
/* Disable lights. */
|
||||
gpl->flag &= ~GP_LAYER_USE_LIGHTS;
|
||||
}
|
||||
|
|
|
@ -1037,7 +1037,7 @@ static bGPDframe *rna_GPencil_frame_copy(bGPDlayer *layer, bGPDframe *src)
|
|||
|
||||
static bGPDlayer *rna_GPencil_layer_new(bGPdata *gpd, const char *name, bool setactive)
|
||||
{
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, name, setactive != 0);
|
||||
bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, name, setactive != 0, false);
|
||||
|
||||
WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
|
||||
|
||||
|
|
Loading…
Reference in New Issue