[Bf-blender-cvs] [679d46ff027] greasepencil-object: Add menu to set origin operator
Antonio Vazquez
noreply at git.blender.org
Sat Jul 8 17:10:52 CEST 2017
Commit: 679d46ff0275feeb8d703b4b784c5f8c78196963
Author: Antonio Vazquez
Date: Sat Jul 8 17:09:49 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB679d46ff0275feeb8d703b4b784c5f8c78196963
Add menu to set origin operator
In order to keep the UI consistency I have added a menu.
This menu has only one option, but the UI panel looks more consistent
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M source/blender/editors/gpencil/gpencil_edit.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 00aadc3d9cf..8585a44b40a 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -221,9 +221,7 @@ class GreasePencilStrokeEditPanel:
if is_3d_view:
layout.separator()
layout.operator_menu_enum("gpencil.reproject", text="Reproject Strokes...", property="type")
- layout.separator()
- layout.label("Set Origin:")
- layout.operator("gpencil.origin_to_cursor", text="Origin to 3D Cursor")
+ layout.operator_menu_enum("gpencil.origin_to_cursor", "type", text="Set Origin")
class GreasePencilAnimationPanel:
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 79dc43834bd..6de0c9dac12 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2565,6 +2565,10 @@ void GPENCIL_OT_stroke_subdivide(wmOperatorType *ot)
}
+enum {
+ GP_ORIGIN_TO_CURSOR = 0
+};
+
/* Poll callback for origin operators */
/* We only allow these in the 3D view and edit mode
*/
@@ -2579,13 +2583,14 @@ static int gp_origin_to_cursor_poll(bContext *C)
/* --------------------------------- */
-static int gp_origin_to_cursor_exec(bContext *C, wmOperator *UNUSED(op))
+static int gp_origin_to_cursor_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
bGPdata *gpd = ED_gpencil_data_get_active(C);
Object *obact = CTX_data_active_object(C);
+ int centermode = RNA_enum_get(op->ptr, "type");
bGPDspoint *pt;
float imat[3][3], bmat[3][3];
@@ -2598,47 +2603,58 @@ static int gp_origin_to_cursor_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
}
- /* move pivot point to 3D cursor location */
- WM_operator_name_call(C, "VIEW3D_OT_snap_selected_to_cursor", WM_OP_EXEC_REGION_WIN, NULL);
+ if (centermode == GP_ORIGIN_TO_CURSOR) {
+ /* move pivot point to 3D cursor location */
+ WM_operator_name_call(C, "VIEW3D_OT_snap_selected_to_cursor", WM_OP_EXEC_REGION_WIN, NULL);
- sub_v3_v3v3(offset_global, cursor_loc, obact->obmat[3]);
- copy_m3_m4(bmat, obact->obmat);
- invert_m3_m3(imat, bmat);
- mul_m3_v3(imat, offset_global);
- mul_v3_m3v3(offset_local, imat, offset_global);
+ sub_v3_v3v3(offset_global, cursor_loc, obact->obmat[3]);
+ copy_m3_m4(bmat, obact->obmat);
+ invert_m3_m3(imat, bmat);
+ mul_m3_v3(imat, offset_global);
+ mul_v3_m3v3(offset_local, imat, offset_global);
- /* recalculate all strokes (all layers are considered without evaluating lock attributtes) */
- for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
- for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
- /* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false)
- continue;
+ /* recalculate all strokes (all layers are considered without evaluating lock attributtes) */
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+ /* skip strokes that are invalid for current view */
+ if (ED_gpencil_stroke_can_use(C, gps) == false)
+ continue;
- for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- sub_v3_v3(&pt->x, offset_local);
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ sub_v3_v3(&pt->x, offset_local);
+ }
}
}
}
- }
- BKE_gpencil_batch_cache_dirty(gpd);
- WM_event_add_notifier(C, NC_SCENE | NC_GPENCIL, NULL);
+ BKE_gpencil_batch_cache_dirty(gpd);
+ WM_event_add_notifier(C, NC_SCENE | NC_GPENCIL, NULL);
+ }
return OPERATOR_FINISHED;
}
void GPENCIL_OT_origin_to_cursor(wmOperatorType *ot)
{
+ static EnumPropertyItem prop_set_center_types[] = {
+ { GP_ORIGIN_TO_CURSOR, "ORIGIN_CURSOR", 0, "Origin to 3D Cursor",
+ "Move strokes origin to position of the 3D cursor" },
+ { 0, NULL, 0, NULL, NULL }
+ };
+
/* identifiers */
ot->name = "Origin to 3D cursor";
ot->idname = "GPENCIL_OT_origin_to_cursor";
ot->description = "Set origing to current 3D cursor location moving pivot point and recalcule strokes";
/* callbacks */
+ ot->invoke = WM_menu_invoke;
ot->exec = gp_origin_to_cursor_exec;
ot->poll = gp_origin_to_cursor_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ ot->prop = RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
}
More information about the Bf-blender-cvs
mailing list