[Bf-blender-cvs] [e5989702ee0] greasepencil-object: New Separate operator
Antonio Vazquez
noreply at git.blender.org
Thu Feb 1 16:31:10 CET 2018
Commit: e5989702ee047a1d228e9de3334e28cbff615605
Author: Antonio Vazquez
Date: Thu Feb 1 16:17:19 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBe5989702ee047a1d228e9de3334e28cbff615605
New Separate operator
This operator works similar to mesh separate operator, but for grease pencil strokes.
Two options:
a) Selected Strokes
b) Active Layer
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_ops.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index d78423fac6c..c695982de63 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -232,6 +232,12 @@ class GreasePencilStrokeEditPanel:
col.operator("gpencil.stroke_simplify", text="Simplify Adaptative")
col.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
col.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
+
+ col.separator()
+ col.operator("gpencil.stroke_separate", text="Separate").mode = 'SELECT'
+ col.operator("gpencil.stroke_separate", text="Separate Layer").mode = 'LAYER'
+
+ col.separator()
col.operator("gpencil.stroke_flip", text="Flip Direction")
col.separator()
@@ -1006,6 +1012,15 @@ class GPENCIL_MT_snap(Menu):
layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
+class GPENCIL_MT_separate(Menu):
+ bl_label = "Separate"
+
+ def draw(self, context):
+ layout = self.layout
+ layout.operator("gpencil.stroke_separate", text="Selected Strokes").mode = 'SELECT'
+ layout.operator("gpencil.stroke_separate", text="Active Layer").mode = 'LAYER'
+
+
class GPENCIL_MT_gpencil_edit_specials(Menu):
bl_label = "GPencil Specials"
@@ -1019,6 +1034,9 @@ class GPENCIL_MT_gpencil_edit_specials(Menu):
layout.operator("gpencil.stroke_simplify_fixed", text="Simplify")
layout.operator("gpencil.stroke_simplify", text="Simplify Adaptative")
+ layout.separator()
+ layout.menu("GPENCIL_MT_separate", text="Separate")
+
layout.separator()
layout.operator("gpencil.stroke_join", text="Join").type = 'JOIN'
@@ -1345,15 +1363,16 @@ class GreasePencilDataPanel:
# Full-Row - Frame Locking (and Delete Frame)
row = layout.row(align=True)
- row.active = not gpl.lock
+ if gpl:
+ row.active = not gpl.lock
- if gpl.active_frame:
- lock_status = iface_("Locked") if gpl.lock_frame else iface_("Unlocked")
- lock_label = iface_("Frame: %d (%s)") % (gpl.active_frame.frame_number, lock_status)
- else:
- lock_label = iface_("Lock Frame")
- row.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
- row.operator("gpencil.active_frame_delete", text="", icon='X')
+ if gpl.active_frame:
+ lock_status = iface_("Locked") if gpl.lock_frame else iface_("Unlocked")
+ lock_label = iface_("Frame: %d (%s)") % (gpl.active_frame.frame_number, lock_status)
+ else:
+ lock_label = iface_("Lock Frame")
+ row.prop(gpl, "lock_frame", text=lock_label, icon='UNLOCKED')
+ row.operator("gpencil.active_frame_delete", text="", icon='X')
class GreasePencilLayerOptionPanel:
@@ -1734,6 +1753,7 @@ classes = (
GPENCIL_MT_pie_tools_more,
GPENCIL_MT_pie_sculpt,
GPENCIL_MT_snap,
+ GPENCIL_MT_separate,
GPENCIL_MT_gpencil_edit_specials,
GPENCIL_MT_gpencil_sculpt_specials,
GPENCIL_MT_gpencil_draw_specials,
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 5d727a578cd..f047baf1b93 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -3326,6 +3326,7 @@ class VIEW3D_MT_edit_gpencil(Menu):
layout.separator()
+ layout.operator_menu_enum("gpencil.stroke_separate", "mode", text="Separate...")
layout.operator_menu_enum("gpencil.stroke_join", "type", text="Join...")
layout.operator("gpencil.stroke_flip", text="Flip Direction")
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 856dea662fa..2a5a0915c27 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -85,6 +85,7 @@ void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct bGPDframe
void BKE_gpencil_copy_data(struct Main *bmain, struct bGPdata *gpd_dst, const struct bGPdata *gpd_src, const int flag);
struct bGPdata *BKE_gpencil_copy(struct Main *bmain, const struct bGPdata *gpd);
struct bGPdata *BKE_gpencil_data_duplicate(struct Main *bmain, const struct bGPdata *gpd, bool internal_copy);
+void BKE_gpencil_copy_palette_data(struct bGPdata *gpd_dst, const struct bGPdata *gpd_src);
void BKE_gpencil_make_local(struct Main *bmain, struct bGPdata *gpd, const bool lib_local);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 5440897a07e..fa7f101d9fa 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1067,7 +1067,6 @@ bGPDbrush *BKE_gpencil_brush_duplicate(const bGPDbrush *brush_src)
return brush_dst;
}
-
/* make a copy of a given gpencil layer */
bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
{
@@ -1102,37 +1101,27 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
}
/**
- * Only copy internal data of GreasePencil ID from source to already allocated/initialized destination.
- * You probably never want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
- *
- * WARNING! This function will not handle ID user count!
- *
- * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
- */
-void BKE_gpencil_copy_data(Main *UNUSED(bmain), bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag))
+* Only copy internal data of palettes to already allocated/initialized destination.
+*
+* WARNING! This function will not handle ID user count!
+*
+*/
+void BKE_gpencil_copy_palette_data(bGPdata *gpd_dst, const bGPdata *gpd_src)
{
- /* copy layers */
- BLI_listbase_clear(&gpd_dst->layers);
- for (const bGPDlayer *gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) {
- /* make a copy of source layer and its data */
- bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); /* TODO here too could add unused flags... */
- BLI_addtail(&gpd_dst->layers, gpl_dst);
- }
-
/* copy palette slots */
BLI_listbase_clear(&gpd_dst->palette_slots);
for (const bGPDpaletteref *palslot_src = gpd_src->palette_slots.first; palslot_src; palslot_src = palslot_src->next) {
bGPDpaletteref *palslot_dst = MEM_dupallocN(palslot_src);
-
+
/* TODO: Separate out into separate function, and make use of LIB_ID_COPY flags? */
if (palslot_dst->palette) {
/* XXX: Better safe than sorry... at worst, usercount won't go down,
- * and the user has to reload?
- */
+ * and the user has to reload?
+ */
id_us_plus(&palslot_dst->palette->id);
}
palslot_dst->next = palslot_dst->prev = NULL;
-
+
BLI_addtail(&gpd_dst->palette_slots, palslot_dst);
}
@@ -1144,6 +1133,28 @@ void BKE_gpencil_copy_data(Main *UNUSED(bmain), bGPdata *gpd_dst, const bGPdata
}
}
+/**
+ * Only copy internal data of GreasePencil ID from source to already allocated/initialized destination.
+ * You probably never want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_gpencil_copy_data(Main *UNUSED(bmain), bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag))
+{
+ /* copy layers */
+ BLI_listbase_clear(&gpd_dst->layers);
+ for (const bGPDlayer *gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) {
+ /* make a copy of source layer and its data */
+ bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); /* TODO here too could add unused flags... */
+ BLI_addtail(&gpd_dst->layers, gpl_dst);
+ }
+
+ /* copy palette slots */
+ BKE_gpencil_copy_palette_data(gpd_dst, gpd_src);
+}
+
/* Standard API to make a copy of GP datablock, separate from copying its data */
bGPdata *BKE_gpencil_copy(Main *bmain, const bGPdata *gpd)
{
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 73d774d9467..5bcfa0696ae 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -55,11 +55,13 @@
#include "DNA_gpencil_types.h"
#include "DNA_workspace_types.h"
+#include "BKE_main.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_paint.h"
#include "BKE_library.h"
+#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_screen.h"
#include "BKE_workspace.h"
@@ -83,6 +85,7 @@
#include "ED_space_api.h"
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "gpencil_intern.h"
@@ -3065,3 +3068,166 @@ void GPENCIL_OT_stroke_simplify_fixed(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
+
+/* ***************** Separate Strokes ********************** */
+typedef enum eGP_SeparateModes {
+ /* Selected Strokes */
+ GP_SEPARATE_SELECT = 0,
+ /* Current Layer */
+ GP_SEPARATE_LAYER,
+} eGP_SeparateModes;
+
+/* XXX: Reuse reproject poll */
+static int gp_stroke_separate_poll(bContext *C)
+{
+ /* 2 Requirements:
+ * - 1) Editable GP data
+ * - 2) 3D View only
+ */
+ return (gp_stroke_edit_poll(C) && ED_operator_view3d_active(C));
+}
+
+static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
+{
+ Base *base_new;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Base *base_old = CTX_data_active_base(C);
+ bGPdata *src_gpd = ED_gpencil_data_get_active(C);
+ Object *src_ob = CTX_data_active_object(C);
+ Object *dst_ob = NULL;
+ bGPdata *dst_gpd = NULL;
+
+ eGP_SeparateModes mode = RNA_enum_get(op->ptr, "mode");
+
+ /* sanity checks */
+ if (ELEM(NULL, src_ob, src_gpd)) {
+ return OPERATOR_CANCELLED;
+ }
+ bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(src_gpd);
+
+ /* create a new object */
+ base_new = ED_object_add_duplicate(bmai
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list