Commit: 009dbc2bc9fbd45f974b46835679fefae7b42561
Author: Antonioya
Date:   Tue Apr 9 20:12:21 2019 +0200
Branches: master
https://developer.blender.org/rB009dbc2bc9fbd45f974b46835679fefae7b42561

Fix T63427: Annotations don'twork with 2.79 settings

The problem was the colors were not converted and the annotation flag was not 
enabled.

Note: For Scene data (View3D) there is a convert operator.

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

M       source/blender/blenkernel/intern/gpencil.c
M       source/blender/blenloader/intern/versioning_280.c
M       source/blender/editors/gpencil/gpencil_old.c

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

diff --git a/source/blender/blenkernel/intern/gpencil.c 
b/source/blender/blenkernel/intern/gpencil.c
index 7109764faab..c204a8128c1 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1069,7 +1069,7 @@ Material *BKE_gpencil_object_material_new(Main *bmain, 
Object *ob, const char *n
 /* Returns the material for a brush with respect to its pinned state. */
 Material *BKE_gpencil_object_material_get_from_brush(Object *ob, Brush *brush)
 {
-       if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
+       if ((brush) && (brush->gpencil_settings->flag & 
GP_BRUSH_MATERIAL_PINNED)) {
                Material *ma = BKE_gpencil_brush_material_get(brush);
                return ma;
        }
@@ -1081,7 +1081,7 @@ Material 
*BKE_gpencil_object_material_get_from_brush(Object *ob, Brush *brush)
 /* Returns the material index for a brush with respect to its pinned state. */
 int BKE_gpencil_object_material_get_index_from_brush(Object *ob, Brush *brush)
 {
-       if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
+       if ((brush) && (brush->gpencil_settings->flag & 
GP_BRUSH_MATERIAL_PINNED)) {
                return BKE_gpencil_object_material_get_index(ob, 
brush->gpencil_settings->material);
        }
        else {
diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index a32ff9f5ef0..6eeb70c3e16 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -564,6 +564,28 @@ static void 
do_version_collection_propagate_lib_to_children(Collection *collecti
        }
 }
 
+/** convert old annotations colors */
+static void do_versions_fix_annotations(bGPdata *gpd)
+{
+       for (const bGPDpalette *palette = gpd->palettes.first; palette; palette 
= palette->next) {
+               for (bGPDpalettecolor *palcolor = palette->colors.first; 
palcolor; palcolor = palcolor->next) {
+                       /* fix layers */
+                       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) {
+                                               if ((gps->colorname[0] != '\0') 
&&
+                                                       (STREQ(gps->colorname, 
palcolor->info)))
+                                               {
+                                                       /* copy color settings 
*/
+                                                       copy_v4_v4(gpl->color, 
palcolor->color);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
 void do_versions_after_linking_280(Main *bmain)
 {
        bool use_collection_compat_28 = true;
@@ -657,6 +679,30 @@ void do_versions_after_linking_280(Main *bmain)
                }
        }
 
+       if (!MAIN_VERSION_ATLEAST(bmain, 280, 0)) {
+               for (bScreen *screen = bmain->screens.first; screen; screen = 
screen->id.next) {
+                       for (ScrArea *sa = screen->areabase.first; sa; sa = 
sa->next) {
+                               for (SpaceLink *space = sa->spacedata.first; 
space; space = space->next) {
+                                       if (space->spacetype == SPACE_IMAGE) {
+                                               SpaceImage *sima = (SpaceImage 
*)space;
+                                               if ((sima) && (sima->gpd)) {
+                                                       sima->gpd->flag |= 
GP_DATA_ANNOTATIONS;
+                                                       
do_versions_fix_annotations(sima->gpd);
+                                               }
+                                       }
+                                       if (space->spacetype == SPACE_CLIP) {
+                                               SpaceClip *spclip = (SpaceClip 
*)space;
+                                               MovieClip *clip = spclip->clip;
+                                               if ((clip) && (clip->gpd)) {
+                                                       clip->gpd->flag |= 
GP_DATA_ANNOTATIONS;
+                                                       
do_versions_fix_annotations(clip->gpd);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
        /* New workspace design */
        if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
                do_version_workspaces_after_lib_link(bmain);
diff --git a/source/blender/editors/gpencil/gpencil_old.c 
b/source/blender/editors/gpencil/gpencil_old.c
index a6d63fadbd4..f1ef46b8995 100644
--- a/source/blender/editors/gpencil/gpencil_old.c
+++ b/source/blender/editors/gpencil/gpencil_old.c
@@ -48,6 +48,9 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
 #include "ED_object.h"
 #include "ED_gpencil.h"
 
@@ -94,14 +97,16 @@ static bool gpencil_convert_old_files_poll(bContext *C)
        return (int) (scene->gpd != NULL);
 }
 
-static int gpencil_convert_old_files_exec(bContext *C, wmOperator *UNUSED(op))
+static int gpencil_convert_old_files_exec(bContext *C, wmOperator *op)
 {
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
        ViewLayer *view_layer = CTX_data_view_layer(C);
+       const bool is_annotation = RNA_boolean_get(op->ptr, "annotation");
+       bGPdata *gpd = scene->gpd;
 
        /* Convert grease pencil scene datablock to GP object */
-       if ((scene->gpd) && (view_layer != NULL)) {
+       if ((!is_annotation) && (view_layer != NULL)) {
                Object *ob;
                ob = BKE_object_add_for_data(bmain, view_layer, OB_GPENCIL, 
"GP_Scene", &scene->gpd->id, false);
                zero_v3(ob->loc);
@@ -161,6 +166,26 @@ static int gpencil_convert_old_files_exec(bContext *C, 
wmOperator *UNUSED(op))
                scene->gpd = NULL;
        }
 
+       if (is_annotation) {
+               for (const bGPDpalette *palette = gpd->palettes.first; palette; 
palette = palette->next) {
+                       for (bGPDpalettecolor *palcolor = 
palette->colors.first; palcolor; palcolor = palcolor->next) {
+                               /* fix layers */
+                               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) {
+                                                       if ((gps->colorname[0] 
!= '\0') &&
+                                                               
(STREQ(gps->colorname, palcolor->info)))
+                                                       {
+                                                               /* copy color 
settings */
+                                                               
copy_v4_v4(gpl->color, palcolor->color);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 
@@ -170,9 +195,9 @@ static int gpencil_convert_old_files_exec(bContext *C, 
wmOperator *UNUSED(op))
 void GPENCIL_OT_convert_old_files(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name = "Convert 2.7 Grease Pencil File";
+       ot->name = "Convert Grease Pencil";
        ot->idname = "GPENCIL_OT_convert_old_files";
-       ot->description = "Convert 2.7x grease pencil files to 2.8";
+       ot->description = "Convert 2.7x grease pencil files to 2.80";
 
        /* callbacks */
        ot->exec = gpencil_convert_old_files_exec;
@@ -180,4 +205,7 @@ void GPENCIL_OT_convert_old_files(wmOperatorType *ot)
 
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* props */
+       ot->prop = RNA_def_boolean(ot->srna, "annotation", 0, "Annotation", 
"Convert to Annotations");
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to