[Bf-blender-cvs] [fa3a0697b84] master: Annotations: Split annotation operators and pointer functions

Antonio Vazquez noreply at git.blender.org
Tue Jan 7 11:34:26 CET 2020


Commit: fa3a0697b846bd0ed3766fcabd1bf6f260aa425a
Author: Antonio Vazquez
Date:   Tue Jan 7 11:29:42 2020 +0100
Branches: master
https://developer.blender.org/rBfa3a0697b846bd0ed3766fcabd1bf6f260aa425a

Annotations: Split annotation operators and pointer functions

This allows to have annotation panels and grease pencil object panel at the same time.

Differential Revision: https://developer.blender.org/D6467

===================================================================

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/gpencil/annotate_draw.c
M	source/blender/editors/gpencil/annotate_paint.c
M	source/blender/editors/gpencil/gpencil_data.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
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/screen/screen_context.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 45cb10bb3bd..2001f46820f 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -581,9 +581,9 @@ class AnnotationDataPanel:
     def poll(cls, context):
         # Show this panel as long as someone that might own this exists
         # AND the owner isn't an object (e.g. GP Object)
-        if context.gpencil_data_owner is None:
+        if context.annotation_data_owner is None:
             return False
-        elif type(context.gpencil_data_owner) is bpy.types.Object:
+        elif type(context.annotation_data_owner) is bpy.types.Object:
             return False
         else:
             return True
@@ -597,14 +597,14 @@ class AnnotationDataPanel:
         layout.use_property_decorate = False
 
         # Grease Pencil owner.
-        gpd_owner = context.gpencil_data_owner
-        gpd = context.gpencil_data
+        gpd_owner = context.annotation_data_owner
+        gpd = context.annotation_data
 
         # Owner selector.
         if context.space_data.type == 'CLIP_EDITOR':
             layout.row().prop(context.space_data, "grease_pencil_source", expand=True)
 
-        layout.template_ID(gpd_owner, "grease_pencil", new="gpencil.data_add", unlink="gpencil.data_unlink")
+        layout.template_ID(gpd_owner, "grease_pencil", new="gpencil.annotation_add", unlink="gpencil.data_unlink")
 
         # List of layers/notes.
         if gpd and gpd.layers:
@@ -624,17 +624,17 @@ class AnnotationDataPanel:
         col = row.column()
 
         sub = col.column(align=True)
-        sub.operator("gpencil.layer_add", icon='ADD', text="")
-        sub.operator("gpencil.layer_remove", icon='REMOVE', text="")
+        sub.operator("gpencil.layer_annotation_add", icon='ADD', text="")
+        sub.operator("gpencil.layer_annotation_remove", icon='REMOVE', text="")
 
-        gpl = context.active_gpencil_layer
+        gpl = context.active_annotation_layer
         if gpl:
             if len(gpd.layers) > 1:
                 col.separator()
 
                 sub = col.column(align=True)
-                sub.operator("gpencil.layer_move", icon='TRIA_UP', text="").type = 'UP'
-                sub.operator("gpencil.layer_move", icon='TRIA_DOWN', text="").type = 'DOWN'
+                sub.operator("gpencil.layer_annotation_move", icon='TRIA_UP', text="").type = 'UP'
+                sub.operator("gpencil.layer_annotation_move", icon='TRIA_DOWN', text="").type = 'DOWN'
 
         tool_settings = context.tool_settings
         if gpd and gpl:
@@ -653,7 +653,7 @@ class AnnotationDataPanel:
             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')
+            row.operator("gpencil.annotation_active_frame_delete", text="", icon='X')
 
 
 class AnnotationOnionSkin:
@@ -665,26 +665,26 @@ class AnnotationOnionSkin:
     def poll(cls, context):
         # Show this panel as long as someone that might own this exists
         # AND the owner isn't an object (e.g. GP Object)
-        if context.gpencil_data_owner is None:
+        if context.annotation_data_owner is None:
             return False
-        elif type(context.gpencil_data_owner) is bpy.types.Object:
+        elif type(context.annotation_data_owner) is bpy.types.Object:
             return False
         else:
-            gpl = context.active_gpencil_layer
+            gpl = context.active_annotation_layer
             if gpl is None:
                 return False
 
             return True
 
     def draw_header(self, context):
-        gpl = context.active_gpencil_layer
+        gpl = context.active_annotation_layer
         self.layout.prop(gpl, "use_annotation_onion_skinning", text="")
 
     def draw(self, context):
         layout = self.layout
         layout.use_property_decorate = False
 
-        gpl = context.active_gpencil_layer
+        gpl = context.active_annotation_layer
         col = layout.column()
         split = col.split(factor=0.5)
         split.active = gpl.use_annotation_onion_skinning
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index e0f3a03733e..170b635f7e1 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -2115,6 +2115,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             _defs_gpencil_paint.curve,
             _defs_gpencil_paint.box,
             _defs_gpencil_paint.circle,
