diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-02-28 16:52:17 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-02-28 16:52:17 +0300 |
commit | 8b8e16dc2cedd03d0a22f89c9165c76722cc706a (patch) | |
tree | 1b72c623547f4b4ad5b47d552d7d6975170382b7 /source/blender/blenkernel/intern | |
parent | e7aca5bd3c8d8199834b535e97972216e7747bfa (diff) |
De-duplicate tool settings copy and make tool settings freeing reusable
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 188 |
1 files changed, 81 insertions, 107 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 3f27e136e8c..9b3299bdbc5 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -143,6 +143,83 @@ static void remove_sequencer_fcurves(Scene *sce) } } +/* flag -- copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). */ +ToolSettings *BKE_toolsettings_copy(ToolSettings *toolsettings, const int flag) +{ + if (toolsettings == NULL) { + return NULL; + } + ToolSettings *ts = MEM_dupallocN(toolsettings); + if (ts->vpaint) { + ts->vpaint = MEM_dupallocN(ts->vpaint); + BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, flag); + } + if (ts->wpaint) { + ts->wpaint = MEM_dupallocN(ts->wpaint); + BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, flag); + } + if (ts->sculpt) { + ts->sculpt = MEM_dupallocN(ts->sculpt); + BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, flag); + } + if (ts->uvsculpt) { + ts->uvsculpt = MEM_dupallocN(ts->uvsculpt); + BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, flag); + } + + BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, flag); + ts->imapaint.paintcursor = NULL; + ts->particle.paintcursor = NULL; + ts->particle.scene = NULL; + ts->particle.object = NULL; + + /* duplicate Grease Pencil Drawing Brushes */ + BLI_listbase_clear(&ts->gp_brushes); + for (bGPDbrush *brush = toolsettings->gp_brushes.first; brush; brush = brush->next) { + bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush); + BLI_addtail(&ts->gp_brushes, newbrush); + } + + /* duplicate Grease Pencil interpolation curve */ + ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo); + return ts; +} + +void BKE_toolsettings_free(ToolSettings *toolsettings) +{ + if (toolsettings == NULL) { + return; + } + if (toolsettings->vpaint) { + BKE_paint_free(&toolsettings->vpaint->paint); + MEM_freeN(toolsettings->vpaint); + } + if (toolsettings->wpaint) { + BKE_paint_free(&toolsettings->wpaint->paint); + MEM_freeN(toolsettings->wpaint); + } + if (toolsettings->sculpt) { + BKE_paint_free(&toolsettings->sculpt->paint); + MEM_freeN(toolsettings->sculpt); + } + if (toolsettings->uvsculpt) { + BKE_paint_free(&toolsettings->uvsculpt->paint); + MEM_freeN(toolsettings->uvsculpt); + } + BKE_paint_free(&toolsettings->imapaint.paint); + + /* free Grease Pencil Drawing Brushes */ + BKE_gpencil_free_brushes(&toolsettings->gp_brushes); + BLI_freelistN(&toolsettings->gp_brushes); + + /* free Grease Pencil interpolation curve */ + if (toolsettings->gp_interpolate.custom_ipo) { + curvemapping_free(toolsettings->gp_interpolate.custom_ipo); + } + + MEM_freeN(toolsettings); +} + /** * Only copy internal data of Scene ID from source to already allocated/initialized destination. * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs. @@ -215,41 +292,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons curvemapping_copy_data(&sce_dst->r.mblur_shutter_curve, &sce_src->r.mblur_shutter_curve); /* tool settings */ - if (sce_dst->toolsettings != NULL) { - ToolSettings *ts = sce_dst->toolsettings = MEM_dupallocN(sce_dst->toolsettings); - if (ts->vpaint) { - ts->vpaint = MEM_dupallocN(ts->vpaint); - BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, flag_subdata); - } - if (ts->wpaint) { - ts->wpaint = MEM_dupallocN(ts->wpaint); - BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, flag_subdata); - } - if (ts->sculpt) { - ts->sculpt = MEM_dupallocN(ts->sculpt); - BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, flag_subdata); - } - if (ts->uvsculpt) { - ts->uvsculpt = MEM_dupallocN(ts->uvsculpt); - BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, flag_subdata); - } - - BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, flag_subdata); - ts->imapaint.paintcursor = NULL; - ts->particle.paintcursor = NULL; - ts->particle.scene = NULL; - ts->particle.object = NULL; - - /* duplicate Grease Pencil Drawing Brushes */ - BLI_listbase_clear(&ts->gp_brushes); - for (bGPDbrush *brush = sce_src->toolsettings->gp_brushes.first; brush; brush = brush->next) { - bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush); - BLI_addtail(&ts->gp_brushes, newbrush); - } - - /* duplicate Grease Pencil interpolation curve */ - ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo); - } + sce_dst->toolsettings = BKE_toolsettings_copy(sce_dst->toolsettings, flag_subdata); /* make a private copy of the avicodecdata */ if (sce_src->r.avicodecdata) { @@ -288,7 +331,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) /* TODO this should/could most likely be replaced by call to more generic code at some point... * But for now, let's keep it well isolated here. */ if (type == SCE_COPY_EMPTY) { - ToolSettings *ts; ListBase rl, rv; sce_copy = BKE_scene_add(bmain, sce->id.name + 2); @@ -325,46 +367,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) curvemapping_copy_data(&sce_copy->r.mblur_shutter_curve, &sce->r.mblur_shutter_curve); /* tool settings */ - sce_copy->toolsettings = MEM_dupallocN(sce->toolsettings); - - ts = sce_copy->toolsettings; - if (ts) { - if (ts->vpaint) { - ts->vpaint = MEM_dupallocN(ts->vpaint); - BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint, 0); - } - if (ts->wpaint) { - ts->wpaint = MEM_dupallocN(ts->wpaint); - BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint, 0); - } - if (ts->sculpt) { - ts->sculpt = MEM_dupallocN(ts->sculpt); - BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint, 0); - } - if (ts->uvsculpt) { - ts->uvsculpt = MEM_dupallocN(ts->uvsculpt); - BKE_paint_copy(&ts->uvsculpt->paint, &ts->uvsculpt->paint, 0); - } - - BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint, 0); - ts->imapaint.paintcursor = NULL; - id_us_plus((ID *)ts->imapaint.stencil); - id_us_plus((ID *)ts->imapaint.clone); - id_us_plus((ID *)ts->imapaint.canvas); - ts->particle.paintcursor = NULL; - ts->particle.scene = NULL; - ts->particle.object = NULL; - - /* duplicate Grease Pencil Drawing Brushes */ - BLI_listbase_clear(&ts->gp_brushes); - for (bGPDbrush *brush = sce->toolsettings->gp_brushes.first; brush; brush = brush->next) { - bGPDbrush *newbrush = BKE_gpencil_brush_duplicate(brush); - BLI_addtail(&ts->gp_brushes, newbrush); - } - - /* duplicate Grease Pencil interpolation curve */ - ts->gp_interpolate.custom_ipo = curvemapping_copy(ts->gp_interpolate.custom_ipo); - } + sce_copy->toolsettings = BKE_toolsettings_copy(sce->toolsettings, 0); /* make a private copy of the avicodecdata */ if (sce->r.avicodecdata) { @@ -500,37 +503,8 @@ void BKE_scene_free(Scene *sce) BLI_freelistN(&sce->r.layers); BLI_freelistN(&sce->r.views); - if (sce->toolsettings) { - if (sce->toolsettings->vpaint) { - BKE_paint_free(&sce->toolsettings->vpaint->paint); - MEM_freeN(sce->toolsettings->vpaint); - } - if (sce->toolsettings->wpaint) { - BKE_paint_free(&sce->toolsettings->wpaint->paint); - MEM_freeN(sce->toolsettings->wpaint); - } - if (sce->toolsettings->sculpt) { - BKE_paint_free(&sce->toolsettings->sculpt->paint); - MEM_freeN(sce->toolsettings->sculpt); - } - if (sce->toolsettings->uvsculpt) { - BKE_paint_free(&sce->toolsettings->uvsculpt->paint); - MEM_freeN(sce->toolsettings->uvsculpt); - } - BKE_paint_free(&sce->toolsettings->imapaint.paint); - - /* free Grease Pencil Drawing Brushes */ - BKE_gpencil_free_brushes(&sce->toolsettings->gp_brushes); - BLI_freelistN(&sce->toolsettings->gp_brushes); - - /* free Grease Pencil interpolation curve */ - if (sce->toolsettings->gp_interpolate.custom_ipo) { - curvemapping_free(sce->toolsettings->gp_interpolate.custom_ipo); - } - - MEM_freeN(sce->toolsettings); - sce->toolsettings = NULL; - } + BKE_toolsettings_free(sce->toolsettings); + sce->toolsettings = NULL; DAG_scene_free(sce); if (sce->depsgraph) |