+            None,
+            *_tools_annotate,
         ],
         'EDIT_GPENCIL': [
             *_tools_gpencil_select,
@@ -2129,11 +2131,13 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
                 _defs_gpencil_edit.shear,
                 _defs_gpencil_edit.tosphere,
             ),
-
+            None,
+            *_tools_annotate,
         ],
         'SCULPT_GPENCIL': [
             _defs_gpencil_sculpt.generate_from_brushes,
             None,
+            *_tools_annotate,
             lambda context: (
                 VIEW3D_PT_tools_active._tools_gpencil_select
                 if _defs_gpencil_sculpt.poll_select_mask(context)
@@ -2142,6 +2146,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
         ],
         'WEIGHT_GPENCIL': [
             _defs_gpencil_weight.generate_from_brushes,
+            None,
+            *_tools_annotate,
         ],
     }
 
diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c
index 67bf64a2903..6e91be862a9 100644
--- a/source/blender/editors/gpencil/annotate_draw.c
+++ b/source/blender/editors/gpencil/annotate_draw.c
@@ -1056,7 +1056,7 @@ void ED_annotation_draw_2dimage(const bContext *C)
   int offsx, offsy, sizex, sizey;
   int dflag = GP_DRAWDATA_NOSTATUS;
 
-  bGPdata *gpd = ED_gpencil_data_get_active(C);  // XXX
+  bGPdata *gpd = ED_annotation_data_get_active(C);
   if (gpd == NULL) {
     return;
   }
@@ -1132,7 +1132,7 @@ void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
   if (sa == NULL) {
     return;
   }
-  bGPdata *gpd = ED_gpencil_data_get_active(C);  // XXX
+  bGPdata *gpd = ED_annotation_data_get_active(C);
   if (gpd == NULL) {
     return;
   }
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 7a10547f35c..04b5d8f6d40 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -218,19 +218,9 @@ static void gp_session_validatebuffer(tGPsdata *p);
 /* check if context is suitable for drawing */
 static bool gpencil_draw_poll(bContext *C)
 {
-  /* if is inside grease pencil draw mode cannot use annotations */
-  Object *obact = CTX_data_active_object(C);
-  ScrArea *sa = CTX_wm_area(C);
-  if ((sa) && (sa->spacetype == SPACE_VIEW3D)) {
-    if ((obact) && (obact->type == OB_GPENCIL) && (obact->mode == OB_MODE_PAINT_GPENCIL)) {
-      CTX_wm_operator_poll_msg_set(C, "Annotation cannot be used in grease pencil draw mode");
-      return false;
-    }
-  }
-
   if (ED_operator_regionactive(C)) {
     /* check if current context can support GPencil data */
-    if (ED_gpencil_data_get_pointers(C, NULL) != NULL) {
+    if (ED_annotation_data_get_pointers(C, NULL) != NULL) {
       /* check if Grease Pencil isn't already running */
       if (ED_gpencil_session_active() == 0) {
         return true;
@@ -240,7 +230,7 @@ static bool gpencil_draw_poll(bContext *C)
       }
     }
     else {
-      CTX_wm_operator_poll_msg_set(C, "Failed to find Grease Pencil data to draw into");
+      CTX_wm_operator_poll_msg_set(C, "Failed to find Annotation data to draw into");
     }
   }
   else {
@@ -1115,7 +1105,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
   }
 
   /* get gp-data */
-  gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr);
+  gpd_ptr = ED_annotation_data_get_pointers(C, &p->ownerPtr);
   if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) {
     p->status = GP_STATUS_ERROR;
     if (G.debug & G_DEBUG) {
@@ -1886,9 +1876,6 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
 /* start of interactive drawing part of operator */
 static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-  Object *ob = CTX_data_active_object(C);
-  ScrArea *sa = CTX_wm_area(C);
-  Scene *scene = CTX_data_scene(C);
   tGPsdata *p = NULL;
 
   /* support for tablets eraser pen */
@@ -1896,26 +1883,6 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
     RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER);
   }
 
-  /* if try to do annotations with a gp object selected, first
-   * unselect the object to avoid conflicts.
-   * The solution is not perfect but we can keep running the annotations while
-   * found a better solution.
-   */
-  if (sa && sa->spacetype == SPACE_VIEW3D) {
-    if ((ob != NULL) && (ob->type == OB_GPENCIL)) {
-      ob->mode = OB_MODE_OBJECT;
-      bGPdata *gpd = (bGPdata *)ob->data;
-      ED_gpencil_setup_modes(C, gpd, 0);
-      DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
-
-      ViewLayer *view_layer = CTX_data_view_layer(C);
-      BKE_view_layer_base_deselect_all(view_layer);
-      view_layer->basact = NULL;
-      DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
-      WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-    }
-  }
-
   if (G.debug & G_DEBUG) {
     printf("GPencil - Starting Drawing\n");
   }
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 1331cc92d96..fa23dd5e059 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -91,64 +91,43 @@
 /* ******************* Add New Data ************************ */
 static bool gp_data_add_po

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list